mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added helper methods for config reader
This commit is contained in:
+2
-2
@@ -50,7 +50,7 @@ public class DialogFactory {
|
||||
public void initialize(JFrame mainFrame) {
|
||||
this.mainFrame = mainFrame;
|
||||
String lastDirectoryPath = (String) ConfigurationManager.getInstance()
|
||||
.getConfigurationItem(PATH_KEY);
|
||||
.readString(PATH_KEY, null);
|
||||
if (lastDirectoryPath != null) {
|
||||
lastDirectory = new File(lastDirectoryPath);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class DialogFactory {
|
||||
fileChooser.setAccessory(null);
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
lastDirectory = fileChooser.getCurrentDirectory();
|
||||
ConfigurationManager.getInstance().setConfigurationItem(PATH_KEY,
|
||||
ConfigurationManager.getInstance().writeValue(PATH_KEY,
|
||||
lastDirectory.getAbsolutePath());
|
||||
if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
|
||||
return fileChooser.getSelectedFile();
|
||||
|
||||
+2
-5
@@ -48,11 +48,8 @@ public class CanvasPlugin implements IPlugIn {
|
||||
scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort),
|
||||
new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in)
|
||||
.convertToPixels());
|
||||
Boolean metric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem(
|
||||
Presenter.METRIC_KEY);
|
||||
if (metric == null) {
|
||||
metric = true;
|
||||
}
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(
|
||||
Presenter.METRIC_KEY, true);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.addUnitListener(new IRulerListener() {
|
||||
|
||||
|
||||
+3
-6
@@ -207,17 +207,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
break;
|
||||
case SELECTION_SIZE_CHANGED:
|
||||
Point2D size = (Point2D) params[0];
|
||||
Boolean isMetric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem(
|
||||
Presenter.METRIC_KEY);
|
||||
if (isMetric == null) {
|
||||
isMetric = true;
|
||||
}
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(
|
||||
Presenter.METRIC_KEY, true);
|
||||
if (size == null) {
|
||||
getSizeLabel().setText("N/A");
|
||||
} else {
|
||||
getSizeLabel().setText(
|
||||
sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY())
|
||||
+ (isMetric ? " cm" : " in"));
|
||||
+ (metric ? " cm" : " in"));
|
||||
}
|
||||
break;
|
||||
case SLOT_CHANGED:
|
||||
|
||||
+7
-11
@@ -836,7 +836,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (IDIYComponent component : selectedComponents) {
|
||||
String className = component.getClass().getName();
|
||||
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
||||
ConfigurationManager.getInstance().setConfigurationItem(
|
||||
ConfigurationManager.getInstance().writeValue(
|
||||
DEFAULTS_KEY + className + ":" + propertyName, value);
|
||||
}
|
||||
}
|
||||
@@ -845,13 +845,13 @@ public class Presenter implements IPlugInPort {
|
||||
public void setProjectDefaultPropertyValue(String propertyName, Object value) {
|
||||
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value));
|
||||
LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName);
|
||||
ConfigurationManager.getInstance().setConfigurationItem(
|
||||
ConfigurationManager.getInstance().writeValue(
|
||||
DEFAULTS_KEY + Project.class.getName() + ":" + propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
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,
|
||||
calculateSelectionDimension());
|
||||
}
|
||||
@@ -957,11 +957,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (selectedComponents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Boolean isMetric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem(
|
||||
METRIC_KEY);
|
||||
if (isMetric == null) {
|
||||
isMetric = true;
|
||||
}
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(METRIC_KEY, true);
|
||||
Area area = new Area();
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
Area componentArea = componentAreaMap.get(component);
|
||||
@@ -973,7 +969,7 @@ public class Presenter implements IPlugInPort {
|
||||
double height = area.getBounds2D().getHeight();
|
||||
width /= Constants.PIXELS_PER_INCH;
|
||||
height /= Constants.PIXELS_PER_INCH;
|
||||
if (isMetric) {
|
||||
if (metric) {
|
||||
width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
|
||||
height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
|
||||
}
|
||||
@@ -1082,8 +1078,8 @@ public class Presenter implements IPlugInPort {
|
||||
object.getClass());
|
||||
// Override with default values if available.
|
||||
for (PropertyWrapper property : properties) {
|
||||
Object defaultValue = ConfigurationManager.getInstance().getConfigurationItem(
|
||||
DEFAULTS_KEY + object.getClass().getName() + ":" + property.getName());
|
||||
Object defaultValue = ConfigurationManager.getInstance().readObject(
|
||||
DEFAULTS_KEY + object.getClass().getName() + ":" + property.getName(), null);
|
||||
if (defaultValue != null) {
|
||||
property.setValue(cloner.deepClone(defaultValue));
|
||||
property.writeTo(object);
|
||||
|
||||
Reference in New Issue
Block a user