View Javadoc

1   /*
2    *                Doelan development code
3    *
4    * This code may be freely distributed and modified under the
5    * terms of the GNU General Public Licence.  This should
6    * be distributed with the code. If you do not have a copy,
7    * see:
8    *
9    *      http://www.gnu.org/copyleft/gpl.txt
10   *
11   * Copyright (c) 2004-2005 ENS Microarray Platform
12   * Copyright for this code is held jointly by the individual
13   * authors.  These should be listed in @author doc comments.
14   *
15   * For more information on the Doelan project and its aims,
16   * or to join the Doelan mailing list, visit the home page
17   * at:
18   *
19   *      http://www.transcriptome.ens.fr/doelan
20   */
21  
22  package fr.ens.transcriptome.doelan.gui;
23  
24  import java.awt.GridBagConstraints;
25  
26  import javax.swing.JLabel;
27  import javax.swing.JPanel;
28  import javax.swing.JTextField;
29  
30  /***
31   * This class implements a file chooser.
32   * @author Laurent Jourdren
33   */
34  public class DescriptionWidget {
35  
36    private String label;
37    private JPanel jPanel;
38    private int position;
39    private int mnemonicKey;
40  
41    private JTextField descriptionField = new JTextField();
42  
43    //
44    // Getters
45    //
46  
47    /***
48     * Get the text of the label.
49     * @return Returns the labelText
50     */
51    private String getLabel() {
52      return label;
53    }
54  
55    /***
56     * Get the panel.
57     * @return Returns the Panel
58     */
59    private JPanel getPanel() {
60      return jPanel;
61    }
62  
63    /***
64     * Get the position in the panel.
65     * @return Returns the position
66     */
67    private int getPosition() {
68      return position;
69    }
70  
71    /***
72     * Get the mnemonic key.
73     * @return Returns the mnemonicKey
74     */
75    public int getMnemonicKey() {
76      return mnemonicKey;
77    }
78  
79    /***
80     * Get the text of the description.
81     * @return the text of the description
82     */
83    public String getDescription() {
84      return this.descriptionField.getText();
85    }
86  
87    //
88    // Setters
89    //
90  
91    /***
92     * Set the label of the text.
93     * @param labelText The labelText to set
94     */
95    private void setLabel(final String labelText) {
96      this.label = labelText;
97    }
98  
99    /***
100    * Set the panel.
101    * @param panel The Panel to set
102    */
103   private void setPanel(final JPanel panel) {
104     jPanel = panel;
105   }
106 
107   /***
108    * Set the postion in the panel.
109    * @param position The position to set
110    */
111   private void setPosition(final int position) {
112     this.position = position;
113   }
114 
115   /***
116    * set the mnemonic key.
117    * @param mnemonicKey The mnemonicKey to set
118    */
119   public void setMnemonicKey(final int mnemonicKey) {
120     this.mnemonicKey = mnemonicKey;
121   }
122 
123   //
124   // Other methods
125   //
126 
127   private void init() {
128 
129     GridBagConstraints gridBagConstraints;
130     // JPanel selectorPanel = new JPanel();
131     // selectorPanel.setLayout(new java.awt.GridBagLayout());
132     final JPanel selectorPanel = getPanel();
133 
134     // File label
135     JLabel jLabel1 = new JLabel(getLabel());
136     gridBagConstraints = new java.awt.GridBagConstraints();
137     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
138     gridBagConstraints.gridx = 0;
139     gridBagConstraints.gridy = getPosition();
140     gridBagConstraints.ipadx = 30;
141     selectorPanel.add(jLabel1, gridBagConstraints);
142     jLabel1.setDisplayedMnemonic(getMnemonicKey());
143     jLabel1.setLabelFor(descriptionField);
144 
145     // Name of file selected
146     gridBagConstraints = new java.awt.GridBagConstraints();
147     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
148     gridBagConstraints.gridx = 1;
149     gridBagConstraints.gridwidth = 4;
150     gridBagConstraints.gridy = getPosition();
151     selectorPanel.add(descriptionField, gridBagConstraints);
152 
153   }
154 
155   //
156   // Constructor
157   //
158 
159   /***
160    * Public constructor.
161    * @param label the Label of the widget
162    * @param panel Calling panel
163    * @param position Position of the chooser
164    */
165   public DescriptionWidget(final String label, final int mnemonicKey,
166       final JPanel panel, final int position) {
167 
168     setLabel(label);
169     setMnemonicKey(mnemonicKey);
170     setPanel(panel);
171     setPosition(position);
172     init();
173   }
174 
175 }