diff --git a/core/build.xml b/core/build.xml
index 04820e3a4..2af57b225 100644
--- a/core/build.xml
+++ b/core/build.xml
@@ -27,7 +27,7 @@
-
+
diff --git a/core/src/logback.xml b/core/src/logback.xml
deleted file mode 100644
index 930599f30..000000000
--- a/core/src/logback.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/core/src/net/sf/openrocket/appearance/DecalImage.java b/core/src/net/sf/openrocket/appearance/DecalImage.java
index 31aa9013a..544eda8b3 100644
--- a/core/src/net/sf/openrocket/appearance/DecalImage.java
+++ b/core/src/net/sf/openrocket/appearance/DecalImage.java
@@ -13,6 +13,7 @@ public interface DecalImage extends ChangeSource, Comparable {
public InputStream getBytes() throws FileNotFoundException, IOException;
- public void exportImage(File file, boolean watchForChanges) throws IOException;
+ public void exportImage(File file) throws IOException;
+ public void fireChangeEvent(Object source);
}
diff --git a/core/src/net/sf/openrocket/appearance/defaults/ResourceDecalImage.java b/core/src/net/sf/openrocket/appearance/defaults/ResourceDecalImage.java
index 20d2661ac..65ae08506 100644
--- a/core/src/net/sf/openrocket/appearance/defaults/ResourceDecalImage.java
+++ b/core/src/net/sf/openrocket/appearance/defaults/ResourceDecalImage.java
@@ -33,8 +33,11 @@ class ResourceDecalImage implements DecalImage {
}
@Override
- public void exportImage(File file, boolean watchForChanges) throws IOException {
+ public void exportImage(File file) throws IOException {
+ }
+ @Override
+ public void fireChangeEvent(Object source) {
}
@Override
diff --git a/core/src/net/sf/openrocket/database/ComponentPresetDatabase.java b/core/src/net/sf/openrocket/database/ComponentPresetDatabase.java
index 24bca83ae..df9db3f22 100644
--- a/core/src/net/sf/openrocket/database/ComponentPresetDatabase.java
+++ b/core/src/net/sf/openrocket/database/ComponentPresetDatabase.java
@@ -11,30 +11,16 @@ import org.slf4j.LoggerFactory;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.startup.Application;
-public abstract class ComponentPresetDatabase extends Database implements ComponentPresetDao {
+public class ComponentPresetDatabase extends Database implements ComponentPresetDao {
private static final Logger logger = LoggerFactory.getLogger(ComponentPresetDatabase.class);
- private volatile boolean startedLoading = false;
- private volatile boolean endedLoading = false;
- private final boolean asynchronous;
-
- /** Set to true the first time {@link #blockUntilLoaded()} is called. */
- protected volatile boolean inUse = false;
-
public ComponentPresetDatabase() {
super();
- this.asynchronous = false;
}
- public ComponentPresetDatabase(boolean asynchronous ) {
- super();
- this.asynchronous = asynchronous;
- }
-
@Override
public List listAll() {
- blockUntilLoaded();
return list;
}
@@ -45,7 +31,6 @@ public abstract class ComponentPresetDatabase extends Database
@Override
public List listForType( ComponentPreset.Type type ) {
- blockUntilLoaded();
if ( type == null ) {
return Collections.emptyList();
}
@@ -71,8 +56,6 @@ public abstract class ComponentPresetDatabase extends Database
*/
@Override
public List listForType( ComponentPreset.Type type, boolean favorite ) {
- blockUntilLoaded();
-
if ( !favorite ) {
return listForType(type);
}
@@ -91,8 +74,6 @@ public abstract class ComponentPresetDatabase extends Database
@Override
public List listForTypes( ComponentPreset.Type ... type ) {
- blockUntilLoaded();
-
if( type == null || type.length == 0 ) {
return Collections.emptyList();
}
@@ -118,13 +99,11 @@ public abstract class ComponentPresetDatabase extends Database
@Override
public List listForTypes( List types ) {
- blockUntilLoaded();
return listForTypes( (ComponentPreset.Type[]) types.toArray() );
}
@Override
public List find(String manufacturer, String partNo) {
- blockUntilLoaded();
List presets = new ArrayList();
for( ComponentPreset preset : list ) {
if ( preset.getManufacturer().getSimpleName().equals(manufacturer) && preset.getPartNo().equals(partNo) ) {
@@ -136,75 +115,8 @@ public abstract class ComponentPresetDatabase extends Database
@Override
public void setFavorite( ComponentPreset preset, ComponentPreset.Type type, boolean favorite ) {
- blockUntilLoaded();
Application.getPreferences().setComponentFavorite( preset, type, favorite );
this.fireAddEvent(preset);
}
-
- /**
- * Used for loading the component preset database. This method will be called in a background
- * thread to load the presets asynchronously.
- */
- protected abstract void load();
-
- /**
- * Start loading the presets.
- *
- * @throws IllegalStateException if this method has already been called.
- */
- public void startLoading() {
- if (startedLoading) {
- throw new IllegalStateException("Already called startLoading");
- }
- startedLoading = true;
- if (asynchronous) {
- new LoadingThread().start();
- } else {
- load();
- }
- synchronized (this) {
- endedLoading = true;
- this.notifyAll();
- }
- }
-
- /**
- * Background thread for loading the presets.
- */
- private class LoadingThread extends Thread {
-
- private LoadingThread() {
- this.setName("PresetLoadingThread");
- this.setPriority(MIN_PRIORITY);
- }
- @Override
- public void run() {
- load();
- }
- }
-
- /**
- * Block the current thread until loading of the presets has been completed.
- *
- * @throws IllegalStateException if startLoading() has not been called.
- */
- public void blockUntilLoaded() {
- inUse = true;
- if (!startedLoading) {
- throw new IllegalStateException("startLoading() has not been called");
- }
- if (!endedLoading) {
- synchronized (this) {
- while (!endedLoading) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- logger.warn("InterruptedException occurred, ignoring", e);
- }
- }
- }
- }
- }
-
}
diff --git a/core/src/net/sf/openrocket/document/DecalRegistry.java b/core/src/net/sf/openrocket/document/DecalRegistry.java
index 607e4adc5..931a4d7e7 100644
--- a/core/src/net/sf/openrocket/document/DecalRegistry.java
+++ b/core/src/net/sf/openrocket/document/DecalRegistry.java
@@ -35,8 +35,6 @@ import org.slf4j.LoggerFactory;
public class DecalRegistry {
private static Logger log = LoggerFactory.getLogger(DecalRegistry.class);
- private WatchService watchService = Application.getWatchService();
-
DecalRegistry() {
}
@@ -121,6 +119,11 @@ public class DecalRegistry {
return name != null ? name : delegate.getName();
}
+ @Override
+ public void fireChangeEvent(Object source) {
+ delegate.fireChangeEvent(source);
+ }
+
/**
* 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.
@@ -147,7 +150,7 @@ public class DecalRegistry {
}
@Override
- public void exportImage(File file, boolean watchForChanges) throws IOException {
+ public void exportImage(File file) throws IOException {
try {
InputStream is = getBytes();
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
@@ -159,19 +162,6 @@ public class DecalRegistry {
this.fileSystemLocation = file;
- if (watchForChanges) {
- watchService.register(new FileWatcher(this.fileSystemLocation) {
-
- @Override
- public void handleEvent(WatchEvent evt) {
- DecalImageImpl.this.delegate.fireChangeEvent();
- //System.out.println(this.getFile() + " has changed");
-
- }
-
- });
- }
-
} catch (IOException iex) {
throw new BugException(iex);
}
diff --git a/core/src/net/sf/openrocket/gui/ExportDecalDialog.java b/core/src/net/sf/openrocket/gui/ExportDecalDialog.java
index b83262e01..457dfa54e 100644
--- a/core/src/net/sf/openrocket/gui/ExportDecalDialog.java
+++ b/core/src/net/sf/openrocket/gui/ExportDecalDialog.java
@@ -100,7 +100,7 @@ public class ExportDecalDialog extends JDialog {
private void export(DecalImage decal, File selectedFile) {
try {
- decal.exportImage(selectedFile, false);
+ decal.exportImage(selectedFile);
} catch (IOException iex) {
String message = MessageFormat.format(trans.get("ExportDecalDialog.exception"), selectedFile.getAbsoluteFile());
JOptionPane.showMessageDialog(this, message, "", JOptionPane.ERROR_MESSAGE);
diff --git a/core/src/net/sf/openrocket/gui/components/compass/Tester.java b/core/src/net/sf/openrocket/gui/components/compass/Tester.java
index 86a82a495..9273088f7 100644
--- a/core/src/net/sf/openrocket/gui/components/compass/Tester.java
+++ b/core/src/net/sf/openrocket/gui/components/compass/Tester.java
@@ -11,16 +11,16 @@ import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.util.GUIUtil;
-import net.sf.openrocket.l10n.ResourceBundleTranslator;
-import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.startup.BasicApplication;
import net.sf.openrocket.unit.UnitGroup;
public class Tester {
-
+
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
- Application.setBaseTranslator(new ResourceBundleTranslator("l10n.messages"));
+ BasicApplication baseApp = new BasicApplication();
+ baseApp.initializeApplication();
GUIUtil.setBestLAF();
@@ -33,7 +33,7 @@ public class Tester {
DoubleModel model = new DoubleModel(Math.toRadians(45), UnitGroup.UNITS_ANGLE);
DoubleModel second = new DoubleModel(Math.toRadians(30), UnitGroup.UNITS_ANGLE);
-
+
CompassPointer rose = new CompassSelector(model);
rose.setPreferredSize(new Dimension(300, 300));
rose.setSecondaryModel(second);
@@ -51,11 +51,11 @@ public class Tester {
spin.setPreferredSize(new Dimension(50, 20));
panel.add(spin, "wrap para");
-
+
CompassSelectionButton button = new CompassSelectionButton(model);
panel.add(button);
-
+
frame.add(panel);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java
index 459750cd2..94c424dfb 100644
--- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java
+++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java
@@ -52,6 +52,8 @@ import net.sf.openrocket.util.StateChangeListener;
public class AppearancePanel extends JPanel {
private static final Translator trans = Application.getTranslator();
+ private EditDecalHelper editDecalHelper = Application.getInjector().getInstance(EditDecalHelper.class);
+
private AppearanceBuilder ab;
// We hang on to the user selected appearance when switching to default appearance.
@@ -269,7 +271,7 @@ public class AppearancePanel extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
try {
- EditDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage());
+ editDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage());
} catch (EditDecalHelperException ex) {
JOptionPane.showMessageDialog(AppearancePanel.this, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE);
}
diff --git a/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java b/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java
index 696b6e59e..e4e9f94e2 100644
--- a/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java
+++ b/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java
@@ -1,19 +1,15 @@
package net.sf.openrocket.gui.preset;
-import net.miginfocom.swing.MigLayout;
-import net.sf.openrocket.gui.util.FileHelper;
-import net.sf.openrocket.gui.util.Icons;
-import net.sf.openrocket.gui.util.SwingPreferences;
-import net.sf.openrocket.l10n.ResourceBundleTranslator;
-import net.sf.openrocket.l10n.Translator;
-import net.sf.openrocket.logging.Markers;
-import net.sf.openrocket.material.Material;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.loader.MaterialHolder;
-import net.sf.openrocket.preset.loader.RocksimComponentFileTranslator;
-import net.sf.openrocket.preset.xml.OpenRocketComponentDTO;
-import net.sf.openrocket.preset.xml.OpenRocketComponentSaver;
-import net.sf.openrocket.startup.Application;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -34,486 +30,476 @@ import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.xml.bind.JAXBException;
+import net.miginfocom.swing.MigLayout;
+import net.sf.openrocket.gui.util.FileHelper;
+import net.sf.openrocket.gui.util.Icons;
+import net.sf.openrocket.gui.util.SwingPreferences;
+import net.sf.openrocket.logging.Markers;
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.loader.MaterialHolder;
+import net.sf.openrocket.preset.loader.RocksimComponentFileTranslator;
+import net.sf.openrocket.preset.xml.OpenRocketComponentDTO;
+import net.sf.openrocket.preset.xml.OpenRocketComponentSaver;
+import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.startup.BasicApplication;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.awt.Window;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* A UI for editing component presets. Currently this is a standalone application - run the main within this class.
* TODO: Full I18n TODO: Save As .csv
*/
public class ComponentPresetEditor extends JPanel implements PresetResultListener {
-
- /**
- * The logger.
- */
- private static final Logger log = LoggerFactory.getLogger(ComponentPresetEditor.class);
-
- /**
- * The I18N translator.
- */
- private static Translator trans = null;
-
- /**
- * The table of presets.
- */
- private JTable table;
-
- /**
- * The table's data model.
- */
- private DataTableModel model;
-
- private final OpenedFileContext editContext = new OpenedFileContext();
-
- static {
- trans = Application.getTranslator();
- }
-
- /**
- * Create the panel.
- *
- * @param frame the parent window
- */
- public ComponentPresetEditor(final JFrame frame) {
- setLayout(new MigLayout("", "[82.00px, grow][168.00px, grow][84px, grow][117.00px, grow][][222px]",
- "[346.00px, grow][29px]"));
-
- model = new DataTableModel(new String[]{"Manufacturer", "Type", "Part No", "Description", ""});
-
- table = new JTable(model);
- table.getTableHeader().setFont(new JLabel().getFont());
- //The action never gets called because the table MouseAdapter intercepts it first. Still need an empty
- // instance though.
- Action action = new AbstractAction() {
- @Override
- public void actionPerformed(final ActionEvent e) {
- }
- };
- //Create a editor/renderer for the delete operation. Instantiation self-registers into the table.
- new ButtonColumn(table, action, 4);
- table.getColumnModel().getColumn(4).setMaxWidth(Icons.EDIT_DELETE.getIconWidth());
- table.getColumnModel().getColumn(4).setMinWidth(Icons.EDIT_DELETE.getIconWidth());
-
- JScrollPane scrollPane = new JScrollPane(table);
- table.setFillsViewportHeight(true);
- table.setAutoCreateRowSorter(true);
- add(scrollPane, "cell 0 0 6 1,grow");
-
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- JTable target = (JTable) e.getSource();
- int selectedColumn = table.getColumnModel().getColumnIndexAtX(target.getSelectedColumn());
- final int targetSelectedRow = target.getSelectedRow();
- if (targetSelectedRow > -1 && targetSelectedRow < model.getRowCount()) {
- int selectedRow = table.getRowSorter().convertRowIndexToModel(targetSelectedRow);
- if (selectedColumn == 4) {
- if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(ComponentPresetEditor.this,
- "Do you want to delete this preset?",
- "Confirm Delete", JOptionPane.YES_OPTION,
- JOptionPane.QUESTION_MESSAGE)) {
- model.removeRow(selectedRow);
- }
- }
- else {
- if (e.getClickCount() == 2) {
- editContext.setEditingSelected(true);
- new PresetEditorDialog(ComponentPresetEditor.this,
- (ComponentPreset) model.getAssociatedObject(selectedRow), editContext.getMaterialsLoaded()).setVisible(true);
- }
- }
- }
- }
- });
-
-
- JMenuBar menuBar = new JMenuBar();
- frame.setJMenuBar(menuBar);
-
- JMenu mnFile = new JMenu("File");
- menuBar.add(mnFile);
-
- JMenuItem mntmOpen = new JMenuItem("Open...");
- mnFile.add(mntmOpen);
- mntmOpen.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent e) {
- if (model.getRowCount() > 0) {
- /*
- * If the table model already contains presets, ask the user if they a) want to discard those
- * presets, b) save them before reading in another component file, or c) merge the read component file
- * with the current contents of the table model.
- */
- Object[] options = {"Save",
- "Merge",
- "Discard",
- "Cancel"};
- int n = JOptionPane.showOptionDialog(frame,
- "The editor contains existing component presets. What would you like to do with them?",
- "Existing Component Presets",
- JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[0]);
- if (n == 0) { //Save. Then remove existing rows and open.
- if (saveAndHandleError()) {
- model.removeAllRows();
- }
- else { //Save failed; bail out.
- return;
- }
- }
- else if (n == 2) { //Discard and open
- model.removeAllRows();
- }
- else if (n == 3) { //Cancel. Bail out.
- return;
- }
- }
- //Open file dialog
- openComponentFile();
- }
- });
-
- JSeparator separator = new JSeparator();
- mnFile.add(separator);
-
- JMenuItem mntmSave = new JMenuItem("Save As...");
- mnFile.add(mntmSave);
- mntmSave.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(final ActionEvent e) {
- saveAndHandleError();
- }
- });
-
- JSeparator separator_1 = new JSeparator();
- mnFile.add(separator_1);
-
- JMenuItem mntmExit = new JMenuItem("Close");
- mnFile.add(mntmExit);
- mntmExit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- Window w = SwingUtilities.getWindowAncestor(ComponentPresetEditor.this);
- w.dispose();
- }
- });
-
-
- JButton addBtn = new JButton("Add");
- addBtn.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- editContext.setEditingSelected(false);
- new PresetEditorDialog(ComponentPresetEditor.this).setVisible(true);
- }
- });
- add(addBtn, "cell 0 1,alignx left,aligny top");
- }
-
- /**
- * Callback method from the PresetEditorDialog to notify this class when a preset has been saved. The 'save' is
- * really just a call back here so the preset can be added to the master table. It's not to be confused with the
- * save to disk.
- *
- * @param preset the new or modified preset
- */
- @Override
- public void notifyResult(final ComponentPreset preset) {
- if (preset != null) {
- DataTableModel myModel = (DataTableModel) table.getModel();
- //Is this a new preset?
- String description = preset.has(ComponentPreset.DESCRIPTION) ? preset.get(ComponentPreset.DESCRIPTION) :
- preset.getPartNo();
- if (!editContext.isEditingSelected() || table.getSelectedRow() == -1) {
- myModel.addRow(new Object[]{preset.getManufacturer().getDisplayName(), preset.getType().name(),
- preset.getPartNo(), description, Icons.EDIT_DELETE}, preset);
- }
- else {
- //This is a modified preset; update all of the columns and the stored associated instance.
- int row = table.getSelectedRow();
- myModel.setValueAt(preset.getManufacturer().getDisplayName(), row, 0);
- myModel.setValueAt(preset.getType().name(), row, 1);
- myModel.setValueAt(preset.getPartNo(), row, 2);
- myModel.setValueAt(description, row, 3);
- myModel.associated.set(row, preset);
- }
- }
- editContext.setEditingSelected(false);
- }
-
- /**
- * Launch the test main.
- */
- public static void main(String[] args) {
- try {
- trans = new ResourceBundleTranslator("l10n.messages");
- net.sf.openrocket.startup.Application.setBaseTranslator(trans);
-
- Application.setPreferences(new SwingPreferences());
- JFrame dialog = new JFrame();
- dialog.getContentPane().add(new ComponentPresetEditor(dialog));
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.pack();
- dialog.setVisible(true);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * A table model that adds associated objects to each row, allowing for easy retrieval.
- */
- class DataTableModel extends DefaultTableModel {
-
- private List