Source for javax.swing.plaf.metal.MetalTreeUI

   1: /* MetalTreeUI.java
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.metal;
  40: 
  41: import gnu.classpath.NotImplementedException;
  42: 
  43: import java.awt.Graphics;
  44: import java.awt.Insets;
  45: import java.awt.Rectangle;
  46: 
  47: import javax.swing.JComponent;
  48: import javax.swing.JTree;
  49: import javax.swing.tree.TreePath;
  50: import javax.swing.plaf.ComponentUI;
  51: import javax.swing.plaf.basic.BasicTreeUI;
  52: 
  53: /**
  54:  * A UI delegate for the {@link JTree} component.
  55:  */
  56: public class MetalTreeUI extends BasicTreeUI
  57: {
  58:   /**
  59:    * Constructs a new instance of <code>MetalTreeUI</code>.
  60:    */
  61:   public MetalTreeUI()
  62:   {
  63:     super();
  64:   }
  65: 
  66:   /**
  67:    * Returns a new instance of <code>MetalTreeUI</code>.
  68:    *
  69:    * @param component the component for which we return an UI instance
  70:    *
  71:    * @return A new instance of <code>MetalTreeUI</code>.
  72:    */
  73:   public static ComponentUI createUI(JComponent component)
  74:   {
  75:     return new MetalTreeUI();
  76:   }
  77:   
  78:   /**
  79:    * The horizontal element of legs between nodes starts at the right of the
  80:    * left-hand side of the child node by default. This method makes the
  81:    * leg end before that.
  82:    */
  83:   protected int getHorizontalLegBuffer()
  84:   {
  85:     return super.getHorizontalLegBuffer();
  86:   }
  87: 
  88:   /**
  89:    * Configures the specified component appropriate for the look and feel.
  90:    * This method is invoked when the ComponentUI instance is being installed 
  91:    * as the UI delegate on the specified component. This method should completely 
  92:    * configure the component for the look and feel, including the following:
  93:    * 1. Install any default property values for color, fonts, borders, icons, 
  94:    *    opacity, etc. on the component. Whenever possible, property values
  95:    *    initialized by the client program should not be overridden.
  96:    * 2. Install a LayoutManager on the component if necessary.
  97:    * 3. Create/add any required sub-components to the component.
  98:    * 4. Create/install event listeners on the component.
  99:    * 5. Create/install a PropertyChangeListener on the component in order 
 100:    *    to detect and respond to component property changes appropriately.
 101:    * 6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
 102:    * 7. Initialize any appropriate instance data. 
 103:    */
 104:   public void installUI(JComponent c)
 105:   {
 106:     // TODO: What to do here, if anything?
 107:     super.installUI(c);
 108:   }
 109:   
 110:   /**
 111:    * Reverses configuration which was done on the specified component during 
 112:    * installUI. This method is invoked when this UIComponent instance is being 
 113:    * removed as the UI delegate for the specified component. This method should 
 114:    * undo the configuration performed in installUI, being careful to leave the 
 115:    * JComponent instance in a clean state (no extraneous listeners, 
 116:    * look-and-feel-specific property objects, etc.). This should include 
 117:    * the following:
 118:    * 1. Remove any UI-set borders from the component.
 119:    * 2. Remove any UI-set layout managers on the component.
 120:    * 3. Remove any UI-added sub-components from the component.
 121:    * 4. Remove any UI-added event/property listeners from the component.
 122:    * 5. Remove any UI-installed keyboard UI from the component.
 123:    * 6. Nullify any allocated instance data objects to allow for GC. 
 124:    */
 125:   public void uninstallUI(JComponent c)
 126:   {
 127:     // TODO: What to do here?
 128:     super.uninstallUI(c);
 129:   }
 130:   
 131:   /**
 132:    * This function converts between the string passed into the client
 133:    * property and the internal representation (currently an int).
 134:    * 
 135:    * @param lineStyleFlag - String representation
 136:    */     
 137:   protected void decodeLineStyle(Object lineStyleFlag)
 138:     throws NotImplementedException
 139:   {
 140:     // FIXME: not implemented
 141:   }
 142: 
 143:   /**
 144:    * Checks if the location is in expand control.
 145:    * 
 146:    * @param row - current row
 147:    * @param rowLevel - current level
 148:    * @param mouseX - current x location of the mouse click
 149:    * @param mouseY - current y location of the mouse click
 150:    */
 151:   protected boolean isLocationInExpandControl(int row, int rowLevel,
 152:                                           int mouseX, int mouseY)
 153:   {
 154:     return super.isLocationInExpandControl(tree.getPathForRow(row), 
 155:                                            mouseX, mouseY);
 156:   }
 157:   
 158:   /**
 159:    * Paints the specified component appropriate for the look and feel. 
 160:    * This method is invoked from the ComponentUI.update method when the 
 161:    * specified component is being painted. Subclasses should override this 
 162:    * method and use the specified Graphics object to render the content of 
 163:    * the component.
 164:    * 
 165:    * @param g - the current graphics configuration.
 166:    * @param c - the current component to draw
 167:    */
 168:   public void paint(Graphics g, JComponent c)
 169:   {
 170:     // Calls BasicTreeUI's paint since it takes care of painting all
 171:     // types of icons. 
 172:     super.paint(g, c);
 173:   }
 174:   
 175:   /**
 176:    * Paints the horizontal separators.
 177:    * 
 178:    * @param g - the current graphics configuration.
 179:    * @param c - the current component to draw
 180:    */
 181:   protected void paintHorizontalSeparators(Graphics g, JComponent c)
 182:     throws NotImplementedException
 183:   {
 184:     // FIXME: not implemented
 185:   }
 186: 
 187:   
 188:   /**
 189:    * Paints the vertical part of the leg. The receiver should NOT modify 
 190:    * clipBounds, insets.
 191:    * 
 192:    * @param g - the current graphics configuration.
 193:    * @param clipBounds -
 194:    * @param insets - 
 195:    * @param path - the current path
 196:    */
 197:   protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
 198:                                     Insets insets, TreePath path)
 199:   {
 200:     super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
 201:   }
 202: 
 203:   /**
 204:    * Paints the horizontal part of the leg. The receiver should NOT \
 205:    * modify clipBounds, or insets.
 206:    * NOTE: parentRow can be -1 if the root is not visible.
 207:    */
 208:   protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
 209:                                         Insets insets, Rectangle bounds,
 210:                                         TreePath path, int row,
 211:                                         boolean isExpanded, boolean hasBeenExpanded,
 212:                                         boolean isLeaf)
 213:   {
 214:     super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, 
 215:                                    isExpanded, hasBeenExpanded, isLeaf);
 216:   }
 217: }