2 |
|
|
3 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
import java.awt.Dimension; |
|
import java.awt.Frame; |
|
|
import java.awt.Window; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.WindowAdapter; |
|
|
import java.awt.event.WindowEvent; |
|
|
import java.awt.event.WindowListener; |
|
|
import java.util.ArrayList; |
|
5 |
import java.util.List; |
import java.util.List; |
6 |
|
|
|
import javax.swing.AbstractAction; |
|
7 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
|
import javax.swing.Box; |
|
|
import javax.swing.JComponent; |
|
8 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
9 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
10 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
14 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
15 |
|
|
16 |
import schmitzm.swing.SpringUtilities; |
import schmitzm.swing.SpringUtilities; |
|
import schmitzm.swing.SwingUtil; |
|
17 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
18 |
|
|
19 |
/** |
/** |
22 |
* |
* |
23 |
*/ |
*/ |
24 |
public class TranslationEditJPanel extends JPanel { |
public class TranslationEditJPanel extends JPanel { |
25 |
public static final String PROPERTY_CANCEL_AND_CLOSE = "CANCEL"; |
static final protected Logger LOGGER = Logger.getLogger(TranslationEditJPanel.class); |
|
public static final String PROPERTY_APPLY_AND_CLOSE = "APPLY"; |
|
|
private static JDialog dialog; |
|
|
private static OkButton okButton; |
|
26 |
|
|
27 |
private static CancelButton cancelButton; |
private final List<String> languages; |
|
Logger log = Logger.getLogger(TranslationEditJPanel.class); |
|
|
private List<String> languages; |
|
28 |
private JPanel translationGrid; |
private JPanel translationGrid; |
29 |
private Translation trans; |
private Translation trans; |
30 |
|
|
41 |
this.trans = trans; |
this.trans = trans; |
42 |
this.languages = languages_; |
this.languages = languages_; |
43 |
|
|
|
|
|
|
|
|
44 |
add(getTranslationGrid(), BorderLayout.CENTER); |
add(getTranslationGrid(), BorderLayout.CENTER); |
45 |
|
|
46 |
if (question != null) { |
if (question != null) { |
81 |
return translationGrid; |
return translationGrid; |
82 |
} |
} |
83 |
|
|
84 |
/** |
// /** |
85 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
86 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
87 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
88 |
* |
// * |
89 |
* @deprecated Use {@link TranslationAskJDialog} |
// * @deprecated Use {@link TranslationAskJDialog} |
90 |
*/ |
// */ |
91 |
public static void ask(Frame parentFrame, final TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(Frame parentFrame, final TranslationEditJPanel... translationEditJPanels) { |
92 |
dialog = new JDialog(parentFrame); |
// dialog = new JDialog(parentFrame); |
93 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
94 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
95 |
} |
// } |
96 |
|
// |
97 |
|
// |
98 |
/** |
// /** |
99 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
100 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
101 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
102 |
|
// |
103 |
* @deprecated User {@link TranslationAskJDialog} * |
// * @deprecated User {@link TranslationAskJDialog} * |
104 |
*/ |
// */ |
105 |
public static void ask(Window parentWindow, TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(Window parentWindow, TranslationEditJPanel... translationEditJPanels) { |
106 |
dialog = new JDialog(parentWindow); |
// dialog = new JDialog(parentWindow); |
107 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
108 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
109 |
} |
// } |
110 |
|
// |
111 |
/** |
// /** |
112 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
113 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
114 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
115 |
* |
// * |
116 |
* * @deprecated User {@link TranslationAskJDialog} |
// * * @deprecated User {@link TranslationAskJDialog} |
117 |
*/ |
// */ |
118 |
public static void ask(JDialog parentDialog, TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(JDialog parentDialog, TranslationEditJPanel... translationEditJPanels) { |
119 |
dialog = new JDialog(parentDialog); |
// dialog = new JDialog(parentDialog); |
120 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
121 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
122 |
} |
// } |
123 |
|
// |
124 |
|
// |
125 |
/** |
// /** |
126 |
* * @deprecated User {@link TranslationAskJDialog} |
// * * @deprecated User {@link TranslationAskJDialog} |
127 |
* @param d |
// * @param d |
128 |
* @param translationEditJPanels |
// * @param translationEditJPanels |
129 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
// * @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
130 |
*/ |
// */ |
131 |
public static void showDialog(JDialog d, JComponent... translationEditJPanels) { |
// public static void showDialog(JDialog d, JComponent... translationEditJPanels) { |
132 |
dialog = d; |
// dialog = d; |
133 |
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
// dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
134 |
SwingUtil.centerFrameOnScreen(dialog); |
// SwingUtil.centerFrameOnScreen(dialog); |
135 |
Box box = Box.createVerticalBox(); |
// Box box = Box.createVerticalBox(); |
136 |
for (JComponent panel : translationEditJPanels) { |
// for (JComponent panel : translationEditJPanels) { |
137 |
box.add(panel); |
// box.add(panel); |
138 |
} |
// } |
139 |
JPanel cp = new JPanel( new BorderLayout()); |
// JPanel cp = new JPanel( new BorderLayout()); |
140 |
cp.add( box, BorderLayout.CENTER); |
// cp.add( box, BorderLayout.CENTER); |
141 |
cp.add( getButtons(), BorderLayout.SOUTH ); |
// cp.add( getButtons(), BorderLayout.SOUTH ); |
142 |
dialog.setContentPane(cp); |
// dialog.setContentPane(cp); |
143 |
|
// |
144 |
// dialog.getRootPane().setDefaultButton(okButton); |
// // dialog.getRootPane().setDefaultButton(okButton); |
145 |
|
// |
146 |
dialog.setTitle("Please translate"); //i8n |
// dialog.setTitle("Please translate"); //i8n |
147 |
dialog.setModal(true); |
// dialog.setModal(true); |
148 |
dialog.pack(); |
// dialog.pack(); |
149 |
dialog.setVisible(true); |
// dialog.setVisible(true); |
150 |
} |
// } |
151 |
|
// |
152 |
/** |
// /** |
153 |
* @deprecated Use TranslationAskJDialog |
// * @deprecated Use TranslationAskJDialog |
154 |
* @return |
// * @return |
155 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
// * @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
156 |
*/ |
// */ |
157 |
private static JComponent getButtons() { |
// private static JComponent getButtons() { |
158 |
JPanel jPanel = new JPanel(); |
// JPanel jPanel = new JPanel(); |
159 |
if (okButton == null) { |
// if (okButton == null) { |
160 |
okButton = new OkButton(new AbstractAction("enter") { |
// okButton = new OkButton(new AbstractAction("enter") { |
161 |
public void actionPerformed(ActionEvent evt) { |
// public void actionPerformed(ActionEvent evt) { |
162 |
firePropertyChange(PROPERTY_APPLY_AND_CLOSE, null, null); |
// firePropertyChange(PROPERTY_APPLY_AND_CLOSE, null, null); |
163 |
dialog.dispose(); |
// dialog.dispose(); |
164 |
} |
// } |
165 |
} ); |
// } ); |
166 |
} |
// } |
167 |
jPanel.add(okButton); |
// jPanel.add(okButton); |
168 |
|
// |
169 |
if (cancelButton == null) { |
// if (cancelButton == null) { |
170 |
cancelButton = new CancelButton(new AbstractAction("") { |
// cancelButton = new CancelButton(new AbstractAction("") { |
171 |
public void actionPerformed(ActionEvent evt) { |
// public void actionPerformed(ActionEvent evt) { |
172 |
// restore(); |
// // restore(); |
173 |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
// firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
174 |
dialog.dispose(); |
// dialog.dispose(); |
175 |
} |
// } |
176 |
} ); |
// } ); |
177 |
} |
// } |
178 |
jPanel.add(okButton); |
// jPanel.add(okButton); |
179 |
|
// |
180 |
return jPanel; |
// return jPanel; |
181 |
} |
// } |
182 |
|
|
183 |
/** |
/** |
184 |
* @return The {@link Translation} that this {@link TranslationEditJPanel} deals with. |
* @return The {@link Translation} that this {@link TranslationEditJPanel} deals with. |
186 |
public Translation getTranslation() { |
public Translation getTranslation() { |
187 |
return trans; |
return trans; |
188 |
} |
} |
189 |
// |
|
|
// |
|
|
// public static void main(String[] args) { |
|
|
// ArrayList<String> lang = new ArrayList <String> (); |
|
|
// lang.add("de"); |
|
|
// lang.add("en"); |
|
|
// lang.add("fr"); |
|
|
// |
|
|
// Translation transe = new Translation(); |
|
|
// transe.put("de", "Terciopelo-Lanzenotter"); |
|
|
// TranslationEditJPanel p1 = new TranslationEditJPanel("Name von New Group", |
|
|
// transe, lang); |
|
|
// |
|
|
// |
|
|
// Translation transe2 = new Translation(); |
|
|
// transe2.put("de", "Terciopelo-Lanzenotter (Bothrops asper) ist eine in Mittelamerika und im Nordwesten Südamerikas weit verbreitete Schlangenart."); |
|
|
// TranslationEditJPanel p2 = new TranslationEditJPanel("Description of Animal:", |
|
|
// transe2, lang); |
|
|
// |
|
|
//// JFrame frame = new JFrame(); |
|
|
//// frame.setContentPane(p1); |
|
|
//// frame.pack(); |
|
|
//// frame.setVisible(true); |
|
|
// |
|
|
// ask(new Frame(),p1,p2); |
|
|
// } |
|
190 |
} |
} |