Changeset 298


Ignore:
Timestamp:
09/12/08 11:53:22 (16 years ago)
Author:
ra33
Message:

Adding networking stuff for peer to peer sharing of frames

Location:
trunk/src/org/expeditee
Files:
2 added
1 deleted
27 edited
1 moved

Legend:

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

    r296 r298  
    108108                                        // This doesnt apply when running directly from the jar
    109109                                        // because the test classes are not compiled into the jar.
    110                                         if (!url.toString().toLowerCase().contains("test")) {
    111                                                 resource = url;
    112                                                 break;
    113                                         }
     110                                        // TODO change this so it is only done when running from
     111                                        // Eclipse... if it causes problems again!!
     112                                        // if (!url.toString().toLowerCase().contains("/tests/")) {
     113                                        resource = url;
     114                                        // break;
     115                                        // }
    114116                                }
    115117                        } catch (Exception e) {
     
    388390                command = command.substring(mname.length()).trim();
    389391                // If no params are provided get them from a text item on the cursor
    390                 if (command.length() == 0 && launcher instanceof Text && launcher.isFloating()) {
     392                if (command.length() == 0 && launcher instanceof Text
     393                                && launcher.isFloating()) {
    391394                        command = launcher.getText();
    392395                }
  • trunk/src/org/expeditee/actions/IDE.java

    r133 r298  
    1414                Frame source = DisplayIO.getCurrentFrame();
    1515                String title = source.getTitleItem().getText();
    16                 String[] tokens = title.split(" ");
     16                String[] tokens = title.split("\\s+");
    1717                String className = tokens[tokens.length - 1];
    1818                String fileName = "expeditee/src/" + className + ".java";
  • trunk/src/org/expeditee/actions/Simple.java

    r291 r298  
    13821382                                        String frameName = context.getPrimitives().getStringValue(
    13831383                                                        tokens[1]);
    1384                                         String path = FrameIO.LoadFrame(frameName).path;
     1384                                        String path = FrameIO.LoadFrame(frameName).getPath();
    13851385                                        String filePath = FrameIO.getFrameFullPathName(path,
    13861386                                                        frameName);
     
    20002000                        String framesetName = context.getPrimitives().getStringValue(
    20012001                                        tokens[1]);
    2002                         boolean success = FrameIO.DeleteFrameset(framesetName);
     2002                        boolean success = FrameIO.deleteFrameset(framesetName);
    20032003                        if (!success && _verbose) {
    20042004                                MessageBay.warningMessage("Error deleting " + framesetName);
     
    20492049                                try {
    20502050                                        FrameIO.CreateFrameset(freshCopy.getFramesetName(),
    2051                                                         frameToCopy.path);
     2051                                                        frameToCopy.getPath());
    20522052                                        nextNumber = 1;
    20532053                                } catch (Exception e) {
  • trunk/src/org/expeditee/agents/CopyTree.java

    r133 r298  
    3838                        // get the last used frame in the destination frameset
    3939                        _lastNumber = FrameIO.getLastNumber(_nameTo);
    40                         Frame one = FrameIO.CreateFrameset(_nameTo, init.path);
     40                        Frame one = FrameIO.CreateFrameset(_nameTo, init.getPath());
    4141
    42                         _framePath = one.path;
     42                        _framePath = one.getPath();
    4343                        _lastNumber = -1;
    4444                        _firstNumber = 1;
     
    104104                        }
    105105                _frameCount++;
    106                 fresh.path = _framePath;
     106                fresh.setPath(_framePath);
    107107                FrameIO.ForceSaveFrame(fresh);
    108108                FrameIO.ResumeCache();
  • trunk/src/org/expeditee/agents/SearchAgent.java

    r294 r298  
    6565                String title = this.getClass().getSimpleName() + " [" + startName
    6666                                + "] [" + _pattern + "]";
    67                 _results = new FrameCreator(resultsFrameset, null, title, false, true);
     67                _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title, false, true);
    6868                // Set the frame to be displayed after running the agent
    6969                _end = _results.getFirstFrame();
  • trunk/src/org/expeditee/agents/SearchFramesetFast.java

    r292 r298  
    2727                        frame = FrameIO.LoadFrame(_startName + '0');
    2828                }
    29                 String path = frame.path;
     29                String path = frame.getPath();
    3030               
    3131                int count = FrameIO.getLastNumber(_startName);
  • trunk/src/org/expeditee/agents/SearchFramesetNoResults.java

    r292 r298  
    2525        @Override
    2626        protected Frame process(Frame frame) {
    27                 String path = frame.path;
     27                String path = frame.getPath();
    2828                int count = FrameIO.getLastNumber(frame.getFramesetName());
    2929                for (long i = _firstFrame;i <= _maxFrame && i <= count; i++) {
  • trunk/src/org/expeditee/agents/mail/MailSession.java

    r292 r298  
    207207                                                        } catch (Exception e) {
    208208                                                                e.printStackTrace();
     209                                                                MessageBay.errorMessage("Mail connection unavailable");
     210                                                                finalise();
     211                                                                break;
    209212                                                        }
    210213                                                }
     
    464467                                        // Create a frameCreator
    465468                                        final FrameCreator frames = new FrameCreator(frame
    466                                                         .getFramesetName(), frame.path, subject, false, false);
     469                                                        .getFramesetName(), frame.getPath(), subject, false, false);
    467470
    468471                                        frames.addText("@date: " + message.getSentDate(), null,
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r282 r298  
    262262                                        pJustification));
    263263                        _SetMethods.put("width", Text.class.getMethod("setWidth", pInt));
     264                        _SetMethods.put("w", Text.class.getMethod("setWidth", pInt));
     265                       
    264266                        _SetMethods.put("size", Item.class.getMethod("setSize", pFloat));
    265267                        _SetMethods.put("s", Item.class.getMethod("setSize", pFloat));
  • trunk/src/org/expeditee/gui/Browser.java

    r290 r298  
    2727import org.expeditee.io.Logger;
    2828import org.expeditee.items.widgets.WidgetCacheManager;
     29import org.expeditee.network.FrameShare;
    2930import org.expeditee.stats.StatsLogger;
    3031import org.expeditee.taskmanagement.EntitySaveManager;
     
    393394                                                MessageBay
    394395                                                                .displayMessage("Stopping Simple programs..."); // TODO:
    395                                                 // Only
    396                                                 // stop
    397                                                 // if
    398                                                 // need
    399                                                 // to...
     396                                                /**
     397                                                 * Only stop if need to...
     398                                                 */
    400399                                                while (Simple.isProgramRunning()) {
    401400                                                        Thread.sleep(100); // Brook: What purpose does this
     
    419418                                        FrameIO.SaveFrame(DisplayIO.getCurrentFrame());
    420419
    421                                         while (FrameIO.DeleteFrameset("messages"))
     420                                        while (FrameIO.moveFrameset("messages",
     421                                                        FrameIO.MESSAGES_PATH))
    422422                                                ;
    423423
     
    427427                                        if (MailSession.getInstance() != null) {
    428428                                                if (MailSession.getInstance().finalise()) {
    429                                                         MessageBay.displayMessage("Closing ExpMail...");
     429                                                        // TODO display this message before the finalising
     430                                                        // is done but only if the mail needs closing
     431                                                        MessageBay.displayMessage("Closed ExpMail...");
    430432                                                }
     433                                        }
     434
     435                                        if (FrameShare.getInstance() != null) {
     436                                                MessageBay.displayMessage("Stopping FrameServer...");
     437                                                FrameShare.getInstance().finalise();
    431438                                        }
    432439
  • trunk/src/org/expeditee/gui/Frame.java

    r294 r298  
    8383        private Color _foreground = null;
    8484
    85         public String path;
     85        private String path;
     86       
     87        private boolean _isLocal = true;
    8688
    8789        private boolean _sorted = true;
     
    201203                boolean oldValue = _change;
    202204
     205                if (value) {
     206                        notifyObservers();
     207                }
     208               
    203209                if (oldValue == value)
    204210                        return;
     
    207213
    208214                if (_change) {
    209                         notifyObservers();
    210 
    211215                        setBufferValid(false);
    212216                        _saved = false;
     
    20482052                FrameUtils.Parse(this);
    20492053        }
     2054
     2055        public void setPath(String path) {
     2056                this.path = path;
     2057        }
     2058
     2059        public String getPath() {
     2060                return path;
     2061        }
     2062
     2063        public void setLocal(boolean isLocal) {
     2064                this._isLocal = isLocal;
     2065        }
     2066
     2067        public boolean isLocal() {
     2068                return _isLocal;
     2069        }
    20502070}
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r292 r298  
    3939        public FrameCreator(String frameTitle) {
    4040                this(DisplayIO.getCurrentFrame().getFramesetName(), DisplayIO
    41                                 .getCurrentFrame().path, frameTitle, false, false);
     41                                .getCurrentFrame().getPath(), frameTitle, false, false);
    4242        }
    4343
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r296 r298  
    6161        public static void ToggleAudienceMode() {
    6262                Frame current = DisplayIO.getCurrentFrame();
    63                 if (_Mode == MODE_AUDIENCE)
     63                if (_Mode == MODE_XRAY) {
     64                        ToggleXRayMode();
     65                }
     66
     67                if (_Mode == MODE_AUDIENCE) {
    6468                        _Mode = MODE_NORMAL;
    65                 else {
     69                } else {
    6670                        _Mode = MODE_AUDIENCE;
    6771                        ItemUtils.UpdateConnectedToAnnotations(current.getItems());
     
    8690         */
    8791        public static void ToggleXRayMode() {
    88                 if (_Mode == MODE_XRAY)
     92                if (_Mode == MODE_AUDIENCE) {
     93                        ToggleAudienceMode();
     94                }
     95
     96                if (_Mode == MODE_XRAY) {
    8997                        setMode(MODE_NORMAL, true);
    90                 else
     98                } else {
    9199                        setMode(MODE_XRAY, true);
     100                }
     101                DisplayIO.getCurrentFrame().refreshSize();
    92102                DisplayIO.UpdateTitle();
    93103                FrameMouseActions.getInstance().refreshHighlights();
  • trunk/src/org/expeditee/gui/FrameIO.java

    r294 r298  
    2828import org.expeditee.items.Permission;
    2929import org.expeditee.items.Text;
     30import org.expeditee.network.FrameShare;
    3031import org.expeditee.stats.SessionStats;
    3132
     
    4647                PUBLIC_PATH = PARENT_FOLDER + "public" + File.separator;
    4748                FRAME_PATH = PARENT_FOLDER + "framesets" + File.separator;
     49                MESSAGES_PATH = PARENT_FOLDER + "messages" + File.separator;
    4850                TRASH_PATH = PARENT_FOLDER + "trash" + File.separator;
    4951                IMAGES_PATH = PARENT_FOLDER + IMAGES_FOLDER;
     
    6668
    6769        public static String FRAME_PATH;
    68        
     70
     71        public static String MESSAGES_PATH;
     72
    6973        public static String PUBLIC_PATH;
    7074
     
    148152                return LoadFrame(frameName, false);
    149153        }
    150        
     154
    151155        public static Frame LoadFrame(String frameName, boolean ignoreAnnotations) {
    152156                if (!isValidFrameName(frameName))
     
    167171        }
    168172
    169         private static Frame LoadUnknownPath(String framename, boolean ignoreAnnotations) {
     173        public static String LoadPublicFrame(String frameName) {
     174                assert (isValidFrameName(frameName));
     175                Frame loaded = null;
     176                String frameNameLower = frameName.toLowerCase();
     177                // first try reading from cache
     178                if (isCacheOn() && _Cache.containsKey(frameNameLower)) {
     179                        Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName
     180                                        + " from cache.");
     181                        loaded = _Cache.get(frameNameLower);
     182                } else {
     183
     184                        Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName
     185                                        + " from disk.");
     186
     187                        loaded = LoadFrame(PUBLIC_PATH, frameName);
     188                }
     189
     190                String result = null;
     191                // Get the contents of the frame to send to someone...
     192                // TODO use a more efficient method to directly get the frame contents
     193                // if possible
     194                if (loaded != null) {
     195                        result = SaveFrame(loaded);
     196                }
     197
     198                return result;
     199        }
     200
     201        private static Frame LoadUnknownPath(String framename,
     202                        boolean ignoreAnnotations) {
    170203                Frame loaded = null;
    171204
     
    173206                        loaded = LoadFrame(path, framename);
    174207                        if (loaded != null) {
    175                                 FrameUtils.Parse(loaded, true, ignoreAnnotations);
    176208                                break;
    177209                        }
     210                }
     211
     212                if (loaded == null) {
     213                        loaded = FrameShare.getInstance().loadFrame(framename);
     214                }
     215
     216                if (loaded != null) {
     217                        FrameUtils.Parse(loaded, true, ignoreAnnotations);
    178218                }
    179219
     
    215255         * @return null if the frame can not be located.
    216256         */
    217         public static synchronized String getFrameFullPathName(String path, String frameName) {
     257        public static synchronized String getFrameFullPathName(String path,
     258                        String frameName) {
    218259                String source = path + Conversion.getFramesetName(frameName)
    219260                                + File.separator;
     
    244285        public static boolean canAccessFrame(String frameName) {
    245286                Frame current = DisplayIO.getCurrentFrame();
    246                 //Just incase the current frame is not yet saved...
    247                 if(frameName.equals(current.getName())){
    248                         FrameIO.SaveFrame(current,false,false);
     287                // Just incase the current frame is not yet saved...
     288                if (frameName.equals(current.getName())) {
     289                        FrameIO.SaveFrame(current, false, false);
    249290                        current.change();
    250291                        return true;
    251292                }
    252                
     293
    253294                for (String path : UserSettings.FrameDirs) {
    254295                        if (getFrameFullPathName(path, frameName) != null)
     
    315356                        }
    316357
    317                         frame.path = path;
     358                        frame.setPath(path);
    318359
    319360                        // do not put 0 frames or virtual frames into the cache
     
    388429                // read the maximum from the INF file
    389430                try {
    390                         max = ReadINF(current.path, current.getFramesetName());
     431                        max = ReadINF(current.getPath(), current.getFramesetName());
    391432                } catch (IOException ioe) {
    392433                        MessageBay.errorMessage("Error loading INF file for frameset '"
     
    453494        public static Frame LoadZero() {
    454495                Frame current = DisplayIO.getCurrentFrame();
    455                 return LoadZero(current.getFramesetName(), current.path);
     496                return LoadZero(current.getFramesetName(), current.getPath());
    456497        }
    457498
    458499        public static Frame LoadLast() {
    459500                Frame current = DisplayIO.getCurrentFrame();
    460                 return LoadLast(current.getFramesetName(), current.path);
     501                return LoadLast(current.getFramesetName(), current.getPath());
    461502        }
    462503
     
    486527                if (toDelete.getNumber() == 0) {
    487528                        throw new SecurityException("Deleting a zero frame is illegal");
     529                }
     530
     531                // Dont delete the zero frame
     532                if (!toDelete.isLocal()) {
     533                        throw new SecurityException("Attempted to delete remote frame");
    488534                }
    489535
     
    497543                try {
    498544                        // create the new frameset
    499                         Frame one = FrameIO.CreateFrameset(DELETED_FRAMES, toDelete.path);
    500                         framePath = one.path;
     545                        Frame one = FrameIO.CreateFrameset(DELETED_FRAMES, toDelete
     546                                        .getPath());
     547                        framePath = one.getPath();
    501548                        lastNumber = 0;
    502549                } catch (Exception e) {
    503550                        Frame zero = FrameIO.LoadFrame(DELETED_FRAMES + "0");
    504                         framePath = zero.path;
     551                        framePath = zero.getPath();
    505552                }
    506553
    507554                // get the fill path to determine which file version it is
    508                 String source = getFrameFullPathName(toDelete.path, toDelete.getName());
     555                String source = getFrameFullPathName(toDelete.getPath(), toDelete
     556                                .getName());
    509557
    510558                String oldFrameName = toDelete.getName().toLowerCase();
     
    512560                toDelete.setFrameset(DELETED_FRAMES);
    513561                toDelete.setFrameNumber(lastNumber + 1);
    514                 toDelete.path = framePath;
     562                toDelete.setPath(framePath);
    515563                ForceSaveFrame(toDelete);
    516564
     
    542590         * @return The newly created Frame.
    543591         */
    544         public static synchronized Frame CreateFrame(String frameset, String frameTitle,
    545                         String templateFrame) throws RuntimeException {
     592        public static synchronized Frame CreateFrame(String frameset,
     593                        String frameTitle, String templateFrame) throws RuntimeException {
    546594
    547595                if (!FrameIO.isValidFramesetName(frameset)) {
     
    576624                // read the next number from the INF file
    577625                try {
    578                         next = ReadINF(destFramesetZero.path, frameset);
     626                        next = ReadINF(destFramesetZero.getPath(), frameset);
    579627                } catch (IOException ioe) {
    580628                        ioe.printStackTrace();
     
    595643                // update INF file
    596644                try {
    597                         WriteINF(template.path, frameset, frameset + next);
     645                        WriteINF(template.getPath(), frameset, frameset + next);
    598646                } catch (IOException ioe) {
    599647                        ioe.printStackTrace();
     
    739787                        return "";
    740788                }
    741                 // Get the full path only to determine which format to use for saving
    742                 // the frame
    743                 // At this stage use Exp format for saving Exp frames only.
    744                 // Later this will be changed so that KMS frames will be updated to the
    745                 // Exp format.
    746                 String fullPath = getFrameFullPathName(toSave.path, toSave.getName());
    747789
    748790                // Dont save if the frame is protected and it exists
     
    752794                        return "";
    753795                }
     796
     797                // Save frame that is not local through the Networking classes
     798                // TODO
     799                if (!toSave.isLocal())
     800                        return "";
     801
     802                /**
     803                 * Get the full path only to determine which format to use for saving
     804                 * the frame. At this stage use Exp format for saving Exp frames only.
     805                 * Later this will be changed so that KMS frames will be updated to the
     806                 * Exp format.
     807                 */
     808                String fullPath = getFrameFullPathName(toSave.getPath(), toSave
     809                                .getName());
    754810
    755811                // Check if the frame exists
     
    778834                                // This will make sure links to the original are set correctly
    779835                                _Cache.remove(toSave.getName().toLowerCase());
    780                                 int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
     836                                int nextnum = ReadINF(toSave.getPath(), toSave
     837                                                .getFramesetName()) + 1;
    781838                                SuspendCache();
    782839                                Frame original = LoadFrame(toSave.getName());
     
    806863                                        original = toSave;
    807864                                int orignum = original.getNumber();
    808                                 int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
     865                                int nextnum = ReadINF(toSave.getPath(), toSave
     866                                                .getFramesetName()) + 1;
    809867
    810868                                original.setFrameNumber(nextnum);
     
    849907
    850908                        // check that the INF file is not out of date
    851                         int last = ReadINF(toSave.path, toSave.getFramesetName());
     909                        int last = ReadINF(toSave.getPath(), toSave.getFramesetName());
    852910                        if (last <= toSave.getNumber())
    853                                 WriteINF(toSave.path, toSave.getFramesetName(), toSave
     911                                WriteINF(toSave.getPath(), toSave.getFramesetName(), toSave
    854912                                                .getName());
    855913
     
    9531011                return _Cache.containsKey(name);
    9541012        }
    955        
     1013
    9561014        /**
    9571015         * Gets a frame from the cache.
    9581016         *
    9591017         * @param name
    960          *              The frame to get from the cache
    961          *
    962          * @return
    963          *              The frame from cache. Null if not cached.
     1018         *            The frame to get from the cache
     1019         *
     1020         * @return The frame from cache. Null if not cached.
    9641021         */
    9651022        public static Frame FrameFromCache(String name) {
     
    10271084         */
    10281085        public static Frame CreateNewFrameset(String name) throws Exception {
    1029                 String path = DisplayIO.getCurrentFrame().path;
     1086                String path = DisplayIO.getCurrentFrame().getPath();
    10301087
    10311088                // if current frameset is profile directory change it to framesets
     
    10551112
    10561113                try {
    1057                         num = ReadINF(zero.path, frameset);
     1114                        num = ReadINF(zero.getPath(), frameset);
    10581115                } catch (IOException e) {
    10591116                        // TODO Auto-generated catch block
     
    11461203                base.setFrameNumber(0);
    11471204                base.setTitle(base.getFramesetName() + "0");
    1148                 base.path = path;
     1205                base.setPath(path);
    11491206                base.change();
    11501207                SaveFrame(base, false);
     
    11941251        }
    11951252
    1196         public static boolean DeleteFrameset(String framesetName) {
     1253        public static boolean deleteFrameset(String framesetName) {
     1254                return moveFrameset(framesetName, FrameIO.TRASH_PATH);
     1255        }
     1256
     1257        public static boolean moveFrameset(String framesetName,
     1258                        String destinationFolder) {
    11971259                if (!FrameIO.canAccessFrameset(framesetName))
    11981260                        return false;
     
    12031265                        // Once we have found the directory move it to the trash
    12041266                        if (framesetDirectory.exists()) {
    1205                                 String destPath = FrameIO.TRASH_PATH
     1267                                String destPath = destinationFolder
    12061268                                                + framesetName.toLowerCase();
    12071269                                int copyNumber = 1;
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r287 r298  
    16031603
    16041604        private void mouseMoved(MouseEvent e, boolean shiftStateChanged) {
    1605                 FrameKeyboardActions.resetEnclosedItems();
     1605                //System.out.println(_context);
     1606                if (_context == CONTEXT_FREESPACE)
     1607                        FrameKeyboardActions.resetEnclosedItems();
    16061608                // System.out.println(e.getX() + "," + e.getY() + " " + e.getWhen());
    16071609                if (LastRobotX != null) {
     
    18701872                                                        Item.HighlightMode.Enclosed);
    18711873                                }
     1874                                _context = CONTEXT_AT_ENCLOSURE;
    18721875                        } else if (_lastHighlightedItem != null) {
    18731876                                // System.out.println("LastHighlightedItem");
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r289 r298  
    3232import org.expeditee.items.widgets.WidgetCorner;
    3333import org.expeditee.items.widgets.WidgetEdge;
    34 import org.expeditee.network.PeerToPeer;
     34import org.expeditee.network.FrameShare;
    3535import org.expeditee.stats.SessionStats;
    3636import org.jfree.util.ArrayUtilities;
     
    583583                        else if (attribute.equals("mailsettings"))
    584584                                MailSession.init(item.getChild());
    585                         else if (attribute.equals("peertopeersettings"))
    586                                 PeerToPeer.init(item.getChild());
     585                        else if (attribute.equals("networksettings"))
     586                                FrameShare.init(item.getChild());
    587587                        else if (attribute.equals("reminders"))
    588588                                Reminders.init(item.getChild());
  • trunk/src/org/expeditee/gui/MessageBay.java

    r292 r298  
    282282                if (_creator == null) {
    283283                        _creator = new FrameCreator(MESSAGES_FRAMESET_NAME,
    284                                         FrameIO.PROFILE_PATH, MESSAGES_FRAMESET_NAME, true, false);
     284                                        FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false);
    285285                }
    286286
  • trunk/src/org/expeditee/gui/UserSettings.java

    r289 r298  
    8080                UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
    8181                UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
     82                UserSettings.FrameDirs.add(FrameIO.MESSAGES_PATH);
    8283        }
    8384
  • trunk/src/org/expeditee/io/ExpReader.java

    r247 r298  
    6060         *             Any exceptions occured by the BufferedReader.
    6161         */
    62         public Frame readFrame(String fullpath) throws IOException {
    63                 _reader = new BufferedReader(new FileReader(fullpath));
     62        public Frame readFrame(BufferedReader reader) throws IOException {
     63                _reader = reader;
    6464                String next = "";
    6565                Frame newFrame = new Frame();
  • trunk/src/org/expeditee/io/ExpWriter.java

    r198 r298  
    3939
    4040                if (_filename == null)
    41                         _filename = start.path + name + File.separator
     41                        _filename = start.getPath() + name + File.separator
    4242                                        + start.getNumber() + ExpReader.EXTENTION;
    4343
  • trunk/src/org/expeditee/io/FrameReader.java

    r241 r298  
    44import java.awt.Font;
    55import java.awt.Point;
     6import java.io.BufferedReader;
     7import java.io.FileReader;
    68import java.io.IOException;
    79import java.lang.reflect.Method;
     
    126128        }
    127129       
    128         public abstract Frame readFrame(String fullPath) throws IOException;
     130        public Frame readFrame(String fullPath) throws IOException {
     131                return readFrame(new BufferedReader(new FileReader(fullPath)));
     132        }
     133       
     134        public abstract Frame readFrame(BufferedReader frameContents) throws IOException;
    129135}
  • trunk/src/org/expeditee/io/KMSReader.java

    r247 r298  
    151151         *             Any exceptions occured by the BufferedReader.
    152152         */
    153         public Frame readFrame(String fullPath) throws IOException {
    154                 _reader = new BufferedReader(new FileReader(fullPath));
     153        public Frame readFrame(BufferedReader reader) throws IOException {
     154                _reader = reader;
    155155                Frame newFrame = null;
    156156                String next = "";
  • trunk/src/org/expeditee/io/KMSWriter.java

    r143 r298  
    4242
    4343                if (_filename == null)
    44                         _filename = start.path + name + File.separator + name + "."
     44                        _filename = start.getPath() + name + File.separator + name + "."
    4545                                        + start.getNumber();
    4646
  • trunk/src/org/expeditee/items/Line.java

    r278 r298  
    8686
    8787        private void refreshStroke(float thick) {
     88                thick = Math.round(thick);
     89               
    8890                int[] pattern = _start.getLinePattern();
    8991                if (pattern == null)
     
    259261                super.setLinePattern(pattern);
    260262
    261                 float thick = getThickness();
     263                float thick = Math.round(getThickness());
    262264
    263265                if (thick < 0)
  • trunk/src/org/expeditee/items/Text.java

    r291 r298  
    936936        private static final int NEARBY_GRAVITY = 2;
    937937
    938         private static final int MINIMUM_FONT_SIZE = 8;
     938        private static final int MINIMUM_FONT_SIZE = 6;
    939939
    940940        public void toggleFontFamily() {
  • trunk/src/org/expeditee/items/widgets/charts/AbstractChart.java

    r279 r298  
    6969                // create a chart...
    7070                _chart = createNewChart();
    71                 _chart.getPlot().setNoDataMessage("Add link to data frame");
     71                _chart.getPlot().setNoDataMessage("Add data to chart");
    7272                _legend = _chart.getLegend();
    7373                ChartPanel cp = new ChartPanel(_chart);
  • trunk/src/org/expeditee/items/widgets/charts/AbstractPie.java

    r294 r298  
    6565                                continue;
    6666                        AttributeValuePair avp = new AttributeValuePair(text);
    67                         if (avp != null) {
     67                        if (avp != null && avp.hasPair()) {
    6868                                try {
    6969                                        _data.setValue(avp.getAttribute(), avp.getDoubleValue());
  • trunk/src/org/expeditee/network/FrameShare.java

    r294 r298  
    11package org.expeditee.network;
    22
     3import java.io.BufferedReader;
     4import java.io.IOException;
     5import java.io.StringReader;
     6import java.net.DatagramPacket;
     7import java.net.DatagramSocket;
     8import java.net.UnknownHostException;
    39import java.util.HashMap;
    410import java.util.Map;
     
    713import org.expeditee.gui.Frame;
    814import org.expeditee.gui.MessageBay;
     15import org.expeditee.io.ExpReader;
     16import org.expeditee.io.FrameReader;
    917import org.expeditee.items.Text;
    10 import org.net.p2p.Connection;
    11 import org.net.p2p.Protocol;
    12 import org.net.p2p.jnmp2p;
    1318
     19public class FrameShare {
    1420
    15 public class PeerToPeer {
    16         public static boolean _autoConnect = false;
     21        private static FrameShare _theSession = null;
    1722
    18         private static PeerToPeer _theSession = null;
     23        private static FrameServer _server = null;
    1924
    20         private Map<String, AttributeValuePair> _peers;
    21        
    22         private Map<String, Connection> _peerConnections;
    23 
    24         private Boolean _bConnecting;
     25        private Map<String, Peer> _peers;
    2526
    2627        public static void init(Frame settingsFrame) {
     
    2930
    3031                if (_theSession == null)
    31                         _theSession = new PeerToPeer(settingsFrame);
     32                        _theSession = new FrameShare(settingsFrame);
    3233        }
    33        
    34         private PeerToPeer(Frame settingsFrame) {
    35                 _bConnecting = false;
    3634
    37                 _peers = new HashMap<String, AttributeValuePair>();
     35        private FrameShare(Frame settingsFrame) {
     36                _peers = new HashMap<String, Peer>();
    3837
    3938                // Set the settings
    4039                for (Text item : settingsFrame.getBodyTextItems(false)) {
    41                         if (item.getText().toLowerCase().trim().equals("autoconnect")) {
    42                                 _autoConnect = true;
     40                        String text = item.getText().toLowerCase().trim();
     41                        AttributeValuePair avp = new AttributeValuePair(item.getText());
     42
     43                        if (text.equals("server")) {
     44                                try {
     45                                        if (!avp.hasPair()) {
     46                                                _server = new FrameServer();
     47                                        } else {
     48                                                _server = new FrameServer("FrameServer", avp
     49                                                                .getIntegerValue());
     50                                        }
     51                                } catch (Exception e) {
     52                                        e.printStackTrace();
     53                                        MessageBay.errorMessage("Could not start frame server ["
     54                                                        + avp.toString() + "]");
     55                                }
    4356                                continue;
    4457                        }
    45                         AttributeValuePair avp = new AttributeValuePair(item.getText());
     58
    4659                        if (!avp.hasPair())
    4760                                continue;
    48                         String attributeFullCase = avp.getAttribute();
    49                         String attribute = attributeFullCase.toLowerCase();
    50                        
    51                         _peers.put(attribute, avp);
     61                        String attribute = avp.getAttribute().toLowerCase();
     62
     63                        try {
     64                                _peers.put(attribute, new Peer(avp));
     65                        } catch (UnknownHostException e) {
     66                                MessageBay.errorMessage("Could not locate peer ["
     67                                                + avp.toString() + "]");
     68                        }
    5269                }
    5370
    54                
    5571                try {
    56                         if (_autoConnect) {
    57                                 connectThreaded();
     72                        if (_server != null) {
     73                                _server.start();
    5874                        }
    5975                } catch (Exception e) {
     
    6177                }
    6278        }
     79       
     80        public void finalise() {
     81                _server.close();
     82        }
     83
     84        public static FrameShare getInstance() {
     85                return _theSession;
     86        }
    6387
    6488        /**
    65          * Attempts to connect with peers.
     89         * TODO check each peer on a different thread.
     90         *
     91         * @param frameName
     92         * @return
    6693         */
    67         public static void connect() {
    68                 if (_theSession._bConnecting) {
    69                         MessageBay.errorMessage("Already connecting to peers");
    70                         return;
    71                 } else if (_theSession != null) {
    72                         _theSession.connectThreaded();
     94        public Frame loadFrame(String frameName) {
     95                byte[] nameBuf = frameName.getBytes();
     96                byte[] buf = new byte[2056];
     97
     98                String result = null;
     99                String peerName = null;
     100                try {
     101                        // get a datagram socket
     102                        DatagramSocket socket = new DatagramSocket();
     103                        socket.setSoTimeout(1000);
     104
     105                        for (Peer peer : _peers.values()) {
     106                                try {
     107                                        // send request for a frame
     108                                        DatagramPacket packet = new DatagramPacket(nameBuf,
     109                                                        nameBuf.length, peer.getAddress(), peer.getPort());
     110                                        socket.send(packet);
     111
     112                                        // get response
     113                                        packet = new DatagramPacket(buf, buf.length);
     114                                        socket.receive(packet);
     115
     116                                        // store frame contents
     117                                        result = new String(packet.getData(), 0, packet.getLength());
     118                                        peerName = peer.getName();
     119                                        break;
     120                                } catch (Exception e) {
     121                                }
     122                        }
     123                        socket.close();
     124                } catch (Exception e) {
     125
    73126                }
    74         }
    75127
    76         private void connectThreaded() {
    77                 Thread t = new ConnectThread(this);
    78                 t.start();
    79         }
     128                // Now read the frame from the file contents
     129                FrameReader reader = new ExpReader(frameName);
     130                Frame frame = null;
     131                try {
     132                        frame = reader.readFrame(new BufferedReader(
     133                                        new StringReader(result)));
     134                        // Set the path for the frame to indicate it is NOT a local frame
     135                        // This allows the frame to be saved in the correct location
     136                        frame.setLocal(false);
     137                        frame.setPath(peerName);
     138                } catch (IOException e) {
     139                        e.printStackTrace();
     140                }
    80141
    81         public synchronized void connectToPeers() {
    82                 _bConnecting = true;
    83                
    84                 //Connect to peers
    85                 Protocol p = new Protocol(new Object());
    86                
    87                 jnmp2p jnm = new jnmp2p(p, 3000);
    88                
    89                 for(AttributeValuePair avp: _peers.values()){
    90                         _peerConnections.put(avp.getAttribute().toLowerCase(), jnm.connect(avp.getValue()));
     142                if (frame == null) {
     143                        MessageBay.errorMessage("Error: " + frameName
     144                                        + " could not be successfully loaded.");
     145                        return null;
    91146                }
    92                
    93                 _bConnecting = false;
     147
     148                return frame;
    94149        }
    95150}
Note: See TracChangeset for help on using the changeset viewer.