Search in sources :

Example 1 with TrainDiagramPartFactory

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;
}
Also used : Company(net.parostroj.timetable.model.Company) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory)

Example 2 with TrainDiagramPartFactory

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;
}
Also used : Group(net.parostroj.timetable.model.Group) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory)

Example 3 with TrainDiagramPartFactory

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;
}
Also used : TimetableImage(net.parostroj.timetable.model.TimetableImage) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory)

Example 4 with TrainDiagramPartFactory

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);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) TimetableImage(net.parostroj.timetable.model.TimetableImage) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory) BufferedImage(java.awt.image.BufferedImage)

Example 5 with TrainDiagramPartFactory

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);
    }
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) TimetableImage(net.parostroj.timetable.model.TimetableImage) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory)

Aggregations

TrainDiagramPartFactory (net.parostroj.timetable.model.TrainDiagramPartFactory)6 TimetableImage (net.parostroj.timetable.model.TimetableImage)3 BufferedImage (java.awt.image.BufferedImage)1 JFileChooser (javax.swing.JFileChooser)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 Company (net.parostroj.timetable.model.Company)1 Group (net.parostroj.timetable.model.Group)1 Region (net.parostroj.timetable.model.Region)1