1 /* ====================================================================
2  *
3  * Skin Look And Feel 6.7 License.
4  *
5  * Copyright (c) 2000-2006 L2FProd.com.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if
20  *    any, must include the following acknowlegement:
21  *       "This product includes software developed by L2FProd.com
22  *        (http://www.L2FProd.com/)."
23  *    Alternately, this acknowlegement may appear in the software itself,
24  *    if and wherever such third-party acknowlegements normally appear.
25  *
26  * 4. The names "Skin Look And Feel", "SkinLF" and "L2FProd.com" must not
27  *    be used to endorse or promote products derived from this software
28  *    without prior written permission. For written permission, please
29  *    contact info@L2FProd.com.
30  *
31  * 5. Products derived from this software may not be called "SkinLF"
32  *    nor may "SkinLF" appear in their names without prior written
33  *    permission of L2FProd.com.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
39  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
44  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
45  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  * ====================================================================
47  */
48 package com.l2fprod.gui.plaf.skin.impl.gtk;
49 
50 import java.awt.Dimension;
51 import java.awt.Graphics;
52 import java.awt.Insets;
53 import javax.swing.JSplitPane;
54 import javax.swing.SwingConstants;
55 import javax.swing.JComponent;
56 
57 import com.l2fprod.gui.plaf.skin.*;
58 import com.l2fprod.gui.plaf.skin.impl.*;
59 import com.l2fprod.gui.plaf.skin.impl.gtk.parser.*;
60 
61 /**
62  * @author    $Author: l2fprod $
63  * @created   27 avril 2002
64  * @version   $Revision: 1.2 $, $Date: 2003/12/06 21:50:13 $
65  */
66 final class GtkSplitPane extends AbstractSkinSplitPane implements SkinSplitPane, SwingConstants {
67 
68   DefaultButton h_gutter, v_gutter;
69   DefaultButton h_thumb, v_thumb;
70 
71   DefaultButton up, down, left, right;
72 
73   /**
74    * Constructor for the GtkSplitPane object
75    *
76    * @param parser         Description of Parameter
77    * @exception Exception  Description of Exception
78    */
GtkSplitPane(GtkParser parser)79   public GtkSplitPane(GtkParser parser) throws Exception {
80 
81     h_gutter = GtkUtils.newButton(parser, "GtkPaned",
82         new String[]{"function", "orientation"},
83         new String[]{"BOX", "HORIZONTAL"});
84 
85     v_gutter = GtkUtils.newButton(parser, "GtkPaned",
86         new String[]{"function", "orientation"},
87         new String[]{"BOX", "VERTICAL"});
88 
89     h_thumb = GtkUtils.newButton(parser, "GtkPaned",
90         new String[]{"function", "orientation"},
91         new String[]{"HANDLE", "HORIZONTAL"});
92     if (h_thumb == null) {
93       h_thumb = h_gutter;
94     }
95 
96     v_thumb = GtkUtils.newButton(parser, "GtkPaned",
97         new String[]{"function", "orientation"},
98         new String[]{"HANDLE", "VERTICAL"});
99     if (v_thumb == null) {
100       v_thumb = v_gutter;
101     }
102 
103     up = GtkUtils.newButton(parser, "GtkPaned",
104         new String[]{"function", "arrow_direction"},
105         new String[]{"ARROW", "UP"});
106 
107     down = GtkUtils.newButton(parser, "GtkPaned",
108         new String[]{"function", "arrow_direction"},
109         new String[]{"ARROW", "DOWN"});
110 
111     left = GtkUtils.newButton(parser, "GtkPaned",
112         new String[]{"function", "arrow_direction"},
113         new String[]{"ARROW", "LEFT"});
114 
115     right = GtkUtils.newButton(parser, "GtkPaned",
116         new String[]{"function", "arrow_direction"},
117         new String[]{"ARROW", "RIGHT"});
118   }
119 
120   /**
121    * Gets the PreferredSize attribute of the GtkSplitPane object
122    *
123    * @param splitpane  Description of Parameter
124    * @return           The PreferredSize value
125    */
getPreferredSize(JSplitPane splitpane)126   public Dimension getPreferredSize(JSplitPane splitpane) {
127     Insets insets = splitpane.getInsets();
128     int width = 0;
129     int height = 0;
130     if (splitpane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
131       width = Math.max(Math.max(up.getWidth(), down.getWidth()), 10);
132       height = splitpane.getHeight() + insets.top + insets.bottom;
133     }
134     else {
135       height = Math.max(Math.max(left.getHeight(), right.getHeight()), 10);
136       width = splitpane.getWidth() + insets.left + insets.right;
137     }
138     Dimension d = new Dimension(width, height);
139     return (d);
140     //return (splitpane.getOrientation() == JSplitPane.VERTICAL_SPLIT)
141     //    ? new Dimension(Math.max(10, Math.min(up.getWidth(), v_thumb.getWidth())), 48)
142     //	: new Dimension(48, Math.max(10, Math.min(left.getHeight(), h_thumb.getHeight())));
143   }
144 
145   /**
146    * Gets the ArrowPreferredSize attribute of the GtkSplitPane object
147    *
148    * @param direction  Description of Parameter
149    * @return           The ArrowPreferredSize value
150    */
getArrowPreferredSize(int direction)151   public Dimension getArrowPreferredSize(int direction) {
152     switch (direction) {
153       case NORTH:
154         return new Dimension(up.getWidth(), up.getHeight());
155       case SOUTH:
156         return new Dimension(down.getWidth(), down.getHeight());
157       case WEST:
158         return new Dimension(left.getWidth(), left.getHeight());
159       case EAST:
160         return new Dimension(right.getWidth(), right.getHeight());
161       default:
162         throw new Error("Invalid direction " + direction);
163     }
164 
165   }
166 
167   /**
168    * Description of the Method
169    *
170    * @return   Description of the Returned Value
171    */
status()172   public boolean status() {
173     return true;
174   }
175 
176   /**
177    * Description of the Method
178    *
179    * @param c  Description of Parameter
180    * @return   Description of the Returned Value
181    */
installSkin(JComponent c)182   public boolean installSkin(JComponent c) {
183     return true;
184   }
185 
186   /**
187    * Description of the Method
188    *
189    * @param g          Description of Parameter
190    * @param b          Description of Parameter
191    * @param direction  Description of Parameter
192    * @return           Description of the Returned Value
193    */
paintArrow(java.awt.Graphics g, javax.swing.AbstractButton b, int direction)194   public boolean paintArrow(java.awt.Graphics g, javax.swing.AbstractButton b, int direction) {
195     java.awt.Dimension size = b.getSize();
196     switch (direction) {
197 
198       case NORTH:
199         down.paint(g, 0, 0, size.width, size.height, b);
200         break;
201       case SOUTH:
202         up.paint(g, 0, 0, size.width, size.height, b);
203         break;
204       case WEST:
205         left.paint(g, 0, 0, size.width, size.height, b);
206         break;
207       case EAST:
208         right.paint(g, 0, 0, size.width, size.height, b);
209     }
210     return true;
211   }
212 
213   // track is under thumb
214   /**
215    * Description of the Method
216    *
217    * @param g          Description of Parameter
218    * @param splitpane  Description of Parameter
219    * @param d          Description of Parameter
220    * @return           Description of the Returned Value
221    */
paintGutter(Graphics g, JSplitPane splitpane, Dimension d)222   public boolean paintGutter(Graphics g, JSplitPane splitpane, Dimension d) {
223     if (splitpane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
224       h_gutter.paint(g, 0, 0, d.width, d.height, splitpane);
225       return true;
226     }
227     else {
228       v_gutter.paint(g, 0, 0, d.width, d.height, splitpane);
229       return true;
230     }
231   }
232 
233   // thumb is the variable area
234   /**
235    * Description of the Method
236    *
237    * @param g          Description of Parameter
238    * @param splitpane  Description of Parameter
239    * @param d          Description of Parameter
240    * @return           Description of the Returned Value
241    */
paintThumb(Graphics g, JSplitPane splitpane, Dimension d)242   public boolean paintThumb(Graphics g, JSplitPane splitpane, Dimension d) {
243     // the UI translate the graphics to thumbBounds.x and .y
244 
245     if (splitpane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT && h_thumb != null) {
246       h_thumb.paint(g, Math.max(0, (d.width - h_thumb.getWidth()) / 2),
247           (d.height - h_thumb.getHeight()) / 2,
248           Math.min(d.width, h_thumb.getWidth()),
249           h_thumb.getHeight(), splitpane);
250     }
251     else if (splitpane.getOrientation() == JSplitPane.VERTICAL_SPLIT && v_thumb != null) {
252       v_thumb.paint(g, (d.width - v_thumb.getWidth()) / 2,
253           Math.max(0, (d.height - v_thumb.getHeight()) / 2),
254           v_thumb.getWidth(),
255           Math.min(d.height, v_thumb.getHeight()), splitpane);
256     }
257     else {
258       return false;
259     }
260     return true;
261   }
262 
263 }
264