Source Code Cross Referenced for EncodingsOptionPane.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » options » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jEdit » org.gjt.sp.jedit.options 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EncodingsOptionPane.java - Encodings options panel
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2006 Björn Kautler
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.options;
024:
025:        //{{{ Imports
026:        import java.awt.Component;
027:        import java.awt.Dimension;
028:
029:        import java.awt.event.ActionEvent;
030:        import java.awt.event.ActionListener;
031:
032:        import java.util.Arrays;
033:        import java.util.Vector;
034:
035:        import javax.swing.Box;
036:        import javax.swing.JButton;
037:        import javax.swing.JCheckBox;
038:        import javax.swing.JComboBox;
039:        import javax.swing.JLabel;
040:        import javax.swing.JPanel;
041:        import javax.swing.JScrollPane;
042:        import javax.swing.JTextField;
043:
044:        import javax.swing.border.EmptyBorder;
045:        import javax.swing.border.TitledBorder;
046:
047:        import javax.swing.event.TableModelEvent;
048:        import javax.swing.event.TableModelListener;
049:
050:        import org.gjt.sp.jedit.AbstractOptionPane;
051:        import org.gjt.sp.jedit.Buffer;
052:        import org.gjt.sp.jedit.MiscUtilities;
053:        import org.gjt.sp.jedit.jEdit;
054:
055:        import org.gjt.sp.jedit.MiscUtilities.StringICaseCompare;
056:
057:        import org.gjt.sp.jedit.gui.JCheckBoxList;
058:
059:        import org.gjt.sp.jedit.gui.JCheckBoxList.Entry;
060:
061:        import static java.awt.GridBagConstraints.BOTH;
062:
063:        import static java.util.Arrays.sort;
064:
065:        import static javax.swing.Box.createHorizontalBox;
066:        import static javax.swing.Box.createHorizontalStrut;
067:
068:        import static org.gjt.sp.jedit.jEdit.getBooleanProperty;
069:        import static org.gjt.sp.jedit.jEdit.getProperty;
070:        import static org.gjt.sp.jedit.jEdit.setBooleanProperty;
071:        import static org.gjt.sp.jedit.jEdit.unsetProperty;
072:
073:        import static org.gjt.sp.jedit.MiscUtilities.getEncodings;
074:
075:        //}}}
076:
077:        //{{{ EncodingsOptionPane class
078:        /**
079:         * Encodings options.
080:         * 
081:         * @author Björn Kautler
082:         * @since jEdit 4.3pre6
083:         * @version $Id: EncodingsOptionPane.java 9998 2007-07-11 10:25:00Z Vampire0 $
084:         */
085:        public class EncodingsOptionPane extends AbstractOptionPane {
086:            //{{{ Instance variables
087:            private JComboBox defaultEncoding;
088:            private JCheckBox encodingAutodetect;
089:            private JTextField encodingDetectors;
090:            private JTextField fallbackEncodings;
091:
092:            private JCheckBoxList encodingsList;
093:            private JButton selectAllButton;
094:            private JButton selectNoneButton;
095:
096:            //}}}
097:
098:            //{{{ EncodingsOptionPane constructor
099:            public EncodingsOptionPane() {
100:                super ("encodings");
101:            } //}}}
102:
103:            //{{{ _init() method
104:            protected void _init() {
105:                // Default file encoding
106:                String[] encodings = getEncodings(true);
107:                sort(encodings, new StringICaseCompare());
108:                defaultEncoding = new JComboBox(encodings);
109:                defaultEncoding.setEditable(true);
110:                defaultEncoding
111:                        .setSelectedItem(jEdit.getProperty("buffer."
112:                                + Buffer.ENCODING, System
113:                                .getProperty("file.encoding")));
114:                addComponent(jEdit.getProperty("options.general.encoding"),
115:                        defaultEncoding);
116:
117:                // Auto detect encoding
118:                encodingAutodetect = new JCheckBox(jEdit
119:                        .getProperty("options.general.encodingAutodetect"));
120:                encodingAutodetect.setSelected(jEdit
121:                        .getBooleanProperty("buffer.encodingAutodetect"));
122:                addComponent(encodingAutodetect, BOTH);
123:
124:                // Encoding detectors
125:                encodingDetectors = new JTextField(jEdit.getProperty(
126:                        "encodingDetectors", "BOM XML-PI"));
127:                addComponent(jEdit
128:                        .getProperty("options.general.encodingDetectors"),
129:                        encodingDetectors);
130:
131:                // Fallback Encodings
132:                fallbackEncodings = new JTextField(jEdit.getProperty(
133:                        "fallbackEncodings", ""));
134:                fallbackEncodings
135:                        .setToolTipText(jEdit
136:                                .getProperty("options.general.fallbackEncodings.tooltip"));
137:                addComponent(jEdit
138:                        .getProperty("options.general.fallbackEncodings"),
139:                        fallbackEncodings);
140:
141:                // Encodings to display
142:                encodings = getEncodings(false);
143:                sort(encodings, new StringICaseCompare());
144:                Vector<Entry> encodingEntriesVector = new Vector<Entry>();
145:                boolean enableSelectAll = false;
146:                boolean enableSelectNone = false;
147:                for (String encoding : encodings) {
148:                    boolean selected = !getBooleanProperty("encoding.opt-out."
149:                            + encoding, false);
150:                    enableSelectAll = enableSelectAll || !selected;
151:                    enableSelectNone = enableSelectNone || selected;
152:                    encodingEntriesVector.add(new Entry(selected, encoding));
153:                }
154:                encodingsList = new JCheckBoxList(encodingEntriesVector);
155:                encodingsList.getModel().addTableModelListener(
156:                        new TableModelHandler());
157:                JScrollPane encodingsScrollPane = new JScrollPane(encodingsList);
158:                encodingsScrollPane.setBorder(new TitledBorder(
159:                        getProperty("options.encodings.selectEncodings")));
160:                Dimension d = encodingsList.getPreferredSize();
161:                d.height = Math.min(d.height, 200);
162:                encodingsScrollPane.setPreferredSize(d);
163:                addComponent(encodingsScrollPane, BOTH);
164:
165:                // Select All/None Buttons
166:                Box buttonsBox = createHorizontalBox();
167:                buttonsBox.add(createHorizontalStrut(12));
168:
169:                ActionHandler actionHandler = new ActionHandler();
170:                selectAllButton = new JButton(
171:                        getProperty("options.encodings.selectAll"));
172:                selectAllButton.addActionListener(actionHandler);
173:                selectAllButton.setEnabled(enableSelectAll);
174:                buttonsBox.add(selectAllButton);
175:                buttonsBox.add(createHorizontalStrut(12));
176:
177:                selectNoneButton = new JButton(
178:                        getProperty("options.encodings.selectNone"));
179:                selectNoneButton.addActionListener(actionHandler);
180:                selectNoneButton.setEnabled(enableSelectNone);
181:                buttonsBox.add(selectNoneButton);
182:                buttonsBox.add(createHorizontalStrut(12));
183:
184:                addComponent(buttonsBox);
185:            } //}}}
186:
187:            //{{{ _save() method
188:            protected void _save() {
189:
190:                jEdit.setProperty("buffer." + Buffer.ENCODING,
191:                        (String) defaultEncoding.getSelectedItem());
192:                jEdit.setBooleanProperty("buffer.encodingAutodetect",
193:                        encodingAutodetect.isSelected());
194:                jEdit.setProperty("encodingDetectors", encodingDetectors
195:                        .getText());
196:                jEdit.setProperty("fallbackEncodings", fallbackEncodings
197:                        .getText());
198:
199:                for (Entry entry : encodingsList.getValues()) {
200:                    if (entry.isChecked()) {
201:                        unsetProperty("encoding.opt-out." + entry.getValue());
202:                    } else {
203:                        setBooleanProperty("encoding.opt-out."
204:                                + entry.getValue(), true);
205:                    }
206:                }
207:            } //}}}
208:
209:            //{{{ Inner classes
210:
211:            //{{{ ActionHandler class
212:            class ActionHandler implements  ActionListener {
213:                public void actionPerformed(ActionEvent ae) {
214:                    Object source = ae.getSource();
215:                    if (source == selectAllButton) {
216:                        encodingsList.selectAll();
217:                    } else if (source == selectNoneButton) {
218:                        for (int i = 0, c = encodingsList.getRowCount(); i < c; i++) {
219:                            encodingsList.setValueAt(false, i, 0);
220:                        }
221:                    }
222:                }
223:            } //}}}
224:
225:            //{{{ TableModelHandler class
226:            class TableModelHandler implements  TableModelListener {
227:                public void tableChanged(TableModelEvent tme) {
228:                    int checkedAmount = encodingsList.getCheckedValues().length;
229:                    if (0 == checkedAmount) {
230:                        selectNoneButton.setEnabled(false);
231:                    } else {
232:                        selectNoneButton.setEnabled(true);
233:                    }
234:                    if (encodingsList.getValues().length == checkedAmount) {
235:                        selectAllButton.setEnabled(false);
236:                    } else {
237:                        selectAllButton.setEnabled(true);
238:                    }
239:                }
240:            } //}}}
241:
242:            //}}}
243:
244:        } //}}}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.