589 * Get the role of this object.
590 *
591 * @return an instance of AccessibleRole describing the role of the
592 * object
593 * @see AccessibleRole
594 */
595 public AccessibleRole getAccessibleRole() {
596 return AccessibleRole.COLOR_CHOOSER;
597 }
598
599 } // inner class AccessibleJColorChooser
600 }
601
602
603 /*
604 * Class which builds a color chooser dialog consisting of
605 * a JColorChooser with "Ok", "Cancel", and "Reset" buttons.
606 *
607 * Note: This needs to be fixed to deal with localization!
608 */
609 class ColorChooserDialog extends JDialog {
610 private Color initialColor;
611 private JColorChooser chooserPane;
612 private JButton cancelButton;
613
614 public ColorChooserDialog(Dialog owner, String title, boolean modal,
615 Component c, JColorChooser chooserPane,
616 ActionListener okListener, ActionListener cancelListener)
617 throws HeadlessException {
618 super(owner, title, modal);
619 initColorChooserDialog(c, chooserPane, okListener, cancelListener);
620 }
621
622 public ColorChooserDialog(Frame owner, String title, boolean modal,
623 Component c, JColorChooser chooserPane,
624 ActionListener okListener, ActionListener cancelListener)
625 throws HeadlessException {
626 super(owner, title, modal);
627 initColorChooserDialog(c, chooserPane, okListener, cancelListener);
628 }
648 JPanel buttonPane = new JPanel();
649 buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
650 JButton okButton = new JButton(okString);
651 getRootPane().setDefaultButton(okButton);
652 okButton.getAccessibleContext().setAccessibleDescription(okString);
653 okButton.setActionCommand("OK");
654 okButton.addActionListener(new ActionListener() {
655 public void actionPerformed(ActionEvent e) {
656 hide();
657 }
658 });
659 if (okListener != null) {
660 okButton.addActionListener(okListener);
661 }
662 buttonPane.add(okButton);
663
664 cancelButton = new JButton(cancelString);
665 cancelButton.getAccessibleContext().setAccessibleDescription(cancelString);
666
667 // The following few lines are used to register esc to close the dialog
668 Action cancelKeyAction = new AbstractAction() {
669 public void actionPerformed(ActionEvent e) {
670 ((AbstractButton)e.getSource()).fireActionPerformed(e);
671 }
672 };
673 KeyStroke cancelKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
674 InputMap inputMap = cancelButton.getInputMap(JComponent.
675 WHEN_IN_FOCUSED_WINDOW);
676 ActionMap actionMap = cancelButton.getActionMap();
677 if (inputMap != null && actionMap != null) {
678 inputMap.put(cancelKeyStroke, "cancel");
679 actionMap.put("cancel", cancelKeyAction);
680 }
681 // end esc handling
682
683 cancelButton.setActionCommand("cancel");
684 cancelButton.addActionListener(new ActionListener() {
685 public void actionPerformed(ActionEvent e) {
686 hide();
687 }
712 getRootPane().setWindowDecorationStyle(JRootPane.COLOR_CHOOSER_DIALOG);
713 }
714 }
715 applyComponentOrientation(((c == null) ? getRootPane() : c).getComponentOrientation());
716
717 pack();
718 setLocationRelativeTo(c);
719
720 this.addWindowListener(new Closer());
721 }
722
723 public void show() {
724 initialColor = chooserPane.getColor();
725 super.show();
726 }
727
728 public void reset() {
729 chooserPane.setColor(initialColor);
730 }
731
732 class Closer extends WindowAdapter implements Serializable{
733 public void windowClosing(WindowEvent e) {
734 cancelButton.doClick(0);
735 Window w = e.getWindow();
736 w.hide();
737 }
738 }
739
740 static class DisposeOnClose extends ComponentAdapter implements Serializable{
741 public void componentHidden(ComponentEvent e) {
742 Window w = (Window)e.getComponent();
743 w.dispose();
744 }
745 }
746
747 }
748
749 class ColorTracker implements ActionListener, Serializable {
750 JColorChooser chooser;
751 Color color;
752
753 public ColorTracker(JColorChooser c) {
754 chooser = c;
755 }
756
757 public void actionPerformed(ActionEvent e) {
758 color = chooser.getColor();
759 }
760
761 public Color getColor() {
762 return color;
763 }
764 }
|
589 * Get the role of this object.
590 *
591 * @return an instance of AccessibleRole describing the role of the
592 * object
593 * @see AccessibleRole
594 */
595 public AccessibleRole getAccessibleRole() {
596 return AccessibleRole.COLOR_CHOOSER;
597 }
598
599 } // inner class AccessibleJColorChooser
600 }
601
602
603 /*
604 * Class which builds a color chooser dialog consisting of
605 * a JColorChooser with "Ok", "Cancel", and "Reset" buttons.
606 *
607 * Note: This needs to be fixed to deal with localization!
608 */
609 @SuppressWarnings("serial") // Superclass is not serializable across versions
610 class ColorChooserDialog extends JDialog {
611 private Color initialColor;
612 private JColorChooser chooserPane;
613 private JButton cancelButton;
614
615 public ColorChooserDialog(Dialog owner, String title, boolean modal,
616 Component c, JColorChooser chooserPane,
617 ActionListener okListener, ActionListener cancelListener)
618 throws HeadlessException {
619 super(owner, title, modal);
620 initColorChooserDialog(c, chooserPane, okListener, cancelListener);
621 }
622
623 public ColorChooserDialog(Frame owner, String title, boolean modal,
624 Component c, JColorChooser chooserPane,
625 ActionListener okListener, ActionListener cancelListener)
626 throws HeadlessException {
627 super(owner, title, modal);
628 initColorChooserDialog(c, chooserPane, okListener, cancelListener);
629 }
649 JPanel buttonPane = new JPanel();
650 buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
651 JButton okButton = new JButton(okString);
652 getRootPane().setDefaultButton(okButton);
653 okButton.getAccessibleContext().setAccessibleDescription(okString);
654 okButton.setActionCommand("OK");
655 okButton.addActionListener(new ActionListener() {
656 public void actionPerformed(ActionEvent e) {
657 hide();
658 }
659 });
660 if (okListener != null) {
661 okButton.addActionListener(okListener);
662 }
663 buttonPane.add(okButton);
664
665 cancelButton = new JButton(cancelString);
666 cancelButton.getAccessibleContext().setAccessibleDescription(cancelString);
667
668 // The following few lines are used to register esc to close the dialog
669 @SuppressWarnings("serial") // anonymous class
670 Action cancelKeyAction = new AbstractAction() {
671 public void actionPerformed(ActionEvent e) {
672 ((AbstractButton)e.getSource()).fireActionPerformed(e);
673 }
674 };
675 KeyStroke cancelKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
676 InputMap inputMap = cancelButton.getInputMap(JComponent.
677 WHEN_IN_FOCUSED_WINDOW);
678 ActionMap actionMap = cancelButton.getActionMap();
679 if (inputMap != null && actionMap != null) {
680 inputMap.put(cancelKeyStroke, "cancel");
681 actionMap.put("cancel", cancelKeyAction);
682 }
683 // end esc handling
684
685 cancelButton.setActionCommand("cancel");
686 cancelButton.addActionListener(new ActionListener() {
687 public void actionPerformed(ActionEvent e) {
688 hide();
689 }
714 getRootPane().setWindowDecorationStyle(JRootPane.COLOR_CHOOSER_DIALOG);
715 }
716 }
717 applyComponentOrientation(((c == null) ? getRootPane() : c).getComponentOrientation());
718
719 pack();
720 setLocationRelativeTo(c);
721
722 this.addWindowListener(new Closer());
723 }
724
725 public void show() {
726 initialColor = chooserPane.getColor();
727 super.show();
728 }
729
730 public void reset() {
731 chooserPane.setColor(initialColor);
732 }
733
734 @SuppressWarnings("serial") // JDK-implementation class
735 class Closer extends WindowAdapter implements Serializable{
736 public void windowClosing(WindowEvent e) {
737 cancelButton.doClick(0);
738 Window w = e.getWindow();
739 w.hide();
740 }
741 }
742
743 @SuppressWarnings("serial") // JDK-implementation class
744 static class DisposeOnClose extends ComponentAdapter implements Serializable{
745 public void componentHidden(ComponentEvent e) {
746 Window w = (Window)e.getComponent();
747 w.dispose();
748 }
749 }
750
751 }
752
753 @SuppressWarnings("serial") // JDK-implementation class
754 class ColorTracker implements ActionListener, Serializable {
755 JColorChooser chooser;
756 Color color;
757
758 public ColorTracker(JColorChooser c) {
759 chooser = c;
760 }
761
762 public void actionPerformed(ActionEvent e) {
763 color = chooser.getColor();
764 }
765
766 public Color getColor() {
767 return color;
768 }
769 }
|