use of com.willwinder.ugs.nbp.designer.io.c2d.C2dReader 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());
}
});
}
use of com.willwinder.ugs.nbp.designer.io.c2d.C2dReader in project Universal-G-Code-Sender by winder.
the class ToolImportAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Scalable Vector Graphics (.svg)", "svg"));
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Autodesk CAD (.dxf)", "dxf"));
fileDialog.addChoosableFileFilter(new FileNameExtensionFilter("Carbide Create (.c2d)", "c2d"));
fileDialog.showOpenDialog(null);
ThreadHelper.invokeLater(() -> {
File f = fileDialog.getSelectedFile();
if (f != null) {
Optional<Design> optionalDesign = Optional.empty();
if (StringUtils.endsWithIgnoreCase(f.getName(), ".svg")) {
SvgReader svgReader = new SvgReader();
optionalDesign = svgReader.read(f);
} else if (StringUtils.endsWithIgnoreCase(f.getName(), ".dxf")) {
DxfReader reader = new DxfReader();
optionalDesign = reader.read(f);
} else if (StringUtils.endsWithIgnoreCase(f.getName(), ".c2d")) {
C2dReader reader = new C2dReader();
optionalDesign = reader.read(f);
}
if (optionalDesign.isPresent()) {
Design design = optionalDesign.get();
controller.addEntities(design.getEntities());
controller.getSelectionManager().addSelection(design.getEntities());
controller.getDrawing().repaint();
controller.setTool(Tool.SELECT);
} else {
throw new RuntimeException("Could not open: " + f.getName());
}
}
});
}
Aggregations