Remove the Daos interface and have the Application hold the ComponentPresetDao itself. This was an unnecessary layer of abstraction.

This commit is contained in:
Kevin Ruland 2012-04-03 02:05:17 +00:00
parent addca0b4b8
commit 2da4c7df98
7 changed files with 15 additions and 39 deletions

View File

@ -16,9 +16,9 @@ public class ComponentPresetDao {
private final List<ComponentPreset> templates = new ArrayList<ComponentPreset>();
// Package scope constructor to control creation pattern.
ComponentPresetDao() {}
public ComponentPresetDao() {}
void initialize() throws IOException {
public void initialize() throws IOException {
InputStream is = ComponentPresetDao.class.getResourceAsStream("/datafiles/bodytubepresets.csv");

View File

@ -1,7 +0,0 @@
package net.sf.openrocket.database;
public interface Daos {
public ComponentPresetDao getBodyTubePresetDao();
}

View File

@ -1,19 +0,0 @@
package net.sf.openrocket.database;
public class DaosImpl implements Daos {
private ComponentPresetDao bodyTubePresetDao;
public DaosImpl() throws Exception {
bodyTubePresetDao = new ComponentPresetDao();
bodyTubePresetDao.initialize();
}
@Override
public ComponentPresetDao getBodyTubePresetDao() {
return bodyTubePresetDao;
}
}

View File

@ -28,9 +28,8 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
private final List<ComponentPreset> presets;
public PresetModel(RocketComponent component) {
// FIXME: Make generic for any component type
// FIXME: This should load only the user's favorites, NOT all presets
presets = Application.getDaos().getBodyTubePresetDao().listAll();
presets = Application.getComponentPresetDao().listAll();
this.component = component;
previousPreset = component.getPresetComponent();
component.addComponentChangeListener(this);

View File

@ -37,7 +37,7 @@ public class ComponentPresetChooserDialog extends JDialog {
this.component = component;
// FIXME: Make generic for component type
presets = Application.getDaos().getBodyTubePresetDao().listAll();
presets = Application.getComponentPresetDao().listAll();

View File

@ -1,6 +1,6 @@
package net.sf.openrocket.startup;
import net.sf.openrocket.database.Daos;
import net.sf.openrocket.database.ComponentPresetDao;
import net.sf.openrocket.database.MotorDatabase;
import net.sf.openrocket.l10n.ClassBasedTranslator;
import net.sf.openrocket.l10n.DebugTranslator;
@ -25,7 +25,7 @@ public final class Application {
private static MotorDatabase motorSetDatabase;
private static Daos daos;
private static ComponentPresetDao componentPresetDao;
private static Preferences preferences;
@ -163,12 +163,13 @@ public final class Application {
Application.motorSetDatabase = motorSetDatabase;
}
public static Daos getDaos() {
return daos;
public static ComponentPresetDao getComponentPresetDao() {
return componentPresetDao;
}
public static void setDaos(Daos daos) {
Application.daos = daos;
public static void setComponentPresetDao(ComponentPresetDao componentPresetDao) {
Application.componentPresetDao = componentPresetDao;
}

View File

@ -4,7 +4,7 @@ import java.io.PrintStream;
import java.util.Locale;
import java.util.prefs.Preferences;
import net.sf.openrocket.database.DaosImpl;
import net.sf.openrocket.database.ComponentPresetDao;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.DebugTranslator;
import net.sf.openrocket.l10n.L10N;
@ -57,7 +57,9 @@ public class Startup {
initializeL10n();
// Must be done after localization is initialized
Application.setDaos( new DaosImpl() );
ComponentPresetDao componentPresetDao = new ComponentPresetDao();
componentPresetDao.initialize();
Application.setComponentPresetDao( componentPresetDao );
// Continue startup in Startup2 class (where Application is already set up)
Startup2.runMain(args);