use of com.willwinder.ugs.nbp.designer.io.dxf.DxfReader 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