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

  1. /*
  2.  * @(#)OrganicDesktopMenu.java    1.5 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.organic;
  22.  
  23. import com.sun.java.swing.*;
  24. import java.awt.event.*;
  25. import java.awt.Point;
  26. import java.awt.Component;
  27. import java.awt.Dimension;
  28. import java.awt.Insets;
  29. import java.awt.Graphics;
  30. import com.sun.java.swing.plaf.DesktopPaneUI;
  31. import com.sun.java.swing.plaf.basic.BasicDesktopPaneUI;
  32. import java.util.*;
  33.  
  34.  
  35. /**
  36.  * This class implements the little square in the top-right corner of the OrganicDesktopPane.
  37.  * It doesn't have much behavior.  It is mostly in charge of display.
  38.  * <p>
  39.  * Warning: serialized objects of this class will not be compatible with
  40.  * future swing releases.  The current serialization support is appropriate
  41.  * for short term storage or RMI between Swing1.0 applications.  It will
  42.  * not be possible to load serialized Swing1.0 objects with future releases
  43.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  44.  * baseline for the serialized form of Swing objects.
  45.  *
  46.  * @see OrganicDesktopPaneUI
  47.  * @see OrganicDesktopManager
  48.  * @version 1.5 02/02/98
  49.  * @author Steve Wilson
  50.  */
  51. public class OrganicDesktopMenu extends JComponent implements ComponentListener{
  52.     static final int initWidth = 41;
  53.     static final int initHeight = 6;
  54.     static final int iconizedWindowHeight = 3;
  55.  
  56.     private int numberIconizedWindows;
  57.  
  58.     private OrganicDesktopPaneUI desktop;
  59.   
  60.  
  61.     public OrganicDesktopMenu(OrganicDesktopPaneUI pane) {
  62.         setSize (initWidth, initHeight);
  63.     desktop = pane;
  64.     }
  65.  
  66.     /**
  67.       * this function moves the DesktopMenu to the correct location in it's parent
  68.       * container.  In Organic this is the Top-Right corner of the window.
  69.       */
  70.     protected void locateInParent(JComponent parent) {
  71.         setLocation(parent.getSize().width - (initWidth), 0 );
  72.  
  73.     }
  74.  
  75.     /**
  76.       * This method changes the size of the Desktop menu to allow
  77.       * each iconized window representation to fit within the bounds of the window
  78.       * it is called by the change() method in this class.
  79.       */
  80.     protected void resizeForWindows() {
  81.         numberIconizedWindows = desktop.getIconizedWindows().size();
  82.         setSize(initWidth, initHeight + numberIconizedWindows * iconizedWindowHeight);
  83.     }
  84.        
  85.     /**
  86.       * This method is called to notify the desktop menu
  87.       * that the number of iconized windows has changed.  When this
  88.       * function is called it causes the desktop menu to update its
  89.       * display to reflect the current state of the system.
  90.       */
  91.     public void change() {
  92.         resizeForWindows();
  93.     repaint();    
  94.     }
  95.  
  96.     /**
  97.       * this override from component displays the proper look 
  98.       * of the desktop menu.
  99.       */
  100.     public void paint (Graphics g) {
  101.         Dimension size = getSize();
  102.  
  103.         g.setColor(OrganicLookAndFeel.getLightAccent1()); 
  104.         g.fillRect(0,0, size.width, size.height); // paint the background
  105.  
  106.         g.setColor(OrganicLookAndFeel.getWindowFrameRight());
  107.         g.fillRect(1,1, 9, initHeight-2);  // paint the first square
  108.  
  109.         g.setColor(OrganicLookAndFeel.getWindowFrameBottom());
  110.         g.fillRect(11,1, 9, initHeight-2);  // paint the second square
  111.  
  112.         g.setColor(OrganicLookAndFeel.getWindowFrameTop());
  113.         g.fillRect(21,1, 9, initHeight-2);  // paint the third square
  114.  
  115.         g.setColor(OrganicLookAndFeel.getWindowFrameLeft());
  116.         g.fillRect(31,1, 9, initHeight-2);  // paint the fourth square
  117.  
  118.  
  119.     // paint each iconized window represenation
  120.     for ( int bar = 0; bar < numberIconizedWindows; bar++) {
  121.         int h = initHeight+(iconizedWindowHeight*bar);
  122.         g.setColor(OrganicLookAndFeel.getControl1());
  123.         g.drawLine( 1, h-1, initWidth-2, h-1 );
  124.         g.setColor(OrganicLookAndFeel.getControl3());
  125.         g.fillRect( 1, h, initWidth-2, iconizedWindowHeight-1);
  126.     }
  127.  
  128.      }
  129.   
  130.      /** 
  131.        *gets the location (in this components coordinate system
  132.        * which specifies where to display the popup menu
  133.        */
  134.      public Point getPopupLocation(JPopupMenu pop) {
  135.         int popWidth = pop.getPreferredSize().width;
  136.         int x = -popWidth + initWidth;
  137.         return new Point ( x, initHeight );
  138.  
  139.      }
  140.  
  141.      /**
  142.        * This implementation from ComponentListener is designed to
  143.        * deal with the case that someone resizes the desktop.
  144.        * If the desktop is resized then this is called back and we
  145.        * can adjust the location of the desktop menu
  146.        */
  147.      public void componentResized(ComponentEvent e) {
  148.          locateInParent((JComponent)this.getParent());
  149.      }
  150.   
  151.      public void componentHidden(ComponentEvent e) {} // stubbed for ComponentListener
  152.  
  153.      public void componentShown(ComponentEvent e) {} // stubbed for ComponentListener
  154.  
  155.      public void componentMoved(ComponentEvent e) {} // stubbed for ComponentListener
  156.  
  157. }
  158.