Search in sources :

Example 51 with JPopupMenu

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

the class RosterTable method showTableHeaderPopup.

protected void showTableHeaderPopup(MouseEvent e) {
    JPopupMenu popupMenu = new JPopupMenu();
    for (int i = 0; i < columnModel.getColumnCount(false); i++) {
        TableColumn tc = columnModel.getColumnByModelIndex(i);
        JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(dataTable.getModel().getColumnName(i), columnModel.isColumnVisible(tc));
        menuItem.addActionListener(new headerActionListener(tc));
        popupMenu.add(menuItem);
    }
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 52 with JPopupMenu

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

the class ControlPanel method initGUI.

/**
     * Create, initialize and place GUI components.
     */
private void initGUI() {
    mainPanel = new JPanel();
    this.setContentPane(mainPanel);
    mainPanel.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    speedControlPanel = new JPanel();
    speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
    speedControlPanel.setOpaque(false);
    mainPanel.add(speedControlPanel, BorderLayout.CENTER);
    sliderPanel = new JPanel();
    sliderPanel.setLayout(new GridBagLayout());
    sliderPanel.setOpaque(false);
    speedSlider = new JSlider(0, intSpeedSteps);
    speedSlider.setOpaque(false);
    speedSlider.setValue(0);
    speedSlider.setFocusable(false);
    // add mouse-wheel support
    speedSlider.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
    speedSliderContinuous.setValue(0);
    speedSliderContinuous.setOpaque(false);
    speedSliderContinuous.setFocusable(false);
    // add mouse-wheel support
    speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSpinner = new JSpinner();
    speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
    speedSpinner.setModel(speedSpinnerModel);
    speedSpinner.setFocusable(false);
    SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
    SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
    SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
    SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
    forwardButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        forwardButton.setBorderPainted(false);
        forwardButton.setContentAreaFilled(false);
        forwardButton.setText(null);
        forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
        forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
        forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
    } else {
        forwardButton.setText(Bundle.getMessage("ButtonForward"));
    }
    reverseButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        reverseButton.setBorderPainted(false);
        reverseButton.setContentAreaFilled(false);
        reverseButton.setText(null);
        reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
        reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
        reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
    } else {
        reverseButton.setText(Bundle.getMessage("ButtonReverse"));
    }
    propertiesPopup = new JPopupMenu();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    Insets insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    sliderPanel.add(speedSlider, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(sliderPanel);
    speedSlider.setOrientation(JSlider.VERTICAL);
    speedSlider.setMajorTickSpacing(maxSpeed / 2);
    java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    speedSlider.setLabelTable(labelTable);
    speedSlider.setPaintTicks(true);
    speedSlider.setPaintLabels(true);
    // remove old actions
    speedSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSlider.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
                    }
                    if (sliderPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
                    }
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
                        }
                    }
                }
            }
        }
    });
    speedSliderContinuousPanel = new JPanel();
    speedSliderContinuousPanel.setLayout(new GridBagLayout());
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(speedSliderContinuousPanel);
    speedSliderContinuous.setOrientation(JSlider.VERTICAL);
    speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
    labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
    labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
    speedSliderContinuous.setLabelTable(labelTable);
    speedSliderContinuous.setPaintTicks(true);
    speedSliderContinuous.setPaintLabels(true);
    // remove old actions
    speedSliderContinuous.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSliderContinuous.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
                    boolean newDir = (speedSliderContinuous.getValue() >= 0);
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
                    }
                    if (speedSliderContinuousPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                        if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
                            throttle.setIsForward(newDir);
                        }
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                    if (speedSlider != null) {
                        speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                }
            }
        }
    });
    spinnerPanel = new JPanel();
    spinnerPanel.setLayout(new GridBagLayout());
    spinnerPanel.add(speedSpinner, constraints);
    speedControlPanel.add(spinnerPanel);
    // remove old actions
    speedSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                //if (!speedSpinner.getValueIsAdjusting())
                //{
                float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
                if (log.isDebugEnabled()) {
                    log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
                }
                if (throttle != null) {
                    if (spinnerPanel.isVisible()) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
                        }
                    }
                } else {
                    log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
                }
            //}
            }
        }
    });
    ButtonGroup speedStepButtons = new ButtonGroup();
    speedStepButtons.add(SpeedStep128Button);
    speedStepButtons.add(SpeedStep28Button);
    speedStepButtons.add(SpeedStep27Button);
    speedStepButtons.add(SpeedStep14Button);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    spinnerPanel.add(SpeedStep128Button, constraints);
    constraints.gridy = 2;
    spinnerPanel.add(SpeedStep28Button, constraints);
    constraints.gridy = 3;
    spinnerPanel.add(SpeedStep27Button, constraints);
    constraints.gridy = 4;
    spinnerPanel.add(SpeedStep14Button, constraints);
    SpeedStep14Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode14);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
        }
    });
    SpeedStep27Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode27);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
        }
    });
    SpeedStep28Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode28);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
        }
    });
    SpeedStep128Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode128);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
        }
    });
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    ButtonGroup directionButtons = new ButtonGroup();
    directionButtons.add(forwardButton);
    directionButtons.add(reverseButton);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 3;
    }
    buttonPanel.add(forwardButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 1;
    } else {
        constraints.gridy = 2;
    }
    buttonPanel.add(reverseButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 2;
    }
    forwardButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(true);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    reverseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(false);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    stopButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        stopButton.setBorderPainted(false);
        stopButton.setContentAreaFilled(false);
        stopButton.setText(null);
        stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
        stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
        stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
    } else {
        stopButton.setText(Bundle.getMessage("ButtonEStop"));
    }
    constraints.gridy = 4;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    buttonPanel.add(stopButton, constraints);
    stopButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
        }
    });
    stopButton.addMouseListener(new MouseListener() {

        @Override
        public void mousePressed(MouseEvent e) {
            stop();
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    idleButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        idleButton.setBorderPainted(false);
        idleButton.setContentAreaFilled(false);
        idleButton.setText(null);
        idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
        idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
        idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
    } else {
        idleButton.setText(Bundle.getMessage("ButtonIdle"));
    }
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridy = 1;
    } else {
        constraints.gridy = 3;
    }
    buttonPanel.add(idleButton, constraints);
    idleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            speedSlider.setValue(0);
            if (speedSpinner != null) {
                speedSpinner.setValue(Integer.valueOf(0));
            }
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(Integer.valueOf(0));
            }
            throttle.setSpeedSetting(0);
        }
    });
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            changeOrientation();
        }
    });
    JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
    propertiesItem.addActionListener(this);
    propertiesPopup.add(propertiesItem);
    // Add a mouse listener all components to trigger the popup menu.
    MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
    MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
    // Install the Key bindings on all Components
    KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
    // set by default which speed selection method is on top
    setSpeedController(_displaySlider);
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) MouseWheelListener(java.awt.event.MouseWheelListener) SpinnerNumberModel(javax.swing.SpinnerNumberModel) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) JMenuItem(javax.swing.JMenuItem) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) MouseWheelEvent(java.awt.event.MouseWheelEvent) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) JSpinner(javax.swing.JSpinner) ComponentEvent(java.awt.event.ComponentEvent) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 53 with JPopupMenu

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

the class PanelEditor method showPopUp.

/**
     * Create popup for a Positionable object Popup items common to all
     * positionable objects are done before and after the items that pertain
     * only to specific Positionable types.
     */
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
    if (!((JComponent) p).isVisible()) {
        // component must be showing on the screen to determine its location
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    PositionablePopupUtil util = p.getPopupUtility();
    if (p.isEditable()) {
        // items for all Positionables
        if (p.doViemMenu()) {
            popup.add(p.getNameString());
            setPositionableMenu(p, popup);
            if (p.isPositionable()) {
                setShowCoordinatesMenu(p, popup);
                setShowAlignmentMenu(p, popup);
            }
            setDisplayLevelMenu(p, popup);
            setHiddenMenu(p, popup);
            popup.addSeparator();
        }
        // Positionable items with defaults or using overrides
        boolean popupSet = false;
        popupSet |= p.setRotateOrthogonalMenu(popup);
        popupSet |= p.setRotateMenu(popup);
        popupSet |= p.setScaleMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setEditIconMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setTextEditMenu(popup);
        if (util != null) {
            util.setFixedTextMenu(popup);
            util.setTextMarginMenu(popup);
            util.setTextBorderMenu(popup);
            util.setTextFontMenu(popup);
            util.setBackgroundMenu(popup);
            util.setTextJustificationMenu(popup);
            util.setTextOrientationMenu(popup);
            util.copyItem(popup);
            popup.addSeparator();
            util.propertyUtil(popup);
            util.setAdditionalEditPopUpMenu(popup);
            popupSet = true;
        }
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        p.setDisableControlMenu(popup);
        // for Positionables with unique item settings
        p.showPopUp(popup);
        setRemoveMenu(p, popup);
    } else {
        p.showPopUp(popup);
        if (util != null) {
            util.setAdditionalViewPopUpMenu(popup);
        }
    }
    popup.show((Component) p, p.getWidth() / 2, p.getHeight() / 2);
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) JPopupMenu(javax.swing.JPopupMenu)

Example 54 with JPopupMenu

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

the class AbstractGravityTrackerTest method testRemoveComponent.

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

Example 55 with JPopupMenu

use of javax.swing.JPopupMenu in project processdash by dtuma.

the class TaskScheduleDialog method buildMainButtons.

protected Component buildMainButtons(boolean isRollup) {
    JPanel result = new JPanel(new BorderLayout());
    result.setBorder(BorderFactory.createRaisedBevelBorder());
    Box box = Box.createHorizontalBox();
    result.add(newVBox(Box.createVerticalStrut(2), box, Box.createVerticalStrut(2)), BorderLayout.CENTER);
    box.add(Box.createHorizontalGlue());
    JPopupMenu popupMenu = treeTable.getComponentPopupMenu();
    /*
        if (isRollup) {
            recalcButton = new JButton("Refresh");
            recalcButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    recalcAll(); }});
            box.add(recalcButton);
        }
        */
    errorAction = new TSAction("Buttons.Errors") {

        public void actionPerformed(ActionEvent e) {
            displayErrorDialog(getErrors());
        }
    };
    final JButton errorButton = new JButton(errorAction);
    errorButton.setBackground(Color.red);
    errorButton.setFocusPainted(false);
    errorAction.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            errorButton.setVisible(errorAction.isEnabled());
        }
    });
    errorAction.setEnabled(getErrors() != null);
    box.add(errorButton);
    box.add(Box.createHorizontalStrut(2));
    filteredChartAction = new TSAction("Buttons.Filtered_Chart") {

        public void actionPerformed(ActionEvent e) {
            showFilteredChart();
        }
    };
    filteredChartAction.setEnabled(false);
    addRenamedPopupMenuItem(popupMenu, filteredChartAction, "Buttons.View_Filtered_Chart");
    chartAction = new TSAction("Buttons.Chart") {

        public void actionPerformed(ActionEvent e) {
            showChart();
        }
    };
    box.add(makeDropDownButton(chartAction, filteredChartAction));
    box.add(Box.createHorizontalStrut(2));
    altReportActions = buildAltReportActions();
    weekReportAction = new TSAction("Buttons.Weekly_Report") {

        public void actionPerformed(ActionEvent e) {
            showWeekReport();
        }
    };
    filteredReportAction = new TSAction("Buttons.Filtered_Report") {

        public void actionPerformed(ActionEvent e) {
            showFilteredHTML();
        }
    };
    filteredReportAction.setEnabled(false);
    addRenamedPopupMenuItem(popupMenu, filteredReportAction, "Buttons.View_Filtered_Report");
    reportAction = new TSAction("Buttons.Report") {

        public void actionPerformed(ActionEvent e) {
            showHTML();
        }
    };
    box.add(makeDropDownButton(reportAction, weekReportAction, altReportActions, filteredReportAction));
    box.add(Box.createHorizontalStrut(2));
    closeAction = new TSAction("Close") {

        public void actionPerformed(ActionEvent e) {
            confirmClose(true);
        }
    };
    box.add(new JButton(closeAction));
    box.add(Box.createHorizontalStrut(2));
    saveAction = new TSAction("Save") {

        public void actionPerformed(ActionEvent e) {
            save();
        }
    };
    if (canEdit()) {
        box.add(new JButton(saveAction));
        box.add(Box.createHorizontalStrut(2));
    }
    Dimension size = result.getMinimumSize();
    size.width = 2000;
    result.setMaximumSize(size);
    return result;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) BorderLayout(java.awt.BorderLayout) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu)

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