use of net.parostroj.timetable.model.TrainDiagramPartFactory in project grafikon by jub77.
the class EditCompaniesDialog method createNew.
@Override
protected Company createNew(String name) {
TrainDiagramPartFactory factory = element.getPartFactory();
Company newCompany = factory.createCompany(factory.createId());
newCompany.setAbbr(name);
return newCompany;
}
use of net.parostroj.timetable.model.TrainDiagramPartFactory in project grafikon by jub77.
the class EditGroupsDialog method createNew.
@Override
protected Group createNew(String name) {
TrainDiagramPartFactory factory = element.getPartFactory();
Group newGroup = factory.createGroup(factory.createId());
newGroup.setName(name);
return newGroup;
}
use of net.parostroj.timetable.model.TrainDiagramPartFactory in project grafikon by jub77.
the class LSImage method createTimetableImage.
public TimetableImage createTimetableImage(TrainDiagram diagram) {
TrainDiagramPartFactory factory = diagram.getPartFactory();
TimetableImage image = factory.createImage(factory.createId(), filename, imageWidth, imageHeight);
return image;
}
use of net.parostroj.timetable.model.TrainDiagramPartFactory in project grafikon by jub77.
the class EditImagesDialog method newButtonActionPerformed.
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
// new image based on selected file ...
JFileChooser chooser = getFileChooser();
int result = chooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile().getName();
if (checkExistence(fileName, null)) {
// show error message and return
JOptionPane.showMessageDialog(this, ResourceLoader.getString("dialog.error.duplicatefile"), ResourceLoader.getString("dialog.error.title"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
// get size of the image
BufferedImage img = ImageIO.read(chooser.getSelectedFile());
TrainDiagramPartFactory factory = diagram.getPartFactory();
TimetableImage image = factory.createImage(factory.createId(), fileName, img.getWidth(), img.getHeight());
File tempFile = File.createTempFile("gt_", ".temp");
Files.asByteSource(chooser.getSelectedFile()).copyTo(Files.asByteSink(tempFile));
image.setImageFile(tempFile);
tempFile.deleteOnExit();
diagram.getImages().add(image);
listModel.addWrapper(new Wrapper<TimetableImage>(image));
} catch (IOException e) {
log.warn("Cannot save temporary image file.", e);
JOptionPane.showMessageDialog(this, ResourceLoader.getString("dialog.error.temporaryfile"), ResourceLoader.getString("dialog.error.title"), JOptionPane.ERROR_MESSAGE);
}
}
}
use of net.parostroj.timetable.model.TrainDiagramPartFactory in project grafikon by jub77.
the class EditImagesDialog method renameButtonActionPerformed.
private void renameButtonActionPerformed(java.awt.event.ActionEvent evt) {
TimetableImage selected = (TimetableImage) ((Wrapper<?>) imagesList.getSelectedValue()).getElement();
// ask for a new name
String newName = (String) JOptionPane.showInputDialog(this, ResourceLoader.getString("images.edit.name"), null, JOptionPane.QUESTION_MESSAGE, null, null, selected.getFilename());
if (newName != null && !newName.equals(selected.getFilename())) {
TrainDiagramPartFactory factory = diagram.getPartFactory();
TimetableImage newImage = factory.createImage(factory.createId(), newName, selected.getImageWidth(), selected.getImageHeight());
if (checkExistence(newName, selected)) {
// show error message and return
JOptionPane.showMessageDialog(this, ResourceLoader.getString("dialog.error.duplicatefile"), ResourceLoader.getString("dialog.error.title"), JOptionPane.ERROR_MESSAGE);
return;
}
newImage.setImageFile(selected.getImageFile());
// train diagram
diagram.getImages().remove(selected);
diagram.getImages().add(newImage);
// list model
listModel.removeObject(selected);
Wrapper<TimetableImage> newWrapper = new Wrapper<TimetableImage>(newImage);
listModel.addWrapper(newWrapper);
// set selected
imagesList.setSelectedValue(newWrapper, true);
}
}
Aggregations