Source Code Cross Referenced for BrowserColorsOptionPane.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:         * BrowserColorsOptionPane.java - Browser colors options panel
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2001, 2002 Slava Pestov
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 javax.swing.border.EmptyBorder;
027:        import javax.swing.event.*;
028:        import javax.swing.table.*;
029:        import javax.swing.*;
030:        import java.awt.event.*;
031:        import java.awt.*;
032:        import java.util.*;
033:        import org.gjt.sp.jedit.gui.RolloverButton;
034:        import org.gjt.sp.jedit.*;
035:
036:        //}}}
037:
038:        //{{{ BrowserColorsOptionPane class
039:        /**
040:         * Browser color editor.
041:         * @author Slava Pestov
042:         * @version $Id: BrowserColorsOptionPane.java 4892 2003-10-11 02:21:37Z spestov $
043:         */
044:        public class BrowserColorsOptionPane extends AbstractOptionPane {
045:            //{{{ BrowserColorsOptionPane constructor
046:            public BrowserColorsOptionPane() {
047:                super ("browser.colors");
048:            } //}}}
049:
050:            //{{{ Protected members
051:
052:            //{{{ _init() method
053:            protected void _init() {
054:                setLayout(new BorderLayout());
055:
056:                colorsModel = new BrowserColorsModel();
057:                colorsTable = new JTable(colorsModel);
058:                colorsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
059:                colorsTable.getTableHeader().setReorderingAllowed(false);
060:                colorsTable.addMouseListener(new MouseHandler());
061:                colorsTable.getSelectionModel().addListSelectionListener(
062:                        new SelectionHandler());
063:                TableColumnModel tcm = colorsTable.getColumnModel();
064:                tcm.getColumn(1).setCellRenderer(
065:                        new BrowserColorsModel.ColorRenderer());
066:                Dimension d = colorsTable.getPreferredSize();
067:                d.height = Math.min(d.height, 200);
068:                JScrollPane scroller = new JScrollPane(colorsTable);
069:                scroller.setPreferredSize(d);
070:                add(BorderLayout.CENTER, scroller);
071:
072:                JPanel buttons = new JPanel();
073:                buttons.setBorder(new EmptyBorder(3, 0, 0, 0));
074:                buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
075:                ActionHandler actionHandler = new ActionHandler();
076:                add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
077:                add.setToolTipText(jEdit.getProperty("common.add"));
078:                add.addActionListener(actionHandler);
079:                buttons.add(add);
080:                buttons.add(Box.createHorizontalStrut(6));
081:                remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
082:                remove.setToolTipText(jEdit.getProperty("common.remove"));
083:                remove.addActionListener(actionHandler);
084:                buttons.add(remove);
085:                buttons.add(Box.createHorizontalStrut(6));
086:                moveUp = new RolloverButton(GUIUtilities.loadIcon("ArrowU.png"));
087:                moveUp.setToolTipText(jEdit.getProperty("common.moveUp"));
088:                moveUp.addActionListener(actionHandler);
089:                buttons.add(moveUp);
090:                buttons.add(Box.createHorizontalStrut(6));
091:                moveDown = new RolloverButton(GUIUtilities
092:                        .loadIcon("ArrowD.png"));
093:                moveDown.setToolTipText(jEdit.getProperty("common.moveDown"));
094:                moveDown.addActionListener(actionHandler);
095:                buttons.add(moveDown);
096:                buttons.add(Box.createGlue());
097:
098:                add(BorderLayout.SOUTH, buttons);
099:
100:                updateEnabled();
101:            } //}}}
102:
103:            //{{{ _save() method
104:            protected void _save() {
105:                colorsModel.save();
106:            } //}}}
107:
108:            //}}}
109:
110:            //{{{ Private members
111:            private BrowserColorsModel colorsModel;
112:            private JTable colorsTable;
113:            private JButton add;
114:            private JButton remove;
115:            private JButton moveUp;
116:            private JButton moveDown;
117:
118:            //{{{ updateEnabled() method
119:            private void updateEnabled() {
120:                int selectedRow = colorsTable.getSelectedRow();
121:                remove.setEnabled(selectedRow != -1);
122:                moveUp.setEnabled(selectedRow > 0);
123:                moveUp.setEnabled(selectedRow != -1
124:                        && selectedRow != colorsModel.getRowCount());
125:            } //}}}
126:
127:            //{{{ setSelectedRow() method
128:            private void setSelectedRow(int row) {
129:                colorsTable.getSelectionModel().setSelectionInterval(row, row);
130:                colorsTable.scrollRectToVisible(colorsTable.getCellRect(row, 0,
131:                        true));
132:            } //}}}
133:
134:            //}}}
135:
136:            //{{{ SelectionHandler class
137:            class SelectionHandler implements  ListSelectionListener {
138:                public void valueChanged(ListSelectionEvent evt) {
139:                    updateEnabled();
140:                }
141:            } //}}}
142:
143:            //{{{ ActionHandler class
144:            class ActionHandler implements  ActionListener {
145:                public void actionPerformed(ActionEvent evt) {
146:                    Object source = evt.getSource();
147:                    if (source == add) {
148:                        colorsModel.add();
149:                    } else if (source == remove) {
150:                        int selectedRow = colorsTable.getSelectedRow();
151:                        colorsModel.remove(selectedRow);
152:                        updateEnabled();
153:                    } else if (source == moveUp) {
154:                        int selectedRow = colorsTable.getSelectedRow();
155:                        if (selectedRow != 0) {
156:                            colorsModel.moveUp(selectedRow);
157:                            setSelectedRow(selectedRow - 1);
158:                        }
159:                        updateEnabled();
160:                    } else if (source == moveDown) {
161:                        int selectedRow = colorsTable.getSelectedRow();
162:                        if (selectedRow != colorsTable.getRowCount() - 1) {
163:                            colorsModel.moveDown(selectedRow);
164:                            setSelectedRow(selectedRow + 1);
165:                        }
166:                        updateEnabled();
167:                    }
168:                }
169:            } //}}}
170:
171:            //{{{ MouseHandler class
172:            class MouseHandler extends MouseAdapter {
173:                public void mouseClicked(MouseEvent evt) {
174:                    Point p = evt.getPoint();
175:                    int row = colorsTable.rowAtPoint(p);
176:                    int column = colorsTable.columnAtPoint(p);
177:                    if (row == -1 || column != 1)
178:                        return;
179:
180:                    Color color = JColorChooser.showDialog(
181:                            BrowserColorsOptionPane.this , jEdit
182:                                    .getProperty("colorChooser.title"),
183:                            (Color) colorsModel.getValueAt(row, 1));
184:                    if (color != null)
185:                        colorsModel.setValueAt(color, row, 1);
186:                }
187:            } //}}}
188:        } //}}}
189:
190:        //{{{ BrowserColorsModel class
191:        class BrowserColorsModel extends AbstractTableModel {
192:            //{{{ BrowserColorsModel constructor
193:            BrowserColorsModel() {
194:                entries = new ArrayList();
195:
196:                int i = 0;
197:                String glob;
198:                while ((glob = jEdit.getProperty("vfs.browser.colors." + i
199:                        + ".glob")) != null) {
200:                    entries
201:                            .add(new Entry(glob, jEdit.getColorProperty(
202:                                    "vfs.browser.colors." + i + ".color",
203:                                    Color.black)));
204:                    i++;
205:                }
206:            } //}}}
207:
208:            //{{{ add() method
209:            void add() {
210:                entries
211:                        .add(new Entry("", UIManager
212:                                .getColor("Tree.foreground")));
213:                fireTableRowsInserted(entries.size() - 1, entries.size() - 1);
214:            } //}}}
215:
216:            //{{{ remove() method
217:            void remove(int index) {
218:                entries.remove(index);
219:                fireTableRowsDeleted(entries.size(), entries.size());
220:            } //}}}
221:
222:            //{{{ moveUp() method
223:            public void moveUp(int index) {
224:                Object obj = entries.get(index);
225:                entries.remove(index);
226:                entries.add(index - 1, obj);
227:                fireTableRowsUpdated(index - 1, index);
228:            } //}}}
229:
230:            //{{{ moveDown() method
231:            public void moveDown(int index) {
232:                Object obj = entries.get(index);
233:                entries.remove(index);
234:                entries.add(index + 1, obj);
235:                fireTableRowsUpdated(index, index + 1);
236:            } //}}}
237:
238:            //{{{ save() method
239:            void save() {
240:                int i;
241:                for (i = 0; i < entries.size(); i++) {
242:                    Entry entry = (Entry) entries.get(i);
243:                    jEdit.setProperty("vfs.browser.colors." + i + ".glob",
244:                            entry.glob);
245:                    jEdit.setColorProperty(
246:                            "vfs.browser.colors." + i + ".color", entry.color);
247:                }
248:                jEdit.unsetProperty("vfs.browser.colors." + i + ".glob");
249:                jEdit.unsetProperty("vfs.browser.colors." + i + ".color");
250:            } //}}}
251:
252:            //{{{ getColumnCount() method
253:            public int getColumnCount() {
254:                return 2;
255:            } //}}}
256:
257:            //{{{ getRowCount() method
258:            public int getRowCount() {
259:                return entries.size();
260:            } //}}}
261:
262:            //{{{ getValueAt() method
263:            public Object getValueAt(int row, int col) {
264:                Entry entry = (Entry) entries.get(row);
265:
266:                switch (col) {
267:                case 0:
268:                    return entry.glob;
269:                case 1:
270:                    return entry.color;
271:                default:
272:                    return null;
273:                }
274:            } //}}}
275:
276:            //{{{ isCellEditable() method
277:            public boolean isCellEditable(int row, int col) {
278:                return (col == 0);
279:            } //}}}
280:
281:            //{{{ setValueAt() method
282:            public void setValueAt(Object value, int row, int col) {
283:                Entry entry = (Entry) entries.get(row);
284:
285:                if (col == 0)
286:                    entry.glob = (String) value;
287:                else
288:                    entry.color = (Color) value;
289:
290:                fireTableRowsUpdated(row, row);
291:            } //}}}
292:
293:            //{{{ getColumnName() method
294:            public String getColumnName(int index) {
295:                switch (index) {
296:                case 0:
297:                    return jEdit.getProperty("options.browser.colors.glob");
298:                case 1:
299:                    return jEdit.getProperty("options.browser.colors.color");
300:                default:
301:                    return null;
302:                }
303:            } //}}}
304:
305:            //{{{ getColumnClass() method
306:            public Class getColumnClass(int col) {
307:                switch (col) {
308:                case 0:
309:                    return String.class;
310:                case 1:
311:                    return Color.class;
312:                default:
313:                    throw new InternalError();
314:                }
315:            } //}}}
316:
317:            private ArrayList entries;
318:
319:            //{{{ Entry class
320:            static class Entry {
321:                String glob;
322:                Color color;
323:
324:                Entry(String glob, Color color) {
325:                    this .glob = glob;
326:                    this .color = color;
327:                }
328:            } //}}}
329:
330:            //{{{ ColorRenderer class
331:            static class ColorRenderer extends JLabel implements 
332:                    TableCellRenderer {
333:                //{{{ ColorRenderer constructor
334:                public ColorRenderer() {
335:                    setOpaque(true);
336:                    setBorder(SyntaxHiliteOptionPane.noFocusBorder);
337:                } //}}}
338:
339:                //{{{ getTableCellRendererComponent() method
340:                public Component getTableCellRendererComponent(JTable table,
341:                        Object value, boolean isSelected, boolean cellHasFocus,
342:                        int row, int col) {
343:                    if (isSelected) {
344:                        setBackground(table.getSelectionBackground());
345:                        setForeground(table.getSelectionForeground());
346:                    } else {
347:                        setBackground(table.getBackground());
348:                        setForeground(table.getForeground());
349:                    }
350:
351:                    if (value != null)
352:                        setBackground((Color) value);
353:
354:                    setBorder((cellHasFocus) ? UIManager
355:                            .getBorder("Table.focusCellHighlightBorder")
356:                            : SyntaxHiliteOptionPane.noFocusBorder);
357:                    return this ;
358:                } //}}}
359:            } //}}}
360:        } //}}}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.