use of de.neemann.gui.MyFileChooser in project Digital by hneemann.
the class TableDialog method createFileMenu.
private JMenu createFileMenu() {
JMenu fileMenu = new JMenu(Lang.get("menu_file"));
fileMenu.add(new ToolTipAction(Lang.get("menu_open")) {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
if (fc.showOpenDialog(TableDialog.this) == JFileChooser.APPROVE_OPTION) {
try {
File file = fc.getSelectedFile();
TruthTable truthTable = TruthTable.readFromFile(file);
setModel(new TruthTableTableModel(truthTable));
TableDialog.this.filename = file;
} catch (IOException e1) {
new ErrorMessage().addCause(e1).show(TableDialog.this);
}
}
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_save")) {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
new SaveAsHelper(TableDialog.this, fc, "tru").checkOverwrite(file -> {
model.getTable().save(file);
TableDialog.this.filename = file;
});
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportTableLaTeX")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
ExpressionListener expressionListener = new LaTeXExpressionListener(model);
if (createJK.isSelected())
expressionListener = new ExpressionListenerJK(expressionListener);
lastGeneratedExpressions.replayTo(expressionListener);
} catch (ExpressionException | FormatterException e1) {
new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(TableDialog.this);
}
}
});
fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportHex")) {
@Override
public void actionPerformed(ActionEvent e) {
int res = JOptionPane.OK_OPTION;
if (model.getTable().getVars().size() > 20)
res = JOptionPane.showConfirmDialog(TableDialog.this, Lang.get("msg_tableHasManyRowsConfirm"));
if (res == JOptionPane.OK_OPTION) {
JFileChooser fc = new MyFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "hex"));
new SaveAsHelper(TableDialog.this, fc, "hex").checkOverwrite(file -> model.getTable().saveHex(file));
}
}
}.setToolTip(Lang.get("menu_table_exportHex_tt")).createJMenuItem());
createJK = new JCheckBoxMenuItem(Lang.get("menu_table_JK"));
createJK.addActionListener(e -> calculateExpressions());
fileMenu.add(createJK);
return fileMenu;
}
use of de.neemann.gui.MyFileChooser in project Digital by hneemann.
the class GenerateFile method generate.
@Override
public void generate(JDialog parent, File circuitFile, TruthTable table, ExpressionListenerStore expressions) throws Exception {
ModelAnalyserInfo mai = table.getModelAnalyzerInfo();
if (mai == null) {
JOptionPane.showMessageDialog(parent, new LineBreaker().toHTML().breakLines(Lang.get("msg_circuitIsRequired")), Lang.get("msg_warning"), JOptionPane.WARNING_MESSAGE);
return;
} else {
ArrayList<String> pinsWithoutNumber = mai.getPinsWithoutNumber();
if (!pinsWithoutNumber.isEmpty()) {
int res = JOptionPane.showConfirmDialog(parent, new LineBreaker().toHTML().breakLines(Lang.get("msg_thereAreMissingPinNumbers", pinsWithoutNumber)), Lang.get("msg_warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (res != JOptionPane.OK_OPTION)
return;
}
}
if (circuitFile == null)
circuitFile = new File("circuit." + suffix);
else
circuitFile = SaveAsHelper.checkSuffix(circuitFile, suffix);
JFileChooser fileChooser = new MyFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("JEDEC", suffix));
fileChooser.setSelectedFile(circuitFile);
if (fileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
ExpressionToFileExporter expressionExporter = factory.create();
expressionExporter.getPinMapping().addAll(mai.getPins());
expressionExporter.getPinMapping().setClockPin(mai.getClockPinInt());
new BuilderExpressionCreator(expressionExporter.getBuilder(), ExpressionModifier.IDENTITY).create(expressions);
expressionExporter.export(SaveAsHelper.checkSuffix(fileChooser.getSelectedFile(), suffix));
}
}
use of de.neemann.gui.MyFileChooser in project Digital by hneemann.
the class GenerateCUPL method generate.
@Override
public void generate(JDialog parent, File circuitFile, TruthTable table, ExpressionListenerStore expressions) throws Exception {
File cuplPath;
if (circuitFile == null) {
JFileChooser fc = new MyFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(Lang.get("msg_selectAnEmptyFolder"));
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
cuplPath = fc.getSelectedFile();
circuitFile = cuplPath;
} else {
return;
}
} else {
if (circuitFile.isDirectory()) {
cuplPath = circuitFile;
} else {
String name = circuitFile.getName();
if (name.length() > 3 && name.charAt(name.length() - 4) == '.')
name = name.substring(0, name.length() - 4);
cuplPath = new File(circuitFile.getParentFile(), "CUPL_" + name);
}
}
if (!cuplPath.mkdirs())
if (!cuplPath.exists())
throw new IOException(Lang.get("err_couldNotCreateFolder_N0", cuplPath.getPath()));
File f = new File(cuplPath, "CUPL.PLD");
CuplExporter cuplExporter = cuplExporterFactory.create();
cuplExporter.setProjectName(circuitFile.getName());
final ModelAnalyserInfo modelAnalyzerInfo = table.getModelAnalyzerInfo();
if (modelAnalyzerInfo != null)
cuplExporter.getPinMapping().addAll(modelAnalyzerInfo.getPins());
new BuilderExpressionCreator(cuplExporter.getBuilder(), ExpressionModifier.IDENTITY).create(expressions);
try (FileOutputStream out = new FileOutputStream(f)) {
cuplExporter.writeTo(out);
}
}
Aggregations