SDK :
- Skybox wizard now supports dds file format - Terrain editor now supports loading of dds files - Optimized buttons creation in the terrain editor's texture list git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8017 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
		
							parent
							
								
									2a7d6582ae
								
							
						
					
					
						commit
						fb6abf7e84
					
				| @ -42,6 +42,7 @@ import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; | ||||
| import com.jme3.gde.core.sceneexplorer.nodes.JmeTerrainQuad; | ||||
| import com.jme3.gde.core.sceneexplorer.nodes.NodeUtility; | ||||
| import com.jme3.gde.core.properties.TexturePropertyEditor; | ||||
| import com.jme3.gde.core.properties.preview.DDSPreview; | ||||
| import com.jme3.gde.core.util.DataObjectSaveNode; | ||||
| import com.jme3.gde.core.util.ToggleButtonGroup; | ||||
| import com.jme3.gde.terraineditor.sky.SkyboxWizardAction; | ||||
| @ -66,6 +67,8 @@ import java.beans.PropertyChangeEvent; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.logging.Logger; | ||||
| import javax.swing.AbstractCellEditor; | ||||
| import javax.swing.DefaultListSelectionModel; | ||||
| @ -128,8 +131,9 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     private JmeSpatial selectedSpat; | ||||
|     private TerrainNodeListener terrainDeletedNodeListener; | ||||
|     private boolean availableNormalTextures; | ||||
| 
 | ||||
|     private HelpCtx ctx = new HelpCtx("sdk.terrain_editor"); | ||||
|     private DDSPreview ddsPreview; | ||||
|     private Map<String, JButton> buttons = new HashMap<String, JButton>(); | ||||
| 
 | ||||
|     public TerrainEditorTopComponent() { | ||||
|         initComponents(); | ||||
| @ -140,7 +144,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         result = Utilities.actionsGlobalContext().lookupResult(JmeSpatial.class); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     class EntropyCalcProgressMonitor implements ProgressMonitor { | ||||
| 
 | ||||
|         private ProgressHandle progressHandle; | ||||
| @ -178,7 +181,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| //                } | ||||
| //            }); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void setHintText(String text) { | ||||
| @ -186,12 +188,12 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     } | ||||
| 
 | ||||
|     private void setHintText(TerrainTool tool) { | ||||
|         if (tool != null) | ||||
|         if (tool != null) { | ||||
|             hintTextArea.setText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, tool.getToolHintTextKey())); | ||||
|         else | ||||
|         } else { | ||||
|             hintTextArea.setText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.toolHint.default")); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** This method is called from within the constructor to | ||||
|      * initialize the form. | ||||
| @ -619,11 +621,12 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     }//GEN-LAST:event_paintButtonActionPerformed | ||||
| 
 | ||||
|     private void addTextureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTextureButtonActionPerformed | ||||
|         if (editorController == null || editorController.getTerrain(null) == null) | ||||
|         if (editorController == null || editorController.getTerrain(null) == null) { | ||||
|             return; | ||||
|         } | ||||
|         int index = getTableModel().getRowCount(); // get the last row | ||||
|         addNewTextureLayer(index); | ||||
|         editorController.enableTextureButtons(); | ||||
|         //  editorController.enableTextureButtons(); | ||||
|     }//GEN-LAST:event_addTextureButtonActionPerformed | ||||
| 
 | ||||
|     protected void enableAddTextureButton(boolean enabled) { | ||||
| @ -643,12 +646,16 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     } | ||||
| 
 | ||||
|     private void removeTextureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTextureButtonActionPerformed | ||||
|         if (editorController == null || editorController.getTerrain(null) == null) | ||||
|         if (editorController == null || editorController.getTerrain(null) == null) { | ||||
|             return; | ||||
|         if (getTableModel().getRowCount() == 0) | ||||
|         } | ||||
|         if (getTableModel().getRowCount() == 0) { | ||||
|             return; | ||||
|         } | ||||
|         int index = getTableModel().getRowCount() - 1; // get the last row | ||||
|         removeTextureLayer(index); | ||||
|         buttons.remove(index + "-" + 1); | ||||
|         buttons.remove(index + "-" + 2); | ||||
|         editorController.enableTextureButtons(); | ||||
|     }//GEN-LAST:event_removeTextureButtonActionPerformed | ||||
| 
 | ||||
| @ -666,8 +673,9 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     private void triPlanarCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_triPlanarCheckBoxActionPerformed | ||||
|         editorController.setTriPlanarEnabled(triPlanarCheckBox.isSelected()); | ||||
|         ((TextureTableModel) textureTable.getModel()).updateScales(); | ||||
|         if ( triPlanarCheckBox.isSelected()) | ||||
|         if (triPlanarCheckBox.isSelected()) { | ||||
|             setHintText("Make sure your scale is a power of 2, (1/2^n), when in tri-planar mode"); | ||||
|         } | ||||
|     }//GEN-LAST:event_triPlanarCheckBoxActionPerformed | ||||
| 
 | ||||
|     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed | ||||
| @ -686,13 +694,15 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     }//GEN-LAST:event_levelTerrainButtonActionPerformed | ||||
| 
 | ||||
|     private void radiusSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_radiusSliderStateChanged | ||||
|         if (toolController != null) | ||||
|         if (toolController != null) { | ||||
|             toolController.setHeightToolRadius((float) radiusSlider.getValue() / (float) radiusSlider.getMaximum()); | ||||
|         } | ||||
|     }//GEN-LAST:event_radiusSliderStateChanged | ||||
| 
 | ||||
|     private void heightSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_heightSliderStateChanged | ||||
|         if (toolController != null) | ||||
|         if (toolController != null) { | ||||
|             toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum()); | ||||
|         } | ||||
|     }//GEN-LAST:event_heightSliderStateChanged | ||||
| 
 | ||||
|     private void smoothTerrainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smoothTerrainButtonActionPerformed | ||||
| @ -705,7 +715,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|             setHintText((TerrainTool) null); | ||||
|         } | ||||
|     }//GEN-LAST:event_smoothTerrainButtonActionPerformed | ||||
| 
 | ||||
|     // Variables declaration - do not modify//GEN-BEGIN:variables | ||||
|     private javax.swing.JButton addTextureButton; | ||||
|     private javax.swing.JButton createTerrainButton; | ||||
| @ -741,6 +750,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     private javax.swing.JPanel toolSettingsPanel; | ||||
|     private javax.swing.JCheckBox triPlanarCheckBox; | ||||
|     // End of variables declaration//GEN-END:variables | ||||
| 
 | ||||
|     /** | ||||
|      * Gets default instance. Do not use directly: reserved for *.settings files only, | ||||
|      * i.e. deserialization routines; otherwise you could get a non-deserialized instance. | ||||
| @ -753,7 +763,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         return instance; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public void addSpatial(final String name) { | ||||
|         if (selectedSpat == null) { | ||||
| 
 | ||||
| @ -768,21 +777,21 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         final Spatial node = selectedSpat.getLookup().lookup(Spatial.class); | ||||
|         if (node != null) { | ||||
|             if ("Terrain".equals(name)) { | ||||
|                 if (terrainWizard == null) | ||||
|                 if (terrainWizard == null) { | ||||
|                     terrainWizard = new CreateTerrainWizardAction(this); | ||||
|                 } | ||||
|                 terrainWizard.performAction(); | ||||
|             } else if ("Skybox".equals(name)) { | ||||
|                 if (skyboxWizard == null) | ||||
|                 if (skyboxWizard == null) { | ||||
|                     skyboxWizard = new SkyboxWizardAction(this); | ||||
|                 } | ||||
|                 skyboxWizard.performAction(); | ||||
|             } else if ("Ocean".equals(name)) { | ||||
|                  | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     protected void generateTerrain(final WizardDescriptor wizardDescriptor) { | ||||
|         final Spatial node = selectedSpat.getLookup().lookup(Spatial.class); | ||||
| 
 | ||||
| @ -892,6 +901,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|      * and reinitialize the texture table | ||||
|      */ | ||||
|     private class TerrainNodeListener implements NodeListener { | ||||
| 
 | ||||
|         public void childrenAdded(NodeMemberEvent nme) { | ||||
|         } | ||||
| 
 | ||||
| @ -908,13 +918,11 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|         public void propertyChange(PropertyChangeEvent evt) { | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /* | ||||
|      * | ||||
|      *******************************************************************/ | ||||
| 
 | ||||
|     /** | ||||
|      * Obtain the TerrainEditorTopComponent instance. Never call {@link #getDefault} directly! | ||||
|      */ | ||||
| @ -1070,6 +1078,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|             toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum()); | ||||
| 
 | ||||
|             java.awt.EventQueue.invokeLater(new Runnable() { | ||||
| 
 | ||||
|                 public void run() { | ||||
|                     reinitTextureTable(); // update the UI | ||||
|                     if (editorController.getTerrain(null) != null) { | ||||
| @ -1083,6 +1092,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|     protected synchronized void addDataObject(final DataObjectSaveNode dataObject) { | ||||
|         java.awt.EventQueue.invokeLater(new Runnable() { | ||||
| 
 | ||||
|             public void run() { | ||||
|                 addSaveNode(dataObject); | ||||
|             } | ||||
| @ -1099,9 +1109,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|             public void run() { | ||||
|                 if (jmeNode != null) { | ||||
| 
 | ||||
|                 } else { | ||||
| 
 | ||||
|                 } | ||||
| 
 | ||||
|                 if (!active) { | ||||
| @ -1135,8 +1143,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     public void previewRequested(PreviewRequest request) { | ||||
|     } | ||||
| 
 | ||||
|      | ||||
| 
 | ||||
|     private void cleanupControllers() { | ||||
|         if (camController != null) { | ||||
|             camController.disable(); | ||||
| @ -1167,18 +1173,21 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         textureTable.getColumnModel().getColumn(2).setCellEditor(rendererNormal); | ||||
| 
 | ||||
|         // empty out the table | ||||
|         for (int i=0; i<textureTable.getModel().getRowCount(); i++) | ||||
|         for (int i = 0; i < textureTable.getModel().getRowCount(); i++) { | ||||
|             ((TextureTableModel) textureTable.getModel()).removeRow(i); | ||||
|         } | ||||
| 
 | ||||
|         if (editorController.getTerrain(null) == null) | ||||
|         if (editorController.getTerrain(null) == null) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         getTableModel().initModel(); | ||||
| 
 | ||||
|         if (textureTable.getRowCount() > 0) | ||||
|         if (textureTable.getRowCount() > 0) { | ||||
|             toolController.setSelectedTextureIndex(0); // select the first row by default | ||||
|         else | ||||
|         } else { | ||||
|             toolController.setSelectedTextureIndex(-1); | ||||
|         } | ||||
| 
 | ||||
|         editorController.enableTextureButtons(); | ||||
|         triPlanarCheckBox.setSelected(editorController.isTriPlanarEnabled()); | ||||
| @ -1202,15 +1211,16 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|      * @param selectedIndex | ||||
|      */ | ||||
|     private void removeTextureLayer(int selectedIndex) { | ||||
|         if (selectedIndex < 0) | ||||
|         if (selectedIndex < 0) { | ||||
|             return; // abort | ||||
| 
 | ||||
|         } | ||||
|         getTableModel().removeTexture(selectedIndex); | ||||
|     } | ||||
| 
 | ||||
|     private TextureTableModel getTableModel() { | ||||
|         if (textureTable == null) | ||||
|         if (textureTable == null) { | ||||
|             return null; | ||||
|         } | ||||
|         return (TextureTableModel) textureTable.getModel(); | ||||
|     } | ||||
| 
 | ||||
| @ -1228,17 +1238,20 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         public void initModel() { | ||||
| 
 | ||||
|             // empty the table | ||||
|             while (getRowCount() > 0) | ||||
|             while (getRowCount() > 0) { | ||||
|                 removeRow(0); | ||||
|             } | ||||
| 
 | ||||
|             // fill the table with the proper data | ||||
|             for (int i = 0; i < editorController.MAX_TEXTURES; i++) { | ||||
|                 if (!editorController.hasTextureAt(i)) | ||||
|                 if (!editorController.hasTextureAt(i)) { | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                 Float scale = editorController.getTextureScale(i); | ||||
|                 if (scale == null) | ||||
|                 if (scale == null) { | ||||
|                     scale = editorController.DEFAULT_TEXTURE_SCALE; | ||||
|                 } | ||||
|                 addRow(new Object[]{"", i, i, scale}); | ||||
|             } | ||||
|         } | ||||
| @ -1253,13 +1266,15 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         // it seems to keep the selection when we delete the row | ||||
|         @Override | ||||
|         public void setValueAt(Object aValue, int row, int column) { | ||||
|             if (row < 0 || row > getRowCount()-1) | ||||
|             if (row < 0 || row > getRowCount() - 1) { | ||||
|                 return; | ||||
|             } | ||||
|             super.setValueAt(aValue, row, column); | ||||
| 
 | ||||
|             if (column == 3) | ||||
|             if (column == 3) { | ||||
|                 setTextureScale(row, new Float((String) aValue)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected void addNewTexture(int newIndex) { | ||||
|             float scale = editorController.DEFAULT_TEXTURE_SCALE; | ||||
| @ -1304,7 +1319,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|             editorController.removeTextureLayer(index); | ||||
|             editorController.enableTextureButtons(); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -1316,10 +1330,12 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|             super.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | ||||
| 
 | ||||
|             addListSelectionListener(new ListSelectionListener() { | ||||
| 
 | ||||
|                 public void valueChanged(ListSelectionEvent e) { | ||||
|                     if (toolController != null) | ||||
|                     if (toolController != null) { | ||||
|                         toolController.setSelectedTextureIndex(textureTable.getSelectedRow()); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
| @ -1351,49 +1367,80 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|         private JButton getButton(Object value, final int row, final int column) { | ||||
| 
 | ||||
|             JButton button = buttons.get(row + "-" + column); | ||||
|             if (button == null) { | ||||
|                 final JButton lbl = new JButton(); | ||||
|                 buttons.put(row + "-" + column, lbl); | ||||
| 
 | ||||
|                 //TODO check if there is a normal or a texture here at this index | ||||
|             if (value == null) | ||||
|                 if (value == null) { | ||||
|                     value = getTableModel().getValueAt(row, column); | ||||
|                 } | ||||
| 
 | ||||
|                 if (value != null) { | ||||
|                     int index = 0; | ||||
|                     // this is messy, fix it so we know what values are coming in from where: | ||||
|                 if (value instanceof String) | ||||
|                     if (value instanceof String) { | ||||
|                         index = new Float((String) value).intValue(); | ||||
|                 else if (value instanceof Float) | ||||
|                     } else if (value instanceof Float) { | ||||
|                         index = ((Float) value).intValue(); | ||||
|                 else if (value instanceof Integer) | ||||
|                     } else if (value instanceof Integer) { | ||||
|                         index = (Integer) value; | ||||
|                     } | ||||
| 
 | ||||
|                     Texture tex = getTextureFromModel(index); // delegate to sub-class | ||||
| 
 | ||||
|                     //Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture((String)value); | ||||
|                     if (tex != null) { | ||||
|                         String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|                         if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                             if (ddsPreview == null) { | ||||
|                                 ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                             } | ||||
|                             ddsPreview.requestPreview(selected, "", 80, 80, lbl, null); | ||||
| 
 | ||||
|                         } else { | ||||
|                             Icon icon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                             lbl.setIcon(icon); | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                 } | ||||
| 
 | ||||
|                 lbl.addActionListener(new ActionListener() { | ||||
| 
 | ||||
|                     public void actionPerformed(ActionEvent e) { | ||||
| 
 | ||||
|                     if (alreadyChoosing) | ||||
|                         if (alreadyChoosing) { | ||||
|                             return; | ||||
|                         } | ||||
| 
 | ||||
|                         alreadyChoosing = true; | ||||
| 
 | ||||
|                         try { | ||||
|                             Texture selectedTex = getTextureFromModel(row); // delegates to sub class | ||||
|                             if (selectedTex == null && !availableNormalTextures) // bail if we are at our texture limit | ||||
|                             { | ||||
|                                 return; | ||||
|                             } | ||||
|                             TexturePropertyEditor editor = new TexturePropertyEditor(selectedTex); | ||||
|                             Component view = editor.getCustomEditor(); | ||||
|                             view.setVisible(true); | ||||
|                             Texture tex = (Texture) editor.getValue(); | ||||
|                             if (editor.getValue() != null) { | ||||
|                                 String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|                                 if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                                     if (ddsPreview == null) { | ||||
|                                         ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                                     } | ||||
|                                     ddsPreview.requestPreview(selected, "", 80, 80, lbl, null); | ||||
| 
 | ||||
|                                 } else { | ||||
|                                     Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                                     lbl.setIcon(newicon); | ||||
|                                 } | ||||
|                             } else if (supportsNullTexture()) { | ||||
|                                 lbl.setIcon(null); | ||||
|                             } | ||||
| @ -1403,30 +1450,37 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|                         } | ||||
|                     } | ||||
|                 }); | ||||
| 
 | ||||
|                 return lbl; | ||||
|             } | ||||
|             return button; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public class TextureCellRendererEditor extends CellRendererEditor { | ||||
| 
 | ||||
|         @Override | ||||
|         public Object getCellEditorValue() { | ||||
|             int row = textureTable.getSelectedRow(); | ||||
|             if (row < 0) | ||||
|             if (row < 0) { | ||||
|                 return null; | ||||
|             } | ||||
|             return getTableModel().getValueAt(row, 1); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void setTextureInModel(int row, String path) { | ||||
|             if (path != null) | ||||
|             if (path != null) { | ||||
|                 getTableModel().setTexture(row, path); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void setTextureInModel(int row, Texture tex) { | ||||
|             if (tex != null) | ||||
|             if (tex != null) { | ||||
|                 getTableModel().setTexture(row, tex); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected Texture getTextureFromModel(int index) { | ||||
| @ -1437,15 +1491,16 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         protected boolean supportsNullTexture() { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public class NormalCellRendererEditor extends CellRendererEditor { | ||||
| 
 | ||||
|         @Override | ||||
|         public Object getCellEditorValue() { | ||||
|             int row = textureTable.getSelectedRow(); | ||||
|             if (row < 0) | ||||
|             if (row < 0) { | ||||
|                 return null; | ||||
|             } | ||||
|             return getTableModel().getValueAt(row, 2); | ||||
|         } | ||||
| 
 | ||||
| @ -1470,7 +1525,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * A file filter to only show images | ||||
|      */ | ||||
| @ -1478,6 +1532,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|         Utils utils = new Utils(); | ||||
|         //Accept all directories and all gif, jpg, tiff, or png files. | ||||
| 
 | ||||
|         public boolean accept(File f) { | ||||
|             if (f.isDirectory()) { | ||||
|                 return true; | ||||
| @ -1485,12 +1540,13 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
| 
 | ||||
|             String extension = utils.getExtension(f); | ||||
|             if (extension != null) { | ||||
|                 if (extension.equals(utils.tiff) || | ||||
|                     extension.equals(utils.tif) || | ||||
|                     extension.equals(utils.gif) || | ||||
|                     extension.equals(utils.jpeg) || | ||||
|                     extension.equals(utils.jpg) || | ||||
|                     extension.equals(utils.png)) { | ||||
|                 if (extension.equals(utils.tiff) | ||||
|                         || extension.equals(utils.tif) | ||||
|                         || extension.equals(utils.gif) | ||||
|                         || extension.equals(utils.jpeg) | ||||
|                         || extension.equals(utils.jpg) | ||||
|                         || extension.equals(utils.png) | ||||
|                         || extension.equals(utils.dds)) { | ||||
|                     return true; | ||||
|                 } else { | ||||
|                     return false; | ||||
| @ -1509,50 +1565,44 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     /** | ||||
|      * restricts the file chooser to a specified directory tree, such as the assets folder | ||||
|      */ | ||||
|     class DirectoryRestrictedFileSystemView extends FileSystemView | ||||
|     { | ||||
|     class DirectoryRestrictedFileSystemView extends FileSystemView { | ||||
| 
 | ||||
|         private final File[] rootDirectories; | ||||
| 
 | ||||
|         DirectoryRestrictedFileSystemView(File rootDirectory) | ||||
|         { | ||||
|         DirectoryRestrictedFileSystemView(File rootDirectory) { | ||||
|             this.rootDirectories = new File[]{rootDirectory}; | ||||
|         } | ||||
| 
 | ||||
|         DirectoryRestrictedFileSystemView(File[] rootDirectories) | ||||
|         { | ||||
|         DirectoryRestrictedFileSystemView(File[] rootDirectories) { | ||||
|             this.rootDirectories = rootDirectories; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public Boolean isTraversable(File f) { | ||||
|             if (f.getAbsolutePath().indexOf(rootDirectories[0].getAbsolutePath()) >= 0) | ||||
|             if (f.getAbsolutePath().indexOf(rootDirectories[0].getAbsolutePath()) >= 0) { | ||||
|                 return Boolean.valueOf(f.isDirectory()); | ||||
|             else | ||||
|             } else { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public File getDefaultDirectory() | ||||
|         { | ||||
|         public File getDefaultDirectory() { | ||||
|             return rootDirectories[0]; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public File getHomeDirectory() | ||||
|         { | ||||
|         public File getHomeDirectory() { | ||||
|             return rootDirectories[0]; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         public File[] getRoots() | ||||
|         { | ||||
|         public File[] getRoots() { | ||||
|             return rootDirectories; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         @Override | ||||
|         public File createNewFolder(File containingDir) throws IOException | ||||
|         { | ||||
|         public File createNewFolder(File containingDir) throws IOException { | ||||
|             throw new UnsupportedOperationException("Unable to create directory"); | ||||
|         } | ||||
|         /* | ||||
| @ -1575,12 +1625,14 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce | ||||
|     } | ||||
| 
 | ||||
|     public class Utils { | ||||
| 
 | ||||
|         public final String jpeg = "jpeg"; | ||||
|         public final String jpg = "jpg"; | ||||
|         public final String gif = "gif"; | ||||
|         public final String tiff = "tiff"; | ||||
|         public final String tif = "tif"; | ||||
|         public final String png = "png"; | ||||
|         public final String dds = "dds"; | ||||
| 
 | ||||
|         /* | ||||
|          * Get the extension of a file. | ||||
|  | ||||
| @ -31,7 +31,10 @@ | ||||
|  */ | ||||
| package com.jme3.gde.terraineditor.sky; | ||||
| 
 | ||||
| import com.jme3.gde.core.assets.ProjectAssetManager; | ||||
| import com.jme3.gde.core.properties.TexturePropertyEditor; | ||||
| import com.jme3.gde.core.properties.preview.DDSPreview; | ||||
| import com.jme3.gde.core.scene.SceneApplication; | ||||
| import com.jme3.texture.Texture; | ||||
| import java.awt.Component; | ||||
| import javax.swing.Icon; | ||||
| @ -43,6 +46,8 @@ import org.openide.util.ImageUtilities; | ||||
| 
 | ||||
| public final class SkyboxVisualPanel2 extends JPanel { | ||||
| 
 | ||||
|     private DDSPreview ddsPreview; | ||||
| 
 | ||||
|     /** Creates new form SkyboxVisualPanel2 */ | ||||
|     public SkyboxVisualPanel2() { | ||||
|         initComponents(); | ||||
| @ -60,7 +65,6 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|     public JPanel getSingleTexturePanel() { | ||||
|         return singleTexturePanel; | ||||
|     } | ||||
| 
 | ||||
|     TexturePropertyEditor editorNorth = new TexturePropertyEditor(); | ||||
|     TexturePropertyEditor editorSouth = new TexturePropertyEditor(); | ||||
|     TexturePropertyEditor editorEast = new TexturePropertyEditor(); | ||||
| @ -97,7 +101,6 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         return editorWest; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** This method is called from within the constructor to | ||||
|      * initialize the form. | ||||
|      * WARNING: Do NOT modify this code. The content of this method is | ||||
| @ -420,9 +423,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorSouth.getValue() != null) { | ||||
|             Texture tex = (Texture) editorSouth.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, southPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 southPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexSouthLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void multipleTexNorthLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexNorthLoadButtonActionPerformed | ||||
| @ -430,9 +443,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorNorth.getValue() != null) { | ||||
|             Texture tex = (Texture) editorNorth.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, northPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 northPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexNorthLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void multipleTexEastLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexEastLoadButtonActionPerformed | ||||
| @ -440,9 +463,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorEast.getValue() != null) { | ||||
|             Texture tex = (Texture) editorEast.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, eastPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 eastPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexEastLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void multipleTexWestLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexWestLoadButtonActionPerformed | ||||
| @ -450,9 +483,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorWest.getValue() != null) { | ||||
|             Texture tex = (Texture) editorWest.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, westPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 westPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexWestLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void multipleTexTopLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexTopLoadButtonActionPerformed | ||||
| @ -460,9 +503,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorTop.getValue() != null) { | ||||
|             Texture tex = (Texture) editorTop.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, topPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 topPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexTopLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void multipleTexBottomLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleTexBottomLoadButtonActionPerformed | ||||
| @ -470,9 +523,19 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorBottom.getValue() != null) { | ||||
|             Texture tex = (Texture) editorBottom.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, bottomPic, null); | ||||
| 
 | ||||
|             } else { | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 bottomPic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_multipleTexBottomLoadButtonActionPerformed | ||||
| 
 | ||||
|     private void singleTexLoadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleTexLoadButtonActionPerformed | ||||
| @ -480,11 +543,21 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|         view.setVisible(true); | ||||
|         if (editorSingle.getValue() != null) { | ||||
|             Texture tex = (Texture) editorSingle.getValue(); | ||||
|             String selected = tex.getKey().getName(); | ||||
| 
 | ||||
|             if (selected.endsWith(".dds") || selected.endsWith(".DDS")) { | ||||
|                 if (ddsPreview == null) { | ||||
|                     ddsPreview = new DDSPreview((ProjectAssetManager) SceneApplication.getApplication().getAssetManager()); | ||||
|                 } | ||||
|                 ddsPreview.requestPreview(selected, "", 80, 80, singlePic, null); | ||||
| 
 | ||||
|             } else { | ||||
| 
 | ||||
|                 Icon newicon = ImageUtilities.image2Icon(ImageToAwt.convert(tex.getImage(), false, true, 0)); | ||||
|                 singlePic.setIcon(newicon); | ||||
|             } | ||||
|         } | ||||
|     }//GEN-LAST:event_singleTexLoadButtonActionPerformed | ||||
| 
 | ||||
|     // Variables declaration - do not modify//GEN-BEGIN:variables | ||||
|     private javax.swing.JLabel bottomPic; | ||||
|     private javax.swing.JLabel eastPic; | ||||
| @ -548,6 +621,4 @@ public final class SkyboxVisualPanel2 extends JPanel { | ||||
|     public JCheckBox getSpheremapCheckBox() { | ||||
|         return spheremapCheckBox; | ||||
|     } | ||||
| 
 | ||||
|      | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user