Revision 100
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/MainAction.java | ||
---|---|---|
68 | 68 |
public void actionPerformed(ActionEvent e) { |
69 | 69 |
String title = getComponentTitle(); |
70 | 70 |
int index = tabbedPane.indexOfTab(title); |
71 |
if (index > -1) { |
|
72 |
tabbedPane.setSelectedIndex(index); |
|
73 |
} else { |
|
71 |
if (index <= -1) { |
|
74 | 72 |
tabbedPane.addTab(title, createComponent()); |
73 |
index = tabbedPane.indexOfTab(title); |
|
75 | 74 |
} |
75 |
tabbedPane.setSelectedIndex(index); |
|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
protected abstract JComponent createComponent(); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/Main.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
18 | 18 |
import org.gvsig.tools.main.dynobject.DynObjectComponentAction; |
19 |
import org.gvsig.tools.main.usability.UsabilityAction; |
|
19 | 20 |
|
20 | 21 |
/** |
21 | 22 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
... | ... | |
75 | 76 |
toolBar.add(new JButton(actions[i])); |
76 | 77 |
} |
77 | 78 |
|
78 |
frame.setPreferredSize(new Dimension(640, 480));
|
|
79 |
frame.setPreferredSize(new Dimension(800, 600));
|
|
79 | 80 |
|
80 | 81 |
frame.setJMenuBar(menuBar); |
81 | 82 |
frame.add(toolBar, BorderLayout.PAGE_START); |
... | ... | |
86 | 87 |
} |
87 | 88 |
|
88 | 89 |
private MainAction[] createActions() { |
89 |
return new MainAction[] { new DynObjectComponentAction(tabbedPane) }; |
|
90 |
return new MainAction[] { new DynObjectComponentAction(tabbedPane), |
|
91 |
new UsabilityAction(tabbedPane) }; |
|
90 | 92 |
} |
91 | 93 |
|
92 | 94 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/usability/UsabilityAction.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2010 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.tools.main.usability; |
|
28 |
|
|
29 |
import java.awt.Component; |
|
30 |
|
|
31 |
import javax.swing.BoxLayout; |
|
32 |
import javax.swing.JButton; |
|
33 |
import javax.swing.JComponent; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JTabbedPane; |
|
36 |
|
|
37 |
import org.gvsig.tools.main.MainAction; |
|
38 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
39 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
40 |
|
|
41 |
/** |
|
42 |
* Shows the panel of usability components. |
|
43 |
* |
|
44 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
|
45 |
*/ |
|
46 |
public class UsabilityAction extends MainAction { |
|
47 |
|
|
48 |
private static final long serialVersionUID = 6471916708466720365L; |
|
49 |
|
|
50 |
private static final UsabilitySwingManager manager = ToolsSwingLocator |
|
51 |
.getUsabilitySwingManager(); |
|
52 |
|
|
53 |
/** |
|
54 |
* @see MainAction#MainAction(JTabbedPane) |
|
55 |
*/ |
|
56 |
public UsabilityAction(JTabbedPane tabbedPane) { |
|
57 |
super("Usability", tabbedPane); |
|
58 |
putValue(SHORT_DESCRIPTION, "Usability components"); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
protected JComponent createComponent() { |
|
63 |
JTabbedPane tabbedPane = new JTabbedPane(); |
|
64 |
tabbedPane.setTabPlacement(JTabbedPane.RIGHT); |
|
65 |
|
|
66 |
tabbedPane.addTab("JButton", createJButtonComponent()); |
|
67 |
|
|
68 |
return tabbedPane; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
protected String getComponentTitle() { |
|
73 |
return "Usability"; |
|
74 |
} |
|
75 |
|
|
76 |
private Component createJButtonComponent() { |
|
77 |
// Create the container panel |
|
78 |
JPanel panel = new JPanel(); |
|
79 |
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); |
|
80 |
// panel.setLayout(new GridLayout(18, 1)); |
|
81 |
// panel.setLayout(new ); |
|
82 |
|
|
83 |
// Create buttons with different sizes |
|
84 |
StringBuffer text = new StringBuffer("012"); |
|
85 |
for (int i = 4; i < 22; i++) { |
|
86 |
text.append(String.valueOf(i % 10)); |
|
87 |
JButton button = manager.createJButton(text.toString()); |
|
88 |
panel.add(button); |
|
89 |
} |
|
90 |
|
|
91 |
return panel; |
|
92 |
} |
|
93 |
|
|
94 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/README.txt | ||
---|---|---|
1 |
To add a new tab to the application, perform the following steps: |
|
2 |
|
|
3 |
- Create a new class extending the MainAction class, implementing the methods: |
|
4 |
|
|
5 |
- createComponent(): create your demo panel |
|
6 |
|
|
7 |
- getComponentTitle(): return the name of the panel |
|
8 |
|
|
9 |
- Add your new action class to the list of actions in the Main.createActions() |
|
10 |
method. |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/ToolsSwingDefaultImplLibrary.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.tools.swing.impl; |
23 | 23 |
|
24 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
25 |
import org.gvsig.tools.swing.impl.dynobject.DefaultDynObjectSwingManager; |
|
24 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
26 | 25 |
import org.gvsig.tools.library.AbstractLibrary; |
27 | 26 |
import org.gvsig.tools.library.Library; |
28 | 27 |
import org.gvsig.tools.library.LibraryException; |
28 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
29 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
|
30 |
import org.gvsig.tools.swing.api.dynobject.dynfield.DynFieldComponentFactory; |
|
31 |
import org.gvsig.tools.swing.impl.dynobject.DefaultDynObjectSwingManager; |
|
32 |
import org.gvsig.tools.swing.impl.dynobject.dynfield.NumberFieldComponentFactory; |
|
33 |
import org.gvsig.tools.swing.impl.usability.DefaultUsabilitySwingManager; |
|
29 | 34 |
|
30 | 35 |
/** |
31 | 36 |
* {@link Library} for the default tools swing implementation. |
... | ... | |
38 | 43 |
protected void doInitialize() throws LibraryException { |
39 | 44 |
ToolsSwingLocator |
40 | 45 |
.registerDynObjectSwingManager(DefaultDynObjectSwingManager.class); |
46 |
ToolsSwingLocator |
|
47 |
.registerUsabilitySwingManager(DefaultUsabilitySwingManager.class); |
|
41 | 48 |
} |
42 | 49 |
|
43 | 50 |
@Override |
44 | 51 |
protected void doPostInitialize() throws LibraryException { |
45 |
// Do nothing |
|
52 |
DynObjectSwingManager dsManager = ToolsSwingLocator |
|
53 |
.getDynObjectSwingManager(); |
|
54 |
|
|
55 |
DynFieldComponentFactory numberFactory = new NumberFieldComponentFactory(); |
|
56 |
dsManager.registerDynFieldComponentFactory(numberFactory, |
|
57 |
DataTypes.BYTE); |
|
58 |
dsManager |
|
59 |
.registerDynFieldComponentFactory(numberFactory, DataTypes.INT); |
|
60 |
dsManager.registerDynFieldComponentFactory(numberFactory, |
|
61 |
DataTypes.LONG); |
|
62 |
dsManager.registerDynFieldComponentFactory(numberFactory, |
|
63 |
DataTypes.FLOAT); |
|
64 |
dsManager.registerDynFieldComponentFactory(numberFactory, |
|
65 |
DataTypes.DOUBLE); |
|
46 | 66 |
} |
47 | 67 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/usability/button/JStandardizedButton.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program 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 |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.tools.swing.impl.usability.button; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
|
|
45 |
import javax.swing.Action; |
|
46 |
import javax.swing.Icon; |
|
47 |
import javax.swing.JButton; |
|
48 |
|
|
49 |
/** |
|
50 |
* According to the gvSIG's GUI style sheet all the buttons in the application |
|
51 |
* will have a normative size. No smaller than a concrete size, and big enough |
|
52 |
* to contain the text and avoiding the "..." characters. The button will grow |
|
53 |
* up in width by a set of widths defined in this style sheet, always choosing |
|
54 |
* the smallest width that can contain the text. If the biggest width is not |
|
55 |
* enought for this purpose then the button will automatically grow up to the |
|
56 |
* smallest necessary width to fit the text.<br> |
|
57 |
* <p> |
|
58 |
* The button resizing is based on the <b>setText(String txt)</b> method. |
|
59 |
* However, it is possible to use a custom size if you invoke one of |
|
60 |
* <b>setSize(..)</b>, <b>setBorders(...)</b> or <b>setPreferredSize(...)</b> |
|
61 |
* after invoking the <b>setText(...)<b> method. |
|
62 |
* <p> |
|
63 |
* This class is just a standard javax.swing.JButton that handles this issue. |
|
64 |
* </p> |
|
65 |
* |
|
66 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
67 |
* |
|
68 |
*/ |
|
69 |
public class JStandardizedButton extends JButton { |
|
70 |
private static final long serialVersionUID = -1635879317292710725L; |
|
71 |
|
|
72 |
// TODO this should be initialized from a properties file or so. |
|
73 |
private static int[][] buttonSizes = new int[][] { new int[] { 90, 23 }, |
|
74 |
new int[] { 110, 23 }, new int[] { 135, 23 }, new int[] { 160, 23 } }; |
|
75 |
|
|
76 |
private String enableText; |
|
77 |
private String toolTip; |
|
78 |
|
|
79 |
/** |
|
80 |
* Creates a new empty instance of org.gvsig.gui.beans.swing.JButton. |
|
81 |
*/ |
|
82 |
public JStandardizedButton() { |
|
83 |
super(); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing a |
|
88 |
* text. |
|
89 |
* |
|
90 |
* @param text |
|
91 |
*/ |
|
92 |
public JStandardizedButton(String text) { |
|
93 |
super(); |
|
94 |
setText(text); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
99 |
* image and a text. |
|
100 |
* |
|
101 |
* @param text |
|
102 |
* @param icon |
|
103 |
*/ |
|
104 |
public JStandardizedButton(String text, Icon icon) { |
|
105 |
super(icon); |
|
106 |
setText(text); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
111 |
* image. |
|
112 |
*/ |
|
113 |
public JStandardizedButton(Icon icon) { |
|
114 |
super(icon); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton from an |
|
119 |
* {@link Action}. |
|
120 |
*/ |
|
121 |
public JStandardizedButton(Action action) { |
|
122 |
super(action); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Gets the text that appears in the tooltip when the button is disabled. |
|
127 |
* |
|
128 |
* @return String |
|
129 |
*/ |
|
130 |
public String getEnableText() { |
|
131 |
return enableText; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Sets the text that appears in the tooltip when the button is disabled. |
|
136 |
* |
|
137 |
* @param enableText |
|
138 |
* The enableText to set. |
|
139 |
*/ |
|
140 |
public void setEnableText(String enableText) { |
|
141 |
this.enableText = enableText; |
|
142 |
} |
|
143 |
|
|
144 |
public void setEnabled(boolean aFlag) { |
|
145 |
super.setEnabled(aFlag); |
|
146 |
if (aFlag) { |
|
147 |
setToolTipText(toolTip); |
|
148 |
} else { |
|
149 |
setToolTipText(enableText); |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Sets the text that appears in the tooltip when the button is enabled. |
|
155 |
*/ |
|
156 |
public void setToolTip(String text) { |
|
157 |
toolTip = text; |
|
158 |
} |
|
159 |
|
|
160 |
// public void setText(String text) { |
|
161 |
// super.setText(text); |
|
162 |
// Dimension d = getUI().getMinimumSize(this); |
|
163 |
// int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
164 |
// int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
165 |
// |
|
166 |
// // figure out the suitable width |
|
167 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
168 |
// if (oldWidth < buttonSizes[i][0]) |
|
169 |
// newWidth = buttonSizes[i][0]; |
|
170 |
// |
|
171 |
// // figure out the suitable height |
|
172 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
173 |
// if (oldHeight < buttonSizes[i][1]) |
|
174 |
// newHeight = buttonSizes[i][1]; |
|
175 |
// |
|
176 |
// Dimension sz = new Dimension(newWidth, newHeight); |
|
177 |
// super.setSize(sz); |
|
178 |
// super.setPreferredSize(sz); |
|
179 |
// } |
|
180 |
|
|
181 |
@Override |
|
182 |
public Dimension getPreferredSize() { |
|
183 |
Dimension d = getUI().getMinimumSize(this); |
|
184 |
int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
185 |
int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
186 |
|
|
187 |
// figure out the suitable width |
|
188 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
189 |
if (oldWidth < buttonSizes[i][0]) |
|
190 |
newWidth = buttonSizes[i][0]; |
|
191 |
|
|
192 |
// figure out the suitable height |
|
193 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
194 |
if (oldHeight < buttonSizes[i][1]) |
|
195 |
newHeight = buttonSizes[i][1]; |
|
196 |
|
|
197 |
return new Dimension(newWidth, newHeight); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public Dimension getMaximumSize() { |
|
202 |
return getPreferredSize(); |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public Dimension getMinimumSize() { |
|
207 |
return getPreferredSize(); |
|
208 |
} |
|
209 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/usability/DefaultUsabilitySwingManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2010 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.tools.swing.impl.usability; |
|
28 |
|
|
29 |
import javax.swing.Action; |
|
30 |
import javax.swing.Icon; |
|
31 |
import javax.swing.JButton; |
|
32 |
|
|
33 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
34 |
import org.gvsig.tools.swing.impl.usability.button.JStandardizedButton; |
|
35 |
|
|
36 |
/** |
|
37 |
* Default implementation for the {@link UsabilitySwingManager}. |
|
38 |
* |
|
39 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
|
40 |
*/ |
|
41 |
public class DefaultUsabilitySwingManager implements UsabilitySwingManager { |
|
42 |
|
|
43 |
public JButton createJButton() { |
|
44 |
return new JStandardizedButton(); |
|
45 |
} |
|
46 |
|
|
47 |
public JButton createJButton(String text) { |
|
48 |
return new JStandardizedButton(text); |
|
49 |
} |
|
50 |
|
|
51 |
public JButton createJButton(Icon icon) { |
|
52 |
return new JStandardizedButton(icon); |
|
53 |
} |
|
54 |
|
|
55 |
public JButton createJButton(String text, Icon icon) { |
|
56 |
return new JStandardizedButton(text, icon); |
|
57 |
} |
|
58 |
|
|
59 |
public JButton createJButton(Action action) { |
|
60 |
return new JStandardizedButton(action); |
|
61 |
} |
|
62 |
|
|
63 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/usability/UsabilitySwingManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2010 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.tools.swing.api.usability; |
|
28 |
|
|
29 |
import javax.swing.Action; |
|
30 |
import javax.swing.Icon; |
|
31 |
import javax.swing.JButton; |
|
32 |
|
|
33 |
/** |
|
34 |
* Creates common Swing components which take into account usability guides |
|
35 |
* defined for the gvSIG project. |
|
36 |
* |
|
37 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
|
38 |
*/ |
|
39 |
public interface UsabilitySwingManager { |
|
40 |
|
|
41 |
/** |
|
42 |
* Creates a button with no set text or icon. |
|
43 |
* |
|
44 |
* @return a button |
|
45 |
*/ |
|
46 |
JButton createJButton(); |
|
47 |
|
|
48 |
/** |
|
49 |
* Creates a button with text. |
|
50 |
* |
|
51 |
* @param text |
|
52 |
* the text of the button |
|
53 |
* |
|
54 |
* @return a button |
|
55 |
*/ |
|
56 |
JButton createJButton(String text); |
|
57 |
|
|
58 |
/** |
|
59 |
* Creates a button with an icon. |
|
60 |
* |
|
61 |
* @param icon |
|
62 |
* the Icon image to display on the button |
|
63 |
* |
|
64 |
* @return a button |
|
65 |
*/ |
|
66 |
JButton createJButton(Icon icon); |
|
67 |
|
|
68 |
/** |
|
69 |
* Creates a button with initial text and icon. |
|
70 |
* |
|
71 |
* @param text |
|
72 |
* the text of the button |
|
73 |
* @param icon |
|
74 |
* the Icon image to display on the button |
|
75 |
* |
|
76 |
* @return a button |
|
77 |
*/ |
|
78 |
JButton createJButton(String text, Icon icon); |
|
79 |
|
|
80 |
/** |
|
81 |
* Creates a button where properties are taken from the {@link Action} |
|
82 |
* supplied. |
|
83 |
* |
|
84 |
* @param a |
|
85 |
* the {@link Action} used to specify the new button |
|
86 |
* |
|
87 |
*/ |
|
88 |
JButton createJButton(Action action); |
|
89 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingLocator.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import org.gvsig.tools.locator.BaseLocator; |
25 | 25 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
26 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
26 | 27 |
|
27 | 28 |
/** |
28 | 29 |
* Locator for the tools swing Library. Returns references to the library's main |
... | ... | |
38 | 39 |
|
39 | 40 |
public static final String DYNOBJECT_SWING_MANAGER_DESCRIPTION = "Tools DynObject Swing Manager"; |
40 | 41 |
|
42 |
public static final String USABILITY_SWING_MANAGER_NAME = "Tools.usability.swing.manager"; |
|
43 |
|
|
44 |
public static final String USABILITY_SWING_MANAGER_DESCRIPTION = "Tools Usability Swing Manager"; |
|
45 |
|
|
41 | 46 |
/** |
42 | 47 |
* Unique instance. |
43 | 48 |
*/ |
... | ... | |
83 | 88 |
DYNOBJECT_SWING_MANAGER_NAME); |
84 | 89 |
} |
85 | 90 |
|
91 |
/** |
|
92 |
* Registers the Class implementing the UsabilitySwingManager interface. |
|
93 |
* |
|
94 |
* @param clazz |
|
95 |
* implementing the UsabilitySwingManager interface |
|
96 |
*/ |
|
97 |
public static void registerUsabilitySwingManager( |
|
98 |
Class<? extends UsabilitySwingManager> clazz) { |
|
99 |
getInstance().register(USABILITY_SWING_MANAGER_NAME, |
|
100 |
USABILITY_SWING_MANAGER_DESCRIPTION, clazz); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* Gets the instance of the {@link UsabilitySwingManager} registered. |
|
105 |
* |
|
106 |
* @return {@link UsabilitySwingManager} |
|
107 |
*/ |
|
108 |
public static UsabilitySwingManager getUsabilitySwingManager() { |
|
109 |
return (UsabilitySwingManager) getInstance().get( |
|
110 |
USABILITY_SWING_MANAGER_NAME); |
|
111 |
} |
|
112 |
|
|
86 | 113 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingLibrary.java | ||
---|---|---|
25 | 25 |
import org.gvsig.tools.library.LibraryException; |
26 | 26 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
27 | 27 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
28 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
28 | 29 |
|
29 | 30 |
/** |
30 | 31 |
* Initialization of the Tools swing library. |
... | ... | |
36 | 37 |
@Override |
37 | 38 |
protected void doInitialize() throws LibraryException { |
38 | 39 |
// Do nothing |
39 |
|
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
@Override |
43 | 43 |
protected void doPostInitialize() throws LibraryException { |
44 | 44 |
// Validate there is any DynObjectSwingManager implementation |
45 | 45 |
// registered. |
46 |
DynObjectSwingManager uiManager = ToolsSwingLocator.getDynObjectSwingManager(); |
|
46 |
DynObjectSwingManager dynObjectSwingManager = ToolsSwingLocator |
|
47 |
.getDynObjectSwingManager(); |
|
47 | 48 |
|
48 |
if (uiManager == null) {
|
|
49 |
if (dynObjectSwingManager == null) {
|
|
49 | 50 |
throw new ReferenceNotRegisteredException( |
50 |
ToolsSwingLocator.DYNOBJECT_SWING_MANAGER_NAME, ToolsSwingLocator
|
|
51 |
.getInstance());
|
|
51 |
ToolsSwingLocator.DYNOBJECT_SWING_MANAGER_NAME, |
|
52 |
ToolsSwingLocator.getInstance());
|
|
52 | 53 |
} |
54 |
|
|
55 |
// Validate there is any UsabilitySwingManager implementation |
|
56 |
// registered. |
|
57 |
UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator |
|
58 |
.getUsabilitySwingManager(); |
|
59 |
|
|
60 |
if (usabilitySwingManager == null) { |
|
61 |
throw new ReferenceNotRegisteredException( |
|
62 |
ToolsSwingLocator.USABILITY_SWING_MANAGER_NAME, |
|
63 |
ToolsSwingLocator.getInstance()); |
|
64 |
} |
|
53 | 65 |
} |
54 |
|
|
55 | 66 |
} |
Also available in: Unified diff