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

Diff of /trunk/src/skrueger/swing/TranslationAskJDialog.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 38 by alfonx, Sun Apr 5 15:06:56 2009 UTC revision 120 by alfonx, Sat May 16 21:25:44 2009 UTC
# Line 14  import java.util.Locale; Line 14  import java.util.Locale;
14  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
15  import javax.swing.Action;  import javax.swing.Action;
16  import javax.swing.Box;  import javax.swing.Box;
17    import javax.swing.JButton;
18  import javax.swing.JComponent;  import javax.swing.JComponent;
19  import javax.swing.JDialog;  import javax.swing.JDialog;
20  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
# Line 49  public class TranslationAskJDialog exten Line 50  public class TranslationAskJDialog exten
50    
51          private boolean hasBeenCanceled;          private boolean hasBeenCanceled;
52    
53            private JButton[] optionalButtons;
54    
55          /**          /**
56           * Since the registerKeyboardAction() method is part of the JComponent class           * Since the registerKeyboardAction() method is part of the JComponent class
57           * definition, you must define the Escape keystroke and register the           * definition, you must define the Escape keystroke and register the
# Line 82  public class TranslationAskJDialog exten Line 85  public class TranslationAskJDialog exten
85           * This class handles the cancel button itself. You may still want to listen           * This class handles the cancel button itself. You may still want to listen
86           * to PROPERTY_APPLY_AND_CLOSE events. This dialog is modal. The dialog has           * to PROPERTY_APPLY_AND_CLOSE events. This dialog is modal. The dialog has
87           * to be set visible afterwards.<br/>           * to be set visible afterwards.<br/>
88             *
89             * @param owner
90             *            A component of the GUI that this dialog is related to. If no
91             *            {@link Window} is passed, SwingUtil.getParentWindow(owner) is
92             *            called.
93           */           */
94          public TranslationAskJDialog(Window owner,          public TranslationAskJDialog(Component owner,
95                          final JComponent... translationEditJPanels) {                          final JComponent... translationEditJPanels) {
96                  super(owner);                  super(owner instanceof Window ? (Window) owner : SwingUtil
97                                    .getParentWindow(owner));
98                  setComponents(translationEditJPanels);                  setComponents(translationEditJPanels);
99          }          }
100    
# Line 101  public class TranslationAskJDialog exten Line 110  public class TranslationAskJDialog exten
110           * Using this constructor, you have to call setComponents afterwards.           * Using this constructor, you have to call setComponents afterwards.
111           */           */
112          public TranslationAskJDialog(Window owner) {          public TranslationAskJDialog(Window owner) {
113                  super(owner);                  this(owner, new JComponent[] {});
114          }          }
115    
116          /**          /**
# Line 158  public class TranslationAskJDialog exten Line 167  public class TranslationAskJDialog exten
167                  pack();                  pack();
168          }          }
169    
170            public void setButtons(JButton... optionalButtons) {
171                    this.optionalButtons = optionalButtons;
172                    init();
173            }
174    
175          protected void cancel() {          protected void cancel() {
176                  firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);                  firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);
177                  restore();                  restore();
# Line 177  public class TranslationAskJDialog exten Line 191  public class TranslationAskJDialog exten
191    
192          private JComponent getButtons() {          private JComponent getButtons() {
193                  JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));                  JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
194    
195                    if (optionalButtons != null)
196                            for (JButton b : optionalButtons) {
197                                    jPanel.add(b);
198                            }
199    
200                  if (okButton == null) {                  if (okButton == null) {
201                          okButton = new OkButton(new AbstractAction() {                          okButton = new OkButton(new AbstractAction() {
202                                  {                                  {
# Line 199  public class TranslationAskJDialog exten Line 219  public class TranslationAskJDialog exten
219                                  public void actionPerformed(ActionEvent evt) {                                  public void actionPerformed(ActionEvent evt) {
220                                          TranslationAskJDialog.this.firePropertyChange(                                          TranslationAskJDialog.this.firePropertyChange(
221                                                          PROPERTY_APPLY_AND_CLOSE, null, null);                                                          PROPERTY_APPLY_AND_CLOSE, null, null);
222                                            
223                                          if (!checkValidInputs()) return;                                          if (!checkValidInputs())
224                                                                                            return;
225    
226                                          setVisible(false);                                          setVisible(false);
227                                          dispose();                                          dispose();
228                                  }                                  }
# Line 229  public class TranslationAskJDialog exten Line 250  public class TranslationAskJDialog exten
250          }          }
251    
252          /**          /**
253           * @return <code>true</code> if none of the translations contains illegal characters.           * @return <code>true</code> if none of the translations contains illegal
254             *         characters.
255           */           */
256          protected boolean checkValidInputs() {          protected boolean checkValidInputs() {
257                    
258                  for (JComponent component : translationEditJPanelsOrJustComponents) {                  for (JComponent component : translationEditJPanelsOrJustComponents) {
259                          if (component instanceof TranslationEditJPanel) {                          if (component instanceof TranslationEditJPanel) {
260                                  TranslationEditJPanel tep = (TranslationEditJPanel) component;                                  TranslationEditJPanel tep = (TranslationEditJPanel) component;
261                                    
262                                  for (String l : tep.getTranslation().values()){                                  for (String l : tep.getTranslation().values()) {
263                                          if ( l.contains("{") || l.contains("}")) {                                          if (l.contains("{") || l.contains("}")) {
264                                                  JOptionPane.showMessageDialog(this, RESOURCE.getString("ErrorMsg.InvalidCharacterInTranslation"));                                                  JOptionPane
265                                                                    .showMessageDialog(
266                                                                                    this,
267                                                                                    RESOURCE
268                                                                                                    .getString("ErrorMsg.InvalidCharacterInTranslation"));
269                                                  return false;                                                  return false;
270                                          }                                          }
271                                  }                                  }
272                                    
273                          }                          }
274                  }                  }
275                    
                   
276                  return true;                  return true;
277          }          }
278    

Legend:
Removed from v.38  
changed lines
  Added in v.120

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26