editable project properties

This commit is contained in:
bancika
2011-01-15 10:31:07 +00:00
parent dd4080accb
commit c677e98cad
11 changed files with 135 additions and 46 deletions
@@ -7,12 +7,12 @@
</org.diylc.core.measures.Resistance>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry>
<string>metric</string>
<boolean>false</boolean>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry>
<string>default.org.diylc.components.semiconductors.DIL_IC:Value</string>
@@ -288,11 +288,10 @@ public interface IPlugInPort {
void setDefaultPropertyValue(String propertyName, Object value);
/**
* Returns a list of properties that are mutual for all the selected
* components. Resulting list may be empty if selected components do not
* have mutual properties or can be null if the selection is empty.
*
* @return
* @return a list of properties that are mutual for all the selected
* components. Resulting list may be empty if selected components do
* not have mutual properties or can be null if the selection is
* empty.
*/
List<PropertyWrapper> getMutualSelectionProperties();
@@ -306,6 +305,18 @@ public interface IPlugInPort {
*/
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
* instantiate new component.
@@ -3,8 +3,6 @@ package org.diylc.common;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.diylc.core.IDIYComponent;
/**
* Entity class for editable properties extracted from component objects.
* Represents a single editable property together with it's current value.
@@ -30,9 +28,9 @@ public class PropertyWrapper implements Cloneable {
this.defaultable = defaultable;
}
public void readFrom(IDIYComponent<?> component) throws IllegalArgumentException,
public void readFrom(Object object) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
this.value = getter.invoke(component);
this.value = getter.invoke(object);
}
// 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 {
setter.invoke(component, value);
setter.invoke(object, value);
}
public String getName() {
@@ -56,8 +56,9 @@ public class DialogFactory {
}
}
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties) {
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties);
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties,
String title) {
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties, title);
return editor;
}
@@ -33,8 +33,8 @@ public class PropertyEditorDialog extends ButtonDialog {
private List<PropertyWrapper> properties;
private Set<PropertyWrapper> defaultedProperties;
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
super(owner, "Component Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) {
super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
LOG.debug("Creating property editor for: " + properties);
@@ -120,8 +120,8 @@ public class PropertyEditorDialog extends ButtonDialog {
return defaultedProperties;
}
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties);
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties, String title) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
editor.setVisible(true);
if (OK.equals(editor.getSelectedButtonCaption())) {
return true;
@@ -23,7 +23,8 @@ public enum IconLoader {
"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(
"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;
Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

@@ -166,8 +166,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
plugInPort.deleteSelectedComponents();
}
// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(), e.isShiftDown(), e
// .isAltDown());
// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
// e.isShiftDown(), e
// .isAltDown());
}
});
addMouseMotionListener(new MouseAdapter() {
@@ -187,26 +188,31 @@ class CanvasPanel extends JComponent implements Autoscroll {
if (e.getClickCount() == 2) {
List<PropertyWrapper> properties = plugInPort
.getMutualSelectionProperties();
if (properties != null) {
if (properties.isEmpty()) {
} else {
PropertyEditorDialog editor = DialogFactory.getInstance()
.createPropertyEditorDialog(properties);
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
try {
plugInPort.applyPropertiesToSelection(properties);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (PropertyWrapper property : editor.getDefaultedProperties()) {
if (property.getValue() != null) {
plugInPort.setDefaultPropertyValue(property.getName(),
property.getValue());
}
}
if (properties == null || properties.isEmpty()) {
properties = plugInPort.getProjectProperties();
PropertyEditorDialog editor = DialogFactory.getInstance()
.createPropertyEditorDialog(properties, "Edit Project");
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyPropertiesToProject(properties);
}
} else {
PropertyEditorDialog editor = DialogFactory.getInstance()
.createPropertyEditorDialog(properties, "Edit Selection");
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
try {
plugInPort.applyPropertiesToSelection(properties);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
// Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) {
if (property.getValue() != null) {
plugInPort.setDefaultPropertyValue(property.getName(), property
.getValue());
}
}
}
@@ -19,10 +19,14 @@ import org.diylc.common.ComponentSelection;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.gui.DialogFactory;
import org.diylc.gui.editor.PropertyEditorDialog;
import org.diylc.images.IconLoader;
import com.diyfever.gui.ButtonDialog;
import com.diyfever.gui.undo.IUndoListener;
import com.diyfever.gui.undo.UndoHandler;
import com.rits.cloning.Cloner;
@@ -76,6 +80,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
plugInPort.injectMenuAction(null, EDIT_TITLE);
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
plugInPort.injectMenuAction(new EditProjectAction(), EDIT_TITLE);
plugInPort.injectMenuAction(null, EDIT_TITLE);
plugInPort.injectMenuAction(new GroupAction(), 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
@Override
@@ -109,8 +109,7 @@ public class ComponentProcessor {
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public List<PropertyWrapper> extractProperties(Class<? extends IDIYComponent> clazz) {
public List<PropertyWrapper> extractProperties(Class<?> clazz) {
if (propertyCache.containsKey(clazz)) {
return cloner.deepClone(propertyCache.get(clazz));
}
@@ -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
public void setNewComponentSlot(ComponentType componentType) {
LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null