Search in sources :

Example 16 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project sling by apache.

the class Util method setupComponentLocationSize.

static void setupComponentLocationSize(final Component comp, final String propX, final String propY, final String propWidth, final String propHeight, final int defaultX, final int defaultY, final int defaultWidth, final int defaultHeight) {
    comp.setLocation(getPreference(propX, defaultY), getPreference(propY, defaultX));
    comp.setSize(getPreference(propWidth, defaultWidth), getPreference(propHeight, defaultHeight));
    comp.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentMoved(ComponentEvent e) {
            setPreference(propX, e.getComponent().getX(), false);
            setPreference(propY, e.getComponent().getY(), true);
        }

        @Override
        public void componentResized(ComponentEvent e) {
            setPreference(propWidth, e.getComponent().getWidth(), false);
            setPreference(propHeight, e.getComponent().getHeight(), true);
        }
    });
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 17 with ComponentAdapter

use of java.awt.event.ComponentAdapter in project JMRI by JMRI.

the class DccLocoAddressSelector method getCombinedJPanel.

/* Get a JPanel containing the combined selector.
     *
     * <P>
     * Because Swing only allows a component to be inserted in one
     * container, this can only be done once
     */
public JPanel getCombinedJPanel() {
    if (panelUsed) {
        log.error("getCombinedPanel invoked after panel already requested");
        return null;
    }
    if (textUsed) {
        log.error("getCombinedPanel invoked after text already requested");
        return null;
    }
    if (boxUsed) {
        log.error("getCombinedPanel invoked after text already requested");
        return null;
    }
    panelUsed = true;
    if (varFontSize) {
        text.setFont(new Font("", Font.PLAIN, 32));
    }
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(text);
    if (!locked || ((InstanceManager.getNullableDefault(jmri.ThrottleManager.class) != null) && !InstanceManager.throttleManagerInstance().addressTypeUnique())) {
        p.add(box);
    }
    p.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            changeFontSizes();
        }
    });
    return p;
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) ComponentEvent(java.awt.event.ComponentEvent) Font(java.awt.Font) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 18 with ComponentAdapter

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

the class StateChartVisualTest method createMockTimeline.

private JLayeredPane createMockTimeline() {
    JLayeredPane timelinePane = new JLayeredPane();
    timelinePane.add(mNetworkStatusChart);
    timelinePane.add(mRadioStateChart);
    timelinePane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            JLayeredPane host = (JLayeredPane) e.getComponent();
            if (host != null) {
                Dimension dim = host.getSize();
                int numChart = 0;
                for (Component c : host.getComponents()) {
                    if (c instanceof AxisComponent) {
                        AxisComponent axis = (AxisComponent) c;
                        switch(axis.getOrientation()) {
                            case LEFT:
                                axis.setBounds(0, 0, AXIS_SIZE, dim.height);
                                break;
                            case BOTTOM:
                                axis.setBounds(0, dim.height - AXIS_SIZE, dim.width, AXIS_SIZE);
                                break;
                            case RIGHT:
                                axis.setBounds(dim.width - AXIS_SIZE, 0, AXIS_SIZE, dim.height);
                                break;
                            case TOP:
                                axis.setBounds(0, 0, dim.width, AXIS_SIZE);
                                break;
                        }
                    } else if (c instanceof StateChart) {
                        int y = numChart % 2 == 0 ? AXIS_SIZE : dim.height - AXIS_SIZE * 2;
                        c.setBounds(AXIS_SIZE, y, dim.width - AXIS_SIZE * 2, AXIS_SIZE);
                        numChart++;
                    }
                }
            }
        }
    });
    return timelinePane;
}
Also used : AxisComponent(com.android.tools.adtui.AxisComponent) ComponentEvent(java.awt.event.ComponentEvent) AxisComponent(com.android.tools.adtui.AxisComponent) AnimatedComponent(com.android.tools.adtui.AnimatedComponent) StateChart(com.android.tools.adtui.chart.StateChart) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 19 with ComponentAdapter

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

the class AxisLineChartVisualTest method createMockTimeline.

private JLayeredPane createMockTimeline() {
    JBLayeredPane timelinePane = new JBLayeredPane();
    timelinePane.add(mMemoryAxis1);
    timelinePane.add(mMemoryAxis2);
    timelinePane.add(mTimeAxis);
    timelinePane.add(mLineChart);
    timelinePane.add(mSelection);
    timelinePane.add(mGrid);
    timelinePane.add(mScrollbar);
    // TODO move to ProfilerOverviewVisualTest.
    JBPanel labelPanel = new JBPanel();
    labelPanel.setLayout(new FlowLayout());
    labelPanel.add(mLegendComponent);
    timelinePane.add(labelPanel);
    timelinePane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            JLayeredPane host = (JLayeredPane) e.getComponent();
            if (host != null) {
                Dimension dim = host.getSize();
                for (Component c : host.getComponents()) {
                    if (c instanceof AxisComponent) {
                        AxisComponent axis = (AxisComponent) c;
                        switch(axis.getOrientation()) {
                            case LEFT:
                                axis.setBounds(0, 0, AXIS_SIZE, dim.height);
                                break;
                            case BOTTOM:
                                axis.setBounds(0, dim.height - AXIS_SIZE, dim.width, AXIS_SIZE);
                                break;
                            case RIGHT:
                                axis.setBounds(dim.width - AXIS_SIZE, 0, AXIS_SIZE, dim.height);
                                break;
                            case TOP:
                                axis.setBounds(0, 0, dim.width, AXIS_SIZE);
                                break;
                        }
                    } else if (c instanceof RangeScrollbar) {
                        int sbHeight = c.getPreferredSize().height;
                        c.setBounds(0, dim.height - sbHeight, dim.width, sbHeight);
                    } else {
                        c.setBounds(AXIS_SIZE, AXIS_SIZE, dim.width - AXIS_SIZE * 2, dim.height - AXIS_SIZE * 2);
                    }
                }
            }
        }
    });
    return timelinePane;
}
Also used : JBLayeredPane(com.intellij.ui.components.JBLayeredPane) ComponentEvent(java.awt.event.ComponentEvent) JBPanel(com.intellij.ui.components.JBPanel) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 20 with ComponentAdapter

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

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