mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added helper methods for config reader
This commit is contained in:
@@ -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="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;Library&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;DIYLC&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/>
|
||||||
|
<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>
|
||||||
Binary file not shown.
+2
-2
@@ -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();
|
||||||
|
|||||||
+2
-5
@@ -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() {
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -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:
|
||||||
|
|||||||
+7
-11
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user