|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WindowTagHandler.java | 66,7% | 100% | 100% | 90,9% |
|
1 |
/**
|
|
2 |
* Java Gui Builder - A library to build GUIs using an XML file.
|
|
3 |
* Copyright 2002, 2003 (C) François Beausoleil
|
|
4 |
*
|
|
5 |
* This library is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
|
7 |
* License as published by the Free Software Foundation; either
|
|
8 |
* version 2.1 of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This library is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 |
* Lesser General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
|
16 |
* License along with this library; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
*/
|
|
19 |
|
|
20 |
package jgb.handlers.swing;
|
|
21 |
|
|
22 |
import jgb.builder.TagHandler;
|
|
23 |
import org.xml.sax.SAXException;
|
|
24 |
|
|
25 |
import javax.swing.*;
|
|
26 |
import java.awt.*;
|
|
27 |
import java.util.Map;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* @since 0.1a
|
|
31 |
* @author Francois Beausoleil, <a href="mailto:fbos@users.sourceforge.net">fbos@users.sourceforge.net</a>
|
|
32 |
*/
|
|
33 |
public class WindowTagHandler extends AbstractTagHandler { |
|
34 |
/**
|
|
35 |
* The name of the type attribute.
|
|
36 |
*/
|
|
37 |
protected static final String ATTR_TYPE = "type"; |
|
38 |
|
|
39 |
/**
|
|
40 |
* The value of the type attribute which will instantiate a
|
|
41 |
* {@link javax.swing.JDialog JDialog}.
|
|
42 |
*/
|
|
43 |
protected static final String JDIALOG_VALUE = "jdialog"; |
|
44 |
|
|
45 |
/**
|
|
46 |
* The value of the type attribute which will instantiate a
|
|
47 |
* {@link javax.swing.JFrame JFrame}.
|
|
48 |
*/
|
|
49 |
protected static final String JFRAME_VALUE = "jframe"; |
|
50 |
|
|
51 | 20 |
public void enterElement(Map atts) throws SAXException { |
52 | 20 |
Window window = null;
|
53 |
|
|
54 | 20 |
if (atts.get(ATTR_TYPE).equals(JDIALOG_VALUE)) {
|
55 | 17 |
window = new JDialog();
|
56 | 3 |
} else if (atts.get(ATTR_TYPE).equals(JFRAME_VALUE)) { |
57 | 3 |
window = new JFrame();
|
58 |
} |
|
59 |
|
|
60 | 20 |
tagContext.put(TagHandler.CURRENT_WINDOW_ID_KEY, atts.get(ATTR_ID)); |
61 | 20 |
tagContext.put(TagHandler.CURRENT_WINDOW_KEY, window); |
62 |
|
|
63 | 20 |
if (null != atts.get(ATTR_ID)) { |
64 | 20 |
Map m = (Map)tagContext.get(TagHandler.OBJECTS_MAP_KEY); |
65 | 20 |
m.put(atts.get(ATTR_ID), window); |
66 |
} |
|
67 |
|
|
68 | 20 |
pushCurrentObject((String)atts.get(ATTR_ID), window); |
69 |
} |
|
70 |
|
|
71 | 16 |
public void exitElement() throws SAXException { |
72 | 16 |
popCurrentObject(); |
73 |
|
|
74 | 16 |
tagContext.remove(TagHandler.CURRENT_WINDOW_KEY); |
75 | 16 |
tagContext.remove(TagHandler.CURRENT_WINDOW_ID_KEY); |
76 |
} |
|
77 |
} |
|
78 |
|
|