Changeset 1280 for trunk


Ignore:
Timestamp:
04/04/19 14:41:47 (5 years ago)
Author:
bln4
Message:

Renamed MailMode action to ToggleBay
Renamed FrameCreator enums to more desirable names (David request)
Created test for altered functionality of FrameCreator as documented below.

FrameCreator now more cleanly obeys the specification of the enum parameter to its constructor. For example, override existing frameset ensures that the old frameset has been deleted (moved to trash).

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

Legend:

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

    r1196 r1280  
    2828import javax.swing.JPanel;
    2929
     30import org.expeditee.core.Colour;
    3031import org.expeditee.gio.swing.SwingGraphicsManager;
    3132import org.expeditee.gio.swing.SwingInputManager;
    3233import org.expeditee.gui.DisplayController;
     34import org.expeditee.gui.FrameCreator;
     35import org.expeditee.gui.FrameIO;
    3336import org.expeditee.gui.MessageBay;
    3437import org.expeditee.items.Constraint;
     
    126129                MessageBay.displayMessage(DisplayController.getCurrentFrame().getItems().stream().filter(t -> t.getMinWidth() != null).collect(Collectors.toList()).size() + "");
    127130        }
     131       
     132        public static void FrameCreatorTest() {
     133                FrameCreator creator = new FrameCreator("testFrameset", FrameIO.FRAME_PATH, "TestFrameset", FrameCreator.ExistingFramesetOptions.AppendSegregatedFrames, false);
     134                creator.addText("Test1", Colour.CYAN, null, null, true);
     135               
     136                creator = new FrameCreator("testFrameset", FrameIO.FRAME_PATH, "TestFrameset", FrameCreator.ExistingFramesetOptions.AppendSegregatedFrames, false);
     137                creator.addText("Test2", Colour.CYAN, null, null, true);
     138               
     139                creator = new FrameCreator("testFrameset", FrameIO.FRAME_PATH, "TestFrameset", FrameCreator.ExistingFramesetOptions.OverrideExistingFrames, false);
     140                creator.addText("Test3", Colour.CYAN, null, null, true);
     141        }
    128142}
  • trunk/src/org/expeditee/agents/SearchAgent.java

    r1276 r1280  
    9898                                + "]"+getResultsTitleSuffix();
    9999                _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title,
    100                                 FrameCreator.ExistingFramesetOptions.CreateNewFramesOnly, true);
     100                                FrameCreator.ExistingFramesetOptions.AppendSegregatedFrames, true);
    101101                // Set the frame to be displayed after running the agent
    102102                _end = _results.getFirstFrame();
  • trunk/src/org/expeditee/agents/mail/MailSession.java

    r1276 r1280  
    527527                                        final FrameCreator frames = new FrameCreator(frame
    528528                                                        .getFramesetName(), frame.getPath(), subject,
    529                                                         FrameCreator.ExistingFramesetOptions.CreateNewFramesOnly, false);
     529                                                        FrameCreator.ExistingFramesetOptions.AppendSegregatedFrames, false);
    530530
    531531                                        frames.addText("@date: " + message.getSentDate(), null,
  • trunk/src/org/expeditee/auth/Actions.java

    r1279 r1280  
    9797         * @throws ParseException
    9898         */
    99         public static void MailMode() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException {
     99        public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException {
    100100                if (!DisplayController.isMailMode()) {
    101101                        Mail.clear();
  • trunk/src/org/expeditee/auth/gui/MailBay.java

    r1276 r1280  
    9393                if (_creator == null || currentUser != UserSettings.UserName.get()) {
    9494                        currentUser = UserSettings.UserName.get();
    95                         _creator = new FrameCreator(EXPEDITEE_MAIL_FRAMESET_NAME, FrameIO.MAIL_PATH, EXPEDITEE_MAIL_FRAMESET_NAME, FrameCreator.ExistingFramesetOptions.ReobtainStateFromExistingFrames, false);
     95                        _creator = new FrameCreator(EXPEDITEE_MAIL_FRAMESET_NAME, FrameIO.MAIL_PATH, EXPEDITEE_MAIL_FRAMESET_NAME, FrameCreator.ExistingFramesetOptions.AppendAfterLastItem, false);
    9696                }
    9797                               
     
    107107                Mail mail = new Mail(message, message2, options);
    108108                Text t = mail.getPreviewMessage(true);
    109                 _previewMessages.add(t);
    110109                _messages.add(t);
    111110                _creator.addText(timestamp, Colour.BLACK, null, null, false);
     
    113112                        _creator.addItem(line.copy(), false);
    114113                }
     114                t.setLink(_creator.getCurrentFrame().getName());
     115                _previewMessages.add(t);
    115116                _creator.addSpace(SPACING);
    116117                _creator.save();
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r1276 r1280  
    1919package org.expeditee.gui;
    2020
     21import java.io.File;
     22import java.io.IOException;
     23import java.nio.file.Files;
     24import java.nio.file.Path;
     25import java.nio.file.Paths;
    2126import java.util.LinkedList;
    2227import java.util.List;
    2328
    2429import org.expeditee.agents.ExistingFramesetException;
     30import org.expeditee.agents.InvalidFramesetNameException;
    2531import org.expeditee.core.Colour;
    2632import org.expeditee.items.Item;
     
    2834
    2935public class FrameCreator {
    30        
     36
    3137        public static final int INDENT_FROM_TITLE = 20;
    3238
     
    5359
    5460        private boolean _multiColumn;
    55        
     61
    5662        public enum ExistingFramesetOptions {
    5763                /**
    58                  * Do not attempt to use any existing frames in specified framesets. 
     64                 * Do not attempt to use any existing frames in specified framesets.
    5965                 */
    60                 CreateNewFramesOnly,
     66                AppendSegregatedFrames,
    6167                /**
    6268                 * Override any existing frames in specified framesets.
     
    6470                OverrideExistingFrames,
    6571                /**
    66                  * Use the existing frames in the framesets to reobtain what the state of the FrameCreator should be.
     72                 * Use the existing frames in the framesets to reobtain what the state of the
     73                 * FrameCreator should be.
    6774                 */
    68                 ReobtainStateFromExistingFrames
    69         }
    70        
     75                AppendAfterLastItem
     76        }
     77
    7178        private final List<Frame> framesCreated = new LinkedList<Frame>();
    7279
    7380        public FrameCreator(String frameTitle) {
    74                 this(DisplayController.getCurrentFrame().getFramesetName(), DisplayController
    75                                 .getCurrentFrame().getPath(), frameTitle, ExistingFramesetOptions.CreateNewFramesOnly, false);
    76         }
    77        
     81                this(DisplayController.getCurrentFrame().getFramesetName(), DisplayController.getCurrentFrame().getPath(),
     82                                frameTitle, ExistingFramesetOptions.AppendSegregatedFrames, false);
     83        }
     84
    7885        public FrameCreator(String framesetName, String path, String frameTitle, ExistingFramesetOptions establishState, boolean multiColumn) {
    79                 if (establishState == ExistingFramesetOptions.ReobtainStateFromExistingFrames) {
    80                         initialiseReobtainState(framesetName, path, frameTitle, establishState, multiColumn);
    81                 } else {
    82                         initialiseStandard(framesetName, path, frameTitle, establishState, multiColumn);
    83                 }
    84         }
    85        
    86         private void initialiseReobtainState(String framesetName, String path, String frameTitle, ExistingFramesetOptions establishState, boolean multiColumn) {
     86                switch (establishState) {
     87                        case OverrideExistingFrames:
     88                                try {
     89                                        FrameIO.SuspendCache();
     90                                        Path framesetDir = Files.createTempDirectory("temporaryExpediteeFrameset");
     91                                        initialise(framesetName, framesetDir.toAbsolutePath(), frameTitle, multiColumn);
     92                                        FrameIO.EnableCache();
     93                                        FrameIO.deleteFrameset(framesetName);
     94                                        FrameIO.moveFrameset(framesetName, framesetDir.toAbsolutePath().toString() + File.separator, path);
     95                                        _current.setPath(path);
     96                                } catch (IOException e) {
     97                                        e.printStackTrace();
     98                                }
     99                                break;
     100                        case AppendSegregatedFrames:
     101                                initialise(framesetName, Paths.get(path), frameTitle, multiColumn);
     102                                break;
     103                        case AppendAfterLastItem:
     104                                initialiseReobtainState(framesetName, Paths.get(path), frameTitle, multiColumn);
     105                                break;
     106                }
     107        }
     108
     109        private void initialiseReobtainState(String framesetName, Path path, String frameTitle, boolean multiColumn) {
    87110                _multiColumn = multiColumn;
    88111                _Mnext = createButton("@Next", null, null, 10, 15);
    89112                _Mprev = createButton("@Previous", null, null, _Mnext.getBoundsWidth() + _Mnext.getAnchorRight() + 20, 15);
    90113                _Mfirst = createButton("@First", null, null, _Mprev.getBoundsWidth() + _Mprev.getAnchorRight() + 20, 15);
    91                
     114
    92115                int lastNumber = FrameIO.getLastNumber(framesetName);
    93116                for (int i = 1; i <= lastNumber; i++) {
    94                         Frame frame = FrameIO.LoadFrame(framesetName + i, path);
     117                        Frame frame = FrameIO.LoadFrame(framesetName + i, path.toAbsolutePath().toString());
    95118                        this.framesCreated.add(frame);
    96119                }
    97120                if (this.framesCreated.isEmpty()) {
    98                         initialiseStandard(framesetName, path, frameTitle, ExistingFramesetOptions.CreateNewFramesOnly, multiColumn);
     121                        initialise(framesetName, path, frameTitle, multiColumn);
    99122                        return;
    100123                }
    101124                _firstFrame = this.framesCreated.get(0);
    102125                _current = this.framesCreated.get(this.framesCreated.size() - 1);
     126
     127                createNextFrame();
    103128               
    104                 createNextFrame();
    105         }
    106 
    107         private void initialiseStandard(String framesetName, String path, String frameTitle, ExistingFramesetOptions establishState,
    108                         boolean multiColumn) {
     129                Paths.get(_current.getFramePathLogical());
     130        }
     131       
     132        private void initialise(String framesetName, Path path, String frameTitle, boolean multiColumn) {
    109133                _multiColumn = multiColumn;
    110134                _Mnext = createButton("@Next", null, null, 10, 15);
    111 
    112                 _Mprev = createButton("@Previous", null, null, _Mnext.getBoundsWidth()
    113                                 + _Mnext.getAnchorRight() + 20, 15);
    114 
    115                 _Mfirst = createButton("@First", null, null, _Mprev.getBoundsWidth()
    116                                 + _Mprev.getAnchorRight() + 20, 15);
    117 
    118                 Frame toUse = null;
     135                _Mprev = createButton("@Previous", null, null, _Mnext.getBoundsWidth() + _Mnext.getAnchorRight() + 20, 15);
     136                _Mfirst = createButton("@First", null, null, _Mprev.getBoundsWidth() + _Mprev.getAnchorRight() + 20, 15);
     137                       
    119138                try {
    120                         toUse = FrameIO.CreateFrameset(framesetName, path, establishState == ExistingFramesetOptions.CreateNewFramesOnly ? false : true);
    121                 } catch (ExistingFramesetException efe) {
    122                         // Need a comment here to explain why this catch() clause is empty
    123                         // (or else it should be throwing an exception)
    124                 } catch (Exception e) {
     139                        Frame toUse;
     140                        if (FrameIO.canAccessFrameset(framesetName, path)) {
     141                                toUse = FrameIO.CreateFrame(framesetName, frameTitle, null);
     142                        } else {
     143                                toUse = FrameIO.CreateFrameset(framesetName, path.toAbsolutePath().toString() + File.separator, true);
     144                        }
     145               
     146                        this.framesCreated.add(toUse);
     147                        resetGlobals(toUse);
     148                        _firstFrame = toUse;
     149                       
     150                        path.toAbsolutePath().resolve(framesetName);
     151                } catch (InvalidFramesetNameException e) {
    125152                        e.printStackTrace();
    126                 }
    127 
    128                 if (toUse == null) {
    129                         toUse = FrameIO.CreateFrame(framesetName, frameTitle, null);
    130                         this.framesCreated.add(toUse);
    131                 }
    132 
    133                 resetGlobals(toUse);
    134                 _firstFrame = toUse;
     153                } catch (ExistingFramesetException e) {
     154                        // This should never happen as we are allowing for an override of existing frameset.
     155                }
    135156        }
    136157
     
    141162         *            the caption for the button
    142163         * @param x
    143          *            the x position for the button. Null if the button is anchored
    144          *            to the right of the screen.
     164         *            the x position for the button. Null if the button is anchored to
     165         *            the right of the screen.
    145166         * @param y
    146          *            the y position for the button. Null if the button is anchored
    147          *            to the bottom of the screen.
     167         *            the y position for the button. Null if the button is anchored to
     168         *            the bottom of the screen.
    148169         * @param right
    149          *            the distance the button is anchored from the right of this
    150          *            screen. Null if an absolute position is used.
     170         *            the distance the button is anchored from the right of this screen.
     171         *            Null if an absolute position is used.
    151172         * @param bottom
    152          *            the distance the button is to be anchored from the bottom of
    153          *            the screen. Null if the button is given an absolute position.
     173         *            the distance the button is to be anchored from the bottom of the
     174         *            screen. Null if the button is given an absolute position.
    154175         * @return the newly created button.
    155176         */
    156         public static Item createButton(String text, Integer x, Integer y, Integer right,
    157                         Integer bottom) {
     177        public static Item createButton(String text, Integer x, Integer y, Integer right, Integer bottom) {
    158178                Text button = new Text(text);
    159179
     
    180200
    181201        /**
    182          * Creates the next frame in the frameset, with a previous button already
    183          * added and linked to the last frame. _current then gets updated to point
    184          * at the newly created Frame, and _lastY is reset
     202         * Creates the next frame in the frameset, with a previous button already added
     203         * and linked to the last frame. _current then gets updated to point at the
     204         * newly created Frame, and _lastY is reset
    185205         */
    186206        public boolean createNextFrame() {
    187207                try {
    188                         Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(),
    189                                         _current.getTitle(), null);
     208                        Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(), _current.getTitle(), null);
    190209
    191210                        this.framesCreated.add(newFrame);
    192                        
     211
    193212                        // add link to previous frame
    194213                        // _prev =
     
    211230                }
    212231        }
    213        
     232
    214233        public List<Frame> getFramesCreated() {
    215234                return this.framesCreated;
    216235        }
    217236
    218         private void resetGlobals(Frame toUse)
    219         {
     237        private void resetGlobals(Frame toUse) {
    220238                Text title = toUse.getTitleItem();
    221239                START_X = INDENT_FROM_TITLE + title.getX();
     
    227245                        if (it instanceof Text) {
    228246                                Text t = (Text) it;
    229                                 if (t.getText().toLowerCase().equals("@start")
    230                                                 || t.getText().toLowerCase().startsWith("@start:")) {
     247                                if (t.getText().toLowerCase().equals("@start") || t.getText().toLowerCase().startsWith("@start:")) {
    231248                                        t.stripFirstWord();
    232249
     
    253270                                // if there is no more room on the X axis, we have to start a
    254271                                // new frame
    255                                 if (!_multiColumn
    256                                                 || toAdd.getBoundsWidth() + _lastX > DisplayController.getFramePaintAreaWidth()) {
     272                                if (!_multiColumn || toAdd.getBoundsWidth() + _lastX > DisplayController.getFramePaintAreaWidth()) {
    257273                                        // Make sure text items that are created on the current
    258274                                        // frame are removed
     
    281297        }
    282298
    283         public Text addText(String toAdd, Colour c, String link, String action,
    284                         boolean bSave) {
     299        public Text addText(String toAdd, Colour c, String link, String action, boolean bSave) {
    285300                Text text = _current.createNewText(toAdd);
    286301                if (c != null)
     
    297312                FrameIO.ForceSaveFrame(_current);
    298313        }
    299        
     314
    300315        public int getLastY() {
    301316                return _lastY;
    302317        }
    303        
     318
    304319        public void setLastY(int lastY) {
    305320                _lastY = lastY;
    306321        }
    307        
     322
    308323        public Frame getCurrentFrame() {
    309324                return _current;
     
    345360                previousButton.setLinkHistory(false);
    346361                previousButton.setLinkMark(false);
    347                 // previousButton.setPermission(new PermissionPair(UserAppliedPermission.followLinks));
     362                // previousButton.setPermission(new
     363                // PermissionPair(UserAppliedPermission.followLinks));
    348364                current.addItem(previousButton);
    349365
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1277 r1280  
    15791579         * @return
    15801580         */
    1581         public static Boolean canAccessFrameset(String framesetName) {
     1581        public static boolean canAccessFrameset(String framesetName) {
    15821582                framesetName = framesetName.toLowerCase();
    15831583                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    1584                         if ((new File(path + framesetName)).exists()) {
     1584                        if (canAccessFrameset(framesetName, Paths.get(path))) {
    15851585                                return true;
    15861586                        }
    15871587                }
    15881588                return false;
     1589        }
     1590       
     1591        public static boolean canAccessFrameset(String framesetName, Path path) {
     1592                File framesetDir = path.resolve(framesetName).toFile();
     1593                if (framesetDir.exists() && framesetDir.isDirectory()) {
     1594                        return true;
     1595                } else {
     1596                        return false;
     1597                }
    15891598        }
    15901599
     
    17231732                // Search all the available directories for the directory
    17241733                for (String path : FolderSettings.FrameDirs.getAbsoluteDirs()) {
    1725                         String source = path + framesetName.toLowerCase() + File.separator;
    1726                         File framesetDirectory = new File(source);
    1727                         // Once we have found the directory move it
    1728                         if (framesetDirectory.exists()) {
    1729                                 String destPath = destinationFolder
    1730                                                 + framesetName.toLowerCase();
    1731                                 int copyNumber = 1;
    1732                                 File dest = new File(destPath + File.separator);
    1733                                 // Create the destination folder if it doesnt already exist
    1734                                 if (!dest.getParentFile().exists()) {
    1735                                         dest.mkdirs();
     1734                        return moveFrameset(framesetName, path, destinationFolder);
     1735                }
     1736                return false;
     1737        }
     1738
     1739        public static boolean moveFrameset(String framesetName, String path, String destinationFolder) {
     1740                String source = path + framesetName.toLowerCase() + File.separator;
     1741                File framesetDirectory = new File(source);
     1742                // Once we have found the directory move it
     1743                if (framesetDirectory.exists()) {
     1744                        String destPath = destinationFolder
     1745                                        + framesetName.toLowerCase();
     1746                        int copyNumber = 1;
     1747                        File dest = new File(destPath + File.separator);
     1748                        // Create the destination folder if it doesnt already exist
     1749                        if (!dest.getParentFile().exists()) {
     1750                                dest.mkdirs();
     1751                        }
     1752                        // If a frameset with the same name is already in the
     1753                        // destination add
     1754                        // a number to the end
     1755                        while (dest.exists()) {
     1756                                dest = new File(destPath + ++copyNumber + File.separator);
     1757                        }
     1758                        try {
     1759                                copyFileTree(framesetDirectory.toPath(), dest.toPath());       
     1760                        } catch (IOException e) {
     1761                                e.printStackTrace();
     1762                                return false;
     1763                        }
     1764                       
     1765                        for (File f : framesetDirectory.listFiles()) {
     1766                                if (!f.delete()) {
     1767                                        return false;
    17361768                                }
    1737                                 // If a frameset with the same name is already in the
    1738                                 // destination add
    1739                                 // a number to the end
    1740                                 while (dest.exists()) {
    1741                                         dest = new File(destPath + ++copyNumber + File.separator);
    1742                                 }
    1743                                 if (!framesetDirectory.renameTo(dest)) {
    1744                                         for (File f : framesetDirectory.listFiles()) {
    1745                                                 if (!f.delete()) {
    1746                                                         return false;
    1747                                                 }
    1748                                         }
    1749                                         if (!framesetDirectory.delete()) {
    1750                                                 return false;
    1751                                         }
    1752                                 }
    1753                                 return true;
    1754                         }
    1755                 }
    1756                 return false;
     1769                        }
     1770                        if (!framesetDirectory.delete()) {
     1771                                return false;
     1772                        }
     1773                        return true;
     1774                } else {
     1775                        return false;
     1776                }
    17571777        }
    17581778
  • trunk/src/org/expeditee/settings/Settings.java

    r1276 r1280  
    230230        private static void generateSettingsTree(String page, Text text) {
    231231                Frame parent = text.getParentOrCurrentFrame();
    232                 FrameCreator frames = new FrameCreator(parent.getFramesetName(), parent.getPath(), page, FrameCreator.ExistingFramesetOptions.CreateNewFramesOnly, false);
     232                FrameCreator frames = new FrameCreator(parent.getFramesetName(), parent.getPath(), page, FrameCreator.ExistingFramesetOptions.AppendSegregatedFrames, false);
    233233                text.setLink(frames.getName());
    234234               
Note: See TracChangeset for help on using the changeset viewer.