View Javadoc

1   /*
2      Copyright 2002-2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15  */
16  package org.xulux.guilayer.swing.widgets;
17  
18  import java.awt.Component;
19  import java.awt.Dimension;
20  
21  import javax.swing.JComponent;
22  import javax.swing.JSplitPane;
23  
24  import org.xulux.api.gui.IWidget;
25  import org.xulux.gui.ContainerWidget;
26  
27  /**
28   * The splitpane
29   *
30   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
31   * @version $Id: SplitPane.java,v 1.1 2005/12/18 12:58:18 mvdb Exp $
32   */
33  public class SplitPane extends ContainerWidget {
34  
35      /**
36       * the splitpane
37       */
38      private JSplitPane pane;
39  
40      /**
41       * @param name the name of the widget
42       */
43      public SplitPane(String name) {
44          super(name);
45      }
46  
47      /**
48       * @see org.xulux.nyx.gui.XuluxWidget#getNativeWidget()
49       */
50      public Object getNativeWidget() {
51          if (!initialized) {
52              initialize();
53          }
54          return this.pane;
55      }
56  
57      /**
58       * @see org.xulux.nyx.gui.XuluxWidget#initialize()
59       */
60      public void initialize() {
61          if (initialized) {
62              return;
63          }
64          initialized = true;
65          pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
66          initializeChildren();
67          //pane.setOneTouchExpandable(true);
68          pane.setContinuousLayout(true);
69          refresh();
70      }
71  
72      /**
73       * @see org.xulux.nyx.gui.XuluxWidget#refresh()
74       */
75      public void refresh() {
76          if (isRefreshing()) {
77              return;
78          }
79          if (!initialized) {
80              initialize();
81          }
82          isRefreshing = true;
83          String orientation = getProperty("orientation");
84          if (orientation != null) {
85              if ("horizontal".equalsIgnoreCase(orientation)) {
86                  pane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
87              } else if ("vertical".equalsIgnoreCase(orientation)) {
88                  pane.setOrientation(JSplitPane.VERTICAL_SPLIT);
89              }
90          }
91          int divLocation = pane.getDividerLocation();
92          try {
93            divLocation = Integer.parseInt(getProperty("dividerlocation"));
94          } catch(NumberFormatException nfe) {
95          }
96          pane.setDividerLocation(divLocation);
97          isRefreshing = false;
98      }
99  
100     /**
101      * @see org.xulux.nyx.gui.XuluxWidget#getGuiValue()
102      */
103     public Object getGuiValue() {
104         return null;
105     }
106 
107     /**
108      * @see org.xulux.nyx.gui.XuluxWidget#focus()
109      */
110     public void focus() {
111 
112     }
113 
114     /**
115      * @see org.xulux.nyx.gui.XuluxWidget#isValueEmpty()
116      */
117     public boolean isValueEmpty() {
118         return false;
119     }
120 
121     /**
122      * @see org.xulux.nyx.gui.XuluxWidget#canContainValue()
123      */
124     public boolean canContainValue() {
125         return false;
126     }
127 
128     /**
129      * Specifies if the bottom component was processed
130      */
131     private boolean bottomProcessed;
132     /**
133      * Specified if the top component was processed
134      */
135     private boolean topProcessed;
136     /**
137      * @see org.xulux.nyx.gui.ContainerWidget#addToParent(org.xulux.nyx.gui.XuluxWidget)
138      */
139     public void addToParent(IWidget widget) {
140         String position = widget.getProperty("pane");
141         JComponent comp = (JComponent) widget.getNativeWidget();
142         int divLocation = 10;
143         try {
144           divLocation = Integer.parseInt(getProperty("dividerlocation"));
145         } catch(NumberFormatException nfe) {
146         }
147         pane.setDividerLocation(divLocation);
148         comp.setMinimumSize(new Dimension(divLocation, 10));
149         if (position == null) {
150             if (!topProcessed) {
151                 topProcessed = true;
152                 pane.setTopComponent((Component) widget.getNativeWidget());
153             } else if (!bottomProcessed) {
154                 bottomProcessed = true;
155                 pane.setBottomComponent((Component) widget.getNativeWidget());
156             } else {
157                 System.out.println("Ignoring widget " + widget + " since we already have a bottom and top component");
158             }
159         } else if ("bottom".equalsIgnoreCase(position)) {
160             pane.setBottomComponent((Component) widget.getNativeWidget());
161         } else if ("top".equalsIgnoreCase(position)) {
162             pane.setTopComponent((Component) widget.getNativeWidget());
163         }
164         widget.refresh();
165     }
166 
167 }