Changeset 1188 for trunk


Ignore:
Timestamp:
10/31/18 10:22:24 (6 years ago)
Author:
bln4
Message:

org.expeditee.gui.FrameIO ->

Added ability to specify were frames are being loaded from.

Location:
trunk/src/org/expeditee/gui
Files:
2 edited

Legend:

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

    r1102 r1188  
    392392                        Attribute a = attribSet.get(prop);
    393393                        // Make sure the classes of the methods match the item
    394                         if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {
    395                                
     394                        if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {     
    396395                                try {
    397396                                        String s = getValue(prop, a, toExtract, true);
    398                                         if (s == null)
     397                                        if (s == null) {
    399398                                                continue;
     399                                        }
    400400                                        // Append the attributes
    401401                                        attributes.append(a.displayName)
     
    410410
    411411                // if no attributes were extracted
    412                 if (attributes.length() <= 0)
     412                if (attributes.length() <= 0) {
    413413                        return null;
    414 
    415                 while (attributes.charAt(attributes.length() - 1) == '\n')
     414                }
     415
     416                while (attributes.charAt(attributes.length() - 1) == '\n') {
    416417                        attributes.delete(attributes.length() - 1, attributes.length());
     418                }
    417419
    418420                // create the text Item
     
    450452                        // are in the AllowNull list
    451453                        if (_AllowNull.contains(a.getter)) {
    452                                 if (name.equals("color"))
     454                                if (name.equals("color")) {
    453455                                        o = "default";
    454                                 else if (name.equals("backgroundcolor"))
     456                                } else if (name.equals("backgroundcolor")) {
    455457                                        o = "transparent";
    456                                 else if (name.equals("foregroundcolor"))
     458                                } else if (name.equals("foregroundcolor")) {
    457459                                        o = "auto";
    458                                 else
     460                                } else {
    459461                                        o = "";
     462                                }
    460463                        } else {
    461464                                return null;
     
    469472                if (o instanceof Integer) {
    470473                        Integer i = (Integer) o;
    471                         if (i == Item.DEFAULT_INTEGER)
     474                        if (i == Item.DEFAULT_INTEGER) {
    472475                                return null;
     476                        }
    473477                        if (a.getter.getName().endsWith("Justification")
    474                                         && ((Justification) o).toString() != null)
     478                                        && ((Justification) o).toString() != null) {
    475479                                o = ((Justification) o).toString();
    476480                        // -1 indicates default value
    477                         else
     481                        } else {
    478482                                o = i;
     483                        }
    479484                } else if (o instanceof Float) {
    480485                        if (((Float) o) < -0.0001)
     486                         {
    481487                                return null;
    482488                        // Null indicates default
    483489                        // o = Math.round((Float) o);
     490                        }
    484491                } else if (o instanceof Double) {
    485492                        // -1 indicates default value
    486                         if (((Double) o) < 0.0001)
     493                        if (((Double) o) < 0.0001) {
    487494                                return null;
     495                        }
    488496                } else if (o instanceof Colour) {
    489497                        // converts the color to the Expeditee code
    490498                        o = Conversion.getExpediteeColorCode((Colour) o);
    491                         if (o == null)
     499                        if (o == null) {
    492500                                return null;
     501                        }
    493502                } else if (o instanceof Point) {
    494503                        Point p = (Point) o;
     
    498507
    499508                        String s = f.getFamilyName() + "-";
    500                         if (f.isPlain())
     509                        if (f.isPlain()) {
    501510                                s += "Plain";
    502 
    503                         if (f.isBold())
     511                        }
     512
     513                        if (f.isBold()) {
    504514                                s += "Bold";
    505 
    506                         if (f.isItalic())
     515                        }
     516
     517                        if (f.isItalic()) {
    507518                                s += "Italic";
     519                        }
    508520
    509521                        s += "-" + f.getSize();
     
    514526                        List list = (List) o;
    515527                        StringBuffer sb = new StringBuffer();
    516                         for (Object ob : list)
     528                        for (Object ob : list) {
    517529                                // TODO check that this works ok
    518530                                if (sb.length() == 0) {
     
    521533                                        sb.append('\n').append(a.displayName).append(AttributeValuePair.SEPARATOR_STRING).append(ob);
    522534                                }
     535                        }
    523536                        return sb.toString();
    524537                } else if (o instanceof int[]) {
     
    532545                } else if (o instanceof Boolean) {
    533546                        // true is the default for boolean values
    534                         if (((Boolean) o).booleanValue())
     547                        if (((Boolean) o).booleanValue()) {
    535548                                return null;
     549                        }
    536550                }
    537551                return o.toString();
     
    557571                        int minAttributeLength) {
    558572                // error checking
    559                 if (toSet == null || attribs == null)
     573                if (toSet == null || attribs == null) {
    560574                        return false;
     575                }
    561576
    562577                ensureReady();
     
    589604                        // attribute merging
    590605                        if (!avp.hasAttribute()
    591                                         || avp.getAttribute().length() < minAttributeLength)
     606                                        || avp.getAttribute().length() < minAttributeLength) {
    592607                                return false;
     608                        }
    593609
    594610                        // check if the next string is another attribute to merge or a
     
    699715                // if there are duplicate methods with the same name
    700716                List<Method> possibles = new LinkedList<Method>();
    701                 if (a.setter.getDeclaringClass().isInstance(toSet))
     717                if (a.setter.getDeclaringClass().isInstance(toSet)) {
    702718                        possibles.add(a.setter);
     719                }
    703720                int i = 0;
    704721                while (attribSet.containsKey(attribute + i)) {
     
    741758
    742759                if(possibles.size() == 0){
    743                         if(invokeAttributeGetMethod(avp.getAttribute(), toSet) == null)
     760                        if(invokeAttributeGetMethod(avp.getAttribute(), toSet) == null) {
    744761                                throw new NoSuchAttributeException(avp.getAttribute(), toSet.getClass().getSimpleName());
     762                        }
    745763                        throw new ReadOnlyAttributeException(avp.getAttribute(), toSet.getClass().getSimpleName());
    746764                }
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1105 r1188  
    152152        public static void Precache(String framename) {
    153153                // if the cache is turned off, do nothing
    154                 if (!isCacheOn())
     154                if (!isCacheOn()) {
    155155                        return;
     156                }
    156157
    157158                // if the frame is already in the cache, do nothing
    158                 if (_Cache.containsKey(framename.toLowerCase()))
     159                if (_Cache.containsKey(framename.toLowerCase())) {
    159160                        return;
     161                }
    160162
    161163                // otherwise, load the frame and put it in the cache
     
    177179         */
    178180        public static boolean isPositiveInteger(String s) {
    179                 if (s == null || s.length() == 0)
     181                if (s == null || s.length() == 0) {
    180182                        return false;
     183                }
    181184
    182185                for (int i = 0; i < s.length(); i++) {
    183                         if (!Character.isDigit(s.charAt(i)))
     186                        if (!Character.isDigit(s.charAt(i))) {
    184187                                return false;
     188                        }
    185189                }
    186190                return true;
    187191        }
     192       
     193        public static String FRAMESET_CONSULT_PATH = null;
    188194
    189195        public static Frame LoadFrame(String frameName) {
    190                 return LoadFrame(frameName, null, false);
     196                return LoadFrame(frameName, FRAMESET_CONSULT_PATH, false);
    191197        }
    192198
     
    197203        public static Frame LoadFrame(String frameName, String path, boolean ignoreAnnotations)
    198204        {
    199                 if (!isValidFrameName(frameName)) return null;
     205                if (!isValidFrameName(frameName)) {
     206                        return null;
     207                }
    200208
    201209                String frameNameLower = frameName.toLowerCase();
     
    261269                String fullPath = FrameIO.getFrameFullPathName(PUBLIC_PATH, frameName);
    262270
    263                 if (fullPath == null)
     271                if (fullPath == null) {
    264272                        return null;
     273                }
    265274
    266275                File frameFile = new File(fullPath);
     
    313322                for (String path : FolderSettings.FrameDirs.get()) {
    314323                        File files = new File(path);
    315                         if (!files.exists())
     324                        if (!files.exists()) {
    316325                                continue;
     326                        }
    317327                        for (File f : (new File(path)).listFiles()) {
    318328                                if (f.isDirectory()) {
     
    354364
    355365                File tester = new File(source);
    356                 if (!tester.exists())
     366                if (!tester.exists()) {
    357367                        return null;
     368                }
    358369
    359370                String fullPath;
     
    372383                tester = new File(fullPath);
    373384
    374                 if (tester.exists())
     385                if (tester.exists()) {
    375386                        return fullPath;
     387                }
    376388
    377389                // check for oldfile name format
     
    380392                tester = new File(fullPath);
    381393
    382                 if (tester.exists())
     394                if (tester.exists()) {
    383395                        return fullPath;
     396                }
    384397
    385398                return null;
     
    396409
    397410                for (String path : FolderSettings.FrameDirs.get()) {
    398                         if (getFrameFullPathName(path, frameName) != null)
     411                        if (getFrameFullPathName(path, frameName) != null) {
    399412                                return true;
     413                        }
    400414                }
    401415                return false;
     
    408422                        for (String possiblePath : FolderSettings.FrameDirs.get()) {
    409423                                fullPath = getFrameFullPathName(possiblePath, frameName);
    410                                 if (fullPath != null)
     424                                if (fullPath != null) {
    411425                                        break;
     426                                }
    412427                        }
    413428                } else {
     
    415430                }
    416431                // If the frame was not located return null
    417                 if (fullPath == null)
     432                if (fullPath == null) {
    418433                        return null;
     434                }
    419435                Collection<String> results = new LinkedList<String>();
    420436                // Open the file and search the text items
     
    425441                                if (next.startsWith("T")) {
    426442                                        String toSearch = next.substring(2);
    427                                         if (toSearch.toLowerCase().contains(pattern))
     443                                        if (toSearch.toLowerCase().contains(pattern)) {
    428444                                                results.add(toSearch);
     445                                        }
    429446                                }
    430447                        }
     
    440457        private static Frame LoadKnowPath(String path, String frameName) {
    441458                String fullPath = getFrameFullPathName(path, frameName);
    442                 if (fullPath == null)
     459                if (fullPath == null) {
    443460                        return null;
     461                }
    444462
    445463                try {
     
    463481                        // do not put 0 frames or virtual frames into the cache
    464482                        // Why are zero frames not put in the cache
    465                         if (_Cache.size() > MAX_CACHE)
     483                        if (_Cache.size() > MAX_CACHE) {
    466484                                _Cache.clear();
    467 
    468                         if (frame.getNumber() > 0 && isCacheOn())
     485                        }
     486
     487                        if (frame.getNumber() > 0 && isCacheOn()) {
    469488                                _Cache.put(frameName.toLowerCase(), frame);
     489                        }
    470490
    471491                        return frame;
     
    490510                Frame fresh = FrameIO.LoadFrame(DisplayController.getCurrentFrame().getName());
    491511                _UseCache = cache;
    492                 if (_Cache.containsKey(fresh.getName().toLowerCase()))
     512                if (_Cache.containsKey(fresh.getName().toLowerCase())) {
    493513                        addToCache(fresh);
     514                }
    494515                DisplayController.setCurrentFrame(fresh, false);
    495516        }
     
    505526                for (; num >= 0; num--) {
    506527                        Frame f = LoadFrame(name + num, current.getPath());
    507                         if (f != null)
     528                        if (f != null) {
    508529                                return f;
     530                        }
    509531                }
    510532
     
    543565                for (; num <= max; num++) {
    544566                        Frame f = LoadFrame(name + num, current.getPath());
    545                         if (f != null)
     567                        if (f != null) {
    546568                                return f;
     569                        }
    547570                }
    548571
     
    582605                for (int num = max; num > 0; num--) {
    583606                        Frame f = LoadFromDisk(framesetName + num, path, false);
    584                         if (f != null)
     607                        if (f != null) {
    585608                                return f;
     609                        }
    586610                }
    587611
     
    625649        public static String DeleteFrame(Frame toDelete) throws IOException,
    626650                        SecurityException {
    627                 if (toDelete == null)
     651                if (toDelete == null) {
    628652                        return null;
     653                }
    629654
    630655                // Dont delete the zero frame
     
    667692                ForceSaveFrame(toDelete);
    668693
    669                 if (_Cache.containsKey(oldFrameName))
     694                if (_Cache.containsKey(oldFrameName)) {
    670695                        _Cache.remove(oldFrameName);
     696                }
    671697
    672698                File del = new File(source);
     
    761787
    762788                for (Item i : template.getItems()) {
    763                         if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT))
     789                        if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT)) {
    764790                                i.setLink(null);
     791                        }
    765792                }
    766793
     
    812839        {
    813840                SuspendCache();
    814                 for (Frame frame : _Cache.values()) frame.setBuffer(null);
     841                for (Frame frame : _Cache.values()) {
     842                        frame.setBuffer(null);
     843                }
    815844                ResumeCache();
    816845        }
     
    842871        public static boolean isValidFrameName(String frameName) {
    843872
    844                 if (frameName == null || frameName.length() < 2)
     873                if (frameName == null || frameName.length() < 2) {
    845874                        return false;
     875                }
    846876
    847877                int lastCharIndex = frameName.length() - 1;
    848878                // String must begin with a letter and end with a digit
    849879                if (!Character.isLetter(frameName.charAt(0))
    850                                 || !Character.isDigit(frameName.charAt(lastCharIndex)))
     880                                || !Character.isDigit(frameName.charAt(lastCharIndex))) {
    851881                        return false;
     882                }
    852883
    853884                // All the characters between first and last must be letters
    854885                // or digits
    855886                for (int i = 1; i < lastCharIndex; i++) {
    856                         if (!isValidFrameNameChar(frameName.charAt(i)))
     887                        if (!isValidFrameNameChar(frameName.charAt(i))) {
    857888                                return false;
     889                        }
    858890                }
    859891                return true;
     
    10111043
    10121044                                Frame original = LoadFrame(toSave.getName());
    1013                                 if (original == null)
     1045                                if (original == null) {
    10141046                                        original = toSave;
     1047                                }
    10151048                                int orignum = original.getNumber();
    10161049
     
    10561089
    10571090                        // avoid out-of-sync frames (when in TwinFrames mode)
    1058                         if (_Cache.containsKey(toSave.getName().toLowerCase()))
     1091                        if (_Cache.containsKey(toSave.getName().toLowerCase())) {
    10591092                                addToCache(toSave);
     1093                        }
    10601094
    10611095                        Logger.Log(Logger.SYSTEM, Logger.SAVE, "Saving " + toSave.getName()
     
    10651099                        int last = ReadINF(toSave.getPath(), toSave.getFramesetName(),
    10661100                                        false);
    1067                         if (last <= toSave.getNumber())
     1101                        if (last <= toSave.getNumber()) {
    10681102                                WriteINF(toSave.getPath(), toSave.getFramesetName(), toSave
    10691103                                                .getName());
     1104                        }
    10701105
    10711106                        // check if this was the profile frame (and thus needs
     
    11521187        public static boolean isProfileFrame(Frame toCheck)
    11531188        {
    1154                 if (toCheck.getNumber() == 0) return false;
     1189                if (toCheck.getNumber() == 0) {
     1190                        return false;
     1191                }
    11551192               
    11561193                return toCheck.getPath().equals(PROFILE_PATH);
     
    12751312                                        capital = false;
    12761313                                        result.append(Character.toUpperCase(cur));
    1277                                 } else
     1314                                } else {
    12781315                                        result.append(cur);
     1316                                }
    12791317                        } else {
    12801318                                capital = true;
     
    12841322                int lastCharIndex = result.length() - 1;
    12851323                if (!Character.isLetter(result.charAt(lastCharIndex))) {
    1286                         if (lastCharIndex == MAX_NAME_LENGTH - 1)
     1324                        if (lastCharIndex == MAX_NAME_LENGTH - 1) {
    12871325                                result.setCharAt(lastCharIndex, FRAME_NAME_LAST_CHAR);
    1288                         else
     1326                        } else {
    12891327                                result.append(FRAME_NAME_LAST_CHAR);
     1328                        }
    12901329                }
    12911330
     
    13081347        public static Frame CreateNewFrame(Item linker, OnNewFrameAction action) throws RuntimeException {
    13091348            Frame newFrame = FrameIO.CreateNewFrame(linker);
    1310             if(action != null) action.exec(linker, newFrame);
     1349            if(action != null) {
     1350                        action.exec(linker, newFrame);
     1351                }
    13111352            return newFrame;
    13121353        }
     
    13581399
    13591400                // the frameset does not exist (or has no 0 frame)
    1360                 if (zero == null)
     1401                if (zero == null) {
    13611402                        return -1;
     1403                }
    13621404
    13631405                try {
     
    13881430                framesetName = framesetName.toLowerCase();
    13891431                for (String path : FolderSettings.FrameDirs.get()) {
    1390                         if ((new File(path + framesetName)).exists())
     1432                        if ((new File(path + framesetName)).exists()) {
    13911433                                return true;
     1434                        }
    13921435                }
    13931436                return false;
     
    13981441                String conversion = frameset + " --> ";
    13991442
    1400                 if (!isValidFramesetName(frameset)) throw new Exception("Invalid frameset name");
     1443                if (!isValidFramesetName(frameset)) {
     1444                        throw new Exception("Invalid frameset name");
     1445                }
    14011446
    14021447                if (!recreate && FrameIO.canAccessFrameset(frameset)) {
     
    14131458                 */
    14141459                // ignore annotation character
    1415                 if (frameset.startsWith("@"))
     1460                if (frameset.startsWith("@")) {
    14161461                        frameset = frameset.substring(1);
     1462                }
    14171463
    14181464                conversion += " --> " + frameset;
     
    14981544
    14991545                if (!Character.isLetter(frameset.charAt(0))
    1500                                 || !Character.isLetter(frameset.charAt(lastCharIndex)))
     1546                                || !Character.isLetter(frameset.charAt(lastCharIndex))) {
    15011547                        return false;
     1548                }
    15021549
    15031550                for (int i = 1; i < lastCharIndex; i++) {
     
    15151562        public static boolean moveFrameset(String framesetName,
    15161563                        String destinationFolder) {
    1517                 if (!FrameIO.canAccessFrameset(framesetName))
     1564                if (!FrameIO.canAccessFrameset(framesetName)) {
    15181565                        return false;
     1566                }
    15191567                // Clear the cache
    15201568                _Cache.clear();
     
    15311579                                File dest = new File(destPath + File.separator);
    15321580                                // Create the destination folder if it doesnt already exist
    1533                                 if (!dest.getParentFile().exists())
     1581                                if (!dest.getParentFile().exists()) {
    15341582                                        dest.mkdirs();
     1583                                }
    15351584                                // If a frameset with the same name is already in the
    15361585                                // destination add
     
    15411590                                if (!framesetDirectory.renameTo(dest)) {
    15421591                                        for (File f : framesetDirectory.listFiles()) {
    1543                                                 if (!f.delete())
     1592                                                if (!f.delete()) {
    15441593                                                        return false;
     1594                                                }
    15451595                                        }
    1546                                         if (!framesetDirectory.delete())
     1596                                        if (!framesetDirectory.delete()) {
    15471597                                                return false;
     1598                                        }
    15481599                                }
    15491600                                return true;
     
    15551606        public static boolean CopyFrameset(String framesetToCopy,
    15561607                        String copiedFrameset) throws Exception {
    1557                 if (!FrameIO.canAccessFrameset(framesetToCopy))
     1608                if (!FrameIO.canAccessFrameset(framesetToCopy)) {
    15581609                        return false;
    1559                 if (FrameIO.canAccessFrameset(copiedFrameset))
     1610                }
     1611                if (FrameIO.canAccessFrameset(copiedFrameset)) {
    15601612                        return false;
     1613                }
    15611614                // search through all the directories to find the frameset we are
    15621615                // copying
     
    15691622                                File copyFramesetDirectory = new File(path
    15701623                                                + copiedFrameset.toLowerCase() + File.separator);
    1571                                 if (!copyFramesetDirectory.mkdirs())
     1624                                if (!copyFramesetDirectory.mkdirs()) {
    15721625                                        return false;
     1626                                }
    15731627                                // copy each of the frames
    15741628                                for (File f : framesetDirectory.listFiles()) {
    15751629                                        // Ignore hidden files
    1576                                         if (f.getName().charAt(0) == '.')
     1630                                        if (f.getName().charAt(0) == '.') {
    15771631                                                continue;
     1632                                        }
    15781633                                        String copyPath = copyFramesetDirectory.getAbsolutePath()
    15791634                                                        + File.separator + f.getName();
Note: See TracChangeset for help on using the changeset viewer.