Source Code Cross Referenced for SceneLayerTableAdapter.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » game » model » adapter » 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.adapter 
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.adapter;
042:
043:        import java.awt.Point;
044:        import java.beans.PropertyChangeEvent;
045:        import java.beans.PropertyChangeListener;
046:        import java.util.ArrayList;
047:        import java.util.Iterator;
048:        import javax.swing.event.TableModelEvent;
049:        import javax.swing.event.TableModelListener;
050:        import javax.swing.table.TableModel;
051:        import org.netbeans.modules.vmd.game.model.Layer;
052:        import org.netbeans.modules.vmd.game.model.Scene;
053:        import org.netbeans.modules.vmd.game.model.SceneListener;
054:        import org.netbeans.modules.vmd.game.model.Scene.LayerInfo;
055:        import org.openide.DialogDescriptor;
056:        import org.openide.DialogDisplayer;
057:        import org.openide.util.NbBundle;
058:
059:        public class SceneLayerTableAdapter implements  TableModel,
060:                SceneListener, PropertyChangeListener {
061:
062:            public static final boolean DEBUG = false;
063:
064:            private final static int COLS = 7;
065:
066:            public final static int COL_INDEX_LAYER_TYPE = 0;
067:            public final static int COL_INDEX_LAYER_INDEX = 1;
068:            public final static int COL_INDEX_LAYER_VISIBILITY_INDICATOR = 2;
069:            public final static int COL_INDEX_LAYER_LOCK_INDICATOR = 3;
070:            public final static int COL_INDEX_LAYER_NAME = 4;
071:            public final static int COL_INDEX_LAYER_POS_X = 5;
072:            public final static int COL_INDEX_LAYER_POS_Y = 6;
073:
074:            private Scene scene;
075:
076:            private ArrayList listeners = new ArrayList();
077:
078:            public SceneLayerTableAdapter(Scene scene) {
079:                this .scene = scene;
080:                this .scene.addSceneListener(this );
081:            }
082:
083:            public int getColumnCount() {
084:                return COLS;
085:            }
086:
087:            public int getRowCount() {
088:                return this .scene.getLayerCount();
089:            }
090:
091:            public boolean isCellEditable(int rowIndex, int columnIndex) {
092:                //cannot manually edit layer position (Z) - this is done only by using DnD
093:                if (columnIndex == COL_INDEX_LAYER_INDEX)
094:                    return false;
095:                //cannot edit layer type
096:                if (columnIndex == COL_INDEX_LAYER_TYPE)
097:                    return false;
098:                //if the layer is locked then disable editing of layer location (X, Y)
099:                if (columnIndex == COL_INDEX_LAYER_POS_X
100:                        || columnIndex == COL_INDEX_LAYER_POS_Y) {
101:                    if (this .scene.isLayerLocked(this .scene
102:                            .getLayerAt(rowIndex))) {
103:                        return false;
104:                    }
105:                }
106:                return true;
107:            }
108:
109:            public Class getColumnClass(int columnIndex) {
110:                if (columnIndex == COL_INDEX_LAYER_TYPE)
111:                    return Layer.class;
112:                if (columnIndex == COL_INDEX_LAYER_INDEX)
113:                    return Integer.class;
114:                if (columnIndex == COL_INDEX_LAYER_VISIBILITY_INDICATOR)
115:                    return Boolean.class;
116:                if (columnIndex == COL_INDEX_LAYER_LOCK_INDICATOR)
117:                    return Boolean.class;
118:                if (columnIndex == COL_INDEX_LAYER_NAME)
119:                    return String.class;
120:                if (columnIndex == COL_INDEX_LAYER_POS_X)
121:                    return Integer.class;
122:                if (columnIndex == COL_INDEX_LAYER_POS_Y)
123:                    return Integer.class;
124:                return Object.class;
125:            }
126:
127:            public Object getValueAt(int rowIndex, int columnIndex) {
128:                if (rowIndex < 0 || rowIndex >= this .scene.getLayerCount()
129:                        || columnIndex < 0 || columnIndex >= COLS)
130:                    return null;
131:                Layer layer = this .scene.getLayerAt(rowIndex);
132:                switch (columnIndex) {
133:                case COL_INDEX_LAYER_TYPE:
134:                    return layer;
135:                case COL_INDEX_LAYER_INDEX:
136:                    return new Integer(this .scene.indexOf(layer));
137:                case COL_INDEX_LAYER_VISIBILITY_INDICATOR:
138:                    return new Boolean(this .scene.isLayerVisible(layer));
139:                case COL_INDEX_LAYER_LOCK_INDICATOR:
140:                    return new Boolean(this .scene.isLayerLocked(layer));
141:                case COL_INDEX_LAYER_NAME:
142:                    return layer.getName();
143:                case COL_INDEX_LAYER_POS_X:
144:                    return new Integer(this .scene.getLayerPosition(layer).x);
145:                case COL_INDEX_LAYER_POS_Y:
146:                    return new Integer(this .scene.getLayerPosition(layer).y);
147:                }
148:                return null;
149:            }
150:
151:            public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
152:                if (rowIndex < 0 || rowIndex >= this .scene.getLayerCount()
153:                        || columnIndex < 0 || columnIndex >= COLS) {
154:                    throw new IllegalArgumentException("Arguments rowIndex = "
155:                            + rowIndex // NOI18N
156:                            + ", columnIndex = " + columnIndex
157:                            + " are illegal for table of "
158:                            + // NOI18N
159:                            this .scene.getLayerCount() + " rows and " + COLS
160:                            + " columns."); // NOI18N
161:                }
162:                Layer layer = this .scene.getLayerAt(rowIndex);
163:                switch (columnIndex) {
164:                //XXX this case has not been tested - this cell is not editable for now
165:                case COL_INDEX_LAYER_INDEX:
166:                    Integer indexVal = (Integer) aValue;
167:                    int newIndex = indexVal.intValue();
168:                    this .scene.move(layer, newIndex);
169:                    break;
170:                case COL_INDEX_LAYER_VISIBILITY_INDICATOR:
171:                    boolean visible = ((Boolean) aValue).booleanValue();
172:                    this .scene.setLayerVisible(layer, visible);
173:                    break;
174:                case COL_INDEX_LAYER_LOCK_INDICATOR:
175:                    boolean locked = ((Boolean) aValue).booleanValue();
176:                    this .scene.setLayerLocked(layer, locked);
177:                    break;
178:                case COL_INDEX_LAYER_NAME:
179:                    String name = (String) aValue;
180:                    if (name.equals(layer.getName())) {
181:                        return;
182:                    }
183:                    if (!this .scene.getGameDesign().isComponentNameAvailable(
184:                            name)) {
185:                        DialogDisplayer
186:                                .getDefault()
187:                                .notify(
188:                                        new DialogDescriptor.Message(
189:                                                NbBundle
190:                                                        .getMessage(
191:                                                                SceneLayerTableAdapter.class,
192:                                                                "SceneLayerTableAdapter.noRenameDialog.txt",
193:                                                                name),
194:                                                //"Layer cannot be renamed because component name '" + name + "' already exists.", 
195:                                                DialogDescriptor.ERROR_MESSAGE));
196:                    } else {
197:                        layer.setName(name);
198:                    }
199:                    break;
200:                case COL_INDEX_LAYER_POS_X:
201:                    Integer xPos = (Integer) aValue;
202:                    this .scene.setLayerPositionX(layer, xPos.intValue(), false);
203:                    break;
204:                case COL_INDEX_LAYER_POS_Y:
205:                    Integer yPos = (Integer) aValue;
206:                    this .scene.setLayerPositionY(layer, yPos.intValue(), false);
207:                    break;
208:                }
209:            }
210:
211:            public String getColumnName(int columnIndex) {
212:                switch (columnIndex) {
213:                case COL_INDEX_LAYER_TYPE:
214:                    return "Type";
215:                case COL_INDEX_LAYER_INDEX:
216:                    return "Z";
217:                case COL_INDEX_LAYER_VISIBILITY_INDICATOR:
218:                    return "View";
219:                case COL_INDEX_LAYER_LOCK_INDICATOR:
220:                    return "Lock";
221:                case COL_INDEX_LAYER_NAME:
222:                    return "Name";
223:                case COL_INDEX_LAYER_POS_X:
224:                    return "X";
225:                case COL_INDEX_LAYER_POS_Y:
226:                    return "Y";
227:                default:
228:                    return "???";
229:                }
230:            }
231:
232:            public void addTableModelListener(TableModelListener l) {
233:                this .listeners.add(l);
234:            }
235:
236:            public void removeTableModelListener(TableModelListener l) {
237:                this .listeners.remove(l);
238:            }
239:
240:            private void fireTableChanged(TableModelEvent e) {
241:                for (Iterator iter = this .listeners.iterator(); iter.hasNext();) {
242:                    TableModelListener l = (TableModelListener) iter.next();
243:                    l.tableChanged(e);
244:                }
245:
246:            }
247:
248:            //listens for name changes on all layers
249:            public void propertyChange(PropertyChangeEvent evt) {
250:                if (evt.getSource() instanceof  Layer) {
251:                    Layer layer = (Layer) evt.getSource();
252:                    if (DEBUG)
253:                        System.out.println("layer changed: " + layer); // NOI18N
254:                    int index = this .scene.indexOf(layer);
255:                    TableModelEvent e = new TableModelEvent(this , index, index,
256:                            TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE);
257:                    this .fireTableChanged(e);
258:                }
259:
260:            }
261:
262:            public void layerAdded(Scene sourceScene, Layer layer, int index) {
263:                TableModelEvent e = new TableModelEvent(this , index, index,
264:                        TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
265:                layer.addPropertyChangeListener(this );
266:                this .fireTableChanged(e);
267:            }
268:
269:            public void layerRemoved(Scene sourceScene, Layer layer,
270:                    LayerInfo info, int index) {
271:                TableModelEvent e = new TableModelEvent(this , index, index,
272:                        TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE);
273:                layer.removePropertyChangeListener(this );
274:                this .fireTableChanged(e);
275:            }
276:
277:            public void layerModified(Scene sourceScene, Layer layer) {
278:                int index = sourceScene.indexOf(layer);
279:                TableModelEvent e = new TableModelEvent(this , index, index,
280:                        TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE);
281:                this .fireTableChanged(e);
282:            }
283:
284:            public void layerMoved(Scene sourceScene, Layer layer,
285:                    int indexOld, int indexNew) {
286:                this .layerRemoved(sourceScene, layer, null, indexOld);
287:                this .layerAdded(sourceScene, layer, indexNew);
288:            }
289:
290:            public void layerLockChanged(Scene sourceScene, Layer layer,
291:                    boolean locked) {
292:                this .layerModified(sourceScene, layer);
293:            }
294:
295:            public void layerPositionChanged(Scene sourceScene, Layer layer,
296:                    Point oldPosition, Point newPosition, boolean inTransition) {
297:                this .layerModified(sourceScene, layer);
298:            }
299:
300:            public void layerVisibilityChanged(Scene sourceScene, Layer layer,
301:                    boolean visible) {
302:                this.layerModified(sourceScene, layer);
303:            }
304:
305:        }
w__w___w___._j___a___va_2__s___.__c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.