Search in sources :

Example 1 with JPopupMenu

use of javax.swing.JPopupMenu in project jna by java-native-access.

the class ShapedWindowDemo method main.

public static void main(String[] args) {
    try {
        System.setProperty("sun.java2d.noddraw", "true");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    final JFrame frame = new JFrame("Shaped Window Demo");
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        private void showPopup(MouseEvent e) {
            final JPopupMenu m = new JPopupMenu();
            m.add(new AbstractAction("Hide") {

                public void actionPerformed(ActionEvent e) {
                    frame.setState(JFrame.ICONIFIED);
                }

                private static final long serialVersionUID = 1L;
            });
            m.add(new AbstractAction("Close") {

                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }

                private static final long serialVersionUID = 1L;
            });
            m.pack();
            m.show(e.getComponent(), e.getX(), e.getY());
        }

        public void mousePressed(MouseEvent e) {
            offset = e.getPoint();
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        public void mouseDragged(MouseEvent e) {
            if (!SwingUtilities.isLeftMouseButton(e))
                return;
            Point where = e.getPoint();
            where.translate(-offset.x, -offset.y);
            Point loc = frame.getLocationOnScreen();
            loc.translate(where.x, where.y);
            frame.setLocation(loc.x, loc.y);
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }
    };
    frame.addMouseListener(handler);
    frame.addMouseMotionListener(handler);
    ClockFace face = new ClockFace(new Dimension(150, 150));
    frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    frame.getContentPane().add(face);
    frame.setUndecorated(true);
    try {
        Shape mask = new Area(new Ellipse2D.Float(0, 0, 150, 150));
        WindowUtils.setWindowMask(frame, mask);
        if (WindowUtils.isWindowAlphaSupported()) {
            WindowUtils.setWindowAlpha(frame, .7f);
        }
        frame.setIconImage(face.getIconImage());
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocation(100, 100);
        frame.setVisible(true);
    } catch (UnsatisfiedLinkError e) {
        e.printStackTrace();
        String msg = e.getMessage() + "\nError loading the JNA library";
        JTextArea area = new JTextArea(msg);
        area.setOpaque(false);
        area.setFont(UIManager.getFont("Label.font"));
        area.setEditable(false);
        area.setColumns(80);
        area.setRows(8);
        area.setWrapStyleWord(true);
        area.setLineWrap(true);
        JOptionPane.showMessageDialog(frame, new JScrollPane(area), "Library Load Error: " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) Shape(java.awt.Shape) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) Point(java.awt.Point) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) Ellipse2D(java.awt.geom.Ellipse2D) Area(java.awt.geom.Area) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) AbstractAction(javax.swing.AbstractAction) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 2 with JPopupMenu

use of javax.swing.JPopupMenu in project ACS by ACS-Community.

the class SmartTextPane method getPopup.

/**
	 * Insert the method's description here.
	 * Creation date: (18.2.2002 17:58:02)
	 * @return javax.swing.JPopupMenu
	 */
public javax.swing.JPopupMenu getPopup() {
    if (popup == null) {
        popup = new JPopupMenu("Smart text pane");
        JMenuItem saveItem = new JMenuItem("Save");
        saveItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {
                saveTextToFile();
            }
        });
        popup.add(saveItem);
    }
    return popup;
}
Also used : JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 3 with JPopupMenu

use of javax.swing.JPopupMenu in project ACS by ACS-Community.

the class ConnectionWidget method initialize.

/**
	 * Init the GUI
	 */
private void initialize() {
    popMenu = new JPopupMenu();
    reconnectMI = new JMenuItem("Reconnect");
    popMenu.add(reconnectMI);
    reconnectMI.addActionListener(this);
}
Also used : JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with JPopupMenu

use of javax.swing.JPopupMenu in project ACS by ACS-Community.

the class ErrorTreeCellRenderer method getNewNodePopupMenu.

/**
	 * This method initializes jPopupMenu	
	 * 	
	 * @return javax.swing.JPopupMenu	
	 */
private JPopupMenu getNewNodePopupMenu() {
    if (newNodePopupMenu == null) {
        newNodePopupMenu = new JPopupMenu();
        newNodePopupMenu.add(getNewErrorMenuItem());
        newNodePopupMenu.add(getNewCompletionMenuItem());
    }
    return newNodePopupMenu;
}
Also used : JPopupMenu(javax.swing.JPopupMenu)

Example 5 with JPopupMenu

use of javax.swing.JPopupMenu in project ACS by ACS-Community.

the class ErrorTreeCellRenderer method getAddPopupMenu.

/**
	 * This method initializes jPopupMenu	
	 * 	
	 * @return javax.swing.JPopupMenu	
	 */
private JPopupMenu getAddPopupMenu() {
    if (addPopupMenu == null) {
        addPopupMenu = new JPopupMenu();
        addPopupMenu.add(getAddFileItem());
        addPopupMenu.add(getAddDirectoryItem());
        addPopupMenu.add(getAddDefaultsItem());
    }
    return addPopupMenu;
}
Also used : JPopupMenu(javax.swing.JPopupMenu)

Aggregations

JPopupMenu (javax.swing.JPopupMenu)437 JMenuItem (javax.swing.JMenuItem)223 ActionEvent (java.awt.event.ActionEvent)150 ActionListener (java.awt.event.ActionListener)99 JMenu (javax.swing.JMenu)66 MouseEvent (java.awt.event.MouseEvent)64 Point (java.awt.Point)57 AbstractAction (javax.swing.AbstractAction)52 Component (java.awt.Component)51 MouseAdapter (java.awt.event.MouseAdapter)47 JScrollPane (javax.swing.JScrollPane)42 JLabel (javax.swing.JLabel)36 ArrayList (java.util.ArrayList)35 JButton (javax.swing.JButton)35 JPanel (javax.swing.JPanel)35 BorderLayout (java.awt.BorderLayout)34 JSeparator (javax.swing.JSeparator)31 Dimension (java.awt.Dimension)28 Action (javax.swing.Action)28 JComponent (javax.swing.JComponent)28