src/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2006, 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


 287 
 288     private Handler getHandler() {
 289         if (handler == null) {
 290             handler = new Handler();
 291         }
 292         return handler;
 293     }
 294 
 295     private class Handler implements PropertyChangeListener {
 296         public void propertyChange(PropertyChangeEvent evt) {
 297             String propertyName = evt.getPropertyName();
 298             if ("desktopManager" == propertyName) {
 299                 installDesktopManager();
 300             }
 301         }
 302     }
 303 
 304     /**
 305      * The default DesktopManager installed by the UI.
 306      */

 307     private class BasicDesktopManager extends DefaultDesktopManager
 308             implements UIResource {
 309     }
 310 
 311     private static class Actions extends UIAction {
 312         private static String CLOSE = "close";
 313         private static String ESCAPE = "escape";
 314         private static String MAXIMIZE = "maximize";
 315         private static String MINIMIZE = "minimize";
 316         private static String MOVE = "move";
 317         private static String RESIZE = "resize";
 318         private static String RESTORE = "restore";
 319         private static String LEFT = "left";
 320         private static String RIGHT = "right";
 321         private static String UP = "up";
 322         private static String DOWN = "down";
 323         private static String SHRINK_LEFT = "shrinkLeft";
 324         private static String SHRINK_RIGHT = "shrinkRight";
 325         private static String SHRINK_UP = "shrinkUp";
 326         private static String SHRINK_DOWN = "shrinkDown";


 615                 if (iFrame == null) {
 616                     return false;
 617                 } else if (action == Actions.CLOSE) {
 618                     return iFrame.isClosable();
 619                 } else if (action == Actions.MINIMIZE) {
 620                     return iFrame.isIconifiable();
 621                 } else if (action == Actions.MAXIMIZE) {
 622                     return iFrame.isMaximizable();
 623                 }
 624                 return true;
 625             }
 626             return false;
 627         }
 628     }
 629 
 630 
 631     /**
 632      * Handles restoring a minimized or maximized internal frame.
 633      * @since 1.3
 634      */

 635     protected class OpenAction extends AbstractAction {
 636         public void actionPerformed(ActionEvent evt) {
 637             JDesktopPane dp = (JDesktopPane)evt.getSource();
 638             SHARED_ACTION.setState(dp, Actions.RESTORE);
 639         }
 640 
 641         public boolean isEnabled() {
 642             return true;
 643         }
 644     }
 645 
 646     /**
 647      * Handles closing an internal frame.
 648      */

 649     protected class CloseAction extends AbstractAction {
 650         public void actionPerformed(ActionEvent evt) {
 651             JDesktopPane dp = (JDesktopPane)evt.getSource();
 652             SHARED_ACTION.setState(dp, Actions.CLOSE);
 653         }
 654 
 655         public boolean isEnabled() {
 656             JInternalFrame iFrame = desktop.getSelectedFrame();
 657             if (iFrame != null) {
 658                 return iFrame.isClosable();
 659             }
 660             return false;
 661         }
 662     }
 663 
 664     /**
 665      * Handles minimizing an internal frame.
 666      */

 667     protected class MinimizeAction extends AbstractAction {
 668         public void actionPerformed(ActionEvent evt) {
 669             JDesktopPane dp = (JDesktopPane)evt.getSource();
 670             SHARED_ACTION.setState(dp, Actions.MINIMIZE);
 671         }
 672 
 673         public boolean isEnabled() {
 674             JInternalFrame iFrame = desktop.getSelectedFrame();
 675             if (iFrame != null) {
 676                 return iFrame.isIconifiable();
 677             }
 678             return false;
 679         }
 680     }
 681 
 682     /**
 683      * Handles maximizing an internal frame.
 684      */

 685     protected class MaximizeAction extends AbstractAction {
 686         public void actionPerformed(ActionEvent evt) {
 687             JDesktopPane dp = (JDesktopPane)evt.getSource();
 688             SHARED_ACTION.setState(dp, Actions.MAXIMIZE);
 689         }
 690 
 691         public boolean isEnabled() {
 692             JInternalFrame iFrame = desktop.getSelectedFrame();
 693             if (iFrame != null) {
 694                 return iFrame.isMaximizable();
 695             }
 696             return false;
 697         }
 698     }
 699 
 700     /**
 701      * Handles navigating to the next internal frame.
 702      */

 703     protected class NavigateAction extends AbstractAction {
 704         public void actionPerformed(ActionEvent evt) {
 705             JDesktopPane dp = (JDesktopPane)evt.getSource();
 706             dp.selectFrame(true);
 707         }
 708 
 709         public boolean isEnabled() {
 710             return true;
 711         }
 712     }
 713 }
   1 /*
   2  * Copyright (c) 1997, 2014, 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


 287 
 288     private Handler getHandler() {
 289         if (handler == null) {
 290             handler = new Handler();
 291         }
 292         return handler;
 293     }
 294 
 295     private class Handler implements PropertyChangeListener {
 296         public void propertyChange(PropertyChangeEvent evt) {
 297             String propertyName = evt.getPropertyName();
 298             if ("desktopManager" == propertyName) {
 299                 installDesktopManager();
 300             }
 301         }
 302     }
 303 
 304     /**
 305      * The default DesktopManager installed by the UI.
 306      */
 307     @SuppressWarnings("serial") // JDK-implementation class
 308     private class BasicDesktopManager extends DefaultDesktopManager
 309             implements UIResource {
 310     }
 311 
 312     private static class Actions extends UIAction {
 313         private static String CLOSE = "close";
 314         private static String ESCAPE = "escape";
 315         private static String MAXIMIZE = "maximize";
 316         private static String MINIMIZE = "minimize";
 317         private static String MOVE = "move";
 318         private static String RESIZE = "resize";
 319         private static String RESTORE = "restore";
 320         private static String LEFT = "left";
 321         private static String RIGHT = "right";
 322         private static String UP = "up";
 323         private static String DOWN = "down";
 324         private static String SHRINK_LEFT = "shrinkLeft";
 325         private static String SHRINK_RIGHT = "shrinkRight";
 326         private static String SHRINK_UP = "shrinkUp";
 327         private static String SHRINK_DOWN = "shrinkDown";


 616                 if (iFrame == null) {
 617                     return false;
 618                 } else if (action == Actions.CLOSE) {
 619                     return iFrame.isClosable();
 620                 } else if (action == Actions.MINIMIZE) {
 621                     return iFrame.isIconifiable();
 622                 } else if (action == Actions.MAXIMIZE) {
 623                     return iFrame.isMaximizable();
 624                 }
 625                 return true;
 626             }
 627             return false;
 628         }
 629     }
 630 
 631 
 632     /**
 633      * Handles restoring a minimized or maximized internal frame.
 634      * @since 1.3
 635      */
 636     @SuppressWarnings("serial") // Superclass is not serializable across versions
 637     protected class OpenAction extends AbstractAction {
 638         public void actionPerformed(ActionEvent evt) {
 639             JDesktopPane dp = (JDesktopPane)evt.getSource();
 640             SHARED_ACTION.setState(dp, Actions.RESTORE);
 641         }
 642 
 643         public boolean isEnabled() {
 644             return true;
 645         }
 646     }
 647 
 648     /**
 649      * Handles closing an internal frame.
 650      */
 651     @SuppressWarnings("serial") // Superclass is not serializable across versions
 652     protected class CloseAction extends AbstractAction {
 653         public void actionPerformed(ActionEvent evt) {
 654             JDesktopPane dp = (JDesktopPane)evt.getSource();
 655             SHARED_ACTION.setState(dp, Actions.CLOSE);
 656         }
 657 
 658         public boolean isEnabled() {
 659             JInternalFrame iFrame = desktop.getSelectedFrame();
 660             if (iFrame != null) {
 661                 return iFrame.isClosable();
 662             }
 663             return false;
 664         }
 665     }
 666 
 667     /**
 668      * Handles minimizing an internal frame.
 669      */
 670     @SuppressWarnings("serial") // Superclass is not serializable across versions
 671     protected class MinimizeAction extends AbstractAction {
 672         public void actionPerformed(ActionEvent evt) {
 673             JDesktopPane dp = (JDesktopPane)evt.getSource();
 674             SHARED_ACTION.setState(dp, Actions.MINIMIZE);
 675         }
 676 
 677         public boolean isEnabled() {
 678             JInternalFrame iFrame = desktop.getSelectedFrame();
 679             if (iFrame != null) {
 680                 return iFrame.isIconifiable();
 681             }
 682             return false;
 683         }
 684     }
 685 
 686     /**
 687      * Handles maximizing an internal frame.
 688      */
 689     @SuppressWarnings("serial") // Superclass is not serializable across versions
 690     protected class MaximizeAction extends AbstractAction {
 691         public void actionPerformed(ActionEvent evt) {
 692             JDesktopPane dp = (JDesktopPane)evt.getSource();
 693             SHARED_ACTION.setState(dp, Actions.MAXIMIZE);
 694         }
 695 
 696         public boolean isEnabled() {
 697             JInternalFrame iFrame = desktop.getSelectedFrame();
 698             if (iFrame != null) {
 699                 return iFrame.isMaximizable();
 700             }
 701             return false;
 702         }
 703     }
 704 
 705     /**
 706      * Handles navigating to the next internal frame.
 707      */
 708     @SuppressWarnings("serial") // Superclass is not serializable across versions
 709     protected class NavigateAction extends AbstractAction {
 710         public void actionPerformed(ActionEvent evt) {
 711             JDesktopPane dp = (JDesktopPane)evt.getSource();
 712             dp.selectFrame(true);
 713         }
 714 
 715         public boolean isEnabled() {
 716             return true;
 717         }
 718     }
 719 }