Changeset 504


Ignore:
Timestamp:
11/19/13 12:01:52 (11 years ago)
Author:
jts21
Message:

New copy/paste handling, add pdfImporter, add dictionary and documentation to resources, other small changes

Location:
trunk/src/org/expeditee
Files:
4 added
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r492 r504  
    106106        final ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
    107107
     108        String realPackageName = packageName;
    108109        packageName = packageName.replace(".", "/");
    109110        URL packageURL = classLoader.getResource(packageName);
     
    162163               
    163164                for (File actual: contenuti) {
    164                     String entryName = actual.getName();
     165                    String entryName = realPackageName + actual.getName();
    165166
    166167                    if (entryName.endsWith(".class") && !entryName.contains("$")) {
    167168                        entryName = entryName.substring(0, entryName.lastIndexOf('.'));
     169                        entryName.replace('/', '.');
    168170                   
    169171                        names.add(entryName);
  • trunk/src/org/expeditee/actions/Misc.java

    r464 r504  
    1212import java.util.ArrayList;
    1313import java.util.Collection;
    14 import java.util.HashMap;
    1514import java.util.LinkedList;
    1615import java.util.List;
    17 import java.util.Set;
    1816
    1917import javax.imageio.ImageIO;
    20 
    21 import org.expeditee.actions.Simple;
    2218
    2319import org.expeditee.gui.AttributeUtils;
     
    2824import org.expeditee.gui.FrameIO;
    2925import org.expeditee.gui.FrameMouseActions;
    30 import org.expeditee.gui.FrameUtils;
    3126import org.expeditee.gui.MessageBay;
    3227import org.expeditee.gui.Reminders;
    3328import org.expeditee.gui.TimeKeeper;
    3429import org.expeditee.importer.FrameDNDTransferHandler;
    35 import org.expeditee.io.FrameReader;
    3630import org.expeditee.items.Item;
    37 
    3831import org.expeditee.items.ItemUtils;
    3932import org.expeditee.items.Line;
    4033import org.expeditee.items.Text;
    41 
    4234import org.expeditee.math.ExpediteeJEP;
    4335import org.expeditee.simple.SString;
  • trunk/src/org/expeditee/gui/Browser.java

    r467 r504  
    3030import org.expeditee.agents.mail.MailSession;
    3131import org.expeditee.importer.FrameDNDTransferHandler;
     32import org.expeditee.io.ItemSelection;
    3233import org.expeditee.items.Item;
    3334import org.expeditee.items.widgets.WidgetCacheManager;
     
    397398
    398399        public void windowDeactivated(WindowEvent e) {
     400                ItemSelection.cut(FreeItems.getInstance());
    399401        }
    400402
  • trunk/src/org/expeditee/gui/FrameIO.java

    r454 r504  
    5858                IMAGES_PATH = PARENT_FOLDER + IMAGES_FOLDER;
    5959                HELP_PATH = PARENT_FOLDER + "documentation" + File.separator;
     60                DICT_PATH = PARENT_FOLDER + "dict" + File.separator;
    6061                PROFILE_PATH = PARENT_FOLDER + "profiles" + File.separator;
    6162                EXPORTS_DIR = PARENT_FOLDER + "exports" + File.separator;
     
    8384
    8485        public static String HELP_PATH;
     86       
     87        public static String DICT_PATH;
    8588
    8689        public static String PROFILE_PATH;
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r454 r504  
    2222import org.expeditee.actions.Navigation;
    2323import org.expeditee.actions.Simple;
     24import org.expeditee.io.ItemSelection;
    2425import org.expeditee.items.Circle;
    2526import org.expeditee.items.Dot;
     
    586587        }
    587588
    588         /**
    589          * Used to add items to a frame when pasting text from the clipboard.
    590          *
    591          * @param text
    592          *            the next paragraph of text to be pasted.
    593          * @param lastItem
    594          *            the item to drop from when pasting the next paragraph of text.
    595          * @return the new text item created from pasting the text.
    596          */
    597         private static Item addTextItemToCurrentFrame(String text, Item lastItem,
    598                         boolean bDrop) {
    599                 if (text.trim().length() > 0) {
    600                         if (lastItem != null && bDrop)
    601                                 Drop(lastItem, true);
    602 
    603                         Text textItem = createText();
    604                         textItem.setText(text.substring(0, text.length() - 1));
    605 
    606                         if (lastItem != null && !bDrop) {
    607                                 textItem.setY(lastItem.getY() + lastItem.getBoundsHeight());
    608                         } else {
    609                                 textItem.setY(FrameMouseActions.getY());
    610                         }
    611                         textItem.setX(FrameMouseActions.getX());
    612                         textItem.justify(false);
    613                         DisplayIO.getCurrentFrame().addItem(textItem);
    614                         return textItem;
    615                 }
    616                 return lastItem;
    617         }
    618 
    619589        private static void copyItemToClipboard(Item on) {
    620590                if (on == null || !(on instanceof Text))
     
    797767                        break;
    798768                case KeyEvent.VK_V:
    799                         try {
    800                                 // read in the data from the clipboard
    801                                 String clip = ((String) Toolkit.getDefaultToolkit()
    802                                                 .getSystemClipboard().getContents(null)
    803                                                 .getTransferData(DataFlavor.stringFlavor));
    804                                 // Covert the line separator char when pasting in
    805                                 // windows (\r\n) or max (\r)
    806                                 clip = StringUtils.convertNewLineChars(clip);
    807 
    808                                 Item clicked = FrameUtils.getCurrentItem();
    809 
    810                                 if (clicked != null) {
    811                                         // check permissions
    812                                         if (!clicked.hasPermission(UserAppliedPermission.full)
    813                                                         && clicked.getParent() != null
    814                                                         && clicked.getParent().getNameItem() != clicked) {
    815                                                 MessageBay.displayMessage("Insufficient Permission");
    816                                                 return;
    817                                         }
    818 
    819                                         Text text = createText();
    820                                         text.setText(clip);
    821                                         List<Item> clipboard = new ArrayList<Item>();
    822                                         clipboard.add(text);
    823                                         FrameMouseActions.merge(clipboard, clicked);
    824                                         text.delete();
    825                                 } else {
    826                                         StringTokenizer st = new StringTokenizer(clip, "\n", true);
    827 
    828                                         String temp = "";
    829                                         // int y = FrameMouseActions.getY();
    830                                         Item lastItem = null;
    831 
    832                                         boolean drop = currentFrame.hasAnnotation("next");
    833                                         // separate the clipboard content into items based on
    834                                         // blank lines
    835                                         while (st.hasMoreTokens()) {
    836                                                 String s = st.nextToken();
    837                                                 // if this is a blank line, then it is an item separator
    838                                                 if (s.trim().length() == 0) {
    839                                                         lastItem = addTextItemToCurrentFrame(temp,
    840                                                                         lastItem, drop);
    841                                                         temp = "";
    842                                                 } else {
    843                                                         temp += s + "\n";
    844                                                         if (st.hasMoreTokens())
    845                                                                 st.nextToken();
    846                                                 }
    847                                         }
    848                                         // the last item will not be finished by the above loop
    849                                         addTextItemToCurrentFrame(temp, lastItem, drop);
    850                                         FrameIO.ForceSaveFrame(DisplayIO.getCurrentFrame());
    851                                         DisplayIO.setCurrentFrame(currentFrame, false);
    852                                 }
    853                         } catch (Exception ex) {
    854                         }
    855                         // if this is a copy command
    856                         break;
     769                        ItemSelection.paste();
     770                        return;
    857771                case KeyEvent.VK_C:
    858                         if (current == null)
     772                        if(FreeItems.itemsAttachedToCursor()) {
     773                                ItemSelection.copyClone(FreeItems.getInstance());
    859774                                return;
    860 
    861                         if (current instanceof Text) {
    862                                 if (current != null && !current.hasPermission(UserAppliedPermission.copy)) {
    863                                         MessageBay
    864                                                         .displayMessage("Insufficient permission to copy that item");
    865                                         return;
    866                                 }
     775                        }
     776                        if(current instanceof Text) {
    867777                                copyItemToClipboard(current);
    868                                 // MessageBay.displayMessage("Item copied to clipboard");
    869                                 return;
    870                         }
    871                         if (current != null && !current.hasPermission(UserAppliedPermission.full)) {
    872                                 MessageBay
    873                                                 .displayMessage("Insufficient permission edit that item");
    874                                 return;
    875778                        }
    876779                        Text item = null;
     
    895798                        return;
    896799                case KeyEvent.VK_X:
    897                         if (current == null)
    898                                 return;
    899                         if (current != null && !current.hasPermission(UserAppliedPermission.full)) {
    900                                 MessageBay
    901                                                 .displayMessage("Insufficient permission to cut that item");
    902                                 return;
    903                         }
    904                         copyItemToClipboard(current);
    905                         if (current instanceof Text && ((Text) current).hasSelection()) {
    906                                 ((Text) current).cutSelectedText();
    907                                 ((Text) current).clearSelection();
    908                         } else {
    909                                 FrameMouseActions.delete(current);
    910                         }
     800                        ItemSelection.cut(FreeItems.getInstance());
    911801                        return;
    912802                case KeyEvent.VK_M:
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r454 r504  
    66import java.awt.Rectangle;
    77import java.io.File;
     8import java.io.FileInputStream;
    89import java.io.FileNotFoundException;
     10import java.io.FileOutputStream;
    911import java.io.IOException;
     12import java.io.InputStream;
     13import java.net.JarURLConnection;
     14import java.net.URL;
    1015import java.util.ArrayList;
     16import java.util.Arrays;
    1117import java.util.Collection;
    1218import java.util.Collections;
    1319import java.util.Comparator;
     20import java.util.Enumeration;
    1421import java.util.LinkedHashSet;
    1522import java.util.LinkedList;
    1623import java.util.List;
     24import java.util.jar.JarEntry;
     25import java.util.jar.JarFile;
     26import java.util.zip.ZipEntry;
    1727
    1828import org.expeditee.agents.SearchGreenstone;
     
    2838import org.expeditee.items.Line;
    2939import org.expeditee.items.PermissionPair;
    30 import org.expeditee.items.UserAppliedPermission;
    3140import org.expeditee.items.Picture;
    3241import org.expeditee.items.Text;
     42import org.expeditee.items.UserAppliedPermission;
    3343import org.expeditee.items.XRayable;
    3444import org.expeditee.items.widgets.InteractiveWidget;
     
    15161526                yPos = intialYPos + spacing;
    15171527
    1518                 // Iterate through the help folder and add links
     1528                // Load documentation
     1529                extractDocumentation();
     1530               
     1531                // Add documentation links
    15191532                File helpDirectory = new File(FrameIO.HELP_PATH);
    15201533                if (helpDirectory != null) {
     
    16611674                }
    16621675        }
     1676       
     1677        private static void extractDocumentation() {
     1678                try     {
     1679                        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
     1680                        URL docURL = classLoader.getResource("org/expeditee/resources");
     1681                       
     1682                        String path;
     1683                        String classPath;
     1684                       
     1685                        // copy files from the jar file to the profile folder
     1686                        if (docURL.getProtocol().equals("jar")) {
     1687                                JarURLConnection ju_connection=(JarURLConnection)docURL.openConnection();
     1688                                JarFile jf =ju_connection.getJarFile();
     1689                                Enumeration<JarEntry> jarEntries = jf.entries();
     1690                               
     1691                                ZipEntry ze;
     1692                               
     1693                                while(jarEntries.hasMoreElements()) {
     1694                                        ze = jarEntries.nextElement();
     1695                                        if(!(ze.getName().startsWith("org/expeditee/resources/documentation") || ze.getName().startsWith("org/expeditee/resources/dict"))) {
     1696                                                continue;
     1697                                        }
     1698                                        // NOTE: assumes HELP_PATH is "${PARENT_FOLDER}/documentation/" and DICT_PATH is "${PARENT_FOLDER}/dict/"
     1699                                        File out = new File(FrameIO.PARENT_FOLDER + ze.getName().substring("org/expeditee/resources/".length()));
     1700                                        // System.out.println("Didn't crash here " + out.getPath());
     1701                                        if(out.exists()) {
     1702                                                continue;
     1703                                        }
     1704                                        if(ze.isDirectory()) {
     1705                                                // System.out.println(out.getPath() + " IS DIRECTORY");
     1706                                                out.mkdirs();
     1707                                                continue;
     1708                                        }
     1709                                        FileOutputStream fOut = null;
     1710                                        InputStream fIn = null;
     1711                                        try {
     1712                                                // System.out.println(out.getPath());
     1713                                                fOut =  new FileOutputStream(out);
     1714                                                fIn = classLoader.getResourceAsStream(ze.getName());
     1715                                                byte[] bBuffer = new byte[1024];
     1716                                                int nLen;
     1717                                                while ((nLen = fIn.read(bBuffer)) > 0) {
     1718                                                        fOut.write(bBuffer, 0, nLen);
     1719                                                }
     1720                                                fOut.flush();
     1721                                        } catch (Exception e) {
     1722                                                e.printStackTrace();
     1723                                        } finally {
     1724                                                if(fOut != null) {
     1725                                                        fOut.close();
     1726                                                }
     1727                                                if(fIn != null) {
     1728                                                        fIn.close();
     1729                                                }
     1730                                        }
     1731                                }
     1732                               
     1733                        // Copy files from the source folder to the profile folder
     1734                        } else {
     1735                                File folder = new File(docURL.toURI().getPath());
     1736                                LinkedList<File> items = new LinkedList<File>();
     1737                                items.addAll(Arrays.asList(folder.listFiles()));
     1738                                LinkedList<File> files = new LinkedList<File>();
     1739                                while (items.size() > 0) {
     1740                                        File file = items.remove(0);
     1741                                        if(file.isFile()) {
     1742                                                if(!file.getName().contains(".svn")) {
     1743                                                        files.add(file);
     1744                                                }
     1745                                        } else {
     1746                                                if (!file.getName().contains(".svn")) {
     1747                                                        items.addAll(Arrays.asList(file.listFiles()));
     1748                                                }
     1749                                        }
     1750                                }
     1751                                for (File file : files) {
     1752                                        if(file.getPath().contains("org/expeditee/resources/documentation")) {
     1753                                                path = FrameIO.HELP_PATH;
     1754                                                classPath = "org/expeditee/resources/documentation";
     1755                                        } else if (file.getPath().contains("org/expeditee/resources/dict")) {
     1756                                                path = FrameIO.DICT_PATH;
     1757                                                classPath = "org/expeditee/resources/dict";
     1758                                        } else {
     1759                                                continue;
     1760                                        }
     1761                                        File out = new File(path + file.getPath().substring(file.getPath().indexOf(classPath) + classPath.length()));
     1762                                        if(out.exists()) {
     1763                                                continue;
     1764                                        }
     1765                                        out.getParentFile().mkdirs();
     1766                                        FileOutputStream fOut = null;
     1767                                        FileInputStream fIn = null;
     1768                                        try {
     1769                                                // System.out.println(out.getPath());
     1770                                                fOut = new FileOutputStream(out);
     1771                                                fIn = new FileInputStream(file);
     1772                                                byte[] bBuffer = new byte[1024];
     1773                                                int nLen;
     1774                                                while ((nLen = fIn.read(bBuffer)) > 0) {
     1775                                                        fOut.write(bBuffer, 0, nLen);
     1776                                                }
     1777                                                fOut.flush();
     1778                                        } catch (Exception e) {
     1779                                                e.printStackTrace();
     1780                                        } finally {
     1781                                                if(fOut != null) {
     1782                                                        fOut.close();
     1783                                                }
     1784                                                if(fIn != null) {
     1785                                                        fIn.close();
     1786                                                }
     1787                                        }
     1788                                       
     1789                                }
     1790                        }
     1791                }
     1792                catch (Exception e)
     1793                {
     1794                        e.printStackTrace();
     1795                }
     1796        }
    16631797
    16641798        public static Text getLastEdited() {
  • trunk/src/org/expeditee/gui/UserSettings.java

    r490 r504  
    7474        static {
    7575                String expeditee_home = System.getProperty("expeditee.home");
    76 
    7776                if (expeditee_home != null) {
    78                     FrameIO.changeParentFolder(expeditee_home + File.separator);
    79                 }
    80                 else {
    81                     String jarPath = getJarLocation();
    82 
    83                     if (jarPath != null){
    84                         FrameIO.changeParentFolder(jarPath);
    85                     }
    86                     else {
    87 
    88                         FrameIO.changeParentFolder("." + File.separator + "expeditee"
    89                                                    + File.separator);
    90                     }
    91                 }
    92 
     77            FrameIO.changeParentFolder(expeditee_home + File.separator);
     78        } else {
     79                FrameIO.changeParentFolder(getSaveLocation());
     80        }
     81         
    9382                UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
    9483                UserSettings.FrameDirs.add(FrameIO.PUBLIC_PATH);
     
    10089
    10190        /**
    102          * Find where abouts the Jar is located that is running expeditee. The
    103          * reason for this was so that the framesets could be stored in the same
    104          * location as the jar file for now. Using the current directory fails to
    105          * achieve this as the current directory not the same as the directory the
    106          * jar is stored in if the user double clicks on the jar file in Linux or
    107          * runs the jar from the command line from another directory.
    108          *
    109          * @return the full path location of the Jar
     91         * Find the appropriate directory to store application settings in for
     92         * the current OS.
     93         * This has only been tested on Linux so far, so if it doesn't work it
     94         * may need to be modified or reverted. Should return:
     95         *      Linux: ~/.expeditee
     96         *      Windows: %appdata%\.expeditee
     97         *      Mac: ~/Library/Application\ Support/.expeditee
     98         * @return the path to store expeditee's settings
    11099         */
    111         public static String getJarLocation() {
    112                 // Get a File object for the package
    113                 File directory = null;
    114 
    115                 ClassLoader cld = Thread.currentThread().getContextClassLoader();
    116                 URL resource = cld.getResource("org");
    117                 directory = new File(resource.getFile());
    118 
    119                 int splitPoint = directory.getPath().indexOf('!');
    120                 if (splitPoint > 0) {
    121                         String jarName = directory.getPath().substring("file:".length(),
    122                                         splitPoint);
    123                         // Windows HACK
    124                         if (jarName.indexOf(":") >= 0)
    125                                 jarName = jarName.substring(1);
    126 
    127                         if (jarName.indexOf("%20") > 0) {
    128                                 jarName = jarName.replace("%20", " ");
    129                         }
    130 
    131                         int lastFileSeparator = jarName.lastIndexOf(File.separator);
    132                        
    133                         DisplayIO.TITLE = jarName.substring(lastFileSeparator + 1, jarName.length() - 4);
    134                        
    135                         return jarName.substring(0, lastFileSeparator + 1);
     100        public static String getSaveLocation() {
     101                String OS=System.getProperty("os.name").toLowerCase();
     102                if(OS.indexOf("win")>0) {                       //windoze
     103                        return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
     104                } else if(OS.indexOf("mac")>0) {        //mac
     105                        return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
     106                } else {                                                        //linux or other
     107                        return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
    136108                }
    137                 return null;
    138109        }
    139110}
  • trunk/src/org/expeditee/importer/FrameDNDTransferHandler.java

    r270 r504  
    5454                // TODO: Image
    5555                _standardFileImporters.add(new ImageImporter());
     56                _standardFileImporters.add(new pdfImporter());
    5657                _standardFileImporters.add(new TextImporter());
    5758                _standardFileImporters.add(new FilePathImporter()); // Filepath importer
  • trunk/src/org/expeditee/io/ExpReader.java

    r427 r504  
    4646         * @return true if s begins with a tag
    4747         */
    48         private static boolean isValidLine(String s) {
     48        protected static boolean isValidLine(String s) {
    4949                return s.length() >= 2 && s.charAt(1) == ' '
    5050                                && Character.isLetter(s.charAt(0));
     
    184184         *            The line of text read in from the file to process.
    185185         */
    186         private void processBodyLine(Item item, String line) {
     186        protected void processBodyLine(Item item, String line) {
    187187                // separate the tag from the value
    188188                Character tag = getTag(line);
     
    203203        }
    204204
    205         private static Character getTag(String line) {
     205        protected static Character getTag(String line) {
    206206                assert (line.length() > 0);
    207207                return line.charAt(0);
    208208        }
    209209
    210         private static String getValue(String line) {
     210        protected static String getValue(String line) {
    211211                if (line.length() > 2)
    212212                        return line.substring(2);
     
    250250
    251251        // Returns a point from a String containing two ints separated by a space
    252         private java.awt.Point separateValues(String line) {
     252        protected java.awt.Point separateValues(String line) {
    253253                int x = Integer.parseInt(line.substring(0, line.indexOf(" ")));
    254254                int y = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
  • trunk/src/org/expeditee/io/ExpWriter.java

    r362 r504  
    3131        private ProxyWriter _writer = null;
    3232
    33         private StringBuilder _stringWriter = null;
     33        protected StringBuilder _stringWriter = null;
    3434
    3535        private static final char TERMINATOR = 'Z';
     
    130130        }
    131131
    132         private void writeTerminator() throws IOException {
     132        protected void writeTerminator() throws IOException {
    133133                writeLine(TERMINATOR + "\n");
    134134        }
    135135
    136136        // writes the given line out to the file
    137         private void writeLine(String line) throws IOException {
     137        protected void writeLine(String line) throws IOException {
    138138                // do not write empty lines
    139139                if (line == null)
     
    152152                        return;
    153153
     154                writeItemAlways(item);
     155        }
     156       
     157        protected void writeItemAlways(Item item) throws IOException {
    154158                if (item.isLineEnd())
    155159                        writeLineEnd(item);
     
    173177
    174178        // writes out all lines to the file
    175         private void writeLineData() throws IOException {
     179        protected void writeLineData() throws IOException {
    176180                List<Line> seen = new LinkedList<Line>();
    177181
     
    206210
    207211        // writes out any constraints to the file
    208         private void writeConstraintData() throws IOException {
     212        protected void writeConstraintData() throws IOException {
    209213                // outputs any constraints the points have
    210214
  • trunk/src/org/expeditee/items/Text.java

    r475 r504  
    13211321
    13221322                float y = -1;
    1323 
    1324                 synchronized (_textLayouts) {
    1325                         for (TextLayout layout : _textLayouts) {
    1326                                 Rectangle2D bounds = layout.getLogicalHighlightShape(0,
    1327                                                 layout.getCharacterCount()).getBounds2D();
    1328 
    1329                                 if (y < 0)
    1330                                         y = 0;
    1331                                 else
    1332                                         y += getLineDrop(layout);
    1333 
    1334                                 maxX = Math.max(maxX, (int) bounds.getMaxX());
    1335                                 minX = Math.min(minX, (int) bounds.getMinX());
    1336                                 maxY = Math.max(maxY, (int) (bounds.getMaxY() + y));
    1337                                 minY = Math.min(minY, (int) (bounds.getMinY() + y));
    1338                         }
     1323               
     1324                // Fix concurrency error in ScaleFrameset
     1325                List<TextLayout> tmpTextLayouts;
     1326                synchronized(_textLayouts) {
     1327                        tmpTextLayouts = new LinkedList<TextLayout>(_textLayouts);
     1328                }
     1329
     1330                for (TextLayout layout : tmpTextLayouts) {
     1331                        Rectangle2D bounds = layout.getLogicalHighlightShape(0,
     1332                                        layout.getCharacterCount()).getBounds2D();
     1333               
     1334                        if (y < 0)
     1335                                y = 0;
     1336                        else
     1337                                y += getLineDrop(layout);
     1338
     1339                        maxX = Math.max(maxX, (int) bounds.getMaxX());
     1340                        minX = Math.min(minX, (int) bounds.getMinX());
     1341                        maxY = Math.max(maxY, (int) (bounds.getMaxY() + y));
     1342                        minY = Math.min(minY, (int) (bounds.getMinY() + y));
    13391343                }
    13401344
Note: See TracChangeset for help on using the changeset viewer.