Search in sources :

Example 31 with AbstractButton

use of javax.swing.AbstractButton in project jdk8u_jdk by JetBrains.

the class Test6524757 method create.

private static Object[] create() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    // show color chooser
    JColorChooser chooser = new JColorChooser();
    JDialog dialog = JColorChooser.createDialog(frame, null, false, chooser, null, null);
    dialog.setVisible(true);
    // process all values
    List<Object> list = new ArrayList<Object>(KEYS.length);
    Component component = getC(getC(dialog.getLayeredPane(), 0), 1);
    AbstractButton ok = (AbstractButton) getC(component, 0);
    AbstractButton cancel = (AbstractButton) getC(component, 1);
    AbstractButton reset = (AbstractButton) getC(component, 2);
    list.add(ok.getText());
    list.add(cancel.getText());
    list.add(reset.getText());
    list.add(Integer.valueOf(reset.getMnemonic()));
    for (int i = 0; i < 5; i++) {
        AbstractColorChooserPanel panel = (AbstractColorChooserPanel) getC(getC(getC(chooser, 0), i), 0);
        list.add(panel.getDisplayName());
        list.add(Integer.valueOf(panel.getMnemonic()));
        if (i == 0) {
            JLabel label = (JLabel) getC(getC(panel, 0), 1);
            JPanel upper = (JPanel) getC(getC(getC(panel, 0), 0), 0);
            JPanel lower = (JPanel) getC(getC(getC(panel, 0), 2), 0);
            addSize(list, upper, 1, 1, 31, 9);
            list.add(label.getText());
            addSize(list, lower, 1, 1, 5, 7);
        } else {
            Component container = getC(panel, 0);
            for (int j = 0; j < 3; j++) {
                AbstractButton button = (AbstractButton) getC(container, j);
                list.add(button.getText());
            }
            JLabel label = (JLabel) getC(container, 3);
            list.add(label.getText());
            if (i == 4) {
                label = (JLabel) getC(container, 4);
                list.add(label.getText());
            }
            if (i == 3) {
                label = (JLabel) getC(panel, 1);
                list.add(label.getText());
                list.add(Integer.valueOf(label.getDisplayedMnemonic()));
            }
        }
    }
    // close dialog
    dialog.setVisible(false);
    dialog.dispose();
    // close frame
    frame.setVisible(false);
    frame.dispose();
    return list.toArray();
}
Also used : JPanel(javax.swing.JPanel) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) AbstractButton(javax.swing.AbstractButton) JFrame(javax.swing.JFrame) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) JComponent(javax.swing.JComponent) Component(java.awt.Component) JColorChooser(javax.swing.JColorChooser) JDialog(javax.swing.JDialog)

Example 32 with AbstractButton

use of javax.swing.AbstractButton in project jdk8u_jdk by JetBrains.

the class bug7199708 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    final File folder = createLargeFolder();
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser(folder);
            fileChooser.showSaveDialog(null);
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            final String detailsTooltip = UIManager.getString("FileChooser." + "detailsViewButtonToolTipText", fileChooser.getLocale());
            doAction(fileChooser, new ComponentAction() {

                @Override
                public boolean accept(Component component) {
                    return (component instanceof AbstractButton) && detailsTooltip.equals(((AbstractButton) component).getToolTipText());
                }

                @Override
                public void perform(Component component) {
                    ((AbstractButton) component).doClick();
                }
            });
            doAction(fileChooser, new ComponentAction() {

                @Override
                public boolean accept(Component component) {
                    return (component instanceof JTable);
                }

                @Override
                public void perform(Component component) {
                    Point tableLocation = component.getLocationOnScreen();
                    locationX = (int) tableLocation.getX();
                    locationY = (int) tableLocation.getY();
                    width = (int) fileChooser.getBounds().getWidth();
                }
            });
        }
    });
    toolkit.realSync();
    int d = 25;
    for (int i = 0; i < width / d; i++) {
        robot.mouseMove(locationX + i * d, locationY + 5);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();
    }
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);
}
Also used : AbstractButton(javax.swing.AbstractButton) JFileChooser(javax.swing.JFileChooser) JTable(javax.swing.JTable) SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Component(java.awt.Component) Robot(java.awt.Robot) File(java.io.File) Point(java.awt.Point)

Example 33 with AbstractButton

use of javax.swing.AbstractButton in project JMRI by JMRI.

the class JmriJFrameServlet method sendClick.

void sendClick(String name, Component c, int xg, int yg, Container FrameContentPane) {
    // global positions
    int x = xg - c.getLocation().x;
    int y = yg - c.getLocation().y;
    // log.debug("component is {}", c);
    log.debug("Local click at {},{}", x, y);
    if (c.getClass().equals(JButton.class)) {
        ((AbstractButton) c).doClick();
    } else if (c.getClass().equals(JCheckBox.class)) {
        ((AbstractButton) c).doClick();
    } else if (c.getClass().equals(JRadioButton.class)) {
        ((AbstractButton) c).doClick();
    } else if (MouseListener.class.isAssignableFrom(c.getClass())) {
        log.debug("Invoke directly on MouseListener, at {},{}", x, y);
        sendClickSequence((MouseListener) c, c, x, y);
    } else if (c instanceof jmri.jmrit.display.MultiSensorIcon) {
        log.debug("Invoke Clicked on MultiSensorIcon");
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
        0, // modifiers
        0, // this component expects global positions for some reason
        xg, // this component expects global positions for some reason
        yg, // one click
        1, // not a popup
        false);
        ((Positionable) c).doMouseClicked(e);
    } else if (Positionable.class.isAssignableFrom(c.getClass())) {
        log.debug("Invoke Pressed, Released and Clicked on Positionable");
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMousePressed(e);
        e = new MouseEvent(c, MouseEvent.MOUSE_RELEASED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMouseReleased(e);
        e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMouseClicked(e);
    } else {
        MouseListener[] la = c.getMouseListeners();
        log.debug("Invoke {} contained mouse listeners", la.length);
        log.debug("component is {}", c);
        // y -= (int)(pc.getY() - pf.getY());
        for (MouseListener ml : la) {
            log.debug("Send click sequence at {},{}", x, y);
            sendClickSequence(ml, c, x, y);
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) AbstractButton(javax.swing.AbstractButton) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) Positionable(jmri.jmrit.display.Positionable)

Example 34 with AbstractButton

use of javax.swing.AbstractButton in project processdash by dtuma.

the class BoundRadioButtons method updateFromMap.

public void updateFromMap() {
    Object value = map.get(this.propertyName);
    boolean buttonFound = false;
    if (value != null && value instanceof String) {
        Enumeration<AbstractButton> buttons = buttonGroup.getElements();
        while (buttons.hasMoreElements() && !buttonFound) {
            AbstractButton button = buttons.nextElement();
            if (((String) value).equalsIgnoreCase(button.getActionCommand())) {
                button.setSelected(true);
                buttonFound = true;
            }
        }
    }
    if (!buttonFound) {
        Enumeration<AbstractButton> buttons = buttonGroup.getElements();
        while (buttons.hasMoreElements() && !buttonFound) {
            AbstractButton button = buttons.nextElement();
            Option option = (Option) button.getClientProperty(Option.class);
            if (option != null && option.isDefaultOption) {
                button.setSelected(true);
                buttonFound = true;
            }
        }
    }
}
Also used : AbstractButton(javax.swing.AbstractButton)

Example 35 with AbstractButton

use of javax.swing.AbstractButton in project processdash by dtuma.

the class BoundRadioButtons method getButtonPanel.

private JPanel getButtonPanel(Map<String, Option> options) {
    JPanel buttonPannel = new JPanel(new GridLayout(0, 1));
    buttonGroup = new ButtonGroup();
    JRadioButton button = null;
    Option option = null;
    for (Map.Entry<String, Option> optionDefinition : options.entrySet()) {
        option = optionDefinition.getValue();
        button = new JRadioButton(option.label);
        button.setActionCommand(option.value);
        button.addActionListener(this);
        button.setSelected(option.isDefaultOption);
        button.putClientProperty(Option.class, option);
        buttonGroup.add(button);
        buttonPannel.add(button);
    }
    if (buttonGroup.getSelection() == null) {
        // Since no button is selected, we select the first one
        Enumeration<AbstractButton> buttons = buttonGroup.getElements();
        if (buttons.hasMoreElements()) {
            buttons.nextElement().setSelected(true);
        }
    }
    return buttonPannel;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JRadioButton(javax.swing.JRadioButton) AbstractButton(javax.swing.AbstractButton) ButtonGroup(javax.swing.ButtonGroup) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

AbstractButton (javax.swing.AbstractButton)50 JLabel (javax.swing.JLabel)8 JPanel (javax.swing.JPanel)8 Component (java.awt.Component)7 ButtonModel (javax.swing.ButtonModel)7 JRadioButton (javax.swing.JRadioButton)5 JButton (javax.swing.JButton)4 Dimension (java.awt.Dimension)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 NotConfigurableException (org.knime.core.node.NotConfigurableException)3 FlowLayout (java.awt.FlowLayout)2 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 MouseEvent (java.awt.event.MouseEvent)2 JComboBox (javax.swing.JComboBox)2 JComponent (javax.swing.JComponent)2 JFileChooser (javax.swing.JFileChooser)2 JTextField (javax.swing.JTextField)2