1 package rero.dck.items; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 import javax.swing.*; 7 import javax.swing.event.*; 8 9 import java.io.*; 10 import java.nio.charset.*; 11 12 import java.util.*; 13 14 import rero.dck.*; 15 import rero.config.*; 16 17 public class CharsetInput extends SuperInput 18 { 19 public static final String DEFAULT_CHARSET = "Platform Default"; 20 21 protected JComboBox name; 22 protected boolean listing = true; 23 protected JLabel label; 24 25 public CharsetInput(String _variable, String aLabel, char mnemonic, int rightGap) 26 { 27 variable = _variable; 28 29 setLayout(new BorderLayout()); 30 31 name = new JComboBox(); 32 name.addItem("Loading Charsets..."); 33 34 add(name, BorderLayout.CENTER); 35 36 if (rightGap > 0) 37 { 38 JPanel temp = new JPanel(); 39 temp.setPreferredSize(new Dimension(rightGap, 0)); 40 41 add(temp, BorderLayout.EAST); 42 } 43 44 label = new JLabel(" " + aLabel + " "); 45 label.setDisplayedMnemonic(mnemonic); 46 47 add(label, BorderLayout.WEST); 48 } 49 50 public void setAlignWidth(int width) 51 { 52 label.setPreferredSize(new Dimension(width, 0)); 53 revalidate(); 54 } 55 56 public void save() 57 { 58 ClientState.getClientState().setString(getVariable(), name.getSelectedItem().toString()); 59 } 60 61 public JComponent getComponent() 62 { 63 return this; 64 } 65 66 public int getEstimatedWidth() 67 { 68 return (int)label.getPreferredSize().getWidth(); 69 } 70 71 public void refresh() 72 { 73 if (!listing) 74 { 75 name.setSelectedItem(ClientState.getClientState().getString(getVariable(), DEFAULT_CHARSET)); 76 } 77 else 78 { 79 SwingUtilities.invokeLater(new Runnable () 80 { 81 public void run() 82 { 83 name.addItem(DEFAULT_CHARSET); 84 85 Iterator i = Charset.availableCharsets().keySet().iterator(); 86 87 while (i.hasNext()) 88 { 89 name.addItem(i.next().toString()); 90 } 91 92 name.removeItemAt(0); 93 listing = false; 94 refresh(); 95 revalidate(); 96 } 97 }); 98 } 99 } 100 } 101 102 103 | Popular Tags |