mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
apply template to existing components
do not mess up selection on right click popup menu improvements
This commit is contained in:
Binary file not shown.
Binary file not shown.
+3
-2
@@ -37,8 +37,9 @@ public enum IconLoader {
|
||||
"document_edit.png"), EditComponent("edit_component.png"), Size(
|
||||
"size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort(
|
||||
"sort.png"), ElementsSelection("elements_selection.png"), BranchAdd(
|
||||
"branch_add.png"), Briefcase_Add("briefcase_add.png"), RotateCW(
|
||||
"rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png");
|
||||
"branch_add.png"), BriefcaseAdd("briefcase_add.png"), BriefcaseInto(
|
||||
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW(
|
||||
"rotate_ccw.png"), ElementInto("element_into.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 951 B |
+24
-11
@@ -22,6 +22,7 @@ import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
@@ -61,7 +62,8 @@ public class ActionFactory {
|
||||
return new OpenAction(plugInPort, swingUI);
|
||||
}
|
||||
|
||||
public ImportAction createImportAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||
public ImportAction createImportAction(IPlugInPort plugInPort,
|
||||
ISwingUI swingUI) {
|
||||
return new ImportAction(plugInPort, swingUI);
|
||||
}
|
||||
|
||||
@@ -286,15 +288,17 @@ public class ActionFactory {
|
||||
this.presenter = new Presenter(new IView() {
|
||||
|
||||
@Override
|
||||
public int showConfirmDialog(String message, String title, int optionType,
|
||||
int messageType) {
|
||||
public int showConfirmDialog(String message, String title,
|
||||
int optionType, int messageType) {
|
||||
return JOptionPane.showConfirmDialog(null, message, title,
|
||||
optionType, messageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
JOptionPane.showMessageDialog(null, message, title, messageType);
|
||||
public void showMessage(String message, String title,
|
||||
int messageType) {
|
||||
JOptionPane.showMessageDialog(null, message, title,
|
||||
messageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,14 +307,16 @@ public class ActionFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
|
||||
public boolean editProperties(List<PropertyWrapper> properties,
|
||||
Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
putValue(AbstractAction.NAME, "Import");
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_I, ActionEvent.CTRL_MASK));
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.ElementInto.getIcon());
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.ElementInto
|
||||
.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -328,9 +334,12 @@ public class ActionFactory {
|
||||
LOG.debug("Opening from " + file.getAbsolutePath());
|
||||
// Load project in temp presenter
|
||||
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
// Grab all components and paste them into the main presenter
|
||||
plugInPort.pasteComponents(presenter.getCurrentProject().getComponents());
|
||||
// Cleanup components in the temp presenter, don't need them anymore
|
||||
// Grab all components and paste them into the main
|
||||
// presenter
|
||||
plugInPort.pasteComponents(presenter
|
||||
.getCurrentProject().getComponents());
|
||||
// Cleanup components in the temp presenter, don't need
|
||||
// them anymore
|
||||
presenter.selectAll();
|
||||
presenter.deleteSelectedComponents();
|
||||
return null;
|
||||
@@ -911,7 +920,7 @@ public class ActionFactory {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
putValue(AbstractAction.NAME, "Save as Template");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Briefcase_Add
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.BriefcaseAdd
|
||||
.getIcon());
|
||||
}
|
||||
|
||||
@@ -1006,6 +1015,8 @@ public class ActionFactory {
|
||||
this.plugInPort = plugInPort;
|
||||
putValue(AbstractAction.NAME, "Send Backward");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Back.getIcon());
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_DOWN, ActionEvent.ALT_MASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1026,6 +1037,8 @@ public class ActionFactory {
|
||||
this.plugInPort = plugInPort;
|
||||
putValue(AbstractAction.NAME, "Bring Forward");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Front.getIcon());
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_UP, ActionEvent.ALT_MASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+93
-35
@@ -23,6 +23,7 @@ import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
@@ -33,6 +34,7 @@ import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.images.IconLoader;
|
||||
@@ -53,6 +55,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private JPopupMenu popupMenu;
|
||||
private JMenu selectionMenu;
|
||||
private JMenu expandMenu;
|
||||
private JMenu applyTemplateMenu;
|
||||
|
||||
private ActionFactory.CutAction cutAction;
|
||||
private ActionFactory.CopyAction copyAction;
|
||||
@@ -104,37 +107,52 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (plugInPort.getNewComponentTypeSlot() == null
|
||||
&& e.isPopupTrigger()) {
|
||||
// Enable actions.
|
||||
boolean enabled = !plugInPort.getSelectedComponents()
|
||||
.isEmpty();
|
||||
getCutAction().setEnabled(enabled);
|
||||
getCopyAction().setEnabled(enabled);
|
||||
try {
|
||||
getPasteAction()
|
||||
.setEnabled(
|
||||
clipboard
|
||||
.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||
} catch (Exception ex) {
|
||||
getPasteAction().setEnabled(false);
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e
|
||||
.isControlDown(), e.isShiftDown(), e.isAltDown(), e
|
||||
.getClickCount());
|
||||
// Invoke the rest of the code later so we get the chance to
|
||||
// process selection messages.
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugInPort.getNewComponentTypeSlot() == null
|
||||
&& e.isPopupTrigger()) {
|
||||
// Enable actions.
|
||||
boolean enabled = !plugInPort
|
||||
.getSelectedComponents().isEmpty();
|
||||
getCutAction().setEnabled(enabled);
|
||||
getCopyAction().setEnabled(enabled);
|
||||
try {
|
||||
getPasteAction()
|
||||
.setEnabled(
|
||||
clipboard
|
||||
.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||
} catch (Exception ex) {
|
||||
getPasteAction().setEnabled(false);
|
||||
}
|
||||
getEditSelectionAction().setEnabled(enabled);
|
||||
getDeleteSelectionAction().setEnabled(enabled);
|
||||
getExpandSelectionAllAction().setEnabled(
|
||||
enabled);
|
||||
getExpandSelectionImmediateAction().setEnabled(
|
||||
enabled);
|
||||
getExpandSelectionSameTypeAction().setEnabled(
|
||||
enabled);
|
||||
getGroupAction().setEnabled(enabled);
|
||||
getUngroupAction().setEnabled(enabled);
|
||||
getSendToBackAction().setEnabled(enabled);
|
||||
getBringToFrontAction().setEnabled(enabled);
|
||||
|
||||
getSaveAsTemplateAction().setEnabled(
|
||||
plugInPort.getSelectedComponents()
|
||||
.size() == 1);
|
||||
|
||||
showPopupAt(e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
getEditSelectionAction().setEnabled(enabled);
|
||||
getDeleteSelectionAction().setEnabled(enabled);
|
||||
getExpandSelectionAllAction().setEnabled(enabled);
|
||||
getExpandSelectionImmediateAction().setEnabled(enabled);
|
||||
getExpandSelectionSameTypeAction().setEnabled(enabled);
|
||||
getGroupAction().setEnabled(enabled);
|
||||
getUngroupAction().setEnabled(enabled);
|
||||
getSendToBackAction().setEnabled(enabled);
|
||||
getBringToFrontAction().setEnabled(enabled);
|
||||
|
||||
getSaveAsTemplateAction().setEnabled(
|
||||
plugInPort.getSelectedComponents().size() == 1);
|
||||
|
||||
showPopupAt(e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -163,9 +181,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e
|
||||
.isControlDown(), e.isShiftDown(), e.isAltDown(), e
|
||||
.getClickCount());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -234,6 +250,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private void showPopupAt(int x, int y) {
|
||||
updateSelectionMenu(x, y);
|
||||
updateApplyTemplateMenu();
|
||||
getPopupMenu().show(canvasPanel, x, y);
|
||||
}
|
||||
|
||||
@@ -255,6 +272,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
popupMenu.add(getSendToBackAction());
|
||||
popupMenu.add(getBringToFrontAction());
|
||||
popupMenu.add(getSaveAsTemplateAction());
|
||||
popupMenu.add(getApplyTemplateMenu());
|
||||
popupMenu.add(getExpandMenu());
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.add(ActionFactory.getInstance().createEditProjectAction(
|
||||
@@ -282,6 +300,14 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
return expandMenu;
|
||||
}
|
||||
|
||||
public JMenu getApplyTemplateMenu() {
|
||||
if (applyTemplateMenu == null) {
|
||||
applyTemplateMenu = new JMenu("Apply Template");
|
||||
applyTemplateMenu.setIcon(IconLoader.BriefcaseInto.getIcon());
|
||||
}
|
||||
return applyTemplateMenu;
|
||||
}
|
||||
|
||||
private void updateSelectionMenu(int x, int y) {
|
||||
getSelectionMenu().removeAll();
|
||||
for (IDIYComponent<?> component : plugInPort
|
||||
@@ -302,6 +328,36 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateApplyTemplateMenu() {
|
||||
getApplyTemplateMenu().removeAll();
|
||||
List<Template> templates = null;
|
||||
|
||||
try {
|
||||
templates = plugInPort.getTemplatesForSelection();
|
||||
} catch (Exception e) {
|
||||
LOG.info("Could not get templates for selection");
|
||||
getApplyTemplateMenu().setEnabled(false);
|
||||
}
|
||||
|
||||
if (templates == null)
|
||||
return;
|
||||
|
||||
getApplyTemplateMenu().setEnabled(templates.size() > 0);
|
||||
|
||||
for (Template template : templates) {
|
||||
JMenuItem item = new JMenuItem(template.getName());
|
||||
final Template finalTemplate = template;
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
plugInPort.applyTemplateToSelection(finalTemplate);
|
||||
}
|
||||
});
|
||||
getApplyTemplateMenu().add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionFactory.CutAction getCutAction() {
|
||||
if (cutAction == null) {
|
||||
cutAction = ActionFactory.getInstance().createCutAction(plugInPort,
|
||||
@@ -344,14 +400,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
public ActionFactory.RotateSelectionAction getRotateClockwiseAction() {
|
||||
if (rotateClockwiseAction == null) {
|
||||
rotateClockwiseAction = ActionFactory.getInstance().createRotateSelectionAction(plugInPort, 1);
|
||||
rotateClockwiseAction = ActionFactory.getInstance()
|
||||
.createRotateSelectionAction(plugInPort, 1);
|
||||
}
|
||||
return rotateClockwiseAction;
|
||||
}
|
||||
|
||||
public ActionFactory.RotateSelectionAction getRotateCounterclockwiseAction() {
|
||||
if (rotateCounterclockwiseAction == null) {
|
||||
rotateCounterclockwiseAction = ActionFactory.getInstance().createRotateSelectionAction(plugInPort, -1);
|
||||
rotateCounterclockwiseAction = ActionFactory.getInstance()
|
||||
.createRotateSelectionAction(plugInPort, -1);
|
||||
}
|
||||
return rotateCounterclockwiseAction;
|
||||
}
|
||||
|
||||
+5
-2
@@ -234,10 +234,10 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||
swingUI.injectMenuAction(getDeleteSelectionAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getRotateClockwiseAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getRotateCounterclockwiseAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getGroupAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getUngroupAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getSendToBackAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getBringToFrontAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getGroupAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getUngroupAction(), EDIT_TITLE);
|
||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||
swingUI.injectMenuAction(getSaveAsTemplateAction(), EDIT_TITLE);
|
||||
swingUI.injectSubmenu(RENUMBER_TITLE, IconLoader.Sort.getIcon(),
|
||||
@@ -298,6 +298,9 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||
getUngroupAction().setEnabled(enabled);
|
||||
getSendToBackAction().setEnabled(enabled);
|
||||
getBringToFrontAction().setEnabled(enabled);
|
||||
getRotateClockwiseAction().setEnabled(enabled);
|
||||
getRotateCounterclockwiseAction().setEnabled(enabled);
|
||||
getSaveAsTemplateAction().setEnabled(enabled);
|
||||
}
|
||||
|
||||
// ClipboardOwner
|
||||
|
||||
@@ -1194,6 +1194,10 @@
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Moving multiple components doesn't honor snap to grid OFF setting</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Do not change selection on right click when right clicking on one of the selected components</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Ability to import existing DIY files into a project</description>
|
||||
@@ -1202,6 +1206,14 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added primitive shapes - ellipse, polygon and (rounded) rectangle</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added tri-pad board (thanks Hauke!)</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Apply template to one or more existing components from the context menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Moved all schematic symbols to a dedicated category</description>
|
||||
|
||||
Reference in New Issue
Block a user