Search in sources :

Example 21 with MouseMotionAdapter

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

the class ViewGeneratedSpeciesPanel method initialize.

private void initialize() {
    try {
        setName("ViewGeneratedSpeciesPanel");
        setLayout(new GridBagLayout());
        shapePanel = new LargeShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spls != null) {
                    spls.paintSelf(g);
                }
            }

            @Override
            public DisplayMode getDisplayMode() {
                return DisplayMode.other;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
                return RuleAnalysisChanged.UNCHANGED;
            }

            @Override
            public RuleParticipantSignature getSignature() {
                return null;
            }

            @Override
            public GroupingCriteria getCriteria() {
                return null;
            }

            @Override
            public boolean isViewSingleRow() {
                return true;
            }
        };
        Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
        shapePanel.setLayout(new GridBagLayout());
        shapePanel.setBackground(Color.white);
        // not really editable but we don't want the brown contours here
        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, 135);
        // dimension of shape panel
        containerOfScrollPanel.setPreferredSize(dim);
        containerOfScrollPanel.setMinimumSize(dim);
        containerOfScrollPanel.setMaximumSize(dim);
        // ------------------------------------------------------------------------
        table = new EditorScrollTable();
        tableModel = new GeneratedSpeciesTableModel(table, owner);
        table.setModel(tableModel);
        table.getSelectionModel().addListSelectionListener(eventHandler);
        table.getModel().addTableModelListener(eventHandler);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        int gridy = 0;
        gbc = new java.awt.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);
        // gbc = new java.awt.GridBagConstraints();
        // gbc.gridx = 9;
        // gbc.gridy = gridy;
        // 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 java.awt.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(totalSpeciesLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        // gbc.weightx = 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 the flattened species 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 species context in the Depiction column of the species table)
        DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {

            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 GeneratedSpeciesTableRow) {
                            SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
                            // sp cannot be null
                            SpeciesPattern sp = sc.getSpeciesPattern();
                            Graphics panelContext = table.getGraphics();
                            spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
                        }
                    } else {
                        spss = null;
                    }
                }
                setText("");
                return this;
            }

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (spss != null) {
                    spss.paintSelf(g);
                }
            }
        };
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.iColDepiction).setPreferredWidth(400);
        table.getColumnModel().getColumn(GeneratedSpeciesTableModel.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) RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) SpeciesPatternSmallShape(cbit.vcell.graph.SpeciesPatternSmallShape) SpeciesContext(cbit.vcell.model.SpeciesContext) JTextField(javax.swing.JTextField) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) LargeShapePanel(cbit.vcell.graph.gui.LargeShapePanel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) RuleAnalysisChanged(cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) GroupingCriteria(cbit.vcell.model.GroupingCriteria) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Point(java.awt.Point) GridBagConstraints(java.awt.GridBagConstraints) Point(java.awt.Point) Graphics(java.awt.Graphics) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) Border(javax.swing.border.Border)

Example 22 with MouseMotionAdapter

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

the class ScrollTable method initialize.

private void initialize() {
    autoResizeMode = AUTO_RESIZE_OFF;
    // make it bigger on Mac
    setRowHeight(getRowHeight() + 4);
    putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
    scrollTableActionManager = new DefaultScrollTableActionManager(this);
    enclosingScrollPane = new JScrollPane(this);
    enclosingScrollPane.getViewport().setBackground(Color.WHITE);
    contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(enclosingScrollPane, BorderLayout.CENTER);
    setPreferredScrollableViewportSize(new Dimension(200, 100));
    setIntercellSpacing(new Dimension(2, 2));
    defaultTableCellRenderer = new DefaultScrollTableCellRenderer();
    setDefaultRenderer(Object.class, defaultTableCellRenderer);
    setDefaultRenderer(Number.class, defaultTableCellRenderer);
    setDefaultRenderer(Double.class, defaultTableCellRenderer);
    setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
    setDefaultEditor(Boolean.class, new ScrollTableBooleanEditor());
    final TableCellRenderer defaultTableCellHeaderRenderer = getTableHeader().getDefaultRenderer();
    TableCellRenderer defaultTableHeaderRenderer = new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component component = defaultTableCellHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (component instanceof JLabel) {
                JLabel label = (JLabel) component;
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setBackground(tableHeaderColor);
                label.setBorder(BorderFactory.createCompoundBorder(tableCellHeaderBorder, new EmptyBorder(1, 0, 1, 0)));
            }
            return component;
        }
    };
    getTableHeader().setDefaultRenderer(defaultTableHeaderRenderer);
    MouseAdapter mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (!javaVersion.startsWith("1.5")) {
                if (!hasFocus()) {
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        addFocusListener(new FocusListener() {

                            public void focusLost(FocusEvent e) {
                            }

                            public void focusGained(FocusEvent e) {
                                removeFocusListener(this);
                                Robot robot;
                                try {
                                    robot = new Robot();
                                    robot.mousePress(InputEvent.BUTTON1_MASK);
                                    robot.mouseRelease(InputEvent.BUTTON1_MASK);
                                } catch (AWTException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        });
                    }
                    requestFocusInWindow();
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            scrollTableActionManager.triggerPopup(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            hoverRow = -1;
            hoverColumn = -1;
            repaint();
        }
    };
    MouseMotionAdapter mouseMotionListener = new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            hoverRow = rowAtPoint(e.getPoint());
            hoverColumn = columnAtPoint(e.getPoint());
            repaint();
        }
    };
    addMouseListener(mouseListener);
    addMouseMotionListener(mouseMotionListener);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) ScopedExpressionTableCellRenderer(cbit.vcell.model.gui.ScopedExpressionTableCellRenderer) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) EventObject(java.util.EventObject) Component(java.awt.Component) JComponent(javax.swing.JComponent) EmptyBorder(javax.swing.border.EmptyBorder) FocusListener(java.awt.event.FocusListener) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 23 with MouseMotionAdapter

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

the class ReactionRuleEditorPropertiesPanel method initialize.

private void initialize() {
    try {
        shapePanel = new RulesShapePanel() {

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                reactantShape.paintSelf(g);
                productShape.paintSelf(g);
            }
        };
        shapePanel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if (getViewSingleRowButton().isSelected()) {
                    return;
                }
                if (e.getButton() == 1) {
                    // left click selects the object (we highlight it)
                    Point whereClicked = e.getPoint();
                    PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                    reactantShape.setPointLocationInShapeContext(locationContext);
                    productShape.setPointLocationInShapeContext(locationContext);
                    manageMouseActivity(locationContext);
                } else if (e.getButton() == 3) {
                    // right click invokes popup menu (only if the object is highlighted)
                    Point whereClicked = e.getPoint();
                    PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
                    reactantShape.setPointLocationInShapeContext(locationContext);
                    productShape.setPointLocationInShapeContext(locationContext);
                    manageMouseActivity(locationContext);
                    if (locationContext.getDeepestShape() != null && !locationContext.getDeepestShape().isHighlighted()) {
                    // TODO: (maybe) add code here to highlight the shape if it's not highlighted already but don't show the menu
                    // return;
                    }
                    showPopupMenu(e, locationContext);
                }
            }

            private void manageMouseActivity(PointLocationInShapeContext locationContext) {
                Graphics g = shapePanel.getGraphics();
                reactantShape.turnHighlightOffRecursive(g);
                productShape.turnHighlightOffRecursive(g);
                boolean found = false;
                if (reactantShape.contains(locationContext)) {
                    found = true;
                }
                if (!found) {
                    if (productShape.contains(locationContext)) {
                        // we just need to initialize the location context with the proper shapes under the cursor by calling "contains"
                        ;
                    }
                }
                locationContext.highlightDeepestShape();
                // if(locationContext.getDeepestShape() == null) {
                // // nothing selected means all the reactant bar or all the product bar is selected
                int xExtent = SpeciesPatternLargeShape.calculateXExtent(shapePanel);
                Rectangle2D reactantRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetReactantInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
                Rectangle2D productRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetProductInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
                if (locationContext.isInside(reactantRectangle)) {
                    reactantShape.paintSelf(g, true);
                } else if (locationContext.isInside(productRectangle)) {
                    productShape.paintSelf(g, true);
                // } else {
                // 
                // }
                // } else {
                // locationContext.paintDeepestShape(g);
                }
            }
        });
        shapePanel.addMouseMotionListener(new MouseMotionAdapter() {

            public void mouseMoved(MouseEvent e) {
                if (getViewSingleRowButton().isSelected()) {
                    shapePanel.setToolTipText("Single Row is view-only. To edit, unselect the 'Single Row Viewer' check box.");
                    return;
                }
                Point overWhat = e.getPoint();
                PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
                boolean inReactant = reactantShape.contains(locationContext);
                boolean inProduct = productShape.contains(locationContext);
                HighlightableShapeInterface hsi = locationContext.getDeepestShape();
                if (hsi == null) {
                    shapePanel.setToolTipText(null);
                } else {
                    shapePanel.setToolTipText("Right click for " + hsi.getDisplayType() + " menus");
                }
                List<SpeciesPatternLargeShape> spsList = null;
                if (inReactant) {
                    spsList = reactantShape.getSpeciesPatternShapeList();
                } else if (inProduct) {
                    spsList = productShape.getSpeciesPatternShapeList();
                }
                if (spsList != null) {
                    for (SpeciesPatternLargeShape sps : spsList) {
                        for (MolecularTypeLargeShape mtls : sps.getMolecularTypeLargeShapes()) {
                            Rectangle r = mtls.getAnchorHotspot();
                            if (r != null && r.contains(overWhat)) {
                                mtls.getMolecularType();
                                shapePanel.setToolTipText(mtls.getAnchorsHTML());
                                break;
                            }
                        }
                    }
                }
            }
        });
        shapePanel.setLayout(new GridBagLayout());
        shapePanel.setBackground(Color.white);
        shapePanel.zoomSmaller();
        shapePanel.zoomSmaller();
        getZoomSmallerButton().setEnabled(true);
        getZoomLargerButton().setEnabled(true);
        scrollPane = new JScrollPane(shapePanel);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        isReversibleCheckBox = new JCheckBox("Reversible");
        isReversibleCheckBox.setHorizontalTextPosition(SwingConstants.LEFT);
        isReversibleCheckBox.addActionListener(eventHandler);
        isReversibleCheckBox.setEnabled(true);
        JPanel optionsPanel = new JPanel();
        optionsPanel.setPreferredSize(new Dimension(156, 200));
        optionsPanel.setLayout(new GridBagLayout());
        int gridy = 0;
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.insets = new Insets(6, 1, 2, 2);
        gbc.anchor = GridBagConstraints.WEST;
        optionsPanel.add(isReversibleCheckBox, gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.insets = new Insets(0, 0, 0, 0);
        // empty cell to take all available horizontal space and push the next 2 buttons to the right
        gbc.weightx = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        optionsPanel.add(new JLabel(""), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.insets = new Insets(6, 2, 2, 2);
        gbc.anchor = GridBagConstraints.EAST;
        optionsPanel.add(getZoomLargerButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 3;
        gbc.gridy = gridy;
        gbc.insets = new Insets(6, 2, 2, 4);
        gbc.anchor = GridBagConstraints.EAST;
        optionsPanel.add(getZoomSmallerButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        // top, left bottom, right
        gbc.insets = new Insets(4, 4, 2, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.NORTHWEST;
        optionsPanel.add(getAddReactantButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        gbc.insets = new Insets(2, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.NORTHWEST;
        optionsPanel.add(getAddProductButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        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);
        // -----------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        gbc.insets = new Insets(2, 4, 0, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getViewSingleRowButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowMoleculeColorButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 4;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowNonTrivialButton(), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.insets = new Insets(0, 4, 4, 4);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.SOUTHWEST;
        optionsPanel.add(getShowDifferencesButton(), gbc);
        // set initial buttons' state
        getViewSingleRowButton().setSelected(false);
        getShowMoleculeColorButton().setSelected(true);
        getShowNonTrivialButton().setSelected(true);
        getShowDifferencesButton().setSelected(false);
        shapePanel.setViewSingleRow(getViewSingleRowButton().isSelected());
        shapePanel.setShowMoleculeColor(getShowMoleculeColorButton().isSelected());
        shapePanel.setShowNonTrivialOnly(getShowNonTrivialButton().isSelected());
        shapePanel.setShowDifferencesOnly(getShowDifferencesButton().isSelected());
        // ----------------------------------------------------------
        containerOfScrollPanel = new JPanel();
        containerOfScrollPanel.setLayout(new BorderLayout());
        containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
        containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
        reactantTree = new BioModelNodeEditableTree();
        reactantTreeModel = new ReactionRulePropertiesTreeModel(reactantTree, ReactionRuleParticipantType.Reactant);
        reactantTree.setModel(reactantTreeModel);
        productTree = new BioModelNodeEditableTree();
        productTreeModel = new ReactionRulePropertiesTreeModel(productTree, ReactionRuleParticipantType.Product);
        productTree.setModel(productTreeModel);
        setLayout(new BorderLayout());
        add(containerOfScrollPanel, BorderLayout.CENTER);
        setBackground(Color.white);
    } 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) Rectangle(java.awt.Rectangle) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) RulesShapePanel(cbit.vcell.graph.gui.RulesShapePanel) MolecularTypeLargeShape(cbit.vcell.graph.MolecularTypeLargeShape) BorderLayout(java.awt.BorderLayout) List(java.util.List) ArrayList(java.util.ArrayList) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Rectangle2D(java.awt.geom.Rectangle2D) HighlightableShapeInterface(cbit.vcell.graph.HighlightableShapeInterface) JLabel(javax.swing.JLabel) Point(java.awt.Point) Dimension(java.awt.Dimension) PointLocationInShapeContext(cbit.vcell.graph.PointLocationInShapeContext) Point(java.awt.Point) Graphics(java.awt.Graphics) JCheckBox(javax.swing.JCheckBox) MouseMotionAdapter(java.awt.event.MouseMotionAdapter)

Example 24 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project n2a by frothga.

the class FixedParameterSpacePanel method buildDomainTab.

private void buildDomainTab(ParameterDomain domain) {
    TNode nRoot = new TNode(new NodeSimpleLabel(domain.getName()));
    populate(nRoot, domain);
    FilterableParameterTreePanel pnlFilterableTree = new FilterableParameterTreePanel(nRoot);
    final ParameterTree treParams = pnlFilterableTree.getTree();
    treParams.addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            TreePath path = treParams.getPathForLocation(e.getX(), e.getY());
            if (path == null || ((TNode) path.getLastPathComponent()).getUserObject() instanceof NodeSubdomain) {
                treParams.setCursor(Cursor.getDefaultCursor());
            } else {
                treParams.setCursor(DragCursors.getOpenhandcursor());
            }
        }
    });
    treParams.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            updateDetailsPanelFromTree(treParams);
        }
    });
    treParams.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1 && treParams.getSelectionCount() != 0) {
                List<ParameterBundle> bundles = getSelectedParamsAsBundles(treParams.getSelectionPaths());
                if (bundles != null) {
                    dropIntoGroups(bundles, dropEmphasis);
                }
            }
        }
    });
    DragSource ds = new DragSource();
    ds.createDefaultDragGestureRecognizer(treParams, DnDConstants.ACTION_LINK, this);
    int existingIndex = tabParamDomains.indexOfTabByKey(domain.getName());
    if (existingIndex != -1) {
        tabParamDomains.remove(existingIndex);
    }
    tabParamDomains.add(domain.getName(), pnlFilterableTree);
    int index = tabParamDomains.getTabCount();
    tabParamDomains.setIconAt(index - 1, domain.getIcon());
    tabParamDomains.setUseBorderAt(index - 1, true);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ParameterTree(gov.sandia.umf.platform.ui.ensemble.tree.ParameterTree) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DragSource(java.awt.dnd.DragSource) NodeSimpleLabel(replete.gui.controls.simpletree.NodeSimpleLabel) NodeSubdomain(gov.sandia.umf.platform.ui.ensemble.tree.NodeSubdomain) FilterableParameterTreePanel(gov.sandia.umf.platform.ui.ensemble.tree.FilterableParameterTreePanel) TNode(replete.gui.controls.simpletree.TNode) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) TreePath(javax.swing.tree.TreePath) List(java.util.List) ParameterSetList(gov.sandia.umf.platform.ensemble.params.ParameterSetList) ArrayList(java.util.ArrayList) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 25 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project knime-core by knime.

the class SelectionPanel method createIncludePanel.

private void createIncludePanel() {
    m_includePanel = new JPanel(new GridBagLayout());
    new DropTarget(m_includePanel, DnDConstants.ACTION_MOVE, this, true, null);
    m_scrollPane = new JScrollPane(m_includePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    m_scrollPane.setPreferredSize(new Dimension(300, 200));
    m_scrollPane.getVerticalScrollBar().setUnitIncrement(20);
    MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {

        int lasty = 0;

        @Override
        public void mouseDragged(final MouseEvent e) {
            if (Math.abs(lasty - e.getY()) < 10) {
                int i = m_scrollPane.getVerticalScrollBar().getValue();
                if (e.getY() > lasty) {
                    m_scrollPane.getVerticalScrollBar().setValue(i + 2);
                } else if (e.getY() < lasty) {
                    m_scrollPane.getVerticalScrollBar().setValue(i - 2);
                }
            }
            if (e.getY() < 10) {
                lasty = 10;
            } else if (e.getY() > m_includePanel.getVisibleRect().getMaxY()) {
                lasty = (int) m_includePanel.getVisibleRect().getMaxY() - 10;
            } else if (Math.abs(lasty - e.getY()) > 10) {
                lasty = e.getY();
            }
        }
    };
    m_includePanel.addMouseMotionListener(doScrollRectToVisible);
    m_includePanel.setAutoscrolls(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) DropTarget(java.awt.dnd.DropTarget) Dimension(java.awt.Dimension) MouseMotionListener(java.awt.event.MouseMotionListener)

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