Search in sources :

Example 91 with ComponentEvent

use of java.awt.event.ComponentEvent in project blue by kunstmusik.

the class TracksEditor method setupTable.

private void setupTable() {
    table.setShowGrid(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setDefaultRenderer(String.class, new TrackerCellRenderer());
    table.setDefaultEditor(String.class, new TrackColumnEditor());
    table.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            namePanel.updateSize();
        }
    });
    table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
            if (trackList != null) {
                namePanel.updateLabelSizes();
            }
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
        }
    });
    table.getColumnModel().getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
        int h = table.getRowHeight();
        int y1 = table.getSelectedRow() * h;
        int selectionH = table.getSelectedRowCount() * h;
        table.repaint(0, y1, table.getWidth(), selectionH);
    });
    SwingUtil.installActions(table, new Action[] { new IncrementAction(), new DecrementAction(), new TieAction(), new SpaceBarAction(), new NoteOffAction(), new CutAction(), new CopyAction(), new PasteAction(), new InsertAction(), new DeleteAction(), new BackSpaceAction() });
}
Also used : TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Point(java.awt.Point) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 92 with ComponentEvent

use of java.awt.event.ComponentEvent in project cytoscape-impl by cytoscape.

the class VisualPropertySheetItem method getMappingPnl.

protected JPanel getMappingPnl() {
    if (mappingPnl == null) {
        mappingPnl = new JPanel();
        mappingPnl.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("Separator.foreground")));
        mappingPnl.setLayout(new BorderLayout());
        mappingPnl.setVisible(false);
        mappingPnl.add(getPropSheetPnl(), BorderLayout.CENTER);
        final JPanel bottomPnl = new JPanel();
        bottomPnl.setLayout(new BoxLayout(bottomPnl, BoxLayout.X_AXIS));
        bottomPnl.add(Box.createHorizontalGlue());
        bottomPnl.add(getRemoveMappingBtn());
        bottomPnl.add(Box.createRigidArea(new Dimension(0, PROP_SHEET_ROW_HEIGHT)));
        bottomPnl.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
        mappingPnl.add(bottomPnl, BorderLayout.SOUTH);
        mappingPnl.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentShown(final ComponentEvent e) {
                updateMappingPanelSize();
            }
        });
    }
    return mappingPnl;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 93 with ComponentEvent

use of java.awt.event.ComponentEvent in project cytoscape-impl by cytoscape.

the class VisualPropertySheetItem method getPropSheetTbl.

protected PropertySheetTable getPropSheetTbl() {
    if (propSheetTbl == null) {
        propSheetTbl = new VizMapPropertySheetTable();
        propSheetTbl.setRowHeight(PROP_SHEET_ROW_HEIGHT);
        propSheetTbl.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        propSheetTbl.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentResized(final ComponentEvent e) {
                updateMappingPanelSize();
            }
        });
    }
    return propSheetTbl;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 94 with ComponentEvent

use of java.awt.event.ComponentEvent in project cytoscape-impl by cytoscape.

the class VisualPropertySheetItem method getMappingBtn.

protected JToggleButton getMappingBtn() {
    if (mappingBtn == null) {
        mappingBtn = new VizMapperToggleButton();
        mappingBtn.setIcon(getIcon(null, VALUE_ICON_WIDTH, VALUE_ICON_HEIGHT));
        mappingBtn.setUI(new VPButtonUI(VPButtonUI.SOUTH));
        mappingBtn.setHorizontalAlignment(JLabel.CENTER);
        mappingBtn.setDisabledIcon(disabledBtnIcon);
        updateMappingIcon();
        mappingBtn.addActionListener(evt -> {
            if (getMappingPnl().isShowing())
                collapse();
            else
                expand();
            updateMappingIcon();
        });
        getMappingPnl().addComponentListener(new ComponentAdapter() {

            @Override
            public void componentShown(final ComponentEvent ce) {
                if (mappingBtn != null)
                    mappingBtn.setSelected(true);
                updateMappingIcon();
            }

            @Override
            public void componentHidden(final ComponentEvent ce) {
                if (mappingBtn != null)
                    mappingBtn.setSelected(false);
                updateMappingIcon();
            }
        });
    }
    return mappingBtn;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 95 with ComponentEvent

use of java.awt.event.ComponentEvent in project cytoscape-impl by cytoscape.

the class VizMapperMediator method addViewListeners.

private void addViewListeners(final VisualPropertySheet vpSheet, final VisualPropertySheetItem<?> vpSheetItem) {
    if (vpSheetItem.getModel().getVisualPropertyDependency() == null) {
        // It's a regular VisualProperty Editor...
        // Default value button clicked
        vpSheetItem.getDefaultBtn().addActionListener(evt -> {
            openDefaultValueEditor(evt, vpSheetItem);
        });
        // Default value button right-clicked
        vpSheetItem.getDefaultBtn().addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(final MouseEvent e) {
                maybeShowContextMenu(e);
            }

            @Override
            public void mouseReleased(final MouseEvent e) {
                maybeShowContextMenu(e);
            }

            private void maybeShowContextMenu(final MouseEvent e) {
                if (e.isPopupTrigger()) {
                    final JPopupMenu contextMenu = new JPopupMenu();
                    contextMenu.add(new JMenuItem(new AbstractAction("Reset Default Value") {

                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            vpSheetItem.getModel().resetDefaultValue();
                        }
                    }));
                    showContextMenu(contextMenu, e);
                }
            }
        });
        // Bypass button clicked
        if (vpSheetItem.getModel().isLockedValueAllowed()) {
            // Create context menu
            final JPopupMenu bypassMenu = new JPopupMenu();
            final JMenuItem removeBypassMenuItem;
            bypassMenu.add(new JMenuItem(new AbstractAction("Set Bypass...") {

                @Override
                public void actionPerformed(final ActionEvent e) {
                    openLockedValueEditor(e, vpSheetItem);
                }
            }));
            bypassMenu.add(removeBypassMenuItem = new JMenuItem(new AbstractAction("Remove Bypass") {

                @Override
                public void actionPerformed(final ActionEvent e) {
                    removeLockedValue(e, vpSheetItem);
                }
            }));
            // Right-clicked
            vpSheetItem.getBypassBtn().addMouseListener(new MouseAdapter() {

                @Override
                public void mousePressed(final MouseEvent e) {
                    maybeShowContextMenu(e);
                }

                @Override
                public void mouseReleased(final MouseEvent e) {
                    maybeShowContextMenu(e);
                }

                private void maybeShowContextMenu(final MouseEvent e) {
                    if (vpSheetItem.getBypassBtn().isEnabled() && e.isPopupTrigger()) {
                        final LockedValueState state = vpSheetItem.getModel().getLockedValueState();
                        removeBypassMenuItem.setEnabled(state != LockedValueState.ENABLED_NOT_SET);
                        showContextMenu(bypassMenu, e);
                    }
                }
            });
            // Left-clicked
            vpSheetItem.getBypassBtn().addActionListener(evt -> {
                final LockedValueState state = vpSheetItem.getModel().getLockedValueState();
                final JButton btn = vpSheetItem.getBypassBtn();
                if (state == LockedValueState.ENABLED_NOT_SET) {
                    // There is only one option to execute, so do it now, rather than showing the popup menu
                    openLockedValueEditor(evt, vpSheetItem);
                } else {
                    bypassMenu.show(btn, 0, btn.getHeight());
                    bypassMenu.requestFocusInWindow();
                }
            });
        }
        // Right-click
        final ContextMenuMouseListener cmMouseListener = new ContextMenuMouseListener(vpSheet, vpSheetItem);
        vpSheetItem.addMouseListener(cmMouseListener);
        if (vpSheetItem.getModel().isVisualMappingAllowed()) {
            vpSheetItem.getPropSheetPnl().getTable().addMouseListener(cmMouseListener);
            vpSheetItem.getRemoveMappingBtn().addActionListener(evt -> {
                removeVisualMapping(vpSheetItem);
            });
            vpSheetItem.getPropSheetTbl().addPropertyChangeListener("editingVizMapperProperty", evt -> {
                // Save the current editor (the one the user is interacting with)
                curVpSheetItem = vpSheetItem;
                curVizMapperProperty = (VizMapperProperty<?, ?, ?>) evt.getNewValue();
                final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, ?>> mappingTypeProperty = vizMapPropertyBuilder.getMappingTypeProperty(vpSheetItem.getPropSheetPnl());
                final VisualMappingFunctionFactory factory = (VisualMappingFunctionFactory) mappingTypeProperty.getValue();
                attrProxy.setCurrentMappingType(factory != null ? factory.getMappingFunctionType() : null);
                final VizMapperProperty<VisualProperty<?>, String, VisualMappingFunctionFactory> columnProp = vizMapPropertyBuilder.getColumnProperty(vpSheetItem.getPropSheetPnl());
                final Object columnValue = columnProp.getValue();
                mappingFactoryProxy.setCurrentColumnName(columnValue != null ? columnValue.toString() : null);
                mappingFactoryProxy.setCurrentTargetDataType(vpSheet.getModel().getTargetDataType());
            });
        }
    } else {
        // It's a Dependency Editor...
        vpSheetItem.getDependencyCkb().addItemListener(evt -> {
            onDependencySelectionChanged(evt, vpSheetItem);
        });
    }
    // Save sheet items that were explicitly shown/hidden by the user,
    // so his preferences can be respected when the current style changes
    vpSheetItem.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(final ComponentEvent e) {
            userProps.put(vpSheetItem.getModel().getId(), Boolean.TRUE);
        }

        @Override
        public void componentHidden(final ComponentEvent e) {
            userProps.put(vpSheetItem.getModel().getId(), Boolean.FALSE);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) JButton(javax.swing.JButton) JPopupMenu(javax.swing.JPopupMenu) LockedValueState(org.cytoscape.view.vizmap.gui.internal.model.LockedValueState) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) ComponentEvent(java.awt.event.ComponentEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentEvent (java.awt.event.ComponentEvent)120 ComponentAdapter (java.awt.event.ComponentAdapter)97 Dimension (java.awt.Dimension)22 Component (java.awt.Component)18 ActionEvent (java.awt.event.ActionEvent)18 JPanel (javax.swing.JPanel)18 JScrollPane (javax.swing.JScrollPane)16 ComponentListener (java.awt.event.ComponentListener)15 MouseEvent (java.awt.event.MouseEvent)15 JButton (javax.swing.JButton)15 JLabel (javax.swing.JLabel)15 BorderLayout (java.awt.BorderLayout)12 Point (java.awt.Point)12 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 MouseAdapter (java.awt.event.MouseAdapter)11 ActionListener (java.awt.event.ActionListener)10 JTable (javax.swing.JTable)9 AbstractAction (javax.swing.AbstractAction)8 BoxLayout (javax.swing.BoxLayout)8