/[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 206 by alfonx, Thu Jul 9 16:45:26 2009 UTC
# Line 13  import java.util.Locale; Line 13  import java.util.Locale;
13    
14  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
15  import javax.swing.Action;  import javax.swing.Action;
16    import javax.swing.BorderFactory;
17  import javax.swing.Box;  import javax.swing.Box;
18    import javax.swing.JButton;
19  import javax.swing.JComponent;  import javax.swing.JComponent;
20  import javax.swing.JDialog;  import javax.swing.JDialog;
21  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
# Line 21  import javax.swing.JPanel; Line 23  import javax.swing.JPanel;
23  import javax.swing.JRootPane;  import javax.swing.JRootPane;
24  import javax.swing.KeyStroke;  import javax.swing.KeyStroke;
25    
26    import schmitzm.geotools.styling.StylingUtil;
27  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
28  import schmitzm.lang.ResourceProvider;  import schmitzm.lang.ResourceProvider;
29  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
# Line 28  import skrueger.i8n.Translation; Line 31  import skrueger.i8n.Translation;
31    
32  public class TranslationAskJDialog extends JDialog {  public class TranslationAskJDialog extends JDialog {
33    
         /**  
          * {@link ResourceProvider}, der die Lokalisation fuer GUI-Komponenten des  
          * Package {@code skrueger.swing} zur Verfuegung stellt. Diese sind in  
          * properties-Datein unter {@code skrueger.swing.resource.locales}  
          * hinterlegt.  
          */  
         public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil  
                         .extendPackagePath(TranslationAskJDialog.class,  
                                         "resource.locales.SwingResourceBundle"), Locale.ENGLISH);  
   
34          private String[] backup = new String[50]; // Maximum 50 languages ;-)          private String[] backup = new String[50]; // Maximum 50 languages ;-)
35          private OkButton okButton;          private OkButton okButton;
36          private CancelButton cancelButton;          private CancelButton cancelButton;
# Line 49  public class TranslationAskJDialog exten Line 42  public class TranslationAskJDialog exten
42    
43          private boolean hasBeenCanceled;          private boolean hasBeenCanceled;
44    
45            private JButton[] optionalButtons;
46    
47          /**          /**
48           * Since the registerKeyboardAction() method is part of the JComponent class           * Since the registerKeyboardAction() method is part of the JComponent class
49           * 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 77  public class TranslationAskJDialog exten
77           * 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
78           * 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
79           * to be set visible afterwards.<br/>           * to be set visible afterwards.<br/>
80             *
81             * @param owner
82             *            A component of the GUI that this dialog is related to. If no
83             *            {@link Window} is passed, SwingUtil.getParentWindow(owner) is
84             *            called.
85           */           */
86          public TranslationAskJDialog(Window owner,          public TranslationAskJDialog(Component owner,
87                          final JComponent... translationEditJPanels) {                          final JComponent... translationEditJPanels) {
88                  super(owner);                  super(SwingUtil.getParentWindow(owner));
89                  setComponents(translationEditJPanels);                  setComponents(translationEditJPanels);
90          }          }
91    
# Line 100  public class TranslationAskJDialog exten Line 100  public class TranslationAskJDialog exten
100           * to be set visible afterwards.<br/>           * to be set visible afterwards.<br/>
101           * Using this constructor, you have to call setComponents afterwards.           * Using this constructor, you have to call setComponents afterwards.
102           */           */
103          public TranslationAskJDialog(Window owner) {          public TranslationAskJDialog(Component owner) {
104                  super(owner);                  this(owner, new JComponent[] {});
105          }          }
106    
107          /**          /**
# Line 146  public class TranslationAskJDialog exten Line 146  public class TranslationAskJDialog exten
146                  SwingUtil.centerFrameOnScreen(this);                  SwingUtil.centerFrameOnScreen(this);
147                  Box box = Box.createVerticalBox();                  Box box = Box.createVerticalBox();
148                  for (JComponent panel : translationEditJPanelsOrJustComponents) {                  for (JComponent panel : translationEditJPanelsOrJustComponents) {
149                            panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
150                            panel.setBorder( BorderFactory.createEmptyBorder(5, 6, 5, 6));
151                          box.add(panel);                          box.add(panel);
152                            
153                  }                  }
154                  JPanel cp = new JPanel(new BorderLayout());                  JPanel cp = new JPanel(new BorderLayout());
155                  cp.add(box, BorderLayout.CENTER);                  cp.add(box, BorderLayout.WEST);
156                  cp.add(getButtons(), BorderLayout.SOUTH);                  cp.add(getButtons(), BorderLayout.SOUTH);
157                  setContentPane(cp);                  setContentPane(cp);
158                    
159                  setTitle(RESOURCE.getString("translation_dialog_title")); // i8n                  setTitle(SwingUtil.R("TranslationAskJDialog.Title"));
160                  setModal(true);                  setModal(true);
161                  pack();                  pack();
162          }          }
163    
164            public void setButtons(JButton... optionalButtons) {
165                    this.optionalButtons = optionalButtons;
166                    init();
167            }
168    
169          protected void cancel() {          protected void cancel() {
170                  firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);                  firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);
171                  restore();                  restore();
# Line 177  public class TranslationAskJDialog exten Line 185  public class TranslationAskJDialog exten
185    
186          private JComponent getButtons() {          private JComponent getButtons() {
187                  JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));                  JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
188    
189                    if (optionalButtons != null)
190                            for (JButton b : optionalButtons) {
191                                    jPanel.add(b);
192                            }
193    
194                  if (okButton == null) {                  if (okButton == null) {
195                          okButton = new OkButton(new AbstractAction() {                          okButton = new OkButton(new AbstractAction() {
196                                  {                                  {
# Line 199  public class TranslationAskJDialog exten Line 213  public class TranslationAskJDialog exten
213                                  public void actionPerformed(ActionEvent evt) {                                  public void actionPerformed(ActionEvent evt) {
214                                          TranslationAskJDialog.this.firePropertyChange(                                          TranslationAskJDialog.this.firePropertyChange(
215                                                          PROPERTY_APPLY_AND_CLOSE, null, null);                                                          PROPERTY_APPLY_AND_CLOSE, null, null);
216                                            
217                                          if (!checkValidInputs()) return;                                          if (!checkValidInputs())
218                                                                                            return;
219    
220                                          setVisible(false);                                          setVisible(false);
221                                          dispose();                                          dispose();
222                                  }                                  }
# Line 229  public class TranslationAskJDialog exten Line 244  public class TranslationAskJDialog exten
244          }          }
245    
246          /**          /**
247           * @return <code>true</code> if none of the translations contains illegal characters.           * @return <code>true</code> if none of the translations contains illegal
248             *         characters.
249           */           */
250          protected boolean checkValidInputs() {          protected boolean checkValidInputs() {
251                    
252                  for (JComponent component : translationEditJPanelsOrJustComponents) {                  for (JComponent component : translationEditJPanelsOrJustComponents) {
253                          if (component instanceof TranslationEditJPanel) {                          if (component instanceof TranslationEditJPanel) {
254                                  TranslationEditJPanel tep = (TranslationEditJPanel) component;                                  TranslationEditJPanel tep = (TranslationEditJPanel) component;
255                                    
256                                  for (String l : tep.getTranslation().values()){                                  for (String l : tep.getTranslation().values()) {
257                                          if ( l.contains("{") || l.contains("}")) {                                          if (l.contains("{") || l.contains("}")) {
258                                                  JOptionPane.showMessageDialog(this, RESOURCE.getString("ErrorMsg.InvalidCharacterInTranslation"));                                                  JOptionPane
259                                                                    .showMessageDialog(
260                                                                                    this,
261                                                                                    SwingUtil.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation"));
262                                                  return false;                                                  return false;
263                                          }                                          }
264                                  }                                  }
265                                    
266                          }                          }
267                  }                  }
268                    
                   
269                  return true;                  return true;
270          }          }
271    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26