View Javadoc
1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is ""  Description:
10   * ""
11   *
12   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13   * 2001.  All Rights Reserved.
14   *
15   * Contributor(s): ______________________________________.
16   *
17   * Alternatively, the contents of this file may be used under the terms of the
18   * GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
19   * applicable instead of those above.  If you wish to allow use of your version of this
20   * file only under the terms of the GPL and not to allow others to use your version
21   * of this file under the MPL, indicate your decision by deleting  the provisions above
22   * and replace  them with the notice and other provisions required by the GPL License.
23   * If you do not delete the provisions above, a recipient may use your version of
24   * this file under either the MPL or the GPL.
25   */
26  package ca.uhn.hl7v2.testpanel.ui;
27  
28  import java.awt.Dimension;
29  import java.awt.GridBagConstraints;
30  import java.awt.GridBagLayout;
31  import java.awt.Insets;
32  import java.nio.charset.Charset;
33  import java.util.ArrayList;
34  import java.util.Collections;
35  import java.util.List;
36  
37  import javax.swing.ComboBoxModel;
38  import javax.swing.DefaultComboBoxModel;
39  import javax.swing.JComboBox;
40  import javax.swing.JLabel;
41  import javax.swing.JPanel;
42  
43  import ca.uhn.hl7v2.testpanel.controller.Prefs;
44  
45  public class FileChooserOpenAccessory extends JPanel {
46  	private static final long serialVersionUID = 1L;
47  	private JLabel mylabel;
48  	private JComboBox myCharsetCombo;
49  
50  	/**
51  	 * Create the panel.
52  	 */
53  	public FileChooserOpenAccessory() {
54  		GridBagLayout gridBagLayout = new GridBagLayout();
55  		gridBagLayout.columnWidths = new int[] { 0, 0 };
56  		gridBagLayout.rowHeights = new int[] { 0, 0 };
57  		gridBagLayout.columnWeights = new double[] { 0.0, 1.0 };
58  		gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
59  		setLayout(gridBagLayout);
60  
61  		mylabel = new JLabel("Charset");
62  		GridBagConstraints gbc_label = new GridBagConstraints();
63  		gbc_label.anchor = GridBagConstraints.EAST;
64  		gbc_label.insets = new Insets(0, 0, 0, 5);
65  		gbc_label.gridx = 0;
66  		gbc_label.gridy = 0;
67  		add(mylabel, gbc_label);
68  
69  		myCharsetCombo = new JComboBox();
70  		myCharsetCombo.setMaximumSize(new Dimension(180, 32767));
71  		myCharsetCombo.setPreferredSize(new Dimension(180, 27));
72  		myCharsetCombo.setMinimumSize(new Dimension(180, 27));
73  		GridBagConstraints gbc_CharsetCombo = new GridBagConstraints();
74  		gbc_CharsetCombo.anchor = GridBagConstraints.WEST;
75  		gbc_CharsetCombo.gridx = 1;
76  		gbc_CharsetCombo.gridy = 0;
77  		add(myCharsetCombo, gbc_CharsetCombo);
78  
79  		List<String> charSets = new ArrayList<String>(Charset.availableCharsets().keySet());
80  		Collections.sort(charSets);
81  		ComboBoxModel charsetModel = new DefaultComboBoxModel(charSets.toArray(new String[0]));
82  		myCharsetCombo.setModel(charsetModel);
83  		Charset openOrSaveCharset = Prefs.getInstance().getOpenOrSaveCharset();
84  		myCharsetCombo.setSelectedItem(openOrSaveCharset.name());
85  
86  	}
87  
88  	/**
89  	 * Note: Saves the value as a preference
90  	 */
91  	public Charset getSelectedCharset() {
92  		Charset retVal = Charset.forName((String) myCharsetCombo.getSelectedItem());
93  		Prefs.getInstance().setOpenOrSaveCharset(retVal);
94  		return retVal;
95  	}
96  
97  
98  }