View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
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 net.sf.jguiraffe.gui.builder.components;
17  
18  import java.util.Map;
19  
20  import net.sf.jguiraffe.gui.builder.components.model.StaticTextData;
21  import net.sf.jguiraffe.gui.builder.components.tags.BorderLayoutTag;
22  import net.sf.jguiraffe.gui.builder.components.tags.ButtonLayoutTag;
23  import net.sf.jguiraffe.gui.builder.components.tags.ButtonTag;
24  import net.sf.jguiraffe.gui.builder.components.tags.CheckboxTag;
25  import net.sf.jguiraffe.gui.builder.components.tags.ComboBoxTag;
26  import net.sf.jguiraffe.gui.builder.components.tags.DesktopPanelTag;
27  import net.sf.jguiraffe.gui.builder.components.tags.FontTag;
28  import net.sf.jguiraffe.gui.builder.components.tags.LabelTag;
29  import net.sf.jguiraffe.gui.builder.components.tags.ListBoxTag;
30  import net.sf.jguiraffe.gui.builder.components.tags.PanelTag;
31  import net.sf.jguiraffe.gui.builder.components.tags.PasswordFieldTag;
32  import net.sf.jguiraffe.gui.builder.components.tags.PercentLayoutTag;
33  import net.sf.jguiraffe.gui.builder.components.tags.ProgressBarTag;
34  import net.sf.jguiraffe.gui.builder.components.tags.RadioButtonTag;
35  import net.sf.jguiraffe.gui.builder.components.tags.SliderTag;
36  import net.sf.jguiraffe.gui.builder.components.tags.SplitterTag;
37  import net.sf.jguiraffe.gui.builder.components.tags.StaticTextTag;
38  import net.sf.jguiraffe.gui.builder.components.tags.TabbedPaneTag;
39  import net.sf.jguiraffe.gui.builder.components.tags.TextAreaTag;
40  import net.sf.jguiraffe.gui.builder.components.tags.TextFieldTag;
41  import net.sf.jguiraffe.gui.builder.components.tags.ToggleButtonTag;
42  import net.sf.jguiraffe.gui.builder.components.tags.TreeTag;
43  import net.sf.jguiraffe.gui.builder.components.tags.table.TableTag;
44  import net.sf.jguiraffe.gui.builder.event.PlatformEventManager;
45  import net.sf.jguiraffe.gui.forms.ComponentHandler;
46  import net.sf.jguiraffe.locators.Locator;
47  
48  /**
49   * <p>
50   * Definition of an interface to a concrete GUI manager.
51   * </p>
52   * <p>
53   * The form framework tries to be independent of a specific GUI technology like
54   * Swing or SWT. Instead widgets are addressed in a generic way, as objects.
55   * This interface defines accessor methods for such generic GUI objects.
56   * Concrete implementation classes will map these methods onto an existing GUI
57   * library.
58   * </p>
59   * <p>
60   * The most important client for this interface is the form builder jelly tag
61   * library. The tags represent generic form elements, e.g. labels, text fields
62   * or radio buttons. Concrete implementations for these elements are created
63   * through interface methods. This makes it possible to plug in different GUI
64   * libraries. So one and the same jelly script could once create a Swing GUI and
65   * another time an SWT GUI.
66   * </p>
67   * <p>
68   * A large part of the methods defined in this interface deal with the creation
69   * of GUI components. Those components are wrapped into a
70   * {@link ComponentHandler} implementation, which makes it possible to add them
71   * to a {@link net.sf.jguiraffe.gui.forms.Form Form} object and to access their
72   * data. Some of these methods have a boolean argument <code>create</code>.
73   * During the processing of the Jelly script that defines the GUI they are
74   * called twice, once with the argument set to <b>true</b> and once with the
75   * argument set to <b>false</b>. The first call comes before the tag's body is
76   * evaluated, the second after that. This allows for different ways of
77   * constructing component hierarchies (e.g. in Swing components are added to
78   * containers using an <code>add()</code> of the container, SWT on the other
79   * hand requires the container being passed into the component's constructor -
80   * thus the container must have been created prior than the component.
81   * </p>
82   * <p>
83   * Additional methods are responsible for creating auxiliary objects, like
84   * icons, fonts or layout constraints, or for manipulating container objects,
85   * which can contain other GUI elements.
86   * </p>
87   * <p>
88   * <strong>Note:</strong> This interface is not intended to be directly
89   * implemented by client code. It is subject to change even in minor releases as
90   * new features are made available. Therefore if an application needs to provide
91   * a custom implementation of this interface, it should extend an existing
92   * implementation. For instance, the {@link ComponentManagerWrapper} class is a
93   * good candidate if only a subset of methods is to be modified.
94   * </p>
95   *
96   * @author Oliver Heger
97   * @version $Id: ComponentManager.java 205 2012-01-29 18:29:57Z oheger $
98   */
99  public interface ComponentManager
100 {
101     /**
102      * Adds a component to a container using the specified constraints. This
103      * method is called to populate container objects.
104      *
105      * @param container the container
106      * @param component the component which is to be added to the container
107      * @param constraints a generic constraints object; this object must be
108      * compatible with the layout manager set for the container; it may be
109      * <b>null</b>
110      */
111     void addContainerComponent(Object container, Object component,
112             Object constraints);
113 
114     /**
115      * Defines the layout manager for a container.
116      *
117      * @param container the container
118      * @param layout the new layout manager
119      */
120     void setContainerLayout(Object container, Object layout);
121 
122     /**
123      * Returns a concrete implementation of the
124      * <code>PlatformEventManager</code> interface for dealing with event
125      * notifications. This method is called once when the event handling
126      * features are used for the first time.
127      *
128      * @return the platform specific event manager
129      */
130     PlatformEventManager createEventManager();
131 
132     /**
133      * Returns a <code>WidgetHandler</code> for the specified component. This
134      * method is called by {@link ComponentBuilderData} when the user asks for a
135      * handler to a certain component. The passed in object is one of the
136      * components that was created during the last builder operation. An
137      * implementation may throw a runtime exception if a widget handler for the
138      * passed in component cannot be obtained.
139      *
140      * @param component the component
141      * @return a <code>WidgetHandler</code> wrapping the specified component
142      */
143     WidgetHandler getWidgetHandlerFor(Object component);
144 
145     /**
146      * Creates a label object. All needed properties are extracted from the
147      * passed in tag.
148      *
149      * @param tag the label tag
150      * @param create the create flag
151      * @return the new label
152      * @throws FormBuilderException if an error occurs
153      */
154     Object createLabel(LabelTag tag, boolean create)
155             throws FormBuilderException;
156 
157     /**
158      * Associates a link with another component. This method will be called if
159      * the <code>componentref</code> attribute of a <code>LabelTag</code>
160      * was used to define a link between a lable and another component. An
161      * implementation will have to use library specific methods to establish
162      * such a connection. Eventually the label's text has to be set to the given
163      * text (this is the case if the label is undefined; its text is then
164      * obtained from the component's display name).
165      *
166      * @param label the label (as returned by the <code>createLabel()</code>
167      * method
168      * @param component the component to be linked to the label
169      * @param text an optional text to be set for the label; can be <b>null</b>,
170      * then no text has to be set
171      * @throws FormBuilderException if an error occurs
172      */
173     void linkLabel(Object label, Object component, String text)
174             throws FormBuilderException;
175 
176     /**
177      * Creates an icon object with the data obtained from the specified
178      * <code>Locator</code>
179      *
180      * @param locator the <code>Locator</code> pointing to the data
181      * @return the new icon object
182      * @throws FormBuilderException if an error occurs
183      */
184     Object createIcon(Locator locator) throws FormBuilderException;
185 
186     /**
187      * Creates a font object from the data specified by the given {@code
188      * FontTag}.
189      *
190      * @param tag the {@code FontTag}
191      * @return the newly created font
192      * @throws FormBuilderException if an error occurs
193      */
194     Object createFont(FontTag tag) throws FormBuilderException;
195 
196     /**
197      * Creates a percent layout object whose parameters are obtained from the
198      * specified tag.
199      *
200      * @param tag the percent layout tag
201      * @return the new layout object
202      * @throws FormBuilderException if an error occurs
203      */
204     Object createPercentLayout(PercentLayoutTag tag)
205             throws FormBuilderException;
206 
207     /**
208      * Creates a button layout object whose parameters are obtained from the
209      * specified tag.
210      *
211      * @param tag the button layout tag
212      * @return the new layout object
213      * @throws FormBuilderException if an error occurs
214      */
215     Object createButtonLayout(ButtonLayoutTag tag) throws FormBuilderException;
216 
217     /**
218      * Creates a border layout object whose parameters are obtained form the
219      * specified tag.
220      *
221      * @param tag the border layout tag
222      * @return the new layout object
223      * @throws FormBuilderException if an error occurs
224      */
225     Object createBorderLayout(BorderLayoutTag tag) throws FormBuilderException;
226 
227     /**
228      * Creates a panel whose parameters are obtained from the specified tag.
229      *
230      * @param tag the panel tag
231      * @param create the create flag
232      * @return the new panel object
233      * @throws FormBuilderException if an error occurs
234      */
235     Object createPanel(PanelTag tag, boolean create)
236             throws FormBuilderException;
237 
238     /**
239      * Creates a desktop panel whose parameters are obtained from the specified
240      * tag. The desktop panel can be used as basic background for MDI child
241      * windows.
242      *
243      * @param tag the desktop panel tag
244      * @param create the create flag
245      * @return the new desktop panel object
246      * @throws FormBuilderException if an error occurs
247      */
248     Object createDesktopPanel(DesktopPanelTag tag, boolean create)
249             throws FormBuilderException;
250 
251     /**
252      * Creates a splitter whose parameters are obtained from the specified tag.
253      *
254      * @param tag the splitter tag
255      * @param create the create flag
256      * @return the new splitter component
257      * @throws FormBuilderException if an error occurs
258      */
259     Object createSplitter(SplitterTag tag, boolean create)
260             throws FormBuilderException;
261 
262     /**
263      * Creates a radio group which contains the radio buttons stored in the
264      * passed in map. Radio groups are treated as non visual components that
265      * merely implement the radio logic. They will not be inserted into a GUI
266      * container. The passed in map contains the names of the radio buttons as
267      * keys and the corresponding component objects as values.
268      *
269      * @param radioButtons a map with the radio button components that belong to
270      *        the group
271      * @return the new radio group
272      * @throws FormBuilderException if an error occurs
273      */
274     Object createRadioGroup(Map<String, Object> radioButtons)
275             throws FormBuilderException;
276 
277     /**
278      * Creates a button component. All needed properties are extracted from the
279      * passed in tag. Buttons (or to be more precise: command buttons) are
280      * considered as input components though they do not gather user input. The
281      * reason for this is that the event mechanism is coupled to
282      * <code>ComponentHandler</code> instances, so for a button to generate
283      * events there must be an associated component handler. Note that the
284      * returned component handler is usually not added to the generated
285      * <code>Form</code> object. If the button really should be used as input
286      * component, its data is a boolean value indicating whether the button is
287      * selected (which makes sense if the button is used as a toggle button).
288      *
289      * @param tag the button tag
290      * @param create the create flag
291      * @return the component handler for the new button
292      * @throws FormBuilderException if an error occurs
293      */
294     ComponentHandler<Boolean> createButton(ButtonTag tag, boolean create)
295             throws FormBuilderException;
296 
297     /**
298      * Creates a toggle button component. A toggle button is a simple switch
299      * that can be selected (pressed) or not. So the data associated with
300      * components of this type is simply a boolean.
301      *
302      * @param tag the tag defining the toggle button
303      * @param create the create flag
304      * @return the component handler for the new toggle button
305      * @throws FormBuilderException if an error occurs
306      */
307     ComponentHandler<Boolean> createToggleButton(ToggleButtonTag tag, boolean create)
308             throws FormBuilderException;
309 
310     /**
311      * Creates a component handler that wraps a text field. The data type of
312      * this handler is String.
313      *
314      * @param tag the tag defining the text field
315      * @param create the create flag
316      * @return the component handler for the text field
317      * @throws FormBuilderException if an error occurs
318      */
319     ComponentHandler<String> createTextField(TextFieldTag tag, boolean create)
320             throws FormBuilderException;
321 
322     /**
323      * Creates a component handler that wraps a text area. The data type of this
324      * handler is String.
325      *
326      * @param tag the tag defining the text area
327      * @param create the create flag
328      * @return the component handler for the text area
329      * @throws FormBuilderException if an error occurs
330      */
331     ComponentHandler<String> createTextArea(TextAreaTag tag, boolean create)
332             throws FormBuilderException;
333 
334     /**
335      * Creates a {@code ComponentHandler} that wraps a password text field. This
336      * handler acts like a regular handler for text input fields. Only the
337      * visual representation is different because the characters typed by the
338      * user in the text field are not readable.
339      *
340      * @param tag the tag defining the password text field
341      * @param create the create flag
342      * @return the {@code ComponentHandler} for the password text field
343      * @throws FormBuilderException if an error occurs
344      */
345     ComponentHandler<String> createPasswordField(PasswordFieldTag tag,
346             boolean create) throws FormBuilderException;
347 
348     /**
349      * Creates a component handler that wraps a checkbox. This handler's data is
350      * of type boolean.
351      *
352      * @param tag the tag defining the checkbox
353      * @param create the create flag
354      * @return the component handler for the checkbox
355      * @throws FormBuilderException if an error occurs
356      */
357     ComponentHandler<Boolean> createCheckbox(CheckboxTag tag, boolean create)
358             throws FormBuilderException;
359 
360     /**
361      * Creates a component handler that wraps a radio button. This handler's
362      * data is of type boolean.
363      *
364      * @param tag the tag defining the radio button
365      * @param create the create flag
366      * @return the component handler for the radio button
367      * @throws FormBuilderException if an error occurs
368      */
369     ComponentHandler<Boolean> createRadioButton(RadioButtonTag tag, boolean create)
370             throws FormBuilderException;
371 
372     /**
373      * Creates a component handler that wraps a combo box. This handler
374      * maintains a single data object of the same type as the combo box's list
375      * model.
376      *
377      * @param tag the tag defining the combo box
378      * @param create the create flag
379      * @return the component handler for the combo box
380      * @throws FormBuilderException if an error occurs
381      */
382     ComponentHandler<Object> createComboBox(ComboBoxTag tag, boolean create)
383             throws FormBuilderException;
384 
385     /**
386      * Creates a component handler that wraps a list box. This handler's data
387      * type is based on the type of the list's model and on the list's multi
388      * selection flag: for a single selection list the type is the same as the
389      * list's model's type, for a multi selection list it is an array of this
390      * type.
391      *
392      * @param tag the tag defining the list box
393      * @param create the create flag
394      * @return the component handler for the list box
395      * @throws FormBuilderException if an error occurs
396      */
397     ComponentHandler<Object> createListBox(ListBoxTag tag, boolean create)
398             throws FormBuilderException;
399 
400     /**
401      * Creates a component handler that wraps a tabbed pane. The handler's data
402      * consists of a single <code>Integer</code> object, which represents the
403      * (0-based) index of the selected tab. It can be read and set.
404      *
405      * @param tag the tag defining the tabbed pane
406      * @param create the create flag
407      * @return the component handler for the tabbed pane
408      * @throws FormBuilderException if an error occurs
409      */
410     ComponentHandler<Integer> createTabbedPane(TabbedPaneTag tag, boolean create)
411             throws FormBuilderException;
412 
413     /**
414      * Creates a component handler that wraps a static text element. The
415      * handler's data consists of a
416      * <code>{@link net.sf.jguiraffe.gui.builder.components.model.StaticTextData
417      * StaticTextData}</code>
418      * object, which can be used to read and write the static text's properties.
419      * The returned handler can be casted into a
420      * <code>{@link net.sf.jguiraffe.gui.builder.components.model.StaticTextHandler}</code>
421      * object; the additional methods defined by this interface can be used to
422      * directly set the key properties of the static text component.
423      *
424      * @param tag the tag defining the static text
425      * @param create the create flag
426      * @return the component handler for the static text
427      * @throws FormBuilderException if an error occurs
428      */
429     ComponentHandler<StaticTextData> createStaticText(StaticTextTag tag, boolean create)
430             throws FormBuilderException;
431 
432     /**
433      * Creates a component handler that wraps a progress bar element. The
434      * handler's data is an integer value representing the current position of
435      * the progress bar. The handler can be casted into a
436      * {@link net.sf.jguiraffe.gui.builder.components.model.ProgressBarHandler}
437      * object; the additional methods defined by this interface can be used to
438      * manipulate further properties of the progress bar.
439      *
440      * @param tag the tag defining the progress bar
441      * @param create the create flag
442      * @return the component handler for the progress bar
443      * @throws FormBuilderException if an error occurs
444      */
445     ComponentHandler<Integer> createProgressBar(ProgressBarTag tag,
446             boolean create) throws FormBuilderException;
447 
448     /**
449      * Creates a component handler that wraps a slider component. The handler's
450      * data is an integer value representing the current value of the slider.
451      *
452      * @param tag the tag defining the slider
453      * @param create the create flag
454      * @return the component handler for the slider
455      * @throws FormBuilderException if an error occurs
456      */
457     ComponentHandler<Integer> createSlider(SliderTag tag, boolean create)
458             throws FormBuilderException;
459 
460     /**
461      * Creates a table based on the information stored in the passed in table
462      * tag. This is a complex operation because it has to be ensured that the
463      * table is fully initialized. It is guaranteed that the tag contains only
464      * valid data. The table's data model, its columns, and form objects to be
465      * used for rendering or editing cells are available. The returned
466      * <code>ComponentHandler</code> object wraps the table component. It can
467      * be casted into a
468      * <code>{@link net.sf.jguiraffe.gui.builder.components.model.TableHandler TableHandler}</code>
469      * object. Its data depends on the selection type of the table: in single
470      * selection mode it is the index of the selected row; in multi selection
471      * mode it is an int[] with the indices of the selected rows. By registering
472      * a change listener at the returned <code>ComponentHandler</code>
473      * interested components can be notified when the table's selection changes.
474      *
475      * @param tag the table tag
476      * @param create the create flag
477      * @return the component handler for the new table component
478      * @throws FormBuilderException if an error occurs
479      */
480     ComponentHandler<Object> createTable(TableTag tag, boolean create)
481             throws FormBuilderException;
482 
483     /**
484      * Creates a tree component based on the information stored in the passed in
485      * tree tag. The tag has been fully initialized, it especially contains the
486      * model to be used for the tree. The <code>ComponentHandler</code> returned
487      * by this method can be casted into a
488      * <code>{@link net.sf.jguiraffe.gui.builder.components.model.TreeHandler TreeHandler}</code>
489      * object. Refer to the documentation of this class for more information
490      * about the data supported by this handler.
491      *
492      * @param tag the tree tag
493      * @param create the create flag
494      * @return the component handler for the new tree component
495      * @throws FormBuilderException if an error occurs
496      */
497     ComponentHandler<Object> createTree(TreeTag tag, boolean create)
498             throws FormBuilderException;
499 }