From 7db51b9b65d69aa685b4916d0f6fc326cc0cc4e8 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Sun, 16 Dec 2012 13:45:49 -0600 Subject: [PATCH 01/12] Always save using .zip container format. Removed the "use compression" option from the StorageOptionChooser. --- core/resources/l10n/messages.properties | 2 -- .../openrocket/document/StorageOptions.java | 10 ------- .../openrocket/file/GeneralRocketLoader.java | 2 -- .../openrocket/file/GeneralRocketSaver.java | 10 ------- .../file/openrocket/OpenRocketSaver.java | 27 +++---------------- .../openrocket/importt/OpenRocketLoader.java | 1 - .../openrocket/gui/StorageOptionChooser.java | 12 --------- .../sf/openrocket/utils/RocksimConverter.java | 1 - 8 files changed, 3 insertions(+), 62 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index c9f462b4c..46eac5375 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1063,8 +1063,6 @@ StorageOptChooser.lbl.longC1 = Store only the values shown in the summary StorageOptChooser.lbl.longC2 = This results in the smallest files. StorageOptChooser.checkbox.IncludeDecals = Include decals StorageOptChooser.lbl.IncludeDecals = "Including decals will produce a compressed zip file" -StorageOptChooser.checkbox.Compfile = Compress file -StorageOptChooser.lbl.UsingComp = Using compression reduces the file size significantly. StorageOptChooser.lbl.longD1 = An estimate on how large the resulting file would be with the present options. StorageOptChooser.ttip.Saveopt = Save options StorageOptChooser.lbl.Estfilesize = Estimated file size: diff --git a/core/src/net/sf/openrocket/document/StorageOptions.java b/core/src/net/sf/openrocket/document/StorageOptions.java index abff296a0..5ecb38b1c 100644 --- a/core/src/net/sf/openrocket/document/StorageOptions.java +++ b/core/src/net/sf/openrocket/document/StorageOptions.java @@ -16,8 +16,6 @@ public class StorageOptions implements Cloneable { private boolean includeDecals = false; - private boolean compressionEnabled = true; - private double simulationTimeSkip = SIMULATION_DATA_NONE; private boolean explicitlySet = false; @@ -38,14 +36,6 @@ public class StorageOptions implements Cloneable { this.includeDecals = includeDecals; } - public boolean isCompressionEnabled() { - return compressionEnabled; - } - - public void setCompressionEnabled(boolean compression) { - this.compressionEnabled = compression; - } - public double getSimulationTimeSkip() { return simulationTimeSkip; } diff --git a/core/src/net/sf/openrocket/file/GeneralRocketLoader.java b/core/src/net/sf/openrocket/file/GeneralRocketLoader.java index 4147f6f68..18974131c 100644 --- a/core/src/net/sf/openrocket/file/GeneralRocketLoader.java +++ b/core/src/net/sf/openrocket/file/GeneralRocketLoader.java @@ -106,7 +106,6 @@ public class GeneralRocketLoader { // Check for GZIP if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) { OpenRocketDocument doc = loadFromStream(new GZIPInputStream(source), motorFinder); - doc.getDefaultStorageOptions().setCompressionEnabled(true); doc.getDecalRegistry().setIsZipFile(false); return doc; } @@ -122,7 +121,6 @@ public class GeneralRocketLoader { } if (entry.getName().matches(".*\\.[oO][rR][kK]$")) { OpenRocketDocument doc = loadFromStream(in, motorFinder); - doc.getDefaultStorageOptions().setCompressionEnabled(true); doc.getDefaultStorageOptions().setIncludeDecals(true); doc.getDecalRegistry().setIsZipFile(true); return doc; diff --git a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java index d1a4b3e1d..e8a1bad52 100644 --- a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java +++ b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java @@ -146,16 +146,6 @@ public class GeneralRocketSaver { private void save(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options) throws IOException { - // If we don't include decals, just write the simple file. - if (!options.isIncludeDecals()) { - saveInternal(output,document,options); - return; - } - - // We're saving decals, so the result will be a zip file. There's no - // need to gzip the rocket model file in the archive. - options.setCompressionEnabled(false); - /* if we want a directory ... String path = fileName; int dotlocation = fileName.lastIndexOf('.'); diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index 94d2cd245..761546ec6 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.zip.GZIPOutputStream; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.document.OpenRocketDocument; @@ -57,11 +56,8 @@ public class OpenRocketSaver extends RocketSaver { // Estimated storage used by different portions // These have been hand-estimated from saved files - private static final int BYTES_PER_COMPONENT_UNCOMPRESSED = 590; private static final int BYTES_PER_COMPONENT_COMPRESSED = 80; - private static final int BYTES_PER_SIMULATION_UNCOMPRESSED = 1000; private static final int BYTES_PER_SIMULATION_COMPRESSED = 100; - private static final int BYTES_PER_DATAPOINT_UNCOMPRESSED = 350; private static final int BYTES_PER_DATAPOINT_COMPRESSED = 100; @@ -73,11 +69,6 @@ public class OpenRocketSaver extends RocketSaver { log.info("Saving .ork file"); - if (options.isCompressionEnabled()) { - log.debug("Enabling compression"); - output = new GZIPOutputStream(output); - } - dest = new BufferedWriter(new OutputStreamWriter(output, OPENROCKET_CHARSET)); // Select file version number @@ -121,9 +112,6 @@ public class OpenRocketSaver extends RocketSaver { log.debug("Writing complete, flushing buffers"); dest.flush(); - if (options.isCompressionEnabled()) { - ((GZIPOutputStream) output).finish(); - } } /* @@ -178,17 +166,11 @@ public class OpenRocketSaver extends RocketSaver { componentCount++; } - if (options.isCompressionEnabled()) - size += componentCount * BYTES_PER_COMPONENT_COMPRESSED; - else - size += componentCount * BYTES_PER_COMPONENT_UNCOMPRESSED; + size += componentCount * BYTES_PER_COMPONENT_COMPRESSED; // Size per simulation - if (options.isCompressionEnabled()) - size += doc.getSimulationCount() * BYTES_PER_SIMULATION_COMPRESSED; - else - size += doc.getSimulationCount() * BYTES_PER_SIMULATION_UNCOMPRESSED; + size += doc.getSimulationCount() * BYTES_PER_SIMULATION_COMPRESSED; // Size per flight data point @@ -205,10 +187,7 @@ public class OpenRocketSaver extends RocketSaver { } } - if (options.isCompressionEnabled()) - size += pointCount * BYTES_PER_DATAPOINT_COMPRESSED; - else - size += pointCount * BYTES_PER_DATAPOINT_UNCOMPRESSED; + size += pointCount * BYTES_PER_DATAPOINT_COMPRESSED; return size; } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index 5558a2a7e..91b9debc8 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -84,7 +84,6 @@ public class OpenRocketLoader extends AbstractRocketLoader { timeSkip = Math.rint(timeSkip * 100) / 100; doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip); - doc.getDefaultStorageOptions().setCompressionEnabled(false); // Set by caller if compressed doc.getDefaultStorageOptions().setExplicitlySet(false); doc.clearUndo(); diff --git a/core/src/net/sf/openrocket/gui/StorageOptionChooser.java b/core/src/net/sf/openrocket/gui/StorageOptionChooser.java index 47f3ae40f..62f605f1d 100644 --- a/core/src/net/sf/openrocket/gui/StorageOptionChooser.java +++ b/core/src/net/sf/openrocket/gui/StorageOptionChooser.java @@ -39,7 +39,6 @@ public class StorageOptionChooser extends JPanel { private JSpinner timeSpinner; - private JCheckBox compressButton; private JCheckBox decalButton; private JLabel estimateLabel; @@ -130,14 +129,6 @@ public class StorageOptionChooser extends JPanel { decalButton.addActionListener(actionUpdater); this.add(decalButton, "spanx, wrap para"); - //// Compress file - // FIXME - if the user selects save decals, should we automatically select compress file? - compressButton = new JCheckBox(trans.get("StorageOptChooser.checkbox.Compfile")); - //// Using compression reduces the file size significantly. - compressButton.setToolTipText(trans.get("StorageOptChooser.lbl.UsingComp")); - compressButton.addActionListener(actionUpdater); - this.add(compressButton, "spanx, wrap para"); - // Estimate is updated in loadOptions(opts) estimateLabel = new JLabel(""); @@ -176,8 +167,6 @@ public class StorageOptionChooser extends JPanel { timeSpinner.setValue(t); artificialEvent = false; - // Compression checkbox - compressButton.setSelected(opts.isCompressionEnabled()); decalButton.setSelected(opts.isIncludeDecals()); updateEstimate(); @@ -198,7 +187,6 @@ public class StorageOptionChooser extends JPanel { opts.setSimulationTimeSkip(t); opts.setIncludeDecals(decalButton.isSelected()); - opts.setCompressionEnabled(compressButton.isSelected()); opts.setExplicitlySet(true); } diff --git a/core/src/net/sf/openrocket/utils/RocksimConverter.java b/core/src/net/sf/openrocket/utils/RocksimConverter.java index 3ff4ea756..519a0fd5a 100644 --- a/core/src/net/sf/openrocket/utils/RocksimConverter.java +++ b/core/src/net/sf/openrocket/utils/RocksimConverter.java @@ -59,7 +59,6 @@ public class RocksimConverter { try { StorageOptions opts = new StorageOptions(); opts.setFileType(StorageOptions.FileType.OPENROCKET); - opts.setCompressionEnabled(true); opts.setSimulationTimeSkip(StorageOptions.SIMULATION_DATA_NONE); opts.setExplicitlySet(true); From e516f99a8fe42b4f3e66beaf9195e9f60e3ed04b Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Sun, 16 Dec 2012 21:25:23 -0600 Subject: [PATCH 02/12] Removed the "include decals" storage option - they will always be included when saving as ork file. Fixed saving rocksim files - they are just plain files and have no references to decals. --- core/resources/l10n/messages.properties | 2 -- .../openrocket/document/StorageOptions.java | 10 ------- .../openrocket/file/GeneralRocketLoader.java | 1 - .../openrocket/file/GeneralRocketSaver.java | 26 +++++++++++++++++-- .../file/rocksim/export/RocksimSaver.java | 1 - .../openrocket/gui/StorageOptionChooser.java | 14 ---------- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 46eac5375..7f75f02f5 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1061,8 +1061,6 @@ StorageOptChooser.lbl.seconds = seconds StorageOptChooser.rdbut.Onlyprimfig = Only primary figures StorageOptChooser.lbl.longC1 = Store only the values shown in the summary table.
StorageOptChooser.lbl.longC2 = This results in the smallest files. -StorageOptChooser.checkbox.IncludeDecals = Include decals -StorageOptChooser.lbl.IncludeDecals = "Including decals will produce a compressed zip file" StorageOptChooser.lbl.longD1 = An estimate on how large the resulting file would be with the present options. StorageOptChooser.ttip.Saveopt = Save options StorageOptChooser.lbl.Estfilesize = Estimated file size: diff --git a/core/src/net/sf/openrocket/document/StorageOptions.java b/core/src/net/sf/openrocket/document/StorageOptions.java index 5ecb38b1c..4618aa5d2 100644 --- a/core/src/net/sf/openrocket/document/StorageOptions.java +++ b/core/src/net/sf/openrocket/document/StorageOptions.java @@ -14,8 +14,6 @@ public class StorageOptions implements Cloneable { private FileType fileType = FileType.OPENROCKET; - private boolean includeDecals = false; - private double simulationTimeSkip = SIMULATION_DATA_NONE; private boolean explicitlySet = false; @@ -28,14 +26,6 @@ public class StorageOptions implements Cloneable { this.fileType = fileType; } - public boolean isIncludeDecals() { - return includeDecals; - } - - public void setIncludeDecals(boolean includeDecals) { - this.includeDecals = includeDecals; - } - public double getSimulationTimeSkip() { return simulationTimeSkip; } diff --git a/core/src/net/sf/openrocket/file/GeneralRocketLoader.java b/core/src/net/sf/openrocket/file/GeneralRocketLoader.java index 18974131c..0211f5064 100644 --- a/core/src/net/sf/openrocket/file/GeneralRocketLoader.java +++ b/core/src/net/sf/openrocket/file/GeneralRocketLoader.java @@ -121,7 +121,6 @@ public class GeneralRocketLoader { } if (entry.getName().matches(".*\\.[oO][rR][kK]$")) { OpenRocketDocument doc = loadFromStream(in, motorFinder); - doc.getDefaultStorageOptions().setIncludeDecals(true); doc.getDecalRegistry().setIsZipFile(true); return doc; } else if ( entry.getName().matches(".*\\.[rR][kK][tT]$")) { diff --git a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java index e8a1bad52..da1e7e7cf 100644 --- a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java +++ b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java @@ -18,6 +18,7 @@ import net.sf.openrocket.appearance.AppearanceBuilder; import net.sf.openrocket.appearance.Decal; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.StorageOptions; +import net.sf.openrocket.document.StorageOptions.FileType; import net.sf.openrocket.file.openrocket.OpenRocketSaver; import net.sf.openrocket.file.rocksim.export.RocksimSaver; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -229,6 +230,11 @@ public class GeneralRocketSaver { } // Now we have to loop through all the components and update their names. + // FIXME - we probably don't want to modify the existing document. + // Suppose the user has been using a couple of decal files from the file system. + // He currently is editing some decal files, but decides to do an itermediate save. + // The saved file should contain references to the decal copied into the zip container, + // however, the currently open document should still be looking at the filesystem copy. for( RocketComponent c : document.getRocket() ) { if ( c.getAppearance() == null ) { @@ -248,7 +254,23 @@ public class GeneralRocketSaver { c.setAppearance(builder.getAppearance()); } + + Map decalMap = new HashMap(); + for( Map.Entry image : decals.entrySet() ) { + String newName = decalNameNormalization.get(image.getKey()); + decalMap.put(newName, image.getValue()); + } + if ( options.getFileType() == FileType.OPENROCKET ) { + saveAllPartsZipFile(fileName, output, document, options, decalMap); + } else { + saveInternal(output, document, options); + output.close(); + } + } + + public void saveAllPartsZipFile(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options, Map decals) throws IOException { + // Open a zip stream to write to. ZipOutputStream zos = new ZipOutputStream(output); zos.setLevel(9); @@ -265,8 +287,8 @@ public class GeneralRocketSaver { for( Map.Entry image : decals.entrySet() ) { - String newName = decalNameNormalization.get(image.getKey()); - ZipEntry decal = new ZipEntry(newName); + String name = image.getKey(); + ZipEntry decal = new ZipEntry(name); zos.putNextEntry(decal); InputStream is = image.getValue(); diff --git a/core/src/net/sf/openrocket/file/rocksim/export/RocksimSaver.java b/core/src/net/sf/openrocket/file/rocksim/export/RocksimSaver.java index 87af02831..eff692e2a 100644 --- a/core/src/net/sf/openrocket/file/rocksim/export/RocksimSaver.java +++ b/core/src/net/sf/openrocket/file/rocksim/export/RocksimSaver.java @@ -62,7 +62,6 @@ public class RocksimSaver extends RocketSaver { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dest, "UTF-8")); writer.write(marshalToRocksim(doc)); writer.flush(); - writer.close(); } @Override diff --git a/core/src/net/sf/openrocket/gui/StorageOptionChooser.java b/core/src/net/sf/openrocket/gui/StorageOptionChooser.java index 62f605f1d..eac318011 100644 --- a/core/src/net/sf/openrocket/gui/StorageOptionChooser.java +++ b/core/src/net/sf/openrocket/gui/StorageOptionChooser.java @@ -39,8 +39,6 @@ public class StorageOptionChooser extends JPanel { private JSpinner timeSpinner; - private JCheckBox decalButton; - private JLabel estimateLabel; @@ -122,14 +120,6 @@ public class StorageOptionChooser extends JPanel { noneButton.addActionListener(actionUpdater); this.add(noneButton, "spanx, wrap 20lp"); - //// Save decals - // FIXME - should we hide this if there are no decals? - decalButton = new JCheckBox(trans.get("StorageOptChooser.checkbox.IncludeDecals")); - decalButton.setToolTipText(trans.get("StorageOptChooser.lbl.IncludeDecals")); - decalButton.addActionListener(actionUpdater); - this.add(decalButton, "spanx, wrap para"); - - // Estimate is updated in loadOptions(opts) estimateLabel = new JLabel(""); //// An estimate on how large the resulting file would @@ -167,8 +157,6 @@ public class StorageOptionChooser extends JPanel { timeSpinner.setValue(t); artificialEvent = false; - decalButton.setSelected(opts.isIncludeDecals()); - updateEstimate(); } @@ -186,8 +174,6 @@ public class StorageOptionChooser extends JPanel { opts.setSimulationTimeSkip(t); - opts.setIncludeDecals(decalButton.isSelected()); - opts.setExplicitlySet(true); } From 86d07ca8b8161c4e0b1ec40ba33b75554594e930 Mon Sep 17 00:00:00 2001 From: bkuker Date: Fri, 14 Dec 2012 11:47:31 -0500 Subject: [PATCH 03/12] I10n for color label --- core/resources/l10n/messages.properties | 1 + .../src/net/sf/openrocket/gui/configdialog/AppearancePanel.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 7f75f02f5..09862a8f8 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -725,6 +725,7 @@ AppearanceCfg.lbl.Usedefault = Use default AppearanceCfg.but.savedefault = Save as default appearance AppearanceCfg.lbl.Texture = Texture: AppearanceCfg.lbl.shine = Shine: +AppearanceCfg.lbl.color.Color = Color: AppearanceCfg.lbl.color.diffuse = Diffuse Color: AppearanceCfg.lbl.color.ambient = Ambient Color: AppearanceCfg.lbl.color.specular = Specular Color: diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 4d86ae005..93fb231d8 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -249,7 +249,7 @@ public class AppearancePanel extends JPanel { }*/ { // Color - add(new JLabel("Color")); + add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color"))); mDefault.addEnableComponent(colorButton, false); add(colorButton); } From 97b2c4002c3bcf47878781b02b0cf0b517573095 Mon Sep 17 00:00:00 2001 From: bkuker Date: Fri, 14 Dec 2012 11:52:04 -0500 Subject: [PATCH 04/12] Smaller sliders --- .../net/sf/openrocket/gui/configdialog/AppearancePanel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 93fb231d8..eba8c5709 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -270,7 +270,7 @@ public class AppearancePanel extends JPanel { add(scaleV, "wrap, w 40"); } - {// Placeholder + {// Shine add(new JLabel(trans.get("AppearanceCfg.lbl.shine"))); IntegerModel shineModel = new IntegerModel(ab, "Shine", 0, 100); JSpinner spin = new JSpinner(shineModel.getSpinnerModel()); @@ -279,7 +279,7 @@ public class AppearancePanel extends JPanel { mDefault.addEnableComponent(spin, false); add(spin, "split 2, w 50"); - add(slide, "w 100"); + add(slide, "w 50"); } @@ -319,7 +319,7 @@ public class AppearancePanel extends JPanel { add(new UnitSelector(rotationModel)); BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI)); mDefault.addEnableComponent(bs, false); - add(bs, "w 100, wrap"); + add(bs, "w 50, wrap"); } From d966973f7dc8d3d951b0e81d4e6da3255d35355b Mon Sep 17 00:00:00 2001 From: bkuker Date: Fri, 14 Dec 2012 11:54:53 -0500 Subject: [PATCH 05/12] Rename texture unit and use it for offset too --- .../gui/configdialog/AppearancePanel.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index eba8c5709..5135bb715 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -49,7 +49,11 @@ public class AppearancePanel extends JPanel { private SimpleAppearanceBuilder ab; - private final static UnitGroup UNIT_FOR_SCALES = new UnitGroup(); + /** + * A non-unit that adjusts by a small amount, suitable for + * values that are on the 0-1 scale + */ + private final static UnitGroup TEXTURE_UNIT = new UnitGroup(); static { Unit no_unit = new GeneralUnit(1,"",2) { @Override @@ -63,7 +67,7 @@ public class AppearancePanel extends JPanel { } }; - UNIT_FOR_SCALES.addUnit(no_unit); + TEXTURE_UNIT.addUnit(no_unit); } private static final JColorChooser colorChooser = new JColorChooser(); @@ -258,13 +262,13 @@ public class AppearancePanel extends JPanel { add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale"))); add(new JLabel("x:"), "split 4"); - JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX",UNIT_FOR_SCALES).getSpinnerModel()); + JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX", TEXTURE_UNIT).getSpinnerModel()); scaleU.setEditor(new SpinnerEditor(scaleU)); mDefault.addEnableComponent(scaleU, false); add(scaleU, "w 40"); add(new JLabel("y:")); - JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY",UNIT_FOR_SCALES).getSpinnerModel()); + JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY", TEXTURE_UNIT).getSpinnerModel()); scaleV.setEditor(new SpinnerEditor(scaleV)); mDefault.addEnableComponent(scaleV, false); add(scaleV, "wrap, w 40"); @@ -287,13 +291,13 @@ public class AppearancePanel extends JPanel { add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset"))); add(new JLabel("x:"), "split 4"); - JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU").getSpinnerModel()); + JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU", TEXTURE_UNIT).getSpinnerModel()); offsetU.setEditor(new SpinnerEditor(offsetU)); mDefault.addEnableComponent(offsetU, false); add(offsetU, "w 40"); add(new JLabel("y:")); - JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV").getSpinnerModel()); + JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV", TEXTURE_UNIT).getSpinnerModel()); offsetV.setEditor(new SpinnerEditor(offsetV)); mDefault.addEnableComponent(offsetV, false); add(offsetV, "wrap, w 40"); From 787ef8e3476e07b9d5dc6b489fd036dd86f2221d Mon Sep 17 00:00:00 2001 From: bkuker Date: Fri, 14 Dec 2012 15:06:25 -0500 Subject: [PATCH 06/12] Clean out some comments --- .../gui/configdialog/AppearancePanel.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 5135bb715..c2371e99a 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -121,10 +121,6 @@ public class AppearancePanel extends JPanel { } final JButton figureColorButton = new JButton(new ColorIcon(figureColor)); - /*final JButton diffuseColorButton = new JButton(new ColorIcon(ab.getDiffuse())); - final JButton ambientColorButton = new JButton(new ColorIcon(ab.getAmbient())); - final JButton specularColorButton = new JButton(new ColorIcon(ab.getSpecular()));*/ - final JButton colorButton = new JButton(new ColorIcon(ab.getAmbient())); final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));; @@ -133,9 +129,6 @@ public class AppearancePanel extends JPanel { @Override public void stateChanged(EventObject e) { figureColorButton.setIcon(new ColorIcon(c.getColor())); - /*diffuseColorButton.setIcon(new ColorIcon(ab.getDiffuse())); - ambientColorButton.setIcon(new ColorIcon(ab.getAmbient())); - specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));*/ colorButton.setIcon(new ColorIcon(ab.getColor())); c.setAppearance(ab.getAppearance()); } @@ -154,9 +147,6 @@ public class AppearancePanel extends JPanel { figureColorButton.addActionListener(new ColorActionListener(c, "Color")); colorButton.addActionListener(new ColorActionListener(ab, "Color")); - /*diffuseColorButton.addActionListener(new ColorActionListener(ab, "Diffuse")); - ambientColorButton.addActionListener(new ColorActionListener(ab, "Ambient")); - specularColorButton.addActionListener(new ColorActionListener(ab, "Specular"));*/ BooleanModel mDefault = new BooleanModel(c.getAppearance() == null); BooleanModel fDefault = new BooleanModel(c.getColor() == null); @@ -245,12 +235,6 @@ public class AppearancePanel extends JPanel { p.add(textureDropDown, "grow"); add(p, "span 3, growx, wrap"); } - - /*{ // Diffuse - add(new JLabel(trans.get("AppearanceCfg.lbl.color.diffuse"))); - mDefault.addEnableComponent(diffuseColorButton, false); - add(diffuseColorButton); - }*/ { // Color add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color"))); From f4a85993e60c8989e53c4af79d3f46e820d1c59d Mon Sep 17 00:00:00 2001 From: bkuker Date: Mon, 17 Dec 2012 12:09:56 -0500 Subject: [PATCH 07/12] Disable color choice when you have a texture selected. --- .../openrocket/gui/configdialog/AppearancePanel.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index c2371e99a..bd6dc9f20 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -121,7 +121,7 @@ public class AppearancePanel extends JPanel { } final JButton figureColorButton = new JButton(new ColorIcon(figureColor)); - final JButton colorButton = new JButton(new ColorIcon(ab.getAmbient())); + final JButton colorButton = new JButton(new ColorIcon(ab.getColor())); final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));; @@ -238,8 +238,15 @@ public class AppearancePanel extends JPanel { { // Color add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color"))); - mDefault.addEnableComponent(colorButton, false); + //mDefault.addEnableComponent(colorButton, false); + colorButton.setEnabled(ab.getImage() == null); add(colorButton); + ab.addChangeListener(new StateChangeListener() { + @Override + public void stateChanged(EventObject e) { + colorButton.setEnabled(ab.getImage() == null); + } + }); } { // Scale From 31c351c9d58a2d89ee770af1419f0e3678295051 Mon Sep 17 00:00:00 2001 From: bkuker Date: Mon, 17 Dec 2012 12:14:18 -0500 Subject: [PATCH 08/12] Remove concept of material default for component --- .../gui/configdialog/AppearancePanel.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index bd6dc9f20..99ed9c78e 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -148,7 +148,6 @@ public class AppearancePanel extends JPanel { figureColorButton.addActionListener(new ColorActionListener(c, "Color")); colorButton.addActionListener(new ColorActionListener(ab, "Color")); - BooleanModel mDefault = new BooleanModel(c.getAppearance() == null); BooleanModel fDefault = new BooleanModel(c.getColor() == null); @@ -214,24 +213,11 @@ public class AppearancePanel extends JPanel { {// Texture Header Row add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD), "wrap"); - - final JCheckBox materialDefault = new JCheckBox(mDefault); - materialDefault.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (materialDefault.isSelected()) { - c.setAppearance(null); - } else { - c.setAppearance(ab.getAppearance()); - } - } - }); } {// Texture File add(new JLabel(trans.get("AppearanceCfg.lbl.Texture"))); JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]")); - mDefault.addEnableComponent(textureDropDown, false); p.add(textureDropDown, "grow"); add(p, "span 3, growx, wrap"); } @@ -255,13 +241,11 @@ public class AppearancePanel extends JPanel { add(new JLabel("x:"), "split 4"); JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX", TEXTURE_UNIT).getSpinnerModel()); scaleU.setEditor(new SpinnerEditor(scaleU)); - mDefault.addEnableComponent(scaleU, false); add(scaleU, "w 40"); add(new JLabel("y:")); JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY", TEXTURE_UNIT).getSpinnerModel()); scaleV.setEditor(new SpinnerEditor(scaleV)); - mDefault.addEnableComponent(scaleV, false); add(scaleV, "wrap, w 40"); } @@ -270,8 +254,6 @@ public class AppearancePanel extends JPanel { IntegerModel shineModel = new IntegerModel(ab, "Shine", 0, 100); JSpinner spin = new JSpinner(shineModel.getSpinnerModel()); JSlider slide = new JSlider(shineModel.getSliderModel()); - mDefault.addEnableComponent(slide, false); - mDefault.addEnableComponent(spin, false); add(spin, "split 2, w 50"); add(slide, "w 50"); @@ -284,13 +266,11 @@ public class AppearancePanel extends JPanel { add(new JLabel("x:"), "split 4"); JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU", TEXTURE_UNIT).getSpinnerModel()); offsetU.setEditor(new SpinnerEditor(offsetU)); - mDefault.addEnableComponent(offsetU, false); add(offsetU, "w 40"); add(new JLabel("y:")); JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV", TEXTURE_UNIT).getSpinnerModel()); offsetV.setEditor(new SpinnerEditor(offsetV)); - mDefault.addEnableComponent(offsetV, false); add(offsetV, "wrap, w 40"); } @@ -299,7 +279,6 @@ public class AppearancePanel extends JPanel { EdgeMode[] list = new EdgeMode[EdgeMode.values().length + 1]; System.arraycopy(EdgeMode.values(), 0, list, 1, EdgeMode.values().length); JComboBox combo = new JComboBox(new EnumModel(ab, "EdgeMode", list)); - mDefault.addEnableComponent(combo, false); add(combo); } @@ -309,11 +288,9 @@ public class AppearancePanel extends JPanel { DoubleModel rotationModel = new DoubleModel(ab, "Rotation", UnitGroup.UNITS_ANGLE); JSpinner rotation = new JSpinner(rotationModel.getSpinnerModel()); rotation.setEditor(new SpinnerEditor(rotation)); - mDefault.addEnableComponent(rotation, false); add(rotation, "split 3, w 50"); add(new UnitSelector(rotationModel)); BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI)); - mDefault.addEnableComponent(bs, false); add(bs, "w 50, wrap"); } From 728de34d8b428ffcb0d4aa5fc24ec8bbaa4c0865 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Wed, 19 Dec 2012 16:08:27 -0600 Subject: [PATCH 09/12] Fix build to use new jfreechart and jcommon jars. --- core/build.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.xml b/core/build.xml index ee1ee9c5d..5af1a93c7 100644 --- a/core/build.xml +++ b/core/build.xml @@ -91,8 +91,8 @@ - - + + From 079ef2ba13a8055d326c2abfe0fc081c24c76293 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Fri, 21 Dec 2012 10:05:03 -0600 Subject: [PATCH 10/12] Removed comments about possible caching, it really isn't necessary. --- .../src/net/sf/openrocket/document/DecalRegistry.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/core/src/net/sf/openrocket/document/DecalRegistry.java b/core/src/net/sf/openrocket/document/DecalRegistry.java index 4a7c3b4b1..adb99fabf 100644 --- a/core/src/net/sf/openrocket/document/DecalRegistry.java +++ b/core/src/net/sf/openrocket/document/DecalRegistry.java @@ -28,10 +28,6 @@ public class DecalRegistry { private Map exportedDecalMap = new HashMap(); - /* TODO - should we implement caching? - private Map cache = new HashMap(); - */ - public void setBaseFile(FileInfo fileInfo) { this.fileInfo = fileInfo; } @@ -74,13 +70,6 @@ public class DecalRegistry { * @throws IOException */ public InputStream getDecal( String name ) throws FileNotFoundException, IOException { - /* TODO - // if the decal has already been cached return it. - byte[] bytes = cache.get(name); - if ( bytes != null ) { - return new ByteArrayInputStream(bytes); - } - */ // This is the InputStream to be returned. InputStream rawIs = null; From 618dd63b5cfaf0acba186bb2cf6d7d13735e025e Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Fri, 21 Dec 2012 10:19:52 -0600 Subject: [PATCH 11/12] Moved Rocksim saving condition to the top of save, since there is no need to do all the decal name manipulation if we don't save decals in Rocksim files. --- .../openrocket/file/GeneralRocketSaver.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java index da1e7e7cf..d0856d961 100644 --- a/core/src/net/sf/openrocket/file/GeneralRocketSaver.java +++ b/core/src/net/sf/openrocket/file/GeneralRocketSaver.java @@ -147,13 +147,14 @@ public class GeneralRocketSaver { private void save(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options) throws IOException { - /* if we want a directory ... - String path = fileName; - int dotlocation = fileName.lastIndexOf('.'); - if ( dotlocation > 1 ) { - path = fileName.substring(dotlocation); + // For now, we don't save decal inforamtion in ROCKSIM files, so don't do anything + // which follows. + // TODO - add support for decals in ROCKSIM files? + if ( options.getFileType() == FileType.ROCKSIM ) { + saveInternal(output, document, options); + output.close(); + return; } - */ // grab the set of decal images. We do this up front // so we can fail early if some resource is missing. @@ -230,12 +231,12 @@ public class GeneralRocketSaver { } // Now we have to loop through all the components and update their names. - // FIXME - we probably don't want to modify the existing document. - // Suppose the user has been using a couple of decal files from the file system. - // He currently is editing some decal files, but decides to do an itermediate save. - // The saved file should contain references to the decal copied into the zip container, - // however, the currently open document should still be looking at the filesystem copy. - for( RocketComponent c : document.getRocket() ) { + + // First we copy the OpenRocketDocument so we can modify the decal file names + // without changing the ui's copy. This is so the ui will continue to + // use the exported decals. + OpenRocketDocument rocketDocCopy = document.copy(); + for( RocketComponent c : rocketDocCopy.getRocket() ) { if ( c.getAppearance() == null ) { continue; @@ -261,12 +262,8 @@ public class GeneralRocketSaver { String newName = decalNameNormalization.get(image.getKey()); decalMap.put(newName, image.getValue()); } - if ( options.getFileType() == FileType.OPENROCKET ) { - saveAllPartsZipFile(fileName, output, document, options, decalMap); - } else { - saveInternal(output, document, options); - output.close(); - } + + saveAllPartsZipFile(fileName, output, rocketDocCopy, options, decalMap); } public void saveAllPartsZipFile(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options, Map decals) throws IOException { From bd1e3ce83c436dda11b5903ebddd509f7f979ea6 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Fri, 21 Dec 2012 22:16:13 -0600 Subject: [PATCH 12/12] Minor fixups and method renaming. --- .../sf/openrocket/document/DecalRegistry.java | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/core/src/net/sf/openrocket/document/DecalRegistry.java b/core/src/net/sf/openrocket/document/DecalRegistry.java index adb99fabf..5b51b4f32 100644 --- a/core/src/net/sf/openrocket/document/DecalRegistry.java +++ b/core/src/net/sf/openrocket/document/DecalRegistry.java @@ -27,7 +27,7 @@ public class DecalRegistry { private boolean isZipFile = false; private Map exportedDecalMap = new HashMap(); - + public void setBaseFile(FileInfo fileInfo) { this.fileInfo = fileInfo; } @@ -48,7 +48,7 @@ public class DecalRegistry { return false; } try { - InputStream is = forwardToEntry(name); + InputStream is = findInZipContainer(name); if ( is != null ) { is.close(); return true; @@ -59,7 +59,7 @@ public class DecalRegistry { return false; } } - + /** * This function returns an InputStream backed by a byte[] containing the decal pixels. * If it reads in the bytes from an actual file, the underlying file is closed. @@ -74,7 +74,7 @@ public class DecalRegistry { // This is the InputStream to be returned. InputStream rawIs = null; - + // First check if the decal had been exported { File exportedFile= exportedDecalMap.get(name); @@ -90,7 +90,7 @@ public class DecalRegistry { } if ( rawIs == null && isZipFile ) { - rawIs = forwardToEntry(name); + rawIs = findInZipContainer(name); } // Check absolute file name: @@ -120,7 +120,6 @@ public class DecalRegistry { try { byte[] bytes = FileUtils.readBytes(rawIs); - // TODO - here we would update the cache. return new ByteArrayInputStream(bytes); } finally { @@ -130,7 +129,7 @@ public class DecalRegistry { } public void exportDecal( String decalName, File selectedFile ) throws IOException { - + try { InputStream is = getDecal(decalName); OutputStream os = new BufferedOutputStream( new FileOutputStream(selectedFile)); @@ -139,21 +138,26 @@ public class DecalRegistry { is.close(); os.close(); - + exportedDecalMap.put(decalName, selectedFile ); - + } catch (IOException iex) { throw new BugException(iex); } - - + + } - - - private ZipInputStream forwardToEntry( String name ) throws IOException { - ZipInputStream zis = new ZipInputStream(fileInfo.fileURL.openStream()); + + + private ZipInputStream findInZipContainer( String name ) { + ZipInputStream zis = null; + try { + zis = new ZipInputStream(fileInfo.fileURL.openStream()); + } catch( IOException ex ) { + return null; + } try { ZipEntry entry = zis.getNextEntry(); while ( entry != null ) { @@ -162,12 +166,16 @@ public class DecalRegistry { } entry = zis.getNextEntry(); } + zis.close(); + return null; } catch ( IOException ioex ) { - zis.close(); - throw ioex; + try { + zis.close(); + } catch ( IOException ex ) { + // why does close throw? it's maddening + } + return null; } - zis.close(); - return null; } }