API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.swing.plaf.metal. MetalScrollButton View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

/*
 * @(#)MetalScrollButton.java	1.26 05/11/17
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.swing.plaf.metal;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Polygon;

import javax.swing.*;

import javax.swing.plaf.basic.BasicArrowButton;


/**
 * JButton object for Metal scrollbar arrows.
 * <p>
 * <strong>Warning:</strong>
 * Serialized objects of this class will not be compatible with
 * future Swing releases. The current serialization support is
 * appropriate for short term storage or RMI between applications running
 * the same version of Swing.  As of 1.4, support for long term storage
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
 * has been added to the <code>java.beans</code> package.
 * Please see {@link java.beans.XMLEncoder}.
 *
 * @version 1.15 08/28/98
 * @author Tom Santos
 * @author Steve Wilson
 */
public class MetalScrollButton extends BasicArrowButton
{
  private static Color shadowColor;
  private static Color highlightColor;
  private boolean isFreeStanding = false;

  private int buttonWidth;

        public MetalScrollButton( int direction, int width, boolean freeStanding )
        {
            super( direction );

	    shadowColor = UIManager.getColor("ScrollBar.darkShadow");
	    highlightColor = UIManager.getColor("ScrollBar.highlight");

            buttonWidth = width;
	    isFreeStanding = freeStanding;
        }

        public void setFreeStanding( boolean freeStanding )
        {
	    isFreeStanding = freeStanding;
        }

	public void paint( Graphics g )
        {
            boolean leftToRight = MetalUtils.isLeftToRight(this);
	    boolean isEnabled = getParent().isEnabled();

	    Color arrowColor = isEnabled ? MetalLookAndFeel.getControlInfo() : MetalLookAndFeel.getControlDisabled();
	    boolean isPressed = getModel().isPressed();
	    int width = getWidth();
	    int height = getHeight();
	    int w = width;
	    int h = height;
	    int arrowHeight = (height+1) / 4;
	    int arrowWidth = (height+1) / 2;

	    if ( isPressed )
	    {
	        g.setColor( MetalLookAndFeel.getControlShadow() );
	    }
	    else
            {
	        g.setColor( getBackground() );
	    }

	    g.fillRect( 0, 0, width, height );

	    if ( getDirection() == NORTH )
	    {
	        if ( !isFreeStanding ) {
                    height +=1;
                    g.translate( 0, -1 );
                    width += 2;
                    if ( !leftToRight ) {
                        g.translate( -1, 0 );
                    }
		}

	        // Draw the arrow
	        g.setColor( arrowColor );
		int startY = ((h+1) - arrowHeight) / 2;
		int startX = (w / 2);
		//		    System.out.println( "startX :" + startX + " startY :"+startY);
		for (int line = 0; line < arrowHeight; line++) {
		    g.drawLine( startX-line, startY+line, startX +line+1, startY+line);
		}
	/*	g.drawLine( 7, 6, 8, 6 );
		g.drawLine( 6, 7, 9, 7 );
		g.drawLine( 5, 8, 10, 8 );
		g.drawLine( 4, 9, 11, 9 );*/
	        
		if (isEnabled) {
		    g.setColor( highlightColor );

		    if ( !isPressed )
		    {
			g.drawLine( 1, 1, width - 3, 1 );
			g.drawLine( 1, 1, 1, height - 1 );
		    }

		    g.drawLine( width - 1, 1, width - 1, height - 1 );

		    g.setColor( shadowColor );
		    g.drawLine( 0, 0, width - 2, 0 );
		    g.drawLine( 0, 0, 0, height - 1 );
		    g.drawLine( width - 2, 2, width - 2, height - 1 );
		} else {
		    MetalUtils.drawDisabledBorder(g, 0, 0, width, height+1);
		}
	        if ( !isFreeStanding ) {
                    height -= 1;
                    g.translate( 0, 1 );
                    width -= 2;
                    if ( !leftToRight ) {
                        g.translate( 1, 0 );
                    }
		}
	    }
	    else if ( getDirection() == SOUTH )
	    {
	        if ( !isFreeStanding ) {
		    height += 1;
                    width += 2;
                    if ( !leftToRight ) {
                        g.translate( -1, 0 );
                    }
		}

	        // Draw the arrow
	        g.setColor( arrowColor );

		int startY = (((h+1) - arrowHeight) / 2)+ arrowHeight-1;
		int startX = (w / 2);

		//	    System.out.println( "startX2 :" + startX + " startY2 :"+startY);

		for (int line = 0; line < arrowHeight; line++) {
		    g.drawLine( startX-line, startY-line, startX +line+1, startY-line);
		}

	/*	g.drawLine( 4, 5, 11, 5 );
		g.drawLine( 5, 6, 10, 6 );
		g.drawLine( 6, 7, 9, 7 );
		g.drawLine( 7, 8, 8, 8 ); */

		if (isEnabled) {
		    g.setColor( highlightColor );

		    if ( !isPressed )
		    {
			g.drawLine( 1, 0, width - 3, 0 );
			g.drawLine( 1, 0, 1, height - 3 );
		    }

		    g.drawLine( 1, height - 1, width - 1, height - 1 );
		    g.drawLine( width - 1, 0, width - 1, height - 1 );

		    g.setColor( shadowColor );
		    g.drawLine( 0, 0, 0, height - 2 );
		    g.drawLine( width - 2, 0, width - 2, height - 2 );
		    g.drawLine( 2, height - 2, width - 2, height - 2 );
		} else {
		    MetalUtils.drawDisabledBorder(g, 0,-1, width, height+1);
		}

	        if ( !isFreeStanding ) {
		    height -= 1;
                    width -= 2;
                    if ( !leftToRight ) {
                        g.translate( 1, 0 );
                    }
		}
	    }
	    else if ( getDirection() == EAST )
	    {
	        if ( !isFreeStanding ) {
		    height += 2;
		    width += 1;
		}

	        // Draw the arrow
	        g.setColor( arrowColor );

		int startX = (((w+1) - arrowHeight) / 2) + arrowHeight-1;
		int startY = (h / 2);

		//System.out.println( "startX2 :" + startX + " startY2 :"+startY);

		for (int line = 0; line < arrowHeight; line++) {
		    g.drawLine( startX-line, startY-line, startX -line, startY+line+1);
		}


/*		g.drawLine( 5, 4, 5, 11 );
		g.drawLine( 6, 5, 6, 10 );
		g.drawLine( 7, 6, 7, 9 );
		g.drawLine( 8, 7, 8, 8 );*/

		if (isEnabled) {
		    g.setColor( highlightColor );

		    if ( !isPressed )
		    {
		        g.drawLine( 0, 1, width - 3, 1 );
		        g.drawLine( 0, 1, 0, height - 3 );
		    }

		    g.drawLine( width - 1, 1, width - 1, height - 1 );
		    g.drawLine( 0, height - 1, width - 1, height - 1 );

		    g.setColor( shadowColor );
		    g.drawLine( 0, 0,width - 2, 0 );
		    g.drawLine( width - 2, 2, width - 2, height - 2 );
		    g.drawLine( 0, height - 2, width - 2, height - 2 );
		} else {
		    MetalUtils.drawDisabledBorder(g,-1,0, width+1, height);
		}
	        if ( !isFreeStanding ) {
		    height -= 2;
		    width -= 1;
		}
	    }
	    else if ( getDirection() == WEST )
	    {
	        if ( !isFreeStanding ) {
		    height += 2;
		    width += 1;
		    g.translate( -1, 0 );
		}

	        // Draw the arrow
	        g.setColor( arrowColor );

		int startX = (((w+1) - arrowHeight) / 2);
		int startY = (h / 2);


		for (int line = 0; line < arrowHeight; line++) {
		    g.drawLine( startX+line, startY-line, startX +line, startY+line+1);
		}

	/*	g.drawLine( 6, 7, 6, 8 );
		g.drawLine( 7, 6, 7, 9 );
		g.drawLine( 8, 5, 8, 10 );
		g.drawLine( 9, 4, 9, 11 );*/

		if (isEnabled) {
		    g.setColor( highlightColor );


		    if ( !isPressed )
		    {
		        g.drawLine( 1, 1, width - 1, 1 );
			g.drawLine( 1, 1, 1, height - 3 );
		    }

		    g.drawLine( 1, height - 1, width - 1, height - 1 );
		
		    g.setColor( shadowColor );
		    g.drawLine( 0, 0, width - 1, 0 );
		    g.drawLine( 0, 0, 0, height - 2 );
		    g.drawLine( 2, height - 2, width - 1, height - 2 );
		} else {
		    MetalUtils.drawDisabledBorder(g,0,0, width+1, height);
		}

	        if ( !isFreeStanding ) {
		    height -= 2;
		    width -= 1;
		    g.translate( 1, 0 );
		}
	    }
        }

        public Dimension getPreferredSize()
        {
	    if ( getDirection() == NORTH )
	    {
	        return new Dimension( buttonWidth, buttonWidth - 2 );
	    }
	    else if ( getDirection() == SOUTH )
            {
	        return new Dimension( buttonWidth, buttonWidth - (isFreeStanding ? 1 : 2) );
	    }
	    else if ( getDirection() == EAST )
            {
	        return new Dimension( buttonWidth - (isFreeStanding ? 1 : 2), buttonWidth );
	    }
	    else if ( getDirection() == WEST )
            {
	        return new Dimension( buttonWidth - 2, buttonWidth );
	    }
	    else
            {
	        return new Dimension( 0, 0 );
	    }
        }

        public Dimension getMinimumSize()
        {
            return getPreferredSize();
        }

        public Dimension getMaximumSize()
        {
            return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
        }
    
        public int getButtonWidth() {
	    return buttonWidth;
	}
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar