Source Code Cross Referenced for TiledLayerDialog.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.event.ChangeEvent;
0069:        import javax.swing.event.ChangeListener;
0070:        import javax.swing.event.DocumentEvent;
0071:        import javax.swing.event.DocumentListener;
0072:        import javax.swing.event.ListSelectionEvent;
0073:        import javax.swing.event.ListSelectionListener;
0074:        import org.netbeans.api.project.Project;
0075:        import org.netbeans.api.project.SourceGroup;
0076:        import org.netbeans.modules.vmd.game.dialog.AbstractImagePreviewComponent;
0077:        import org.netbeans.modules.vmd.game.dialog.FullImageGridPreview;
0078:        import org.netbeans.modules.vmd.game.dialog.PartialImageGridPreview;
0079:        import org.netbeans.modules.vmd.game.model.CodeUtils;
0080:        import org.netbeans.modules.vmd.game.model.GlobalRepository;
0081:        import org.netbeans.modules.vmd.game.model.ImageResource;
0082:        import org.netbeans.modules.vmd.game.model.Scene;
0083:        import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
0084:        import org.openide.DialogDescriptor;
0085:        import org.openide.DialogDisplayer;
0086:        import org.openide.NotifyDescriptor;
0087:        import org.openide.filesystems.FileObject;
0088:        import org.openide.filesystems.FileUtil;
0089:        import org.openide.util.HelpCtx;
0090:        import org.openide.util.NbBundle;
0091:        import org.openide.util.Utilities;
0092:
0093:        /**
0094:         *
0095:         * @author  kherink
0096:         */
0097:        public class TiledLayerDialog extends javax.swing.JPanel implements 
0098:                ActionListener {
0099:
0100:            private GlobalRepository gameDesign;
0101:
0102:            private static final Icon ICON_ERROR = new ImageIcon(
0103:                    Utilities
0104:                            .loadImage("org/netbeans/modules/vmd/midp/resources/error.gif")); // NOI18N
0105:
0106:            private static final int DEFAULT_COLS = 20;
0107:            private static final int DEFAULT_ROWS = 20;
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 TiledLayerDialog(GlobalRepository gameDesign) {
0113:                this .gameDesign = gameDesign;
0114:                initComponents();
0115:                manualInit();
0116:            }
0117:
0118:            public TiledLayerDialog(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:                fieldLayerName = new javax.swing.JTextField();
0150:                jLabel3 = new javax.swing.JLabel();
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:                                TiledLayerDialog.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:                                TiledLayerDialog.class,
0167:                                "SpriteDialog.buttonImportImages.txt")); // NOI18N
0168:                buttonImportImages.setActionCommand(org.openide.util.NbBundle
0169:                        .getMessage(TiledLayerDialog.class,
0170:                                "SpriteDialog.buttonImportImages.txt")); // NOI18N
0171:
0172:                org.jdesktop.layout.GroupLayout panelCustomizerLayout = new org.jdesktop.layout.GroupLayout(
0173:                        panelCustomizer);
0174:                panelCustomizer.setLayout(panelCustomizerLayout);
0175:                panelCustomizerLayout
0176:                        .setHorizontalGroup(panelCustomizerLayout
0177:                                .createParallelGroup(
0178:                                        org.jdesktop.layout.GroupLayout.LEADING)
0179:                                .add(
0180:                                        panelCustomizerLayout
0181:                                                .createSequentialGroup()
0182:                                                .add(
0183:                                                        panelCustomizerLayout
0184:                                                                .createParallelGroup(
0185:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0186:                                                                .add(
0187:                                                                        labelImageFile)
0188:                                                                .add(
0189:                                                                        buttonImportImages)
0190:                                                                .add(
0191:                                                                        jScrollPane1,
0192:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0193:                                                                        231,
0194:                                                                        Short.MAX_VALUE))
0195:                                                .addContainerGap()));
0196:                panelCustomizerLayout
0197:                        .setVerticalGroup(panelCustomizerLayout
0198:                                .createParallelGroup(
0199:                                        org.jdesktop.layout.GroupLayout.LEADING)
0200:                                .add(
0201:                                        panelCustomizerLayout
0202:                                                .createSequentialGroup()
0203:                                                .add(labelImageFile)
0204:                                                .addPreferredGap(
0205:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0206:                                                .add(
0207:                                                        jScrollPane1,
0208:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0209:                                                        261, Short.MAX_VALUE)
0210:                                                .add(18, 18, 18).add(
0211:                                                        buttonImportImages)));
0212:
0213:                labelImageFile
0214:                        .getAccessibleContext()
0215:                        .setAccessibleName(
0216:                                org.openide.util.NbBundle
0217:                                        .getMessage(TiledLayerDialog.class,
0218:                                                "SpriteDialog.labelSelectImage.accessible.name")); // NOI18N
0219:                labelImageFile
0220:                        .getAccessibleContext()
0221:                        .setAccessibleDescription(
0222:                                org.openide.util.NbBundle
0223:                                        .getMessage(TiledLayerDialog.class,
0224:                                                "SpriteDialog.labelSelectImage.accessible.description")); // NOI18N
0225:                buttonImportImages
0226:                        .getAccessibleContext()
0227:                        .setAccessibleName(
0228:                                org.openide.util.NbBundle
0229:                                        .getMessage(TiledLayerDialog.class,
0230:                                                "SpriteDialog.buttonImportImages.accessible.name")); // NOI18N
0231:                buttonImportImages
0232:                        .getAccessibleContext()
0233:                        .setAccessibleDescription(
0234:                                org.openide.util.NbBundle
0235:                                        .getMessage(TiledLayerDialog.class,
0236:                                                "SpriteDialog.buttonImportImages.accessible.description")); // NOI18N
0237:
0238:                labelImagePreview.setLabelFor(panelImage);
0239:                labelImagePreview.setText(org.openide.util.NbBundle.getMessage(
0240:                        TiledLayerDialog.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:                        TiledLayerDialog.class,
0251:                        "SpriteDialog.labelTilewidth.txt", new Object[] { 0 })); // NOI18N
0252:
0253:                labelTileHeight
0254:                        .setText(org.openide.util.NbBundle.getMessage(
0255:                                TiledLayerDialog.class,
0256:                                "SpriteDialog.labelTileheight.txt",
0257:                                new Object[] { 0 })); // NOI18N
0258:
0259:                org.openide.awt.Mnemonics.setLocalizedText(checkBoxZoom,
0260:                        org.openide.util.NbBundle.getMessage(
0261:                                TiledLayerDialog.class,
0262:                                "SpriteDialog.labelZoom.txt")); // NOI18N
0263:                checkBoxZoom.setBorder(javax.swing.BorderFactory
0264:                        .createEmptyBorder(0, 0, 0, 0));
0265:                checkBoxZoom.setMargin(new java.awt.Insets(0, 0, 0, 0));
0266:
0267:                org.jdesktop.layout.GroupLayout panelPreviewLayout = new org.jdesktop.layout.GroupLayout(
0268:                        panelPreview);
0269:                panelPreview.setLayout(panelPreviewLayout);
0270:                panelPreviewLayout
0271:                        .setHorizontalGroup(panelPreviewLayout
0272:                                .createParallelGroup(
0273:                                        org.jdesktop.layout.GroupLayout.LEADING)
0274:                                .add(
0275:                                        panelPreviewLayout
0276:                                                .createSequentialGroup()
0277:                                                .addContainerGap()
0278:                                                .add(
0279:                                                        panelPreviewLayout
0280:                                                                .createParallelGroup(
0281:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0282:                                                                .add(
0283:                                                                        panelPreviewLayout
0284:                                                                                .createSequentialGroup()
0285:                                                                                .add(
0286:                                                                                        labelTileWidth)
0287:                                                                                .add(
0288:                                                                                        51,
0289:                                                                                        51,
0290:                                                                                        51)
0291:                                                                                .add(
0292:                                                                                        labelTileHeight)
0293:                                                                                .addContainerGap())
0294:                                                                .add(
0295:                                                                        panelPreviewLayout
0296:                                                                                .createSequentialGroup()
0297:                                                                                .add(
0298:                                                                                        sliderWidth,
0299:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0300:                                                                                        389,
0301:                                                                                        Short.MAX_VALUE)
0302:                                                                                .add(
0303:                                                                                        22,
0304:                                                                                        22,
0305:                                                                                        22))
0306:                                                                .add(
0307:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0308:                                                                        panelPreviewLayout
0309:                                                                                .createSequentialGroup()
0310:                                                                                .add(
0311:                                                                                        panelPreviewLayout
0312:                                                                                                .createParallelGroup(
0313:                                                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0314:                                                                                                .add(
0315:                                                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0316:                                                                                                        panelPreviewLayout
0317:                                                                                                                .createSequentialGroup()
0318:                                                                                                                .add(
0319:                                                                                                                        labelImagePreview)
0320:                                                                                                                .addPreferredGap(
0321:                                                                                                                        org.jdesktop.layout.LayoutStyle.RELATED,
0322:                                                                                                                        224,
0323:                                                                                                                        Short.MAX_VALUE)
0324:                                                                                                                .add(
0325:                                                                                                                        checkBoxZoom))
0326:                                                                                                .add(
0327:                                                                                                        panelImage,
0328:                                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0329:                                                                                                        381,
0330:                                                                                                        Short.MAX_VALUE))
0331:                                                                                .addPreferredGap(
0332:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0333:                                                                                .add(
0334:                                                                                        sliderHeight,
0335:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0336:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0337:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))));
0338:                panelPreviewLayout
0339:                        .setVerticalGroup(panelPreviewLayout
0340:                                .createParallelGroup(
0341:                                        org.jdesktop.layout.GroupLayout.LEADING)
0342:                                .add(
0343:                                        org.jdesktop.layout.GroupLayout.TRAILING,
0344:                                        panelPreviewLayout
0345:                                                .createSequentialGroup()
0346:                                                .add(
0347:                                                        panelPreviewLayout
0348:                                                                .createParallelGroup(
0349:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0350:                                                                .add(
0351:                                                                        labelImagePreview)
0352:                                                                .add(
0353:                                                                        checkBoxZoom))
0354:                                                .addPreferredGap(
0355:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0356:                                                .add(
0357:                                                        panelPreviewLayout
0358:                                                                .createParallelGroup(
0359:                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
0360:                                                                .add(
0361:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0362:                                                                        sliderHeight,
0363:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0364:                                                                        249,
0365:                                                                        Short.MAX_VALUE)
0366:                                                                .add(
0367:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
0368:                                                                        panelImage,
0369:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0370:                                                                        249,
0371:                                                                        Short.MAX_VALUE))
0372:                                                .addPreferredGap(
0373:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0374:                                                .add(
0375:                                                        sliderWidth,
0376:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0377:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0378:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0379:                                                .addPreferredGap(
0380:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0381:                                                .add(
0382:                                                        panelPreviewLayout
0383:                                                                .createParallelGroup(
0384:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0385:                                                                .add(
0386:                                                                        labelTileWidth,
0387:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0388:                                                                        16,
0389:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0390:                                                                .add(
0391:                                                                        labelTileHeight))));
0392:
0393:                labelImagePreview
0394:                        .getAccessibleContext()
0395:                        .setAccessibleName(
0396:                                org.openide.util.NbBundle
0397:                                        .getMessage(TiledLayerDialog.class,
0398:                                                "SpriteDialog.labelAdjustTileSize.accessible.name")); // NOI18N
0399:                labelImagePreview
0400:                        .getAccessibleContext()
0401:                        .setAccessibleDescription(
0402:                                org.openide.util.NbBundle
0403:                                        .getMessage(TiledLayerDialog.class,
0404:                                                "SpriteDialog.labelAdjustTileSize.accessible.description")); // NOI18N
0405:                sliderWidth.getAccessibleContext().setAccessibleName(
0406:                        org.openide.util.NbBundle.getMessage(
0407:                                TiledLayerDialog.class,
0408:                                "SpriteDialog.sliderWidth.accessible.name")); // NOI18N
0409:                sliderWidth
0410:                        .getAccessibleContext()
0411:                        .setAccessibleDescription(
0412:                                org.openide.util.NbBundle
0413:                                        .getMessage(TiledLayerDialog.class,
0414:                                                "SpriteDialog.sliderWidth.accessible.description")); // NOI18N
0415:                sliderHeight.getAccessibleContext().setAccessibleName(
0416:                        org.openide.util.NbBundle.getMessage(
0417:                                TiledLayerDialog.class,
0418:                                "SpriteDialog.sliderHeight.accessible.name")); // NOI18N
0419:                sliderHeight
0420:                        .getAccessibleContext()
0421:                        .setAccessibleDescription(
0422:                                org.openide.util.NbBundle
0423:                                        .getMessage(TiledLayerDialog.class,
0424:                                                "SpriteDialog.sliderHeight.accessible.description")); // NOI18N
0425:                checkBoxZoom.getAccessibleContext().setAccessibleName(
0426:                        org.openide.util.NbBundle.getMessage(
0427:                                TiledLayerDialog.class,
0428:                                "SpriteDialog.labelZoom.accessible.name")); // NOI18N
0429:                checkBoxZoom
0430:                        .getAccessibleContext()
0431:                        .setAccessibleDescription(
0432:                                org.openide.util.NbBundle
0433:                                        .getMessage(TiledLayerDialog.class,
0434:                                                "SpriteDialog.labelZoom.accessible.description")); // NOI18N
0435:
0436:                labelError.setForeground(new java.awt.Color(255, 0, 0));
0437:
0438:                org.jdesktop.layout.GroupLayout panelErrorLayout = new org.jdesktop.layout.GroupLayout(
0439:                        panelError);
0440:                panelError.setLayout(panelErrorLayout);
0441:                panelErrorLayout.setHorizontalGroup(panelErrorLayout
0442:                        .createParallelGroup(
0443:                                org.jdesktop.layout.GroupLayout.LEADING).add(
0444:                                org.jdesktop.layout.GroupLayout.TRAILING,
0445:                                labelError,
0446:                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0447:                                686, Short.MAX_VALUE));
0448:                panelErrorLayout
0449:                        .setVerticalGroup(panelErrorLayout
0450:                                .createParallelGroup(
0451:                                        org.jdesktop.layout.GroupLayout.LEADING)
0452:                                .add(
0453:                                        panelErrorLayout
0454:                                                .createSequentialGroup()
0455:                                                .addContainerGap(24,
0456:                                                        Short.MAX_VALUE)
0457:                                                .add(
0458:                                                        labelError,
0459:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0460:                                                        27,
0461:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
0462:
0463:                jLabel3.setLabelFor(fieldLayerName);
0464:                org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
0465:                        org.openide.util.NbBundle.getMessage(
0466:                                TiledLayerDialog.class,
0467:                                "TiledLayerDialog.labelTiledLayerName.txt")); // NOI18N
0468:
0469:                org.jdesktop.layout.GroupLayout panelLayerInfoLayout = new org.jdesktop.layout.GroupLayout(
0470:                        panelLayerInfo);
0471:                panelLayerInfo.setLayout(panelLayerInfoLayout);
0472:                panelLayerInfoLayout
0473:                        .setHorizontalGroup(panelLayerInfoLayout
0474:                                .createParallelGroup(
0475:                                        org.jdesktop.layout.GroupLayout.LEADING)
0476:                                .add(
0477:                                        panelLayerInfoLayout
0478:                                                .createSequentialGroup()
0479:                                                .add(jLabel3)
0480:                                                .addPreferredGap(
0481:                                                        org.jdesktop.layout.LayoutStyle.UNRELATED)
0482:                                                .add(
0483:                                                        fieldLayerName,
0484:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0485:                                                        591, Short.MAX_VALUE)));
0486:                panelLayerInfoLayout
0487:                        .setVerticalGroup(panelLayerInfoLayout
0488:                                .createParallelGroup(
0489:                                        org.jdesktop.layout.GroupLayout.LEADING)
0490:                                .add(
0491:                                        panelLayerInfoLayout
0492:                                                .createSequentialGroup()
0493:                                                .addContainerGap()
0494:                                                .add(
0495:                                                        panelLayerInfoLayout
0496:                                                                .createParallelGroup(
0497:                                                                        org.jdesktop.layout.GroupLayout.BASELINE)
0498:                                                                .add(jLabel3)
0499:                                                                .add(
0500:                                                                        fieldLayerName,
0501:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0502:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0503:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0504:                                                .addContainerGap(
0505:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0506:                                                        Short.MAX_VALUE)));
0507:
0508:                jLabel3
0509:                        .getAccessibleContext()
0510:                        .setAccessibleName(
0511:                                org.openide.util.NbBundle
0512:                                        .getMessage(TiledLayerDialog.class,
0513:                                                "TiledLayerDialog.labelTiledLayerName.accessible.name")); // NOI18N
0514:                jLabel3
0515:                        .getAccessibleContext()
0516:                        .setAccessibleDescription(
0517:                                org.openide.util.NbBundle
0518:                                        .getMessage(TiledLayerDialog.class,
0519:                                                "TiledLayerDialog.labelTiledLayerName.accessible.description")); // NOI18N
0520:
0521:                jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
0522:
0523:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
0524:                        this );
0525:                this .setLayout(layout);
0526:                layout
0527:                        .setHorizontalGroup(layout
0528:                                .createParallelGroup(
0529:                                        org.jdesktop.layout.GroupLayout.LEADING)
0530:                                .add(
0531:                                        layout
0532:                                                .createSequentialGroup()
0533:                                                .addContainerGap()
0534:                                                .add(
0535:                                                        layout
0536:                                                                .createParallelGroup(
0537:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0538:                                                                .add(
0539:                                                                        panelLayerInfo,
0540:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0541:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0542:                                                                        Short.MAX_VALUE)
0543:                                                                .add(
0544:                                                                        layout
0545:                                                                                .createSequentialGroup()
0546:                                                                                .addPreferredGap(
0547:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0548:                                                                                .add(
0549:                                                                                        panelCustomizer,
0550:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0551:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0552:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0553:                                                                                .addPreferredGap(
0554:                                                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0555:                                                                                .add(
0556:                                                                                        jSeparator2,
0557:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0558:                                                                                        8,
0559:                                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0560:                                                                                .addPreferredGap(
0561:                                                                                        org.jdesktop.layout.LayoutStyle.UNRELATED)
0562:                                                                                .add(
0563:                                                                                        panelPreview,
0564:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0565:                                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0566:                                                                                        Short.MAX_VALUE))
0567:                                                                .add(
0568:                                                                        jSeparator1,
0569:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0570:                                                                        686,
0571:                                                                        Short.MAX_VALUE)
0572:                                                                .add(
0573:                                                                        org.jdesktop.layout.GroupLayout.TRAILING,
0574:                                                                        panelError,
0575:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0576:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0577:                                                                        Short.MAX_VALUE))
0578:                                                .addContainerGap()));
0579:                layout
0580:                        .setVerticalGroup(layout
0581:                                .createParallelGroup(
0582:                                        org.jdesktop.layout.GroupLayout.LEADING)
0583:                                .add(
0584:                                        layout
0585:                                                .createSequentialGroup()
0586:                                                .add(
0587:                                                        panelLayerInfo,
0588:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0589:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0590:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0591:                                                .addPreferredGap(
0592:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0593:                                                .add(
0594:                                                        jSeparator1,
0595:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0596:                                                        13,
0597:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0598:                                                .addPreferredGap(
0599:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
0600:                                                .add(
0601:                                                        layout
0602:                                                                .createParallelGroup(
0603:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
0604:                                                                .add(
0605:                                                                        panelCustomizer,
0606:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0607:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0608:                                                                        Short.MAX_VALUE)
0609:                                                                .add(
0610:                                                                        jSeparator2,
0611:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0612:                                                                        322,
0613:                                                                        Short.MAX_VALUE)
0614:                                                                .add(
0615:                                                                        panelPreview,
0616:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0617:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0618:                                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
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.JLabel jLabel3;
0635:            private javax.swing.JScrollPane jScrollPane1;
0636:            private javax.swing.JSeparator jSeparator1;
0637:            private javax.swing.JSeparator jSeparator2;
0638:            private javax.swing.JLabel labelError;
0639:            private javax.swing.JLabel labelImageFile;
0640:            private javax.swing.JLabel labelImagePreview;
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 manualInit() {
0673:                HelpCtx
0674:                        .setHelpIDString(this ,
0675:                                "org.netbeans.modules.vmd.game.nbdialog.TiledLayerDialog");
0676:
0677:                this .getAccessibleContext().setAccessibleName(
0678:                        NbBundle.getMessage(TiledLayerDialog.class,
0679:                                "TiledLayerDialog.accessible.name"));
0680:                this .getAccessibleContext().setAccessibleDescription(
0681:                        NbBundle.getMessage(TiledLayerDialog.class,
0682:                                "TiledLayerDialog.accessible.description"));
0683:
0684:                this .labelError.setIcon(ICON_ERROR);
0685:
0686:                this .fieldLayerName.getDocument().addDocumentListener(
0687:                        new LayerFieldListener());
0688:                this .fieldLayerName.addFocusListener(new LayerFieldListener());
0689:
0690:                this .listImageFileName
0691:                        .addListSelectionListener(new ImageListListener());
0692:                this .listImageFileName
0693:                        .setCellRenderer(new DefaultListCellRenderer() {
0694:                            public Component getListCellRendererComponent(
0695:                                    JList src, Object value, int index,
0696:                                    boolean isSelected, boolean hasfocus) {
0697:                                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) value;
0698:                                return super .getListCellRendererComponent(src,
0699:                                        entry.getValue(), index, isSelected,
0700:                                        hasfocus);
0701:                            }
0702:                        });
0703:
0704:                this .sliderWidth.setModel(new DefaultBoundedRangeModel());
0705:                this .sliderHeight.setModel(new DefaultBoundedRangeModel());
0706:
0707:                this .sliderWidth.addChangeListener(sliderListener);
0708:                this .sliderHeight.addChangeListener(sliderListener);
0709:
0710:                this .sliderWidth.setValue(0);
0711:                this .sliderHeight.setValue(0);
0712:
0713:                this .sliderWidth.setPaintLabels(true);
0714:                this .sliderHeight.setPaintLabels(true);
0715:
0716:                this .sliderWidth.setSnapToTicks(true);
0717:                this .sliderHeight.setSnapToTicks(true);
0718:
0719:                this .sliderWidth.setEnabled(false);
0720:                this .sliderHeight.setEnabled(false);
0721:
0722:                this .buttonImportImages.addActionListener(this );
0723:
0724:                this .setPreviewFull();
0725:
0726:                this .checkBoxZoom.addActionListener(new ActionListener() {
0727:                    public void actionPerformed(ActionEvent e) {
0728:                        if (TiledLayerDialog.this .checkBoxZoom.isSelected()) {
0729:                            setPreviewPartial();
0730:                        } else {
0731:                            setPreviewFull();
0732:                        }
0733:                    }
0734:                });
0735:            }
0736:
0737:            private void setPreviewPartial() {
0738:                if (this .imagePreview != null) {
0739:                    try {
0740:                        if (DEBUG)
0741:                            System.out.println("setPreviewPartial"); // NOI18N
0742:                        this .partialImagePreview.setImageURL(this .imagePreview
0743:                                .getImageURL());
0744:                    } catch (MalformedURLException e) {
0745:                        this .labelError.setText(NbBundle.getMessage(
0746:                                TiledLayerDialog.class,
0747:                                "SpriteDialog.labelInvalidImgLoc.txt"));
0748:                        e.printStackTrace();
0749:                        return;
0750:                    } catch (IllegalArgumentException iae) {
0751:                        this .labelError.setText(NbBundle.getMessage(
0752:                                TiledLayerDialog.class,
0753:                                "SpriteDialog.labelInvalidImgFomat.txt"));
0754:                        return;
0755:                    }
0756:                    this .partialImagePreview.setTileWidth(this .imagePreview
0757:                            .getTileWidth());
0758:                    this .partialImagePreview.setTileHeight(this .imagePreview
0759:                            .getTileHeight());
0760:                }
0761:                this .panelImage.removeAll();
0762:                this .panelImage.add(this .partialImagePreview,
0763:                        BorderLayout.CENTER);
0764:                this .imagePreview = this .partialImagePreview;
0765:                this .repaint();
0766:                this .validate();
0767:            }
0768:
0769:            private void setPreviewFull() {
0770:                if (this .imagePreview != null) {
0771:                    try {
0772:                        if (DEBUG)
0773:                            System.out.println("setPreviewFull"); // NOI18N
0774:                        this .fullImagePreview.setImageURL(this .imagePreview
0775:                                .getImageURL());
0776:                    } catch (MalformedURLException e) {
0777:                        this .labelError.setText(NbBundle.getMessage(
0778:                                TiledLayerDialog.class,
0779:                                "SpriteDialog.labelInvalidImgLoc.txt"));
0780:                        e.printStackTrace();
0781:                        return;
0782:                    } catch (IllegalArgumentException iae) {
0783:                        this .labelError.setText(NbBundle.getMessage(
0784:                                TiledLayerDialog.class,
0785:                                "SpriteDialog.labelInvalidImgFomat.txt"));
0786:                        iae.printStackTrace();
0787:                        return;
0788:                    }
0789:                    this .fullImagePreview.setTileWidth(this .imagePreview
0790:                            .getTileWidth());
0791:                    this .fullImagePreview.setTileHeight(this .imagePreview
0792:                            .getTileHeight());
0793:                }
0794:                this .panelImage.removeAll();
0795:                JScrollPane scroll = new JScrollPane(this .fullImagePreview);
0796:                scroll.setBorder(BorderFactory.createEmptyBorder());
0797:                this .panelImage.add(scroll, BorderLayout.CENTER);
0798:                this .imagePreview = this .fullImagePreview;
0799:                this .repaint();
0800:                this .validate();
0801:            }
0802:
0803:            private List<Map.Entry<FileObject, String>> getImageList() {
0804:                Map<FileObject, String> imgMap = MidpProjectSupport
0805:                        .getImagesForProject(this .gameDesign
0806:                                .getDesignDocument(), true);
0807:                List<Map.Entry<FileObject, String>> list = new ArrayList<Map.Entry<FileObject, String>>();
0808:                list.addAll(imgMap.entrySet());
0809:                Collections.sort(list, new Comparator() {
0810:                    public int compare(Object a, Object b) {
0811:                        Map.Entry<FileObject, String> ea = (Map.Entry<FileObject, String>) a;
0812:                        Map.Entry<FileObject, String> eb = (Map.Entry<FileObject, String>) b;
0813:                        return ea.getValue().compareTo(eb.getValue());
0814:                    }
0815:                });
0816:                return list;
0817:            }
0818:
0819:            private DefaultListModel getImageListModel() {
0820:                DefaultListModel dlm = new DefaultListModel();
0821:                List<Map.Entry<FileObject, String>> images = this 
0822:                        .getImageList();
0823:                for (Map.Entry<FileObject, String> imageEntry : images) {
0824:                    dlm.addElement(imageEntry);
0825:                }
0826:                return dlm;
0827:            }
0828:
0829:            private class SliderListener implements  ChangeListener {
0830:
0831:                public void stateChanged(ChangeEvent e) {
0832:                    int tileWidth = TiledLayerDialog.this .tileWidths
0833:                            .get(((Integer) TiledLayerDialog.this .sliderWidth
0834:                                    .getValue()).intValue());
0835:                    int tileHeight = TiledLayerDialog.this .tileHeigths
0836:                            .get(((Integer) TiledLayerDialog.this .sliderHeight
0837:                                    .getValue()).intValue());
0838:
0839:                    if (e.getSource() == TiledLayerDialog.this .sliderHeight) {
0840:                        TiledLayerDialog.this .imagePreview
0841:                                .setTileHeight(tileHeight);
0842:                        TiledLayerDialog.this .labelTileHeight.setText(NbBundle
0843:                                .getMessage(TiledLayerDialog.class,
0844:                                        "SpriteDialog.labelTileheight.txt",
0845:                                        tileHeight));
0846:                    } else if (e.getSource() == TiledLayerDialog.this .sliderWidth) {
0847:                        TiledLayerDialog.this .imagePreview
0848:                                .setTileWidth(tileWidth);
0849:                        TiledLayerDialog.this .labelTileWidth.setText(NbBundle
0850:                                .getMessage(TiledLayerDialog.class,
0851:                                        "SpriteDialog.labelTilewidth.txt",
0852:                                        tileWidth));
0853:                    } else {
0854:                        if (DEBUG)
0855:                            System.out.println("ERR: Spinner event came from "
0856:                                    + e.getSource()); // NOI18N
0857:                    }
0858:                }
0859:
0860:            }
0861:
0862:            private class LayerFieldListener implements  DocumentListener,
0863:                    FocusListener {
0864:                public void insertUpdate(DocumentEvent e) {
0865:                    this .handleTextContentChange(e);
0866:                }
0867:
0868:                public void removeUpdate(DocumentEvent e) {
0869:                    this .handleTextContentChange(e);
0870:                }
0871:
0872:                public void changedUpdate(DocumentEvent e) {
0873:                    this .handleTextContentChange(e);
0874:                }
0875:
0876:                private void handleTextContentChange(DocumentEvent e) {
0877:                    String err = getFieldLayerNameError();
0878:                    if (e.getDocument() == TiledLayerDialog.this .fieldLayerName
0879:                            .getDocument()) {
0880:                        if (err == null) {
0881:                            err = getFieldImageFileNameError();
0882:                        }
0883:                        TiledLayerDialog.this .labelError.setText(err);
0884:                    }
0885:                    if (err == null) {
0886:                        TiledLayerDialog.this .setOKButtonEnabled(true);
0887:                    } else {
0888:                        TiledLayerDialog.this .setOKButtonEnabled(false);
0889:                    }
0890:                }
0891:
0892:                public void focusGained(FocusEvent e) {
0893:                    if (e.getComponent() == TiledLayerDialog.this .fieldLayerName) {
0894:                        TiledLayerDialog.this .labelError
0895:                                .setText(getFieldLayerNameError());
0896:                    }
0897:                    if (getFieldLayerNameError() == null
0898:                            && getFieldImageFileNameError() == null)
0899:                        TiledLayerDialog.this .setOKButtonEnabled(true);
0900:                    else
0901:                        TiledLayerDialog.this .setOKButtonEnabled(false);
0902:                }
0903:
0904:                public void focusLost(FocusEvent e) {
0905:                }
0906:            }
0907:
0908:            private String getFieldLayerNameError() {
0909:                String illegalIdentifierName = NbBundle.getMessage(
0910:                        TiledLayerDialog.class,
0911:                        "SpriteDialog.labelInvalidName.txt");
0912:                String errMsg = null;
0913:                String layerName = this .fieldLayerName.getText();
0914:                if (layerName.equals("")) {
0915:                    errMsg = NbBundle.getMessage(TiledLayerDialog.class,
0916:                            "SpriteDialog.labelEnterName.txt");
0917:                } else if (!this .gameDesign.isComponentNameAvailable(layerName)) {
0918:                    errMsg = NbBundle.getMessage(TiledLayerDialog.class,
0919:                            "SpriteDialog.labelNameExists.txt");
0920:                } else if (!isValidJavaIdentifier(layerName)) {
0921:                    errMsg = illegalIdentifierName;
0922:                }
0923:                return errMsg;
0924:            }
0925:
0926:            private static boolean isValidJavaIdentifier(String str) {
0927:                if (!Character.isJavaIdentifierStart(str.charAt(0))) {
0928:                    return false;
0929:                }
0930:                for (int i = 1; i < str.length(); i++) {
0931:                    if (!Character.isJavaIdentifierPart(str.charAt(i))) {
0932:                        return false;
0933:                    }
0934:                }
0935:                return true;
0936:            }
0937:
0938:            public void setOKButtonEnabled(boolean enable) {
0939:                if (!enable) {
0940:                    this .labelError.setIcon(ICON_ERROR);
0941:                } else {
0942:                    this .labelError.setIcon(null);
0943:                }
0944:                this .dd.setValid(enable);
0945:            }
0946:
0947:            private String getFieldImageFileNameError() {
0948:                String errMsg = null;
0949:                if (this .listImageFileName.getModel().getSize() == 0) {
0950:                    errMsg = NbBundle.getMessage(TiledLayerDialog.class,
0951:                            "SpriteDialog.labelNoImages.txt");
0952:                } else if (this .listImageFileName.getSelectedValue() == null) {
0953:                    errMsg = NbBundle.getMessage(TiledLayerDialog.class,
0954:                            "SpriteDialog.labelSelectImgFile.txt");
0955:                } else {
0956:                    Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
0957:                            .getSelectedValue();
0958:                    URL imageURL = null;
0959:                    try {
0960:                        imageURL = entry.getKey().getURL();
0961:                    } catch (Exception e) {
0962:                        e.printStackTrace();
0963:                    }
0964:                    String relativeResourcePath = entry.getValue();
0965:
0966:                    assert (imageURL != null);
0967:                    assert (relativeResourcePath != null);
0968:
0969:                    String imgName = CodeUtils
0970:                            .getIdealImageName(relativeResourcePath);
0971:
0972:                    List<String> derivedImageNames = GlobalRepository
0973:                            .deriveUsedNames(imgName);
0974:                    for (String derivedName : derivedImageNames) {
0975:                        if (derivedName.equals(this .fieldLayerName.getText())) {
0976:                            errMsg = NbBundle.getMessage(SpriteDialog.class,
0977:                                    "SpriteDialog.imgFileSameAsLayerName.txt");
0978:                        }
0979:                    }
0980:                }
0981:                return errMsg;
0982:            }
0983:
0984:            private class ImageListListener implements  ListSelectionListener {
0985:
0986:                public void valueChanged(ListSelectionEvent e) {
0987:                    if (e.getValueIsAdjusting()) {
0988:                        return;
0989:                    }
0990:                    this .handleImageSelectionChange();
0991:                }
0992:
0993:                private void handleImageSelectionChange() {
0994:                    TiledLayerDialog.this .sliderWidth.setEnabled(true);
0995:                    TiledLayerDialog.this .sliderHeight.setEnabled(true);
0996:                    String errMsg = null;
0997:
0998:                    errMsg = TiledLayerDialog.this .getFieldLayerNameError();
0999:                    try {
1000:                        TiledLayerDialog.this .loadImagePreview();
1001:                    } catch (MalformedURLException e) {
1002:                        errMsg = NbBundle.getMessage(TiledLayerDialog.class,
1003:                                "SpriteDialog.labelInvalidImgLoc.txt");
1004:                        e.printStackTrace();
1005:                    } catch (IllegalArgumentException iae) {
1006:                        errMsg = NbBundle.getMessage(TiledLayerDialog.class,
1007:                                "SpriteDialog.labelInvalidImgFomat.txt");
1008:                        iae.printStackTrace();
1009:                    }
1010:
1011:                    if (errMsg == null) {
1012:                        errMsg = TiledLayerDialog.this 
1013:                                .getFieldImageFileNameError();
1014:                    }
1015:
1016:                    if (errMsg != null) {
1017:                        TiledLayerDialog.this .labelError.setText(errMsg);
1018:                        TiledLayerDialog.this .setOKButtonEnabled(false);
1019:                    } else {
1020:                        TiledLayerDialog.this .labelError.setText("");
1021:                        TiledLayerDialog.this .setOKButtonEnabled(true);
1022:                    }
1023:                }
1024:            }
1025:
1026:            private void loadImagePreview() throws MalformedURLException,
1027:                    IllegalArgumentException {
1028:                if (DEBUG)
1029:                    System.out.println("load image preview"); // NOI18N
1030:
1031:                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
1032:                        .getSelectedValue();
1033:                URL imageURL = null;
1034:                try {
1035:                    imageURL = entry.getKey().getURL();
1036:                } catch (Exception e) {
1037:                    e.printStackTrace();
1038:                }
1039:
1040:                assert (imageURL != null);
1041:
1042:                this .sliderWidth.removeChangeListener(this .sliderListener);
1043:                this .sliderHeight.removeChangeListener(this .sliderListener);
1044:
1045:                this .imagePreview.setImageURL(imageURL);
1046:
1047:                this .tileWidths = this .imagePreview.getValidTileWidths();
1048:                this .tileHeigths = this .imagePreview.getValidTileHeights();
1049:
1050:                DefaultBoundedRangeModel modelWidth = new DefaultBoundedRangeModel(
1051:                        tileWidths.size() - 1, 0, 0, tileWidths.size() - 1);
1052:                DefaultBoundedRangeModel modelHeight = new DefaultBoundedRangeModel(
1053:                        tileHeigths.size() - 1, 0, 0, tileHeigths.size() - 1);
1054:                this .sliderWidth.setModel(modelWidth);
1055:                this .sliderHeight.setModel(modelHeight);
1056:
1057:                this .sliderWidth
1058:                        .setValue(this .tileWidths.indexOf(getNearestValue(
1059:                                DEFAULT_TILE_WIDTH, tileWidths)));
1060:                this .sliderHeight.setValue(this .tileHeigths
1061:                        .indexOf(getNearestValue(DEFAULT_TILE_HEIGHT,
1062:                                tileHeigths)));
1063:
1064:                //set labels
1065:                int tileWidth = this .tileWidths.get(((Integer) this .sliderWidth
1066:                        .getValue()).intValue());
1067:                int tileHeight = this .tileHeigths
1068:                        .get(((Integer) this .sliderHeight.getValue())
1069:                                .intValue());
1070:
1071:                this .labelTileHeight.setText(NbBundle.getMessage(
1072:                        TiledLayerDialog.class,
1073:                        "SpriteDialog.labelTileheight.txt", tileHeight));
1074:                this .labelTileWidth.setText(NbBundle.getMessage(
1075:                        TiledLayerDialog.class,
1076:                        "SpriteDialog.labelTilewidth.txt", tileWidth));
1077:
1078:                this .imagePreview.setTileWidth(tileWidth);
1079:                this .imagePreview.setTileHeight(tileHeight);
1080:
1081:                this .repaint();
1082:
1083:                this .sliderWidth.addChangeListener(sliderListener);
1084:                this .sliderHeight.addChangeListener(sliderListener);
1085:
1086:            }
1087:
1088:            private static int getNearestValue(int mark, List<Integer> values) {
1089:                int nearest = Integer.MAX_VALUE;
1090:                for (Integer value : values) {
1091:                    int nearestDiff = Math.abs(mark - nearest);
1092:                    int valueDiff = Math.abs(mark - value);
1093:                    if (valueDiff < nearestDiff
1094:                            || (valueDiff == nearestDiff && value > nearest)) {
1095:                        nearest = value;
1096:                    }
1097:                }
1098:                return nearest;
1099:            }
1100:
1101:            public void actionPerformed(ActionEvent e) {
1102:                //if OK button pressed create the new layer
1103:                if (e.getSource() == NotifyDescriptor.OK_OPTION) {
1104:                    this .handleOKButton();
1105:                }
1106:                if (e.getSource() == this .buttonImportImages) {
1107:                    try {
1108:                        this .handleImportImagesButton();
1109:                    } catch (IOException ex) {
1110:                        ex.printStackTrace();
1111:                    }
1112:                }
1113:            }
1114:
1115:            private void handleImportImagesButton() throws IOException {
1116:                InputStream inImgPlatformTiles = TiledLayerDialog.class
1117:                        .getResourceAsStream("res/platform_tiles.png"); // NOI18N
1118:                assert inImgPlatformTiles != null;
1119:                InputStream inImgTopViewTiles = TiledLayerDialog.class
1120:                        .getResourceAsStream("res/topview_tiles.png"); // NOI18N
1121:                assert inImgTopViewTiles != null;
1122:
1123:                Project p = MidpProjectSupport
1124:                        .getProjectForDocument(this .gameDesign
1125:                                .getDesignDocument());
1126:                SourceGroup sg = MidpProjectSupport.getSourceGroup(p);
1127:                FileObject foSrc = sg.getRootFolder();
1128:
1129:                OutputStream topViewOut = null;
1130:                OutputStream platformOut = null;
1131:                try {
1132:                    FileObject foPlatform = FileUtil.createData(foSrc,
1133:                            "platform_tiles.png"); // NOI18N
1134:                    FileObject foTop = FileUtil.createData(foSrc,
1135:                            "topview_tiles.png"); // NOI18N
1136:
1137:                    platformOut = foPlatform.getOutputStream();
1138:                    FileUtil.copy(inImgPlatformTiles, platformOut);
1139:                    topViewOut = foTop.getOutputStream();
1140:                    FileUtil.copy(inImgTopViewTiles, topViewOut);
1141:                } finally {
1142:                    try {
1143:                        if (platformOut != null) {
1144:                            platformOut.close();
1145:                        }
1146:                        if (topViewOut != null) {
1147:                            topViewOut.close();
1148:                        }
1149:                    } catch (Exception ex) {
1150:                    }
1151:                }
1152:                this .listImageFileName.setModel(this .getImageListModel());
1153:                DialogDisplayer.getDefault().notify(
1154:                        new NotifyDescriptor.Message(NbBundle.getMessage(
1155:                                TiledLayerDialog.class,
1156:                                "SpriteDialog.imgImportedMsg.txt"),
1157:                                NotifyDescriptor.INFORMATION_MESSAGE));
1158:            }
1159:
1160:            private void handleOKButton() {
1161:                String name = this .fieldLayerName.getText();
1162:
1163:                int tileWidth = TiledLayerDialog.this .tileWidths
1164:                        .get(((Integer) TiledLayerDialog.this .sliderWidth
1165:                                .getValue()).intValue());
1166:                int tileHeight = TiledLayerDialog.this .tileHeigths
1167:                        .get(((Integer) TiledLayerDialog.this .sliderHeight
1168:                                .getValue()).intValue());
1169:
1170:                Map.Entry<FileObject, String> entry = (Map.Entry<FileObject, String>) this .listImageFileName
1171:                        .getSelectedValue();
1172:
1173:                URL imageURL = null;
1174:                try {
1175:                    imageURL = entry.getKey().getURL();
1176:                } catch (Exception e) {
1177:                    e.printStackTrace();
1178:                }
1179:                String relativeResourcePath = entry.getValue();
1180:
1181:                assert (imageURL != null);
1182:                assert (relativeResourcePath != null);
1183:
1184:                ImageResource imgRes = this .gameDesign.getImageResource(
1185:                        imageURL, relativeResourcePath);
1186:
1187:                if (this .scene != null) {
1188:                    this .scene.createTiledLayer(name, imgRes, DEFAULT_ROWS,
1189:                            DEFAULT_COLS, tileWidth, tileHeight);
1190:                } else {
1191:                    this .gameDesign.createTiledLayer(name, imgRes,
1192:                            (Integer) DEFAULT_ROWS, DEFAULT_COLS, tileWidth,
1193:                            tileHeight);
1194:                }
1195:            }
1196:
1197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.