Source Code Cross Referenced for BasicInternalFrameUI.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » basic » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.plaf.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Vadim L. Bogdanov
020:         * @version $Revision$
021:         */package javax.swing.plaf.basic;
022:
023:        import java.awt.Component;
024:        import java.awt.Container;
025:        import java.awt.Dimension;
026:        import java.awt.Insets;
027:        import java.awt.LayoutManager;
028:        import java.awt.Point;
029:        import java.awt.Rectangle;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ComponentEvent;
032:        import java.awt.event.ComponentListener;
033:        import java.awt.event.MouseEvent;
034:        import java.beans.PropertyChangeEvent;
035:        import java.beans.PropertyChangeListener;
036:        import java.beans.PropertyVetoException;
037:
038:        import javax.swing.AbstractAction;
039:        import javax.swing.DefaultDesktopManager;
040:        import javax.swing.DesktopManager;
041:        import javax.swing.InputMap;
042:        import javax.swing.JComponent;
043:        import javax.swing.JDesktopPane;
044:        import javax.swing.JInternalFrame;
045:        import javax.swing.KeyStroke;
046:        import javax.swing.LookAndFeel;
047:        import javax.swing.SwingConstants;
048:        import javax.swing.SwingUtilities;
049:        import javax.swing.UIManager;
050:        import javax.swing.event.InternalFrameEvent;
051:        import javax.swing.event.InternalFrameListener;
052:        import javax.swing.event.MouseInputAdapter;
053:        import javax.swing.event.MouseInputListener;
054:        import javax.swing.plaf.ActionMapUIResource;
055:        import javax.swing.plaf.ComponentUI;
056:        import javax.swing.plaf.InternalFrameUI;
057:        import javax.swing.plaf.UIResource;
058:
059:        import org.apache.harmony.x.swing.ComponentDragImplHelper;
060:        import org.apache.harmony.x.swing.Utilities;
061:
062:        public class BasicInternalFrameUI extends InternalFrameUI {
063:
064:            public class InternalFrameLayout implements  LayoutManager {
065:                public Dimension preferredLayoutSize(final Container c) {
066:                    Dimension size = frame.getRootPane().getPreferredSize();
067:
068:                    if (northPane != null) {
069:                        Dimension northPref = northPane.getPreferredSize();
070:                        size.height += northPref.height;
071:                        size.width = Math.max(size.width, northPref.width);
072:                    }
073:                    if (southPane != null) {
074:                        Dimension southPref = southPane.getPreferredSize();
075:                        size.height += southPref.height;
076:                        size.width = Math.max(size.width, southPref.width);
077:                    }
078:                    if (westPane != null) {
079:                        Dimension westPref = westPane.getPreferredSize();
080:                        size.width += westPref.width;
081:                        size.height = Math.max(size.height, westPref.height);
082:                    }
083:                    if (eastPane != null) {
084:                        Dimension eastPref = eastPane.getPreferredSize();
085:                        size.width += eastPref.width;
086:                        size.height = Math.max(size.height, eastPref.height);
087:                    }
088:
089:                    return Utilities.addInsets(size, frame.getInsets());
090:                }
091:
092:                public Dimension minimumLayoutSize(final Container c) {
093:                    Dimension size = new Dimension();
094:
095:                    if (northPane != null) {
096:                        size.setSize(northPane.getMinimumSize());
097:                    }
098:
099:                    return Utilities.addInsets(size, frame.getInsets());
100:                }
101:
102:                public void layoutContainer(final Container c) {
103:                    Dimension size = frame.getSize();
104:
105:                    Insets insets = frame.getInsets();
106:                    int top = insets.top;
107:                    int left = insets.left;
108:                    int right = size.width - insets.right;
109:                    int bottom = size.height - insets.bottom;
110:
111:                    if (northPane != null) {
112:                        size = northPane.getPreferredSize();
113:                        northPane.setBounds(left, top, right - left,
114:                                size.height);
115:                        top += northPane.getHeight();
116:                    }
117:
118:                    if (southPane != null) {
119:                        size = southPane.getPreferredSize();
120:                        southPane.setBounds(left, bottom - size.height, right
121:                                - left, size.height);
122:                        bottom -= southPane.getHeight();
123:                    }
124:
125:                    if (westPane != null) {
126:                        size = westPane.getPreferredSize();
127:                        westPane.setBounds(left, top, size.width, bottom - top);
128:                        left += westPane.getWidth();
129:                    }
130:
131:                    if (eastPane != null) {
132:                        size = eastPane.getPreferredSize();
133:                        eastPane.setBounds(right - size.width, top, size.width,
134:                                bottom - top);
135:                        right -= eastPane.getWidth();
136:                    }
137:
138:                    frame.getRootPane().setBounds(left, top, right - left,
139:                            bottom - top);
140:                }
141:
142:                public void addLayoutComponent(final String name,
143:                        final Component c) {
144:                }
145:
146:                public void removeLayoutComponent(final Component c) {
147:                }
148:            }
149:
150:            public class InternalFramePropertyChangeListener implements 
151:                    PropertyChangeListener {
152:
153:                public void propertyChange(final PropertyChangeEvent e) {
154:                    if (JInternalFrame.IS_ICON_PROPERTY.equals(e
155:                            .getPropertyName())) {
156:                        iconPropertyChange(e.getNewValue());
157:
158:                    } else if (JInternalFrame.IS_MAXIMUM_PROPERTY.equals(e
159:                            .getPropertyName())) {
160:                        maximumPropertyChange(e.getNewValue());
161:
162:                    } else if (JInternalFrame.IS_CLOSED_PROPERTY.equals(e
163:                            .getPropertyName())) {
164:                        closeFrame(frame);
165:
166:                    } else if (JInternalFrame.IS_SELECTED_PROPERTY.equals(e
167:                            .getPropertyName())) {
168:                        selectedPropertyChange(e.getNewValue());
169:
170:                    } else if (JInternalFrame.GLASS_PANE_PROPERTY.equals(e
171:                            .getPropertyName())) {
172:                        glassPanePropertyChange(e);
173:
174:                    } else if ("resizable".equals(e.getPropertyName())) {
175:                        frame.repaint();
176:
177:                    } else if ("ancestor".equals(e.getPropertyName())) {
178:                        ancestorPropertyChange(e);
179:                    }
180:                }
181:
182:                private void maximumPropertyChange(final Object newValue) {
183:                    if (((Boolean) newValue).booleanValue()) {
184:                        maximizeFrame(frame);
185:                    } else {
186:                        minimizeFrame(frame);
187:                    }
188:                }
189:
190:                private void iconPropertyChange(final Object newValue) {
191:                    if (((Boolean) newValue).booleanValue()) {
192:                        iconifyFrame(frame);
193:                    } else {
194:                        deiconifyFrame(frame);
195:                    }
196:                }
197:
198:                private void selectedPropertyChange(final Object newValue) {
199:                    if (((Boolean) newValue).booleanValue()) {
200:                        activateFrame(frame);
201:                    } else {
202:                        deactivateFrame(frame);
203:                    }
204:                    frame.repaint();
205:                }
206:
207:                private void glassPanePropertyChange(final PropertyChangeEvent e) {
208:                    ((Component) e.getOldValue())
209:                            .removeMouseListener(glassPaneDispatcher);
210:                    ((Component) e.getOldValue())
211:                            .removeMouseMotionListener(glassPaneDispatcher);
212:
213:                    frame.getGlassPane().addMouseListener(glassPaneDispatcher);
214:                    frame.getGlassPane().addMouseMotionListener(
215:                            glassPaneDispatcher);
216:                }
217:
218:                private void ancestorPropertyChange(final PropertyChangeEvent e) {
219:                    if (e.getOldValue() != null) {
220:                        ((Container) e.getOldValue())
221:                                .removeComponentListener(componentListener);
222:                    }
223:                    if (e.getNewValue() != null) {
224:                        ((Container) e.getNewValue())
225:                                .addComponentListener(componentListener);
226:                    }
227:                }
228:            }
229:
230:            protected class BasicInternalFrameListener implements 
231:                    InternalFrameListener {
232:                public void internalFrameClosing(final InternalFrameEvent e) {
233:                }
234:
235:                public void internalFrameClosed(final InternalFrameEvent e) {
236:                }
237:
238:                public void internalFrameOpened(final InternalFrameEvent e) {
239:                }
240:
241:                public void internalFrameIconified(final InternalFrameEvent e) {
242:                }
243:
244:                public void internalFrameDeiconified(final InternalFrameEvent e) {
245:                    if (frame.isMaximum()) {
246:                        Container parent = getFrameParent();
247:                        if (parent != null) {
248:                            frame.setSize(parent.getSize());
249:                        }
250:                    }
251:                }
252:
253:                public void internalFrameActivated(final InternalFrameEvent e) {
254:                    if (isKeyBindingRegistered()) {
255:                        return;
256:                    }
257:
258:                    setupMenuOpenKey();
259:                    setupMenuCloseKey();
260:                    setKeyBindingRegistered(true);
261:                }
262:
263:                public void internalFrameDeactivated(final InternalFrameEvent e) {
264:                }
265:            }
266:
267:            protected class BorderListener extends MouseInputAdapter implements 
268:                    SwingConstants {
269:
270:                protected final int RESIZE_NONE = 0;
271:
272:                private final ComponentDragImplHelper helper = new ComponentDragImplHelper();
273:                private int resizeDirection = RESIZE_NONE;
274:
275:                public void mouseClicked(final MouseEvent e) {
276:                    if (e.getSource() != frame
277:                            && SwingUtilities.isLeftMouseButton(e)
278:                            && e.getClickCount() > 1) {
279:                        if (frame.isMaximizable()) {
280:                            try {
281:                                frame.setMaximum(!frame.isMaximum());
282:                            } catch (final PropertyVetoException v) {
283:                            }
284:                        }
285:                    }
286:                }
287:
288:                public void mousePressed(final MouseEvent e) {
289:                    try {
290:                        frame.setSelected(true);
291:                    } catch (final PropertyVetoException e1) {
292:                    }
293:
294:                    if (frame.isMaximum()) {
295:                        return;
296:                    }
297:
298:                    resizeDirection = ComponentDragImplHelper
299:                            .getResizeDirection(e, frame);
300:                    if (resizeDirection != RESIZE_NONE && frame.isResizable()) {
301:                        getDesktopManager().beginResizingFrame(frame,
302:                                resizeDirection);
303:                        helper.beginResizing(e, frame, frame.getParent());
304:                    } else if (isTitlePaneClick(e)) {
305:                        getDesktopManager().beginDraggingFrame(frame);
306:                        helper.beginDragging(e, frame, frame.getParent());
307:                    }
308:                }
309:
310:                public void mouseDragged(final MouseEvent e) {
311:                    if (!helper.isDragging()) {
312:                        return;
313:                    }
314:
315:                    Rectangle newBounds = helper.mouseDragged(e);
316:                    if (resizeDirection == RESIZE_NONE) {
317:                        getDesktopManager().dragFrame(frame, newBounds.x,
318:                                newBounds.y);
319:                    } else {
320:                        getDesktopManager().resizeFrame(frame, newBounds.x,
321:                                newBounds.y, newBounds.width, newBounds.height);
322:                    }
323:                }
324:
325:                public void mouseReleased(final MouseEvent e) {
326:                    if (!helper.isDragging()) {
327:                        return;
328:                    }
329:
330:                    if (resizeDirection == RESIZE_NONE) {
331:                        getDesktopManager().endDraggingFrame(frame);
332:                    } else {
333:                        getDesktopManager().endResizingFrame(frame);
334:                    }
335:                    helper.endDraggingOrResizing(e);
336:
337:                    updateMouseCursor(e);
338:                }
339:
340:                public void mouseMoved(final MouseEvent e) {
341:                    updateMouseCursor(e);
342:                }
343:
344:                public void mouseExited(final MouseEvent e) {
345:                    if (!helper.isDragging()) {
346:                        frame.getParent().setCursor(null);
347:                    }
348:                }
349:
350:                private boolean isTitlePaneClick(final MouseEvent e) {
351:                    Point p = SwingUtilities.convertPoint(e.getComponent(), e
352:                            .getPoint(), titlePane);
353:
354:                    return titlePane.contains(p);
355:                }
356:
357:                private void updateMouseCursor(final MouseEvent e) {
358:                    if (!frame.isResizable() || frame.isMaximum()) {
359:                        return;
360:                    }
361:
362:                    frame.getParent().setCursor(
363:                            ComponentDragImplHelper.getUpdatedCursor(e, frame));
364:                }
365:            }
366:
367:            protected class ComponentHandler implements  ComponentListener {
368:                public void componentResized(final ComponentEvent e) {
369:                    if (frame.isMaximum()) {
370:                        frame.setSize(frame.getParent().getSize());
371:                    }
372:                }
373:
374:                public void componentMoved(final ComponentEvent e) {
375:                }
376:
377:                public void componentShown(final ComponentEvent e) {
378:                }
379:
380:                public void componentHidden(final ComponentEvent e) {
381:                }
382:            }
383:
384:            protected class GlassPaneDispatcher implements  MouseInputListener {
385:                private Component pressedTarget;
386:                private Component moveTarget;
387:
388:                public void mouseEntered(final MouseEvent e) {
389:                    forwardMouseEvent(e);
390:                }
391:
392:                public void mouseExited(final MouseEvent e) {
393:                    forwardMouseEvent(e);
394:                }
395:
396:                public void mouseClicked(final MouseEvent e) {
397:                    forwardMouseEvent(e);
398:                }
399:
400:                public void mouseReleased(final MouseEvent e) {
401:                    forwardMouseEvent(e);
402:                }
403:
404:                public void mousePressed(final MouseEvent e) {
405:                    try {
406:                        frame.setSelected(true);
407:                    } catch (final PropertyVetoException e1) {
408:                    }
409:
410:                    forwardMouseEvent(e);
411:                }
412:
413:                public void mouseDragged(final MouseEvent e) {
414:                    forwardMouseEvent(e);
415:                }
416:
417:                public void mouseMoved(final MouseEvent e) {
418:                    Component target = frame.getLayeredPane().findComponentAt(
419:                            e.getPoint());
420:                    if (target != moveTarget) {
421:                        createAndDispatchMouseEvent(moveTarget,
422:                                MouseEvent.MOUSE_EXITED, e);
423:                        createAndDispatchMouseEvent(target,
424:                                MouseEvent.MOUSE_ENTERED, e);
425:                        moveTarget = target;
426:                    }
427:
428:                    forwardMouseEvent(e);
429:                }
430:
431:                private void forwardMouseEvent(final MouseEvent e) {
432:                    // look for the target component
433:                    Component target = frame.getLayeredPane().findComponentAt(
434:                            e.getPoint());
435:                    switch (e.getID()) {
436:                    case MouseEvent.MOUSE_RELEASED:
437:                    case MouseEvent.MOUSE_DRAGGED:
438:                        target = pressedTarget;
439:                        break;
440:                    case MouseEvent.MOUSE_PRESSED:
441:                        pressedTarget = target;
442:                        break;
443:                    case MouseEvent.MOUSE_EXITED:
444:                        target = moveTarget;
445:                        break;
446:                    }
447:
448:                    if (target != null) {
449:                        MouseEvent e1 = SwingUtilities.convertMouseEvent(frame
450:                                .getGlassPane(), e, target);
451:                        target.dispatchEvent(e1);
452:                    }
453:                }
454:
455:                private void createAndDispatchMouseEvent(
456:                        final Component target, final int id, final MouseEvent e) {
457:                    if (target == null) {
458:                        return;
459:                    }
460:
461:                    Point p = SwingUtilities.convertPoint(frame.getGlassPane(),
462:                            e.getPoint(), target);
463:                    MouseEvent newE = new MouseEvent(target, id, e.getWhen(), e
464:                            .getModifiers(), p.x, p.y, e.getClickCount(), e
465:                            .isPopupTrigger());
466:                    target.dispatchEvent(newE);
467:                }
468:            }
469:
470:            protected JInternalFrame frame;
471:            protected KeyStroke openMenuKey;
472:            protected BasicInternalFrameTitlePane titlePane;
473:            protected ComponentListener componentListener;
474:            protected MouseInputListener glassPaneDispatcher;
475:            protected PropertyChangeListener propertyChangeListener;
476:            protected MouseInputAdapter borderListener;
477:            protected LayoutManager internalFrameLayout;
478:            protected JComponent northPane;
479:            protected JComponent southPane;
480:            protected JComponent eastPane;
481:            protected JComponent westPane;
482:
483:            private InternalFrameListener internalFrameListener;
484:
485:            /*
486:             * If frame is not in some JDesktopPane, this field is used
487:             * in getDesktopManager() to store the created desktop manager.
488:             */
489:            private DesktopManager defaultDesktopManager;
490:
491:            private boolean keyBindingActive;
492:            private boolean keyBindingRegistered;
493:
494:            public BasicInternalFrameUI(final JInternalFrame frame) {
495:            }
496:
497:            public void setWestPane(final JComponent c) {
498:                westPane = c;
499:            }
500:
501:            public JComponent getWestPane() {
502:                return westPane;
503:            }
504:
505:            public void setSouthPane(final JComponent c) {
506:                southPane = c;
507:            }
508:
509:            public JComponent getSouthPane() {
510:                return southPane;
511:            }
512:
513:            public void setNorthPane(final JComponent c) {
514:                replacePane(getNorthPane(), c);
515:                northPane = c;
516:            }
517:
518:            public JComponent getNorthPane() {
519:                return northPane;
520:            }
521:
522:            public void setEastPane(final JComponent c) {
523:                eastPane = c;
524:            }
525:
526:            public JComponent getEastPane() {
527:                return eastPane;
528:            }
529:
530:            public Dimension getPreferredSize(final JComponent c) {
531:                if (c != frame) {
532:                    return new Dimension(100, 100);
533:                }
534:
535:                return internalFrameLayout.preferredLayoutSize(c);
536:            }
537:
538:            public Dimension getMinimumSize(final JComponent c) {
539:                if (c != frame) {
540:                    return new Dimension(0, 0);
541:                }
542:
543:                return internalFrameLayout.minimumLayoutSize(c);
544:            }
545:
546:            public Dimension getMaximumSize(final JComponent c) {
547:                return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
548:            }
549:
550:            public static ComponentUI createUI(final JComponent c) {
551:                return new BasicInternalFrameUI((JInternalFrame) c);
552:            }
553:
554:            public void installUI(final JComponent c) {
555:                frame = (JInternalFrame) c;
556:
557:                installDefaults();
558:                installListeners();
559:                installComponents();
560:                installKeyboardActions();
561:            }
562:
563:            public void uninstallUI(final JComponent c) {
564:                uninstallKeyboardActions();
565:                uninstallComponents();
566:                uninstallListeners();
567:                uninstallDefaults();
568:            }
569:
570:            protected MouseInputAdapter createBorderListener(
571:                    final JInternalFrame f) {
572:                return new BorderListener();
573:            }
574:
575:            protected JComponent createWestPane(final JInternalFrame f) {
576:                return null;
577:            }
578:
579:            protected JComponent createSouthPane(final JInternalFrame f) {
580:                return null;
581:            }
582:
583:            protected JComponent createNorthPane(final JInternalFrame f) {
584:                titlePane = new BasicInternalFrameTitlePane(f);
585:                return titlePane;
586:            }
587:
588:            protected JComponent createEastPane(final JInternalFrame f) {
589:                return null;
590:            }
591:
592:            protected void replacePane(final JComponent oldPane,
593:                    final JComponent newPane) {
594:                if (oldPane != null) {
595:                    deinstallMouseHandlers(oldPane);
596:                    frame.remove(oldPane);
597:                }
598:
599:                if (newPane != null) {
600:                    installMouseHandlers(newPane);
601:                    frame.add(newPane);
602:                    if (newPane instanceof  BasicInternalFrameTitlePane) {
603:                        titlePane = ((BasicInternalFrameTitlePane) newPane);
604:                    }
605:                }
606:            }
607:
608:            protected void minimizeFrame(final JInternalFrame f) {
609:                getDesktopManager().minimizeFrame(f);
610:                fireSoundAction("InternalFrame.restoreDownSound");
611:            }
612:
613:            protected void maximizeFrame(final JInternalFrame f) {
614:                getDesktopManager().maximizeFrame(f);
615:                fireSoundAction("InternalFrame.maximizeSound");
616:            }
617:
618:            protected void iconifyFrame(final JInternalFrame f) {
619:                getDesktopManager().iconifyFrame(f);
620:                fireSoundAction("InternalFrame.minimizeSound");
621:            }
622:
623:            protected void deiconifyFrame(final JInternalFrame f) {
624:                getDesktopManager().deiconifyFrame(f);
625:                fireSoundAction("InternalFrame.restoreUpSound");
626:            }
627:
628:            protected void activateFrame(final JInternalFrame f) {
629:                getDesktopManager().activateFrame(f);
630:                f.getGlassPane().setVisible(false);
631:            }
632:
633:            protected void deactivateFrame(final JInternalFrame f) {
634:                getDesktopManager().deactivateFrame(f);
635:                f.getGlassPane().setVisible(true);
636:            }
637:
638:            protected void closeFrame(final JInternalFrame f) {
639:                getDesktopManager().closeFrame(f);
640:                fireSoundAction("InternalFrame.closeSound");
641:            }
642:
643:            protected void installMouseHandlers(final JComponent c) {
644:                c.addMouseListener(borderListener);
645:                c.addMouseMotionListener(borderListener);
646:            }
647:
648:            protected void deinstallMouseHandlers(final JComponent c) {
649:                c.removeMouseListener(borderListener);
650:                c.removeMouseMotionListener(borderListener);
651:            }
652:
653:            protected DesktopManager getDesktopManager() {
654:                JDesktopPane desktop = frame.getDesktopPane();
655:                if (desktop != null) {
656:                    return desktop.getDesktopManager();
657:                }
658:
659:                if (defaultDesktopManager == null) {
660:                    defaultDesktopManager = createDesktopManager();
661:                }
662:                return defaultDesktopManager;
663:            }
664:
665:            protected DesktopManager createDesktopManager() {
666:                return new DefaultDesktopManager();
667:            }
668:
669:            protected PropertyChangeListener createPropertyChangeListener() {
670:                if (propertyChangeListener == null) {
671:                    propertyChangeListener = new InternalFramePropertyChangeListener();
672:                }
673:
674:                return propertyChangeListener;
675:            }
676:
677:            protected MouseInputListener createGlassPaneDispatcher() {
678:                return new GlassPaneDispatcher();
679:            }
680:
681:            protected ComponentListener createComponentListener() {
682:                return new ComponentHandler();
683:            }
684:
685:            protected LayoutManager createLayoutManager() {
686:                return new InternalFrameLayout();
687:            }
688:
689:            protected final void setKeyBindingRegistered(final boolean b) {
690:                keyBindingRegistered = b;
691:            }
692:
693:            protected final boolean isKeyBindingRegistered() {
694:                return keyBindingRegistered;
695:            }
696:
697:            protected final void setKeyBindingActive(final boolean b) {
698:                keyBindingActive = b;
699:            }
700:
701:            public final boolean isKeyBindingActive() {
702:                return keyBindingActive;
703:            }
704:
705:            protected void setupMenuOpenKey() {
706:                if (frame == null) {
707:                    throw new NullPointerException();
708:                }
709:
710:                Object[] keys = (Object[]) UIManager
711:                        .get("InternalFrame.windowBindings");
712:                if (keys == null) {
713:                    return;
714:                }
715:
716:                InputMap map = LookAndFeel.makeComponentInputMap(frame, keys);
717:                SwingUtilities.replaceUIInputMap(frame,
718:                        JComponent.WHEN_IN_FOCUSED_WINDOW, map);
719:            }
720:
721:            protected void setupMenuCloseKey() {
722:                // does nothing, all the work is done in setupMenuOnenKey()
723:            }
724:
725:            protected void installListeners() {
726:                borderListener = createBorderListener(frame);
727:                installMouseHandlers(frame);
728:
729:                componentListener = createComponentListener();
730:                if (frame.getParent() != null) {
731:                    frame.getParent().addComponentListener(componentListener);
732:                }
733:
734:                glassPaneDispatcher = createGlassPaneDispatcher();
735:                frame.getGlassPane().addMouseListener(glassPaneDispatcher);
736:                frame.getGlassPane()
737:                        .addMouseMotionListener(glassPaneDispatcher);
738:
739:                propertyChangeListener = createPropertyChangeListener();
740:                frame.addPropertyChangeListener(propertyChangeListener);
741:            }
742:
743:            protected void uninstallListeners() {
744:                frame.removePropertyChangeListener(propertyChangeListener);
745:
746:                frame.getGlassPane().removeMouseListener(glassPaneDispatcher);
747:                frame.getGlassPane().removeMouseMotionListener(
748:                        glassPaneDispatcher);
749:
750:                if (frame.getParent() != null) {
751:                    frame.getParent()
752:                            .removeComponentListener(componentListener);
753:                }
754:
755:                deinstallMouseHandlers(frame);
756:            }
757:
758:            protected void installKeyboardActions() {
759:                createInternalFrameListener();
760:                frame.addInternalFrameListener(internalFrameListener);
761:
762:                ActionMapUIResource actionMap = new ActionMapUIResource();
763:                actionMap.put("showSystemMenu", new AbstractAction() {
764:                    public void actionPerformed(final ActionEvent e) {
765:                        if (titlePane != null) {
766:                            titlePane.showSystemMenu();
767:                        }
768:                    }
769:                });
770:
771:                actionMap.setParent(((BasicLookAndFeel) UIManager
772:                        .getLookAndFeel()).getAudioActionMap());
773:                SwingUtilities.replaceUIActionMap(frame, actionMap);
774:            }
775:
776:            protected void uninstallKeyboardActions() {
777:                SwingUtilities.replaceUIActionMap(frame, null);
778:                SwingUtilities.replaceUIInputMap(frame,
779:                        JComponent.WHEN_IN_FOCUSED_WINDOW, null);
780:
781:                frame.removeInternalFrameListener(internalFrameListener);
782:            }
783:
784:            protected void installDefaults() {
785:                if (Utilities.isUIResource(frame.getBackground())) {
786:                    frame.setBackground(UIManager
787:                            .getColor("InternalFrame.inactiveTitleBackground"));
788:                }
789:
790:                LookAndFeel.installBorder(frame, "InternalFrame.border");
791:
792:                if (Utilities.isUIResource(frame.getFrameIcon())) {
793:                    frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
794:                }
795:
796:                internalFrameLayout = createLayoutManager();
797:                frame.setLayout(internalFrameLayout);
798:
799:                LookAndFeel.installProperty(frame, "opaque", Boolean.TRUE);
800:            }
801:
802:            protected void uninstallDefaults() {
803:                LookAndFeel.uninstallBorder(frame);
804:
805:                if (frame.getFrameIcon() instanceof  UIResource) {
806:                    frame.setFrameIcon(null);
807:                }
808:
809:                internalFrameLayout = null;
810:                frame.setLayout(internalFrameLayout);
811:            }
812:
813:            protected void installComponents() {
814:                setNorthPane(createNorthPane(frame));
815:            }
816:
817:            protected void uninstallComponents() {
818:                setNorthPane(null);
819:            }
820:
821:            protected void createInternalFrameListener() {
822:                if (internalFrameListener == null) {
823:                    internalFrameListener = new BasicInternalFrameListener();
824:                }
825:            }
826:
827:            private Container getFrameParent() {
828:                Container parent = frame.getParent();
829:                if (parent == null) {
830:                    parent = frame.getDesktopIcon().getParent();
831:                }
832:                return parent;
833:            }
834:
835:            private void fireSoundAction(final String name) {
836:                ((BasicLookAndFeel) UIManager.getLookAndFeel())
837:                        .fireSoundAction(frame, name);
838:            }
839:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.