home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / WindowsDesktopPaneUI.java < prev    next >
Text File  |  1998-02-26  |  4KB  |  113 lines

  1. /*
  2.  * @(#)WindowsDesktopPaneUI.java    1.6 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.windows;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.plaf.basic.*;
  25. import com.sun.java.swing.plaf.ComponentUI;
  26. import java.awt.event.*;
  27.  
  28. /**
  29.  * Windows desktop pane.
  30.  * <p>
  31.  * Warning: serialized objects of this class will not be compatible with
  32.  * future swing releases.  The current serialization support is appropriate
  33.  * for short term storage or RMI between Swing1.0 applications.  It will
  34.  * not be possible to load serialized Swing1.0 objects with future releases
  35.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  36.  * baseline for the serialized form of Swing objects.
  37.  *
  38.  * @version %i% 02/02/98
  39.  * @author unknown
  40.  */
  41. public class WindowsDesktopPaneUI extends BasicDesktopPaneUI
  42. {
  43.     public static ComponentUI createUI(JComponent c) {
  44.         return new WindowsDesktopPaneUI();
  45.     }
  46.  
  47.     protected void installDesktopManager() {
  48.     if(desktop.getDesktopManager() == null) {
  49.         desktopManager = new WindowsDesktopManager();
  50.         desktop.setDesktopManager(desktopManager);
  51.     }
  52.     }
  53.  
  54.     public void installUI(JComponent c) {
  55.         super.installUI(c);
  56.         installKeyboardActions(c);
  57.     }
  58.  
  59.     public void uninstallUI(JComponent c) {
  60.         uninstallKeyboardActions(c);
  61.         super.uninstallUI(c);
  62.     }
  63.  
  64.     void switchFrame(boolean next) {
  65.         WindowsDesktopManager dm = 
  66.             (WindowsDesktopManager)desktop.getDesktopManager();
  67.         if (dm == null) {
  68.             return;
  69.         }
  70.         if (next) {
  71.             dm.activateNextFrame();
  72.         } else {
  73.             dm.activatePreviousFrame();
  74.         }
  75.     }
  76.  
  77.     protected void installKeyboardActions(JComponent c) {
  78.         c.registerKeyboardAction(
  79.             new AbstractAction() {
  80.                 public void actionPerformed(ActionEvent e) {
  81.                     switchFrame(true);
  82.                 }
  83.                 public boolean isEnabled() { 
  84.                     return true; 
  85.                 }
  86.             },
  87.             KeyStroke.getKeyStroke(KeyEvent.VK_F6, InputEvent.ALT_MASK), 
  88.             JComponent.WHEN_IN_FOCUSED_WINDOW);
  89.         c.registerKeyboardAction(
  90.             new AbstractAction() {
  91.                 public void actionPerformed(ActionEvent e) {
  92.                     switchFrame(false);
  93.                 }
  94.                 public boolean isEnabled() { 
  95.                     return true; 
  96.                 }
  97.             },
  98.             KeyStroke.getKeyStroke(KeyEvent.VK_F6, 
  99.                                    InputEvent.ALT_MASK | InputEvent.SHIFT_MASK), 
  100.             JComponent.WHEN_IN_FOCUSED_WINDOW);
  101.         
  102.         // Request focus if it isn't set.
  103.         if(!c.requestDefaultFocus()) {
  104.             c.requestFocus();
  105.         }
  106.     }
  107.  
  108.     protected void uninstallKeyboardActions(JComponent c) {
  109.         c.resetKeyboardActions();
  110.     }
  111. }
  112.  
  113.