jdk/src/share/classes/javax/swing/plaf/metal/MetalTreeUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 23010 6dadb192ad81
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The metal look and feel implementation of <code>TreeUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>MetalTreeUI</code> allows for configuring how to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * visually render the spacing and delineation between nodes. The following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * hints are supported:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <table summary="Descriptions of supported hints: Angled, Horizontal, and None">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *  <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
    49
 *    <th><p style="text-align:left">Angled</p></th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    <td>A line is drawn connecting the child to the parent. For handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *          of the root node refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *          {@link javax.swing.JTree#setRootVisible} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *          {@link javax.swing.JTree#setShowsRootHandles}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *    </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *  <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
    57
 *     <th><p style="text-align:left">Horizontal</p></th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     <td>A horizontal line is drawn dividing the children of the root node.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *  <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
    61
 *      <th><p style="text-align:left">None</p></th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      <td>Do not draw any visual indication between nodes.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20451
diff changeset
    67
 * As it is typically impractical to obtain the <code>TreeUI</code> from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the <code>JTree</code> and cast to an instance of <code>MetalTreeUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * you enable this property via the client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <code>JTree.lineStyle</code>. For example, to switch to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>Horizontal</code> style you would do:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>tree.putClientProperty("JTree.lineStyle", "Horizontal");</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * The default is <code>Angled</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @author Steve Wilson (value add stuff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class MetalTreeUI extends BasicTreeUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static Color lineColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final String LINE_STYLE = "JTree.lineStyle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final String LEG_LINE_STYLE_STRING = "Angled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final String HORIZ_STYLE_STRING = "Horizontal";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final String NO_STYLE_STRING = "None";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final int LEG_LINE_STYLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final int HORIZ_LINE_STYLE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final int NO_LINE_STYLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int lineStyle = LEG_LINE_STYLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private PropertyChangeListener lineStyleListener = new LineListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    96
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    97
     * Constructs the {@code MetalTreeUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    98
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
    99
     * @param x a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   100
     * @return the instance of the {@code MetalTreeUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   101
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return new MetalTreeUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   106
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   107
     * Constructs the {@code MetalTreeUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   108
     */
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   109
    public MetalTreeUI() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   113
    protected int getHorizontalLegBuffer() {
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   114
        return 3;
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   115
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void installUI( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super.installUI( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        lineColor = UIManager.getColor( "Tree.line" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Object lineStyleFlag = c.getClientProperty( LINE_STYLE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        decodeLineStyle(lineStyleFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        c.addPropertyChangeListener(lineStyleListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public void uninstallUI( JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         c.removePropertyChangeListener(lineStyleListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         super.uninstallUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   132
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   133
     * Converts between the string passed into the client property
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   134
     * and the internal representation (currently and int)
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   135
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   136
     * @param lineStyleFlag a flag
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   137
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected void decodeLineStyle(Object lineStyleFlag) {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   139
        if ( lineStyleFlag == null ||
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   140
                    lineStyleFlag.equals(LEG_LINE_STYLE_STRING)) {
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   141
            lineStyle = LEG_LINE_STYLE; // default case
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   142
        } else {
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   143
            if ( lineStyleFlag.equals(NO_STYLE_STRING) ) {
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   144
                lineStyle = NO_LINE_STYLE;
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   145
            } else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) {
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   146
                lineStyle = HORIZ_LINE_STYLE;
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   147
            }
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   148
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   151
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   152
     * Returns {@code true} if a point with X coordinate {@code mouseX}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   153
     * and Y coordinate {@code mouseY} is in expanded control.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   154
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   155
     * @param row a row
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   156
     * @param rowLevel a row level
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   157
     * @param mouseX X coordinate
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   158
     * @param mouseY Y coordinate
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   159
     * @return {@code true} if a point with X coordinate {@code mouseX}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   160
     *         and Y coordinate {@code mouseY} is in expanded control.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   161
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected boolean isLocationInExpandControl(int row, int rowLevel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                                int mouseX, int mouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if(tree != null && !isLeaf(row)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            int                     boxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if(getExpandedIcon() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                boxWidth = getExpandedIcon().getIconWidth() + 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                boxWidth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            Insets i = tree.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            int    boxLeftX = (i != null) ? i.left : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            boxLeftX += (((rowLevel + depthOffset - 1) * totalChildIndent) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        getLeftChildIndent()) - boxWidth/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            int boxRightX = boxLeftX + boxWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return mouseX >= boxLeftX && mouseX <= boxRightX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        super.paint( g, c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // Paint the lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (lineStyle == HORIZ_LINE_STYLE && !largeModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            paintHorizontalSeparators(g,c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   196
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   197
     * Paints the horizontal separators.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   198
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   199
     * @param g an instance of {@code Graphics}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   200
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 23010
diff changeset
   201
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    protected void paintHorizontalSeparators(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        g.setColor( lineColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Rectangle clipBounds = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        int beginRow = getRowForPath(tree, getClosestPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                     (tree, 0, clipBounds.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        int endRow = getRowForPath(tree, getClosestPathForLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                             (tree, 0, clipBounds.y + clipBounds.height - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if ( beginRow <= -1 || endRow <= -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        for ( int i = beginRow; i <= endRow; ++i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            TreePath        path = getPathForRow(tree, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if(path != null && path.getPathCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                Rectangle       rowBounds = getPathBounds(tree,getPathForRow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                                          (tree, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                // Draw a line at the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if(rowBounds != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    g.drawLine(clipBounds.x, rowBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                               clipBounds.x + clipBounds.width, rowBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                          Insets insets, TreePath path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (lineStyle == LEG_LINE_STYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                            Insets insets, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                            TreePath path, int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                            boolean isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                            boolean hasBeenExpanded, boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                            isLeaf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (lineStyle == LEG_LINE_STYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                           path, row, isExpanded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                           hasBeenExpanded, isLeaf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /** This class listens for changes in line style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    class LineListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if ( name.equals( LINE_STYLE ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                decodeLineStyle(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    } // end class PaletteListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
}