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

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

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

revision 127 by mojays, Sat May 30 14:29:58 2009 UTC revision 256 by alfonx, Fri Jul 31 14:43:47 2009 UTC
# Line 1  Line 1 
1  package skrueger.swing;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.awt.BorderLayout;   *
4  import java.awt.Dimension;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.util.List;   * classes based on Java 1.6, focusing (not only) on Java Swing
6     * and the Geotools library.
7  import javax.swing.BorderFactory;   *
8  import javax.swing.JLabel;   * The SCHMITZM project is hosted at:
9  import javax.swing.JPanel;   * http://wald.intevation.org/projects/schmitzm/
10  import javax.swing.SpringLayout;   *
11  import javax.swing.SwingConstants;   * 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  import org.apache.log4j.Logger;   * as published by the Free Software Foundation; either version 3
14     * of the License, or (at your option) any later version.
15  import schmitzm.swing.SpringUtilities;   *
16  import skrueger.i8n.Translation;   * 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   * A {@link JPanel} that asks the user for translation of several strings   * GNU General Public License for more details.
20   * @author Stefan Alfons Krüger   *
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  public class TranslationEditJPanel extends JPanel {   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24          static final protected Logger LOGGER = Logger.getLogger(TranslationEditJPanel.class);   * or try this link: http://www.gnu.org/licenses/lgpl.html
25             *
26          private final List<String> languages;   * Contributors:
27          private JPanel translationGrid;   *     Martin O. J. Schmitz - initial API and implementation
28          private Translation trans;   *     Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30          public TranslationEditJPanel(Translation trans, List<String> languages_) {  package skrueger.swing;
31                  this(null, trans, languages_);  
32          }  import java.awt.BorderLayout;
33    import java.awt.Container;
34          public TranslationEditJPanel(String question, Translation trans,  import java.awt.Dimension;
35                          List<String> languages_) {  import java.awt.event.ActionEvent;
36                  super(new BorderLayout());  import java.awt.event.ActionListener;
37                    import java.awt.event.KeyEvent;
38                  if (trans == null) trans = new Translation();  import java.awt.event.KeyListener;
39    import java.beans.PropertyChangeListener;
40                  this.trans = trans;  import java.util.HashSet;
41                  this.languages = languages_;  import java.util.List;
42                    import java.util.Set;
43                  add(getTranslationGrid(), BorderLayout.CENTER);  
44    import javax.swing.BorderFactory;
45                  if (question != null) {  import javax.swing.JLabel;
46                          JLabel questionLable = new JLabel(question);  import javax.swing.JPanel;
47                          questionLable.setBorder(BorderFactory.createEmptyBorder(  import javax.swing.JTextField;
48                                          6, 6, 6, 6));  import javax.swing.SpringLayout;
49                          add(questionLable, BorderLayout.NORTH);  import javax.swing.SwingConstants;
50                  }  
51          }  import org.apache.log4j.Logger;
52    
53          private JPanel getTranslationGrid() {  import schmitzm.swing.SpringUtilities;
54                  if (translationGrid == null) {  import skrueger.i8n.Translation;
55                          translationGrid = new JPanel(new SpringLayout());  
56    /**
57                          for (String langId : languages) {   * A {@link JPanel} that asks the user for the translations of a String in
58     * several languages. Use {@link TranslationAskJDialog} to display.<br/>
59                                  // language code : entry field for translation   * The class does not implement any backup/clong strategies. The
60                                  JLabel langDesc = new JLabel(langId.toUpperCase() + " :"); // i8n   * {@link Translation} object is manipulated directly.<br/>
61                                  langDesc.setHorizontalAlignment(SwingConstants.RIGHT);   * {@link TranslationEditJPanel}s. {@link TranslationAskJDialog} implements a
62                                  langDesc.setVerticalAlignment(SwingConstants.NORTH);   * transparent Apply/Cancel logic.
63     *
64                                  TranslationJTextField langTextField = new TranslationJTextField(   * @author Stefan Alfons Krüger
65                                                  trans, langId);   */
66                                  // Setting a size  public class TranslationEditJPanel extends JPanel  {
67                                  langTextField.setPreferredSize( new Dimension(360,22));          static final protected Logger LOGGER = Logger
68                                  langDesc.setLabelFor(langTextField);                          .getLogger(TranslationEditJPanel.class);
69                                  translationGrid.add(langDesc);  
70                                  translationGrid.add(langTextField);          private final List<String> languages;
71                          }          private JPanel translationGrid;
72            private Translation trans;
73                          // Lay out the panel.  
74                          SpringUtilities.makeCompactGrid(translationGrid, languages.size(), // rows,          /**
75                                          2, // cols           * Remembers all {@link JTextField} that have been created.
76                                          6, 6, // initX, initY           */
77                                          6, 6); // xPad, yPad          private Set<JTextField> langTextFields = new HashSet<JTextField>();
78    
79                  }          /**
80                  return translationGrid;           * Creates a {@link JPanel} that asks the user for the translation of a
81          }           * String in several languages
82             */
83  //      /**          public TranslationEditJPanel(Translation trans, List<String> languages_) {
84  //       * Merges a few {@link TranslationEditJPanel}s and shows them together..                  this(null, trans, languages_);
85  //       * So far this is working on the Translation object directly, Cancel not possible.          }
86  //       * @param translationEditJPanel  
87  //       *          /**
88  //       * @deprecated Use {@link TranslationAskJDialog}           * Creates a {@link JPanel} that asks the user for the translation of a
89  //       */           * String in several languages and additionally puts a {@link JLabel} with a
90  //      public static void ask(Frame parentFrame, final TranslationEditJPanel... translationEditJPanels) {           * question at the {@link JPanel}'s first row.
91  //              dialog = new JDialog(parentFrame);           */
92  //      //      backup( translationEditJPanels );          public TranslationEditJPanel(String question, Translation trans,
93  //              showDialog(dialog, translationEditJPanels);                          List<String> languages_) {
94  //      }                  super(new BorderLayout());
95  //  
96  //                        if (trans == null)
97  //      /**                          trans = new Translation();
98  //       * Merges a few {@link TranslationEditJPanel}s and shows them together..  
99  //       * So far this is working on the Translation object directly, Cancel not possible.                  this.trans = trans;
100  //       * @param translationEditJPanel                  this.languages = languages_;
101  //  
102  //       * @deprecated User {@link TranslationAskJDialog}        *                  add(getTranslationGrid(), BorderLayout.CENTER);
103  //       */  
104  //      public static void ask(Window parentWindow, TranslationEditJPanel... translationEditJPanels) {                  if (question != null) {
105  //              dialog = new JDialog(parentWindow);                          JLabel questionLable = new JLabel(question);
106  //      //      backup( translationEditJPanels );                          questionLable
107  //              showDialog(dialog, translationEditJPanels);                                          .setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
108  //      }                          add(questionLable, BorderLayout.NORTH);
109  //                        }
110  //      /**          }
111  //       * Merges a few {@link TranslationEditJPanel}s and shows them together..  
112  //       * So far this is working on the Translation object directly, Cancel not possible.          private JPanel getTranslationGrid() {
113  //       * @param translationEditJPanel                  if (translationGrid == null) {
114  //       *                          translationGrid = new JPanel(new SpringLayout());
115  //       *       * @deprecated User {@link TranslationAskJDialog}  
116  //       */                          for (String langId : languages) {
117  //      public static void ask(JDialog parentDialog, TranslationEditJPanel... translationEditJPanels) {  
118  //              dialog = new JDialog(parentDialog);                                  // language code : entry field for translation
119  //      //      backup( translationEditJPanels );                                  JLabel langDesc = new JLabel(langId.toUpperCase() + " :"); // i8n
120  //              showDialog(dialog, translationEditJPanels);                                  langDesc.setHorizontalAlignment(SwingConstants.RIGHT);
121  //      }                                  langDesc.setVerticalAlignment(SwingConstants.NORTH);
122  //        
123  //                                        TranslationJTextField langTextField = new TranslationJTextField(
124  //      /**                                                  trans, langId);
125  //       *       * @deprecated User {@link TranslationAskJDialog}                                  // Setting a size
126  //       * @param d                                  langTextField.setPreferredSize(new Dimension(360, 22));
127  //       * @param translationEditJPanels                                  langDesc.setLabelFor(langTextField);
128  //       * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                                  translationGrid.add(langDesc);
129  //       */                                  translationGrid.add(langTextField);
130  //      public static void showDialog(JDialog d, JComponent... translationEditJPanels) {                                  
131  //              dialog = d;                                  langTextFields .add(langTextField);
132  //              dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);                          }
133  //              SwingUtil.centerFrameOnScreen(dialog);  
134  //              Box box = Box.createVerticalBox();                          // Lay out the panel.
135  //              for (JComponent panel : translationEditJPanels) {                          SpringUtilities.makeCompactGrid(translationGrid, languages.size(), // rows,
136  //                      box.add(panel);                                          2, // cols
137  //              }                                          6, 6, // initX, initY
138  //              JPanel cp = new JPanel( new BorderLayout());                                          6, 6); // xPad, yPad
139  //              cp.add( box, BorderLayout.CENTER);  
140  //              cp.add( getButtons(), BorderLayout.SOUTH  );                  }
141  //              dialog.setContentPane(cp);                  return translationGrid;
142  //                        }
143  //              // dialog.getRootPane().setDefaultButton(okButton);  
144  //                        /**
145  //              dialog.setTitle("Please translate"); //i8n           * @return The {@link Translation} that this {@link TranslationEditJPanel}
146  //              dialog.setModal(true);           *         deals with.
147  //              dialog.pack();           */
148  //              dialog.setVisible(true);          public Translation getTranslation() {
149  //      }                  return trans;
150  //          }
151  //      /**  
152  //       * @deprecated Use TranslationAskJDialog          public void addActionListener(final ActionListener actionListener) {
153  //       * @return                  for (final JTextField langTextField : langTextFields){
154  //       * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>                          langTextField.addKeyListener( new KeyListener(){
155  //       */  
156  //      private static JComponent getButtons() {                                  @Override
157  //              JPanel jPanel = new JPanel();                                  public void keyPressed(KeyEvent e) {
158  //              if (okButton == null) {                                  }
159  //                      okButton = new OkButton(new AbstractAction("enter") {  
160  //                  public void actionPerformed(ActionEvent evt) {                                  @Override
161  //                      firePropertyChange(PROPERTY_APPLY_AND_CLOSE, null, null);                                  public void keyReleased(KeyEvent e) {
162  //                      dialog.dispose();                                  }
163  //                  }  
164  //              } );                                  @Override
165  //              }                                  public void keyTyped(KeyEvent e) {
166  //              jPanel.add(okButton);                                          actionListener.actionPerformed(new ActionEvent(TranslationEditJPanel.this, 0, ""));
167  //                                  }
168  //              if (cancelButton == null) {                                  
169  //                      cancelButton = new CancelButton(new AbstractAction("") {                          });
170  //                  public void actionPerformed(ActionEvent evt) {                  }
171  //                      // restore();          }
172  //                      firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);  
173  //                      dialog.dispose();          public void removeActionListener(ActionListener actionListener) {
174  //                  }                  for (JTextField langTextField : langTextFields){
175  //              } );                          langTextField.removeActionListener(actionListener);
176  //              }                  }
177  //              jPanel.add(okButton);          }
178  //  
179  //              return jPanel;  }
 //      }  
           
         /**  
          * @return The {@link Translation} that this {@link TranslationEditJPanel} deals with.  
          */  
         public Translation getTranslation() {  
                 return trans;  
         }  
   
 }  

Legend:
Removed from v.127  
changed lines
  Added in v.256

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26