Changeset 1436 for trunk


Ignore:
Timestamp:
11/05/19 16:16:11 (4 years ago)
Author:
bnemhaus
Message:

Added the ability to copy/paste recognised files (mostly images) into Expeditee. This functionality already existed when drag n dropping, but now also works when using copy/paste.

At this stage, recognised files get imported as a approapriate Text Item. For example, a image will create a @i Text Item and attach it to your cursor. Ideally this would be the image directly. Unfortunately, items attached to the cursor (FreeItems) are not currently parsed. This is something I will discuss with David as there are confounding issues to consider. For example: surrogates...

Attached to the bottom of this commit message are my current thoughts.

Also made it so when creating a @i through DND or Copy/Paste, that @i is as relative as possible. The users image directories setting is used to achieve this.


  • FreeItems need to be parsed...we would need to deal with primaries/surrogates in them...
  • Do we want FreeItems to be parsed? If I attach an item to my cursor and then enter surrogate mode, should it change?
  • My gut says no. Both because it would be work, and also because it kind of feels like a free win if we do not.
  • But we do want to replace @i with images etc. Therefore, we want an old style parse for FreeItems?
Location:
trunk/src/org
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/io/SampledAudioFileImporter.java

    r1142 r1436  
    1818public class SampledAudioFileImporter implements FileImporter {
    1919
    20         public Item importFile(File f, Point location) throws IOException
     20        public Item importFile(File f, Point location, boolean attachToFreeItems) throws IOException
    2121        {
    2222                if (location == null || !AudioIO.canImportFile(f) || DisplayController.getCurrentFrame() == null) return null;
  • trunk/src/org/expeditee/actions/Misc.java

    r1415 r1436  
    10441044                }
    10451045                try {
    1046                         EcosystemManager.getDragAndDropManager().importFileList(files, EcosystemManager.getInputManager().getCursorPosition());
     1046                        EcosystemManager.getDragAndDropManager().importFileList(files, EcosystemManager.getInputManager().getCursorPosition(), false);
    10471047                } catch (Exception e) {
    10481048                }
     
    10531053                if (file.exists()) {
    10541054                        try {
    1055                                 EcosystemManager.getDragAndDropManager().importFile(file, EcosystemManager.getInputManager().getCursorPosition());
     1055                                EcosystemManager.getDragAndDropManager().importFile(file, EcosystemManager.getInputManager().getCursorPosition(), false);
    10561056                        } catch (Exception e) {
    10571057                                e.printStackTrace();
  • trunk/src/org/expeditee/agents/mail/MailSession.java

    r1304 r1436  
    517517                        final Frame frame, final Point point) {
    518518
    519                 final Text source = DragAndDropManager.importString("Reading message " + messageNo + "...", point);
     519                final Text source = DragAndDropManager.importString("Reading message " + messageNo + "...", point, false);
    520520
    521521                new Thread() {
  • trunk/src/org/expeditee/gio/ClipboardManager.java

    r1097 r1436  
    11package org.expeditee.gio;
     2
     3import java.io.File;
     4import java.util.List;
    25
    36import org.expeditee.core.Image;
     
    4144                 */
    4245                public String stringRepresentation;
     46                /**
     47                 * A List representation of the clipboard data
     48                 * (for use when copy/pasting to/from directories),
     49                 */
     50                public List<File> fileRepresentation;
    4351               
    4452                /** Default constructor. */
  • trunk/src/org/expeditee/gio/DragAndDropManager.java

    r1142 r1436  
    1111import org.expeditee.core.Point;
    1212import org.expeditee.gui.DisplayController;
     13import org.expeditee.gui.FreeItems;
    1314import org.expeditee.importer.FileImporter;
    1415import org.expeditee.importer.FilePathImporter;
     
    7980         * @param text
    8081         *            The text content.
    81          *
    8282         * @param expediteeDropPoint
    8383         *            The location in the current expeditee frame of where to drop
    8484         *            the text item.
    85          */
    86         public static Text importString(String text, Point expediteeDropPoint)
     85         * @param attachToFreeItems TODO
     86         */
     87        public static Text importString(String text, Point expediteeDropPoint, boolean attachToFreeItems)
    8788        {
    8889                assert (DisplayController.getCurrentFrame() != null);
     
    9293                importedTextItem.setPosition(expediteeDropPoint);
    9394
    94                 DisplayController.getCurrentFrame().addItem(importedTextItem);
     95                if (attachToFreeItems) {
     96                        FreeItems.getInstance().add(importedTextItem);
     97                       
     98                } else {
     99                        DisplayController.getCurrentFrame().addItem(importedTextItem);
     100                }
    95101                DisplayController.requestRefresh(true);
    96102
     
    98104        }
    99105
    100         /** Imports a list of files into Expeditee's current frame. */
    101         public void importFileList(List<? extends File> files, Point expediteeDropPoint) throws IOException
    102         {
     106        /** Imports a list of files into Expeditee's current frame.
     107         * @param attachToFreeItems TODO*/
     108        public void importFileList(List<? extends File> files, Point expediteeDropPoint, boolean attachToFreeItems) throws IOException {
    103109                Point currentPoint = new Point(expediteeDropPoint);
    104110
     
    106112                for (File fileToImport : files) {
    107113
    108                         Item lastItem = importFile(fileToImport, currentPoint);
    109 
     114                        Item lastItem = importFile(fileToImport, currentPoint, attachToFreeItems);
     115                       
    110116                        if (lastItem == null) {
    111117                                currentPoint.setY(currentPoint.getY() + 30);
     
    127133         * @param f
    128134         *            The file to import.
    129          *
    130135         * @param expediteeDropPoint
     136         * @param attachToFreeItems If true, instead of adding to generated item at {@code expediteeDropPoint}, add to free items.
    131137         *
    132138         * @throws IOException
    133139         */
    134         public Item importFile(File f, Point expediteeDropPoint) throws IOException
     140        public Item importFile(File f, Point expediteeDropPoint, boolean attachToFreeItems) throws IOException
    135141        {
    136142                assert (f != null);
     
    139145                // importing routines...
    140146                Item lastCreatedItem;
    141                 if (null == (lastCreatedItem = performFileImport(_customFileImporters, f, expediteeDropPoint))) {
     147                if (null == (lastCreatedItem = performFileImport(_customFileImporters, f, expediteeDropPoint, attachToFreeItems))) {
    142148                        // Standard file importing
    143                         lastCreatedItem = performFileImport(_standardFileImporters, f, expediteeDropPoint);
     149                        lastCreatedItem = performFileImport(_standardFileImporters, f, expediteeDropPoint, attachToFreeItems);
    144150                }
    145151               
     
    150156         * Imports a single file into Expeditee's current frame. Importers are given the opportunity to
    151157         * interpret the file in order of their addition to the list.
    152          */
    153         private Item performFileImport(List<FileImporter> importers, File f, Point expediteeDropPoint) throws IOException
     158         * @param attachToFreeItems If true, instead of adding to generated item at {@code expediteeDropPoint}, add to free items.
     159         */
     160        private Item performFileImport(List<FileImporter> importers, File f, Point expediteeDropPoint, boolean attachToFreeItems) throws IOException
    154161        {
    155162                for (FileImporter fi : importers) {
    156                         Item lastCreated = fi.importFile(f, expediteeDropPoint);
     163                        Item lastCreated = fi.importFile(f, expediteeDropPoint, attachToFreeItems);
    157164                       
    158165                        if (lastCreated != null) return lastCreated;
  • trunk/src/org/expeditee/gio/javafx/JavaFXDragAndDropManager.java

    r1097 r1436  
    6666                                                List<File> files = dragboard.getFiles();
    6767                                                if (files != null && files.size() > 0) {
    68                                                         importFileList(files, dropPoint);
     68                                                        importFileList(files, dropPoint, false);
    6969                                                }
    7070                                        } else if (dragboard.hasContent(_URIListDataflavorString)) {
    7171                                                String data = (String) dragboard.getContent(_URIListDataflavorString);
    7272                                                List<File> files = textURIListToFileList(data);
    73                                                 importFileList(files, dropPoint);
     73                                                importFileList(files, dropPoint, false);
    7474                                                success = true;
    7575                                        } else if (dragboard.hasContent(_URIListDataflavorCharArray)) {
     
    7777                                                String uriString = new String(data);
    7878                                                List<File> files = textURIListToFileList(uriString);
    79                                                 importFileList(files, dropPoint);
     79                                                importFileList(files, dropPoint, false);
    8080                                                success = true;
    8181                                        } else if (dragboard.hasString()) {
    8282                                                String str = dragboard.getString();
    8383                                                if (str != null && str.length() > 0) {
    84                                                         importString(str, dropPoint);
     84                                                        importString(str, dropPoint, false);
    8585                                                        success = true;
    8686                                                }
  • trunk/src/org/expeditee/gio/swing/SwingClipboardManager.java

    r1097 r1436  
    55import java.awt.datatransfer.Transferable;
    66import java.awt.datatransfer.UnsupportedFlavorException;
     7import java.io.File;
    78import java.io.IOException;
    89import java.util.LinkedList;
     
    1011
    1112import org.expeditee.core.Image;
     13import org.expeditee.core.Point;
    1214import org.expeditee.gio.ClipboardManager;
     15import org.expeditee.gio.DragAndDropManager;
     16import org.expeditee.gio.EcosystemManager;
     17import org.expeditee.gui.DisplayController;
    1318
    1419/** TODO: Comment. cts16 */
     
    2126                        SwingClipboardManager.expediteeDataFlavour,
    2227                        DataFlavor.imageFlavor,
    23                         DataFlavor.stringFlavor
     28                        DataFlavor.stringFlavor,
     29                        DataFlavor.javaFileListFlavor
    2430        };
    2531       
     
    8288                } else if (DataFlavor.stringFlavor.equals(flavour)) {
    8389                        out.stringRepresentation = (String) content.getTransferData(flavour);
     90                } else if (DataFlavor.javaFileListFlavor.equals(flavour)) {
     91                        @SuppressWarnings("unchecked")
     92                        List<File> transferData = (List<File>) content.getTransferData(flavour);
     93                        out.fileRepresentation = transferData;
    8494                }
    85         }
     95        }
    8696       
    8797        private Image handleGetImage(Transferable content) throws IOException, UnsupportedFlavorException
  • trunk/src/org/expeditee/gio/swing/SwingDragAndDropManager.java

    r1097 r1436  
    115115
    116116                                                if (str != null && str.length() > 0) {
    117                                                         importString(str, expediteeDropPoint);
     117                                                        importString(str, expediteeDropPoint, false);
    118118                                                        return true;
    119119                                                }
     
    125125                                                List<? extends File> files = (List<? extends File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
    126126
    127                                                 importFileList(files, expediteeDropPoint);
     127                                                importFileList(files, expediteeDropPoint, false);
    128128
    129129                                                return true;
     
    136136                                                List<File> files = textURIListToFileList(data);
    137137
    138                                                 importFileList(files, expediteeDropPoint);
     138                                                importFileList(files, expediteeDropPoint, false);
    139139
    140140                                                return true;
     
    148148                                                List<File> files = textURIListToFileList(uriString);
    149149
    150                                                 importFileList(files, expediteeDropPoint);
     150                                                importFileList(files, expediteeDropPoint, false);
    151151
    152152                                                return true;
  • trunk/src/org/expeditee/gui/management/ResourceManager.java

    r1435 r1436  
    2929        private static ResolvedDirectoryList audio = instance.new ResolvedDirectoryList(FolderSettings.AudioDirs);
    3030       
    31         public static void invalidateAllResourceDirectories() {
    32                 commonInvalidated = true;
    33         }
    34        
    35         private static void refreshAll() {
    36                 Frame currentFrame = DisplayController.getCurrentFrame();
    37                 String framesetPath = currentFrame == null ? null : currentFrame.getFramesetPath();
    38                 frames.refresh(framesetPath);
    39                 images.refresh(framesetPath);
    40                 audio.refresh(framesetPath);
    41         }
    42        
     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                       
    4354        /**
    4455         * Creates a Frame object from an associated resour
     
    224235        }
    225236       
     237        public static void invalidateAllResourceDirectories() {
     238                commonInvalidated = true;
     239        }
     240       
     241        private static void refreshAll() {
     242                Frame currentFrame = DisplayController.getCurrentFrame();
     243                String framesetPath = currentFrame == null ? null : currentFrame.getFramesetPath();
     244                frames.refresh(framesetPath);
     245                images.refresh(framesetPath);
     246                audio.refresh(framesetPath);
     247        }
     248       
    226249        private class ResolvedDirectoryList {
    227250                private List<String> directories = null;
     
    262285               
    263286                private void refresh(String context) {
     287                       
    264288                        List<String> unresolved = source.getAbsoluteDirs();
    265289                        directories = resolve(unresolved, context);
  • trunk/src/org/expeditee/importer/FileImporter.java

    r1102 r1436  
    4242         * @param f
    4343         *              The file to import. Not null.
    44          *
    4544         * @param location
    4645         *              The location in expeditee space where the import was requested.
    4746         *              Null if not applicable.
     47         * @param attachToFreeItems TODO
    4848         *
    4949         * @return
     
    5555         *              If the import procedure failed.
    5656         */
    57         Item importFile(File f, Point location) throws IOException;
     57        Item importFile(File f, Point location, boolean attachToFreeItems) throws IOException;
    5858}
  • trunk/src/org/expeditee/importer/FilePathImporter.java

    r1102 r1436  
    3535public class FilePathImporter implements FileImporter {
    3636
    37         public Item importFile(File f, Point location) throws IOException {
     37        public Item importFile(File f, Point location, boolean attachToFreeItems) throws IOException {
    3838                if (location != null && f != null) {
    39                         return DragAndDropManager.importString(f.getAbsolutePath(), location);                 
     39                        return DragAndDropManager.importString(f.getAbsolutePath(), location, false);                   
    4040                }
    4141
  • trunk/src/org/expeditee/importer/ImageImporter.java

    r1109 r1436  
    3434import org.expeditee.gui.FrameIO;
    3535import org.expeditee.gui.FrameUtils;
     36import org.expeditee.gui.management.ResourceManager;
    3637import org.expeditee.items.Item;
    3738import org.expeditee.items.Text;
     
    5354        }
    5455
    55         public Item importFile(File f, Point location) throws IOException {
     56        public Item importFile(File f, Point location, boolean attachToFreeItems) throws IOException {
    5657
    5758                if (location == null || f == null) {
     
    8788                }
    8889                Text source;
    89                 final Path imagePath = Paths.get(fullPath);
    90                 final Path imagesPath = Paths.get(FrameIO.IMAGES_PATH);
    91                 if(imagePath.startsWith(imagesPath))
    92                         source = DragAndDropManager.importString("@i: " + imagePath.getFileName() + size, location);
    93                 else source = DragAndDropManager.importString("@i: " + fullPath + size, location);
     90                Path imagePath = Paths.get(fullPath);
     91                Path imagePathRelitivized = ResourceManager.relativiseImagePath(imagePath, DisplayController.getCurrentFrame());
     92                source = DragAndDropManager.importString("@i: " + imagePathRelitivized.toString() + size, location, attachToFreeItems);
     93//              final Path imagesPath = Paths.get(FrameIO.IMAGES_PATH);
     94//              if(imagePath.startsWith(imagesPath)) {
     95//                      source = DragAndDropManager.importString("@i: " + imagePath.getFileName() + size, location, attachToFreeItems);
     96//              } else {
     97//                      source = DragAndDropManager.importString("@i: " + fullPath + size, location, attachToFreeItems);
     98//              }
    9499                source.setThickness(thickness);
    95100                source.setBorderColor(borderColor);
  • trunk/src/org/expeditee/importer/TextImporter.java

    r1102 r1436  
    4040        }
    4141
    42         public Item importFile(final File f, Point location) throws IOException {
     42        public Item importFile(final File f, Point location, boolean attachToFreeItems) throws IOException {
    4343                if (location == null || f == null) {
    4444                        return null;
     
    4646                final String fullPath = f.getAbsolutePath();
    4747
    48                 final Text source = DragAndDropManager.importString(f.getPath(), location);
     48                final Text source = DragAndDropManager.importString(f.getPath(), location, false);
    4949
    5050                // Create a frameCreator to write the text
  • trunk/src/org/expeditee/importer/pdfImporter.java

    r1242 r1436  
    2424import java.nio.ByteBuffer;
    2525import java.nio.channels.FileChannel;
     26import java.nio.file.Path;
     27import java.nio.file.Paths;
    2628
    2729import org.expeditee.core.Colour;
     
    3739import org.expeditee.gui.FrameIO;
    3840import org.expeditee.gui.MessageBay;
     41import org.expeditee.gui.management.ResourceManager;
    3942import org.expeditee.items.Item;
    4043import org.expeditee.items.Text;
     
    4548public class pdfImporter implements FileImporter {
    4649       
    47         public Item importFile(final File f, Point location) throws IOException {
     50        public Item importFile(final File f, Point location, boolean attachToFreeItems) throws IOException {
    4851                if (location == null || f == null) {
    4952                        return null;
     
    6366                }
    6467               
    65                 final Text link = DragAndDropManager.importString(name, location);
     68                final Text link = DragAndDropManager.importString(name, location, false);
    6669                link.setLink(name+"1");
    6770               
     
    135138                              g.popDrawingSurface();
    136139                              //save it as a file
    137                               File out = new File(framesetPath+i+".png");
     140                              Path p = Paths.get(framesetPath+i+".png");
     141                              p = ResourceManager.relativiseImagePath(p, DisplayController.getCurrentFrame());
     142                              File out = p.toFile();
    138143                              bimg.writeToDisk("png", out);
    139144                              //generate a frame with that image
    140145                              System.out.println(width);
    141                               System.out.println("@i: "+framesetPath+i+".png "+width);
    142                                                 currentFrame.addText(x, y, "@i: "+framesetPath+i+".png "+width, null);
     146                              System.out.println("@i: "+p.toString()+width);
     147                                                currentFrame.addText(x, y, "@i: "+p.toString()+width, null);
    143148                                                if(i>1)
    144149                                                {
  • trunk/src/org/expeditee/io/ItemSelection.java

    r1104 r1436  
    2626
    2727import org.expeditee.core.Image;
     28import org.expeditee.core.Point;
    2829import org.expeditee.gio.ClipboardManager.ClipboardData;
    2930import org.expeditee.gio.EcosystemManager;
     
    204205                                        prevItem = item;
    205206                                }
     207                        } else if (content.fileRepresentation != null) { // Files
     208                                EcosystemManager.getDragAndDropManager().importFileList(content.fileRepresentation, DisplayController.getMousePosition(), true);
    206209                        } /* else if {
    207210                                // Next handler
  • trunk/src/org/expeditee/setting/DirectoryListSetting.java

    r1434 r1436  
    33import java.io.File;
    44import java.util.ArrayList;
    5 import java.util.HashMap;
    65import java.util.LinkedList;
    76import java.util.List;
    8 import java.util.Map;
    97
    10 import org.expeditee.gui.DisplayController;
    118import org.expeditee.gui.FrameIO;
    129import org.expeditee.gui.FrameUtils;
Note: See TracChangeset for help on using the changeset viewer.