Source Code Cross Referenced for DigitalBiosphereClient.java in  » 6.0-JDK-Modules » java-3d » com » db » client » 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 » 6.0 JDK Modules » java 3d » com.db.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:/*
0002: *      @(#)digitalBiosphereClient.java 1.0, 1 May 2000
0003: *
0004: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
0005: *
0006: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
0007: * royalty free, license to use, modify and redistribute this 
0008: * software in source and binary code form,
0009: * provided that i) this  copyright notice and license appear on all copies of
0010: * the software; and ii) Licensee does not utilize the software in a manner
0011: * which is disparaging to Silvere Martin-Michiellot.
0012: *
0013: * This software is provided "AS IS," without a warranty of any kind. ALL
0014: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
0015: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
0016: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
0017: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
0018: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
0019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
0020: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
0021: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
0022: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
0023: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
0024: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
0025: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
0026: *
0027: * This software is not designed or intended for use in on-line control of
0028: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
0029: * the design, construction, operation or maintenance of any nuclear
0030: * facility. Licensee represents and warrants that it will not use or
0031: * redistribute the Software for such purposes.
0032: *
0033: * @Author: Silvere Martin-Michiellot
0034: *
0035: */
0036:
0037:package com.db.client;
0038:
0039:import com.db.behaviors.*;
0040:import com.db.devices.HMD.*;
0041:import com.db.geography.coords.*;
0042:import com.db.geography.ellipsoids.*;
0043:import com.db.geography.transforms.*;
0044:import com.db.help.*;
0045:import com.db.loaders.*;
0046:import com.db.media.diagnostics.*;
0047:import com.db.media.in.*;
0048:import com.db.media.out.*;
0049:import com.db.media.print.*;
0050:import com.db.media.voice.*;
0051:import com.db.utils.*;
0052:import com.db.utils.timers.*;
0053:import com.db.viewpoint.*;
0054:
0055:import com.db.server.ClientInformation;
0056:import com.db.server.LoginInformation;
0057:
0058:import com.sun.j3d.utils.behaviors.mouse.*;
0059:import com.sun.j3d.audioengines.javasound.*;
0060:import com.sun.j3d.utils.scenegraph.io.*;
0061:import com.sun.j3d.utils.behaviors.vp.*;
0062:import com.sun.j3d.utils.universe.*;
0063:
0064:import ncsa.j3d.ui.tools.*;
0065:import ncsa.devices.spaceorb.*;
0066:import ncsa.j3d.application.*;
0067:import ncsa.devices.wand.*;
0068:import ncsa.devices.bird.*;
0069:import ncsa.j3d.ui.PortfolioProperties;
0070:
0071://import com.sun.j3d.demos.utils.behaviors.*;
0072://import com.sun.j3d.demos.utils.capability.*;
0073://import com.sun.j3d.demos.utils.geometry.*;
0074://import com.sun.j3d.demos.utils.gui.*;
0075:import com.sun.j3d.demos.utils.scenegraph.traverser.*;
0076:import com.sun.j3d.demos.utils.vpbehaviors.*;
0077:
0078:import java.awt.*;
0079:import java.awt.image.BufferedImage;
0080:import java.awt.event.*;
0081:import java.net.InetAddress;
0082:import java.net.URL;
0083:import java.lang.reflect.*;
0084:import java.util.*;
0085:import java.security.PublicKey;
0086:import java.security.cert.Certificate;
0087:import javax.comm.*;
0088:import javax.help.*;
0089:import javax.media.j3d.*;
0090:import javax.swing.*;
0091:import javax.swing.event.*;
0092:import javax.swing.text.*;
0093:import javax.swing.undo.*;
0094:import javax.vecmath.*;
0095:
0096:import java.io.*;
0097:import java.util.Locale;
0098:import java.util.ResourceBundle;
0099:import java.util.StringTokenizer;
0100:import javax.speech.*;
0101:import javax.speech.recognition.*;
0102:import javax.speech.synthesis.*;
0103:
0104:import com.oyoaha.swing.plaf.oyoaha.*;
0105:import javax.swing.*;
0106:import java.io.*; 
0107:
0108://use collision detection from j3d.org
0109://autoinstall and version update
0110://full devices support
0111://slider for graphic acceleration (or advanced properties)
0112://configuration file from config
0113:
0114:public class DigitalBiosphereClient extends JApplet implements  ActionListener, ItemListener {
0115:    
0116:    private static boolean debug = false;
0117:    
0118:    private WandDevice wandDevice;
0119:    private BirdAngleDevice birdAngleDevice;
0120:    private boolean wand;
0121:    private boolean bird;
0122:    private boolean going;
0123:    private int flocks;
0124:    
0125:    static RuleGrammar ruleGrammar;
0126:    static DictationGrammar dictationGrammar;
0127:    static Recognizer recognizer;
0128:    static Synthesizer synthesizer;
0129:    static ResourceBundle resources;
0130:    
0131:    private static final int WORLD_ENABLE = (1<<0);
0132:    private static final int OBJECTS_ENABLE = (1<<1);
0133:    private static final int TOOLS_ENABLE = (1<<2);
0134:    private static final int LIGHTS_ENABLE = (1<<3);
0135:    private static final int BROWSER_ENABLE = (1<<4);
0136:    private static final int AVATAR_ENABLE = (1<<5);
0137:    private static final int TEXT_ENABLE = (1<<6);
0138:    private int digitalBiosphereKinds =  WORLD_ENABLE + OBJECTS_ENABLE + TOOLS_ENABLE + LIGHTS_ENABLE + BROWSER_ENABLE + AVATAR_ENABLE + TEXT_ENABLE;
0139:    
0140:    private ResourceBundle resourceBundle;
0141:    
0142:    private Hashtable userProperties;
0143:    private Hashtable environmentProperties;
0144:    
0145:    //we could use the j3DVideoRenderer to display video from a web cam in a 3D world Shape3D
0146:    
0147:    private Canvas3D canvas3D;
0148:    private OffScreenCanvas3D offScreenCanvas3D;
0149:    private static final int OFF_SCREEN_SCALE = 3;
0150:    
0151:    private J3DLiveAudioRenderer j3DLiveAudioRenderer;
0152:    private AudioVideoSaver audioVideoSaver;
0153:    
0154:    private JavaSoundMixer javaSoundMixer;
0155:    private javax.media.j3d.Locale highResolutionLocale;
0156:    
0157:    private BranchGroup WorldBranchGroup;
0158:    private BranchGroup ObjectsBranchGroup;
0159:    private BranchGroup ToolsBranchGroup;
0160:    private BranchGroup LightsBranchGroup;
0161:    private BranchGroup BrowserBranchGroup;
0162:    private ViewerAvatar AvatarBranchGroup;
0163:    private PlatformGeometry ConsoleBranchGroup;
0164:    private BranchGroup UserBranchGroup;
0165:    
0166:    private TransformGroup UserTransform;
0167:    
0168:    private static final float fieldOfView = (float)Math.PI/2;
0169:    private static final float frontClip = 0.01f;
0170:    private static final float backClip = 30.0f;
0171:    
0172:    private static final int cursorPreferredWidth = 24;
0173:    private static final int cursorPreferredHeight = 24;
0174:    
0175:    private final static float highlightLevel = 0.2f;
0176:    
0177:    private DirectionalLight headLight;
0178:    private AmbientLight ambientLight;
0179:    
0180:    private static final int WALK_MODE = 0;
0181:    private static final int EXAMINE_MODE = 1;
0182:    private static final int FLY_MODE = 2;
0183:    
0184:    private Switch TheSwitch;
0185:    
0186:    private JMenuBar jMenuBar;
0187:    private UndoManager undoManager;
0188:    
0189:    private UndoAction undoAction;
0190:    private RedoAction redoAction;
0191:    
0192:    private static final int MAX_CHARACTERS = 3000;
0193:    private LimitedPlainDocument limitedPlainDocument;
0194:    private JTextField jTextField;
0195:    private JTextArea jTextArea;
0196:    
0197:    private Hashtable textActionsHashtable;
0198:    
0199:    private Client client;
0200:private ClientInformation clientInformation;
0201:
0202:private final int DefaultLocalHostPort = 4356;
0203:    
0204:    private Thread loadThread;
0205:    private Object lock = new Object();
0206:    private boolean shouldStop = false;
0207:    private JProgressBar progressBar;
0208:    private JTextField progressTextField;
0209:    
0210:    // "X", "Y", "Z", "-X", "-Y", "-Z"
0211:    private int showAllAxis = 5;
0212:    
0213:    private boolean collisionCapabilitySet = false;
0214:    private VPDefaultCollision collisionControl = null;
0215:    private BoundingSphere bigBounds;
0216:    
0217:    private VPBehavior viewBehavior = null;
0218:    
0219:    private ArrayList graphs;
0220:    
0221:    private HelpSet helpSet;
0222:    private HelpBroker helpBroker;
0223:    
0224:    public String getAppletInfo() {
0225:        
0226:        return new String(resourceBundle.getString("CopyrightInformation"));
0227:        
0228:    }
0229:    
0230:    public String[][] getParameterInfo() {
0231:        
0232:        String[][] info = {
0233:            {"height",           "int",         resourceBundle.getString("HeightParameter")},
0234:            {"width",            "int",         resourceBundle.getString("WidthParameter")},
0235:            {"preferedlanguage", "string",      resourceBundle.getString("LanguageParameter")},
0236:            {"preferedcountry",  "string",      resourceBundle.getString("CountryParameter")},
0237:        };
0238:        return info;
0239:        
0240:    }
0241:    
0242:    //must intialize user properties beforehand (especially for run as applet)
0243:    //reads if file exists
0244:    private void readUserProperties() {
0245:        
0246:        FileInputStream fileInputStream;
0247:        ObjectInputStream objectInputStream;
0248:        
0249:        if (((Boolean)(environmentProperties.get("runasapplet"))).booleanValue() == false) {
0250:            fileInputStream = new FileInputStream("digitalbiosphere.properties");
0251:            
0252:            if (fileInputStream.available()>0) {
0253:                objectInputStream = new ObjectInputStream(fileInputStream);
0254:                
0255:                environmentProperties = (Hashtable) objectInputStream.readObject();
0256:                
0257:                objectInputStream.close();
0258:                fileInputStream.close();
0259:            }
0260:            
0261:        }
0262:        
0263:    }
0264:    
0265:    //reads if file exists
0266:    private void readEnvironmentProperties() {
0267:        
0268:        FileInputStream fileInputStream;
0269:        ObjectInputStream objectInputStream;
0270:        
0271:        if (((Boolean)(environmentProperties.get("runasapplet"))).booleanValue() == false) {
0272:            fileInputStream = new FileInputStream("user.properties");
0273:            
0274:            if (fileInputStream.available()>0) {
0275:                objectInputStream = new ObjectInputStream(fileInputStream);
0276:                
0277:                userProperties = (Hashtable) objectInputStream.readObject();
0278:                
0279:                objectInputStream.close();
0280:                fileInputStream.close();
0281:            }
0282:            
0283:        }
0284:        
0285:    }
0286:    
0287:    private void initializeUserProperties() {
0288:        
0289:        userProperties = new Hashtable(18);
0290:        userProperties.put("userlastname", new String(resourceBundle.getString("AnonymousLastName")));
0291:        userProperties.put("userfirstname", new String(resourceBundle.getString("AnonymousFirstName")));
0292:        userProperties.put("useremail", new String(resourceBundle.getString("AnonymousEMail")));
0293:        userProperties.put("userlogin", new String(""));
0294:        userProperties.put("userpassword", new String(""));
0295:        userProperties.put("userpublickey", new String(""));
0296:        userProperties.put("userage", new Integer(0));
0297:        userProperties.put("useragecertificate", new String(""));
0298:        userProperties.put("usersex", new String(resourceBundle.getString("DefaultSex")));
0299:        userProperties.put("preferedlanguage", new String("en"));
0300:        userProperties.put("preferedcountry", new String("US"));
0301:        userProperties.put("userheadlight", new Boolean(true));
0302:        userProperties.put("userambientlight", new Boolean(true));
0303:        userProperties.put("usercollision", new Boolean(true));
0304:        userProperties.put("usernavigationmode", new Integer(WALK_MODE));
0305:        userProperties.put("userserverconnection", InetAddress.getByName("127.0.0.0"));
0306:        userProperties.put("userserverportconnection", new Integer(0));
0307:        
0308:    }
0309:    
0310:    private void initializeEnvironmentProperties() {
0311:        
0312:        environmentProperties = new Hashtable(14);
0313:        environmentProperties.put("runasapplet", new Boolean(true));
0314:        environmentProperties.put("applicationheight", new Integer(512));
0315:        environmentProperties.put("applicationwidth", new Integer(512));
0316:        environmentProperties.put("currentlanguage", new String("en"));
0317:        environmentProperties.put("currentcountry", new String("US"));
0318:        environmentProperties.put("currentlookandfeel", UIManager.getLookAndFeel().getName());
0319:        environmentProperties.put("audioplaybacktype", new Integer(-1));
0320:        environmentProperties.put("doublebufferavailable", new Boolean(false));
0321:        environmentProperties.put("doublebufferenable", new Boolean(false));
0322:        environmentProperties.put("stereoavailable", new Boolean(false));
0323:        environmentProperties.put("stereoenable", new Boolean(false));
0324:        environmentProperties.put("texture3davailable", new Boolean(false));
0325:        environmentProperties.put("texturecolortablesize", new Integer(0));
0326:        environmentProperties.put("sceneantialiasingenable", new Boolean(false));
0327:        
0328:    }
0329:    
0330:    private void finalizeUserProperties() {
0331:        
0332:        FileOutputStream fileOutputStream;
0333:        ObjectOutputStream objectOutputStream;
0334:        
0335:        if (((Boolean)(environmentProperties.get("runasapplet"))).booleanValue() == false) {
0336:            //write parameters to file
0337:            fileOutputStream = new FileOutputStream("user.properties");
0338:            objectOutputStream = new ObjectOutputStream(fileOutputStream);
0339:            
0340:            objectOutputStream.writeObject(userProperties);
0341:            
0342:            objectOutputStream.flush();
0343:            fileOutputStream.close();
0344:        }
0345:        
0346:    }
0347:    
0348:    private void finalizeEnvironmentProperties() {
0349:        
0350:        FileOutputStream fileOutputStream;
0351:        ObjectOutputStream objectOutputStream;
0352:        
0353:        if (((Boolean)(environmentProperties.get("runasapplet"))).booleanValue() == false) {
0354:            //write parameters to file
0355:            fileOutputStream = new FileOutputStream("digitalbiosphere.properties");
0356:            objectOutputStream = new ObjectOutputStream(fileOutputStream);
0357:            
0358:            objectOutputStream.writeObject(environmentProperties);
0359:            
0360:            objectOutputStream.flush();
0361:            fileOutputStream.close();
0362:        }
0363:        
0364:    }
0365:    
0366:    private void parseArgs(String[] args) {
0367:        
0368:        ArrayList arrayList = new ArrayList(args.length);
0369:        
0370:        for ( int i = 0; i < args.length; i++ ) {
0371:            arrayList.add(i, args[i]);
0372:        }
0373:        
0374:        while (arrayList.size() > 0) {
0375:            //WARNING debug flag as parameter
0376:            if (arrayList.get(0) == "-d") {
0377:                arrayList.remove(0);
0378:                debug=true;
0379:            }
0380:            else
0381:                if (arrayList.get(0) == "-height") {
0382:                    if (arrayList.size() > 1) {
0383:                        try {
0384:                            environmentProperties.put("applicationheight", new Integer(Math.max(128, new Integer((String)arrayList.get(1)).intValue())));
0385:                        }
0386:                        catch (NumberFormatException exception) {
0387:                            System.err.println(resourceBundle.getString("InvalidArgumentsError"));
0388:                        }
0389:                        arrayList.remove(0);
0390:                        arrayList.remove(1);
0391:                    }
0392:                    else {
0393:                        System.err.println(resourceBundle.getString("MissingArgumentsError"));
0394:                    }
0395:                }
0396:                else
0397:                    if (arrayList.get(0) == "-width") {
0398:                        if (arrayList.size() > 1) {
0399:                            try {
0400:                                environmentProperties.put("applicationwidth", new Integer(Math.max(128, new Integer((String)arrayList.get(1)).intValue())));
0401:                            }
0402:                            catch (NumberFormatException exception) {
0403:                                System.err.println(resourceBundle.getString("InvalidArgumentsError"));
0404:                            }
0405:                            arrayList.remove(0);
0406:                            arrayList.remove(1);
0407:                        }
0408:                        else {
0409:                            System.err.println(resourceBundle.getString("MissingArgumentsError"));
0410:                        }
0411:                    }
0412:                    else
0413:                        if (arrayList.get(0) == "-preferedlanguage") {
0414:                            if (arrayList.size() > 1) {
0415:                                environmentProperties.put("applicationlanguage", arrayList.get(1));
0416:                                arrayList.remove(0);
0417:                                arrayList.remove(1);
0418:                            }
0419:                            else {
0420:                                System.err.println(resourceBundle.getString("MissingArgumentsError"));
0421:                            }
0422:                        }
0423:                        else
0424:                            if (arrayList.get(0) == "-preferedcountry") {
0425:                                if (arrayList.size() > 1) {
0426:                                    environmentProperties.put("applicationcountry", arrayList.get(1));
0427:                                    arrayList.remove(0);
0428:                                    arrayList.remove(1);
0429:                                }
0430:                                else {
0431:                                    System.err.println(resourceBundle.getString("MissingArgumentsError"));
0432:                                }
0433:                            }
0434:                            else System.err.println(resourceBundle.getString("ExcessArgumentsError") + arrayList.get(0));
0435:        }
0436:        
0437:    }
0438:    
0439:    public DigitalBiosphereClient() {
0440:        
0441:        super ();
0442:        
0443:    }
0444:    
0445:    public void init() {
0446:        
0447:        super .init();
0448:        
0449:        java.util.Locale locale = new java.util.Locale(new String("en"),new String("US"));
0450:        resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0451:        
0452:        SplashWindow.showSplashscreen("com/db/client/images/splash.jpg");
0453:        
0454:        SplashWindow.showMessage(resourceBundle.getString("Initialising"));
0455:        
0456:        this .initializeUserProperties();
0457:        this .initializeEnvironmentProperties();
0458:        environmentProperties.put("runasapplet", new Boolean(true));
0459:        
0460:        String parameter = this .getParameter("height");
0461:        if (parameter != null) {
0462:            try {
0463:                environmentProperties.put("applicationheight",  new Integer(parameter));
0464:            }
0465:            catch (NumberFormatException exception) {
0466:                System.err.println(resourceBundle.getString("InvalidArgumentsError"));
0467:            }
0468:        }
0469:        parameter = this .getParameter("width");
0470:        if (parameter != null) {
0471:            try {
0472:                environmentProperties.put("applicationwidth",  new Integer(parameter));
0473:            }
0474:            catch (NumberFormatException exception) {
0475:                System.err.println(resourceBundle.getString("InvalidArgumentsError"));
0476:            }
0477:        }
0478:        parameter = this .getParameter("preferedlanguage");
0479:        if (parameter != null) {
0480:            environmentProperties.put("currentlanguage", parameter);
0481:        }
0482:        parameter = this .getParameter("preferedcountry");
0483:        if (parameter != null) {
0484:            environmentProperties.put("currentcountry", parameter);
0485:        }
0486:        
0487:        locale = new java.util.Locale((String)environmentProperties.get("currentlanguage"),(String)environmentProperties.get("currentcountry"));
0488:        resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0489:        if (resourceBundle==null) {
0490:            
0491:            environmentProperties.put("currentlanguage", new String("en"));
0492:            environmentProperties.put("currentcountry", new String("US"));
0493:            locale = new java.util.Locale((String)environmentProperties.get("currentlanguage"),(String)environmentProperties.get("currentcountry"));
0494:            resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0495:        }
0496:        
0497:        this .initializeSynthetizer();
0498:        
0499:        this .setCursor(new Cursor(Cursor.WAIT_CURSOR));
0500:        this .showStatus(resourceBundle.getString("ApplicationTitle") + resourceBundle.getString("SpaceDot") + resourceBundle.getString("Initializing"));
0501:        
0502:        undoManager = new UndoManager();
0503:        this .setContentPane(this .createContentPane());
0504:        this .createVirtualUniverse();
0505:        this .setJMenuBar(this .createJMenuBar());
0506:        
0507:        JRootPane jRootPane = this .getRootPane();
0508:        Dimension dimensions = new Dimension(128,128);
0509:        jRootPane.setMinimumSize(dimensions);
0510:        dimensions = new Dimension(((Integer)environmentProperties.get("applicationheight")).intValue(), ((Integer)environmentProperties.get("applicationwidth")).intValue());
0511:        jRootPane.setPreferredSize(dimensions);
0512:        //this.setSize(this.getPreferredSize());
0513:        this .resize(this .getPreferredSize());
0514:        
0515:        this .setupDevices();
0516:        
0517:        //network initilization
0518:        this .startClient();
0519:        
0520:        SplashWindow.destroySplashscreen();
0521:        
0522:    }
0523:    
0524:    public void startClient() {
0525:        
0526:        client = new Client(this .highResolutionLocale);
0527:
0528:    }
0529:    
0530:    public void start() {
0531:        
0532:        super .start();
0533:        
0534:        this .setCursor(Cursor.getDefaultCursor());
0535:        this .showStatus(resourceBundle.getString("ApplicationTitle"));
0536:        
0537:        jTextField.requestFocus();
0538:        
0539:    }
0540:
0541:        public void run() {
0542:        
0543: //Refresh position, avatar and world contents        
0544:        //give a chance to user to use avatar gestures        
0545:        //send chat message        
0546:        //and command line language here
0547:         
0548:        //set up a new account
0549:        
0550:        //delete account
0551:        
0552:        //think about using another connection window using serverHelper
0553:                
0554:    }
0555:
0556:    public void stop() {
0557:        
0558:        //free ressources
0559:        stopSynthetizer();
0560:        finalizeUserProperties();
0561:        finalizeEnvironmentProperties();
0562:        super .stop();
0563:        
0564:    }
0565:    
0566:    public void destroy() {
0567:        
0568:        super .destroy();
0569:        
0570:    }
0571:    
0572:    public static void main(String[] args) {
0573:        
0574:        DigitalBiosphereClient digitalBiosphereClient = new DigitalBiosphereClient();
0575:        
0576:        java.util.Locale locale = new java.util.Locale(new String("en"),new String("US"));
0577:        digitalBiosphereClient.resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0578:        
0579:        SplashWindow.showSplashscreen("com/db/client/images/splash.jpg");
0580:        
0581:        SplashWindow.showMessage(digitalBiosphereClient.resourceBundle.getString("Initialising"));
0582:        
0583:        digitalBiosphereClient.initializeUserProperties();
0584:        digitalBiosphereClient.initializeEnvironmentProperties();
0585:        
0586:        digitalBiosphereClient.readUserProperties();
0587:        digitalBiosphereClient.readEnvironmentProperties();
0588:        
0589:        digitalBiosphereClient.environmentProperties.put("runasapplet", new Boolean(false));
0590:        
0591:        digitalBiosphereClient.parseArgs(args);
0592:        
0593:        locale = new java.util.Locale((String)(digitalBiosphereClient.environmentProperties.get("currentlanguage")),(String)(digitalBiosphereClient.environmentProperties.get("currentcountry")));
0594:        digitalBiosphereClient.resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0595:        if (digitalBiosphereClient.resourceBundle==null) {
0596:            
0597:            digitalBiosphereClient.environmentProperties.put("currentlanguage", new String("en"));
0598:            digitalBiosphereClient.environmentProperties.put("currentcountry", new String("US"));
0599:            locale = new java.util.Locale((String)(digitalBiosphereClient.environmentProperties.get("currentlanguage")),(String)(digitalBiosphereClient.environmentProperties.get("currentcountry")));
0600:            digitalBiosphereClient.resourceBundle = ResourceBundle.getBundle("ResourceBundle", locale);
0601:        }
0602:        
0603:        JFrame jFrame = new JFrame();
0604:        
0605:        //java1.4 fullscreen code
0606:        //jFrame.setResizable(false);
0607:        //jFrame.setUndecorated(true);
0608:        //graphicsDevice.setFullScreenWindow(jFrame);
0609:        //we might also need for previous versions to set the parent frame of this frame to a JWindow
0610:        
0611:        jFrame.addWindowListener(new WindowAdapter() {
0612:            
0613:            public void windowClosing(WindowEvent winEvent) {
0614:                digitalBiosphereClient.stop();
0615:            }
0616:        });
0617:        jFrame.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {});
0618:        
0619:        jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage("images/appliicon.gif"));
0620:        
0621:        jFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0622:        
0623:        digitalBiosphereClient.initializeSynthetizer();
0624:        
0625:        jFrame.setTitle(digitalBiosphereClient.resourceBundle.getString("ApplicationTitle") + digitalBiosphereClient.resourceBundle.getString("SpaceDot") + digitalBiosphereClient.resourceBundle.getString("Initializing"));
0626:        digitalBiosphereClient.undoManager = new UndoManager();
0627:        jFrame.setContentPane(digitalBiosphereClient.createContentPane());
0628:        digitalBiosphereClient.createVirtualUniverse();
0629:        jFrame.setJMenuBar(digitalBiosphereClient.createJMenuBar());
0630:        
0631:        JRootPane jRootPane = jFrame.getRootPane();
0632:        Dimension dimensions = new Dimension(128, 128);
0633:        jRootPane.setMinimumSize(dimensions);
0634:        dimensions = new Dimension(((Integer)digitalBiosphereClient.environmentProperties.get("applicationheight")).intValue(), ((Integer)digitalBiosphereClient.environmentProperties.get("applicationwidth")).intValue());
0635:        jRootPane.setPreferredSize(dimensions);
0636:        //jFrame.pack();
0637:        jFrame.setSize(jFrame.getPreferredSize());
0638:        jFrame.setResizable(true);
0639:        
0640:        digitalBiosphereClient.setupDevices();
0641:        
0642:        //network initilization
0643:        digitalBiosphereClient.startClient();
0644:        
0645:        SplashWindow.destroySplashscreen();
0646:        
0647:        jFrame.setCursor(Cursor.getDefaultCursor());
0648:        
0649:        jFrame.setTitle(digitalBiosphereClient.resourceBundle.getString("ApplicationTitle"));
0650:        
0651:        //jFrame.show();
0652:        jFrame.setVisible(true);
0653:        
0654:    }
0655:    
0656:    private Container createContentPane() {
0657:        
0658:        Container contentPane;
0659:        
0660:        //global definition Canvas3D canvas3D; LimitedPlainDocument limitedPlainDocument; JTextField jTextField; JTextArea jTextArea;
0661:        GridLayout gridLayout;
0662:        GraphicsConfigTemplate3D graphicsConfigTemplate3D;
0663:        JScrollPane jScrollPane;
0664:        String url;
0665:        Dimension dimension;
0666:        
0667:        contentPane = new Container();
0668:        
0669:        gridLayout = new GridLayout(3,1,2,2);
0670:        contentPane.setLayout(gridLayout);
0671:        
0672:        graphicsConfigTemplate3D = new GraphicsConfigTemplate3D();
0673:        graphicsConfigTemplate3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
0674:        graphicsConfigTemplate3D.setDoubleBuffer(GraphicsConfigTemplate.REQUIRED);
0675:        graphicsConfigTemplate3D.setStereo(GraphicsConfigTemplate.UNNECESSARY);
0676:        graphicsConfigTemplate3D.setDepthSize(16);
0677:        graphicsConfigTemplate3D.setRedSize(2);
0678:        graphicsConfigTemplate3D.setBlueSize(2);
0679:        graphicsConfigTemplate3D.setGreenSize(2);
0680:        GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(graphicsConfigTemplate3D);
0681:        
0682:        canvas3D = new Canvas3D(graphicsConfiguration);
0683:        canvas3D.setSize(((Integer)environmentProperties.get("applicationwidth")).intValue(),((Integer)environmentProperties.get("applicationheight")).intValue()/3);
0684:        contentPane.add(canvas3D);
0685:        
0686:        environmentProperties.put("doublebufferavailable", new Boolean(canvas3D.getDoubleBufferAvailable()));
0687:        environmentProperties.put("doublebufferenable", new Boolean(canvas3D.getDoubleBufferEnable()));
0688:        environmentProperties.put("stereoavailable", new Boolean(canvas3D.getStereoAvailable()));
0689:        environmentProperties.put("stereoenable", new Boolean(canvas3D.getStereoEnable()));
0690:        environmentProperties.put("texture3davailable", new Boolean(getTexture3DAvailable(canvas3D)));
0691:        environmentProperties.put("texturecolortablesize", new Integer(getTextureColorTableSize(canvas3D)));
0692:        
0693:        if ((TEXT_ENABLE & digitalBiosphereKinds)!=0) {
0694:            limitedPlainDocument = new LimitedPlainDocument(MAX_CHARACTERS);
0695:            limitedPlainDocument.addUndoableEditListener(new StandardUndoableEditListener());
0696:            
0697:            jTextArea = new JTextArea(limitedPlainDocument);
0698:            jTextArea.setEditable(false);
0699:            jTextArea.setFont(new Font("Serif", Font.PLAIN, 16));
0700:            jTextArea.setLineWrap(true);
0701:            jTextArea.setWrapStyleWord(true);
0702:            jTextArea.setToolTipText(resourceBundle.getString("ToolTipTextArea"));
0703:            jTextArea.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("TextAreaDescription"));
0704:            jScrollPane = new JScrollPane(jTextArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
0705:            jScrollPane.setPreferredSize(new Dimension(((Integer)environmentProperties.get("applicationwidth")).intValue(), ((Integer)environmentProperties.get("applicationheight")).intValue()/3));
0706:            contentPane.add(jScrollPane);
0707:            
0708:            jTextField = new JTextField();
0709:            jTextField.setDocument(limitedPlainDocument);
0710:            jTextField.setToolTipText(resourceBundle.getString("ToolTipTextField"));
0711:            jTextField.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("TextFieldDescription"));
0712:            jTextField.setPreferredSize(new Dimension(((Integer)environmentProperties.get("applicationwidth")).intValue(), jTextField.getPreferredSize().height));
0713:            jTextField.addActionListener(this );
0714:            createTextActionsTable(jTextField);
0715:            contentPane.add(jTextField);
0716:        }
0717:        
0718:        return contentPane;
0719:        
0720:    }
0721:    
0722:    private void createTextActionsTable(JTextComponent textComponent) {
0723:        
0724:        textActionsHashtable = new Hashtable();
0725:        Action[] actionsArray = textComponent.getActions();
0726:        for (int i = 0; i < actionsArray.length; i++) {
0727:            Action a = actionsArray[i];
0728:            textActionsHashtable.put(a.getValue(Action.NAME), a);
0729:        }
0730:        
0731:    }
0732:    
0733:    private Action getActionByName(String name) {
0734:        
0735:        return (Action)(textActionsHashtable.get(name));
0736:        
0737:    }
0738:    
0739:    private JMenuBar createJMenuBar() {
0740:        
0741:        //global definition JMenuBar jMenuBar; UndoAction undoAction, redoAction RedoAction; textActionsHashtable;
0742:        JMenu jMenu;
0743:        JMenuItem jMenuItem;
0744:        ButtonGroup buttonGroup;
0745:        JRadioButtonMenuItem jRadioButtonMenuItem;
0746:        JCheckBoxMenuItem jCheckBoxMenuItem;
0747:        
0748:        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
0749:        ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
0750:        jMenuBar = new JMenuBar();
0751:        jMenu = new JMenu(resourceBundle.getString("MenuFile"));
0752:        jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuFileDescription"));
0753:        jMenu.setMnemonic(KeyEvent.VK_F);
0754:        if (!((Boolean)environmentProperties.get("runasapplet")).booleanValue()) {
0755:            jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemStartMotionCapture"));
0756:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemStartMotionCaptureDescription"));
0757:            jMenuItem.setActionCommand(new String("MenuItemStartMotionCapture"));
0758:            jMenuItem.setEnabled(false);
0759:            jMenuItem.addActionListener(this );
0760:            jMenu.add(jMenuItem);
0761:            jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemStopMotionCapture"));
0762:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemStopMotionCaptureDescription"));
0763:            jMenuItem.setActionCommand(new String("MenuItemStopMotionCapture"));
0764:            jMenuItem.addActionListener(this );
0765:            jMenu.add(jMenuItem);
0766:            jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemCaptureScreen"));
0767:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemCaptureScreenDescription"));
0768:            jMenuItem.setActionCommand(new String("MenuItemCaptureScreen"));
0769:            jMenuItem.addActionListener(this );
0770:            jMenu.add(jMenuItem);
0771:            jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemPrintScreen"));
0772:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemPrintScreenDescription"));
0773:            jMenuItem.setActionCommand(new String("MenuItemPrintScreen"));
0774:            jMenuItem.addActionListener(this );
0775:            jMenu.add(jMenuItem);
0776:        }
0777:        jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemConnect"));
0778:        jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemConnectDescription"));
0779:        jMenuItem.setActionCommand(new String("MenuItemConnect"));
0780:        jMenuItem.addActionListener(this );
0781:        jMenu.add(jMenuItem);
0782:        
0783:        if (!((Boolean)environmentProperties.get("runasapplet")).booleanValue()) {
0784:            jMenu.addSeparator();
0785:            jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemExit"));
0786:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemExitDescription"));
0787:            jMenuItem.setMnemonic(KeyEvent.VK_STOP);
0788:            jMenuItem.setActionCommand(new String("MenuItemExit"));
0789:            jMenuItem.addActionListener(this );
0790:            jMenu.add(jMenuItem);
0791:        }
0792:        
0793:        jMenuBar.add(jMenu);
0794:        
0795:        jMenu = new JMenu(resourceBundle.getString("MenuEdit"));
0796:        jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuEditDescription"));
0797:        if ((TEXT_ENABLE & digitalBiosphereKinds)!=0) {
0798:            undoAction = new UndoAction();
0799:            jMenu.add(undoAction);
0800:            redoAction = new RedoAction();
0801:            jMenu.add(redoAction);
0802:            jMenu.addSeparator();
0803:            jMenu.add(getActionByName(DefaultEditorKit.cutAction));
0804:            jMenu.add(getActionByName(DefaultEditorKit.copyAction));
0805:            jMenu.add(getActionByName(DefaultEditorKit.pasteAction));
0806:            jMenu.add(getActionByName(DefaultEditorKit.selectAllAction));
0807:            jMenu.addSeparator();
0808:        }
0809:        jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemFramesPerSecond"));
0810:        jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemFramesPerSecondsDescription"));
0811:        jMenuItem.setActionCommand(new String("MenuItemFramesPerSecond"));
0812:        jMenuItem.addActionListener(this );
0813:        jMenu.add(jMenuItem);
0814:        jMenu.addSeparator();
0815:        jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemPreferences"));
0816:        jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemPreferencesDescription"));
0817:        jMenuItem.setActionCommand(new String("MenuItemPreferences"));
0818:        jMenuItem.addActionListener(this );
0819:        jMenu.add(jMenuItem);
0820:        jMenuBar.add(jMenu);
0821:        
0822:        if (((BROWSER_ENABLE & digitalBiosphereKinds)!=0)||((LIGHTS_ENABLE & digitalBiosphereKinds)!=0)) {
0823:            jMenu = new JMenu(resourceBundle.getString("MenuView"));
0824:            jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuViewDescription"));
0825:            if ((BROWSER_ENABLE & digitalBiosphereKinds)!=0) {
0826:                buttonGroup = new ButtonGroup();
0827:                jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemWalk"));
0828:                jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemWalkDescription"));
0829:                jRadioButtonMenuItem.setSelected(((Integer)userProperties.get("usernavigationmode")).intValue() == WALK_MODE);
0830:                jRadioButtonMenuItem.setActionCommand(new String("MenuItemWalk"));
0831:                jRadioButtonMenuItem.addActionListener(this );
0832:                buttonGroup.add(jRadioButtonMenuItem);
0833:                jMenu.add(jRadioButtonMenuItem);
0834:                jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemExamine"));
0835:                jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemExamineDescription"));
0836:                jRadioButtonMenuItem.setSelected(((Integer)userProperties.get("usernavigationmode")).intValue() == EXAMINE_MODE);
0837:                jRadioButtonMenuItem.setActionCommand(new String("MenuItemExamine"));
0838:                jRadioButtonMenuItem.addActionListener(this );
0839:                buttonGroup.add(jRadioButtonMenuItem);
0840:                jMenu.add(jRadioButtonMenuItem);
0841:                jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemFly"));
0842:                jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemFlyDescription"));
0843:                jRadioButtonMenuItem.setSelected(((Integer)userProperties.get("usernavigationmode")).intValue() == FLY_MODE);
0844:                jRadioButtonMenuItem.setActionCommand(new String("MenuItemFly"));
0845:                jRadioButtonMenuItem.addActionListener(this );
0846:                buttonGroup.add(jRadioButtonMenuItem);
0847:                jMenu.add(jRadioButtonMenuItem);
0848:                jMenu.addSeparator();
0849:                jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemStraighten"));
0850:                jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemStraightenDescription"));
0851:                jMenuItem.setActionCommand(new String("MenuItemStraighten"));
0852:                jMenuItem.addActionListener(this );
0853:                jMenu.add(jMenuItem);
0854:            }
0855:            if (((BROWSER_ENABLE + LIGHTS_ENABLE) & digitalBiosphereKinds)!=0) {
0856:                jMenu.addSeparator();
0857:            }
0858:            if ((LIGHTS_ENABLE & digitalBiosphereKinds)!=0) {
0859:                jCheckBoxMenuItem = new JCheckBoxMenuItem(resourceBundle.getString("MenuItemHeadLight"),((Boolean)userProperties.get("userheadlight")).booleanValue());
0860:                jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemHeadLightDescription"));
0861:                jCheckBoxMenuItem.setSelected(((Boolean)userProperties.get("userheadlight")).booleanValue());
0862:                jCheckBoxMenuItem.setActionCommand(new String("MenuItemHeadLight"));
0863:                jCheckBoxMenuItem.addActionListener(this );
0864:                jMenu.add(jCheckBoxMenuItem);
0865:                jCheckBoxMenuItem = new JCheckBoxMenuItem(resourceBundle.getString("MenuItemAmbientLight"),((Boolean)userProperties.get("userambientlight")).booleanValue());
0866:                jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemAmbientLightDescription"));
0867:                jCheckBoxMenuItem.setSelected(((Boolean)userProperties.get("userambientlight")).booleanValue());
0868:                jCheckBoxMenuItem.setActionCommand(new String("MenuItemAmbientLight"));
0869:                jCheckBoxMenuItem.addActionListener(this );
0870:                jMenu.add(jCheckBoxMenuItem);
0871:                jMenuBar.add(jMenu);
0872:            }
0873:            if (((BROWSER_ENABLE + LIGHTS_ENABLE) & digitalBiosphereKinds)!=0) {
0874:                jMenu.addSeparator();
0875:            }
0876:                            jCheckBoxMenuItem = new JCheckBoxMenuItem(resourceBundle.getString("MenuItemCollision"),((Boolean)userProperties.get("userheadlight")).booleanValue());
0877:                jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemCollisionDescription"));
0878:                jCheckBoxMenuItem.setSelected(((Boolean)userProperties.get("usercollision")).booleanValue());
0879:                jCheckBoxMenuItem.setActionCommand(new String("MenuItemCollision"));
0880:                jCheckBoxMenuItem.addActionListener(this );
0881:                jMenu.add(jCheckBoxMenuItem);
0882:
0883:        }
0884:        
0885:        jMenu = new JMenu(resourceBundle.getString("MenuTools"));
0886:        jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuToolsDescription"));
0887:        
0888:        buttonGroup = new ButtonGroup();
0889:        
0890:        for(int i = 0; i<this .getToolNames().length; i++){
0891:            jMenuItem = new JRadioButtonMenuItem(this .getToolNames()[i], null, false);
0892:            jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemToolDescription"));
0893:            jMenuItem.setActionCommand(new String("MenuItemTool"+i));
0894:            jMenuItem.addActionListener(this );
0895:            jMenu.add(jMenuItem);
0896:            buttonGroup.add(jMenuItem);
0897:        }
0898:        
0899:        jMenuBar.add(jMenu);
0900:        
0901:        jMenu = new JMenu(resourceBundle.getString("MenuViewpoints"));
0902:        jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuViewpointsDescription"));
0903:        jMenu.setEnabled(false);
0904:        jMenuBar.add(jMenu);
0905:        
0906:        if ((((Integer)environmentProperties.get("audioplaybacktype")).intValue())!=0)  {
0907:            jMenu = new JMenu(resourceBundle.getString("MenuVolume"));
0908:            jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuVolumeDescription"));
0909:            buttonGroup = new ButtonGroup();
0910:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemSilent"));
0911:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemSilentDescription"));
0912:            jRadioButtonMenuItem.setSelected(false);
0913:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemSilent"));
0914:            jRadioButtonMenuItem.addActionListener(this );
0915:            buttonGroup.add(jRadioButtonMenuItem);
0916:            jMenu.add(jRadioButtonMenuItem);
0917:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemVeryLow"));
0918:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemVeryLowDescription"));
0919:            jRadioButtonMenuItem.setSelected(false);
0920:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemVeryLow"));
0921:            jRadioButtonMenuItem.addActionListener(this );
0922:            buttonGroup.add(jRadioButtonMenuItem);
0923:            jMenu.add(jRadioButtonMenuItem);
0924:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemLow"));
0925:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemLowDescription"));
0926:            jRadioButtonMenuItem.setSelected(false);
0927:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemLow"));
0928:            jRadioButtonMenuItem.addActionListener(this );
0929:            buttonGroup.add(jRadioButtonMenuItem);
0930:            jMenu.add(jRadioButtonMenuItem);
0931:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemNormal"));
0932:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemNormalDescription"));
0933:            jRadioButtonMenuItem.setSelected(true);
0934:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemNormal"));
0935:            jRadioButtonMenuItem.addActionListener(this );
0936:            buttonGroup.add(jRadioButtonMenuItem);
0937:            jMenu.add(jRadioButtonMenuItem);
0938:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemHigh"));
0939:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemHighDescription"));
0940:            jRadioButtonMenuItem.setSelected(false);
0941:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemHigh"));
0942:            jRadioButtonMenuItem.addActionListener(this );
0943:            buttonGroup.add(jRadioButtonMenuItem);
0944:            jMenu.add(jRadioButtonMenuItem);
0945:            jRadioButtonMenuItem = new JRadioButtonMenuItem(resourceBundle.getString("MenuItemVeryHigh"));
0946:            jRadioButtonMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemVeryHighDescription"));
0947:            jRadioButtonMenuItem.setSelected(false);
0948:            jRadioButtonMenuItem.setActionCommand(new String("MenuItemVeryHigh"));
0949:            jRadioButtonMenuItem.addActionListener(this );
0950:            buttonGroup.add(jRadioButtonMenuItem);
0951:            jMenu.add(jRadioButtonMenuItem);
0952:            jMenuBar.add(jMenu);
0953:        }
0954:        
0955:        jMenuBar.add(Box.createHorizontalGlue());
0956:        
0957:        jMenu = new JMenu(resourceBundle.getString("MenuHelp"));
0958:        jMenu.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuHelpDescription"));
0959:        jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemContents"));
0960:        jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemContentsDescription"));
0961:        this .createHelpSet();
0962:        jMenuItem.setMnemonic(KeyEvent.VK_HELP);
0963:        jMenuItem.setActionCommand(new String("MenuItemContents"));
0964:        jMenuItem.addActionListener(this );
0965:        jMenu.add(jMenuItem);
0966:        jMenuItem = new JMenuItem(resourceBundle.getString("MenuItemAbout"));
0967:        jMenuItem.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("MenuItemAboutDescription"));
0968:        jMenuItem.setActionCommand(new String("MenuItemAbout"));
0969:        jMenuItem.addActionListener(this );
0970:        jMenu.add(jMenuItem);
0971:        jMenuBar.add(jMenu);
0972:        
0973:        return jMenuBar;
0974:        
0975:    }
0976:    
0977:    private void createHelpSet() {
0978:        
0979:        URL url;
0980:        HelpSet helpSet;
0981:        HelpBroker helpBroker;
0982:        ClassLoader loader;
0983:        
0984:        loader = this .getClass().getClassLoader();
0985:        
0986:        try {
0987:            url = HelpSet.findHelpSet(loader, new String("DigitalBiosphereClientHelp"));
0988:            if (url == null) {
0989:                url = new URL(getCodeBase(), "DigitalBiosphereClientHelp.hs");
0990:            }
0991:            helpSet = new HelpSet(loader, url);
0992:            helpBroker = helpSet.createHelpBroker();
0993:        } catch (Exception exception) {
0994:            System.err.println("Trouble in HelpSet creation.");
0995:            exception.printStackTrace();
0996:        }
0997:        
0998:    }
0999:    
1000:    private void createVirtualUniverse() {
1001:        
1002:        //global definition Canvas3D canvas3D; DirectionalLight headLight, AmbientLight ambientLight; Switch TheSwitch;boolean volumeMenuEnabled; JavaSoundMixer javaSoundMixer;
1003:        // global definition of all the BranchGroup
1004:        VirtualUniverse virtualUniverse;
1005:        PhysicalBody physicalBody;
1006:        PhysicalEnvironment physicalEnvironment;
1007:        javax.media.j3d.View view;
1008:        
1009:        ViewPlatform viewPlatform;
1010:        
1011:        BoundingSphere browserBounds;
1012:        BoundingSphere lightBounds;
1013:        
1014:        WalkViewerBehavior2 walkViewerBehavior2;
1015:        ExamineViewerBehavior examineViewerBehavior;
1016:        FlyViewerBehavior flyViewerBehavior;
1017:        
1018:        StandardPickViewer standardPickViewer;
1019:        
1020:        Cursor walkCursor;
1021:        Cursor examineCursor;
1022:        Cursor flyCursor;
1023:        
1024:        Cursor pickCursor;
1025:        
1026:        String url;
1027:        AudioVideoSaver audioVideoSaver;
1028:        PointSound soundOutput;
1029:        
1030:        KeyNavigatorBehavior keyNavigatorBehavior;
1031:        
1032:        virtualUniverse = new VirtualUniverse();
1033:        highResolutionLocale = new javax.media.j3d.Locale(virtualUniverse);
1034:        physicalBody = new PhysicalBody();
1035:        physicalEnvironment = new PhysicalEnvironment();
1036:        javaSoundMixer = new JavaSoundMixer(physicalEnvironment);
1037:        boolean volumeMenuEnabled = javaSoundMixer.initialize();
1038:        if (volumeMenuEnabled){
1039:            physicalEnvironment.setAudioDevice(javaSoundMixer);
1040:            environmentProperties.put("audioplaybacktype", new Integer(javaSoundMixer.getAudioPlaybackType()));
1041:        }
1042:        else {
1043:            environmentProperties.put("audioplaybacktype", new Integer(-1));
1044:        }
1045:        
1046:        view = new javax.media.j3d.View();
1047:        view.setFieldOfView(fieldOfView);
1048:        view.setFrontClipDistance(frontClip);
1049:        view.setBackClipDistance(backClip);
1050:        view.addCanvas3D(canvas3D);
1051:        view.setPhysicalBody(physicalBody);
1052:        view.setPhysicalEnvironment(physicalEnvironment);
1053:        environmentProperties.put("sceneantialiasingenable", new Boolean(view.getSceneAntialiasingEnable()));
1054:        
1055:        if ((WORLD_ENABLE & digitalBiosphereKinds)!=0) {
1056:            WorldBranchGroup = new BranchGroup();
1057:            WorldBranchGroup.setCapability(Node.ALLOW_BOUNDS_READ);
1058:            WorldBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1059:            WorldBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1060:            WorldBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1061:        }
1062:        
1063:        if ((OBJECTS_ENABLE & digitalBiosphereKinds)!=0) {
1064:            ObjectsBranchGroup = new BranchGroup();
1065:            ObjectsBranchGroup.setCapability(Node.ALLOW_BOUNDS_READ);
1066:            ObjectsBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1067:            ObjectsBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1068:            ObjectsBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1069:        }
1070:        
1071:        if ((TOOLS_ENABLE & digitalBiosphereKinds)!=0) {
1072:            ToolsBranchGroup = new BranchGroup();
1073:            ToolsBranchGroup.setCapability(Node.ALLOW_BOUNDS_READ);
1074:            ToolsBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1075:            ToolsBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1076:            ToolsBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1077:            ToolsBranchGroup.setCapability(BranchGroup.ALLOW_DETACH);
1078:        }
1079:        
1080:        UserBranchGroup = new BranchGroup();
1081:        UserBranchGroup.setCapability(Node.ALLOW_BOUNDS_READ);
1082:        UserBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1083:        UserBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1084:        UserBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1085:        
1086:        UserTransform = new TransformGroup();
1087:        UserTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
1088:        UserTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
1089:        UserTransform.setCapability(Group.ALLOW_CHILDREN_READ);
1090:        UserTransform.setCapability(Group.ALLOW_CHILDREN_WRITE);
1091:        UserTransform.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1092:        
1093:        UserBranchGroup.addChild(UserTransform);
1094:        
1095:        viewPlatform = new ViewPlatform();
1096:        //XXXXXuse client autocompute
1097:        viewPlatform.setActivationRadius(62.0f);
1098:        
1099:        view.attachViewPlatform(viewPlatform);
1100:        UserTransform.addChild(viewPlatform);
1101:        
1102:        if (JMFSupportedVersion.getVersion()>=2) {
1103:            // Create the off-screen Canvas3D object
1104:            offScreenCanvas3D = new OffScreenCanvas3D(canvas3D.getGraphicsConfiguration(), true);
1105:            // Set the off-screen size based on a scale factor times the
1106:            // on-screen size
1107:            Screen3D sOn = canvas3D.getScreen3D();
1108:            Screen3D sOff = offScreenCanvas3D.getScreen3D();
1109:            Dimension dimension = sOn.getSize();
1110:            dimension.width *= OFF_SCREEN_SCALE;
1111:            dimension.height *= OFF_SCREEN_SCALE;
1112:            sOff.setSize(dimension);
1113:            sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * OFF_SCREEN_SCALE);
1114:            sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * OFF_SCREEN_SCALE);
1115:            
1116:            // attach the offscreen canvas to the view
1117:            view.addCanvas3D(offScreenCanvas3D);
1118:            
1119:            //create a new handler to save captured motion
1120:            url = new String("capture.mov");
1121:            dimension = new Dimension(320, 200);
1122:            
1123:            audioVideoSaver = new AudioVideoSaver(url, canvas3D, dimension, AudioVideoSaver.VIDEO_ONLY);
1124:            
1125:            //create a new Sound to play live audio in
1126:            //you must have a microphone
1127:            //PointSound soundOutput = new PointSound();
1128:            //objects.addChild(soundOutput);            
1129:            //simpleUniverse.addBranchGraph(objects);
1130:            //j3DLiveAudioRenderer = new J3DLiveAudioRenderer(soundOutput);
1131:
1132:        }
1133:        
1134:        if ((LIGHTS_ENABLE & digitalBiosphereKinds)!=0) {
1135:            LightsBranchGroup = new BranchGroup();
1136:            LightsBranchGroup.setCapability(Node.ALLOW_BOUNDS_READ);
1137:            LightsBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1138:            LightsBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1139:            LightsBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
1140:            
1141:            UserTransform.addChild(LightsBranchGroup);
1142:            
1143:            lightBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE);
1144:            
1145:            headLight = new DirectionalLight(((Boolean)userProperties.get("userheadlight")).booleanValue(), new Color3f(0.8f, 0.8f, 0.8f), new Vector3f(0.0f, 0.0f, -1.0f));
1146:            headLight.setCapability(Light.ALLOW_STATE_WRITE);
1147:            headLight.setInfluencingBounds(lightBounds);
1148:            
1149:            LightsBranchGroup.addChild(headLight);
1150:            
1151:            ambientLight = new AmbientLight(((Boolean)userProperties.get("userambientlight")).booleanValue(), new Color3f(0.2f, 0.2f, 0.2f));
1152:            ambientLight.setInfluencingBounds(lightBounds);
1153:            ambientLight.setCapability(Light.ALLOW_STATE_WRITE);
1154:            
1155:            LightsBranchGroup.addChild(ambientLight);
1156:        }
1157:        
1158:        if ((BROWSER_ENABLE & digitalBiosphereKinds)!=0) {
1159:            BrowserBranchGroup = new BranchGroup();
1160:            BrowserBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
1161:            BrowserBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
1162:            
1163:            Image image;
1164:            
1165:            Toolkit toolkit = Toolkit.getDefaultToolkit();
1166:            Dimension cursorDimension = toolkit.getBestCursorSize(cursorPreferredWidth, cursorPreferredHeight);
1167:            int maximumcolors = toolkit.getMaximumCursorColors();
1168:            
1169:            if ((cursorDimension.getHeight()!=0) && (cursorDimension.getWidth()!=0) && (maximumcolors>0)) {
1170:                //should make more tests
1171:                image = toolkit.getImage("images/walkcursor.gif");
1172:                try {
1173:                    walkCursor = toolkit.createCustomCursor(image, new Point(8,8), resourceBundle.getString("WalkCursorDescription"));
1174:                }
1175:                catch (IndexOutOfBoundsException exception) {
1176:                    walkCursor =  new Cursor(Cursor.MOVE_CURSOR);
1177:                }
1178:                image.flush();
1179:                image = toolkit.getImage("images/examinecursor.gif");
1180:                try {
1181:                    examineCursor = toolkit.createCustomCursor(image, new Point(8,8), resourceBundle.getString("ExamineCursorDescription"));
1182:                }
1183:                catch (IndexOutOfBoundsException exception) {
1184:                    examineCursor =  new Cursor(Cursor.MOVE_CURSOR);
1185:                }
1186:                image.flush();
1187:                image = toolkit.getImage("images/flycursor.gif");
1188:                try {
1189:                    flyCursor = toolkit.createCustomCursor(image, new Point(8,8), resourceBundle.getString("FlyCursorDescription"));
1190:                }
1191:                catch (IndexOutOfBoundsException exception) {
1192:                    flyCursor =  new Cursor(Cursor.MOVE_CURSOR);
1193:                }
1194:                image.flush();
1195:            }
1196:            else {
1197:                walkCursor =  new Cursor(Cursor.MOVE_CURSOR);
1198:                examineCursor = new Cursor(Cursor.MOVE_CURSOR);
1199:                flyCursor = new Cursor(Cursor.MOVE_CURSOR);
1200:                pickCursor = new Cursor(Cursor.HAND_CURSOR);
1201:            }
1202:            
1203:            browserBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE);
1204:            
1205:            walkViewerBehavior2 = new WalkViewerBehavior2(UserTransform, canvas3D);
1206:            walkViewerBehavior2.setSchedulingBounds(browserBounds);
1207:            walkViewerBehavior2.setActiveCursor(walkCursor);
1208:            examineViewerBehavior = new ExamineViewerBehavior(UserTransform, canvas3D);
1209:            examineViewerBehavior.setSchedulingBounds(browserBounds);
1210:            examineViewerBehavior.setActiveCursor(examineCursor);
1211:            flyViewerBehavior = new FlyViewerBehavior(UserTransform, canvas3D);
1212:            flyViewerBehavior.setSchedulingBounds(browserBounds);
1213:            flyViewerBehavior.setActiveCursor(flyCursor);
1214:            
1215:            TheSwitch = new Switch();
1216:            TheSwitch.setCapability( Switch.ALLOW_SWITCH_WRITE );
1217:            
1218:            //order is important here WALK_MODE = 0; EXAMINE_MODE = 1; FLY_MODE = 2;
1219:            TheSwitch.addChild(walkViewerBehavior2);
1220:            TheSwitch.addChild(examineViewerBehavior);
1221:            TheSwitch.addChild(flyViewerBehavior);
1222:            
1223:            BrowserBranchGroup.addChild(TheSwitch);
1224:            
1225:            if ((OBJECTS_ENABLE & digitalBiosphereKinds)!=0) {
1226:                if ((cursorDimension.getHeight()!=0) && (cursorDimension.getWidth()!=0) && (maximumcolors>0)) {
1227:                    image = toolkit.getImage("images/pickcursor.gif");
1228:                    try {
1229:                        pickCursor = toolkit.createCustomCursor(image, new Point(8,8), resourceBundle.getString("PickCursorDescription"));
1230:                    }
1231:                    catch (IndexOutOfBoundsException exception) {
1232:                        pickCursor =  new Cursor(Cursor.HAND_CURSOR);
1233:                    }
1234:                    image.flush();
1235:                }
1236:                else {
1237:                    pickCursor = new Cursor(Cursor.HAND_CURSOR);
1238:                }
1239:                standardPickViewer = new StandardPickViewer(ObjectsBranchGroup, canvas3D, browserBounds);
1240:                standardPickViewer.setHighlightLevel(highlightLevel);
1241:                standardPickViewer.setActiveCursor(pickCursor);
1242:                BrowserBranchGroup.addChild(standardPickViewer);
1243:            }
1244:            
1245:            keyNavigatorBehavior = new KeyNavigatorBehavior(UserTransform);
1246:            
1247:            BrowserBranchGroup.addChild(keyNavigatorBehavior);
1248:            
1249:            TheSwitch.setWhichChild( ((Integer)userProperties.get("usernavigationmode")).intValue() );
1250:            
1251:            UserTransform.addChild(BrowserBranchGroup);
1252:        }
1253:        
1254:        if ((AVATAR_ENABLE & digitalBiosphereKinds)!=0) {
1255:            AvatarBranchGroup = new ViewerAvatar();
1256:            //XXXX
1257:            //Avatar
1258:            UserTransform.addChild(AvatarBranchGroup);
1259:        }
1260:        
1261:        if ((TOOLS_ENABLE & digitalBiosphereKinds)!=0) {
1262:            ConsoleBranchGroup = new PlatformGeometry();
1263:            //Console
1264:            UserTransform.addChild(ConsoleBranchGroup);
1265:        }
1266:        
1267:        if ((WORLD_ENABLE & digitalBiosphereKinds)!=0) {
1268:            //XXXXX
1269:            //world = new World();
1270:            //objRoot.addchild(world);
1271:            //node.setBoundsAutoCompute(boolean autoCompute)
1272:            //setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE)
1273:            //setCapability,(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ)
1274:            // objBounds = (BoundingSphere)objRoot.getBounds();
1275:            WorldBranchGroup.compile();
1276:            highResolutionLocale.addBranchGraph(WorldBranchGroup);
1277:        }
1278:        if ((OBJECTS_ENABLE & digitalBiosphereKinds)!=0) {
1279:            ObjectsBranchGroup.compile();
1280:            highResolutionLocale.addBranchGraph(ObjectsBranchGroup);
1281:        }
1282:        if ((TOOLS_ENABLE & digitalBiosphereKinds)!=0) {
1283:            ToolsBranchGroup.compile();
1284:            highResolutionLocale.addBranchGraph(ToolsBranchGroup);
1285:        }
1286:        if ((LIGHTS_ENABLE & digitalBiosphereKinds)!=0) {
1287:            LightsBranchGroup.compile();
1288:        }
1289:        if ((BROWSER_ENABLE & digitalBiosphereKinds)!=0) {
1290:            BrowserBranchGroup.compile();
1291:        }
1292:        if ((AVATAR_ENABLE & digitalBiosphereKinds)!=0) {
1293:            AvatarBranchGroup.compile();
1294:        }
1295:        if ((TOOLS_ENABLE & digitalBiosphereKinds)!=0) {
1296:            ConsoleBranchGroup.compile();
1297:        }
1298:        
1299:        UserBranchGroup.compile();
1300:        highResolutionLocale.addBranchGraph(UserBranchGroup);
1301:        
1302:    }
1303:    
1304:    public void setupDevices() {
1305:        
1306:        PortfolioApplication portfolioApplication;
1307:        
1308:        portfolioApplication = new PortfolioApplication();
1309:        portfolioApplication.configure(canvas3D, UserBranchGroup, UserTransform);
1310:        
1311:        wandDevice = new WandDevice();
1312:        birdAngleDevice = new BirdAngleDevice();
1313:        going = true;
1314:        flocks = birdAngleDevice.getSensorCount();
1315:        
1316:        wand = true;
1317:        bird = true;
1318:        
1319:        try {
1320:            wandDevice.initializePortfolioDevice("WandDriver");
1321:        } catch (NullPointerException npe) {
1322:            wand = false;
1323:            System.err.println("No wand found.");
1324:        }
1325:        
1326:        try {
1327:            birdAngleDevice.initializePortfolioDevice("BirdAngleDevice");
1328:        } catch (NullPointerException npe) {
1329:            bird = false;
1330:            System.err.println("No bird found.");
1331:        }
1332:        
1333:    }
1334:    
1335:    public boolean getTexture3DAvailable(Canvas3D canvas3D) {
1336:        
1337:        return ((Boolean)canvas3D.queryProperties().get("texture3DAvailable")).booleanValue();
1338:        
1339:    }
1340:    
1341:    public int getTextureColorTableSize(Canvas3D canvas3D) {
1342:        
1343:        return ((Integer)canvas3D.queryProperties().get("textureColorTableSize")).intValue();
1344:        
1345:    }
1346:    
1347:    private void TheConnectionCommand() {
1348:        
1349:        ConnectionJDialog connectionJDialog;
1350:        
1351:        connectionJDialog = new ConnectionJDialog(this , this .resourceBundle);
1352:        connectionJDialog.show();
1353:        
1354:    }
1355:    
1356:    protected void setConnectionJDialogResult(InetAddress inetAddress, int port, LoginInformation loginInformation) {
1357:        
1358:        InetAddress localHostIP;
1359:        int localHostPort;
1360:        String countryOfCall;
1361:        
1362:        localHostIP = InetAddress.getLocalHost();
1363:        localHostPort = DefaultLocalHostPort;
1364:        countryOfCall = new String("");
1365:        
1366:        //for applets
1367:        //String hostName;
1368:        //hostName = this.getCodeBase().getHost();
1369:        //if (hostName.equals("")) hostName = "127.0.0.1";
1370:        
1371:        userProperties.put("userserverconnection", inetAddress.toString());
1372:        userProperties.put("userserverportconnection", new Integer(port));
1373:        
1374:        //We could also use server helper
1375:        clientInformation = new ClientInformation(localHostIP, localHostPort, countryOfCall, inetAddress, port, loginInformation, new Transform3D());
1376:        client.openConnection(clientInformation);
1377:        // give a description of connection failure
1378:        
1379:    }
1380:    
1381:    public void actionPerformed(ActionEvent evt) {
1382:        
1383:        if (evt.getSource() instanceof  JTextField) {
1384:            jTextArea.append(jTextField.getText());
1385:            jTextField.setText(new String());
1386:        } else
1387:            if (evt.getSource() instanceof  JMenuItem) {
1388:                String arg = evt.getActionCommand();
1389:                if (arg.equals("MenuItemConnect")) {
1390:                    TheConnectionCommand();
1391:                } else
1392:                    if (arg.equals("MenuItemStartMotionCapture")) {
1393:                        ((JMenuItem)evt.getSource()).setEnabled(false);
1394:                        audioVideoSaver.start();
1395:                    } else
1396:                        if (arg.equals("MenuItemStopMotionCapture")) {
1397:                            audioVideoSaver.stop();
1398:                        } else
1399:                            if (arg.equals("MenuItemCaptureScreen")) {
1400:                                Point location = canvas3D.getLocationOnScreen();
1401:                                offScreenCanvas3D.setOffScreenLocation(location);
1402:                                Dimension dimension = canvas3D.getSize();
1403:                                dimension.width *= OFF_SCREEN_SCALE;
1404:                                dimension.height *= OFF_SCREEN_SCALE;
1405:                                BufferedImage bufferedImage = offScreenCanvas3D.doRender(dimension.width, dimension.height);
1406:                                new ImageSaver(bufferedImage).save("capture.jpg", 90.0f);
1407:                            } else
1408:                                if (arg.equals("MenuItemPrintScreen")) {
1409:                                    Point location = canvas3D.getLocationOnScreen();
1410:                                    offScreenCanvas3D.setOffScreenLocation(location);
1411:                                    Dimension dimension = canvas3D.getSize();
1412:                                    dimension.width *= OFF_SCREEN_SCALE;
1413:                                    dimension.height *= OFF_SCREEN_SCALE;
1414:                                    BufferedImage bufferedImage = offScreenCanvas3D.doRender(dimension.width, dimension.height);
1415:                                    new ImagePrinter(bufferedImage).print();
1416:                                } else
1417:                                    if (arg.equals("MenuItemExit")) {
1418:                                        this .stop();
1419:                                    } else
1420:                                        //undo, redo, cut,copy,paste, select all handled by inner classes
1421:                                        if (arg.equals("MenuItemFramesPerSecond")) {
1422:                                            float frameRate = canvas3D.getView().getFrameNumber() / canvas3D.getView().getLastFrameDuration();
1423:                                            System.out.println(frameRate);
1424:                                            
1425:                                        } else
1426:                                            if (arg.startsWith("MenuItemTool")) {
1427:                                                this .setActiveTool(new Integer(arg.substring(12, 13)).intValue());
1428:                                            } else
1429:                                                if (arg.equals("MenuItemPreferences")) {
1430:                                                    PreferencesJDialog preferencesJDialog = new PreferencesJDialog(new java.util.Locale((String)environmentProperties.get("currentlanguage"),(String)environmentProperties.get("currentcountry")), canvas3D, environmentProperties);
1431:                                                } else
1432:                                                    if (arg.equals("MenuItemWalk")) {
1433:                                                        userProperties.put("usernavigationmode", new Integer(WALK_MODE));
1434:                                                        TheSwitch.setWhichChild( ((Integer)userProperties.get("usernavigationmode")).intValue() );
1435:                                                    } else
1436:                                                        if (arg.equals("MenuItemExamine")) {
1437:                                                            userProperties.put("usernavigationmode", new Integer(EXAMINE_MODE));
1438:                                                            TheSwitch.setWhichChild( ((Integer)userProperties.get("usernavigationmode")).intValue() );
1439:                                                        } else
1440:                                                            if (arg.equals("MenuItemFly")) {
1441:                                                                userProperties.put("usernavigationmode", new Integer(FLY_MODE));
1442:                                                                TheSwitch.setWhichChild( ((Integer)userProperties.get("usernavigationmode")).intValue() );
1443:                                                            } else
1444:                                                                if (arg.equals("MenuItemStraighten")) {
1445:                                                                    Matrix3d matrix3d = new Matrix3d();
1446:                                                                    matrix3d.rotY(0.0d);
1447:                                                                    //must initialize transform3D for compiler
1448:                                                                    Transform3D transform3D = new Transform3D();
1449:                                                                    UserTransform.getTransform(transform3D);
1450:                                                                    transform3D.setRotation(matrix3d);
1451:                                                                    UserTransform.setTransform(transform3D);
1452:                                                                } else
1453:                                                                    if (arg.equals("MenuItemSilent")) {
1454:                                                                        setSoundVolume(0.0f);
1455:                                                                    } else
1456:                                                                        if (arg.equals("MenuItemVeryLow")) {
1457:                                                                            setSoundVolume(0.33f);
1458:                                                                        } else
1459:                                                                            if (arg.equals("MenuItemLow")) {
1460:                                                                                setSoundVolume(0.66f);
1461:                                                                            } else
1462:                                                                                if (arg.equals("MenuItemNormal")) {
1463:                                                                                    setSoundVolume(1.0f);
1464:                                                                                } else
1465:                                                                                    if (arg.equals("MenuItemHigh")) {
1466:                                                                                        setSoundVolume(1.33f);
1467:                                                                                    } else
1468:                                                                                        if (arg.equals("MenuItemVeryHigh")) {
1469:                                                                                            setSoundVolume(1.66f);
1470:                                                                                        } else
1471:                                                                                            if (arg.equals("MenuItemContents")) {
1472:                                                                                                helpBroker.setDisplayed(true);
1473:                                                                                            } else
1474:                                                                                                if (arg.equals("MenuItemAbout")) {
1475:                                                                                                    AboutJDialog aboutJDialog = new AboutJDialog(resourceBundle);
1476:                                                                                                    aboutJDialog.setVisible(true);
1477:                                                                                                }
1478:            }
1479:        
1480:    }
1481:    
1482:    public void itemStateChanged(ItemEvent evt) {
1483:        
1484:        JCheckBoxMenuItem Source;
1485:        
1486:        if (evt.getSource() instanceof  JCheckBoxMenuItem) {
1487:            Source = (JCheckBoxMenuItem)evt.getSource();
1488:            //Source = (JCheckBoxMenuItem)evt.getItem();
1489:            String arg = Source.getActionCommand();
1490:            if (Source.getActionCommand().equals("MenuItemHeadLight")) {
1491:                //boolean selected = (((JCheckBoxMenuItem)evt).getStateChange() == ItemEvent.SELECTED);
1492:                userProperties.put("userheadlight", new Boolean(Source.getState()));
1493:                headLight.setEnable(((Boolean)userProperties.get("userheadlight")).booleanValue());
1494:            } else
1495:                if (Source.getActionCommand().equals("MenuItemAmbientLight")) {
1496:                    //boolean selected = (((JCheckBoxMenuItem)evt).getStateChange() == ItemEvent.SELECTED);
1497:                    userProperties.put("userambientlight", new Boolean(Source.getState()));
1498:                    ambientLight.setEnable(((Boolean)userProperties.get("userambientlight")).booleanValue());
1499:                }
1500:        }
1501:        
1502:    }
1503:    
1504:    public void setSoundVolume(float volume) {
1505:        
1506:        javaSoundMixer.setGain(volume);
1507:        
1508:    }
1509:    
1510:    public String[] getToolNames(){
1511:        
1512:        return ToolManager.instance().getToolNames();
1513:        
1514:    }
1515:    
1516:    public void setActiveTool(int i){
1517:        
1518:        ToolManager.instance().setActiveTool(i);
1519:        
1520:    }
1521:    
1522:    public int button(int x) {
1523:        
1524:        return wandDevice.button(x);
1525:        
1526:    }
1527:    
1528:    public void pollAndProcessInput() {
1529:        
1530:        if (wand) {
1531:            wandDevice.pollAndProcessInput();
1532:        }
1533:        if (bird) {
1534:            birdAngleDevice.pollAndProcessInput();
1535:        }
1536:        
1537:    }
1538:    
1539:    public void paint(Graphics g) {
1540:        
1541:        pollAndProcessInput();
1542:        
1543:        if (bird) {
1544:            for (int x = 0; x < flocks; x++) {
1545:                fText[x][0].setText("X:  " + Float.toString(birdAngleDevice.getX(x)));
1546:                fText[x][1].setText("Y:  " + Float.toString(birdAngleDevice.getY(x)));
1547:                fText[x][2].setText("Z:  " + Float.toString(birdAngleDevice.getZ(x)));
1548:                fText[x][3].setText("XR: " + Float.toString(birdAngleDevice.getXR(x)));
1549:                fText[x][4].setText("YR: " + Float.toString(birdAngleDevice.getYR(x)));
1550:                fText[x][5].setText("ZR: " + Float.toString(birdAngleDevice.getZR(x)));
1551:            }
1552:        }
1553:        
1554:        if (wand) {
1555:            // Buttons
1556:            for (int x = 0; x < 3; x++) {
1557:                if (button(x) == 1) {
1558:                    g.setColor(new Color(1.0f, 0.0f, 0.0f));
1559:                } else {
1560:                    float shade = ((x + 1) % 3)/2.0f;
1561:                    g.setColor(new Color(shade, shade, shade));
1562:                }
1563:                if (x == 0)      { g.fillOval(10,40,25,25); }
1564:                else if (x == 1) { g.fillOval(50,25,25,25); }
1565:                else if (x == 2) { g.fillOval(90,40,25,25); }
1566:            }
1567:            
1568:            // Joystick
1569:            g.setColor(new Color(0.0f,0.0f,0.0f));
1570:            g.drawOval(37,70,50,50);
1571:            g.setColor(new Color(1.0f, 1.0f, 0.0f));
1572:            
1573:            double x = wandDevice.valuator(0);
1574:            double y = wandDevice.valuator(1);
1575:            
1576:            double theta = Math.atan2(y,x);
1577:            
1578:            g.drawLine(62,95,(int) (62 + 25 *  Math.abs(x) * Math.cos(theta) ),
1579:            (int) (95 + 25 * -Math.abs(y) * Math.sin(theta) ) );
1580:            
1581:            g.setColor(new Color(0.0f,0.0f,0.0f));
1582:        }
1583:        
1584:        if (going) { //true sauf iconified
1585:            repaint(100);
1586:        }
1587:        
1588:    }
1589:    
1590:    private void initializeSynthetizer() {
1591:        
1592:        try {
1593:            
1594:            //System.out.println("Starting JavaSpeech");
1595:            //System.out.println("locale is " + Locale.getDefault());
1596:            resources = ResourceBundle.getBundle("voice.properties");
1597:            
1598:            // create a recognizer matching default locale, add audio listener
1599:            recognizer = Central.createRecognizer(null);
1600:            recognizer.allocate();
1601:            recognizer.getAudioManager().addAudioListener(audioListener);
1602:            
1603:            // create dictation grammar
1604:            dictationGrammar = recognizer.getDictationGrammar(null);
1605:            dictationGrammar.addResultListener(dictationListener);
1606:            
1607:            // create a rule grammar, activate it
1608:            String grammarName = resources.getString("grammar");
1609:            Reader reader = new FileReader(grammarName);
1610:            ruleGrammar = recognizer.loadJSGF(reader);
1611:            ruleGrammar.addResultListener(ruleListener);
1612:            ruleGrammar.setEnabled(true);
1613:            
1614:            // commit new grammars, start recognizer
1615:            recognizer.commitChanges();
1616:            recognizer.requestFocus();
1617:            recognizer.resume();
1618:            
1619:            SynthesizerModeDesc required = new SynthesizerModeDesc();
1620:            Voice voice = new Voice(null, Voice.GENDER_FEMALE, Voice.AGE_TEENAGER, null);
1621:            required.addVoice(voice);
1622:            
1623:            // create a synthesizer, speak a greeting
1624:            synthesizer = Central.createSynthesizer(required);
1625:            
1626:            if (synthesizer!=null) synthesizer.allocate();
1627:            speak(resources.getString("greeting"));
1628:        } catch (Exception e) {
1629:            
1630:            e.printStackTrace();
1631:            System.exit(-1);
1632:            
1633:        }
1634:        
1635:    }
1636:    
1637:    // This is the listener for rule grammar results.  The
1638:    // resultAccepted method is called when the user issues a command.
1639:    // We then request the tags that we associated with the grammar in
1640:    // simplegrammar_en.gram, and take an action based on the tag.  Using tags
1641:    // rather than looking directly at what the user said means we can
1642:    // change the grammar without having to change our code.
1643:    //
1644:    private ResultListener ruleListener = new ResultAdapter() {
1645:        
1646:        // accepted result
1647:        public void resultAccepted(ResultEvent e) {
1648:            
1649:            try {
1650:                
1651:                // get the result
1652:                FinalRuleResult result = (FinalRuleResult) e.getSource();
1653:                String tags[] = result.getTags();
1654:                
1655:                if (tags[0].equals("begin")) {
1656:                    speak("listening");
1657:                    jTextArea.append("\"");
1658:                    ruleGrammar.setEnabled(false);
1659:                    ruleGrammar.setEnabled("<stop>", true);
1660:                    dictationGrammar.setEnabled(true);
1661:                    recognizer.commitChanges();
1662:                    
1663:                } else if (tags[0].equals("emote")) {
1664:                    speak("listening closely");
1665:                    jTextArea.append("emote ");
1666:                    ruleGrammar.setEnabled(false);
1667:                    ruleGrammar.setEnabled("<stop>", true);
1668:                    dictationGrammar.setEnabled(true);
1669:                    recognizer.commitChanges();
1670:                    
1671:                    
1672:                    // the user has said "that's all"
1673:                } else if (tags[0].equals("stop")) {
1674:                    dictationGrammar.setEnabled(false);
1675:                    ruleGrammar.setEnabled(true);
1676:                    recognizer.commitChanges();
1677:                    
1678:                } else if (tags[0].equals("lookleft")) {
1679:                    //XXX
1680:                }  else if (tags[0].equals("lookright")) {
1681:                    //XXX
1682:                } else if (tags[0].equals("left")) {
1683:                    //XXX
1684:                } else if (tags[0].equals("right")) {
1685:                    //XXX
1686:                } else if (tags[0].equals("run")) {
1687:                    //XXX
1688:                } else if (tags[0].equals("forward")) {
1689:                    //XXX
1690:                } else if (tags[0].equals("back")) {
1691:                    //XXX
1692:                } else if (tags[0].equals("halt")) {
1693:                    //XXX
1694:                } else if (tags[0].equals("bye")) {
1695:                    speak(resources.getString("bye"));
1696:                    //    synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
1697:                    //XXX
1698:                }
1699:            } catch (Exception ex) {
1700:                ex.printStackTrace();
1701:            }
1702:        }
1703:        
1704:        // rejected result - say "eh?" etc.
1705:        int i = 0;
1706:        String eh[] = null;
1707:        
1708:        public void resultRejected(ResultEvent e) {
1709:            
1710:         /*   if (eh==null) {
1711:                String s = resources.getString("eh");
1712:                StringTokenizer t = new StringTokenizer(s);
1713:                int n = t.countTokens();
1714:                eh = new String[n];
1715:                for (int i=0; i<n; i++)
1716:                    eh[i] = t.nextToken();
1717:            }*/
1718:            //            speak(eh[(i++)%eh.length]);
1719:        }
1720:        
1721:    };
1722:    
1723:    
1724:    //
1725:    // This is the listener for dictation results.  The resultUpdated
1726:    // method is called for every recognized token.  The
1727:    // resultAccepted method is called when the dictation result
1728:    // completes, which in this application occurs when the user says
1729:    // "that's all".
1730:    //
1731:    private ResultListener dictationListener = new ResultAdapter() {
1732:        
1733:        int n = 0;
1734:        
1735:        public synchronized void resultUpdated(ResultEvent e) {
1736:            Result result = (Result) e.getSource();
1737:            for (int i=n; i<result.numTokens(); i++) {
1738:                jTextArea.setText(jTextArea.getText()+" "+result.getBestToken(i).getSpokenText());
1739:            }
1740:            n = result.numTokens();
1741:        }
1742:        
1743:        public void resultAccepted(ResultEvent e) {
1744:            speak("Thank you");
1745:        }
1746:    };
1747:    
1748:    
1749:    //
1750:    // Audio listener prints out audio levels to help diagnose problems.
1751:    //
1752:    static RecognizerAudioListener audioListener = new RecognizerAudioAdapter(){
1753:        
1754:        public void audioLevel(RecognizerAudioEvent e) {
1755:        }
1756:        
1757:    };
1758:    
1759://checks programs to update from a repository
1760://by comparing checksum versions of every class
1761://and dowloading new versions as needed then launch the main file
1762:    XXXXXXXX
1763:autoupdater call
1764:If you are invoking the autoupdater on the Java GUI thread (for example, if you invoke it from an ActionListener or other code associated with a Java GUI component like a button), the gui event to build the progress window never gets processed, since the autoupdater itself is using the GUI thread. The solution is to spawn a separate thread that invokes the autoupdater. So instead of doing something like this  to invoke Autoupdater:
1765:Autoupdater.main(new String[] { ".", "http://www.xxx.com/client" }); 
1766:Do something like this :
1767:new Thread() { public void run() { Autoupdater.main(new String[] { ".", "http://www.xxx.com/client" }); } }.start(); 
1768:
1769:setLookAndFeel() {
1770:try
1771:{ File file = new File(System.getProperty("user.dir"), "gang.otm");
1772:OyoahaLookAndFeel lnf = new OyoahaLookAndFeel();
1773:
1774:if(file.exists())
1775:lnf.setOyoahaTheme(file);
1776:
1777:UIManager.setLookAndFeel(lnf); }
1778:catch (Exception e)
1779:{
1780:
1781:}
1782:
1783:}
1784:    //
1785:    // Here's a method to say something. If the synthesizer isn't
1786:    // available, we just print the message.
1787:    //
1788:    private void speak(String s) {
1789:        
1790:        if (synthesizer!=null) {
1791:            try {
1792:                synthesizer.speak(s, null);
1793:            } catch (Exception e) {
1794:                e.printStackTrace();
1795:            }
1796:        } else
1797:            System.out.println(s);
1798:        
1799:    }
1800:    
1801:    public synchronized void stopSynthetizer() {
1802:        
1803:        try { synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY); }
1804:        catch (Exception e) {}
1805:        
1806:    }
1807:    
1808:    public class LimitedPlainDocument  extends PlainDocument {
1809:        
1810:        int maxCharacters;
1811:        
1812:        public LimitedPlainDocument(int maxChars) {
1813:            
1814:            maxCharacters = maxChars;
1815:            
1816:        }
1817:        
1818:        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
1819:            
1820:            if ((getLength() + str.length()) <= maxCharacters) {
1821:                super .insertString(offs, str, a);
1822:            }
1823:            else {
1824:                //not very nice
1825:                Toolkit.getDefaultToolkit().beep();
1826:            }
1827:            
1828:        }
1829:        
1830:    }
1831:    
1832:    class UndoAction extends AbstractAction {
1833:        
1834:        public UndoAction() {
1835:            super (resourceBundle.getString("UndoAction"));
1836:            setEnabled(false);
1837:            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_UNDO));
1838:            putValue(Action.LONG_DESCRIPTION, resourceBundle.getString("UndoActionLongDescription"));
1839:            putValue(Action.SHORT_DESCRIPTION, resourceBundle.getString("UndoActionToolTip"));
1840:            //putValue(Action.SMALL_ICON, new ImageIcon("images/undo.gif")) );
1841:        }
1842:        
1843:        public void actionPerformed(ActionEvent e) {
1844:            try {
1845:                undoManager.undo();
1846:            } catch (CannotUndoException ex) {
1847:                //do nothing
1848:            }
1849:            updateUndoState();
1850:            redoAction.updateRedoState();
1851:        }
1852:        
1853:        protected void updateUndoState() {
1854:            if (undoManager.canUndo()) {
1855:                setEnabled(true);
1856:                putValue(Action.NAME, new String(resourceBundle.getString("UndoAction")).concat(new String(" ").concat(undoManager.getUndoPresentationName())));
1857:            } else {
1858:                setEnabled(false);
1859:                putValue(Action.NAME, resourceBundle.getString("UndoAction"));
1860:            }
1861:        }
1862:    }
1863:    
1864:    class RedoAction extends AbstractAction {
1865:        
1866:        public RedoAction() {
1867:            super (resourceBundle.getString("RedoAction"));
1868:            setEnabled(false);
1869:            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_AGAIN));
1870:            putValue(Action.LONG_DESCRIPTION, resourceBundle.getString("RedoActionLongDescription"));
1871:            putValue(Action.SHORT_DESCRIPTION, resourceBundle.getString("RedoActionToolTip"));
1872:            //putValue(Action.SMALL_ICON, new ImageIcon("images/redo.gif")) );
1873:        }
1874:        
1875:        public void actionPerformed(ActionEvent e) {
1876:            try {
1877:                undoManager.redo();
1878:            } catch (CannotRedoException cannotRedoException) {
1879:                //do nothing
1880:            }
1881:            updateRedoState();
1882:            undoAction.updateUndoState();
1883:        }
1884:        
1885:        protected void updateRedoState() {
1886:            if (undoManager.canRedo()) {
1887:                setEnabled(true);
1888:                putValue(Action.NAME, new String(resourceBundle.getString("RedoAction")).concat(new String(" ").concat(undoManager.getRedoPresentationName())));
1889:            } else {
1890:                setEnabled(false);
1891:                putValue(Action.NAME, resourceBundle.getString("RedoAction"));
1892:            }
1893:        }
1894:    }
1895:    
1896:    protected class StandardUndoableEditListener implements  UndoableEditListener {
1897:        
1898:        public void undoableEditHappened(UndoableEditEvent undoableEditEvent) {
1899:            
1900:            undoManager.addEdit(undoableEditEvent.getEdit());
1901:            undoAction.updateUndoState();
1902:            redoAction.updateRedoState();
1903:            
1904:        }
1905:        
1906:    }
1907:    
1908:    /**
1909:     * Enable/Disable collision detection for viewplatform behavior.
1910:     * If necessary set the capability bits in the scenegraph to
1911:     * enable picking of geometry which is how the collision detection is
1912:     * implemented
1913:     */
1914:    private void enableCollisionCStateChanged(javax.swing.event.ChangeEvent evt) {
1915:        
1916:        if (viewBehavior==null) {
1917:            return;
1918:        }
1919:        
1920:        if (!collisionCapabilitySet) {
1921:            collisionControl = new VPDefaultCollision();
1922:            
1923:            BranchGroup bg;
1924:            for(int i=0; i<graphs.size(); i++) {
1925:                bg = (BranchGroup)graphs.get(i);
1926:                setCollisionCapabilityBits(bg);
1927:            }
1928:            collisionCapabilitySet = true;
1929:            collisionControl.setCollisionLocale(highResolutionLocale);
1930:            collisionControl.setVPSweptVolume(new SimpleSweptVolume());
1931:            viewBehavior.setCollisionControl(collisionControl);
1932:        }
1933:        
1934:        viewBehavior.setCollisionEnabled(true);
1935:        
1936:    }
1937:    
1938:    /**
1939:     * Change the collisionController to the new object.
1940:     * Copy the state from the old controller to the new
1941:     */
1942:    private void changeCollisionController(VPDefaultCollision newController) {
1943:        
1944:        VPDefaultCollision oldController;
1945:        
1946:        oldController = collisionControl;
1947:        collisionControl = newController;
1948:        collisionControl.setCollisionLocale(highResolutionLocale);
1949:        
1950:        if (oldController==null) {
1951:            collisionControl.setVPSweptVolume(new SimpleSweptVolume());
1952:        } else {
1953:            collisionControl.setVPSweptVolume(oldController.getVPSweptVolume());
1954:        }
1955:    }
1956:    
1957:    private void setCollisionCapabilityBits(BranchGroup branchGroup) {
1958:        
1959:        NodeChangeProcessor nodeChangeProcessor;
1960:        
1961:        nodeChangeProcessor = new NodeChangeProcessor() {
1962:            
1963:            public void changeNode(Node node) {
1964:                com.sun.j3d.utils.picking.PickTool.setCapabilities(node, com.sun.j3d.utils.picking.PickTool.INTERSECT_COORD);
1965:            }
1966:            
1967:        };
1968:        
1969:        TreeScan.findNode( branchGroup, Shape3D.class, nodeChangeProcessor, false, true );
1970:        
1971:    }
1972:    
1973:    
1974:    private void changeController(java.awt.event.ActionEvent evt) {
1975:        
1976:        HoverBehavior hoverBehavior;
1977:        FlyBehavior flyBehavior;
1978:        OrbitBehavior orbitBehavior;
1979:        
1980:        boolean isCompiled = false;
1981:        for(int i=0; i<graphs.size(); i++) {
1982:            isCompiled |= ((BranchGroup)graphs.get(i)).isCompiled();
1983:        }
1984:        
1985:        if (viewBehaviorCB.getSelectedItem().equals("Hover")) {
1986:            hoverBehavior = new HoverBehavior(view);
1987:            hoverBehavior.setTarget(viewingPlatform.getViewPlatformTransform());
1988:            hoverBehavior.setSchedulingBounds( bigBounds );
1989:            hoverBehavior.setCollisionEnabled( true );
1990:            if (collisionControl!=null) {
1991:                if (collisionControl instanceof  VPDriveCollision)
1992:                    changeCollisionController(new VPDefaultCollision());
1993:                hoverBehavior.setCollisionControl( collisionControl );
1994:            }
1995:            viewBehavior = hoverBehavior;
1996:            viewingPlatform.setViewPlatformBehavior( hoverBehavior );
1997:        } else if (viewBehaviorCB.getSelectedItem().equals("Fly")) {
1998:            flyBehavior = new FlyBehavior();
1999:            flyBehavior.setTarget(viewingPlatform.getViewPlatformTransform());
2000:            flyBehavior.setSchedulingBounds(browserBounds);
2001:            flyBehavior.setCollisionEnabled(((Boolean)userProperties.get("usercollision")).booleanValue());
2002:            if (collisionControl!=null) {
2003:                if (collisionControl instanceof  VPDriveCollision)
2004:                    changeCollisionController( new VPDefaultCollision() );
2005:                flyBehavior.setCollisionControl( collisionControl );
2006:            }
2007:            viewBehavior = flyBehavior;
2008:            viewingPlatform.setViewPlatformBehavior( flyBehavior );
2009:        }  else if (viewBehaviorCB.getSelectedItem().equals("Orbit")) {
2010:            if (gotValidBounds || !isCompiled) {
2011:                viewBehavior = null;
2012:                // Orbit should really listen for WorldBoundsChange Events, but in
2013:                // the meantime the center is updated whenever new geometry is loaded
2014:                orbitBehavior = new OrbitBehavior( canvas3D, OrbitBehavior.REVERSE_ROTATE | OrbitBehavior.REVERSE_TRANSLATE );
2015:                orbitBehavior.setSchedulingBounds( bigBounds );
2016:                computeWorldBounds();
2017:                if (worldBounds!=null) {
2018:                    Point3d center = new Point3d();
2019:                    worldBounds.getCenter( center );
2020:                    orbitBehavior.setRotationCenter( center );
2021:                }
2022:                viewingPlatform.setViewPlatformBehavior( orbitBehavior );
2023:            }
2024:            
2025:        }
2026:        
2027:    }
2028:    
2029:    private void computeWorldBounds() {
2030:        
2031:        if (graphs.size()==0 || gotValidBounds) return;
2032:        
2033:        worldBounds = (BoundingSphere)((BranchGroup)graphs.get(0)).getBounds();
2034:        for (int i=1; i<graphs.size(); i++) {
2035:            worldBounds.combine(((BranchGroup)graphs.get(i)).getBounds());
2036:        }
2037:        gotValidBounds=true;
2038:        
2039:    }
2040:    
2041:    /**
2042:     * Set the transform so that everything inside the BoundingSphere is
2043:     * visible within the view frustum
2044:     */
2045:    private void setViewpoint( TransformGroup tg, BoundingSphere sceneBounds, javax.media.j3d.View view ) {
2046:        
2047:        Transform3D viewTrans = new Transform3D();
2048:        
2049:        com.sun.j3d.utils.universe.MultiTransformGroup mtg = universe.getViewingPlatform().getMultiTransformGroup();
2050:        TransformGroup scaleTG = mtg.getTransformGroup(0);
2051:        Transform3D t3d = new Transform3D();
2052:        scaleTG.getTransform( t3d );
2053:        double scale = t3d.getScale();
2054:        
2055:        // point the view at the center of the object
2056:        Point3d center = new Point3d();
2057:        sceneBounds.getCenter(center);
2058:        center.x /= scale;
2059:        center.y /= scale;
2060:        center.z /= scale;
2061:        
2062:        double radius = sceneBounds.getRadius()/scale;
2063:        
2064:        //System.out.println("Bounds "+center+"  "+radius );
2065:        
2066:        Point3d eyePos = new Point3d(center);
2067:        Vector3d up = new Vector3d();
2068:        
2069:        double fov = Math.toRadians( 45 );
2070:        //System.out.println("FOV "+Math.toDegrees(universe.getViewer().getView().getFieldOfView()));
2071:        
2072:        // pull the eye back far enough to see the whole object
2073:        double eyeDist = radius / Math.tan(fov / 2.0);
2074:        switch( showAllAxis ) {
2075:            case 0 :
2076:                eyePos.x += eyeDist;
2077:                up.y = 1;
2078:                break;
2079:            case 1 :
2080:                eyePos.y += eyeDist;
2081:                up.z = -1;
2082:                break;
2083:            case 2 :
2084:                eyePos.z += eyeDist;
2085:                up.y = 1;
2086:                break;
2087:            case 3 :
2088:                eyePos.x -= eyeDist;
2089:                up.y = 1;
2090:                break;
2091:            case 4 :
2092:                eyePos.y -= eyeDist;
2093:                up.z = -1;
2094:                break;
2095:            case 5 :
2096:                eyePos.z -= eyeDist;
2097:                up.y = 1;
2098:                break;
2099:        }
2100:        
2101:        //System.out.println( "Eye Pos "+eyePos );
2102:        //System.out.println( "Center "+center);
2103:        
2104:        viewTrans.lookAt( eyePos, center, up );
2105:        viewTrans.invert();
2106:        // If we have moved the model behind the back clip distance then change
2107:        // the back clip distance
2108:        if (view.getBackClipDistance()<eyeDist) {
2109:            view.setBackClipDistance( eyeDist );
2110:            
2111:        }
2112:        
2113:        // set the view transform
2114:        tg.setTransform(viewTrans);
2115:    }
2116:    
2117:    public class ProgressBarPanel extends JPanel {
2118:        
2119:        //global definition Thread loadThread; Object lock = new Object();  boolean shouldStop = false; JProgressBar progressBar;JTextField progressTextField;
2120:        JPanel bottomPanel;
2121:        JButton cancelButton;
2122:        JLabel loadStatus;
2123:        
2124:        public ProgressBarPanel() {
2125:            
2126:            setLayout(new BorderLayout());
2127:            
2128:            progressTextField = new JTextField();
2129:            progressTextField.setToolTipText(resourceBundle.getString("ToolTipProgressTextField"));
2130:            progressTextField.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("ProgressTextFieldDescription"));
2131:            add(progressTextField, BorderLayout.NORTH);
2132:            
2133:            bottomPanel = new JPanel();
2134:            bottomPanel.setLayout(new GridLayout(0,1));
2135:            bottomPanel.setToolTipText(resourceBundle.getString("ToolTipBottomPanel"));
2136:            bottomPanel.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("BottomPanelDescription"));
2137:            progressBar = new JProgressBar();
2138:            progressBar.setToolTipText(resourceBundle.getString("ToolTipProgressBar"));
2139:            progressBar.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("ProgressBarDescription"));
2140:            progressBar.setStringPainted(true);
2141:            bottomPanel.add(progressBar);
2142:            loadStatus = new JLabel(resourceBundle.getString("LoadStatus"));
2143:            loadStatus.setToolTipText(resourceBundle.getString("ToolTipLoadStatus"));
2144:            loadStatus.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("LoadStatusDescription"));
2145:            bottomPanel.add(loadStatus);
2146:            cancelButton = new JButton(resourceBundle.getString("CancelLoading"));
2147:            cancelButton.setToolTipText(resourceBundle.getString("ToolTipCancelButton"));
2148:            cancelButton.getAccessibleContext().setAccessibleDescription(resourceBundle.getString("CancelButtonDescription"));
2149:            cancelButton.addActionListener(
2150:            new ActionListener() {
2151:                public void actionPerformed(ActionEvent e) {
2152:                    stopLoading();
2153:                }
2154:            });
2155:            bottomPanel.add(cancelButton);
2156:            add(bottomPanel, BorderLayout.SOUTH);
2157:            
2158:            loadThread = new LoadThread();
2159:            shouldStop = false;
2160:            loadThread.start();
2161:            
2162:        }
2163:        
2164:        public void stopLoading() {
2165:            
2166:            synchronized(lock) {
2167:                shouldStop = true;
2168:                lock.notify();
2169:            }
2170:            
2171:        }
2172:        
2173:    }
2174:    
2175:    class LoadThread extends Thread {
2176:        
2177:        public void run() {
2178:            int min = 0;
2179:            int max = 100;
2180:            progressBar.setValue(min);
2181:            progressBar.setMinimum(min);
2182:            progressBar.setMaximum(max);
2183:            Runnable runner = new Runnable() {
2184:                public void run() {
2185:                    int value = progressBar.getValue();
2186:                    value++;
2187:                    //XXXXXX load something
2188:                    progressBar.setValue(value);
2189:                    progressTextField.setText(""+value);
2190:                }
2191:            };
2192:            for (int i=min;i<=max;i++) {
2193:                try {
2194:                    SwingUtilities.invokeAndWait(runner);
2195:                } catch (InvocationTargetException e) {
2196:                    break;
2197:                } catch (InterruptedException e) {
2198:                }
2199:                synchronized(lock) {
2200:                    if(shouldStop)
2201:                        break;
2202:                    try {
2203:                        lock.wait(100);
2204:                    } catch (InterruptedException e) {
2205:                    }
2206:                }
2207:            }
2208:            loadThread = null;
2209:        }
2210:        
2211:    }
2212:    
2213:    protected void debugPrint(String message) {
2214:        
2215:        if (debug)
2216:            System.out.print(message);
2217:        
2218:    }
2219:    
2220:    protected void debugPrint(boolean flag, String message) {
2221:        
2222:        if (flag)
2223:            System.out.print(message);
2224:        
2225:    }
2226:    
2227:    protected void debugPrintln(String message) {
2228:        
2229:        if (debug)
2230:            System.out.println(message);
2231:        
2232:    }
2233:    
2234:    protected void debugPrintln(boolean flag, String message) {
2235:        
2236:        if (flag)
2237:            System.out.println(message);
2238:        
2239:    }
2240:    
2241:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.