Example usage for javax.swing JPopupMenu getHeight

List of usage examples for javax.swing JPopupMenu getHeight

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java

/**
 * Creates the listener responsible for calling the correct handlers based
 * on mouse events, and to select invidual cells.
 *///from  w  w  w .ja v a  2s  .  com
protected MouseListener createMouseListener() {

    return new MouseHandler() {

        /**
         * Invoked when a mouse button has been pressed on a component.
         *
         //@Override
         public void mousePressed(MouseEvent e) {
                
         Object o = graph.getFirstCellForLocation(e.getX(), e.getY());
                
         if (o instanceof VGraphCell) {
                
         VGraphCell cell = (VGraphCell) o;
                
         JPopupMenu menu = new JPopupMenu();
                
         VChartPanel chartPanel = (VChartPanel) cell.getUserObject();
                
         if (chartPanel.isShowPopUp()) {
                
         LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
         JMenu first = new JMenu("1-39");
         int checker = 0;
                
         for (Iterator iter = collect.iterator(); iter.hasNext();) {
         LegendItem item = (LegendItem) iter.next();
         checker++;
         first.add(new JMenuItem(item.getLabel()));
         if ((checker % 40) == 0) {
         menu.add(first);
                
         first = new JMenu("" + checker + "-" + (checker + 39));
         }
         if (!iter.hasNext()) {
         menu.add(first);
         }
         }
                
         menu.show(graph, e.getX(), e.getY());
         }
         }
                
         super.mousePressed(e);
         }
         */

        /**
         * Invoked when a mouse button has been pressed on a component.
         */
        @Override
        public void mousePressed(MouseEvent e) {

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) {
                if (o instanceof VGraphCell) {

                    VGraphCell cell = (VGraphCell) o;

                    JPopupMenu menu = new JPopupMenu();

                    VChartPanel chartPanel = (VChartPanel) cell.getUserObject();

                    LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
                    JMenu first = new JMenu("1-39");
                    int checker = 0;

                    for (Iterator iter = collect.iterator(); iter.hasNext();) {
                        LegendItem item = (LegendItem) iter.next();
                        checker++;
                        first.add(new JMenuItem(item.getLabel()));
                        if ((checker % 40) == 0) {
                            menu.add(first);

                            first = new JMenu("" + checker + "-" + (checker + 39));
                        }
                        if (!iter.hasNext()) {
                            menu.add(first);
                        }
                    }

                    menu.show(graph, e.getX(), e.getY());
                }
            }

            super.mousePressed(e);

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mousePressed(e);
                    }
                }
            }
        }

        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mouseReleased(e);
                    }
                }
            }
        }

        /**
         * Invoked when the mouse has been clicked on a component.
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    if (SwingUtilities.isRightMouseButton(e)) {
                        JPopupMenu menu = chart.createPopupMenu(true, true, true, true);

                        menu.show(graph, e.getX(), e.getY());
                    }

                    /*
                    for (MouseListener l : chart.getMouseListeners()) {
                    System.out.println("LISTENS CLI");
                    l.mouseClicked(e);
                    }
                    */
                }
            }
        }

        /*
        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
        super.mouseReleased(e);
                
        Object[] cells = graphSelectionModel.getSelectionCells();
                
        Rectangle2D bounds = graph.getCellBounds(cells);
                
        if (bounds != null) {
            Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone());
            graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight()));
        }
        }
        */

        /**
         * Invoked when the mouse pointer has been moved on a component (with no
         * buttons down).
         */
        @Override
        public void mouseMoved(MouseEvent e) {

            if (graph.isMoveable()) {
                super.mouseMoved(e);
            }

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                selectedCell = (VGraphCell) o;

                Rectangle2D bounds = graph.getCellBounds(selectedCell);

                menu.show(graph, (int) (bounds.getX() + bounds.getWidth()),
                        (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight()));
            }
        }
    };
}

From source file:picocash.components.mode.buttons.ModeButton.java

private void init() {
    setLayout(new MigLayout("fill"));
    add(iconLabel);/*from www .  ja  v a  2 s  .co  m*/
    add(nameLabel, "push");
    add(minimizeLabel);

    minimizeLabel.setIcon(PicocashIcons.getSystemIcon("minimize-dark"));

    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            JPopupMenu popupMenu = new JPopupMenu();
            fillPopupMenu(popupMenu);
            Dimension dimension = getSize();
            popupMenu.setSize(dimension.width, popupMenu.getHeight());
            popupMenu.show((Component) arg0.getSource(), -1, dimension.height + 3);
        }
    });
}