Exemplo n.º 1
0
  private void setupAttributes() {
    Color frameColor = (Color) AttributeFigure.getDefaultAttribute("FrameColor");
    Color fillColor = (Color) AttributeFigure.getDefaultAttribute("FillColor");
    Color textColor = (Color) AttributeFigure.getDefaultAttribute("TextColor");
    Integer arrowMode = (Integer) AttributeFigure.getDefaultAttribute("ArrowMode");
    String fontName = (String) AttributeFigure.getDefaultAttribute("FontName");

    FigureEnumeration k = view().selectionElements();
    while (k.hasMoreElements()) {
      Figure f = k.nextFigure();
      frameColor = (Color) f.getAttribute("FrameColor");
      fillColor = (Color) f.getAttribute("FillColor");
      textColor = (Color) f.getAttribute("TextColor");
      arrowMode = (Integer) f.getAttribute("ArrowMode");
      fontName = (String) f.getAttribute("FontName");
    }

    fFrameColor.setSelectedIndex(ColorMap.colorIndex(frameColor));
    fFillColor.setSelectedIndex(ColorMap.colorIndex(fillColor));
    // fTextColor.select(ColorMap.colorIndex(textColor));
    if (arrowMode != null) {
      fArrowChoice.setSelectedIndex(arrowMode.intValue());
    }
    if (fontName != null) {
      fFontChoice.setSelectedItem(fontName);
    }
  }
 /**
  * Hook method which can be overriden by subclasses to provide specialised behaviour in the event
  * of a popup trigger.
  */
 protected void handlePopupMenu(MouseEvent e, int x, int y) {
   Figure figure = drawing().findFigure(e.getX(), e.getY());
   if (figure != null) {
     Object attribute = figure.getAttribute(Figure.POPUP_MENU);
     if (attribute == null) {
       figure = drawing().findFigureInside(e.getX(), e.getY());
     }
     if (figure != null) {
       showPopupMenu(figure, e.getX(), e.getY(), e.getComponent());
     }
   }
 }
Exemplo n.º 3
0
 private String getURL(Figure figure) {
   String url = (String) figure.getAttribute("URL");
   if (url == null) {
     url = "";
   }
   return url;
 }
Exemplo n.º 4
0
 private Rectangle fieldBounds(Figure figure) {
   Rectangle box = figure.displayBox();
   int nChars = Math.max(20, getURL(figure).length());
   Dimension d = fTextField.getPreferredSize(nChars);
   box.x = Math.max(0, box.x + (box.width - d.width) / 2);
   box.y = Math.max(0, box.y + (box.height - d.height) / 2);
   return new Rectangle(box.x, box.y, d.width, d.height);
 }
 /**
  * This method displays a popup menu, if there is one registered with the Figure (the Figure's
  * attributes are queried for Figure.POPUP_MENU which is used to indicate an association of a
  * popup menu with the Figure).
  *
  * @param figure Figure for which a popup menu should be displayed
  * @param x x coordinate where the popup menu should be displayed
  * @param y y coordinate where the popup menu should be displayed
  * @param component Component which invoked the popup menu
  */
 protected void showPopupMenu(Figure figure, int x, int y, Component comp) {
   final Object attribute = figure.getAttribute(Figure.POPUP_MENU);
   if ((attribute != null) && (attribute instanceof JPopupMenu)) {
     JPopupMenu popup = (JPopupMenu) attribute;
     if (popup instanceof PopupMenuFigureSelection) {
       ((PopupMenuFigureSelection) popup).setSelectedFigure(figure);
     }
     // calculate offsets for internal MDI frames
     Point newLocation = new Point(x, y);
     adjustOffsets(comp.getParent(), newLocation);
     popup.setLocation(newLocation);
     popup.setInvoker(comp);
     popup.setVisible(true);
   }
 }
Exemplo n.º 6
0
  private int constrainY(int y) {
    LineConnection line = ownerConnection();
    Figure startFigure = line.getStartConnector().owner();
    Figure endFigure = line.getEndConnector().owner();
    Rectangle start = startFigure.displayBox();
    Rectangle end = endFigure.displayBox();
    Insets i1 = startFigure.connectionInsets();
    Insets i2 = endFigure.connectionInsets();

    int r1y, r1height, r2y, r2height;
    r1y = start.y + i1.top;
    r1height = start.height - i1.top - i1.bottom - 1;
    r2y = end.y + i2.top;
    r2height = end.height - i2.top - i2.bottom - 1;

    if (fSegment == 0) {
      y = Geom.range(r1y, r1y + r1height, y);
    }
    if (fSegment == line.pointCount() - 2) {
      y = Geom.range(r2y, r2y + r2height, y);
    }
    return y;
  }
Exemplo n.º 7
0
  private int constrainX(int x) {
    LineConnection line = ownerConnection();
    Figure startFigure = line.getStartConnector().owner();
    Figure endFigure = line.getEndConnector().owner();
    Rectangle start = startFigure.displayBox();
    Rectangle end = endFigure.displayBox();
    Insets i1 = startFigure.connectionInsets();
    Insets i2 = endFigure.connectionInsets();

    int r1x, r1width, r2x, r2width;
    r1x = start.x + i1.left;
    r1width = start.width - i1.left - i1.right - 1;

    r2x = end.x + i2.left;
    r2width = end.width - i2.left - i2.right - 1;

    if (fSegment == 0) {
      x = Geom.range(r1x, r1x + r1width, x);
    }
    if (fSegment == line.pointCount() - 2) {
      x = Geom.range(r2x, r2x + r2width, x);
    }
    return x;
  }
Exemplo n.º 8
0
 private void setURL(Figure figure, String url) {
   figure.setAttribute("URL", url);
 }