Changeset 1441 for trunk


Ignore:
Timestamp:
11/07/19 12:22:50 (4 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.

Location:
trunk/src/org/expeditee
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/management/ProfileManager.java

    r1440 r1441  
    2828public class ProfileManager {
    2929
    30         private static final String USER_NAME_PATTERN_INTERNAL = "USER_NAME";
    3130        private static final String DEFAULT = UserSettings.DEFAULT_PROFILE_NAME;
    3231        private static final String[] startPages = { "exploratorysearch", "webbrowser" };
    33         public static final String USER_NAME_PATTERN = "${" + USER_NAME_PATTERN_INTERNAL + "}";
     32        public static final String USER_NAME_FLAG = "${" + "USER.NAME" + "}";
    3433
    3534        public static Frame createProfile(String profileFor, Map<String, Setting> specifiedSettings,
     
    8584                                        if (item instanceof Text) {
    8685                                                String content = item.getText();
    87                                                 item.setText(ResourceUtil.substitute(content, ProfileManager.USER_NAME_PATTERN, profileFor));
     86                                                item.setText(ResourceUtil.substitute(content, ProfileManager.USER_NAME_FLAG, profileFor));
    8887                                        }
    8988                                }
  • trunk/src/org/expeditee/gui/management/ResourceManager.java

    r1439 r1441  
    2525        private static boolean commonInvalidated = false;
    2626        private static ResourceManager instance = new ResourceManager();
    27         private static ResolvedDirectoryList frames = instance.new ResolvedDirectoryList(FolderSettings.FrameDirs);
    28         private static ResolvedDirectoryList images = instance.new ResolvedDirectoryList(FolderSettings.ImageDirs);
    29         private static ResolvedDirectoryList audio = instance.new ResolvedDirectoryList(FolderSettings.AudioDirs);
    30        
    31         /**
    32          * Attempts to relativise a image path using the users the directories listed for images in their settings.
    33          * @param path The path to attempt to relativise
    34          * @param context The context to use.  Most likely the Frame that the image is on.
    35          * @return Returns the most relativised path if one exists, otherwise returns a copy of the ref parameter passed in.
    36          */
    37         /*public static Path relativiseImagePath(Path path, Frame context) {
    38                 String pathStr = path.toString();
    39                
    40                 // Consult the resolved images directory for a list of paths to relativise too.
    41                 List<String> directories = images.getDirectories(context);
    42                
    43                 // Find the longest match that can be used to relativise the path.
    44                 String longestMatch = "";
    45                 for (String dir: directories) {
    46                         if (pathStr.startsWith(dir) && (dir.length() > longestMatch.length())) {
    47                                 longestMatch = dir;
    48                         }
    49                 }
    50                
    51                 return Paths.get(pathStr.replace(longestMatch, ""));
    52         }*/
    53        
    54         public static Path relativiseImagePath(Path path, Frame context) {
    55                 Path expediteeHome = Paths.get(FrameIO.PARENT_FOLDER);
    56                 if (path.startsWith(expediteeHome)) {
    57                         return expediteeHome.relativize(path);
    58                 } else {
    59                         return path;
    60                 }
    61         }
    62                        
     27        protected static ResolvedDirectoryList frames = instance.new ResolvedDirectoryList(FolderSettings.FrameDirs);
     28        protected static ResolvedDirectoryList images = instance.new ResolvedDirectoryList(FolderSettings.ImageDirs);
     29        protected static ResolvedDirectoryList audio = instance.new ResolvedDirectoryList(FolderSettings.AudioDirs);
     30       
    6331        /**
    6432         * Creates a Frame object from an associated resour
     
    256224        }
    257225       
    258         private class ResolvedDirectoryList {
     226        protected class ResolvedDirectoryList {
    259227                private List<String> directories = null;
    260228                private String contextFramesetPath = null;
  • 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        /**
  • trunk/src/org/expeditee/importer/ImageImporter.java

    r1436 r1441  
    3434import org.expeditee.gui.FrameIO;
    3535import org.expeditee.gui.FrameUtils;
    36 import org.expeditee.gui.management.ResourceManager;
     36import org.expeditee.gui.management.ResourceUtil;
    3737import org.expeditee.items.Item;
    3838import org.expeditee.items.Text;
     
    8989                Text source;
    9090                Path imagePath = Paths.get(fullPath);
    91                 Path imagePathRelitivized = ResourceManager.relativiseImagePath(imagePath, DisplayController.getCurrentFrame());
     91                Path imagePathRelitivized = ResourceUtil.relativiseImagePath(imagePath);
    9292                source = DragAndDropManager.importString("@i: " + imagePathRelitivized.toString() + size, location, attachToFreeItems);
    9393//              final Path imagesPath = Paths.get(FrameIO.IMAGES_PATH);
  • trunk/src/org/expeditee/importer/pdfImporter.java

    r1436 r1441  
    3939import org.expeditee.gui.FrameIO;
    4040import org.expeditee.gui.MessageBay;
    41 import org.expeditee.gui.management.ResourceManager;
     41import org.expeditee.gui.management.ResourceUtil;
    4242import org.expeditee.items.Item;
    4343import org.expeditee.items.Text;
     
    139139                              //save it as a file
    140140                              Path p = Paths.get(framesetPath+i+".png");
    141                               p = ResourceManager.relativiseImagePath(p, DisplayController.getCurrentFrame());
     141                              p = ResourceUtil.relativiseImagePath(p);
    142142                              File out = p.toFile();
    143143                              bimg.writeToDisk("png", out);
  • 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();
  • trunk/src/org/expeditee/settings/UserSettings.java

    r1440 r1441  
    6969                String profileName = UserSettings.ProfileName.get();
    7070                        if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
    71                                 if (!profileName.equals(ProfileManager.USER_NAME_PATTERN)) {
     71                                if (!profileName.equals(ProfileManager.USER_NAME_FLAG)) {
    7272                                        text.setLink(profileName + "1");
    7373                                }
Note: See TracChangeset for help on using the changeset viewer.