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


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.vmd.game.nbdialog;
0043:
0044:        import java.awt.BorderLayout;
0045:        import java.awt.Component;
0046:        import java.awt.event.ActionEvent;
0047:        import java.awt.event.ActionListener;
0048:        import java.awt.event.FocusEvent;
0049:        import java.awt.event.FocusListener;
0050:        import java.io.IOException;
0051:        import java.io.InputStream;
0052:        import java.io.OutputStream;
0053:        import java.net.MalformedURLException;
0054:        import java.net.URL;
0055:        import java.util.ArrayList;
0056:        import java.util.Collections;
0057:        import java.util.Comparator;
0058:        import java.util.List;
0059:        import java.util.Map;
0060:        import javax.swing.BorderFactory;
0061:        import javax.swing.DefaultBoundedRangeModel;
0062:        import javax.swing.DefaultListCellRenderer;
0063:        import javax.swing.DefaultListModel;
0064:        import javax.swing.Icon;
0065:        import javax.swing.ImageIcon;
0066:        import javax.swing.JList;
0067:        import javax.swing.JScrollPane;
0068:        import javax.swing.SpinnerNumberModel;
0069:        import javax.swing.event.ChangeEvent;
0070:        import javax.swing.event.ChangeListener;
0071:        import javax.swing.event.DocumentEvent;
0072:        import javax.swing.event.DocumentListener;
0073:        import javax.swing.event.ListSelectionEvent;
0074:        import javax.swing.event.ListSelectionListener;
0075:        import org.netbeans.api.project.Project;
0076:        import org.netbeans.api.project.SourceGroup;
0077:        import org.netbeans.modules.vmd.game.dialog.AbstractImagePreviewComponent;
0078:        import org.netbeans.modules.vmd.game.dialog.FullImageGridPreview;
0079:        import org.netbeans.modules.vmd.game.dialog.PartialImageGridPreview;
0080:        import org.netbeans.modules.vmd.game.model.CodeUtils;
0081:        import org.netbeans.modules.vmd.game.model.GlobalRepository;
0082:        import org.netbeans.modules.vmd.game.model.ImageResource;
0083:        import org.netbeans.modules.vmd.game.model.Scene;
0084:        import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
0085:        import org.openide.DialogDescriptor;
0086:        import org.openide.DialogDisplayer;
0087:        import org.openide.NotifyDescriptor;
0088:        import org.openide.filesystems.FileObject;
0089:        import org.openide.filesystems.FileUtil;
0090:        import org.openide.util.HelpCtx;
0091:        import org.openide.util.NbBundle;
0092:        import org.openide.util.Utilities;
0093:
0094:        /**
0095:         *
0096:         * @author  kherink
0097:         */
0098:        public class SpriteDialog extends javax.swing.JPanel implements 
0099:                ActionListener {
0100:
0101:            private GlobalRepository gameDesign;
0102:
0103:            private static final Icon ICON_ERROR = new ImageIcon(
0104:                    Utilities
0105:                            .loadImage("org/netbeans/modules/vmd/midp/resources/error.gif")); // NOI18N
0106:
0107:            private static final int DEFAULT_FRAMES = 5;
0108:            private static final int DEFAULT_TILE_WIDTH = 18;
0109:            private static final int DEFAULT_TILE_HEIGHT = 18;
0110:
0111:            /** Creates new form NewTiledLayerDialog */
0112:            public SpriteDialog(GlobalRepository gameDesign) {
0113:                this .gameDesign = gameDesign;
0114:                initComponents();
0115:                init();
0116:            }
0117:
0118:            public SpriteDialog(Scene parent) {
0119:                this (parent.getGameDesign());
0120:                this .scene = parent;
0121:            }
0122:
0123:            /** This method is called from within the constructor to
0124:             * initialize the form.
0125:             * WARNING: Do NOT modify this code. The content of this method is
0126:             * always regenerated by the Form Editor.
0127:             */
0128:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
0129:            private void initComponents() {
0130:
0131:                buttonGroupLayers = new javax.swing.ButtonGroup();
0132:                panelCustomizer = new javax.swing.JPanel();
0133:                labelImageFile = new javax.swing.JLabel();
0134:                jScrollPane1 = new javax.swing.JScrollPane();
0135:                listImageFileName = new javax.swing.JList();
0136:                buttonImportImages = new javax.swing.JButton();
0137:                panelPreview = new javax.swing.JPanel();
0138:                labelImagePreview = new javax.swing.JLabel();
0139:                panelImage = new javax.swing.JPanel();
0140:                sliderWidth = new javax.swing.JSlider();
0141:                sliderHeight = new javax.swing.JSlider();
0142:                labelTileWidth = new javax.swing.JLabel();
0143:                labelTileHeight = new javax.swing.JLabel();
0144:                checkBoxZoom = new javax.swing.JCheckBox();
0145:                panelError = new javax.swing.JPanel();
0146:                labelError = new javax.swing.JLabel();
0147:                jSeparator1 = new javax.swing.JSeparator();
0148:                panelLayerInfo = new javax.swing.JPanel();
0149:                labelLayerName = new javax.swing.JLabel();
0150:                fieldLayerName = new javax.swing.JTextField();
0151:                jSeparator2 = new javax.swing.JSeparator();
0152:
0153:                labelImageFile.setLabelFor(listImageFileName);
0154:                org.openide.awt.Mnemonics.setLocalizedText(labelImageFile,
0155:                        org.openide.util.NbBundle.getMessage(
0156:                                SpriteDialog.class,
0157:                                "SpriteDialog.labelSelectImage.txt")); // NOI18N
0158:
0159:                listImageFileName.setModel(this .getImageListModel());
0160:                listImageFileName
0161:                        .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
0162:                jScrollPane1.setViewportView(listImageFileName);
0163:
0164:                org.openide.awt.Mnemonics.setLocalizedText(buttonImportImages,
0165:                        org.openide.util.NbBundle.getMessage(
0166:                                SpriteDialog.class,
0167:                                "SpriteDialog.buttonImportImages.txt")); // NOI18N
0168:
0169:                org.jdesktop.layout.GroupLayout panelCustomizerLayout = new org.jdesktop.layout.GroupLayout(
0170:                        panelCustomizer);
0171:                panelCustomizer.setLayout(panelCustomizerLayout);
0172:                panelCustomizerLayout
0173:                        .setHorizontalGroup(panelCustomizerLayout
0174:                                .createParallelGroup(
0175:                                        org.jdesktop.layout.GroupLayout.LEADING)
0176:                                .add(
0177:                                        panelCustomizerLayout
0178:                                                .createSequentialGroup()
0179:                                                .add(
0180:                                                        panelCustomizerLayout
0181:                                                                .createParallelGroup(
0182:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0183:                                                                .add(
0184:                                                                        labelImageFile)
0185:                                                                .add(
0186:                                                                        buttonImportImages)
0187:                                                                .add(
0188:                                                                        jScrollPane1,
0189:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0190:                                                                        235,
0191:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0192:                                                .addContainerGap(
0193:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0194:                                                        Short.MAX_VALUE)));
0195:                panelCustomizerLayout
0196:                        .setVerticalGroup(panelCustomizerLayout
0197:                                .createParallelGroup(
0198:                                        org.jdesktop.layout.GroupLayout.LEADING)
0199:                                .add(
0200:                                        panelCustomizerLayout
0201:                                                .createSequentialGroup()
0202:                                                .add(labelImageFile)
0203:                                                .addPreferredGap(
0204:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0205:                                                .add(
0206:                                                        jScrollPane1,
0207:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0208:                                                        256, Short.MAX_VALUE)
0209:                                                .addPreferredGap(
0210:                                                        org.jdesktop.layout.LayoutStyle.UNRELATED)
0211:                                                .add(buttonImportImages)));
0212:
0213:                labelImageFile
0214:                        .getAccessibleContext()
0215:                        .setAccessibleName(
0216:                                org.openide.util.NbBundle
0217:                                        .getMessage(SpriteDialog.class,
0218:                                                "SpriteDialog.labelSelectImage.accessible.name")); // NOI18N
0219:                labelImageFile
0220:                        .getAccessibleContext()
0221:                        .setAccessibleDescription(
0222:                                org.openide.util.NbBundle
0223:                                        .getMessage(SpriteDialog.class,
0224:                                                "SpriteDialog.labelSelectImage.accessible.description")); // NOI18N
0225:                buttonImportImages
0226:                        .getAccessibleContext()
0227:                        .setAccessibleName(
0228:                                org.openide.util.NbBundle
0229:                                        .getMessage(SpriteDialog.class,
0230:                                                "SpriteDialog.buttonImportImages.accessible.name")); // NOI18N
0231:                buttonImportImages
0232:                        .getAccessibleContext()
0233:                        .setAccessibleDescription(
0234:                                org.openide.util.NbBundle
0235:                                        .getMessage(SpriteDialog.class,
0236:                                                "SpriteDialog.buttonImportImages.accessible.description")); // NOI18N
0237:
0238:                labelImagePreview.setLabelFor(panelImage);
0239:                labelImagePreview.setText(org.openide.util.NbBundle.getMessage(
0240:                        SpriteDialog.class,
0241:                        "SpriteDialog.labelAdjustTileSize.txt")); // NOI18N
0242:
0243:                panelImage.setBorder(javax.swing.BorderFactory
0244:                        .createLineBorder(new java.awt.Color(102, 102, 102)));
0245:                panelImage.setLayout(new java.awt.BorderLayout());
0246:
0247:                sliderHeight.setOrientation(javax.swing.JSlider.VERTICAL);
0248:
0249:                labelTileWidth.setText(org.openide.util.NbBundle.getMessage(
0250:                        SpriteDialog.class, "SpriteDialog.labelTilewidth.txt",
0251:                        new Object[] { 0 })); // NOI18N
0252:
0253:                labelTileHeight.setText(org.openide.util.NbBundle.getMessage(
0254:                        SpriteDialog.class, "SpriteDialog.labelTileheight.txt",
0255:                        new Object[] { 0 // NOI18N
0256:                        }));
0257:
0258:                org.openide.awt.Mnemonics.setLocalizedText(checkBoxZoom,
0259:                        org.openide.util.NbBundle.getMessage(
0260:                                SpriteDialog.class,
0261:                                "SpriteDialog.labelZoom.txt")); // NOI18N
0262:                checkBoxZoom.setBorder(javax.swing.BorderFactory
0263:                        .createEmptyBorder(0, 0, 0, 0));
0264:                checkBoxZoom.setMargin(new java.awt.Insets(0, 0, 0, 0));
0265:
0266:                org.jdesktop.layout.GroupLayout panelPreviewLayout = new org.jdesktop.layout.GroupLayout(
0267:                        panelPreview);
0268:                panelPreview.setLayout(panelPreviewLayout);
0269:                panelPreviewLayout
0270:                        .setHorizontalGroup(panelPreviewLayout
0271:                                .createParallelGroup(
0272:                                        org.jdesktop.layout.GroupLayout.LEADING)
0273:                                .add(
0274:                                        panelPreviewLayout
0275:                                                .createSequentialGroup()
0276:                                                .addContainerGap()
0277:                                                .add(
0278:                                                        panelPreviewLayout
0279:                                                                .createParallelGroup(
0280:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0281:                                                                .add(
0282:                                                                        panelPreviewLayout
0283:                                                                                .createSequentialGroup()
0284:                                                                                .add(
0285:                                                                                        labelTileWidth)
0286:                                                                                .add(
0287:                                                                                        40,
0288:                                                                                        40,
0289:                                                                                        40)
0290:                                                                                .add(
0291:                                                                                        labelTileHeight)
0292:                                                                                .addContainerGap(
0293:                                                                                        217,
0294:                                                                                        Short.MAX_VALUE))
0295:                                                                .add(
0296:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0297:                                                                        panelPreviewLayout
0298:                                                                                .createSequentialGroup()
0299:                                                                                .add(
0300:                                                                                        panelPreviewLayout
0301:                                                                                                .createParallelGroup(
0302:                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0303:                                                                                                .add(
0304:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0305:                                                                                                        panelPreviewLayout
0306:                                                                                                                .createSequentialGroup()
0307:                                                                                                                .add(
0308:                                                                                                                        labelImagePreview)
0309:                                                                                                                .addPreferredGap(
0310:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED,
0311:                                                                                                                        240,
0312:                                                                                                                        Short.MAX_VALUE)
0313:                                                                                                                .add(
0314:                                                                                                                        checkBoxZoom))
0315:                                                                                                .add(
0316:                                                                                                        panelImage,
0317:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0318:                                                                                                        397,
0319:                                                                                                        Short.MAX_VALUE)
0320:                                                                                                .add(
0321:                                                                                                        sliderWidth,
0322:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0323:                                                                                                        397,
0324:                                                                                                        Short.MAX_VALUE))
0325:                                                                                .addPreferredGap(
0326:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0327:                                                                                .add(
0328:                                                                                        sliderHeight,
0329:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0330:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0331:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))));
0332:                panelPreviewLayout
0333:                        .setVerticalGroup(panelPreviewLayout
0334:                                .createParallelGroup(
0335:                                        org.jdesktop.layout.GroupLayout.LEADING)
0336:                                .add(
0337:                                        org.jdesktop.layout.GroupLayout.TRAILING,
0338:                                        panelPreviewLayout
0339:                                                .createSequentialGroup()
0340:                                                .add(
0341:                                                        panelPreviewLayout
0342:                                                                .createParallelGroup(
0343:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0344:                                                                .add(
0345:                                                                        labelImagePreview)
0346:                                                                .add(
0347:                                                                        checkBoxZoom))
0348:                                                .addPreferredGap(
0349:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0350:                                                .add(
0351:                                                        panelPreviewLayout
0352:                                                                .createParallelGroup(
0353:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0354:                                                                .add(
0355:                                                                        sliderHeight,
0356:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0357:                                                                        243,
0358:                                                                        Short.MAX_VALUE)
0359:                                                                .add(
0360:                                                                        panelImage,
0361:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0362:                                                                        243,
0363:                                                                        Short.MAX_VALUE))
0364:                                                .addPreferredGap(
0365:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0366:                                                .add(
0367:                                                        sliderWidth,
0368:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0369:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0370:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0371:                                                .addPreferredGap(
0372:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0373:                                                .add(
0374:                                                        panelPreviewLayout
0375:                                                                .createParallelGroup(
0376:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0377:                                                                .add(
0378:                                                                        labelTileHeight)
0379:                                                                .add(
0380:                                                                        labelTileWidth,
0381:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0382:                                                                        16,
0383:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))));
0384:
0385:                labelImagePreview
0386:                        .getAccessibleContext()
0387:                        .setAccessibleName(
0388:                                org.openide.util.NbBundle
0389:                                        .getMessage(SpriteDialog.class,
0390:                                                "SpriteDialog.labelAdjustTileSize.accessible.name")); // NOI18N
0391:                labelImagePreview
0392:                        .getAccessibleContext()
0393:                        .setAccessibleDescription(
0394:                                org.openide.util.NbBundle
0395:                                        .getMessage(SpriteDialog.class,
0396:                                                "SpriteDialog.labelAdjustTileSize.accessible.description")); // NOI18N
0397:                sliderWidth.getAccessibleContext().setAccessibleName(
0398:                        org.openide.util.NbBundle.getMessage(
0399:                                SpriteDialog.class,
0400:                                "SpriteDialog.sliderWidth.accessible.name")); // NOI18N
0401:                sliderWidth
0402:                        .getAccessibleContext()
0403:                        .setAccessibleDescription(
0404:                                org.openide.util.NbBundle
0405:                                        .getMessage(SpriteDialog.class,
0406:                                                "SpriteDialog.sliderWidth.accessible.description")); // NOI18N
0407:                sliderHeight.getAccessibleContext().setAccessibleName(
0408:                        org.openide.util.NbBundle.getMessage(
0409:                                SpriteDialog.class,
0410:                                "SpriteDialog.sliderHeight.accessible.name")); // NOI18N
0411:                sliderHeight
0412:                        .getAccessibleContext()
0413:                        .setAccessibleDescription(
0414:                                org.openide.util.NbBundle
0415:                                        .getMessage(SpriteDialog.class,
0416:                                                "SpriteDialog.sliderHeight.accessible.description")); // NOI18N
0417:                checkBoxZoom.getAccessibleContext().setAccessibleName(
0418:                        org.openide.util.NbBundle.getMessage(
0419:                                SpriteDialog.class,
0420:                                "SpriteDialog.labelZoom.accessible.name")); // NOI18N
0421:                checkBoxZoom
0422:                        .getAccessibleContext()
0423:                        .setAccessibleDescription(
0424:                                org.openide.util.NbBundle
0425:                                        .getMessage(SpriteDialog.class,
0426:                                                "SpriteDialog.labelZoom.accessible.description")); // NOI18N
0427:
0428:                labelError.setForeground(new java.awt.Color(255, 0, 0));
0429:
0430:                org.jdesktop.layout.GroupLayout panelErrorLayout = new org.jdesktop.layout.GroupLayout(
0431:                        panelError);
0432:                panelError.setLayout(panelErrorLayout);
0433:                panelErrorLayout.setHorizontalGroup(panelErrorLayout
0434:                        .createParallelGroup(
0435:                                org.jdesktop.layout.GroupLayout.LEADING).add(
0436:                                org.jdesktop.layout.GroupLayout.TRAILING,
0437:                                labelError,
0438:                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0439:                                696, Short.MAX_VALUE));
0440:                panelErrorLayout
0441:                        .setVerticalGroup(panelErrorLayout
0442:                                .createParallelGroup(
0443:                                        org.jdesktop.layout.GroupLayout.LEADING)
0444:                                .add(
0445:                                        panelErrorLayout
0446:                                                .createSequentialGroup()
0447:                                                .addContainerGap(24,
0448:                                                        Short.MAX_VALUE)
0449:                                                .add(
0450:                                                        labelError,
0451:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0452:                                                        27,
0453:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
0454:
0455:                labelLayerName.setLabelFor(fieldLayerName);
0456:                org.openide.awt.Mnemonics.setLocalizedText(labelLayerName,
0457:                        org.openide.util.NbBundle.getMessage(
0458:                                SpriteDialog.class,
0459:                                "SpriteDialog.labelSpriteName.txt")); // NOI18N
0460:
0461:                org.jdesktop.layout.GroupLayout panelLayerInfoLayout = new org.jdesktop.layout.GroupLayout(
0462:                        panelLayerInfo);
0463:                panelLayerInfo.setLayout(panelLayerInfoLayout);
0464:                panelLayerInfoLayout
0465:                        .setHorizontalGroup(panelLayerInfoLayout
0466:                                .createParallelGroup(
0467:                                        org.jdesktop.layout.GroupLayout.LEADING)
0468:                                .add(
0469:                                        panelLayerInfoLayout
0470:                                                .createSequentialGroup()
0471:                                                .add(
0472:                                                        labelLayerName,
0473:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0474:                                                        86,
0475:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0476:                                                .addPreferredGap(
0477:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0478:                                                .add(
0479:                                                        fieldLayerName,
0480:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0481:                                                        606, Short.MAX_VALUE)));
0482:                panelLayerInfoLayout
0483:                        .setVerticalGroup(panelLayerInfoLayout
0484:                                .createParallelGroup(
0485:                                        org.jdesktop.layout.GroupLayout.LEADING)
0486:                                .add(
0487:                                        panelLayerInfoLayout
0488:                                                .createSequentialGroup()
0489:                                                .addContainerGap()
0490:                                                .add(
0491:                                                        panelLayerInfoLayout
0492:                                                                .createParallelGroup(
0493:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0494:                                                                .add(
0495:                                                                        labelLayerName)
0496:                                                                .add(
0497:                                                                        fieldLayerName,
0498:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0499:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0500:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0501:                                                .addContainerGap(
0502:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0503:                                                        Short.MAX_VALUE)));
0504:
0505:                labelLayerName
0506:                        .getAccessibleContext()
0507:                        .setAccessibleName(
0508:                                org.openide.util.NbBundle
0509:                                        .getMessage(SpriteDialog.class,
0510:                                                "SpriteDialog.labelSpriteName.accessible.name")); // NOI18N
0511:                labelLayerName
0512:                        .getAccessibleContext()
0513:                        .setAccessibleDescription(
0514:                                org.openide.util.NbBundle
0515:                                        .getMessage(SpriteDialog.class,
0516:                                                "SpriteDialog.labelSpriteName.accessible.description")); // NOI18N
0517:
0518:                jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
0519:
0520:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
0521:                        this );
0522:                this .setLayout(layout);
0523:                layout
0524:                        .setHorizontalGroup(layout
0525:                                .createParallelGroup(
0526:                                        org.jdesktop.layout.GroupLayout.LEADING)
0527:                                .add(
0528:                                        layout
0529:                                                .createSequentialGroup()
0530:                                                .addContainerGap()
0531:                                                .add(
0532:                                                        layout
0533:                                                                .createParallelGroup(
0534:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0535:                                                                .add(
0536:                                                                        panelLayerInfo,
0537:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0538:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0539:                                                                        Short.MAX_VALUE)
0540:                                                                .add(
0541:                                                                        panelError,
0542:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0543:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0544:                                                                        Short.MAX_VALUE)
0545:                                                                .add(
0546:                                                                        jSeparator1,
0547:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0548:                                                                        696,
0549:                                                                        Short.MAX_VALUE)
0550:                                                                .add(
0551:                                                                        layout
0552:                                                                                .createSequentialGroup()
0553:                                                                                .add(
0554:                                                                                        panelCustomizer,
0555:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0556:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0557:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0558:                                                                                .addPreferredGap(
0559:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0560:                                                                                .add(
0561:                                                                                        jSeparator2,
0562:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0563:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0564:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0565:                                                                                .addPreferredGap(
0566:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0567:                                                                                .add(
0568:                                                                                        panelPreview,
0569:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0570:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0571:                                                                                        Short.MAX_VALUE)))
0572:                                                .addContainerGap()));
0573:                layout
0574:                        .setVerticalGroup(layout
0575:                                .createParallelGroup(
0576:                                        org.jdesktop.layout.GroupLayout.LEADING)
0577:                                .add(
0578:                                        layout
0579:                                                .createSequentialGroup()
0580:                                                .add(
0581:                                                        panelLayerInfo,
0582:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0583:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0584:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0585:                                                .addPreferredGap(
0586:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0587:                                                .add(
0588:                                                        jSeparator1,
0589:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0590:                                                        13,
0591:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0592:                                                .addPreferredGap(
0593:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0594:                                                .add(
0595:                                                        layout
0596:                                                                .createParallelGroup(
0597:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0598:                                                                .add(
0599:                                                                        panelPreview,
0600:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0601:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0602:                                                                        Short.MAX_VALUE)
0603:                                                                .add(
0604:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0605:                                                                        jSeparator2,
0606:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0607:                                                                        316,
0608:                                                                        Short.MAX_VALUE)
0609:                                                                .add(
0610:                                                                        layout
0611:                                                                                .createSequentialGroup()
0612:                                                                                .add(
0613:                                                                                        panelCustomizer,
0614:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0615:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0616:                                                                                        Short.MAX_VALUE)
0617:                                                                                .addPreferredGap(
0618:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)))
0619:                                                .addPreferredGap(
0620:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0621:                                                .add(
0622:                                                        panelError,
0623:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0624:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0625:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0626:                                                .addContainerGap()));
0627:            }// </editor-fold>//GEN-END:initComponents
0628:
0629:            // Variables declaration - do not modify//GEN-BEGIN:variables
0630:            private javax.swing.ButtonGroup buttonGroupLayers;
0631:            private javax.swing.JButton buttonImportImages;
0632:            private javax.swing.JCheckBox checkBoxZoom;
0633:            private javax.swing.JTextField fieldLayerName;
0634:            private javax.swing.JScrollPane jScrollPane1;
0635:            private javax.swing.JSeparator jSeparator1;
0636:            private javax.swing.JSeparator jSeparator2;
0637:            private javax.swing.JLabel labelError;
0638:            private javax.swing.JLabel labelImageFile;
0639:            private javax.swing.JLabel labelImagePreview;
0640:            private javax.swing.JLabel labelLayerName;
0641:            private javax.swing.JLabel labelTileHeight;
0642:            private javax.swing.JLabel labelTileWidth;
0643:            private javax.swing.JList listImageFileName;
0644:            private javax.swing.JPanel panelCustomizer;
0645:            private javax.swing.JPanel panelError;
0646:            private javax.swing.JPanel panelImage;
0647:            private javax.swing.JPanel panelLayerInfo;
0648:            private javax.swing.JPanel panelPreview;
0649:            private javax.swing.JSlider sliderHeight;
0650:            private javax.swing.JSlider sliderWidth;
0651:            // End of variables declaration//GEN-END:variables
0652:
0653:            private DialogDescriptor dd;
0654:
0655:            public static final boolean DEBUG = false;
0656:
0657:            private SliderListener sliderListener = new SliderListener();
0658:
0659:            private AbstractImagePreviewComponent imagePreview;
0660:            private PartialImageGridPreview partialImagePreview = new PartialImageGridPreview();
0661:            private FullImageGridPreview fullImagePreview = new FullImageGridPreview();
0662:
0663:            private Scene scene;
0664:
0665:            private List<Integer> tileWidths;
0666:            private List<Integer> tileHeigths;
0667:
0668:            public void setDialogDescriptor(DialogDescriptor dd) {
0669:                this .dd = dd;
0670:            }
0671:
0672:            private void init() {
0673:                HelpCtx.setHelpIDString(this ,
0674:                        "org.netbeans.modules.vmd.game.nbdialog.SpriteDialog");
0675:                this .getAccessibleContext().setAccessibleName(
0676:                        NbBundle.getMessage(TiledLayerDialog.class,
0677:                                "SpriteDialog.accessible.name"));
0678:                this .getAccessibleContext().setAccessibleDescription(
0679:                        NbBundle.getMessage(TiledLayerDialog.class,
0680:                                "SpriteDialog.accessible.description"));
0681:
0682:                this .labelError.setIcon(ICON_ERROR);
0683:
0684:                SpinnerNumberModel snm = new SpinnerNumberModel();
0685:                snm.setMinimum(1);
0686:                snm.setMaximum(256);
0687:                snm.setStepSize(1);
0688:                snm.setValue(5);
0689:
0690:                this .fieldLayerName.getDocument().addDocumentListener(
0691:                        new LayerFieldListener());
0692:                this .fieldLayerName.addFocusListener(new LayerFieldListener());
0693:
0694:                this .listImageFileName
0695:                        .addListSelectionListener(new ImageListListener());
0696:                this .listImageFileName
0697:                        .setCellRenderer(new DefaultListCellRenderer() {
0698:                            public Component getListCellRendererComponent(
0699:                                    JList src, Object value, int index,
0700:                                    boolean isSelected, boolean hasfocus) {
0701:                                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) value;
0702:                                return super .getListCellRendererComponent(src,
0703:                                        entry.getValue(), index, isSelected,
0704:                                        hasfocus);
0705:                            }
0706:                        });
0707:
0708:                this .sliderWidth.setModel(new DefaultBoundedRangeModel());
0709:                this .sliderHeight.setModel(new DefaultBoundedRangeModel());
0710:
0711:                this .sliderWidth.addChangeListener(sliderListener);
0712:                this .sliderHeight.addChangeListener(sliderListener);
0713:
0714:                this .sliderWidth.setValue(0);
0715:                this .sliderHeight.setValue(0);
0716:
0717:                this .sliderWidth.setPaintLabels(true);
0718:                this .sliderHeight.setPaintLabels(true);
0719:
0720:                this .sliderWidth.setSnapToTicks(true);
0721:                this .sliderHeight.setSnapToTicks(true);
0722:
0723:                this .sliderWidth.setEnabled(false);
0724:                this .sliderHeight.setEnabled(false);
0725:
0726:                this .buttonImportImages.addActionListener(this );
0727:
0728:                this .setPreviewFull();
0729:
0730:                this .checkBoxZoom.addActionListener(new ActionListener() {
0731:                    public void actionPerformed(ActionEvent e) {
0732:                        if (checkBoxZoom.isSelected()) {
0733:                            setPreviewPartial();
0734:                        } else {
0735:                            setPreviewFull();
0736:                        }
0737:                    }
0738:                });
0739:            }
0740:
0741:            private void setPreviewPartial() {
0742:                if (this .imagePreview != null) {
0743:                    try {
0744:                        if (DEBUG)
0745:                            System.out.println("setPreviewPartial"); // NOI18N
0746:                        this .partialImagePreview.setImageURL(this .imagePreview
0747:                                .getImageURL());
0748:                    } catch (MalformedURLException e) {
0749:                        this .labelError.setText(NbBundle.getMessage(
0750:                                SpriteDialog.class,
0751:                                "SpriteDialog.labelInvalidImgLoc.txt"));
0752:                        e.printStackTrace();
0753:                        return;
0754:                    } catch (IllegalArgumentException iae) {
0755:                        this .labelError.setText(NbBundle.getMessage(
0756:                                SpriteDialog.class,
0757:                                "SpriteDialog.labelInvalidImgFomat.txt"));
0758:                        iae.printStackTrace();
0759:                        return;
0760:                    }
0761:                    this .partialImagePreview.setTileWidth(this .imagePreview
0762:                            .getTileWidth());
0763:                    this .partialImagePreview.setTileHeight(this .imagePreview
0764:                            .getTileHeight());
0765:                }
0766:                this .panelImage.removeAll();
0767:                this .panelImage.add(this .partialImagePreview,
0768:                        BorderLayout.CENTER);
0769:                this .imagePreview = this .partialImagePreview;
0770:                this .repaint();
0771:                this .validate();
0772:            }
0773:
0774:            private void setPreviewFull() {
0775:                if (this .imagePreview != null) {
0776:                    try {
0777:                        if (DEBUG)
0778:                            System.out.println("setPreviewFull"); // NOI18N
0779:                        this .fullImagePreview.setImageURL(this .imagePreview
0780:                                .getImageURL());
0781:                    } catch (MalformedURLException e) {
0782:                        this .labelError.setText(NbBundle.getMessage(
0783:                                SpriteDialog.class,
0784:                                "SpriteDialog.labelInvalidImgLoc.txt"));
0785:                        e.printStackTrace();
0786:                        return;
0787:                    } catch (IllegalArgumentException iae) {
0788:                        this .labelError.setText(NbBundle.getMessage(
0789:                                SpriteDialog.class,
0790:                                "SpriteDialog.labelInvalidImgFomat.txt"));
0791:                        iae.printStackTrace();
0792:                        return;
0793:                    }
0794:                    this .fullImagePreview.setTileWidth(this .imagePreview
0795:                            .getTileWidth());
0796:                    this .fullImagePreview.setTileHeight(this .imagePreview
0797:                            .getTileHeight());
0798:                }
0799:                this .panelImage.removeAll();
0800:                JScrollPane scroll = new JScrollPane(this .fullImagePreview);
0801:                scroll.setBorder(BorderFactory.createEmptyBorder());
0802:                this .panelImage.add(scroll, BorderLayout.CENTER);
0803:                this .imagePreview = this .fullImagePreview;
0804:                this .repaint();
0805:                this .validate();
0806:            }
0807:
0808:            private List<Map.Entry<FileObject, String>> getImageList() {
0809:                Map<FileObject, String> imgMap = MidpProjectSupport
0810:                        .getImagesForProject(this .gameDesign
0811:                                .getDesignDocument(), true);
0812:                List<Map.Entry<FileObject, String>> list = new ArrayList<Map.Entry<FileObject, String>>();
0813:                list.addAll(imgMap.entrySet());
0814:                Collections.sort(list, new Comparator() {
0815:                    public int compare(Object a, Object b) {
0816:                        Map.Entry<FileObject, String> ea = (Map.Entry<FileObject, String>) a;
0817:                        Map.Entry<FileObject, String> eb = (Map.Entry<FileObject, String>) b;
0818:                        return ea.getValue().compareTo(eb.getValue());
0819:                    }
0820:                });
0821:                return list;
0822:            }
0823:
0824:            private DefaultListModel getImageListModel() {
0825:                DefaultListModel dlm = new DefaultListModel();
0826:                List<Map.Entry<FileObject, String>> images = this 
0827:                        .getImageList();
0828:                for (Map.Entry<FileObject, String> imageEntry : images) {
0829:                    dlm.addElement(imageEntry);
0830:                }
0831:                return dlm;
0832:            }
0833:
0834:            private class SliderListener implements  ChangeListener {
0835:
0836:                public void stateChanged(ChangeEvent e) {
0837:                    //System.out.println("Slider state changed");
0838:                    int tileWidth = SpriteDialog.this .tileWidths
0839:                            .get(((Integer) SpriteDialog.this .sliderWidth
0840:                                    .getValue()).intValue());
0841:                    int tileHeight = SpriteDialog.this .tileHeigths
0842:                            .get(((Integer) SpriteDialog.this .sliderHeight
0843:                                    .getValue()).intValue());
0844:
0845:                    if (e.getSource() == SpriteDialog.this .sliderHeight) {
0846:                        SpriteDialog.this .imagePreview
0847:                                .setTileHeight(tileHeight);
0848:                        SpriteDialog.this .labelTileHeight.setText(NbBundle
0849:                                .getMessage(SpriteDialog.class,
0850:                                        "SpriteDialog.labelTileheight.txt",
0851:                                        tileHeight));
0852:                    } else if (e.getSource() == SpriteDialog.this .sliderWidth) {
0853:                        SpriteDialog.this .imagePreview.setTileWidth(tileWidth);
0854:                        SpriteDialog.this .labelTileWidth.setText(NbBundle
0855:                                .getMessage(SpriteDialog.class,
0856:                                        "SpriteDialog.labelTilewidth.txt",
0857:                                        tileWidth));
0858:                    } else {
0859:                        if (DEBUG)
0860:                            System.out.println("ERR: ChangeEvent came from "
0861:                                    + e.getSource()); // NOI18N
0862:                    }
0863:                }
0864:
0865:            }
0866:
0867:            private class LayerFieldListener implements  DocumentListener,
0868:                    FocusListener {
0869:                public void insertUpdate(DocumentEvent e) {
0870:                    this .handleTextContentChange(e);
0871:                }
0872:
0873:                public void removeUpdate(DocumentEvent e) {
0874:                    this .handleTextContentChange(e);
0875:                }
0876:
0877:                public void changedUpdate(DocumentEvent e) {
0878:                    this .handleTextContentChange(e);
0879:                }
0880:
0881:                private void handleTextContentChange(DocumentEvent e) {
0882:                    String err = getFieldLayerNameError();
0883:                    if (e.getDocument() == SpriteDialog.this .fieldLayerName
0884:                            .getDocument()) {
0885:                        if (err == null) {
0886:                            err = getFieldImageFileNameError();
0887:                        }
0888:                        SpriteDialog.this .labelError.setText(err);
0889:                    }
0890:                    if (err == null) {
0891:                        SpriteDialog.this .setOKButtonEnabled(true);
0892:                    } else {
0893:                        SpriteDialog.this .setOKButtonEnabled(false);
0894:                    }
0895:                }
0896:
0897:                public void focusGained(FocusEvent e) {
0898:                    if (e.getComponent() == SpriteDialog.this .fieldLayerName) {
0899:                        SpriteDialog.this .labelError
0900:                                .setText(getFieldLayerNameError());
0901:                    }
0902:                    if (getFieldLayerNameError() == null
0903:                            && getFieldImageFileNameError() == null)
0904:                        SpriteDialog.this .setOKButtonEnabled(true);
0905:                    else
0906:                        SpriteDialog.this .setOKButtonEnabled(false);
0907:                }
0908:
0909:                public void focusLost(FocusEvent e) {
0910:                }
0911:            }
0912:
0913:            private String getFieldLayerNameError() {
0914:                String illegalIdentifierName = NbBundle
0915:                        .getMessage(SpriteDialog.class,
0916:                                "SpriteDialog.labelInvalidName.txt");
0917:                String errMsg = null;
0918:                String layerName = this .fieldLayerName.getText();
0919:                if (layerName.equals("")) {
0920:                    errMsg = NbBundle.getMessage(SpriteDialog.class,
0921:                            "SpriteDialog.labelEnterName.txt");
0922:                } else if (!this .gameDesign.isComponentNameAvailable(layerName)) {
0923:                    errMsg = NbBundle.getMessage(SpriteDialog.class,
0924:                            "SpriteDialog.labelNameExists.txt");
0925:                } else if (!isValidJavaIdentifier(layerName)) {
0926:                    errMsg = illegalIdentifierName;
0927:                }
0928:                return errMsg;
0929:            }
0930:
0931:            private static boolean isValidJavaIdentifier(String str) {
0932:                if (!Character.isJavaIdentifierStart(str.charAt(0))) {
0933:                    return false;
0934:                }
0935:                for (int i = 1; i < str.length(); i++) {
0936:                    if (!Character.isJavaIdentifierPart(str.charAt(i))) {
0937:                        return false;
0938:                    }
0939:                }
0940:                return true;
0941:            }
0942:
0943:            public void setOKButtonEnabled(boolean enable) {
0944:                if (!enable) {
0945:                    this .labelError.setIcon(ICON_ERROR);
0946:                } else {
0947:                    this .labelError.setIcon(null);
0948:                }
0949:                this .dd.setValid(enable);
0950:            }
0951:
0952:            private String getFieldImageFileNameError() {
0953:                String errMsg = null;
0954:                if (this .listImageFileName.getModel().getSize() == 0) {
0955:                    errMsg = NbBundle.getMessage(SpriteDialog.class,
0956:                            "SpriteDialog.labelNoImages.txt");
0957:                } else if (this .listImageFileName.getSelectedValue() == null) {
0958:                    errMsg = NbBundle.getMessage(SpriteDialog.class,
0959:                            "SpriteDialog.labelSelectImgFile.txt");
0960:                } else {
0961:                    Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
0962:                            .getSelectedValue();
0963:                    URL imageURL = null;
0964:                    try {
0965:                        imageURL = entry.getKey().getURL();
0966:                    } catch (Exception e) {
0967:                        e.printStackTrace();
0968:                    }
0969:                    String relativeResourcePath = entry.getValue();
0970:
0971:                    assert (imageURL != null);
0972:                    assert (relativeResourcePath != null);
0973:
0974:                    String imgName = CodeUtils
0975:                            .getIdealImageName(relativeResourcePath);
0976:
0977:                    List<String> derivedImageNames = GlobalRepository
0978:                            .deriveUsedNames(imgName);
0979:                    for (String derivedName : derivedImageNames) {
0980:                        if (derivedName.equals(this .fieldLayerName.getText())) {
0981:                            errMsg = NbBundle.getMessage(SpriteDialog.class,
0982:                                    "SpriteDialog.imgFileSameAsLayerName.txt");
0983:                        }
0984:                    }
0985:
0986:                }
0987:                return errMsg;
0988:            }
0989:
0990:            private class ImageListListener implements  ListSelectionListener {
0991:
0992:                public void valueChanged(ListSelectionEvent e) {
0993:                    if (e.getValueIsAdjusting()) {
0994:                        return;
0995:                    }
0996:                    this .handleImageSelectionChange();
0997:                }
0998:
0999:                private void handleImageSelectionChange() {
1000:                    SpriteDialog.this .sliderWidth.setEnabled(true);
1001:                    SpriteDialog.this .sliderHeight.setEnabled(true);
1002:                    String errMsg = null;
1003:
1004:                    errMsg = SpriteDialog.this .getFieldLayerNameError();
1005:                    try {
1006:                        SpriteDialog.this .loadImagePreview();
1007:                    } catch (MalformedURLException e) {
1008:                        errMsg = NbBundle.getMessage(SpriteDialog.class,
1009:                                "SpriteDialog.labelInvalidImgLoc.txt");
1010:                        e.printStackTrace();
1011:                    } catch (IllegalArgumentException iae) {
1012:                        errMsg = NbBundle.getMessage(SpriteDialog.class,
1013:                                "SpriteDialog.labelInvalidImgFomat.txt");
1014:                        iae.printStackTrace();
1015:                    }
1016:
1017:                    if (errMsg == null) {
1018:                        errMsg = SpriteDialog.this .getFieldImageFileNameError();
1019:                    }
1020:
1021:                    if (errMsg != null) {
1022:                        SpriteDialog.this .labelError.setText(errMsg);
1023:                        SpriteDialog.this .setOKButtonEnabled(false);
1024:                    } else {
1025:                        SpriteDialog.this .labelError.setText("");
1026:                        SpriteDialog.this .setOKButtonEnabled(true);
1027:                    }
1028:                }
1029:            }
1030:
1031:            private void loadImagePreview() throws MalformedURLException,
1032:                    IllegalArgumentException {
1033:                if (DEBUG)
1034:                    System.out.println("load image preview"); // NOI18N
1035:
1036:                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
1037:                        .getSelectedValue();
1038:                URL imageURL = null;
1039:                try {
1040:                    imageURL = entry.getKey().getURL();
1041:                } catch (Exception e) {
1042:                    e.printStackTrace();
1043:                }
1044:
1045:                assert (imageURL != null);
1046:
1047:                this .sliderWidth.removeChangeListener(this .sliderListener);
1048:                this .sliderHeight.removeChangeListener(this .sliderListener);
1049:
1050:                this .imagePreview.setImageURL(imageURL);
1051:
1052:                this .tileWidths = this .imagePreview.getValidTileWidths();
1053:                this .tileHeigths = this .imagePreview.getValidTileHeights();
1054:
1055:                DefaultBoundedRangeModel modelWidth = new DefaultBoundedRangeModel(
1056:                        tileWidths.size() - 1, 0, 0, tileWidths.size() - 1);
1057:                DefaultBoundedRangeModel modelHeight = new DefaultBoundedRangeModel(
1058:                        tileHeigths.size() - 1, 0, 0, tileHeigths.size() - 1);
1059:                this .sliderWidth.setModel(modelWidth);
1060:                this .sliderHeight.setModel(modelHeight);
1061:
1062:                this .sliderWidth
1063:                        .setValue(this .tileWidths.indexOf(getNearestValue(
1064:                                DEFAULT_TILE_WIDTH, tileWidths)));
1065:                this .sliderHeight.setValue(this .tileHeigths
1066:                        .indexOf(getNearestValue(DEFAULT_TILE_HEIGHT,
1067:                                tileHeigths)));
1068:
1069:                //set labels
1070:                int tileWidth = this .tileWidths.get(((Integer) this .sliderWidth
1071:                        .getValue()).intValue());
1072:                int tileHeight = this .tileHeigths
1073:                        .get(((Integer) this .sliderHeight.getValue())
1074:                                .intValue());
1075:
1076:                this .labelTileHeight.setText(NbBundle.getMessage(
1077:                        SpriteDialog.class, "SpriteDialog.labelTileheight.txt",
1078:                        tileHeight));
1079:                this .labelTileWidth.setText(NbBundle.getMessage(
1080:                        SpriteDialog.class, "SpriteDialog.labelTilewidth.txt",
1081:                        tileWidth));
1082:
1083:                this .imagePreview.setTileWidth(tileWidth);
1084:                this .imagePreview.setTileHeight(tileHeight);
1085:
1086:                this .repaint();
1087:
1088:                this .sliderWidth.addChangeListener(sliderListener);
1089:                this .sliderHeight.addChangeListener(sliderListener);
1090:
1091:            }
1092:
1093:            private static int getNearestValue(int mark, List<Integer> values) {
1094:                int nearest = Integer.MAX_VALUE;
1095:                for (Integer value : values) {
1096:                    int nearestDiff = Math.abs(mark - nearest);
1097:                    int valueDiff = Math.abs(mark - value);
1098:                    if (valueDiff < nearestDiff
1099:                            || (valueDiff == nearestDiff && value > nearest)) {
1100:                        nearest = value;
1101:                    }
1102:                }
1103:                return nearest;
1104:            }
1105:
1106:            public void actionPerformed(ActionEvent e) {
1107:                //if OK button pressed create the new layer
1108:                if (e.getSource() == NotifyDescriptor.OK_OPTION) {
1109:                    this .handleOKButton();
1110:                } else if (e.getSource() == this .buttonImportImages) {
1111:                    try {
1112:                        this .handleImportImagesButton();
1113:                    } catch (IOException ex) {
1114:                        ex.printStackTrace();
1115:                    }
1116:                }
1117:            }
1118:
1119:            private void handleImportImagesButton() throws IOException {
1120:                InputStream inImgPlatformTiles = SpriteDialog.class
1121:                        .getResourceAsStream("res/platform_tiles.png"); // NOI18N
1122:                assert inImgPlatformTiles != null;
1123:                InputStream inImgTopViewTiles = SpriteDialog.class
1124:                        .getResourceAsStream("res/topview_tiles.png"); // NOI18N
1125:                assert inImgTopViewTiles != null;
1126:
1127:                Project p = MidpProjectSupport
1128:                        .getProjectForDocument(this .gameDesign
1129:                                .getDesignDocument());
1130:                SourceGroup sg = MidpProjectSupport.getSourceGroup(p);
1131:                FileObject foSrc = sg.getRootFolder();
1132:
1133:                OutputStream topViewOut = null;
1134:                OutputStream platformOut = null;
1135:                try {
1136:                    FileObject foPlatform = FileUtil.createData(foSrc,
1137:                            "platform_tiles.png"); // NOI18N
1138:                    FileObject foTop = FileUtil.createData(foSrc,
1139:                            "topview_tiles.png"); // NOI18N
1140:
1141:                    platformOut = foPlatform.getOutputStream();
1142:                    FileUtil.copy(inImgPlatformTiles, platformOut);
1143:                    topViewOut = foTop.getOutputStream();
1144:                    FileUtil.copy(inImgTopViewTiles, topViewOut);
1145:                } finally {
1146:                    try {
1147:                        if (platformOut != null) {
1148:                            platformOut.close();
1149:                        }
1150:                        if (topViewOut != null) {
1151:                            topViewOut.close();
1152:                        }
1153:                    } catch (Exception ex) {
1154:                    }
1155:                }
1156:                this .listImageFileName.setModel(this .getImageListModel());
1157:                DialogDisplayer.getDefault().notify(
1158:                        new NotifyDescriptor.Message(NbBundle.getMessage(
1159:                                SpriteDialog.class,
1160:                                "SpriteDialog.imgImportedMsg.txt"),
1161:                                NotifyDescriptor.INFORMATION_MESSAGE));
1162:            }
1163:
1164:            private void handleOKButton() {
1165:                String name = this .fieldLayerName.getText();
1166:
1167:                int tileWidth = SpriteDialog.this .tileWidths
1168:                        .get(((Integer) SpriteDialog.this .sliderWidth
1169:                                .getValue()).intValue());
1170:                int tileHeight = SpriteDialog.this .tileHeigths
1171:                        .get(((Integer) SpriteDialog.this .sliderHeight
1172:                                .getValue()).intValue());
1173:
1174:                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
1175:                        .getSelectedValue();
1176:
1177:                URL imageURL = null;
1178:                try {
1179:                    imageURL = entry.getKey().getURL();
1180:                } catch (Exception e) {
1181:                    e.printStackTrace();
1182:                }
1183:                String relativeResourcePath = entry.getValue();
1184:
1185:                assert (imageURL != null);
1186:                assert (relativeResourcePath != null);
1187:
1188:                ImageResource imgRes = this.gameDesign.getImageResource(
1189:                        imageURL, relativeResourcePath);
1190:
1191:                if (this.scene != null) {
1192:                    this.scene.createSprite(name, imgRes, DEFAULT_FRAMES,
1193:                            tileWidth, tileHeight);
1194:                } else {
1195:                    this.gameDesign.createSprite(name, imgRes, DEFAULT_FRAMES,
1196:                            tileWidth, tileHeight);
1197:                }
1198:            }
1199:
1200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.