Ignore:
Timestamp:
11/07/19 12:22:50 (5 years ago)
Author:
bnemhaus
Message:

Copying images in Expeditee now duplicates the associated file on the filesystem.
Also changed USER_NAME back to USER.NAME on David's direction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Picture.java

    r1431 r1441  
    2121import java.io.File;
    2222import java.io.IOException;
     23import java.nio.file.Files;
     24import java.nio.file.Path;
     25import java.nio.file.Paths;
     26import java.nio.file.StandardCopyOption;
    2327import java.text.DecimalFormat;
    2428
     
    4751import org.expeditee.gui.FrameUtils;
    4852import org.expeditee.gui.MessageBay;
     53import org.expeditee.gui.management.ResourceUtil;
    4954
    5055/**
     
    626631                p._image = _image;
    627632                p._highlightMode = _highlightMode;
     633               
     634                String copyFileName = _fileName;
     635                try {
     636                        String name = getName();
     637                        Path imageFilePath = ResourceUtil.resolveImagePath(Paths.get(name), this.getSource().getParent());
     638                        Path imageDirectoryPath = imageFilePath.getParent();
     639                        String fileName = name.substring(0, name.indexOf('.'));
     640                        String suffix = name.substring(name.indexOf('.'));
     641                        File copiedFile = File.createTempFile(fileName, suffix, imageDirectoryPath.toFile());
     642                        Path newFilePath = Files.copy(imageFilePath, Paths.get(copiedFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
     643                        Path newFilePathResolved = ResourceUtil.resolveImagePath(newFilePath.getFileName(), this.getSource().getParent());
     644                        Path newFilePathRelativeToExpediteeHome = ResourceUtil.relativiseImagePath(newFilePathResolved);
     645                        copyFileName = newFilePathRelativeToExpediteeHome.toString();
     646                } catch (IOException e) {
     647                        MessageBay.displayMessage("Unable to duplicate image file, new copy refers to existing image file.");
     648                        MessageBay.displayMessage("Caused by IOException with message: " + e.getMessage());
     649                }
     650               
    628651                // Doing Duplicate item duplicates link mark which we dont want to do
    629652                // when in audience mode because the linkMark will be copied incorrectly
     
    668691                p._scaleType = _scaleType;
    669692                p._path = _path;
    670                 p._fileName = _fileName;
     693                p._fileName = copyFileName;
    671694
    672695                p.updateSource();
Note: See TracChangeset for help on using the changeset viewer.