Search in sources :

Example 6 with TimetableImage

use of net.parostroj.timetable.model.TimetableImage 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 7 with TimetableImage

use of net.parostroj.timetable.model.TimetableImage in project grafikon by jub77.

the class EditImagesDialog method updateValues.

private void updateValues() {
    listModel = new WrapperListModel<TimetableImage>();
    imagesList.setModel(listModel);
    if (this.diagram != null) {
        for (TimetableImage item : this.diagram.getImages()) {
            listModel.addWrapper(new Wrapper<TimetableImage>(item));
        }
    }
}
Also used : TimetableImage(net.parostroj.timetable.model.TimetableImage)

Example 8 with TimetableImage

use of net.parostroj.timetable.model.TimetableImage 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 9 with TimetableImage

use of net.parostroj.timetable.model.TimetableImage 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)

Example 10 with TimetableImage

use of net.parostroj.timetable.model.TimetableImage in project grafikon by jub77.

the class TrainDiagramBuilder method addImage.

public void addImage(LSImage lsImage) {
    TimetableImage image = lsImage.createTimetableImage(diagram);
    diagram.getImages().add(image);
}
Also used : TimetableImage(net.parostroj.timetable.model.TimetableImage)

Aggregations

TimetableImage (net.parostroj.timetable.model.TimetableImage)10 ZipEntry (java.util.zip.ZipEntry)3 TrainDiagramPartFactory (net.parostroj.timetable.model.TrainDiagramPartFactory)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileChannel (java.nio.channels.FileChannel)2 ZipFile (java.util.zip.ZipFile)2 BufferedImage (java.awt.image.BufferedImage)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 Date (java.util.Date)1 JFileChooser (javax.swing.JFileChooser)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 EngineClass (net.parostroj.timetable.model.EngineClass)1 Output (net.parostroj.timetable.model.Output)1 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)1 Route (net.parostroj.timetable.model.Route)1