Source Code Cross Referenced for GameDesignOverViewPanel.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » game » view » 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.view 
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.view;
042:
043:        import java.awt.Component;
044:        import java.awt.Dialog;
045:        import java.awt.Dimension;
046:        import java.awt.FlowLayout;
047:        import java.awt.Font;
048:        import java.awt.Rectangle;
049:        import java.awt.event.ComponentEvent;
050:        import java.awt.event.ComponentListener;
051:        import java.awt.event.MouseAdapter;
052:        import java.awt.event.MouseEvent;
053:        import java.util.HashMap;
054:        import java.util.List;
055:        import java.util.Map;
056:        import javax.swing.JComponent;
057:        import javax.swing.JLabel;
058:        import javax.swing.JPanel;
059:        import javax.swing.Scrollable;
060:        import javax.swing.SwingConstants;
061:        import org.netbeans.modules.vmd.game.dialog.NewSceneDialog;
062:        import org.netbeans.modules.vmd.game.model.GlobalRepository;
063:        import org.netbeans.modules.vmd.game.model.GlobalRepositoryListener;
064:        import org.netbeans.modules.vmd.game.model.ImageResource;
065:        import org.netbeans.modules.vmd.game.model.Scene;
066:        import org.netbeans.modules.vmd.game.model.Sprite;
067:        import org.netbeans.modules.vmd.game.model.TiledLayer;
068:        import org.netbeans.modules.vmd.game.nbdialog.SpriteDialog;
069:        import org.netbeans.modules.vmd.game.nbdialog.TiledLayerDialog;
070:        import org.openide.DialogDescriptor;
071:        import org.openide.DialogDisplayer;
072:        import org.openide.util.NbBundle;
073:
074:        /**
075:         *
076:         * @author kaja
077:         */
078:        public class GameDesignOverViewPanel extends ScrollableFlowPanel
079:                implements  ComponentListener {
080:
081:            private GlobalRepository gameDesign;
082:
083:            private JLabel labelTiledLayers;
084:            private JLabel labelSprites;
085:            private JLabel labelScenes;
086:
087:            private ScrollableFlowPanel panelTiledLayers = new ScrollableFlowPanel();
088:            private ScrollableFlowPanel panelSprites = new ScrollableFlowPanel();
089:            private ScrollableFlowPanel panelScenes = new ScrollableFlowPanel();
090:
091:            private Map<TiledLayer, GameDesignPreviewComponent> tiledLayerPreviews = new HashMap<TiledLayer, GameDesignPreviewComponent>();
092:            private Map<Sprite, GameDesignPreviewComponent> spritePreviews = new HashMap<Sprite, GameDesignPreviewComponent>();
093:            private Map<Scene, GameDesignPreviewComponent> scenePreviews = new HashMap<Scene, GameDesignPreviewComponent>();
094:
095:            public GameDesignOverViewPanel(final GlobalRepository gameDesign) {
096:                this .gameDesign = gameDesign;
097:                this .gameDesign
098:                        .addGlobalRepositoryListener(new GlobalRepositoryListener() {
099:                            public void sceneAdded(Scene scene, int index) {
100:                                GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
101:                                        gameDesign, scene.getPreview(), scene
102:                                                .getName(), scene);
103:                                panelScenes.add(preview, index);
104:                                panelScenes.revalidate();
105:                                panelScenes.repaint();
106:                                scenePreviews.put(scene, preview);
107:                            }
108:
109:                            public void sceneRemoved(Scene scene, int index) {
110:                                JComponent preview = scenePreviews
111:                                        .remove(scene);
112:                                if (preview != null) {
113:                                    panelScenes.remove(preview);
114:                                    panelScenes.revalidate();
115:                                    panelScenes.repaint();
116:                                }
117:                            }
118:
119:                            public void tiledLayerAdded(TiledLayer tiledLayer,
120:                                    int index) {
121:                                GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
122:                                        gameDesign, tiledLayer.getPreview(),
123:                                        tiledLayer.getName(), tiledLayer);
124:                                panelTiledLayers.add(preview, index);
125:                                panelTiledLayers.revalidate();
126:                                panelTiledLayers.repaint();
127:                                tiledLayerPreviews.put(tiledLayer, preview);
128:                            }
129:
130:                            public void tiledLayerRemoved(
131:                                    TiledLayer tiledLayer, int index) {
132:                                JComponent preview = tiledLayerPreviews
133:                                        .remove(tiledLayer);
134:                                if (preview != null) {
135:                                    panelTiledLayers.remove(preview);
136:                                    panelTiledLayers.revalidate();
137:                                    panelTiledLayers.repaint();
138:                                }
139:                            }
140:
141:                            public void spriteAdded(Sprite sprite, int index) {
142:                                ImagePreviewComponent imagePreviewComponent = new ImagePreviewComponent(
143:                                        true);
144:                                imagePreviewComponent.setPreviewable(sprite
145:                                        .getDefaultSequence().getFrame(0));
146:                                final GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
147:                                        gameDesign, imagePreviewComponent,
148:                                        sprite.getName(), sprite);
149:                                panelSprites.add(preview, index);
150:                                panelSprites.revalidate();
151:                                panelSprites.repaint();
152:                                spritePreviews.put(sprite, preview);
153:                            }
154:
155:                            public void spriteRemoved(Sprite sprite, int index) {
156:                                JComponent preview = spritePreviews
157:                                        .remove(sprite);
158:                                if (preview != null) {
159:                                    panelSprites.remove(preview);
160:                                    panelSprites.revalidate();
161:                                    panelSprites.repaint();
162:                                }
163:                            }
164:
165:                            public void imageResourceAdded(
166:                                    ImageResource imageResource) {
167:                            }
168:                        });
169:                this .manualInit();
170:                this .addComponentListener(this );
171:
172:                // vlv: print
173:                putClientProperty(java.awt.print.Printable.class, ""); // NOI18N
174:            }
175:
176:            private void manualInit() {
177:                this .setBackground(ColorConstants.COLOR_EDITOR_PANEL);
178:                this .panelTiledLayers
179:                        .setBackground(ColorConstants.COLOR_EDITOR_PANEL);
180:                this .panelSprites
181:                        .setBackground(ColorConstants.COLOR_EDITOR_PANEL);
182:                this .panelScenes
183:                        .setBackground(ColorConstants.COLOR_EDITOR_PANEL);
184:
185:                ((FlowLayout) this .getLayout()).setAlignment(FlowLayout.LEFT);
186:                ((FlowLayout) this .panelTiledLayers.getLayout())
187:                        .setAlignment(FlowLayout.LEFT);
188:                ((FlowLayout) this .panelSprites.getLayout())
189:                        .setAlignment(FlowLayout.LEFT);
190:                ((FlowLayout) this .panelScenes.getLayout())
191:                        .setAlignment(FlowLayout.LEFT);
192:
193:                //add scenes label
194:                labelScenes = new JLabel(NbBundle.getMessage(
195:                        GameDesignOverViewPanel.class,
196:                        "GameDesignOverViewPanel.labelScenes.txt"));
197:                labelScenes.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
198:                labelScenes.setForeground(ColorConstants.COLOR_TEXT_PLAIN);
199:                labelScenes.setHorizontalAlignment(SwingConstants.LEFT);
200:                this .add(labelScenes);
201:                //add scenes list
202:                this .add(this .panelScenes);
203:
204:                //add tiled layers label
205:                labelTiledLayers = new JLabel(NbBundle.getMessage(
206:                        GameDesignOverViewPanel.class,
207:                        "GameDesignOverViewPanel.labelTiledLayers.txt"));
208:                labelTiledLayers.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
209:                labelTiledLayers
210:                        .setForeground(new java.awt.Color(163, 184, 215));
211:                labelTiledLayers.setHorizontalAlignment(SwingConstants.LEFT);
212:                this .add(labelTiledLayers);
213:                //add tiled layers list
214:                this .add(this .panelTiledLayers);
215:
216:                //add sprites label
217:                labelSprites = new JLabel(NbBundle.getMessage(
218:                        GameDesignOverViewPanel.class,
219:                        "GameDesignOverViewPanel.labelSprites.txt"));
220:                labelSprites.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
221:                labelSprites.setForeground(ColorConstants.COLOR_TEXT_PLAIN);
222:                labelSprites.setHorizontalAlignment(SwingConstants.LEFT);
223:                this .add(labelSprites);
224:                //add sprites list
225:                this .add(this .panelSprites);
226:
227:                this .populateScenePreviewList(panelScenes);
228:                this .populateTiledLayerPreviewList(panelTiledLayers);
229:                this .populateSpritePreviewList(panelSprites);
230:
231:                this .getAccessibleContext().setAccessibleName(
232:                        (NbBundle.getMessage(GameDesignOverViewPanel.class,
233:                                "GameDesignOverViewPanel.accessible.name")));
234:                this 
235:                        .getAccessibleContext()
236:                        .setAccessibleDescription(
237:                                (NbBundle
238:                                        .getMessage(
239:                                                GameDesignOverViewPanel.class,
240:                                                "GameDesignOverViewPanel.accessible.description")));
241:
242:            }
243:
244:            private void populateTiledLayerPreviewList(JComponent container) {
245:
246:                List<TiledLayer> layers = this .gameDesign.getTiledLayers();
247:                for (TiledLayer tiledLayer : layers) {
248:                    GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
249:                            gameDesign, tiledLayer.getPreview(), tiledLayer
250:                                    .getName(), tiledLayer);
251:                    container.add(preview);
252:                    tiledLayerPreviews.put(tiledLayer, preview);
253:                }
254:
255:                final JLabel lblCreate = new JLabel(NbBundle.getMessage(
256:                        GameDesignOverViewPanel.class,
257:                        "GameDesignOverViewPanel.labelNewTiledLayer.txt"));
258:                lblCreate.setPreferredSize(new Dimension(lblCreate
259:                        .getPreferredSize().width + 15, 40));
260:                lblCreate.setForeground(new java.awt.Color(100, 123, 156));
261:                lblCreate.addMouseListener(new MouseAdapter() {
262:                    public void mouseEntered(MouseEvent e) {
263:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
264:                                Font.BOLD));
265:                    }
266:
267:                    public void mouseExited(MouseEvent e) {
268:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
269:                                Font.PLAIN));
270:                    }
271:
272:                    public void mouseClicked(MouseEvent e) {
273:                        TiledLayerDialog nld = new TiledLayerDialog(gameDesign);
274:                        DialogDescriptor dd = new DialogDescriptor(
275:                                nld,
276:                                NbBundle
277:                                        .getMessage(
278:                                                GameDesignOverViewPanel.class,
279:                                                "GameDesignOverViewPanel.dialogNewTiledLayer.txt"));
280:                        dd.setButtonListener(nld);
281:                        dd.setValid(false);
282:                        nld.setDialogDescriptor(dd);
283:                        Dialog d = DialogDisplayer.getDefault()
284:                                .createDialog(dd);
285:                        d.setVisible(true);
286:                    }
287:                });
288:                container.add(lblCreate);
289:            }
290:
291:            private void populateSpritePreviewList(JComponent container) {
292:                List<Sprite> sprites = this .gameDesign.getSprites();
293:                for (Sprite sprite : sprites) {
294:                    ImagePreviewComponent imagePreviewComponent = new ImagePreviewComponent(
295:                            true);
296:                    imagePreviewComponent.setPreviewable(sprite
297:                            .getDefaultSequence().getFrame(0));
298:                    final GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
299:                            gameDesign, imagePreviewComponent,
300:                            sprite.getName(), sprite);
301:                    container.add(preview);
302:                    spritePreviews.put(sprite, preview);
303:                }
304:
305:                final JLabel lblCreate = new JLabel(NbBundle.getMessage(
306:                        GameDesignOverViewPanel.class,
307:                        "GameDesignOverViewPanel.labelNewSprite.txt"));
308:                lblCreate.setPreferredSize(new Dimension(lblCreate
309:                        .getPreferredSize().width + 15, 40));
310:                lblCreate.setForeground(new java.awt.Color(100, 123, 156));
311:                lblCreate.addMouseListener(new MouseAdapter() {
312:                    public void mouseEntered(MouseEvent e) {
313:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
314:                                Font.BOLD));
315:                    }
316:
317:                    public void mouseExited(MouseEvent e) {
318:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
319:                                Font.PLAIN));
320:                    }
321:
322:                    public void mouseClicked(MouseEvent e) {
323:                        SpriteDialog nld = new SpriteDialog(gameDesign);
324:                        DialogDescriptor dd = new DialogDescriptor(
325:                                nld,
326:                                NbBundle
327:                                        .getMessage(
328:                                                GameDesignOverViewPanel.class,
329:                                                "GameDesignOverViewPanel.dialogNewSprite.txt"));
330:                        dd.setButtonListener(nld);
331:                        dd.setValid(false);
332:                        nld.setDialogDescriptor(dd);
333:                        Dialog d = DialogDisplayer.getDefault()
334:                                .createDialog(dd);
335:                        d.setVisible(true);
336:                    }
337:                });
338:                container.add(lblCreate);
339:            }
340:
341:            private void populateScenePreviewList(JComponent container) {
342:                List<Scene> scenes = this .gameDesign.getScenes();
343:                for (Scene scene : scenes) {
344:                    GameDesignPreviewComponent preview = new GameDesignPreviewComponent(
345:                            gameDesign, scene.getPreview(), scene.getName(),
346:                            scene);
347:                    container.add(preview);
348:                    scenePreviews.put(scene, preview);
349:                }
350:
351:                final JLabel lblCreate = new JLabel(NbBundle.getMessage(
352:                        GameDesignOverViewPanel.class,
353:                        "GameDesignOverViewPanel.labelNewScene.txt"));
354:                lblCreate.setPreferredSize(new Dimension(lblCreate
355:                        .getPreferredSize().width + 15, 40));
356:                lblCreate.setForeground(new java.awt.Color(100, 123, 156));
357:                lblCreate.addMouseListener(new MouseAdapter() {
358:                    public void mouseEntered(MouseEvent e) {
359:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
360:                                Font.BOLD));
361:                    }
362:
363:                    public void mouseExited(MouseEvent e) {
364:                        lblCreate.setFont(lblCreate.getFont().deriveFont(
365:                                Font.PLAIN));
366:                    }
367:
368:                    public void mouseClicked(MouseEvent e) {
369:                        NewSceneDialog dialog = new NewSceneDialog(gameDesign);
370:                        DialogDescriptor dd = new DialogDescriptor(
371:                                dialog,
372:                                NbBundle
373:                                        .getMessage(
374:                                                GameDesignOverViewPanel.class,
375:                                                "GameDesignOverViewPanel.dialogNewScene.txt"));
376:                        dd.setButtonListener(dialog);
377:                        dd.setValid(false);
378:                        dialog.setDialogDescriptor(dd);
379:                        Dialog d = DialogDisplayer.getDefault()
380:                                .createDialog(dd);
381:                        d.setVisible(true);
382:                    }
383:                });
384:                container.add(lblCreate);
385:            }
386:
387:            private void resizeLabels() {
388:                Dimension d = labelTiledLayers.getPreferredSize();
389:                this .labelTiledLayers.setPreferredSize(new Dimension(this 
390:                        .getWidth(), d.getSize().height));
391:
392:                d = labelSprites.getPreferredSize();
393:                this .labelSprites.setPreferredSize(new Dimension(this 
394:                        .getWidth(), d.getSize().height));
395:
396:                d = labelScenes.getPreferredSize();
397:                this .labelScenes.setPreferredSize(new Dimension(
398:                        this .getWidth(), d.getSize().height));
399:            }
400:
401:            public void componentResized(ComponentEvent e) {
402:                this .resizeLabels();
403:            }
404:
405:            public void componentMoved(ComponentEvent e) {
406:                this .resizeLabels();
407:            }
408:
409:            public void componentShown(ComponentEvent e) {
410:                this .resizeLabels();
411:            }
412:
413:            public void componentHidden(ComponentEvent e) {
414:            }
415:        }
416:
417:        class ScrollableFlowPanel extends JPanel implements  Scrollable {
418:
419:            public void setBounds(int x, int y, int width, int height) {
420:                super .setBounds(x, y, getParent().getWidth(), height);
421:            }
422:
423:            public Dimension getPreferredSize() {
424:                return new Dimension(getWidth(), getPreferredHeight());
425:            }
426:
427:            public Dimension getPreferredScrollableViewportSize() {
428:                return super .getPreferredSize();
429:            }
430:
431:            public int getScrollableUnitIncrement(Rectangle visibleRect,
432:                    int orientation, int direction) {
433:                int hundredth = (orientation == SwingConstants.VERTICAL ? getParent()
434:                        .getHeight()
435:                        : getParent().getWidth()) / 100;
436:                return hundredth == 0 ? 1 : hundredth;
437:            }
438:
439:            public int getScrollableBlockIncrement(Rectangle visibleRect,
440:                    int orientation, int direction) {
441:                return orientation == SwingConstants.VERTICAL ? getParent()
442:                        .getHeight() : getParent().getWidth();
443:            }
444:
445:            public boolean getScrollableTracksViewportWidth() {
446:                return true;
447:            }
448:
449:            public boolean getScrollableTracksViewportHeight() {
450:                return false;
451:            }
452:
453:            private int getPreferredHeight() {
454:                int rv = 0;
455:                for (int k = 0, count = getComponentCount(); k < count; k++) {
456:                    Component comp = getComponent(k);
457:                    Rectangle r = comp.getBounds();
458:                    int height = r.y + r.height;
459:                    if (height > rv) {
460:                        rv = height;
461:                    }
462:                }
463:                rv += ((FlowLayout) getLayout()).getVgap();
464:                return rv;
465:            }
466:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.