mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
refactored actions out
added right click menu
This commit is contained in:
+736
@@ -0,0 +1,736 @@
|
|||||||
|
package org.diylc.swing;
|
||||||
|
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.ClipboardOwner;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.print.PrinterException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.images.IconLoader;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
|
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||||
|
import org.diylc.swing.plugins.file.BomDialog;
|
||||||
|
import org.diylc.swing.plugins.file.BomEntry;
|
||||||
|
import org.diylc.swing.plugins.file.BomMaker;
|
||||||
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
|
||||||
|
import com.diyfever.gui.ButtonDialog;
|
||||||
|
import com.diyfever.gui.IDrawingProvider;
|
||||||
|
import com.diyfever.gui.export.DrawingExporter;
|
||||||
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
|
public class ActionFactory {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(ActionFactory.class);
|
||||||
|
|
||||||
|
private static ActionFactory instance;
|
||||||
|
private static Cloner cloner = new Cloner();
|
||||||
|
|
||||||
|
public static ActionFactory getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ActionFactory();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// File menu actions.
|
||||||
|
|
||||||
|
public NewAction createNewAction(IPlugInPort plugInPort) {
|
||||||
|
return new NewAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenAction createOpenAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
return new OpenAction(plugInPort, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaveAction createSaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
return new SaveAction(plugInPort, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaveAsAction createSaveAsAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
return new SaveAsAction(plugInPort, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreateBomAction createBomAction(IPlugInPort plugInPort) {
|
||||||
|
return new CreateBomAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportPDFAction createExportPDFAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
|
||||||
|
return new ExportPDFAction(drawingProvider, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportPNGAction createExportPNGAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
|
||||||
|
return new ExportPNGAction(drawingProvider, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrintAction createPrintAction(IDrawingProvider drawingProvider) {
|
||||||
|
return new PrintAction(drawingProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExitAction createExitAction(IPlugInPort plugInPort) {
|
||||||
|
return new ExitAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit menu actions.
|
||||||
|
|
||||||
|
public CutAction createCutAction(IPlugInPort plugInPort, Clipboard clipboard,
|
||||||
|
ClipboardOwner clipboardOwner) {
|
||||||
|
return new CutAction(plugInPort, clipboard, clipboardOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CopyAction createCopyAction(IPlugInPort plugInPort, Clipboard clipboard,
|
||||||
|
ClipboardOwner clipboardOwner) {
|
||||||
|
return new CopyAction(plugInPort, clipboard, clipboardOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasteAction createPasteAction(IPlugInPort plugInPort, Clipboard clipboard) {
|
||||||
|
return new PasteAction(plugInPort, clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectAllAction createSelectAllAction(IPlugInPort plugInPort) {
|
||||||
|
return new SelectAllAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupAction createGroupAction(IPlugInPort plugInPort) {
|
||||||
|
return new GroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UngroupAction createUngroupAction(IPlugInPort plugInPort) {
|
||||||
|
return new UngroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditProjectAction createEditProjectAction(IPlugInPort plugInPort) {
|
||||||
|
return new EditProjectAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditSelectionAction createEditSelectionAction(IPlugInPort plugInPort) {
|
||||||
|
return new EditSelectionAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteSelectionAction createDeleteSelectionAction(IPlugInPort plugInPort) {
|
||||||
|
return new DeleteSelectionAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
// File menu actions.
|
||||||
|
|
||||||
|
public static class NewAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public NewAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "New");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("NewAction triggered");
|
||||||
|
if (!plugInPort.allowFileAction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugInPort.createNewProject();
|
||||||
|
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.setProjectDefaultPropertyValue(property.getName(), property
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OpenAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
public OpenAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
putValue(AbstractAction.NAME, "Open");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.FolderOut.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("OpenAction triggered");
|
||||||
|
if (!plugInPort.allowFileAction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final File file = DialogFactory.getInstance().showOpenDialog(
|
||||||
|
FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
|
||||||
|
null);
|
||||||
|
if (file != null) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Opening from " + file.getAbsolutePath());
|
||||||
|
plugInPort.loadProjectFromFile(file.getAbsolutePath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error",
|
||||||
|
ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SaveAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
public SaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
putValue(AbstractAction.NAME, "Save");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("SaveAction triggered");
|
||||||
|
if (plugInPort.getCurrentFileName() == null) {
|
||||||
|
final File file = DialogFactory.getInstance().showSaveDialog(
|
||||||
|
FileFilterEnum.DIY.getFilter(), null,
|
||||||
|
FileFilterEnum.DIY.getExtensions()[0], null);
|
||||||
|
if (file != null) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Saving to " + file.getAbsolutePath());
|
||||||
|
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not save to file. " + e.getMessage(),
|
||||||
|
"Error", ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Saving to " + plugInPort.getCurrentFileName());
|
||||||
|
plugInPort.saveProjectToFile(plugInPort.getCurrentFileName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
|
||||||
|
ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SaveAsAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
public SaveAsAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
putValue(AbstractAction.NAME, "Save As");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("SaveAsAction triggered");
|
||||||
|
final File file = DialogFactory.getInstance().showSaveDialog(
|
||||||
|
FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
|
||||||
|
null);
|
||||||
|
if (file != null) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Saving to " + file.getAbsolutePath());
|
||||||
|
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
|
||||||
|
ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CreateBomAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public CreateBomAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Create B.O.M.");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.BOM.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("CreateBomAction triggered");
|
||||||
|
List<BomEntry> bom = BomMaker.getInstance().createBom(
|
||||||
|
plugInPort.getCurrentProject().getComponents());
|
||||||
|
BomDialog dialog = DialogFactory.getInstance().createBomDialog(bom);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExportPDFAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IDrawingProvider drawingProvider;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
public ExportPDFAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.drawingProvider = drawingProvider;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
putValue(AbstractAction.NAME, "Export to PDF");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("ExportPDFAction triggered");
|
||||||
|
final File file = DialogFactory.getInstance().showSaveDialog(
|
||||||
|
FileFilterEnum.PDF.getFilter(), null, FileFilterEnum.PDF.getExtensions()[0],
|
||||||
|
null);
|
||||||
|
if (file != null) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Exporting to " + file.getAbsolutePath());
|
||||||
|
DrawingExporter.getInstance().exportPDF(
|
||||||
|
ExportPDFAction.this.drawingProvider, file);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not export to PDF. " + e.getMessage(), "Error",
|
||||||
|
ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExportPNGAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IDrawingProvider drawingProvider;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
public ExportPNGAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.drawingProvider = drawingProvider;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
putValue(AbstractAction.NAME, "Export to PNG");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Image.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("ExportPNGAction triggered");
|
||||||
|
final File file = DialogFactory.getInstance().showSaveDialog(
|
||||||
|
FileFilterEnum.PNG.getFilter(), null, FileFilterEnum.PNG.getExtensions()[0],
|
||||||
|
null);
|
||||||
|
if (file != null) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
LOG.debug("Exporting to " + file.getAbsolutePath());
|
||||||
|
DrawingExporter.getInstance().exportPNG(
|
||||||
|
ExportPNGAction.this.drawingProvider, file);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
swingUI.showMessage("Could not export to PNG. " + e.getMessage(), "Error",
|
||||||
|
ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PrintAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IDrawingProvider drawingProvider;
|
||||||
|
|
||||||
|
public PrintAction(IDrawingProvider drawingProvider) {
|
||||||
|
super();
|
||||||
|
this.drawingProvider = drawingProvider;
|
||||||
|
putValue(AbstractAction.NAME, "Print...");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("ExportPNGAction triggered");
|
||||||
|
try {
|
||||||
|
DrawingExporter.getInstance().print(this.drawingProvider);
|
||||||
|
} catch (PrinterException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExitAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public ExitAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Exit");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Exit.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (plugInPort.allowFileAction()) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit menu actions.
|
||||||
|
|
||||||
|
public static class CutAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private Clipboard clipboard;
|
||||||
|
private ClipboardOwner clipboardOwner;
|
||||||
|
|
||||||
|
public CutAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.clipboard = clipboard;
|
||||||
|
this.clipboardOwner = clipboardOwner;
|
||||||
|
putValue(AbstractAction.NAME, "Cut");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Cut triggered");
|
||||||
|
clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
|
||||||
|
.getSelectedComponents())), clipboardOwner);
|
||||||
|
plugInPort.deleteSelectedComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CopyAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private Clipboard clipboard;
|
||||||
|
private ClipboardOwner clipboardOwner;
|
||||||
|
|
||||||
|
public CopyAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.clipboard = clipboard;
|
||||||
|
this.clipboardOwner = clipboardOwner;
|
||||||
|
putValue(AbstractAction.NAME, "Copy");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Copy triggered");
|
||||||
|
clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
|
||||||
|
.getSelectedComponents())), clipboardOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PasteAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private Clipboard clipboard;
|
||||||
|
|
||||||
|
public PasteAction(IPlugInPort plugInPort, Clipboard clipboard) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.clipboard = clipboard;
|
||||||
|
putValue(AbstractAction.NAME, "Paste");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Paste triggered");
|
||||||
|
try {
|
||||||
|
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
||||||
|
.getData(ComponentTransferable.listFlavor);
|
||||||
|
plugInPort.pasteComponents(cloner.deepClone(components));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Coule not paste.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SelectAllAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public SelectAllAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Select All");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Select All triggered");
|
||||||
|
plugInPort.selectAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GroupAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public GroupAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Group Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Group.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Group Selection triggered");
|
||||||
|
plugInPort.groupSelectedComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class UngroupAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public UngroupAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Ungroup Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Ungroup.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Ungroup Selection triggered");
|
||||||
|
plugInPort.ungroupSelectedComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EditProjectAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public EditProjectAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
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.setProjectDefaultPropertyValue(property.getName(), property
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EditSelectionAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public EditSelectionAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Edit Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.EditComponent.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Edit Selection triggered");
|
||||||
|
List<PropertyWrapper> properties = plugInPort.getMutualSelectionProperties();
|
||||||
|
if (properties == null || properties.isEmpty()) {
|
||||||
|
LOG.info("Nothing to edit");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
|
||||||
|
properties, "Edit Selection");
|
||||||
|
editor.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
|
plugInPort.applyPropertiesToSelection(properties);
|
||||||
|
}
|
||||||
|
// Save default values.
|
||||||
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
|
if (property.getValue() != null) {
|
||||||
|
plugInPort.setSelectionDefaultPropertyValue(property.getName(), property
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DeleteSelectionAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public DeleteSelectionAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Delete Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Delete.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Delete Selection triggered");
|
||||||
|
plugInPort.deleteSelectedComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -39,7 +39,7 @@ import org.diylc.images.IconLoader;
|
|||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
||||||
import org.diylc.swing.plugins.clipboard.EditMenuPlugin;
|
import org.diylc.swing.plugins.edit.EditMenuPlugin;
|
||||||
import org.diylc.swing.plugins.file.FileMenuPlugin;
|
import org.diylc.swing.plugins.file.FileMenuPlugin;
|
||||||
import org.diylc.swing.plugins.help.HelpMenuPlugin;
|
import org.diylc.swing.plugins.help.HelpMenuPlugin;
|
||||||
import org.diylc.swing.plugins.layers.LayersMenuPlugin;
|
import org.diylc.swing.plugins.layers.LayersMenuPlugin;
|
||||||
|
|||||||
+12
-13
@@ -16,7 +16,6 @@ import java.awt.dnd.DropTarget;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.KeyAdapter;
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -155,18 +154,18 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addKeyListener(new KeyAdapter() {
|
// addKeyListener(new KeyAdapter() {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void keyPressed(KeyEvent e) {
|
// public void keyPressed(KeyEvent e) {
|
||||||
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
// if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||||
plugInPort.deleteSelectedComponents();
|
// plugInPort.deleteSelectedComponents();
|
||||||
}
|
// }
|
||||||
// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
|
// // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
|
||||||
// e.isShiftDown(), e
|
// // e.isShiftDown(), e
|
||||||
// .isAltDown());
|
// // .isAltDown());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
addMouseMotionListener(new MouseAdapter() {
|
addMouseMotionListener(new MouseAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+120
-4
@@ -2,11 +2,17 @@ package org.diylc.swing.plugins.canvas;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.ClipboardOwner;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.event.MouseWheelListener;
|
import java.awt.event.MouseWheelListener;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -17,14 +23,16 @@ import org.diylc.common.IPlugInPort;
|
|||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
|
import org.diylc.swing.ActionFactory;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||||
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
|
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
|
||||||
|
|
||||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||||
import com.diyfever.gui.ruler.IRulerListener;
|
import com.diyfever.gui.ruler.IRulerListener;
|
||||||
import com.diyfever.gui.ruler.RulerScrollPane;
|
import com.diyfever.gui.ruler.RulerScrollPane;
|
||||||
|
|
||||||
public class CanvasPlugin implements IPlugIn {
|
public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||||
|
|
||||||
@@ -32,12 +40,24 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
|
|
||||||
private RulerScrollPane scrollPane;
|
private RulerScrollPane scrollPane;
|
||||||
private CanvasPanel canvasPanel;
|
private CanvasPanel canvasPanel;
|
||||||
private IPlugInPort plugInPort;
|
private JPopupMenu popupMenu;
|
||||||
|
|
||||||
|
private ActionFactory.CutAction cutAction;
|
||||||
|
private ActionFactory.CopyAction copyAction;
|
||||||
|
private ActionFactory.PasteAction pasteAction;
|
||||||
|
private ActionFactory.EditSelectionAction editSelectionAction;
|
||||||
|
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
||||||
|
private ActionFactory.GroupAction groupAction;
|
||||||
|
private ActionFactory.UngroupAction ungroupAction;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
private ISwingUI swingUI;
|
private ISwingUI swingUI;
|
||||||
|
|
||||||
|
private Clipboard clipboard;
|
||||||
|
|
||||||
public CanvasPlugin(ISwingUI swingUI) {
|
public CanvasPlugin(ISwingUI swingUI) {
|
||||||
this.swingUI = swingUI;
|
this.swingUI = swingUI;
|
||||||
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,6 +73,32 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
public CanvasPanel getCanvasPanel() {
|
public CanvasPanel getCanvasPanel() {
|
||||||
if (canvasPanel == null) {
|
if (canvasPanel == null) {
|
||||||
canvasPanel = new CanvasPanel(plugInPort);
|
canvasPanel = new CanvasPanel(plugInPort);
|
||||||
|
canvasPanel.addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
if (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);
|
||||||
|
getGroupAction().setEnabled(enabled);
|
||||||
|
getUngroupAction().setEnabled(enabled);
|
||||||
|
|
||||||
|
getPopupMenu().show(canvasPanel, e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return canvasPanel;
|
return canvasPanel;
|
||||||
}
|
}
|
||||||
@@ -102,6 +148,70 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
return scrollPane;
|
return scrollPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JPopupMenu getPopupMenu() {
|
||||||
|
if (popupMenu == null) {
|
||||||
|
popupMenu = new JPopupMenu();
|
||||||
|
popupMenu.add(getCutAction());
|
||||||
|
popupMenu.add(getCopyAction());
|
||||||
|
popupMenu.add(getPasteAction());
|
||||||
|
popupMenu.addSeparator();
|
||||||
|
popupMenu.add(getEditSelectionAction());
|
||||||
|
popupMenu.add(getDeleteSelectionAction());
|
||||||
|
popupMenu.add(getGroupAction());
|
||||||
|
popupMenu.add(getUngroupAction());
|
||||||
|
}
|
||||||
|
return popupMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.CutAction getCutAction() {
|
||||||
|
if (cutAction == null) {
|
||||||
|
cutAction = ActionFactory.getInstance().createCutAction(plugInPort, clipboard, this);
|
||||||
|
}
|
||||||
|
return cutAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.CopyAction getCopyAction() {
|
||||||
|
if (copyAction == null) {
|
||||||
|
copyAction = ActionFactory.getInstance().createCopyAction(plugInPort, clipboard, this);
|
||||||
|
}
|
||||||
|
return copyAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.PasteAction getPasteAction() {
|
||||||
|
if (pasteAction == null) {
|
||||||
|
pasteAction = ActionFactory.getInstance().createPasteAction(plugInPort, clipboard);
|
||||||
|
}
|
||||||
|
return pasteAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
||||||
|
if (editSelectionAction == null) {
|
||||||
|
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
||||||
|
}
|
||||||
|
return editSelectionAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
|
||||||
|
if (deleteSelectionAction == null) {
|
||||||
|
deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(plugInPort);
|
||||||
|
}
|
||||||
|
return deleteSelectionAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.GroupAction getGroupAction() {
|
||||||
|
if (groupAction == null) {
|
||||||
|
groupAction = ActionFactory.getInstance().createGroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
return groupAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.UngroupAction getUngroupAction() {
|
||||||
|
if (ungroupAction == null) {
|
||||||
|
ungroupAction = ActionFactory.getInstance().createUngroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
return ungroupAction;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT);
|
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT);
|
||||||
@@ -147,8 +257,8 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Causes ruler scroll pane to refresh by sending a fake mouse moved
|
* Causes ruler scroll pane to refresh by sending a fake mouse moved message
|
||||||
* message to the canvasPanel.
|
* to the canvasPanel.
|
||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
MouseEvent event = new MouseEvent(canvasPanel, MouseEvent.MOUSE_MOVED, System
|
MouseEvent event = new MouseEvent(canvasPanel, MouseEvent.MOUSE_MOVED, System
|
||||||
@@ -157,4 +267,10 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
0, false);
|
0, false);
|
||||||
canvasPanel.dispatchEvent(event);
|
canvasPanel.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-328
@@ -1,328 +0,0 @@
|
|||||||
package org.diylc.swing.plugins.clipboard;
|
|
||||||
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.datatransfer.Clipboard;
|
|
||||||
import java.awt.datatransfer.ClipboardOwner;
|
|
||||||
import java.awt.datatransfer.FlavorEvent;
|
|
||||||
import java.awt.datatransfer.FlavorListener;
|
|
||||||
import java.awt.datatransfer.Transferable;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
import javax.swing.KeyStroke;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
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.images.IconLoader;
|
|
||||||
import org.diylc.swing.ISwingUI;
|
|
||||||
import org.diylc.swing.gui.DialogFactory;
|
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
|
||||||
|
|
||||||
import com.diyfever.gui.ButtonDialog;
|
|
||||||
import com.diyfever.gui.undo.IUndoListener;
|
|
||||||
import com.diyfever.gui.undo.UndoHandler;
|
|
||||||
import com.rits.cloning.Cloner;
|
|
||||||
|
|
||||||
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(EditMenuPlugin.class);
|
|
||||||
|
|
||||||
private static final String EDIT_TITLE = "Edit";
|
|
||||||
private IPlugInPort plugInPort;
|
|
||||||
|
|
||||||
private Clipboard clipboard;
|
|
||||||
private Cloner cloner;
|
|
||||||
|
|
||||||
private CutAction cutAction;
|
|
||||||
private CopyAction copyAction;
|
|
||||||
private PasteAction pasteAction;
|
|
||||||
|
|
||||||
private UndoHandler<Project> undoHandler;
|
|
||||||
|
|
||||||
public EditMenuPlugin(ISwingUI swingUI) {
|
|
||||||
SecurityManager securityManager = System.getSecurityManager();
|
|
||||||
if (securityManager != null) {
|
|
||||||
try {
|
|
||||||
securityManager.checkSystemClipboardAccess();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
||||||
cloner = new Cloner();
|
|
||||||
undoHandler = new UndoHandler<Project>(new IUndoListener<Project>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(Project currentState) {
|
|
||||||
plugInPort.loadProject(currentState, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
clipboard.addFlavorListener(new FlavorListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flavorsChanged(FlavorEvent e) {
|
|
||||||
refreshActions();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
swingUI.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(undoHandler.getRedoAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
|
||||||
cutAction = new CutAction();
|
|
||||||
swingUI.injectMenuAction(cutAction, EDIT_TITLE);
|
|
||||||
copyAction = new CopyAction();
|
|
||||||
swingUI.injectMenuAction(copyAction, EDIT_TITLE);
|
|
||||||
pasteAction = new PasteAction();
|
|
||||||
swingUI.injectMenuAction(pasteAction, EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(new EditSelectionAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(new EditProjectAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(new GroupAction(), EDIT_TITLE);
|
|
||||||
swingUI.injectMenuAction(new UngroupAction(), EDIT_TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connect(IPlugInPort plugInPort) {
|
|
||||||
this.plugInPort = plugInPort;
|
|
||||||
refreshActions();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
|
||||||
return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processMessage(EventType eventType, Object... params) {
|
|
||||||
switch (eventType) {
|
|
||||||
case SELECTION_CHANGED:
|
|
||||||
refreshActions();
|
|
||||||
break;
|
|
||||||
case PROJECT_MODIFIED:
|
|
||||||
undoHandler.stateChanged((Project) params[0], (Project) params[1], (String) params[2]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshActions() {
|
|
||||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
|
||||||
cutAction.setEnabled(enabled);
|
|
||||||
copyAction.setEnabled(enabled);
|
|
||||||
try {
|
|
||||||
pasteAction.setEnabled(clipboard
|
|
||||||
.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
|
||||||
} catch (Exception e) {
|
|
||||||
pasteAction.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CutAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public CutAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Cut");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Cut triggered");
|
|
||||||
clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
|
|
||||||
.getSelectedComponents())), EditMenuPlugin.this);
|
|
||||||
plugInPort.deleteSelectedComponents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CopyAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public CopyAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Copy");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Copy triggered");
|
|
||||||
clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
|
|
||||||
.getSelectedComponents())), EditMenuPlugin.this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PasteAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public PasteAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Paste");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Paste triggered");
|
|
||||||
try {
|
|
||||||
List<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
|
||||||
.getData(ComponentTransferable.listFlavor);
|
|
||||||
plugInPort.pasteComponents(cloner.deepClone(components));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.error("Coule not paste.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SelectAllAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public SelectAllAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Select All");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Select All triggered");
|
|
||||||
plugInPort.selectAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class GroupAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public GroupAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Group Selection");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Group.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Group Selection triggered");
|
|
||||||
plugInPort.groupSelectedComponents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class UngroupAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public UngroupAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Ungroup Selection");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Ungroup.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Ungroup Selection triggered");
|
|
||||||
plugInPort.ungroupSelectedComponents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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.setProjectDefaultPropertyValue(property.getName(), property
|
|
||||||
.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EditSelectionAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public EditSelectionAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Edit Selection");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.EditComponent.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Edit Selection triggered");
|
|
||||||
List<PropertyWrapper> properties = plugInPort.getMutualSelectionProperties();
|
|
||||||
if (properties == null || properties.isEmpty()) {
|
|
||||||
LOG.info("Nothing to edit");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
|
|
||||||
properties, "Edit Selection");
|
|
||||||
editor.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
|
||||||
plugInPort.applyPropertiesToSelection(properties);
|
|
||||||
}
|
|
||||||
// Save default values.
|
|
||||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
|
||||||
if (property.getValue() != null) {
|
|
||||||
plugInPort.setSelectionDefaultPropertyValue(property.getName(), property
|
|
||||||
.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClipboardOwner
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
|
||||||
refreshActions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package org.diylc.swing.plugins.clipboard;
|
package org.diylc.swing.plugins.edit;
|
||||||
|
|
||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
+176
@@ -0,0 +1,176 @@
|
|||||||
|
package org.diylc.swing.plugins.edit;
|
||||||
|
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.ClipboardOwner;
|
||||||
|
import java.awt.datatransfer.FlavorEvent;
|
||||||
|
import java.awt.datatransfer.FlavorListener;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.diylc.common.EventType;
|
||||||
|
import org.diylc.common.IPlugIn;
|
||||||
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.core.Project;
|
||||||
|
import org.diylc.swing.ActionFactory;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
|
||||||
|
import com.diyfever.gui.undo.IUndoListener;
|
||||||
|
import com.diyfever.gui.undo.UndoHandler;
|
||||||
|
|
||||||
|
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||||
|
|
||||||
|
private static final String EDIT_TITLE = "Edit";
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
private Clipboard clipboard;
|
||||||
|
|
||||||
|
private ActionFactory.CutAction cutAction;
|
||||||
|
private ActionFactory.CopyAction copyAction;
|
||||||
|
private ActionFactory.PasteAction pasteAction;
|
||||||
|
private ActionFactory.EditSelectionAction editSelectionAction;
|
||||||
|
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
||||||
|
private ActionFactory.GroupAction groupAction;
|
||||||
|
private ActionFactory.UngroupAction ungroupAction;
|
||||||
|
|
||||||
|
private UndoHandler<Project> undoHandler;
|
||||||
|
|
||||||
|
public EditMenuPlugin(ISwingUI swingUI) {
|
||||||
|
// SecurityManager securityManager = System.getSecurityManager();
|
||||||
|
// if (securityManager != null) {
|
||||||
|
// try {
|
||||||
|
// securityManager.checkSystemClipboardAccess();
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
undoHandler = new UndoHandler<Project>(new IUndoListener<Project>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(Project currentState) {
|
||||||
|
plugInPort.loadProject(currentState, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clipboard.addFlavorListener(new FlavorListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flavorsChanged(FlavorEvent e) {
|
||||||
|
refreshActions();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionFactory actionFactory = ActionFactory.getInstance();
|
||||||
|
|
||||||
|
swingUI.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(undoHandler.getRedoAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getCutAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getCopyAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getPasteAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createSelectAllAction(plugInPort), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getEditSelectionAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getDeleteSelectionAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getGroupAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getUngroupAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createEditProjectAction(plugInPort), EDIT_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.CutAction getCutAction() {
|
||||||
|
if (cutAction == null) {
|
||||||
|
cutAction = ActionFactory.getInstance().createCutAction(plugInPort, clipboard, this);
|
||||||
|
}
|
||||||
|
return cutAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.CopyAction getCopyAction() {
|
||||||
|
if (copyAction == null) {
|
||||||
|
copyAction = ActionFactory.getInstance().createCopyAction(plugInPort, clipboard, this);
|
||||||
|
}
|
||||||
|
return copyAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.PasteAction getPasteAction() {
|
||||||
|
if (pasteAction == null) {
|
||||||
|
pasteAction = ActionFactory.getInstance().createPasteAction(plugInPort, clipboard);
|
||||||
|
}
|
||||||
|
return pasteAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
||||||
|
if (editSelectionAction == null) {
|
||||||
|
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
||||||
|
}
|
||||||
|
return editSelectionAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
|
||||||
|
if (deleteSelectionAction == null) {
|
||||||
|
deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(
|
||||||
|
plugInPort);
|
||||||
|
}
|
||||||
|
return deleteSelectionAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.GroupAction getGroupAction() {
|
||||||
|
if (groupAction == null) {
|
||||||
|
groupAction = ActionFactory.getInstance().createGroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
return groupAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionFactory.UngroupAction getUngroupAction() {
|
||||||
|
if (ungroupAction == null) {
|
||||||
|
ungroupAction = ActionFactory.getInstance().createUngroupAction(plugInPort);
|
||||||
|
}
|
||||||
|
return ungroupAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(IPlugInPort plugInPort) {
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
refreshActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
|
return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processMessage(EventType eventType, Object... params) {
|
||||||
|
switch (eventType) {
|
||||||
|
case SELECTION_CHANGED:
|
||||||
|
refreshActions();
|
||||||
|
break;
|
||||||
|
case PROJECT_MODIFIED:
|
||||||
|
undoHandler.stateChanged((Project) params[0], (Project) params[1], (String) params[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshActions() {
|
||||||
|
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||||
|
getCutAction().setEnabled(enabled);
|
||||||
|
getCopyAction().setEnabled(enabled);
|
||||||
|
try {
|
||||||
|
getPasteAction().setEnabled(
|
||||||
|
clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||||
|
} catch (Exception e) {
|
||||||
|
getPasteAction().setEnabled(false);
|
||||||
|
}
|
||||||
|
getEditSelectionAction().setEnabled(enabled);
|
||||||
|
getDeleteSelectionAction().setEnabled(enabled);
|
||||||
|
getGroupAction().setEnabled(enabled);
|
||||||
|
getUngroupAction().setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClipboardOwner
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||||
|
refreshActions();
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
-363
@@ -1,27 +1,13 @@
|
|||||||
package org.diylc.swing.plugins.file;
|
package org.diylc.swing.plugins.file;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.print.PrinterException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
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.ITask;
|
|
||||||
import org.diylc.common.PropertyWrapper;
|
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
|
import org.diylc.swing.ActionFactory;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swing.gui.DialogFactory;
|
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
|
||||||
|
|
||||||
import com.diyfever.gui.ButtonDialog;
|
|
||||||
import com.diyfever.gui.IDrawingProvider;
|
|
||||||
import com.diyfever.gui.export.DrawingExporter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point class for File management utilities.
|
* Entry point class for File management utilities.
|
||||||
@@ -30,12 +16,9 @@ import com.diyfever.gui.export.DrawingExporter;
|
|||||||
*/
|
*/
|
||||||
public class FileMenuPlugin implements IPlugIn {
|
public class FileMenuPlugin implements IPlugIn {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(FileMenuPlugin.class);
|
|
||||||
|
|
||||||
private static final String FILE_TITLE = "File";
|
private static final String FILE_TITLE = "File";
|
||||||
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
||||||
|
|
||||||
private IPlugInPort plugInPort;
|
|
||||||
private ProjectDrawingProvider drawingProvider;
|
private ProjectDrawingProvider drawingProvider;
|
||||||
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
||||||
|
|
||||||
@@ -48,355 +31,30 @@ public class FileMenuPlugin implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(IPlugInPort plugInPort) {
|
public void connect(IPlugInPort plugInPort) {
|
||||||
this.plugInPort = plugInPort;
|
|
||||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false);
|
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false);
|
||||||
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
|
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
|
||||||
|
|
||||||
swingUI.injectMenuAction(new NewAction(), FILE_TITLE);
|
ActionFactory actionFactory = ActionFactory.getInstance();
|
||||||
swingUI.injectMenuAction(new OpenAction(), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createNewAction(plugInPort), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new SaveAction(), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createOpenAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new SaveAsAction(), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createSaveAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createSaveAsAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new ExportPDFAction(drawingProvider), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createExportPDFAction(drawingProvider, swingUI),
|
||||||
swingUI.injectMenuAction(new ExportPNGAction(drawingProvider), FILE_TITLE);
|
FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new PrintAction(drawingProvider), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createExportPNGAction(drawingProvider, swingUI),
|
||||||
|
FILE_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createPrintAction(drawingProvider), FILE_TITLE);
|
||||||
swingUI.injectSubmenu(TRACE_MASK_TITLE, IconLoader.TraceMask.getIcon(), FILE_TITLE);
|
swingUI.injectSubmenu(TRACE_MASK_TITLE, IconLoader.TraceMask.getIcon(), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new ExportPDFAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
swingUI.injectMenuAction(actionFactory.createExportPDFAction(traceMaskDrawingProvider,
|
||||||
swingUI.injectMenuAction(new ExportPNGAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
swingUI), TRACE_MASK_TITLE);
|
||||||
swingUI.injectMenuAction(new PrintAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
swingUI.injectMenuAction(actionFactory.createExportPNGAction(traceMaskDrawingProvider,
|
||||||
swingUI.injectMenuAction(new CreateBomAction(), FILE_TITLE);
|
swingUI), TRACE_MASK_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createPrintAction(traceMaskDrawingProvider),
|
||||||
|
TRACE_MASK_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||||
swingUI.injectMenuAction(new ExitAction(), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createExitAction(plugInPort), FILE_TITLE);
|
||||||
}
|
|
||||||
|
|
||||||
class NewAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public NewAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "New");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("NewAction triggered");
|
|
||||||
if (!plugInPort.allowFileAction()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugInPort.createNewProject();
|
|
||||||
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.setProjectDefaultPropertyValue(property.getName(), property
|
|
||||||
.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class OpenAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public OpenAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Open");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.FolderOut.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("OpenAction triggered");
|
|
||||||
if (!plugInPort.allowFileAction()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final File file = DialogFactory.getInstance().showOpenDialog(
|
|
||||||
FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
|
|
||||||
null);
|
|
||||||
if (file != null) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Opening from " + file.getAbsolutePath());
|
|
||||||
plugInPort.loadProjectFromFile(file.getAbsolutePath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error",
|
|
||||||
ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SaveAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public SaveAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Save");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("SaveAction triggered");
|
|
||||||
if (plugInPort.getCurrentFileName() == null) {
|
|
||||||
final File file = DialogFactory.getInstance().showSaveDialog(
|
|
||||||
FileFilterEnum.DIY.getFilter(), null,
|
|
||||||
FileFilterEnum.DIY.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Saving to " + file.getAbsolutePath());
|
|
||||||
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not save to file. " + e.getMessage(),
|
|
||||||
"Error", ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Saving to " + plugInPort.getCurrentFileName());
|
|
||||||
plugInPort.saveProjectToFile(plugInPort.getCurrentFileName());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
|
|
||||||
ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SaveAsAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public SaveAsAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Save As");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("SaveAsAction triggered");
|
|
||||||
final File file = DialogFactory.getInstance().showSaveDialog(
|
|
||||||
FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
|
|
||||||
null);
|
|
||||||
if (file != null) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Saving to " + file.getAbsolutePath());
|
|
||||||
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
|
|
||||||
ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CreateBomAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public CreateBomAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Create B.O.M.");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.BOM.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("CreateBomAction triggered");
|
|
||||||
List<BomEntry> bom = BomMaker.getInstance().createBom(
|
|
||||||
plugInPort.getCurrentProject().getComponents());
|
|
||||||
BomDialog dialog = DialogFactory.getInstance().createBomDialog(bom);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExportPDFAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private IDrawingProvider drawingProvider;
|
|
||||||
|
|
||||||
public ExportPDFAction(IDrawingProvider drawingProvider) {
|
|
||||||
super();
|
|
||||||
this.drawingProvider = drawingProvider;
|
|
||||||
putValue(AbstractAction.NAME, "Export to PDF");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("ExportPDFAction triggered");
|
|
||||||
final File file = DialogFactory.getInstance().showSaveDialog(
|
|
||||||
FileFilterEnum.PDF.getFilter(), null, FileFilterEnum.PDF.getExtensions()[0],
|
|
||||||
null);
|
|
||||||
if (file != null) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Exporting to " + file.getAbsolutePath());
|
|
||||||
DrawingExporter.getInstance().exportPDF(
|
|
||||||
ExportPDFAction.this.drawingProvider, file);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not export to PDF. " + e.getMessage(), "Error",
|
|
||||||
ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExportPNGAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private IDrawingProvider drawingProvider;
|
|
||||||
|
|
||||||
public ExportPNGAction(IDrawingProvider drawingProvider) {
|
|
||||||
super();
|
|
||||||
this.drawingProvider = drawingProvider;
|
|
||||||
putValue(AbstractAction.NAME, "Export to PNG");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Image.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("ExportPNGAction triggered");
|
|
||||||
final File file = DialogFactory.getInstance().showSaveDialog(
|
|
||||||
FileFilterEnum.PNG.getFilter(), null, FileFilterEnum.PNG.getExtensions()[0],
|
|
||||||
null);
|
|
||||||
if (file != null) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
LOG.debug("Exporting to " + file.getAbsolutePath());
|
|
||||||
DrawingExporter.getInstance().exportPNG(
|
|
||||||
ExportPNGAction.this.drawingProvider, file);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not export to PNG. " + e.getMessage(), "Error",
|
|
||||||
ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PrintAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private IDrawingProvider drawingProvider;
|
|
||||||
|
|
||||||
public PrintAction(IDrawingProvider drawingProvider) {
|
|
||||||
super();
|
|
||||||
this.drawingProvider = drawingProvider;
|
|
||||||
putValue(AbstractAction.NAME, "Print...");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("ExportPNGAction triggered");
|
|
||||||
try {
|
|
||||||
DrawingExporter.getInstance().print(this.drawingProvider);
|
|
||||||
} catch (PrinterException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExitAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ExitAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Exit");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Exit.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (plugInPort.allowFileAction()) {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -406,7 +64,6 @@ public class FileMenuPlugin implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMessage(EventType eventType, Object... params) {
|
public void processMessage(EventType eventType, Object... params) {
|
||||||
// TODO Auto-generated method stub
|
// Do nothing.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@
|
|||||||
<description>Added worker thread for longer file operation, so
|
<description>Added worker thread for longer file operation, so
|
||||||
GUI doesn't freeze</description>
|
GUI doesn't freeze</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Added right click menu on the canvas</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added label component</description>
|
<description>Added label component</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user