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 @ 168
History | View | Annotate | Download (3.69 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 |
/* (non-Javadoc)
|
51 |
* @see org.gvsig.tools.swing.api.usability.UsabilitySwingManager#createBoxLayout(java.awt.Component, java.awt.Component, java.lang.Integer, java.lang.Integer)
|
52 |
*/
|
53 |
public JPanel createGridBagRowPanel(JPanel gridBagPanel, Component labelComponent, |
54 |
Component fieldComponent,
|
55 |
Integer labelMargin, Integer fieldMargin) { |
56 |
// Create a panel that uses BoxLayout.
|
57 |
JPanel panel;
|
58 |
if (gridBagPanel==null){ |
59 |
panel = new JPanel(); |
60 |
panel.setLayout(new GridBagLayout()); |
61 |
}else
|
62 |
panel = gridBagPanel; |
63 |
|
64 |
GridBagConstraints constr = this.getDefaultParametersConstraints(); |
65 |
constr.fill = GridBagConstraints.HORIZONTAL;
|
66 |
|
67 |
constr.gridwidth = GridBagConstraints.RELATIVE;
|
68 |
constr.weighty = 0;
|
69 |
|
70 |
if (labelComponent != null) { |
71 |
// constr.weightx = 0;
|
72 |
// int width = labelComponent.getSize().width;
|
73 |
|
74 |
if (labelMargin != null) |
75 |
constr.weightx = labelMargin; |
76 |
panel.add(labelComponent, constr); |
77 |
} |
78 |
constr.fill = GridBagConstraints.NONE;
|
79 |
// constr.gridwidth = GridBagConstraints.RELATIVE;
|
80 |
|
81 |
|
82 |
if (fieldComponent != null) { |
83 |
constr.weightx = 0;
|
84 |
if (fieldMargin != null) |
85 |
constr.weightx = labelMargin; |
86 |
panel.add(fieldComponent, constr); |
87 |
} |
88 |
return panel;
|
89 |
} |
90 |
|
91 |
public JButton createJButton() { |
92 |
return new JStandardizedButton(); |
93 |
} |
94 |
|
95 |
public JButton createJButton(Action action) { |
96 |
return new JStandardizedButton(action); |
97 |
} |
98 |
|
99 |
public JButton createJButton(Icon icon) { |
100 |
return new JStandardizedButton(icon); |
101 |
} |
102 |
|
103 |
public JButton createJButton(String text) { |
104 |
return new JStandardizedButton(text); |
105 |
} |
106 |
|
107 |
public JButton createJButton(String text, Icon icon) { |
108 |
return new JStandardizedButton(text, icon); |
109 |
} |
110 |
|
111 |
|
112 |
public JButton createJToolButton(String text) { |
113 |
return new JStandardizedToolButton(text); |
114 |
} |
115 |
|
116 |
/**
|
117 |
* @return
|
118 |
*/
|
119 |
private GridBagConstraints getDefaultParametersConstraints() { |
120 |
GridBagConstraints constr = new GridBagConstraints(); |
121 |
constr.insets = new Insets(2, 2, 2, 2); |
122 |
constr.ipadx = 2;
|
123 |
constr.ipady = 2;
|
124 |
constr.anchor = GridBagConstraints.PAGE_START;
|
125 |
return constr;
|
126 |
} |
127 |
|
128 |
} |