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
Binary file not shown.
@@ -39,7 +39,7 @@ public enum IconLoader {
"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(
"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;
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.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.core.Project;
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.presenter.Presenter;
import org.diylc.swing.gui.DialogFactory;
@@ -162,6 +166,10 @@ public class ActionFactory {
return new BringToFrontAction(plugInPort);
}
public NudgeAction createNudgeAction(IPlugInPort plugInPort) {
return new NudgeAction(plugInPort);
}
// Config actions.
public ConfigAction createConfigAction(IPlugInPort plugInPort, String title, String configKey, boolean defaultValue) {
@@ -204,16 +212,17 @@ public class ActionFactory {
return;
}
plugInPort.createNewProject();
List<PropertyWrapper> properties = plugInPort.getProjectProperties();
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project");
List<PropertyWrapper> properties = plugInPort.getProperties(plugInPort.getCurrentProject());
PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project", true);
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyPropertiesToProject(properties);
plugInPort.applyProperties(plugInPort.getCurrentProject(), properties);
}
// Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) {
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
public void actionPerformed(ActionEvent e) {
LOG.info("Edit Project triggered");
List<PropertyWrapper> properties = plugInPort.getProjectProperties();
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project");
List<PropertyWrapper> properties = plugInPort.getProperties(plugInPort.getCurrentProject());
PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Project", true);
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
plugInPort.applyPropertiesToProject(properties);
plugInPort.applyProperties(plugInPort.getCurrentProject(), properties);
}
// Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) {
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 {
private static final long serialVersionUID = 1L;
@@ -57,12 +57,12 @@ public class DialogFactory {
}
}
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties, String title) {
return createPropertyEditorDialog(mainFrame, properties, title);
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties, String title, boolean saveDefaults) {
return createPropertyEditorDialog(mainFrame, properties, title, saveDefaults);
}
public PropertyEditorDialog createPropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
public PropertyEditorDialog createPropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title, boolean saveDefaults) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title, saveDefaults);
return editor;
}
@@ -221,7 +221,7 @@ public class MainFrame extends JFrame implements ISwingUI {
@Override
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);
defaultedProperties.addAll(editor.getDefaultedProperties());
return ButtonDialog.OK.equals(editor.getSelectedButtonCaption());
@@ -32,16 +32,17 @@ public class PropertyEditorDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
public static boolean SHOW_DEFAULT_BOXES = true;
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>";
private List<PropertyWrapper> properties;
private Set<PropertyWrapper> defaultedProperties;
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});
this.saveDefaults = saveDefaults;
LOG.debug("Creating property editor for: " + properties);
@@ -112,7 +113,7 @@ public class PropertyEditorDialog extends ButtonDialog {
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0;
if (SHOW_DEFAULT_BOXES) {
if (saveDefaults) {
editorPanel.add(createDefaultCheckBox(property), gbc);
}
}
@@ -29,6 +29,7 @@ import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.BadPositionException;
import org.diylc.common.EventType;
import org.diylc.common.IComponentTransformer;
@@ -71,6 +72,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private ActionFactory.UngroupAction ungroupAction;
private ActionFactory.SendToBackAction sendToBackAction;
private ActionFactory.BringToFrontAction bringToFrontAction;
private ActionFactory.NudgeAction nudgeAction;
private ActionFactory.ExpandSelectionAction expandSelectionAllAction;
private ActionFactory.ExpandSelectionAction expandSelectionImmediateAction;
private ActionFactory.ExpandSelectionAction expandSelectionSameTypeAction;
@@ -148,6 +150,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
getExpandSelectionSameTypeAction().setEnabled(enabled);
getGroupAction().setEnabled(enabled);
getUngroupAction().setEnabled(enabled);
getNudgeAction().setEnabled(enabled);
getSendToBackAction().setEnabled(enabled);
getBringToFrontAction().setEnabled(enabled);
getRotateClockwiseAction().setEnabled(enabled);
@@ -169,7 +172,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override
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();
}
}
@@ -180,7 +183,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override
public void mouseMoved(MouseEvent e) {
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
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());
}
});
@@ -218,7 +221,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
public void mouseWheelMoved(MouseWheelEvent e) {
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
scrollPane.setWheelScrollingEnabled(false);
@@ -319,6 +322,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
transformMenu.add(getMirrorHorizontallyAction());
transformMenu.add(getMirrorVerticallyAction());
transformMenu.addSeparator();
transformMenu.add(getNudgeAction());
transformMenu.addSeparator();
transformMenu.add(getSendToBackAction());
transformMenu.add(getBringToFrontAction());
transformMenu.addSeparator();
@@ -492,6 +497,13 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
return bringToFrontAction;
}
public ActionFactory.NudgeAction getNudgeAction() {
if (nudgeAction == null) {
nudgeAction = ActionFactory.getInstance().createNudgeAction(plugInPort);
}
return nudgeAction;
}
public ActionFactory.ExpandSelectionAction getExpandSelectionAllAction() {
if (expandSelectionAllAction == null) {
expandSelectionAllAction = ActionFactory.getInstance().createExpandSelectionAction(plugInPort, ExpansionMode.ALL);
@@ -10,6 +10,7 @@ import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.EnumSet;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
@@ -27,6 +28,7 @@ import javax.swing.event.ChangeListener;
import org.diylc.common.DrawOption;
import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper;
import org.diylc.swing.gui.components.HTMLTextArea;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.utils.KeywordExtractor;
@@ -204,10 +206,12 @@ public class UploadDialog extends ButtonDialog {
if (nameField == null) {
nameField = new JTextField();
List<PropertyWrapper> props = plugInPort.getProperties(plugInPort.getCurrentProject());
// set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Title"))
nameField.setText(plugInPort.getProjectProperties().get(i).getValue().toString());
for (int i = 0; i < props.size(); i++)
if (props.get(i).getName().equals("Title"))
nameField.setText(props.get(i).getValue().toString());
}
return nameField;
}
@@ -232,11 +236,13 @@ public class UploadDialog extends ButtonDialog {
if (descriptionArea == null) {
descriptionArea = new HTMLTextArea();
List<PropertyWrapper> props = plugInPort.getProperties(plugInPort.getCurrentProject());
// set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Description"))
for (int i = 0; i < props.size(); i++)
if (props.get(i).getName().equals("Description"))
try {
descriptionArea.setText(plugInPort.getProjectProperties().get(i).getValue().toString());
descriptionArea.setText(props.get(i).getValue().toString());
} catch (Exception e) {
}
descriptionArea.setBorder(null);
@@ -327,7 +327,7 @@ public class ResultsScrollPanel extends JScrollPane {
List<PropertyWrapper> projectProperties = CloudPresenter.Instance.getProjectProperties(project);
PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(cloudUI.getOwnerFrame(), projectProperties,
"Edit Published Project");
"Edit Published Project", true);
editor.setVisible(true);
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
// Update the project
@@ -41,6 +41,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
private ActionFactory.UngroupAction ungroupAction;
private ActionFactory.SendToBackAction sendToBackAction;
private ActionFactory.BringToFrontAction bringToFrontAction;
private ActionFactory.NudgeAction nudgeAction;
private ActionFactory.RenumberAction renumberXAxisAction;
private ActionFactory.RenumberAction renumberYAxisAction;
private ActionFactory.ExpandSelectionAction expandSelectionAllAction;
@@ -144,6 +145,13 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
}
return bringToFrontAction;
}
public ActionFactory.NudgeAction getNudgeAction() {
if (nudgeAction == null) {
nudgeAction = ActionFactory.getInstance().createNudgeAction(plugInPort);
}
return nudgeAction;
}
public ActionFactory.RenumberAction getRenumberXAxisAction() {
if (renumberXAxisAction == null) {
@@ -249,6 +257,8 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
swingUI.injectMenuAction(getMirrorHorizontallyAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(getMirrorVerticallyAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE);
swingUI.injectMenuAction(getNudgeAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE);
swingUI.injectMenuAction(getSendToBackAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(getBringToFrontAction(), TRANSFORM_TITLE);
swingUI.injectMenuAction(null, TRANSFORM_TITLE);
@@ -306,6 +316,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
getExpandSelectionAllAction().setEnabled(enabled);
getExpandSelectionImmediateAction().setEnabled(enabled);
getExpandSelectionSameTypeAction().setEnabled(enabled);
getNudgeAction().setEnabled(enabled);
getUngroupAction().setEnabled(enabled);
getSendToBackAction().setEnabled(enabled);
getBringToFrontAction().setEnabled(enabled);
@@ -22,6 +22,7 @@ import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
@@ -68,7 +69,7 @@ public class ComponentButtonFactory {
}
}
// Ctrl appends selection
if (e.isControlDown() || e.isMetaDown()) {
if (Utils.isMac() ? e.isMetaDown() : e.isControlDown()) {
newSelection.addAll(plugInPort.getSelectedComponents());
}
plugInPort.updateSelection(newSelection);
@@ -82,7 +83,8 @@ public class ComponentButtonFactory {
@Override
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;