public void repositionLabel(int i) { Rectangle r = getConstraint(); if (r == null) return; Dimension s = labelControl.getPreferredSize(); // "Default", "Upper", "Center", "Bottom" int[][] style = { {1, 1}, {1, 1 - s.height}, {(r.width / 2) - (s.width / 2), (r.height / 2) - (s.height / 2)}, {1, r.height} }; if (i >= style.length) { return; } setConstraint(labelControl, new Rectangle(style[i][0], style[i][1], -1, -1)); setBackgroundColor(ColorConstants.white); }
public int setText(String text) { textLb.setText(text); return textLb.getPreferredSize().width; }
public void layout(IFigure container) { Rectangle area = container.getClientArea(); // calculate a virtual area if (scale != null && scale.isDirty()) M = Math.max( FigureUtilities.getTextWidth( scale.format(scale.getRange().getLower()), scale.getFont()), FigureUtilities.getTextWidth( scale.format(scale.getRange().getUpper()), scale.getFont())) / 2; int h = area.height; int w = area.width; if (h > HW_RATIO * (w - 2 * M)) h = (int) (HW_RATIO * (w - 2 * M)); // else if (w > h/HW_RATIO + 2*M) // w = (int) (h/HW_RATIO + 2*M); double r = h / (1 - Math.sin(ALPHA) / 2); int x = (int) (area.x - r * (1.0 - Math.cos(ALPHA)) + M); int y = area.y; area = new Rectangle(x, y, (int) (2 * r), (int) (2 * r)); Point center = area.getCenter(); if (scale != null) { scale.setBounds(area); } if (ramp != null && ramp.isVisible()) { Rectangle rampBounds = area.getCopy(); ramp.setBounds( rampBounds.shrink( area.width / 4 - ramp.getRampWidth(), area.height / 4 - ramp.getRampWidth())); } if (valueLabel != null) { Dimension labelSize = valueLabel.getPreferredSize(); valueLabel.setBounds( new Rectangle( area.x + area.width / 2 - labelSize.width / 2, area.y + area.height / 2 - area.height / 4 - (scale.getInnerRadius() - area.height / 4) / 2 - labelSize.height / 2, labelSize.width, labelSize.height)); } if (needle != null && scale != null) { needlePoints.setPoint( new Point(center.x + area.width / 4, center.y - NEEDLE_WIDTH / 2 + 3), 0); scale.getScaleTickMarks(); needlePoints.setPoint( new Point(center.x + scale.getInnerRadius() - GAP_BTW_NEEDLE_SCALE, center.y), 1); needlePoints.setPoint( new Point(center.x + area.width / 4, center.y + NEEDLE_WIDTH / 2 - 3), 2); double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false); if (maximum > minimum) { if (value > maximum) valuePosition += 8; else if (value < minimum) valuePosition -= 8; } else { if (value > minimum) valuePosition -= 8; else if (value < maximum) valuePosition += 8; } needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center), 2); needle.setPoints(needlePoints); } // if(needleCenter != null){ // needleCenter.setBounds(new Rectangle(center.x - area.width/4, // center.y - area.height/4, // area.width/2, area.height/2)); // } }
/** * @param contents IFigure * @param name String * @param route DotRoute * @return PolylineConnection */ private PolylineConnection addConnectionFromRoute( final IFigure contents, final String name, final DotRoute route) { final float[] coords = new float[6]; final ArrayList<AbsoluteBendpoint> bends = new ArrayList<AbsoluteBendpoint>(); boolean isFirstPoint = true; final Point min = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); final Point max = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); for (final PathIterator ite = new FlatteningPathIterator( route.getPath().getPathIterator(new AffineTransform()), PATH_ITERATOR_FLATNESS); !ite.isDone(); ite.next()) { final int segType = ite.currentSegment(coords); switch (segType) { case PathIterator.SEG_MOVETO: if (isFirstPoint) { addBendPoint(coords, bends, min, max); } else { LOG.error("Got SEG_MOVETO after first point"); } break; case PathIterator.SEG_LINETO: addBendPoint(coords, bends, min, max); break; default: LOG.error("Unexpected segment type " + segType); break; } isFirstPoint = false; } final Rectangle bounds = new Rectangle(min, max); final PolylineConnection conn = new PolylineConnection(); final Point sourcePoint = bends.remove(0); final Point targetPoint; if (route.getEndPt() != null) { targetPoint = new PrecisionPoint(route.getEndPt().getX(), route.getEndPt().getY()); } else { targetPoint = bends.remove(bends.size() - 1); } conn.setSourceAnchor(new XYRelativeAnchor(conn, sourcePoint)); conn.setTargetAnchor(new XYRelativeAnchor(conn, targetPoint)); if (bends.isEmpty()) { conn.setConnectionRouter(null); } else { conn.setConnectionRouter(new BendpointConnectionRouter()); conn.setRoutingConstraint(bends); } if (name != null) { final Label label = new Label(name); label.setOpaque(true); label.setBackgroundColor(ColorConstants.buttonLightest); label.setBorder(new LineBorder()); label.setFont(Application.getInstance().getFont(Application.LINK_FONT)); final ConnectionLocator locator = new MidpointLocator(conn, bends.size() / 2); locator.setRelativePosition(PositionConstants.CENTER); // Includes the label in the connection bounds. // Worst case scenario, the label is on the connection edge. final Dimension labelSize = label.getPreferredSize(); bounds.expand(labelSize.width, labelSize.height); conn.add(label, locator); } contents.add(conn, bounds); return conn; }
public void layout(IFigure container) { Rectangle area = container.getClientArea(); area.width = Math.min(area.width, area.height); area.height = area.width; area.shrink(BORDER_WIDTH, BORDER_WIDTH); Point center = area.getCenter(); if (scale != null) { scale.setBounds(area); } if (ramp != null && ramp.isVisible()) { Rectangle rampBounds = area.getCopy(); ramp.setBounds(rampBounds.shrink(area.width / 4, area.height / 4)); } if (valueLabel != null) { Dimension labelSize = valueLabel.getPreferredSize(); valueLabel.setBounds( new Rectangle( area.x + area.width / 2 - labelSize.width / 2, area.y + area.height * 7 / 8 - labelSize.height / 2, labelSize.width, labelSize.height)); } if (needle != null && scale != null) { needlePoints.setPoint(new Point(center.x, center.y - NeedleCenter.DIAMETER / 2 + 3), 0); scale.getScaleTickMarks(); needlePoints.setPoint( new Point( center.x + area.width / 2 - RoundScaleTickMarks.MAJOR_TICK_LENGTH - GAP_BTW_NEEDLE_SCALE, center.y), 1); needlePoints.setPoint(new Point(center.x, center.y + NeedleCenter.DIAMETER / 2 - 3), 2); double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false); if (maximum > minimum) { if (value > maximum) valuePosition += 10; else if (value < minimum) valuePosition -= 10; } else { if (value > minimum) valuePosition -= 10; else if (value < maximum) valuePosition += 10; } needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center), 2); needle.setPoints(needlePoints); } if (needleCenter != null) { needleCenter.setBounds( new Rectangle( center.x - NeedleCenter.DIAMETER / 2, center.y - NeedleCenter.DIAMETER / 2, NeedleCenter.DIAMETER, NeedleCenter.DIAMETER)); } }
public int getDefaultHeight() { return label.getPreferredSize().height; }