added helper methods for config reader

This commit is contained in:
bancika
2011-01-15 20:32:46 +00:00
parent 84818eef6a
commit 03444c3146
6 changed files with 29 additions and 24 deletions
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<stringAttribute key="bad_container_name" value="\DIYLC\r"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/DIYLC/src/org/diylc/DIYLCStarter.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;Library&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;DIYLC&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.DIYLCStarter"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="DIYLC"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms32m -Xmx128m"/>
</launchConfiguration>
@@ -50,7 +50,7 @@ public class DialogFactory {
public void initialize(JFrame mainFrame) { public void initialize(JFrame mainFrame) {
this.mainFrame = mainFrame; this.mainFrame = mainFrame;
String lastDirectoryPath = (String) ConfigurationManager.getInstance() String lastDirectoryPath = (String) ConfigurationManager.getInstance()
.getConfigurationItem(PATH_KEY); .readString(PATH_KEY, null);
if (lastDirectoryPath != null) { if (lastDirectoryPath != null) {
lastDirectory = new File(lastDirectoryPath); lastDirectory = new File(lastDirectoryPath);
} }
@@ -111,7 +111,7 @@ public class DialogFactory {
fileChooser.setAccessory(null); fileChooser.setAccessory(null);
if (result == JFileChooser.APPROVE_OPTION) { if (result == JFileChooser.APPROVE_OPTION) {
lastDirectory = fileChooser.getCurrentDirectory(); lastDirectory = fileChooser.getCurrentDirectory();
ConfigurationManager.getInstance().setConfigurationItem(PATH_KEY, ConfigurationManager.getInstance().writeValue(PATH_KEY,
lastDirectory.getAbsolutePath()); lastDirectory.getAbsolutePath());
if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) { if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
return fileChooser.getSelectedFile(); return fileChooser.getSelectedFile();
@@ -48,11 +48,8 @@ public class CanvasPlugin implements IPlugIn {
scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort), scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort),
new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in) new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in)
.convertToPixels()); .convertToPixels());
Boolean metric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem( boolean metric = ConfigurationManager.getInstance().readBoolean(
Presenter.METRIC_KEY); Presenter.METRIC_KEY, true);
if (metric == null) {
metric = true;
}
scrollPane.setMetric(metric); scrollPane.setMetric(metric);
scrollPane.addUnitListener(new IRulerListener() { scrollPane.addUnitListener(new IRulerListener() {
@@ -207,17 +207,14 @@ public class StatusBar extends JPanel implements IPlugIn {
break; break;
case SELECTION_SIZE_CHANGED: case SELECTION_SIZE_CHANGED:
Point2D size = (Point2D) params[0]; Point2D size = (Point2D) params[0];
Boolean isMetric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem( boolean metric = ConfigurationManager.getInstance().readBoolean(
Presenter.METRIC_KEY); Presenter.METRIC_KEY, true);
if (isMetric == null) {
isMetric = true;
}
if (size == null) { if (size == null) {
getSizeLabel().setText("N/A"); getSizeLabel().setText("N/A");
} else { } else {
getSizeLabel().setText( getSizeLabel().setText(
sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY()) sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY())
+ (isMetric ? " cm" : " in")); + (metric ? " cm" : " in"));
} }
break; break;
case SLOT_CHANGED: case SLOT_CHANGED:
@@ -836,7 +836,7 @@ public class Presenter implements IPlugInPort {
for (IDIYComponent component : selectedComponents) { for (IDIYComponent component : selectedComponents) {
String className = component.getClass().getName(); String className = component.getClass().getName();
LOG.debug("Default property value set for " + className + ":" + propertyName); LOG.debug("Default property value set for " + className + ":" + propertyName);
ConfigurationManager.getInstance().setConfigurationItem( ConfigurationManager.getInstance().writeValue(
DEFAULTS_KEY + className + ":" + propertyName, value); DEFAULTS_KEY + className + ":" + propertyName, value);
} }
} }
@@ -845,13 +845,13 @@ public class Presenter implements IPlugInPort {
public void setProjectDefaultPropertyValue(String propertyName, Object value) { public void setProjectDefaultPropertyValue(String propertyName, Object value) {
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value)); LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value));
LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName); LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName);
ConfigurationManager.getInstance().setConfigurationItem( ConfigurationManager.getInstance().writeValue(
DEFAULTS_KEY + Project.class.getName() + ":" + propertyName, value); DEFAULTS_KEY + Project.class.getName() + ":" + propertyName, value);
} }
@Override @Override
public void setMetric(boolean isMetric) { public void setMetric(boolean isMetric) {
ConfigurationManager.getInstance().setConfigurationItem(Presenter.METRIC_KEY, isMetric); ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric);
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
calculateSelectionDimension()); calculateSelectionDimension());
} }
@@ -957,11 +957,7 @@ public class Presenter implements IPlugInPort {
if (selectedComponents.isEmpty()) { if (selectedComponents.isEmpty()) {
return null; return null;
} }
Boolean isMetric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem( boolean metric = ConfigurationManager.getInstance().readBoolean(METRIC_KEY, true);
METRIC_KEY);
if (isMetric == null) {
isMetric = true;
}
Area area = new Area(); Area area = new Area();
for (IDIYComponent<?> component : selectedComponents) { for (IDIYComponent<?> component : selectedComponents) {
Area componentArea = componentAreaMap.get(component); Area componentArea = componentAreaMap.get(component);
@@ -973,7 +969,7 @@ public class Presenter implements IPlugInPort {
double height = area.getBounds2D().getHeight(); double height = area.getBounds2D().getHeight();
width /= Constants.PIXELS_PER_INCH; width /= Constants.PIXELS_PER_INCH;
height /= Constants.PIXELS_PER_INCH; height /= Constants.PIXELS_PER_INCH;
if (isMetric) { if (metric) {
width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor(); width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor(); height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
} }
@@ -1082,8 +1078,8 @@ public class Presenter implements IPlugInPort {
object.getClass()); object.getClass());
// Override with default values if available. // Override with default values if available.
for (PropertyWrapper property : properties) { for (PropertyWrapper property : properties) {
Object defaultValue = ConfigurationManager.getInstance().getConfigurationItem( Object defaultValue = ConfigurationManager.getInstance().readObject(
DEFAULTS_KEY + object.getClass().getName() + ":" + property.getName()); DEFAULTS_KEY + object.getClass().getName() + ":" + property.getName(), null);
if (defaultValue != null) { if (defaultValue != null) {
property.setValue(cloner.deepClone(defaultValue)); property.setValue(cloner.deepClone(defaultValue));
property.writeTo(object); property.writeTo(object);