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

  1. /*
  2.  * @(#)MetalToggleButtonUI.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.metal;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import com.sun.java.swing.plaf.basic.BasicToggleButtonUI;
  26.  
  27. import com.sun.java.swing.*;
  28. import com.sun.java.swing.border.*;
  29. import com.sun.java.swing.plaf.*;
  30. import com.sun.java.swing.*;
  31.  
  32. import java.io.Serializable;
  33.  
  34. /**
  35.  * MetalToggleButton implementation
  36.  * <p>
  37.  * Warning: serialized objects of this class will not be compatible with
  38.  * future swing releases.  The current serialization support is appropriate
  39.  * for short term storage or RMI between Swing1.0 applications.  It will
  40.  * not be possible to load serialized Swing1.0 objects with future releases
  41.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  42.  * baseline for the serialized form of Swing objects.
  43.  *
  44.  * @version 1.6 02/02/98
  45.  * @author Tom Santos
  46.  */
  47. public class MetalToggleButtonUI extends BasicToggleButtonUI {
  48.     private static Color selectedColor;
  49.     private static Color disabledTextColor;
  50.     private static Color focusColor;
  51.  
  52.     protected final static Insets defaultMargin = new Insets(2,14,2,14);
  53.  
  54.     private static final MetalToggleButtonUI metalToggleButtonUI = new MetalToggleButtonUI();
  55.  
  56.     public static ComponentUI createUI(JComponent b) {
  57.         return metalToggleButtonUI;
  58.     }
  59.  
  60.     public void installUI(JComponent c) {
  61.         super.installUI(c);
  62.     selectedColor = UIManager.getColor("ToggleButton.selected");
  63.     disabledTextColor = UIManager.getColor("ToggleButton.disabledText");
  64.     focusColor = UIManager.getColor("ToggleButton.focus");
  65.     }
  66.  
  67.     protected void paintButtonPressed(Graphics g, AbstractButton b) {
  68.         Dimension size = b.getSize();
  69.     g.setColor( selectedColor );
  70.     g.fillRect( 0, 0, size.width, size.height );
  71.     }
  72.  
  73.     public Insets getDefaultMargin( AbstractButton b ) {
  74.         return defaultMargin;
  75.     }
  76.  
  77.     static class MetalToggleButtonBorder extends MetalButtonBorder {
  78.         public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  79.         JToggleButton button = (JToggleButton)c;
  80.         ButtonModel model = button.getModel();
  81.  
  82.         if ( model.isPressed() && model.isArmed() ) {
  83.             MetalUtils.drawPressed3DBorder( g, x, y, w, h );
  84.         } else if (button.hasFocus()) {
  85.             MetalUtils.drawActiveButtonBorder( g, x, y, w, h );
  86.         } else if ( model.isSelected() ) {
  87.             MetalUtils.drawDark3DBorder( g, x, y, w, h );
  88.         } else {
  89.             MetalUtils.drawFlush3DBorder( g, x, y, w, h );
  90.         }
  91.     }
  92.     }
  93.  
  94.     protected void paintFocus(Graphics g, Dimension size){
  95.         g.setColor(toggleButtonFocus);
  96.     g.drawRect(2,2, size.width-5, size.height-5);    
  97.     }
  98. }
  99.