use of java.awt.Stroke in project vcell by virtualcell.
the class ReactionToolShapeIcon method main.
public static void main(String[] args) {
try {
Frame frame = new Frame();
Icon iconNormal = new ReactionToolShapeIcon(State.normal, Mode.plain);
int diameter = 20;
int x = 50;
int y = 80;
JPanel panel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
// --------------------------------------------------------------
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke(new BasicStroke(5f));
g2.setColor(Color.black);
Color c1, c2;
// -16
int xx = x - 16;
// -15
int yy = y - 15;
// 8
int w = diameter * 8;
int h = diameter * 8;
c1 = Color.black;
c2 = Color.lightGray;
Arc2D arc = new // Line2D
Arc2D.Double(// Line2D
xx, // Line2D
yy, // Line2D
w, // Line2D
h, 0, 300, Arc2D.OPEN);
GradientPaint gp = new GradientPaint(50, 50 + 200, c1, 50 + 5, 50 + 200 - 5, c2, true);
g2.setPaint(gp);
g2.draw(arc);
// -------------------------------------------------------------
g2.setPaint(paintOld);
int a = 0;
float[] dash = { 10.0f };
Stroke dashed = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash, 0);
g2.setStroke(dashed);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 10;
float[] dash1 = { 5.0f };
Stroke dashed1 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash1, 0);
g2.setStroke(dashed1);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 20;
float[] dash2 = { 12.0f, 10.0f, 8.0f };
Stroke dashed2 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash2, 0);
g2.setStroke(dashed2);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 30;
float[] dash3 = { 12.0f, 10.0f, 8.0f };
Stroke dashed3 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash3, 50);
g2.setStroke(dashed3);
g2.drawLine(10, 10 + a, 150, 10 + a);
// ----------------------------------------------------------------------------------
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
};
panel.setSize(500, 400);
frame.add("Center", panel);
frame.setSize(panel.getSize());
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.awt.Panel");
exception.printStackTrace(System.out);
}
}
use of java.awt.Stroke in project vcell by virtualcell.
the class ReactionToolShapeIcon method paintIcon.
@Override
public void paintIcon(Component comp, Graphics g, int x, int y) {
if (comp == null) {
return;
}
if (!(comp instanceof JToolBarToggleButton)) {
return;
}
JToolBarToggleButton button = (JToolBarToggleButton) comp;
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke(new BasicStroke(2f));
Color c1, c2, c3, c4;
// for the arrowhead
float x1, x2, y1, y2;
int xx = x - 16;
int yy = y - 15;
// we'll paint a small arc from the upper left part of a very large circle
int w = diameter * 8;
int h = diameter * 8;
// the start and end coordinates of the membrane (for the flux button)
float m1 = 9f;
float m2 = 14f;
if (state == State.normal) {
// paint yellow arc
c1 = Color.yellow.darker();
c2 = Color.yellow;
c3 = Color.black;
c4 = Color.yellow.darker();
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
} else {
c1 = Color.yellow.darker();
c2 = Color.yellow.brighter();
c3 = Color.black;
c4 = Color.yellow.darker().darker();
xx += 1;
yy += 1;
x1 = 1;
x2 = 1;
y1 = 1;
y2 = 1;
m1 += 1.0f;
m2 += 1.0f;
}
Arc2D arc;
if (mode == Mode.catalyst) {
arc = new Arc2D.Double(xx, yy, w, h, 125, 18, Arc2D.OPEN);
} else {
arc = new Arc2D.Double(xx, yy, w, h, // starting angle
126, // angular extent
18, Arc2D.OPEN);
}
int a = 0;
int b = -10;
int c = 12;
// the wide yellow halo
g2.setStroke(new BasicStroke(4.0f));
GradientPaint gp = new GradientPaint(a, b, c1, a + c, b - c, c2, true);
g2.setPaint(gp);
g2.draw(arc);
if (mode == Mode.flux) {
// the "membrane" line, only for flux reactions
g2.setStroke(new BasicStroke(5.0f));
g2.setPaint(Color.orange.darker());
Line2D line = new Line2D.Float(m1, m1, m2, m2);
g2.draw(line);
}
if (mode == Mode.catalyst) {
// dashed black line for catalyst
float[] dash = { 6.2f, 3.6f };
Stroke dashed = new BasicStroke(1.6f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash, 0);
g2.setStroke(dashed);
g2.setPaint(Color.black);
// gp = new GradientPaint(a, b, c3, a+c, b-c, c4, true);
// g2.setPaint(gp);
g2.draw(arc);
} else {
// the continuous black line for plain and flux reactions
g2.setStroke(new BasicStroke(2f));
gp = new GradientPaint(a, b, c3, a + c, b - c, c4, true);
g2.setPaint(gp);
g2.draw(arc);
}
// TODO: draw arrow (maybe)
// g2.setStroke(new BasicStroke(1.4f, // Line width
// BasicStroke.CAP_ROUND, // End-cap style
// BasicStroke.JOIN_ROUND)); // Vertex join style
// Line2D l1 = new Line2D.Float(x1, y1, x2, y2);
// Line2D l2 = new Line2D.Float(x1, y1, x2, y2);
// g2.draw(l1);
// g2.draw(l2);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.Stroke in project vcell by virtualcell.
the class ResizeCanvasShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
if (!(c instanceof JButton)) {
return;
}
JButton b = (JButton) c;
// button center
int cx = b.getWidth() / 2;
int cy = b.getHeight() / 2;
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// the nock (base end, towards the fletching) of the arrow shaft
Color interior;
// the spine (tip end, connecting to the arrow head) of the shaft
Color exterior;
// the arrow head
Color tip;
Color[] colors;
float[] dist;
Color c1, c2, c3;
if (sign == Sign.expand) {
c1 = SpeciesPatternLargeShape.componentGreen.darker();
c2 = SpeciesPatternLargeShape.componentGreen.darker().darker();
c3 = Color.green.darker().darker();
} else {
c1 = SpeciesPatternLargeShape.componentBad.darker();
c2 = SpeciesPatternLargeShape.componentBad.darker().darker();
c3 = Color.red.darker().darker();
}
Point2D center = new Point2D.Float(cx, cy);
float radius = side / 2 + 1;
// white mapped in the center
Point2D focus = new Point2D.Float(cx, cy);
if (b.isEnabled()) {
if (state == State.normal) {
// Color.cyan;
interior = c1;
// Color.blue;
exterior = c2;
// Color.blue.darker();
tip = c3.darker();
} else {
// pressed! same colors, brighter when button is pressed
// Color.cyan.brighter();
interior = c1.brighter();
// Color.blue.brighter();
exterior = c2.brighter();
// Color.blue;
tip = c3.brighter();
}
} else {
// disabled - uniform gray, regardless of pressed
interior = Color.lightGray;
exterior = Color.gray;
tip = Color.gray;
}
if (sign == Sign.expand) {
colors = new Color[] { interior, exterior };
dist = new float[] { 0.2f, 1.0f };
} else {
// arrow points the other way, so the arrow colors are inverted
colors = new Color[] { exterior, interior };
dist = new float[] { 0.9f, 1.0f };
}
RadialGradientPaint paint = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(paint);
// starting offset (how far away from center starts the shaft of the arrow)
int o;
// length of the 2 "wings" of the arrow head)
int d;
int xx = side / 2;
int yy = side / 2;
float strokeWidth;
if (sign == Sign.expand) {
o = 2;
d = 4;
strokeWidth = 2.0f;
} else {
// shrink
o = 2;
d = 4;
// xx++;
// yy++;
strokeWidth = 1.6f;
}
g2.setStroke(new // Line width
BasicStroke(// Line width
strokeWidth, // End-cap style
BasicStroke.CAP_ROUND, // Vertex join style
BasicStroke.JOIN_ROUND));
// upper left
g2.drawLine(cx - o, cy - o, cx - xx, cy - yy);
// upper right
g2.drawLine(cx + o, cy - o, cx + xx, cy - yy);
// lower left
g2.drawLine(cx - o, cy + o, cx - xx, cy + yy);
// lower right
g2.drawLine(cx + o, cy + o, cx + xx, cy + yy);
g2.setPaint(paintOld);
g2.setColor(tip);
if (sign == Sign.expand) {
// upper left
g2.drawLine(cx - xx, cy - yy, cx - xx + d, cy - yy);
g2.drawLine(cx - xx, cy - yy, cx - xx, cy - yy + d);
// upper right
g2.drawLine(cx + xx, cy - yy, cx + xx - d, cy - yy);
g2.drawLine(cx + xx, cy - yy, cx + xx, cy - yy + d);
// lower left
g2.drawLine(cx - xx, cy + yy, cx - xx + d, cy + yy);
g2.drawLine(cx - xx, cy + yy, cx - xx, cy + yy - d);
// lower right
g2.drawLine(cx + xx, cy + yy, cx + xx - d, cy + yy);
g2.drawLine(cx + xx, cy + yy, cx + xx, cy + yy - d);
} else {
// upper left
g2.drawLine(cx - o, cy - o, cx - o - d, cy - o);
g2.drawLine(cx - o, cy - o, cx - o, cy - o - d);
// upper right
g2.drawLine(cx + o, cy - o, cx + o + d, cy - o);
g2.drawLine(cx + o, cy - o, cx + o, cy - o - d);
// lower left
g2.drawLine(cx - o, cy + o, cx - o - d, cy + o);
g2.drawLine(cx - o, cy + o, cx - o, cy + o + d);
// lower right
g2.drawLine(cx + o, cy + o, cx + o + d, cy + o);
g2.drawLine(cx + o, cy + o, cx + o, cy + o + d);
}
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.Stroke in project vcell by virtualcell.
the class GroupMoleculeToolShape method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
if (!(c instanceof JToolBarToggleButton)) {
return;
}
JToolBarToggleButton b = (JToolBarToggleButton) c;
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color c1;
Color c2;
Color c3;
Color c4;
// offset from upper left corner
int init;
switch(state) {
case normal:
init = 0;
c1 = Color.red.darker();
c2 = Color.darkGray;
c3 = Color.gray;
c4 = AbstractComponentShape.componentMediumPalePink;
break;
case selected:
init = 1;
c1 = Color.red.darker().darker();
c2 = Color.darkGray;
c3 = Color.gray;
c4 = AbstractComponentShape.componentPalePink;
break;
case disabled:
default:
init = 0;
c1 = Color.lightGray;
c2 = Color.lightGray;
c3 = Color.lightGray;
c4 = AbstractComponentShape.componentMediumPalePink;
break;
}
g2.setStroke(new BasicStroke(1.2f));
g2.setPaint(c2);
// the large square
final int delta = 15;
int xx = x + init + 1;
int yy = y + init + 1;
Rectangle2D rect = new Rectangle2D.Double(xx, yy, delta + 1, delta);
g2.draw(rect);
g2.setStroke(new BasicStroke(0.8f));
final int delta2 = 7;
// the lower small rectangle
xx += 5;
yy += 5;
rect = new Rectangle2D.Double(xx, yy, delta2 + 1, delta2);
g2.setPaint(c3);
g2.draw(rect);
// the upper small rectangle
xx -= 2;
yy -= 2;
rect = new Rectangle2D.Double(xx, yy, delta2 + 1, delta2);
g2.setPaint(c4);
// overwrite some of the smaller rectangle
g2.fill(rect);
g2.setPaint(c3);
g2.draw(rect);
// ---------------------------------------------------------------------
int m = 3;
// upper left corner small red square
g2.setStroke(new BasicStroke(1.0f));
g2.setPaint(c1);
xx = x + init;
yy = y + init;
rect = new Rectangle2D.Double(xx, yy, m, m);
// g2.draw(rect);
g2.fill(rect);
xx = x + init + delta + 1;
yy = y + init;
rect = new Rectangle2D.Double(xx, yy, m, m);
g2.fill(rect);
xx = x + init;
yy = y + init + delta;
rect = new Rectangle2D.Double(xx, yy, m, m);
g2.fill(rect);
xx = x + init + delta + 1;
yy = y + init + delta;
rect = new Rectangle2D.Double(xx, yy, m, m);
g2.fill(rect);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.Stroke in project vcell by virtualcell.
the class HighlightCatalystShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color c1, c2, c3;
int xx, yy;
if (state == State.normal) {
c1 = Color.green.darker();
c2 = Color.green.darker();
c3 = Color.black;
xx = x + 1;
yy = y + 1;
} else {
// button pressed
c1 = Color.green.darker();
c2 = Color.magenta.darker();
c3 = Color.black;
xx = x + 2;
yy = y + 2;
}
double w = diameter / 2 - 2;
double h = diameter / 2 - 2;
g2.setStroke(new BasicStroke(1.2f));
Ellipse2D e1 = new Ellipse2D.Double(xx, yy, w, h);
g2.setPaint(c3);
g2.draw(e1);
g2.setPaint(c1);
g2.fill(e1);
Ellipse2D e2 = new Ellipse2D.Double(xx + 9, yy + 8, w, h);
g2.setPaint(c3);
g2.draw(e2);
g2.setPaint(c2);
g2.fill(e2);
g2.setStroke(new BasicStroke(1.2f));
g2.setPaint(c3);
Line2D line = new Line2D.Double(xx + w / 2, yy + h + 1, xx + w / 2, yy + h + 7);
g2.draw(line);
g2.setStroke(new BasicStroke(1.6f));
line = new Line2D.Double(xx + 9 + w / 2, yy + 1, xx + 9 + w / 2, yy + 2);
g2.draw(line);
line = new Line2D.Double(xx + 9 + w / 2, yy + 6, xx + 9 + w / 2, yy + 7);
g2.draw(line);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
Aggregations