/[schmitzm]/trunk/src/skrueger/swing/TranslationEditJPanel.java
ViewVC logotype

Contents of /trunk/src/skrueger/swing/TranslationEditJPanel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 289 - (show annotations)
Mon Aug 3 22:29:36 2009 UTC (15 years, 6 months ago) by mojays
File size: 5523 byte(s)
Chart-Selection highlighting for CategoryDatasets.
DatasetSelectionModel and Feature2DatasetMapping parameterized with 3 data types (Dataset, SeriesKey type, ItemKey type).
Imports organized.
1 /*******************************************************************************
2 * Copyright (c) 2009 Martin O. J. Schmitz.
3 *
4 * This file is part of the SCHMITZM library - a collection of utility
5 * classes based on Java 1.6, focusing (not only) on Java Swing
6 * and the Geotools library.
7 *
8 * The SCHMITZM project is hosted at:
9 * http://wald.intevation.org/projects/schmitzm/
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License (license.txt)
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * or try this link: http://www.gnu.org/licenses/lgpl.html
25 *
26 * Contributors:
27 * Martin O. J. Schmitz - initial API and implementation
28 * Stefan A. Krüger - additional utility classes
29 ******************************************************************************/
30 package skrueger.swing;
31
32 import java.awt.BorderLayout;
33 import java.awt.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.KeyEvent;
37 import java.awt.event.KeyListener;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Set;
41
42 import javax.swing.BorderFactory;
43 import javax.swing.JLabel;
44 import javax.swing.JTextField;
45 import javax.swing.SpringLayout;
46 import javax.swing.SwingConstants;
47
48 import org.apache.log4j.Logger;
49
50 import schmitzm.swing.JPanel;
51 import schmitzm.swing.SpringUtilities;
52 import skrueger.i8n.Translation;
53
54 /**
55 * A {@link JPanel} that asks the user for the translations of a String in
56 * several languages. Use {@link TranslationAskJDialog} to display.<br/>
57 * The class does not implement any backup/clong strategies. The
58 * {@link Translation} object is manipulated directly.<br/>
59 * {@link TranslationEditJPanel}s. {@link TranslationAskJDialog} implements a
60 * transparent Apply/Cancel logic.
61 *
62 * @author Stefan Alfons Krüger
63 */
64 public class TranslationEditJPanel extends JPanel {
65 static final protected Logger LOGGER = Logger
66 .getLogger(TranslationEditJPanel.class);
67
68 private final List<String> languages;
69 private JPanel translationGrid;
70 private Translation trans;
71
72 /**
73 * Remembers all {@link JTextField} that have been created.
74 */
75 private Set<JTextField> langTextFields = new HashSet<JTextField>();
76
77 /**
78 * Creates a {@link JPanel} that asks the user for the translation of a
79 * String in several languages
80 */
81 public TranslationEditJPanel(Translation trans, List<String> languages_) {
82 this(null, trans, languages_);
83 }
84
85 /**
86 * Creates a {@link JPanel} that asks the user for the translation of a
87 * String in several languages and additionally puts a {@link JLabel} with a
88 * question at the {@link JPanel}'s first row.
89 */
90 public TranslationEditJPanel(String question, Translation trans,
91 List<String> languages_) {
92 super(new BorderLayout());
93
94 if (trans == null)
95 trans = new Translation();
96
97 this.trans = trans;
98 this.languages = languages_;
99
100 add(getTranslationGrid(), BorderLayout.CENTER);
101
102 if (question != null) {
103 JLabel questionLable = new JLabel(question);
104 questionLable
105 .setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
106 add(questionLable, BorderLayout.NORTH);
107 }
108 }
109
110 private JPanel getTranslationGrid() {
111 if (translationGrid == null) {
112 translationGrid = new JPanel(new SpringLayout());
113
114 for (String langId : languages) {
115
116 // language code : entry field for translation
117 JLabel langDesc = new JLabel(langId.toUpperCase() + " :"); // i8n
118 langDesc.setHorizontalAlignment(SwingConstants.RIGHT);
119 langDesc.setVerticalAlignment(SwingConstants.NORTH);
120
121 TranslationJTextField langTextField = new TranslationJTextField(
122 trans, langId);
123 // Setting a size
124 langTextField.setPreferredSize(new Dimension(360, 22));
125 langDesc.setLabelFor(langTextField);
126 translationGrid.add(langDesc);
127 translationGrid.add(langTextField);
128
129 langTextFields .add(langTextField);
130 }
131
132 // Lay out the panel.
133 SpringUtilities.makeCompactGrid(translationGrid, languages.size(), // rows,
134 2, // cols
135 6, 6, // initX, initY
136 6, 6); // xPad, yPad
137
138 }
139 return translationGrid;
140 }
141
142 /**
143 * @return The {@link Translation} that this {@link TranslationEditJPanel}
144 * deals with.
145 */
146 public Translation getTranslation() {
147 return trans;
148 }
149
150 public void addActionListener(final ActionListener actionListener) {
151 for (final JTextField langTextField : langTextFields){
152 langTextField.addKeyListener( new KeyListener(){
153
154 @Override
155 public void keyPressed(KeyEvent e) {
156 }
157
158 @Override
159 public void keyReleased(KeyEvent e) {
160 }
161
162 @Override
163 public void keyTyped(KeyEvent e) {
164 actionListener.actionPerformed(new ActionEvent(TranslationEditJPanel.this, 0, ""));
165 }
166
167 });
168 }
169 }
170
171 public void removeActionListener(ActionListener actionListener) {
172 for (JTextField langTextField : langTextFields){
173 langTextField.removeActionListener(actionListener);
174 }
175 }
176
177 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26