Revision 168 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
DefaultUsabilitySwingManager.java | ||
---|---|---|
26 | 26 |
*/ |
27 | 27 |
package org.gvsig.tools.swing.impl.usability; |
28 | 28 |
|
29 |
import java.awt.Component; |
|
30 |
import java.awt.GridBagConstraints; |
|
31 |
import java.awt.GridBagLayout; |
|
32 |
import java.awt.Insets; |
|
33 |
|
|
29 | 34 |
import javax.swing.Action; |
30 | 35 |
import javax.swing.Icon; |
31 | 36 |
import javax.swing.JButton; |
37 |
import javax.swing.JPanel; |
|
32 | 38 |
|
33 | 39 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
34 | 40 |
import org.gvsig.tools.swing.impl.usability.button.JStandardizedButton; |
41 |
import org.gvsig.tools.swing.impl.usability.button.JStandardizedToolButton; |
|
35 | 42 |
|
36 | 43 |
/** |
37 | 44 |
* Default implementation for the {@link UsabilitySwingManager}. |
... | ... | |
40 | 47 |
*/ |
41 | 48 |
public class DefaultUsabilitySwingManager implements UsabilitySwingManager { |
42 | 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 |
|
|
43 | 91 |
public JButton createJButton() { |
44 | 92 |
return new JStandardizedButton(); |
45 | 93 |
} |
46 | 94 |
|
47 |
public JButton createJButton(String text) {
|
|
48 |
return new JStandardizedButton(text);
|
|
95 |
public JButton createJButton(Action action) {
|
|
96 |
return new JStandardizedButton(action);
|
|
49 | 97 |
} |
50 | 98 |
|
51 | 99 |
public JButton createJButton(Icon icon) { |
52 | 100 |
return new JStandardizedButton(icon); |
53 | 101 |
} |
54 | 102 |
|
103 |
public JButton createJButton(String text) { |
|
104 |
return new JStandardizedButton(text); |
|
105 |
} |
|
106 |
|
|
55 | 107 |
public JButton createJButton(String text, Icon icon) { |
56 | 108 |
return new JStandardizedButton(text, icon); |
57 | 109 |
} |
110 |
|
|
58 | 111 |
|
59 |
public JButton createJButton(Action action) {
|
|
60 |
return new JStandardizedButton(action);
|
|
112 |
public JButton createJToolButton(String text) {
|
|
113 |
return new JStandardizedToolButton(text);
|
|
61 | 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 |
} |
|
62 | 127 |
|
63 | 128 |
} |
Also available in: Unified diff