2 * bnac : virtual museum environment creation/manipulation project
3 * Copyright (C) 2010 Felipe CaƱas Sabat
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package cl
.uchile
.dcc
.bnac
.editor
;
21 import cl
.uchile
.dcc
.bnac
.CObject
;
22 import cl
.uchile
.dcc
.bnac
.Capture
;
23 import cl
.uchile
.dcc
.bnac
.MuseumEnvironment
;
24 import cl
.uchile
.dcc
.bnac
.Route
;
26 import java
.awt
.BorderLayout
;
27 import java
.awt
.FlowLayout
;
28 import java
.awt
.GridBagConstraints
;
29 import java
.awt
.GridBagLayout
;
30 import java
.awt
.event
.ActionEvent
;
31 import java
.awt
.event
.ActionListener
;
32 import java
.awt
.event
.ItemEvent
;
33 import java
.awt
.event
.ItemListener
;
34 import javax
.swing
.BorderFactory
;
35 import javax
.swing
.DefaultComboBoxModel
;
36 import javax
.swing
.JButton
;
37 import javax
.swing
.JComboBox
;
38 import javax
.swing
.JLabel
;
39 import javax
.swing
.JPanel
;
40 import javax
.swing
.JTextField
;
41 import javax
.swing
.SwingUtilities
;
43 public class TranslateTool
extends JPanel
44 implements ActionListener
, ItemListener
46 protected Project project
;
48 protected JPanel pnMain
;
49 protected JComboBox cbType
;
50 protected JButton bnClose
;
52 public TranslateTool (Project project
)
54 super(new BorderLayout());
55 this.project
= project
;
57 pnMain
= new JPanel();
58 cbType
= new JComboBox();
59 bnClose
= new JButton(BnacEditor
.gs("CLOSE"));
63 cbType
.setModel(new DefaultComboBoxModel(Type
.values()));
65 pnMain
.add(new CaptureTranslateBox());
67 cbType
.addItemListener(this);
68 bnClose
.addActionListener(this);
71 protected void buildUi ()
73 setBorder(BorderFactory
.createEmptyBorder(5, 5, 5, 5));
74 pnMain
.setBorder(BorderFactory
.createEtchedBorder());
76 JPanel caca
= new JPanel(new FlowLayout(FlowLayout
.LEADING
, 2, 2));
77 caca
.add(new JLabel(String
.format("%s:",
78 BnacEditor
.gs("TYPE_TO_TRANSLATE"))));
80 add(caca
, BorderLayout
.NORTH
);
81 add(pnMain
, BorderLayout
.CENTER
);
82 add(bnClose
, BorderLayout
.SOUTH
);
85 public void actionPerformed (ActionEvent e
)
87 if (e
.getSource() == bnClose
) {
88 SwingUtilities
.getWindowAncestor(this).setVisible(false);
92 public void itemStateChanged (ItemEvent e
)
94 if (e
.getStateChange() == ItemEvent
.SELECTED
) {
96 Type t
= (Type
) e
.getItem();
99 pnMain
.add(new CaptureTranslateBox());
102 pnMain
.add(new RouteTranslateBox());
105 SwingUtilities
.getWindowAncestor(this).pack();
109 class CaptureTranslateBox
extends JPanel
110 implements ActionListener
, ItemListener
112 protected Language lang
;
114 protected JComboBox cbCaps
;
115 protected JComboBox cbLangs
;
116 protected JTextField tfAuthor
;
117 protected JTextField tfTitle
;
118 protected JTextField tfType
;
119 protected JButton bnSave
;
120 protected JButton bnOrig
;
122 public CaptureTranslateBox ()
124 super(new GridBagLayout());
126 lang
= Language
.values()[0];
128 cbCaps
= new JComboBox();
129 cbLangs
= new JComboBox();
130 tfAuthor
= new JTextField();
131 tfTitle
= new JTextField();
132 tfType
= new JTextField();
133 bnSave
= new JButton(BnacEditor
.gs("SAVE"));
134 bnOrig
= new JButton(BnacEditor
.gs("ORIGINAL_VALUES"));
139 new String
[project
.getMuseumEnvironment().captureNo()];
141 for (Capture ca
: project
.getMuseumEnvironment().captureArray()) {
142 caps
[i
++] = String
.format("%s - %s",
143 ca
.getReferencedObject().get("Author"),
144 ca
.getReferencedObject().get("Title"));
146 cbCaps
.setModel(new DefaultComboBoxModel(caps
));
148 cbLangs
.setModel(new DefaultComboBoxModel(Language
.values()));
150 cbCaps
.addItemListener(this);
151 cbLangs
.addItemListener(this);
152 bnOrig
.addActionListener(this);
153 bnSave
.addActionListener(this);
158 protected void buildUi ()
162 pnMain
.setLayout(new GridBagLayout());
163 GridBagConstraints c
= new GridBagConstraints();
167 c
.fill
= GridBagConstraints
.HORIZONTAL
;
173 c
.gridx
= GridBagConstraints
.RELATIVE
;
176 c
.anchor
= GridBagConstraints
.WEST
;
180 add(new JLabel(BnacEditor
.gs("AUTHOR")), c
);
181 c
.gridy
= GridBagConstraints
.RELATIVE
;
182 add(new JLabel(BnacEditor
.gs("TITLE")), c
);
183 add(new JLabel(BnacEditor
.gs("TYPE")), c
);
189 c
.gridy
= GridBagConstraints
.RELATIVE
;
203 setBorder(BorderFactory
.createEmptyBorder(3, 3, 3, 3));
206 public void actionPerformed (ActionEvent e
)
208 Capture c
= project
.getMuseumEnvironment().
209 captureArray()[cbCaps
.getSelectedIndex()];
210 CObject obj
= c
.getReferencedObject();
211 if (e
.getSource() == bnOrig
) {
212 tfAuthor
.setText(obj
.get("Author"));
213 tfTitle
.setText(obj
.get("Title"));
214 tfType
.setText(obj
.get("Type"));
216 } else if (e
.getSource() == bnSave
) {
217 project
.getMuseumEnvironment().addString(
218 obj
.getId(), lang
.getCode(),
219 "Author", tfAuthor
.getText());
220 project
.getMuseumEnvironment().addString(
221 obj
.getId(), lang
.getCode(),
222 "Title", tfTitle
.getText());
223 project
.getMuseumEnvironment().addString(
224 obj
.getId(), lang
.getCode(),
225 "Type", tfType
.getText());
229 public void itemStateChanged (ItemEvent e
)
231 if (e
.getStateChange() == ItemEvent
.SELECTED
) {
232 if (e
.getSource() == cbCaps
) {
234 } else if (e
.getSource() == cbLangs
) {
235 lang
= (Language
) e
.getItem();
241 public void fillCaptureInfo ()
243 Capture c
= project
.getMuseumEnvironment().
244 captureArray()[cbCaps
.getSelectedIndex()];
245 CObject obj
= c
.getReferencedObject();
246 String id
= obj
.getId();
247 String l
= lang
.getCode();
248 MuseumEnvironment me
= project
.getMuseumEnvironment();
249 if (me
.getString(id
, l
, "Author") != null) {
250 tfAuthor
.setText(me
.getString(id
, l
, "Author"));
252 tfAuthor
.setText("");
254 if (me
.getString(id
, l
, "Title") != null) {
255 tfTitle
.setText(me
.getString(id
, l
, "Title"));
259 if (me
.getString(id
, l
, "Type") != null) {
260 tfType
.setText(me
.getString(id
, l
, "Type"));
267 class RouteTranslateBox
extends JPanel
268 implements ActionListener
, ItemListener
270 protected Language lang
;
271 protected JComboBox cbRoutes
;
272 protected JComboBox cbLangs
;
273 protected JTextField tfName
;
274 protected JButton bnSave
;
276 public RouteTranslateBox ()
278 super(new GridBagLayout());
280 lang
= Language
.values()[0];
281 cbLangs
= new JComboBox();
282 cbRoutes
= new JComboBox();
283 tfName
= new JTextField(20);
284 bnSave
= new JButton(BnacEditor
.gs("SAVE"));
289 String
[project
.getMuseumEnvironment().routeArray().length
];
291 for (Route r
: project
.getMuseumEnvironment().routeArray()) {
292 rts
[i
++] = r
.getId();
294 cbRoutes
.setModel(new DefaultComboBoxModel(rts
));
295 cbLangs
.setModel(new DefaultComboBoxModel(Language
.values()));
297 cbRoutes
.addItemListener(this);
298 cbLangs
.addItemListener(this);
299 bnSave
.addActionListener(this);
304 protected void buildUi ()
306 GridBagConstraints c
= new GridBagConstraints();
310 c
.fill
= GridBagConstraints
.HORIZONTAL
;
325 add(new JLabel(BnacEditor
.gs("NAME")), c
);
335 setBorder(BorderFactory
.createEmptyBorder(3, 3, 3, 3));
338 public void actionPerformed (ActionEvent e
)
340 Route route
= project
.getMuseumEnvironment().routeArray()[
341 cbRoutes
.getSelectedIndex()];
342 if (e
.getSource() == bnSave
) {
343 project
.getMuseumEnvironment().addString(
344 route
.getId(), lang
.getCode(),
345 "Name", tfName
.getText());
349 public void itemStateChanged (ItemEvent e
)
351 if (e
.getStateChange() == ItemEvent
.SELECTED
) {
352 if (e
.getSource() == cbRoutes
) {
354 } else if (e
.getSource() == cbLangs
) {
355 lang
= (Language
) e
.getItem();
361 public void fillRouteInfo ()
363 Route route
= project
.getMuseumEnvironment().routeArray()[
364 cbRoutes
.getSelectedIndex()];
365 String s
= project
.getMuseumEnvironment().getString(
366 route
.getId(), lang
.getCode(), "Name");