KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > options > EncodingsOptionPane


1 /*
2  * EncodingsOptionPane.java - Encodings options panel
3  * :tabSize=4:indentSize=4:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2006 Björn Kautler
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.options;
24
25 //{{{ Imports
26
import java.awt.BorderLayout JavaDoc;
27 import java.awt.Component JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import javax.swing.Box JavaDoc;
33 import javax.swing.JButton JavaDoc;
34 import javax.swing.JCheckBox JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JScrollPane JavaDoc;
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 //}}}
42

43 //{{{ EncodingsOptionPane class
44
/**
45  * Encodings editor.
46  * @author Björn Kautler
47  * @since jEdit 4.3pre6
48  * @version $Id: EncodingsOptionPane.java 6483 2006-08-02 14:21:07Z vampire0 $
49  */

50 public class EncodingsOptionPane extends AbstractOptionPane
51 {
52     //{{{ EncodingsOptionPane constructor
53
public EncodingsOptionPane()
54     {
55         super("encodings");
56     } //}}}
57

58     //{{{ _init() method
59
protected void _init()
60     {
61         setLayout(new BorderLayout JavaDoc());
62
63         add(new JLabel JavaDoc(jEdit.getProperty("options.encodings.selectEncodings")),BorderLayout.NORTH);
64
65         Box JavaDoc encodingsBox = Box.createVerticalBox();
66         String JavaDoc[] encodings = MiscUtilities.getEncodings(false);
67         Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
68         int encodingsAmount = encodings.length;
69         encodingCheckBoxArray = new JCheckBox JavaDoc[encodingsAmount];
70         for (int i=0 ; i<encodingsAmount ; i++) {
71             String JavaDoc encoding = encodings[i];
72             JCheckBox JavaDoc encodingCheckBox = new JCheckBox JavaDoc(encoding,!jEdit.getBooleanProperty("encoding.opt-out."+encoding,false));
73             encodingCheckBoxArray[i] = encodingCheckBox;
74             encodingsBox.add(encodingCheckBox);
75         }
76         JScrollPane JavaDoc encodingsScrollPane = new JScrollPane JavaDoc(encodingsBox);
77         Dimension JavaDoc 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 JavaDoc buttonsBox = Box.createHorizontalBox();
84         selectAllButton = new JButton JavaDoc(jEdit.getProperty("options.encodings.selectAll"));
85         selectAllButton.addActionListener(actionHandler);
86         buttonsBox.add(selectAllButton);
87         selectNoneButton = new JButton JavaDoc(jEdit.getProperty("options.encodings.selectNone"));
88         selectNoneButton.addActionListener(actionHandler);
89         buttonsBox.add(selectNoneButton);
90         add(buttonsBox,BorderLayout.SOUTH);
91     } //}}}
92

93     //{{{ _save() method
94
protected void _save()
95     {
96         for (int i=0, c=encodingCheckBoxArray.length ; i<c ; i++)
97         {
98             JCheckBox JavaDoc 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     } //}}}
109

110     //{{{ Private members
111

112     //{{{ Instance variables
113
private JCheckBox JavaDoc[] encodingCheckBoxArray;
114     private JButton JavaDoc selectAllButton;
115     private JButton JavaDoc selectNoneButton;
116     //}}}
117

118     //{{{ ActionHandler class
119
class ActionHandler implements ActionListener JavaDoc
120     {
121         public void actionPerformed(ActionEvent JavaDoc e)
122         {
123             boolean select;
124             Object JavaDoc 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     } //}}}
143
} //}}}
144
Popular Tags