object optimization

This commit is contained in:
bancika
2011-01-16 23:08:31 +00:00
parent c3d5556121
commit 796276b1c1
2 changed files with 3 additions and 2 deletions
@@ -86,7 +86,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.setColor(bodyColor); g2d.setColor(bodyColor);
g2d.fill(shape); g2d.fill(shape);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
g2d.setStroke(new BasicStroke(1)); g2d.setStroke(Constants.BASIC_STROKE);
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.draw(shape); g2d.draw(shape);
@@ -107,7 +107,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED .setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR); : LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); FontMetrics fontMetrics = g2d.getFontMetrics();
String label = display == Display.NAME ? getName() : getValue().toString(); String label = display == Display.NAME ? getName() : getValue().toString();
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2, g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
@@ -20,6 +20,7 @@ public class Constants {
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 11); public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 11);
public static final Stroke BASIC_STROKE = new BasicStroke();
public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 2.0f, new float[] { 2.0f }, 0.0f); BasicStroke.JOIN_MITER, 2.0f, new float[] { 2.0f }, 0.0f);
} }