added nudge

fixed ctrl/meta handling
This commit is contained in:
bancika
2017-04-24 12:59:56 +02:00
parent 217c0b1b67
commit cd5d5011c6
17 changed files with 220 additions and 51 deletions
@@ -30,7 +30,8 @@ import org.diylc.core.Theme;
* @see IMessageListener * @see IMessageListener
* @see EventType * @see EventType
*/ */
public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, ITemplateProcessor, IBlockProcessor { public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, ITemplateProcessor,
IBlockProcessor {
public static final String ANTI_ALIASING_KEY = "antiAliasing"; public static final String ANTI_ALIASING_KEY = "antiAliasing";
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender"; public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
@@ -198,10 +199,11 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/** /**
* Sets default value for the specified property name for projects. * Sets default value for the specified property name for projects.
* *
* @param clazz class to set defaults to
* @param propertyName display name for property * @param propertyName display name for property
* @param value new default value, must not be null * @param value new default value, must not be null
*/ */
void setProjectDefaultPropertyValue(String propertyName, Object value); void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value);
/** /**
* @return a list of properties that are mutual for all the selected components. Resulting list * @return a list of properties that are mutual for all the selected components. Resulting list
@@ -214,15 +216,18 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/** /**
* @return a list of editable properties of the current project. * @return a list of editable properties of the current project.
*
* @param obj
*/ */
List<PropertyWrapper> getProjectProperties(); List<PropertyWrapper> getProperties(Object obj);
/** /**
* Applies specified properties to the current project. * Applies specified properties to the current project.
* *
* @param obj
* @param properties * @param properties
*/ */
void applyPropertiesToProject(List<PropertyWrapper> properties); void applyProperties(Object obj, List<PropertyWrapper> properties);
/** /**
* Gets the current new component slot. * Gets the current new component slot.
@@ -255,8 +260,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
void setLayerLocked(int layerZOrder, boolean locked); void setLayerLocked(int layerZOrder, boolean locked);
/** /**
* Shows or hides the specified layer. All components within +- 0.5 range will be affected by * Shows or hides the specified layer. All components within +- 0.5 range will be affected by the
* the change as well. * change as well.
* *
* @param layerZOrder * @param layerZOrder
* @param visible * @param visible
@@ -7,6 +7,7 @@ import java.util.List;
import org.diylc.core.ExpansionMode; import org.diylc.core.ExpansionMode;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.measures.Size;
public interface ISelectionProcessor { public interface ISelectionProcessor {
@@ -81,4 +82,13 @@ public interface ISelectionProcessor {
* @return * @return
*/ */
Rectangle2D getSelectionBounds(); Rectangle2D getSelectionBounds();
/**
* Moves selection for the specified offset.
*
* @param xOffset
* @param yOffset
* @param affectStuckComponents
*/
void nudgeSelection(Size xOffset, Size yOffset, boolean affectStuckComponents);
} }
@@ -0,0 +1,37 @@
package org.diylc.core.measures;
import org.diylc.core.annotations.EditableProperty;
public class Nudge {
private Size xOffset;
private Size yOffset;
private boolean affectStuckComponents;
@EditableProperty(name = "X-axis", sortOrder = 1)
public Size getxOffset() {
return xOffset;
}
public void setxOffset(Size xOffset) {
this.xOffset = xOffset;
}
@EditableProperty(name = "Y-axis", sortOrder = 2)
public Size getyOffset() {
return yOffset;
}
public void setyOffset(Size yOffset) {
this.yOffset = yOffset;
}
@EditableProperty(name = "Include stuck", sortOrder = 10)
public boolean getAffectStuckComponents() {
return affectStuckComponents;
}
public void setAffectStuckComponents(boolean affectStuckComponents) {
this.affectStuckComponents = affectStuckComponents;
}
}
@@ -51,6 +51,7 @@ import org.diylc.core.Project;
import org.diylc.core.Template; import org.diylc.core.Template;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.core.annotations.IAutoCreator; import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@@ -854,6 +855,42 @@ public class Presenter implements IPlugInPort {
return totalArea.getBounds2D(); return totalArea.getBounds2D();
} }
@Override
public void nudgeSelection(Size xOffset, Size yOffset, boolean affectStuckComponents) {
if (selectedComponents == null || selectedComponents.isEmpty())
return;
LOG.debug(String.format("nudgeSelection(%s, %s)", xOffset, yOffset));
Map<IDIYComponent<?>, Set<Integer>> controlPointMap = new HashMap<IDIYComponent<?>, Set<Integer>>();
// If there aren't any control points, try to add all the selected
// components with all their control points. That will allow the
// user to drag the whole components.
for (IDIYComponent<?> c : selectedComponents) {
Set<Integer> pointIndices = new HashSet<Integer>();
if (c.getControlPointCount() > 0) {
for (int i = 0; i < c.getControlPointCount(); i++) {
pointIndices.add(i);
}
controlPointMap.put(c, pointIndices);
}
}
if (controlPointMap.isEmpty()) {
return;
}
if (affectStuckComponents) {
includeStuckComponents(controlPointMap);
}
int dx = (int) xOffset.convertToPixels();
int dy = (int) yOffset.convertToPixels();
Project oldProject = currentProject.clone();
moveComponents(controlPointMap, dx, dy, false);
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Move Selection");
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
@Override @Override
public VersionNumber getCurrentVersionNumber() { public VersionNumber getCurrentVersionNumber() {
return CURRENT_VERSION; return CURRENT_VERSION;
@@ -1403,10 +1440,10 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public void setProjectDefaultPropertyValue(String propertyName, Object value) { public void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value) {
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value)); LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s, %s)", clazz.getName(), 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().writeValue(DEFAULTS_KEY_PREFIX + Project.class.getName() + ":" + propertyName, ConfigurationManager.getInstance().writeValue(DEFAULTS_KEY_PREFIX + clazz.getName() + ":" + propertyName,
value); value);
} }
@@ -1849,14 +1886,14 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public List<PropertyWrapper> getProjectProperties() { public List<PropertyWrapper> getProperties(Object object) {
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(Project.class); List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(object.getClass());
try { try {
for (PropertyWrapper property : properties) { for (PropertyWrapper property : properties) {
property.readFrom(currentProject); property.readFrom(object);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not get project properties", e); LOG.error("Could not get object properties", e);
return null; return null;
} }
Collections.sort(properties, ComparatorFactory.getInstance().getDefaultPropertyComparator()); Collections.sort(properties, ComparatorFactory.getInstance().getDefaultPropertyComparator());
@@ -1864,16 +1901,16 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public void applyPropertiesToProject(List<PropertyWrapper> properties) { public void applyProperties(Object obj, List<PropertyWrapper> properties) {
LOG.debug(String.format("applyPropertiesToProject(%s)", properties)); LOG.debug(String.format("applyProperties(%s, %s)", obj, properties));
Project oldProject = currentProject.clone(); Project oldProject = currentProject.clone();
try { try {
for (PropertyWrapper property : properties) { for (PropertyWrapper property : properties) {
property.writeTo(currentProject); property.writeTo(obj);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Could not apply project properties", e); LOG.error("Could not apply properties", e);
view.showMessage("Could not apply changes to the project. Check the log for details.", "Error", view.showMessage("Could not apply changes. Check the log for details.", "Error",
IView.ERROR_MESSAGE); IView.ERROR_MESSAGE);
} finally { } finally {
// Notify the listeners. // Notify the listeners.
Binary file not shown.
Binary file not shown.
@@ -39,7 +39,7 @@ public enum IconLoader {
"messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal( "messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal(
"flip_horizontal.png"), FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png"), PinGrey("pin_grey.png"), PinGreen( "flip_horizontal.png"), FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png"), PinGrey("pin_grey.png"), PinGreen(
"pin_green.png"), CoffeebeanEdit("coffeebean_edit.png"), ApplicationEdit("application_edit.png"), ComponentAdd( "pin_green.png"), CoffeebeanEdit("coffeebean_edit.png"), ApplicationEdit("application_edit.png"), ComponentAdd(
"component_add.png"), History("history.png"), DocumentPlain("document_plain.png"); "component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

@@ -25,7 +25,11 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.core.ExpansionMode; import org.diylc.core.ExpansionMode;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IView; import org.diylc.core.IView;
import org.diylc.core.Project;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.core.measures.Nudge;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.DialogFactory; import org.diylc.swing.gui.DialogFactory;
@@ -162,6 +166,10 @@ public class ActionFactory {
return new BringToFrontAction(plugInPort); return new BringToFrontAction(plugInPort);
} }
public NudgeAction createNudgeAction(IPlugInPort plugInPort) {
return new NudgeAction(plugInPort);
}
// Config actions. // Config actions.
public ConfigAction createConfigAction(IPlugInPort plugInPort, String title, String configKey, boolean defaultValue) { public ConfigAction createConfigAction(IPlugInPort plugInPort, String title, String configKey, boolean defaultValue) {
@@ -204,16 +212,17 @@ public class ActionFactory {
return; return;
} }
plugInPort.createNewProject(); plugInPort.createNewProject();
List<PropertyWrapper> properties = plugInPort.getProjectProperties(); List<PropertyWrapper> properties = plugInPort.getProperties(plugInPort.getCurrentProject());
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project"); PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project", true);
editor.setVisible(true); editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyPropertiesToProject(properties); plugInPort.applyProperties(plugInPort.getCurrentProject(), properties);
} }
// Save default values. // Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) { for (PropertyWrapper property : editor.getDefaultedProperties()) {
if (property.getValue() != null) { if (property.getValue() != null) {
plugInPort.setProjectDefaultPropertyValue(property.getName(), property.getValue()); plugInPort.setDefaultPropertyValue(Project.class, property.getName(), property.getValue());
} }
} }
} }
@@ -795,21 +804,60 @@ public class ActionFactory {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
LOG.info("Edit Project triggered"); LOG.info("Edit Project triggered");
List<PropertyWrapper> properties = plugInPort.getProjectProperties(); List<PropertyWrapper> properties = plugInPort.getProperties(plugInPort.getCurrentProject());
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project"); PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project", true);
editor.setVisible(true); editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyPropertiesToProject(properties); plugInPort.applyProperties(plugInPort.getCurrentProject(), properties);
} }
// Save default values. // Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) { for (PropertyWrapper property : editor.getDefaultedProperties()) {
if (property.getValue() != null) { if (property.getValue() != null) {
plugInPort.setProjectDefaultPropertyValue(property.getName(), property.getValue()); plugInPort.setDefaultPropertyValue(Project.class, property.getName(), property.getValue());
} }
} }
} }
} }
public static class NudgeAction extends AbstractAction {
private static final long serialVersionUID = 1L;
private IPlugInPort plugInPort;
public NudgeAction(IPlugInPort plugInPort) {
super();
this.plugInPort = plugInPort;
putValue(AbstractAction.NAME, "Nudge");
putValue(AbstractAction.SMALL_ICON, IconLoader.FitToSize.getIcon());
putValue(AbstractAction.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
@Override
public void actionPerformed(ActionEvent e) {
LOG.info("Nudge triggered");
Nudge n = new Nudge();
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
if (metric) {
n.setxOffset(new Size(0d, SizeUnit.mm));
n.setyOffset(new Size(0d, SizeUnit.mm));
} else {
n.setxOffset(new Size(0d, SizeUnit.in));
n.setyOffset(new Size(0d, SizeUnit.in));
}
List<PropertyWrapper> properties = plugInPort.getProperties(n);
PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Nudge Selection", false);
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyProperties(n, properties);
plugInPort.nudgeSelection(n.getxOffset(), n.getyOffset(), n.getAffectStuckComponents());
}
}
}
public static class EditSelectionAction extends AbstractAction { public static class EditSelectionAction extends AbstractAction {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -57,12 +57,12 @@ public class DialogFactory {
} }
} }
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties, String title) { public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties, String title, boolean saveDefaults) {
return createPropertyEditorDialog(mainFrame, properties, title); return createPropertyEditorDialog(mainFrame, properties, title, saveDefaults);
} }
public PropertyEditorDialog createPropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) { public PropertyEditorDialog createPropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title, boolean saveDefaults) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title); PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title, saveDefaults);
return editor; return editor;
} }
@@ -221,7 +221,7 @@ public class MainFrame extends JFrame implements ISwingUI {
@Override @Override
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) { public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Selection"); PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Selection", true);
editor.setVisible(true); editor.setVisible(true);
defaultedProperties.addAll(editor.getDefaultedProperties()); defaultedProperties.addAll(editor.getDefaultedProperties());
return ButtonDialog.OK.equals(editor.getSelectedButtonCaption()); return ButtonDialog.OK.equals(editor.getSelectedButtonCaption());
@@ -32,16 +32,17 @@ public class PropertyEditorDialog extends ButtonDialog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static boolean SHOW_DEFAULT_BOXES = true;
private static final String DEFAULT_BOX_TOOLTIP = private static final String DEFAULT_BOX_TOOLTIP =
"<html>If this box is checked application will use the current value as a<br>default when creating new components of the same type</html>"; "<html>If this box is checked application will use the current value as a<br>default when creating new components of the same type</html>";
private List<PropertyWrapper> properties; private List<PropertyWrapper> properties;
private Set<PropertyWrapper> defaultedProperties; private Set<PropertyWrapper> defaultedProperties;
private Component componentToFocus = null; private Component componentToFocus = null;
private boolean saveDefaults;
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) { public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title, boolean saveDefaults) {
super(owner, title, new String[] {ButtonDialog.OK, ButtonDialog.CANCEL}); super(owner, title, new String[] {ButtonDialog.OK, ButtonDialog.CANCEL});
this.saveDefaults = saveDefaults;
LOG.debug("Creating property editor for: " + properties); LOG.debug("Creating property editor for: " + properties);
@@ -112,7 +113,7 @@ public class PropertyEditorDialog extends ButtonDialog {
gbc.fill = GridBagConstraints.NONE; gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0; gbc.weightx = 0;
if (SHOW_DEFAULT_BOXES) { if (saveDefaults) {
editorPanel.add(createDefaultCheckBox(property), gbc); editorPanel.add(createDefaultCheckBox(property), gbc);
} }
} }
@@ -29,6 +29,7 @@ import javax.swing.SwingUtilities;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener; import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.BadPositionException; import org.diylc.common.BadPositionException;
import org.diylc.common.EventType; import org.diylc.common.EventType;
import org.diylc.common.IComponentTransformer; import org.diylc.common.IComponentTransformer;
@@ -71,6 +72,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private ActionFactory.UngroupAction ungroupAction; private ActionFactory.UngroupAction ungroupAction;
private ActionFactory.SendToBackAction sendToBackAction; private ActionFactory.SendToBackAction sendToBackAction;
private ActionFactory.BringToFrontAction bringToFrontAction; private ActionFactory.BringToFrontAction bringToFrontAction;
private ActionFactory.NudgeAction nudgeAction;
private ActionFactory.ExpandSelectionAction expandSelectionAllAction; private ActionFactory.ExpandSelectionAction expandSelectionAllAction;
private ActionFactory.ExpandSelectionAction expandSelectionImmediateAction; private ActionFactory.ExpandSelectionAction expandSelectionImmediateAction;
private ActionFactory.ExpandSelectionAction expandSelectionSameTypeAction; private ActionFactory.ExpandSelectionAction expandSelectionSameTypeAction;
@@ -148,6 +150,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
getExpandSelectionSameTypeAction().setEnabled(enabled); getExpandSelectionSameTypeAction().setEnabled(enabled);
getGroupAction().setEnabled(enabled); getGroupAction().setEnabled(enabled);
getUngroupAction().setEnabled(enabled); getUngroupAction().setEnabled(enabled);
getNudgeAction().setEnabled(enabled);
getSendToBackAction().setEnabled(enabled); getSendToBackAction().setEnabled(enabled);
getBringToFrontAction().setEnabled(enabled); getBringToFrontAction().setEnabled(enabled);
getRotateClockwiseAction().setEnabled(enabled); getRotateClockwiseAction().setEnabled(enabled);
@@ -169,7 +172,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (plugInPort.keyPressed(e.getKeyCode(), e.isControlDown() || e.isMetaDown(), e.isShiftDown(), e.isAltDown())) { if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown())) {
e.consume(); e.consume();
} }
} }
@@ -180,7 +183,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint())); canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
plugInPort.mouseMoved(e.getPoint(), e.isControlDown() || e.isMetaDown(), e.isShiftDown(), e.isAltDown()); plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown());
} }
}); });
@@ -188,7 +191,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown() || e.isMetaDown(), e.isShiftDown(), plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
e.isAltDown(), e.getClickCount()); e.isAltDown(), e.getClickCount());
} }
}); });
@@ -218,7 +221,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
public void mouseWheelMoved(MouseWheelEvent e) { public void mouseWheelMoved(MouseWheelEvent e) {
boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false); boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
if (wheelZoom || e.isControlDown() || e.isMetaDown()) { if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
// disable scrolling // disable scrolling
scrollPane.setWheelScrollingEnabled(false); scrollPane.setWheelScrollingEnabled(false);
@@ -319,6 +322,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
transformMenu.add(getMirrorHorizontallyAction()); transformMenu.add(getMirrorHorizontallyAction());
transformMenu.add(getMirrorVerticallyAction()); transformMenu.add(getMirrorVerticallyAction());
transformMenu.addSeparator(); transformMenu.addSeparator();
transformMenu.add(getNudgeAction());
transformMenu.addSeparator();
transformMenu.add(getSendToBackAction()); transformMenu.add(getSendToBackAction());
transformMenu.add(getBringToFrontAction()); transformMenu.add(getBringToFrontAction());
transformMenu.addSeparator(); transformMenu.addSeparator();
@@ -492,6 +497,13 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
return bringToFrontAction; return bringToFrontAction;
} }
public ActionFactory.NudgeAction getNudgeAction() {
if (nudgeAction == null) {
nudgeAction = ActionFactory.getInstance().createNudgeAction(plugInPort);
}
return nudgeAction;
}
public ActionFactory.ExpandSelectionAction getExpandSelectionAllAction() { public ActionFactory.ExpandSelectionAction getExpandSelectionAllAction() {
if (expandSelectionAllAction == null) { if (expandSelectionAllAction == null) {
expandSelectionAllAction = ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.ALL); expandSelectionAllAction = ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.ALL);
@@ -10,6 +10,7 @@ import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
@@ -27,6 +28,7 @@ import javax.swing.event.ChangeListener;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper;
import org.diylc.swing.gui.components.HTMLTextArea; import org.diylc.swing.gui.components.HTMLTextArea;
import org.diylc.swingframework.ButtonDialog; import org.diylc.swingframework.ButtonDialog;
import org.diylc.utils.KeywordExtractor; import org.diylc.utils.KeywordExtractor;
@@ -204,10 +206,12 @@ public class UploadDialog extends ButtonDialog {
if (nameField == null) { if (nameField == null) {
nameField = new JTextField(); nameField = new JTextField();
List<PropertyWrapper> props = plugInPort.getProperties(plugInPort.getCurrentProject());
// set default from the project // set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++) for (int i = 0; i < props.size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Title")) if (props.get(i).getName().equals("Title"))
nameField.setText(plugInPort.getProjectProperties().get(i).getValue().toString()); nameField.setText(props.get(i).getValue().toString());
} }
return nameField; return nameField;
} }
@@ -232,11 +236,13 @@ public class UploadDialog extends ButtonDialog {
if (descriptionArea == null) { if (descriptionArea == null) {
descriptionArea = new HTMLTextArea(); descriptionArea = new HTMLTextArea();
List<PropertyWrapper> props = plugInPort.getProperties(plugInPort.getCurrentProject());
// set default from the project // set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++) for (int i = 0; i < props.size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Description")) if (props.get(i).getName().equals("Description"))
try { try {
descriptionArea.setText(plugInPort.getProjectProperties().get(i).getValue().toString()); descriptionArea.setText(props.get(i).getValue().toString());
} catch (Exception e) { } catch (Exception e) {
} }
descriptionArea.setBorder(null); descriptionArea.setBorder(null);
@@ -327,7 +327,7 @@ public class ResultsScrollPanel extends JScrollPane {
List<PropertyWrapper> projectProperties = CloudPresenter.Instance.getProjectProperties(project); List<PropertyWrapper> projectProperties = CloudPresenter.Instance.getProjectProperties(project);
PropertyEditorDialog editor = PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(cloudUI.getOwnerFrame(), projectProperties, DialogFactory.getInstance().createPropertyEditorDialog(cloudUI.getOwnerFrame(), projectProperties,
"Edit Published Project"); "Edit Published Project", true);
editor.setVisible(true); editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
// Update the project // Update the project
@@ -41,6 +41,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
private ActionFactory.UngroupAction ungroupAction; private ActionFactory.UngroupAction ungroupAction;
private ActionFactory.SendToBackAction sendToBackAction; private ActionFactory.SendToBackAction sendToBackAction;
private ActionFactory.BringToFrontAction bringToFrontAction; private ActionFactory.BringToFrontAction bringToFrontAction;
private ActionFactory.NudgeAction nudgeAction;
private ActionFactory.RenumberAction renumberXAxisAction; private ActionFactory.RenumberAction renumberXAxisAction;
private ActionFactory.RenumberAction renumberYAxisAction; private ActionFactory.RenumberAction renumberYAxisAction;
private ActionFactory.ExpandSelectionAction expandSelectionAllAction; private ActionFactory.ExpandSelectionAction expandSelectionAllAction;
@@ -145,6 +146,13 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
return bringToFrontAction; return bringToFrontAction;
} }
public ActionFactory.NudgeAction getNudgeAction() {
if (nudgeAction == null) {
nudgeAction = ActionFactory.getInstance().createNudgeAction(plugInPort);
}
return nudgeAction;
}
public ActionFactory.RenumberAction getRenumberXAxisAction() { public ActionFactory.RenumberAction getRenumberXAxisAction() {
if (renumberXAxisAction == null) { if (renumberXAxisAction == null) {
renumberXAxisAction = ActionFactory.getInstance().createRenumberAction(plugInPort, true); renumberXAxisAction = ActionFactory.getInstance().createRenumberAction(plugInPort, true);
@@ -249,6 +257,8 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
swingUI.injectMenuAction(getMirrorHorizontallyAction(), TRANSFORM_TITLE); swingUI.injectMenuAction(getMirrorHorizontallyAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(getMirrorVerticallyAction(), TRANSFORM_TITLE); swingUI.injectMenuAction(getMirrorVerticallyAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE); swingUI.injectMenuAction(null, TRANSFORM_TITLE);
swingUI.injectMenuAction(getNudgeAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE);
swingUI.injectMenuAction(getSendToBackAction(), TRANSFORM_TITLE); swingUI.injectMenuAction(getSendToBackAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(getBringToFrontAction(), TRANSFORM_TITLE); swingUI.injectMenuAction(getBringToFrontAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE); swingUI.injectMenuAction(null, TRANSFORM_TITLE);
@@ -306,6 +316,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
getExpandSelectionAllAction().setEnabled(enabled); getExpandSelectionAllAction().setEnabled(enabled);
getExpandSelectionImmediateAction().setEnabled(enabled); getExpandSelectionImmediateAction().setEnabled(enabled);
getExpandSelectionSameTypeAction().setEnabled(enabled); getExpandSelectionSameTypeAction().setEnabled(enabled);
getNudgeAction().setEnabled(enabled);
getUngroupAction().setEnabled(enabled); getUngroupAction().setEnabled(enabled);
getSendToBackAction().setEnabled(enabled); getSendToBackAction().setEnabled(enabled);
getBringToFrontAction().setEnabled(enabled); getBringToFrontAction().setEnabled(enabled);
@@ -22,6 +22,7 @@ import javax.swing.SwingUtilities;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
@@ -68,7 +69,7 @@ public class ComponentButtonFactory {
} }
} }
// Ctrl appends selection // Ctrl appends selection
if (e.isControlDown() || e.isMetaDown()) { if (Utils.isMac() ? e.isMetaDown() : e.isControlDown()) {
newSelection.addAll(plugInPort.getSelectedComponents()); newSelection.addAll(plugInPort.getSelectedComponents());
} }
plugInPort.updateSelection(newSelection); plugInPort.updateSelection(newSelection);
@@ -82,7 +83,8 @@ public class ComponentButtonFactory {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
plugInPort.keyPressed(e.getKeyCode(), e.isControlDown() || e.isMetaDown(), e.isShiftDown(), e.isAltDown()); plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
e.isAltDown());
} }
}); });
return button; return button;