Search in sources :

Example 6 with ComponentListener

use of java.awt.event.ComponentListener in project clusterMaker2 by RBVI.

the class ScatterPlotDialog method repaintScatterPlot.

public void repaintScatterPlot() {
    int pointSize = 2;
    try {
        pointSize = Integer.parseInt(textFieldPointSize.getText());
    } catch (NumberFormatException er) {
        JOptionPane.showMessageDialog(null, textFieldPointSize.getText() + " is not a number", "Error: Size of point", JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Execute when button is pressed
    container.remove(0);
    for (ComponentListener cl : container.getComponentListeners()) container.removeComponentListener(cl);
    int xAxis = 0;
    int yAxis = 1;
    if (variances != null) {
        xAxis = comboXAxis.getSelectedIndex();
        yAxis = comboYAxis.getSelectedIndex();
    }
    ScatterPlot scatterPlot = new ScatterPlot(manager, scores, loadings, xAxis, yAxis, pointColor, pointSize, loadingsColorMap, useLoadings);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.insets = new Insets(5, 5, 5, 5);
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    container.add(scatterPlot, constraints, 0);
    container.updateUI();
}
Also used : ComponentListener(java.awt.event.ComponentListener) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) Point(java.awt.Point)

Example 7 with ComponentListener

use of java.awt.event.ComponentListener in project logisim-evolution by reds-heig.

the class Analyzer method addTab.

private void addTab(int index, final JComponent comp) {
    final JScrollPane pane = new JScrollPane(comp, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    if (comp instanceof TableTab) {
        pane.setVerticalScrollBar(((TableTab) comp).getVerticalScrollBar());
    }
    pane.addComponentListener(new ComponentListener() {

        public void componentHidden(ComponentEvent arg0) {
        }

        public void componentMoved(ComponentEvent arg0) {
        }

        public void componentResized(ComponentEvent event) {
            int width = pane.getViewport().getWidth();
            comp.setSize(new Dimension(width, comp.getHeight()));
        }

        public void componentShown(ComponentEvent arg0) {
        }
    });
    tabbedPane.insertTab("Untitled", null, pane, null, index);
}
Also used : JScrollPane(javax.swing.JScrollPane) ComponentListener(java.awt.event.ComponentListener) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension)

Example 8 with ComponentListener

use of java.awt.event.ComponentListener in project chatty by chatty.

the class LiveStreamsList method addListeners.

private void addListeners() {
    ComponentListener cl = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            // Trick from kleopatra:
            // https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height
            // next line possible if list is of type JXList
            // list.invalidateCellSizeCache();
            // for core: force cache invalidation by temporarily setting fixed height
            setFixedCellHeight(10);
            setFixedCellHeight(-1);
        }
    };
    addComponentListener(cl);
    JListActionHelper.install(this, (a, l, s) -> {
        if (a == Action.CONTEXT_MENU) {
            StreamInfosContextMenu m = new StreamInfosContextMenu(s, true);
            for (ContextMenuListener cml : contextMenuListeners) {
                m.addContextMenuListener(cml);
            }
            lastContextMenu = m;
            m.show(this, l.x, l.y);
        } else if (a == Action.ENTER) {
            List<String> channels = new ArrayList<>();
            s.forEach(si -> channels.add(si.stream));
            for (ContextMenuListener cml : contextMenuListeners) {
                cml.streamsMenuItemClicked(new ActionEvent(s, 0, "join"), channels);
            }
        } else if (a == Action.DOUBLE_CLICK || a == Action.SPACE) {
            StreamInfo info = getSelectedValue();
            if (info != null && liveStreamListener != null) {
                liveStreamListener.liveStreamClicked(info);
            }
        }
    });
}
Also used : Color(java.awt.Color) Timer(java.util.Timer) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) Helper(chatty.Helper) ArrayList(java.util.ArrayList) Border(javax.swing.border.Border) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) ComponentListener(java.awt.event.ComponentListener) TitledBorder(javax.swing.border.TitledBorder) TimerTask(java.util.TimerTask) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) Set(java.util.Set) StreamInfo(chatty.util.api.StreamInfo) BorderFactory(javax.swing.BorderFactory) ComponentEvent(java.awt.event.ComponentEvent) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) Action(chatty.gui.components.JListActionHelper.Action) List(java.util.List) DateTime(chatty.util.DateTime) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) ComponentListener(java.awt.event.ComponentListener) StreamInfosContextMenu(chatty.gui.components.menus.StreamInfosContextMenu) ActionEvent(java.awt.event.ActionEvent) ContextMenuListener(chatty.gui.components.menus.ContextMenuListener) StreamInfo(chatty.util.api.StreamInfo) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 9 with ComponentListener

use of java.awt.event.ComponentListener in project briefcase by opendatakit.

the class ODKOptionPane method showErrorDialog.

public static void showErrorDialog(Component parentComponent, String errorString, String title) {
    // create a n-character wide label for aiding layout calculations...
    // the dialog box will display this width of text.
    JLabel t = new JLabel("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
    JTextArea textArea = new JTextArea(errorString);
    textArea.setEditable(false);
    // same as JLabel
    textArea.setFont(t.getFont());
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    // same as JLabel
    textArea.setBackground(t.getBackground());
    // textArea.setBackground(Color.white); // same as JLabel
    // same as JLabel
    textArea.setForeground(t.getForeground());
    final JScrollPane scrollPane = new JScrollPane(textArea);
    // don't show the gray border of the scroll pane
    // unless we are showing the scroll bar, in which case we do show it.
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.getVerticalScrollBar().addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent component) {
            if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
                scrollPane.setBorder(BorderFactory.createEmptyBorder());
            }
        }

        @Override
        public void componentMoved(ComponentEvent component) {
        }

        @Override
        public void componentResized(ComponentEvent component) {
        }

        @Override
        public void componentShown(ComponentEvent component) {
            if (component.getComponent().equals(scrollPane.getVerticalScrollBar())) {
                scrollPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));
            }
        }
    });
    // set preferred and minimum widths of the scroll pane to
    // the width of the 't' label above with 5 lines within the scroll area.
    Dimension pref = t.getPreferredSize();
    pref.setSize(pref.getWidth(), 5.3 * pref.getHeight());
    scrollPane.setMinimumSize(pref);
    scrollPane.setPreferredSize(pref);
    JOptionPane.showMessageDialog(parentComponent, scrollPane, title, JOptionPane.ERROR_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) ComponentListener(java.awt.event.ComponentListener) JTextArea(javax.swing.JTextArea) JLabel(javax.swing.JLabel) ComponentEvent(java.awt.event.ComponentEvent) Dimension(java.awt.Dimension)

Example 10 with ComponentListener

use of java.awt.event.ComponentListener in project Universal-G-Code-Sender by winder.

the class ExperimentalWindow method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    // Fix look and feel to use CMD+C/X/V/A instead of CTRL
    if (SystemUtils.IS_OS_MAC) {
        Collection<InputMap> ims = new ArrayList<>();
        ims.add((InputMap) UIManager.get("TextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextArea.focusInputMap"));
        ims.add((InputMap) UIManager.get("EditorPane.focusInputMap"));
        ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("PasswordField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextPane.focusInputMap"));
        int c = KeyEvent.VK_C;
        int v = KeyEvent.VK_V;
        int x = KeyEvent.VK_X;
        int a = KeyEvent.VK_A;
        int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        for (InputMap im : ims) {
            im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction);
            im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction);
            im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction);
            im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction);
        }
    }
    /* Create the form */
    final ExperimentalWindow mw = new ExperimentalWindow();
    /* Apply the settings to the ExperimentalWindow bofore showing it */
    mw.setSize(mw.backend.getSettings().getMainWindowSettings().width, mw.backend.getSettings().getMainWindowSettings().height);
    mw.setLocation(mw.backend.getSettings().getMainWindowSettings().xLocation, mw.backend.getSettings().getMainWindowSettings().yLocation);
    mw.addComponentListener(new ComponentListener() {

        @Override
        public void componentResized(ComponentEvent ce) {
            mw.backend.getSettings().getMainWindowSettings().height = ce.getComponent().getSize().height;
            mw.backend.getSettings().getMainWindowSettings().width = ce.getComponent().getSize().width;
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
            mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y;
        }

        @Override
        public void componentShown(ComponentEvent ce) {
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
        }
    });
    /* Display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            mw.setVisible(true);
        }
    });
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            mw.connectionPanel.saveSettings();
            mw.commandPanel.saveSettings();
            if (mw.pendantUI != null) {
                mw.pendantUI.stop();
            }
        }
    });
    // Check command line for a file to open.
    boolean open = false;
    for (String arg : args) {
        if (open) {
            try {
                mw.backend.setGcodeFile(new File(arg));
                open = false;
            } catch (Exception ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            }
        }
        if (arg.equals("--open") || arg.equals("-o")) {
            open = true;
        }
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) ArrayList(java.util.ArrayList) javax.swing(javax.swing) ComponentEvent(java.awt.event.ComponentEvent) File(java.io.File)

Aggregations

ComponentListener (java.awt.event.ComponentListener)18 ComponentEvent (java.awt.event.ComponentEvent)14 Component (java.awt.Component)4 Dimension (java.awt.Dimension)4 JScrollPane (javax.swing.JScrollPane)4 Point (java.awt.Point)3 JLabel (javax.swing.JLabel)3 JTextArea (javax.swing.JTextArea)3 ComponentAdapter (java.awt.event.ComponentAdapter)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 javax.swing (javax.swing)2 DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)2 Helper (chatty.Helper)1 Action (chatty.gui.components.JListActionHelper.Action)1 ContextMenuListener (chatty.gui.components.menus.ContextMenuListener)1 StreamInfosContextMenu (chatty.gui.components.menus.StreamInfosContextMenu)1