gvsig-tools / 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 @ 298
History | View | Annotate | Download (4.05 KB)
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 java.awt.Component; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.GridBagLayout; |
32 |
import java.awt.Insets; |
33 |
|
34 |
import javax.swing.Action; |
35 |
import javax.swing.Icon; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JPanel; |
38 |
|
39 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
40 |
import org.gvsig.tools.swing.impl.usability.button.JStandardizedButton; |
41 |
import org.gvsig.tools.swing.impl.usability.button.JStandardizedToolButton; |
42 |
|
43 |
/**
|
44 |
* Default implementation for the {@link UsabilitySwingManager}.
|
45 |
*
|
46 |
* @author 2010- C?sar Ordi?ana - gvSIG team
|
47 |
*/
|
48 |
public class DefaultUsabilitySwingManager implements UsabilitySwingManager { |
49 |
|
50 |
/*
|
51 |
* (non-Javadoc)
|
52 |
*
|
53 |
* @see
|
54 |
* org.gvsig.tools.swing.api.usability.UsabilitySwingManager#createBoxLayout
|
55 |
* (java.awt.Component, java.awt.Component, java.lang.Integer,
|
56 |
* java.lang.Integer)
|
57 |
*/
|
58 |
public JPanel createGridBagRowPanel(JPanel gridBagPanel, |
59 |
Component labelComponent, Component fieldComponent, |
60 |
Integer labelMargin, Integer fieldMargin) { |
61 |
// Create a panel that uses BoxLayout.
|
62 |
JPanel panel;
|
63 |
if (gridBagPanel == null) { |
64 |
panel = new JPanel(); |
65 |
panel.setLayout(new GridBagLayout()); |
66 |
} else {
|
67 |
panel = gridBagPanel; |
68 |
} |
69 |
|
70 |
GridBagConstraints constr = this.getDefaultParametersConstraints(); |
71 |
constr.fill = GridBagConstraints.HORIZONTAL;
|
72 |
|
73 |
constr.gridwidth = GridBagConstraints.RELATIVE;
|
74 |
constr.weighty = 0;
|
75 |
|
76 |
if (labelComponent != null) { |
77 |
// constr.weightx = 0;
|
78 |
// int width = labelComponent.getSize().width;
|
79 |
|
80 |
if (labelMargin != null) { |
81 |
constr.weightx = labelMargin; |
82 |
} |
83 |
panel.add(labelComponent, constr); |
84 |
} |
85 |
constr.fill = GridBagConstraints.NONE;
|
86 |
// constr.gridwidth = GridBagConstraints.RELATIVE;
|
87 |
|
88 |
if (fieldComponent != null) { |
89 |
constr.weightx = 0;
|
90 |
if (fieldMargin != null) { |
91 |
constr.weightx = labelMargin; |
92 |
} |
93 |
panel.add(fieldComponent, constr); |
94 |
} |
95 |
return panel;
|
96 |
} |
97 |
|
98 |
public JButton createJButton() { |
99 |
return new JStandardizedButton(); |
100 |
} |
101 |
|
102 |
public JButton createJButton(Action action) { |
103 |
return new JStandardizedButton(action); |
104 |
} |
105 |
|
106 |
public JButton createJButton(Icon icon) { |
107 |
return new JStandardizedButton(icon); |
108 |
} |
109 |
|
110 |
public JButton createJButton(String text) { |
111 |
return new JStandardizedButton(text); |
112 |
} |
113 |
|
114 |
public JButton createJButton(String text, Icon icon) { |
115 |
return new JStandardizedButton(text, icon); |
116 |
} |
117 |
|
118 |
public JButton createJToolButton(String text) { |
119 |
return new JStandardizedToolButton(text); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* @return
|
124 |
*/
|
125 |
private GridBagConstraints getDefaultParametersConstraints() { |
126 |
GridBagConstraints constr = new GridBagConstraints(); |
127 |
constr.insets = new Insets(2, 2, 2, 2); |
128 |
constr.ipadx = 2;
|
129 |
constr.ipady = 2;
|
130 |
constr.anchor = GridBagConstraints.PAGE_START;
|
131 |
return constr;
|
132 |
} |
133 |
|
134 |
} |