1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
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 }