Search in sources :

Example 16 with MouseMotionAdapter

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

the class AutoScrollToSourceHandler method install.

public void install(final JTable table) {
    myAutoScrollAlarm = new Alarm();
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (clickCount >= 2)
                return false;
            Component location = table.getComponentAt(e.getPoint());
            if (location != null) {
                onMouseClicked(table);
                return isAutoScrollMode();
            }
            return false;
        }
    }.installOn(table);
    table.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(final MouseEvent e) {
            onSelectionChanged(table);
        }
    });
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            onSelectionChanged(table);
        }
    });
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) Alarm(com.intellij.util.Alarm) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 17 with MouseMotionAdapter

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

the class AutoScrollToSourceHandler method install.

public void install(final JTree tree) {
    myAutoScrollAlarm = new Alarm();
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (clickCount > 1)
                return false;
            TreePath location = tree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (location != null) {
                onMouseClicked(tree);
                return isAutoScrollMode();
            }
            return false;
        }
    }.installOn(tree);
    tree.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(final MouseEvent e) {
            onSelectionChanged(tree);
        }
    });
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            onSelectionChanged(tree);
        }
    });
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) Alarm(com.intellij.util.Alarm) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 18 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project yyl_example by Relucent.

the class IGOBoard method addControlListener.

protected void addControlListener() {
    this.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent event) {
            int x = event.getX();
            int y = event.getY();
            if (((preMousePoint.x - x) > 2) || ((preMousePoint.x - x) < 2) && ((preMousePoint.y - y) > 2) || ((preMousePoint.y - y) < 2)) {
                int cside = accountCellSide();
                repaint(preMousePoint.x - cside, preMousePoint.y - cside, cside * 2, cside * 2);
                preMousePoint = new Point(x, y);
            }
        }
    });
    addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent event) {
            int event_x = event.getX();
            int event_y = event.getY();
            Point point = getToPoint(event_x, event_y);
            if (point == null)
                return;
            switch(event.getButton()) {
                case MouseEvent.BUTTON1:
                    {
                        gogo(point.y, point.x, YIN);
                    }
                    break;
                case MouseEvent.BUTTON2:
                    {
                        gogo(point.y, point.x, VOID);
                    }
                    break;
                case MouseEvent.BUTTON3:
                    {
                        gogo(point.y, point.x, YANG);
                    }
                    break;
                default:
                    {
                    }
                    break;
            }
            repaint();
        }

        public void mouseExited(MouseEvent event) {
            int cside = accountCellSide();
            repaint(preMousePoint.x - cside, preMousePoint.y - cside, cside * 2, cside * 2);
            preMousePoint = new Point(-255, -255);
            repaint(event.getX() - cside, event.getY() - cside, cside * 2, cside * 2);
            System.out.println(event.getX());
        }
    });
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Point(java.awt.Point)

Example 19 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project jdk8u_jdk by JetBrains.

the class GetMousePositionWithPopup method constructTestUI.

private static void constructTestUI() {
    frame1 = new Frame();
    frame1.setBounds(100, 100, 100, 100);
    frame1.addMouseMotionListener(new MouseMotionAdapter() {

        private boolean shown = false;

        @Override
        public void mouseMoved(MouseEvent e) {
            if (shown) {
                return;
            }
            shown = true;
            frame2 = new Frame();
            frame2.setBounds(120, 120, 120, 120);
            frame2.setVisible(true);
            Point positionInFrame2 = frame2.getMousePosition();
            if (positionInFrame2.x != 30 || positionInFrame2.y != 30) {
                throw new RuntimeException("Wrong position reported. Should be [30, 30] but was [" + positionInFrame2.x + ", " + positionInFrame2.y + "]");
            }
            Point positionInFrame1 = frame1.getMousePosition();
            if (positionInFrame1 != null) {
                throw new RuntimeException("Wrong position reported. Should be null");
            }
        }
    });
    frame1.setVisible(true);
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent)

Example 20 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project vcell by virtualcell.

the class ViewGeneratedReactionsPanel method initialize.

private void initialize() {
    try {
        setName("ViewGeneratedReactionsPanel");
        setLayout(new GridBagLayout());
        shapePanel = new RulesShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (AbstractComponentShape stls : reactantPatternShapeList) {
                    stls.paintSelf(g);
                }
                for (AbstractComponentShape stls : productPatternShapeList) {
                    stls.paintSelf(g);
                }
            }
        };
        Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
        shapePanel.setLayout(new GridBagLayout());
        shapePanel.setBackground(Color.white);
        // don't show the brown contour even though it's not editable
        shapePanel.setEditable(true);
        shapePanel.setShowMoleculeColor(true);
        shapePanel.setShowNonTrivialOnly(true);
        JScrollPane scrollPane = new JScrollPane(shapePanel);
        scrollPane.setBorder(loweredBevelBorder);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new GridBagLayout());
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(false);
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(0, 0, 0, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomLargerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(2, 0, 4, 10);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(getZoomSmallerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1;
        // fake cell used for filling all the vertical empty space
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(4, 4, 4, 10);
        optionsPanel.add(new JLabel(""), gbc);
        JPanel containerOfScrollPanel = new JPanel();
        containerOfScrollPanel.setLayout(new BorderLayout());
        containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
        containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
        Dimension dim = new Dimension(500, 140);
        // dimension of shape panel
        containerOfScrollPanel.setPreferredSize(dim);
        containerOfScrollPanel.setMinimumSize(dim);
        containerOfScrollPanel.setMaximumSize(dim);
        // -----------------------------------------------------------------------------
        table = new EditorScrollTable();
        tableModel = new GeneratedReactionTableModel(table, owner);
        table.setModel(tableModel);
        table.getSelectionModel().addListSelectionListener(eventHandler);
        table.getModel().addTableModelListener(eventHandler);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        // table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setCellRenderer(rightRenderer);	// right align first table column
        // table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setMaxWidth(60);				// left column wide enough for 6-7 digits
        int gridy = 0;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        // table.setPreferredScrollableViewportSize(new Dimension(400,200));
        add(table.getEnclosingScrollPane(), gbc);
        // add toolTipText for each table cell
        table.addMouseMotionListener(new MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                Point p = e.getPoint();
                int row = table.rowAtPoint(p);
                int column = table.columnAtPoint(p);
                table.setToolTipText(String.valueOf(table.getValueAt(row, column)));
            }
        });
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        add(new JLabel("Search "), gbc);
        textFieldSearch = new JTextField(70);
        textFieldSearch.addActionListener(eventHandler);
        textFieldSearch.getDocument().addDocumentListener(eventHandler);
        textFieldSearch.putClientProperty("JTextField.variant", "search");
        gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 0, 4, 4);
        add(textFieldSearch, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 4, 4, 10);
        add(totalReactionsLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        // gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        add(containerOfScrollPanel, gbc);
        // rendering the small shapes of a fake rule in the Depiction column of this viewer table)
        // TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
        // of a rule in the Depiction column of the reaction table)
        DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

            List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();

            SpeciesPatternSmallShape spss = null;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (table.getModel() instanceof VCellSortTableModel<?>) {
                    Object selectedObject = null;
                    if (table.getModel() == tableModel) {
                        selectedObject = tableModel.getValueAt(row);
                    }
                    if (selectedObject != null) {
                        if (selectedObject instanceof GeneratedReactionTableRow) {
                            ReactionRule rr = ((GeneratedReactionTableRow) selectedObject).getReactionRule();
                            Graphics panelContext = table.getGraphics();
                            BioModel bioModel = owner.getSimulationContext().getBioModel();
                            spssList.clear();
                            List<ReactantPattern> rpList = rr.getReactantPatterns();
                            int xPos = 4;
                            for (int i = 0; i < rpList.size(); i++) {
                                SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
                                spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
                                if (i < rpList.size() - 1) {
                                    spss.addEndText("+");
                                } else {
                                    if (rr.isReversible()) {
                                        spss.addEndText("<->");
                                        xPos += 7;
                                    } else {
                                        spss.addEndText("->");
                                    }
                                }
                                xPos += spss.getWidth() + 14;
                                spssList.add(spss);
                            }
                            List<ProductPattern> ppList = rr.getProductPatterns();
                            xPos += 7;
                            for (int i = 0; i < ppList.size(); i++) {
                                SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
                                spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
                                if (i < ppList.size() - 1) {
                                    spss.addEndText("+");
                                }
                                xPos += spss.getWidth() + 14;
                                spssList.add(spss);
                            }
                        }
                    } else {
                        spssList.clear();
                    }
                }
                setText("");
                return this;
            }

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (SpeciesPatternSmallShape spss : spssList) {
                    if (spss == null) {
                        continue;
                    }
                    spss.paintSelf(g);
                }
            }
        };
        table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
        table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setPreferredWidth(400);
        table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setMinWidth(400);
        table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDefinition).setPreferredWidth(30);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) JTextField(javax.swing.JTextField) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) RulesShapePanel(cbit.vcell.graph.gui.RulesShapePanel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) AbstractComponentShape(cbit.vcell.graph.AbstractComponentShape) ReactantPattern(cbit.vcell.model.ReactantPattern) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) ReactionRule(cbit.vcell.model.ReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point) Graphics(java.awt.Graphics) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) JTable(javax.swing.JTable) BioModel(cbit.vcell.biomodel.BioModel) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) Border(javax.swing.border.Border) EtchedBorder(javax.swing.border.EtchedBorder)

Aggregations

MouseEvent (java.awt.event.MouseEvent)25 MouseMotionAdapter (java.awt.event.MouseMotionAdapter)25 Point (java.awt.Point)13 MouseAdapter (java.awt.event.MouseAdapter)13 BorderLayout (java.awt.BorderLayout)12 JLabel (javax.swing.JLabel)12 GridBagConstraints (java.awt.GridBagConstraints)11 GridBagLayout (java.awt.GridBagLayout)11 Insets (java.awt.Insets)11 JPanel (javax.swing.JPanel)11 JScrollPane (javax.swing.JScrollPane)11 Dimension (java.awt.Dimension)10 Graphics (java.awt.Graphics)9 PointLocationInShapeContext (cbit.vcell.graph.PointLocationInShapeContext)6 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)6 GroupingCriteria (cbit.vcell.model.GroupingCriteria)6 Border (javax.swing.border.Border)6 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)5 JTextField (javax.swing.JTextField)5 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)5