Source Code Cross Referenced for SVGImageEditorElement.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » midpnb » propertyeditors » 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 » IDE Netbeans » vmd.analyzer » org.netbeans.modules.vmd.midpnb.propertyeditors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.vmd.midpnb.propertyeditors;
043:
044:        import java.awt.BorderLayout;
045:        import java.io.File;
046:        import java.io.FileNotFoundException;
047:        import java.io.IOException;
048:        import java.io.InputStream;
049:        import java.util.ArrayList;
050:        import java.util.Arrays;
051:        import java.util.Collections;
052:        import java.util.HashMap;
053:        import java.util.Iterator;
054:        import java.util.List;
055:        import java.util.Map;
056:        import java.util.Map.Entry;
057:        import java.util.concurrent.atomic.AtomicBoolean;
058:        import javax.swing.DefaultComboBoxModel;
059:        import javax.microedition.m2g.SVGImage;
060:        import javax.swing.*;
061:        import javax.swing.filechooser.FileFilter;
062:        import org.netbeans.api.project.Project;
063:        import org.netbeans.modules.mobility.svgcore.util.Util;
064:        import org.netbeans.modules.vmd.api.io.ProjectUtils;
065:        import org.netbeans.modules.vmd.api.model.Debug;
066:        import org.netbeans.modules.vmd.api.model.DesignComponent;
067:        import org.netbeans.modules.vmd.api.model.DesignDocument;
068:        import org.netbeans.modules.vmd.api.model.PropertyValue;
069:        import org.netbeans.modules.vmd.api.model.TypeID;
070:        import org.netbeans.modules.vmd.api.model.common.ActiveDocumentSupport;
071:        import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
072:        import org.netbeans.modules.vmd.midp.components.MidpTypes;
073:        import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.element.PropertyEditorResourceElement;
074:        import org.netbeans.modules.vmd.midp.propertyeditors.api.usercode.PropertyEditorMessageAwareness;
075:        import org.netbeans.modules.vmd.midpnb.components.svg.SVGImageCD;
076:        import org.netbeans.modules.vmd.midpnb.components.svg.SVGMenuCD;
077:        import org.netbeans.modules.vmd.midpnb.components.svg.util.SVGUtils;
078:        import org.netbeans.modules.vmd.midpnb.screen.display.SVGImageComponent;
079:        import org.openide.DialogDisplayer;
080:        import org.openide.NotifyDescriptor;
081:        import org.openide.filesystems.FileObject;
082:        import org.openide.filesystems.FileUtil;
083:        import org.openide.util.NbBundle;
084:
085:        /**
086:         *
087:         * @author Anton Chechel
088:         */
089:        public class SVGImageEditorElement extends
090:                PropertyEditorResourceElement implements  Runnable {
091:
092:            private static final String EXTENSION = "svg"; // NOI18N
093:            private long componentID;
094:            private boolean doNotFireEvent;
095:            private Project project;
096:            private String lastDir;
097:            private SVGImageComponent imageView;
098:            private DefaultComboBoxModel comboBoxModel;
099:            private Map<String, FileObject> paths;
100:            private final AtomicBoolean requiresModelUpdate = new AtomicBoolean(
101:                    false);
102:            private DesignComponentWrapper wrapper;
103:            private PropertyEditorMessageAwareness messageAwareness;
104:
105:            public SVGImageEditorElement() {
106:                paths = new HashMap<String, FileObject>();
107:                comboBoxModel = new DefaultComboBoxModel();
108:                initComponents();
109:                progressBar.setVisible(false);
110:                imageView = new SVGImageComponent();
111:                previewPanel.add(imageView, BorderLayout.CENTER);
112:            }
113:
114:            @Override
115:            public void setPropertyEditorMessageAwareness(
116:                    PropertyEditorMessageAwareness messageAwareness) {
117:                this .messageAwareness = messageAwareness;
118:            }
119:
120:            public JComponent getJComponent() {
121:                return this ;
122:            }
123:
124:            public TypeID getTypeID() {
125:                return SVGImageCD.TYPEID;
126:            }
127:
128:            public List<String> getPropertyValueNames() {
129:                return Arrays.asList(SVGImageCD.PROP_RESOURCE_PATH);
130:            }
131:
132:            public void setDesignComponentWrapper(
133:                    final DesignComponentWrapper wrapper) {
134:                this .wrapper = wrapper;
135:                DesignDocument document = ActiveDocumentSupport.getDefault()
136:                        .getActiveDocument();
137:                if (document != null) {
138:                    project = ProjectUtils.getProject(document);
139:                }
140:
141:                if (wrapper == null) {
142:                    // UI stuff
143:                    setText(null);
144:                    setAllEnabled(false);
145:                    return;
146:                }
147:
148:                this .componentID = wrapper.getComponentID();
149:                final String[] _pathText = new String[1];
150:
151:                final DesignComponent component = wrapper.getComponent();
152:                if (component != null) {
153:                    // existing component
154:                    if (!component.getType().equals(getTypeID())) {
155:                        throw new IllegalArgumentException(
156:                                "Passed component must have typeID "
157:                                        + getTypeID() + " instead passed "
158:                                        + component.getType()); // NOI18N
159:                    }
160:
161:                    this .componentID = component.getComponentID();
162:                    component.getDocument().getTransactionManager().readAccess(
163:                            new Runnable() {
164:
165:                                public void run() {
166:                                    PropertyValue propertyValue = component
167:                                            .readProperty(SVGImageCD.PROP_RESOURCE_PATH);
168:                                    if (!isPropertyValueAUserCodeType(propertyValue)) {
169:                                        _pathText[0] = MidpTypes
170:                                                .getString(propertyValue);
171:                                    }
172:                                }
173:                            });
174:                }
175:
176:                if (wrapper.hasChanges()) {
177:                    Map<String, PropertyValue> changes = wrapper.getChanges();
178:                    for (String propertyName : changes.keySet()) {
179:                        final PropertyValue propertyValue = changes
180:                                .get(propertyName);
181:                        if (SVGImageCD.PROP_RESOURCE_PATH.equals(propertyName)) {
182:                            _pathText[0] = MidpTypes.getString(propertyValue);
183:                        }
184:                    }
185:                }
186:
187:                // UI stuff
188:                setAllEnabled(true);
189:                setText(_pathText[0]);
190:            }
191:
192:            @Override
193:            public boolean isPostSetValueSupported(
194:                    final DesignComponent component) {
195:                final boolean[] retValue = new boolean[1];
196:                component.getDocument().getTransactionManager().readAccess(
197:                        new Runnable() {
198:
199:                            public void run() {
200:                                retValue[0] = component.getDocument()
201:                                        .getDescriptorRegistry().isInHierarchy(
202:                                                SVGMenuCD.TYPEID,
203:                                                component.getType())
204:                                        && component.readProperty(
205:                                                SVGMenuCD.PROP_ELEMENTS)
206:                                                .getArray().size() == 0;
207:                            }
208:                        });
209:
210:                return retValue[0];
211:            }
212:
213:            @Override
214:            public void postSetValue(final DesignComponent parentComponent,
215:                    final DesignComponent childComponent) {
216:                final FileObject[] svgImageFileObject = new FileObject[1];
217:                childComponent.getDocument().getTransactionManager()
218:                        .readAccess(new Runnable() {
219:
220:                            public void run() {
221:                                PropertyValue propertyValue = childComponent
222:                                        .readProperty(SVGImageCD.PROP_RESOURCE_PATH);
223:                                if (propertyValue.getKind() == PropertyValue.Kind.VALUE) {
224:                                    Map<FileObject, FileObject> images = MidpProjectSupport
225:                                            .getFileObjectsForRelativeResourcePath(
226:                                                    parentComponent
227:                                                            .getDocument(),
228:                                                    MidpTypes
229:                                                            .getString(propertyValue));
230:                                    Iterator<FileObject> iterator = images
231:                                            .keySet().iterator();
232:                                    svgImageFileObject[0] = iterator.hasNext() ? iterator
233:                                            .next()
234:                                            : null;
235:                                }
236:                            }
237:                        });
238:
239:                if (svgImageFileObject[0] != null) {
240:                    InputStream inputStream = null;
241:                    try {
242:                        inputStream = svgImageFileObject[0].getInputStream();
243:                        if (inputStream != null) {
244:                            SVGUtils.parseSVGMenu(inputStream, parentComponent);
245:                        }
246:                    } catch (FileNotFoundException ex) {
247:                        Debug.warning(ex);
248:                    } finally {
249:                        if (inputStream != null) {
250:                            try {
251:                                inputStream.close();
252:                            } catch (IOException ioe) {
253:                                Debug.warning(ioe);
254:                            }
255:                        }
256:                    }
257:                }
258:            }
259:
260:            private void setText(String text) {
261:                if (text == null) {
262:                    text = ""; // NOI18N
263:                }
264:
265:                addImage(text, true);
266:            }
267:
268:            private void addImage(String path, boolean selectImage) {
269:                doNotFireEvent = true;
270:                if (comboBoxModel.getIndexOf(path) == -1) {
271:                    comboBoxModel.addElement(path);
272:                    sortComboBoxContent();
273:                }
274:                if (selectImage) {
275:                    pathTextComboBox.setSelectedItem(path);
276:                    updatePreview();
277:                }
278:                doNotFireEvent = false;
279:            }
280:
281:            @SuppressWarnings(value="unchecked")
282:            private void sortComboBoxContent() {
283:                int size = pathTextComboBox.getItemCount();
284:                List list = new ArrayList(size);
285:                for (int i = 0; i < size; i++) {
286:                    list.add(pathTextComboBox.getItemAt(i));
287:                }
288:                Collections.sort(list, StringComparator.instance);
289:                pathTextComboBox.removeAllItems();
290:                for (Object object : list) {
291:                    pathTextComboBox.addItem(object);
292:                }
293:            }
294:
295:            void setAllEnabled(boolean isEnabled) {
296:                pathLabel.setEnabled(isEnabled);
297:                pathTextComboBox.setEnabled(isEnabled);
298:                previewLabel.setEnabled(isEnabled);
299:                previewPanel.setEnabled(isEnabled);
300:                widthLabel.setEnabled(isEnabled);
301:                widthTextField.setEnabled(isEnabled);
302:                heightLabel.setEnabled(isEnabled);
303:                heightTextField.setEnabled(isEnabled);
304:                chooserButton.setEnabled(isEnabled);
305:            }
306:
307:            private void updateModel(DesignDocument document) {
308:                boolean isEnabled = pathTextComboBox.isEnabled();
309:                pathTextComboBox.setEnabled(false);
310:                doNotFireEvent = true;
311:                comboBoxModel.removeAllElements();
312:                doNotFireEvent = false;
313:                paths.clear();
314:
315:                Map<FileObject, String> fileMap = MidpProjectSupport
316:                        .getAllFilesForProjectByExt(document, Collections
317:                                .<String> singleton(EXTENSION));
318:                for (Entry<FileObject, String> entry : fileMap.entrySet()) {
319:                    checkFile(entry.getKey(), entry.getValue());
320:                }
321:
322:                if (isEnabled) {
323:                    pathTextComboBox.setEnabled(true);
324:                }
325:            }
326:
327:            private void checkFile(FileObject fo, String relativePath) {
328:                if (EXTENSION.equals(fo.getExt().toLowerCase())) {
329:                    String path = convertFile(fo, relativePath, false);
330:                    if (path != null) {
331:                        addImage(path, false);
332:                    }
333:                }
334:            }
335:
336:            private void updatePreview() {
337:                String relativePath = (String) pathTextComboBox
338:                        .getSelectedItem();
339:                FileObject fo = paths.get(relativePath);
340:                SVGImage svgImage = null;
341:                try {
342:                    if (fo != null) {
343:                        svgImage = Util.createSVGImage(fo, true);
344:                    }
345:                    if (messageAwareness != null) {
346:                        messageAwareness.clearErrorStatus();
347:                    }
348:                } catch (IOException e) {
349:                    Debug.warning(e);
350:                    if (messageAwareness != null) {
351:                        messageAwareness.displayWarning(NbBundle.getMessage(
352:                                SVGImageEditorElement.class,
353:                                "MSG_SVG_Image_Not_SVG_Tiny")); // NOI18N
354:                    }
355:                }
356:
357:                if (svgImage != null) {
358:                    int width = svgImage.getViewportWidth();
359:                    int height = svgImage.getViewportHeight();
360:                    widthTextField.setText(String.valueOf(width));
361:                    heightTextField.setText(String.valueOf(height));
362:                } else {
363:                    widthTextField.setText(null);
364:                    heightTextField.setText(null);
365:                }
366:                imageView.setImage(svgImage);
367:
368:                previewPanel.invalidate();
369:                previewPanel.validate();
370:                previewPanel.repaint();
371:            }
372:
373:            private FileObject getSourceFolder() {
374:                if (project == null) {
375:                    throw Debug.illegalState("Current project is null"); // NOI18N
376:                }
377:                String projectID = ProjectUtils.getProjectID(project);
378:                return ProjectUtils.getSourceGroups(projectID).iterator()
379:                        .next().getRootFolder();
380:            }
381:
382:            private String convertFile(FileObject fo, String relPath,
383:                    boolean needCopy) {
384:                String relativePath;
385:                FileObject sourceFolder = getSourceFolder();
386:                String sourcePath = sourceFolder.getPath();
387:
388:                File file = FileUtil.toFile(fo);
389:                if (file == null) {
390:                    // abstract FO - zip/jar...
391:                    relativePath = "/" + fo.getPath(); // NOI18N
392:                } else {
393:                    String fullPath = file.getAbsolutePath();
394:                    if (fullPath.contains(sourcePath)) {
395:                        // file is inside sources
396:                        fullPath = fo.getPath();
397:                        int i = fullPath.indexOf(sourcePath)
398:                                + sourcePath.length();
399:                        relativePath = fullPath.substring(i);
400:                    } else if (needCopy) {
401:                        // somewhere outside sources - need to copy (export image)
402:                        File possible = new File(sourcePath + File.separator
403:                                + fo.getNameExt());
404:                        if (possible.exists()) {
405:                            // file exists, do not convert
406:                            return null;
407:                        }
408:
409:                        try {
410:                            fo = fo.copy(sourceFolder, fo.getName(), fo
411:                                    .getExt());
412:                        } catch (IOException ex) {
413:                            Debug.warning(
414:                                    "SVGImageEditorElement.convertFile()",
415:                                    "can't copy file", fullPath, ex); // NOI18N
416:                        }
417:                        relativePath = "/" + fo.getNameExt(); // NOI18N
418:                    } else {
419:                        // somewhere outside sources, no need to copy - folder attached to resources
420:                        relativePath = relPath;
421:                    }
422:                }
423:                paths.put(relativePath, fo);
424:
425:                return relativePath;
426:            }
427:
428:            public void run() {
429:                DesignDocument document = ActiveDocumentSupport.getDefault()
430:                        .getActiveDocument();
431:                if (document != null) {
432:                    updateModel(document);
433:                }
434:
435:                showProgressBar(false);
436:                setDesignComponentWrapper(wrapper);
437:                requiresModelUpdate.set(false);
438:            }
439:
440:            @Override
441:            public void addNotify() {
442:                super .addNotify();
443:
444:                if (requiresModelUpdate.getAndSet(true)) {
445:                    return;
446:                }
447:
448:                showProgressBar(true);
449:                new Thread(this ).start();
450:            }
451:
452:            private void showProgressBar(final boolean isShowing) {
453:                SwingUtilities.invokeLater(new Runnable() {
454:
455:                    public void run() {
456:                        progressBar.setVisible(isShowing);
457:                    }
458:                });
459:            }
460:
461:            @Override
462:            public void removeNotify() {
463:                paths.clear();
464:                project = null;
465:                wrapper = null;
466:                super .removeNotify();
467:            }
468:
469:            private static class ImageFilter extends FileFilter {
470:
471:                private String description;
472:
473:                public ImageFilter() {
474:                    description = NbBundle
475:                            .getMessage(SVGImageEditorElement.class,
476:                                    "DISP_SVG_Image_Files"); // NOI18N
477:                }
478:
479:                public boolean accept(File file) {
480:                    if (file.isDirectory()) {
481:                        return true;
482:                    }
483:
484:                    String extension = getExtension(file);
485:                    return EXTENSION.equals(extension);
486:                }
487:
488:                public String getDescription() {
489:                    return description;
490:                }
491:
492:                private static String getExtension(File file) {
493:                    String ext = null;
494:                    String s = file.getName();
495:                    int i = s.lastIndexOf('.'); // NOI18N
496:                    if (i > 0 && i < s.length() - 1) {
497:                        ext = s.substring(i + 1).toLowerCase();
498:                    }
499:                    return ext;
500:                }
501:            }
502:
503:            /** This method is called from within the constructor to
504:             * initialize the form.
505:             * WARNING: Do NOT modify this code. The content of this method is
506:             * always regenerated by the Form Editor.
507:             */
508:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
509:            private void initComponents() {
510:
511:                pathLabel = new javax.swing.JLabel();
512:                previewLabel = new javax.swing.JLabel();
513:                previewPanel = new javax.swing.JPanel();
514:                widthLabel = new javax.swing.JLabel();
515:                widthTextField = new javax.swing.JTextField();
516:                heightLabel = new javax.swing.JLabel();
517:                heightTextField = new javax.swing.JTextField();
518:                chooserButton = new javax.swing.JButton();
519:                pathTextComboBox = new javax.swing.JComboBox();
520:                progressBar = new javax.swing.JProgressBar();
521:
522:                org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
523:                        org.openide.util.NbBundle.getMessage(
524:                                SVGImageEditorElement.class,
525:                                "ImageEditorElement.pathLabel.text")); // NOI18N
526:                pathLabel.setEnabled(false);
527:
528:                previewLabel.setText(org.openide.util.NbBundle.getMessage(
529:                        SVGImageEditorElement.class,
530:                        "ImageEditorElement.previewLabel.text")); // NOI18N
531:                previewLabel.setEnabled(false);
532:
533:                previewPanel.setEnabled(false);
534:                previewPanel.setLayout(new java.awt.BorderLayout());
535:
536:                widthLabel.setText(org.openide.util.NbBundle.getMessage(
537:                        SVGImageEditorElement.class,
538:                        "ImageEditorElement.widthLabel.text")); // NOI18N
539:                widthLabel.setEnabled(false);
540:
541:                widthTextField.setEditable(false);
542:                widthTextField.setEnabled(false);
543:
544:                heightLabel.setText(org.openide.util.NbBundle.getMessage(
545:                        SVGImageEditorElement.class,
546:                        "ImageEditorElement.heightLabel.text")); // NOI18N
547:                heightLabel.setEnabled(false);
548:
549:                heightTextField.setEditable(false);
550:                heightTextField.setEnabled(false);
551:
552:                chooserButton.setText(org.openide.util.NbBundle.getMessage(
553:                        SVGImageEditorElement.class,
554:                        "ImageEditorElement.chooserButton.text")); // NOI18N
555:                chooserButton.setEnabled(false);
556:                chooserButton
557:                        .addActionListener(new java.awt.event.ActionListener() {
558:                            public void actionPerformed(
559:                                    java.awt.event.ActionEvent evt) {
560:                                chooserButtonActionPerformed(evt);
561:                            }
562:                        });
563:
564:                pathTextComboBox.setEditable(true);
565:                pathTextComboBox.setModel(comboBoxModel);
566:                pathTextComboBox.setEnabled(false);
567:                pathTextComboBox
568:                        .addActionListener(new java.awt.event.ActionListener() {
569:                            public void actionPerformed(
570:                                    java.awt.event.ActionEvent evt) {
571:                                pathTextComboBoxActionPerformed(evt);
572:                            }
573:                        });
574:
575:                progressBar.setIndeterminate(true);
576:
577:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
578:                        this );
579:                this .setLayout(layout);
580:                layout
581:                        .setHorizontalGroup(layout
582:                                .createParallelGroup(
583:                                        org.jdesktop.layout.GroupLayout.LEADING)
584:                                .add(
585:                                        layout.createSequentialGroup().add(
586:                                                pathLabel).addContainerGap(272,
587:                                                Short.MAX_VALUE))
588:                                .add(
589:                                        org.jdesktop.layout.GroupLayout.TRAILING,
590:                                        layout
591:                                                .createSequentialGroup()
592:                                                .add(
593:                                                        layout
594:                                                                .createParallelGroup(
595:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
596:                                                                .add(
597:                                                                        layout
598:                                                                                .createSequentialGroup()
599:                                                                                .add(
600:                                                                                        previewLabel)
601:                                                                                .addPreferredGap(
602:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
603:                                                                                .add(
604:                                                                                        previewPanel,
605:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
606:                                                                                        85,
607:                                                                                        Short.MAX_VALUE)
608:                                                                                .add(
609:                                                                                        18,
610:                                                                                        18,
611:                                                                                        18)
612:                                                                                .add(
613:                                                                                        layout
614:                                                                                                .createParallelGroup(
615:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
616:                                                                                                .add(
617:                                                                                                        layout
618:                                                                                                                .createSequentialGroup()
619:                                                                                                                .add(
620:                                                                                                                        layout
621:                                                                                                                                .createParallelGroup(
622:                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
623:                                                                                                                                .add(
624:                                                                                                                                        heightLabel)
625:                                                                                                                                .add(
626:                                                                                                                                        widthLabel))
627:                                                                                                                .addPreferredGap(
628:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
629:                                                                                                                .add(
630:                                                                                                                        layout
631:                                                                                                                                .createParallelGroup(
632:                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING,
633:                                                                                                                                        false)
634:                                                                                                                                .add(
635:                                                                                                                                        widthTextField,
636:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
637:                                                                                                                                        92,
638:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
639:                                                                                                                                .add(
640:                                                                                                                                        heightTextField,
641:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
642:                                                                                                                                        92,
643:                                                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
644:                                                                                                .add(
645:                                                                                                        progressBar,
646:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
647:                                                                                                        146,
648:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
649:                                                                .add(
650:                                                                        pathTextComboBox,
651:                                                                        0,
652:                                                                        295,
653:                                                                        Short.MAX_VALUE))
654:                                                .addPreferredGap(
655:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
656:                                                .add(
657:                                                        chooserButton,
658:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
659:                                                        30,
660:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
661:                layout
662:                        .setVerticalGroup(layout
663:                                .createParallelGroup(
664:                                        org.jdesktop.layout.GroupLayout.LEADING)
665:                                .add(
666:                                        layout
667:                                                .createSequentialGroup()
668:                                                .add(pathLabel)
669:                                                .addPreferredGap(
670:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
671:                                                .add(
672:                                                        layout
673:                                                                .createParallelGroup(
674:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
675:                                                                .add(
676:                                                                        chooserButton)
677:                                                                .add(
678:                                                                        pathTextComboBox,
679:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
680:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
681:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
682:                                                .addPreferredGap(
683:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
684:                                                .add(
685:                                                        layout
686:                                                                .createParallelGroup(
687:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
688:                                                                .add(
689:                                                                        layout
690:                                                                                .createSequentialGroup()
691:                                                                                .add(
692:                                                                                        layout
693:                                                                                                .createParallelGroup(
694:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
695:                                                                                                .add(
696:                                                                                                        widthLabel)
697:                                                                                                .add(
698:                                                                                                        widthTextField,
699:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
700:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
701:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
702:                                                                                .addPreferredGap(
703:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
704:                                                                                .add(
705:                                                                                        layout
706:                                                                                                .createParallelGroup(
707:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
708:                                                                                                .add(
709:                                                                                                        heightLabel)
710:                                                                                                .add(
711:                                                                                                        heightTextField,
712:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
713:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
714:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
715:                                                                                .addPreferredGap(
716:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
717:                                                                                .add(
718:                                                                                        progressBar,
719:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
720:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
721:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
722:                                                                                .addContainerGap())
723:                                                                .add(
724:                                                                        previewLabel)
725:                                                                .add(
726:                                                                        previewPanel,
727:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
728:                                                                        100,
729:                                                                        Short.MAX_VALUE))));
730:            }// </editor-fold>//GEN-END:initComponents
731:
732:            private void chooserButtonActionPerformed(
733:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooserButtonActionPerformed
734:                JFileChooser chooser = new JFileChooser(
735:                        lastDir != null ? lastDir : project
736:                                .getProjectDirectory().getPath());
737:                chooser.setFileFilter(new ImageFilter());
738:                int returnVal = chooser.showOpenDialog(this );
739:                if (returnVal == JFileChooser.APPROVE_OPTION) {
740:                    FileObject fo = FileUtil.toFileObject(FileUtil
741:                            .normalizeFile(chooser.getSelectedFile()));
742:                    lastDir = chooser.getSelectedFile().getParentFile()
743:                            .getPath();
744:                    String relativePath = convertFile(fo, null, true);
745:                    if (relativePath != null) {
746:                        setText(relativePath);
747:                        pathTextComboBoxActionPerformed(null);
748:                    } else {
749:                        String message = NbBundle.getMessage(
750:                                SVGImageEditorElement.class, "MSG_FILE_EXIST"); // NOI18N
751:                        DialogDisplayer.getDefault().notify(
752:                                new NotifyDescriptor.Message(message));
753:                    }
754:                }
755:            }//GEN-LAST:event_chooserButtonActionPerformed
756:
757:            private void pathTextComboBoxActionPerformed(
758:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathTextComboBoxActionPerformed
759:                if (!doNotFireEvent) {
760:                    String text = (String) pathTextComboBox.getSelectedItem();
761:                    fireElementChanged(componentID,
762:                            SVGImageCD.PROP_RESOURCE_PATH,
763:                            MidpTypes.createStringValue(text != null ? text
764:                                    : "")); // NOI18N
765:                    updatePreview();
766:                }
767:            }//GEN-LAST:event_pathTextComboBoxActionPerformed
768:
769:            // Variables declaration - do not modify//GEN-BEGIN:variables
770:            private javax.swing.JButton chooserButton;
771:            private javax.swing.JLabel heightLabel;
772:            private javax.swing.JTextField heightTextField;
773:            private javax.swing.JLabel pathLabel;
774:            private javax.swing.JComboBox pathTextComboBox;
775:            private javax.swing.JLabel previewLabel;
776:            private javax.swing.JPanel previewPanel;
777:            private javax.swing.JProgressBar progressBar;
778:            private javax.swing.JLabel widthLabel;
779:            private javax.swing.JTextField widthTextField;
780:            // End of variables declaration//GEN-END:variables
781:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.