Source Code Cross Referenced for LabelStylePanel.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:
033:        package com.vividsolutions.jump.workbench.ui.style;
034:
035:        import java.awt.*;
036:        import java.awt.event.ActionEvent;
037:        import java.awt.geom.Point2D;
038:
039:        import javax.swing.*;
040:        import javax.swing.border.Border;
041:        import javax.swing.event.DocumentEvent;
042:        import javax.swing.event.DocumentListener;
043:
044:        import com.vividsolutions.jts.util.Assert;
045:        import com.vividsolutions.jump.I18N;
046:        import com.vividsolutions.jump.feature.AttributeType;
047:        import com.vividsolutions.jump.feature.Feature;
048:        import com.vividsolutions.jump.feature.FeatureSchema;
049:        import com.vividsolutions.jump.workbench.model.Layer;
050:        import com.vividsolutions.jump.workbench.ui.ErrorHandler;
051:        import com.vividsolutions.jump.workbench.ui.FontChooser;
052:        import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
053:        import com.vividsolutions.jump.workbench.ui.ValidatingTextField;
054:        import com.vividsolutions.jump.workbench.ui.images.IconLoader;
055:        import com.vividsolutions.jump.workbench.ui.renderer.style.LabelStyle;
056:
057:        public class LabelStylePanel extends JPanel implements  StylePanel {
058:            private static final String NONE = "("
059:                    + I18N.get("ui.style.LabelStylePanel.none") + ")";
060:            private BorderLayout borderLayout1 = new BorderLayout();
061:            private GridBagLayout gridBagLayout6 = new GridBagLayout();
062:            private JLabel attributeLabel = new JLabel();
063:            private JComboBox attributeComboBox = new JComboBox();
064:            private JComboBox angleAttributeComboBox = new JComboBox();
065:
066:            public String getTitle() {
067:                return I18N.get("ui.style.LabelStylePanel.labels");
068:            }
069:
070:            public String validateInput() {
071:                return null;
072:            }
073:
074:            private JPanel previewPanel = new JPanel() {
075:                protected void paintComponent(Graphics g) {
076:                    super .paintComponent(g);
077:
078:                    LabelStyle labelStyle = createLabelStyle(layer
079:                            .getLabelStyle());
080:
081:                    if (!labelStyle.isEnabled()) {
082:                        return;
083:                    }
084:
085:                    labelStyle.initialize(layer);
086:                    labelStyle
087:                            .paint(
088:                                    (Graphics2D) g,
089:                                    sampleText(),
090:                                    layerViewPanel.getViewport().getScale(),
091:                                    new Point2D.Double(getWidth() / 2d,
092:                                            getHeight() / 2d),
093:                                    layer.getFeatureCollectionWrapper()
094:                                            .isEmpty() ? 0
095:                                            : LabelStyle
096:                                                    .angle(
097:                                                            (Feature) layer
098:                                                                    .getFeatureCollectionWrapper()
099:                                                                    .iterator()
100:                                                                    .next(),
101:                                                            getAngleAttribute(),
102:                                                            0),
103:                                    layer.getFeatureCollectionWrapper()
104:                                            .isEmpty() ? getLabelHeight()
105:                                            : LabelStyle
106:                                                    .height(
107:                                                            (Feature) layer
108:                                                                    .getFeatureCollectionWrapper()
109:                                                                    .iterator()
110:                                                                    .next(),
111:                                                            getHeightAttribute(),
112:                                                            getLabelHeight()),
113:                                    false);
114:                }
115:            };
116:
117:            private JCheckBox scaleCheckBox = new JCheckBox();
118:            private Layer layer;
119:            private JCheckBox labellingCheckBox = new JCheckBox();
120:            private Border border1;
121:            private LayerViewPanel layerViewPanel;
122:            private JDialog parent;
123:            private Color color;
124:            private Font labelFont;
125:
126:            private ValidatingTextField heightTextField = new ValidatingTextField(
127:                    "999", 7, new ValidatingTextField.Validator() {
128:                        public boolean isValid(String text) {
129:                            if (text.length() == 0) {
130:                                return true;
131:                            }
132:
133:                            try {
134:                                Double.parseDouble(text);
135:
136:                                return true;
137:                            } catch (NumberFormatException e) {
138:                                return false;
139:                            }
140:                        }
141:                    });
142:            private JLabel heightLabel = new JLabel();
143:            private JLabel previewLabel = new JLabel();
144:            private JPanel fillerPanel = new JPanel();
145:            private JPanel buttonPanel = new JPanel();
146:            private GridBagLayout gridBagLayout2 = new GridBagLayout();
147:            private JButton colorButton = new JButton();
148:            private JButton fontButton = new JButton();
149:            private JPanel jPanel3 = new JPanel();
150:            private JLabel verticalAlignmentLabel = new JLabel();
151:            private JComboBox verticalAlignmentComboBox = new JComboBox();
152:            private JLabel angleLabel = new JLabel();
153:            private JCheckBox hideOverlappingLabelsCheckBox = new JCheckBox();
154:            private JLabel heightAttributeLabel = new JLabel();
155:            private JComboBox heightAttributeComboBox = new JComboBox();
156:
157:            public LabelStylePanel(Layer layer, LayerViewPanel layerViewPanel,
158:                    JDialog parent, ErrorHandler errorHandler) {
159:                try {
160:                    this .parent = parent;
161:                    this .layerViewPanel = layerViewPanel;
162:
163:                    //Populate verticalAlignmentComboBox before calling #setLayer so that
164:                    //initially selected item can be properly set. [Jon Aquino]
165:                    verticalAlignmentComboBox.addItem(LabelStyle.ABOVE_LINE);
166:                    verticalAlignmentComboBox.addItem(LabelStyle.ON_LINE);
167:                    verticalAlignmentComboBox.addItem(LabelStyle.BELOW_LINE);
168:
169:                    //Call #setLayer before #jbInit, so no events will be fired. Otherwise,
170:                    //NullPointerExceptions will be thrown. [Jon Aquino]
171:                    setLayer(layer);
172:                    jbInit();
173:                    heightTextField.getDocument().addDocumentListener(
174:                            new DocumentListener() {
175:                                public void insertUpdate(DocumentEvent e) {
176:                                    documentChanged();
177:                                }
178:
179:                                public void removeUpdate(DocumentEvent e) {
180:                                    documentChanged();
181:                                }
182:
183:                                public void changedUpdate(DocumentEvent e) {
184:                                    documentChanged();
185:                                }
186:
187:                                private void documentChanged() {
188:                                    updateControls();
189:                                }
190:                            });
191:                    colorButton.setToolTipText(I18N
192:                            .get("ui.style.LabelStylePanel.browse"));
193:                    fontButton.setToolTipText(I18N
194:                            .get("ui.style.LabelStylePanel.browse"));
195:                    updateControls();
196:                    verticalAlignmentComboBox
197:                            .setRenderer(new ListCellRenderer() {
198:                                private Icon aboveIcon = IconLoader
199:                                        .icon("BigLabelAbove.gif");
200:                                private Icon onIcon = IconLoader
201:                                        .icon("BigLabelOn.gif");
202:                                private Icon belowIcon = IconLoader
203:                                        .icon("BigLabelBelow.gif");
204:                                private DefaultListCellRenderer renderer = new DefaultListCellRenderer();
205:
206:                                public Component getListCellRendererComponent(
207:                                        JList list, Object value, int index,
208:                                        boolean isSelected, boolean cellHasFocus) {
209:                                    JLabel label = (JLabel) renderer
210:                                            .getListCellRendererComponent(list,
211:                                                    "", index, isSelected,
212:                                                    cellHasFocus);
213:                                    label
214:                                            .setIcon(value
215:                                                    .equals(LabelStyle.ABOVE_LINE) ? aboveIcon
216:                                                    : (value
217:                                                            .equals(LabelStyle.ON_LINE) ? onIcon
218:                                                            : belowIcon));
219:
220:                                    return label;
221:                                }
222:                            });
223:                } catch (Throwable t) {
224:                    errorHandler.handleThrowable(t);
225:                }
226:            }
227:
228:            private String sampleText() {
229:                String sampleText = "Abc123";
230:
231:                if (layer.getFeatureCollectionWrapper().isEmpty()) {
232:                    return sampleText;
233:                }
234:
235:                Feature firstFeature = (Feature) layer
236:                        .getFeatureCollectionWrapper().iterator().next();
237:                Object attribute = getLabelAttribute().equals(
238:                        LabelStyle.FID_COLUMN) ? (firstFeature.getID() + "")
239:                        : firstFeature.getAttribute(getLabelAttribute());
240:
241:                if (attribute == null) {
242:                    return sampleText;
243:                }
244:
245:                if (attribute.toString().trim().length() == 0) {
246:                    return sampleText;
247:                }
248:
249:                return attribute.toString().trim();
250:            }
251:
252:            private void setLayer(Layer layer) {
253:                this .layer = layer;
254:                setLabelling(layer.getLabelStyle().isEnabled());
255:                setAttributes(layer.getFeatureCollectionWrapper()
256:                        .getFeatureSchema());
257:                setAttribute(layer.getLabelStyle().getAttribute());
258:                setAngleAttribute(layer.getLabelStyle().getAngleAttribute());
259:                setHeightAttribute(layer.getLabelStyle().getHeightAttribute());
260:                setColor(layer.getLabelStyle().getColor());
261:                setLabelFont(layer.getLabelStyle().getFont());
262:                setScaling(layer.getLabelStyle().isScaling());
263:                hideOverlappingLabelsCheckBox.setSelected(layer.getLabelStyle()
264:                        .isHidingOverlappingLabels());
265:                heightTextField.setText(layer.getLabelStyle().getHeight() + "");
266:                verticalAlignmentComboBox.setSelectedItem(layer.getLabelStyle()
267:                        .getVerticalAlignment());
268:            }
269:
270:            private void setAttributes(FeatureSchema schema) {
271:                attributeComboBox.removeAllItems();
272:                angleAttributeComboBox.removeAllItems();
273:                heightAttributeComboBox.removeAllItems();
274:                attributeComboBox.addItem(LabelStyle.FID_COLUMN);
275:                angleAttributeComboBox.addItem(NONE);
276:                heightAttributeComboBox.addItem(NONE);
277:
278:                for (int i = 0; i < schema.getAttributeCount(); i++) {
279:                    attributeComboBox.addItem(schema.getAttributeName(i));
280:
281:                    if ((schema.getAttributeType(i) == AttributeType.DOUBLE)
282:                            || (schema.getAttributeType(i) == AttributeType.INTEGER)) {
283:                        angleAttributeComboBox.addItem(schema
284:                                .getAttributeName(i));
285:                        heightAttributeComboBox.addItem(schema
286:                                .getAttributeName(i));
287:                    }
288:                }
289:            }
290:
291:            private void setLabelling(boolean labelling) {
292:                labellingCheckBox.setSelected(labelling);
293:            }
294:
295:            private void setColor(Color color) {
296:                this .color = color;
297:            }
298:
299:            private void setAttribute(String attribute) {
300:                Assert.isTrue(!attribute.equals(""));
301:                attributeComboBox.setSelectedItem(attribute);
302:            }
303:
304:            private void setAngleAttribute(String angleAttribute) {
305:                if (angleAttribute.equals("")) {
306:                    angleAttributeComboBox.setSelectedItem(NONE);
307:
308:                    return;
309:                }
310:
311:                angleAttributeComboBox.setSelectedItem(angleAttribute);
312:            }
313:
314:            private void setHeightAttribute(String heightAttribute) {
315:                if (heightAttribute.equals("")) {
316:                    heightAttributeComboBox.setSelectedItem(NONE);
317:
318:                    return;
319:                }
320:
321:                heightAttributeComboBox.setSelectedItem(heightAttribute);
322:            }
323:
324:            private void setLabelFont(Font labelFont) {
325:                this .labelFont = labelFont;
326:            }
327:
328:            private void setScaling(boolean scaling) {
329:                scaleCheckBox.setSelected(scaling);
330:            }
331:
332:            void jbInit() throws Exception {
333:                border1 = BorderFactory.createEmptyBorder(10, 10, 10, 10);
334:                this .setLayout(borderLayout1);
335:                setLayout(gridBagLayout6);
336:                attributeLabel.setText(I18N
337:                        .get("ui.style.LabelStylePanel.label-attribute"));
338:                previewPanel.setBackground(Color.white);
339:                previewPanel
340:                        .setBorder(BorderFactory.createLoweredBevelBorder());
341:                previewPanel.setMaximumSize(new Dimension(200, 40));
342:                previewPanel.setMinimumSize(new Dimension(200, 40));
343:                previewPanel.setPreferredSize(new Dimension(200, 40));
344:                scaleCheckBox
345:                        .setText(I18N
346:                                .get("ui.style.LabelStylePanel.scale-labels-with-the-zoom-level"));
347:                scaleCheckBox
348:                        .addActionListener(new java.awt.event.ActionListener() {
349:                            public void actionPerformed(ActionEvent e) {
350:                                scaleCheckBox_actionPerformed(e);
351:                            }
352:                        });
353:                setBorder(border1);
354:                labellingCheckBox.setText(I18N
355:                        .get("ui.style.LabelStylePanel.enable-labelling"));
356:                labellingCheckBox
357:                        .addActionListener(new java.awt.event.ActionListener() {
358:                            public void actionPerformed(ActionEvent e) {
359:                                enableLabellingCheckBox_actionPerformed(e);
360:                            }
361:                        });
362:                heightLabel
363:                        .setText(I18N.get("ui.style.LabelStylePanel.height"));
364:                attributeComboBox
365:                        .addActionListener(new java.awt.event.ActionListener() {
366:                            public void actionPerformed(ActionEvent e) {
367:                                attributeComboBox_actionPerformed(e);
368:                            }
369:                        });
370:                angleAttributeComboBox
371:                        .addActionListener(new java.awt.event.ActionListener() {
372:                            public void actionPerformed(ActionEvent e) {
373:                                angleAttributeComboBox_actionPerformed(e);
374:                            }
375:                        });
376:                previewLabel
377:                        .setText(I18N
378:                                .get("ui.style.LabelStylePanel.preview-at-current-zoom-level"));
379:                buttonPanel.setLayout(gridBagLayout2);
380:                colorButton.setText(I18N
381:                        .get("ui.style.LabelStylePanel.change-colour"));
382:                colorButton
383:                        .addActionListener(new java.awt.event.ActionListener() {
384:                            public void actionPerformed(ActionEvent e) {
385:                                colorButton_actionPerformed(e);
386:                            }
387:                        });
388:                fontButton.setText(I18N
389:                        .get("ui.style.LabelStylePanel.change-font"));
390:                fontButton
391:                        .addActionListener(new java.awt.event.ActionListener() {
392:                            public void actionPerformed(ActionEvent e) {
393:                                fontButton_actionPerformed(e);
394:                            }
395:                        });
396:                verticalAlignmentLabel
397:                        .setText(I18N
398:                                .get("ui.style.LabelStylePanel.vertical-alignment-for-lines"));
399:                verticalAlignmentComboBox
400:                        .addActionListener(new java.awt.event.ActionListener() {
401:                            public void actionPerformed(ActionEvent e) {
402:                                verticalAlignmentComboBox_actionPerformed(e);
403:                            }
404:                        });
405:                angleLabel
406:                        .setText(I18N
407:                                .get("ui.style.LabelStylePanel.angle-attribute-degrees"));
408:                hideOverlappingLabelsCheckBox
409:                        .setText(I18N
410:                                .get("ui.style.LabelStylePanel.hide-overlapping-labels"));
411:                hideOverlappingLabelsCheckBox
412:                        .addActionListener(new java.awt.event.ActionListener() {
413:                            public void actionPerformed(ActionEvent e) {
414:                                hideOverlappingLabelsCheckBox_actionPerformed(e);
415:                            }
416:                        });
417:                heightAttributeLabel.setText(I18N
418:                        .get("ui.style.LabelStylePanel.height-attribute"));
419:                heightAttributeComboBox
420:                        .addActionListener(new java.awt.event.ActionListener() {
421:                            public void actionPerformed(ActionEvent e) {
422:                                heightAttributeComboBox_actionPerformed(e);
423:                            }
424:                        });
425:                add(attributeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0,
426:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
427:                        new Insets(0, 0, 0, 0), 0, 0));
428:                add(attributeComboBox, new GridBagConstraints(1, 1, 1, 1, 0.0,
429:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
430:                        new Insets(2, 4, 2, 0), 0, 0));
431:                add(angleAttributeComboBox, new GridBagConstraints(1, 3, 1, 1,
432:                        0.0, 0.0, GridBagConstraints.WEST,
433:                        GridBagConstraints.NONE, new Insets(0, 4, 2, 0), 0, 0));
434:                add(previewPanel, new GridBagConstraints(0, 13, 2, 1, 0.0, 0.0,
435:                        GridBagConstraints.WEST, GridBagConstraints.NONE,
436:                        new Insets(0, 10, 4, 4), 0, 0));
437:                add(scaleCheckBox, new GridBagConstraints(0, 9, 2, 1, 0.0, 0.0,
438:                        GridBagConstraints.WEST, GridBagConstraints.NONE,
439:                        new Insets(0, 0, 0, 0), 0, 0));
440:                add(labellingCheckBox, new GridBagConstraints(0, 0, 2, 1, 0.0,
441:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
442:                        new Insets(0, 0, 0, 0), 0, 0));
443:                this .add(heightTextField, new GridBagConstraints(1, 5, 1, 1,
444:                        0.0, 0.0, GridBagConstraints.WEST,
445:                        GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0));
446:                this .add(heightLabel, new GridBagConstraints(0, 5, 1, 1, 0.0,
447:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
448:                        new Insets(0, 0, 0, 0), 0, 0));
449:                this .add(previewLabel, new GridBagConstraints(0, 12, 2, 1, 0.0,
450:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
451:                        new Insets(10, 0, 0, 0), 0, 0));
452:                this .add(fillerPanel, new GridBagConstraints(98, 104, 1, 1,
453:                        1.0, 1.0, GridBagConstraints.CENTER,
454:                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
455:                this .add(buttonPanel, new GridBagConstraints(0, 11, 3, 1, 0.0,
456:                        0.0, GridBagConstraints.WEST,
457:                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
458:                        0, 0));
459:                buttonPanel.add(colorButton, new GridBagConstraints(1, 0, 1, 1,
460:                        0.0, 0.0, GridBagConstraints.CENTER,
461:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
462:                buttonPanel.add(fontButton, new GridBagConstraints(2, 0, 1, 1,
463:                        0.0, 0.0, GridBagConstraints.CENTER,
464:                        GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
465:                buttonPanel.add(jPanel3, new GridBagConstraints(3, 0, 1, 1,
466:                        1.0, 0.0, GridBagConstraints.CENTER,
467:                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
468:                        0, 0));
469:                this .add(verticalAlignmentLabel, new GridBagConstraints(0, 2,
470:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
471:                        GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
472:                this .add(verticalAlignmentComboBox, new GridBagConstraints(1,
473:                        2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
474:                        GridBagConstraints.NONE, new Insets(2, 4, 2, 0), 0, 0));
475:                this .add(angleLabel, new GridBagConstraints(0, 3, 1, 1, 0.0,
476:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
477:                        new Insets(0, 0, 0, 0), 0, 0));
478:                this .add(hideOverlappingLabelsCheckBox, new GridBagConstraints(
479:                        0, 10, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
480:                        GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
481:                this .add(heightAttributeLabel, new GridBagConstraints(0, 4, 1,
482:                        1, 0.0, 0.0, GridBagConstraints.WEST,
483:                        GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
484:                this .add(heightAttributeComboBox, new GridBagConstraints(1, 4,
485:                        1, 1, 0.0, 0.0, GridBagConstraints.WEST,
486:                        GridBagConstraints.NONE, new Insets(2, 4, 2, 0), 0, 0));
487:            }
488:
489:            public void updateStyles() {
490:                boolean firingEvents = layer.getLayerManager().isFiringEvents();
491:                layer.getLayerManager().setFiringEvents(false);
492:
493:                try {
494:                    //
495:                    LabelStyle newLabelStyle = createLabelStyle(layer
496:                            .getLabelStyle());
497:                    layer.removeStyle(layer.getLabelStyle());
498:                    layer.addStyle(newLabelStyle);
499:                } finally {
500:                    layer.getLayerManager().setFiringEvents(firingEvents);
501:                }
502:
503:                layer.fireAppearanceChanged();
504:            }
505:
506:            private String getAngleAttribute() {
507:                if (NONE == angleAttributeComboBox.getSelectedItem()) {
508:                    return "";
509:                }
510:
511:                return (String) angleAttributeComboBox.getSelectedItem();
512:            }
513:
514:            private String getHeightAttribute() {
515:                if (NONE == heightAttributeComboBox.getSelectedItem()) {
516:                    return "";
517:                }
518:
519:                return (String) heightAttributeComboBox.getSelectedItem();
520:            }
521:
522:            private String getLabelAttribute() {
523:                return (String) attributeComboBox.getSelectedItem();
524:            }
525:
526:            public LabelStyle createLabelStyle(LabelStyle defaultValues) {
527:                LabelStyle labelStyle = (LabelStyle) defaultValues.clone();
528:                labelStyle.setEnabled(labellingCheckBox.isSelected());
529:                Assert.isTrue(attributeComboBox.getSelectedIndex() != -1);
530:                labelStyle.setAttribute(getLabelAttribute());
531:                labelStyle.setAngleAttribute(getAngleAttribute());
532:                labelStyle.setHeightAttribute(getHeightAttribute());
533:                labelStyle.setColor(color);
534:                labelStyle.setFont(labelFont);
535:                labelStyle.setScaling(scaleCheckBox.isSelected());
536:                labelStyle
537:                        .setHidingOverlappingLabels(hideOverlappingLabelsCheckBox
538:                                .isSelected());
539:                labelStyle.setHeight(getLabelHeight());
540:                labelStyle
541:                        .setVerticalAlignment((String) verticalAlignmentComboBox
542:                                .getSelectedItem());
543:
544:                return labelStyle;
545:            }
546:
547:            private double getLabelHeight() {
548:                return (heightTextField.getText().length() == 0) ? LabelStyle.FONT_BASE_SIZE
549:                        : Double.parseDouble(heightTextField.getText());
550:            }
551:
552:            public void updateControls() {
553:                previewPanel.repaint();
554:                attributeLabel.setEnabled(labellingCheckBox.isSelected());
555:                angleLabel.setEnabled(labellingCheckBox.isSelected());
556:                heightAttributeLabel.setEnabled(labellingCheckBox.isSelected());
557:                attributeComboBox.setEnabled(labellingCheckBox.isSelected());
558:                angleAttributeComboBox.setEnabled(labellingCheckBox
559:                        .isSelected());
560:                heightAttributeComboBox.setEnabled(labellingCheckBox
561:                        .isSelected());
562:                colorButton.setEnabled(labellingCheckBox.isSelected());
563:                fontButton.setEnabled(labellingCheckBox.isSelected());
564:                heightLabel.setEnabled(labellingCheckBox.isSelected()
565:                        && getHeightAttribute().equals(""));
566:                heightTextField.setEnabled(labellingCheckBox.isSelected()
567:                        && getHeightAttribute().equals(""));
568:                scaleCheckBox.setEnabled(labellingCheckBox.isSelected());
569:                hideOverlappingLabelsCheckBox.setEnabled(labellingCheckBox
570:                        .isSelected());
571:                previewLabel.setEnabled(labellingCheckBox.isSelected());
572:                previewPanel.setEnabled(labellingCheckBox.isSelected());
573:                verticalAlignmentLabel.setEnabled(labellingCheckBox
574:                        .isSelected());
575:                verticalAlignmentComboBox.setEnabled(labellingCheckBox
576:                        .isSelected());
577:            }
578:
579:            void colorButton_actionPerformed(ActionEvent e) {
580:                Color newColor = JColorChooser.showDialog(this , I18N
581:                        .get("ui.style.LabelStylePanel.choose-colour"), color);
582:
583:                if (newColor == null) {
584:                    return;
585:                }
586:
587:                setColor(newColor);
588:                updateControls();
589:            }
590:
591:            void fontButton_actionPerformed(ActionEvent e) {
592:                Font newFont = FontChooser
593:                        .showDialog(parent, I18N
594:                                .get("ui.style.LabelStylePanel.choose-font"),
595:                                labelFont);
596:
597:                if (newFont == null) {
598:                    return;
599:                }
600:
601:                setLabelFont(newFont);
602:                updateControls();
603:            }
604:
605:            void enableLabellingCheckBox_actionPerformed(ActionEvent e) {
606:                updateControls();
607:            }
608:
609:            void attributeComboBox_actionPerformed(ActionEvent e) {
610:                updateControls();
611:            }
612:
613:            void angleAttributeComboBox_actionPerformed(ActionEvent e) {
614:                updateControls();
615:            }
616:
617:            void scaleCheckBox_actionPerformed(ActionEvent e) {
618:                updateControls();
619:            }
620:
621:            void verticalAlignmentComboBox_actionPerformed(ActionEvent e) {
622:                updateControls();
623:            }
624:
625:            void hideOverlappingLabelsCheckBox_actionPerformed(ActionEvent e) {
626:                updateControls();
627:            }
628:
629:            void heightAttributeComboBox_actionPerformed(ActionEvent e) {
630:                updateControls();
631:            }
632:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.