Source Code Cross Referenced for TextStyleOptionsTab.java in  » Source-Control » gruntspud » gruntspud » style » 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 » Source Control » gruntspud » gruntspud.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Gruntspud
003:         *
004:         *  Copyright (C) 2002 Brett Smith.
005:         *
006:         *  Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007:         *
008:         *  This program is free software; you can redistribute it and/or
009:         *  modify it under the terms of the GNU Library General Public License
010:         *  as published by the Free Software Foundation; either version 2 of
011:         *  the License, or (at your option) any later version.
012:         *  This program is distributed in the hope that it will be useful,
013:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         *  GNU Library General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU Library General Public
018:         *  License along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         */
021:
022:        package gruntspud.style;
023:
024:        import gruntspud.Constants;
025:        import gruntspud.GruntspudContext;
026:        import gruntspud.ui.ColorComboBox;
027:        import gruntspud.ui.UIUtil;
028:        import gruntspud.ui.icons.ColorIcon;
029:        import gruntspud.ui.icons.CompoundIcon;
030:        import gruntspud.ui.preferences.AbstractOptionsTab;
031:
032:        import java.awt.BorderLayout;
033:        import java.awt.Color;
034:        import java.awt.Component;
035:        import java.awt.Dimension;
036:        import java.awt.Font;
037:        import java.awt.GridBagConstraints;
038:        import java.awt.GridBagLayout;
039:        import java.awt.Insets;
040:        import java.awt.event.ActionEvent;
041:        import java.awt.event.ActionListener;
042:        import java.util.Iterator;
043:
044:        import javax.swing.BorderFactory;
045:        import javax.swing.DefaultListCellRenderer;
046:        import javax.swing.JCheckBox;
047:        import javax.swing.JLabel;
048:        import javax.swing.JList;
049:        import javax.swing.JPanel;
050:        import javax.swing.JScrollPane;
051:        import javax.swing.ListSelectionModel;
052:        import javax.swing.event.ChangeEvent;
053:        import javax.swing.event.ChangeListener;
054:        import javax.swing.event.ListSelectionEvent;
055:        import javax.swing.event.ListSelectionListener;
056:
057:        /**
058:         *  Description of the Class
059:         *
060:         *@author     magicthize
061:         *@created    26 May 2002
062:         */
063:        public class TextStyleOptionsTab extends AbstractOptionsTab implements 
064:                ActionListener, ChangeListener {
065:
066:            private ColorComboBox foreground;
067:            private ColorComboBox background;
068:            private JCheckBox bold, italic;
069:            private JList styles;
070:            private TextStyleModel model;
071:            private boolean adjusting;
072:
073:            /**
074:             *  Constructor for the GlobalOptionsTab object
075:             */
076:            public TextStyleOptionsTab() {
077:                super ("Styles", UIUtil.getCachedIcon(Constants.ICON_TOOL_COLOR));
078:            }
079:
080:            /**
081:             * DOCUMENT ME!
082:             *
083:             * @param context DOCUMENT ME!
084:             */
085:            public void init(GruntspudContext context) {
086:                super .init(context);
087:
088:                setTabToolTipText("Set various color / font styles used in Gruntspud.");
089:                setTabLargeIcon(UIUtil
090:                        .getCachedIcon(Constants.ICON_TOOL_LARGE_COLOR));
091:                setLayout(new BorderLayout());
092:                setTabMnemonic('s');
093:                setTabContext("UI");
094:
095:                try {
096:                    model = (TextStyleModel) context.getTextStyleModel()
097:                            .clone();
098:                } catch (CloneNotSupportedException e1) {
099:                }
100:                styles = new JList(model);
101:                styles.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
102:                styles.setCellRenderer(new StyleListCellRenderer());
103:                styles.getSelectionModel().addListSelectionListener(
104:                        new ListSelectionListener() {
105:                            public void valueChanged(ListSelectionEvent lse) {
106:                                Constants.UI_LOG.debug("Style selected");
107:                                if (!adjusting) {
108:                                    setSettingsForStyle();
109:
110:                                }
111:                            }
112:                        });
113:                JScrollPane stylesScroller = new JScrollPane(styles);
114:                JPanel s = new JPanel(new BorderLayout());
115:                s.add(stylesScroller, BorderLayout.CENTER);
116:                s.setBorder(BorderFactory.createTitledBorder("Styles"));
117:
118:                //
119:                JPanel e = new JPanel(new GridBagLayout());
120:                GridBagConstraints gbc = new GridBagConstraints();
121:                gbc.insets = new Insets(3, 3, 3, 3);
122:                gbc.anchor = GridBagConstraints.WEST;
123:                gbc.fill = GridBagConstraints.HORIZONTAL;
124:                gbc.weightx = 0.0;
125:                UIUtil.jGridBagAdd(e, new JLabel("Foreground"), gbc, 1);
126:                gbc.weightx = 1.0;
127:                UIUtil.jGridBagAdd(e, foreground = new ColorComboBox(true),
128:                        gbc, GridBagConstraints.RELATIVE);
129:                foreground.addChangeListener(this );
130:                gbc.weightx = 0.0;
131:                UIUtil.jGridBagAdd(e, bold = new JCheckBox("Bold"), gbc,
132:                        GridBagConstraints.REMAINDER);
133:                bold.addActionListener(this );
134:                bold.setMnemonic('b');
135:                gbc.weightx = 0.0;
136:                UIUtil.jGridBagAdd(e, new JLabel("Background"), gbc, 1);
137:                gbc.weightx = 1.0;
138:                UIUtil.jGridBagAdd(e, background = new ColorComboBox(true),
139:                        gbc, GridBagConstraints.RELATIVE);
140:                background.addChangeListener(this );
141:                gbc.weightx = 0.0;
142:                UIUtil.jGridBagAdd(e, italic = new JCheckBox("Italic"), gbc,
143:                        GridBagConstraints.REMAINDER);
144:                italic.addActionListener(this );
145:                italic.setMnemonic('i');
146:
147:                add(s, BorderLayout.CENTER);
148:                add(e, BorderLayout.SOUTH);
149:
150:                if (styles.getModel().getSize() > 0)
151:                    styles.setSelectedIndex(0);
152:                setSettingsForStyle();
153:            }
154:
155:            public void actionPerformed(ActionEvent evt) {
156:                if (!adjusting) {
157:                    applySettings();
158:                }
159:            }
160:
161:            private void applySettings() {
162:                Constants.UI_LOG.debug("Applying settings");
163:                TextStyle style = model.getStyleAt(styles.getSelectedIndex());
164:                style.setForeground(foreground.getColor());
165:                style.setBackground(background.getColor());
166:                style.setItalic(italic.isSelected());
167:                style.setBold(bold.isSelected());
168:                model.updateStyle(style);
169:            }
170:
171:            private void setSettingsForStyle() {
172:                adjusting = true;
173:                int idx = styles.getSelectedIndex();
174:                if (idx == -1) {
175:                    foreground.setEnabled(false);
176:                    background.setEnabled(false);
177:                    italic.setEnabled(false);
178:                    bold.setEnabled(false);
179:                    foreground.setColor(null);
180:                    background.setColor(null);
181:                } else {
182:                    TextStyle style = model.getStyleAt(idx);
183:                    foreground.setEnabled(true);
184:                    background.setEnabled(true);
185:                    italic.setEnabled(true);
186:                    bold.setEnabled(true);
187:                    foreground.setColor(style.getForeground());
188:                    background.setColor(style.getBackground());
189:                    italic.setSelected(style.isItalic());
190:                    bold.setSelected(style.isBold());
191:                }
192:                adjusting = false;
193:            }
194:
195:            /**
196:             *  Description of the Method
197:             *
198:             *@return    Description of the Return Value
199:             */
200:            public boolean validateTab() {
201:                return true;
202:            }
203:
204:            /**
205:             *  Description of the Method
206:             */
207:            public void tabSelected() {
208:            }
209:
210:            /**
211:             *  Description of the Method
212:             */
213:            public void applyTab() {
214:                Constants.UI_LOG.debug("Applying new styles");
215:                Iterator j = getContext().getTextStyleModel().styles();
216:                for (Iterator i = model.styles(); i.hasNext();) {
217:                    TextStyle s1 = (TextStyle) j.next();
218:                    TextStyle s2 = (TextStyle) i.next();
219:                    s1.setBackground(s2.getBackground());
220:                    s1.setForeground(s2.getForeground());
221:                    s1.setBold(s2.isBold());
222:                    s1.setItalic(s2.isItalic());
223:                    getContext().getTextStyleModel().updateStyle(s1);
224:                }
225:            }
226:
227:            class StyleListCellRenderer extends DefaultListCellRenderer {
228:
229:                private Color fg;
230:                private ColorIcon backgroundIcon, foregroundIcon;
231:                private CompoundIcon icon;
232:
233:                public StyleListCellRenderer() {
234:                    super ();
235:                    backgroundIcon = new ColorIcon(Color.black, new Dimension(
236:                            12, 12), styles.getForeground());
237:                    foregroundIcon = new ColorIcon(Color.black, new Dimension(
238:                            12, 12), styles.getForeground());
239:                    icon = new CompoundIcon(backgroundIcon, foregroundIcon);
240:                    icon.setGap(4);
241:                    icon.setMargin(new Insets(1, 4, 1, 4));
242:                    setVerticalTextPosition(JLabel.CENTER);
243:                    setVerticalAlignment(JLabel.CENTER);
244:                }
245:
246:                public Component getListCellRendererComponent(JList list,
247:                        Object value, int index, boolean isSelected,
248:                        boolean cellHasFocus) {
249:                    super .getListCellRendererComponent(list, value, index,
250:                            isSelected, cellHasFocus);
251:                    TextStyle style = (TextStyle) value;
252:                    Color bgi = style.getBackground();
253:                    Color fgi = style.getForeground();
254:                    //            if(!isSelected)
255:                    //                setForeground(fgi == null ? styles.getForeground() : fgi);
256:                    backgroundIcon.setColor(bgi);
257:                    foregroundIcon.setColor(fgi);
258:                    setIcon(icon);
259:                    setFont(getFont().deriveFont(
260:                            (style.isBold() ? Font.BOLD : 0)
261:                                    + (style.isItalic() ? Font.ITALIC : 0)));
262:                    return this ;
263:                }
264:            }
265:
266:            /* (non-Javadoc)
267:             * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
268:             */
269:            public void stateChanged(ChangeEvent e) {
270:                if (!adjusting) {
271:                    applySettings();
272:                }
273:            }
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.