Search in sources :

Example 21 with ComponentEvent

use of java.awt.event.ComponentEvent in project android by JetBrains.

the class NetworkCaptureSegment method createCaptureTable.

@NotNull
private JTable createCaptureTable() {
    JBTable table = new JBTable(new NetworkCaptureTableModel());
    table.setDefaultRenderer(StateChart.class, (t, value, isSelected, hasFocus, row, column) -> myCharts.get(row));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(e -> {
        if (table.getSelectedRow() < myDataList.size()) {
            myDetailedViewListener.showDetailedConnection(myDataList.get(table.getSelectedRow()));
        }
    });
    table.setFont(AdtUiUtils.DEFAULT_FONT);
    table.setRowHeight(myRowHeight);
    table.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            table.getColumnModel().getColumn(Column.TIMELINE.ordinal()).setPreferredWidth(myCaptureTable.getWidth() / 2);
        }
    });
    return table;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) JBTable(com.intellij.ui.table.JBTable) ComponentAdapter(java.awt.event.ComponentAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with ComponentEvent

use of java.awt.event.ComponentEvent in project JWildfire by thargor6.

the class Buffer method addImageBuffer.

private void addImageBuffer(JDesktopPane pDesktop) {
    final int TRANSFORMERS_WIDTH = 300;
    // left + right border
    final int X_BORDER = 5 + 5 + TRANSFORMERS_WIDTH;
    // top + bottom border
    final int Y_BORDER = 30 + 5;
    int imageWidth = img.getImageWidth();
    int imageHeight = img.getImageHeight();
    int maxWidth, maxHeight;
    if (pDesktop != null) {
        maxWidth = pDesktop.getWidth() - X_BORDER;
        maxHeight = pDesktop.getHeight() - Y_BORDER;
    } else {
        maxWidth = imageWidth;
        maxHeight = imageHeight;
    }
    int panelWidth;
    if ((imageWidth <= maxWidth) && (imageHeight <= maxHeight))
        panelWidth = imageWidth;
    else if ((imageWidth > maxWidth) && (imageHeight <= maxHeight))
        panelWidth = maxWidth;
    else if ((imageWidth <= maxWidth) && (imageHeight > maxHeight))
        panelWidth = (int) (((double) maxHeight / (double) imageHeight) * (double) imageWidth + 0.5);
    else {
        double sclWidth = (double) maxWidth / (double) imageWidth;
        double sclHeight = (double) maxHeight / (double) imageHeight;
        double scl = (sclWidth < sclHeight) ? sclWidth : sclHeight;
        panelWidth = (int) (scl * (double) imageWidth + 0.5);
    }
    if (pDesktop != null) {
        pnl = new ImagePanel(img, 0, 0, panelWidth);
        pnl.setLayout(null);
        internalFrame = new JInternalFrame();
        internalFrame.setTitle(getTitle(panelWidth));
        internalFrame.setClosable(true);
        internalFrame.setMaximizable(true);
        internalFrame.setIconifiable(true);
        internalFrame.setResizable(true);
        internalFrame.setVisible(true);
        internalFrame.setContentPane(pnl);
        internalFrame.pack();
        pDesktop.add(internalFrame, null);
        internalFrame.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent arg0) {
            // empty
            }

            @Override
            public void componentMoved(ComponentEvent arg0) {
            // empty
            }

            @Override
            public void componentResized(ComponentEvent evt) {
                Component c = (Component) evt.getSource();
                Dimension newSize = c.getSize();
                int imgWidth = img.getImageWidth();
                int windowWidth = newSize.width;
                int newWidth;
                if (Math.abs(windowWidth - imgWidth) < imgWidth * 0.03)
                    newWidth = imgWidth;
                else
                    newWidth = windowWidth;
                pnl.setImage(img, 0, 0, newWidth);
                internalFrame.setTitle(getTitle(newWidth));
            }

            @Override
            public void componentShown(ComponentEvent arg0) {
            // empty
            }
        });
        internalFrame.toFront();
        pDesktop.repaint();
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension) Component(java.awt.Component) JInternalFrame(javax.swing.JInternalFrame)

Example 23 with ComponentEvent

use of java.awt.event.ComponentEvent 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 24 with ComponentEvent

use of java.awt.event.ComponentEvent 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 25 with ComponentEvent

use of java.awt.event.ComponentEvent 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

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