mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
editable project properties
This commit is contained in:
@@ -7,12 +7,12 @@
|
|||||||
</org.diylc.core.measures.Resistance>
|
</org.diylc.core.measures.Resistance>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>metric</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>lastPath</string>
|
||||||
<boolean>false</boolean>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>default.org.diylc.components.semiconductors.DIL_IC:Value</string>
|
<string>default.org.diylc.components.semiconductors.DIL_IC:Value</string>
|
||||||
|
|||||||
+16
-5
@@ -288,11 +288,10 @@ public interface IPlugInPort {
|
|||||||
void setDefaultPropertyValue(String propertyName, Object value);
|
void setDefaultPropertyValue(String propertyName, Object value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of properties that are mutual for all the selected
|
* @return a list of properties that are mutual for all the selected
|
||||||
* components. Resulting list may be empty if selected components do not
|
* components. Resulting list may be empty if selected components do
|
||||||
* have mutual properties or can be null if the selection is empty.
|
* not have mutual properties or can be null if the selection is
|
||||||
*
|
* empty.
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<PropertyWrapper> getMutualSelectionProperties();
|
List<PropertyWrapper> getMutualSelectionProperties();
|
||||||
|
|
||||||
@@ -306,6 +305,18 @@ public interface IPlugInPort {
|
|||||||
*/
|
*/
|
||||||
void applyPropertiesToSelection(List<PropertyWrapper> properties) throws Exception;
|
void applyPropertiesToSelection(List<PropertyWrapper> properties) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a list of editable properties of the current project.
|
||||||
|
*/
|
||||||
|
List<PropertyWrapper> getProjectProperties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies specified properties to the current project.
|
||||||
|
*
|
||||||
|
* @param properties
|
||||||
|
*/
|
||||||
|
void applyPropertiesToProject(List<PropertyWrapper> properties);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the new component slot. Specified component type will be used to
|
* Sets the new component slot. Specified component type will be used to
|
||||||
* instantiate new component.
|
* instantiate new component.
|
||||||
|
|||||||
+4
-6
@@ -3,8 +3,6 @@ package org.diylc.common;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.diylc.core.IDIYComponent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity class for editable properties extracted from component objects.
|
* Entity class for editable properties extracted from component objects.
|
||||||
* Represents a single editable property together with it's current value.
|
* Represents a single editable property together with it's current value.
|
||||||
@@ -30,9 +28,9 @@ public class PropertyWrapper implements Cloneable {
|
|||||||
this.defaultable = defaultable;
|
this.defaultable = defaultable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFrom(IDIYComponent<?> component) throws IllegalArgumentException,
|
public void readFrom(Object object) throws IllegalArgumentException,
|
||||||
IllegalAccessException, InvocationTargetException {
|
IllegalAccessException, InvocationTargetException {
|
||||||
this.value = getter.invoke(component);
|
this.value = getter.invoke(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void readUniqueFrom(IDIYComponent component)
|
// public void readUniqueFrom(IDIYComponent component)
|
||||||
@@ -44,9 +42,9 @@ public class PropertyWrapper implements Cloneable {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void writeTo(IDIYComponent<?> component) throws IllegalArgumentException,
|
public void writeTo(Object object) throws IllegalArgumentException,
|
||||||
IllegalAccessException, InvocationTargetException {
|
IllegalAccessException, InvocationTargetException {
|
||||||
setter.invoke(component, value);
|
setter.invoke(object, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
+3
-2
@@ -56,8 +56,9 @@ public class DialogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties) {
|
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties,
|
||||||
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties);
|
String title) {
|
||||||
|
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties, title);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -33,8 +33,8 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
private List<PropertyWrapper> properties;
|
private List<PropertyWrapper> properties;
|
||||||
private Set<PropertyWrapper> defaultedProperties;
|
private Set<PropertyWrapper> defaultedProperties;
|
||||||
|
|
||||||
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
|
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) {
|
||||||
super(owner, "Component Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
||||||
|
|
||||||
LOG.debug("Creating property editor for: " + properties);
|
LOG.debug("Creating property editor for: " + properties);
|
||||||
|
|
||||||
@@ -120,8 +120,8 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
return defaultedProperties;
|
return defaultedProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties) {
|
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties, String title) {
|
||||||
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties);
|
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
|
||||||
editor.setVisible(true);
|
editor.setVisible(true);
|
||||||
if (OK.equals(editor.getSelectedButtonCaption())) {
|
if (OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+2
-1
@@ -23,7 +23,8 @@ public enum IconLoader {
|
|||||||
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
|
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
|
||||||
"wrench.png"), Group("group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq(
|
"wrench.png"), Group("group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq(
|
||||||
"faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
|
"faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
|
||||||
"donate.png"), Bug("bug.png"), AboutDialog("about_dialog.png");
|
"donate.png"), Bug("bug.png"), AboutDialog("about_dialog.png"), DocumentEdit(
|
||||||
|
"document_edit.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 765 B |
+28
-22
@@ -166,8 +166,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||||
plugInPort.deleteSelectedComponents();
|
plugInPort.deleteSelectedComponents();
|
||||||
}
|
}
|
||||||
// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(), e.isShiftDown(), e
|
// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
|
||||||
// .isAltDown());
|
// e.isShiftDown(), e
|
||||||
|
// .isAltDown());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addMouseMotionListener(new MouseAdapter() {
|
addMouseMotionListener(new MouseAdapter() {
|
||||||
@@ -187,26 +188,31 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
List<PropertyWrapper> properties = plugInPort
|
List<PropertyWrapper> properties = plugInPort
|
||||||
.getMutualSelectionProperties();
|
.getMutualSelectionProperties();
|
||||||
if (properties != null) {
|
if (properties == null || properties.isEmpty()) {
|
||||||
if (properties.isEmpty()) {
|
properties = plugInPort.getProjectProperties();
|
||||||
|
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||||
} else {
|
.createPropertyEditorDialog(properties, "Edit Project");
|
||||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
editor.setVisible(true);
|
||||||
.createPropertyEditorDialog(properties);
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
editor.setVisible(true);
|
plugInPort.applyPropertiesToProject(properties);
|
||||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
}
|
||||||
try {
|
} else {
|
||||||
plugInPort.applyPropertiesToSelection(properties);
|
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||||
} catch (Exception e1) {
|
.createPropertyEditorDialog(properties, "Edit Selection");
|
||||||
// TODO Auto-generated catch block
|
editor.setVisible(true);
|
||||||
e1.printStackTrace();
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
}
|
try {
|
||||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
plugInPort.applyPropertiesToSelection(properties);
|
||||||
if (property.getValue() != null) {
|
} catch (Exception e1) {
|
||||||
plugInPort.setDefaultPropertyValue(property.getName(),
|
// TODO Auto-generated catch block
|
||||||
property.getValue());
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Save default values.
|
||||||
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
|
if (property.getValue() != null) {
|
||||||
|
plugInPort.setDefaultPropertyValue(property.getName(), property
|
||||||
|
.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
@@ -19,10 +19,14 @@ import org.diylc.common.ComponentSelection;
|
|||||||
import org.diylc.common.EventType;
|
import org.diylc.common.EventType;
|
||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
|
import org.diylc.gui.DialogFactory;
|
||||||
|
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
|
|
||||||
|
import com.diyfever.gui.ButtonDialog;
|
||||||
import com.diyfever.gui.undo.IUndoListener;
|
import com.diyfever.gui.undo.IUndoListener;
|
||||||
import com.diyfever.gui.undo.UndoHandler;
|
import com.diyfever.gui.undo.UndoHandler;
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
@@ -76,6 +80,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
|
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
||||||
|
plugInPort.injectMenuAction(new EditProjectAction(), EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(new GroupAction(), EDIT_TITLE);
|
plugInPort.injectMenuAction(new GroupAction(), EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(new UngroupAction(), EDIT_TITLE);
|
plugInPort.injectMenuAction(new UngroupAction(), EDIT_TITLE);
|
||||||
@@ -232,6 +237,37 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EditProjectAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public EditProjectAction() {
|
||||||
|
super();
|
||||||
|
putValue(AbstractAction.NAME, "Edit Project");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentEdit.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Edit Project triggered");
|
||||||
|
List<PropertyWrapper> properties = plugInPort.getProjectProperties();
|
||||||
|
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
|
||||||
|
properties, "Edit Project");
|
||||||
|
editor.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
|
plugInPort.applyPropertiesToProject(properties);
|
||||||
|
}
|
||||||
|
// Save default values.
|
||||||
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
|
if (property.getValue() != null) {
|
||||||
|
plugInPort.setDefaultPropertyValue(property.getName(), property.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ClipboardOwner
|
// ClipboardOwner
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-2
@@ -109,8 +109,7 @@ public class ComponentProcessor {
|
|||||||
* @param clazz
|
* @param clazz
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public List<PropertyWrapper> extractProperties(Class<?> clazz) {
|
||||||
public List<PropertyWrapper> extractProperties(Class<? extends IDIYComponent> clazz) {
|
|
||||||
if (propertyCache.containsKey(clazz)) {
|
if (propertyCache.containsKey(clazz)) {
|
||||||
return cloner.deepClone(propertyCache.get(clazz));
|
return cloner.deepClone(propertyCache.get(clazz));
|
||||||
}
|
}
|
||||||
|
|||||||
+37
@@ -1017,6 +1017,43 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PropertyWrapper> getProjectProperties() {
|
||||||
|
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||||
|
Project.class);
|
||||||
|
try {
|
||||||
|
for (PropertyWrapper property : properties) {
|
||||||
|
property.readFrom(currentProject);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Could not get project properties", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyPropertiesToProject(List<PropertyWrapper> properties) {
|
||||||
|
LOG.debug(String.format("applyPropertiesToProject(%s)", properties));
|
||||||
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
try {
|
||||||
|
for (PropertyWrapper property : properties) {
|
||||||
|
property.writeTo(currentProject);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Could not apply project properties", e);
|
||||||
|
} finally {
|
||||||
|
// Notify the listeners.
|
||||||
|
if (!oldProject.equals(currentProject)) {
|
||||||
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
|
.deepClone(currentProject), "Edit Project");
|
||||||
|
}
|
||||||
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
|
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||||
|
calculateSelectionDimension());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNewComponentSlot(ComponentType componentType) {
|
public void setNewComponentSlot(ComponentType componentType) {
|
||||||
LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
||||||
|
|||||||
Reference in New Issue
Block a user