Search in sources :

Example 56 with JPopupMenu

use of javax.swing.JPopupMenu in project cytoscape-api by cytoscape.

the class AbstractGravityTrackerTest method testAddMenu.

@Test
public void testAddMenu() {
    final JMenu menu1 = new JMenu();
    gravityTracker.addMenu(menu1, 10.0);
    final JMenu menu2 = new JMenu();
    gravityTracker.addMenu(menu2, 5.0);
    final Component someMenu = gravityTracker.getMenu();
    if (someMenu instanceof JMenu) {
        final JMenu menu = (JMenu) someMenu;
        assertEquals(menu2, menu.getMenuComponent(0));
        assertEquals(menu1, menu.getMenuComponent(1));
    } else {
        final JPopupMenu menu = (JPopupMenu) someMenu;
        assertEquals(menu2, menu.getComponent(0));
        assertEquals(menu1, menu.getComponent(1));
    }
}
Also used : Component(java.awt.Component) JMenu(javax.swing.JMenu) JPopupMenu(javax.swing.JPopupMenu) Test(org.junit.Test)

Example 57 with JPopupMenu

use of javax.swing.JPopupMenu in project cytoscape-api by cytoscape.

the class AbstractGravityTrackerTest method testAddMenuSeparator.

@Test
public void testAddMenuSeparator() {
    final JMenu menu1 = new JMenu();
    gravityTracker.addMenu(menu1, 10.0);
    final JMenu menu2 = new JMenu();
    gravityTracker.addMenu(menu2, 5.0);
    gravityTracker.addMenuSeparator(7.5);
    final Component someMenu = gravityTracker.getMenu();
    if (someMenu instanceof JMenu) {
        final JMenu menu = (JMenu) someMenu;
        assertEquals(menu2, menu.getMenuComponent(0));
        assertTrue(menu.getMenuComponent(1) instanceof JSeparator);
        assertEquals(menu1, menu.getMenuComponent(2));
    } else {
        final JPopupMenu menu = (JPopupMenu) someMenu;
        assertEquals(menu2, menu.getComponent(0));
        assertTrue(menu.getComponent(1) instanceof JSeparator);
        assertEquals(menu1, menu.getComponent(2));
    }
}
Also used : Component(java.awt.Component) JMenu(javax.swing.JMenu) JSeparator(javax.swing.JSeparator) JPopupMenu(javax.swing.JPopupMenu) Test(org.junit.Test)

Example 58 with JPopupMenu

use of javax.swing.JPopupMenu in project cytoscape-api by cytoscape.

the class JMenuTrackerTest method setUp.

@Before
public void setUp() {
    popup = new JPopupMenu("test");
    tracker = new JMenuTracker(popup);
    menuBar = new JMenuBar();
    menuBarTracker = new JMenuTracker(menuBar);
}
Also used : JPopupMenu(javax.swing.JPopupMenu) JMenuBar(javax.swing.JMenuBar) Before(org.junit.Before)

Example 59 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class TableFrames method showPopup.

void showPopup(MouseEvent me) {
    Point p = me.getPoint();
    int col = _oBlockTable.columnAtPoint(p);
    if (!me.isPopupTrigger() && !me.isMetaDown() && !me.isAltDown() && col == OBlockTableModel.STATECOL) {
        int row = _oBlockTable.rowAtPoint(p);
        String stateStr = (String) _oBlockModel.getValueAt(row, col);
        int state = Integer.parseInt(stateStr, 2);
        stateStr = OBlockTableModel.getValue(state);
        JPopupMenu popupMenu = new JPopupMenu();
        popupMenu.add(new JMenuItem(stateStr));
        popupMenu.show(_oBlockTable, me.getX(), me.getY());
    }
}
Also used : Point(java.awt.Point) JMenuItem(javax.swing.JMenuItem) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 60 with JPopupMenu

use of javax.swing.JPopupMenu in project JMRI by JMRI.

the class LayoutTurnout method showPopUp.

/**
     * Display popup menu for information and editing
     */
protected void showPopUp(MouseEvent e) {
    if (popup != null) {
        popup.removeAll();
    } else {
        popup = new JPopupMenu();
    }
    if (layoutEditor.isEditable()) {
        JMenuItem jmi = null;
        switch(getTurnoutType()) {
            case RH_TURNOUT:
                jmi = popup.add(Bundle.getMessage("RightTurnout"));
                break;
            case LH_TURNOUT:
                jmi = popup.add(Bundle.getMessage("LeftTurnout"));
                break;
            case WYE_TURNOUT:
                jmi = popup.add(rb.getString("WYETurnout"));
                break;
            case DOUBLE_XOVER:
                jmi = popup.add(rb.getString("DoubleCrossOver"));
                break;
            case RH_XOVER:
                jmi = popup.add(Bundle.getMessage("RightCrossOver"));
                break;
            case LH_XOVER:
                jmi = popup.add(Bundle.getMessage("LeftCrossOver"));
                break;
            default:
                break;
        }
        jmi.setEnabled(false);
        jmi = popup.add(ident);
        jmi.setEnabled(false);
        if (getTurnout() == null) {
            jmi = popup.add(rb.getString("NoTurnout"));
        } else {
            jmi = popup.add(Bundle.getMessage("BeanNameTurnout") + ": " + turnoutName);
        }
        jmi.setEnabled(false);
        if (blockName.equals("")) {
            jmi = popup.add(rb.getString("NoBlock"));
        } else {
            jmi = popup.add(Bundle.getMessage("BeanNameBlock") + ": " + getLayoutBlock().getID());
        }
        jmi.setEnabled(false);
        if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
            // check if extra blocks have been entered
            if (blockB != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 2) + ": " + blockBName);
                jmi.setEnabled(false);
            }
            if (blockC != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 3) + ": " + blockCName);
                jmi.setEnabled(false);
            }
            if (blockD != null) {
                jmi = popup.add(Bundle.getMessage("Block_ID", 4) + ": " + blockDName);
                jmi.setEnabled(false);
            }
        }
        if (hidden) {
            jmi = popup.add(rb.getString("Hidden"));
        } else {
            jmi = popup.add(rb.getString("NotHidden"));
        }
        jmi.setEnabled(false);
        popup.add(new JSeparator(JSeparator.HORIZONTAL));
        // Rotate if there are no track connections
        if ((connectA == null) && (connectB == null) && (connectC == null) && (connectD == null)) {
            JMenuItem rotateItem = new JMenuItem(rb.getString("Rotate") + "...");
            popup.add(rotateItem);
            rotateItem.addActionListener((ActionEvent event) -> {
                boolean entering = true;
                boolean error = false;
                String newAngle = "";
                while (entering) {
                    // prompt for rotation angle
                    error = false;
                    newAngle = JOptionPane.showInputDialog(layoutEditor, rb.getString("EnterRotation") + " :");
                    if (newAngle.length() < 1) {
                        // cancelled
                        return;
                    }
                    double rot = 0.0;
                    try {
                        rot = Double.parseDouble(newAngle);
                    } catch (Exception e1) {
                        JOptionPane.showMessageDialog(layoutEditor, rb.getString("Error3") + " " + e1, Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
                        error = true;
                        newAngle = "";
                    }
                    if (!error) {
                        entering = false;
                        if (rot != 0.0) {
                            rotateCoords(rot);
                            layoutEditor.redrawPanel();
                        }
                    }
                }
            });
        }
        if (disableItem == null) {
            disableItem = new JCheckBoxMenuItem(Bundle.getMessage("Disabled"));
        }
        disableItem.setSelected(disabled);
        popup.add(disableItem);
        disableItem.addActionListener((java.awt.event.ActionEvent e2) -> {
            disabled = disableItem.isSelected();
        });
        if (disableWhenOccupiedItem == null) {
            disableWhenOccupiedItem = new JCheckBoxMenuItem(rb.getString("DisabledWhenOccupied"));
        }
        disableWhenOccupiedItem.setSelected(disableWhenOccupied);
        popup.add(disableWhenOccupiedItem);
        disableWhenOccupiedItem.addActionListener((java.awt.event.ActionEvent e3) -> {
            disableWhenOccupied = disableWhenOccupiedItem.isSelected();
        });
        popup.add(new AbstractAction(rb.getString("UseSizeAsDefault")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                setUpDefaultSize();
            }
        });
        popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                editLayoutTurnout();
            }
        });
        popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (layoutEditor.removeLayoutTurnout(instance)) {
                    // Returned true if user did not cancel
                    remove();
                    dispose();
                }
            }
        });
        if (getTurnout() != null) {
            popup.add(new AbstractAction(rb.getString("SetSignals")) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (tools == null) {
                        tools = new LayoutEditorTools(layoutEditor);
                    }
                    if ((getTurnoutType() == DOUBLE_XOVER) || (getTurnoutType() == RH_XOVER) || (getTurnoutType() == LH_XOVER)) {
                        tools.setSignalsAtXoverTurnoutFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == NO_LINK) {
                        tools.setSignalsAtTurnoutFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == THROAT_TO_THROAT) {
                        tools.setThroatToThroatFromMenu(instance, linkedTurnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == FIRST_3_WAY) {
                        tools.set3WayFromMenu(turnoutName, linkedTurnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    } else if (linkType == SECOND_3_WAY) {
                        tools.set3WayFromMenu(linkedTurnoutName, turnoutName, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
                    }
                }
            });
        }
        if (!blockName.equals("")) {
            final String[] boundaryBetween = getBlockBoundaries();
            boolean blockBoundaries = false;
            for (int i = 0; i < 4; i++) {
                if (boundaryBetween[i] != null) {
                    blockBoundaries = true;
                }
            }
            if (InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled()) {
                if (blockBName.equals("") && blockCName.equals("") && blockDName.equals("")) {
                    popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlock());
                            routeTableAction.actionPerformed(e);
                        }
                    });
                } else {
                    JMenu viewRouting = new JMenu(rb.getString("ViewBlockRouting"));
                    viewRouting.add(new AbstractAction(blockName) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockName, getLayoutBlock());
                            routeTableAction.actionPerformed(e);
                        }
                    });
                    if (!blockBName.equals("") && !blockBName.equals(blockName)) {
                        viewRouting.add(new AbstractAction(blockBName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockBName, getLayoutBlockB());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    if (!blockCName.equals("") && !blockCName.equals(blockName) && !blockCName.equals(blockBName)) {
                        viewRouting.add(new AbstractAction(blockCName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockCName, getLayoutBlockC());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    if (!blockDName.equals("") && !blockDName.equals(blockName) && !blockDName.equals(blockBName) && !blockDName.equals(blockCName)) {
                        viewRouting.add(new AbstractAction(blockDName) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockDName, getLayoutBlockD());
                                routeTableAction.actionPerformed(e);
                            }
                        });
                    }
                    popup.add(viewRouting);
                }
            }
            if (blockBoundaries) {
                popup.add(new AbstractAction(rb.getString("SetSignalMasts")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (tools == null) {
                            tools = new LayoutEditorTools(layoutEditor);
                        }
                        tools.setSignalMastsAtTurnoutFromMenu(instance, boundaryBetween);
                    }
                });
                popup.add(new AbstractAction(rb.getString("SetSensors")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (tools == null) {
                            tools = new LayoutEditorTools(layoutEditor);
                        }
                        tools.setSensorsAtTurnoutFromMenu(instance, boundaryBetween, layoutEditor.sensorIconEditor, layoutEditor.sensorFrame);
                    }
                });
            }
        }
        setAdditionalEditPopUpMenu(popup);
        layoutEditor.setShowAlignmentMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    } else if (!viewAdditionalMenu.isEmpty()) {
        setAdditionalViewPopUpMenu(popup);
        popup.show(e.getComponent(), e.getX(), e.getY());
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) LayoutBlockRouteTableAction(jmri.jmrit.display.layoutEditor.blockRoutingTable.LayoutBlockRouteTableAction) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)203 JMenuItem (javax.swing.JMenuItem)105 ActionEvent (java.awt.event.ActionEvent)61 ActionListener (java.awt.event.ActionListener)46 JMenu (javax.swing.JMenu)28 Point (java.awt.Point)24 Component (java.awt.Component)20 JLabel (javax.swing.JLabel)20 JSeparator (javax.swing.JSeparator)19 JScrollPane (javax.swing.JScrollPane)18 MouseEvent (java.awt.event.MouseEvent)17 JButton (javax.swing.JButton)16 AbstractAction (javax.swing.AbstractAction)15 BorderLayout (java.awt.BorderLayout)13 JPanel (javax.swing.JPanel)13 JTable (javax.swing.JTable)13 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)12 MouseAdapter (java.awt.event.MouseAdapter)11 ArrayList (java.util.ArrayList)11 Icon (javax.swing.Icon)11