root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / modeler / parameters / StringPanel.java @ 83
History | View | Annotate | Download (3.61 KB)
1 |
package es.unex.sextante.gui.modeler.parameters; |
---|---|
2 |
|
3 |
import info.clearthought.layout.TableLayout; |
4 |
import info.clearthought.layout.TableLayoutConstants; |
5 |
|
6 |
import javax.swing.JDialog; |
7 |
import javax.swing.JLabel; |
8 |
import javax.swing.JOptionPane; |
9 |
import javax.swing.JTextField; |
10 |
|
11 |
import es.unex.sextante.additionalInfo.AdditionalInfoString; |
12 |
import es.unex.sextante.core.Sextante; |
13 |
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException; |
14 |
import es.unex.sextante.gui.modeler.ModelerPanel; |
15 |
import es.unex.sextante.parameters.Parameter; |
16 |
import es.unex.sextante.parameters.ParameterString; |
17 |
|
18 |
public class StringPanel |
19 |
extends
|
20 |
ParameterPanel { |
21 |
|
22 |
private JTextField jTextFieldDefault; |
23 |
private JLabel jLabelDefault; |
24 |
|
25 |
|
26 |
public StringPanel(final JDialog parent, |
27 |
final ModelerPanel panel) {
|
28 |
|
29 |
super(parent, panel);
|
30 |
|
31 |
} |
32 |
|
33 |
|
34 |
public StringPanel(final ModelerPanel panel) { |
35 |
|
36 |
super(panel);
|
37 |
|
38 |
} |
39 |
|
40 |
|
41 |
@Override
|
42 |
protected void initGUI() { |
43 |
|
44 |
super.initGUI();
|
45 |
|
46 |
super.setTitle(Sextante.getText("modeler_add_par_string")); |
47 |
|
48 |
super.setPreferredSize(new java.awt.Dimension(400, 200)); |
49 |
|
50 |
try {
|
51 |
{ |
52 |
final TableLayout thisLayout = new TableLayout |
53 |
(new double[][] { { TableLayoutConstants.MINIMUM, 5.0, TableLayoutConstants.FILL }, |
54 |
{ TableLayoutConstants.MINIMUM, } }); |
55 |
thisLayout.setHGap(5);
|
56 |
thisLayout.setVGap(5);
|
57 |
jPanelMiddle.setLayout(thisLayout); |
58 |
{ |
59 |
jLabelDefault = new JLabel(); |
60 |
jPanelMiddle.add(jLabelDefault, "0, 0");
|
61 |
jLabelDefault.setText(Sextante.getText("Default_value"));
|
62 |
} |
63 |
{ |
64 |
jTextFieldDefault = new JTextField(); |
65 |
jPanelMiddle.add(jTextFieldDefault, "2, 0");
|
66 |
} |
67 |
} |
68 |
} |
69 |
catch (final Exception e) { |
70 |
Sextante.addErrorToLog(e); |
71 |
} |
72 |
|
73 |
} |
74 |
|
75 |
|
76 |
@Override
|
77 |
public String getParameterDescription() { |
78 |
|
79 |
return Sextante.getText("String"); |
80 |
|
81 |
} |
82 |
|
83 |
|
84 |
@Override
|
85 |
protected boolean prepareParameter() { |
86 |
|
87 |
|
88 |
final String sDescription = jTextFieldDescription.getText(); |
89 |
final String sDefault = jTextFieldDefault.getText(); |
90 |
|
91 |
if (sDescription.length() != 0) { |
92 |
final AdditionalInfoString ai = new AdditionalInfoString(); |
93 |
ai.setDefaultString(sDefault); |
94 |
m_Parameter = new ParameterString();
|
95 |
m_Parameter.setParameterDescription(sDescription); |
96 |
m_Parameter.setParameterAdditionalInfo(ai); |
97 |
|
98 |
m_Parameter.setColorR(m_Color.getRed()); |
99 |
m_Parameter.setColorG(m_Color.getGreen()); |
100 |
m_Parameter.setColorB(m_Color.getBlue()); |
101 |
m_Parameter.setColorAlpha(m_Color.getAlpha()); |
102 |
|
103 |
return true; |
104 |
} |
105 |
else {
|
106 |
JOptionPane.showMessageDialog(null, Sextante.getText("Invalid_description"), Sextante.getText("Warning"), |
107 |
JOptionPane.WARNING_MESSAGE);
|
108 |
return false; |
109 |
} |
110 |
|
111 |
|
112 |
} |
113 |
|
114 |
|
115 |
@Override
|
116 |
public void setParameter(final Parameter param) { |
117 |
|
118 |
super.setParameter(param);
|
119 |
|
120 |
try {
|
121 |
final AdditionalInfoString ai = (AdditionalInfoString) param.getParameterAdditionalInfo();
|
122 |
jTextFieldDefault.setText(ai.getDefaultString()); |
123 |
} |
124 |
catch (final NullParameterAdditionalInfoException e) { |
125 |
e.printStackTrace(); |
126 |
} |
127 |
|
128 |
} |
129 |
|
130 |
|
131 |
@Override
|
132 |
public boolean parameterCanBeAdded() { |
133 |
|
134 |
return true; |
135 |
|
136 |
} |
137 |
|
138 |
} |