Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

In this page you can find the example usage for javax.swing JPopupMenu JPopupMenu.

Prototype

public JPopupMenu() 

Source Link

Document

Constructs a JPopupMenu without an "invoker".

Usage

From source file:net.sf.xmm.moviemanager.gui.DialogIMDbMultiAdd.java

/**
 * Not yet fully implemented//from  w w w. j ava  2 s.c  om
 * @param e
 */
void handleFileLocationPopup(MouseEvent e) {

    if (!GUIUtil.isRightMouseButton(e))
        return;

    JPopupMenu fileLocationPopup = new JPopupMenu();
    JMenuItem fileLocationItem = new JMenuItem("Open content folder");
    fileLocationPopup.add(fileLocationItem);

    fileLocationPopup.show(fileLocation, e.getX(), e.getY());
}

From source file:gui.DownloadPanel.java

private JPopupMenu initPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();

    openItem = new JMenuItem(bundle.getString("downloadPanel.openItem.name"));
    openItem.addActionListener(this);
    openFolderItem = new JMenuItem(bundle.getString("downloadPanel.openFolderItem.name"));
    openFolderItem.addActionListener(this);

    resumeItem = new JMenuItem(bundle.getString("downloadPanel.resumeItem.name"));
    resumeItem.addActionListener(this);
    pauseItem = new JMenuItem(bundle.getString("downloadPanel.pauseItem.name"));
    pauseItem.addActionListener(this);
    clearItem = new JMenuItem(bundle.getString("downloadPanel.clearItem.name"));
    clearItem.addActionListener(this);

    reJoinItem = new JMenuItem(bundle.getString("downloadPanel.reJoinItem.name"));
    reJoinItem.addActionListener(this);
    reDownloadItem = new JMenuItem(bundle.getString("downloadPanel.reDownloadItem.name"));
    reDownloadItem.addActionListener(this);

    moveToQueueItem = new JMenuItem(bundle.getString("downloadPanel.moveToQueueItem.name"));
    moveToQueueItem.addActionListener(this);
    removeFromQueueItem = new JMenuItem(bundle.getString("downloadPanel.removeFromQueueItem.name"));
    removeFromQueueItem.addActionListener(this);

    propertiesItem = new JMenuItem(bundle.getString("downloadPanel.propertiesItem.name"));
    propertiesItem.addActionListener(this);

    popupMenu.add(openItem);/*ww w.j  ava 2s  .c  o  m*/
    popupMenu.add(openFolderItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(resumeItem);
    popupMenu.add(pauseItem);
    popupMenu.add(clearItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(reJoinItem);
    popupMenu.add(reDownloadItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(moveToQueueItem);
    popupMenu.add(removeFromQueueItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(propertiesItem);

    setStateOfMenuItems();

    return popupMenu;
}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initAuthorsTable() {
    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/*from  w w  w .  j a v a2s.com*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel selectionModel = authorsTable.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
            if (source.getMinSelectionIndex() >= 0) {
                authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex());
            }

            if (!e.getValueIsAdjusting()) {
                booksTableModel.setAuthorIndex(source.getMinSelectionIndex());
            }

        }
    });

    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    JPopupMenu authorsPopupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");

    authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = authorsTable.rowAtPoint(
                            SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable));
                    if (rowAtPoint > -1) {
                        authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                        authorsTableModel.setCurrentSlectedIndex(rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteItem.addActionListener(new ActionListener() {
        private Author author;

        @Override
        public void actionPerformed(ActionEvent e) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow());
                    log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname()
                            + " from database.");
                    authorManager.deleteAuthor(author);

                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (InterruptedException | ExecutionException e) {
                        if (e.getCause() instanceof DataIntegrityViolationException) {
                            JOptionPane.showMessageDialog(MainWindow.this,
                                    "Couldn't delete author; there are still some books assigned to him.",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                        log.error("There was an exception thrown during deletion author: "
                                + author.getFirstname() + " " + author.getSurname(), e);

                        return;
                    }

                    updateModel();
                }
            }.execute();
        }
    });
    authorsPopupMenu.add(deleteItem);
    authorsTable.setComponentPopupMenu(authorsPopupMenu);
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 *
 *//*from   ww w.  jav a  2  s.  com*/
private void createComponents() {

    // creat popup menus
    {

        popupMenu = new JPopupMenu();
        removeMenuItem = new JMenuItem(I18N
                .getGUILabel("plotter.configuration_dialog.color_scheme_dialog.remove_color_menu_item.label"));
        removeMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                removeSelectedColorAction();
            }

        });
        popupMenu.add(removeMenuItem);

        changeColorMenuItem = new JMenuItem(I18N
                .getGUILabel("plotter.configuration_dialog.color_scheme_dialog.change_color_menu_item.label"));
        changeColorMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                replaceSelectedColorAction();
            }

        });
        popupMenu.add(changeColorMenuItem);

        popupMenu.addSeparator();

        moveUpColorMenuItem = new JMenuItem(
                I18N.getGUILabel("plotter.configuration_dialog.color_scheme_dialog.move_up_menu_item.label"));
        moveUpColorMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                moveSelectedColorUpAction();

            }

        });
        popupMenu.add(moveUpColorMenuItem);

        moveDownColorMenuItem = new JMenuItem(
                I18N.getGUILabel("plotter.configuration_dialog.color_scheme_dialog.move_down_menu_item.label"));
        moveDownColorMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                moveSelectedColorDownAction();
            }

        });
        popupMenu.add(moveDownColorMenuItem);

    }

    JPanel containerPanel = new JPanel(new GridBagLayout());
    containerPanel.setPreferredSize(new Dimension(520, 450));

    // create containing panel
    {

        {
            JPanel configurePanel = new JPanel(new GridBagLayout());
            configurePanel.setPreferredSize(new Dimension(220, 400));
            configurePanel.setBorder(BorderFactory.createTitledBorder(I18N.getGUILabel(
                    "plotter.configuration_dialog.color_scheme_dialog.scheme_configuration_border.label")));

            // add scheme list panel
            {
                JPanel schemeComboBoxPanel = createSchemeComboBoxPanel();

                // add category choosing panel
                GridBagConstraints itemConstraint = new GridBagConstraints();
                itemConstraint.fill = GridBagConstraints.BOTH;
                itemConstraint.weightx = 1;
                itemConstraint.weighty = 1;
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.insets = new Insets(2, 2, 2, 5);

                configurePanel.add(schemeComboBoxPanel, itemConstraint);
            }

            {
                categoryAndGradientConfigPanel = new JPanel(new GridBagLayout());

                // add categories panel
                {
                    JPanel categoryConfigurationPanel = createColorCategoriesPanel();

                    // add category choosing panel
                    GridBagConstraints itemConstraint = new GridBagConstraints();
                    itemConstraint.fill = GridBagConstraints.BOTH;
                    itemConstraint.weightx = 1;
                    itemConstraint.weighty = 1;
                    itemConstraint.insets = new Insets(2, 2, 2, 5);
                    itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

                    categoryAndGradientConfigPanel.add(categoryConfigurationPanel, itemConstraint);

                }

                // add gradient chooser panel
                {
                    JPanel gradientConfigPanel = createGradientConfigurationPanel();

                    GridBagConstraints itemConstraint = new GridBagConstraints();
                    itemConstraint.fill = GridBagConstraints.BOTH;
                    itemConstraint.weightx = 1;
                    itemConstraint.weighty = 1;
                    itemConstraint.insets = new Insets(2, 2, 2, 5);
                    itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

                    categoryAndGradientConfigPanel.add(gradientConfigPanel, itemConstraint);
                }

                GridBagConstraints itemConstraint = new GridBagConstraints();
                itemConstraint.fill = GridBagConstraints.BOTH;
                itemConstraint.weightx = 1;
                itemConstraint.weighty = 1;
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.insets = new Insets(2, 2, 2, 5);

                configurePanel.add(categoryAndGradientConfigPanel, itemConstraint);

            }

            GridBagConstraints itemConstraint = new GridBagConstraints();
            itemConstraint.fill = GridBagConstraints.BOTH;
            itemConstraint.weightx = 1;
            itemConstraint.weighty = 1;
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
            containerPanel.add(configurePanel, itemConstraint);
        }

        createPlotPreviewPanel(containerPanel);

    }

    // create buttons
    Collection<AbstractButton> buttons = new LinkedList<AbstractButton>();
    buttons.add(makeOkButton());

    Action saveAction = new ResourceAction("plotter.configuration_dialog.color_scheme_dialog.save_button") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            save(currentColorSchemes, currentActiveColorSchemeName);

            // set new scheme
            plotConfig.setColorSchemes(currentColorSchemes, currentActiveColorSchemeName);
        }
    };
    saveButton = new JButton(saveAction);
    buttons.add(saveButton);
    saveButton.setEnabled(false);

    Action revertAction = new ResourceAction("plotter.configuration_dialog.color_scheme_dialog.revert_button") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            revert();
        }
    };
    revertButton = new JButton(revertAction);
    revertButton.setEnabled(false);
    buttons.add(revertButton);
    buttons.add(makeCancelButton("plotter.configuration_dialog.color_scheme_dialog.cancel_button"));

    layoutDefault(containerPanel, buttons);
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

public CodeTemplatePanel(Frame parent) {
    this.parent = parent;
    setLayout(new MigLayout("insets 0, novisualpadding, hidemode 3, fill"));
    setBackground(UIConstants.BACKGROUND_COLOR);
    initComponents();/*from   w ww . j a  v  a  2  s . c o  m*/
    initToolTips();
    initLayout();

    codeTemplateTasks = new JXTaskPane();
    codeTemplateTasks.setTitle("Code Template Tasks");
    codeTemplateTasks.setName(TaskConstants.CODE_TEMPLATE_KEY);
    codeTemplateTasks.setFocusable(false);

    codeTemplatePopupMenu = new JPopupMenu();
    templateTreeTableScrollPane.setComponentPopupMenu(codeTemplatePopupMenu);

    parent.addTask(TaskConstants.CODE_TEMPLATE_REFRESH, "Refresh", "Refresh the list of code templates.", "",
            new ImageIcon(Frame.class.getResource("images/arrow_refresh.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_SAVE, "Save Changes",
            "Save all changes made to all libraries and code templates.", "",
            new ImageIcon(Frame.class.getResource("images/disk.png")), codeTemplateTasks, codeTemplatePopupMenu,
            this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_NEW, "New Code Template", "Create a new code template.", "N",
            new ImageIcon(Frame.class.getResource("images/add.png")), codeTemplateTasks, codeTemplatePopupMenu,
            this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_LIBRARY_NEW, "New Library",
            "Create a new code template library.", "", new ImageIcon(Frame.class.getResource("images/add.png")),
            codeTemplateTasks, codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_IMPORT, "Import Code Templates",
            "Import list of code templates from an XML file.", "",
            new ImageIcon(Frame.class.getResource("images/report_go.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_LIBRARY_IMPORT, "Import Libraries",
            "Import list of code template libraries from an XML file.", "",
            new ImageIcon(Frame.class.getResource("images/report_go.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_EXPORT, "Export Code Template",
            "Export the selected code template to an XML file.", "",
            new ImageIcon(Frame.class.getResource("images/report_disk.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_LIBRARY_EXPORT, "Export Library",
            "Export the selected code template library to an XML file.", "",
            new ImageIcon(Frame.class.getResource("images/report_disk.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_LIBRARY_EXPORT_ALL, "Export All Libraries",
            "Export all libraries to XML files.", "",
            new ImageIcon(Frame.class.getResource("images/report_disk.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_DELETE, "Delete Code Template",
            "Delete the currently selected code template.", "L",
            new ImageIcon(Frame.class.getResource("images/delete.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_LIBRARY_DELETE, "Delete Library",
            "Delete the currently selected code template library.", "",
            new ImageIcon(Frame.class.getResource("images/delete.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);
    parent.addTask(TaskConstants.CODE_TEMPLATE_VALIDATE, "Validate Script",
            "Validate the currently viewed script.", "",
            new ImageIcon(Frame.class.getResource("images/accept.png")), codeTemplateTasks,
            codeTemplatePopupMenu, this);

    parent.setNonFocusable(codeTemplateTasks);
    parent.taskPaneContainer.add(codeTemplateTasks, parent.taskPaneContainer.getComponentCount() - 1);

    setTaskVisible(TASK_CODE_TEMPLATE_REFRESH);
    setTaskVisible(TASK_CODE_TEMPLATE_NEW);
    setTaskVisible(TASK_CODE_TEMPLATE_IMPORT);
    setTaskVisible(TASK_CODE_TEMPLATE_LIBRARY_NEW);
    setTaskVisible(TASK_CODE_TEMPLATE_LIBRARY_IMPORT);
    setTaskVisible(TASK_CODE_TEMPLATE_LIBRARY_EXPORT_ALL);

    setTaskInvisible(TASK_CODE_TEMPLATE_SAVE);
    setTaskInvisible(TASK_CODE_TEMPLATE_EXPORT);
    setTaskInvisible(TASK_CODE_TEMPLATE_LIBRARY_EXPORT);
    setTaskInvisible(TASK_CODE_TEMPLATE_DELETE);
    setTaskInvisible(TASK_CODE_TEMPLATE_LIBRARY_DELETE);
    setTaskInvisible(TASK_CODE_TEMPLATE_VALIDATE);
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java

/**
 * @param txtComp/* www  .  j a v  a 2s. c o  m*/
 */
private void addPopupMenu(final JTextComponent txtComp) {
    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem mi = new JMenuItem(UIRegistry.getResourceString("DELETE"));
    popupMenu.add(mi);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PickListItemIFace pli = (PickListItemIFace) comboBox.getSelectedItem();
            if (pli != null) {
                PickListIFace pl = adapter.getPickList();
                pl.removeItem(pli);
            }
        }
    });
}

From source file:net.panthema.BispanningGame.GamePanel.java

public GamePanel() throws IOException {

    makeActions();/*w  ww . j av  a2  s .  c o m*/

    setBackground(Color.WHITE);

    ImageAlice = ImageIO.read(
            getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Alice.png"));
    ImageBob = ImageIO.read(
            getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Bob.png"));

    logTextArea = new JTextArea();

    makeNewRandomGraph(8);
    mLayout = MyGraphLayoutFactory(mGraph);

    mVV = new VisualizationViewer<Integer, MyEdge>(mLayout);
    mVV.setSize(new Dimension(1000, 800));
    mVV.setBackground(Color.WHITE);

    // Bob's play does not repeat.
    mPlayBob.setRepeats(false);

    // set up mouse handling
    PluggableGraphMouse gm = new PluggableGraphMouse();
    gm.add(new MyEditingGraphMousePlugin<Integer, MyEdge>(MouseEvent.CTRL_MASK, new MyVertexFactory(),
            new MyEdgeFactory()));
    gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK));
    gm.add(new MyGraphMousePlugin(MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON3_MASK));
    gm.add(new PickingGraphMousePlugin<Integer, MyEdge>());
    gm.add(new ScalingGraphMousePlugin(new LayoutScalingControl(), 0, 1.1f, 0.9f));
    mVV.setGraphMouse(gm);

    // set vertex and label drawing
    mVV.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.black));
    mVV.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return "v" + v;
        }
    });
    mVV.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    mVV.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    mVV.getRenderer().setEdgeRenderer(new MyEdgeRenderer());
    mVV.getRenderContext().setVertexDrawPaintTransformer(new MyVertexDrawPaintTransformer<Integer>());
    mVV.getRenderContext().setVertexFillPaintTransformer(new MyVertexFillPaintTransformer());

    mVV.getRenderContext().setEdgeStrokeTransformer(new MyEdgeStrokeTransformer());
    MyQuadCurve<Integer, MyEdge> quadcurve = new MyQuadCurve<Integer, MyEdge>();
    mVV.getRenderContext().setEdgeShapeTransformer(quadcurve);
    mVV.getRenderContext().setParallelEdgeIndexFunction(quadcurve);

    mVV.getRenderContext().setEdgeDrawPaintTransformer(new MyEdgeDrawPaintTransformer());
    mVV.getRenderContext().setEdgeFillPaintTransformer(new MyEdgeFillPaintTransformer());
    mVV.getRenderContext().setEdgeArrowStrokeTransformer(new MyEdgeInnerStrokeTransformer());

    mVV.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.black));
    mVV.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() {
        public String transform(MyEdge e) {
            return e.toString();
        }
    });
    mVV.getRenderContext().setLabelOffset(6);

    // create pick support to select closest nodes and edges
    mPickSupport = new ShapePickSupport<Integer, MyEdge>(mVV, mPickDistance);

    // add pre renderer to draw Alice and Bob
    mVV.addPreRenderPaintable(new MyGraphPreRenderer());

    // add post renderer to show error messages in background
    mVV.addPostRenderPaintable(new MyGraphPostRenderer());

    setLayout(new BorderLayout());
    add(mVV, BorderLayout.CENTER);

    JPanel panelSouth = new JPanel();
    add(panelSouth, BorderLayout.SOUTH);
    panelSouth.setLayout(new GridLayout(0, 2, 0, 0));

    JPanel panelButtons = new JPanel();
    panelSouth.add(panelButtons);
    panelButtons.setLayout(new GridLayout(2, 2, 0, 0));
    panelSouth.setPreferredSize(new Dimension(800, 60));

    final JButton btnNewRandomGraph = new JButton("New Random Graph");
    btnNewRandomGraph.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            for (int i = 0; i < actionRandomGraph.length; ++i) {
                if (actionRandomGraph[i] != null)
                    popup.add(actionRandomGraph[i]);
            }
            popup.addSeparator();
            popup.add(getActionNewGraphType());

            popup.show(btnNewRandomGraph, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnNewRandomGraph);

    final JButton btnNewNamedGraph = new JButton("New Named Graph");
    btnNewNamedGraph.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            for (int i = 0; i < actionNamedGraph.size(); ++i) {
                if (actionNamedGraph.get(i) != null)
                    popup.add(actionNamedGraph.get(i));
            }

            popup.show(btnNewNamedGraph, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnNewNamedGraph);

    final JButton btnRelayout = new JButton("Relayout");
    btnRelayout.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            relayoutGraph();
        }
    });
    panelButtons.add(btnRelayout);

    final JButton btnOptions = new JButton("Options");
    btnOptions.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            addPopupActions(popup);
            popup.addSeparator();

            popup.show(btnOptions, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnOptions);

    JScrollPane scrollPane = new JScrollPane(logTextArea);
    panelSouth.add(scrollPane);

    logTextArea.setEditable(false);

    setSize(new Dimension(1000, 800));
    relayoutGraph();
}

From source file:com.clough.android.adbv.view.UpdateTableDialog.java

private void showTableChangeOptionMenu(int x, int y, final int rowIndex) {
    JPopupMenu tableChangeOptionPopupMenu = new JPopupMenu();
    JMenuItem newRowMenuItem = new JMenuItem("Add row");
    newRowMenuItem.addActionListener(new ActionListener() {

        @Override/*  w  ww  .  j a v  a2  s.c  o  m*/
        public void actionPerformed(ActionEvent e) {
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, null, -1).setVisible(true);
        }
    });
    JMenuItem updateRowMenuItem = new JMenuItem("Update row");
    updateRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object[] row = new Object[columnNames.length];
            for (int columnIndex = 0; columnIndex < row.length; columnIndex++) {
                row[columnIndex] = defaultTableModel.getValueAt(rowIndex, columnIndex);
            }
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, row, rowIndex)
                    .setVisible(true);
            tableColumnAdjuster.adjustColumns();
        }
    });
    JMenuItem removeRowMenuItem = new JMenuItem("Remove row");
    removeRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this row?", "Remove row",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                defaultTableModel.removeRow(rowIndex);
                rowController.removeRow(rowIndex);
                tableColumnAdjuster.adjustColumns();
            }
        }
    });
    tableChangeOptionPopupMenu.add(newRowMenuItem);
    tableChangeOptionPopupMenu.add(updateRowMenuItem);
    tableChangeOptionPopupMenu.add(removeRowMenuItem);
    tableChangeOptionPopupMenu.show(this, x, y);
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

public MainForm(final String fileToOpen) {
    Log.info("Start in editor mode");

    this.application = null;
    this.hexLayerList = null;

    initComponents();//w  w  w . ja v a  2s.c om

    final JFrame theFrame = this;

    for (final javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        final JMenuItem landfItem = new JMenuItem(info.getName());
        landfItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                } catch (Exception ex) {
                    Log.error("Can't change L&F", ex);
                }
                SwingUtilities.updateComponentTreeUI(theFrame);
            }
        });
        menuLANDF.add(landfItem);
    }

    popupMenu = new JPopupMenu();
    final JMenuItem comments = new JMenuItem("Comments");
    comments.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // open dialog for cell comment
            final CellCommentDialog commentDialog = new CellCommentDialog(theFrame,
                    "Commentaries for the cell at " + popupHex.getColumn() + "," + popupHex.getRow(),
                    cellComments.getForHex(popupHex));
            commentDialog.setVisible(true);
            final String result = commentDialog.getResult();
            if (result != null) {
                cellComments.setForHex(popupHex, result);
            }
        }
    });
    popupMenu.add(comments);

    hexMapPanelDesktop = new Desktop();
    layers = new LayerListModel(256, 128);

    try {
        this.setIconImage(ImageIO.read(this.getClass().getClassLoader()
                .getResource("com/igormaznitsa/jhexed/swing/editor/icons/logo.png")));
    } catch (Exception ex) {
        Log.error("Can't load app icon", ex);
    }

    hexMapPanel = new HexMapPanel(this.layers);
    hexMapPanel.addHexMapPanelListener(this);

    hexMapPanel.addMouseListener(this);
    hexMapPanel.addMouseMotionListener(this);
    hexMapPanel.addMouseWheelListener(this);

    this.panelMainArea.add(hexMapPanelDesktop, BorderLayout.CENTER);

    this.frameLayers = new FrameLayers(layers, hexMapPanel);
    this.frameTools = new FrameTools();
    this.frameToolOptions = new FrameToolOptions();

    hexMapPanelDesktop.addFrame(this.frameLayers);
    hexMapPanelDesktop.addFrame(this.frameTools);
    hexMapPanelDesktop.addFrame(this.frameToolOptions);

    this.frameLayers.setVisible(true);
    this.frameTools.setVisible(true);
    this.frameToolOptions.setVisible(true);

    hexMapPanelDesktop.setContentPane(hexMapPanel);

    this.dsl = new GroovyPluginBase(this, this.layers);
    this.compilerConfiguration = new CompilerConfiguration();
    this.compilerConfiguration.setScriptBaseClass(DelegatingScript.class.getName());
    this.groovyShell = new GroovyShell(this.compilerConfiguration);

    InsideApplicationBus.getInstance().addAppBusListener(this);

    loadSettings();

    resetState();

    Log.info("The MainForm created");

    registerInternalPlugins();
    registerExternalPlugins(".");

    if (fileToOpen != null) {
        Log.info("Started with parameter: " + fileToOpen);
        final File file = new File(fileToOpen);
        loadFromFile(file);
    }

    this.lookupContainer = new ObjectLookup(this, this.hexMapPanel.getHexEngine(), this,
            Log.makeApplicationLog());
    this.applicationGraphics = null;
}

From source file:com.net2plan.gui.tools.GUINetworkDesign.java

@Override
public void configure(JPanel contentPane) {
    this.currentNetPlan = new NetPlan();

    BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>();
    Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>();
    for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) {
        mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size());
        layerVisibilityMap.put(layer, true);
    }/*w w  w  .  j  a  v a 2  s . co  m*/
    this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap,
            MAXSIZEUNDOLISTPICK);

    topologyPanel = new TopologyPanel(this, JUNGCanvas.class);

    JPanel leftPane = new JPanel(new BorderLayout());
    JPanel logSection = configureLeftBottomPanel();
    if (logSection == null) {
        leftPane.add(topologyPanel, BorderLayout.CENTER);
    } else {
        JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneTopology.setTopComponent(topologyPanel);
        splitPaneTopology.setBottomComponent(logSection);
        splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener());
        splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground()));
        splitPaneTopology.setOneTouchExpandable(true);
        splitPaneTopology.setDividerSize(7);
        leftPane.add(splitPaneTopology, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, "grow");

    viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout());

    reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT);

    setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan);
    Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState
            .generateCanvasDefaultVisualizationLayerInfo(getDesign());
    vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond());

    /* Initialize the undo/redo manager, and set its initial design */
    this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES);
    this.undoRedoManager.addNetPlanChange();

    onlineSimulationPane = new OnlineSimulationPane(this);
    executionPane = new OfflineExecutionPanel(this);
    whatIfAnalysisPane = new WhatIfAnalysisPane(this);

    // Closing windows
    WindowUtils.clearFloatingWindows();

    final JTabbedPane tabPane = new JTabbedPane();
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network),
            viewEditTopTables);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online),
            onlineSimulationPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif),
            whatIfAnalysisPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane);

    // Installing customized mouse listener
    MouseListener[] ml = tabPane.getListeners(MouseListener.class);

    for (int i = 0; i < ml.length; i++) {
        tabPane.removeMouseListener(ml[i]);
    }

    // Left click works as usual, right click brings up a pop-up menu.
    tabPane.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JTabbedPane tabPane = (JTabbedPane) e.getSource();

            int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY());

            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
                if (tabIndex == tabPane.getSelectedIndex()) {
                    if (tabPane.isRequestFocusEnabled()) {
                        tabPane.requestFocus();

                        tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex));
                    }
                } else {
                    tabPane.setSelectedIndex(tabIndex);
                }

                if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) {
                    final JPopupMenu popupMenu = new JPopupMenu();

                    final JMenuItem popWindow = new JMenuItem("Pop window out");
                    popWindow.addActionListener(e1 -> {
                        final int selectedIndex = tabPane.getSelectedIndex();
                        final String tabName = tabPane.getTitleAt(selectedIndex);
                        final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent();

                        // Pops up the selected tab.
                        final WindowController.WindowToTab windowToTab = WindowController.WindowToTab
                                .parseString(tabName);

                        if (windowToTab != null) {
                            switch (windowToTab) {
                            case offline:
                                WindowController.buildOfflineWindow(selectedComponent);
                                WindowController.showOfflineWindow(true);
                                break;
                            case online:
                                WindowController.buildOnlineWindow(selectedComponent);
                                WindowController.showOnlineWindow(true);
                                break;
                            case whatif:
                                WindowController.buildWhatifWindow(selectedComponent);
                                WindowController.showWhatifWindow(true);
                                break;
                            case report:
                                WindowController.buildReportWindow(selectedComponent);
                                WindowController.showReportWindow(true);
                                break;
                            default:
                                return;
                            }
                        }

                        tabPane.setSelectedIndex(0);
                    });

                    // Disabling the pop up button for the network state tab.
                    if (WindowController.WindowToTab.parseString(tabPane
                            .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) {
                        popWindow.setEnabled(false);
                    }

                    popupMenu.add(popWindow);

                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    // Building windows
    WindowController.buildTableControlWindow(tabPane);
    WindowController.showTablesWindow(false);

    addAllKeyCombinationActions();
    updateVisualizationAfterNewTopology();
}