Search in sources :

Example 1 with MouseListener

use of java.awt.event.MouseListener in project buck by facebook.

the class BuckToolWindowFactory method createBuildInfoPanel.

private JComponent createBuildInfoPanel(Project project) {
    Tree result = new Tree(BuckUIManager.getInstance(project).getTreeModel());
    result.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Tree tree = (Tree) e.getComponent();
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
            if (selRow != -1 && e.getClickCount() == 2) {
                TreeNode node = (TreeNode) selPath.getLastPathComponent();
                if (node.isLeaf()) {
                    BuckTreeNodeDetail buckNode = (BuckTreeNodeDetail) node;
                    if (buckNode instanceof BuckTreeNodeDetailError) {
                        BuckToolWindowFactory.this.handleClickOnError((BuckTreeNodeDetailError) buckNode);
                    }
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    result.setCellRenderer(new BuckTreeCellRenderer());
    result.setShowsRootHandles(false);
    result.setRowHeight(0);
    JBScrollPane treeView = new JBScrollPane(result);
    return treeView;
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) Tree(com.intellij.ui.treeStructure.Tree) BuckTreeNodeDetailError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeDetailError) BuckTreeCellRenderer(com.facebook.buck.intellij.ideabuck.ui.tree.renderers.BuckTreeCellRenderer) JBScrollPane(com.intellij.ui.components.JBScrollPane) BuckTreeNodeDetail(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeDetail)

Example 2 with MouseListener

use of java.awt.event.MouseListener in project silk by jbee.

the class TestMockingBinds method moreSpecificUpperBoundTypesAreMorePrecise.

@Test
public void moreSpecificUpperBoundTypesAreMorePrecise() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    MouseListener mock = injector.resolve(dependency(MouseListener.class));
    assertTrue(isProxyClass(mock.getClass()));
    assertEquals(EventListener.class.getCanonicalName(), mock.toString());
}
Also used : MouseListener(java.awt.event.MouseListener) Injector(se.jbee.inject.Injector) EventListener(java.util.EventListener) Test(org.junit.Test)

Example 3 with MouseListener

use of java.awt.event.MouseListener in project languagetool by languagetool-org.

the class LanguageToolSupport method init.

private void init() {
    try {
        config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null);
    } catch (IOException ex) {
        throw new RuntimeException("Could not load configuration", ex);
    }
    Language defaultLanguage = config.getLanguage();
    if (defaultLanguage == null) {
        defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault());
    }
    /**
     * Warm-up: we have a lot of lazy init in LT, which causes the first check to
     * be very slow (several seconds) for languages with a lot of data and a lot of
     * rules. We just assume that the default language is the language that the user
     * often uses and init the LT object for that now, not just when it's first used.
     * This makes the first check feel much faster:
     */
    reloadLanguageTool(defaultLanguage);
    checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            t.setPriority(Thread.MIN_PRIORITY);
            t.setName(t.getName() + "-lt-background");
            return t;
        }
    });
    check = new AtomicInteger(0);
    this.textComponent.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), false);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), true);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }
    });
    mouseListener = new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent me) {
        }

        @Override
        public void mousePressed(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    };
    this.textComponent.addMouseListener(mouseListener);
    actionListener = e -> _actionPerformed(e);
    mustDetectLanguage = config.getAutoDetect();
    if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) {
        checkImmediately(null);
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) MouseEvent(java.awt.event.MouseEvent) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) IOException(java.io.IOException) MouseListener(java.awt.event.MouseListener) Language(org.languagetool.Language) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Example 4 with MouseListener

use of java.awt.event.MouseListener 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 5 with MouseListener

use of java.awt.event.MouseListener in project intellij-community by JetBrains.

the class PaletteItemsComponent method updateUI.

@Override
public void updateUI() {
    setUI(new BasicListUI() {

        MouseListener myListener;

        @Override
        protected void updateLayoutState() {
            super.updateLayoutState();
            Insets insets = list.getInsets();
            int listWidth = list.getWidth() - (insets.left + insets.right);
            if (listWidth >= cellWidth) {
                int columnCount = listWidth / cellWidth;
                cellWidth = (columnCount == 0) ? 1 : listWidth / columnCount;
            }
        }

        @Override
        protected void installListeners() {
            addMouseListener(myListener = new MouseAdapter() {

                @Override
                public void mousePressed(MouseEvent e) {
                    myBeforeClickSelectedRow = list.getSelectedIndex();
                }
            });
            super.installListeners();
        }

        @Override
        protected void uninstallListeners() {
            if (myListener != null) {
                removeMouseListener(myListener);
            }
            super.uninstallListeners();
        }
    });
    invalidate();
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) BasicListUI(javax.swing.plaf.basic.BasicListUI)

Aggregations

MouseListener (java.awt.event.MouseListener)104 MouseEvent (java.awt.event.MouseEvent)67 Dimension (java.awt.Dimension)21 JLabel (javax.swing.JLabel)20 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 Component (java.awt.Component)14 JComponent (javax.swing.JComponent)14 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)11 MouseMotionListener (java.awt.event.MouseMotionListener)11 JButton (javax.swing.JButton)11 JScrollPane (javax.swing.JScrollPane)11 Insets (java.awt.Insets)8 BorderLayout (java.awt.BorderLayout)7 Color (java.awt.Color)7 Point (java.awt.Point)7 File (java.io.File)7 ImageIcon (javax.swing.ImageIcon)6 JCheckBox (javax.swing.JCheckBox)6