OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / javax / swing / plaf / gtk / GtkSliderUI.java
1 /* GtkSliderUI.java
2    Copyright (c) 1999 by 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 package gnu.javax.swing.plaf.gtk;
39 import java.awt.*;
40 import javax.swing.*;
41 import javax.swing.plaf.*;
42 import javax.swing.plaf.basic.*;
43
44 /**
45  * Gtk-like slider
46  *
47  * @author Brian Jones
48  * @see javax.swing.LookAndFeel
49  */
50 public class GtkSliderUI extends BasicSliderUI
51 {
52     private static Color thumbFgColor;
53     private static Color thumbBgColor;
54     private static Color thumbHighlight;
55     private static Color thumbFocus;
56
57     private static Color bgColor;
58     private static Color fgColor;
59     private static Color focusColor;
60     private static Color highlight;
61     private static Color shadow;
62
63     private static final Dimension PREF_HORIZ = new Dimension(250, 15);
64     private static final Dimension PREF_VERT = new Dimension(15, 250);
65     private static final Dimension MIN_HORIZ = new Dimension(25, 15);
66     private static final Dimension MIN_VERT = new Dimension(15, 25);
67
68     public GtkSliderUI() 
69     {
70         super(null);
71         bgColor = UIManager.getColor("Slider.background");
72         fgColor = UIManager.getColor("Slider.foreground");
73         focusColor = UIManager.getColor("Slider.focus");
74         highlight = UIManager.getColor("Slider.highlight");
75         shadow = UIManager.getColor("Slider.shadow");
76
77         System.out.println("bgColor: " + bgColor);
78         System.out.println("fgColor: " + fgColor);
79         System.out.println("focusColor: " + focusColor);
80         System.out.println("highlight: " + highlight);
81         System.out.println("shadow: " + shadow);
82     }
83
84     public static ComponentUI createUI(JComponent c)
85     {
86         return new GtkSliderUI();
87     }
88
89     // methods not overridden here, using Basic defaults
90     // installUI()
91     // uninstall()
92
93     public Dimension getPreferredHorizontalSize()
94     {
95         /*
96         Dimension thumbSize = getThumbSize();
97         Dimenstion labelSize = getLabelSize();
98         // getTickLength()
99         int width = thumbSize.width + 
100         getWidthOfWidestLabel
101         */
102         return PREF_HORIZ;
103     }
104
105     public Dimension getPreferredVerticalSize()
106     {
107         return PREF_VERT;
108     }
109
110     public Dimension getMinimumHorizontalSize()
111     {
112         return MIN_HORIZ;
113     }
114
115     public Dimension getMinimumVerticalSize()
116     {
117         return MIN_VERT;
118     }
119
120     /** 
121      * Returns thumb size based on slider orientation
122      */
123     protected Dimension getThumbSize()
124     {
125         Dimension size = new Dimension();
126
127         if (slider.getOrientation() == JSlider.VERTICAL) {
128             size.width = 15;
129             size.height = 33;
130         }
131         else {
132             size.width = 33;
133             size.height = 15;
134         }
135         return size;
136     }
137
138     /**
139      * Reserved width or height for ticks, as appropriate to the slider
140      * orientation.
141      */
142     protected int getTickLength()
143     {
144         return 10;
145     }
146
147     public void paintFocus(Graphics g)
148     {
149         super.paintFocus(g);
150         System.err.println("focus " + focusRect);
151     }
152
153     /**
154      * Must account for Unicode when drawing text.
155      */
156     public void paintLabels(Graphics g)
157     {
158         super.paintLabels(g);
159         System.err.println("label " + labelRect);
160     }
161
162     /**
163      * A drawRect() generated slider has ghosting when moving left on 
164      * a horizontal slider and the bottom is not painted when moving 
165      * right.
166      */
167     public void paintThumb(Graphics g)
168     {
169         int x = thumbRect.x;
170         int y = thumbRect.y;
171         int h = thumbRect.height;
172         int w = thumbRect.width;
173
174 //          "Slider.background", "#888888",
175 //          "Slider.focus", "#c3c3c3",
176 //          "Slider.foreground", "#d6d6d6",
177 //          "Slider.highlight", "#ffffff",
178 //          "Slider.shadow", "#000000"
179
180         g.setColor(fgColor);
181         g.fillRect(x,y,w,h);
182         g.setColor(bgColor);
183         
184         if (slider.getOrientation() == JSlider.HORIZONTAL) {
185             g.drawRect(x, y, w, h);
186             g.setColor(highlight);
187             g.drawLine(x+1, y+h-1, x+w, y+h-1);
188             g.setColor(focusColor);
189             g.drawLine(x+2, y+h-2, x+w, y+h-2);
190             g.setColor(Color.black);
191             g.drawLine(x+1, y+h-2, x+1, y+h-2);
192             g.drawRect(x+1, y+1, w-1, 12);          
193         }       
194         else 
195             g.drawRect(x, y, w, h);
196
197         System.err.println("thumb " + thumbRect);
198     }
199
200     // public void paintTicks(Graphics g)
201     
202     public void paintTrack(Graphics g)
203     {
204 //      super.paintTrack(g);
205         int x = trackRect.x;
206         int y = trackRect.y;
207         int h = trackRect.height;
208         int w = trackRect.width;
209
210         System.err.println("track " + trackRect);
211
212         g.setColor(Color.black);
213         g.fillRect(x,y,w,h);
214
215 //      if (slider.getOrientation() == JSlider.HORIZONTAL)
216 //          g.drawLine(x, y+h-1, x+w-1, y+h-1);
217 //      else
218 //          g.drawLine(x+w-1, y, x+w-1, y+h-1);
219
220 //      System.err.println("track " + trackRect);
221 //      System.err.println("content " + contentRect);
222     }
223
224     // the four methods below allow you to control tick painting without 
225     // worrying about what paintTicks does, look for in other UI delegates
226     // protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
227     // protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
228     // protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x)
229     // protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y)
230 }