32 import javax.swing.*;
33 import javax.swing.plaf.*;
34 import javax.swing.event.InternalFrameEvent;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.beans.PropertyVetoException;
38 import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
39 import static java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST;
40
41 import sun.swing.DefaultLookup;
42
43 /**
44 * The class that manages a basic title bar
45 * <p>
46 * <strong>Warning:</strong>
47 * Serialized objects of this class will not be compatible with
48 * future Swing releases. The current serialization support is
49 * appropriate for short term storage or RMI between applications running
50 * the same version of Swing. As of 1.4, support for long term storage
51 * of all JavaBeans™
52 * has been added to the <code>java.beans</code> package.
53 * Please see {@link java.beans.XMLEncoder}.
54 *
55 * @author David Kloba
56 * @author Steve Wilson
57 */
58 @SuppressWarnings("serial") // Same-version serialization only
59 public class BasicInternalFrameTitlePane extends JComponent
60 {
61 /**
62 * The instance of {@code JMenuBar}.
63 */
64 protected JMenuBar menuBar;
65 /**
66 * The iconify button.
67 */
68 protected JButton iconButton;
69 /**
70 * The maximize button.
71 */
72 protected JButton maxButton;
703 x = (leftToRight) ? w - 16 - 2 : 2;
704
705 if (frame.isClosable()) {
706 closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
707 x += (leftToRight) ? -(16 + 2) : 16 + 2;
708 }
709
710 if (frame.isMaximizable()) {
711 maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
712 x += (leftToRight) ? -(16 + 2) : 16 + 2;
713 }
714
715 if (frame.isIconifiable()) {
716 iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
717 }
718 }
719 }
720
721 /**
722 * This class should be treated as a "protected" inner class.
723 * Instantiate it only within subclasses of <code>Foo</code>.
724 */
725 public class PropertyChangeHandler implements PropertyChangeListener {
726 // NOTE: This class exists only for backward compatibility. All
727 // its functionality has been moved into Handler. If you need to add
728 // new functionality add it to the Handler, but make sure this
729 // class calls into the Handler.
730 public void propertyChange(PropertyChangeEvent evt) {
731 getHandler().propertyChange(evt);
732 }
733 }
734
735 /**
736 * This class should be treated as a "protected" inner class.
737 * Instantiate it only within subclasses of <code>Foo</code>.
738 */
739 public class TitlePaneLayout implements LayoutManager {
740 // NOTE: This class exists only for backward compatibility. All
741 // its functionality has been moved into Handler. If you need to add
742 // new functionality add it to the Handler, but make sure this
743 // class calls into the Handler.
744 public void addLayoutComponent(String name, Component c) {
745 getHandler().addLayoutComponent(name, c);
746 }
747
748 public void removeLayoutComponent(Component c) {
749 getHandler().removeLayoutComponent(c);
750 }
751
752 public Dimension preferredLayoutSize(Container c) {
753 return getHandler().preferredLayoutSize(c);
754 }
755
756 public Dimension minimumLayoutSize(Container c) {
757 return getHandler().minimumLayoutSize(c);
758 }
759
760 public void layoutContainer(Container c) {
761 getHandler().layoutContainer(c);
762 }
763 }
764
765 /**
766 * This class should be treated as a "protected" inner class.
767 * Instantiate it only within subclasses of <code>Foo</code>.
768 */
769 public class CloseAction extends AbstractAction {
770 /**
771 * Constructs a new instance of a {@code CloseAction}.
772 */
773 public CloseAction() {
774 super(UIManager.getString(
775 "InternalFrameTitlePane.closeButtonText"));
776 }
777
778 public void actionPerformed(ActionEvent e) {
779 if(frame.isClosable()) {
780 frame.doDefaultCloseAction();
781 }
782 }
783 } // end CloseAction
784
785 /**
786 * This class should be treated as a "protected" inner class.
787 * Instantiate it only within subclasses of <code>Foo</code>.
788 */
789 public class MaximizeAction extends AbstractAction {
790 /**
791 * Constructs a new instance of a {@code MaximizeAction}.
792 */
793 public MaximizeAction() {
794 super(UIManager.getString(
795 "InternalFrameTitlePane.maximizeButtonText"));
796 }
797
798 public void actionPerformed(ActionEvent evt) {
799 if (frame.isMaximizable()) {
800 if (frame.isMaximum() && frame.isIcon()) {
801 try {
802 frame.setIcon(false);
803 } catch (PropertyVetoException e) { }
804 } else if (!frame.isMaximum()) {
805 try {
806 frame.setMaximum(true);
807 } catch (PropertyVetoException e) { }
808 } else {
809 try {
810 frame.setMaximum(false);
811 } catch (PropertyVetoException e) { }
812 }
813 }
814 }
815 }
816
817 /**
818 * This class should be treated as a "protected" inner class.
819 * Instantiate it only within subclasses of <code>Foo</code>.
820 */
821 public class IconifyAction extends AbstractAction {
822 /**
823 * Constructs a new instance of an {@code IconifyAction}.
824 */
825 public IconifyAction() {
826 super(UIManager.getString(
827 "InternalFrameTitlePane.minimizeButtonText"));
828 }
829
830 public void actionPerformed(ActionEvent e) {
831 if(frame.isIconifiable()) {
832 if(!frame.isIcon()) {
833 try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
834 } else{
835 try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
836 }
837 }
838 }
839 } // end IconifyAction
840
841 /**
842 * This class should be treated as a "protected" inner class.
843 * Instantiate it only within subclasses of <code>Foo</code>.
844 */
845 public class RestoreAction extends AbstractAction {
846 /**
847 * Constructs a new instance of a {@code RestoreAction}.
848 */
849 public RestoreAction() {
850 super(UIManager.getString(
851 "InternalFrameTitlePane.restoreButtonText"));
852 }
853
854 public void actionPerformed(ActionEvent evt) {
855 if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
856 try {
857 frame.setIcon(false);
858 } catch (PropertyVetoException e) { }
859 } else if (frame.isMaximizable() && frame.isMaximum()) {
860 try {
861 frame.setMaximum(false);
862 } catch (PropertyVetoException e) { }
863 } else if (frame.isIconifiable() && frame.isIcon()) {
864 try {
865 frame.setIcon(false);
866 } catch (PropertyVetoException e) { }
867 }
868 }
869 }
870
871 /**
872 * This class should be treated as a "protected" inner class.
873 * Instantiate it only within subclasses of <code>Foo</code>.
874 */
875 public class MoveAction extends AbstractAction {
876 /**
877 * Constructs a new instance of a {@code MoveAction}.
878 */
879 public MoveAction() {
880 super(UIManager.getString(
881 "InternalFrameTitlePane.moveButtonText"));
882 }
883
884 public void actionPerformed(ActionEvent e) {
885 // This action is currently undefined
886 }
887 } // end MoveAction
888
889 /*
890 * Handles showing and hiding the system menu.
891 */
892 private class ShowSystemMenuAction extends AbstractAction {
893 private boolean show; // whether to show the menu
894
895 public ShowSystemMenuAction(boolean show) {
896 this.show = show;
897 }
898
899 public void actionPerformed(ActionEvent e) {
900 if (show) {
901 windowMenu.doClick();
902 } else {
903 windowMenu.setVisible(false);
904 }
905 }
906 }
907
908 /**
909 * This class should be treated as a "protected" inner class.
910 * Instantiate it only within subclasses of <code>Foo</code>.
911 */
912 public class SizeAction extends AbstractAction {
913 /**
914 * Constructs a new instance of a {@code SizeAction}.
915 */
916 public SizeAction() {
917 super(UIManager.getString(
918 "InternalFrameTitlePane.sizeButtonText"));
919 }
920
921 public void actionPerformed(ActionEvent e) {
922 // This action is currently undefined
923 }
924 } // end SizeAction
925
926
927 /**
928 * This class should be treated as a "protected" inner class.
929 * Instantiate it only within subclasses of <code>Foo</code>.
930 */
931 @SuppressWarnings("deprecation")
932 public class SystemMenuBar extends JMenuBar {
933 public boolean isFocusTraversable() { return false; }
934 public void requestFocus() {}
935 public void paint(Graphics g) {
936 Icon icon = frame.getFrameIcon();
937 if (icon == null) {
938 icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
939 "InternalFrame.icon");
940 }
941 if (icon != null) {
942 // Resize to 16x16 if necessary.
943 if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
944 Image img = ((ImageIcon)icon).getImage();
945 ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
946 }
947 icon.paintIcon(this, g, 0, 0);
948 }
949 }
|
32 import javax.swing.*;
33 import javax.swing.plaf.*;
34 import javax.swing.event.InternalFrameEvent;
35 import java.beans.PropertyChangeListener;
36 import java.beans.PropertyChangeEvent;
37 import java.beans.PropertyVetoException;
38 import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
39 import static java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST;
40
41 import sun.swing.DefaultLookup;
42
43 /**
44 * The class that manages a basic title bar
45 * <p>
46 * <strong>Warning:</strong>
47 * Serialized objects of this class will not be compatible with
48 * future Swing releases. The current serialization support is
49 * appropriate for short term storage or RMI between applications running
50 * the same version of Swing. As of 1.4, support for long term storage
51 * of all JavaBeans™
52 * has been added to the {@code java.beans} package.
53 * Please see {@link java.beans.XMLEncoder}.
54 *
55 * @author David Kloba
56 * @author Steve Wilson
57 */
58 @SuppressWarnings("serial") // Same-version serialization only
59 public class BasicInternalFrameTitlePane extends JComponent
60 {
61 /**
62 * The instance of {@code JMenuBar}.
63 */
64 protected JMenuBar menuBar;
65 /**
66 * The iconify button.
67 */
68 protected JButton iconButton;
69 /**
70 * The maximize button.
71 */
72 protected JButton maxButton;
703 x = (leftToRight) ? w - 16 - 2 : 2;
704
705 if (frame.isClosable()) {
706 closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
707 x += (leftToRight) ? -(16 + 2) : 16 + 2;
708 }
709
710 if (frame.isMaximizable()) {
711 maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
712 x += (leftToRight) ? -(16 + 2) : 16 + 2;
713 }
714
715 if (frame.isIconifiable()) {
716 iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
717 }
718 }
719 }
720
721 /**
722 * This class should be treated as a "protected" inner class.
723 * Instantiate it only within subclasses of {@code Foo}.
724 */
725 public class PropertyChangeHandler implements PropertyChangeListener {
726 // NOTE: This class exists only for backward compatibility. All
727 // its functionality has been moved into Handler. If you need to add
728 // new functionality add it to the Handler, but make sure this
729 // class calls into the Handler.
730 public void propertyChange(PropertyChangeEvent evt) {
731 getHandler().propertyChange(evt);
732 }
733 }
734
735 /**
736 * This class should be treated as a "protected" inner class.
737 * Instantiate it only within subclasses of {@code Foo}.
738 */
739 public class TitlePaneLayout implements LayoutManager {
740 // NOTE: This class exists only for backward compatibility. All
741 // its functionality has been moved into Handler. If you need to add
742 // new functionality add it to the Handler, but make sure this
743 // class calls into the Handler.
744 public void addLayoutComponent(String name, Component c) {
745 getHandler().addLayoutComponent(name, c);
746 }
747
748 public void removeLayoutComponent(Component c) {
749 getHandler().removeLayoutComponent(c);
750 }
751
752 public Dimension preferredLayoutSize(Container c) {
753 return getHandler().preferredLayoutSize(c);
754 }
755
756 public Dimension minimumLayoutSize(Container c) {
757 return getHandler().minimumLayoutSize(c);
758 }
759
760 public void layoutContainer(Container c) {
761 getHandler().layoutContainer(c);
762 }
763 }
764
765 /**
766 * This class should be treated as a "protected" inner class.
767 * Instantiate it only within subclasses of {@code Foo}.
768 */
769 public class CloseAction extends AbstractAction {
770 /**
771 * Constructs a new instance of a {@code CloseAction}.
772 */
773 public CloseAction() {
774 super(UIManager.getString(
775 "InternalFrameTitlePane.closeButtonText"));
776 }
777
778 public void actionPerformed(ActionEvent e) {
779 if(frame.isClosable()) {
780 frame.doDefaultCloseAction();
781 }
782 }
783 } // end CloseAction
784
785 /**
786 * This class should be treated as a "protected" inner class.
787 * Instantiate it only within subclasses of {@code Foo}.
788 */
789 public class MaximizeAction extends AbstractAction {
790 /**
791 * Constructs a new instance of a {@code MaximizeAction}.
792 */
793 public MaximizeAction() {
794 super(UIManager.getString(
795 "InternalFrameTitlePane.maximizeButtonText"));
796 }
797
798 public void actionPerformed(ActionEvent evt) {
799 if (frame.isMaximizable()) {
800 if (frame.isMaximum() && frame.isIcon()) {
801 try {
802 frame.setIcon(false);
803 } catch (PropertyVetoException e) { }
804 } else if (!frame.isMaximum()) {
805 try {
806 frame.setMaximum(true);
807 } catch (PropertyVetoException e) { }
808 } else {
809 try {
810 frame.setMaximum(false);
811 } catch (PropertyVetoException e) { }
812 }
813 }
814 }
815 }
816
817 /**
818 * This class should be treated as a "protected" inner class.
819 * Instantiate it only within subclasses of {@code Foo}.
820 */
821 public class IconifyAction extends AbstractAction {
822 /**
823 * Constructs a new instance of an {@code IconifyAction}.
824 */
825 public IconifyAction() {
826 super(UIManager.getString(
827 "InternalFrameTitlePane.minimizeButtonText"));
828 }
829
830 public void actionPerformed(ActionEvent e) {
831 if(frame.isIconifiable()) {
832 if(!frame.isIcon()) {
833 try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
834 } else{
835 try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
836 }
837 }
838 }
839 } // end IconifyAction
840
841 /**
842 * This class should be treated as a "protected" inner class.
843 * Instantiate it only within subclasses of {@code Foo}.
844 */
845 public class RestoreAction extends AbstractAction {
846 /**
847 * Constructs a new instance of a {@code RestoreAction}.
848 */
849 public RestoreAction() {
850 super(UIManager.getString(
851 "InternalFrameTitlePane.restoreButtonText"));
852 }
853
854 public void actionPerformed(ActionEvent evt) {
855 if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
856 try {
857 frame.setIcon(false);
858 } catch (PropertyVetoException e) { }
859 } else if (frame.isMaximizable() && frame.isMaximum()) {
860 try {
861 frame.setMaximum(false);
862 } catch (PropertyVetoException e) { }
863 } else if (frame.isIconifiable() && frame.isIcon()) {
864 try {
865 frame.setIcon(false);
866 } catch (PropertyVetoException e) { }
867 }
868 }
869 }
870
871 /**
872 * This class should be treated as a "protected" inner class.
873 * Instantiate it only within subclasses of {@code Foo}.
874 */
875 public class MoveAction extends AbstractAction {
876 /**
877 * Constructs a new instance of a {@code MoveAction}.
878 */
879 public MoveAction() {
880 super(UIManager.getString(
881 "InternalFrameTitlePane.moveButtonText"));
882 }
883
884 public void actionPerformed(ActionEvent e) {
885 // This action is currently undefined
886 }
887 } // end MoveAction
888
889 /*
890 * Handles showing and hiding the system menu.
891 */
892 private class ShowSystemMenuAction extends AbstractAction {
893 private boolean show; // whether to show the menu
894
895 public ShowSystemMenuAction(boolean show) {
896 this.show = show;
897 }
898
899 public void actionPerformed(ActionEvent e) {
900 if (show) {
901 windowMenu.doClick();
902 } else {
903 windowMenu.setVisible(false);
904 }
905 }
906 }
907
908 /**
909 * This class should be treated as a "protected" inner class.
910 * Instantiate it only within subclasses of {@code Foo}.
911 */
912 public class SizeAction extends AbstractAction {
913 /**
914 * Constructs a new instance of a {@code SizeAction}.
915 */
916 public SizeAction() {
917 super(UIManager.getString(
918 "InternalFrameTitlePane.sizeButtonText"));
919 }
920
921 public void actionPerformed(ActionEvent e) {
922 // This action is currently undefined
923 }
924 } // end SizeAction
925
926
927 /**
928 * This class should be treated as a "protected" inner class.
929 * Instantiate it only within subclasses of {@code Foo}.
930 */
931 @SuppressWarnings("deprecation")
932 public class SystemMenuBar extends JMenuBar {
933 public boolean isFocusTraversable() { return false; }
934 public void requestFocus() {}
935 public void paint(Graphics g) {
936 Icon icon = frame.getFrameIcon();
937 if (icon == null) {
938 icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
939 "InternalFrame.icon");
940 }
941 if (icon != null) {
942 // Resize to 16x16 if necessary.
943 if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
944 Image img = ((ImageIcon)icon).getImage();
945 ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
946 }
947 icon.paintIcon(this, g, 0, 0);
948 }
949 }
|