1 /*
   2  * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.java.swing.plaf.motif;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 
  31 import java.io.*;
  32 import java.util.*;
  33 
  34 import javax.swing.*;
  35 import javax.swing.plaf.*;
  36 import javax.swing.tree.*;
  37 import javax.swing.plaf.basic.*;
  38 
  39 /**
  40  * Motif rendition of the tree component.
  41  * <p>
  42  * <strong>Warning:</strong>
  43  * Serialized objects of this class will not be compatible with
  44  * future Swing releases.  The current serialization support is appropriate
  45  * for short term storage or RMI between applications running the same
  46  * version of Swing.  A future release of Swing will provide support for
  47  * long term persistence.
  48  *
  49  * @author Jeff Dinkins
  50  */
  51 public class MotifTreeUI extends BasicTreeUI
  52 {
  53     static final int HALF_SIZE = 7;
  54     static final int SIZE = 14;
  55 
  56     /**
  57      * creates a UI object to represent a Motif Tree widget
  58      */
  59     public MotifTreeUI() {
  60         super();
  61     }
  62 
  63     public void installUI(JComponent c) {
  64         super.installUI(c);
  65     }
  66 
  67     // BasicTreeUI overrides
  68 
  69     protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
  70       {
  71           if (tree.getComponentOrientation().isLeftToRight()) {
  72               g.fillRect( x, top, 2, bottom - top + 2 );
  73           } else {
  74               g.fillRect( x - 1, top, 2, bottom - top + 2 );
  75           }
  76       }
  77 
  78     protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
  79       {
  80           g.fillRect( left, y, right - left + 1, 2 );
  81       }
  82 
  83 
  84     /**
  85      * The minus sign button icon.
  86      * <p>
  87      * <strong>Warning:</strong>
  88      * Serialized objects of this class will not be compatible with
  89      * future Swing releases.  The current serialization support is appropriate
  90      * for short term storage or RMI between applications running the same
  91      * version of Swing.  A future release of Swing will provide support for
  92      * long term persistence.
  93      */
  94     public static class MotifExpandedIcon implements Icon, Serializable {
  95         static Color bg;
  96         static Color fg;
  97         static Color highlight;
  98         static Color shadow;
  99 
 100         public MotifExpandedIcon() {
 101             bg = UIManager.getColor("Tree.iconBackground");
 102             fg = UIManager.getColor("Tree.iconForeground");
 103             highlight = UIManager.getColor("Tree.iconHighlight");
 104             shadow = UIManager.getColor("Tree.iconShadow");
 105         }
 106 
 107         public static Icon createExpandedIcon() {
 108             return new MotifExpandedIcon();
 109         }
 110 
 111         public void paintIcon(Component c, Graphics g, int x, int y) {
 112             g.setColor(highlight);
 113             g.drawLine(x, y, x+SIZE-1, y);
 114             g.drawLine(x, y+1, x, y+SIZE-1);
 115 
 116             g.setColor(shadow);
 117             g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1);
 118             g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1);
 119 
 120             g.setColor(bg);
 121             g.fillRect(x+1, y+1, SIZE-2, SIZE-2);
 122 
 123             g.setColor(fg);
 124             g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1);
 125             g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE);
 126         }
 127 
 128         public int getIconWidth() { return SIZE; }
 129         public int getIconHeight() { return SIZE; }
 130     }
 131 
 132     /**
 133      * The plus sign button icon.
 134      * <p>
 135      * <strong>Warning:</strong>
 136      * Serialized objects of this class will not be compatible with
 137      * future Swing releases.  The current serialization support is appropriate
 138      * for short term storage or RMI between applications running the same
 139      * version of Swing.  A future release of Swing will provide support for
 140      * long term persistence.
 141      */
 142     public static class MotifCollapsedIcon extends MotifExpandedIcon {
 143         public static Icon createCollapsedIcon() {
 144             return new MotifCollapsedIcon();
 145         }
 146 
 147         public void paintIcon(Component c, Graphics g, int x, int y) {
 148             super.paintIcon(c, g, x, y);
 149             g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4));
 150             g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4));
 151         }
 152     }
 153 
 154     public static ComponentUI createUI(JComponent x) {
 155         return new MotifTreeUI();
 156     }
 157 
 158     /**
 159      * Returns the default cell renderer that is used to do the
 160      * stamping of each node.
 161      */
 162     public TreeCellRenderer createDefaultCellRenderer() {
 163         return new MotifTreeCellRenderer();
 164     }
 165 
 166 }