Source Code Cross Referenced for BasicStylePanel.java in  » GIS » openjump » com » vividsolutions » jump » workbench » ui » 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 » GIS » openjump » com.vividsolutions.jump.workbench.ui.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003:         * for visualizing and manipulating spatial features with geometry and attributes.
004:         *
005:         * Copyright (C) 2003 Vivid Solutions
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
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 General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         *
021:         * For more information, contact:
022:         *
023:         * Vivid Solutions
024:         * Suite #1A
025:         * 2328 Government Street
026:         * Victoria BC  V8T 5G5
027:         * Canada
028:         *
029:         * (250)385-6040
030:         * www.vividsolutions.com
031:         */
032:        package com.vividsolutions.jump.workbench.ui.style;
033:
034:        import java.awt.*;
035:        import java.awt.event.ActionEvent;
036:        import java.awt.event.ActionListener;
037:        import java.awt.geom.Line2D;
038:        import java.awt.geom.Rectangle2D;
039:        import java.util.ArrayList;
040:        import java.util.Collection;
041:        import java.util.Iterator;
042:        import java.util.StringTokenizer;
043:
044:        import javax.swing.*;
045:        import javax.swing.event.ChangeEvent;
046:        import javax.swing.event.ChangeListener;
047:        import javax.swing.event.DocumentEvent;
048:        import javax.swing.event.DocumentListener;
049:        import javax.swing.plaf.basic.BasicComboBoxEditor;
050:
051:        import com.vividsolutions.jts.util.Assert;
052:        import com.vividsolutions.jump.I18N;
053:        import com.vividsolutions.jump.util.Blackboard;
054:        import com.vividsolutions.jump.util.CollectionUtil;
055:        import com.vividsolutions.jump.util.StringUtil;
056:        import com.vividsolutions.jump.workbench.ui.ColorChooserPanel;
057:        import com.vividsolutions.jump.workbench.ui.GUIUtil;
058:        import com.vividsolutions.jump.workbench.ui.TransparencyPanel;
059:        import com.vividsolutions.jump.workbench.ui.ValidatingTextField;
060:        import com.vividsolutions.jump.workbench.ui.renderer.style.BasicFillPattern;
061:        import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
062:        import com.vividsolutions.jump.workbench.ui.renderer.style.FillPatternFactory;
063:
064:        public class BasicStylePanel extends JPanel {
065:            protected static final int SLIDER_TEXT_FIELD_COLUMNS = 3;
066:            protected static final Dimension SLIDER_DIMENSION = new Dimension(
067:                    130, 49);
068:            private Paint[] fillPatterns = new FillPatternFactory()
069:                    .createFillPatterns();
070:            protected JPanel centerPanel = new JPanel();
071:            private AbstractPalettePanel palettePanel;
072:            protected JCheckBox fillCheckBox = new JCheckBox();
073:            protected JCheckBox lineCheckBox = new JCheckBox();
074:            protected TransparencyPanel transparencyPanel = new TransparencyPanel();
075:            protected JLabel transparencyLabel = new JLabel();
076:            protected ColorChooserPanel lineColorChooserPanel = new ColorChooserPanel();
077:            protected ColorChooserPanel fillColorChooserPanel = new ColorChooserPanel();
078:            protected JLabel lineWidthLabel = new JLabel();
079:            protected JCheckBox synchronizeCheckBox = new JCheckBox();
080:            private JCheckBox linePatternCheckBox = new JCheckBox();
081:            private JCheckBox fillPatternCheckBox = new JCheckBox();
082:            private String[] linePatterns = new String[] { "1", "3", "5",
083:                    "5,1", "7", "7,12", "9", "9,2", "15,6", "20,3" };
084:            private JComboBox linePatternComboBox = new JComboBox(linePatterns) {
085:
086:                {
087:                    final ValidatingTextField.Cleaner cleaner = new ValidatingTextField.Cleaner() {
088:                        public String clean(String text) {
089:                            String pattern = "";
090:                            StringTokenizer tokenizer = new StringTokenizer(
091:                                    StringUtil.replaceAll(text, ",", " "));
092:
093:                            while (tokenizer.hasMoreTokens()) {
094:                                pattern += (tokenizer.nextToken() + " ");
095:                            }
096:
097:                            return StringUtil.replaceAll(pattern.trim(), " ",
098:                                    ",");
099:                        }
100:                    };
101:
102:                    BasicComboBoxEditor editor = new BasicComboBoxEditor();
103:                    setEditor(editor);
104:                    setEditable(true);
105:                    addActionListener(new ActionListener() {
106:                        public void actionPerformed(ActionEvent e) {
107:                            updateControls();
108:                        }
109:                    });
110:                    ValidatingTextField.installValidationBehavior(
111:                            (JTextField) editor.getEditorComponent(),
112:                            new ValidatingTextField.Validator() {
113:                                public boolean isValid(String text) {
114:                                    try {
115:                                        BasicStyle.toArray(cleaner.clean(text),
116:                                                1);
117:
118:                                        return true;
119:                                    } catch (Exception e) {
120:                                        return false;
121:                                    }
122:                                }
123:                            }, cleaner);
124:                    ((JTextField) editor.getEditorComponent()).getDocument()
125:                            .addDocumentListener(new DocumentListener() {
126:                                public void changedUpdate(DocumentEvent e) {
127:                                    updateControls();
128:                                }
129:
130:                                public void insertUpdate(DocumentEvent e) {
131:                                    updateControls();
132:                                }
133:
134:                                public void removeUpdate(DocumentEvent e) {
135:                                    updateControls();
136:                                }
137:                            });
138:                    setRenderer(new ListCellRenderer() {
139:                        private JPanel panel = new JPanel() {
140:                            private int lineWidth = 2;
141:
142:                            protected void paintComponent(Graphics g) {
143:                                super .paintComponent(g);
144:
145:                                Graphics2D g2 = (Graphics2D) g;
146:                                g2.setStroke(new BasicStroke(lineWidth,
147:                                        BasicStroke.CAP_BUTT,
148:                                        BasicStroke.JOIN_BEVEL, 1.0f,
149:                                        BasicStyle.toArray(linePattern,
150:                                                lineWidth), 0));
151:                                g2.draw(new Line2D.Double(0,
152:                                        panel.getHeight() / 2.0, panel
153:                                                .getWidth(),
154:                                        panel.getHeight() / 2.0));
155:                            }
156:                        };
157:
158:                        private String linePattern;
159:
160:                        public Component getListCellRendererComponent(
161:                                JList list, Object value, int index,
162:                                boolean isSelected, boolean cellHasFocus) {
163:                            linePattern = (String) value;
164:                            panel
165:                                    .setForeground(UIManager
166:                                            .getColor(isSelected ? "ComboBox.selectionForeground"
167:                                                    : "ComboBox.foreground"));
168:                            panel
169:                                    .setBackground(UIManager
170:                                            .getColor(isSelected ? "ComboBox.selectionBackground"
171:                                                    : "ComboBox.background"));
172:
173:                            return panel;
174:                        }
175:                    });
176:                }
177:            };
178:
179:            private JComboBox fillPatternComboBox = new JComboBox(fillPatterns) {
180:
181:                {
182:                    setMaximumRowCount(24);
183:                    setEditable(false);
184:                    addActionListener(new ActionListener() {
185:                        public void actionPerformed(ActionEvent e) {
186:                            updateControls();
187:                        }
188:                    });
189:                    setRenderer(new ListCellRenderer() {
190:                        private Paint fillPattern;
191:                        private JLabel label = new JLabel(" ");
192:                        private JPanel panel = new JPanel(new BorderLayout()) {
193:
194:                            {
195:                                label.setPreferredSize(new Dimension(150,
196:                                        (int) label.getPreferredSize()
197:                                                .getHeight()));
198:                                add(label, BorderLayout.CENTER);
199:                            }
200:
201:                            protected void paintComponent(Graphics g) {
202:                                super .paintComponent(g);
203:                                ((Graphics2D) g).setPaint(fillPattern);
204:                                ((Graphics2D) g).fill(new Rectangle2D.Double(0,
205:                                        0, getWidth(), getHeight()));
206:                            }
207:                        };
208:
209:                        public Component getListCellRendererComponent(
210:                                JList list, Object value, int index,
211:                                boolean isSelected, boolean cellHasFocus) {
212:                            fillPattern = (Paint) value;
213:                            label.setText(""
214:                                    + (1 + CollectionUtil.indexOf(fillPattern,
215:                                            fillPatterns)));
216:                            label
217:                                    .setForeground(UIManager
218:                                            .getColor(isSelected ? "ComboBox.selectionForeground"
219:                                                    : "ComboBox.foreground"));
220:                            panel
221:                                    .setBackground(UIManager
222:                                            .getColor(isSelected ? "ComboBox.selectionBackground"
223:                                                    : "ComboBox.background"));
224:
225:                            return panel;
226:                        }
227:                    });
228:                }
229:            };
230:
231:            protected JSlider lineWidthSlider = new JSlider() {
232:
233:                {
234:                    addChangeListener(new ChangeListener() {
235:                        public void stateChanged(ChangeEvent e) {
236:                            updateControls();
237:                        }
238:                    });
239:                }
240:            };
241:
242:            private Blackboard blackboard;
243:
244:            /**
245:             * Parameterless constructor for JBuilder GUI designer.
246:             */
247:            public BasicStylePanel() {
248:                this (null, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
249:            }
250:
251:            public BasicStylePanel(Blackboard blackboard,
252:                    int palettePanelVerticalScrollBarPolicy) {
253:                this .blackboard = blackboard;
254:                palettePanel = new ListPalettePanel(
255:                        palettePanelVerticalScrollBarPolicy);
256:
257:                try {
258:                    jbInit();
259:                } catch (Exception e) {
260:                    e.printStackTrace(System.err);
261:                    Assert.shouldNeverReachHere();
262:                }
263:
264:                transparencyPanel.getSlider().getModel().addChangeListener(
265:                        new ChangeListener() {
266:                            public void stateChanged(ChangeEvent e) {
267:                                updateControls();
268:                            }
269:                        });
270:                palettePanel.add(new GridPalettePanel.Listener() {
271:                    public void basicStyleChosen(BasicStyle basicStyle) {
272:                        //Preserve some settings e.g. line and fill patterns, alpha;
273:                        BasicStyle newBasicStyle = getBasicStyle();
274:                        newBasicStyle.setFillColor(basicStyle.getFillColor());
275:                        newBasicStyle.setLineColor(basicStyle.getLineColor());
276:                        newBasicStyle.setLineWidth(basicStyle.getLineWidth());
277:                        newBasicStyle.setLinePattern(basicStyle
278:                                .getLinePattern());
279:                        newBasicStyle.setRenderingLinePattern(basicStyle
280:                                .isRenderingLinePattern());
281:                        newBasicStyle.setRenderingFill(basicStyle
282:                                .isRenderingFill());
283:                        newBasicStyle.setRenderingLine(basicStyle
284:                                .isRenderingLine());
285:                        setBasicStyle(newBasicStyle);
286:                    }
287:                });
288:                updateControls();
289:            }
290:
291:            /**
292:             * Remove extra commas
293:             */
294:            private String clean(String linePattern) {
295:                String pattern = "";
296:                StringTokenizer tokenizer = new StringTokenizer(StringUtil
297:                        .replaceAll(linePattern, ",", " "));
298:
299:                while (tokenizer.hasMoreTokens()) {
300:                    pattern += (tokenizer.nextToken() + " ");
301:                }
302:
303:                return StringUtil.replaceAll(pattern.trim(), " ", ",");
304:            }
305:
306:            //UT made it protected for testing
307:            protected void jbInit() throws Exception {
308:                lineWidthSlider.setPreferredSize(SLIDER_DIMENSION);
309:                lineWidthSlider.setPaintLabels(true);
310:                lineWidthSlider.setValue(1);
311:                lineWidthSlider.setLabelTable(lineWidthSlider
312:                        .createStandardLabels(10));
313:                lineWidthSlider.setMajorTickSpacing(5);
314:                lineWidthSlider.setMaximum(30);
315:                lineWidthSlider.setMinorTickSpacing(1);
316:                setLayout(new GridBagLayout());
317:                linePatternCheckBox.setText(I18N
318:                        .get("ui.style.BasicStylePanel.line-pattern"));
319:                fillPatternCheckBox.setText(I18N
320:                        .get("ui.style.BasicStylePanel.fill-pattern"));
321:                linePatternCheckBox
322:                        .addActionListener(new java.awt.event.ActionListener() {
323:                            public void actionPerformed(ActionEvent e) {
324:                                linePatternCheckBox_actionPerformed(e);
325:                            }
326:                        });
327:                fillPatternCheckBox
328:                        .addActionListener(new java.awt.event.ActionListener() {
329:                            public void actionPerformed(ActionEvent e) {
330:                                fillPatternCheckBox_actionPerformed(e);
331:                            }
332:                        });
333:                add(centerPanel, new GridBagConstraints(0, 0, 1, 2, 0, 0,
334:                        GridBagConstraints.WEST, GridBagConstraints.NONE,
335:                        new Insets(2, 2, 2, 2), 0, 0));
336:                add(new JPanel(), new GridBagConstraints(3, 0, 1, 1, 1, 0,
337:                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
338:                        new Insets(2, 2, 2, 2), 0, 0));
339:                add(new JLabel(I18N.get("ui.style.BasicStylePanel.presets")),
340:                        new GridBagConstraints(2, 0, 1, 1, 0, 0,
341:                                GridBagConstraints.WEST,
342:                                GridBagConstraints.NONE,
343:                                new Insets(0, 30, 0, 0), 0, 0));
344:                add(palettePanel, new GridBagConstraints(2, 1, 1, 1, 0, 1,
345:                        GridBagConstraints.WEST, GridBagConstraints.VERTICAL,
346:                        new Insets(0, 30, 0, 0), 0, 0));
347:                centerPanel.setLayout(new GridBagLayout());
348:                setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
349:                fillColorChooserPanel
350:                        .addActionListener(new java.awt.event.ActionListener() {
351:                            public void actionPerformed(ActionEvent e) {
352:                                fillColorChooserPanel_actionPerformed(e);
353:                            }
354:                        });
355:                lineColorChooserPanel
356:                        .addActionListener(new java.awt.event.ActionListener() {
357:                            public void actionPerformed(ActionEvent e) {
358:                                lineColorChooserPanel_actionPerformed(e);
359:                            }
360:                        });
361:                synchronizeCheckBox
362:                        .setText(I18N
363:                                .get("ui.style.BasicStylePanel.sync-line-colour-with-fill-colour"));
364:                synchronizeCheckBox
365:                        .addActionListener(new java.awt.event.ActionListener() {
366:                            public void actionPerformed(ActionEvent e) {
367:                                synchronizeCheckBox_actionPerformed(e);
368:                            }
369:                        });
370:                fillCheckBox.setText(I18N.get("ui.style.BasicStylePanel.fill"));
371:                fillCheckBox
372:                        .addActionListener(new java.awt.event.ActionListener() {
373:                            public void actionPerformed(ActionEvent e) {
374:                                fillCheckBox_actionPerformed(e);
375:                            }
376:                        });
377:                lineCheckBox.setText(I18N.get("ui.style.BasicStylePanel.line"));
378:                lineCheckBox
379:                        .addActionListener(new java.awt.event.ActionListener() {
380:                            public void actionPerformed(ActionEvent e) {
381:                                lineCheckBox_actionPerformed(e);
382:                            }
383:                        });
384:                centerPanel.add(GUIUtil.createSyncdTextField(transparencyPanel
385:                        .getSlider(), SLIDER_TEXT_FIELD_COLUMNS),
386:                        new GridBagConstraints(2, 21, 1, 1, 0.0, 0.0,
387:                                GridBagConstraints.CENTER,
388:                                GridBagConstraints.NONE,
389:                                new Insets(2, 2, 2, 2), 0, 0));
390:                centerPanel.add(lineWidthSlider, new GridBagConstraints(1, 19,
391:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
392:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
393:                centerPanel.add(GUIUtil.createSyncdTextField(lineWidthSlider,
394:                        SLIDER_TEXT_FIELD_COLUMNS), new GridBagConstraints(2,
395:                        19, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
396:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
397:                fillColorChooserPanel
398:                        .addActionListener(new java.awt.event.ActionListener() {
399:                            public void actionPerformed(ActionEvent e) {
400:                                fillColorChooserPanel_actionPerformed(e);
401:                            }
402:                        });
403:                lineWidthLabel.setText(I18N
404:                        .get("ui.style.BasicStylePanel.line-width"));
405:                transparencyLabel.setText(I18N
406:                        .get("ui.style.BasicStylePanel.transparency"));
407:                centerPanel.add(synchronizeCheckBox, new GridBagConstraints(0,
408:                        18, 3, 1, 0.0, 0.0, GridBagConstraints.WEST,
409:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
410:                centerPanel.add(transparencyLabel, new GridBagConstraints(0,
411:                        21, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
412:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
413:                centerPanel.add(fillColorChooserPanel, new GridBagConstraints(
414:                        1, 5, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
415:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
416:                centerPanel.add(lineColorChooserPanel, new GridBagConstraints(
417:                        1, 11, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
418:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
419:                centerPanel.add(transparencyPanel, new GridBagConstraints(1,
420:                        21, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
421:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
422:                centerPanel.add(fillCheckBox, new GridBagConstraints(0, 5, 1,
423:                        1, 0.0, 0.0, GridBagConstraints.WEST,
424:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
425:                centerPanel.add(lineCheckBox, new GridBagConstraints(0, 11, 1,
426:                        1, 0.0, 0.0, GridBagConstraints.WEST,
427:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
428:                centerPanel.add(lineWidthLabel, new GridBagConstraints(0, 19,
429:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
430:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
431:                centerPanel.add(linePatternCheckBox, new GridBagConstraints(0,
432:                        16, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
433:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
434:                centerPanel.add(fillPatternCheckBox, new GridBagConstraints(0,
435:                        7, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
436:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
437:                centerPanel.add(linePatternComboBox, new GridBagConstraints(1,
438:                        16, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
439:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
440:                centerPanel.add(fillPatternComboBox, new GridBagConstraints(1,
441:                        7, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
442:                        GridBagConstraints.NONE, new Insets(2, 2, 0, 2), 0, 0));
443:            }
444:
445:            public JSlider getTransparencySlider() {
446:                return transparencyPanel.getSlider();
447:            }
448:
449:            protected void setAlpha(int alpha) {
450:                transparencyPanel.getSlider().setValue(255 - alpha);
451:            }
452:
453:            protected int getAlpha() {
454:                return 255 - transparencyPanel.getSlider().getValue();
455:            }
456:
457:            public void setBasicStyle(BasicStyle basicStyle) {
458:                addCustomFillPatterns();
459:                fillColorChooserPanel.setColor(basicStyle.getFillColor());
460:                lineColorChooserPanel.setColor(basicStyle.getLineColor());
461:                setAlpha(basicStyle.getAlpha());
462:                fillCheckBox.setSelected(basicStyle.isRenderingFill());
463:                lineCheckBox.setSelected(basicStyle.isRenderingLine());
464:                lineWidthSlider.setValue(basicStyle.getLineWidth());
465:                linePatternCheckBox.setSelected(basicStyle
466:                        .isRenderingLinePattern());
467:                fillPatternCheckBox.setSelected(basicStyle
468:                        .isRenderingFillPattern());
469:                linePatternComboBox
470:                        .setSelectedItem(basicStyle.getLinePattern());
471:
472:                //Update fill pattern colors before finding the basic style's current fill
473:                //pattern in the combobox. [Jon Aquino]
474:                updateFillPatternColors();
475:
476:                //Because fillPatternComboBox is not editable, we must use findEquivalentItem,
477:                //otherwise the combobox gets confused and a stack overflow occurs
478:                //if the two items are equal but not == . [Jon Aquino]
479:
480:                Object fill = findEquivalentItem(basicStyle.getFillPattern(),
481:                        fillPatternComboBox);
482:
483:                if (fill != null)
484:                    fillPatternComboBox.setSelectedItem(fill);
485:
486:                updateControls();
487:            }
488:
489:            private void addCustomFillPatterns() {
490:                for (Iterator i = ((Collection) blackboard.get(
491:                        FillPatternFactory.CUSTOM_FILL_PATTERNS_KEY,
492:                        new ArrayList())).iterator(); i.hasNext();) {
493:                    Paint fillPattern = (Paint) i.next();
494:
495:                    if (null == findEquivalentItem(fillPattern,
496:                            fillPatternComboBox)) {
497:                        //Clone it because several BasicStylePanels access the collection of
498:                        //custom fill patterns [Jon Aquino]
499:                        ((DefaultComboBoxModel) fillPatternComboBox.getModel())
500:                                .addElement(cloneIfBasicFillPattern(fillPattern));
501:                    }
502:                }
503:            }
504:
505:            private Object findEquivalentItem(Object item, JComboBox comboBox) {
506:
507:                if (comboBox == null)
508:                    return null;
509:
510:                if (item == null) {
511:                    return comboBox.getItemCount() > 0 ? comboBox.getItemAt(0)
512:                            : null;
513:                }
514:
515:                for (int i = 0; i < comboBox.getItemCount(); i++) {
516:                    if (item.equals(comboBox.getItemAt(i))) {
517:                        return comboBox.getItemAt(i);
518:                    }
519:                }
520:
521:                return null;
522:            }
523:
524:            public BasicStyle getBasicStyle() {
525:                BasicStyle basicStyle = new BasicStyle();
526:                basicStyle.setFillColor(fillColorChooserPanel.getColor());
527:                basicStyle.setLineColor(lineColorChooserPanel.getColor());
528:                basicStyle.setAlpha(getAlpha());
529:                basicStyle.setRenderingFill(fillCheckBox.isSelected());
530:                basicStyle.setRenderingLine(lineCheckBox.isSelected());
531:                basicStyle.setRenderingLinePattern(linePatternCheckBox
532:                        .isSelected());
533:                basicStyle.setRenderingFillPattern(fillPatternCheckBox
534:                        .isSelected());
535:                basicStyle.setLinePattern(clean((String) linePatternComboBox
536:                        .getEditor().getItem()));
537:                basicStyle
538:                        .setFillPattern(cloneIfBasicFillPattern((Paint) fillPatternComboBox
539:                                .getSelectedItem()));
540:                basicStyle.setLineWidth(lineWidthSlider.getValue());
541:
542:                return basicStyle;
543:            }
544:
545:            private Paint cloneIfBasicFillPattern(Paint fillPattern) {
546:                return (fillPattern instanceof  BasicFillPattern) ? (Paint) ((BasicFillPattern) fillPattern)
547:                        .clone()
548:                        : fillPattern;
549:            }
550:
551:            protected void setFillColor(Color newColor) {
552:                fillColorChooserPanel.setColor(newColor);
553:                transparencyPanel.setColor(newColor);
554:            }
555:
556:            protected void updateControls() {
557:                linePatternComboBox
558:                        .setEnabled(linePatternCheckBox.isSelected());
559:                fillPatternComboBox
560:                        .setEnabled(fillPatternCheckBox.isSelected());
561:                lineColorChooserPanel.setEnabled(lineCheckBox.isSelected());
562:                fillColorChooserPanel.setEnabled(fillCheckBox.isSelected());
563:                fillColorChooserPanel.setAlpha(getAlpha());
564:                lineColorChooserPanel.setAlpha(getAlpha());
565:                palettePanel.setAlpha(getAlpha());
566:                transparencyPanel
567:                        .setColor((lineCheckBox.isSelected() && !fillCheckBox
568:                                .isSelected()) ? lineColorChooserPanel
569:                                .getColor() : fillColorChooserPanel.getColor());
570:                updateFillPatternColors();
571:                fillPatternComboBox.repaint();
572:            }
573:
574:            private void updateFillPatternColors() {
575:                //Iterate through combo box contents rather than fillPatterns field, because
576:                //the combo box contents = fillPatterns + customFillPatterns [Jon Aquino]
577:                for (int i = 0; i < fillPatternComboBox.getItemCount(); i++) {
578:                    if (fillPatternComboBox.getItemAt(i) instanceof  BasicFillPattern) {
579:                        ((BasicFillPattern) fillPatternComboBox.getItemAt(i))
580:                                .setColor(GUIUtil.alphaColor(
581:                                        fillColorChooserPanel.getColor(),
582:                                        getAlpha()));
583:                    }
584:                }
585:            }
586:
587:            void fillCheckBox_actionPerformed(ActionEvent e) {
588:                updateControls();
589:            }
590:
591:            void fillColorChooserPanel_actionPerformed(ActionEvent e) {
592:                if (synchronizeCheckBox.isSelected()) {
593:                    syncLineColor();
594:                }
595:
596:                updateControls();
597:            }
598:
599:            private void syncLineColor() {
600:                lineColorChooserPanel.setColor(fillColorChooserPanel.getColor()
601:                        .darker());
602:            }
603:
604:            void lineColorChooserPanel_actionPerformed(ActionEvent e) {
605:                if (synchronizeCheckBox.isSelected()) {
606:                    fillColorChooserPanel.setColor(lineColorChooserPanel
607:                            .getColor().brighter());
608:                }
609:
610:                updateControls();
611:            }
612:
613:            void lineCheckBox_actionPerformed(ActionEvent e) {
614:                updateControls();
615:            }
616:
617:            public void setSynchronizingLineColor(
618:                    boolean newSynchronizingLineColor) {
619:                synchronizeCheckBox.setSelected(newSynchronizingLineColor);
620:            }
621:
622:            protected void synchronizeCheckBox_actionPerformed(ActionEvent e) {
623:                if (synchronizeCheckBox.isSelected()) {
624:                    syncLineColor();
625:                }
626:
627:                updateControls();
628:            }
629:
630:            public JCheckBox getSynchronizeCheckBox() {
631:                return synchronizeCheckBox;
632:            }
633:
634:            void linePatternCheckBox_actionPerformed(ActionEvent e) {
635:                updateControls();
636:            }
637:
638:            void fillPatternCheckBox_actionPerformed(ActionEvent e) {
639:                updateControls();
640:            }
641:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.