1 22 23 package org.gjt.sp.jedit.options; 24 25 import java.awt.BorderLayout ; 27 import java.awt.Component ; 28 import java.awt.Dimension ; 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.ActionListener ; 31 import java.util.Arrays ; 32 import javax.swing.Box ; 33 import javax.swing.JButton ; 34 import javax.swing.JCheckBox ; 35 import javax.swing.JLabel ; 36 import javax.swing.JScrollPane ; 37 import org.gjt.sp.jedit.AbstractOptionPane; 38 import org.gjt.sp.jedit.jEdit; 39 import org.gjt.sp.jedit.MiscUtilities; 40 import org.gjt.sp.jedit.MiscUtilities.StringICaseCompare; 41 43 50 public class EncodingsOptionPane extends AbstractOptionPane 51 { 52 public EncodingsOptionPane() 54 { 55 super("encodings"); 56 } 58 protected void _init() 60 { 61 setLayout(new BorderLayout ()); 62 63 add(new JLabel (jEdit.getProperty("options.encodings.selectEncodings")),BorderLayout.NORTH); 64 65 Box encodingsBox = Box.createVerticalBox(); 66 String [] encodings = MiscUtilities.getEncodings(false); 67 Arrays.sort(encodings,new MiscUtilities.StringICaseCompare()); 68 int encodingsAmount = encodings.length; 69 encodingCheckBoxArray = new JCheckBox [encodingsAmount]; 70 for (int i=0 ; i<encodingsAmount ; i++) { 71 String encoding = encodings[i]; 72 JCheckBox encodingCheckBox = new JCheckBox (encoding,!jEdit.getBooleanProperty("encoding.opt-out."+encoding,false)); 73 encodingCheckBoxArray[i] = encodingCheckBox; 74 encodingsBox.add(encodingCheckBox); 75 } 76 JScrollPane encodingsScrollPane = new JScrollPane (encodingsBox); 77 Dimension d = encodingsBox.getPreferredSize(); 78 d.height = Math.min(d.height,200); 79 encodingsScrollPane.setPreferredSize(d); 80 add(encodingsScrollPane,BorderLayout.CENTER); 81 82 ActionHandler actionHandler = new ActionHandler(); 83 Box buttonsBox = Box.createHorizontalBox(); 84 selectAllButton = new JButton (jEdit.getProperty("options.encodings.selectAll")); 85 selectAllButton.addActionListener(actionHandler); 86 buttonsBox.add(selectAllButton); 87 selectNoneButton = new JButton (jEdit.getProperty("options.encodings.selectNone")); 88 selectNoneButton.addActionListener(actionHandler); 89 buttonsBox.add(selectNoneButton); 90 add(buttonsBox,BorderLayout.SOUTH); 91 } 93 protected void _save() 95 { 96 for (int i=0, c=encodingCheckBoxArray.length ; i<c ; i++) 97 { 98 JCheckBox encodingCheckBox = encodingCheckBoxArray[i]; 99 if (encodingCheckBox.isSelected()) 100 { 101 jEdit.unsetProperty("encoding.opt-out."+encodingCheckBox.getText()); 102 } 103 else 104 { 105 jEdit.setBooleanProperty("encoding.opt-out."+encodingCheckBox.getText(),true); 106 } 107 } 108 } 110 112 private JCheckBox [] encodingCheckBoxArray; 114 private JButton selectAllButton; 115 private JButton selectNoneButton; 116 118 class ActionHandler implements ActionListener 120 { 121 public void actionPerformed(ActionEvent e) 122 { 123 boolean select; 124 Object source = e.getSource(); 125 if (source == selectAllButton) 126 { 127 select = true; 128 } 129 else if (source == selectNoneButton) 130 { 131 select = false; 132 } 133 else 134 { 135 return; 136 } 137 for (int i=0, c=encodingCheckBoxArray.length ; i<c ; i++) 138 { 139 encodingCheckBoxArray[i].setSelected(select); 140 } 141 } 142 } } | Popular Tags |