home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / JFC.bin / MetalProgressBarUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  111 lines

  1. /*
  2.  * @(#)MetalProgressBarUI.java    1.10 98/04/11
  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.metal;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.plaf.*;
  25. import com.sun.java.swing.plaf.basic.*;
  26. //import com.sun.java.swing.event.*;
  27. import java.awt.*;
  28.  
  29. /**
  30.  * The Metal implementation of ProgressBarUI.
  31.  * <p>
  32.  * Warning: serialized objects of this class will not be compatible with
  33.  * future swing releases.  The current serialization support is appropriate
  34.  * for short term storage or RMI between Swing1.0 applications.  It will
  35.  * not be possible to load serialized Swing1.0 objects with future releases
  36.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  37.  * baseline for the serialized form of Swing objects.
  38.  *
  39.  * @version 1.10 04/11/98
  40.  * @author Michael C. Albers
  41.  */
  42. public class MetalProgressBarUI extends BasicProgressBarUI {
  43.  
  44.     public static ComponentUI createUI(JComponent c) {
  45.     return new MetalProgressBarUI();
  46.     }
  47.  
  48.     /**
  49.      * The sole reason for this paint method to even be here is that
  50.      * the JLF/Metal ProgressBar has a bit of special highlighting that
  51.      * needs to get drawn. The core painting is defered to the
  52.      * BasicProgressBar's paint method.
  53.      */ 
  54.     public void paint(Graphics g, JComponent c) {
  55.     super.paint(g,c);
  56.  
  57.     JProgressBar progressBar = (JProgressBar)c;
  58.     BoundedRangeModel model = progressBar.getModel();
  59.  
  60.     Dimension size = progressBar.getSize(); //total size
  61.     Insets i = progressBar.getInsets(); // area for border
  62.     Rectangle barRect = new Rectangle(size); // area to draw progress
  63.  
  64.     barRect.x += i.left;
  65.     barRect.y += i.top;
  66.     barRect.width -= (i.right + barRect.x);
  67.     barRect.height -= (i.bottom + barRect.y);
  68.     int amountFull = getAmountFull(c); // amount of progress to draw
  69.     
  70.     if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
  71.          // Highlighting
  72.         //     over the unfilled portion
  73.         //     actually, draw all the way across - let others draw over it
  74.         g.setColor(MetalLookAndFeel.getControlShadow());
  75.         g.drawLine(barRect.x,barRect.y, barRect.width,barRect.y);
  76.  
  77.         //     line on left
  78.         if (model.getValue() == model.getMinimum()) { // haven't started
  79.         g.setColor(MetalLookAndFeel.getControlShadow());
  80.         } else { // Some portion of bar is filled
  81.         g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  82.         }
  83.         g.drawLine(barRect.x,barRect.y, barRect.x,barRect.height);
  84.  
  85.         //     over the filled portion
  86.         //     get color from "line on left" above
  87.         g.drawLine(barRect.x,barRect.y, amountFull,barRect.y);
  88.     } else { // VERTICAL
  89.         // Highlighting
  90.         //     left of the unfilled portion
  91.         //     actually, draw all the way down - let others draw over it
  92.         g.setColor(MetalLookAndFeel.getControlShadow());
  93.         g.drawLine(barRect.x,barRect.y, barRect.x,barRect.height);
  94.  
  95.         //     line on bottom
  96.         if (model.getValue() == model.getMinimum()) { // haven't started
  97.         g.setColor(MetalLookAndFeel.getControlShadow());
  98.         } else { // Some portion of bar is filled
  99.         g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
  100.         }
  101.         g.drawLine(barRect.x,     barRect.height,
  102.                barRect.width, barRect.height);
  103.  
  104.         //     left of the filled portion
  105.         //     pick up color from the "line on bottom" above
  106.         g.drawLine(barRect.x, barRect.height,
  107.                barRect.x, barRect.height-amountFull);
  108.     }
  109.     }
  110. }
  111.