コード例 #1
0
 /**
  * Internal MDI frames have offsets where a popup menu should be shown (in JDK 1.2). This method
  * sums up iteratively all x and y offsets of all parent compontents until the top parent
  * component is reached.
  */
 private void adjustOffsets(Component comp, Point offsetPoint) {
   if (comp != null) {
     Point compLocation = comp.getLocation();
     offsetPoint.translate(compLocation.x, compLocation.y);
     adjustOffsets(comp.getParent(), offsetPoint);
   }
 }
コード例 #2
0
 /**
  * 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);
   }
 }