Source Code Cross Referenced for ImageEditorElement.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » midp » propertyeditors » resource » elements » 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.midp.propertyeditors.resource.elements 
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.midp.propertyeditors.resource.elements;
043:
044:        import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.element.PropertyEditorResourceElement;
045:        import java.awt.BorderLayout;
046:        import java.awt.Color;
047:        import java.awt.Graphics;
048:        import java.awt.Image;
049:        import java.awt.image.BufferedImage;
050:        import java.io.File;
051:        import java.io.IOException;
052:        import java.util.ArrayList;
053:        import java.util.Arrays;
054:        import java.util.Collections;
055:        import java.util.HashMap;
056:        import java.util.List;
057:        import java.util.Map;
058:        import java.util.Map.Entry;
059:        import java.util.concurrent.atomic.AtomicBoolean;
060:        import javax.imageio.ImageIO;
061:        import javax.swing.DefaultComboBoxModel;
062:        import javax.swing.JComponent;
063:        import javax.swing.JFileChooser;
064:        import javax.swing.SwingUtilities;
065:        import javax.swing.filechooser.FileFilter;
066:        import org.netbeans.api.project.Project;
067:        import org.netbeans.modules.vmd.api.io.ProjectUtils;
068:        import org.netbeans.modules.vmd.api.model.Debug;
069:        import org.netbeans.modules.vmd.api.model.DesignComponent;
070:        import org.netbeans.modules.vmd.api.model.DesignDocument;
071:        import org.netbeans.modules.vmd.api.model.PropertyValue;
072:        import org.netbeans.modules.vmd.api.model.TypeID;
073:        import org.netbeans.modules.vmd.api.model.common.ActiveDocumentSupport;
074:        import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
075:        import org.netbeans.modules.vmd.midp.components.MidpTypes;
076:        import org.netbeans.modules.vmd.midp.components.resources.ImageCD;
077:        import org.openide.DialogDisplayer;
078:        import org.openide.NotifyDescriptor;
079:        import org.openide.filesystems.FileObject;
080:        import org.openide.filesystems.FileUtil;
081:        import org.openide.util.NbBundle;
082:
083:        /**
084:         *
085:         * @author Anton Chechel
086:         */
087:        public class ImageEditorElement extends PropertyEditorResourceElement
088:                implements  Runnable {
089:
090:            private static final String[] EXTENSIONS = { "png", "gif", "jpg",
091:                    "jpeg" }; // NOI18N
092:            private long componentID;
093:            private boolean doNotFireEvent;
094:            private Project project;
095:            private String lastDir;
096:            private ImagePreview imagePreview;
097:            private Image image;
098:            private DefaultComboBoxModel comboBoxModel;
099:            private Map<String, FileObject> paths;
100:            private final AtomicBoolean requiresModelUpdate = new AtomicBoolean(
101:                    false);
102:            private DesignComponentWrapper wrapper;
103:
104:            public ImageEditorElement() {
105:                paths = new HashMap<String, FileObject>();
106:                comboBoxModel = new DefaultComboBoxModel();
107:                initComponents();
108:                progressBar.setVisible(false);
109:                imagePreview = new ImagePreview();
110:                previewPanel.add(imagePreview, BorderLayout.CENTER);
111:            }
112:
113:            public JComponent getJComponent() {
114:                return this ;
115:            }
116:
117:            public TypeID getTypeID() {
118:                return ImageCD.TYPEID;
119:            }
120:
121:            public List<String> getPropertyValueNames() {
122:                return Arrays.asList(ImageCD.PROP_RESOURCE_PATH);
123:            }
124:
125:            public void setDesignComponentWrapper(
126:                    final DesignComponentWrapper wrapper) {
127:                this .wrapper = wrapper;
128:                DesignDocument document = ActiveDocumentSupport.getDefault()
129:                        .getActiveDocument();
130:                if (document != null) {
131:                    project = ProjectUtils.getProject(document);
132:                }
133:
134:                if (wrapper == null) {
135:                    // UI stuff
136:                    setText(null);
137:                    setAllEnabled(false);
138:                    return;
139:                }
140:
141:                this .componentID = wrapper.getComponentID();
142:                final String[] _pathText = new String[1];
143:
144:                final DesignComponent component = wrapper.getComponent();
145:                if (component != null) {
146:                    // existing component
147:                    if (!component.getType().equals(getTypeID())) {
148:                        throw new IllegalArgumentException(
149:                                "Passed component must have typeID "
150:                                        + getTypeID() + " instead passed "
151:                                        + component.getType()); // NOI18N
152:                    }
153:
154:                    this .componentID = component.getComponentID();
155:                    component.getDocument().getTransactionManager().readAccess(
156:                            new Runnable() {
157:
158:                                public void run() {
159:                                    PropertyValue propertyValue = component
160:                                            .readProperty(ImageCD.PROP_RESOURCE_PATH);
161:                                    if (!isPropertyValueAUserCodeType(propertyValue)) {
162:                                        _pathText[0] = MidpTypes
163:                                                .getString(propertyValue);
164:                                    }
165:                                }
166:                            });
167:                }
168:
169:                if (wrapper.hasChanges()) {
170:                    Map<String, PropertyValue> changes = wrapper.getChanges();
171:                    for (String propertyName : changes.keySet()) {
172:                        final PropertyValue propertyValue = changes
173:                                .get(propertyName);
174:                        if (ImageCD.PROP_RESOURCE_PATH.equals(propertyName)) {
175:                            _pathText[0] = MidpTypes.getString(propertyValue);
176:                        }
177:                    }
178:                }
179:
180:                // UI stuff
181:                setAllEnabled(true);
182:                setText(_pathText[0]);
183:            }
184:
185:            private void setText(String text) {
186:                if (text == null) {
187:                    text = ""; // NOI18N
188:                }
189:
190:                addImage(text);
191:            }
192:
193:            private void addImage(String path) {
194:                doNotFireEvent = true;
195:                if (comboBoxModel.getIndexOf(path) == -1) {
196:                    comboBoxModel.addElement(path);
197:                    sortComboBoxContent();
198:                }
199:                pathTextComboBox.setSelectedItem(path);
200:                doNotFireEvent = false;
201:                updatePreview();
202:            }
203:
204:            @SuppressWarnings(value="unchecked")
205:            // NOI18N
206:            private void sortComboBoxContent() {
207:                int size = pathTextComboBox.getItemCount();
208:                List list = new ArrayList(size);
209:                for (int i = 0; i < size; i++) {
210:                    list.add(pathTextComboBox.getItemAt(i));
211:                }
212:                Collections.sort(list, StringComparator.instance);
213:                pathTextComboBox.removeAllItems();
214:                for (Object object : list) {
215:                    pathTextComboBox.addItem(object);
216:                }
217:            }
218:
219:            public void setAllEnabled(boolean isEnabled) {
220:                pathLabel.setEnabled(isEnabled);
221:                pathTextComboBox.setEnabled(isEnabled);
222:                previewLabel.setEnabled(isEnabled);
223:                previewPanel.setEnabled(isEnabled);
224:                widthLabel.setEnabled(isEnabled);
225:                widthTextField.setEnabled(isEnabled);
226:                heightLabel.setEnabled(isEnabled);
227:                heightTextField.setEnabled(isEnabled);
228:                sizeLabel.setEnabled(isEnabled);
229:                sizeTextField.setEnabled(isEnabled);
230:                chooserButton.setEnabled(isEnabled);
231:            }
232:
233:            private void updateModel(DesignDocument document) {
234:                boolean isEnabled = pathTextComboBox.isEnabled();
235:                pathTextComboBox.setEnabled(false);
236:                doNotFireEvent = true;
237:                comboBoxModel.removeAllElements();
238:                doNotFireEvent = false;
239:                paths.clear();
240:
241:                Map<FileObject, String> fileMap = MidpProjectSupport
242:                        .getImagesForProject(document, false);
243:                for (Entry<FileObject, String> entry : fileMap.entrySet()) {
244:                    checkFile(entry.getKey(), entry.getValue());
245:                }
246:
247:                if (isEnabled) {
248:                    pathTextComboBox.setEnabled(true);
249:                }
250:            }
251:
252:            private void checkFile(FileObject fo, String relativePath) {
253:                for (String ext : EXTENSIONS) {
254:                    if (ext.equals(fo.getExt().toLowerCase())) {
255:                        String path = convertFile(fo, relativePath, false);
256:                        if (path != null) {
257:                            addImage(path);
258:                        }
259:                        break;
260:                    }
261:                }
262:            }
263:
264:            private void updatePreview() {
265:                String relativePath = (String) pathTextComboBox
266:                        .getSelectedItem();
267:                FileObject fo = paths.get(relativePath);
268:                BufferedImage bufferedImage = null;
269:                try {
270:                    if (fo != null) {
271:                        bufferedImage = ImageIO.read(fo.getInputStream());
272:                    }
273:                } catch (IOException ex) {
274:                }
275:
276:                if (bufferedImage != null) {
277:                    int width = bufferedImage.getWidth();
278:                    int height = bufferedImage.getHeight();
279:                    widthTextField.setText(String.valueOf(width));
280:                    heightTextField.setText(String.valueOf(height));
281:
282:                    StringBuffer str = new StringBuffer();
283:                    str.append(fo.getSize());
284:                    str.append(' '); // NOI18N
285:                    str.append(NbBundle.getMessage(ImageEditorElement.class,
286:                            "LBL_Size_Bytes")); // NOI18N
287:                    sizeTextField.setText(str.toString());
288:
289:                    image = bufferedImage;
290:                } else {
291:                    image = null;
292:                    widthTextField.setText(null);
293:                    heightTextField.setText(null);
294:                    sizeTextField.setText(null);
295:                }
296:
297:                previewPanel.invalidate();
298:                previewPanel.validate();
299:                previewPanel.repaint();
300:            }
301:
302:            private FileObject getSourceFolder() {
303:                if (project == null) {
304:                    throw Debug.illegalState("Current project is null"); // NOI18N
305:                }
306:                String projectID = ProjectUtils.getProjectID(project);
307:                return ProjectUtils.getSourceGroups(projectID).iterator()
308:                        .next().getRootFolder();
309:            }
310:
311:            private String convertFile(FileObject fo, String relPath,
312:                    boolean needCopy) {
313:                String relativePath;
314:                FileObject sourceFolder = getSourceFolder();
315:                String sourcePath = sourceFolder.getPath();
316:
317:                File file = FileUtil.toFile(fo);
318:                if (file == null) {
319:                    // abstract FO - zip/jar...
320:                    relativePath = "/" + fo.getPath(); // NOI18N
321:                } else {
322:                    String fullPath = file.getAbsolutePath();
323:                    if (fullPath.contains(sourcePath)) {
324:                        // file is inside sources
325:                        fullPath = fo.getPath();
326:                        int i = fullPath.indexOf(sourcePath)
327:                                + sourcePath.length();
328:                        relativePath = fullPath.substring(i);
329:                    } else if (needCopy) {
330:                        // somewhere outside sources - need to copy (export image)
331:                        File possible = new File(sourcePath + File.separator
332:                                + fo.getNameExt());
333:                        if (possible.exists()) {
334:                            // file exists, do not convert
335:                            return null;
336:                        }
337:
338:                        try {
339:                            fo = fo.copy(sourceFolder, fo.getName(), fo
340:                                    .getExt());
341:                        } catch (IOException ex) {
342:                            Debug.warning(
343:                                    "SVGImageEditorElement.convertFile()",
344:                                    "can't copy file", fullPath, ex); // NOI18N
345:                        }
346:                        relativePath = "/" + fo.getNameExt(); // NOI18N
347:                    } else {
348:                        // somewhere outside sources, no need to copy - folder attached to resources
349:                        relativePath = relPath;
350:                    }
351:                }
352:                paths.put(relativePath, fo);
353:
354:                return relativePath;
355:            }
356:
357:            public void run() {
358:                DesignDocument document = ActiveDocumentSupport.getDefault()
359:                        .getActiveDocument();
360:                if (document != null) {
361:                    updateModel(document);
362:                }
363:
364:                showProgressBar(false);
365:                setDesignComponentWrapper(wrapper);
366:                requiresModelUpdate.set(false);
367:            }
368:
369:            @Override
370:            public void addNotify() {
371:                super .addNotify();
372:
373:                if (requiresModelUpdate.getAndSet(true)) {
374:                    return;
375:                }
376:
377:                showProgressBar(true);
378:                new Thread(this ).start();
379:            }
380:
381:            private void showProgressBar(final boolean isShowing) {
382:                SwingUtilities.invokeLater(new Runnable() {
383:
384:                    public void run() {
385:                        progressBar.setVisible(isShowing);
386:                    }
387:                });
388:            }
389:
390:            @Override
391:            public void removeNotify() {
392:                paths.clear();
393:                project = null;
394:                wrapper = null;
395:                super .removeNotify();
396:            }
397:
398:            private static class ImageFilter extends FileFilter {
399:
400:                private String description;
401:
402:                public ImageFilter() {
403:                    description = NbBundle.getMessage(ImageEditorElement.class,
404:                            "DISP_Image_Files"); // NOI18N
405:                }
406:
407:                public boolean accept(File file) {
408:                    if (file.isDirectory()) {
409:                        return true;
410:                    }
411:
412:                    String extension = getExtension(file);
413:                    for (String ext : EXTENSIONS) {
414:                        if (ext.equals(extension)) {
415:                            return true;
416:                        }
417:                    }
418:                    return false;
419:                }
420:
421:                public String getDescription() {
422:                    return description;
423:                }
424:
425:                private static String getExtension(File file) {
426:                    String ext = null;
427:                    String s = file.getName();
428:                    int i = s.lastIndexOf('.'); // NOI18N
429:                    if (i > 0 && i < s.length() - 1) {
430:                        ext = s.substring(i + 1).toLowerCase();
431:                    }
432:                    return ext;
433:                }
434:            }
435:
436:            private class ImagePreview extends JComponent {
437:
438:                private static final int BORDER_EDGE_LENGTH = 10;
439:                private static final int IMAGE_GAP = 10;
440:
441:                @Override
442:                public void paint(Graphics g) {
443:                    if (image != null) {
444:                        int width = image.getWidth(null);
445:                        int height = image.getHeight(null);
446:                        int previewWidth = imagePreview.getWidth() - IMAGE_GAP;
447:                        int previewHeight = imagePreview.getHeight()
448:                                - IMAGE_GAP;
449:                        if (width > previewWidth || height > previewHeight) {
450:                            g.drawImage(image, IMAGE_GAP, IMAGE_GAP,
451:                                    previewWidth, previewHeight, 0, 0, width,
452:                                    height, null);
453:                        } else {
454:                            int xOffset = (previewWidth - width + IMAGE_GAP) / 2;
455:                            int yOffset = (previewHeight - height + IMAGE_GAP) / 2;
456:                            g.drawImage(image, xOffset, yOffset, null);
457:                        }
458:                    }
459:
460:                    // paint the border
461:                    g.setColor(Color.BLACK);
462:                    final int rightX = getWidth() - 1;
463:                    final int bottomY = getHeight() - 1;
464:                    // top left
465:                    g.drawLine(0, 0, 0, BORDER_EDGE_LENGTH);
466:                    g.drawLine(0, 0, BORDER_EDGE_LENGTH, 0);
467:                    // top right
468:                    g.drawLine(rightX, 0, rightX, BORDER_EDGE_LENGTH);
469:                    g.drawLine(rightX, 0, rightX - BORDER_EDGE_LENGTH, 0);
470:                    // bottom left
471:                    g.drawLine(0, bottomY, 0, bottomY - BORDER_EDGE_LENGTH);
472:                    g.drawLine(0, bottomY, BORDER_EDGE_LENGTH, bottomY);
473:                    // bottom right
474:                    g.drawLine(rightX, bottomY, rightX, bottomY
475:                            - BORDER_EDGE_LENGTH);
476:                    g.drawLine(rightX, bottomY, rightX - BORDER_EDGE_LENGTH,
477:                            bottomY);
478:                }
479:            }
480:
481:            /** This method is called from within the constructor to
482:             * initialize the form.
483:             * WARNING: Do NOT modify this code. The content of this method is
484:             * always regenerated by the Form Editor.
485:             */
486:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
487:            private void initComponents() {
488:
489:                pathLabel = new javax.swing.JLabel();
490:                previewLabel = new javax.swing.JLabel();
491:                previewPanel = new javax.swing.JPanel();
492:                widthLabel = new javax.swing.JLabel();
493:                widthTextField = new javax.swing.JTextField();
494:                heightLabel = new javax.swing.JLabel();
495:                heightTextField = new javax.swing.JTextField();
496:                chooserButton = new javax.swing.JButton();
497:                pathTextComboBox = new javax.swing.JComboBox();
498:                sizeLabel = new javax.swing.JLabel();
499:                sizeTextField = new javax.swing.JTextField();
500:                progressBar = new javax.swing.JProgressBar();
501:
502:                org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
503:                        org.openide.util.NbBundle.getMessage(
504:                                ImageEditorElement.class,
505:                                "ImageEditorElement.pathLabel.text")); // NOI18N
506:                pathLabel.setEnabled(false);
507:
508:                previewLabel.setText(org.openide.util.NbBundle.getMessage(
509:                        ImageEditorElement.class,
510:                        "ImageEditorElement.previewLabel.text")); // NOI18N
511:                previewLabel.setEnabled(false);
512:
513:                previewPanel.setEnabled(false);
514:                previewPanel
515:                        .addComponentListener(new java.awt.event.ComponentAdapter() {
516:                            public void componentResized(
517:                                    java.awt.event.ComponentEvent evt) {
518:                                previewPanelComponentResized(evt);
519:                            }
520:                        });
521:                previewPanel.setLayout(new java.awt.BorderLayout());
522:
523:                widthLabel.setText(org.openide.util.NbBundle.getMessage(
524:                        ImageEditorElement.class,
525:                        "ImageEditorElement.widthLabel.text")); // NOI18N
526:                widthLabel.setEnabled(false);
527:
528:                widthTextField.setEditable(false);
529:                widthTextField.setEnabled(false);
530:
531:                heightLabel.setText(org.openide.util.NbBundle.getMessage(
532:                        ImageEditorElement.class,
533:                        "ImageEditorElement.heightLabel.text")); // NOI18N
534:                heightLabel.setEnabled(false);
535:
536:                heightTextField.setEditable(false);
537:                heightTextField.setEnabled(false);
538:
539:                chooserButton.setText(org.openide.util.NbBundle.getMessage(
540:                        ImageEditorElement.class,
541:                        "ImageEditorElement.chooserButton.text")); // NOI18N
542:                chooserButton.setEnabled(false);
543:                chooserButton
544:                        .addActionListener(new java.awt.event.ActionListener() {
545:                            public void actionPerformed(
546:                                    java.awt.event.ActionEvent evt) {
547:                                chooserButtonActionPerformed(evt);
548:                            }
549:                        });
550:
551:                pathTextComboBox.setEditable(true);
552:                pathTextComboBox.setModel(comboBoxModel);
553:                pathTextComboBox.setEnabled(false);
554:                pathTextComboBox
555:                        .addActionListener(new java.awt.event.ActionListener() {
556:                            public void actionPerformed(
557:                                    java.awt.event.ActionEvent evt) {
558:                                pathTextComboBoxActionPerformed(evt);
559:                            }
560:                        });
561:
562:                sizeLabel.setText(org.openide.util.NbBundle.getMessage(
563:                        ImageEditorElement.class,
564:                        "ImageEditorElement.sizeLabel.text")); // NOI18N
565:                sizeLabel.setEnabled(false);
566:
567:                sizeTextField.setEditable(false);
568:                sizeTextField.setEnabled(false);
569:
570:                progressBar.setIndeterminate(true);
571:
572:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
573:                        this );
574:                this .setLayout(layout);
575:                layout
576:                        .setHorizontalGroup(layout
577:                                .createParallelGroup(
578:                                        org.jdesktop.layout.GroupLayout.LEADING)
579:                                .add(
580:                                        layout.createSequentialGroup().add(
581:                                                pathLabel).addContainerGap(287,
582:                                                Short.MAX_VALUE))
583:                                .add(
584:                                        org.jdesktop.layout.GroupLayout.TRAILING,
585:                                        layout
586:                                                .createSequentialGroup()
587:                                                .add(
588:                                                        layout
589:                                                                .createParallelGroup(
590:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
591:                                                                .add(
592:                                                                        layout
593:                                                                                .createSequentialGroup()
594:                                                                                .add(
595:                                                                                        previewLabel)
596:                                                                                .addPreferredGap(
597:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
598:                                                                                .add(
599:                                                                                        previewPanel,
600:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
601:                                                                                        0,
602:                                                                                        Short.MAX_VALUE)
603:                                                                                .add(
604:                                                                                        18,
605:                                                                                        18,
606:                                                                                        18)
607:                                                                                .add(
608:                                                                                        layout
609:                                                                                                .createParallelGroup(
610:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
611:                                                                                                .add(
612:                                                                                                        layout
613:                                                                                                                .createSequentialGroup()
614:                                                                                                                .add(
615:                                                                                                                        layout
616:                                                                                                                                .createParallelGroup(
617:                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING)
618:                                                                                                                                .add(
619:                                                                                                                                        heightLabel)
620:                                                                                                                                .add(
621:                                                                                                                                        widthLabel)
622:                                                                                                                                .add(
623:                                                                                                                                        sizeLabel))
624:                                                                                                                .addPreferredGap(
625:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
626:                                                                                                                .add(
627:                                                                                                                        layout
628:                                                                                                                                .createParallelGroup(
629:                                                                                                                                        org.jdesktop.layout.GroupLayout.LEADING,
630:                                                                                                                                        false)
631:                                                                                                                                .add(
632:                                                                                                                                        widthTextField,
633:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
634:                                                                                                                                        107,
635:                                                                                                                                        Short.MAX_VALUE)
636:                                                                                                                                .add(
637:                                                                                                                                        heightTextField,
638:                                                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
639:                                                                                                                                        107,
640:                                                                                                                                        Short.MAX_VALUE)
641:                                                                                                                                .add(
642:                                                                                                                                        sizeTextField)))
643:                                                                                                .add(
644:                                                                                                        progressBar,
645:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
646:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
647:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
648:                                                                .add(
649:                                                                        pathTextComboBox,
650:                                                                        0,
651:                                                                        310,
652:                                                                        Short.MAX_VALUE))
653:                                                .addPreferredGap(
654:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
655:                                                .add(
656:                                                        chooserButton,
657:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
658:                                                        30,
659:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
660:                layout
661:                        .setVerticalGroup(layout
662:                                .createParallelGroup(
663:                                        org.jdesktop.layout.GroupLayout.LEADING)
664:                                .add(
665:                                        layout
666:                                                .createSequentialGroup()
667:                                                .add(pathLabel)
668:                                                .addPreferredGap(
669:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
670:                                                .add(
671:                                                        layout
672:                                                                .createParallelGroup(
673:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
674:                                                                .add(
675:                                                                        chooserButton)
676:                                                                .add(
677:                                                                        pathTextComboBox,
678:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
679:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
680:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
681:                                                .addPreferredGap(
682:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
683:                                                .add(
684:                                                        layout
685:                                                                .createParallelGroup(
686:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
687:                                                                .add(
688:                                                                        layout
689:                                                                                .createSequentialGroup()
690:                                                                                .add(
691:                                                                                        layout
692:                                                                                                .createParallelGroup(
693:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
694:                                                                                                .add(
695:                                                                                                        widthLabel)
696:                                                                                                .add(
697:                                                                                                        widthTextField,
698:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
699:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
700:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
701:                                                                                .addPreferredGap(
702:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
703:                                                                                .add(
704:                                                                                        layout
705:                                                                                                .createParallelGroup(
706:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
707:                                                                                                .add(
708:                                                                                                        heightLabel)
709:                                                                                                .add(
710:                                                                                                        heightTextField,
711:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
712:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
713:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
714:                                                                                .addPreferredGap(
715:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
716:                                                                                .add(
717:                                                                                        layout
718:                                                                                                .createParallelGroup(
719:                                                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
720:                                                                                                .add(
721:                                                                                                        sizeTextField,
722:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
723:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
724:                                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
725:                                                                                                .add(
726:                                                                                                        sizeLabel))
727:                                                                                .addPreferredGap(
728:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
729:                                                                                .add(
730:                                                                                        progressBar,
731:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
732:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
733:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
734:                                                                                .add(
735:                                                                                        3,
736:                                                                                        3,
737:                                                                                        3))
738:                                                                .add(
739:                                                                        previewLabel)
740:                                                                .add(
741:                                                                        previewPanel,
742:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
743:                                                                        100,
744:                                                                        Short.MAX_VALUE))));
745:            }// </editor-fold>//GEN-END:initComponents
746:
747:            private void chooserButtonActionPerformed(
748:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooserButtonActionPerformed
749:                JFileChooser chooser = new JFileChooser(
750:                        lastDir != null ? lastDir : project
751:                                .getProjectDirectory().getPath());
752:                chooser.setFileFilter(new ImageFilter());
753:                int returnVal = chooser.showOpenDialog(this );
754:                if (returnVal == JFileChooser.APPROVE_OPTION) {
755:                    FileObject fo = FileUtil.toFileObject(FileUtil
756:                            .normalizeFile(chooser.getSelectedFile()));
757:                    lastDir = chooser.getSelectedFile().getParentFile()
758:                            .getPath();
759:                    String relativePath = convertFile(fo, null, true);
760:                    if (relativePath != null) {
761:                        setText(relativePath);
762:                        pathTextComboBoxActionPerformed(null);
763:                    } else {
764:                        String message = NbBundle.getMessage(
765:                                ImageEditorElement.class, "MSG_FILE_EXIST"); // NOI18N
766:                        DialogDisplayer.getDefault().notify(
767:                                new NotifyDescriptor.Message(message));
768:                    }
769:                }
770:            }//GEN-LAST:event_chooserButtonActionPerformed
771:
772:            private void pathTextComboBoxActionPerformed(
773:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathTextComboBoxActionPerformed
774:            //        if (isShowing() && !doNotFireEvent) {
775:                if (!doNotFireEvent) {
776:                    String text = (String) pathTextComboBox.getSelectedItem();
777:                    fireElementChanged(componentID, ImageCD.PROP_RESOURCE_PATH,
778:                            MidpTypes.createStringValue(text != null ? text
779:                                    : "")); // NOI18N
780:                    updatePreview();
781:                }
782:            }//GEN-LAST:event_pathTextComboBoxActionPerformed
783:
784:            private void previewPanelComponentResized(
785:                    java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_previewPanelComponentResized
786:                updatePreview();
787:            }//GEN-LAST:event_previewPanelComponentResized
788:
789:            // Variables declaration - do not modify//GEN-BEGIN:variables
790:            private javax.swing.JButton chooserButton;
791:            private javax.swing.JLabel heightLabel;
792:            private javax.swing.JTextField heightTextField;
793:            private javax.swing.JLabel pathLabel;
794:            private javax.swing.JComboBox pathTextComboBox;
795:            private javax.swing.JLabel previewLabel;
796:            private javax.swing.JPanel previewPanel;
797:            private javax.swing.JProgressBar progressBar;
798:            private javax.swing.JLabel sizeLabel;
799:            private javax.swing.JTextField sizeTextField;
800:            private javax.swing.JLabel widthLabel;
801:            private javax.swing.JTextField widthTextField;
802:            // End of variables declaration//GEN-END:variables
803:        }
w___w___w_.___j_a__v_a__2s._c_o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.