use of de.neemann.gui.ErrorMessage in project Digital by hneemann.
the class LibrarySelector method libraryChanged.
@Override
public void libraryChanged(LibraryNode node) {
componentsMenu.removeAll();
for (LibraryNode n : library.getRoot()) addComponents(componentsMenu, n);
if (library.getCustomNode() != null) {
JMenuItem m = componentsMenu.getItem(componentsMenu.getItemCount() - 1);
if (m instanceof JMenu) {
JMenu menu = (JMenu) m;
menu.addSeparator();
menu.add(new ToolTipAction(Lang.get("menu_update")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
library.updateEntries();
} catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorUpdatingLibrary")).addCause(ex));
}
}
}.setToolTip(Lang.get("menu_update_tt")).createJMenuItem());
}
}
}
use of de.neemann.gui.ErrorMessage in project Digital by hneemann.
the class SaveAsHelper method checkOverwrite.
/**
* Uses the JFileChooser to select a file and checks, if the file exists.
* Uses the gicen interface to save the file.
*
* @param saveAs used to save the file
*/
public void checkOverwrite(SaveAs saveAs) {
do {
repeat = false;
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
final File selectedFile = checkSuffix(fc.getSelectedFile(), suffix);
if (selectedFile.exists()) {
Object[] options = { Lang.get("btn_overwrite"), Lang.get("btn_newName") };
int res = JOptionPane.showOptionDialog(parent, Lang.get("msg_fileExists", selectedFile.getName()), Lang.get("msg_warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
if (res == 1) {
repeat = true;
continue;
}
}
try {
saveAs.saveAs(selectedFile);
} catch (IOException e) {
new ErrorMessage(Lang.get("msg_errorWritingFile")).addCause(e).show(parent);
}
}
} while (repeat);
}
use of de.neemann.gui.ErrorMessage 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.ErrorMessage in project Digital by hneemann.
the class InsertAction method update.
/**
* Updates this action to a new node
*
* @param node the node
*/
public void update(LibraryNode node) {
this.node = node;
try {
final Icon icon = node.getIcon(shapeFactory);
setIcon(icon);
} catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
}
}
use of de.neemann.gui.ErrorMessage in project Digital by hneemann.
the class InsertAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (node.isUnique()) {
VisualElement visualElement = new VisualElement(node.getName()).setPos(new Vector(10, 10)).setShapeFactory(shapeFactory);
if (getIcon() == null) {
try {
node.getDescription();
setIcon(node.getIcon(shapeFactory));
} catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
}
}
if (visualElement.getShape() instanceof MissingShape)
return;
circuitComponent.setPartToInsert(visualElement);
insertHistory.add(this);
}
}
Aggregations