Search in sources :

Example 11 with MouseInputAdapter

use of javax.swing.event.MouseInputAdapter in project jbehave-core by jbehave.

the class JFrameContextView method initialize.

protected void initialize() {
    frame = new JFrame();
    label = new JLabel();
    frame.setAlwaysOnTop(true);
    frame.setSize(width, height);
    frame.setLocation(x, y);
    frame.setUndecorated(true);
    JPanel panel = new JPanel();
    frame.setContentPane(panel);
    panel.setLayout(new BorderLayout());
    label.setBorder(new EmptyBorder(3, 3, 3, 3));
    panel.add(label, BorderLayout.CENTER);
    MouseInputAdapter mia = new MouseInputAdapter() {

        private Point mousePressedScreenCoords;

        private Point mousePressedCompCoords;

        public void mouseReleased(MouseEvent e) {
            mousePressedScreenCoords = null;
            mousePressedCompCoords = null;
        }

        public void mousePressed(MouseEvent e) {
            mousePressedScreenCoords = e.getLocationOnScreen();
            mousePressedCompCoords = e.getPoint();
        }

        public void mouseDragged(MouseEvent e) {
            Point currCoords = e.getLocationOnScreen();
            x = mousePressedScreenCoords.x + (currCoords.x - mousePressedScreenCoords.x) - mousePressedCompCoords.x;
            y = mousePressedScreenCoords.y + (currCoords.y - mousePressedScreenCoords.y) - mousePressedCompCoords.y;
            frame.setLocation(x, y);
        }
    };
    frame.addMouseListener(mia);
    frame.addMouseMotionListener(mia);
    frame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JLabel(javax.swing.JLabel) Point(java.awt.Point) EmptyBorder(javax.swing.border.EmptyBorder) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 12 with MouseInputAdapter

use of javax.swing.event.MouseInputAdapter in project CoreNLP by stanfordnlp.

the class DisplayMatchesPanel method addMatch.

/**
 * Adds the given tree to the display without removing already
 * displayed trees
 * @param match tree to be added
 */
private void addMatch(TreeFromFile match, List<Tree> matchedParts) {
    JPanel treeDisplay = new JPanel(new BorderLayout());
    JTextField filename = new JTextField("From file: " + match.getFilename());
    filename.setEditable(false);
    MouseInputAdapter listener = new FilenameMouseInputAdapter(filename);
    filename.addMouseListener(listener);
    filename.addMouseMotionListener(listener);
    treeDisplay.add(filename, BorderLayout.NORTH);
    if (TregexGUI.getInstance().isTdiffEnabled()) {
        tjp = getTreeJPanel(match.getDiffDecoratedTree(), matchedParts);
        tjp.setDiffConstituents(match.getDiffConstituents());
    } else {
        tjp = getTreeJPanel(match.getTree(), matchedParts);
    }
    matchedPartCoordinates = tjp.getMatchedPartCoordinates();
    matchedPartCoordinateIdx = -1;
    treeDisplay.add(tjp, BorderLayout.CENTER);
    filename.setOpaque(true);
    filename.setBackground(tjp.getBackground());
    filename.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    scroller.setViewportView(treeDisplay);
    this.revalidate();
    this.repaint();
}
Also used : BorderLayout(java.awt.BorderLayout) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 13 with MouseInputAdapter

use of javax.swing.event.MouseInputAdapter in project java-swing-tips by aterai.

the class DesktopLayerUI method createFrame2.

private static JInternalFrame createFrame2() {
    JInternalFrame f = new JInternalFrame("WindowsInternalFrameUI", true, true, true, true) {

        @Override
        public void updateUI() {
            super.updateUI();
            setUI(new WindowsInternalFrameUI(this) {

                @Override
                protected MouseInputAdapter createBorderListener(JInternalFrame w) {
                    return new BorderListener() {

                        @Override
                        public void mouseClicked(MouseEvent e) {
                            if (SwingUtilities.isLeftMouseButton(e)) {
                                super.mouseClicked(e);
                            }
                        }

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (SwingUtilities.isLeftMouseButton(e)) {
                                super.mousePressed(e);
                            }
                        }
                    };
                }
            });
        }
    };
    f.setSize(200, 100);
    f.setLocation(5 + 40, 5 + 50);
    EventQueue.invokeLater(() -> f.setVisible(true));
    return f;
}
Also used : WindowsInternalFrameUI(com.sun.java.swing.plaf.windows.WindowsInternalFrameUI) MouseEvent(java.awt.event.MouseEvent) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Aggregations

MouseInputAdapter (javax.swing.event.MouseInputAdapter)13 MouseEvent (java.awt.event.MouseEvent)12 BorderLayout (java.awt.BorderLayout)7 JPanel (javax.swing.JPanel)7 JLabel (javax.swing.JLabel)6 Point (java.awt.Point)5 JSlider (javax.swing.JSlider)5 ActionEvent (java.awt.event.ActionEvent)4 URL (java.net.URL)4 JFrame (javax.swing.JFrame)4 ChangeEvent (javax.swing.event.ChangeEvent)4 ChangeListener (javax.swing.event.ChangeListener)4 Dimension (java.awt.Dimension)3 ActionListener (java.awt.event.ActionListener)3 EmptyBorder (javax.swing.border.EmptyBorder)3 GraphicsConfiguration (java.awt.GraphicsConfiguration)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Image (java.awt.Image)2 Insets (java.awt.Insets)2