1/*
2 * Copyright (c) 1997, 2014, 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
26package com.sun.java.swing.plaf.motif;
27
28import java.awt.Dimension;
29import java.awt.Graphics;
30import java.awt.Rectangle;
31
32import javax.swing.JComponent;
33import javax.swing.JSlider;
34import javax.swing.plaf.ComponentUI;
35import javax.swing.plaf.basic.BasicSliderUI;
36
37import static sun.swing.SwingUtilities2.drawHLine;
38import static sun.swing.SwingUtilities2.drawVLine;
39
40/**
41 * Motif Slider
42 * <p>
43 * <strong>Warning:</strong>
44 * Serialized objects of this class will not be compatible with
45 * future Swing releases.  The current serialization support is appropriate
46 * for short term storage or RMI between applications running the same
47 * version of Swing.  A future release of Swing will provide support for
48 * long term persistence.
49 *
50 * @author Jeff Dinkins
51 */
52public class MotifSliderUI extends BasicSliderUI {
53
54    static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15);
55    static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164);
56
57    static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15);
58    static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43);
59
60    /**
61     * MotifSliderUI Constructor
62     */
63    public MotifSliderUI(JSlider b)   {
64        super(b);
65    }
66
67    /**
68     * create a MotifSliderUI object
69     */
70    public static ComponentUI createUI(JComponent b)    {
71        return new MotifSliderUI((JSlider)b);
72    }
73
74    public Dimension getPreferredHorizontalSize() {
75        return PREFERRED_HORIZONTAL_SIZE;
76    }
77
78    public Dimension getPreferredVerticalSize() {
79        return PREFERRED_VERTICAL_SIZE;
80    }
81
82    public Dimension getMinimumHorizontalSize() {
83        return MINIMUM_HORIZONTAL_SIZE;
84    }
85
86    public Dimension getMinimumVerticalSize() {
87        return MINIMUM_VERTICAL_SIZE;
88    }
89
90    protected Dimension getThumbSize() {
91        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
92            return new Dimension( 30, 15 );
93        }
94        else {
95            return new Dimension( 15, 30 );
96        }
97    }
98
99    public void paintFocus(Graphics g)  {
100    }
101
102    public void paintTrack(Graphics g)  {
103    }
104
105    public void paintThumb(Graphics g)  {
106        Rectangle knobBounds = thumbRect;
107
108        int x = knobBounds.x;
109        int y = knobBounds.y;
110        int w = knobBounds.width;
111        int h = knobBounds.height;
112
113        if ( slider.isEnabled() ) {
114            g.setColor(slider.getForeground());
115        }
116        else {
117            // PENDING(jeff) - the thumb should be dithered when disabled
118            g.setColor(slider.getForeground().darker());
119        }
120
121        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
122            g.translate(x, knobBounds.y-1);
123
124            // fill
125            g.fillRect(0, 1, w, h - 1);
126
127            // highlight
128            g.setColor(getHighlightColor());
129            drawHLine(g, 0, w - 1, 1);      // top
130            drawVLine(g, 0, 1, h);          // left
131            drawVLine(g, w / 2, 2, h - 1);  // center
132
133            // shadow
134            g.setColor(getShadowColor());
135            drawHLine(g, 0, w - 1, h);      // bottom
136            drawVLine(g, w - 1, 1, h);      // right
137            drawVLine(g, w / 2 - 1, 2, h);  // center
138
139            g.translate(-x, -(knobBounds.y-1));
140        }
141        else {
142            g.translate(knobBounds.x-1, 0);
143
144            // fill
145            g.fillRect(1, y, w - 1, h);
146
147            // highlight
148            g.setColor(getHighlightColor());
149            drawHLine(g, 1, w, y);             // top
150            drawVLine(g, 1, y + 1, y + h - 1); // left
151            drawHLine(g, 2, w - 1, y + h / 2); // center
152
153            // shadow
154            g.setColor(getShadowColor());
155            drawHLine(g, 2, w, y + h - 1);        // bottom
156            drawVLine(g, w, y + h - 1, y);        // right
157            drawHLine(g, 2, w - 1, y + h / 2 - 1);// center
158
159            g.translate(-(knobBounds.x-1), 0);
160        }
161    }
162}
163