/** * Shows an insertion line if there is one or more current children. * * @see LayoutEditPolicy#showLayoutTargetFeedback(Request) */ protected void showLayoutTargetFeedback(Request request) { if (getHost().getChildren().size() == 0) return; Polyline fb = getLineFeedback(); Transposer transposer = new Transposer(); transposer.setEnabled(!isLayoutHorizontal()); int epIndex = getFeedbackIndexFor(request); Rectangle r = null; if (epIndex == -1) { epIndex = getHost().getChildren().size() - 1; EditPart editPart = (EditPart) getHost().getChildren().get(epIndex); r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart)); } else { EditPart editPart = (EditPart) getHost().getChildren().get(epIndex); r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart)); Point p = transposer.t(getLocationFromRequest(request)); if (p.x > r.x + (r.width / 2)) { editPart = (EditPart) getHost().getChildren().get(epIndex); r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart)); } } int x = r.x; Point p1 = new Point(x, r.y - 4); p1 = transposer.t(p1); fb.translateToRelative(p1); Point p2 = new Point(x, r.y + r.height + 4); p2 = transposer.t(p2); fb.translateToRelative(p2); fb.setPoint(p1, 0); fb.setPoint(p2, 1); }
/** * Lazily creates and returns a <code>Polyline</code> Figure for use as feedback. * * @return a Polyline figure */ protected Polyline getLineFeedback() { if (insertionLine == null) { insertionLine = new Polyline(); insertionLine.setLineWidth(2); insertionLine.addPoint(new Point(0, 0)); insertionLine.addPoint(new Point(10, 10)); addFeedback(insertionLine); } return insertionLine; }
/** * Refreshes the visual aspects of this, based upon the model (Wire). It changes the wire color * depending on the state of Wire. */ protected void updateSelected() { final EditPart source = getSource(); if (source != null) { final int sel = source.getSelected(); final Polyline line = (Polyline) getFigure(); if (sel != SELECTED_NONE) { line.setLineWidth(2); } else { line.setLineWidth(1); } } }
/** * Returns the bounds which holds all the points in this polyline connection. Returns any * previously existing bounds, else calculates by unioning all the children's dimensions. * * @return the bounds */ public Rectangle getBounds() { if (bounds == null) { super.getBounds(); for (int i = 0; i < getChildren().size(); i++) { IFigure child = (IFigure) getChildren().get(i); bounds.union(child.getBounds()); } } return bounds; }
public void layout() { Rectangle oldBounds = bounds; super.layout(); bounds = null; if (!getBounds().contains(oldBounds)) { getParent().translateToParent(oldBounds); getUpdateManager().addDirtyRegion(getParent(), oldBounds); } repaint(); fireFigureMoved(); }
public void setPoints(PointList points) { super.setPoints(points); layout(); // update arrows }
static void refreshGrid() { if (styleGrid != null) { styleGrid.dispose(); shell.pack(); } styleGrid = new Group(shell, SWT.NONE); styleGrid.setText(xAxis.getName() + " vs. " + yAxis.getName()); styleGrid.setLayout(new GridLayout(xAxis.getCount() + 1, false)); styleGrid.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); // put blank label in top left corner Label label = new Label(styleGrid, SWT.NONE); // add x-axis labels for (int x = 0; x < xAxis.getCount(); x++) { label = new Label(styleGrid, SWT.NONE); label.setText(xAxis.getName() + " =\n" + xAxis.getAt(x).getName()); } // iterate over the y-axis style settings for (int y = 1; y < yAxis.getCount() + 1; y++) { // add y-axis label for this row label = new Label(styleGrid, SWT.NONE); label.setText(yAxis.getName() + " =\n" + yAxis.getAt(y - 1).getName()); // iterate over the x-axis style settings for (int x = 1; x < xAxis.getCount() + 1; x++) { // create a sample shape instance Shape shape; if (sampleShape == Polyline.class) { Polyline poly = new Polyline(); poly.addPoint(new Point(20, 20)); poly.addPoint(new Point(50, 80)); poly.addPoint(new Point(10, 50)); shape = poly; } else { try { shape = (Shape) sampleShape.getConstructor(null).newInstance(null); } catch (Exception e) { throw new RuntimeException( "Could not find a no args constructor for " + sampleShape.getName()); } shape.setBounds(new Rectangle(0, 0, 100, 75)); } // apply default style shape.setBackgroundColor(ColorConstants.orange()); shape.setLineWidthFloat(defaultLineWidth); shape.setAntialias(SWT.ON); // apply styles imposed by each axis xAxis.applyTo(shape, x - 1); yAxis.applyTo(shape, y - 1); FigureCanvas figureBox = new FigureCanvas(styleGrid); figureBox.setContents(shape); } } shell.pack(); }