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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 621 - (show annotations)
Thu Jan 28 10:06:05 2010 UTC (15 years, 1 month ago) by alfonx
Original Path: branches/2.0-RC2/src/skrueger/swing/TranslationsAskJPanel.java
File MIME type: text/plain
File size: 2901 byte(s)
2.0-RC2 ist für die weiterentwicklung und soll bald in den trunk mergen
1 package skrueger.swing;
2
3 import javax.swing.BorderFactory;
4 import javax.swing.JComponent;
5 import javax.swing.JOptionPane;
6
7 import net.miginfocom.swing.MigLayout;
8 import schmitzm.swing.JPanel;
9 import schmitzm.swing.SwingUtil;
10 import skrueger.i8n.Translation;
11
12 public class TranslationsAskJPanel extends JPanel implements Cancellable, Checkable {
13
14 private String[] backup = new String[50]; // Maximum 50 languages
15 private final JComponent[] translationEditJPanelsOrJustComponents;
16
17 public TranslationsAskJPanel(
18 JComponent... translationEditJPanelsOrJustComponents_) {
19 super(new MigLayout("wrap 1, width 100%", "[]"));
20
21 this.translationEditJPanelsOrJustComponents = translationEditJPanelsOrJustComponents_;
22
23 backup();
24
25 // Box box = Box.createVerticalBox();
26 // for (JComponent panel : translationEditJPanelsOrJustComponents) {
27 // panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
28 // panel.setBorder(BorderFactory.createEmptyBorder(5, 6, 5, 6));
29 // box.add(panel);
30 //
31 // }
32 // add(box);
33
34 for (JComponent panel : translationEditJPanelsOrJustComponents) {
35 panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
36 panel.setBorder(BorderFactory.createEmptyBorder(5, 6, 5, 6));
37 add(panel);
38 }
39
40 }
41
42 /**
43 * Stores the original values of all {@link TranslationEditJPanel}s so
44 * cancel works.
45 */
46 protected void backup() {
47 // Remember backups for all the TranslationEditJPanel
48 int count = 0;
49 for (JComponent component : translationEditJPanelsOrJustComponents) {
50 if (component instanceof TranslationEditJPanel) {
51 TranslationEditJPanel tep = (TranslationEditJPanel) component;
52 Translation orig = tep.getTranslation();
53
54 // We don't want to overwrite the Translation object on
55 // restore(). We just want to change its value.
56 backup[count++] = orig.toOneLine();
57 }
58 }
59 }
60
61 /**
62 * Used to restore all the values when cancel has been pressed.
63 */
64 @Override
65 public void cancel() {
66 int count = 0;
67 for (JComponent component : translationEditJPanelsOrJustComponents) {
68 if (component instanceof TranslationEditJPanel) {
69 TranslationEditJPanel tep = (TranslationEditJPanel) component;
70 tep.getTranslation().fromOneLine(backup[count++]);
71 }
72 }
73 }
74
75
76 /**
77 * @return <code>true</code> if none of the translations contains illegal
78 * characters.
79 */
80 public boolean checkValidInputs() {
81
82 for (JComponent component : translationEditJPanelsOrJustComponents) {
83 if (component instanceof TranslationEditJPanel) {
84 TranslationEditJPanel tep = (TranslationEditJPanel) component;
85
86 final Translation translationToCheck = tep.getTranslation();
87
88 if (!Translation.checkValid(translationToCheck)) {
89 JOptionPane
90 .showMessageDialog(
91 this,
92 SwingUtil
93 .R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation"));
94 return false;
95 }
96
97 }
98 }
99
100 return true;
101 }
102 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26