use of com.willwinder.ugs.nbp.designer.io.ugsd.UgsDesignReader in project Universal-G-Code-Sender by winder.
the class DesignerTopComponent method loadDesign.
private void loadDesign(UgsDataObject dataObject) {
Design design = new Design();
try {
File file = new File(dataObject.getPrimaryFile().getPath());
if (file.exists()) {
UgsDesignReader reader = new UgsDesignReader();
design = reader.read(file).orElse(design);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Couldn't load design from file " + dataObject.getPrimaryFile(), e);
}
controller.setDesign(design);
}
use of com.willwinder.ugs.nbp.designer.io.ugsd.UgsDesignReader in project Universal-G-Code-Sender by winder.
the class PasteAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
String data = (String) contents.getTransferData(DataFlavor.stringFlavor);
UgsDesignReader reader = new UgsDesignReader();
List<Entity> entities = reader.deserialize(data);
controller.getDrawing().insertEntities(entities);
controller.getSelectionManager().clearSelection();
controller.getSelectionManager().setSelection(entities);
} catch (UnsupportedFlavorException | JsonSyntaxException | IOException ex) {
LOGGER.log(Level.INFO, "Unknown paste buffer data format, ignoring");
}
}
use of com.willwinder.ugs.nbp.designer.io.ugsd.UgsDesignReader in project Universal-G-Code-Sender by winder.
the class OpenAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
UndoManager undoManager = CentralLookup.getDefault().lookup(UndoManager.class);
undoManager.clear();
SelectionManager selectionManager = CentralLookup.getDefault().lookup(SelectionManager.class);
selectionManager.clearSelection();
Controller controller = CentralLookup.getDefault().lookup(Controller.class);
fileChooser.showOpenDialog(null);
ThreadHelper.invokeLater(() -> {
DesignReader designReader = new UgsDesignReader();
if (fileChooser.getFileFilter() == SVG_FILE_FILTER) {
designReader = new SvgReader();
} else if (fileChooser.getFileFilter() == C2D_FILE_FILTER) {
designReader = new C2dReader();
}
File selectedFile = fileChooser.getSelectedFile();
Optional<Design> optional = designReader.read(selectedFile);
if (optional.isPresent()) {
controller.setDesign(optional.get());
} else {
throw new RuntimeException("Could not open svg: " + selectedFile.getName());
}
});
}
Aggregations