Source Code Cross Referenced for Layer.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:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         *
006:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
007:         *
008:         * The contents of this file are subject to the terms of either the GNU
009:         * General Public License Version 2 only ("GPL") or the Common
010:         * Development and Distribution License("CDDL") (collectively, the
011:         * "License"). You may not use this file except in compliance with the
012:         * License. You can obtain a copy of the License at
013:         * http://www.netbeans.org/cddl-gplv2.html
014:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
015:         * specific language governing permissions and limitations under the
016:         * License.  When distributing the software, include this License Header
017:         * Notice in each file and include the License file at
018:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
019:         * particular file as subject to the "Classpath" exception as provided
020:         * by Sun in the GPL Version 2 section of the License file that
021:         * accompanied this code. If applicable, add the following below the
022:         * License Header, with the fields enclosed by brackets [] replaced by
023:         * your own identifying information:
024:         * "Portions Copyrighted [year] [name of copyright owner]"
025:         *
026:         * Contributor(s):
027:         *
028:         * The Original Software is NetBeans. The Initial Developer of the Original
029:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
030:         * Microsystems, Inc. All Rights Reserved.
031:         *
032:         * If you wish your version of this file to be governed by only the CDDL
033:         * or only the GPL Version 2, indicate your decision by adding
034:         * "[Contributor] elects to include this software in this distribution
035:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
036:         * single choice of license, a recipient has the option to distribute
037:         * your version of this file under either the CDDL, the GPL Version 2 or
038:         * to extend the choice of license to its licensees as provided above.
039:         * However, if you add GPL Version 2 code and therefore, elected the GPL
040:         * Version 2 license, then the option applies only if the new code is
041:         * made subject to such option by the copyright holder.
042:         */
043:        package org.netbeans.modules.vmd.game.model;
044:
045:        import java.awt.Graphics2D;
046:        import java.awt.datatransfer.DataFlavor;
047:        import java.awt.datatransfer.Transferable;
048:        import java.awt.datatransfer.UnsupportedFlavorException;
049:        import java.awt.event.ActionEvent;
050:        import java.beans.PropertyChangeListener;
051:        import java.beans.PropertyChangeSupport;
052:        import java.io.IOException;
053:        import java.util.ArrayList;
054:        import java.util.Collections;
055:        import java.util.Comparator;
056:        import java.util.List;
057:        import javax.swing.AbstractAction;
058:        import javax.swing.Action;
059:        import javax.swing.JComponent;
060:        import org.openide.DialogDisplayer;
061:        import org.openide.NotifyDescriptor;
062:        import org.openide.util.NbBundle;
063:
064:        public abstract class Layer implements  Previewable, Editable,
065:                Transferable, Identifiable {
066:
067:            private long id = Identifiable.ID_UNKNOWN;
068:
069:            public static final String ACTION_PROP_SCENE = "layer.action.prop.scene"; // NOI18N
070:
071:            protected PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
072:                    this );
073:
074:            private GlobalRepository gameDesign;
075:
076:            private String name;
077:            private ImageResource imageResource;
078:            private int cellWidth;
079:            private int cellHeight;
080:
081:            protected Layer(GlobalRepository gameDesign, String name,
082:                    ImageResource imageResource, int cellWidth, int cellHeight) {
083:                assert (gameDesign != null);
084:                this .gameDesign = gameDesign;
085:                this .name = name;
086:                this .imageResource = imageResource;
087:                this .cellWidth = cellWidth;
088:                this .cellHeight = cellHeight;
089:            }
090:
091:            public String getName() {
092:                return this .name;
093:            }
094:
095:            public GlobalRepository getGameDesign() {
096:                return this .gameDesign;
097:            }
098:
099:            public void setName(String name) {
100:                if (name == null) {
101:                    return;
102:                }
103:                if (this .getName().equals(name)) {
104:                    return;
105:                }
106:                if (!this .gameDesign.isComponentNameAvailable(name)) {
107:                    throw new IllegalArgumentException(
108:                            "Layer cannot be renamed because component name '"
109:                                    + name + "' already exists."); // NOI18N
110:                }
111:                String oldName = this .name;
112:                this .name = name;
113:                this .propertyChangeSupport.firePropertyChange(PROPERTY_NAME,
114:                        oldName, name);
115:            }
116:
117:            public ImageResource getImageResource() {
118:                return this .imageResource;
119:            }
120:
121:            public String toString() {
122:                return this .getName();
123:            }
124:
125:            public void addPropertyChangeListener(PropertyChangeListener l) {
126:                propertyChangeSupport.addPropertyChangeListener(l);
127:            }
128:
129:            public void removePropertyChangeListener(PropertyChangeListener l) {
130:                propertyChangeSupport.removePropertyChangeListener(l);
131:            }
132:
133:            public abstract void paint(Graphics2D g);
134:
135:            public abstract int getHeight();
136:
137:            public abstract int getWidth();
138:
139:            //Transferable Interface
140:
141:            public Object getTransferData(DataFlavor flavor)
142:                    throws UnsupportedFlavorException, IOException {
143:                return this ;
144:            }
145:
146:            public DataFlavor[] getTransferDataFlavors() {
147:                DataFlavor[] flavors = new DataFlavor[1];
148:                try {
149:                    flavors[0] = new LayerDataFlavor();
150:                } catch (ClassNotFoundException e) {
151:                    e.printStackTrace();
152:                }
153:                return flavors;
154:            }
155:
156:            public boolean isDataFlavorSupported(DataFlavor flavor) {
157:                if (flavor instanceof  LayerDataFlavor)
158:                    return true;
159:                return false;
160:            }
161:
162:            public int getTileHeight() {
163:                return this .cellHeight;
164:            }
165:
166:            public int getTileWidth() {
167:                return this .cellWidth;
168:            }
169:
170:            public abstract String getDisplayableTypeName();
171:
172:            public static class NameComparator implements  Comparator {
173:
174:                public int compare(Object arg0, Object arg1) {
175:                    if (!(arg0 instanceof  Layer) || !(arg1 instanceof  Layer))
176:                        throw new ClassCastException(
177:                                "Compared object not instance of Layer"); // NOI18N
178:                    Layer l0 = (Layer) arg0;
179:                    Layer l1 = (Layer) arg1;
180:                    return (l0.getName().compareTo(l1.getName()));
181:                }
182:            }
183:
184:            public List<Action> getActions() {
185:                List<Action> actions = new ArrayList<Action>();
186:                actions.add(new EditLayerAction());
187:                actions.add(new RemoveAction());
188:                return Collections.unmodifiableList(actions);
189:            }
190:
191:            public JComponent getNavigator() {
192:                //TODO : implement this
193:                return null;
194:            }
195:
196:            public class EditLayerAction extends AbstractAction {
197:                {
198:                    this .putValue(NAME, NbBundle.getMessage(Layer.class,
199:                            "Layer.editAction", getDisplayableTypeName()));
200:                }
201:
202:                public void actionPerformed(ActionEvent e) {
203:                    Layer.this .gameDesign.getMainView().requestEditing(
204:                            Layer.this );
205:                }
206:            }
207:
208:            public class RemoveAction extends AbstractAction {
209:                {
210:                    this .putValue(NAME, NbBundle.getMessage(Layer.class,
211:                            "Layer.removeAction", getDisplayableTypeName()));
212:                }
213:
214:                public void actionPerformed(ActionEvent e) {
215:                    Scene scene = (Scene) this 
216:                            .getValue(Layer.ACTION_PROP_SCENE);
217:                    //if we were called in the context of a scene we remove the layer from a scene
218:                    if (scene != null) {
219:                        scene.remove(Layer.this );
220:                    }
221:                    //else delete completely
222:                    else {
223:                        Object response = DialogDisplayer.getDefault().notify(
224:                                new NotifyDescriptor(NbBundle.getMessage(
225:                                        Layer.class, "Layer.removeDialog.text",
226:                                        new Object[] {
227:                                                getDisplayableTypeName(),
228:                                                getName() }), NbBundle
229:                                        .getMessage(Layer.class,
230:                                                "Layer.removeDialog.title"),
231:                                        NotifyDescriptor.YES_NO_OPTION,
232:                                        NotifyDescriptor.QUESTION_MESSAGE,
233:                                        new Object[] {
234:                                                NotifyDescriptor.YES_OPTION,
235:                                                NotifyDescriptor.NO_OPTION },
236:                                        NotifyDescriptor.YES_OPTION));
237:                        if (response == NotifyDescriptor.YES_OPTION) {
238:                            Layer.this .gameDesign.removeLayer(Layer.this );
239:                        }
240:                    }
241:                }
242:            }
243:
244:            public long getId() {
245:                return id;
246:            }
247:
248:            public void setId(long id) {
249:                this.id = id;
250:            }
251:
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.