0001: /*
0002: *
0003: * Sun Public License Notice
0004: *
0005: * The contents of this file are subject to the Sun Public License Version
0006: * 1.0 (the "License"). You may not use this file except in compliance with
0007: * the License. A copy of the License is available at http://www.sun.com/
0008: *
0009: * The Original Code is Java 3D(tm) Fly Through.
0010: * The Initial Developer of the Original Code is Paul Byrne.
0011: * Portions created by Paul Byrne are Copyright (C) 2007.
0012: * All Rights Reserved.
0013: *
0014: * Contributor(s): Paul Byrne.
0015: *
0016: **/
0017: package org.jdesktop.j3dfly.plugins;
0018:
0019: import com.sun.j3d.utils.geometry.Sphere;
0020: import com.sun.j3d.utils.universe.ViewingPlatform;
0021: import java.awt.Dimension;
0022: import java.awt.Graphics;
0023: import java.awt.image.BufferedImage;
0024: import java.io.BufferedInputStream;
0025: import java.io.BufferedOutputStream;
0026: import java.io.File;
0027: import java.io.FileInputStream;
0028: import java.io.FileNotFoundException;
0029: import java.io.FileOutputStream;
0030: import java.io.IOException;
0031: import java.io.InputStream;
0032: import java.net.MalformedURLException;
0033: import java.net.URL;
0034: import java.util.ArrayList;
0035: import java.util.concurrent.Semaphore;
0036: import java.util.zip.GZIPOutputStream;
0037: import javax.imageio.ImageIO;
0038: import javax.media.j3d.Appearance;
0039: import javax.media.j3d.BranchGroup;
0040: import javax.media.j3d.ImageComponent;
0041: import javax.media.j3d.ImageComponent2D;
0042: import javax.media.j3d.Shape3D;
0043: import javax.media.j3d.Texture;
0044: import javax.media.j3d.Transform3D;
0045: import javax.media.j3d.TransformGroup;
0046: import javax.media.jai.JAI;
0047: import javax.media.jai.operator.TransposeDescriptor;
0048: import javax.swing.JFileChooser;
0049: import javax.swing.JOptionPane;
0050: import javax.swing.JPanel;
0051: import javax.swing.filechooser.FileFilter;
0052: import org.jdesktop.j3dfly.J3dFlyContext;
0053: import org.jdesktop.j3d.utils.scenegraph.traverser.TreeScan;
0054: import org.jdesktop.j3d.utils.scenegraph.traverser.ProcessNodeInterface;
0055: import org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL;
0056:
0057: //import org.jdesktop.j3d.utils.scenegraph.BranchGroupURL;
0058:
0059: /**
0060: * Tools for Wonderland work
0061: *
0062: * 1) Replace all the ImageComponent2Ds in a graph with ImageComponent2DURL, export
0063: * the existing images to a file and record the URL.
0064: *
0065: * @author Paul Byrne
0066: */
0067: public class WonderlandPlugin extends J3dFlyPlugin {
0068:
0069: private java.lang.ref.SoftReference panelReference = null;
0070:
0071: private int nameID = 0;
0072:
0073: /** Creates new form PluginTemplate */
0074: public WonderlandPlugin() {
0075: super ();
0076: }
0077:
0078: /** This method is called from within the constructor to
0079: * initialize the form.
0080: * WARNING: Do NOT modify this code. The content of this method is
0081: * always regenerated by the Form Editor.
0082: */
0083: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0084: private void initComponents() {
0085: java.awt.GridBagConstraints gridBagConstraints;
0086:
0087: menuBar = new javax.swing.JMenuBar();
0088: pluginMenu = new javax.swing.JMenu();
0089: urlImageComponentMI = new javax.swing.JMenuItem();
0090: changeBaseURLMI = new javax.swing.JMenuItem();
0091: addGraphInstanceMI = new javax.swing.JMenuItem();
0092: listPlacableLocationsMI = new javax.swing.JMenuItem();
0093: exportModelMI = new javax.swing.JMenuItem();
0094: urlImageDialog = new javax.swing.JDialog();
0095: jPanel1 = new javax.swing.JPanel();
0096: jScrollPane1 = new javax.swing.JScrollPane();
0097: imagePreviewPanel = new ImagePanel();
0098: jPanel2 = new javax.swing.JPanel();
0099: jLabel1 = new javax.swing.JLabel();
0100: mipmapLevelsTF = new javax.swing.JTextField();
0101: applyB = new javax.swing.JButton();
0102: imageFilenameTF = new javax.swing.JTextField();
0103: jLabel2 = new javax.swing.JLabel();
0104: browseB = new javax.swing.JButton();
0105: jLabel3 = new javax.swing.JLabel();
0106: imageSizeTF = new javax.swing.JTextField();
0107: jLabel4 = new javax.swing.JLabel();
0108: jLabel5 = new javax.swing.JLabel();
0109: resolutionTF = new javax.swing.JTextField();
0110: baseUrlDialog = new javax.swing.JDialog();
0111: jPanel3 = new javax.swing.JPanel();
0112: baseUrlApplyB = new javax.swing.JButton();
0113: jPanel4 = new javax.swing.JPanel();
0114: jLabel6 = new javax.swing.JLabel();
0115: urlTF = new javax.swing.JTextField();
0116: jLabel7 = new javax.swing.JLabel();
0117: namePrefixTF = new javax.swing.JTextField();
0118: imageExportDialog = new javax.swing.JDialog();
0119: imageExportPanel = new javax.swing.JPanel();
0120: jLabel9 = new javax.swing.JLabel();
0121: directoryTF = new javax.swing.JTextField();
0122: directoryBrowseB = new javax.swing.JButton();
0123: jLabel10 = new javax.swing.JLabel();
0124: imageNameTF = new javax.swing.JTextField();
0125: exportImagesB = new javax.swing.JButton();
0126: graphInstanceDialog = new javax.swing.JDialog();
0127: jPanel5 = new javax.swing.JPanel();
0128: jLabel8 = new javax.swing.JLabel();
0129: jLabel11 = new javax.swing.JLabel();
0130: graphInstanceBaseUrlTF = new javax.swing.JTextField();
0131: graphInstanceBrowseB = new javax.swing.JButton();
0132: graphNameTF = new javax.swing.JTextField();
0133: graphInstanceApplyB = new javax.swing.JButton();
0134: graphNameBrowseB = new javax.swing.JButton();
0135: modelProcessorDialog = new javax.swing.JDialog();
0136: jLabel12 = new javax.swing.JLabel();
0137: procModelnameTF = new javax.swing.JTextField();
0138: jLabel13 = new javax.swing.JLabel();
0139: procArtProjectPathTF = new javax.swing.JTextField();
0140: procOverwriteTextureCB = new javax.swing.JCheckBox();
0141: jLabel14 = new javax.swing.JLabel();
0142: procTextureNameTF = new javax.swing.JTextField();
0143: jLabel15 = new javax.swing.JLabel();
0144: procBaseURLTF = new javax.swing.JTextField();
0145: exportB = new javax.swing.JButton();
0146:
0147: pluginMenu.setText("Wonderland");
0148: urlImageComponentMI.setText("Convert ImageComponents to URLs");
0149: urlImageComponentMI.setEnabled(false);
0150: urlImageComponentMI
0151: .addActionListener(new java.awt.event.ActionListener() {
0152: public void actionPerformed(
0153: java.awt.event.ActionEvent evt) {
0154: urlImageComponentMIActionPerformed(evt);
0155: }
0156: });
0157:
0158: pluginMenu.add(urlImageComponentMI);
0159:
0160: changeBaseURLMI.setText("Change BaseURL...");
0161: changeBaseURLMI.setEnabled(false);
0162: changeBaseURLMI
0163: .addActionListener(new java.awt.event.ActionListener() {
0164: public void actionPerformed(
0165: java.awt.event.ActionEvent evt) {
0166: changeBaseURLMIActionPerformed(evt);
0167: }
0168: });
0169:
0170: pluginMenu.add(changeBaseURLMI);
0171:
0172: addGraphInstanceMI.setText("Add GraphInstance");
0173: addGraphInstanceMI.setEnabled(false);
0174: addGraphInstanceMI
0175: .addActionListener(new java.awt.event.ActionListener() {
0176: public void actionPerformed(
0177: java.awt.event.ActionEvent evt) {
0178: addGraphInstanceMIActionPerformed(evt);
0179: }
0180: });
0181:
0182: pluginMenu.add(addGraphInstanceMI);
0183:
0184: listPlacableLocationsMI.setText("List Placable Locations");
0185: listPlacableLocationsMI
0186: .addActionListener(new java.awt.event.ActionListener() {
0187: public void actionPerformed(
0188: java.awt.event.ActionEvent evt) {
0189: listPlacableLocationsMIActionPerformed(evt);
0190: }
0191: });
0192:
0193: pluginMenu.add(listPlacableLocationsMI);
0194:
0195: exportModelMI.setText("Export to Wonderland");
0196: exportModelMI
0197: .addActionListener(new java.awt.event.ActionListener() {
0198: public void actionPerformed(
0199: java.awt.event.ActionEvent evt) {
0200: exportModelMIActionPerformed(evt);
0201: }
0202: });
0203:
0204: pluginMenu.add(exportModelMI);
0205:
0206: menuBar.add(pluginMenu);
0207:
0208: jPanel1.setLayout(new java.awt.BorderLayout());
0209:
0210: jScrollPane1.setMinimumSize(new java.awt.Dimension(256, 256));
0211: jScrollPane1.setPreferredSize(new java.awt.Dimension(256, 256));
0212: jScrollPane1.setRequestFocusEnabled(false);
0213: jScrollPane1.setViewportView(imagePreviewPanel);
0214:
0215: jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
0216:
0217: jPanel2.setLayout(new java.awt.GridBagLayout());
0218:
0219: jLabel1.setText("Mipmap Levels");
0220: jPanel2.add(jLabel1, new java.awt.GridBagConstraints());
0221:
0222: mipmapLevelsTF.setColumns(2);
0223: mipmapLevelsTF.setEditable(false);
0224: mipmapLevelsTF.setText("0");
0225: gridBagConstraints = new java.awt.GridBagConstraints();
0226: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0227: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0228: jPanel2.add(mipmapLevelsTF, gridBagConstraints);
0229:
0230: applyB.setText("Apply");
0231: applyB.addActionListener(new java.awt.event.ActionListener() {
0232: public void actionPerformed(java.awt.event.ActionEvent evt) {
0233: applyBActionPerformed(evt);
0234: }
0235: });
0236:
0237: gridBagConstraints = new java.awt.GridBagConstraints();
0238: gridBagConstraints.gridx = 1;
0239: gridBagConstraints.gridy = 3;
0240: jPanel2.add(applyB, gridBagConstraints);
0241:
0242: imageFilenameTF.setColumns(25);
0243: imageFilenameTF.setToolTipText("Filename for texture");
0244: gridBagConstraints = new java.awt.GridBagConstraints();
0245: gridBagConstraints.gridx = 1;
0246: gridBagConstraints.gridy = 2;
0247: gridBagConstraints.gridwidth = 3;
0248: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0249: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0250: jPanel2.add(imageFilenameTF, gridBagConstraints);
0251:
0252: jLabel2.setText("Filename");
0253: gridBagConstraints = new java.awt.GridBagConstraints();
0254: gridBagConstraints.gridx = 0;
0255: gridBagConstraints.gridy = 2;
0256: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0257: jPanel2.add(jLabel2, gridBagConstraints);
0258:
0259: browseB.setText("Browse");
0260: browseB.addActionListener(new java.awt.event.ActionListener() {
0261: public void actionPerformed(java.awt.event.ActionEvent evt) {
0262: browseBActionPerformed(evt);
0263: }
0264: });
0265:
0266: gridBagConstraints = new java.awt.GridBagConstraints();
0267: gridBagConstraints.gridx = 4;
0268: gridBagConstraints.gridy = 2;
0269: jPanel2.add(browseB, gridBagConstraints);
0270:
0271: jLabel3.setText("Size");
0272: gridBagConstraints = new java.awt.GridBagConstraints();
0273: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0274: jPanel2.add(jLabel3, gridBagConstraints);
0275:
0276: imageSizeTF.setColumns(5);
0277: imageSizeTF.setEditable(false);
0278: imageSizeTF.setText("0");
0279: imageSizeTF.setToolTipText("Image size in KB");
0280: gridBagConstraints = new java.awt.GridBagConstraints();
0281: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0282: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
0283: jPanel2.add(imageSizeTF, gridBagConstraints);
0284:
0285: jLabel4.setText("kB");
0286: gridBagConstraints = new java.awt.GridBagConstraints();
0287: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0288: jPanel2.add(jLabel4, gridBagConstraints);
0289:
0290: jLabel5.setText("Resolution");
0291: gridBagConstraints = new java.awt.GridBagConstraints();
0292: gridBagConstraints.gridx = 0;
0293: gridBagConstraints.gridy = 1;
0294: jPanel2.add(jLabel5, gridBagConstraints);
0295:
0296: resolutionTF.setColumns(9);
0297: gridBagConstraints = new java.awt.GridBagConstraints();
0298: gridBagConstraints.gridx = 1;
0299: gridBagConstraints.gridy = 1;
0300: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0301: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0302: jPanel2.add(resolutionTF, gridBagConstraints);
0303:
0304: jPanel1.add(jPanel2, java.awt.BorderLayout.SOUTH);
0305:
0306: urlImageDialog.getContentPane().add(jPanel1,
0307: java.awt.BorderLayout.CENTER);
0308:
0309: baseUrlDialog.setTitle("Image BaseURL update");
0310: baseUrlApplyB.setText("Apply");
0311: baseUrlApplyB
0312: .addActionListener(new java.awt.event.ActionListener() {
0313: public void actionPerformed(
0314: java.awt.event.ActionEvent evt) {
0315: baseUrlApplyBActionPerformed(evt);
0316: }
0317: });
0318:
0319: jPanel3.add(baseUrlApplyB);
0320:
0321: baseUrlDialog.getContentPane().add(jPanel3,
0322: java.awt.BorderLayout.SOUTH);
0323:
0324: jPanel4.setLayout(new java.awt.GridBagLayout());
0325:
0326: jLabel6.setText("Base URL");
0327: gridBagConstraints = new java.awt.GridBagConstraints();
0328: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0329: jPanel4.add(jLabel6, gridBagConstraints);
0330:
0331: urlTF.setColumns(25);
0332: urlTF.setText("http://192.18.37.42");
0333: gridBagConstraints = new java.awt.GridBagConstraints();
0334: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0335: jPanel4.add(urlTF, gridBagConstraints);
0336:
0337: jLabel7.setText("Name Prefix");
0338: gridBagConstraints = new java.awt.GridBagConstraints();
0339: gridBagConstraints.gridx = 0;
0340: gridBagConstraints.gridy = 1;
0341: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0342: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0343: jPanel4.add(jLabel7, gridBagConstraints);
0344:
0345: namePrefixTF.setText("/textures/");
0346: gridBagConstraints = new java.awt.GridBagConstraints();
0347: gridBagConstraints.gridx = 1;
0348: gridBagConstraints.gridy = 1;
0349: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0350: jPanel4.add(namePrefixTF, gridBagConstraints);
0351:
0352: baseUrlDialog.getContentPane().add(jPanel4,
0353: java.awt.BorderLayout.CENTER);
0354:
0355: imageExportPanel.setLayout(new java.awt.GridBagLayout());
0356:
0357: imageExportPanel
0358: .setMinimumSize(new java.awt.Dimension(296, 100));
0359: imageExportPanel.setPreferredSize(new java.awt.Dimension(296,
0360: 100));
0361: jLabel9.setText("Directory");
0362: gridBagConstraints = new java.awt.GridBagConstraints();
0363: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0364: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0365: imageExportPanel.add(jLabel9, gridBagConstraints);
0366:
0367: directoryTF.setColumns(15);
0368: directoryTF
0369: .addActionListener(new java.awt.event.ActionListener() {
0370: public void actionPerformed(
0371: java.awt.event.ActionEvent evt) {
0372: directoryTFActionPerformed(evt);
0373: }
0374: });
0375:
0376: gridBagConstraints = new java.awt.GridBagConstraints();
0377: gridBagConstraints.gridx = 1;
0378: gridBagConstraints.gridy = 0;
0379: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0380: imageExportPanel.add(directoryTF, gridBagConstraints);
0381:
0382: directoryBrowseB.setText("Browse");
0383: directoryBrowseB
0384: .addActionListener(new java.awt.event.ActionListener() {
0385: public void actionPerformed(
0386: java.awt.event.ActionEvent evt) {
0387: directoryBrowseBActionPerformed(evt);
0388: }
0389: });
0390:
0391: gridBagConstraints = new java.awt.GridBagConstraints();
0392: gridBagConstraints.gridx = 2;
0393: gridBagConstraints.gridy = 0;
0394: imageExportPanel.add(directoryBrowseB, gridBagConstraints);
0395:
0396: jLabel10.setText("Image Name");
0397: gridBagConstraints = new java.awt.GridBagConstraints();
0398: gridBagConstraints.gridx = 0;
0399: gridBagConstraints.gridy = 1;
0400: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0401: imageExportPanel.add(jLabel10, gridBagConstraints);
0402:
0403: imageNameTF.setText("texture_");
0404: gridBagConstraints = new java.awt.GridBagConstraints();
0405: gridBagConstraints.gridx = 1;
0406: gridBagConstraints.gridy = 1;
0407: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0408: imageExportPanel.add(imageNameTF, gridBagConstraints);
0409:
0410: exportImagesB.setText("Export");
0411: exportImagesB
0412: .addActionListener(new java.awt.event.ActionListener() {
0413: public void actionPerformed(
0414: java.awt.event.ActionEvent evt) {
0415: exportImagesBActionPerformed(evt);
0416: }
0417: });
0418:
0419: gridBagConstraints = new java.awt.GridBagConstraints();
0420: gridBagConstraints.gridx = 1;
0421: gridBagConstraints.gridy = 2;
0422: gridBagConstraints.insets = new java.awt.Insets(9, 0, 0, 0);
0423: imageExportPanel.add(exportImagesB, gridBagConstraints);
0424:
0425: imageExportDialog.getContentPane().add(imageExportPanel,
0426: java.awt.BorderLayout.CENTER);
0427:
0428: jLabel8.setText("Base URL");
0429:
0430: jLabel11.setText("Graph Name");
0431:
0432: graphInstanceBrowseB.setText("Browse");
0433: graphInstanceBrowseB
0434: .addActionListener(new java.awt.event.ActionListener() {
0435: public void actionPerformed(
0436: java.awt.event.ActionEvent evt) {
0437: graphInstanceBrowseBActionPerformed(evt);
0438: }
0439: });
0440:
0441: graphInstanceApplyB.setText("Apply");
0442: graphInstanceApplyB
0443: .addActionListener(new java.awt.event.ActionListener() {
0444: public void actionPerformed(
0445: java.awt.event.ActionEvent evt) {
0446: graphInstanceApplyBActionPerformed(evt);
0447: }
0448: });
0449:
0450: graphNameBrowseB.setText("Browse");
0451: graphNameBrowseB.setEnabled(false);
0452: graphNameBrowseB
0453: .addActionListener(new java.awt.event.ActionListener() {
0454: public void actionPerformed(
0455: java.awt.event.ActionEvent evt) {
0456: graphNameBrowseBActionPerformed(evt);
0457: }
0458: });
0459:
0460: org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(
0461: jPanel5);
0462: jPanel5.setLayout(jPanel5Layout);
0463: jPanel5Layout
0464: .setHorizontalGroup(jPanel5Layout
0465: .createParallelGroup(
0466: org.jdesktop.layout.GroupLayout.LEADING)
0467: .add(
0468: jPanel5Layout
0469: .createSequentialGroup()
0470: .add(
0471: jPanel5Layout
0472: .createParallelGroup(
0473: org.jdesktop.layout.GroupLayout.LEADING)
0474: .add(
0475: jPanel5Layout
0476: .createSequentialGroup()
0477: .addContainerGap()
0478: .add(
0479: jPanel5Layout
0480: .createParallelGroup(
0481: org.jdesktop.layout.GroupLayout.LEADING)
0482: .add(
0483: jLabel8)
0484: .add(
0485: jLabel11))
0486: .add(
0487: 19,
0488: 19,
0489: 19)
0490: .add(
0491: jPanel5Layout
0492: .createParallelGroup(
0493: org.jdesktop.layout.GroupLayout.LEADING,
0494: false)
0495: .add(
0496: graphNameTF)
0497: .add(
0498: graphInstanceBaseUrlTF,
0499: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0500: 168,
0501: Short.MAX_VALUE))
0502: .add(
0503: 23,
0504: 23,
0505: 23)
0506: .add(
0507: jPanel5Layout
0508: .createParallelGroup(
0509: org.jdesktop.layout.GroupLayout.LEADING)
0510: .add(
0511: graphNameBrowseB)
0512: .add(
0513: graphInstanceBrowseB)))
0514: .add(
0515: jPanel5Layout
0516: .createSequentialGroup()
0517: .add(
0518: 147,
0519: 147,
0520: 147)
0521: .add(
0522: graphInstanceApplyB)))
0523: .addContainerGap(20,
0524: Short.MAX_VALUE)));
0525: jPanel5Layout
0526: .setVerticalGroup(jPanel5Layout
0527: .createParallelGroup(
0528: org.jdesktop.layout.GroupLayout.LEADING)
0529: .add(
0530: jPanel5Layout
0531: .createSequentialGroup()
0532: .addContainerGap()
0533: .add(
0534: jPanel5Layout
0535: .createParallelGroup(
0536: org.jdesktop.layout.GroupLayout.BASELINE)
0537: .add(jLabel8)
0538: .add(
0539: graphInstanceBaseUrlTF,
0540: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0541: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0542: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0543: .add(
0544: graphInstanceBrowseB))
0545: .addPreferredGap(
0546: org.jdesktop.layout.LayoutStyle.RELATED)
0547: .add(
0548: jPanel5Layout
0549: .createParallelGroup(
0550: org.jdesktop.layout.GroupLayout.BASELINE)
0551: .add(jLabel11)
0552: .add(
0553: graphNameTF,
0554: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0555: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0556: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0557: .add(
0558: graphNameBrowseB))
0559: .add(27, 27, 27).add(
0560: graphInstanceApplyB)
0561: .addContainerGap(17,
0562: Short.MAX_VALUE)));
0563: graphInstanceDialog.getContentPane().add(jPanel5,
0564: java.awt.BorderLayout.CENTER);
0565:
0566: jLabel12.setText("Model Name");
0567:
0568: procModelnameTF.setText("Model Name");
0569: procModelnameTF.setToolTipText("The name of the model");
0570:
0571: jLabel13.setText("Wonderland Art Project");
0572:
0573: procArtProjectPathTF.setText("../../lg3d-wonderland-art");
0574: procArtProjectPathTF
0575: .setToolTipText("Path to lg3d-wonderland-art project");
0576:
0577: procOverwriteTextureCB.setText("Overwrite Existing Textures");
0578: procOverwriteTextureCB
0579: .setToolTipText("Overwrite existing texture files");
0580: procOverwriteTextureCB.setBorder(javax.swing.BorderFactory
0581: .createEmptyBorder(0, 0, 0, 0));
0582: procOverwriteTextureCB
0583: .setMargin(new java.awt.Insets(0, 0, 0, 0));
0584:
0585: jLabel14.setText("Default Texture Name");
0586:
0587: procTextureNameTF.setText("texture_");
0588: procTextureNameTF
0589: .setToolTipText("The name used for textures that are not named in the model");
0590:
0591: jLabel15.setText("Base URL");
0592:
0593: procBaseURLTF.setText("http://192.18.37.42");
0594: procBaseURLTF
0595: .setToolTipText("Base URL which will serve image files");
0596:
0597: exportB.setText("Export");
0598: exportB.addActionListener(new java.awt.event.ActionListener() {
0599: public void actionPerformed(java.awt.event.ActionEvent evt) {
0600: exportBActionPerformed(evt);
0601: }
0602: });
0603:
0604: org.jdesktop.layout.GroupLayout modelProcessorDialogLayout = new org.jdesktop.layout.GroupLayout(
0605: modelProcessorDialog.getContentPane());
0606: modelProcessorDialog.getContentPane().setLayout(
0607: modelProcessorDialogLayout);
0608: modelProcessorDialogLayout
0609: .setHorizontalGroup(modelProcessorDialogLayout
0610: .createParallelGroup(
0611: org.jdesktop.layout.GroupLayout.LEADING)
0612: .add(
0613: modelProcessorDialogLayout
0614: .createSequentialGroup()
0615: .add(
0616: modelProcessorDialogLayout
0617: .createParallelGroup(
0618: org.jdesktop.layout.GroupLayout.LEADING)
0619: .add(
0620: modelProcessorDialogLayout
0621: .createSequentialGroup()
0622: .addContainerGap()
0623: .add(
0624: modelProcessorDialogLayout
0625: .createParallelGroup(
0626: org.jdesktop.layout.GroupLayout.LEADING)
0627: .add(
0628: modelProcessorDialogLayout
0629: .createSequentialGroup()
0630: .add(
0631: jLabel14)
0632: .addPreferredGap(
0633: org.jdesktop.layout.LayoutStyle.RELATED)
0634: .add(
0635: procTextureNameTF,
0636: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0637: 109,
0638: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0639: .add(
0640: procOverwriteTextureCB)
0641: .add(
0642: modelProcessorDialogLayout
0643: .createSequentialGroup()
0644: .add(
0645: modelProcessorDialogLayout
0646: .createParallelGroup(
0647: org.jdesktop.layout.GroupLayout.LEADING)
0648: .add(
0649: jLabel13)
0650: .add(
0651: jLabel15)
0652: .add(
0653: jLabel12))
0654: .addPreferredGap(
0655: org.jdesktop.layout.LayoutStyle.RELATED)
0656: .add(
0657: modelProcessorDialogLayout
0658: .createParallelGroup(
0659: org.jdesktop.layout.GroupLayout.LEADING,
0660: false)
0661: .add(
0662: procModelnameTF)
0663: .add(
0664: procBaseURLTF)
0665: .add(
0666: procArtProjectPathTF,
0667: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0668: 207,
0669: Short.MAX_VALUE)))))
0670: .add(
0671: modelProcessorDialogLayout
0672: .createSequentialGroup()
0673: .add(
0674: 150,
0675: 150,
0676: 150)
0677: .add(
0678: exportB)))
0679: .addContainerGap(26,
0680: Short.MAX_VALUE)));
0681: modelProcessorDialogLayout
0682: .setVerticalGroup(modelProcessorDialogLayout
0683: .createParallelGroup(
0684: org.jdesktop.layout.GroupLayout.LEADING)
0685: .add(
0686: modelProcessorDialogLayout
0687: .createSequentialGroup()
0688: .addContainerGap()
0689: .add(
0690: modelProcessorDialogLayout
0691: .createParallelGroup(
0692: org.jdesktop.layout.GroupLayout.BASELINE)
0693: .add(jLabel12)
0694: .add(
0695: procModelnameTF,
0696: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0697: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0698: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0699: .add(
0700: modelProcessorDialogLayout
0701: .createParallelGroup(
0702: org.jdesktop.layout.GroupLayout.LEADING)
0703: .add(
0704: modelProcessorDialogLayout
0705: .createSequentialGroup()
0706: .add(
0707: 35,
0708: 35,
0709: 35)
0710: .add(
0711: jLabel15))
0712: .add(
0713: modelProcessorDialogLayout
0714: .createSequentialGroup()
0715: .addPreferredGap(
0716: org.jdesktop.layout.LayoutStyle.RELATED)
0717: .add(
0718: modelProcessorDialogLayout
0719: .createParallelGroup(
0720: org.jdesktop.layout.GroupLayout.BASELINE)
0721: .add(
0722: procArtProjectPathTF,
0723: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0724: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0725: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0726: .add(
0727: jLabel13))
0728: .addPreferredGap(
0729: org.jdesktop.layout.LayoutStyle.RELATED)
0730: .add(
0731: procBaseURLTF,
0732: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0733: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0734: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
0735: .add(29, 29, 29)
0736: .add(procOverwriteTextureCB)
0737: .addPreferredGap(
0738: org.jdesktop.layout.LayoutStyle.RELATED)
0739: .add(
0740: modelProcessorDialogLayout
0741: .createParallelGroup(
0742: org.jdesktop.layout.GroupLayout.BASELINE)
0743: .add(jLabel14)
0744: .add(
0745: procTextureNameTF,
0746: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0747: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0748: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0749: .addPreferredGap(
0750: org.jdesktop.layout.LayoutStyle.RELATED,
0751: 113, Short.MAX_VALUE)
0752: .add(exportB).addContainerGap()));
0753:
0754: }// </editor-fold>//GEN-END:initComponents
0755:
0756: private void exportBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBActionPerformed
0757: String artProjectPath = procArtProjectPathTF.getText();
0758: final String baseURL = procBaseURLTF.getText();
0759: final String modelname = procModelnameTF.getText();
0760: final String defaultTextureName = procTextureNameTF.getText();
0761: final boolean overwriteTextures = procOverwriteTextureCB
0762: .isSelected();
0763:
0764: final String compiledModelDir = procArtProjectPathTF.getText()
0765: + File.separatorChar + "compiled_models"
0766: + File.separatorChar;
0767:
0768: final String texturePrefix = "textures" + File.separatorChar
0769: + modelname;
0770:
0771: File test = new File(artProjectPath);
0772: if (!test.exists()) {
0773: JOptionPane.showMessageDialog(null,
0774: "lg3d-wonderland-art project not found",
0775: "Bad Path", JOptionPane.ERROR_MESSAGE);
0776: return;
0777: }
0778:
0779: Thread doWork = new Thread() {
0780: public void run() {
0781: j3dflyContext.getLocale(0).setLive(false);
0782: exportImages(overwriteTextures, compiledModelDir
0783: + texturePrefix, defaultTextureName);
0784: changeBaseUrl(baseURL, texturePrefix);
0785:
0786: File file = new File(compiledModelDir
0787: + File.separatorChar + "models"
0788: + File.separatorChar + modelname + ".j3s");
0789: File fileGZ = new File(compiledModelDir
0790: + File.separatorChar + "models"
0791: + File.separatorChar + modelname + ".j3s.gz");
0792: if (file.exists() || fileGZ.exists()) {
0793: int answer = JOptionPane.showConfirmDialog(null,
0794: "File exists, replace ?\n\n"
0795: + file.getAbsolutePath());
0796: if (answer == JOptionPane.NO_OPTION
0797: || answer == JOptionPane.CANCEL_OPTION) {
0798: procModelnameTF.requestFocus();
0799: procModelnameTF.selectAll();
0800: return;
0801: }
0802: }
0803: j3dflyContext.getJ3dFly().getController()
0804: .saveSceneGraphAsStream(file);
0805:
0806: // Compress the file
0807: try {
0808: GZIPOutputStream out = new GZIPOutputStream(
0809: new BufferedOutputStream(
0810: new FileOutputStream(fileGZ)));
0811: InputStream in = new BufferedInputStream(
0812: new FileInputStream(file));
0813:
0814: byte[] buf = new byte[1024 * 1024];
0815: int size;
0816: size = in.read(buf);
0817: while (size != -1) {
0818: out.write(buf, 0, size);
0819: size = in.read(buf);
0820: }
0821: out.close();
0822: in.close();
0823:
0824: file.delete();
0825: } catch (FileNotFoundException ex) {
0826: ex.printStackTrace();
0827: } catch (IOException ex) {
0828: ex.printStackTrace();
0829: }
0830:
0831: modelProcessorDialog.setVisible(false);
0832: j3dflyContext.getLocale(0).setLive(true);
0833: }
0834: };
0835: doWork.start();
0836:
0837: }//GEN-LAST:event_exportBActionPerformed
0838:
0839: private void exportModelMIActionPerformed(
0840: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportModelMIActionPerformed
0841: modelProcessorDialog.pack();
0842: String name = j3dflyContext.getJ3dFly().getController()
0843: .getCurrentSceneName();
0844: procModelnameTF.setText(name
0845: .substring(0, name.lastIndexOf('.')));
0846: modelProcessorDialog.setVisible(true);
0847: }//GEN-LAST:event_exportModelMIActionPerformed
0848:
0849: private void listPlacableLocationsMIActionPerformed(
0850: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listPlacableLocationsMIActionPerformed
0851: // TODO add your handling code here:
0852: j3dflyContext.getLocale(0).setLive(false);
0853: BranchGroup[] groups = j3dflyContext.getLocale(0)
0854: .getBranchGraphs();
0855: try {
0856: final URL url = new URL(urlTF.getText());
0857: final String namePrefix = namePrefixTF.getText();
0858: for (BranchGroup bg : groups) {
0859: TreeScan.findNode(bg, TransformGroup.class,
0860: new ProcessNodeInterface() {
0861: public boolean processNode(
0862: javax.media.j3d.Node node) {
0863: System.out.println(".");
0864: if (node.getName() != null) {
0865: Transform3D vwt3d = new Transform3D();
0866: node.getLocalToVworld(vwt3d);
0867: Transform3D t3d = new Transform3D();
0868: ((TransformGroup) node)
0869: .getTransform(t3d);
0870: t3d.mul(vwt3d);
0871: System.out.println("Node "
0872: + node.getName()
0873: + " location " + t3d);
0874: }
0875: return false;
0876: }
0877: }, false, true);
0878: }
0879: } catch (MalformedURLException mue) {
0880: JOptionPane.showMessageDialog(null, "Malformed URL "
0881: + mue.getMessage());
0882: }
0883: j3dflyContext.getLocale(0).setLive(true);
0884: baseUrlDialog.setVisible(false);
0885: }//GEN-LAST:event_listPlacableLocationsMIActionPerformed
0886:
0887: private void graphNameBrowseBActionPerformed(
0888: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphNameBrowseBActionPerformed
0889: File currentDir = new File(graphInstanceBaseUrlTF.getText());
0890:
0891: JFileChooser chooser = new JFileChooser(currentDir);
0892: chooser
0893: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
0894: FileFilter filter = new FileFilter() {
0895: @Override
0896: public boolean accept(File file) {
0897: return file.isDirectory()
0898: || file.getName().endsWith("j3s");
0899: }
0900:
0901: @Override
0902: public String getDescription() {
0903: return "Wonderland Models";
0904: }
0905: };
0906:
0907: chooser.setFileFilter(filter);
0908: int state = chooser.showOpenDialog(null);
0909: if (state == JFileChooser.APPROVE_OPTION) {
0910: try {
0911: String tmp = chooser.getSelectedFile()
0912: .getCanonicalPath();
0913: tmp
0914: .substring(graphInstanceBaseUrlTF.getText()
0915: .length() + 1);
0916: graphNameTF.setText(tmp);
0917: } catch (IOException ioe) {
0918: ioe.printStackTrace();
0919: }
0920: }
0921: }//GEN-LAST:event_graphNameBrowseBActionPerformed
0922:
0923: private void graphInstanceBrowseBActionPerformed(
0924: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphInstanceBrowseBActionPerformed
0925: File currentDir = new File("." + File.separatorChar);
0926:
0927: JFileChooser chooser = new JFileChooser(currentDir);
0928: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0929: int state = chooser.showDialog(null, "BaseURL");
0930: if (state == JFileChooser.APPROVE_OPTION) {
0931: try {
0932: graphInstanceBaseUrlTF.setText(chooser
0933: .getSelectedFile().getCanonicalPath());
0934: graphNameBrowseB.setEnabled(true);
0935: } catch (IOException ioe) {
0936: ioe.printStackTrace();
0937: }
0938: }
0939: }//GEN-LAST:event_graphInstanceBrowseBActionPerformed
0940:
0941: private void graphInstanceApplyBActionPerformed(
0942: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphInstanceApplyBActionPerformed
0943: // boolean added = false;
0944: // try {
0945: // URL url = new File(graphInstanceBaseUrlTF.getText()).toURI().toURL();
0946: // System.out.println("CREATING BG URL");
0947: // BranchGroupURL bg = new BranchGroupURL(url, graphNameTF.getText());
0948: // BranchGroup[] groups = j3dflyContext.getLocale(0).getBranchGraphs();
0949: // j3dflyContext.getLocale(0).setLive(false);
0950: // for(BranchGroup g : groups) {
0951: // System.out.println("Locale child "+g);
0952: // if (!(g instanceof ViewingPlatform)) {
0953: // g.addChild(bg);
0954: // added = true;
0955: // break;
0956: // }
0957: // }
0958: // if (!added) {
0959: // System.out.println("Creating new root");
0960: // BranchGroup root = new BranchGroup();
0961: // root.addChild(bg);
0962: // j3dflyContext.getJ3dFly().getController().addBranchGraph(root);
0963: // }
0964: //
0965: // j3dflyContext.getLocale(0).setLive(true);
0966: // graphInstanceDialog.setVisible(false);
0967: // } catch(MalformedURLException ex) {
0968: // JOptionPane.showMessageDialog(null, "Malformed URL "+graphInstanceBaseUrlTF.getText());
0969: // } catch(Exception ex) {
0970: // ex.printStackTrace();
0971: // }
0972: }//GEN-LAST:event_graphInstanceApplyBActionPerformed
0973:
0974: private void addGraphInstanceMIActionPerformed(
0975: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGraphInstanceMIActionPerformed
0976: graphInstanceDialog.pack();
0977: graphInstanceDialog.setVisible(true);
0978: }//GEN-LAST:event_addGraphInstanceMIActionPerformed
0979:
0980: private void exportImagesBActionPerformed(
0981: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportImagesBActionPerformed
0982: Thread doWork = new Thread() {
0983: public void run() {
0984: j3dflyContext.getLocale(0).setLive(false);
0985: exportImages(false, directoryTF.getText(), imageNameTF
0986: .getText());
0987: j3dflyContext.getLocale(0).setLive(true);
0988: }
0989: };
0990: doWork.start();
0991: imageExportDialog.setVisible(false);
0992: // throw new RuntimeException("Not Implemented");
0993: }
0994:
0995: private void exportImages(final boolean overwriteExisting,
0996: final String textureDir, final String defaultFilename) {
0997: final ArrayList<ImageComponent2D> completed = new ArrayList();
0998: BranchGroup[] groups = j3dflyContext.getLocale(0)
0999: .getBranchGraphs();
1000:
1001: File dir = new File(textureDir);
1002: if (!dir.exists())
1003: dir.mkdirs();
1004: // System.out.println("Exporting images to dir "+textureDir);
1005:
1006: for (BranchGroup bg : groups) {
1007: TreeScan.findNode(bg, Shape3D.class,
1008: new ProcessNodeInterface() {
1009: public boolean processNode(
1010: javax.media.j3d.Node node) {
1011:
1012: Appearance app = ((Shape3D) node)
1013: .getAppearance();
1014: if (app == null)
1015: return false;
1016: Texture tex = app.getTexture();
1017: if (tex == null)
1018: return false;
1019: ImageComponent[] ics = tex.getImages();
1020: org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL[] newICS = new org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL[ics.length];
1021: String id = getNameID();
1022: for (int i = 0; i < ics.length; i++) {
1023: boolean byRef = true;
1024: boolean yUp = true;
1025:
1026: if (ics[i] instanceof ImageComponent2DURL) {
1027: ImageComponent2DURL icURL = (ImageComponent2DURL) ics[i];
1028: if (!completed.contains(icURL)) {
1029: File file = new File(textureDir
1030: + File.separatorChar
1031: + icURL.getImageName());
1032: if (!file.exists()) {
1033: System.out
1034: .println("Please copy image "
1035: + icURL
1036: .getImageName()
1037: + " to this directory "
1038: + textureDir);
1039: }
1040: completed.add(icURL);
1041: }
1042: newICS[i] = icURL;
1043: } else if (ics[i] instanceof ImageComponent2D) {
1044: ImageComponent2D ic = (ImageComponent2D) ics[i];
1045: System.out.println("Processing IC "
1046: + ic.getName() + " " + ic);
1047: if (completed.contains(ic)
1048: || isDuplicateImage(
1049: completed, ic
1050: .getImage())) {
1051: newICS[i] = (org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL) ic
1052: .getUserData();
1053: } else if (!(ic instanceof org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL)) {
1054: BufferedImage image = ic
1055: .getImage();
1056: if (!ic.isYUp()) {
1057: BufferedImage invertedImage = JAI
1058: .create(
1059: "transpose",
1060: image,
1061: TransposeDescriptor.FLIP_VERTICAL)
1062: .getAsBufferedImage();
1063: image = invertedImage;
1064: ic.set(image);
1065: }
1066:
1067: String format = chooseImageFormat(image);
1068: String filename = defaultFilename
1069: + id
1070: + "-"
1071: + image.getWidth()
1072: + "x"
1073: + image.getHeight()
1074: + "." + format;
1075: System.out
1076: .println("Saving image "
1077: + filename);
1078: File file = new File(textureDir
1079: + File.separatorChar
1080: + filename);
1081: try {
1082: if (!file.exists()
1083: || overwriteExisting) {
1084: ImageIO.write(image,
1085: format, file);
1086: }
1087: ImageComponent2D icByRef = new ImageComponent2D(
1088: ic.getFormat(),
1089: ic.getImage(),
1090: true, true);
1091: newICS[i] = new org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL(
1092: icByRef,
1093: new java.net.URL(
1094: "file:///export/home/paulby/local-code/java.net/j3dfly/textures"),
1095: filename);
1096: } catch (Exception e) {
1097: e.printStackTrace();
1098: }
1099: ic.setName(filename);
1100: ic.setUserData(newICS[i]);
1101: completed.add(ic);
1102: } else
1103: System.out
1104: .println("Unhandled case "
1105: + ic.getClass());
1106: }
1107: }
1108:
1109: tex.setImages(newICS);
1110: for (ImageComponent2D tmp : newICS) {
1111: if (tmp == null)
1112: System.out
1113: .println("***** NULL IMAGECOMPONENT");
1114: else if (tmp.getImage() == null)
1115: System.out
1116: .println("******* NULL IMAGE");
1117: }
1118:
1119: return true;
1120: }
1121: }, false, true);
1122: }
1123:
1124: }//GEN-LAST:event_exportImagesBActionPerformed
1125:
1126: private void directoryTFActionPerformed(
1127: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_directoryTFActionPerformed
1128: // TODO add your handling code here:
1129: }//GEN-LAST:event_directoryTFActionPerformed
1130:
1131: private void directoryBrowseBActionPerformed(
1132: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_directoryBrowseBActionPerformed
1133: // TODO add your handling code here:
1134:
1135: File currentDir = new File("." + File.separatorChar);
1136:
1137: JFileChooser chooser = new JFileChooser(currentDir);
1138: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1139: int state = chooser.showDialog(imageExportDialog, "Export Dir");
1140: if (state == JFileChooser.APPROVE_OPTION) {
1141: try {
1142: directoryTF.setText(chooser.getSelectedFile()
1143: .getCanonicalPath());
1144: } catch (IOException ioe) {
1145: ioe.printStackTrace();
1146: }
1147: }
1148: }//GEN-LAST:event_directoryBrowseBActionPerformed
1149:
1150: private void baseUrlApplyBActionPerformed(
1151: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_baseUrlApplyBActionPerformed
1152: j3dflyContext.getLocale(0).setLive(false);
1153: changeBaseUrl(urlTF.getText(), namePrefixTF.getText());
1154: j3dflyContext.getLocale(0).setLive(true);
1155: baseUrlDialog.setVisible(false);
1156: }
1157:
1158: private void changeBaseUrl(final String baseURL,
1159: final String namePrefix) {
1160: // System.out.println("Changing baseURL "+baseURL+" "+namePrefix);
1161: BranchGroup[] groups = j3dflyContext.getLocale(0)
1162: .getBranchGraphs();
1163: try {
1164: final URL url = new URL(baseURL);
1165: for (BranchGroup bg : groups) {
1166: TreeScan.findNode(bg, Shape3D.class,
1167: new ProcessNodeInterface() {
1168: public boolean processNode(
1169: javax.media.j3d.Node node) {
1170: Appearance app = ((Shape3D) node)
1171: .getAppearance();
1172: if (app == null)
1173: return false;
1174: Texture tex = app.getTexture();
1175: if (tex == null)
1176: return false;
1177: ImageComponent[] ics = tex.getImages();
1178: for (ImageComponent ic : ics) {
1179: if (ic instanceof org.jdesktop.j3d.utils.scenegraph.ImageComponent2DURL) {
1180: ImageComponent2DURL icURL = (ImageComponent2DURL) ic;
1181: icURL.setBaseURL(url);
1182: String filename = icURL
1183: .getImageName();
1184: if (filename.lastIndexOf('/') != -1)
1185: filename
1186: .substring(filename
1187: .lastIndexOf('/') + 1);
1188: if (!filename
1189: .startsWith(namePrefix))
1190: icURL
1191: .setImageName(namePrefix
1192: + "/"
1193: + filename);
1194: } else
1195: System.out
1196: .println("WARNING : non URL ImageComponent2D "
1197: + ic.getName());
1198: }
1199: return false;
1200: }
1201: }, false, true);
1202: }
1203: } catch (MalformedURLException mue) {
1204: JOptionPane.showMessageDialog(null, "Malformed URL "
1205: + mue.getMessage());
1206: }
1207:
1208: }//GEN-LAST:event_baseUrlApplyBActionPerformed
1209:
1210: private void changeBaseURLMIActionPerformed(
1211: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeBaseURLMIActionPerformed
1212: // TODO add your handling code here:
1213: baseUrlDialog.pack();
1214: baseUrlDialog.setVisible(true);
1215: }//GEN-LAST:event_changeBaseURLMIActionPerformed
1216:
1217: private void browseBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseBActionPerformed
1218: // TODO add your handling code here:
1219: JFileChooser chooser = new JFileChooser();
1220: int state = chooser.showSaveDialog(urlImageDialog);
1221: if (state == JFileChooser.APPROVE_OPTION) {
1222: try {
1223: imageFilenameTF.setText(chooser.getSelectedFile()
1224: .getCanonicalPath());
1225: } catch (IOException ioe) {
1226: ioe.printStackTrace();
1227: }
1228: }
1229: }//GEN-LAST:event_browseBActionPerformed
1230:
1231: private void applyBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyBActionPerformed
1232: // TODO add your handling code here:
1233: urlImageDialog.setVisible(false);
1234: ((ImagePanel) imagePreviewPanel).saveImage(imageFilenameTF
1235: .getText());
1236: }//GEN-LAST:event_applyBActionPerformed
1237:
1238: String getNameID() {
1239: return Integer.toString(nameID++);
1240: }
1241:
1242: private void urlImageComponentMIActionPerformed(
1243: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_urlImageComponentMIActionPerformed
1244: // TODO add your handling code here:
1245: imageExportDialog.pack();
1246: imageExportDialog.setVisible(true);
1247: }//GEN-LAST:event_urlImageComponentMIActionPerformed
1248:
1249: /**
1250: * Check for duplicate images
1251: */
1252: private boolean isDuplicateImage(
1253: ArrayList<ImageComponent2D> icList, BufferedImage newImage) {
1254: for (ImageComponent2D ic : icList) {
1255: if (ic.getImage().equals(newImage)) {
1256: System.out.println("Duplicate Image found");
1257: return true;
1258: }
1259: }
1260: return false;
1261: }
1262:
1263: private String bufferedImageTypeToString(int type) {
1264: String[] names = new String[] { "TYPE_CUSTOM", "TYPE_INT_RGB",
1265: "TYPE_INT_ARGB", "TYPE_INT_ARGB_PRE", "TYPE_INT_BGR",
1266: "TYPE_3BYTE_BGR", "TYPE_4BYTE_ABGR",
1267: "TYPE_4BYTE_ABGR_PRE", "TYPE_USHORT_565_RGB",
1268: "TYPE_USHORT_555_RGB", "TYPE_BYTE_GRAY",
1269: "TYPE_USHORT_GRAY", "TYPE_BYTE_BINARY",
1270: "TYPE_BYTE_INDEXED" };
1271:
1272: if (type < 0 || type >= names.length)
1273: return "Out Of Range";
1274:
1275: return names[type];
1276: }
1277:
1278: /**
1279: * Returns the most appropriate file format for this image
1280: *
1281: * @return jpg, gif
1282: */
1283: private String chooseImageFormat(BufferedImage image) {
1284: String ret = null;
1285:
1286: switch (image.getType()) {
1287: case BufferedImage.TYPE_4BYTE_ABGR:
1288: case BufferedImage.TYPE_4BYTE_ABGR_PRE:
1289: case BufferedImage.TYPE_INT_ARGB:
1290: case BufferedImage.TYPE_INT_ARGB_PRE:
1291: // ret = "gif";
1292: ret = "png";
1293: break;
1294: case BufferedImage.TYPE_3BYTE_BGR:
1295: case BufferedImage.TYPE_BYTE_BINARY:
1296: case BufferedImage.TYPE_BYTE_GRAY:
1297: case BufferedImage.TYPE_BYTE_INDEXED:
1298: case BufferedImage.TYPE_CUSTOM:
1299: case BufferedImage.TYPE_INT_BGR:
1300: case BufferedImage.TYPE_INT_RGB:
1301: case BufferedImage.TYPE_USHORT_555_RGB:
1302: case BufferedImage.TYPE_USHORT_565_RGB:
1303: case BufferedImage.TYPE_USHORT_GRAY:
1304: // ret = "jpg";
1305: ret = "png";
1306: break;
1307: }
1308:
1309: return ret;
1310: }
1311:
1312: /**
1313: * Returns the control panel for this plugin, or null if there
1314: * is no control panel
1315: */
1316: public javax.swing.JPanel getControlPanel() {
1317:
1318: // Uncomment this code and change XXXX to instantiate the panel for
1319: // this Plugin if it has one, otherwise return null
1320:
1321: //if (panelReference==null || panelReference.get()==null )
1322: // panelReference = new java.lang.ref.SoftReference( new XXXXX() );
1323:
1324: //return (javax.swing.JPanel)panelReference.get();
1325:
1326: return null;
1327: }
1328:
1329: /**
1330: * Install the plugin and add it's menu item to the menu
1331: */
1332: public void installPlugin(PluginPreference pluginPref,
1333: J3dFlyContext j3dflyContext) {
1334: super .installPlugin(pluginPref, j3dflyContext);
1335: initComponents();
1336:
1337: menuBar.removeAll();
1338: menuBar = null;
1339:
1340: // By default the menu item for this plugin will be added to
1341: // the plugins Menu in the main menu bar for the application.
1342: // You must set the super.menu object to point to the menu item
1343: // you want displayed.
1344:
1345: // Set the menu item for this plugin to be another menu
1346: menu = pluginMenu;
1347: if (pluginPref.isInstallInMenu())
1348: getMenu("Plugins").add(menu);
1349: }
1350:
1351: /**
1352: * Uninstall this plugin
1353: */
1354: public void uninstallPlugin() {
1355: super .uninstallPlugin();
1356: if (pluginPref.isInstallInMenu())
1357: getMenu("Plugins").remove(menu);
1358: menu = null;
1359: }
1360:
1361: /**
1362: * Returns the class of the plugin preference.
1363: *
1364: * Plugins that require more preference information should provide a
1365: * subclass of PluginPrefernece that contains all the extra preference
1366: * data. This class must be Serializable.
1367: */
1368: public Class getPluginPreferenceClass() {
1369: return WonderlandPluginPreference.class;
1370: }
1371:
1372: public static class WonderlandPluginPreference extends
1373: PluginPreference {
1374: public WonderlandPluginPreference() {
1375: super ();
1376: }
1377:
1378: public WonderlandPluginPreference(boolean enabled,
1379: boolean installed) {
1380: super (enabled, installed);
1381: }
1382:
1383: public J3dFlyPlugin instantiatePlugin() {
1384: plugin = new WonderlandPlugin();
1385: return plugin;
1386: }
1387:
1388: /**
1389: * Return a description of this plugin
1390: */
1391: public String getDescription() {
1392: return "Tools for Project Wonderland";
1393: }
1394:
1395: /**
1396: * Return the name of the Plugin for this prefernece.
1397: * This is the name that will appear in the list of plugins
1398: */
1399: public String getName() {
1400: return this .getClass().getName();
1401: }
1402:
1403: }
1404:
1405: class ImagePanel extends JPanel {
1406: private BufferedImage image = null;
1407: private Semaphore sem = new Semaphore(1);
1408:
1409: public void paint(Graphics g) {
1410: if (image != null) {
1411: g.drawImage(image, 0, 0, null);
1412: }
1413: }
1414:
1415: public void setImage(BufferedImage image) {
1416: this .image = image;
1417: try {
1418: sem.acquire();
1419: } catch (InterruptedException ex) {
1420: throw new RuntimeException(ex.getMessage());
1421: }
1422: invalidate();
1423: }
1424:
1425: public Dimension getPreferredSize() {
1426: if (image != null)
1427: return new Dimension(image.getWidth(), image
1428: .getHeight());
1429: else
1430: return new Dimension(256, 256);
1431: }
1432:
1433: public void saveImage(String filename) {
1434: File file = new File(filename);
1435: try {
1436: ImageIO.write(image, "png", file);
1437: } catch (Exception e) {
1438: e.printStackTrace();
1439: }
1440: sem.release();
1441: }
1442: }
1443:
1444: // Variables declaration - do not modify//GEN-BEGIN:variables
1445: private javax.swing.JMenuItem addGraphInstanceMI;
1446: private javax.swing.JButton applyB;
1447: private javax.swing.JButton baseUrlApplyB;
1448: private javax.swing.JDialog baseUrlDialog;
1449: private javax.swing.JButton browseB;
1450: private javax.swing.JMenuItem changeBaseURLMI;
1451: private javax.swing.JButton directoryBrowseB;
1452: private javax.swing.JTextField directoryTF;
1453: private javax.swing.JButton exportB;
1454: private javax.swing.JButton exportImagesB;
1455: private javax.swing.JMenuItem exportModelMI;
1456: private javax.swing.JButton graphInstanceApplyB;
1457: private javax.swing.JTextField graphInstanceBaseUrlTF;
1458: private javax.swing.JButton graphInstanceBrowseB;
1459: private javax.swing.JDialog graphInstanceDialog;
1460: private javax.swing.JButton graphNameBrowseB;
1461: private javax.swing.JTextField graphNameTF;
1462: private javax.swing.JDialog imageExportDialog;
1463: private javax.swing.JPanel imageExportPanel;
1464: private javax.swing.JTextField imageFilenameTF;
1465: private javax.swing.JTextField imageNameTF;
1466: private javax.swing.JPanel imagePreviewPanel;
1467: private javax.swing.JTextField imageSizeTF;
1468: private javax.swing.JLabel jLabel1;
1469: private javax.swing.JLabel jLabel10;
1470: private javax.swing.JLabel jLabel11;
1471: private javax.swing.JLabel jLabel12;
1472: private javax.swing.JLabel jLabel13;
1473: private javax.swing.JLabel jLabel14;
1474: private javax.swing.JLabel jLabel15;
1475: private javax.swing.JLabel jLabel2;
1476: private javax.swing.JLabel jLabel3;
1477: private javax.swing.JLabel jLabel4;
1478: private javax.swing.JLabel jLabel5;
1479: private javax.swing.JLabel jLabel6;
1480: private javax.swing.JLabel jLabel7;
1481: private javax.swing.JLabel jLabel8;
1482: private javax.swing.JLabel jLabel9;
1483: private javax.swing.JPanel jPanel1;
1484: private javax.swing.JPanel jPanel2;
1485: private javax.swing.JPanel jPanel3;
1486: private javax.swing.JPanel jPanel4;
1487: private javax.swing.JPanel jPanel5;
1488: private javax.swing.JScrollPane jScrollPane1;
1489: private javax.swing.JMenuItem listPlacableLocationsMI;
1490: private javax.swing.JMenuBar menuBar;
1491: private javax.swing.JTextField mipmapLevelsTF;
1492: private javax.swing.JDialog modelProcessorDialog;
1493: private javax.swing.JTextField namePrefixTF;
1494: private javax.swing.JMenu pluginMenu;
1495: private javax.swing.JTextField procArtProjectPathTF;
1496: private javax.swing.JTextField procBaseURLTF;
1497: private javax.swing.JTextField procModelnameTF;
1498: private javax.swing.JCheckBox procOverwriteTextureCB;
1499: private javax.swing.JTextField procTextureNameTF;
1500: private javax.swing.JTextField resolutionTF;
1501: private javax.swing.JMenuItem urlImageComponentMI;
1502: private javax.swing.JDialog urlImageDialog;
1503: private javax.swing.JTextField urlTF;
1504: // End of variables declaration//GEN-END:variables
1505:
1506: }
|