Statistics
| Revision:

gvsig-educa / org.gvsig.educa.thematicmap / trunk / org.gvsig.educa.thematicmap / org.gvsig.educa.thematicmap.lib / org.gvsig.educa.thematicmap.lib.prov.locateonthemap / src / main / java / org / gvsig / educa / thematicmap / lib / prov / locateonthemap / StepGeomSelectGame.java @ 228

History | View | Annotate | Download (5.72 KB)

1
package org.gvsig.educa.thematicmap.lib.prov.locateonthemap;
2

    
3
import java.awt.GridBagConstraints;
4
import java.awt.GridBagLayout;
5
import java.awt.Insets;
6

    
7
import javax.swing.JComboBox;
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11
import javax.swing.JTextArea;
12
import javax.swing.JTextField;
13

    
14
import org.apache.commons.lang3.StringUtils;
15
import org.gvsig.educa.thematicmap.ThematicMapLocator;
16
import org.gvsig.educa.thematicmap.ThematicMapManager;
17
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation;
18
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilationInformation;
19
import org.gvsig.educa.thematicmap.impl.editor.DefaultThematicMapCompilationEditor;
20
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
21

    
22
public class StepGeomSelectGame extends JPanel {
23

    
24
        private static final GridBagConstraints LABEL_CONSTRAINT = new GridBagConstraints(
25
                        GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, 1, 1, 0,
26
                        0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4,
27
                                        4, 4, 10), 2, 2);
28

    
29
        private static final GridBagConstraints FIELD_CONSTRAINT = new GridBagConstraints(
30
                        GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE,
31
                        GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.WEST,
32
                        GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 10), 2, 2);
33

    
34
        private final ThematicMapCompilation compilation;
35

    
36
        // private final ThematicMapSwingManager swingManager;
37
        private final ThematicMapManager swingManager;
38

    
39
        @SuppressWarnings("unused")
40
        private final DefaultThematicMapCompilationEditor editor;
41

    
42
        // new
43
        private String questionString;
44
        private String columnNameIDString;
45

    
46
        private JLabel gameDescriptionText;
47

    
48
        private JLabel questionText;
49
        private JLabel answersText;
50

    
51
        private JTextField questionTextField;
52

    
53
        private JTextArea answersTextArea;
54

    
55
        private JComboBox answerIDComboBox;
56

    
57
        private JScrollPane answersListScrollPane;
58

    
59
        private JTextField txtId;
60

    
61
        private JTextField txtName;
62

    
63
        private JTextField txtVersion;
64

    
65
        private JTextArea txtDescription;
66

    
67
        private boolean allowChangeId;
68

    
69
        /**
70
         * @param defaultThematicMapCompilationEditor
71
         * @param allowChangeId
72
         */
73
        public StepGeomSelectGame(
74
                        DefaultThematicMapCompilationEditor defaultThematicMapCompilationEditor,
75
                        boolean allowChangeId) {
76
                // swingManager = ThematicMapSwingLocator.getSwingManager();
77
                swingManager = ThematicMapLocator.getManager();
78
                this.editor = defaultThematicMapCompilationEditor;
79
                this.compilation = defaultThematicMapCompilationEditor.getCompilation();
80
                this.allowChangeId = allowChangeId;
81
                initializeUI();
82
        }
83

    
84
        private void initializeUI() {
85
                this.setLayout(new GridBagLayout());
86

    
87
                gameDescriptionText = new JLabel("Descripcion del proceso o ejercicio");
88
                questionText = new JLabel(
89
                                "Escribe la pregunta a realizar en el ejercicio:");
90
                answersText = new JLabel("Selecciona las posibles respuestas");
91

    
92
                questionTextField = new JTextField("Clicka en la geometr�a correcta");
93
                questionTextField.setEditable(true);
94

    
95
                String[] itemsIDs = { "id1", "id2", "id3" };
96
                // List idList = new ArrayList<String>();
97
                answerIDComboBox = new JComboBox(itemsIDs);
98

    
99
                String[] answers = getSelectedItemAnswers();
100

    
101
                // mirar si ix un darrere de laltre
102
                answersTextArea = new JTextArea(answers.toString());
103
                answersListScrollPane = new JScrollPane(answersTextArea);
104

    
105
                // TODO add fields to container
106

    
107
        }
108

    
109
        private String[] getSelectedItemAnswers() {
110
                // TODO retornar columna asociada al item seleccionat
111

    
112
                String selectedItem = answerIDComboBox.getSelectedItem().toString();
113

    
114
                // String[] answers = manager.getColumnItems(selectedItem) +-
115

    
116
                String[] answers = { "resp1", "resp2", "resp3" };
117
                return answers;
118
        }
119

    
120
        /**
121
         * Add field to form
122
         * 
123
         * @param key
124
         *            translation key for field name
125
         * @param component
126
         *            file input component
127
         * @param large
128
         *            if field is large
129
         */
130
        // private void addField(String key, JComponent component, boolean large) {
131
        // GridBagConstraints gbc = LABEL_CONSTRAINT;
132
        // if (large) {
133
        // // gbc = LARGE_LABEL_CONSTRAINT;
134
        // }
135
        // add(new JLabel(swingManager.getTranslation(key)), gbc.clone());
136
        // gbc = FIELD_CONSTRAINT;
137
        // if (large) {
138
        // // gbc = LARGE_FIELD_CONSTRAINT;
139
        // }
140
        // add(component, gbc.clone());
141
        // }
142

    
143
        /** {@inheridDoc} */
144
        public String getPanelTitle() {
145
                return swingManager.getTranslation("thematic_map_information");
146
        }
147

    
148
        /** {@inheridDoc} */
149
        public void nextPanel() throws NotContinueWizardException {
150
                if (StringUtils.isBlank(questionTextField.getText())) {
151
                        throw new NotContinueWizardException(
152
                                        swingManager.getTranslation("missing_id_value"), txtId,
153
                                        true);
154
                }
155

    
156
                ThematicMapCompilationInformation info = compilation.getInformation();
157
                if (allowChangeId) {
158
                        info.setId(StringUtils.trim(txtId.getText()));
159
                }
160

    
161
                // TODO Set columnNameString y questionString a algun lloc (manager del
162
                // joc?)
163
        }
164

    
165
        /** {@inheridDoc} */
166
        public void lastPanel() {
167
                // TODO Auto-generated method stub
168

    
169
        }
170

    
171
        /** {@inheridDoc} */
172
        public void updatePanel() {
173
                ThematicMapCompilationInformation info = compilation.getInformation();
174
                // TODO: update els meus nous parametres
175
                txtId.setText(info.getId());
176
                txtName.setText(info.getName());
177
                txtVersion.setText(String.valueOf(info.getVersion()));
178
                txtDescription.setText(info.getDescription());
179
        }
180

    
181
        /** {@inheridDoc} */
182
        public JPanel getJPanel() {
183
                return this;
184
        }
185

    
186
        /**
187
         * Informs if all data of the panel is ok
188
         * 
189
         * @return
190
         */
191
        public boolean isPanelDataOk() {
192
                try {
193
                        nextPanel();
194
                } catch (NotContinueWizardException ex) {
195
                        return false;
196
                }
197
                return true;
198
        }
199

    
200
        public boolean isAllowChangeId() {
201
                return allowChangeId;
202
        }
203

    
204
        public void allowChangeId(boolean allow) {
205
                this.allowChangeId = allow;
206
                if (txtId != null) {
207
                        txtId.setEnabled(allow);
208
                }
209

    
210
        }
211

    
212
}