jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/motif/MotifTreeUI.java
author alexsch
Wed, 05 Oct 2016 18:42:34 +0400
changeset 41774 e9156811f79c
parent 25859 3317bb8137f4
permissions -rw-r--r--
8165485: Bad rendering of Swing UI controls with Motif L&F on HiDPI display 8147600: [hidpi] invalid rendering of Swing UI controls (radiobuttons, choice etc.) Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2014, 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 com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.*;
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
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Motif rendition of the tree component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class MotifTreeUI extends BasicTreeUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final int HALF_SIZE = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final int SIZE = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * creates a UI object to represent a Motif Tree widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public MotifTreeUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // BasicTreeUI overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
          if (tree.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
              g.fillRect( x, top, 2, bottom - top + 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
              g.fillRect( x - 1, top, 2, bottom - top + 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
          g.fillRect( left, y, right - left + 1, 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * The minus sign button icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
    94
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static class MotifExpandedIcon implements Icon, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        static Color bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        static Color fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        static Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        static Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public MotifExpandedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            bg = UIManager.getColor("Tree.iconBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            fg = UIManager.getColor("Tree.iconForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            highlight = UIManager.getColor("Tree.iconHighlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            shadow = UIManager.getColor("Tree.iconShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public static Icon createExpandedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return new MotifExpandedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            g.drawLine(x, y, x+SIZE-1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            g.drawLine(x, y+1, x, y+SIZE-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            g.fillRect(x+1, y+1, SIZE-2, SIZE-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            g.setColor(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        public int getIconWidth() { return SIZE; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        public int getIconHeight() { return SIZE; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The plus sign button icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 5506
diff changeset
   143
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static class MotifCollapsedIcon extends MotifExpandedIcon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        public static Icon createCollapsedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return new MotifCollapsedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            super.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return new MotifTreeUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the default cell renderer that is used to do the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * stamping of each node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public TreeCellRenderer createDefaultCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return new MotifTreeCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}