Search in sources :

Example 26 with ComponentAdapter

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

the class DialogUtils method showComponentOptionsTableList.

public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
    // //Create hidden column with original row index so original row index can
    // //be returned for user selections even if rows are sorted
    // final int hiddenColumnIndex = rowDataOrig[0].length;
    // final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
    // for (int i = 0; i < rowDataHiddenIndex.length; i++) {
    // for (int j = 0; j < rowDataOrig[i].length; j++) {
    // rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
    // }
    // rowDataHiddenIndex[i][hiddenColumnIndex] = i;
    // }
    Producer<TableListResult> prod = () -> {
        // Create hidden column with original row index so original row index can
        // be returned for user selections even if rows are sorted
        int hiddenColumnIndex = rowDataOrig[0].length;
        Object[][] rowDataHiddenIndex = rowDataOrig;
        if (rowSortComparator != null) {
            rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
            for (int i = 0; i < rowDataHiddenIndex.length; i++) {
                for (int j = 0; j < rowDataOrig[i].length; j++) {
                    rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
                }
                rowDataHiddenIndex[i][hiddenColumnIndex] = i;
            }
        }
        @SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {

            @Override
            public boolean isSortable(int col) {
                if (rowSortComparator != null) {
                    return true;
                }
                return false;
            }

            public Object getValueAt(int row, int column) {
                return getValueAt(row)[column];
            }

            @Override
            public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
                return new Comparator<Object[]>() {

                    public int compare(Object[] o1, Object[] o2) {
                        if (ascending) {
                            return rowSortComparator.compare(o1[col], o2[col]);
                        }
                        return rowSortComparator.compare(o2[col], o1[col]);
                    }
                };
            }
        };
        final JSortTable table = new JSortTable();
        // table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.setModel(tableModel);
        tableModel.setData(Arrays.asList(rowDataHiddenIndex));
        if (listSelectionModel_SelectMode != null) {
            table.setSelectionMode(listSelectionModel_SelectMode);
        } else {
            table.setRowSelectionAllowed(false);
            table.setColumnSelectionAllowed(false);
        }
        table.setPreferredScrollableViewportSize(new Dimension(500, 250));
        table.disableUneditableForeground();
        OKEnabler tableListOKEnabler = null;
        if (listSelectionModel_SelectMode != null) {
            tableListOKEnabler = new OKEnabler() {

                private JOptionPane jop;

                public void setJOptionPane(JOptionPane joptionPane) {
                    jop = joptionPane;
                    setInternalNotCancelEnabled(joptionPane, false, false);
                    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                        public void valueChanged(ListSelectionEvent e) {
                            if (!e.getValueIsAdjusting()) {
                                if (table.getSelectedRowCount() != 0) {
                                    setInternalNotCancelEnabled(jop, true, false);
                                } else {
                                    setInternalNotCancelEnabled(jop, false, false);
                                }
                            }
                        }
                    });
                }
            };
        }
        if (listSelectionListener != null) {
            table.getSelectionModel().addListSelectionListener(listSelectionListener);
        }
        TableListResult tableListResult = new TableListResult();
        // HACK to fix horizontal scrollbar not showing for large horizontal tables
        // workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
        final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
        Component[] components = table.getEnclosingScrollPane().getComponents();
        for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof JScrollPane) {
                jScrollPaneArr[0] = (JScrollPane) components[i];
                break;
            }
        }
        if (jScrollPaneArr[0] != null) {
            jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {

                @Override
                public void componentResized(ComponentEvent e) {
                    super.componentResized(e);
                    if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                    } else {
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    }
                }
            });
        }
        if (options == null) {
            if (bModal) {
                if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            } else {
                // display non-modal
                JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
                JDialog jDialog = jOptionPane.createDialog(requester, title);
                jDialog.setResizable(true);
                jDialog.setModal(false);
                jDialog.pack();
                jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                jDialog.setVisible(true);
            }
            tableListResult.selectedTableRows = table.getSelectedRows();
        } else {
            tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
            tableListResult.selectedTableRows = table.getSelectedRows();
        }
        if (rowSortComparator != null) {
            // return the index of the original unsorted object array that corresponds to the user row selections
            for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
                tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
            }
        }
        return tableListResult;
    };
    return VCSwingFunction.executeAsRuntimeException(prod);
}
Also used : JScrollPane(javax.swing.JScrollPane) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) Comparator(java.util.Comparator) ListSelectionListener(javax.swing.event.ListSelectionListener) JSortTable(org.vcell.util.gui.sorttable.JSortTable) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter) JDialog(javax.swing.JDialog)

Example 27 with ComponentAdapter

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

the class BasicGraphEditor method insertPalette.

/**
 */
public EditorPalette insertPalette(String title) {
    final EditorPalette palette = new EditorPalette();
    final JScrollPane scrollPane = new JScrollPane(palette);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    libraryPane.add(title, scrollPane);
    // Updates the widths of the palettes if the container size changes
    libraryPane.addComponentListener(new ComponentAdapter() {

        /**
         */
        public void componentResized(ComponentEvent e) {
            int w = scrollPane.getWidth() - scrollPane.getVerticalScrollBar().getWidth();
            palette.setPreferredWidth(w);
        }
    });
    return palette;
}
Also used : JScrollPane(javax.swing.JScrollPane) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 28 with ComponentAdapter

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

the class NetworkViewComparisonPanel method init.

private void init() {
    final Set<CyNetworkView> views = new LinkedHashSet<>();
    for (ViewPanel vp : viewPanels.values()) {
        vp.getNetworkViewContainer().setComparing(true);
        views.add(vp.getNetworkView());
    }
    setName(createUniqueKey(views));
    setLayout(new BorderLayout());
    add(getGridPanel(), BorderLayout.CENTER);
    add(getComparisonToolBar(), BorderLayout.SOUTH);
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
            requestFocusInWindow();
            for (ViewPanel vp : viewPanels.values()) {
                if (vp.isCurrent()) {
                    vp.getNetworkViewContainer().getContentPane().requestFocusInWindow();
                    break;
                }
            }
            arrangePanels();
            update();
        }

        @Override
        public void componentResized(ComponentEvent e) {
            arrangePanels();
        }
    });
    setKeyBindings(this);
    arrangePanels();
    update();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BorderLayout(java.awt.BorderLayout) ComponentEvent(java.awt.event.ComponentEvent) CyNetworkView(org.cytoscape.view.model.CyNetworkView) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 29 with ComponentAdapter

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

the class VisualPropertySheetItem method getShowMappingBtn.

protected ExpandCollapseButton getShowMappingBtn() {
    if (expandCollapseBtn == null) {
        expandCollapseBtn = new ExpandCollapseButton(false, evt -> {
            if (getMappingPnl().isShowing())
                collapse();
            else
                expand();
        });
        final Dimension d = new Dimension(VALUE_ICON_WIDTH, VALUE_ICON_HEIGHT);
        expandCollapseBtn.setMinimumSize(d);
        expandCollapseBtn.setPreferredSize(d);
        expandCollapseBtn.setMaximumSize(d);
        expandCollapseBtn.setBorder(BorderFactory.createEmptyBorder(BUTTON_V_PAD, BUTTON_H_PAD, BUTTON_V_PAD, BUTTON_H_PAD));
        getMappingPnl().addComponentListener(new ComponentAdapter() {

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

            @Override
            public void componentHidden(final ComponentEvent ce) {
                if (expandCollapseBtn != null && expandCollapseBtn.isSelected())
                    expandCollapseBtn.setSelected(false);
            }
        });
    }
    return expandCollapseBtn;
}
Also used : Color(java.awt.Color) LockedValueState(org.cytoscape.view.vizmap.gui.internal.model.LockedValueState) UIManager(javax.swing.UIManager) Cursor(java.awt.Cursor) JToggleButton(javax.swing.JToggleButton) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) Point(java.awt.Point) Border(javax.swing.border.Border) IconManager(org.cytoscape.util.swing.IconManager) MouseWheelEvent(java.awt.event.MouseWheelEvent) Locale(java.util.Locale) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) MouseAdapter(java.awt.event.MouseAdapter) Property(com.l2fprod.common.propertysheet.Property) BorderLayout(java.awt.BorderLayout) ButtonModel(javax.swing.ButtonModel) KeyStroke(javax.swing.KeyStroke) ContinuousMappingEditorPanel(org.cytoscape.view.vizmap.gui.internal.view.editor.mappingeditor.ContinuousMappingEditorPanel) ToolTipManager(javax.swing.ToolTipManager) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) ComponentEvent(java.awt.event.ComponentEvent) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) Box(javax.swing.Box) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) Dimension(java.awt.Dimension) AbstractAction(javax.swing.AbstractAction) Paint(java.awt.Paint) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) Graphics(java.awt.Graphics) JCheckBox(javax.swing.JCheckBox) PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) ActionListener(java.awt.event.ActionListener) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) BasicButtonUI(javax.swing.plaf.basic.BasicButtonUI) SwingConstants(javax.swing.SwingConstants) EmptyIcon(org.jdesktop.swingx.icon.EmptyIcon) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) FocusAdapter(java.awt.event.FocusAdapter) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) TableCellEditor(javax.swing.table.TableCellEditor) Graphics2D(java.awt.Graphics2D) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) Container(java.awt.Container) AbstractButton(javax.swing.AbstractButton) ActionMap(javax.swing.ActionMap) Collator(java.text.Collator) BoxLayout(javax.swing.BoxLayout) VisualProperty(org.cytoscape.view.model.VisualProperty) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) JScrollPane(javax.swing.JScrollPane) VisualPropertyUtil(org.cytoscape.view.vizmap.gui.internal.util.VisualPropertyUtil) FocusEvent(java.awt.event.FocusEvent) JLabel(javax.swing.JLabel) JScrollBar(javax.swing.JScrollBar) ServicesUtil(org.cytoscape.view.vizmap.gui.internal.util.ServicesUtil) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) GradientPaint(java.awt.GradientPaint) MouseWheelListener(java.awt.event.MouseWheelListener) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) InputMap(javax.swing.InputMap) Dimension(java.awt.Dimension) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 30 with ComponentAdapter

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

the class VisualPropertySheet method setItems.

public void setItems(final Set<VisualPropertySheetItem<?>> newItems) {
    // Remove current items
    vpItemMap.clear();
    depItemMap.clear();
    items.clear();
    if (newItems != null) {
        items.addAll(newItems);
        // Create the internal panel that contains the visual property editors
        final JPanel p = new JPanel(new GridBagLayout());
        final GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.gridx = 0;
        c.weightx = 1;
        // Add the visual property editors to the internal panel
        int y = 0;
        int minWidth = 120;
        for (final VisualPropertySheetItem<?> i : items) {
            c.gridy = y++;
            p.add(i, c);
            // Save it for future use
            if (i.getModel().getVisualPropertyDependency() == null)
                vpItemMap.put(i.getModel().getVisualProperty(), i);
            else
                depItemMap.put(i.getModel().getVisualPropertyDependency().getIdString(), i);
            // Add listeners
            i.addMouseListener(new MouseAdapter() {

                @Override
                public void mousePressed(final MouseEvent e) {
                    onMousePressedItem(e, i);
                }
            });
            if (i.getModel().isVisualMappingAllowed()) {
                i.addComponentListener(new ComponentAdapter() {

                    @Override
                    public void componentShown(final ComponentEvent e) {
                        updateCollapseExpandButtons();
                    }

                    @Override
                    public void componentHidden(final ComponentEvent e) {
                        if (selectionHead == i)
                            selectionHead = null;
                        if (selectionTail == i)
                            selectionTail = null;
                        updateCollapseExpandButtons();
                    }
                });
                i.addPropertyChangeListener("enabled", evt -> {
                    updateCollapseExpandButtons();
                });
                i.addPropertyChangeListener("expanded", evt -> {
                    updateCollapseExpandButtons();
                });
                i.getPropSheetPnl().getTable().addMouseListener(new MouseAdapter() {

                    @Override
                    public void mousePressed(final MouseEvent e) {
                        onMousePressedItem(e, i);
                    }
                });
            }
            minWidth = Math.max(minWidth, i.getPreferredSize().width);
        }
        // Add an empty panel to fill the vertical gap
        final JPanel fillPnl = new JPanel();
        fillPnl.setBackground(VisualPropertySheetItem.getBackgroundColor());
        c.fill = GridBagConstraints.BOTH;
        c.weighty = 1;
        p.add(fillPnl, c);
        fillPnl.addMouseListener(new MouseAdapter() {

            @Override
            @SuppressWarnings("unchecked")
            public void mouseClicked(final MouseEvent e) {
                if (// Deselect all items
                !e.isShiftDown() || e.isControlDown())
                    setSelectedItems(Collections.EMPTY_SET);
            }
        });
        getVpListScr().setViewportView(p);
        minWidth = Math.min((minWidth += 10), 400);
        getVpListScr().setMinimumSize(new Dimension(minWidth, 140));
        if (getParent() != null) {
            minWidth = Math.max(minWidth + 8, getParent().getMinimumSize().width);
            getParent().setMinimumSize(new Dimension(minWidth, getParent().getMinimumSize().height));
        }
    }
    updateCollapseExpandButtons();
    createMenuItems();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) MouseAdapter(java.awt.event.MouseAdapter) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentAdapter (java.awt.event.ComponentAdapter)96 ComponentEvent (java.awt.event.ComponentEvent)96 Dimension (java.awt.Dimension)17 ActionEvent (java.awt.event.ActionEvent)17 JPanel (javax.swing.JPanel)17 JButton (javax.swing.JButton)15 Component (java.awt.Component)14 MouseEvent (java.awt.event.MouseEvent)14 JLabel (javax.swing.JLabel)13 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 MouseAdapter (java.awt.event.MouseAdapter)11 Point (java.awt.Point)10 ActionListener (java.awt.event.ActionListener)10 AbstractAction (javax.swing.AbstractAction)8 BoxLayout (javax.swing.BoxLayout)8 JComponent (javax.swing.JComponent)8 JTable (javax.swing.JTable)8