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


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.vmd.game.model;
042:
043:        import java.awt.Dialog;
044:        import java.awt.Graphics2D;
045:        import java.awt.Point;
046:        import java.awt.Rectangle;
047:        import java.awt.event.ActionEvent;
048:        import java.beans.PropertyChangeEvent;
049:        import java.beans.PropertyChangeListener;
050:        import java.beans.PropertyChangeSupport;
051:        import java.util.ArrayList;
052:        import java.util.Collections;
053:        import java.util.Comparator;
054:        import java.util.HashMap;
055:        import java.util.Iterator;
056:        import java.util.List;
057:        import javax.swing.AbstractAction;
058:        import javax.swing.Action;
059:        import javax.swing.JComponent;
060:        import javax.swing.event.EventListenerList;
061:        import org.netbeans.modules.vmd.game.dialog.RenameSceneDialog;
062:        import org.netbeans.modules.vmd.game.editor.scene.SceneEditor;
063:        import org.netbeans.modules.vmd.game.editor.scene.SceneLayerNavigator;
064:        import org.netbeans.modules.vmd.game.editor.scene.ScenePreviewPanel;
065:        import org.netbeans.modules.vmd.game.nbdialog.SpriteDialog;
066:        import org.netbeans.modules.vmd.game.nbdialog.TiledLayerDialog;
067:        import org.openide.DialogDescriptor;
068:        import org.openide.DialogDisplayer;
069:        import org.openide.NotifyDescriptor;
070:        import org.openide.util.NbBundle;
071:
072:        public class Scene implements  GlobalRepositoryListener,
073:                PropertyChangeListener, Previewable, Editable, Identifiable {
074:
075:            private long id = Identifiable.ID_UNKNOWN;
076:
077:            public static final boolean DEBUG = false;
078:
079:            public static final String PROPERTY_LAYERS_BOUNDS = "prop.layers.bounds"; // NOI18N
080:
081:            EventListenerList listenerList = new EventListenerList();
082:
083:            // ---------- PropertyChangeSupport
084:            PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
085:                    this );
086:
087:            private ArrayList<Layer> layers = new ArrayList<Layer>();
088:            private HashMap<Layer, LayerInfo> layerInfos = new HashMap<Layer, LayerInfo>();
089:            private String name;
090:
091:            private SceneLayerNavigator navigator;
092:            private ScenePreviewPanel preview;
093:
094:            private Rectangle allLayersBounds = new Rectangle();
095:            private SceneEditor editor;
096:
097:            private GlobalRepository gameDesign;
098:
099:            Scene(GlobalRepository gameDesign, String name) {
100:                assert (gameDesign != null);
101:                this .gameDesign = gameDesign;
102:                editor = null;
103:                this .name = name;
104:                this .gameDesign.addGlobalRepositoryListener(this );
105:            }
106:
107:            Scene(GlobalRepository gameDesign, String name, Scene other) {
108:                this (gameDesign, name);
109:                for (Iterator iter = other.layers.iterator(); iter.hasNext();) {
110:                    Layer layer = (Layer) iter.next();
111:                    this .insert(layer, other.indexOf(layer));
112:                    this .setLayerLocked(layer, other.isLayerLocked(layer));
113:                    this .setLayerPosition(layer, other.getLayerPosition(layer),
114:                            false);
115:                    this .setLayerVisible(layer, other.isLayerVisible(layer));
116:                }
117:            }
118:
119:            public String getName() {
120:                return this .name;
121:            }
122:
123:            public void setName(String name) {
124:                if (name == null) {
125:                    return;
126:                }
127:                if (this .getName().equals(name)) {
128:                    return;
129:                }
130:                if (!this .gameDesign.isComponentNameAvailable(name)) {
131:                    throw new IllegalArgumentException(
132:                            "Scene cannot be renamed because component name '"
133:                                    + name + "' already exists."); // NOI18N
134:                }
135:                String oldName = this .name;
136:                this .name = name;
137:                this .propertyChangeSupport.firePropertyChange(PROPERTY_NAME,
138:                        oldName, this .name);
139:            }
140:
141:            public void addPropertyChangeListener(PropertyChangeListener l) {
142:                propertyChangeSupport.addPropertyChangeListener(l);
143:            }
144:
145:            public void removePropertyChangeListener(PropertyChangeListener l) {
146:                propertyChangeSupport.removePropertyChangeListener(l);
147:            }
148:
149:            public synchronized void addSceneListener(SceneListener l) {
150:                this .listenerList.add(SceneListener.class, l);
151:            }
152:
153:            public synchronized void removeSceneListener(SceneListener l) {
154:                this .listenerList.remove(SceneListener.class, l);
155:            }
156:
157:            public Rectangle getAllLayersBounds() {
158:                return this .allLayersBounds;
159:            }
160:
161:            private void updateLayersBounds() {
162:                int xMin = Integer.MAX_VALUE;
163:                int xMax = Integer.MIN_VALUE;
164:                int yMin = Integer.MAX_VALUE;
165:                int yMax = Integer.MIN_VALUE;
166:
167:                for (Iterator iter = this .getLayers().iterator(); iter
168:                        .hasNext();) {
169:                    Layer layer = (Layer) iter.next();
170:                    ///System.out.println("looking at " + layer);
171:                    Point point = this .getLayerPosition(layer);
172:                    xMin = xMin < point.x ? xMin : point.x;
173:                    yMin = yMin < point.y ? yMin : point.y;
174:
175:                    int right = point.x + layer.getWidth();
176:                    xMax = xMax > right ? xMax : right;
177:
178:                    int bottom = point.y + layer.getHeight();
179:                    ;
180:                    yMax = yMax > bottom ? yMax : bottom;
181:                }
182:                Rectangle newBounds = new Rectangle(xMin, yMin, xMax - xMin,
183:                        yMax - yMin);
184:                if (!this .allLayersBounds.equals(newBounds)) {
185:                    //System.out.println("bounds changed from: " + this.allLayersBounds + " to " + newBounds);
186:                    Rectangle oldBounds = this .allLayersBounds;
187:                    this .allLayersBounds = newBounds;
188:                    this .propertyChangeSupport.firePropertyChange(
189:                            PROPERTY_LAYERS_BOUNDS, oldBounds, newBounds);
190:                }
191:            }
192:
193:            public TiledLayer createTiledLayer(String name,
194:                    ImageResource imageResource, int rows, int columns,
195:                    int tileWidth, int tileHeight) {
196:                TiledLayer layer = this .gameDesign.createTiledLayer(name,
197:                        imageResource, rows, columns, tileWidth, tileHeight);
198:                this .append(layer);
199:                return layer;
200:            }
201:
202:            public Sprite createSprite(String name,
203:                    ImageResource imageResource, int numberFrames,
204:                    int frameWidth, int frameHeight) {
205:                Sprite sprite = this .gameDesign.createSprite(name,
206:                        imageResource, numberFrames, frameWidth, frameHeight);
207:                this .append(sprite);
208:                return sprite;
209:            }
210:
211:            private LayerInfo getLayerInfo(Layer l) {
212:                return this .layerInfos.get(l);
213:            }
214:
215:            public boolean contains(Layer layer) {
216:                return this .indexOf(layer) >= 0;
217:            }
218:
219:            /**
220:             * Appends a layer to the end of this scene (furthest position from the user), 
221:             * if the layer is already in the scene it is first removed.
222:             */
223:            public void append(Layer layer) {
224:                if (DEBUG)
225:                    System.out.println(this  + " append " + layer); // NOI18N
226:                if (this .layers.contains(layer)) {
227:                    this .remove(layer);
228:                }
229:                this .layers.add(layer);
230:                LayerInfo info = new LayerInfo();
231:                this .layerInfos.put(layer, info);
232:                int index = layers.indexOf(layer);
233:                layer.addPropertyChangeListener(this );
234:                this .updateLayersBounds();
235:                this .fireLayerAdded(layer, index);
236:            }
237:
238:            /**
239:             * Inserts a layer to this scene at the specified index, 
240:             * if the layer is already in the scene it is first removed.
241:             */
242:            public void insert(Layer layer, int index) {
243:                if (DEBUG)
244:                    System.out.println(this  + " insert " + layer); // NOI18N
245:                if (this .layers.contains(layer)) {
246:                    this .move(layer, index);
247:                    return;
248:                }
249:                this .layers.add(index, layer);
250:                LayerInfo info = new LayerInfo();
251:                this .layerInfos.put(layer, info);
252:                layer.addPropertyChangeListener(this );
253:                this .updateLayersBounds();
254:                this .fireLayerAdded(layer, index);
255:            }
256:
257:            /**
258:             * Removed the layer from this scene.
259:             */
260:            public void remove(Layer layer) {
261:                if (DEBUG)
262:                    System.out.println(this  + " remove " + layer); // NOI18N
263:                int index = layers.indexOf(layer);
264:                if (this .layers.remove(layer)) {
265:                    layer.removePropertyChangeListener(this );
266:                    this .updateLayersBounds();
267:                    this .fireLayerRemoved(layer, index);
268:                }
269:            }
270:
271:            /**
272:             * Move layer to a different position in the scene.
273:             */
274:            public void move(Layer layer, int newIndex) {
275:                int oldIndex = layers.indexOf(layer);
276:                if (oldIndex == -1) {
277:                    if (DEBUG)
278:                        System.out.println(this  + " cannot move " + layer
279:                                + " - it is not present"); // NOI18N
280:                    return;
281:                }
282:                if (DEBUG)
283:                    System.out.println(this  + " move " + layer + " from "
284:                            + oldIndex + " to " + newIndex); // NOI18N
285:                if (oldIndex == newIndex) {
286:                    return;
287:                }
288:                this .layers.remove(layer);
289:                this .layers.ensureCapacity(newIndex + 1);
290:                this .layers.add(newIndex, layer);
291:                this .updateLayersBounds();
292:                this .fireLayerMoved(layer, oldIndex, newIndex);
293:            }
294:
295:            private void fireLayerMoved(Layer layer, int oldIndex, int newIndex) {
296:                Object[] listeners = listenerList.getListenerList();
297:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
298:                    if (listeners[i] == SceneListener.class) {
299:                        ((SceneListener) listeners[i + 1]).layerMoved(this ,
300:                                layer, oldIndex, newIndex);
301:                    }
302:                }
303:            }
304:
305:            private void fireLayerAdded(Layer layer, int index) {
306:                Object[] listeners = listenerList.getListenerList();
307:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
308:                    if (listeners[i] == SceneListener.class) {
309:                        ((SceneListener) listeners[i + 1]).layerAdded(this ,
310:                                layer, index);
311:                    }
312:                }
313:            }
314:
315:            private void fireLayerRemoved(Layer layer, int index) {
316:                Object[] listeners = listenerList.getListenerList();
317:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
318:                    if (listeners[i] == SceneListener.class) {
319:                        ((SceneListener) listeners[i + 1]).layerRemoved(this ,
320:                                layer, (LayerInfo) this .getLayerInfo(layer),
321:                                index);
322:                    }
323:                }
324:            }
325:
326:            private void fireLayerPositionModified(Layer layer, int index,
327:                    Point oldPosition, Point newPosition, boolean inTransition) {
328:                Object[] listeners = listenerList.getListenerList();
329:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
330:                    if (listeners[i] == SceneListener.class) {
331:                        ((SceneListener) listeners[i + 1])
332:                                .layerPositionChanged(this , layer, oldPosition,
333:                                        newPosition, inTransition);
334:                    }
335:                }
336:            }
337:
338:            private void fireLayerLockModified(Layer layer, int index,
339:                    boolean locked) {
340:                Object[] listeners = listenerList.getListenerList();
341:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
342:                    if (listeners[i] == SceneListener.class) {
343:                        ((SceneListener) listeners[i + 1]).layerLockChanged(
344:                                this , layer, locked);
345:                    }
346:                }
347:            }
348:
349:            private void fireLayerVisibilityModified(Layer layer, int index,
350:                    boolean visible) {
351:                Object[] listeners = listenerList.getListenerList();
352:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
353:                    if (listeners[i] == SceneListener.class) {
354:                        ((SceneListener) listeners[i + 1])
355:                                .layerVisibilityChanged(this , layer, visible);
356:                    }
357:                }
358:            }
359:
360:            public int indexOf(Layer layer) {
361:                return this .layers.indexOf(layer);
362:            }
363:
364:            public Layer getLayerAt(int index) {
365:                return (Layer) layers.get(index);
366:            }
367:
368:            public int getLayerCount() {
369:                return layers.size();
370:            }
371:
372:            public List<Layer> getLayers() {
373:                return Collections.unmodifiableList(this .layers);
374:            }
375:
376:            public List<Layer> getLayersAtPoint(Point p) {
377:                List<Layer> layers = new ArrayList<Layer>();
378:                for (Iterator iter = this .layers.iterator(); iter.hasNext();) {
379:                    Layer l = (Layer) iter.next();
380:                    LayerInfo li = this .getLayerInfo(l);
381:                    Point lp = li.getPosition();
382:                    if (lp.equals(p)) {
383:                        layers.add(l);
384:                        continue;
385:                    }
386:                    //if too far right
387:                    if (lp.x > p.x) {
388:                        continue;
389:                    }
390:                    //if too far below
391:                    if (lp.y > p.y) {
392:                        continue;
393:                    }
394:                    if (this .getLayerBounds(l).contains(p)) {
395:                        layers.add(l);
396:                    }
397:                }
398:                Collections.sort(layers, new LayerIndexComparator());
399:                return layers;
400:            }
401:
402:            private class LayerIndexComparator implements  Comparator<Layer> {
403:                public int compare(Layer l1, Layer l2) {
404:                    return Scene.this .layers.indexOf(l1)
405:                            - Scene.this .layers.indexOf(l2);
406:                }
407:            }
408:
409:            public Rectangle getLayerBounds(Layer layer) {
410:                Point p = this .getLayerPosition(layer);
411:                return new Rectangle(p.x, p.y, layer.getWidth(), layer
412:                        .getHeight());
413:            }
414:
415:            public Point getLayerPosition(Layer layer) {
416:                Point position = ((LayerInfo) this .getLayerInfo(layer))
417:                        .getPosition();
418:                return position;
419:            }
420:
421:            public void setLayerPositionX(Layer layer, int x,
422:                    boolean inTransition) {
423:                Point p = this .getLayerPosition(layer);
424:                p.x = x;
425:                this .setLayerPosition(layer, p, inTransition);
426:            }
427:
428:            public void setLayerPositionY(Layer layer, int y,
429:                    boolean inTransition) {
430:                Point p = this .getLayerPosition(layer);
431:                p.y = y;
432:                this .setLayerPosition(layer, p, inTransition);
433:            }
434:
435:            public void setLayerPosition(Layer layer, int x, int y,
436:                    boolean inTransition) {
437:                Point p = this .getLayerPosition(layer);
438:                p.x = x;
439:                p.y = y;
440:                this .setLayerPosition(layer, p, inTransition);
441:            }
442:
443:            public void setLayerPosition(Layer layer, Point position,
444:                    boolean inTransition) {
445:                if (this .isLayerLocked(layer))
446:                    throw new IllegalArgumentException("Layer: " + layer
447:                            + " is locked"); // NOI18N
448:                if (DEBUG)
449:                    System.out.println(layer + " set position " + position); // NOI18N
450:                LayerInfo info = (LayerInfo) this .getLayerInfo(layer);
451:                Point old = info.getPosition();
452:                //		if (old.equals(position)) {
453:                //			return;
454:                //		}
455:                info.setPosition(position);
456:                this .updateLayersBounds();
457:                this .fireLayerPositionModified(layer, this .layers
458:                        .indexOf(layer), old, info.getPosition(), inTransition);
459:            }
460:
461:            public boolean isLayerVisible(Layer layer) {
462:                return ((LayerInfo) this .getLayerInfo(layer)).isVisible();
463:            }
464:
465:            public void setLayerVisible(Layer layer, boolean visible) {
466:                if (DEBUG)
467:                    System.out.println(layer + " set visible " + visible); // NOI18N
468:                boolean old = this .getLayerInfo(layer).isVisible();
469:                if (old == visible) {
470:                    return;
471:                }
472:                this .getLayerInfo(layer).setVisible(visible);
473:                this .fireLayerVisibilityModified(layer, this .layers
474:                        .indexOf(layer), visible);
475:            }
476:
477:            public boolean isLayerLocked(Layer layer) {
478:                return ((LayerInfo) this .getLayerInfo(layer)).isLocked();
479:            }
480:
481:            public void setLayerLocked(Layer layer, boolean locked) {
482:                if (DEBUG)
483:                    System.out.println(layer + " set locked " + locked); // NOI18N
484:                boolean old = this .getLayerInfo(layer).isLocked();
485:                if (old == locked) {
486:                    return;
487:                }
488:                this .getLayerInfo(layer).setLocked(locked);
489:                this .fireLayerLockModified(layer, this .layers.indexOf(layer),
490:                        locked);
491:            }
492:
493:            public static class LayerInfo {
494:                private Point position;
495:                private boolean visible;
496:                private boolean locked;
497:
498:                public LayerInfo() {
499:                    this .position = new Point();
500:                    this .visible = true;
501:                }
502:
503:                @Override
504:                public String toString() {
505:                    return "Position: " + this .position + ", visible: "
506:                            + this .visible + ", locked: " + this .locked; // NOI18N
507:                }
508:
509:                /**
510:                 * Returns a COPY of layers position, changes to the returned objet don't affect the
511:                 * LayerInfo, to change the layer position use LayerInfo.setPosition()
512:                 * @return layer position within scene.
513:                 */
514:                public Point getPosition() {
515:                    return new Point(this .position);
516:                }
517:
518:                public void setPosition(Point position) {
519:                    this .position = position;
520:                }
521:
522:                public boolean isVisible() {
523:                    return this .visible;
524:                }
525:
526:                public void setVisible(boolean visible) {
527:                    this .visible = visible;
528:                }
529:
530:                public boolean isLocked() {
531:                    return this .locked;
532:                }
533:
534:                public void setLocked(boolean locked) {
535:                    if (DEBUG)
536:                        System.out.println("setting layer locked = " + locked); // NOI18N
537:                    this .locked = locked;
538:                }
539:
540:            }
541:
542:            // PropertyChangeListener
543:            public void propertyChange(PropertyChangeEvent evt) {
544:                if (DEBUG)
545:                    System.out.println("property change from "
546:                            + evt.getSource() + " new value: "
547:                            + evt.getNewValue()); // NOI18N
548:            }
549:
550:            public JComponent getEditor() {
551:                if (null == this .editor)
552:                    this .editor = new SceneEditor(this );
553:                return this .editor.getJComponent();
554:            }
555:
556:            public ImageResourceInfo getImageResourceInfo() {
557:                return null;
558:            }
559:
560:            public GlobalRepository getGameDesign() {
561:                return this .gameDesign;
562:            }
563:
564:            public String toString() {
565:                return this .name;
566:            }
567:
568:            static class NameComparator implements  Comparator {
569:
570:                public int compare(Object arg0, Object arg1) {
571:                    if (!(arg0 instanceof  Scene) || !(arg1 instanceof  Scene))
572:                        throw new ClassCastException(
573:                                "Compared object not instance of Scene"); // NOI18N
574:                    Scene s0 = (Scene) arg0;
575:                    Scene s1 = (Scene) arg1;
576:                    return (s0.getName().compareTo(s1.getName()));
577:                }
578:            }
579:
580:            public List<Action> getActions() {
581:                ArrayList<Action> actions = new ArrayList<Action>();
582:                actions.add(new EditSceneAction());
583:                actions.add(new RemoveSceneAction());
584:                actions.add(new RenameSceneAction());
585:                return Collections.unmodifiableList(actions);
586:            }
587:
588:            public class RenameSceneAction extends AbstractAction {
589:                {
590:                    this .putValue(NAME, NbBundle.getMessage(Scene.class,
591:                            "Scene.RenameSceneAction.text"));
592:                }
593:
594:                public void actionPerformed(ActionEvent e) {
595:                    RenameSceneDialog dialog = new RenameSceneDialog(Scene.this );
596:                    DialogDescriptor dd = new DialogDescriptor(dialog, NbBundle
597:                            .getMessage(Scene.class,
598:                                    "Scene.RenameSceneAction.text"));
599:                    dd.setButtonListener(dialog);
600:                    dd.setValid(false);
601:                    dialog.setDialogDescriptor(dd);
602:                    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
603:                    d.setVisible(true);
604:                }
605:            }
606:
607:            public class EditSceneAction extends AbstractAction {
608:                {
609:                    this .putValue(NAME, NbBundle.getMessage(Scene.class,
610:                            "Scene.EditSceneAction.text"));
611:                }
612:
613:                public void actionPerformed(ActionEvent e) {
614:                    Scene.this .gameDesign.getMainView().requestEditing(
615:                            Scene.this );
616:                }
617:            }
618:
619:            public class CreateSpriteAction extends AbstractAction {
620:                {
621:                    this .putValue(NAME, NbBundle.getMessage(Scene.class,
622:                            "Scene.CreateSpriteAction.text"));
623:                }
624:
625:                public void actionPerformed(ActionEvent e) {
626:                    SpriteDialog nld = new SpriteDialog(Scene.this );
627:                    DialogDescriptor dd = new DialogDescriptor(nld, NbBundle
628:                            .getMessage(Scene.class,
629:                                    "Scene.CreateSpriteAction.text"));
630:                    dd.setButtonListener(nld);
631:                    dd.setValid(false);
632:                    nld.setDialogDescriptor(dd);
633:                    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
634:                    d.setVisible(true);
635:                }
636:            }
637:
638:            public class CreateTiledLayerAction extends AbstractAction {
639:                {
640:                    this .putValue(NAME, NbBundle.getMessage(Scene.class,
641:                            "Scene.CreateTiledLayerAction.text"));
642:                }
643:
644:                public void actionPerformed(ActionEvent e) {
645:                    TiledLayerDialog nld = new TiledLayerDialog(Scene.this );
646:                    DialogDescriptor dd = new DialogDescriptor(nld, NbBundle
647:                            .getMessage(Scene.class,
648:                                    "Scene.CreateTiledLayerAction.text"));
649:                    dd.setButtonListener(nld);
650:                    dd.setValid(false);
651:                    nld.setDialogDescriptor(dd);
652:                    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
653:                    d.setVisible(true);
654:                }
655:            }
656:
657:            public class RemoveSceneAction extends AbstractAction {
658:                {
659:                    this .putValue(NAME, NbBundle.getMessage(Scene.class,
660:                            "Scene.RemoveSceneAction.text"));
661:                }
662:
663:                public void actionPerformed(ActionEvent e) {
664:                    Object response = DialogDisplayer.getDefault().notify(
665:                            new NotifyDescriptor(NbBundle.getMessage(
666:                                    Scene.class, "Scene.RemoveDialog.text",
667:                                    getName()), NbBundle
668:                                    .getMessage(Scene.class,
669:                                            "Scene.RemoveSceneAction.text"),
670:                                    NotifyDescriptor.YES_NO_OPTION,
671:                                    NotifyDescriptor.QUESTION_MESSAGE,
672:                                    new Object[] { NotifyDescriptor.YES_OPTION,
673:                                            NotifyDescriptor.NO_OPTION },
674:                                    NotifyDescriptor.YES_OPTION));
675:                    if (response == NotifyDescriptor.YES_OPTION) {
676:                        gameDesign.removeScene(Scene.this );
677:                    }
678:                }
679:            }
680:
681:            //----GlobalRepositoryListener
682:            public void sceneAdded(Scene scene, int index) {
683:            }
684:
685:            public void sceneRemoved(Scene scene, int index) {
686:            }
687:
688:            public void tiledLayerAdded(TiledLayer tiledLayer, int index) {
689:            }
690:
691:            public void tiledLayerRemoved(TiledLayer tiledLayer, int index) {
692:                this .remove(tiledLayer);
693:            }
694:
695:            public void spriteAdded(Sprite sprite, int index) {
696:            }
697:
698:            public void spriteRemoved(Sprite sprite, int index) {
699:                this .remove(sprite);
700:            }
701:
702:            public void imageResourceAdded(ImageResource imageResource) {
703:            }
704:
705:            //-----Previewable
706:            public JComponent getPreview() {
707:                if (this .preview == null) {
708:                    return this .preview = new ScenePreviewPanel(this );
709:                }
710:                return this .preview;
711:            }
712:
713:            public JComponent getNavigator() {
714:                if (this .navigator == null) {
715:                    return this .navigator = new SceneLayerNavigator(this );
716:                }
717:                return this .navigator;
718:            }
719:
720:            public void paint(Graphics2D g, int x, int y) {
721:            }
722:
723:            public int getWidth() {
724:                return 0;
725:            }
726:
727:            public int getHeight() {
728:                return 0;
729:            }
730:
731:            public long getId() {
732:                return id;
733:            }
734:
735:            public void setId(long id) {
736:                this.id = id;
737:            }
738:
739:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.