mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Ability to import existing DIY files into a project
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ public enum IconLoader {
|
|||||||
"size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort(
|
"size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort(
|
||||||
"sort.png"), ElementsSelection("elements_selection.png"), BranchAdd(
|
"sort.png"), ElementsSelection("elements_selection.png"), BranchAdd(
|
||||||
"branch_add.png"), Briefcase_Add("briefcase_add.png"), RotateCW(
|
"branch_add.png"), Briefcase_Add("briefcase_add.png"), RotateCW(
|
||||||
"rotate_cw.png"), RotateCCW("rotate_ccw.png");
|
"rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 595 B |
+86
@@ -8,6 +8,7 @@ import java.awt.print.PrinterException;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@@ -23,6 +24,7 @@ import org.diylc.core.IDIYComponent;
|
|||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
import org.diylc.core.Theme;
|
import org.diylc.core.Theme;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.gui.DialogFactory;
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||||
@@ -59,6 +61,10 @@ public class ActionFactory {
|
|||||||
return new OpenAction(plugInPort, swingUI);
|
return new OpenAction(plugInPort, swingUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImportAction createImportAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
return new ImportAction(plugInPort, swingUI);
|
||||||
|
}
|
||||||
|
|
||||||
public SaveAction createSaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
public SaveAction createSaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
return new SaveAction(plugInPort, swingUI);
|
return new SaveAction(plugInPort, swingUI);
|
||||||
}
|
}
|
||||||
@@ -265,6 +271,86 @@ public class ActionFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ImportAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private ISwingUI swingUI;
|
||||||
|
private Presenter presenter;
|
||||||
|
|
||||||
|
public ImportAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.swingUI = swingUI;
|
||||||
|
this.presenter = new Presenter(new IView() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File promptFileSave() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("ImportAction triggered");
|
||||||
|
|
||||||
|
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());
|
||||||
|
// 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
|
||||||
|
presenter.selectAll();
|
||||||
|
presenter.deleteSelectedComponents();
|
||||||
|
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 {
|
public static class SaveAction extends AbstractAction {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
+1
@@ -37,6 +37,7 @@ public class FileMenuPlugin implements IPlugIn {
|
|||||||
ActionFactory actionFactory = ActionFactory.getInstance();
|
ActionFactory actionFactory = ActionFactory.getInstance();
|
||||||
swingUI.injectMenuAction(actionFactory.createNewAction(plugInPort), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createNewAction(plugInPort), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(actionFactory.createOpenAction(plugInPort, swingUI), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createOpenAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
|
swingUI.injectMenuAction(actionFactory.createImportAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(actionFactory.createSaveAction(plugInPort, swingUI), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createSaveAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(actionFactory.createSaveAsAction(plugInPort, swingUI), FILE_TITLE);
|
swingUI.injectMenuAction(actionFactory.createSaveAsAction(plugInPort, swingUI), FILE_TITLE);
|
||||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||||
|
|||||||
@@ -1190,6 +1190,10 @@
|
|||||||
<releaseDate>2013-04-25 20:00:00.000 CET</releaseDate>
|
<releaseDate>2013-04-25 20:00:00.000 CET</releaseDate>
|
||||||
<name></name>
|
<name></name>
|
||||||
<changes>
|
<changes>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Ability to import existing DIY files into a project</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added primitive shapes - ellipse, polygon and (rounded) rectangle</description>
|
<description>Added primitive shapes - ellipse, polygon and (rounded) rectangle</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user