Search in sources :

Example 1 with MouseAdapter

use of java.awt.event.MouseAdapter in project jna by java-native-access.

the class BalloonManagerDemo method main.

public static void main(String[] args) {
    try {
        System.setProperty("sun.java2d.noddraw", "true");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    JFrame f = new JFrame("Balloon Test");
    final String BALLOON_TEXT = "<html><center>" + "This is some sample balloon text<br>" + "which has been formatted with html.<br>" + "Click to dismiss.</center></html>";
    final JLabel content = new JLabel(BALLOON_TEXT);
    content.setIconTextGap(10);
    content.setBorder(new EmptyBorder(0, 8, 0, 8));
    content.setSize(content.getPreferredSize());
    content.setIcon(new InfoIcon());
    JLabel label = new JLabel("Click anywhere for more information");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.addMouseListener(new MouseAdapter() {

        private MouseListener listener = new MouseAdapter() {

            public void mousePressed(MouseEvent e) {
                hidePopup(e);
            }
        };

        private Popup popup;

        private void hidePopup(MouseEvent e) {
            e.getComponent().removeMouseListener(listener);
            if (popup != null)
                popup.hide();
        }

        public void mousePressed(MouseEvent e) {
            hidePopup(e);
            popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
            popup.show();
            content.getParent().addMouseListener(listener);
        }
    });
    f.getContentPane().add(label);
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.setLocation(100, 100);
    try {
        // Force a load of JNA
        WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } 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(null, 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) JTextArea(javax.swing.JTextArea) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MouseListener(java.awt.event.MouseListener) JFrame(javax.swing.JFrame) Popup(javax.swing.Popup) EmptyBorder(javax.swing.border.EmptyBorder)

Example 2 with MouseAdapter

use of java.awt.event.MouseAdapter in project groovy by apache.

the class TableSorter method addMouseListenerToHeaderInTable.

// There is no-where else to put this.
// Add a mouse listener to the Table to trigger a table sort
// when a column heading is clicked in the JTable.
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                if (lastSortedColumn == column)
                    ascending = !ascending;
                sorter.sortByColumn(column, ascending);
                lastSortedColumn = column;
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) TableColumnModel(javax.swing.table.TableColumnModel) JTableHeader(javax.swing.table.JTableHeader)

Example 3 with MouseAdapter

use of java.awt.event.MouseAdapter in project neo4j by neo4j.

the class MainWindow method createStatusPanel.

private JPanel createStatusPanel(CardLayout statusPanelLayout) {
    JPanel panel = withLayout(statusPanelLayout, withTitledBorder("Status", createPanel()));
    for (DatabaseStatus status : DatabaseStatus.values()) {
        panel.add(status.name(), status.display(model));
    }
    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (MouseEvent.BUTTON1 == e.getButton() && e.isAltDown()) {
                debugWindow.show();
            }
        }
    });
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 4 with MouseAdapter

use of java.awt.event.MouseAdapter in project neo4j by neo4j.

the class SysTray method setupTrayIcon.

private void setupTrayIcon() {
    PopupMenu popUpMenu = createPopupMenu();
    trayIcon.setPopupMenu(popUpMenu);
    trayIcon.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            listener.open();
        }
    });
    trayIcon.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            listener.open();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 5 with MouseAdapter

use of java.awt.event.MouseAdapter in project ACS by ACS-Community.

the class LoggingClient method getStatusLinePnl.

/**
	 * Returns the panel for the status line
	 * 
	 * @return the panel for the status line
	 */
private JPanel getStatusLinePnl() {
    if (statusLinePnl == null) {
        try {
            // Load the icons for the status of the connection
            connectionStatusIcons = new ImageIcon[5];
            connectionStatusIcons[CONNECTED_ICON] = new ImageIcon(this.getClass().getResource("/console-connected.png"));
            connectionStatusIcons[CONNECTING_ICON] = new ImageIcon(this.getClass().getResource("/console-connecting.png"));
            connectionStatusIcons[DISCONNECTED_ICON] = new ImageIcon(this.getClass().getResource("/console-disconnected.png"));
            connectionStatusIcons[SUSPENDED_ICON] = new ImageIcon(this.getClass().getResource("/console-suspended.png"));
            connectionStatusIcons[DELAY_ICON] = new ImageIcon(this.getClass().getResource("/console-delay.png"));
            connectionStatusLbl = new JLabel(connectionStatusIcons[CONNECTING_ICON]);
            // Create a label to show the status of the connection with the DB
            connectionDBLbl = new JLabel();
            statusLinePnl = new javax.swing.JPanel();
            statusLinePnl.setName("Status_line");
            statusLinePnl.setLayout(new java.awt.GridBagLayout());
            GridBagConstraints constraintsProgressBar = new GridBagConstraints();
            constraintsProgressBar.gridx = 0;
            constraintsProgressBar.gridy = 0;
            constraintsProgressBar.fill = GridBagConstraints.BOTH;
            constraintsProgressBar.anchor = GridBagConstraints.WEST;
            constraintsProgressBar.weightx = 1.0;
            constraintsProgressBar.insets = new Insets(1, 2, 1, 1);
            statusLinePnl.add(progressBar, constraintsProgressBar);
            GridBagConstraints constraintsNumFlt = new GridBagConstraints();
            constraintsNumFlt.gridx = 1;
            constraintsNumFlt.gridy = 0;
            constraintsNumFlt.insets = new Insets(1, 1, 1, 1);
            maxNumOfLogsLbl.setVisible(true);
            maxNumOfLogsLbl.setBorder(BorderFactory.createLoweredBevelBorder());
            Font fntNumFlt = maxNumOfLogsLbl.getFont();
            Font newFontNumFlt = fntNumFlt.deriveFont(fntNumFlt.getSize() - 2);
            maxNumOfLogsLbl.setFont(newFontNumFlt);
            statusLinePnl.add(maxNumOfLogsLbl, constraintsNumFlt);
            GridBagConstraints constraintsEngineFlt = new GridBagConstraints();
            constraintsEngineFlt.gridx = 2;
            constraintsEngineFlt.gridy = 0;
            constraintsEngineFlt.insets = new Insets(1, 1, 1, 1);
            engineFiltersLbl.setVisible(true);
            engineFiltersLbl.setBorder(BorderFactory.createLoweredBevelBorder());
            Font fntEngineFlt = engineFiltersLbl.getFont();
            Font newFontEngineFlt = fntEngineFlt.deriveFont(fntEngineFlt.getSize() - 2);
            engineFiltersLbl.setFont(newFontEngineFlt);
            statusLinePnl.add(engineFiltersLbl, constraintsEngineFlt);
            GridBagConstraints constraintsTableFlt = new GridBagConstraints();
            constraintsTableFlt.gridx = 3;
            constraintsTableFlt.gridy = 0;
            constraintsTableFlt.insets = new Insets(1, 1, 1, 1);
            tableFiltersLbl.setVisible(true);
            tableFiltersLbl.setBorder(BorderFactory.createLoweredBevelBorder());
            Font fntTableFlt = tableFiltersLbl.getFont();
            Font newFontTableFlt = fntTableFlt.deriveFont(fntTableFlt.getSize() - 2);
            tableFiltersLbl.setFont(newFontTableFlt);
            statusLinePnl.add(tableFiltersLbl, constraintsTableFlt);
            GridBagConstraints constraintsAudience = new GridBagConstraints();
            constraintsAudience.gridx = 4;
            constraintsAudience.gridy = 0;
            constraintsAudience.insets = new Insets(1, 1, 1, 1);
            audienceLbl.setVisible(true);
            audienceLbl.setBorder(BorderFactory.createLoweredBevelBorder());
            Font fnt = audienceLbl.getFont();
            Font newFont = fnt.deriveFont(fnt.getSize() - 2);
            audienceLbl.setFont(newFont);
            statusLinePnl.add(audienceLbl, constraintsAudience);
            GridBagConstraints constraintsConnectionDBStatus = new GridBagConstraints();
            constraintsConnectionDBStatus.gridx = 5;
            constraintsConnectionDBStatus.gridy = 0;
            constraintsConnectionDBStatus.insets = new Insets(1, 2, 1, 2);
            statusLinePnl.add(connectionDBLbl, constraintsConnectionDBStatus);
            GridBagConstraints constraintsJlogErrors = new GridBagConstraints();
            constraintsConnectionDBStatus.gridx = 6;
            constraintsConnectionDBStatus.gridy = 0;
            constraintsConnectionDBStatus.insets = new Insets(1, 2, 1, 2);
            statusLinePnl.add(jlogErrorLbl, constraintsJlogErrors);
            jlogErrorLbl.setVisible(false);
            jlogErrorLbl.setToolTipText("Error reading logs");
            jlogErrorLbl.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    jlogErrorLbl.setVisible(false);
                    errorDialog.setVisible(true, LoggingClient.this);
                    super.mouseClicked(e);
                }
            });
            GridBagConstraints constraintsConnectionStatus = new GridBagConstraints();
            constraintsConnectionStatus.gridx = 7;
            constraintsConnectionStatus.gridy = 0;
            constraintsConnectionStatus.insets = new Insets(1, 2, 1, 2);
            statusLinePnl.add(connectionStatusLbl, constraintsConnectionStatus);
        } catch (java.lang.Throwable ivjExc) {
            handleException(ivjExc);
        }
    }
    return statusLinePnl;
}
Also used : ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Font(java.awt.Font) JPanel(javax.swing.JPanel)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)599 MouseEvent (java.awt.event.MouseEvent)590 Dimension (java.awt.Dimension)149 JPanel (javax.swing.JPanel)134 JLabel (javax.swing.JLabel)132 ActionEvent (java.awt.event.ActionEvent)124 Point (java.awt.Point)101 BorderLayout (java.awt.BorderLayout)96 ActionListener (java.awt.event.ActionListener)93 JButton (javax.swing.JButton)90 JScrollPane (javax.swing.JScrollPane)81 ChangeEvent (javax.swing.event.ChangeEvent)77 ChangeListener (javax.swing.event.ChangeListener)75 Insets (java.awt.Insets)60 JSlider (javax.swing.JSlider)60 KeyEvent (java.awt.event.KeyEvent)59 KeyAdapter (java.awt.event.KeyAdapter)52 GridBagConstraints (java.awt.GridBagConstraints)48 ImageIcon (javax.swing.ImageIcon)45 JPopupMenu (javax.swing.JPopupMenu)44