History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java (1 of 18352 files). Show all

Unified · Split

java/pkg/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java+795−0
@@ -0,0 +1,795 @@
1+/*
2+ * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package javax.swing.plaf.basic;
27+
28+import sun.swing.SwingUtilities2;
29+import java.awt.*;
30+import java.awt.event.*;
31+import javax.accessibility.AccessibleContext;
32+import javax.swing.*;
33+import javax.swing.plaf.*;
34+import javax.swing.border.*;
35+import javax.swing.event.InternalFrameEvent;
36+import java.util.EventListener;
37+import java.beans.PropertyChangeListener;
38+import java.beans.PropertyChangeEvent;
39+import java.beans.VetoableChangeListener;
40+import java.beans.PropertyVetoException;
41+
42+import sun.swing.DefaultLookup;
43+import sun.swing.UIAction;
44+
45+/**
46+ * The class that manages a basic title bar
47+ * <p>
48+ * <strong>Warning:</strong>
49+ * Serialized objects of this class will not be compatible with
50+ * future Swing releases. The current serialization support is
51+ * appropriate for short term storage or RMI between applications running
52+ * the same version of Swing. As of 1.4, support for long term storage
53+ * of all JavaBeans<sup><font size="-2">TM</font></sup>
54+ * has been added to the <code>java.beans</code> package.
55+ * Please see {@link java.beans.XMLEncoder}.
56+ *
57+ * @author David Kloba
58+ * @author Steve Wilson
59+ */
60+public class BasicInternalFrameTitlePane extends JComponent
61+{
62+ protected JMenuBar menuBar;
63+ protected JButton iconButton;
64+ protected JButton maxButton;
65+ protected JButton closeButton;
66+
67+ protected JMenu windowMenu;
68+ protected JInternalFrame frame;
69+
70+ protected Color selectedTitleColor;
71+ protected Color selectedTextColor;
72+ protected Color notSelectedTitleColor;
73+ protected Color notSelectedTextColor;
74+
75+ protected Icon maxIcon;
76+ protected Icon minIcon;
77+ protected Icon iconIcon;
78+ protected Icon closeIcon;
79+
80+ protected PropertyChangeListener propertyChangeListener;
81+
82+ protected Action closeAction;
83+ protected Action maximizeAction;
84+ protected Action iconifyAction;
85+ protected Action restoreAction;
86+ protected Action moveAction;
87+ protected Action sizeAction;
88+
89+ // These constants are not used in JDK code
90+ protected static final String CLOSE_CMD =
91+ UIManager.getString("InternalFrameTitlePane.closeButtonText");
92+ protected static final String ICONIFY_CMD =
93+ UIManager.getString("InternalFrameTitlePane.minimizeButtonText");
94+ protected static final String RESTORE_CMD =
95+ UIManager.getString("InternalFrameTitlePane.restoreButtonText");
96+ protected static final String MAXIMIZE_CMD =
97+ UIManager.getString("InternalFrameTitlePane.maximizeButtonText");
98+ protected static final String MOVE_CMD =
99+ UIManager.getString("InternalFrameTitlePane.moveButtonText");
100+ protected static final String SIZE_CMD =
101+ UIManager.getString("InternalFrameTitlePane.sizeButtonText");
102+
103+ private String closeButtonToolTip;
104+ private String iconButtonToolTip;
105+ private String restoreButtonToolTip;
106+ private String maxButtonToolTip;
107+ private Handler handler;
108+
109+ public BasicInternalFrameTitlePane(JInternalFrame f) {
110+ frame = f;
111+ installTitlePane();
112+ }
113+
114+ protected void installTitlePane() {
115+ installDefaults();
116+ installListeners();
117+
118+ createActions();
119+ enableActions();
120+ createActionMap();
121+
122+ setLayout(createLayout());
123+
124+ assembleSystemMenu();
125+ createButtons();
126+ addSubComponents();
127+
128+ }
129+
130+ protected void addSubComponents() {
131+ add(menuBar);
132+ add(iconButton);
133+ add(maxButton);
134+ add(closeButton);
135+ }
136+
137+ protected void createActions() {
138+ maximizeAction = new MaximizeAction();
139+ iconifyAction = new IconifyAction();
140+ closeAction = new CloseAction();
141+ restoreAction = new RestoreAction();
142+ moveAction = new MoveAction();
143+ sizeAction = new SizeAction();
144+ }
145+
146+ ActionMap createActionMap() {
147+ ActionMap map = new ActionMapUIResource();
148+ map.put("showSystemMenu", new ShowSystemMenuAction(true));
149+ map.put("hideSystemMenu", new ShowSystemMenuAction(false));
150+ return map;
151+ }
152+
153+ protected void installListeners() {
154+ if( propertyChangeListener == null ) {
155+ propertyChangeListener = createPropertyChangeListener();
156+ }
157+ frame.addPropertyChangeListener(propertyChangeListener);
158+ }
159+
160+ protected void uninstallListeners() {
161+ frame.removePropertyChangeListener(propertyChangeListener);
162+ handler = null;
163+ }
164+
165+ protected void installDefaults() {
166+ maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
167+ minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
168+ iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
169+ closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
170+
171+ selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
172+ selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
173+ notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
174+ notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
175+ setFont(UIManager.getFont("InternalFrame.titleFont"));
176+ closeButtonToolTip =
177+ UIManager.getString("InternalFrame.closeButtonToolTip");
178+ iconButtonToolTip =
179+ UIManager.getString("InternalFrame.iconButtonToolTip");
180+ restoreButtonToolTip =
181+ UIManager.getString("InternalFrame.restoreButtonToolTip");
182+ maxButtonToolTip =
183+ UIManager.getString("InternalFrame.maxButtonToolTip");
184+ }
185+
186+
187+ protected void uninstallDefaults() {
188+ }
189+
190+ protected void createButtons() {
191+ iconButton = new NoFocusButton(
192+ "InternalFrameTitlePane.iconifyButtonAccessibleName",
193+ "InternalFrameTitlePane.iconifyButtonOpacity");
194+ iconButton.addActionListener(iconifyAction);
195+ if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
196+ iconButton.setToolTipText(iconButtonToolTip);
197+ }
198+
199+ maxButton = new NoFocusButton(
200+ "InternalFrameTitlePane.maximizeButtonAccessibleName",
201+ "InternalFrameTitlePane.maximizeButtonOpacity");
202+ maxButton.addActionListener(maximizeAction);
203+
204+ closeButton = new NoFocusButton(
205+ "InternalFrameTitlePane.closeButtonAccessibleName",
206+ "InternalFrameTitlePane.closeButtonOpacity");
207+ closeButton.addActionListener(closeAction);
208+ if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) {
209+ closeButton.setToolTipText(closeButtonToolTip);
210+ }
211+
212+ setButtonIcons();
213+ }
214+
215+ protected void setButtonIcons() {
216+ if(frame.isIcon()) {
217+ if (minIcon != null) {
218+ iconButton.setIcon(minIcon);
219+ }
220+ if (restoreButtonToolTip != null &&
221+ restoreButtonToolTip.length() != 0) {
222+ iconButton.setToolTipText(restoreButtonToolTip);
223+ }
224+ if (maxIcon != null) {
225+ maxButton.setIcon(maxIcon);
226+ }
227+ if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
228+ maxButton.setToolTipText(maxButtonToolTip);
229+ }
230+ } else if (frame.isMaximum()) {
231+ if (iconIcon != null) {
232+ iconButton.setIcon(iconIcon);
233+ }
234+ if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
235+ iconButton.setToolTipText(iconButtonToolTip);
236+ }
237+ if (minIcon != null) {
238+ maxButton.setIcon(minIcon);
239+ }
240+ if (restoreButtonToolTip != null &&
241+ restoreButtonToolTip.length() != 0) {
242+ maxButton.setToolTipText(restoreButtonToolTip);
243+ }
244+ } else {
245+ if (iconIcon != null) {
246+ iconButton.setIcon(iconIcon);
247+ }
248+ if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) {
249+ iconButton.setToolTipText(iconButtonToolTip);
250+ }
251+ if (maxIcon != null) {
252+ maxButton.setIcon(maxIcon);
253+ }
254+ if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) {
255+ maxButton.setToolTipText(maxButtonToolTip);
256+ }
257+ }
258+ if (closeIcon != null) {
259+ closeButton.setIcon(closeIcon);
260+ }
261+ }
262+
263+ protected void assembleSystemMenu() {
264+ menuBar = createSystemMenuBar();
265+ windowMenu = createSystemMenu();
266+ menuBar.add(windowMenu);
267+ addSystemMenuItems(windowMenu);
268+ enableActions();
269+ }
270+
271+ protected void addSystemMenuItems(JMenu systemMenu) {
272+ JMenuItem mi = systemMenu.add(restoreAction);
273+ mi.setMnemonic('R');
274+ mi = systemMenu.add(moveAction);
275+ mi.setMnemonic('M');
276+ mi = systemMenu.add(sizeAction);
277+ mi.setMnemonic('S');
278+ mi = systemMenu.add(iconifyAction);
279+ mi.setMnemonic('n');
280+ mi = systemMenu.add(maximizeAction);
281+ mi.setMnemonic('x');
282+ systemMenu.add(new JSeparator());
283+ mi = systemMenu.add(closeAction);
284+ mi.setMnemonic('C');
285+ }
286+
287+ protected JMenu createSystemMenu() {
288+ return new JMenu(" ");
289+ }
290+
291+ protected JMenuBar createSystemMenuBar() {
292+ menuBar = new SystemMenuBar();
293+ menuBar.setBorderPainted(false);
294+ return menuBar;
295+ }
296+
297+ protected void showSystemMenu(){
298+ // windowMenu.setPopupMenuVisible(true);
299+ // windowMenu.setVisible(true);
300+ windowMenu.doClick();
301+ }
302+
303+ public void paintComponent(Graphics g) {
304+ paintTitleBackground(g);
305+
306+ if(frame.getTitle() != null) {
307+ boolean isSelected = frame.isSelected();
308+ Font f = g.getFont();
309+ g.setFont(getFont());
310+ if(isSelected)
311+ g.setColor(selectedTextColor);
312+ else
313+ g.setColor(notSelectedTextColor);
314+
315+ // Center text vertically.
316+ FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
317+ int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
318+ fm.getDescent()) / 2;
319+
320+ int titleX;
321+ Rectangle r = new Rectangle(0, 0, 0, 0);
322+ if (frame.isIconifiable()) r = iconButton.getBounds();
323+ else if (frame.isMaximizable()) r = maxButton.getBounds();
324+ else if (frame.isClosable()) r = closeButton.getBounds();
325+ int titleW;
326+
327+ String title = frame.getTitle();
328+ if( BasicGraphicsUtils.isLeftToRight(frame) ) {
329+ if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right;
330+ titleX = menuBar.getX() + menuBar.getWidth() + 2;
331+ titleW = r.x - titleX - 3;
332+ title = getTitle(frame.getTitle(), fm, titleW);
333+ } else {
334+ titleX = menuBar.getX() - 2
335+ - SwingUtilities2.stringWidth(frame,fm,title);
336+ }
337+
338+ SwingUtilities2.drawString(frame, g, title, titleX, baseline);
339+ g.setFont(f);
340+ }
341+ }
342+
343+ /**
344+ * Invoked from paintComponent.
345+ * Paints the background of the titlepane. All text and icons will
346+ * then be rendered on top of this background.
347+ * @param g the graphics to use to render the background
348+ * @since 1.4
349+ */
350+ protected void paintTitleBackground(Graphics g) {
351+ boolean isSelected = frame.isSelected();
352+
353+ if(isSelected)
354+ g.setColor(selectedTitleColor);
355+ else
356+ g.setColor(notSelectedTitleColor);
357+ g.fillRect(0, 0, getWidth(), getHeight());
358+ }
359+
360+ protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
361+ return SwingUtilities2.clipStringIfNecessary(
362+ frame, fm, text, availTextWidth);
363+ }
364+
365+ /**
366+ * Post a WINDOW_CLOSING-like event to the frame, so that it can
367+ * be treated like a regular Frame.
368+ */
369+ protected void postClosingEvent(JInternalFrame frame) {
370+ InternalFrameEvent e = new InternalFrameEvent(
371+ frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
372+ // Try posting event, unless there's a SecurityManager.
373+ if (JInternalFrame.class.getClassLoader() == null) {
374+ try {
375+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
376+ return;
377+ } catch (SecurityException se) {
378+ // Use dispatchEvent instead.
379+ }
380+ }
381+ frame.dispatchEvent(e);
382+ }
383+
384+
385+ protected void enableActions() {
386+ restoreAction.setEnabled(frame.isMaximum() || frame.isIcon());
387+ maximizeAction.setEnabled(
388+ (frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) ||
389+ (frame.isMaximizable() && frame.isIcon()));
390+ iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon());
391+ closeAction.setEnabled(frame.isClosable());
392+ sizeAction.setEnabled(false);
393+ moveAction.setEnabled(false);
394+ }
395+
396+ private Handler getHandler() {
397+ if (handler == null) {
398+ handler = new Handler();
399+ }
400+ return handler;
401+ }
402+
403+ protected PropertyChangeListener createPropertyChangeListener() {
404+ return getHandler();
405+ }
406+
407+ protected LayoutManager createLayout() {
408+ return getHandler();
409+ }
410+
411+
412+ private class Handler implements LayoutManager, PropertyChangeListener {
413+ //
414+ // PropertyChangeListener
415+ //
416+ public void propertyChange(PropertyChangeEvent evt) {
417+ String prop = evt.getPropertyName();
418+
419+ if (prop == JInternalFrame.IS_SELECTED_PROPERTY) {
420+ repaint();
421+ return;
422+ }
423+
424+ if (prop == JInternalFrame.IS_ICON_PROPERTY ||
425+ prop == JInternalFrame.IS_MAXIMUM_PROPERTY) {
426+ setButtonIcons();
427+ enableActions();
428+ return;
429+ }
430+
431+ if ("closable" == prop) {
432+ if (evt.getNewValue() == Boolean.TRUE) {
433+ add(closeButton);
434+ } else {
435+ remove(closeButton);
436+ }
437+ } else if ("maximizable" == prop) {
438+ if (evt.getNewValue() == Boolean.TRUE) {
439+ add(maxButton);
440+ } else {
441+ remove(maxButton);
442+ }
443+ } else if ("iconable" == prop) {
444+ if (evt.getNewValue() == Boolean.TRUE) {
445+ add(iconButton);
446+ } else {
447+ remove(iconButton);
448+ }
449+ }
450+ enableActions();
451+
452+ revalidate();
453+ repaint();
454+ }
455+
456+
457+ //
458+ // LayoutManager
459+ //
460+ public void addLayoutComponent(String name, Component c) {}
461+ public void removeLayoutComponent(Component c) {}
462+ public Dimension preferredLayoutSize(Container c) {
463+ return minimumLayoutSize(c);
464+ }
465+
466+ public Dimension minimumLayoutSize(Container c) {
467+ // Calculate width.
468+ int width = 22;
469+
470+ if (frame.isClosable()) {
471+ width += 19;
472+ }
473+ if (frame.isMaximizable()) {
474+ width += 19;
475+ }
476+ if (frame.isIconifiable()) {
477+ width += 19;
478+ }
479+
480+ FontMetrics fm = frame.getFontMetrics(getFont());
481+ String frameTitle = frame.getTitle();
482+ int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
483+ frame, fm, frameTitle) : 0;
484+ int title_length = frameTitle != null ? frameTitle.length() : 0;
485+
486+ // Leave room for three characters in the title.
487+ if (title_length > 3) {
488+ int subtitle_w = SwingUtilities2.stringWidth(
489+ frame, fm, frameTitle.substring(0, 3) + "...");
490+ width += (title_w < subtitle_w) ? title_w : subtitle_w;
491+ } else {
492+ width += title_w;
493+ }
494+
495+ // Calculate height.
496+ Icon icon = frame.getFrameIcon();
497+ int fontHeight = fm.getHeight();
498+ fontHeight += 2;
499+ int iconHeight = 0;
500+ if (icon != null) {
501+ // SystemMenuBar forces the icon to be 16x16 or less.
502+ iconHeight = Math.min(icon.getIconHeight(), 16);
503+ }
504+ iconHeight += 2;
505+
506+ int height = Math.max( fontHeight, iconHeight );
507+
508+ Dimension dim = new Dimension(width, height);
509+
510+ // Take into account the border insets if any.
511+ if (getBorder() != null) {
512+ Insets insets = getBorder().getBorderInsets(c);
513+ dim.height += insets.top + insets.bottom;
514+ dim.width += insets.left + insets.right;
515+ }
516+ return dim;
517+ }
518+
519+ public void layoutContainer(Container c) {
520+ boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame);
521+
522+ int w = getWidth();
523+ int h = getHeight();
524+ int x;
525+
526+ int buttonHeight = closeButton.getIcon().getIconHeight();
527+
528+ Icon icon = frame.getFrameIcon();
529+ int iconHeight = 0;
530+ if (icon != null) {
531+ iconHeight = icon.getIconHeight();
532+ }
533+ x = (leftToRight) ? 2 : w - 16 - 2;
534+ menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16);
535+
536+ x = (leftToRight) ? w - 16 - 2 : 2;
537+
538+ if (frame.isClosable()) {
539+ closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
540+ x += (leftToRight) ? -(16 + 2) : 16 + 2;
541+ }
542+
543+ if (frame.isMaximizable()) {
544+ maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
545+ x += (leftToRight) ? -(16 + 2) : 16 + 2;
546+ }
547+
548+ if (frame.isIconifiable()) {
549+ iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14);
550+ }
551+ }
552+ }
553+
554+ /**
555+ * This class should be treated as a &quot;protected&quot; inner class.
556+ * Instantiate it only within subclasses of <Foo>.
557+ */
558+ public class PropertyChangeHandler implements PropertyChangeListener {
559+ // NOTE: This class exists only for backward compatability. All
560+ // its functionality has been moved into Handler. If you need to add
561+ // new functionality add it to the Handler, but make sure this
562+ // class calls into the Handler.
563+ public void propertyChange(PropertyChangeEvent evt) {
564+ getHandler().propertyChange(evt);
565+ }
566+ }
567+
568+ /**
569+ * This class should be treated as a &quot;protected&quot; inner class.
570+ * Instantiate it only within subclasses of <Foo>.
571+ */
572+ public class TitlePaneLayout implements LayoutManager {
573+ // NOTE: This class exists only for backward compatability. All
574+ // its functionality has been moved into Handler. If you need to add
575+ // new functionality add it to the Handler, but make sure this
576+ // class calls into the Handler.
577+ public void addLayoutComponent(String name, Component c) {
578+ getHandler().addLayoutComponent(name, c);
579+ }
580+
581+ public void removeLayoutComponent(Component c) {
582+ getHandler().removeLayoutComponent(c);
583+ }
584+
585+ public Dimension preferredLayoutSize(Container c) {
586+ return getHandler().preferredLayoutSize(c);
587+ }
588+
589+ public Dimension minimumLayoutSize(Container c) {
590+ return getHandler().minimumLayoutSize(c);
591+ }
592+
593+ public void layoutContainer(Container c) {
594+ getHandler().layoutContainer(c);
595+ }
596+ }
597+
598+ /**
599+ * This class should be treated as a &quot;protected&quot; inner class.
600+ * Instantiate it only within subclasses of <Foo>.
601+ */
602+ public class CloseAction extends AbstractAction {
603+ public CloseAction() {
604+ super(UIManager.getString(
605+ "InternalFrameTitlePane.closeButtonText"));
606+ }
607+
608+ public void actionPerformed(ActionEvent e) {
609+ if(frame.isClosable()) {
610+ frame.doDefaultCloseAction();
611+ }
612+ }
613+ } // end CloseAction
614+
615+ /**
616+ * This class should be treated as a &quot;protected&quot; inner class.
617+ * Instantiate it only within subclasses of <Foo>.
618+ */
619+ public class MaximizeAction extends AbstractAction {
620+ public MaximizeAction() {
621+ super(UIManager.getString(
622+ "InternalFrameTitlePane.maximizeButtonText"));
623+ }
624+
625+ public void actionPerformed(ActionEvent evt) {
626+ if (frame.isMaximizable()) {
627+ if (frame.isMaximum() && frame.isIcon()) {
628+ try {
629+ frame.setIcon(false);
630+ } catch (PropertyVetoException e) { }
631+ } else if (!frame.isMaximum()) {
632+ try {
633+ frame.setMaximum(true);
634+ } catch (PropertyVetoException e) { }
635+ } else {
636+ try {
637+ frame.setMaximum(false);
638+ } catch (PropertyVetoException e) { }
639+ }
640+ }
641+ }
642+ }
643+
644+ /**
645+ * This class should be treated as a &quot;protected&quot; inner class.
646+ * Instantiate it only within subclasses of <Foo>.
647+ */
648+ public class IconifyAction extends AbstractAction {
649+ public IconifyAction() {
650+ super(UIManager.getString(
651+ "InternalFrameTitlePane.minimizeButtonText"));
652+ }
653+
654+ public void actionPerformed(ActionEvent e) {
655+ if(frame.isIconifiable()) {
656+ if(!frame.isIcon()) {
657+ try { frame.setIcon(true); } catch (PropertyVetoException e1) { }
658+ } else{
659+ try { frame.setIcon(false); } catch (PropertyVetoException e1) { }
660+ }
661+ }
662+ }
663+ } // end IconifyAction
664+
665+ /**
666+ * This class should be treated as a &quot;protected&quot; inner class.
667+ * Instantiate it only within subclasses of <Foo>.
668+ */
669+ public class RestoreAction extends AbstractAction {
670+ public RestoreAction() {
671+ super(UIManager.getString(
672+ "InternalFrameTitlePane.restoreButtonText"));
673+ }
674+
675+ public void actionPerformed(ActionEvent evt) {
676+ if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) {
677+ try {
678+ frame.setIcon(false);
679+ } catch (PropertyVetoException e) { }
680+ } else if (frame.isMaximizable() && frame.isMaximum()) {
681+ try {
682+ frame.setMaximum(false);
683+ } catch (PropertyVetoException e) { }
684+ } else if (frame.isIconifiable() && frame.isIcon()) {
685+ try {
686+ frame.setIcon(false);
687+ } catch (PropertyVetoException e) { }
688+ }
689+ }
690+ }
691+
692+ /**
693+ * This class should be treated as a &quot;protected&quot; inner class.
694+ * Instantiate it only within subclasses of <Foo>.
695+ */
696+ public class MoveAction extends AbstractAction {
697+ public MoveAction() {
698+ super(UIManager.getString(
699+ "InternalFrameTitlePane.moveButtonText"));
700+ }
701+
702+ public void actionPerformed(ActionEvent e) {
703+ // This action is currently undefined
704+ }
705+ } // end MoveAction
706+
707+ /*
708+ * Handles showing and hiding the system menu.
709+ */
710+ private class ShowSystemMenuAction extends AbstractAction {
711+ private boolean show; // whether to show the menu
712+
713+ public ShowSystemMenuAction(boolean show) {
714+ this.show = show;
715+ }
716+
717+ public void actionPerformed(ActionEvent e) {
718+ if (show) {
719+ windowMenu.doClick();
720+ } else {
721+ windowMenu.setVisible(false);
722+ }
723+ }
724+ }
725+
726+ /**
727+ * This class should be treated as a &quot;protected&quot; inner class.
728+ * Instantiate it only within subclasses of <Foo>.
729+ */
730+ public class SizeAction extends AbstractAction {
731+ public SizeAction() {
732+ super(UIManager.getString(
733+ "InternalFrameTitlePane.sizeButtonText"));
734+ }
735+
736+ public void actionPerformed(ActionEvent e) {
737+ // This action is currently undefined
738+ }
739+ } // end SizeAction
740+
741+
742+ /**
743+ * This class should be treated as a &quot;protected&quot; inner class.
744+ * Instantiate it only within subclasses of <Foo>.
745+ */
746+ public class SystemMenuBar extends JMenuBar {
747+ public boolean isFocusTraversable() { return false; }
748+ public void requestFocus() {}
749+ public void paint(Graphics g) {
750+ Icon icon = frame.getFrameIcon();
751+ if (icon == null) {
752+ icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
753+ "InternalFrame.icon");
754+ }
755+ if (icon != null) {
756+ // Resize to 16x16 if necessary.
757+ if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
758+ Image img = ((ImageIcon)icon).getImage();
759+ ((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
760+ }
761+ icon.paintIcon(this, g, 0, 0);
762+ }
763+ }
764+
765+ public boolean isOpaque() {
766+ return true;
767+ }
768+ } // end SystemMenuBar
769+
770+
771+ private class NoFocusButton extends JButton {
772+ private String uiKey;
773+ public NoFocusButton(String uiKey, String opacityKey) {
774+ setFocusPainted(false);
775+ setMargin(new Insets(0,0,0,0));
776+ this.uiKey = uiKey;
777+
778+ Object opacity = UIManager.get(opacityKey);
779+ if (opacity instanceof Boolean) {
780+ setOpaque(((Boolean)opacity).booleanValue());
781+ }
782+ }
783+ public boolean isFocusTraversable() { return false; }
784+ public void requestFocus() {}
785+ public AccessibleContext getAccessibleContext() {
786+ AccessibleContext ac = super.getAccessibleContext();
787+ if (uiKey != null) {
788+ ac.setAccessibleName(UIManager.getString(uiKey));
789+ uiKey = null;
790+ }
791+ return ac;
792+ }
793+ } // end NoFocusButton
794+
795+} // End Title Pane Class