java.awt.CheckboxGroup Java Examples

The following examples show how to use java.awt.CheckboxGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrawTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #2
Source File: LWCheckboxPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #3
Source File: LWCheckboxPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #4
Source File: CheckboxOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Checkbox.getCheckboxGroup()} through queue
 */
public CheckboxGroup getCheckboxGroup() {
    return (runMapping(new MapAction<CheckboxGroup>("getCheckboxGroup") {
        @Override
        public CheckboxGroup map() {
            return ((Checkbox) getSource()).getCheckboxGroup();
        }
    }));
}
 
Example #5
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #6
Source File: LWCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #7
Source File: LWCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #8
Source File: DrawTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #9
Source File: LWCheckboxPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #10
Source File: LWCheckboxPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #11
Source File: DrawTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #12
Source File: LWCheckboxPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #13
Source File: LWCheckboxPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #14
Source File: DrawTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #15
Source File: CheckboxOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Checkbox.setCheckboxGroup(CheckboxGroup)} through queue
 */
public void setCheckboxGroup(final CheckboxGroup grp) {
    runMapping(new MapVoidAction("setCheckboxGroup") {
        @Override
        public void map() {
            ((Checkbox) getSource()).setCheckboxGroup(grp);
        }
    });
}
 
Example #16
Source File: LWCheckboxPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #17
Source File: DrawTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #18
Source File: LWCheckboxPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #19
Source File: LWCheckboxPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #20
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #21
Source File: LWCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #22
Source File: LWCheckboxPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #23
Source File: DrawTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #24
Source File: LWCheckboxPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #25
Source File: LWCheckboxPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #26
Source File: DrawTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #27
Source File: DrawTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
    this.target = target;
    setLayout(new FlowLayout());
    setBackground(Color.lightGray);
    target.setForeground(Color.red);
    CheckboxGroup group = new CheckboxGroup();
    Checkbox b;
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.red);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.green);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.blue);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.pink);
    add(b = new Checkbox(null, group, false));
    b.addItemListener(this);
    b.setForeground(Color.orange);
    add(b = new Checkbox(null, group, true));
    b.addItemListener(this);
    b.setForeground(Color.black);
    target.setForeground(b.getForeground());
    Choice shapes = new Choice();
    shapes.addItemListener(this);
    shapes.addItem("Lines");
    shapes.addItem("Points");
    shapes.setBackground(Color.lightGray);
    add(shapes);
}
 
Example #28
Source File: LWCheckboxPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}
 
Example #29
Source File: LWCheckboxPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setCheckboxGroup(final CheckboxGroup g) {
    synchronized (getDelegateLock()) {
        getDelegate().getCurrentButton().removeItemListener(this);
        getDelegate().setRadioButton(g != null);
        getDelegate().getCurrentButton().addItemListener(this);
    }
    repaintPeer();
}
 
Example #30
Source File: LWCheckboxPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(final ItemEvent e) {
    // group.setSelectedCheckbox() will repaint the component
    // to let LWCheckboxPeer correctly handle it we should call it
    // after the current event is processed
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            boolean postEvent = true;
            final CheckboxGroup group = getTarget().getCheckboxGroup();
            if (group != null) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (group.getSelectedCheckbox() != getTarget()) {
                        group.setSelectedCheckbox(getTarget());
                    } else {
                        postEvent = false;
                    }
                } else {
                    postEvent = false;
                    if (group.getSelectedCheckbox() == getTarget()) {
                        // Don't want to leave the group with no selected
                        // checkbox.
                        getTarget().setState(true);
                    }
                }
            } else {
                getTarget().setState(e.getStateChange()
                                     == ItemEvent.SELECTED);
            }
            if (postEvent) {
                postEvent(new ItemEvent(getTarget(),
                                        ItemEvent.ITEM_STATE_CHANGED,
                                        getTarget().getLabel(),
                                        e.getStateChange()));
            }
        }
    });
}