/** Creates a custom popup menu for the table header. */
  private JPopupMenu createHeaderPopup() {
    // Create popup menu.
    JPopupMenu popupMenu = new JPopupMenu();

    JMenuItem defaultItem = new JMenuItem();
    defaultItem.setAction(defaultConfigAction);
    popupMenu.add(defaultItem);

    JMenu optionsMenu = new JMenu(I18n.tr("More Options"));
    popupMenu.add(optionsMenu);
    popupMenu.addSeparator();

    JMenuItem autosortItem = new JCheckBoxMenuItem();
    autosortItem.setAction(autosortAction);
    optionsMenu.add(autosortItem);

    JMenuItem tooltipsItem = new JCheckBoxMenuItem();
    tooltipsItem.setAction(tooltipsAction);
    optionsMenu.add(tooltipsItem);

    // Get column headings in default order.
    int columnCount = tableFormat.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
      // Create checkbox menu item for each column heading.
      String headerName = tableFormat.getColumnName(i);
      JMenuItem item = new JCheckBoxMenuItem(headerName, true);
      item.addActionListener(toggleColumnAction);
      popupMenu.add(item);
    }

    return popupMenu;
  }
Ejemplo n.º 2
0
 // this is bordering on comical its so confusing.
 // this method runs for the hubnet client editor.
 // im not yet sure if it runs anywhere else.
 // that seems like bugs waiting to happen. JC - 12/20/10
 protected void doPopup(java.awt.event.MouseEvent e) {
   javax.swing.JPopupMenu menu = new javax.swing.JPopupMenu();
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.button"), "BUTTON", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.slider"), "SLIDER", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.switch"), "SWITCH", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.chooser"), "CHOOSER", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.input"), "INPUT", e.getX(), e.getY()));
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.monitor"), "MONITOR", e.getX(), e.getY()));
   WidgetCreationMenuItem plot =
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.plot"), "PLOT", e.getX(), e.getY());
   // if there are no plots in this model, then you can't have a plot in a hubnet client.
   if (workspace.plotManager().plots().size() == 0) {
     plot.setEnabled(false);
   }
   menu.add(plot);
   menu.add(
       new WidgetCreationMenuItem(
           I18N.guiJ().get("tabs.run.widgets.note"), "NOTE", e.getX(), e.getY()));
   menu.show(this, e.getX(), e.getY());
 }
  public static void main(String[] args) {
    final JPopupMenu menu = new JPopupMenu();
    menu.setLayout(new GridLayout(0, 3, 5, 5));

    final MenuedButton button = new MenuedButton("Icons", menu);

    for (int i = 0; i < 9; i++) {
      // replace "print.gif" with your own image
      final JLabel label = new JLabel("" + i); // new ImageIcon("resources/images/print.gif") );
      label.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              button.getMainButton().setIcon(label.getIcon());
              menu.setVisible(false);
            }
          });
      menu.add(label);
    }

    JFrame frame = new JFrame("Button Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new JLabel("Click Arrow Button To Show Popup"), BorderLayout.NORTH);
    frame.getContentPane().add(button, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
Ejemplo n.º 4
0
  private void showSliderMenu() {
    Point location = new Point(getX(), getY() + getHeight());

    SwingUtilities.convertPointToScreen(location, InputVolumeControlButton.this.getParent());

    if (isFullScreen()) {
      location.setLocation(
          location.getX(),
          location.getY() - sliderMenu.getPreferredSize().getHeight() - getHeight());
    }

    sliderMenu.setLocation(location);

    sliderMenu.addPopupMenuListener(
        new PopupMenuListener() {
          public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = true;
          }

          public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = false;
          }

          public void popupMenuCanceled(PopupMenuEvent ev) {}
        });

    sliderMenu.setVisible(!sliderMenu.isVisible());
  }
Ejemplo n.º 5
0
  /** @param index */
  private void createPlayerTypeOptions() {
    radioHuman = new FRadioButton("Human");
    radioAi = new FRadioButton("AI");
    radioOpen = new FRadioButton("Open");

    final JPopupMenu menu = new JPopupMenu();
    radioAiUseSimulation = new JCheckBoxMenuItem("Use Simulation");
    menu.add(radioAiUseSimulation);
    radioAiUseSimulation.addActionListener(
        new ActionListener() {
          @Override
          public final void actionPerformed(final ActionEvent e) {
            lobby.firePlayerChangeListener(index);
          }
        });
    radioAi.setComponentPopupMenu(menu);

    radioHuman.addMouseListener(radioMouseAdapter(radioHuman, LobbySlotType.LOCAL));
    radioAi.addMouseListener(radioMouseAdapter(radioAi, LobbySlotType.AI));
    radioOpen.addMouseListener(radioMouseAdapter(radioOpen, LobbySlotType.OPEN));

    final ButtonGroup tempBtnGroup = new ButtonGroup();
    tempBtnGroup.add(radioHuman);
    tempBtnGroup.add(radioAi);
    tempBtnGroup.add(radioOpen);
  }
Ejemplo n.º 6
0
  private JTable initSessionList() {

    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem removeItem = new JMenuItem(BundleUtil.getString(BundleUtil.Command_Delete));
    removeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            remove();
          }
        });
    popupMenu.add(removeItem);

    sessionListModel =
        new DefaultTableModel() {
          @Override
          public boolean isCellEditable(int row, int column) {
            return false;
          }
        };

    TableSorter sorter = new TableSorter(sessionListModel);

    JTable sessionsTable = new JTable(sorter);

    sessionsTable.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            JTable table = (JTable) e.getSource();
            int currentRow = table.rowAtPoint(e.getPoint());
            if (currentRow >= 0) {
              table.setRowSelectionInterval(currentRow, currentRow);
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            JTable table = (JTable) e.getSource();
            int currentRow = table.rowAtPoint(e.getPoint());
            if (currentRow >= 0) {
              table.setRowSelectionInterval(currentRow, currentRow);
            }
            currentSession = (Long) table.getValueAt(table.rowAtPoint(e.getPoint()), 0);
            if (e.getButton() == 3) {
              popupMenu.show(table, e.getX(), e.getY());
            }
          }
        });

    sorter.setTableHeader(sessionsTable.getTableHeader());

    sessionListModel.addColumn("会话ID");
    sessionListModel.addColumn("用户名");
    sessionListModel.addColumn("IP地址");
    sessionListModel.addColumn("创建时间");
    sessionListModel.addColumn("操作");
    sessionListModel.addColumn("注销时间");

    return sessionsTable;
  }
  public void eventDispatched(AWTEvent event) {
    if (!isAssertTrigger(event)) {
      return;
    }

    MouseEvent mouse = (MouseEvent) event;

    GuiComponent guiComponent = factory.find(mouse);

    if (guiComponent == null) {
      return;
    }

    assertContext.setGuiComponent(guiComponent);
    assertContext.setPoint(mouse.getPoint());

    JPopupMenu menu = dialogManager.newPopupMenu();

    for (Iterator iterator = actionManager.actions(); iterator.hasNext(); ) {
      AbstractAssert assertAction = (AbstractAssert) iterator.next();
      String actionId = (String) assertAction.getValue(AbstractAssert.ACTION_ID);

      ActionViewUtil.connectActionTo(assertAction, menu.add(actionId));
      assertAction.update();

      if (!guiComponent.isFindable()
          && AbstractAssert.COMPONENT_ASSERT == assertAction.getAssertType()) {
        assertAction.setEnabled(false);
      }
    }

    menu.setBorder(BorderFactory.createLineBorder(Color.blue, 5));
    menu.show(guiComponent.getSwingComponent(), mouse.getX(), mouse.getY());
  }
 private void addLexemePropertiesPopupMenu() {
   menuLexemeProperties =
       new JPopupMenu() {
         @Override
         public void show(Component c, int x, int y) {
           intLexemePropertiesPopup = leksēmuĪpašībuTabula.rowAtPoint(new Point(x, y));
           super.show(c, x, y);
         }
       };
   JMenuItem addLexemeProperty = new JMenuItem("Pievienot īpašību");
   addLexemeProperty.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent arg0) {
           if (intLexemePropertiesPopup >= 0
               && intLexemePropertiesPopup < leksēmuĪpašībuTabula.getRowCount())
             addLexemeProperty();
         }
       });
   JMenuItem deleteLexemeProperty = new JMenuItem("Dzēst īpašību");
   deleteLexemeProperty.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent arg0) {
           if (intLexemePropertiesPopup >= 0
               && intLexemePropertiesPopup < leksēmuĪpašībuTabula.getRowCount())
             deleteLexemeProperty(intLexemePropertiesPopup);
         }
       });
   menuLexemeProperties.add(addLexemeProperty);
   menuLexemeProperties.add(deleteLexemeProperty);
   leksēmuĪpašībuTabula.setComponentPopupMenu(menuLexemeProperties);
 }
  public static void showPopupMenu(
      final JPopupMenu popup, final Component component, int x, int y) {
    final Point p = new Point(x, y);
    SwingUtilities.convertPointToScreen(p, component);
    final Dimension size = popup.getPreferredSize();
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    boolean horiz = false;
    boolean vert = false;

    final int origX = x;

    if ((p.x + size.width > screen.width) && (size.width < screen.width)) {
      x += (screen.width - p.x - size.width);
      horiz = true;
    }

    if ((p.y + size.height > screen.height) && (size.height < screen.height)) {
      y += (screen.height - p.y - size.height);
      vert = true;
    }

    if (horiz && vert) {
      x = origX - size.width - 2;
    }
    popup.show(component, x, y);
  }
Ejemplo n.º 10
0
 private JPopupMenu createTablePopupMenu() {
   final JPopupMenu menu = new JPopupMenu();
   menu.add(
       new AbstractAction("Copy Term") {
         @Override
         public void actionPerformed(ActionEvent e) {
           copyTermAtPoint(tablePopup.getLocation());
         }
       });
   menu.add(
       new AbstractAction("Paste Term") {
         @Override
         public void actionPerformed(ActionEvent e) {
           pasteTermAtPoint(tablePopup.getLocation());
         }
       });
   menu.add(
       new AbstractAction("Edit Post-composed Term") {
         @Override
         public void actionPerformed(ActionEvent e) {
           runPostCompositionForTermAtPoint(tablePopup.getLocation());
         }
       });
   return menu;
 }
 private void addEndingPopupMenu() {
   menuEnding =
       new JPopupMenu() {
         @Override
         public void show(Component c, int x, int y) {
           intEndingPopup = galotņuTabula.rowAtPoint(new Point(x, y));
           super.show(c, x, y);
         }
       };
   JMenuItem addEnding = new JMenuItem("Pievienot galotni");
   addEnding.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent arg0) {
           if (intEndingPopup >= 0 && intEndingPopup < galotņuTabula.getRowCount()) addEnding();
         }
       });
   JMenuItem deleteEnding = new JMenuItem("Dzēst galotni");
   deleteEnding.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent arg0) {
           if (intEndingPopup >= 0 && intEndingPopup < galotņuTabula.getRowCount())
             deleteEnding(intEndingPopup);
         }
       });
   menuEnding.add(addEnding);
   menuEnding.add(deleteEnding);
   galotņuTabula.setComponentPopupMenu(menuEnding);
 }
  @Override
  public JPopupMenu getNullRowSelectedPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(getMenuItme("刷新(R)", 'R', "R"));

    return popupMenu;
  }
Ejemplo n.º 13
0
  protected JPopupMenu createPopupMenu(SearchResultDataLine[] lines) {
    //  do not return a menu if right-clicking on the dummy panel
    if (!isKillable()) return null;

    JPopupMenu menu = new SkinPopupMenu();

    if (lines.length > 0) {
      boolean allWithHash = true;
      for (int i = 0; i < lines.length; i++) {
        if (lines[i].getHash() == null) {
          allWithHash = false;
          break;
        }
      }
      PopupUtils.addMenuItem(
          I18n.tr("Copy Magnet"), COPY_MAGNET_ACTION_LISTENER, menu, allWithHash);
      PopupUtils.addMenuItem(I18n.tr("Copy Hash"), COPY_HASH_ACTION_LISTENER, menu, allWithHash);

      menu.add(createSearchAgainMenu(lines[0]));
    } else {
      menu.add(new SkinMenuItem(new RepeatSearchAction()));
    }

    return (new SearchResultMenu(this)).addToMenu(menu, lines);
  }
Ejemplo n.º 14
0
 private JPopupMenu createPopupMenu() {
   JPopupMenu menu = new JPopupMenu();
   menu.add(this.printAction);
   menu.add(this.copyPreviewAction);
   this.basePanel.ifPresent(p -> menu.add(p.frame().getSwitchPreviewAction()));
   return menu;
 }
Ejemplo n.º 15
0
  private void createPopup(JPopupMenu popup) {
    ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String cmd = e.getActionCommand().trim();
            if (cmd.equalsIgnoreCase("play")) {
              player.play();
            } else if (cmd.equalsIgnoreCase("pause")) {
              player.pause();
            } else if (cmd.equalsIgnoreCase("next")) {
              player.next();
            } else if (cmd.equalsIgnoreCase("previous")) {
              player.prev();
            } else if (cmd.equalsIgnoreCase("stop")) {
              player.stop();
            } else if (cmd.equalsIgnoreCase("quit")) {
              app.exit();
            }
          }
        };

    popup.add("   Play").addActionListener(al);
    popup.add("   Pause").addActionListener(al);
    popup.add("   Next").addActionListener(al);
    popup.add("   Stop").addActionListener(al);
    popup.add("   Previous   ").addActionListener(al);
    popup.add("   Quit").addActionListener(al);
  }
  /**
   * Shows the PopUp
   *
   * @param e MouseEvent
   */
  protected void showPopUpMenu(MouseEvent e) {
    if (!(e.getSource() instanceof JList)) {
      return;
    }

    JList list = (JList) e.getSource();

    int i = list.locationToIndex(e.getPoint());
    list.setSelectedIndex(i);

    JPopupMenu menu = new JPopupMenu();

    Rating selRating = (Rating) list.getSelectedValue();

    JMenuItem item = new JMenuItem(mLocalizer.msg("showDetails", "Show Details"));
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            view();
          }
        });
    item.setFont(item.getFont().deriveFont(Font.BOLD));

    menu.add(item);
    menu.add(new ListAction(this, selRating.getTitle()));
    menu.add(new ShowDetailsAction(selRating.getRatingId()));

    menu.show(list, e.getX(), e.getY());
  }
Ejemplo n.º 17
0
  @Override
  protected JPopupMenu createPopup(Point p) {
    final List<Node> selectedElements = elementsDataTable.getElementsFromSelectedRows();
    final Node clickedElement = elementsDataTable.getElementFromRow(table.rowAtPoint(p));
    JPopupMenu contextMenu = new JPopupMenu();

    // First add edges manipulators items:
    DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    Integer lastManipulatorType = null;
    for (NodesManipulator em : dlh.getNodesManipulators()) {
      em.setup(selectedElements.toArray(new Node[0]), clickedElement);
      if (lastManipulatorType == null) {
        lastManipulatorType = em.getType();
      }
      if (lastManipulatorType != em.getType()) {
        contextMenu.addSeparator();
      }
      lastManipulatorType = em.getType();
      if (em.isAvailable()) {
        contextMenu.add(
            PopupMenuUtils.createMenuItemFromNodesManipulator(
                em, clickedElement, selectedElements.toArray(new Node[0])));
      }
    }

    // Add AttributeValues manipulators submenu:
    Column column = elementsDataTable.getColumnAtIndex(table.columnAtPoint(p));
    if (column != null) {
      contextMenu.add(PopupMenuUtils.createSubMenuFromRowColumn(clickedElement, column));
    }
    return contextMenu;
  }
Ejemplo n.º 18
0
  private void setContextOptions(GameOptions gameType) {
    JPopupMenu contextOptions = new JPopupMenu();

    JMenu addPieces = new JMenu(Resources.getString(Resources.ADD_PIECE));

    String[] pieces = gameType.getPieceList();
    for (int i = 0; i < pieces.length; i++) {
      JMenuItem newPieceName = new JMenuItem(pieces[i]);

      newPieceName.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              System.out.println(((JMenuItem) e.getSource()).getText());
            }
          });

      addPieces.add(newPieceName);
    }

    contextOptions.add(addPieces);

    contextOptions.add(new JMenuItem(Resources.getString(Resources.DELETE_PIECE)));

    this.setComponentPopupMenu(contextOptions);
  }
 public JPopupMenu mouseMenu() {
   JPopupMenu popup = new JPopupMenu();
   JMenuItem removeSelected = new JMenuItem("Remove Selected");
   popup.add(removeSelected);
   removeSelected.addMouseListener(
       new MouseAdapter() {
         public void mousePressed(MouseEvent e) {
           int row = table.getSelectedRow();
           UneditableTableModel model = (UneditableTableModel) table.getModel();
           if (model.getRowCount() > 1) {
             model.removeRow(row);
             model.fireTableDataChanged();
           } else {
             String columnNames[] = {
               "Id",
               "Name",
               "Supplier",
               "Category",
               "Price",
               "Discounted?",
               "Quantity",
               "Amount to Order"
             };
             Object[][] objects = new Object[0][8];
             UneditableTableModel mod = new UneditableTableModel(objects, columnNames);
             table = new JTable(mod);
             scrollPane.getViewport().add(table);
             scrollPane.repaint();
             table.setAutoCreateRowSorter(false);
           }
           passedList.remove(row);
         }
       });
   return popup;
 }
    /**
     * If the user has signalled the opening of a context menu, the event gets redirected to this
     * method. Here we open a file link menu if the user is pointing at a file link icon. Otherwise
     * a general context menu should be shown.
     *
     * @param e The triggering mouse event.
     */
    public void processPopupTrigger(MouseEvent e) {
      BibtexEntry entry = sortedEntries.get(entryTable.rowAtPoint(e.getPoint()));
      BasePanel p = entryHome.get(entry);
      int col = entryTable.columnAtPoint(e.getPoint());
      JPopupMenu menu = new JPopupMenu();
      int count = 0;

      if (col == FILE_COL) {
        // We use a FileListTableModel to parse the field content:
        Object o = entry.getField(GUIGlobals.FILE_FIELD);
        FileListTableModel fileList = new FileListTableModel();
        fileList.setContent((String) o);
        // If there are one or more links, open the first one:
        for (int i = 0; i < fileList.getRowCount(); i++) {
          FileListEntry flEntry = fileList.getEntry(i);
          String description = flEntry.getDescription();
          if ((description == null) || (description.trim().length() == 0))
            description = flEntry.getLink();
          menu.add(
              new ExternalFileMenuItem(
                  p.frame(),
                  entry,
                  description,
                  flEntry.getLink(),
                  flEntry.getType().getIcon(),
                  p.metaData(),
                  flEntry.getType()));
          count++;
        }
      }

      if (count > 0) menu.show(entryTable, e.getX(), e.getY());
    }
Ejemplo n.º 21
0
 private void mousePressedInIconsArea(MouseEvent e) {
   EditorMessageIconRenderer iconRenderer = getIconRendererUnderMouse(e);
   if (iconRenderer != null) {
     if (e.getButton() == MouseEvent.BUTTON3) {
       JPopupMenu popupMenu = iconRenderer.getPopupMenu();
       if (popupMenu != null && e.getID() == MouseEvent.MOUSE_PRESSED) {
         e.consume();
         Component component = e.getComponent();
         popupMenu.show(component == null ? myEditorComponent : component, e.getX(), e.getY());
       }
       return;
     }
     AnAction action = iconRenderer.getClickAction();
     if (e.getButton() == MouseEvent.BUTTON1 && action != null) {
       if (e.getID() == MouseEvent.MOUSE_CLICKED) {
         AnActionEvent actionEvent =
             new AnActionEvent(
                 e,
                 new LeftEditorHighlighterDataContext(myEditorComponent, iconRenderer.getNode()),
                 ICON_AREA,
                 action.getTemplatePresentation(),
                 ActionManager.getInstance(),
                 e.getModifiers());
         action.update(actionEvent);
         action.actionPerformed(actionEvent);
       }
       e.consume();
     }
   }
 }
Ejemplo n.º 22
0
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof JButton) {
      JButton b = (JButton) e.getSource();
      if (b == robotButton) {
        // show popup menu for selecting robots
        robotMenu.show(b, b.getWidth(), 0);
      } else {
        if (!typeMap.containsKey(b))
          // error?
          return;
        // retrieve the type of data selected
        retrieveType(typeMap.get(b));
      }
    } else if (e.getSource() instanceof JMenuItem) {
      JMenuItem m = (JMenuItem) e.getSource();
      if (!robotMap.containsKey(m))
        // error?
        return;
      // select the given robot for future data retrievals
      selectedRobot = robotMap.get(m);
      robotButton.setText(selectedRobot.name());
      robotMenu.setVisible(false);
    }
  }
Ejemplo n.º 23
0
  /** Adds a pop up menu. */
  private void addPopupMenu() {
    final JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_INDEX_MENU.get());
    menuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            newIndexClicked();
          }
        });
    popup.add(menuItem);
    menuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_NEW_VLV_INDEX_MENU.get());
    menuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            newVLVIndexClicked();
          }
        });
    popup.add(menuItem);
    popup.add(new JSeparator());
    deleteMenuItem = Utilities.createMenuItem(INFO_CTRL_PANEL_DELETE_INDEX_MENU.get());
    deleteMenuItem.addActionListener(
        new ActionListener() {
          /** {@inheritDoc} */
          public void actionPerformed(ActionEvent ev) {
            deleteClicked();
          }
        });
    popup.add(deleteMenuItem);
    deleteMenuItem.setEnabled(false);

    ((CustomTree) treePane.getTree()).setPopupMenu(popup);
  }
Ejemplo n.º 24
0
  protected JPopupMenu createPopUpMenu() {
    JPopupMenu menu = new JPopupMenu();
    JMenu saveMenu = new JMenu("Save As..");
    menu.add(saveMenu);

    JMenuItem item = new JMenuItem("PNG");
    item.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveImage("PNG");
          }
        });
    saveMenu.add(item);

    item = new JMenuItem("JPEG");
    item.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveImage("JPEG");
          }
        });
    saveMenu.add(item);

    JMenu[] menus = createMenus();
    if (menus != null) {
      for (int i = 0; i < menus.length; i++) {
        menu.add(menus[i]);
      }
    }

    return menu;
  }
    public void showContextMenu(final ContextMenuParams params) {
      final JPopupMenu popupMenu = new JPopupMenu();
      if (!params.getLinkText().isEmpty()) {
        popupMenu.add(
            createMenuItem(
                "Open link in new window",
                new Runnable() {
                  public void run() {
                    String linkURL = params.getLinkURL();
                    System.out.println("linkURL = " + linkURL);
                  }
                }));
      }

      final Browser browser = params.getBrowser();
      popupMenu.add(
          createMenuItem(
              "Reload",
              new Runnable() {
                public void run() {
                  browser.reload();
                }
              }));

      final Point location = params.getLocation();
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              popupMenu.show(component, location.x, location.y);
            }
          });
    }
Ejemplo n.º 26
0
  // If the user double clicks on a stock with the LMB, graph the stock.
  // If the user right clicks over the table, open up a popup menu.
  private void handleMouseClicked(MouseEvent event) {

    Point point = event.getPoint();

    // Right click on the table - raise menu
    if (event.getButton() == MouseEvent.BUTTON3) {
      JPopupMenu menu = new JPopupMenu();

      popupGraphSymbols = MenuHelper.addMenuItem(this, menu, Locale.getString("GRAPH"));
      popupGraphSymbols.setEnabled(getSelectedRowCount() > 0);

      popupTableSymbols = MenuHelper.addMenuItem(this, menu, Locale.getString("TABLE"));
      popupTableSymbols.setEnabled(getSelectedRowCount() > 0);

      menu.show(this, point.x, point.y);
    }

    // Left double click on the table - graph stock
    else if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) {
      int[] selectedRows = getSelectedRows();
      List symbols = new ArrayList();
      for (int i = 0; i < selectedRows.length; i++) {
        Symbol symbol = (Symbol) model.getValueAt(selectedRows[i], EODQuoteModel.SYMBOL_COLUMN);

        symbols.add(symbol);
      }

      // Graph the highlighted symbols
      CommandManager.getInstance().graphStockBySymbol(symbols);
    }
  }
Ejemplo n.º 27
0
  /** Shows popup with forward history entries */
  private void showForwardHistory(MouseEvent e) {

    JPopupMenu forwardMenu = new JPopupMenu("Forward History");

    if (historyModel == null) {
      return;
    }

    Locale locale = ((JHelp) getControl()).getModel().getHelpSet().getLocale();
    Enumeration items = historyModel.getForwardHistory().elements();
    JMenuItem mi = null;
    int index = historyModel.getIndex() + 1;
    // while(items.hasMoreElements()){
    for (int i = 0; items.hasMoreElements(); i++) {
      HelpModelEvent item = (HelpModelEvent) items.nextElement();
      if (item != null) {
        String title = item.getHistoryName();
        if (title == null) {
          title = HelpUtilities.getString(locale, "history.unknownTitle");
        }
        mi = new JMenuItem(title);
        // mi.setToolTipText(item.getURL().getPath());
        mi.addActionListener(new HistoryActionListener(i + index));
        forwardMenu.add(mi);
      }
    }
    // if(e.isPopupTrigger())
    forwardMenu.show(e.getComponent(), e.getX(), e.getY());
  }
Ejemplo n.º 28
0
    private void showJPopupMenu(MouseEvent e) {
      try {
        if (e.isPopupTrigger() && menu != null) {
          if (window == null) {

            if (isWindows) {
              window = new JDialog((Frame) null);
              ((JDialog) window).setUndecorated(true);
            } else {
              window = new JWindow((Frame) null);
            }
            window.setAlwaysOnTop(true);
            Dimension size = menu.getPreferredSize();

            Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
            if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height);
            else window.setLocation(e.getX(), e.getY());

            window.setVisible(true);

            menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);

            // popup works only for focused windows
            window.toFront();
          }
        }
      } catch (Exception ignored) {
      }
    }
 // todo: i hate the force enable, it destroys all the design...
 private static void registerPMenu(
     JPopupMenu mnu,
     final String id,
     final int index,
     final graphtea.platform.core.AbstractAction n,
     final boolean forceEnable) {
   JMenuItem item = new JMenuItem(id);
   mnu.add(item, index);
   mnu.validate();
   item.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           if (forceEnable) {
             //                    Configuration conf =
             // n.getBlackBoard().getData(UIEventHandler.CONF);
             //                    conf.enableAction(n);
             if (n.isEnable()) {
               n.performAction("popup menu: " + id, null);
             }
           } else {
             n.performAction("popup menu: " + id, null);
           }
         }
       });
 }
Ejemplo n.º 30
0
  /** Sets the visibility of the column with the specified name. */
  public void setColumnVisible(String name, boolean visible) {
    // Get column and set visibility.
    TableColumnExt column = getColumnExt(name);
    column.setVisible(visible);

    // Get column title.
    String columnTitle = column.getTitle();

    // Find checkbox menu item with matching title.
    JCheckBoxMenuItem matchingItem = null;
    int itemCount = headerPopup.getComponentCount();
    for (int i = 0; i < itemCount; i++) {
      Component menuComponent = headerPopup.getComponent(i);
      if (menuComponent instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuComponent;
        String itemTitle = item.getText();
        if (itemTitle.equals(columnTitle)) {
          matchingItem = item;
          break;
        }
      }
    }

    // Select matching menu item.
    if (matchingItem != null) {
      matchingItem.setSelected(visible);
    }
  }