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/gui/management/ResourceUtil.java

    r1439 r1441  
    11package org.expeditee.gui.management;
     2
     3import java.nio.file.Path;
     4import java.nio.file.Paths;
     5import java.util.List;
     6
     7import org.expeditee.gui.Frame;
     8import org.expeditee.gui.FrameIO;
    29
    310public class ResourceUtil {
     
    1017        public static final String CURRENT_FRAMESET_FLAG = "${CURRENT_FRAMESET}";
    1118        public static final String CURRENT_USER = "${CURRENT_USER}";
     19       
     20        /**
     21         * Attempts to relativise a image path using expeditee.home (FrameIO.PARENT_FOLDER).
     22         * @param path The path to attempt to relativise
     23         * @return Returns the most relativised path if one exists, otherwise returns a copy of the ref parameter passed in.
     24         */
     25        public static Path relativiseImagePath(Path path) {
     26                Path expediteeHome = Paths.get(FrameIO.PARENT_FOLDER);
     27                if (path.startsWith(expediteeHome)) {
     28                        return expediteeHome.relativize(path);
     29                } else {
     30                        return path;
     31                }
     32        }
     33       
     34        public static Path resolveImagePath(Path path, Frame context) {
     35                List<String> directories = ResourceManager.images.getDirectories(context);
     36                directories.add(FrameIO.PARENT_FOLDER);
     37               
     38                for (String dir: directories) {
     39                        Path canditate = Paths.get(dir).resolve(path);
     40                        if (canditate.toFile().exists()) {
     41                                return canditate;
     42                        }
     43                }
     44               
     45                return null;
     46        }
    1247       
    1348        /**
Note: See TracChangeset for help on using the changeset viewer.