Changeset 7


Ignore:
Timestamp:
05/01/08 12:26:53 (16 years ago)
Author:
ra33
Message:

New expeditee version

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

Legend:

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

    r4 r7  
    276276                // loose changes
    277277                if (toRun.getDeclaringClass().getName().equals(
    278                                  NAVIGATIONS_CLASS))
     278                                 NAVIGATIONS_CLASS)) {
    279279                        FrameIO.SaveFrame(DisplayIO.getCurrentFrame());
     280                }
    280281
    281282                // if there are duplicate methods with the same name
  • trunk/src/org/expeditee/actions/Misc.java

    r4 r7  
    66import java.awt.image.BufferedImage;
    77import java.io.File;
    8 import java.io.FileInputStream;
    98import java.io.FileNotFoundException;
    10 import java.io.FileOutputStream;
    119import java.io.IOException;
    1210import java.util.List;
     
    113111                Frame toDelete = DisplayIO.getCurrentFrame();
    114112                DisplayIO.Back();
     113                String deletedFrame = toDelete.getFrameName();
     114                String deletedFrameNameLowercase = deletedFrame.toLowerCase();
    115115                try {
    116                         String deletedFrame = toDelete.getFrameName();
    117116                        boolean del = FrameIO.DeleteFrame(toDelete);
    118117                        if (!del) {
     
    123122                                for (Item i : current.getItems())
    124123                                        if (i.getLink() != null
    125                                                         && i.getLink().toLowerCase().equals(
    126                                                                         toDelete.getFrameName().toLowerCase())) {
     124                                                        && i.getAbsoluteLink().toLowerCase().equals(
     125                                                                        deletedFrameNameLowercase)) {
    127126                                                i.setLink(null);
    128127                                        }
    129128
    130129                                FrameGraphics.Repaint();
    131                                 FrameGraphics.DisplayMessage(deletedFrame
    132                                                 + " Deleted.");
     130                                FrameGraphics.DisplayMessage(deletedFrame + " Deleted.");
    133131                        }
    134132                } catch (IOException ioe) {
    135                         FrameGraphics.ErrorMessage("Error trying to delete "
    136                                         + toDelete.getFrameName() + ":\n" + ioe.getMessage());
     133                        FrameGraphics.ErrorMessage("Error trying to delete " + deletedFrame
     134                                        + ":\n" + ioe.getMessage());
    137135                }
    138136        }
     
    240238                FrameGraphics.Repaint();
    241239        }
    242        
     240
    243241        /**
    244242         * Creates a new Text Object containing the available fonts.
     
    246244        public static void GetAvailableFontFamilyNames() {
    247245
    248                 String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
     246                String[] availableFonts = GraphicsEnvironment
     247                                .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    249248                StringBuilder fontsList = new StringBuilder();
    250                 for (String s: availableFonts) {
     249                for (String s : availableFonts) {
    251250                        fontsList.append(s).append('\n');
    252251                }
    253                
     252
    254253                Text text = DisplayIO.getCurrentFrame().createNewText();
    255254                // We dont want the stats to wrap at all
     
    364363        public static void CopyFile(String existingFile, String newFileName) {
    365364                try {
    366                         //TODO is there a built in method which will do this faster?
    367                        
    368                         FrameGraphics.DisplayMessage("Copying file " + existingFile + " to " + newFileName + "...");
    369                         FileInputStream is = new FileInputStream(existingFile);
    370                         FileOutputStream os = new FileOutputStream(
    371                                         newFileName, false);
    372                         int data;
    373                         while ( (data = is.read()) != -1 ) {
    374                                 os.write(data);
    375                         }
    376                         os.flush();
    377                         os.close();
    378                         is.close();
     365                        // TODO is there a built in method which will do this faster?
     366
     367                        FrameGraphics.DisplayMessage("Copying file " + existingFile
     368                                        + " to " + newFileName + "...");
     369                        FrameIO.copyFile(existingFile, newFileName);
    379370                        FrameGraphics.DisplayMessage("File copied successfully");
    380371                } catch (FileNotFoundException e) {
    381372                        FrameGraphics.DisplayMessage("Error opening file: " + existingFile);
    382                 } catch (Exception e){
     373                } catch (Exception e) {
    383374                        FrameGraphics.DisplayMessage("File could not be copied");
    384375                }
     
    446437
    447438                for (Item i : body)
    448                         if (i != child.getTitle() && i != child.getName()
     439                        if (i != child.getTitle() && i != child.getFrameNameItem()
    449440                                        && !i.isAnnotation()) {
    450441                                item = i;
  • trunk/src/org/expeditee/actions/Simple.java

    r4 r7  
    1313import org.expeditee.gui.FrameGraphics;
    1414import org.expeditee.gui.FrameIO;
     15import org.expeditee.gui.FrameKeyboardActions;
    1516import org.expeditee.gui.FrameMouseActions;
    1617import org.expeditee.gui.FrameUtils;
     
    1819import org.expeditee.items.Dot;
    1920import org.expeditee.items.Item;
     21import org.expeditee.items.ItemUtils;
    2022import org.expeditee.items.Line;
    2123import org.expeditee.items.Text;
     
    5961        };
    6062
    61         private static final String BREAK_TEXT = "exitrepeat";
    62 
    63         private static final String CONTINUE_TEXT = "nextrepeat";
     63        private static final String BREAK2_TEXT = "exitrepeat";
     64
     65        private static final String BREAK_TEXT = "break";
     66
     67        private static final String CONTINUE2_TEXT = "nextrepeat";
     68
     69        private static final String CONTINUE_TEXT = "continue";
    6470
    6571        private static final String RETURN_TEXT = "return";
     
    155161
    156162                FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false);
    157 
    158163                FrameGraphics.DisplayMessage("Starting test suite: " + frameset,
    159164                                Color.CYAN);
     
    229234
    230235        private static void FlagError(Item item) {
    231                 item.setColor(Color.CYAN);
     236                // item.setColor(Color.CYAN);
    232237                FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     238                item.showHighlight(true, Color.CYAN);
    233239                FrameIO.SaveFrame(item.getParent());
    234240        }
     
    306312                Frame frame = i.getParent();
    307313
    308                 if (i == frame.getTitle() || i == frame.getName() || i.isAnnotation()) {
     314                if (i == frame.getTitle() || i == frame.getFrameNameItem() || i.isAnnotation()) {
    309315                        return false;
    310316                }
     
    319325         * @return
    320326         */
    321         private static String[] parseStatement(String statement) {
    322                 return statement.split(TOKEN_SEPARATOR);
     327        private static String[] parseStatement(Text code) throws Exception {
     328                String statement = code.getTextNoList();
     329                ArrayList<String> tokens = new ArrayList<String>();
     330
     331                for (int i = 0; i < statement.length(); i++) {
     332                        char c = statement.charAt(i);
     333                        // ignore spaces
     334                        if (c != ' ') {
     335                                int startOfToken = i;
     336                                if (c == '\"') {
     337                                        int endOfToken = statement.length() - 1;
     338                                        // find the end of the string literal
     339                                        while (statement.charAt(endOfToken) != '\"')
     340                                                endOfToken--;
     341                                        if (endOfToken > startOfToken) {
     342                                                tokens.add(statement.substring(startOfToken,
     343                                                                endOfToken + 1));
     344                                        } else {
     345                                                throw new Exception("Expected matching \" "
     346                                                                + code.toString());
     347                                        }
     348                                        break;
     349                                } else if (c == '#' || c == '/') {
     350                                        break;
     351                                } else {
     352                                        // read in a normal token
     353                                        while (++i < statement.length()
     354                                                        && statement.charAt(i) != ' ')
     355                                                ;
     356                                        tokens.add(statement.substring(startOfToken, i)
     357                                                        .toLowerCase());
     358                                }
     359                        }
     360                }
     361
     362                String[] a = new String[tokens.size()];
     363                a = tokens.toArray(a);
     364                code.setProcessedCode(a);
     365                return a;
    323366        }
    324367
     
    464507        private static Status RunItem(Text code, Context context,
    465508                        Status lastItemStatus) throws Exception {
    466                 String codeText = code.getTextNoList();
     509
     510                String[] tokens = code.getProcessedCode();
     511
     512                if (tokens == null) {
     513                        tokens = parseStatement(code);
     514                }
     515
    467516                // Comments without links are a no-op
    468                 if (codeText.startsWith("#") || codeText.startsWith("//")) {
     517                if (tokens.length == 0) {
    469518                        if (code.getLink() == null)
    470519                                return Status.OK;
     
    473522                }
    474523
    475                 // Now check for code statements
    476                 codeText = codeText.trim();
    477                 String[] tokens = parseStatement(codeText.toLowerCase());
    478524                // At present only set statements can have literals so they
    479525                // are the only statements that we have to worry about string
    480526                // literals
    481                 assert (tokens.length > 0);
    482527                if (tokens[0].equals("call") && tokens.length >= 2) {
    483528                        return Call(tokens, code, context);
     
    497542                                                // check for strings enclosed in quotes
    498543                                                if (tokens[2].startsWith("\"")) {
    499                                                         if (tokens[tokens.length - 1].endsWith("\"")) {
    500                                                                 context.getPrimitives().setValue(
    501                                                                                 tokens[1],
    502                                                                                 new SString(codeText.substring(codeText
    503                                                                                                 .indexOf("\"") + 1, codeText
    504                                                                                                 .length() - 1)));
    505                                                                 return Status.OK;
    506                                                         } else
    507                                                                 throw new Exception("Expected matching \" "
    508                                                                                 + code.toString());
     544                                                        context.getPrimitives().setValue(
     545                                                                        tokens[1],
     546                                                                        new SString(tokens[2].substring(1,
     547                                                                                        tokens[2].length() - 1)));
     548                                                        return Status.OK;
     549
    509550                                                        // set a literal
    510551                                                } else if (tokens.length == 3) {
     
    517558                                        throw new RuntimeException(e.getMessage());
    518559                                }
     560                        } else if (tokens[0].equals("setframevalue")) {
     561                                assertMinParametreCount(tokens, 4);
     562                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     563
     564                                // Get the attribute to be searched for on the target frame
     565                                Frame targetFrame = (Frame) context.getPointers().getVariable(
     566                                                tokens[1]).getValue();
     567                                String targetAttribute = context.getPrimitives()
     568                                                .getStringValue(tokens[2]).toLowerCase()
     569                                                + ":";
     570                                String value = context.getPrimitives()
     571                                                .getStringValue(tokens[3]);
     572                                Boolean found = false;
     573                                Text attributeItem = null;
     574                                Text valueItem = null;
     575                                // Begin the search
     576                                for (Text text : targetFrame.getBodyTextItems()) {
     577                                        String s = text.getTextNoList().toLowerCase();
     578                                        if (s.startsWith(targetAttribute)) {
     579                                                attributeItem = text;
     580                                                AttributeUtils.setSingleValue(attributeItem, value);
     581                                                found = true;
     582                                                break;
     583                                        }
     584                                }
     585                                // Keep looking for a matching value nearby if we found an
     586                                // attribute without the value in the same item
     587                                if (!found && attributeItem != null) {
     588                                        Point endPoint = attributeItem.getEndParagraphPosition();
     589
     590                                        for (Text text : targetFrame.getBodyTextItems()) {
     591                                                Point startPoint = text.getPosition();
     592                                                if (Math.abs(startPoint.y - endPoint.y) < 10
     593                                                                && Math.abs(startPoint.x - endPoint.x) < 20) {
     594                                                        found = true;
     595                                                        valueItem = text;
     596                                                        text.setText(value);
     597                                                        break;
     598                                                }
     599                                        }
     600                                }
     601
     602                                // Set the values of the output parametres
     603                                context.getPrimitives()
     604                                                .setValue(tokens[4], new SBoolean(found));
     605                                if (tokens.length > 5) {
     606                                        context.getPointers().setObject(tokens[5], attributeItem);
     607                                        if (tokens.length > 6) {
     608                                                context.getPointers().setObject(tokens[6], valueItem);
     609                                        }
     610                                }
     611
     612                                return Status.OK;
    519613                        } else if (tokens[0].startsWith("setitem")) {
    520614                                if (tokens[0].equals("setitemposition")) {
     
    651745                                        throw new UnitTestFailedException("null", value.toString());
    652746                                return Status.OK;
     747                        } else if (tokens[0].equals("assertnotnull")) {
     748                                assertExactParametreCount(tokens, 1);
     749                                Object value = context.getPrimitives().getVariable(tokens[1])
     750                                                .getValue();
     751                                if (value == null)
     752                                        throw new UnitTestFailedException("not null", "null");
     753                                return Status.OK;
     754                        } else if (tokens[0].equals("assertdefined")) {
     755                                assertExactParametreCount(tokens, 1);
     756                                if (!context.isDefined(tokens[1]))
     757                                        throw new UnitTestFailedException("defined", "not defined");
     758                                return Status.OK;
     759                        } else if (tokens[0].equals("assertnotdefined")) {
     760                                assertExactParametreCount(tokens, 1);
     761                                if (context.isDefined(tokens[1]))
     762                                        throw new UnitTestFailedException("defined", "not defined");
     763                                return Status.OK;
    653764                        } else if (tokens[0].equals("assertequals")) {
    654765                                assertExactParametreCount(tokens, 2);
     
    751862                                        context.getPrimitives().setValue(frameNameVar,
    752863                                                        frame.getFrameName());
     864                                        return Status.OK;
     865                                } else if (tokens[0].startsWith("getframefilepath")) {
     866                                        assertExactParametreCount(tokens, 2);
     867                                        String frameName = context.getPrimitives().getStringValue(
     868                                                        tokens[1]);
     869                                        String path = FrameIO.LoadFrame(frameName).path;
     870                                        String filePath = FrameIO.getFrameFullPathName(path,
     871                                                        frameName);
     872                                        context.getPrimitives().setValue(tokens[2], filePath);
    753873                                        return Status.OK;
    754874                                }
     
    862982                                                new SInteger(AgentStats.getMilliSecondsElapsed()));
    863983                                return Status.OK;
     984                        } else if (tokens[0].equals("getlastnumberinframeset")) {
     985                                String framesetNameVar = DEFAULT_STRING;
     986                                String countVar = DEFAULT_INTEGER;
     987                                if (tokens.length > 1) {
     988                                        assertMinParametreCount(tokens, 2);
     989                                        framesetNameVar = tokens[1];
     990                                        countVar = tokens[2];
     991                                }
     992                                String frameset = context.getPrimitives().getStringValue(
     993                                                framesetNameVar);
     994                                long count = FrameIO.getLastNumber(frameset);
     995                                context.getPrimitives().setValue(countVar, new SInteger(count));
     996                                return Status.OK;
     997                        } else if (tokens[0].equals("getlistofframesets")) {
     998                                String stringVar = DEFAULT_ITEM;
     999                                if (tokens.length > 1) {
     1000                                        assertMinParametreCount(tokens, 1);
     1001                                        stringVar = tokens[1];
     1002                                }
     1003                                context.getPrimitives().setValue(stringVar,
     1004                                                FrameIO.getFramesetList());
     1005                                return Status.OK;
    8641006                        }
    8651007                } else if (tokens[0].equals("or")) {
     
    9031045                                FrameGraphics.DisplayMessage(((Text) message).copy());
    9041046                        } catch (NullPointerException e) {
    905                                 // Just ignore not text items!
    9061047                                FrameGraphics.DisplayMessage("null");
    9071048                        } catch (ClassCastException e) {
     
    9141055                } else if (tokens[0].equals("messageln")
    9151056                                || tokens[0].equals("messageline")
     1057                                || tokens[0].equals("messagelnnospaces")
     1058                                || tokens[0].equals("messagelinenospaces")
    9161059                                || tokens[0].equals("errorln") || tokens[0].equals("errorline")) {
    917                         StringBuilder message = new StringBuilder();
    918                         if (tokens.length == 1) {
    919                                 message.append(context.getPrimitives().getVariable(
    920                                                 DEFAULT_STRING).stringValue()
    921                                                 + " ");
    922                         } else {
    923                                 for (int i = 1; i < tokens.length; i++) {
    924                                         if (Primitives.isPrimitive(tokens[i])) {
    925                                                 message.append(context.getPrimitives().getVariable(
    926                                                                 tokens[i]).stringValue()
    927                                                                 + " ");
    928                                         } else
    929                                                 throw new Exception("Illegal parametre: [" + tokens[i]
    930                                                                 + "] in line " + code.toString());
    931                                 }
    932                         }
     1060                        String message = getMessage(tokens, context, code.toString(),
     1061                                        tokens[0].endsWith("nospaces") ? "" : " ");
    9331062
    9341063                        if (tokens[0].equals("errorln") || tokens[0].equals("errorline"))
    935                                 FrameGraphics.ErrorMessage(message.toString());
     1064                                FrameGraphics.ErrorMessage(message);
    9361065                        else
    937                                 FrameGraphics.DisplayMessageAlways(message.toString());
     1066                                FrameGraphics.DisplayMessageAlways(message);
     1067                        return Status.OK;
     1068                } else if (tokens[0].equals("typein")
     1069                                || tokens[0].equals("typeinnospaces")) {
     1070
     1071                        String s = getMessage(tokens, context, code.toString(), tokens[0]
     1072                                        .equals("typein") ? " " : "");
     1073                        for (int i = 0; i < s.length(); i++) {
     1074                                FrameKeyboardActions.processChar(s.charAt(i));
     1075                                Thread.sleep(25);
     1076                        }
    9381077                        return Status.OK;
    9391078                } else if (tokens[0].startsWith("else")) {
     
    10151154                                                tokens[2]) <= 0;
    10161155                                parametres = 2;
     1156                        } else if (tokens[0].equals("ifexistingframe")) {
     1157                                result = FrameIO.DoesFrameExist(context.getPrimitives()
     1158                                                .getStringValue(tokens[1]));
     1159                        } else if (tokens[0].equals("ifexistingframeset")) {
     1160                                String framesetName = context.getPrimitives().getStringValue(
     1161                                                tokens[1]);
     1162                                result = FrameIO.DoesFramesetExist(framesetName);
    10171163                        } else {
    10181164                                // assertVariableType(variable, 1, SPointer.itemPrefix);
     
    11641310
    11651311                        return Status.OK;
     1312                } else if (tokens[0].equals("deleteitem")) {
     1313                        assertMinParametreCount(tokens, 1);
     1314                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1315                        Item item = (Item) context.getPointers().getVariable(tokens[1])
     1316                                        .getValue();
     1317                        item.delete();
     1318                        return Status.OK;
     1319                } else if (tokens[0].equals("deleteframe")) {
     1320                        assertMinParametreCount(tokens, 1);
     1321                        assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1322                        Frame frame = (Frame) context.getPointers().getVariable(tokens[1])
     1323                                        .getValue();
     1324                        boolean success = FrameIO.DeleteFrame(frame);
     1325
     1326                        if (tokens.length > 2) {
     1327                                context.getPrimitives().setValue(tokens[2],
     1328                                                new SBoolean(success));
     1329                        }
     1330
     1331                        return Status.OK;
     1332                } else if (tokens[0].equals("deleteframeset")) {
     1333                        assertMinParametreCount(tokens, 1);
     1334                        String framesetName = context.getPrimitives().getStringValue(
     1335                                        tokens[1]);
     1336                        boolean success = FrameIO.DeleteFrameset(framesetName);
     1337
     1338                        if (tokens.length > 2) {
     1339                                context.getPrimitives().setValue(tokens[2],
     1340                                                new SBoolean(success));
     1341                        }
     1342
     1343                        return Status.OK;
     1344                } else if (tokens[0].equals("copyitem")) {
     1345                        assertMinParametreCount(tokens, 2);
     1346                        assertVariableType(tokens[1],1,SPointer.itemPrefix);
     1347                        assertVariableType(tokens[2],2,SPointer.itemPrefix);
     1348                        Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue();
     1349                        Item copy = item.copy();
     1350                        context.getPointers().setObject(tokens[2], copy);
     1351
     1352                        return Status.OK;
     1353                }else if (tokens[0].equals("copyframeset")) {
     1354                        assertMinParametreCount(tokens, 2);
     1355                        String framesetToCopy = context.getPrimitives().getStringValue(
     1356                                        tokens[1]);
     1357                        String copiedFrameset = context.getPrimitives().getStringValue(
     1358                                        tokens[2]);
     1359                        boolean success = FrameIO.CopyFrameset(framesetToCopy,
     1360                                        copiedFrameset);
     1361
     1362                        if (tokens.length > 3) {
     1363                                context.getPrimitives().setValue(tokens[3],
     1364                                                new SBoolean(success));
     1365                        }
     1366
     1367                        return Status.OK;
     1368                } else if (tokens[0].equals("copyframe")) {
     1369                        assertMinParametreCount(tokens, 2);
     1370                        assertVariableType(tokens[1],1,SPointer.framePrefix);
     1371                        assertVariableType(tokens[2],2,SPointer.framePrefix);
     1372                        Frame frameToCopy = (Frame) context.getPointers().getVariable(
     1373                                        tokens[1]).getValue();
     1374                        FrameIO.SuspendCache();
     1375                        Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getFrameName());
     1376                        // Change the frameset if one was provided
     1377                        if (tokens.length > 3) {
     1378                                String destinationFrameset = context.getPrimitives()
     1379                                                .getStringValue(tokens[3]);
     1380                                freshCopy.setFrameset(destinationFrameset);
     1381                        }// Otherwise add it to the end of this frameset
     1382                        freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy
     1383                                        .getFramesetName()) + 1);
     1384                        context.getPointers().setObject(tokens[2], freshCopy);
     1385                        String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     1386                        boolean success = fileContents != null;
     1387                        FrameIO.ResumeCache();
     1388                        if (tokens.length > 4) {
     1389                                context.getPrimitives().setValue(tokens[4],
     1390                                                new SBoolean(success));
     1391                        }
     1392                        return Status.OK;
    11661393                } else if (tokens[0].equals("createframe")) {
    11671394
     
    12371464                                context.getPrimitives().setValue(nextCharVarName,
    12381465                                                new SCharacter(nextChar));
     1466
     1467                        return Status.OK;
     1468                } else if (tokens[0].equals("openreadfile")) {
     1469                        assertVariableType(tokens[1], 1, SString.prefix);
     1470                        assertVariableType(tokens[2], 2, SPointer.filePrefix);
     1471
     1472                        if (tokens.length > 3) {
     1473                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1474                                context.openReadFile(tokens[1], tokens[2], tokens[3]);
     1475                        } else
     1476                                context.openReadFile(tokens[1], tokens[2]);
     1477
     1478                        return Status.OK;
     1479                } else if (tokens[0].equals("readlinefile")
     1480                                || tokens[0].equals("readlnfile")) {
     1481                        assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1482
     1483                        if (tokens.length > 3) {
     1484                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1485                                context.readLineFile(tokens[1], tokens[2], tokens[3]);
     1486                        } else
     1487                                context.readLineFile(tokens[1], tokens[2]);
     1488
     1489                        return Status.OK;
     1490                } else if (tokens[0].equals("readitemfile")) {
     1491                        assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1492                        assertVariableType(tokens[2], 1, SPointer.itemPrefix);
     1493
     1494                        if (tokens.length > 3) {
     1495                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1496                                context.readItemFile(tokens[1], tokens[2], tokens[3]);
     1497                        } else
     1498                                context.readItemFile(tokens[1], tokens[2]);
    12391499
    12401500                        return Status.OK;
     
    12761536
    12771537                        return Status.OK;
     1538                } else if (tokens[0].equals("displayframeset")) {
     1539                        assertMinParametreCount(tokens, 1);
     1540                        String framesetName = context.getPrimitives().getStringValue(
     1541                                        tokens[1]);
     1542                        int lastFrameNo = FrameIO.getLastNumber(framesetName);
     1543                        int firstFrameNo = 0;
     1544                        double pause = 0.0;
     1545                        // get the first and last frames to display if they were proided
     1546                        if (tokens.length > 2) {
     1547                                firstFrameNo = (int) context.getPrimitives().getIntegerValue(
     1548                                                tokens[2]);
     1549                                if (tokens.length > 3) {
     1550                                        lastFrameNo = (int) context.getPrimitives()
     1551                                                        .getIntegerValue(tokens[3]);
     1552                                        if (tokens.length > 4) {
     1553                                                pause = context.getPrimitives().getDoubleValue(
     1554                                                                tokens[4]);
     1555                                        }
     1556                                }
     1557                        }
     1558                        // Display the frames
     1559                        String adjustedFramesetName = FrameUtils
     1560                                        .GetFramesetNameAdjusted(framesetName);
     1561                        for (int i = firstFrameNo; i <= lastFrameNo; i++) {
     1562                                Frame frame = FrameIO.LoadFrame(adjustedFramesetName + i);
     1563                                if (frame != null) {
     1564                                        double thisFramesPause = pause;
     1565                                        // check for change in delay for this frame only
     1566                                        Item pauseItem = ItemUtils.FindTag(frame.getItems(),
     1567                                                        "@DisplayFramePause:");
     1568                                        if (pauseItem != null) {
     1569                                                try {
     1570                                                        // attempt to read in the delay value
     1571                                                        thisFramesPause = Double.parseDouble(ItemUtils
     1572                                                                        .StripTag(
     1573                                                                                        ((Text) pauseItem).getFirstLine(),
     1574                                                                                        "@DisplayFramePause:"));
     1575                                                } catch (NumberFormatException nfe) {
     1576                                                }
     1577                                        }
     1578                                        DisplayIO.setCurrentFrame(frame);
     1579                                        pause(thisFramesPause);
     1580                                }
     1581                        }
     1582                        return Status.OK;
     1583                } else if (tokens[0].equals("createframeset")) {
     1584                        String framesetName = DEFAULT_STRING;
     1585                        String successVar = null;
     1586                        if (tokens.length > 1) {
     1587                                framesetName = tokens[1];
     1588                                if (tokens.length > 2)
     1589                                        successVar = tokens[2];
     1590                        }
     1591                        context.createFrameset(framesetName, successVar);
     1592                        return Status.OK;
    12781593                } else if (tokens[0].equals("concatstr")) {
    12791594                        assertMinParametreCount(tokens, 3);
     
    14361751                        }
    14371752
    1438                         double time = context.getPrimitives().getDoubleValue(lengthVar);
    1439                         for (int i = 0; i < time * 10; i++) {
    1440                                 Thread.yield();
    1441                                 Thread.sleep(100);
    1442                         }
     1753                        pause(context.getPrimitives().getDoubleValue(lengthVar));
    14431754                        return Status.OK;
    14441755                } else if (tokens[0].equals("glidecursorto")) {
     
    14731784                        Thread.sleep(milliseconds % timeInterval);
    14741785                        DisplayIO.setCursorPosition(finalX, finalY);
     1786                        return Status.OK;
     1787                } else if (tokens[0].equals("glideitemto")) {
     1788                        assertMinParametreCount(tokens, 3);
     1789                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1790                        Item item = (Item) context.getPointers().getVariable(tokens[1])
     1791                                        .getValue();
     1792                        int finalX = (int) context.getPrimitives().getIntegerValue(
     1793                                        tokens[2]);
     1794                        int finalY = (int) context.getPrimitives().getIntegerValue(
     1795                                        tokens[3]);
     1796
     1797                        // DisplayIO.setCursorPosition(item.getX(), item.getY());
     1798                        // FrameMouseActions.pickup(item);
     1799
     1800                        int milliseconds = 1000;
     1801                        if (tokens.length > 4)
     1802                                milliseconds = (int) (context.getPrimitives().getDoubleValue(
     1803                                                tokens[4]) * 1000);
     1804
     1805                        int initialX = item.getX();
     1806                        int initialY = item.getY();
     1807                        // int initialX = DisplayIO.getMouseX();
     1808                        // int initialY = DisplayIO.getMouseY();
     1809
     1810                        final int timeInterval = 40;
     1811
     1812                        int deltaX = (int) (finalX - initialX);
     1813                        int deltaY = (int) (finalY - initialY);
     1814
     1815                        int intervals = milliseconds / timeInterval;
     1816                        for (double i = 0; i < intervals; i++) {
     1817                                int newX = initialX + (int) (deltaX * i / intervals);
     1818                                int newY = initialY + (int) (deltaY * i / intervals);
     1819                                Thread.yield();
     1820                                Thread.sleep(timeInterval);
     1821                                // DisplayIO.setCursorPosition(newX, newY);
     1822
     1823                                item.setPosition(newX, newY);
     1824                                DisplayIO.repaint();
     1825                        }
     1826                        // Thread.yield();
     1827                        Thread.sleep(milliseconds % timeInterval);
     1828                        item.setPosition(finalX, finalY);
     1829                        // DisplayIO.setCursorPosition(finalX, finalY);
     1830                        FrameMouseActions.anchor(item);
     1831                        Frame.FreeItems.clear();
     1832                        FrameGraphics.Repaint();
     1833                        // FrameMouseActions.updateCursor();
    14751834                        return Status.OK;
    14761835                }
     
    14871846                                        status = Status.OK;
    14881847                                return status;
    1489                         } else if (tokens[0].equals(CONTINUE_TEXT)) {
     1848                        } else if (tokens[0].equals(CONTINUE_TEXT)
     1849                                        || tokens[0].equals(CONTINUE2_TEXT)) {
    14901850                                return Status.Continue;
    1491                         } else if (tokens[0].equals(BREAK_TEXT)) {
     1851                        } else if (tokens[0].equals(BREAK_TEXT)
     1852                                        || tokens[0].equals(BREAK2_TEXT)) {
    14921853                                return Status.Break;
    14931854                        } else if (tokens[0].equals(RETURN_TEXT)) {
     
    15361897                                assertVariableType(tokens[1], 1, SPointer.filePrefix);
    15371898                                context.closeWriteFile(tokens[1]);
     1899
     1900                                return Status.OK;
     1901                        } else if (tokens[0].equals("closereadfile")) {
     1902                                assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1903                                context.closeReadFile(tokens[1]);
    15381904
    15391905                                return Status.OK;
     
    15501916                        }
    15511917                } else if (tokens.length == 3) {
    1552                         if (tokens[0].equals("foreach")) {
     1918                        if (tokens[0].startsWith("foreach")) {
     1919                                Class itemType = Object.class;
     1920                                String type = tokens[0].substring("foreach".length());
     1921                                // Check the type of foreach loop
     1922                                // and set the item type to iterate over
     1923                                if (type.equals("dot")) {
     1924                                        itemType = Dot.class;
     1925                                } else if (type.equals("text")) {
     1926                                        itemType = Text.class;
     1927                                } else if (type.equals("line")) {
     1928                                        itemType = Line.class;
     1929                                }
     1930
    15531931                                assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    15541932                                assertVariableType(tokens[2], 2, SPointer.framePrefix);
     
    15561934                                                tokens[2]).getValue();
    15571935                                // Create the ip variable
     1936                                Item frameName = currFrame.getFrameNameItem();
     1937                                Item frameTitle = currFrame.getTitle();
     1938
    15581939                                for (Item i : currFrame.getItems()) {
     1940                                        if (i == frameName || i == frameTitle)
     1941                                                continue;
     1942                                        if (!(itemType.isInstance(i)))
     1943                                                continue;
     1944
    15591945                                        context.getPointers().setObject(tokens[1], i);
    15601946                                        Status status = RunFrameAndReportError(code, context);
    15611947                                        // check if we need to exit this loop because of
    1562                                         // statements in
    1563                                         // the code that was run
     1948                                        // statements in the code that was run
    15641949                                        if (status == Status.Exit || status == Status.Return)
    15651950                                                return status;
     
    16332018        }
    16342019
     2020        private static void pause(double time) throws Exception {
     2021                for (int i = 0; i < time * 10; i++) {
     2022                        Thread.yield();
     2023                        Thread.sleep(100);
     2024                }
     2025        }
     2026
    16352027        public static int countCharsInString(String s, String pattern) {
    16362028                String newString = s;
     
    16682060                        throw new IncorrectParametreCountException(parametreCount);
    16692061        }
     2062
     2063        private static String getMessage(String[] tokens, Context context,
     2064                        String code, String separator) throws Exception {
     2065                StringBuilder message = new StringBuilder();
     2066                if (tokens.length == 1) {
     2067                        message.append(context.getPrimitives().getVariable(DEFAULT_STRING)
     2068                                        .stringValue());
     2069                } else {
     2070                        for (int i = 1; i < tokens.length; i++) {
     2071                                if (Primitives.isPrimitive(tokens[i])) {
     2072                                        message.append(context.getPrimitives().getVariable(
     2073                                                        tokens[i]).stringValue()
     2074                                                        + separator);
     2075                                } else
     2076                                        throw new Exception("Illegal parametre: [" + tokens[i]
     2077                                                        + "] in line " + code);
     2078                        }
     2079                }
     2080                return message.toString();
     2081        }
    16702082}
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r4 r7  
    9898                        AttributeUtils.setSingleValue(frame.getTitle(), result.toString());
    9999                frameCount++;
    100 
     100                FrameIO.ForceSaveFrame(frame);
     101               
    101102                return result;
    102103        }
  • trunk/src/org/expeditee/agents/CopyTree.java

    r4 r7  
    3838                if (_lastNumber < 0) {
    3939                        // create the new frameset
    40                         Frame one = FrameIO.CreateFrameset(_nameTo, init.path);
    41                         _framePath = one.path;
    42                         _lastNumber = -1;
    43                         _firstNumber = 1;
     40                        try {
     41                                Frame one = FrameIO.CreateFrameset(_nameTo, init.path);
    4442
    45                         // copy the original .0 frame
    46                         Frame zero = FrameIO.LoadFrame(init.getFramesetNameAdjusted() + "0");
    47                         processFrame(zero);
     43                                _framePath = one.path;
     44                                _lastNumber = -1;
     45                                _firstNumber = 1;
     46
     47                                // copy the original .0 frame
     48                                Frame zero = FrameIO.LoadFrame(init.getFramesetNameAdjusted()
     49                                                + "0");
     50                                processFrame(zero);
     51                        } catch (Exception e) {
     52                                // TODO fix this up later.
     53                        }
    4854                } else {
    4955                        // get the frame path
     
    120126                                }
    121127                        }
    122 
    123                         if (changed)
     128                        if (changed) {
    124129                                FrameIO.SaveFrame(toParse);
     130                        }
    125131                }
    126132
    127133                message("Tree successfully copied to " + _nameTo);
    128                 FrameUtils.DisplayFrame(Frame.GetFramesetNameAdjusted(_nameTo) + _firstNumber);
     134                FrameUtils.DisplayFrame(FrameUtils.GetFramesetNameAdjusted(_nameTo)
     135                                + _firstNumber);
    129136        }
    130137
  • trunk/src/org/expeditee/gui/Browser.java

    r4 r7  
    3737        // private static final JScrollPane scrollPane = new JScrollPane();
    3838
     39        public static Browser _theBrowser;
     40       
    3941        /**
    4042         * Constructs a new Browser object, then launches it
     
    4345         */
    4446        public static void main(String[] args) {
    45                 Browser b = new Browser();
     47                _theBrowser = new Browser();
    4648                // Why do we want to ignore repaint?
    4749                // b.setIgnoreRepaint(true);
    48                 b.requestFocus();
     50                _theBrowser.requestFocus();
    4951                // FrameGraphics.ForceRepaint();
    5052        }
    51 
     53       
    5254        public void setSizes(Dimension size) {
    5355                setSize(size);
     
    6365                                .getHeight() / 2)));
    6466
    65                 FrameGraphics.setMaxSize(size);
     67                FrameGraphics.setMaxSize(this.getContentPane().getSize());
    6668        }
    6769
     
    7577                Frame profile = FrameIO.LoadProfile(UserSettings.Username);
    7678                if (profile == null) {
     79                        try{
    7780                        profile = FrameIO.CreateNewProfile(UserSettings.Username);
     81                        }catch(Exception e){
     82                                //TODO fix this later
     83                        }
    7884                }
    7985                FrameUtils.ParseProfile(profile);
     
    110116                setVisible(true);
    111117
    112                 g = (Graphics2D) getGraphics();
     118                setupGraphics();
     119
     120                // required to accept TAB key
     121                setFocusTraversalKeysEnabled(false);
     122
     123                assert (UserSettings.FirstFrame != null);
     124                Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);
     125
     126                DisplayIO.setCurrentFrame(firstFrame);
     127
     128                // Create the action handler for the
     129                FrameMouseActions mouse = new FrameMouseActions();
     130               
     131                this.getContentPane().addMouseListener(mouse);
     132                this.getContentPane().addMouseMotionListener(mouse);
     133                this.addKeyListener(new FrameKeyboardActions());
     134                this.getContentPane().addMouseWheelListener(mouse);
     135        }
     136
     137        private void setupGraphics() {
     138                g = (Graphics2D) this.getContentPane().getGraphics();
    113139                assert g != null;
    114140                g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    115141                                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    116142                g.setFont(g.getFont().deriveFont(40f));
    117 
    118                 FrameGraphics.setDisplayGraphics((Graphics2D) getGraphics());
    119 
    120                 // required to accept TAB key
    121                 setFocusTraversalKeysEnabled(false);
    122 
    123                 assert (UserSettings.FirstFrame != null);
    124                 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame);
    125 
    126                 DisplayIO.setCurrentFrame(firstFrame);
    127 
    128                 // Create the action handler for the
    129                 FrameMouseActions mouse = new FrameMouseActions();
    130 
    131                 this.addMouseListener(mouse);
    132                 this.addMouseMotionListener(mouse);
    133                 this.addKeyListener(new FrameKeyboardActions());
    134                 this.addMouseWheelListener(mouse);
    135 
    136                 // Rob: Why is all this being done????
    137                 g.dispose();
    138                 g = null;
     143                FrameGraphics.setDisplayGraphics(g);
    139144        }
    140145
     
    158163         */
    159164        public void componentResized(ComponentEvent e) {
    160                 FrameGraphics.setMaxSize(this.getSize());
    161                 // FrameGraphics.Repaint();
     165                setSizes(this.getSize());
     166                setupGraphics();
    162167                repaint();
    163168                //System.out.println("Resize");
     
    181186         */
    182187        public void componentHidden(ComponentEvent e) {
    183         }
    184 
    185         public int getTitleBarHeight() {
    186                 Rectangle contentbounds = getContentPane().getBounds();
    187                 contentbounds = this.getGlassPane().getBounds();
    188                 // contentbounds = this.getRootPane().getBounds();
    189                 int titleheight = getSize().height - contentbounds.height;
    190 
    191                 return titleheight;
    192188        }
    193189
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r4 r7  
    1515
    1616import org.expeditee.items.Item;
    17 import org.expeditee.items.ItemPermission;
     17import org.expeditee.items.Picture;
    1818import org.expeditee.stats.SessionStats;
    1919
     
    5959         * The title to display in the Title bar.
    6060         */
    61         public static final String TITLE = "Exp13Mar2008A";
     61        public static final String TITLE = "Exp01May2008A";
    6262
    6363        private DisplayIO() {
     
    8080                _VisitedFrames[0] = new Stack<String>();
    8181                _VisitedFrames[1] = new Stack<String>();
    82                 UpdateTitle();
    8382        }
    8483
     
    175174
    176175        public static void setCursorPosition(int x, int y, boolean forceArrow) {
    177                 y += getOffset();
    178 
    179176                if (Frame.itemAttachedToCursor()) {
    180177                        List<Item> toMove = Frame.FreeItems;
     
    205202                FrameMouseActions.MouseY = y;
    206203
    207                 _Robot.mouseMove(_Browser.getDrawingAreaX() + x, _Browser
    208                                 .getDrawingAreaY()
    209                                 + y);
    210 
     204                _Robot.mouseMove((int)_Browser.getContentPane().getLocationOnScreen().getX() + x, (int)_Browser.getContentPane().getLocationOnScreen().getY() + y);
    211205        }
    212206
     
    269263                        }
    270264
    271                 ItemPermission ip = FrameUtils.getCurrentItem();
    272                 if (ip == null || ip.Item == null)
     265                Item ip = FrameUtils.getCurrentItem();
     266                if (ip == null)
    273267                        _VisitedFrames[side].push(toAdd.getFrameName());
    274268                else
     
    344338
    345339                FrameGraphics.Repaint();
     340                UpdateTitle();
    346341        }
    347342
    348343        public static void UpdateTitle() {
    349                 StringBuffer title = new StringBuffer(TITLE);
     344                StringBuffer title = new StringBuffer(TITLE + " [");
    350345
    351346                if (FrameGraphics.isAudienceMode())
    352347                        title.append(" - Audience Mode");
    353                 // title.append(SessionStats.getShortStats());*/
     348                else
     349                        title.append(SessionStats.getShortStats()).append(']');
    354350
    355351                _Browser.setTitle(title.toString());
     
    452448
    453449        /**
    454          *
    455          */
    456         public static int getOffset() {
    457                 if (_Browser != null)
    458                         return /* getMenuHeight() + */_Browser.getTitleBarHeight();
    459 
    460                 // default offset (if the menu has not been created yet, etc)
    461                 return 0;
    462         }
    463 
    464         /**
    465450         * Returns the current mouse X coordinate. This coordinate is relative to
    466451         * the left edge of the frame the mouse is in. It takes into account the
     
    483468         */
    484469        public static int getMouseY() {
    485                 return FrameMouseActions.MouseY - getOffset();
     470                return FrameMouseActions.MouseY;
    486471        }
    487472
     
    522507                for (Item i : frame.getItems())
    523508                        if (i.getLink() != null
    524                                         && i.getLink().toLowerCase().equals(oldFrame)) {
     509                                        && i.getAbsoluteLink().toLowerCase().equals(oldFrame)) {
    525510                                i.showHighlight(true, BACK_HIGHLIGHT_COLOR);
     511                                //check if its an @f item and if so update the buffer
     512                                if (i instanceof Picture) {
     513                                        Picture p = (Picture)i;
     514                                        p.refresh();
     515                                }
    526516                        }
    527517
  • trunk/src/org/expeditee/gui/Frame.java

    r4 r7  
    163163                _change = value;
    164164
    165                 if (_change)
     165                if (_change) {
    166166                        setBufferValid(false);
     167                        _saved = false;
     168                }
    167169        }
    168170
    169171        // indicates the frame has changed
    170         private void change() {
     172        public void change() {
    171173                setChanged(true);
    172174        }
     
    185187                }
    186188
    187                 return _body;
     189                List<Item> visibleItems = new ArrayList<Item>();
     190
     191                for (Item i : _body) {
     192                        if (i.isVisible())
     193                                visibleItems.add(i);
     194                }
     195
     196                return visibleItems;
    188197        }
    189198
     
    200209                for (Item i : getItems()) {
    201210                        // only add up normal body text items
    202                         if (i instanceof Text && i != _frameName && i != frameTitle
    203                                         && !i.isAnnotation()) {
     211                        if ((i instanceof Text) && i != frameTitle && !i.isAnnotation()) {
    204212                                bodyTextItems.add((Text) i);
    205213                        }
     
    207215
    208216                return bodyTextItems;
     217
    209218        }
    210219
     
    291300                List<Item> items = getItems();
    292301                for (Item i : items) {
    293                         if (i instanceof Text /* && !i.isAnnotation() */&& i != _frameName)
     302                        if (i instanceof Text)
    294303                                return (Text) i;
    295304                }
     
    298307        }
    299308
    300         public Text getName() {
     309        public Text getFrameNameItem() {
    301310                return _frameName;
    302311        }
     
    372381        }
    373382
    374         /*
    375          * public void setItemTemplate(Text template) { if (template != null)
    376          * _template = template; else _template = UserSettings.ItemTemplate.copy(); }
    377          */
    378 
    379383        /**
    380384         * Returns any items on this frame that are within the given Shape. Also
     
    390394
    391395                for (Item i : _body)
    392                         if (i.intersects(poly)) {// || shape.contains(i.getX(),
    393                                 // i.getY())){
     396                        if (i.isVisible() && i != _frameName && i.intersects(poly)) {
    394397                                if (!results.contains(i))
    395398                                        results.add(i);
    396                                 /*
    397                                  * List<Item> connected = i.getConnected(); for(Item item :
    398                                  * connected) if(!results.contains(item))
    399                                  * results.add(item);//All(i.getConnected());
    400                                  */
    401399                        }
    402400
    403401                for (Overlay o : _overlays)
    404402                        results.addAll(o.Frame.getItemsWithin(poly));
    405 
    406                 /*
    407                  * ArrayList<Dot> toInclude = new ArrayList<Line>(0); //remove lines
    408                  * that do not have a point anchored in the polygon for(Item i :
    409                  * results){ if(i instanceof Line){ Line line = (Line) i;
    410                  * if(!(results.contains(line.getStartDot())) &&
    411                  * !(results.contains(line.getEndDot()))) removeLines.add(line); } }
    412                  *
    413                  * results.removeAll(removeLines);
    414                  */
    415403
    416404                return results;
     
    442430        }
    443431
    444         /**
    445          * Adjusts a frameset name so a period is appended if it ends in a digit.
    446          * This form of the frameset name is used when referencing frames in the
    447          * frame set.
    448          *
    449          * @param frameset
    450          * @return
    451          */
    452         public static String GetFramesetNameAdjusted(String frameset) {
    453                 return frameset
    454                                 + (Character.isDigit(frameset.charAt(frameset.length() - 1)) ? "."
    455                                                 : "");
    456         }
    457 
    458432        public void setFrameName(String framename) {
    459433                int num = Conversion.getFrameNumber(framename);
     
    477451
    478452                if (_frameName != null) {
    479                         removeItem(_frameName);
    480453                        id = _frameName.getID();
    481                 } else
     454                } else {
    482455                        id = -1 * getNextItemID();
    483 
     456                }
    484457                _frameName = new Text(id);
     458                _frameName.setMaxSize(FrameGraphics.getMaxFrameSize());
    485459                _frameName.setText(getFramesetNameAdjusted() + _number);
    486460                _frameName.setPosition(FrameGraphics.getMaxFrameSize().width
     
    488462                                - org.expeditee.io.Conversion.X_ADJUST,
    489463                                org.expeditee.io.Conversion.Y_ADJUST);
    490                 addItem(_frameName);
    491 
    492464                setChanged(oldchange);
    493465        }
     
    603575                if (item != null) {
    604576                        if (_body.contains(item)) {
    605                                 System.out.println("Item (" + item.getClass().getSimpleName()
    606                                                 + ") with ID " + item.getID() + " already in body.");
     577                                // System.out.println("Item (" + item.getClass().getSimpleName()
     578                                // + ") with ID " + item.getID() + " already in body.");
    607579                                return;
    608580                        }
     
    687659
    688660                // if the change was to characteristics
    689                 if (_body.contains(undo)) {
     661                if (undo.isVisible() && _body.contains(undo)) {
    690662                        Item old = _body.get(_body.indexOf(undo));
    691663                        _body.set(_body.indexOf(old), undo);
     
    742714        }
    743715
    744         public Item getFrameNameItem() {
    745                 return _frameName;
    746         }
    747 
    748716        /**
    749717         * Returns the format version of this Frame
     
    858826                for (int i = ind - 1; i >= 0; i--) {
    859827                        Item check = _body.get(i);
    860 
    861                         if (FrameUtils.inSameColumn(check, current))
     828                        if (check.isVisible() && FrameUtils.inSameColumn(check, current))
    862829                                return check;
    863830                }
     
    912879                for (int i = _body.indexOf(from); i < _body.size(); i++) {
    913880                        Item item = _body.get(i);
    914                         if (isNormalTextItem(item)) {
     881                        if (item.isVisible() && isNormalTextItem(item)) {
    915882                                if (FrameUtils.inSameColumn(from, item))
    916883                                        column.add(item);
     
    983950
    984951                List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems());
     952                copies.remove(toMergeWith.getFrameNameItem());
    985953
    986954                for (Item i : copies) {
     
    1010978                                        else if (FrameIO
    1011979                                                        .isValidFrameName(((Text) i).getFirstLine())) {
     980                                                // If we get hear we are merging frames
    1012981                                                merge(FrameIO.LoadFrame(((Text) i).getFirstLine()));
    1013982                                        }
     
    1025994        public void clear() {
    1026995                List<Item> newBody = new ArrayList<Item>(0);
    1027 
    1028996                for (Item i : _body)
    1029                         if (i.isAnnotation() || i == getName() || i == getTitle())
     997                        if (i.isAnnotation() || i == getFrameNameItem() || i == getTitle())
    1030998                                newBody.add(i);
    1031999
     
    10691037                        return getAnnotationTemplate();
    10701038                case '/':
     1039                case '#':
    10711040                        return getCodeCommentTemplate();
    10721041                default:
     
    10991068                return d;
    11001069        }
    1101 
    1102         /**
    1103          * Creates a JMenu from the Items present on this Frame and adds it to the
    1104          * Menus on the Display
    1105          */
    1106         /*
    1107          * public void createMenu() { for (Item i : _body) { if (ItemUtils.isTag(i,
    1108          * ItemUtils.TAG_MENU) && i.getLink() != null) { Frame nextMenu =
    1109          * FrameIO.LoadFrame(i.getLink()); JMenu menu = nextMenu.createSubMenu();
    1110          * DisplayIO.addMenu(menu); } } }
    1111          */
    1112 
    1113         /**
    1114          * Creates a new JMenu from the Items present on this Frame
    1115          *
    1116          * @return The newly created JMenu
    1117          */
    1118         /*
    1119          * private JMenu createSubMenu() { Text frameTitle = getTitle();
    1120          *
    1121          * if (frameTitle == null) FrameUtils.Parse(this);
    1122          *
    1123          * if (frameTitle == null || frameTitle.getFirstLine() == null) return null;
    1124          *
    1125          * JMenu menu = new JMenu(frameTitle.getFirstLine());
    1126          *
    1127          * boolean literal = false; String litTitle = null;
    1128          *
    1129          * for (Item i : _body) { // if the @lit tag is active if (literal) {
    1130          * literal = false; if (litTitle == null) litTitle = ((Text)
    1131          * i).getFirstLine(); JMenuItem item = new JMenuItem(litTitle);
    1132          * item.addActionListener(new MenuAction(i, true)); menu.add(item); //
    1133          * non-annotation items with links or actions are put on the // menu } else
    1134          * if (i != _frameName && i instanceof Text && !i.isAnnotation() &&
    1135          * (i.getLink() != null || i.getAction() != null)) { JMenuItem item = new
    1136          * JMenuItem(((Text) i).getText().get(0)); item.addActionListener(new
    1137          * MenuAction(i, false)); menu.add(item); // if this is another menu frame }
    1138          * else if (i.getLink() != null && ItemUtils.isTag(i, ItemUtils.TAG_MENU)) {
    1139          * Frame nextMenu = FrameIO.LoadFrame(i.getLink());
    1140          * menu.add(nextMenu.createSubMenu()); // if this menu is continued on
    1141          * another frame } else if (i.getLink() != null && ItemUtils.isTag(i,
    1142          * ItemUtils.TAG_MENU_NEXT)) {
    1143          *
    1144          * Frame nextMenu = FrameIO.LoadFrame(i.getLink()); JMenu nmenu =
    1145          * nextMenu.createSubMenu(); for(int m = 0; m < nmenu.getComponentCount();
    1146          * m++) menu.add(nmenu.getComponent(m)); // if this is a @lit tag, then the
    1147          * next item is copied } else if (ItemUtils.isTag(i, ItemUtils.TAG_LITERAL)) {
    1148          * literal = true; String title = ItemUtils.StripTag(((Text)
    1149          * i).getFirstLine(), ItemUtils.GetTag(ItemUtils.TAG_LITERAL)); if
    1150          * (title.length() > 0) litTitle = title; else litTitle = null; } }
    1151          *
    1152          * return menu; }
    1153          */
    1154 
    1155         /*
    1156          * private class MenuAction implements ActionListener { private Item _source =
    1157          * null;
    1158          *
    1159          * private boolean _copy = false;
    1160          *
    1161          * public MenuAction(Item source, boolean copy) { _source = source; _copy =
    1162          * copy; }
    1163          *
    1164          * public void actionPerformed(ActionEvent ae) { if (_copy) { Item copy =
    1165          * _source.copy(); copy.setX(DisplayIO.getMouseX());
    1166          * copy.setY(DisplayIO.getMouseY()); FrameMouseActions.pickup(copy); return; }
    1167          *
    1168          * if (_source.getAction() != null) { _source.performActions(); } else {
    1169          * FrameUtils.DisplayFrame(_source.getLink()); } } }
    1170          */
    11711070
    11721071        public boolean isSaved() {
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r4 r7  
    99
    1010        private String _name;
    11        
     11
    1212        private final static int START_Y = 40;
    1313
     
    2020        private int _maxX = 0;
    2121
    22         private int _lastY =  START_Y;
     22        private int _lastY = START_Y;
    2323
    2424        private Text _Mnext = new Text(-1, "@Next");
     
    3131
    3232        public FrameCreator(String name, boolean recreate) {
    33                 int num = -1;
    34                 if (!recreate)
    35                         num = FrameIO.getLastNumber(name);
    36 
    3733                Frame toUse = null;
    38 
    39                 if (num == -1)
    40                         toUse = FrameIO.CreateFrameset(name, FrameIO.HELP_PATH);
    41                 else
    42                         toUse = FrameIO.CreateFrame(name, name, null);
    43 
     34                try {
     35                        toUse = FrameIO
     36                                        .CreateFrameset(name, FrameIO.PROFILE_PATH, recreate);
     37                } catch (Exception e) {
     38                        if (toUse == null)
     39                                toUse = FrameIO.CreateFrame(name, name, null);
     40                }
    4441                _name = name;
    4542                _lastY += toUse.getTitle().getPosition().y;
     
    5754         * at the newly created Frame, and _lastY is reset
    5855         */
    59         public void createNextFrame() {
    60                 Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(),
    61                                 _name, null);
     56        public boolean createNextFrame() {
     57                try {
     58                        Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(),
     59                                        _name, null);
    6260
    63                 // add link to previous frame
    64                 _prev = _Mprev.copy();
    65                 _prev.setID(newFrame.getNextItemID());
    66                 _prev.setLink(_current.getFrameName());
    67                 newFrame.addItem(_prev);
     61                        // add link to previous frame
     62                        _prev = _Mprev.copy();
     63                        _prev.setID(newFrame.getNextItemID());
     64                        _prev.setLink(_current.getFrameName());
     65                        newFrame.addItem(_prev);
    6866
    69                 // add link to new frame
    70                 _next = _Mnext.copy();
    71                 _next.setID(_current.getNextItemID());
    72                 _next.setLink(newFrame.getFrameName());
    73                 _current.addItem(_next);
    74                 FrameIO.SaveFrame(_current, false);
     67                        // add link to new frame
     68                        _next = _Mnext.copy();
     69                        _next.setID(_current.getNextItemID());
     70                        _next.setLink(newFrame.getFrameName());
     71                        _current.addItem(_next);
     72                        FrameIO.SaveFrame(_current, false);
    7573
    76                 // update\reset globals
    77                 _current = newFrame;
    78                 _lastY = START_Y + _current.getTitle().getPosition().y;;
    79                 _lastX = START_X;
    80                 _maxX = 0;
     74                        // update\reset globals
     75                        _current = newFrame;
     76                        _lastY = START_Y + _current.getTitle().getPosition().y;
     77                        ;
     78                        _lastX = START_X;
     79                        _maxX = 0;
     80                        return true;
     81                } catch (Exception e) {
     82                        return false;
     83                }
    8184        }
    8285
    83         public void addItem(Item toAdd) {
    84                 // if we have reached the end of the Y axis, try moving over on the X
    85                 // axis
    86                 if (_lastY >= _Mprev.getY() - _Mprev.getBoundsHeight()) {
    87                         _lastX = _maxX + 10;
    88                         _lastY = START_Y;
     86        public boolean addItem(Item toAdd) {
     87                try {
     88                        // if we have reached the end of the Y axis, try moving over on the
     89                        // X
     90                        // axis
     91                        if (_lastY >= _Mprev.getY() - _Mprev.getBoundsHeight()) {
     92                                _lastX = _maxX + 10;
     93                                _lastY = START_Y;
     94                        }
     95
     96                        // if there is no more room on the X axis, we have to start a new
     97                        // frame
     98                        if (toAdd.getBoundsWidth() + _lastX > FrameGraphics.getMaxSize().width) {
     99                                createNextFrame();
     100                        }
     101
     102                        toAdd.setPosition(_lastX, _lastY);
     103                        toAdd.setOffset(0, 0);
     104                        toAdd.setID(_current.getNextItemID());
     105
     106                        _current.addItem(toAdd);
     107                        // _current.addAllItems(items);
     108
     109                        FrameIO.SaveFrame(_current, false);
     110
     111                        _lastY = toAdd.getY() + toAdd.getBoundsHeight();
     112                        _maxX = Math.max(toAdd.getX() + toAdd.getBoundsWidth(), _maxX);
     113                        return true;
     114                } catch (Exception e) {
     115                        return false;
    89116                }
    90 
    91                 // if there is no more room on the X axis, we have to start a new frame
    92                 if (toAdd.getBoundsWidth() + _lastX > FrameGraphics.getMaxSize().width) {
    93                         createNextFrame();
    94                 }
    95 
    96                 toAdd.setPosition(_lastX, _lastY);
    97                 toAdd.setOffset(0, 0);
    98                 toAdd.setID(_current.getNextItemID());
    99 
    100                 /*
    101                  * List<Item> items = new ArrayList<Item>(4);
    102                  *
    103                  * items.add(_current.getName()); items.add(_current.getTitle());
    104                  * items.add(_prev); items.add(_next);
    105                  *
    106                  * _current.getItems().removeAll(items);
    107                  *
    108                  * //new system.agents.Format().process(_current);
    109                  *
    110                  * //FrameUtils.Align(items, toAdd, true);
    111                  */
    112                 _current.addItem(toAdd);
    113                 // _current.addAllItems(items);
    114 
    115                 FrameIO.SaveFrame(_current, false);
    116 
    117                 _lastY = toAdd.getY() + toAdd.getBoundsHeight();
    118                 _maxX = Math.max(toAdd.getX() + toAdd.getBoundsWidth(), _maxX);
    119117        }
    120118
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r4 r7  
    126126
    127127                // Mike assumes this is the height of the Message window?
    128                 _MaxSize.setSize(max.width, max.height - DisplayIO.getOffset()
    129                                 - MESSAGE_BUFFER_HEIGHT);
     128                _MaxSize.setSize(max.width, max.height - MESSAGE_BUFFER_HEIGHT);
    130129                if (DisplayIO.getCurrentFrame() != null) {
    131130                        DisplayIO.getCurrentFrame().setBuffer(null);
     
    183182                if (g != null
    184183                                && (!isAudienceMode()
    185                                                 || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited))
    186                         // do not paint the name of overlay frames
    187                         if (i.getParent() == null
    188                                         || i.getParent() == DisplayIO.getCurrentFrame()
    189                                         || i.getParent() == DisplayIO.getOppositeFrame()
    190                                         || i != i.getParent().getName()) {
    191                                 Graphics2D tg = (Graphics2D) g.create();
    192                                 i.paint(tg);
    193                                 tg.dispose();
    194 
    195                         }
     184                                                || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited)) {
     185                        /*
     186                         * // do not paint the name of overlay frames if (i.getParent() ==
     187                         * null || i.getParent() == DisplayIO.getCurrentFrame() ||
     188                         * i.getParent() == DisplayIO.getOppositeFrame() || i !=
     189                         * i.getParent().getFrameNameItem()) {
     190                         */
     191                        Graphics2D tg = (Graphics2D) g.create();
     192                        i.paint(tg);
     193                        tg.dispose();
     194                }
    196195        }
    197196
     
    230229
    231230                        Graphics2D bg = (Graphics2D) buffer.getGraphics();
    232                         // Text items should automatically be Anti-Aliased now
    233                         /*
    234                          * bg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    235                          * RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    236                          */
    237231
    238232                        // Nicer looking lines, but may be too jerky while
     
    252246                        else {
    253247                                paintItems.addAll(toPaint.getItems());
    254                                 paintItems.remove(toPaint.getFrameNameItem());
    255248                        }
    256249                        PaintPictures(bg, paintItems);
     
    307300                                PaintLines(bg, Frame.FreeItems);
    308301                        }
    309 
     302                        if (paintOverlay) {
     303                                PaintItem(bg, toPaint.getFrameNameItem());
     304                        }
    310305                        bg.dispose();
    311306                }
     
    377372                        // set the clipping area
    378373                        ((Graphics2D) g).setClip(0, 0, DisplayIO.getMiddle() - 1,
    379                                         _MaxSize.height + DisplayIO.getOffset());
    380                         g.drawImage(left, 0, DisplayIO.getOffset(),
     374                                        _MaxSize.height);
     375                        g.drawImage(left, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null);
     376                        ((Graphics2D) g).setClip(null);
     377                        g.drawImage(right, DisplayIO.getMiddle() + 1, 0,
    381378                                        DisplayIO.DEFAULT_BACKGROUND, null);
    382                         ((Graphics2D) g).setClip(null);
    383                         g.drawImage(right, DisplayIO.getMiddle() + 1,
    384                                         DisplayIO.getOffset(), DisplayIO.DEFAULT_BACKGROUND, null);
    385379
    386380                        // otherwise, just draw whichever side is active
    387381                } else {
    388382                        if (DisplayIO.getCurrentSide() == 0)
    389                                 g.drawImage(left, 0, DisplayIO.getOffset(),
    390                                                 DisplayIO.DEFAULT_BACKGROUND, null);
     383                                g.drawImage(left, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null);
    391384                        else
    392                                 g.drawImage(right, 0, DisplayIO.getOffset(),
    393                                                 DisplayIO.DEFAULT_BACKGROUND, null);
     385                                g.drawImage(right, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null);
    394386                }
    395387                // draw the message area
    396                 g.drawImage(_MessageBuffer, 0, _MaxSize.height + DisplayIO.getOffset(),
    397                                 null);
     388                g.drawImage(_MessageBuffer, 0, _MaxSize.height, null);
    398389                g.dispose();
    399390        }
     
    484475         */
    485476        public static void Highlight(Item i, boolean val, boolean changeMouse) {
    486                 if ((i instanceof Line/* Dot */)) {
    487                         List<Item> connected = i.getAllConnected();
    488 
    489                         for (Item conn : connected)
    490                                 conn.showHighlight(val);
     477                if ((i instanceof Line)) {
     478                        // Check if within 20% of the end of the line
     479                        Line l = (Line) i;
     480                        Item toDisconnect = l.getEndPointToDisconnect(
     481                                        FrameMouseActions.MouseX, FrameMouseActions.MouseY);
     482
     483                        if (toDisconnect != null) {
     484                                if (Frame.itemAttachedToCursor())
     485                                        return;
     486
     487                                // unhighlight all the other dots
     488                                for (Item conn : toDisconnect.getAllConnected()) {
     489                                        conn.showHighlight(false);
     490                                }
     491                                // highlight the dot that will be in disconnect mode
     492                                toDisconnect.showDisconnectHighlight(val);
     493                                toDisconnect.setFilledHighlight(true);
     494                        } else {
     495                                List<Item> connected = i.getAllConnected();
     496                                for (Item conn : connected) {
     497                                        conn.showHighlight(val);
     498                                        conn.setFilledHighlight(false);
     499                                }
     500                        }
    491501                } else {
    492502                        i.showHighlight(val);
     503                        i.setFilledHighlight(true);
    493504                }
    494505
     
    517528         */
    518529        public static void DisplayMessage(String message) {
    519                 DisplayMessage(message, Color.BLACK);
     530                DisplayMessageAlways(message);
    520531        }
    521532
     
    528539                displayMessage(message.getFirstLine(), message.getLink(), message
    529540                                .getColor());
    530                 Misc.Beep();
     541                // Misc.Beep();
    531542        }
    532543
  • trunk/src/org/expeditee/gui/FrameIO.java

    r4 r7  
    44import java.io.BufferedWriter;
    55import java.io.File;
     6import java.io.FileInputStream;
     7import java.io.FileOutputStream;
    68import java.io.FileReader;
    79import java.io.FileWriter;
     
    130132        public static Frame LoadFrame(String frameName) {
    131133                // If the frame name is a positive integer add the frameset name
    132                 if (isPositiveInteger(frameName)){
    133                         assert(false);
     134                if (isPositiveInteger(frameName)) {
     135                        assert (false);
    134136                        frameName = DisplayIO.getCurrentFrame().getFramesetNameAdjusted()
    135137                                        + frameName;
     
    160162
    161163                return loaded;
     164        }
     165
     166        /**
     167         * Gets a list of all the framesets available to the user
     168         *
     169         * @return a string containing a list of all the available framesets on
     170         *         separate lines
     171         */
     172        public static String getFramesetList() {
     173                StringBuffer list = new StringBuffer();
     174
     175                for (String path : UserSettings.FrameDirs) {
     176                        for (File f : (new File(path)).listFiles()) {
     177                                if (f.isDirectory()) {
     178                                        list.append(f.getName()).append('\n');
     179                                }
     180                        }
     181                }
     182                // remove the final new line char
     183                list.deleteCharAt(list.length() - 1);
     184                return list.toString();
    162185        }
    163186
     
    267290
    268291        public static Frame LoadPrevious(Frame current) {
     292                checkTDFC(current);
     293
    269294                // the current name and number
    270295                String name = current.getFramesetNameAdjusted();
     
    292317         */
    293318        public static Frame LoadNext(Frame current) {
     319                checkTDFC(current);
    294320
    295321                // the current name and number
     
    318344                FrameGraphics.DisplayMessage("This is the last frame in the frameset");
    319345                return null;
     346        }
     347
     348        /**
     349         * This method checks if the current frame has just been created with TDFC.
     350         * If it has the frame is saved regardless of whether it has been edited or
     351         * not and the TDFC item property is cleared. This is to ensure that the
     352         * link is saved on the parent frame.
     353         *
     354         * @param current
     355         */
     356        private static void checkTDFC(Frame current) {
     357                if (FrameMouseActions.getTdfcItem() != null) {
     358                        FrameMouseActions.setTdfcItem(null);
     359                        current.change();
     360                }
    320361        }
    321362
     
    331372                }
    332373
    333                 String adjustedName = Frame.GetFramesetNameAdjusted(framesetName);
     374                String adjustedName = FrameUtils.GetFramesetNameAdjusted(framesetName);
    334375
    335376                // loop backwards until a frame that exists is found
     
    368409         */
    369410        public static boolean DeleteFrame(Frame toDelete) throws IOException {
     411                if (toDelete == null)
     412                        return false;
     413
    370414                SaveFrame(toDelete);
    371415
     
    374418                int lastNumber = FrameIO.getLastNumber(DELETED_FRAMES);
    375419                String framePath;
    376                 if (lastNumber < 0) {
     420                try{
    377421                        // create the new frameset
    378422                        Frame one = FrameIO.CreateFrameset(DELETED_FRAMES, toDelete.path);
    379423                        framePath = one.path;
    380424                        lastNumber = 0;
    381                 } else {
     425                } catch(Exception e){
    382426                        Frame zero = FrameIO.LoadFrame(DELETED_FRAMES + "0");
    383427                        framePath = zero.path;
     
    426470                SuspendCache();
    427471
    428                 String adjustFramesetName = Frame.GetFramesetNameAdjusted(frameset);
     472                String adjustFramesetName = FrameUtils
     473                                .GetFramesetNameAdjusted(frameset);
    429474                Frame template = null;
    430475                if (templateFrame == null)
     
    520565         * @return The first Frame of the new Frameset (Frame.1)
    521566         */
    522         public static Frame CreateFrameset(String frameset, String path) {
    523                 String conversion = frameset + " --> ";
    524 
    525                 // ensure the framename is valid
    526                 frameset = NameValidation(frameset);
    527 
    528                 if (frameset == null)
    529                         return null;
    530 
    531                 conversion += frameset;
    532                 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Frameset Name: "
    533                                 + conversion);
    534                 conversion = frameset;
    535 
    536                 /**
    537                  * TODO: Update this to exclude any\all invalid filename characters
    538                  */
    539                 // ignore annotation character
    540                 if (frameset.startsWith("@"))
    541                         frameset = frameset.substring(1);
    542 
    543                 conversion += " --> " + frameset;
    544                 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Name: " + conversion);
    545 
    546                 // create the new Frameset directory
    547                 File dir = new File(path + frameset.toLowerCase() + File.separator);
    548 
    549                 dir.mkdirs();
    550 
    551                 // create the new INF file
    552                 try {
    553                         WriteINF(path, frameset, frameset + getFramesetExtension(frameset));
    554                 } catch (IOException ioe) {
    555                         ioe.printStackTrace();
    556                         Logger.Log(ioe);
    557                 }
    558 
    559                 SuspendCache();
    560                 // copy the default .0 and .1 files
    561                 Frame base;
    562                 try {
    563                         base = LoadFrame(UserSettings.DefaultFrame);
    564                 } catch (Exception e) {
    565                         base = new Frame();
    566                 }
    567                 ResumeCache();
    568 
    569                 base.resetDateCreated();
    570                 base.setFrameset(frameset);
    571                 base.setFrameNumber(0);
    572                 base.path = path;
    573                 SaveFrame(base, false);
    574 
    575                 base.resetDateCreated();
    576                 base.setFrameNumber(1);
    577                 base.setTitle(frameset);
    578                 SaveFrame(base, true);
    579 
    580                 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: "
    581                                 + frameset);
    582 
    583                 return base;
     567        public static Frame CreateFrameset(String frameset, String path) throws Exception{
     568                return CreateFrameset(frameset, path, false);
    584569        }
    585570
     
    600585
    601586                // String must begin with a letter and end with a digit
    602                 if (!Character.isLetter(frameName.charAt(0))
     587                if (!(Character.isLetter(frameName.charAt(0)) || Character.isDigit(frameName.charAt(0)))
    603588                                || !Character.isDigit(frameName.charAt(frameName.length() - 1)))
    604589                        return false;
    605590
    606                 int dotIndex = frameName.indexOf(".");
    607                 // All the characters inbetween first and last must be letters
    608                 // or digits
     591                int dotIndex = frameName.lastIndexOf('.');
     592                // All the characters between first and last must be letters
     593                // or digits or period
    609594                for (int i = 1; i < frameName.length(); i++) {
    610595                        if (dotIndex > 0 && i > dotIndex) {
     
    645630
    646631                if (toSave == null)
     632                        return "";
     633
     634                if (!toSave.hasChanged() || toSave.isSaved())
    647635                        return "";
    648636
     
    713701                        }
    714702                } catch (IOException ioe) {
    715                         ioe.printStackTrace();
     703                        // ioe.printStackTrace();
    716704                        Logger.Log(ioe);
     705                        return null;
    717706                }
    718707
     
    724713        }
    725714
    726         public static Frame CreateNewProfile(String username) {
     715        public static Frame CreateNewProfile(String username) throws Exception{
    727716                Frame profile = CreateFrameset(username, PROFILE_PATH);
    728717                FrameUtils.CreateDefaultProfile(profile);
     
    782771        }
    783772
    784         private static String NameValidation(String toValidate) {
     773        private static String NameValidation(String toValidate) throws Exception{
    785774                String result = "";
    786775
     
    791780                        // check for illegal characters
    792781                        if (ILLEGAL_CHARS.contains("" + cur)) {
    793                                 FrameGraphics
    794                                                 .DisplayMessage("Frameset name contains illegal character '"
     782                                throw new Exception("Frameset name contains illegal character '"
    795783                                                                + cur + "' at position " + (i + 1));
    796                                 return null;
    797784                        }
    798785
     
    808795
    809796                                if (result.length() >= MAX_NAME_LENGTH) {
    810                                         FrameGraphics
    811                                                         .DisplayMessage("Frameset name is too long (Max "
     797                                        throw new Exception("Frameset name is too long (Max "
    812798                                                                        + MAX_NAME_LENGTH + " characters)");
    813                                         return null;
    814799                                }
    815800                        }
     
    832817                // do auto shrinking of the title
    833818                Text titleItem = newFrame.getTitle();
    834                
    835                 while(titleItem.getBoundsWidth() + titleItem.getX() > newFrame.getFrameNameItem().getX() ) {
     819
     820                while (titleItem.getBoundsWidth() + titleItem.getX() > newFrame
     821                                .getFrameNameItem().getX()) {
    836822                        titleItem.setSize(titleItem.getSize() - 1);
    837823                }
    838                        
    839824
    840825                return newFrame;
     
    850835         *         frame)
    851836         */
    852         public static Frame CreateNewFrameset(String name) {
     837        public static Frame CreateNewFrameset(String name) throws Exception{
    853838                String path = DisplayIO.getCurrentFrame().path;
    854839
     
    896881        }
    897882
     883        public static Boolean DoesFramesetExist(String framesetName) {
     884                String zeroFrame = FrameUtils.GetFramesetNameAdjusted(framesetName) + '0';
     885                return FrameIO.DoesFrameExist(zeroFrame);
     886        }
     887
     888        public static Frame CreateFrameset(String frameset, String path,
     889                        boolean recreate) throws Exception{
     890                String conversion = frameset + " --> ";
     891
     892                // ensure the framename is valid
     893                frameset = NameValidation(frameset);
     894
     895                if (frameset == null)
     896                        throw new Exception("Invalid frameset name");
     897
     898                if (!recreate && FrameIO.DoesFramesetExist(frameset)) {
     899                        throw new Exception("A frameset called " + frameset + " already exists.");
     900                }
     901
     902                conversion += frameset;
     903                Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Frameset Name: "
     904                                + conversion);
     905                conversion = frameset;
     906
     907                /**
     908                 * TODO: Update this to exclude any\all invalid filename characters
     909                 */
     910                // ignore annotation character
     911                if (frameset.startsWith("@"))
     912                        frameset = frameset.substring(1);
     913
     914                conversion += " --> " + frameset;
     915                Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Name: " + conversion);
     916
     917                // create the new Frameset directory
     918                File dir = new File(path + frameset.toLowerCase() + File.separator);
     919
     920                dir.mkdirs();
     921
     922                // create the new INF file
     923                try {
     924                        WriteINF(path, frameset, frameset + getFramesetExtension(frameset));
     925                } catch (IOException ioe) {
     926                        ioe.printStackTrace();
     927                        Logger.Log(ioe);
     928                }
     929
     930                SuspendCache();
     931                // copy the default .0 and .1 files
     932                Frame base;
     933                try {
     934                        base = LoadFrame(UserSettings.DefaultFrame);
     935                } catch (Exception e) {
     936                        base = new Frame();
     937                }
     938                ResumeCache();
     939
     940                base.resetDateCreated();
     941                base.setFrameset(frameset);
     942                base.setFrameNumber(0);
     943                base.setTitle(base.getFramesetNameAdjusted() + "0");
     944                base.path = path;
     945                base.change();
     946                SaveFrame(base, false);
     947
     948                base.resetDateCreated();
     949                base.setFrameNumber(1);
     950                base.setTitle(frameset);
     951                base.change();
     952                SaveFrame(base, true);
     953
     954                Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: "
     955                                + frameset);
     956
     957                return base;
     958        }
     959
     960        public static boolean DeleteFrameset(String framesetName) {
     961                if (!FrameIO.DoesFramesetExist(framesetName))
     962                        return false;
     963
     964                for (String path : UserSettings.FrameDirs) {
     965                        String source = path + framesetName.toLowerCase() + File.separator;
     966                        File framesetDirectory = new File(source);
     967                        if (framesetDirectory.exists()) {
     968                                for (File f : framesetDirectory.listFiles())
     969                                        f.delete();
     970                                return framesetDirectory.delete();
     971                        }
     972                }
     973                return false;
     974        }
     975
     976        public static boolean CopyFrameset(String framesetToCopy,
     977                        String copiedFrameset) throws Exception {
     978                if (!FrameIO.DoesFramesetExist(framesetToCopy))
     979                        return false;
     980                if (FrameIO.DoesFramesetExist(copiedFrameset))
     981                        return false;
     982                // search through all the directories to find the frameset we are
     983                // copying
     984                for (String path : UserSettings.FrameDirs) {
     985                        String source = path + framesetToCopy.toLowerCase()
     986                                        + File.separator;
     987                        File framesetDirectory = new File(source);
     988                        if (framesetDirectory.exists()) {
     989                                // copy the frameset
     990                                File copyFramesetDirectory = new File(path
     991                                                + copiedFrameset.toLowerCase() + File.separator);
     992                                if (!copyFramesetDirectory.mkdirs())
     993                                        return false;
     994                                // copy each of the frames
     995                                for (File f : framesetDirectory.listFiles()) {
     996                                        String copyPath = copyFramesetDirectory.getAbsolutePath()
     997                                                        + File.separator + f.getName();
     998                                        FrameIO.copyFile(f.getAbsolutePath(), copyPath);
     999                                }
     1000                                return true;
     1001                        }
     1002                }
     1003                return false;
     1004        }
     1005
     1006        public static void copyFile(String existingFile, String newFileName)
     1007                        throws Exception {
     1008                FileInputStream is = new FileInputStream(existingFile);
     1009                FileOutputStream os = new FileOutputStream(newFileName, false);
     1010                int data;
     1011                while ((data = is.read()) != -1) {
     1012                        os.write(data);
     1013                }
     1014                os.flush();
     1015                os.close();
     1016                is.close();
     1017        }
     1018
     1019        /**
     1020         * Saves a frame regardless of whether or not the frame is marked as having
     1021         * been changed.
     1022         *
     1023         * @param frame
     1024         *            the frame to save
     1025         * @return the contents of the frame or null if it could not be saved
     1026         */
     1027        public static String ForceSaveFrame(Frame frame) {
     1028                frame.change();
     1029                return SaveFrame(frame, false);
     1030        }
     1031
    8981032}
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r4 r7  
    88import java.awt.event.KeyEvent;
    99import java.awt.event.KeyListener;
     10import java.io.IOException;
    1011import java.util.ArrayList;
    1112import java.util.LinkedList;
     
    1819import org.expeditee.items.Dot;
    1920import org.expeditee.items.Item;
    20 import org.expeditee.items.ItemPermission;
    2121import org.expeditee.items.ItemUtils;
    2222import org.expeditee.items.Line;
     
    2525
    2626public class FrameKeyboardActions implements KeyListener {
     27
     28        private static Text _toRemove = null;
    2729
    2830        // these numbers correspond to the Function Key numbers (0 = Escape key)
     
    8183                                // remove the link for alt+l
    8284                                if (ch == 'l') {
    83                                         FrameUtils.getCurrentItem().Item.setLink(null);
     85                                        FrameUtils.getCurrentItem().setLink(null);
    8486                                        FrameGraphics.Repaint();
    8587                                }
     
    9193        }
    9294
    93         private static void processChar(char ch) {
    94 
    95                 ItemPermission ip = FrameUtils.getCurrentItem();
     95        public static void processChar(char ch) {
     96
     97                Item on = FrameUtils.getCurrentItem();
    9698
    9799                // permission check
    98                 if (ip != null && ip.Permission < ItemPermission.PERMISSION_FULL) {
     100                if (on != null && on.Permission < Item.PERMISSION_FULL) {
    99101                        FrameGraphics
    100102                                        .DisplayMessage("Insufficient permission to edit this item");
     
    102104                }
    103105
    104                 Item on = null;
    105 
    106                 if (ip != null)
    107                         on = ip.Item;
     106                if (_toRemove != null && on != _toRemove) {
     107                        assert (_toRemove.getLength() == 0);
     108                        // This line is to protect mistaken removal of items if there is a
     109                        // bug...
     110                        if (_toRemove.getLength() == 0)
     111                                DisplayIO.getCurrentFrame().removeItem(_toRemove);
     112                }
     113                _toRemove = null;
    108114
    109115                // ignore delete and backspace if in free space
     
    124130                        on = null;
    125131
     132                // DisplayIO.UpdateTitle();
     133
    126134                Text text = (Text) on;
    127 
    128                 // DisplayIO.UpdateTitle();
    129 
    130135                // if this text is empty but has not been removed (such as from
    131136                // ESC-pushdown)
     
    135140                                replaceText(text);
    136141                        else {
    137                                 DisplayIO.getCurrentFrame().removeItem(text);
    138142                                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    139143                        }
     
    163167                // away)
    164168                if (text.isEmpty()) {
     169                        _toRemove = text;
     170
    165171                        if (text.getAction() != null)
    166172                                text.setActionMark(true);
     
    170176                                replaceText(text);
    171177                        else {
    172                                 DisplayIO.getCurrentFrame().removeItem(text);
     178                                // DisplayIO.getCurrentFrame().removeItem(text);
    173179                                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    174180                        }
     
    241247
    242248        private void move(int direction) {
    243                 ItemPermission ip = FrameUtils.getCurrentItem();
     249                Item ip = FrameUtils.getCurrentItem();
    244250
    245251                if (ip == null) {
     
    250256                }
    251257
    252                 Item on = ip.Item;
     258                Item on = ip;
    253259                if (on instanceof Text) {
    254260                        // When the user hits the left and right button with mouse
     
    341347
    342348        /**
     349         *
     350         * @param text
     351         * @param yPos
     352         * @return the new yPos for the next item
     353         */
     354        private static int addTextItemToCurrentFrame(String text, int yPos) {
     355                if (text.trim().length() > 0) {
     356                        Text textItem = createText();
     357                        textItem.setText(text.substring(0, text.length() - 1));
     358                        textItem.setY(yPos);
     359                        DisplayIO.getCurrentFrame().addItem(textItem);
     360                        return textItem.getY() + textItem.getBoundsHeight();
     361                }
     362                return yPos;
     363        }
     364
     365        /**
    343366         * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V
    344367         * are copy and paste, all other keystrokes are ignored.
     
    356379                                                .getTransferData(DataFlavor.stringFlavor));
    357380
    358                                 ItemPermission clicked = FrameUtils.getCurrentItem();
     381                                Item clicked = FrameUtils.getCurrentItem();
    359382
    360383                                if (clicked != null) {
    361384                                        // check permissions
    362                                         if (clicked.Permission < ItemPermission.PERMISSION_FULL
    363                                                         && clicked.Item.getParent() != null
    364                                                         && clicked.Item.getParent().getName() != clicked.Item) {
     385                                        if (clicked.Permission < Item.PERMISSION_FULL
     386                                                        && clicked.getParent() != null
     387                                                        && clicked.getParent().getFrameNameItem() != clicked) {
    365388                                                FrameGraphics.DisplayMessage("Insufficient Permission");
    366389                                                return;
     
    372395                                        clipboard.add(text);
    373396                                        List<Item> left = FrameMouseActions.merge(clipboard,
    374                                                         clicked.Item);
     397                                                        clicked);
    375398                                        FrameMouseActions.anchor(left);
    376399                                } else {
     
    382405
    383406                                        // separate the clipboard content into items based on
    384                                         // blank
    385                                         // lines
     407                                        // blank lines
    386408                                        while (st.hasMoreTokens()) {
    387409                                                String s = st.nextToken();
    388410                                                // if this is a blank line, then it is an item separator
    389411                                                if (s.trim().length() == 0) {
    390                                                         if (temp.trim().length() > 0) {
    391                                                                 Text text = createText();
    392                                                                 text.setText(temp);
    393                                                                 text.setY(y);
    394                                                                 DisplayIO.getCurrentFrame().addItem(text);
    395                                                                 y = text.getY() + text.getBoundsHeight();
    396                                                         }
     412                                                        y = addTextItemToCurrentFrame(temp, y);
    397413                                                        temp = "";
    398414                                                } else {
    399                                                         if (st.hasMoreTokens()) {
    400                                                                 temp += s + "\n";
    401                                                                 st.nextToken(); // Skip '\n' separator
    402                                                         } else {
    403                                                                 temp += s;
    404                                                         }
     415                                                        temp += s + "\n";
     416                                                        if (st.hasMoreTokens())
     417                                                                st.nextToken();
    405418                                                }
    406419                                        }
    407420                                        // the last item will not be finished by the above loop
    408                                         if (temp.trim().length() > 1) {
    409                                                 Text text = createText();
    410                                                 text.setText(temp);
    411                                                 text.setY(y);
    412                                                 DisplayIO.getCurrentFrame().addItem(text);
    413                                                 temp = "";
    414                                         }
     421                                        addTextItemToCurrentFrame(temp, y);
    415422                                }
    416423
     
    422429                        // if this is a copy command
    423430                } else if (ch.charAt(0) == KeyEvent.VK_C) {
    424                         ItemPermission ip = FrameUtils.getCurrentItem();
    425 
    426                         if (ip != null && ip.Permission < ItemPermission.PERMISSION_COPY) {
     431                        Item ip = FrameUtils.getCurrentItem();
     432
     433                        if (ip != null && ip.Permission < Item.PERMISSION_COPY) {
    427434                                FrameGraphics
    428435                                                .DisplayMessage("Insufficient permission to copy that item");
     
    432439                        Item on = null;
    433440                        if (ip != null)
    434                                 on = ip.Item;
     441                                on = ip;
    435442
    436443                        if (on == null || !(on instanceof Text))
     
    511518         */
    512519        private static Text getCurrentTextItem() {
    513                 ItemPermission ip = FrameUtils.getCurrentItem();
    514 
    515                 if (ip != null && ip.Permission < ItemPermission.PERMISSION_FULL) {
     520                Item ip = FrameUtils.getCurrentItem();
     521
     522                if (ip != null && ip.Permission < Item.PERMISSION_FULL) {
    516523                        FrameGraphics
    517524                                        .DisplayMessage("Insufficient permission to copy that item");
     
    521528                Item on = null;
    522529                if (ip != null)
    523                         on = ip.Item;
     530                        on = ip;
    524531
    525532                if (on == null || !(on instanceof Text))
     
    535542        public static void functionKey(int key) {
    536543                // get whatever the user is pointing at
    537                 ItemPermission on = FrameUtils.getCurrentItem();
     544                Item on = FrameUtils.getCurrentItem();
    538545
    539546                // check for enclosed mode
    540                 if (on == null || on.Item == null) {
    541                         List<ItemPermission> enclosed = FrameUtils.getCurrentItems();
     547                if (on == null || on == null) {
     548                        List<Item> enclosed = FrameUtils.getCurrentItems();
    542549
    543550                        if (enclosed != null && enclosed.size() > 0) {
     
    549556                                // items
    550557                                boolean resizeLines = true;
    551                                 for (ItemPermission ip : enclosed) {
    552                                         if (ip.Item != null) {
    553                                                 if (!(ip.Item instanceof Line)
    554                                                                 && !(ip.Item instanceof Dot)) {
     558                                for (Item ip : enclosed) {
     559                                        if (ip != null) {
     560                                                if (!(ip instanceof Line) && !(ip instanceof Dot)) {
    555561                                                        resizeLines = false;
    556562                                                        break;
     
    559565                                }
    560566
    561                                 for (ItemPermission ip : enclosed) {
    562                                         if (ip.Item != null && !(connected.indexOf(ip.Item) > 0))
     567                                for (Item ip : enclosed) {
     568                                        if (ip != null && !(connected.indexOf(ip) > 0))
    563569                                                switch (key) {
    564570                                                case SIZE_UP:
    565571                                                        if (resizeLines
    566                                                                         || (!(ip.Item instanceof Line) && !(ip.Item instanceof Dot)))
     572                                                                        || (!(ip instanceof Line) && !(ip instanceof Dot)))
    567573                                                                SetSize(ip, 1, false);
    568574                                                        break;
    569575                                                case SIZE_DOWN:
    570576                                                        if (resizeLines
    571                                                                         || (!(ip.Item instanceof Line) && !(ip.Item instanceof Dot)))
     577                                                                        || (!(ip instanceof Line) && !(ip instanceof Dot)))
    572578                                                                SetSize(ip, -1, false);
    573579                                                        break;
     
    654660         *            indicate the cursor is in free space.
    655661         */
    656         private static void Drop(ItemPermission ip) {
     662        private static void Drop(Item ip) {
    657663                String newItemText = DEFAULT_NEW_ITEM_TEXT;
    658664
     
    664670                Item toDropFrom = null;
    665671                if (ip != null)
    666                         toDropFrom = ip.Item;
     672                        toDropFrom = ip;
    667673
    668674                // if the cursor is in free space then the drop will happen from the
     
    751757                                        Frame moreFrame = DisplayIO.getCurrentFrame();
    752758                                        moreFrame.setTitle(firstFrame.getTitle().getTextNoList());
    753                                         //need to move the mouse to the top of the frame if there wasnt an @start on it
     759                                        // need to move the mouse to the top of the frame if there
     760                                        // wasnt an @start on it
    754761                                        if (!mouseMoved) {
    755                                                 Drop(new ItemPermission(moreFrame.getTitle(), ItemPermission.PERMISSION_FULL));
     762                                                Item moreTitle = moreFrame.getTitle();
     763                                                moreTitle.Permission = Item.PERMISSION_FULL;
     764                                                Drop(moreTitle);
    756765                                        }
    757                                        
     766
    758767                                        // Add the bullet text to the item
    759                                         dummyItem.setPosition(DisplayIO.getMouseX(),
    760                                                         DisplayIO.getMouseY());
     768                                        dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO
     769                                                        .getMouseY());
    761770                                } else {
    762771                                        FrameGraphics
     
    945954         *            with resizing
    946955         */
    947         private static void SetSize(ItemPermission ip, int diff, boolean moveCursor) {
     956        private static void SetSize(Item ip, int diff, boolean moveCursor) {
    948957                List<Item> toSize;
    949958                // the mouse is only moved when the Item is on the frame, not free
     
    962971                } else {
    963972                        // check permissions
    964                         if (ip.Permission < ItemPermission.PERMISSION_FULL) {
     973                        if (ip.Permission < Item.PERMISSION_FULL) {
    965974                                FrameGraphics
    966975                                                .DisplayMessage("Insufficient permission to change the size of that item");
    967976                                return;
    968977                        }
    969                         toSet = ip.Item;
     978                        toSet = ip;
    970979
    971980                        toSize = toSet.getConnected();
     
    10541063                        return;
    10551064
    1056                 Item toSet = item;// .Item;
     1065                Item toSet = item;// ;
    10571066                Color color = toSet.getFillColor();
    10581067
    1059                 color = ColorUtils.getNextColor(color, Item.COLOR_WHEEL);
     1068                color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL);
    10601069
    10611070                // TODO what happens if the above statement returns null??
     
    10741083         *            The Item whose colour is to be changed
    10751084         */
    1076         private static void SetColor(ItemPermission ip) {
     1085        private static void SetColor(Item ip) {
    10771086                // first determine the next color
    10781087                Color color = null;
     
    10861095                        // change the background color if the user is pointing on the
    10871096                        // frame name
    1088                 } else if (ip.Item == DisplayIO.getCurrentFrame().getName()) {
     1097                } else if (ip == DisplayIO.getCurrentFrame().getFrameNameItem()) {
    10891098                        DisplayIO.getCurrentFrame().toggleBackgroundColor();
    10901099                        return;
    10911100                } else {
    10921101                        // check permissions
    1093                         if (ip.Permission < ItemPermission.PERMISSION_FULL) {
     1102                        if (ip.Permission < Item.PERMISSION_FULL) {
    10941103                                FrameGraphics
    10951104                                                .DisplayMessage("Insufficient permission to change that item's color");
    10961105                                return;
    10971106                        }
    1098                         color = ip.Item.getColor();
     1107                        color = ip.getColor();
    10991108                }
    11001109
     
    11101119                                i.setColor(color);
    11111120                } else {
    1112                         Item toSet = ip.Item;
     1121                        Item toSet = ip;
    11131122                        toSet.setColor(color);
    11141123                        toSet.getParent().setChanged(true);
     
    11251134         *            The Item to toggle
    11261135         */
    1127         private static void ToggleAnnotation(ItemPermission toToggle) {
     1136        private static void ToggleAnnotation(Item toToggle) {
    11281137                if (toToggle == null) {
    11291138                        FrameGraphics.DisplayMessage("There is no Item selected to toggle");
     
    11321141
    11331142                // check permissions
    1134                 if (toToggle.Permission < ItemPermission.PERMISSION_FULL) {
     1143                if (toToggle.Permission < Item.PERMISSION_FULL) {
    11351144                        FrameGraphics
    11361145                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    11381147                }
    11391148
    1140                 toToggle.Item.setAnnotation(!toToggle.Item.isAnnotation());
    1141                 toToggle.Item.getParent().setChanged(true);
     1149                toToggle.setAnnotation(!toToggle.isAnnotation());
     1150                toToggle.getParent().setChanged(true);
    11421151                FrameGraphics.Repaint();
    11431152        }
     
    11491158         *            The Item to toggle
    11501159         */
    1151         private static void ToggleFontStyle(ItemPermission toToggle) {
     1160        private static void ToggleFontStyle(Item toToggle) {
    11521161                if (toToggle == null) {
    11531162                        FrameGraphics.DisplayMessage("There is no Item selected to toggle");
     
    11561165
    11571166                // check permissions
    1158                 if (toToggle.Permission < ItemPermission.PERMISSION_FULL) {
     1167                if (toToggle.Permission < Item.PERMISSION_FULL) {
    11591168                        FrameGraphics
    11601169                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    11621171                }
    11631172
    1164                 if (toToggle.Item instanceof Text) {
    1165                         Text text = (Text) toToggle.Item;
     1173                if (toToggle instanceof Text) {
     1174                        Text text = (Text) toToggle;
    11661175                        text.toggleFontStyle();
    11671176
     
    11771186         *            The Item to toggle
    11781187         */
    1179         private static void ToggleFontFamily(ItemPermission toToggle) {
     1188        private static void ToggleFontFamily(Item toToggle) {
    11801189                if (toToggle == null) {
    11811190                        FrameGraphics.DisplayMessage("There is no Item selected to toggle");
     
    11841193
    11851194                // check permissions
    1186                 if (toToggle.Permission < ItemPermission.PERMISSION_FULL) {
     1195                if (toToggle.Permission < Item.PERMISSION_FULL) {
    11871196                        FrameGraphics
    11881197                                        .DisplayMessage("Insufficient permission to toggle that item's annotation");
     
    11901199                }
    11911200
    1192                 if (toToggle.Item instanceof Text) {
    1193                         Text text = (Text) toToggle.Item;
     1201                if (toToggle instanceof Text) {
     1202                        Text text = (Text) toToggle;
    11941203                        text.toggleFontFamily();
    11951204
     
    12071216         *            The Item to prepend the date to, or null
    12081217         */
    1209         private static void AddDate(ItemPermission toAdd) {
     1218        private static void AddDate(Item toAdd) {
    12101219                String date1 = Logger.EasyDateFormat("ddMMMyyyy[HH:mm]");
    12111220                String date2 = Logger.EasyDateFormat("ddMMMyyyy");
     
    12161225                boolean append = false;
    12171226
    1218                 // if the user is pointing at an item, add the date where ever the cursor is pointing
     1227                // if the user is pointing at an item, add the date where ever the
     1228                // cursor is pointing
    12191229                if (toAdd != null) {
    1220                         if (toAdd.Item instanceof Text) {
     1230                        if (toAdd instanceof Text) {
    12211231                                // permission check
    1222                                 if (toAdd.Permission < ItemPermission.PERMISSION_FULL) {
     1232                                if (toAdd.Permission < Item.PERMISSION_FULL) {
    12231233                                        FrameGraphics
    12241234                                                        .DisplayMessage("Insufficicent permission to add the date to that item");
    12251235                                        return;
    12261236                                }
    1227                                
    1228                                 Text textItem = (Text) toAdd.Item;
    1229                                
     1237
     1238                                Text textItem = (Text) toAdd;
     1239
    12301240                                String text = textItem.getTextNoList();
    12311241
     
    12531263                                        }
    12541264                                }
    1255                                
     1265
    12561266                                if (prepend) {
    12571267                                        // add the date to the text item
     
    12651275                                                DisplayIO.setCursorPosition(textItem.getPosition());
    12661276                                } else {
    1267                                         for(int i = 0; i < date1.length(); i++) {
     1277                                        for (int i = 0; i < date1.length(); i++) {
    12681278                                                processChar(date1.charAt(i));
    12691279                                        }
     
    12941304         * @param name
    12951305         */
    1296         private static void CreateFrameset(ItemPermission ip) {
    1297                 if (ip == null || !(ip.Item instanceof Text)) {
     1306        private static void CreateFrameset(Item ip) {
     1307                if (ip == null || !(ip instanceof Text)) {
    12981308                        FrameGraphics
    12991309                                        .DisplayMessage("There is no selected item to use for the Frameset name");
     
    13021312
    13031313                // check permissions
    1304                 if (ip.Permission < ItemPermission.PERMISSION_FULL) {
     1314                if (ip.Permission < Item.PERMISSION_FULL) {
    13051315                        FrameGraphics
    13061316                                        .DisplayMessage("Insufficient permission to create a frameset from this item");
     
    13081318                }
    13091319
    1310                 Text text = (Text) ip.Item;
    1311 
    1312                 // create the new frameset
    1313                 Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine());
    1314                 DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    1315 
    1316                 // if the frameset was created successfully
    1317                 if (linkTo != null) {
     1320                Text text = (Text) ip;
     1321                try {
     1322                        // create the new frameset
     1323                        Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine());
     1324                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
     1325
    13181326                        text.setLink(linkTo.getFrameName());
    13191327
    13201328                        text.getParent().setChanged(true);
    13211329                        FrameUtils.DisplayFrame(linkTo, true);
    1322                 } else {
     1330                        linkTo.moveMouseToDefaultLocation();
     1331                        // this needs to be done if the user doesnt move the mouse before
     1332                        // doing
     1333                        // tdfc while the cursor is set to the text cursor
     1334                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
     1335                } catch (IOException ioe) {
    13231336                        FrameGraphics
    13241337                                        .ErrorMessage("An error occured when trying to create the new frameset");
     1338                } catch (Exception e) {
    13251339                }
    13261340        }
     
    13321346         *            This Item is currently ignored
    13331347         */
    1334         private static void ToggleAudience(ItemPermission ignored) {
     1348        private static void ToggleAudience(Item ignored) {
    13351349                FrameGraphics.ToggleAudienceMode();
    13361350        }
    13371351
    1338         private static void ToggleXRayMode(ItemPermission ignored) {
     1352        private static void ToggleXRayMode(Item ignored) {
    13391353                FrameGraphics.ToggleXRayMode();
    13401354        }
     
    13471361         */
    13481362        /*
    1349          * private static void RunFirstMenuItem(ItemPermission ignored) {
     1363         * private static void RunFirstMenuItem(Item ignored) {
    13501364         * DisplayIO.activateMenuItem(0, 0); }
    13511365         */
     
    13571371         *            This Item is currently ignored
    13581372         */
    1359         private static void Repaint(ItemPermission ignored) {
     1373        private static void Repaint(Item ignored) {
    13601374                FrameUtils.Parse(DisplayIO.getCurrentFrame());
    13611375                FrameGraphics.ForceRepaint();
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r4 r7  
    1717import org.expeditee.actions.Actions;
    1818import org.expeditee.actions.NavigationActions;
     19import org.expeditee.agents.Format;
    1920import org.expeditee.items.Constraint;
    2021import org.expeditee.items.Dot;
    2122import org.expeditee.items.Item;
    22 import org.expeditee.items.ItemPermission;
    2323import org.expeditee.items.ItemUtils;
    2424import org.expeditee.items.Line;
     
    7171        private static int _offX;
    7272
     73        // MIKE: Thinks the offsets are used in getting items to draw in the message
     74        // window?
    7375        private static int _offY;
    7476
     
    8890        private static boolean _isNoOp = false;
    8991
     92        private static boolean _extrude = false;
     93
    9094        // keeps track of the last highlighted Item
    9195        private static Item _lastHighlightedItem = null;
     
    116120        }
    117121
     122        static int _mouseDown = 0;
     123
    118124        private static MouseEvent _lastMouseClick = null;
    119125
    120         private static ItemPermission _lastClickedOn = null;
    121 
    122         private static List<ItemPermission> _lastClickedIn = null;
     126        private static Item _lastClickedOn = null;
     127
     128        private static List<Item> _lastClickedIn = null;
    123129
    124130        private static boolean _pulseOn = false;
    125131
    126         private static int _pulseAmount = 2;
     132        private static final int PULSE_AMOUNT = 2;
    127133
    128134        private static Timer _MouseTimer = new Timer(LITTLE_MOUSE_PAUSE,
     
    131137                                        // check if we are in free space
    132138                                        if (_lastClickedOn == null && Frame.FreeItems.size() == 0) {
    133                                                 System.out.println("SuperBack!");
    134                                                 leftButton(null);
     139                                                // System.out.println("SuperBack!");
    135140                                                _MouseTimer.setDelay(ZERO_MOUSE_PAUSE);
     141                                                back();
    136142                                        } else {
    137                                                 _pulseOn = !_pulseOn;
    138 
    139                                                 if (_MouseTimer.getDelay() == LITTLE_MOUSE_PAUSE)
    140                                                         _MouseTimer.setDelay(LITTLE_MOUSE_PAUSE + 1);
    141                                                 else
    142                                                         _MouseTimer.setDelay(BIG_MOUSE_PAUSE);
    143143                                                if (FrameUtils.getCurrentItem() == null) {
    144                                                         for (Item i : Frame.FreeItems) {
    145                                                                 if (i instanceof Line) {
    146                                                                         Line line = (Line) i;
    147                                                                         if (_pulseAmount < 4
    148                                                                                         && line.getThickness() < 0)
    149                                                                                 _pulseAmount = 4;
    150 
    151                                                                         if (_pulseOn)
    152                                                                                 line.setThickness(line.getThickness()
    153                                                                                                 + _pulseAmount);
    154                                                                         else
    155                                                                                 line.setThickness(line.getThickness()
    156                                                                                                 - _pulseAmount);
    157 
    158                                                                         line.toggleArrow();
     144                                                        // Check if we are toggling arrowhead
     145                                                        if (Frame.FreeItems.size() <= 2) {
     146                                                                for (Item i : Frame.FreeItems) {
     147                                                                        if (i instanceof Line) {
     148                                                                                ((Line) i).toggleArrow();
     149                                                                        }
    159150                                                                }
     151                                                                FrameGraphics.Repaint();
    160152                                                        }
    161                                                         FrameGraphics.Repaint();
    162153                                                }
    163154                                                _MouseTimer.stop();
    164155                                        }
     156                                }
     157                        });
     158
     159        private static void setPulse(boolean pulseOn) {
     160                if (_pulseOn == pulseOn)
     161                        return;
     162                int amount = PULSE_AMOUNT;
     163                if (!pulseOn)
     164                        amount *= -1;
     165                _pulseOn = pulseOn;
     166
     167                for (Item i : _lastClickedOn.getAllConnected()) {
     168                        if (i instanceof Line) {
     169                                Line line = (Line) i;
     170                                line.setThickness(line.getThickness() + amount);
     171                        }
     172                }
     173                FrameGraphics.Repaint();
     174        }
     175
     176        private static Timer _ExtrudeMouseTimer = new Timer(BIG_MOUSE_PAUSE,
     177                        new ActionListener() {
     178                                public void actionPerformed(ActionEvent ae) {
     179                                        setPulse(true);
     180                                        _extrude = true;
     181                                        _ExtrudeMouseTimer.stop();
    165182                                }
    166183                        });
     
    176193         */
    177194        public void mousePressed(MouseEvent e) {
     195                _mouseDown += e.getButton();
    178196                _lastMouseClickDate = new Date();
    179197                _lastClickedOn = FrameUtils.getCurrentItem();
    180198                // load any frame if necessary
    181                 ItemPermission on = _lastClickedOn;
     199                Item on = _lastClickedOn;
    182200
    183201                _lastClickedIn = FrameUtils.getCurrentItems();
     
    186204                if (e.getButton() == MouseEvent.BUTTON1) {
    187205                        SessionStats.AddFrameEvent("Ld");
     206                        _extrude = false;
    188207                } else if (e.getButton() == MouseEvent.BUTTON2) {
    189208                        SessionStats.AddFrameEvent("Md");
     209                        _extrude = false;
    190210                } else if (e.getButton() == MouseEvent.BUTTON3) {
    191211                        SessionStats.AddFrameEvent("Rd");
     
    193213
    194214                _lastMouseClick = e;
    195                 _MouseTimer.start();
     215
     216                // Only start the timer when in free space when the user double clicks
     217                // to do super back
     218                // TODO change this so that there are separate timers for super back and
     219                // the other
     220                // Long depress actions if that is what is wanted.
     221                if (_lastClickedOn == null && Frame.FreeItems.size() == 0) {
     222                        // System.out.println(e.getClickCount());
     223                        if (e.getClickCount() >= 2) {
     224                                _MouseTimer.start();
     225                        }
     226                } else if (_lastClickedOn != null && Frame.FreeItems.size() == 0
     227                                && e.getButton() == MouseEvent.BUTTON3) {
     228                        _ExtrudeMouseTimer.start();
     229
     230                } else {
     231                        _MouseTimer.start();
     232                }
    196233
    197234                // pre-cache the frame if it is linked
    198                 if (on != null && on.Item.getLink() != null && on.Item.isLinkValid()) {
    199                         FrameIO.Precache(on.Item.getLink());
     235                if (on != null && on.getLink() != null && on.isLinkValid()) {
     236                        FrameIO.Precache(on.getLink());
    200237                }
    201238
     
    231268
    232269                // if the user is ranging text
    233                 if (on != null && on.Item instanceof Text && !_isDelete) {
    234                         _lastRanged = (Text) on.Item;
     270                if (on != null && on instanceof Text && !_isDelete) {
     271                        _lastRanged = (Text) on;
    235272                        // set start-drag point
    236273                        _lastRanged.setSelectionStart(DisplayIO.getMouseX(), DisplayIO
     
    238275                }
    239276
    240                 if (on != null && on.Item instanceof Picture
     277                if (on != null && on instanceof Picture
    241278                                && e.getButton() == MouseEvent.BUTTON3 && !_isDelete) {
    242                         _lastCropped = (Picture) on.Item;
     279                        _lastCropped = (Picture) on;
    243280                        // set start crop point
    244281                        _lastCropped.setStartCrop(DisplayIO.getMouseX(), DisplayIO
     
    250287        // This is where all the processing happens
    251288        public void mouseReleased(MouseEvent e) {
     289                _mouseDown -= e.getButton();
    252290                updateCursor();
     291
     292                // System.out.println(e.getX() + ", " + e.getY());
    253293
    254294                Text lastRanged = _lastRanged;
     
    275315                FrameUtils.ResponseTimer.restart();
    276316
     317                _ExtrudeMouseTimer.stop();
    277318                _MouseTimer.stop();
    278                 _MouseTimer.setDelay(LITTLE_MOUSE_PAUSE);
    279 
    280                 if (_pulseOn) {
    281                         for (Item i : Frame.FreeItems) {
    282                                 if (i instanceof Line) {
    283                                         Line line = (Line) i;
    284                                         line.setThickness(line.getThickness() - _pulseAmount);
    285                                 }
    286                         }
    287                         _pulseOn = false;
    288                 }
    289 
    290                 // if the user was performing actions, stop now
    291                 if (_pulseAmount < 0) {
    292                         _pulseAmount = 2;
    293                         return;
    294                 }
    295 
    296                 // reset pulse value
    297                 _pulseAmount = 2;
     319                setPulse(false);
    298320
    299321                if (Actions.isAgentRunning()) {
     
    315337
    316338                // get whatever the user was pointing at
    317                 ItemPermission clickedOn = _lastClickedOn;
    318                 List<ItemPermission> clickedIn = _lastClickedIn;
     339                Item clickedOn = _lastClickedOn;
     340                List<Item> clickedIn = _lastClickedIn;
    319341
    320342                MouseX = e.getX();
    321343                MouseY = e.getY();
    322344
    323                 List<ItemPermission> releasedIn = FrameUtils.getCurrentItems();
    324                 ItemPermission releasedOn = FrameUtils.getCurrentItem();
     345                List<Item> releasedIn = FrameUtils.getCurrentItems();
     346                Item releasedOn = FrameUtils.getCurrentItem();
    325347
    326348                if (_isNoOp
    327                                 && ((releasedOn != null && clickedOn != null && releasedOn.Item != clickedOn.Item) || (releasedOn == null && releasedIn == null))) {
     349                                && ((releasedOn != null && clickedOn != null && releasedOn != clickedOn) || (releasedOn == null && releasedIn == null))) {
    328350                        if (_isDelete) {
    329351                                _isDelete = false;
     
    335357                        if (_lastHighlightedItem != null)
    336358                                FrameGraphics.Highlight(_lastHighlightedItem, false, false);
    337                         // TODO Michael thinks this code should never be reached and can be
    338                         // removed
     359
    339360                        if (Frame.itemAttachedToCursor()) {
    340361                                move(Frame.FreeItems);
     
    352373                if (_isDelete) {
    353374                        if (lastRanged != null) {
    354                                 lastRanged.cutSelectedText();
     375
     376                                Item i = Frame.getItemAttachedToCursor();
     377                                if (i != null && i instanceof Text) {
     378                                        lastRanged.replaceSelectedText(((Text) i).getTextNoList());
     379                                        Frame.FreeItems.clear();
     380                                } else
     381                                        lastRanged.cutSelectedText();
    355382                                lastRanged.clearSelection();
    356383                                FrameGraphics.Repaint();
     
    366393                // if this is an attribute extraction command
    367394                if (_isAttribute) {
    368                         extractAttributes(clickedOn);
     395                        if (clickedOn == null) {
     396                                new Format().process(DisplayIO.getCurrentFrame());
     397                        } else {
     398                                extractAttributes(clickedOn);
     399                        }
    369400                        _wasDouble = true;
    370401                        _isAttribute = false;
     
    402433                }
    403434
    404                 // if the user is cropping an imate
    405                 if (clickedOn != null && clickedOn.Item == _lastCropped
     435                // if the user is cropping an image
     436                if (clickedOn != null && clickedOn == _lastCropped
    406437                                && _lastCropped.getCroppedSize() > 0) {
    407438                        Picture cropped = _lastCropped.copy();
    408 
    409439                        cropped.setParent(null);
    410440                        pickup(cropped);
     
    412442                }
    413443
    414                 // if the user has cropped an imate, either the above happend or this is
     444                // if the user has cropped an image, either the above happend or this is
    415445                // a no-op
    416446                if (_lastCropped != null && _lastCropped.getCroppedSize() > 0) {
     
    448478         * This method handles all left-click actions
    449479         */
    450         public static void leftButton(ItemPermission clicked) {
     480        public static void leftButton(Item clicked) {
    451481                // if the user is pointing at something then either follow the link or
    452482                // do TDFC
     483                if (clicked == null) {
     484                        // Check if the user is nearby another item...
     485                        int mouseX = DisplayIO.getMouseX();
     486                        int mouseY = DisplayIO.getMouseY();
     487                        // System.out.println(mouseX + "," + mouseY);
     488                        for (Item i : DisplayIO.getCurrentFrame().getItems()) {
     489                                if (i instanceof Text) {
     490                                        if (i.isNear(mouseX, mouseY)) {
     491                                                clicked = i;
     492                                                break;
     493                                        }
     494                                }
     495                        }
     496                }
     497
     498                if (clicked instanceof Text) {
     499                        if (((Text) clicked).getTextNoList().length() == 0)
     500                                clicked = null;
     501                }
     502
    453503                if (clicked != null) {
    454504                        // check item permissions
    455                         if (clicked.Permission < ItemPermission.PERMISSION_FOLLOW_LINKS) {
     505                        if (clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) {
    456506                                FrameGraphics
    457507                                                .DisplayMessage("Insufficient Permissions for action on item");
     
    459509                        }
    460510
    461                         Item clickedOn = clicked.Item;
     511                        Item clickedOn = clicked;
     512
    462513                        // actions take priority
    463514                        if (_lastMouseClick != null && !_lastMouseClick.isShiftDown()
     
    480531                        } else {
    481532                                // check for TDFC permission
    482                                 if (clicked.Permission < ItemPermission.PERMISSION_TDFC) {
     533                                if (clicked.Permission < Item.PERMISSION_TDFC) {
    483534                                        FrameGraphics
    484535                                                        .DisplayMessage("Insufficient permission to TDFC from that item");
     
    497548
    498549                                tdfc(clickedOn);
    499                                 DisplayIO.UpdateTitle();
    500550                                return;
    501551                        }
    502                         // if the user is not pointing at something, then this is a back
    503                         // command
     552                        // if user is not pointing at something,this is a back
    504553                } else {
    505554                        back();
    506                         DisplayIO.UpdateTitle();
    507555                        return;
    508556                }
    509557        }
    510558
    511         private static boolean doMerging(ItemPermission clicked) {
     559        private static boolean doMerging(Item clicked) {
    512560                if (clicked == null)
    513561                        return false;
     
    515563                // System.out.println(Frame.FreeItems.size());
    516564                if (isRubberBandingRectangle()
    517                                 && clicked.Item.getAllConnected().contains(
     565                                && clicked.getAllConnected().contains(
    518566                                                Frame.getItemAttachedToCursor()))
    519567                        return true;
     
    524572                Item attachedToCursor = Frame.getItemAttachedToCursor();
    525573
    526                 if (clicked.Item instanceof Text && !(attachedToCursor instanceof Text)) {
     574                if (clicked instanceof Text && !(attachedToCursor instanceof Text)) {
    527575                        return false;
    528576                }
     
    534582         * This method handles all middle-click actions
    535583         */
    536         private static void middleButton(ItemPermission clicked,
    537                         List<ItemPermission> clickedIn) {
     584        private static void middleButton(Item clicked, List<Item> clickedIn) {
    538585                // if the cursor has Items attached
    539586                if (Frame.itemAttachedToCursor()) {
     
    542589                        if (doMerging(clicked)) {
    543590                                // check permissions
    544                                 if (clicked.Permission < ItemPermission.PERMISSION_FULL
    545                                                 && clicked.Item.getParent() != null
    546                                                 && clicked.Item.getParent().getName() != clicked.Item) {
     591                                if (clicked.Permission < Item.PERMISSION_FULL
     592                                                && clicked.getParent() != null
     593                                                && clicked.getParent().getFrameNameItem() != clicked) {
    547594                                        FrameGraphics.DisplayMessage("Insufficient Permission");
    548595                                        return;
    549596                                }
    550597
    551                                 List<Item> left = merge(Frame.FreeItems, clicked.Item);
     598                                List<Item> left = merge(Frame.FreeItems, clicked);
    552599                                anchor(left);
    553600
     
    570617                        if (clicked != null) {
    571618                                // check permissions
    572                                 if (clicked.Permission < ItemPermission.PERMISSION_FULL) {
     619                                if (clicked.Permission < Item.PERMISSION_FULL) {
    573620                                        FrameGraphics
    574621                                                        .DisplayMessage("Insufficient Permission to pick up item");
     
    576623                                }
    577624
    578                                 pickup(clicked.Item);
     625                                // TODO remove rectangle constraints?
     626                                if (clicked instanceof Line) {
     627                                        // Check if within 20% of the end of the line
     628                                        Line l = (Line) clicked;
     629                                        Item toDisconnect = l.getEndPointToDisconnect(
     630                                                        _lastMouseClick.getX(), _lastMouseClick.getY());
     631
     632                                        if (toDisconnect != null) {
     633                                                List<Line> lines = toDisconnect.getLines();
     634                                                if (lines.size() == 1) {
     635                                                        //remove constraints
     636                                                        toDisconnect.removeAllConstraints();
     637                                                       
     638                                                        DisplayIO.setCursorPosition(toDisconnect
     639                                                                        .getPosition(), false);
     640                                                        pickup(toDisconnect);
     641                                                        return;
     642                                                }
     643                                                // If we are then detatch the line and pick up its end
     644                                                // point...
     645                                                Frame currentFrame = DisplayIO.getCurrentFrame();
     646                                                Item newPoint = toDisconnect.copy();
     647                                                newPoint.setID(currentFrame.getNextItemID());
     648                                                currentFrame.addItem(newPoint);
     649                                                // remove the current item from the connected
     650                                                // list for this item
     651                                                for (Item i : lines) {
     652                                                        if (i == l) {
     653                                                                toDisconnect.removeLine(l);
     654                                                                break;
     655                                                        }
     656                                                }
     657                                                if (toDisconnect == l.getStartItem()) {
     658                                                        l.setStartItem(newPoint);
     659                                                } else {
     660                                                        l.setEndItem(newPoint);
     661                                                }
     662
     663                                                // remove unneeded constrains
     664                                                List<Constraint> constraints = toDisconnect
     665                                                                .getConstraints();
     666                                                if (constraints != null) {
     667                                                        for (Constraint c : constraints) {
     668                                                                Item oppositeEnd = l.getOppositeEnd(newPoint);
     669                                                                if (c.contains(oppositeEnd)) {
     670                                                                        toDisconnect.removeConstraint(c);
     671                                                                        oppositeEnd.removeConstraint(c);
     672                                                                        break;
     673                                                                }
     674                                                        }
     675                                                }
     676
     677                                                toDisconnect.showHighlight(false);
     678                                                DisplayIO.setCursorPosition(toDisconnect.getPosition(),
     679                                                                false);
     680                                                pickup(newPoint);
     681
     682                                                return;
     683                                        }
     684                                }
     685
     686                                pickup(clicked);
    579687                                return;
    580688                                // otherwise create a line
     
    583691                                        ArrayList<Item> toPickup = new ArrayList<Item>(clickedIn
    584692                                                        .size());
    585                                         for (ItemPermission ip : clickedIn)
    586                                                 if (ip.Permission >= ItemPermission.PERMISSION_FULL)
    587                                                         toPickup.add(ip.Item);
     693                                        for (Item ip : clickedIn)
     694                                                if (ip.Permission >= Item.PERMISSION_FULL)
     695                                                        toPickup.add(ip);
    588696
    589697                                        pickup(toPickup);
    590698                                        // otherwise the user is creating a line
    591                                 } else
    592                                         createLine();
     699                                } else {
     700                                        Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(),
     701                                                        MouseX, MouseY);
     702                                        Line newLine = createLine();
     703                                        // if the user can spot-weld, show the virtual spot
     704                                        if (on instanceof Line) {
     705                                                Line line = (Line) on;
     706                                                newLine.setThickness(line.getThickness());
     707                                                newLine.setLinePattern(line.getLinePattern());
     708                                                newLine.setColor(line.getColor());
     709                                                line.forceMerge(newLine.getStartItem(), MouseX, MouseY);
     710                                        }
     711                                }
    593712                                return;
    594713                        }
     
    626745         * This method handles all right-click action
    627746         */
    628         private static void rightButton(ItemPermission clicked,
    629                         List<ItemPermission> clickedIn) {
     747        private static void rightButton(Item clicked, List<Item> clickedIn) {
    630748                // if the cursor has Items attached, then anchor a copy of them
    631749                if (Frame.itemAttachedToCursor()) {
     
    633751                        // unless it is a point onto somethin other than a point
    634752                        if (clicked != null
    635                                         && (!(Frame.getItemAttachedToCursor() instanceof Dot && !(clicked.Item instanceof Dot)))) {
     753                                        && (!(Frame.getItemAttachedToCursor() instanceof Dot && !(clicked instanceof Dot)))) {
    636754                                // check permissions
    637                                 if (clicked.Permission < ItemPermission.PERMISSION_FULL
    638                                                 && clicked.Item.getParent().getName() != clicked.Item) {
     755                                if (clicked.Permission < Item.PERMISSION_FULL
     756                                                && clicked.getParent().getFrameNameItem() != clicked) {
    639757                                        FrameGraphics
    640758                                                        .DisplayMessage("Insufficient Permission to merge items");
     
    642760                                }
    643761
    644                                 if (clicked.Item instanceof Text || clicked.Item instanceof Dot) {
     762                                if (clicked instanceof Text || clicked instanceof Dot) {
    645763                                        List<Item> copies = null;
    646764
    647765                                        if (isRubberBandingRectangle()) {
    648                                                 List<Item> remain = merge(Frame.FreeItems, clicked.Item);
     766                                                List<Item> remain = merge(Frame.FreeItems, clicked);
    649767
    650768                                                Dot d = getFirstFreeDot();
     
    654772                                                updateCursor();
    655773                                                // pick up a copy of all enclosed items
    656                                                 List<ItemPermission> items = FrameUtils
    657                                                                 .getItemsEnclosedBy(
    658                                                                                 DisplayIO.getCurrentFrame(), d
    659                                                                                                 .getEnclosedShape());
     774                                                List<Item> items = FrameUtils.getItemsEnclosedBy(
     775                                                                DisplayIO.getCurrentFrame(), d
     776                                                                                .getEnclosedShape());
    660777                                                if (items != null) {
    661778                                                        ArrayList<Item> toCopy = new ArrayList<Item>(items
    662779                                                                        .size());
    663                                                         for (ItemPermission ip : items)
    664                                                                 if (ip.Permission >= ItemPermission.PERMISSION_COPY)
    665                                                                         toCopy.add(ip.Item);
     780                                                        for (Item ip : items)
     781                                                                if (ip.Permission >= Item.PERMISSION_COPY)
     782                                                                        toCopy.add(ip);
    666783
    667784                                                        copies = copy(toCopy);
     
    671788                                        } else if (Frame.FreeItems.size() == 2) {
    672789                                                copies = ItemUtils.UnreelLine(Frame.FreeItems);
    673                                                 List<Item> leftOver = merge(Frame.FreeItems,
    674                                                                 clicked.Item);
     790                                                List<Item> leftOver = merge(Frame.FreeItems, clicked);
    675791                                                anchor(leftOver);
    676792                                                if (copies == null)
     
    685801                                        } else if (Frame.FreeItems.size() == 1) {
    686802                                                copies = copy(Frame.FreeItems);
    687                                                 List<Item> remain = merge(copies, clicked.Item);
     803                                                List<Item> remain = merge(copies, clicked);
    688804
    689805                                                // ignore items that could not be merged.
     
    724840                                        updateCursor();
    725841                                        // pick up a copy of all enclosed items
    726                                         List<ItemPermission> items = FrameUtils.getItemsEnclosedBy(
    727                                                         DisplayIO.getCurrentFrame(), d.getEnclosedShape());
     842                                        List<Item> items = FrameUtils.getItemsEnclosedBy(DisplayIO
     843                                                        .getCurrentFrame(), d.getEnclosedShape());
    728844                                        if (items != null) {
    729845                                                ArrayList<Item> toCopy = new ArrayList<Item>(items
    730846                                                                .size());
    731                                                 for (ItemPermission ip : items)
    732                                                         if (ip.Permission >= ItemPermission.PERMISSION_COPY)
    733                                                                 toCopy.add(ip.Item);
     847                                                for (Item ip : items)
     848                                                        if (ip.Permission >= Item.PERMISSION_COPY)
     849                                                                toCopy.add(ip);
    734850                                                toCopy.removeAll(d.getAllConnected());
    735851
    736852                                                if (toCopy.size() > 0) {
    737853                                                        pickup(copy(toCopy));
    738                                                         DisplayIO.getCurrentFrame().removeAllItems(d.getAllConnected());
     854                                                        DisplayIO.getCurrentFrame().removeAllItems(
     855                                                                        d.getAllConnected());
    739856                                                } else {
    740857                                                        pickup(copy(d.getAllConnected()));
     
    746863                                if (Frame.FreeItems.size() == 2) {
    747864                                        if (clicked != null) {
    748                                                 List<Item> leftOver = merge(Frame.FreeItems,
    749                                                                 clicked.Item);
     865                                                List<Item> leftOver = merge(Frame.FreeItems, clicked);
    750866                                                anchor(leftOver);
    751867                                        }
     
    766882                                }
    767883
     884                                if (_extrude) {
     885                                        List<Item> originals = new ArrayList<Item>();
     886                                        // remove any lines that dont have both endpoints floating
     887                                        for (Item i : Frame.FreeItems) {
     888                                                if (i.isFloating())
     889                                                        originals.add(i);
     890                                        }
     891                                        if (copies == null)
     892                                                copies = ItemUtils.CopyItems(originals, _extrude);
     893                                        for (Item i : copies)
     894                                                i.setOffset(0, 0);
     895                                        anchor(Frame.FreeItems);
     896                                        // Move isnt working right for extruding!!
     897                                        // move(copies);
     898                                        pickup(copies);
     899                                        updateCursor();
     900                                        FrameGraphics.Repaint();
     901                                        return;
     902                                }
     903
    768904                                if (copies == null)
    769                                         copies = copy(Frame.FreeItems);
     905                                        copies = ItemUtils.CopyItems(Frame.FreeItems);
    770906                                // MIKE: what does the below 2 lines do?
    771907                                for (Item i : copies)
     
    784920                        if (clicked != null) {
    785921                                // check permissions
    786                                 if (clicked.Permission < ItemPermission.PERMISSION_COPY) {
     922                                if (clicked.Permission < Item.PERMISSION_COPY) {
    787923                                        FrameGraphics
    788924                                                        .DisplayMessage("Insufficient permission to copy item");
     
    790926                                }
    791927
    792                                 // This happens when the user right clicks on the endpoint of an
    793                                 // existing line
    794                                 // check for unreeling
    795                                 List<Item> copies = ItemUtils.UnreelLine(clicked.Item);
    796 
     928                                List<Item> copies = ItemUtils.UnreelLine(clicked);
     929                                // Copies will NOT be null if the user right clicked on a point
    797930                                if (copies == null) {
    798                                         // check if this is picking up a rectangle
    799                                         if (clicked.Item instanceof Dot
    800                                                         && clicked.Item.getConnected().size() == 3) {
    801                                                 Dot d = null;
    802                                                 // only one dot will be present for rectangles
    803                                                 for (Item i : clicked.Item.getConnected())
    804                                                         if (i instanceof Dot && d == null)
    805                                                                 d = (Dot) i;
    806                                                         else if (i instanceof Dot && d != null)
    807                                                                 d = null;
    808 
    809                                                 // if this is indeed a rectangle anchor
    810                                                 if (d != null) {
    811                                                         // pick up a copy of all enclosed items
    812                                                         List<ItemPermission> items = FrameUtils
    813                                                                         .getItemsEnclosedBy(DisplayIO
    814                                                                                         .getCurrentFrame(), d
    815                                                                                         .getEnclosedShape());
    816                                                         if (items != null) {
    817                                                                 ArrayList<Item> toCopy = new ArrayList<Item>(
    818                                                                                 items.size());
    819                                                                 for (ItemPermission ip : items)
    820                                                                         if (ip.Permission >= ItemPermission.PERMISSION_COPY)
    821                                                                                 toCopy.add(ip.Item);
    822 
    823                                                                 List<Item> toPickup = copy(toCopy);
    824                                                                 clearParent(toPickup);
    825                                                                 pickup(toPickup);
    826                                                         }
    827                                                         return;
    828                                                 }
    829                                         }
    830                                         copies = copy(clicked.Item);
    831                                 }
    832 
     931                                        List<Item> originals = clicked.getConnected();
     932                                        copies = ItemUtils.CopyItems(originals, _extrude);
     933                                }
    833934                                pickup(copies);
    834935                                return;
    835 
    836936                        } else {
    837                                 // if the user is pointing inside a closed shape, copy the items
    838                                 // inside
     937                                // if user is pointing in a closed shape, copy the items inside
    839938                                if (clickedIn != null) {
    840939                                        List<Item> toCopy = new ArrayList<Item>(clickedIn.size());
    841                                         for (ItemPermission ip : clickedIn)
    842                                                 if (ip.Permission >= ItemPermission.PERMISSION_COPY)
    843                                                         toCopy.add(ip.Item);
     940                                        for (Item ip : clickedIn)
     941                                                if (ip.Permission >= Item.PERMISSION_COPY)
     942                                                        toCopy.add(ip);
    844943
    845944                                        List<Item> copies = copy(toCopy);
     
    9521051                        FrameGraphics.Repaint();
    9531052                        return;
     1053                }
     1054
     1055                if (_mouseDown == MouseEvent.BUTTON2 && _lastClickedOn == null
     1056                                && _lastClickedIn == null) {
     1057                        Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), e.getX(),
     1058                                        e.getY());
     1059                        // if the user can spot-weld, show the virtual spot
     1060                        if (Frame.FreeItems.size() == 0 && on instanceof Line) {
     1061                                Line line = (Line) on;
     1062                                line.showVirtualSpot(e.getX(), e.getY());
     1063                        }
    9541064                }
    9551065
     
    9661076                                || Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold)
    9671077                        _isNoOp = true;
     1078
     1079                FrameGraphics.Repaint();
    9681080        }
    9691081
     
    10141126                if (checkHighlight) {
    10151127                        // ByMike: Get the item the mouse is hovering over
    1016                         ItemPermission click = FrameUtils.getCurrentItem();
     1128                        Item click = FrameUtils.getCurrentItem();
    10171129                        Item on = null;
    1018 
     1130                        // System.out.println(click);
    10191131                        if (click != null) {
    1020                                 on = click.Item;
     1132                                on = click;
    10211133                                // set the context
    10221134                                if (on instanceof Line)
     
    11551267
    11561268        private static void move(List<Item> toMove) {
    1157                 int deltax = toMove.get(0).getX() - (DisplayIO.getMouseX() - _offX);
    1158                 int deltay = toMove.get(0).getY() - (MouseY - _offY);
     1269                int xPos = (DisplayIO.getMouseX() - _offX);
     1270
     1271                Item firstDot = toMove.get(0);
     1272
     1273                /*
     1274                 * for (Item i: toMove) { if (i instanceof Dot){ firstDot = i; break; } }
     1275                 */
     1276
     1277                int deltax = firstDot.getX() - xPos;
     1278                int deltay = firstDot.getY() - (MouseY - _offY);
    11591279
    11601280                for (Item move : toMove) {
     
    11751295        private static void checkTDFCItemWaiting() {
    11761296                // if there is a TDFC Item waiting
    1177                 if (_tdfcItem != null) {
     1297                if (getTdfcItem() != null) {
    11781298                        Frame currentFrame = DisplayIO.getCurrentFrame();
    11791299                        boolean change = currentFrame.hasChanged();
     
    11831303                        // possible
    11841304                        if (!change && !saved) {
    1185                                 _tdfcItem.setLink(null);
    1186                                 _tdfcItem.getParent().setChanged(true);
    1187                                 FrameIO.SaveFrame(_tdfcItem.getParent());
     1305                                getTdfcItem().setLink(null);
     1306                                getTdfcItem().getParent().setChanged(true);
     1307                                FrameIO.SaveFrame(getTdfcItem().getParent());
    11881308                                FrameGraphics.Repaint();
    11891309                        } else {
     
    11921312                        }
    11931313
    1194                         _tdfcItem = null;
     1314                        setTdfcItem(null);
    11951315                }
    11961316        }
     
    11981318        private static void back() {
    11991319                checkTDFCItemWaiting();
     1320               
    12001321                DisplayIO.Back();
    1201 
     1322               
    12021323                // repaint things if necessary
    12031324                if (Frame.itemAttachedToCursor())
     
    12261347
    12271348                linker.setLink("" + next.getFrameNumber());
    1228                 _tdfcItem = linker;
     1349                setTdfcItem(linker);
     1350
     1351                // Set the link for an @Parent annotation item if one is on the frame
     1352                for (Item i : next.getItems()) {
     1353                        if ((i instanceof Text) && ItemUtils.isTag(i, ItemUtils.TAG_PARENT)
     1354                                        && i.getLink() == null)
     1355                                i.setLink(DisplayIO.getCurrentFrame().getFrameName());
     1356                }
    12291357
    12301358                FrameUtils.DisplayFrame(next, true);
     
    12471375         *
    12481376         * @param toExtract
    1249          *            ItemPermission containing the Item to extract the attributes
    1250          *            from.
     1377         *            Item containing the Item to extract the attributes from.
    12511378         */
    1252         private static void extractAttributes(ItemPermission toExtract) {
    1253                 if (toExtract == null || toExtract.Item == null)
     1379        private static void extractAttributes(Item toExtract) {
     1380                if (toExtract == null || toExtract == null)
    12541381                        return;
    12551382
     
    12581385
    12591386                Text attribs;
    1260                 Item item = toExtract.Item;
     1387                Item item = toExtract;
    12611388                // Extract the frames attributes when the user clicks on the frame name
    12621389                if (item.isFrameName())
     
    12761403        }
    12771404
    1278         private static void delete(ItemPermission toDelete) {
     1405        private static void delete(Item toDelete) {
    12791406                FrameUtils.LastEdited = null;
    12801407                _offX = _offY = 0;
     
    12821409                // check if the user is pointing at the frame's framename
    12831410                if (toDelete != null
    1284                                 && toDelete.Item == DisplayIO.getCurrentFrame().getName()) {
     1411                                && toDelete == DisplayIO.getCurrentFrame().getFrameNameItem()) {
    12851412                        DisplayIO.getCurrentFrame().clear();
    12861413                        FrameGraphics.Repaint();
     
    12931420                        if (Frame.FreeItems.size() == 1
    12941421                                        && Frame.FreeItems.get(0) instanceof Text
    1295                                         && toDelete != null && toDelete.Item instanceof Text) {
     1422                                        && toDelete != null && toDelete instanceof Text) {
    12961423
    12971424                                // check permissions
    1298                                 if (toDelete.Permission < ItemPermission.PERMISSION_FULL) {
     1425                                if (toDelete.Permission < Item.PERMISSION_FULL) {
    12991426                                        FrameGraphics
    13001427                                                        .DisplayMessage("Insufficient permission to swap Item text");
     
    13021429                                }
    13031430
    1304                                 Text anchored = (Text) toDelete.Item;
     1431                                Text anchored = (Text) toDelete;
    13051432                                Text free = (Text) Frame.FreeItems.get(0);
    13061433
     
    13291456                        // if the user is pointing inside a closed shape, delete all
    13301457                        // items inside it
    1331                         List<ItemPermission> items = FrameUtils.getCurrentItems();
     1458                        List<Item> items = FrameUtils.getCurrentItems();
    13321459
    13331460                        if (items != null) {
    13341461                                ArrayList<Item> toRemove = new ArrayList<Item>(items.size());
    1335                                 for (ItemPermission ip : items)
    1336                                         if (ip.Permission >= ItemPermission.PERMISSION_FULL) {
    1337                                                 toRemove.add(ip.Item);
     1462                                for (Item ip : items)
     1463                                        if (ip.Permission >= Item.PERMISSION_FULL) {
     1464                                                toRemove.add(ip);
    13381465                                        }
    13391466
     
    13521479                } else {
    13531480                        // check permissions
    1354                         if (toDelete.Permission < ItemPermission.PERMISSION_FULL) {
     1481                        if (toDelete.Permission < Item.PERMISSION_FULL) {
    13551482                                FrameGraphics
    13561483                                                .DisplayMessage("Insufficient permission to delete item");
     
    13581485                        }
    13591486
    1360                         Frame current = toDelete.Item.getParent();
     1487                        Frame current = toDelete.getParent();
    13611488
    13621489                        current.setChanged(true);
     
    13641491                        List<Item> toUndo = new LinkedList<Item>();
    13651492
    1366                         if (toDelete.Item instanceof Dot) {
    1367                                 toUndo.addAll(deleteDot((Dot) toDelete.Item));
     1493                        if (toDelete instanceof Dot) {
     1494                                toUndo.addAll(deleteDot((Dot) toDelete));
    13681495                        } else
    1369                                 toUndo.addAll(copy(toDelete.Item.getConnected()));
     1496                                toUndo.addAll(copy(toDelete.getConnected()));
    13701497
    13711498                        current.addAllToUndo(toUndo);
    1372                         current.removeAllItems(toDelete.Item.getConnected());
     1499                        current.removeAllItems(toDelete.getConnected());
    13731500                        // reset the mouse cursor
    13741501                        updateCursor();
     
    14291556                }
    14301557
    1431                 // check for rectangle deletion
    1432                 if (itemList.size() == 3) {
    1433                         boolean rectangle = false;
    1434                         Dot dot = null;
    1435                         // check that this is indeed a rectangle
    1436                         for (Item check : itemList) {
    1437                                 if (dot == null && check instanceof Dot)
    1438                                         dot = (Dot) check;
    1439                                 else if (check != dot && !dot.getLines().contains(check)) {
    1440                                         rectangle = false;
    1441                                         break;
    1442                                 } else
    1443                                         rectangle = true;
    1444                         }
    1445 
    1446                         // if this is a rectangle, remove the entire rectangle
    1447                         if (rectangle) {
    1448                                 // List<Item> copy = copy(dot.getAllConnected());
    1449                                 current.addAllToUndo(dot.getAllConnected());
    1450                                 current.removeAllItems(dot.getAllConnected());
    1451                                 itemList.clear();
    1452                                 // reset the mouse cursor
    1453                                 updateCursor();
    1454                                 FrameGraphics.Repaint();
    1455                                 return;
    1456                         }
    1457                 }
     1558                // Mike: What is the point of the code below
     1559                // It causes problems when deleting three items off the cursor which
     1560                // include a non dot or line item
     1561                /*
     1562                 * // check for rectangle deletion if (itemList.size() == 3) { boolean
     1563                 * rectangle = false; Dot dot = null; // check that this is indeed a
     1564                 * rectangle for (Item check : itemList) { if (dot == null && check
     1565                 * instanceof Dot) dot = (Dot) check; else if (check != dot &&
     1566                 * !dot.getLines().contains(check)) { rectangle = false; break; } else
     1567                 * rectangle = true; } // if this is a rectangle, remove the entire
     1568                 * rectangle if (rectangle) { // List<Item> copy =
     1569                 * copy(dot.getAllConnected());
     1570                 * current.addAllToUndo(dot.getAllConnected());
     1571                 * current.removeAllItems(dot.getAllConnected()); itemList.clear(); //
     1572                 * reset the mouse cursor updateCursor(); FrameGraphics.Repaint();
     1573                 * return; } }
     1574                 */
    14581575
    14591576                current.removeAllItems(itemList);
     
    15161633
    15171634        public static List<Item> merge(List<Item> merger, Item mergee) {
    1518                 if (mergee.getParent().getName() == mergee) {
     1635                if (mergee.getParent().getFrameNameItem() == mergee) {
    15191636                        return mergee.getParent().merge(merger);
    15201637                }
     
    16141731                                                // TODO tidy this up... the text override of this method
    16151732                                                // doesnt use the parametres MouseY and MouseX!!
    1616                                                 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY
    1617                                                                 - DisplayIO.getOffset());
     1733                                                res = mergee.merge(i, DisplayIO.getMouseX(), MouseY);
    16181734                                                if (res != null) {
    16191735                                                        remain.add(res);
     
    16211737                                        }
    16221738                                } else {
    1623                                         res = mergee.merge(i, DisplayIO.getMouseY(), MouseY
    1624                                                         - DisplayIO.getOffset());
     1739                                        res = mergee.merge(i, DisplayIO.getMouseY(), MouseY);
    16251740                                        if (res != null)
    16261741                                                remain.addAll(res.getConnected());
     
    16961811        }
    16971812
    1698         private static void createLine() {
     1813        private static Line createLine() {
    16991814                // create the two endpoints
    17001815                Dot end = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(),
     
    17121827                // attach the line to the cursor
    17131828                pickup(end);
     1829
     1830                return line;
    17141831        }
    17151832
     
    17301847
    17311848        public static void anchor(Item toAnchor) {
     1849                // System.out.println("Anchor:" + toAnchor.getX() + "," +
     1850                // toAnchor.getY());
     1851
    17321852                Frame current = DisplayIO.getCurrentFrame();
    17331853                // toAnchor.anchor(current);
     
    18031923                                        else
    18041924                                                line.toggleArrowHeadLength(arg0.getWheelRotation());
     1925                                        line.getParent().change();
    18051926                                        FrameGraphics.Repaint();
    18061927                                }
     
    18161937                                FrameKeyboardActions.functionKey(rotationType);
    18171938                } else if (clicks == MOUSE_WHEEL_THRESHOLD) {
    1818                         ItemPermission ip = FrameUtils.getCurrentItem();
     1939                        Item ip = FrameUtils.getCurrentItem();
    18191940
    18201941                        // if the user is not pointing to any item
     
    18251946                        } else {
    18261947                                // check permissions
    1827                                 if (ip.Permission < ItemPermission.PERMISSION_FULL) {
     1948                                if (ip.Permission < Item.PERMISSION_FULL) {
    18281949                                        FrameGraphics
    18291950                                                        .DisplayMessage("Insufficient permission to change the size of that item");
     
    18321953                        }
    18331954
    1834                         if (ip.Item instanceof Line) {
    1835                                 Line line = (Line) ip.Item;
     1955                        if (ip instanceof Line) {
     1956                                Line line = (Line) ip;
    18361957                                line.toggleDashed(arg0.getWheelRotation());
     1958                                line.getParent().change();
    18371959                                FrameGraphics.Repaint();
    18381960                                return;
     
    18792001                return isDelete(_lastMouseClick);
    18802002        }
     2003
     2004        public static void setTdfcItem(Item _tdfcItem) {
     2005                FrameMouseActions._tdfcItem = _tdfcItem;
     2006        }
     2007
     2008        public static Item getTdfcItem() {
     2009                return _tdfcItem;
     2010        }
    18812011}
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r4 r7  
    1212import org.expeditee.items.Dot;
    1313import org.expeditee.items.Item;
    14 import org.expeditee.items.ItemPermission;
    1514import org.expeditee.items.ItemUtils;
    1615import org.expeditee.items.Line;
     
    187186                                space = MINIMUM_INTERITEM_SPACING;
    188187
    189                         if (above != curr.getName() && above != curr.getTitle())
     188                        if (above != curr.getFrameNameItem() && above != curr.getTitle())
    190189                                x = above.getX();
    191190
     
    493492                                UserSettings.NoOpThreshold = getInt(item,
    494493                                                UserSettings.NoOpThreshold);
    495                         else if (ItemUtils.isTag(item, "@InitialWidth:")){
    496                                 UserSettings.InitialWidth= getInt(item,
    497                                                 UserSettings.InitialWidth);}
    498                         else if (ItemUtils.isTag(item, "@InitialHeight:")){
    499                                 UserSettings.InitialHeight= getInt(item,
    500                                                 UserSettings.InitialHeight);}
    501                         else if (ItemUtils.isTag(item, "@Logging:")) {
     494                        else if (ItemUtils.isTag(item, "@InitialWidth:")) {
     495                                UserSettings.InitialWidth = getInt(item,
     496                                                UserSettings.InitialWidth);
     497                        } else if (ItemUtils.isTag(item, "@InitialHeight:")) {
     498                                UserSettings.InitialHeight = getInt(item,
     499                                                UserSettings.InitialHeight);
     500                        } else if (ItemUtils.isTag(item, "@Logging:")) {
    502501                                UserSettings.Logging = getBoolean(item, UserSettings.Logging);
    503502                        } else if (ItemUtils.isTag(item, ItemUtils.TAG_ITEM_TEMPLATE)) {
     
    647646
    648647                // Text title = null;
    649                 // Text template = UserSettings.ItemTemplate.copy();
     648                // Text template = UserSettingsTemplate.copy();
    650649
    651650                ArrayList<Overlay> overlays = new ArrayList<Overlay>();
     
    708707                                        // Parse(overlay);
    709708                                        if (overlay != null && !overlays.contains(overlay))
    710                                                 overlays.add(new Overlay(overlay,
    711                                                                 ItemPermission.PERMISSION_NONE));
     709                                                overlays
     710                                                                .add(new Overlay(overlay, Item.PERMISSION_NONE));
    712711                                }
    713712
     
    717716                                        String link = i.getLink();
    718717                                        if (FrameIO.isPositiveInteger(link))
    719                                                 link = toParse.getFramesetNameAdjusted()
    720                                                                 + link;
     718                                                link = toParse.getFramesetNameAdjusted() + link;
    721719                                        Frame overlay = FrameIO.LoadFrame(link);
    722720                                        // Parse(overlay);
     
    726724                                                                .getFirstLine());
    727725                                                // default permission (if none is specified)
    728                                                 int perm = ItemPermission.PERMISSION_FOLLOW_LINKS;
     726                                                int perm = Item.PERMISSION_FOLLOW_LINKS;
    729727
    730728                                                try {
     
    735733                                                                level = level.toLowerCase().trim();
    736734                                                                if (level.equals("none"))
    737                                                                         perm = ItemPermission.PERMISSION_NONE;
     735                                                                        perm = Item.PERMISSION_NONE;
    738736                                                                else if (level.equals("links")
    739737                                                                                || level.equals("link"))
    740                                                                         perm = ItemPermission.PERMISSION_FOLLOW_LINKS;
     738                                                                        perm = Item.PERMISSION_FOLLOW_LINKS;
    741739                                                                else if (level.equals("copy"))
    742                                                                         perm = ItemPermission.PERMISSION_COPY;
     740                                                                        perm = Item.PERMISSION_COPY;
    743741                                                                else if (level.equals("tdfc"))
    744                                                                         perm = ItemPermission.PERMISSION_TDFC;
     742                                                                        perm = Item.PERMISSION_TDFC;
    745743                                                                else if (level.equals("full")
    746744                                                                                || level.equals("all"))
    747                                                                         perm = ItemPermission.PERMISSION_FULL;
     745                                                                        perm = Item.PERMISSION_FULL;
    748746                                                                else
    749747                                                                        FrameGraphics
     
    794792                                }
    795793
    796                                 if (toParse.getFrameNumber() > 0
    797                                                 && ItemUtils.isTag(i, ItemUtils.TAG_PARENT)
    798                                                 && i.getLink() == null)
    799                                         i.setLink(DisplayIO.getCurrentFrame().getFrameName());
    800 
    801794                        } catch (Exception e) {
    802795                                Logger.Log(e);
     
    833826         * @return The Item at the given coordinates, or NULL if none is found.
    834827         */
    835         private static ItemPermission onItem(Frame toCheck, int x, int y) {
     828        public static Item onItem(Frame toCheck, int x, int y) {
    836829                if (toCheck == null)
    837830                        return null;
    838831
    839                 List<ItemPermission> possibles = new ArrayList<ItemPermission>(0);
     832                List<Item> possibles = new ArrayList<Item>(0);
    840833
    841834                // if the mouse is in the message area
     
    843836                        // check the individual message items
    844837                        for (Text message : FrameGraphics.Messages) {
    845                                 if (message != null && message.contains(x, y))
    846                                         possibles.add(new ItemPermission(message,
    847                                                         ItemPermission.PERMISSION_COPY));
     838                                if (message != null) {
     839                                        if (message.contains(x, y)) {
     840                                                message.Permission = Item.PERMISSION_COPY;
     841                                        }
     842                                        possibles.add(message);
     843                                }
    848844                        }
    849845
    850846                        // check the link to the message frame
    851847                        if (FrameGraphics.MessageLink != null) {
    852                                 if (FrameGraphics.MessageLink.contains(x, y))
    853                                         possibles.add(new ItemPermission(FrameGraphics.MessageLink,
    854                                                         ItemPermission.PERMISSION_COPY));
     848                                if (FrameGraphics.MessageLink.contains(x, y)) {
     849                                        FrameGraphics.MessageLink.Permission = Item.PERMISSION_COPY;
     850                                }
     851                                possibles.add(FrameGraphics.MessageLink);
    855852                        }
    856853                        // otherwise, the mouse is on the frame
     
    860857                                        && !Frame.FreeItems.contains(LastEdited)
    861858                                        && LastEdited.getParent() == DisplayIO.getCurrentFrame()
    862                                         && LastEdited.getParent().getItems().contains(LastEdited))
    863                                 return new ItemPermission(LastEdited,
    864                                                 ItemPermission.PERMISSION_FULL);
    865                         else
     859                                        && LastEdited.getParent().getItems().contains(LastEdited)) {
     860                                LastEdited.Permission = Item.PERMISSION_FULL;
     861                                return LastEdited;
     862                        } else
    866863                                LastEdited = null;
    867 
     864                       
    868865                        ArrayList<Item> checkList = new ArrayList<Item>();
    869866                        checkList.addAll(toCheck.getItems());
     867                        checkList.add(toCheck.getFrameNameItem());
    870868                        for (Item i : checkList) {
    871869                                // do not check annotation items in audience mode
     
    873871                                        if (i.contains(x, y) && !Frame.FreeItems.contains(i)) {
    874872                                                // names have copy permissions only
    875                                                 if (i == toCheck.getName())
    876                                                         possibles.add(new ItemPermission(i,
    877                                                                         ItemPermission.PERMISSION_TDFC));
    878                                                 else
    879                                                         possibles.add(new ItemPermission(i,
    880                                                                         ItemPermission.PERMISSION_FULL));
     873                                                if (i == toCheck.getFrameNameItem()) {
     874                                                        i.Permission = Item.PERMISSION_TDFC;
     875                                                        possibles.add(i);
     876                                                } else {
     877                                                        i.Permission = Item.PERMISSION_FULL;
     878                                                        possibles.add(i);
     879                                                }
    881880                                        }
    882881                                }
     
    884883
    885884                        for (Overlay o : toCheck.getOverlays()) {
    886                                 if (o.Level > ItemPermission.PERMISSION_NONE) {
    887                                         ItemPermission i = onItem(o.Frame, x, y);
     885                                if (o.Level > Item.PERMISSION_NONE) {
     886                                        Item i = onItem(o.Frame, x, y);
    888887
    889888                                        // the message is included above with full permissions,
    890                                         // it
    891                                         // should be ignored here
     889                                        // it should be ignored here
    892890                                        if (i != null
    893                                                         && /* i.Item != FrameGraphics.TextMessage && */i.Item
     891                                                        && /* i != FrameGraphics.TextMessage && */i
    894892                                                                        .getID() > 0) {
    895893                                                if (o.Level < i.Permission)
     
    910908
    911909                // return closest x,y pair to mouse
    912                 ItemPermission closest = possibles.get(0);
    913                 int distance = (int) Math.sqrt(Math.pow(Math.abs(closest.Item.getX()
    914                                 - x), 2)
    915                                 + Math.pow(Math.abs(closest.Item.getY() - y), 2));
    916 
    917                 for (ItemPermission ip : possibles) {
    918                         Item i = ip.Item;
     910                Item closest = possibles.get(0);
     911                int distance = (int) Math.sqrt(Math
     912                                .pow(Math.abs(closest.getX() - x), 2)
     913                                + Math.pow(Math.abs(closest.getY() - y), 2));
     914
     915                for (Item ip : possibles) {
     916                        Item i = ip;
    919917
    920918                        int d = (int) Math.sqrt(Math.pow(Math.abs(i.getX() - x), 2)
     
    928926                                 * TODO: Remove line\dot specification
    929927                                 */
    930                                 if ((!(closest.Item instanceof Dot && i instanceof Line))
    931                                                 && (!(closest.Item instanceof Text && i instanceof Line)))
     928                                if ((!(closest instanceof Dot && i instanceof Line))
     929                                                && (!(closest instanceof Text && i instanceof Line)))
    932930                                        closest = ip;
    933931
     
    939937        }
    940938
    941         public static ItemPermission getCurrentItem() {
     939        public static Item getCurrentItem() {
    942940                return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(),
    943941                                DisplayIO.getMouseY());
    944942        }
    945943
    946         public static List<ItemPermission> getCurrentItems() {
    947                 /*
    948                  * // update enclosed shapes Frame current =
    949                  * DisplayIO.getCurrentFrame(); List<Item> items = current.getItems();
    950                  * ArrayList<Dot> dots = new ArrayList<Dot>(0);
    951                  *
    952                  * for (Item i : items) if (i instanceof Dot) dots.add((Dot) i);
    953                  *
    954                  * ArrayList<Polygon> possibles = new ArrayList<Polygon>(0); ArrayList<Dot>
    955                  * used = new ArrayList<Dot>(0);
    956                  *
    957                  * for (Dot d : dots) if (d.isEnclosed()) { boolean skip = false; //
    958                  * check for duplicate enclosures for (Dot seen : used) { if
    959                  * (seen.getEnclosingDots().contains(d)) { skip = true; break; } }
    960                  *
    961                  * if (!skip) { Polygon p = d.getEnclosedShape(); if (p
    962                  * .contains(DisplayIO.getMouseX(), DisplayIO .getMouseY())) {
    963                  * possibles.add(p); used.add(d); } } }
    964                  *
    965                  * if (possibles.size() == 0) return null; // if there is only one
    966                  * possibility, return it if (possibles.size() == 1) { return
    967                  * getItemsEnclosedBy(current, possibles.get(0)); //otherwise, determine
    968                  * which polygon is closest to the cursor }else{
    969                  * Collections.sort(possibles, new Comparator<Polygon>(){ public int
    970                  * compare(Polygon p1, Polygon p2) { int closest = Integer.MAX_VALUE;
    971                  * int close2 = Integer.MAX_VALUE;
    972                  *
    973                  * int mouseX = DisplayIO.getMouseX(); int mouseY =
    974                  * DisplayIO.getMouseY();
    975                  *
    976                  * for(int i = 0; i < p1.npoints; i++){ int diff =
    977                  * Math.abs(p1.xpoints[i] - mouseX) + Math.abs(p1.ypoints[i] - mouseY);
    978                  * int diff2 = Integer.MAX_VALUE;
    979                  *
    980                  * if(i < p2.npoints) diff2 = Math.abs(p2.xpoints[i] - mouseX) +
    981                  * Math.abs(p2.ypoints[i] - mouseY);
    982                  *
    983                  * if(diff < Math.abs(closest)){ close2 = closest; closest = diff; }else
    984                  * if(diff < Math.abs(close2)) close2 = diff;
    985                  *
    986                  * if(diff2 < Math.abs(closest)){ close2 = closest; closest = -diff2;
    987                  * }else if(diff2 < Math.abs(close2)) close2 = diff2; }
    988                  *
    989                  * if(closest > 0 && close2 > 0) return -10;
    990                  *
    991                  * if(closest < 0 && close2 < 0) return 10;
    992                  *
    993                  *
    994                  * if(closest > 0) return -10;
    995                  *
    996                  * return 10; }
    997                  *
    998                  * }); return getItemsEnclosedBy(current, possibles.get(0)); }
    999                  */
     944        public static List<Item> getCurrentItems() {
    1000945
    1001946                List<Dot> enclosure = getEnclosingDots();
     
    10891034        }
    10901035
    1091         public static List<ItemPermission> getItemsEnclosedBy(Frame frame,
    1092                         Polygon poly) {
     1036        public static List<Item> getItemsEnclosedBy(Frame frame, Polygon poly) {
    10931037                List<Item> contained = frame.getItemsWithin(poly);
    10941038
    1095                 ArrayList<ItemPermission> results = new ArrayList<ItemPermission>(
    1096                                 contained.size());
     1039                ArrayList<Item> results = new ArrayList<Item>(contained.size());
    10971040
    10981041                // check for correct permissions
    10991042                for (Item item : contained) {
    11001043                        // if the item is on the frame
    1101                         if (item.getParent() == frame || item.getParent() == null)
     1044                        if (item.getParent() == frame || item.getParent() == null) {
    11021045                                // TODO this is a bit of a hack...
    11031046                                // the
     
    11131056                                // is
    11141057                                // created...
    1115                                 results.add(new ItemPermission(item,
    1116                                                 ItemPermission.PERMISSION_FULL));
    1117                         // otherwise, it must be on an overlay frame
    1118                         else {
     1058                                item.Permission = Item.PERMISSION_FULL;
     1059                                results.add(item);
     1060                                // otherwise, it must be on an overlay frame
     1061                        } else {
    11191062                                for (Overlay overlay : frame.getOverlays())
    11201063                                        if (overlay.Frame == item.getParent()) {
    1121                                                 results.add(new ItemPermission(item, overlay.Level));
     1064                                                item.Permission = overlay.Level;
     1065                                                results.add(item);
    11221066                                                break;
    11231067                                        }
     
    11551099                yPos += spacing;
    11561100
    1157                 profile.addText(xPos, yPos, "@InitialWidth: " + UserSettings.InitialWidth, null);
     1101                profile.addText(xPos, yPos, "@InitialWidth: "
     1102                                + UserSettings.InitialWidth, null);
    11581103                yPos += spacing;
    11591104
    1160                 profile.addText(xPos, yPos, "@InitialHeight: " + UserSettings.InitialHeight, null);
     1105                profile.addText(xPos, yPos, "@InitialHeight: "
     1106                                + UserSettings.InitialHeight, null);
    11611107                yPos += spacing;
    11621108
     
    11751121                yPos = intialYPos;
    11761122
    1177                 Text help = profile.addText(xPos, yPos, "Expeditee Help", null);
    1178                 help.setSize(25);
    1179                 help.setFontStyle("Bold");
    1180                 help.setFamily("SansSerif");
    1181                 help.setColor(Item.COLOR_WHEEL[3]);
    1182 
    1183                 xPos = 625;
    11841123                // Iterate through the help folder and add links
    11851124                File helpDirectory = new File(FrameIO.HELP_PATH);
    11861125                if (helpDirectory != null) {
    1187                         for (File helpFrameset : helpDirectory.listFiles()) {
    1188                                 String framesetName = helpFrameset.getName();
    1189                                 Frame indexFrame = FrameIO.LoadFrame(framesetName
    1190                                                 + FrameIO.getFramesetExtension(framesetName));
    1191                                 // Look through the folder for help index pages
    1192                                 if (indexFrame != null
    1193                                                 && ItemUtils.FindTag(indexFrame.getItems(),
    1194                                                                 "@HelpIndex") != null) {
    1195                                         yPos += spacing;
    1196                                         t = profile.addText(xPos, yPos, indexFrame
    1197                                                         .getFramesetName(), null);
    1198                                         t.setLink(indexFrame.getFrameName());
     1126                        File[] helpFramesets = helpDirectory.listFiles();
     1127                        if (helpFramesets != null) {
     1128
     1129                                // Add the title for the help index
     1130                                Text help = profile.addText(xPos, yPos, "Expeditee Help", null);
     1131                                help.setSize(25);
     1132                                help.setFontStyle("Bold");
     1133                                help.setFamily("SansSerif");
     1134                                help.setColor(Item.COLOR_WHEEL[3]);
     1135
     1136                                xPos = 625;
     1137
     1138                                for (File helpFrameset : helpFramesets) {
     1139                                        String framesetName = helpFrameset.getName();
     1140                                        Frame indexFrame = FrameIO.LoadFrame(framesetName
     1141                                                        + FrameIO.getFramesetExtension(framesetName));
     1142                                        // Look through the folder for help index pages
     1143                                        if (indexFrame != null
     1144                                                        && ItemUtils.FindTag(indexFrame.getItems(),
     1145                                                                        "@HelpIndex") != null) {
     1146                                                yPos += spacing;
     1147                                                t = profile.addText(xPos, yPos, indexFrame
     1148                                                                .getFramesetName(), null);
     1149                                                t.setLink(indexFrame.getFrameName());
     1150                                        }
    11991151                                }
    12001152                        }
     
    12041156                FrameIO.SaveFrame(profile);
    12051157        }
     1158
     1159        /**
     1160         * Adjusts a frameset name so a period is appended if it ends in a digit.
     1161         * This form of the frameset name is used when referencing frames in the
     1162         * frame set.
     1163         *
     1164         * @param frameset
     1165         * @return
     1166         */
     1167        public static String GetFramesetNameAdjusted(String frameset) {
     1168                return frameset
     1169                                + (Character.isDigit(frameset.charAt(frameset.length() - 1)) ? "."
     1170                                                : "");
     1171        }
    12061172}
  • trunk/src/org/expeditee/items/Dot.java

    r4 r7  
    3232
    3333        private boolean _filled = true;
     34       
     35        protected boolean _filledHighlight = false;
    3436
    3537        public Dot(int id) {
     
    108110                if (isHighlighted()) {
    109111                        g.setColor(getHighlightColor());
    110                         g.drawPolygon(getPolygon());
     112                        // Draw the highlighting rectangle surrounding the dot
     113                        // this is drawn even if its part of a rectangle
     114                        if (_filledHighlight)
     115                                g.fillPolygon(getPolygon());
     116                        else
     117                                g.drawPolygon(getPolygon());
    111118                }
    112119
     
    346353                return "P " + getID();
    347354        }
     355       
     356        @Override
     357        public void setFilledHighlight(boolean value) {
     358                _filledHighlight = value;
     359        }
     360       
     361        @Override
     362        public void delete() {
     363                super.delete();
     364               
     365                for(Line l: this.getLines())
     366                        l.delete();
     367        }
    348368}
  • trunk/src/org/expeditee/items/Item.java

    r4 r7  
    3333 *
    3434 */
    35 public abstract class Item implements Comparable<Item>, Runnable {
    36 
     35public abstract class Item implements Comparable<Item>, Runnable {
     36
     37        public static int PERMISSION_NONE = 0;
     38        public static int PERMISSION_FOLLOW_LINKS = 1;
     39        public static int PERMISSION_COPY = 2;
     40        public static int PERMISSION_TDFC = 3;
     41        public static int PERMISSION_FULL = 4;
     42
     43        public static final int NEAR_DISTANCE = 15;
     44       
    3745        /**
    3846         * The default Color to draw highlighting in
     
    4351
    4452        public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN;
     53       
     54        public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE;
    4555
    4656        public static final Color LINK_COLOR = Color.BLACK;
     
    6373        public static final int MARGIN_LEFT = 20;
    6474
    65         private Point _offset = new Point(0, 0);
    66 
    67         private int _x;
    68 
    69         private int _y;
    70 
    71         private int _id;
    72 
    73         private String _creationDate = null;
    74 
    75         private boolean _linkMark = true;
    76 
    77         private boolean _actionMark = true;
    78 
    79         private boolean _highlight = true;
    80 
    81         private boolean _isHighlighted = false;
    82 
    83         // private boolean _isValidLink = true;
    84 
    85         private Dimension _maxSize = null;
    86 
    87         private String _owner = null;
    88 
    89         private String _link = null;
    90 
    91         private StringBuffer _data = new StringBuffer();
    92 
    93         private List<String> _actionCursorEnter = null;
    94 
    95         private List<String> _actionCursorLeave = null;
    96 
    97         private List<String> _actionEnterFrame = null;
    98 
    99         private List<String> _actionLeaveFrame = null;
    100 
    101         private Color _colorFill = null;
    102 
    103         private Color _color = null;
    104 
    105         private Color _highlightColor = DEFAULT_HIGHLIGHT;
    106 
    107         private Color _colorBackground = null;
    108 
    109         private Color _colorTopShadow = null;
    110 
    111         private Color _colorBottomShadow = null;
    112 
    113         // the link\action circle
    114         private Polygon _circle = null;
    115 
    116         // the invalid link cross
    117         private Polygon _circleCross = null;
    118 
    119         private Frame _parent = null;
    120 
    121         protected int _highlightThickness = 2;
    122 
    123         // arrowhead parameters
    124         private int _arrowheadLength = 0;
    125 
    126         private double _arrowheadRatio = 0;
    127 
    128         private Polygon _arrowhead = null;
    129 
    130         // the list of lines that this point is part of.
    131         private List<Line> _lines = new ArrayList<Line>();
    132 
    133         private int[] _linePattern = null;
    134 
    135         private boolean _floating = false;
    136 
    137         // list of points constrained with this point
    138         private List<Constraint> _constraints = null;
    139 
     75        protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5;
     76       
    14077        public static final Color GREEN = Color.GREEN.darker();
    14178
     
    14885                        DisplayIO.DEFAULT_BACKGROUND };
    14986
     87        public static final Color[] FILL_COLOR_WHEEL = { Color.BLACK, new Color(255,150,150),
     88                new Color(150,150,255), new Color(150,255,150), new Color(255,150,255), new Color(255,255,100),
     89                DisplayIO.DEFAULT_BACKGROUND };
     90
    15091        public static final int UNCHANGED_CURSOR = -100;
    15192
     
    160101        public static final int JUSTIFICATION_NONE = -1;
    161102
     103        // private boolean _isValidLink = true;
     104
    162105        public static final int JUSTIFICATION_FULL = 0;
    163106
     
    171114
    172115        public static final int POINTTYPE_CIRCLE = 0;
    173 
    174         private LinkedList<String> _actions = null;
    175 
    176         private String _link_frameset = null;
    177 
    178         private String _link_template = null;
    179 
    180         private String _fillPattern = null;
    181 
    182         protected Item() {
    183                 _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm");
    184         }
    185 
    186         /**
    187          * Items are sorted by their Y coordinate on the screen.
    188          *
    189          * @param i
    190          *            The Item to compare this Item to
    191          * @return a negative integer, zero, or a positive integer as this object is
    192          *         less than, equal to, or greater than the specified object.
    193          */
    194         public int compareTo(Item i) {
    195                 return getY() - i.getY();
    196         }
    197 
    198         public static int getGravity() {
    199                 return org.expeditee.gui.UserSettings.Gravity;
    200         }
    201 
    202         public static boolean showLineHighlight() {
    203                 return org.expeditee.gui.UserSettings.LineHighlight;
    204         }
    205 
    206         public boolean equals(Object o) {
    207                 if (o instanceof Item) {
    208                         Item i = (Item) o;
    209                         return i.getID() == getID()
    210                                         && ((i.getParent() == _parent) || (i.getParent() != null && i
    211                                                         .getParent().equals(_parent)));
    212 
    213                 } else
    214                         return false;
    215         }
    216 
    217         /**
    218          * Adds a given line to the list of lines that this Point is an end for.
    219          *
    220          * @param line
    221          *            The Line that this Point is an end of.
    222          */
    223         public void addLine(Line line) {
    224                 if (_lines.contains(line)) {
    225                         return;
    226                 }
    227 
    228                 line.setColor(getColor());
    229                 line.setSize(getSize());
    230                 line.setLinePattern(getLinePattern());
    231 
    232                 _lines.add(line);
    233         }
    234 
    235         /**
    236          * Removes the given Line from the list of lines that this Dot is an end
    237          * for.
    238          *
    239          * @param line
    240          *            The Line that this Dot is no longer an end of.
    241          */
    242         public void removeLine(Line line) {
    243                 _lines.remove(line);
    244         }
    245 
    246         /**
    247          * Returns a list of Lines where this Dot is an end.
    248          *
    249          * @return A list of the Lines that this Dot is an end for or null if no
    250          *         Lines have been added.
    251          */
    252         public List<Line> getLines() {
    253                 return _lines;
    254         }
    255 
    256         public void setLines(List<Line> lines) {
    257                 _lines = lines;
    258 
    259                 for (Line line : lines)
    260                         line.setLinePattern(getLinePattern());
    261         }
    262 
    263         public void setLinePattern(int[] pattern) {
    264                 _linePattern = pattern;
    265 
    266                 for (Line line : getLines())
    267                         line.setLinePattern(pattern);
    268         }
    269 
    270         public int[] getLinePattern() {
    271                 return _linePattern;
    272         }
    273 
    274         /**
    275          * Clears the list of Lines that this Dot is an end of. Note: This only
    276          * clears this Dot's list and does not have any affect on the Lines or other
    277          * Dots.
    278          */
    279         public void removeAllLines() {
    280                 _lines.clear();
    281         }
    282 
    283         /**
    284          * Returns the list of IDs of the Lines that this Dot is an end of.
    285          *
    286          * @return The list of Line IDs that this point is part of.
    287          */
    288         public String getLineIDs() {
    289                 String lineID = null;
    290 
    291                 if (_lines.size() > 0) {
    292                         lineID = "" + _lines.get(0).getID();
    293 
    294                         for (int i = 1; i < _lines.size(); i++)
    295                                 lineID += " " + _lines.get(i).getID();
    296                 }
    297 
    298                 return lineID;
    299         }
    300 
    301         /**
    302          * Sets the list of lines that this point is part of (may be set to null).
    303          *
    304          * @param lineID
    305          *            A String of line ID numbers separated by spaces.
    306          */
    307         public void setLineIDs(String lineID) {
    308         }
    309 
    310         public void setFloating(boolean val) {
    311                 _floating = val;
    312         }
    313 
    314         public boolean isFloating() {
    315                 return _floating;
    316         }
    317 
    318         /**
    319          * Returns a List of any Constraints that this Dot is a memeber of.
    320          *
    321          * @return a List of Constraints that this Dot is a member of.
    322          */
    323         public List<Constraint> getConstraints() {
    324                 return _constraints;
    325         }
    326 
    327         public String getConstraintIDs() {
    328                 if (_constraints == null || _constraints.size() == 0)
    329                         return null;
    330 
    331                 String cons = "";
    332 
    333                 for (Constraint c : _constraints)
    334                         cons += c.getID() + " ";
    335 
    336                 return cons.trim();
    337         }
    338 
    339         public void setConstraintIDs(String IDs) {
    340         };
    341 
    342         /**
    343          * Adds the given Constraint to this Dot
    344          *
    345          * @param c
    346          *            The Constraint to set this Dot as a member of.
    347          */
    348         public void addConstraint(Constraint c) {
    349                 if (_constraints == null)
    350                         _constraints = new ArrayList<Constraint>();
    351 
    352                 // do not add duplicate constraint
    353                 if (_constraints.contains(c))
    354                         return;
    355 
    356                 _constraints.add(c);
    357         }
    358 
    359         public void setConstraints(List<Constraint> constraints) {
    360                 _constraints = constraints;
    361         }
    362 
    363         public void removeAllConstraints() {
    364                 if (_constraints != null)
    365                         _constraints.clear();
    366         }
    367 
    368         /**
    369          * Removes the given Constraint from the list of constraintss that this Dot
    370          * is a part of.
    371          *
    372          * @param c
    373          *            The Constraint that this Dot is no longer a part of.
    374          */
    375         public void removeConstraint(Constraint c) {
    376                 _constraints.remove(c);
    377         }
    378 
    379         /**
    380          * Returns the ID of this Item, which must be unique for the Frame.
    381          *
    382          * @return The ID of this Item.
    383          */
    384         public int getID() {
    385                 return _id;
    386         }
    387 
    388         /**
    389          * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0
    390          * are not saved
    391          *
    392          * @param newID
    393          *            The new ID to assign this Item.
    394          */
    395         public void setID(int newID) {
    396                 _id = newID;
    397         }
    398 
    399         /**
    400          * Returns the Y coordinate of this Item on the screen
    401          *
    402          * @return The Y coordinate of this Item on the screen
    403          */
    404         public int getY() {
    405                 return _y;
    406         }
    407 
    408         /**
    409          * Returns the X coordinate of this Item on the screen
    410          *
    411          * @return The X coordinate of this Item on the screen
    412          */
    413         public int getX() {
    414                 return _x;
    415         }
    416 
    417         /**
    418          * Sets the position of this item on the screen
    419          *
    420          * @param x
    421          *            The new X coordinate
    422          * @param y
    423          *            The new Y coordinate
    424          */
    425         public void setPosition(int x, int y) {
    426                 _x = x;
    427                 _y = y;
    428 
    429                 updatePolygon();
    430 
    431                 // update the position of any dots that are constrained by this one
    432                 if (_constraints != null) {
    433                         for (Constraint c : _constraints) {
    434                                 Item other = c.getOppositeEnd(this);
    435 
    436                                 // only set the position if the other dot is still fixed to the
    437                                 // frame
    438                                 if (!other.isFloating()) {
    439                                         if (c.getConstraintType() == Constraint.HORIZONTAL
    440                                                         && other.getY() != getY())
    441                                                 other.setY(getY());
    442 
    443                                         if (c.getConstraintType() == Constraint.VERTICAL
    444                                                         && other.getX() != getX())
    445                                                 other.setX(getX());
    446                                 }
    447                         }
    448                 }
    449 
    450                 for (Line line : getLines())
    451                         line.updatePolygon();
    452         }
    453 
    454         public void setPosition(Point position) {
    455                 setPosition(position.x, position.y);
    456         }
    457 
    458         public Point getPosition() {
    459                 return new Point(getX(), getY());
    460         }
    461 
    462         /**
    463          * Sets the position of this Item on the X axis
    464          *
    465          * @param newX
    466          *            The position on the X axis to assign to this Item
    467          */
    468         public void setX(int newX) {
    469                 setPosition(newX, getY());
    470         }
    471 
    472         /**
    473          * Sets the position of this Item on the Y axis
    474          *
    475          * @param newY
    476          *            The position on the Y axis to assign to this Item
    477          */
    478         public void setY(int newY) {
    479                 setPosition(getX(), newY);
    480         }
    481 
    482         /**
    483          * Returns the name of a Frame that this Item links to, or null if this Item
    484          * has no link.
    485          *
    486          * @return The name of a Frame that this Item links to (if any) or null if
    487          *         this Item does not link to anything.
    488          */
    489         public String getLink() {
    490                 return _link;
    491         }
    492 
    493         public String getAbsoluteLink() {
    494                 if (_link == null)
    495                         return null;
    496                 assert (_parent!= null);
    497                 if (_parent == null)
    498                         return null;
    499 
    500                 // if its a relative link then return absolute
    501                 if (FrameIO.isPositiveInteger(_link)) {
    502                         return _parent.getFramesetNameAdjusted()
    503                                         + Conversion.getFrameNumber(_link);
    504                 }
    505                 return _link;
    506         }
    507 
    508         /**
    509          * Links this item to the given Frame, this may be set to null to remove a
    510          * link.
    511          *
    512          * @param frameName
    513          *            The name of the Frame to link this item to.
    514          */
    515         public void setLink(String frameName) {
    516                 _link = frameName;
    517         }
    518 
    519         /*
    520          * public void setLinkValid(boolean val) { _isValidLink = val; }
    521          */
    522 
    523         /**
    524          * Tests if the item link is a valid framename, that is, the String must
    525          * begin with a character, end with a number with 0 or more letters and
    526          * numbers in between. If there is a dot in the framename all the chars
    527          * after it must be digits.
    528          *
    529          * @return True if the given framename is proper, false otherwise.
    530          */
    531         public boolean isLinkValid() {
    532                 if (FrameIO.isPositiveInteger(getLink()))
    533                         return true;
    534 
    535                 if (FrameIO.isValidFrameName(getLink()))
    536                         return true;
    537                 return false;
    538         }
    539 
    540         public void setLinkFrameset(String frameset) {
    541                 _link_frameset = frameset;
    542         }
    543 
    544         public String getLinkFrameset() {
    545                 return _link_frameset;
    546         }
    547 
    548         public void setLinkTemplate(String template) {
    549                 _link_template = template;
    550         }
    551 
    552         public String getLinkTemplate() {
    553                 return _link_template;
    554         }
    555 
    556         /**
    557          * Adds an action to this Item.
    558          *
    559          * @param action
    560          *            The KMS action language to add to this Item
    561          */
    562         public void addAction(String action) {
    563                 if (action == null || action.equals("")) {
    564                         return;
    565                 }
    566 
    567                 if (_actions == null)
    568                         _actions = new LinkedList<String>();
    569                 _actions.add(action);
    570         }
    571 
    572         /**
    573          * Sets any action code (KMS action language) that should be associated with
    574          * this Item Each entry in the list is one line of code
    575          *
    576          * @param actions
    577          *            The lines of code to associate with this Item
    578          */
    579         public void setAction(List<String> actions) {
    580                 if (actions == null || actions.size() == 0)
    581                         _actions = null;
    582                 else
    583                         _actions = new LinkedList<String>(actions);
    584         }
    585 
    586         /**
    587          * Returns a list of any action code (KMS action language) that is currently
    588          * associated with this Item
    589          *
    590          * @return A List of action code associated with this Item, or null if none
    591          *         has been assigned.
    592          */
    593         public List<String> getAction() {
    594                 return _actions;
    595         }
    596 
    597         public String getFirstAction() {
    598                 if (_actions == null)
    599                         return null;
    600                 return _actions.getFirst();
    601         }
    602 
    603         /**
    604          * Displays this item directly on the screen. Note: All Items are
    605          * responsible for their own drawing, buffering, etc.
    606          *
    607          * @param g
    608          *            The Graphics to draw this Item on.
    609          */
    610         public abstract void paint(Graphics2D g);
    611 
    612         /**
    613          * Every Item has an area around it defined by a Shape (typically a
    614          * rectangle), this method returns true if the given x,y pair lies within
    615          * the area and false otherwise.
    616          *
    617          * @param x
    618          *            The x coordinate to check
    619          * @param y
    620          *            The y coordinate to check
    621          * @return True if the Shape around this Item contains the given x,y pair,
    622          *         false otherwise.
    623          */
    624         public boolean contains(int x, int y) {
    625                 return getPolygon().contains(x, y);
    626         }
    627 
    628         /**
    629          * Returns the Shape that surrounds this Item representing this Item's
    630          * 'gravity'.
    631          *
    632          * @return The Shape (rectangle) surrounding this Item, which represents
    633          *         this Items 'gravity'.
    634          */
    635         public abstract Polygon getPolygon();
    636 
    637         public Area getArea() {
    638                 return new Area(getPolygon());
    639         }
    640 
    641         protected abstract void updatePolygon();
    642 
    643         /**
    644          * Returns the height (in pixels) of this Item's surrounding area.
    645          *
    646          * @return The height (in pixels) of this Item's surrounding area as
    647          *         returned by getArea().
    648          */
    649         public int getBoundsHeight() {
    650                 return getPolygon().getBounds().height;
    651         }
    652 
    653         /**
    654          * Returns the width (in pixels) of this Item's surrounding area.
    655          *
    656          * @return The width (in pixels) of this Item's surrounding area as returned
    657          *         by getArea().
    658          */
    659         public int getBoundsWidth() {
    660                 return getPolygon().getBounds().width;
    661         }
    662 
    663         /**
    664          * Checks if the given Shape intersects with the Shape around this Item.
    665          * Note: Both Shape objects should be rectangles for this to work properly.
    666          *
    667          * @param s
    668          *            The Shape to check.
    669          * @return True if the two Shapes overlap, False otherwise.
    670          */
    671         public boolean intersects(Polygon p) {
    672                 if (p == null)
    673                         return false;
    674 
    675                 // return p.getBounds().intersects(getArea().getBounds());
    676                 Area a = new Area(p);
    677                 a.intersect(this.getArea());
    678                 return !a.isEmpty();
    679         }
    680 
    681         /**
    682          * Paints any highlighting of this Item. This may include changing the
    683          * thickness (lines) or painting a box around the item (Text, Images). If
    684          * val is True then the Graphics Color is changed to the highlight Color, if
    685          * False then the Graphics Color is left unchanged (for clearing of
    686          * highlighting).
    687          *
    688          * @param val
    689          *            True if this Item should be highlighted, false if the
    690          *            highlighting is being cleared.\
    691          * @return The desired mouse cursor when this Item is highlighted (negative
    692          *         means no change)
    693          */
    694         public int showHighlight(boolean val) {
    695                 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
    696                 return showHighlight(val, DEFAULT_HIGHLIGHT);
    697         }
    698 
    699         public int showDepressedHighlight(boolean val) {
    700                 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
    701                 return showHighlight(val, DEPRESSED_HIGHLIGHT);
    702         }
    703 
    704         public int showHighlight(boolean val, Color c) {
    705                 _isHighlighted = val;
    706                 if (c != null)
    707                         _highlightColor = c;
    708                 else
    709                         _highlightColor = DEFAULT_HIGHLIGHT;
    710 
    711                 return Item.UNCHANGED_CURSOR;
    712         }
    713 
    714         /**
    715          * Returns True if this Item is currently highlighted.
    716          *
    717          * @return True if this Item is currently highlighted on the screen, False
    718          *         otherwise.
    719          */
    720         public boolean isHighlighted() {
    721                 return _isHighlighted;
    722         }
    723 
    724         public Color getHighlightColor() {
    725                 return _highlightColor;
    726         }
    727 
    728         /**
    729          * Returns a deep copy of this Item, note: it is up to the receiver to
    730          * change the Item ID etc as necessary.
    731          *
    732          * @return A deep copy of this Item.
    733          */
    734         public abstract Item copy();
    735116
    736117        public static void DuplicateItem(Item source, Item dest) {
     
    777158                        dest.setID(source.getID());
    778159                }
     160        }
     161
     162        public static int getGravity() {
     163                return org.expeditee.gui.UserSettings.Gravity;
     164        }
     165
     166        public static boolean showLineHighlight() {
     167                return org.expeditee.gui.UserSettings.LineHighlight;
     168        }
     169       
     170        private Point _offset = new Point(0, 0);
     171
     172        private int _x;
     173
     174        private int _y;
     175
     176        private int _id;
     177
     178        private String _creationDate = null;
     179
     180        private boolean _linkMark = true;
     181
     182        private boolean _actionMark = true;
     183
     184        private boolean _highlight = true;
     185
     186        private boolean _isHighlighted = false;
     187
     188        private Dimension _maxSize = null;
     189
     190        private String _owner = null;
     191
     192        private String _link = null;
     193
     194        private StringBuffer _data = new StringBuffer();
     195
     196        private List<String> _actionCursorEnter = null;
     197
     198        private List<String> _actionCursorLeave = null;
     199
     200        private List<String> _actionEnterFrame = null;
     201
     202        private List<String> _actionLeaveFrame = null;
     203
     204        public int Permission = PERMISSION_FULL;
     205
     206        private Color _colorFill = null;
     207       
     208        private Color _color = null;
     209
     210        private Color _highlightColor = DEFAULT_HIGHLIGHT;
     211
     212        private Color _colorBackground = null;
     213
     214        private Color _colorTopShadow = null;
     215
     216        private Color _colorBottomShadow = null;
     217
     218        // the link\action circle
     219        private Polygon _circle = null;
     220
     221        // the invalid link cross
     222        private Polygon _circleCross = null;
     223
     224        private Frame _parent = null;
     225
     226        protected int _highlightThickness = 2;
     227
     228        // arrowhead parameters
     229        private int _arrowheadLength = 0;
     230
     231        private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO;
     232
     233        private Polygon _arrowhead = null;
     234
     235        // the list of lines that this point is part of.
     236        private List<Line> _lines = new ArrayList<Line>();
     237
     238        private int[] _linePattern = null;
     239
     240        private boolean _floating = false;
     241
     242        // list of points constrained with this point
     243        private List<Constraint> _constraints = null;
     244
     245        private LinkedList<String> _actions = null;
     246       
     247        private String _link_frameset = null;
     248
     249        private String _link_template = null;
     250
     251        private String _fillPattern = null;
     252       
     253        private boolean _visible = true;
     254
     255        protected Item() {
     256                _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm");
     257        }
     258
     259        /**
     260         * Adds an action to this Item.
     261         *
     262         * @param action
     263         *            The KMS action language to add to this Item
     264         */
     265        public void addAction(String action) {
     266                if (action == null || action.equals("")) {
     267                        return;
     268                }
     269
     270                if (_actions == null)
     271                        _actions = new LinkedList<String>();
     272                _actions.add(action);
     273        }
     274
     275        public void addAllConnected(List<Item> connected) {
     276                if (!connected.contains(this))
     277                        connected.add(this);
     278
     279                for (Line line : getLines()) {
     280                        if (!connected.contains(line))
     281                                line.addAllConnected(connected);
     282                }
     283        }
     284
     285        /**
     286         * Adds the given Constraint to this Dot
     287         *
     288         * @param c
     289         *            The Constraint to set this Dot as a member of.
     290         */
     291        public void addConstraint(Constraint c) {
     292                if (_constraints == null)
     293                        _constraints = new ArrayList<Constraint>();
     294
     295                // do not add duplicate constraint
     296                if (_constraints.contains(c))
     297                        return;
     298
     299                _constraints.add(c);
     300        }
     301
     302        /**
     303         * Adds a given line to the list of lines that this Point is an end for.
     304         *
     305         * @param line
     306         *            The Line that this Point is an end of.
     307         */
     308        public void addLine(Line line) {
     309                if (_lines.contains(line)) {
     310                        return;
     311                }
     312
     313                line.setColor(getColor());
     314                line.setSize(getSize());
     315                line.setLinePattern(getLinePattern());
     316
     317                _lines.add(line);
     318        }
     319
     320        /**
     321         * Items are sorted by their Y coordinate on the screen.
     322         *
     323         * @param i
     324         *            The Item to compare this Item to
     325         * @return a negative integer, zero, or a positive integer as this object is
     326         *         less than, equal to, or greater than the specified object.
     327         */
     328        public int compareTo(Item i) {
     329                return getY() - i.getY();
     330        }
     331
     332        /**
     333         * Every Item has an area around it defined by a Shape (typically a
     334         * rectangle), this method returns true if the given x,y pair lies within
     335         * the area and false otherwise.
     336         *
     337         * @param x
     338         *            The x coordinate to check
     339         * @param y
     340         *            The y coordinate to check
     341         * @return True if the Shape around this Item contains the given x,y pair,
     342         *         false otherwise.
     343         */
     344        public boolean contains(int x, int y) {
     345                return getPolygon().contains(x, y);
     346        }
     347
     348        /**
     349         * Returns a deep copy of this Item, note: it is up to the receiver to
     350         * change the Item ID etc as necessary.
     351         *
     352         * @return A deep copy of this Item.
     353         */
     354        public abstract Item copy();
     355
     356        public void delete() {
     357                setVisible(false);
     358        }
     359
     360        public boolean equals(Object o) {
     361                if (o instanceof Item) {
     362                        Item i = (Item) o;
     363                        return i.getID() == getID()
     364                                        && ((i.getParent() == _parent) || (i.getParent() != null && i
     365                                                        .getParent().equals(_parent)));
     366
     367                } else
     368                        return false;
     369        }
     370
     371        final public String getAbsoluteLink() {
     372                String link = getLink();
     373               
     374                if (link == null)
     375                        return null;
     376                //assert (_parent!= null);
     377                if (_parent == null){
     378                        //if parent is null it is an item on the message box
     379                        //so it must already be absolute
     380                        assert(!FrameIO.isPositiveInteger(link));
     381                        return link;
     382                }
     383
     384                // if its a relative link then return absolute
     385                if (FrameIO.isPositiveInteger(link)) {
     386                        return _parent.getFramesetNameAdjusted()
     387                                        + Conversion.getFrameNumber(link);
     388                }
     389                return link;
     390        }
     391
     392        /**
     393         * Returns a list of any action code (KMS action language) that is currently
     394         * associated with this Item
     395         *
     396         * @return A List of action code associated with this Item, or null if none
     397         *         has been assigned.
     398         */
     399        public List<String> getAction() {
     400                return _actions;
     401        }
     402
     403        public List<String> getActionCursorEnter() {
     404                return _actionCursorEnter;
     405        }
     406
     407        public List<String> getActionCursorLeave() {
     408                return _actionCursorLeave;
     409        }
     410
     411        public List<String> getActionEnterFrame() {
     412                return _actionEnterFrame;
     413        }
     414
     415        public List<String> getActionLeaveFrame() {
     416                return _actionLeaveFrame;
     417        };
     418
     419        public boolean getActionMark() {
     420                return _actionMark;
     421        }
     422
     423        public List<Item> getAllConnected() {
     424                List<Item> list = new LinkedList<Item>();
     425                addAllConnected(list);
     426                return list;
     427        }
     428
     429        public Area getArea() {
     430                return new Area(getPolygon());
     431        }
     432
     433        public String getArrow() {
     434                if (!hasVisibleArrow())
     435                        return null;
     436
     437                String ratio = "" + getArrowheadRatio();
     438                if (ratio.length() - ratio.indexOf(".") > 2)
     439                        ratio = ratio.substring(0, ratio.indexOf(".") + 3);
     440
     441                return getArrowheadLength() + " " + ratio;
     442        }
     443
     444        public Polygon getArrowhead() {
     445                return _arrowhead;
     446        }
     447
     448        public int getArrowheadLength() {
     449                return _arrowheadLength;
     450        }
     451
     452        public double getArrowheadRatio() {
     453                return _arrowheadRatio;
     454        }
     455
     456        public Color getBackgroundColor() {
     457                return _colorBackground;
     458        }
     459
     460        /**
     461         * Returns the Color being used to shade the bottom half of this Item's
     462         * border. This can be NULL if no Color is being used
     463         *
     464         * @return The Color displayed on the bottom\right half of this Item's
     465         *         border.
     466         */
     467        public Color getBottomShadowColor() {
     468                return _colorBottomShadow;
     469        }
     470
     471        /**
     472         * Returns the height (in pixels) of this Item's surrounding area.
     473         *
     474         * @return The height (in pixels) of this Item's surrounding area as
     475         *         returned by getArea().
     476         */
     477        public int getBoundsHeight() {
     478                return getPolygon().getBounds().height;
     479        }
     480
     481        /**
     482         * Returns the width (in pixels) of this Item's surrounding area.
     483         *
     484         * @return The width (in pixels) of this Item's surrounding area as returned
     485         *         by getArea().
     486         */
     487        public int getBoundsWidth() {
     488                return getPolygon().getBounds().width;
     489        }
     490
     491        protected Polygon getCircle() {
     492                if (_circle == null) {
     493                        int points = 16;
     494
     495                        double radians = 0.0;
     496                        int xPoints[] = new int[points];
     497                        int yPoints[] = new int[xPoints.length];
     498
     499                        for (int i = 0; i < xPoints.length; i++) {
     500                                // circle looks best if these values are not related to gravity
     501                                xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 *
     502                                // GRAVITY);
     503                                yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY;
     504                                radians += (2.0 * Math.PI) / xPoints.length;
     505                        }
     506
     507                        _circle = new Polygon(xPoints, yPoints, xPoints.length);
     508                }
     509
     510                return _circle;
     511        }
     512
     513        protected Polygon getCircleCross() {
     514
     515                if (_circleCross == null) {
     516                        _circleCross = new Polygon();
     517
     518                        Rectangle bounds = getCircle().getBounds();
     519                        int x1 = (int) bounds.getMinX();
     520                        int x2 = (int) bounds.getMaxX();
     521                        int y1 = (int) bounds.getMinY();
     522                        int y2 = (int) bounds.getMaxY();
     523                        int midX = ((x2 - x1) / 2) + x1;
     524                        int midY = ((y2 - y1) / 2) + y1;
     525
     526                        _circleCross.addPoint(x1, y1);
     527                        _circleCross.addPoint(x2, y2);
     528                        _circleCross.addPoint(midX, midY);
     529                        _circleCross.addPoint(x1, y2);
     530                        _circleCross.addPoint(x2, y1);
     531                        _circleCross.addPoint(midX, midY);
     532                }
     533
     534                return _circleCross;
     535        }
     536
     537        public Color getColor() {
     538                return _color;
     539        }
     540
     541        public List<Item> getConnected() {
     542                List<Item> conn = new LinkedList<Item>();
     543                conn.add(this);
     544
     545                conn.addAll(getLines());
     546                return conn;
     547        }
     548
     549        public String getConstraintIDs() {
     550                if (_constraints == null || _constraints.size() == 0)
     551                        return null;
     552
     553                String cons = "";
     554
     555                for (Constraint c : _constraints)
     556                        cons += c.getID() + " ";
     557
     558                return cons.trim();
     559        }
     560
     561        /*
     562         * public void setLinkValid(boolean val) { _isValidLink = val; }
     563         */
     564
     565        /**
     566         * Returns a List of any Constraints that this Dot is a memeber of.
     567         *
     568         * @return a List of Constraints that this Dot is a member of.
     569         */
     570        public List<Constraint> getConstraints() {
     571                return _constraints;
     572        }
     573
     574        public String getData() {
     575                if (_data != null && _data.length() > 0)
     576                        return _data.toString();
     577                return null;
     578        }
     579
     580        public String getDateCreated() {
     581                return _creationDate;
     582        }
     583
     584        public Color getFillColor() {
     585                return _colorFill;
     586        }
     587
     588        public String getFillPattern() {
     589                return _fillPattern;
     590        }
     591
     592        public String getFirstAction() {
     593                if (_actions == null)
     594                        return null;
     595                return _actions.getFirst();
     596        }
     597
     598        public boolean getHighlight() {
     599                return _highlight;
     600        }
     601
     602        public Color getHighlightColor() {
     603                return _highlightColor;
     604        }
     605
     606        /**
     607         * Returns the ID of this Item, which must be unique for the Frame.
     608         *
     609         * @return The ID of this Item.
     610         */
     611        public int getID() {
     612                return _id;
     613        }
     614
     615        /**
     616         * Returns the list of IDs of the Lines that this Dot is an end of.
     617         *
     618         * @return The list of Line IDs that this point is part of.
     619         */
     620        public String getLineIDs() {
     621                String lineID = null;
     622
     623                if (_lines.size() > 0) {
     624                        lineID = "" + _lines.get(0).getID();
     625
     626                        for (int i = 1; i < _lines.size(); i++)
     627                                lineID += " " + _lines.get(i).getID();
     628                }
     629
     630                return lineID;
     631        }
     632
     633        public int[] getLinePattern() {
     634                return _linePattern;
     635        }
     636
     637        /**
     638         * Returns a list of Lines where this Dot is an end.
     639         *
     640         * @return A list of the Lines that this Dot is an end for or null if no
     641         *         Lines have been added.
     642         */
     643        public List<Line> getLines() {
     644                return _lines;
     645        }
     646
     647        /**
     648         * Returns the name of a Frame that this Item links to, or null if this Item
     649         * has no link.
     650         *
     651         * @return The name of a Frame that this Item links to (if any) or null if
     652         *         this Item does not link to anything.
     653         */
     654        public String getLink() {
     655                return _link;
     656        }
     657
     658        public String getLinkFrameset() {
     659                return _link_frameset;
     660        }
     661
     662        public boolean getLinkMark() {
     663                return _linkMark;
     664        }
     665
     666        public String getLinkTemplate() {
     667                return _link_template;
     668        }
     669
     670        public Dimension getMaxSize() {
     671                return _maxSize;
     672        }
     673
     674        public Point getOffset() {
     675                return _offset;
     676        }
     677
     678        public String getOwner() {
     679                return _owner;
     680        }
     681       
     682        public Color getPaintBackgroundColor() {
     683                if (_colorBackground == null) {
     684                        if (getParent() != null && getParent().getBackgroundColor() != null)
     685                                return getParent().getBackgroundColor();
     686
     687                        return DEFAULT_BACKGROUND;
     688                }
     689
     690                return _colorBackground;
     691        }
     692
     693        /**
     694         * Returns the foreground Color of this Item.
     695         *
     696         * @return The Color of this item (foreground)
     697         */
     698        public Color getPaintColor() {
     699                if (_color == null) {
     700                        if (getParent() != null)
     701                                return getParent().getPaintForegroundColor();
     702
     703                        if (DisplayIO.getCurrentFrame() == null)
     704                                return DEFAULT_FOREGROUND;
     705
     706                        return DisplayIO.getCurrentFrame().getPaintForegroundColor();
     707                }
     708
     709                return _color;
     710        }
     711
     712        protected Color getPaintHighlightColor() {
     713                if (getParent() != null
     714                                && getParent().getPaintBackgroundColor()
     715                                                .equals(_highlightColor))
     716                        return getParent().getPaintForegroundColor();
     717
     718                return _highlightColor;
     719        }
     720
     721        public Frame getParent() {
     722                return _parent;
     723        }
     724
     725        /**
     726         * Returns the Shape that surrounds this Item representing this Item's
     727         * 'gravity'.
     728         *
     729         * @return The Shape (rectangle) surrounding this Item, which represents
     730         *         this Items 'gravity'.
     731         */
     732        public abstract Polygon getPolygon();
     733
     734        public Point getPosition() {
     735                return new Point(getX(), getY());
     736        }
     737
     738        /**
     739         * Returns the size of this Item. For Text this is the Font size, for Lines
     740         * and Dots this is the thickness.
     741         *
     742         * @return The size of this Item.
     743         */
     744        public abstract int getSize();
     745
     746        public float getThickness() {
     747                return 0;
     748        }
     749
     750        /**
     751         * Returns the Color being used to shade the top half of this Item's border.
     752         * This can be NULL if no Color is being used
     753         *
     754         * @return The Color displayed on the top\left half of this Item's border.
     755         */
     756        public Color getTopShadowColor() {
     757                return _colorTopShadow;
     758        }
     759
     760        public String getTypeAndID() {
     761                return "T " + getID();
     762        }
     763
     764        public int getWidth() {
     765                return 0;
     766        }
     767
     768        /**
     769         * Returns the X coordinate of this Item on the screen
     770         *
     771         * @return The X coordinate of this Item on the screen
     772         */
     773        public int getX() {
     774                return _x;
     775        }
     776
     777        /**
     778         * Returns the Y coordinate of this Item on the screen
     779         *
     780         * @return The Y coordinate of this Item on the screen
     781         */
     782        public int getY() {
     783                return _y;
     784        }
     785
     786        protected boolean hasVisibleArrow() {
     787                return false;
     788        }
     789
     790        /**
     791         * Checks if the given Shape intersects with the Shape around this Item.
     792         * Note: Both Shape objects should be rectangles for this to work properly.
     793         *
     794         * @param s
     795         *            The Shape to check.
     796         * @return True if the two Shapes overlap, False otherwise.
     797         */
     798        public boolean intersects(Polygon p) {
     799                if (p == null)
     800                        return false;
     801               
     802                // return p.getBounds().intersects(getArea().getBounds());
     803                Area a = new Area(p);
     804               
     805                a.intersect(this.getArea());
     806                return !a.isEmpty();
     807        }
     808
     809        /**
     810         * Note: Pictures always return False, as they should be drawn even when no
     811         * other annotation Items are.
     812         *
     813         * @return True if this Item is an annotation, False otherwise.
     814         */
     815        public abstract boolean isAnnotation();
     816
     817        public boolean isFloating() {
     818                return _floating;
     819        }
     820
     821        public boolean isFrameName() {
     822                if (this.getParent() == null || this.getParent().getFrameNameItem() != this)
     823                        return false;
     824                return true;
     825        }
     826
     827        public boolean isFrameTitle() {
     828                if (this.getParent() == null || this.getParent().getTitle() != this)
     829                        return false;
     830                return true;
     831        }
     832
     833        /**
     834         * Returns True if this Item is currently highlighted.
     835         *
     836         * @return True if this Item is currently highlighted on the screen, False
     837         *         otherwise.
     838         */
     839        public boolean isHighlighted() {
     840                return _isHighlighted;
     841        }
     842
     843        /**
     844         * Tests if the item link is a valid framename, that is, the String must
     845         * begin with a character, end with a number with 0 or more letters and
     846         * numbers in between. If there is a dot in the framename all the chars
     847         * after it must be digits.
     848         *
     849         * @return True if the given framename is proper, false otherwise.
     850         */
     851        public boolean isLinkValid() {
     852                if (FrameIO.isPositiveInteger(getLink()))
     853                        return true;
     854
     855                if (FrameIO.isValidFrameName(getLink()))
     856                        return true;
     857                return false;
     858        }
     859
     860        public boolean isNear(int x, int y) {
     861               
     862               
     863                int xLeft = getPolygon().getBounds().x;
     864                int yTop = getPolygon().getBounds().y;
     865               
     866                return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE
     867                                && x < xLeft + getBoundsWidth() + NEAR_DISTANCE
     868                                && y < yTop + getBoundsHeight() + NEAR_DISTANCE);
     869        }
     870
     871        /**
     872         * Checks if this item is a frame title.
     873         *
     874         * @return true if the item is a frame title
     875         */
     876        /*
     877         * public boolean isTitle() { // check if the title has been assigned if
     878         * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() <
     879         * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; }
     880         */
     881
     882        public boolean isOldTag() {
     883                if (this instanceof Text)
     884                        if (((Text) this).getText().get(0).toLowerCase().equals("@old"))
     885                                return true;
     886                return false;
    779887        }
    780888
     
    797905
    798906        /**
    799          * Sets the maximum coordinates on the screen that this item may occupy.
    800          * This is used by Text items to compute word-wrapping lengths.
    801          *
    802          * @param d
    803          *            The Maximum size of the Frame containing this Item.
    804          */
    805         public void setMaxSize(Dimension d) {
    806                 if (d != null) {
    807                         _maxSize = d;
    808                         updatePolygon();
    809                 }
    810         }
    811 
    812         public Dimension getMaxSize() {
    813                 return _maxSize;
    814         }
    815 
    816         public Color getColor() {
    817                 return _color;
    818         }
    819 
    820         /**
    821          * Returns the foreground Color of this Item.
    822          *
    823          * @return The Color of this item (foreground)
    824          */
    825         public Color getPaintColor() {
    826                 if (_color == null) {
    827                         if (getParent() != null)
    828                                 return getParent().getPaintForegroundColor();
    829 
    830                         if (DisplayIO.getCurrentFrame() == null)
    831                                 return DEFAULT_FOREGROUND;
    832 
    833                         return DisplayIO.getCurrentFrame().getPaintForegroundColor();
    834                 }
    835 
    836                 return _color;
    837         }
    838 
    839         protected Color getPaintHighlightColor() {
    840                 if (getParent() != null
    841                                 && getParent().getPaintBackgroundColor()
    842                                                 .equals(_highlightColor))
    843                         return getParent().getPaintForegroundColor();
    844 
    845                 return _highlightColor;
     907         * Displays this item directly on the screen. Note: All Items are
     908         * responsible for their own drawing, buffering, etc.
     909         *
     910         * @param g
     911         *            The Graphics to draw this Item on.
     912         */
     913        public abstract void paint(Graphics2D g);
     914
     915        /**
     916         * This method performs all the actions in an items list. If it contains a
     917         * link as well the link is used as the source frame for all acitons.
     918         */
     919        public void performActions() {
     920                Frame sourceFrame = null;
     921                // if a link exists make it the source frame for this action
     922                if (getLink() != null) {
     923                        sourceFrame = FrameUtils.getFrame(getLink());
     924                }
     925                // if no link exists or the link is bad then use the
     926                // currently displayed frame as the source frame for the
     927                // action
     928                if (sourceFrame == null) {
     929                        sourceFrame = DisplayIO.getCurrentFrame();
     930                }
     931
     932                for (String s : getAction()) {
     933                        Actions.PerformAction(sourceFrame, this, s);
     934                }
     935        }
     936
     937        public void removeAllConstraints() {
     938                if (_constraints != null)
     939                        _constraints.clear();
     940        }
     941
     942        /**
     943         * Clears the list of Lines that this Dot is an end of. Note: This only
     944         * clears this Dot's list and does not have any affect on the Lines or other
     945         * Dots.
     946         */
     947        public void removeAllLines() {
     948                _lines.clear();
     949        }
     950
     951        /**
     952         * Removes the given Constraint from the list of constraintss that this Dot
     953         * is a part of.
     954         *
     955         * @param c
     956         *            The Constraint that this Dot is no longer a part of.
     957         */
     958        public void removeConstraint(Constraint c) {
     959                _constraints.remove(c);
     960        }
     961
     962        /**
     963         * Removes the given Line from the list of lines that this Dot is an end
     964         * for.
     965         *
     966         * @param line
     967         *            The Line that this Dot is no longer an end of.
     968         */
     969        public void removeLine(Line line) {
     970                _lines.remove(line);
     971        }
     972
     973        public void run() {
     974                try {
     975                        AgentStats.reset();
     976                        FrameGraphics
     977                                        .DisplayMessage("Running SimpleProgram...", Color.BLUE);
     978                        Simple.RunFrameAndReportError(this, new Context());
     979                        Simple.ProgramFinished();
     980                        FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN);
     981                } catch (ConcurrentModificationException ce) {
     982                        ce.printStackTrace();
     983                } catch (Exception e) {
     984                        FrameGraphics.LinkedErrorMessage(e.getMessage());
     985                        Simple.ProgramFinished();
     986                }
     987        }
     988
     989        /**
     990         * Check if it has a relative link if so make it absolute.
     991         *
     992         */
     993        public void setAbsoluteLink() {
     994                if (_link == null)
     995                        return;
     996                // Check if all the characters are digits and hence it is a relative
     997                // link
     998                for (int i = 0; i < _link.length(); i++) {
     999                        if (!Character.isDigit(_link.charAt(i)))
     1000                                return;
     1001                }
     1002
     1003                // Make it an absolute link
     1004                String framesetName;
     1005
     1006                if (_parent == null)
     1007                        framesetName = DisplayIO.getCurrentFrame()
     1008                                        .getFramesetNameAdjusted();
     1009                else
     1010                        framesetName = _parent.getFramesetNameAdjusted();
     1011
     1012                _link = framesetName + _link;
     1013        }
     1014
     1015        /**
     1016         * Sets any action code (KMS action language) that should be associated with
     1017         * this Item Each entry in the list is one line of code
     1018         *
     1019         * @param actions
     1020         *            The lines of code to associate with this Item
     1021         */
     1022        public void setAction(List<String> actions) {
     1023                if (actions == null || actions.size() == 0)
     1024                        _actions = null;
     1025                else
     1026                        _actions = new LinkedList<String>(actions);
     1027        }
     1028
     1029        public void setActionCursorEnter(List<String> enter) {
     1030                _actionCursorEnter = enter;
     1031        }
     1032
     1033        public void setActionCursorLeave(List<String> leave) {
     1034                _actionCursorLeave = leave;
     1035        }
     1036
     1037        public void setActionEnterFrame(List<String> enter) {
     1038                _actionEnterFrame = enter;
     1039        }
     1040
     1041        public void setActionLeaveFrame(List<String> leave) {
     1042                _actionLeaveFrame = leave;
     1043        }
     1044
     1045        public void setActionMark(boolean val) {
     1046                _actionMark = val;
     1047        }
     1048
     1049        /**
     1050         * Sets whether this Item is an Annotation.
     1051         *
     1052         * @param val
     1053         *            True if this Item is an Annotation, False otherwise.
     1054         */
     1055        public abstract void setAnnotation(boolean val);
     1056
     1057        /**
     1058         * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is
     1059         * shown.
     1060         *
     1061         * @param length
     1062         *            The how far down the shaft of the line the arrowhead should
     1063         *            come.
     1064         * @param ratio
     1065         *            The ratio of the arrow's length to its width.
     1066         */
     1067        public void setArrow(int length, double ratio) {
     1068                _arrowheadLength = length;
     1069                _arrowheadRatio = ratio;
     1070                updateArrowPolygon();
     1071        }
     1072
     1073        public void setArrowhead(Polygon arrow) {
     1074                _arrowhead = arrow;
     1075        }
     1076
     1077        public void setArrowheadLength(int length) {
     1078                _arrowheadLength = length;
     1079                updateArrowPolygon();
     1080        }
     1081
     1082        public void setArrowheadRatio(double ratio) {
     1083                _arrowheadRatio = ratio;
     1084                updateArrowPolygon();
     1085        }
     1086
     1087        public void setBackgroundColor(Color c) {
     1088                _colorBackground = c;
     1089        }
     1090
     1091        /**
     1092         * Sets the Color to use on the bottom and right sections of this Item's
     1093         * border. If top is NULL, then the Item's background Color will be used.
     1094         *
     1095         * @param top
     1096         *            The Color to display in the bottom and right sections of this
     1097         *            Item's border.
     1098         */
     1099        public void setBottomShadowColor(Color bottom) {
     1100                _colorBottomShadow = bottom;
    8461101        }
    8471102
     
    8591114        }
    8601115
    861         /**
    862          * Returns the Color being used to shade the top half of this Item's border.
    863          * This can be NULL if no Color is being used
    864          *
    865          * @return The Color displayed on the top\left half of this Item's border.
    866          */
    867         public Color getTopShadowColor() {
    868                 return _colorTopShadow;
    869         }
    870 
    871         /**
    872          * Sets the Color to use on the top and left sections of this Item's border.
    873          * If top is NULL, then the Item's background Color will be used.
    874          *
    875          * @param top
    876          *            The Color to display in the top and left sections of this
    877          *            Item's border.
    878          */
    879         public void setTopShadowColor(Color top) {
    880                 _colorTopShadow = top;
    881         }
    882 
    883         /**
    884          * Returns the Color being used to shade the bottom half of this Item's
    885          * border. This can be NULL if no Color is being used
    886          *
    887          * @return The Color displayed on the bottom\right half of this Item's
    888          *         border.
    889          */
    890         public Color getBottomShadowColor() {
    891                 return _colorBottomShadow;
    892         }
    893 
    894         /**
    895          * Sets the Color to use on the bottom and right sections of this Item's
    896          * border. If top is NULL, then the Item's background Color will be used.
    897          *
    898          * @param top
    899          *            The Color to display in the bottom and right sections of this
    900          *            Item's border.
    901          */
    902         public void setBottomShadowColor(Color bottom) {
    903                 _colorBottomShadow = bottom;
    904         }
    905 
    906         protected Polygon getCircle() {
    907                 if (_circle == null) {
    908                         int points = 16;
    909 
    910                         double radians = 0.0;
    911                         int xPoints[] = new int[points];
    912                         int yPoints[] = new int[xPoints.length];
    913 
    914                         for (int i = 0; i < xPoints.length; i++) {
    915                                 // circle looks best if these values are not related to gravity
    916                                 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 *
    917                                 // GRAVITY);
    918                                 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY;
    919                                 radians += (2.0 * Math.PI) / xPoints.length;
    920                         }
    921 
    922                         _circle = new Polygon(xPoints, yPoints, xPoints.length);
    923                 }
    924 
    925                 return _circle;
    926         }
    927 
    928         protected Polygon getCircleCross() {
    929 
    930                 if (_circleCross == null) {
    931                         _circleCross = new Polygon();
    932 
    933                         Rectangle bounds = getCircle().getBounds();
    934                         int x1 = (int) bounds.getMinX();
    935                         int x2 = (int) bounds.getMaxX();
    936                         int y1 = (int) bounds.getMinY();
    937                         int y2 = (int) bounds.getMaxY();
    938                         int midX = ((x2 - x1) / 2) + x1;
    939                         int midY = ((y2 - y1) / 2) + y1;
    940 
    941                         _circleCross.addPoint(x1, y1);
    942                         _circleCross.addPoint(x2, y2);
    943                         _circleCross.addPoint(midX, midY);
    944                         _circleCross.addPoint(x1, y2);
    945                         _circleCross.addPoint(x2, y1);
    946                         _circleCross.addPoint(midX, midY);
    947                 }
    948 
    949                 return _circleCross;
    950         }
    951 
    952         public void setFillColor(Color c) {
    953                 _colorFill = c;
    954 
    955                 for (Line line : _lines) {
    956                         Item other = line.getOppositeEnd(this);
    957                         if (other.getFillColor() != c)
    958                                 other.setFillColor(c);
    959                 }
    960         }
    961 
    962         public void setBackgroundColor(Color c) {
    963                 _colorBackground = c;
    964         }
    965 
    966         public Color getBackgroundColor() {
    967                 return _colorBackground;
    968         }
    969 
    970         public Color getPaintBackgroundColor() {
    971                 if (_colorBackground == null) {
    972                         if (getParent() != null && getParent().getBackgroundColor() != null)
    973                                 return getParent().getBackgroundColor();
    974 
    975                         return DEFAULT_BACKGROUND;
    976                 }
    977 
    978                 return _colorBackground;
    979         }
    980 
    981         public Color getFillColor() {
    982                 return _colorFill;
    983         }
    984 
    985         /**
    986          * Returns the size of this Item. For Text this is the Font size, for Lines
    987          * and Dots this is the thickness.
    988          *
    989          * @return The size of this Item.
    990          */
    991         public abstract int getSize();
    992 
    993         /**
    994          * Sets the size of this Item. For Text this is the Font size. For Lines and
    995          * Dots this is the thickness.
    996          */
    997         public abstract void setSize(int size);
    998 
    999         /**
    1000          * Sets whether this Item is an Annotation.
    1001          *
    1002          * @param val
    1003          *            True if this Item is an Annotation, False otherwise.
    1004          */
    1005         public abstract void setAnnotation(boolean val);
    1006 
    1007         /**
    1008          * Note: Pictures always return False, as they should be drawn even when no
    1009          * other annotation Items are.
    1010          *
    1011          * @return True if this Item is an annotation, False otherwise.
    1012          */
    1013         public abstract boolean isAnnotation();
    1014 
    1015         public List<Item> getConnected() {
    1016                 List<Item> conn = new LinkedList<Item>();
    1017                 conn.add(this);
    1018 
    1019                 conn.addAll(getLines());
    1020                 return conn;
    1021         }
    1022 
    1023         public List<Item> getAllConnected() {
    1024                 List<Item> list = new LinkedList<Item>();
    1025                 addAllConnected(list);
    1026                 return list;
    1027         }
    1028 
    1029         public void addAllConnected(List<Item> connected) {
    1030                 if (!connected.contains(this))
    1031                         connected.add(this);
    1032 
    1033                 for (Line line : getLines()) {
    1034                         if (!connected.contains(line))
    1035                                 line.addAllConnected(connected);
    1036                 }
    1037         }
    1038 
    1039         public void setOffset(Point p) {
    1040                 _offset.setLocation(p);
    1041         }
    1042 
    1043         public void setOffset(int x, int y) {
    1044                 _offset.setLocation(x, y);
    1045         }
    1046 
    1047         public Point getOffset() {
    1048                 return _offset;
    1049         }
    1050 
    1051         public void setParent(Frame frame) {
    1052                 _parent = frame;
    1053         }
    1054 
    1055         public Frame getParent() {
    1056                 return _parent;
    1057         }
    1058 
    1059         public void setActionMark(boolean val) {
    1060                 _actionMark = val;
    1061         }
    1062 
    1063         public boolean getActionMark() {
    1064                 return _actionMark;
    1065         }
    1066 
    1067         public void setLinkMark(boolean val) {
    1068                 _linkMark = val;
    1069         }
    1070 
    1071         public boolean getLinkMark() {
    1072                 return _linkMark;
    1073         }
    1074 
    1075         public void setOwner(String own) {
    1076                 _owner = own;
    1077         }
    1078 
    1079         public String getOwner() {
    1080                 return _owner;
    1081         }
    1082 
    1083         public void setHighlight(boolean val) {
    1084                 _highlight = val;
    1085         }
    1086 
    1087         public boolean getHighlight() {
    1088                 return _highlight;
    1089         }
    1090 
    1091         public String getData() {
    1092                 if (_data != null && _data.length() > 0)
    1093                         return _data.toString();
    1094                 return null;
     1116        public void setConstraintIDs(String IDs) {
     1117        }
     1118
     1119        public void setConstraints(List<Constraint> constraints) {
     1120                _constraints = constraints;
    10951121        }
    10961122
     
    11021128        }
    11031129
    1104         public List<String> getActionCursorEnter() {
    1105                 return _actionCursorEnter;
    1106         }
    1107 
    1108         public void setActionCursorEnter(List<String> enter) {
    1109                 _actionCursorEnter = enter;
    1110         }
    1111 
    1112         public List<String> getActionCursorLeave() {
    1113                 return _actionCursorLeave;
    1114         }
    1115 
    1116         public void setActionCursorLeave(List<String> leave) {
    1117                 _actionCursorLeave = leave;
    1118         }
    1119 
    1120         public List<String> getActionEnterFrame() {
    1121                 return _actionEnterFrame;
    1122         }
    1123 
    1124         public void setActionEnterFrame(List<String> enter) {
    1125                 _actionEnterFrame = enter;
    1126         }
    1127 
    1128         public List<String> getActionLeaveFrame() {
    1129                 return _actionLeaveFrame;
    1130         }
    1131 
    1132         public void setActionLeaveFrame(List<String> leave) {
    1133                 _actionLeaveFrame = leave;
     1130        /**
     1131         * Sets the created date of this Frame to the given String.
     1132         *
     1133         * @param date
     1134         *            The date to use for this Frame.
     1135         */
     1136        public void setDateCreated(String date) {
     1137                _creationDate = date;
     1138        }
     1139
     1140        public void setFillColor(Color c) {
     1141                _colorFill = c;
     1142
     1143                for (Line line : _lines) {
     1144                        Item other = line.getOppositeEnd(this);
     1145                        if (other.getFillColor() != c)
     1146                                other.setFillColor(c);
     1147                }
     1148        }
     1149
     1150        public void setFilledHighlight(boolean value) {
    11341151        }
    11351152
     
    11381155        }
    11391156
    1140         public String getFillPattern() {
    1141                 return _fillPattern;
    1142         }
    1143 
    1144         /**
    1145          * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is
    1146          * shown.
    1147          *
    1148          * @param length
    1149          *            The how far down the shaft of the line the arrowhead should
    1150          *            come.
    1151          * @param ratio
    1152          *            The ratio of the arrow's length to its width.
    1153          */
    1154         public void setArrow(int length, double ratio) {
    1155                 _arrowheadLength = length;
    1156                 _arrowheadRatio = ratio;
    1157                 updateArrowPolygon();
    1158         }
    1159 
    1160         public int getArrowheadLength() {
    1161                 return _arrowheadLength;
    1162         }
    1163 
    1164         public double getArrowheadRatio() {
    1165                 return _arrowheadRatio;
    1166         }
    1167 
    1168         public void setArrowheadLength(int length) {
    1169                 _arrowheadLength = length;
    1170                 updateArrowPolygon();
    1171         }
    1172 
    1173         public void setArrowheadRatio(double ratio) {
    1174                 _arrowheadRatio = ratio;
    1175                 updateArrowPolygon();
    1176         }
    1177 
     1157        public void setFloating(boolean val) {
     1158                _floating = val;
     1159        }
     1160
     1161        public void setHighlight(boolean val) {
     1162                _highlight = val;
     1163        }
     1164
     1165        /**
     1166         * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0
     1167         * are not saved
     1168         *
     1169         * @param newID
     1170         *            The new ID to assign this Item.
     1171         */
     1172        public void setID(int newID) {
     1173                _id = newID;
     1174        }
     1175
     1176        /**
     1177         * Sets the list of lines that this point is part of (may be set to null).
     1178         *
     1179         * @param lineID
     1180         *            A String of line ID numbers separated by spaces.
     1181         */
     1182        public void setLineIDs(String lineID) {
     1183        }
     1184
     1185        public void setLinePattern(int[] pattern) {
     1186                _linePattern = pattern;
     1187
     1188                for (Line line : getLines())
     1189                        line.setLinePattern(pattern);
     1190        }
     1191
     1192        public void setLines(List<Line> lines) {
     1193                _lines = lines;
     1194
     1195                for (Line line : lines)
     1196                        line.setLinePattern(getLinePattern());
     1197        }
     1198
     1199        /**
     1200         * Links this item to the given Frame, this may be set to null to remove a
     1201         * link.
     1202         *
     1203         * @param frameName
     1204         *            The name of the Frame to link this item to.
     1205         */
     1206        public void setLink(String frameName) {
     1207                _link = frameName;
     1208        }
     1209
     1210        public void setLinkFrameset(String frameset) {
     1211                _link_frameset = frameset;
     1212        }
     1213
     1214        public void setLinkMark(boolean val) {
     1215                _linkMark = val;
     1216        }
     1217
     1218        public void setLinkTemplate(String template) {
     1219                _link_template = template;
     1220        }
     1221
     1222        /**
     1223         * Sets the maximum coordinates on the screen that this item may occupy.
     1224         * This is used by Text items to compute word-wrapping lengths.
     1225         *
     1226         * @param d
     1227         *            The Maximum size of the Frame containing this Item.
     1228         */
     1229        public void setMaxSize(Dimension d) {
     1230                if (d != null) {
     1231                        _maxSize = d;
     1232                        updatePolygon();
     1233                }
     1234        }
     1235
     1236        public void setOffset(int x, int y) {
     1237                _offset.setLocation(x, y);
     1238        }
     1239
     1240        public void setOffset(Point p) {
     1241                _offset.setLocation(p);
     1242        }
     1243
     1244        public void setOwner(String own) {
     1245                _owner = own;
     1246        }
     1247
     1248        public void setParent(Frame frame) {
     1249                _parent = frame;
     1250        }
     1251
     1252        /**
     1253         * Sets the position of this item on the screen
     1254         *
     1255         * @param x
     1256         *            The new X coordinate
     1257         * @param y
     1258         *            The new Y coordinate
     1259         */
     1260        public void setPosition(int x, int y) {
     1261                _x = x;
     1262                _y = y;
     1263
     1264                updatePolygon();
     1265
     1266                // update the position of any dots that are constrained by this one
     1267                if (_constraints != null) {
     1268                        for (Constraint c : _constraints) {
     1269                                Item other = c.getOppositeEnd(this);
     1270
     1271                                // only set the position if the other dot is still fixed to the
     1272                                // frame
     1273                                if (!other.isFloating()) {
     1274                                        if (c.getConstraintType() == Constraint.HORIZONTAL
     1275                                                        && other.getY() != getY())
     1276                                                other.setY(getY());
     1277
     1278                                        if (c.getConstraintType() == Constraint.VERTICAL
     1279                                                        && other.getX() != getX())
     1280                                                other.setX(getX());
     1281                                }
     1282                        }
     1283                }
     1284
     1285                for (Line line : getLines())
     1286                        line.updatePolygon();
     1287        }
     1288
     1289        public void setPosition(Point position) {
     1290                setPosition(position.x, position.y);
     1291        }
     1292
     1293        public void setRelativeLink() {
     1294                if (_link == null)
     1295                        return;
     1296                assert (_parent != null);
     1297                // Check if the link is for the current frameset
     1298                if (_parent.getFramesetName().equalsIgnoreCase(
     1299                                Conversion.getFrameset(_link))) {
     1300                        _link = "" + Conversion.getFrameNumber(_link);
     1301                }
     1302        }
     1303
     1304        /**
     1305         * Sets the size of this Item. For Text this is the Font size. For Lines and
     1306         * Dots this is the thickness.
     1307         */
     1308        public abstract void setSize(int size);
     1309
     1310        public void setThickness(float thick) throws UnsupportedOperationException {
     1311                throw new UnsupportedOperationException(
     1312                                "Item type does not support thickness attribute!");
     1313        }
     1314
     1315        /**
     1316         * Sets the Color to use on the top and left sections of this Item's border.
     1317         * If top is NULL, then the Item's background Color will be used.
     1318         *
     1319         * @param top
     1320         *            The Color to display in the top and left sections of this
     1321         *            Item's border.
     1322         */
     1323        public void setTopShadowColor(Color top) {
     1324                _colorTopShadow = top;
     1325        }
     1326
     1327        public void setWidth(int width) throws UnsupportedOperationException {
     1328                throw new UnsupportedOperationException(
     1329                                "Item type does not support width attribute!");
     1330        }
     1331
     1332        /**
     1333         * Sets the position of this Item on the X axis
     1334         *
     1335         * @param newX
     1336         *            The position on the X axis to assign to this Item
     1337         */
     1338        public void setX(int newX) {
     1339                setPosition(newX, getY());
     1340        }
     1341
     1342        /**
     1343         * Sets the position of this Item on the Y axis
     1344         *
     1345         * @param newY
     1346         *            The position on the Y axis to assign to this Item
     1347         */
     1348        public void setY(int newY) {
     1349                setPosition(getX(), newY);
     1350        }
     1351
     1352        public int showDepressedHighlight(boolean val) {
     1353                _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
     1354                return showHighlight(val, DEPRESSED_HIGHLIGHT);
     1355        }
     1356
     1357        public int showDisconnectHighlight(boolean val) {
     1358                _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
     1359                return showHighlight(val, DISCONNECT_HIGHLIGHT);
     1360        }
     1361
     1362        /**
     1363         * Paints any highlighting of this Item. This may include changing the
     1364         * thickness (lines) or painting a box around the item (Text, Images). If
     1365         * val is True then the Graphics Color is changed to the highlight Color, if
     1366         * False then the Graphics Color is left unchanged (for clearing of
     1367         * highlighting).
     1368         *
     1369         * @param val
     1370         *            True if this Item should be highlighted, false if the
     1371         *            highlighting is being cleared.\
     1372         * @return The desired mouse cursor when this Item is highlighted (negative
     1373         *         means no change)
     1374         */
     1375        public int showHighlight(boolean val) {
     1376                _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;
     1377                return showHighlight(val, DEFAULT_HIGHLIGHT);
     1378        }
     1379
     1380        public int showHighlight(boolean val, Color c) {
     1381                _isHighlighted = val;
     1382                if (c != null)
     1383                        _highlightColor = c;
     1384                else
     1385                        _highlightColor = DEFAULT_HIGHLIGHT;
     1386
     1387                return Item.UNCHANGED_CURSOR;
     1388        }
    11781389        private void updateArrowPolygon() {
    11791390                if (getArrowheadLength() < 0 || getArrowheadRatio() < 0)
     
    11931404                }
    11941405        }
    1195 
    1196         protected boolean hasVisibleArrow() {
    1197                 return false;
    1198         }
    1199 
    1200         public String getArrow() {
    1201                 if (!hasVisibleArrow())
    1202                         return null;
    1203 
    1204                 String ratio = "" + getArrowheadRatio();
    1205                 if (ratio.length() - ratio.indexOf(".") > 2)
    1206                         ratio = ratio.substring(0, ratio.indexOf(".") + 3);
    1207 
    1208                 return getArrowheadLength() + " " + ratio;
    1209         }
    1210 
    1211         public Polygon getArrowhead() {
    1212                 return _arrowhead;
    1213         }
    1214 
    1215         public void setArrowhead(Polygon arrow) {
    1216                 _arrowhead = arrow;
    1217         }
    1218 
    1219         /**
    1220          * This method performs all the actions in an items list. If it contains a
    1221          * link as well the link is used as the source frame for all acitons.
    1222          */
    1223         public void performActions() {
    1224                 Frame sourceFrame = null;
    1225                 // if a link exists make it the source frame for this action
    1226                 if (getLink() != null) {
    1227                         sourceFrame = FrameUtils.getFrame(getLink());
    1228                 }
    1229                 // if no link exists or the link is bad then use the
    1230                 // currently displayed frame as the source frame for the
    1231                 // action
    1232                 if (sourceFrame == null) {
    1233                         sourceFrame = DisplayIO.getCurrentFrame();
    1234                 }
    1235 
    1236                 for (String s : getAction()) {
    1237                         Actions.PerformAction(sourceFrame, this, s);
    1238                 }
    1239         }
    1240 
    1241         /**
    1242          * Checks if this item is a frame title.
    1243          *
    1244          * @return true if the item is a frame title
    1245          */
    1246         /*
    1247          * public boolean isTitle() { // check if the title has been assigned if
    1248          * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() <
    1249          * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; }
    1250          */
    1251 
    1252         public boolean isOldTag() {
    1253                 if (this instanceof Text)
    1254                         if (((Text) this).getText().get(0).toLowerCase().equals("@old"))
    1255                                 return true;
    1256                 return false;
    1257         }
    1258 
    1259         public boolean isFrameName() {
    1260                 if (this.getParent() == null || this.getParent().getName() != this)
    1261                         return false;
    1262                 return true;
    1263         }
    1264 
    1265         public boolean isFrameTitle() {
    1266                 if (this.getParent() == null || this.getParent().getTitle() != this)
    1267                         return false;
    1268                 return true;
    1269         }
    1270 
    1271         /**
    1272          * Sets the created date of this Frame to the given String.
    1273          *
    1274          * @param date
    1275          *            The date to use for this Frame.
    1276          */
    1277         public void setDateCreated(String date) {
    1278                 _creationDate = date;
    1279         }
    1280 
    1281         public String getDateCreated() {
    1282                 return _creationDate;
    1283         }
    1284 
    1285         public float getThickness() {
    1286                 return 0;
    1287         }
    1288 
    1289         public void setThickness(float thick) throws UnsupportedOperationException {
    1290                 throw new UnsupportedOperationException(
    1291                                 "Item type does not support thickness attribute!");
    1292         }
    1293 
    1294         public void setWidth(int width) throws UnsupportedOperationException {
    1295                 throw new UnsupportedOperationException(
    1296                                 "Item type does not support width attribute!");
    1297         }
    1298 
    1299         public int getWidth() {
    1300                 return 0;
    1301         }
    1302 
    1303         public void run() {
    1304                 try {
    1305                         AgentStats.reset();
    1306                         FrameGraphics
    1307                                         .DisplayMessage("Running SimpleProgram...", Color.BLUE);
    1308                         Simple.RunFrameAndReportError(this, new Context());
    1309                         Simple.ProgramFinished();
    1310                         FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN);
    1311                 } catch (ConcurrentModificationException ce) {
    1312                         ce.printStackTrace();
    1313                 } catch (Exception e) {
    1314                         FrameGraphics.LinkedErrorMessage(e.getMessage());
    1315                         Simple.ProgramFinished();
    1316                 }
    1317         }
    1318 
    1319         public String getTypeAndID() {
    1320                 return "T " + getID();
    1321         }
    1322 
    1323         /**
    1324          * Check if it has a relative link if so make it absolute.
    1325          *
    1326          */
    1327         public void setAbsoluteLink() {
    1328                 if (_link == null)
    1329                         return;
    1330                 // Check if all the characters are digits and hence it is a relative
    1331                 // link
    1332                 for (int i = 0; i < _link.length(); i++) {
    1333                         if (!Character.isDigit(_link.charAt(i)))
    1334                                 return;
    1335                 }
    1336 
    1337                 // Make it an absolute link
    1338                 String framesetName;
    1339 
    1340                 if (_parent == null)
    1341                         framesetName = DisplayIO.getCurrentFrame()
    1342                                         .getFramesetNameAdjusted();
    1343                 else
    1344                         framesetName = _parent.getFramesetNameAdjusted();
    1345 
    1346                 _link = framesetName + _link;
    1347         }
    1348 
    1349         public void setRelativeLink() {
    1350                 if (_link == null)
    1351                         return;
    1352                 assert (_parent != null);
    1353                 // Check if the link is for the current frameset
    1354                 if (_parent.getFramesetName().equalsIgnoreCase(
    1355                                 Conversion.getFrameset(_link))) {
    1356                         _link = "" + Conversion.getFrameNumber(_link);
    1357                 }
     1406       
     1407        protected abstract void updatePolygon();
     1408
     1409        public void setVisible(boolean state) {
     1410                this._visible = state;
     1411        }
     1412
     1413        public boolean isVisible() {
     1414                return _visible;
    13581415        }
    13591416}
  • trunk/src/org/expeditee/items/ItemUtils.java

    r4 r7  
    1616
    1717import org.expeditee.gui.DisplayIO;
     18import org.expeditee.gui.Frame;
    1819
    1920//Static methods that provide functions for the objects\
     
    402403         */
    403404        public static List<Item> CopyItems(List<Item> toCopy) {
     405                return CopyItems(toCopy, false);
     406        }
     407        public static List<Item> CopyItems(List<Item> toCopy, boolean extrude) {
    404408                // The copies to return
    405409                List<Item> copies = new ArrayList<Item>();
     
    413417
    414418                List<Item> seen = new ArrayList<Item>();
    415 
     419               
    416420                for (Item i : toCopy) {
    417421                        // lines are recreated later
     
    452456                                // if this is the frame name, make sure the frame is saved (in
    453457                                // case it is a TDFC frame)
    454                                 if (i == i.getParent().getName())
     458                                if (i == i.getParent().getFrameNameItem())
    455459                                        i.getParent().setChanged(true);
    456460
     
    484488                                copy.removeAllLines();
    485489                                copy.removeAllConstraints();
    486 
     490                               
    487491                                // replace all other instances with the copy
    488492                                ReplaceAll(lineEnds, i, copy);
    489493                                ReplaceAll(vConst, i, copy);
    490494                                ReplaceAll(hConst, i, copy);
     495                               
     496                                if (extrude) {
     497                                        Frame frame = DisplayIO.getCurrentFrame();
     498                                        Line newLine = new Line(i,copy, frame.getNextItemID());
     499                                        frame.addItem(newLine);
     500                                        copies.add(newLine);
     501                                }
    491502
    492503                                seen.add(i);
     
    598609                //copy.setFloating(true);
    599610                origEnd.setArrowheadLength(0);
    600                 copy.setArrowheadLength(0);
     611                //copy.setArrowheadLength(0);
    601612
    602613                List<Item> toReturn = new LinkedList<Item>();
     
    633644                        return;
    634645
     646                //TODO optimise this code!!
    635647                // iterate through all the dots
    636648                for (Dot searchFor : dots) {
  • trunk/src/org/expeditee/items/Line.java

    r4 r7  
    1414import java.util.List;
    1515
     16import org.expeditee.gui.DisplayIO;
     17import org.expeditee.gui.Frame;
     18
    1619/**
    1720 * Implements a line that is drawn on the screen. A line is represented as two
     
    2427
    2528        private static final int AUTO_ARROWHEAD_LENGTH = -1;
    26        
    27         private static final double DEFAULT_ARROWHEAD_RATIO = 0.5;
    2829
    2930        private static final int ARROW_HEAD_TO_LENGTH_RATIO = 8;
     
    8182                // initialise the line size
    8283                float thick;
    83                 if (_start instanceof Dot)
     84
     85                if (_start instanceof Dot && _end instanceof Dot)
     86                        thick = (((Dot) _start).getThickness() + ((Dot) _end)
     87                                        .getThickness()) / 2.0f;
     88                else if (_start instanceof Dot)
    8489                        thick = ((Dot) _start).getThickness();
     90                else if (_end instanceof Dot)
     91                        thick = ((Dot) _end).getThickness();
    8592                else
    86                         thick = _start.getSize();
    87 
    88                 if (_end instanceof Dot)
    89                         thick += ((Dot) _end).getThickness();
    90                 else
    91                         thick += _end.getSize();
    92 
    93                 setLinePattern(_start.getLinePattern());
    94                 // Set the thickness to be half the value of the end points
    95                 setThickness(thick / 2.0f);
     93                        thick = 1;
     94
     95                setThickness(thick);
    9696        }
    9797
     
    300300                                        BasicStroke.JOIN_MITER));
    301301
    302                         if (_start.isFloating() && !_end.isFloating()) {
    303                                 paintArrow(g, _start, _startOffset, _endOffset);
    304                         } else if (!_start.isFloating() && _end.isFloating()) {
    305                                 paintArrow(g, _end, _endOffset, _startOffset);
    306                         } else {
    307                                 paintArrow(g, _start, _startOffset, _endOffset);
    308                                 paintArrow(g, _end, _endOffset, _startOffset);
    309                         }
     302                        paintArrow(g, _start, _startOffset, _endOffset);
     303                        paintArrow(g, _end, _endOffset, _startOffset);
    310304
    311305                        g.setStroke(_lineStroke);
     
    326320                if (showLineHighlight() && isHighlighted()) {
    327321                        g.setColor(getHighlightColor());
     322                        g.setStroke(new BasicStroke(MINIMUM_THICKNESS,
     323                                        BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    328324                        ((Graphics2D) g).draw(this.getArea());
    329325                }
     
    453449        }
    454450
     451        public Item getEndPointToDisconnect(int x, int y) {
     452                Item start = getStartItem();
     453                Item end = getEndItem();
     454                int deltaX = start.getX() - end.getX();
     455                int deltaY = start.getY() - end.getY();
     456                int lineLength = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
     457
     458                int startX = start.getX() - x;
     459                int endX = end.getX() - x;
     460                int startY = start.getY() - y;
     461                int endY = end.getY() - y;
     462
     463                int distStart = (int) Math.sqrt(startX * startX + startY * startY);
     464                int distEnd = (int) Math.sqrt(endX * endX + endY * endY);
     465
     466                final double THRESHHOLD = Math.min(0.2 * lineLength, 25.0);
     467
     468                if (distStart < THRESHHOLD) {
     469                        return start;
     470                } else if (distEnd < THRESHHOLD) {
     471                        return end;
     472                }
     473
     474                return null;
     475        }
     476
    455477        @Override
    456478        public int showHighlight(boolean val) {
     
    547569                }
    548570        }
    549        
     571
    550572        public void autoArrowheadLength() {
    551573                _end.setArrowheadLength(AUTO_ARROWHEAD_LENGTH);
    552                 _end.setArrowheadRatio(DEFAULT_ARROWHEAD_RATIO);
    553574        }
    554575
     
    570591        }
    571592
     593        /**
     594         * This method toggles the arrow on the floating end point of a line. If the
     595         * line does not have one floating end and one fixed end this method does
     596         * nothing.
     597         *
     598         */
    572599        public void toggleArrow() {
    573600                Item arrow;
     
    728755        }
    729756
    730         @Override
    731         public Item merge(Item merger, int mouseX, int mouseY) {
    732                 if (!(merger instanceof Dot))
    733                         return merger;
    734 
     757        public void showVirtualSpot(int mouseX, int mouseY) {
     758                Dot spot = new Dot(mouseX, mouseY, -1);
     759                spot.setThickness(Math.max(this.getThickness(), 5));
     760                if (this.getColor() != Color.RED)
     761                        spot.setColor(Color.RED);
     762                else
     763                        spot.setColor(Color.BLUE);
     764
     765                // calculate nearest point on line from spot
     766                double slope1;
     767                double slope2;
     768                double x, y;
     769
     770                slope1 = (_start.getY() - _end.getY() * 1.0)
     771                                / (_start.getX() - _end.getX());
     772                slope2 = -1 / slope1;
     773
     774                // if the line is horizontal
     775                if (slope1 == 0) {
     776                        x = spot.getX();
     777                        y = _start.getY();
     778                        // if the line is vertical
     779                } else if (slope2 == 0) {
     780                        x = _start.getX();
     781                        y = spot.getY();
     782                        // otherwise, the line is sloped
     783                } else {
     784                        x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1
     785                                        * _start.getX())
     786                                        / (slope1 - slope2);
     787                        y = slope1 * (x - _start.getX()) + _start.getY();
     788                }
     789
     790                // position spot on the line
     791                spot.setPosition((int) x, (int) y);
     792                _virtualSpot = spot;
     793        }
     794
     795        public Item forceMerge(Item merger, int mouseX, int mouseY) {
    735796                Dot spot = (Dot) merger;
    736 
    737                 // dots with multiple lines cannot be attached, nor can dots with no
    738                 // lines
    739                 if (spot.getLines().size() != 1)
    740                         return merger;
    741 
    742                 // lines that are in 'connected' mode, also cannot be attached
    743                 if (spot.getLines().get(0).getOppositeEnd(spot).isFloating())
    744                         return merger;
    745797
    746798                if (spot.getConstraints() != null)
     
    783835                Line temp = copy();
    784836
    785                 temp.setID(-1);
     837                Frame currentFrame = DisplayIO.getCurrentFrame();
     838                temp.setID(currentFrame.getNextItemID());
    786839                temp.setEndItem(_end);
    787840                temp.setStartItem(spot);
     841                currentFrame.addItem(temp);
    788842
    789843                setEndItem(spot);
     
    793847
    794848                return spot;
     849        }
     850
     851        @Override
     852        public Item merge(Item merger, int mouseX, int mouseY) {
     853                if (!(merger instanceof Dot))
     854                        return merger;
     855
     856                Dot spot = (Dot) merger;
     857
     858                // dots with multiple lines cannot be attached, nor can dots with no
     859                // lines
     860                if (spot.getLines().size() != 1)
     861                        return merger;
     862
     863                // lines that are in 'connected' mode, also cannot be attached
     864                if (spot.getLines().get(0).getOppositeEnd(spot).isFloating())
     865                        return merger;
     866
     867                return forceMerge(merger, mouseX, mouseY);
    795868        }
    796869
     
    840913        public int getLineType() {
    841914                return 1;
     915        }
     916
     917        @Override
     918        public boolean isFloating() {
     919                return _start.isFloating() && _end.isFloating();
    842920        }
    843921
     
    895973                }
    896974        }
     975
     976        public void setFilledHighlight(boolean value) {
     977                _start.setFilledHighlight(value);
     978                _end.setFilledHighlight(value);
     979        }
     980
     981        @Override
     982        public void delete() {
     983                super.delete();
     984
     985                _start.removeLine(this);
     986                _end.removeLine(this);
     987
     988                if (_start.getLines().size() == 0)
     989                        _start.delete();
     990                if (_end.getLines().size() == 0)
     991                        _end.delete();
     992        }
    897993}
  • trunk/src/org/expeditee/items/Picture.java

    r4 r7  
    106106                if (path == null && source.getLink() != null) {
    107107                        String link = source.getLink();
    108                         if (FrameIO.isPositiveInteger(link)){
     108                        if (FrameIO.isPositiveInteger(link)) {
    109109                                link = source.getParent().getFramesetNameAdjusted() + link;
    110110                        }
     
    113113                        _image = frame.getBuffer();
    114114                        _isFrame = true;
    115 
    116115                } else {
    117116
     
    427426                Picture p;
    428427
    429                 if (_isFrame){
     428                if (_isFrame) {
    430429                        p = ItemUtils.CreateFramePicture((Text) _source.copy(),
    431430                                        _imageObserver);
    432                 }else
     431                } else
    433432                        p = ItemUtils.CreatePicture((Text) _source.copy(), _imageObserver);
    434433
     
    547546        }
    548547
     548        public void refresh() {
     549                if (_isFrame) {
     550                        String link = _source.getLink();
     551                        if (FrameIO.isPositiveInteger(link)) {
     552                                link = _source.getParent().getFramesetNameAdjusted() + link;
     553                        }
     554                        Frame frame = FrameIO.LoadFrame(link);
     555                        FrameGraphics.UpdateBuffer(frame, false);
     556                        _image = frame.getBuffer();
     557                }
     558        }
     559
    549560}
  • trunk/src/org/expeditee/items/Text.java

    r4 r7  
    3333public class Text extends Item {
    3434
     35        private String[] _processedCode = null;
     36
     37        public String[] getProcessedCode() {
     38                return _processedCode;
     39        }
     40
     41        public void setProcessedCode(String[] tokens) {
     42                _processedCode = tokens;
     43        }
     44
    3545        public static final String FRAME_NAME_SEPARATOR = " on frame ";
    3646
     
    231241
    232242        }
    233        
     243
    234244        public void removeEndText(String textToRemove) {
    235245                int length = _text.length();
     
    253263                rebuild(false);
    254264        }
    255        
     265
    256266        public void appendLine(String text) {
    257267                if (text == null)
    258268                        text = "";
    259                
     269
    260270                if (_text.length() > 0)
    261271                        _text.append('\n');
    262                        
     272
    263273                _text.append(text);
    264274                rebuild(false);
     
    381391
    382392        public String cutSelectedText() {
     393                return replaceSelectedText("");
     394        }
     395
     396        public String replaceSelectedText(String newText) {
    383397                if (_selectionStart < 0 || _selectionEnd < 0)
    384398                        return null;
     
    390404
    391405                String s = _text.substring(left, right);
    392                 for (int i = right; i > left; i--) {
    393                         _text.delete(i - 1, i);
    394                         if (_text.length() > 0) {
    395                                 AttributedString inserting = new AttributedString(_text
    396                                                 .toString());
    397                                 inserting.addAttribute(TextAttribute.FONT, getPaintFont());
    398                                 _lineBreaker.deleteChar(inserting.getIterator(), i - 1);
    399                         }
    400 
    401                         rejustify();
    402                 }
     406
     407                _text.delete(left, right);
     408                _text.insert(left, newText);
     409                rebuild(true);
    403410
    404411                return s;
     
    409416                        return 0;
    410417
    411                 //System.out.println(_selectionStart + ":" + _selectionEnd);
     418                // System.out.println(_selectionStart + ":" + _selectionEnd);
    412419
    413420                return Math.abs(_selectionEnd - _selectionStart);
     
    451458                        // otherwise, we are inserting text
    452459                } else {
     460                        _processedCode = null;
    453461                        // determine what line is being pointed to
    454462                        line = getLinePosition(mouseY);
     
    552560                                                x,
    553561                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    554                 return new Point(x, getY() /* + DisplayIO.getOffset() */+ y
     562                return new Point(x, getY() + y
    555563                                + (int) caret[1]);
    556564        }
     
    621629
    622630                return new Point((int) (getX() + caret[0]) + getJustOffset(current),
    623                                 getY() /* + DisplayIO.getOffset() */+ y + (int) caret[1]);
     631                                getY() + y + (int) caret[1]);
    624632        }
    625633
     
    720728                Font f = getPaintFont();
    721729                String s = "";
    722                
     730
    723731                if (f.isPlain())
    724732                        s += "Plain";
     
    732740                return s;
    733741        }
    734        
    735         public static final String[] FONT_WHEEL = { "sansserif", "monospaced", "serif", "dialog", "dialoginput" };
     742
     743        public static final String[] FONT_WHEEL = { "sansserif", "monospaced",
     744                        "serif", "dialog", "dialoginput" };
     745
    736746        public static final char[] FONT_CHARS = { 's', 'm', 't', 'd', 'i' };
    737        
     747
     748        private static final int NEARBY_GRAVITY = 2;
     749
    738750        public void toggleFontFamily() {
    739751                String fontFamily = getFamily().toLowerCase();
    740                 //set it to the first font by default
     752                // set it to the first font by default
    741753                setFamily(FONT_WHEEL[0]);
    742                
     754
    743755                for (int i = 0; i < FONT_WHEEL.length - 3; i++) {
    744                         if(fontFamily.equals(FONT_WHEEL[i])){
    745                                 setFamily(FONT_WHEEL[i+1]);
     756                        if (fontFamily.equals(FONT_WHEEL[i])) {
     757                                setFamily(FONT_WHEEL[i + 1]);
    746758                                break;
    747759                        }
    748760                }
    749761        }
    750        
     762
    751763        public void toggleFontStyle() {
    752764                Font currentFont = getPaintFont();
     
    882894
    883895        @Override
     896        public boolean intersects(Polygon p) {
     897                if (super.intersects(p)) {
     898                        int textY = getY();
     899
     900                        for (TextLayout text : _textLayouts) {
     901                                // check left and right of each box
     902                                Rectangle textOutline = text.getLogicalHighlightShape(0,
     903                                                text.getCharacterCount()).getBounds();
     904                                textOutline.translate(getX(), textY);
     905                                if (p.intersects(textOutline))
     906                                        return true;
     907                                textY += getLineDrop(text);
     908                        }
     909                }
     910                return false;
     911        }
     912
     913        @Override
    884914        public boolean contains(int mouseX, int mouseY) {
     915                return contains(mouseX, mouseY, getGravity() * NEARBY_GRAVITY);
     916        }
     917
     918        public boolean contains(int mouseX, int mouseY, int gravity) {
    885919                mouseX += getOffset().x;
    886920                mouseY += getOffset().y;
     
    888922                int textY = getY();
    889923                int textX = getX();
    890                 int gravity = getGravity() * 2;
    891924
    892925                Rectangle outline = getPolygon().getBounds();
     
    10091042                while ((layout = _lineBreaker.nextLayout(width)) != null) {
    10101043                        // for some reason lineBreaker will not break on newline
    1011                         // characters
    1012                         // so they have to be check manually
     1044                        // characters so they have to be check manually
    10131045                        int start = _lineOffsets.get(_lineOffsets.size() - 1);
    10141046
     
    13691401                                return;
    13701402
    1371                         //Remove 'a: ' from the begining if it is there
    1372                         if (_text.length() > 3 && _text.charAt(0) == 'a' && _text.charAt(1) == ':'){
     1403                        // Remove 'a: ' from the begining if it is there
     1404                        if (_text.length() > 3 && _text.charAt(0) == 'a'
     1405                                        && _text.charAt(1) == ':') {
    13731406                                _text.delete(0, 2);
    13741407                                while (_text.charAt(0) == ' ')
     
    15021535                Text template = this.copy();
    15031536                template.setID(-1);
    1504                 //The template must have text otherwise the bounds height will be zero!!
    1505                 //This will stop escape drop down from working if there is no item template
     1537                // The template must have text otherwise the bounds height will be
     1538                // zero!!
     1539                // This will stop escape drop down from working if there is no item
     1540                // template
    15061541                template.setText("@");
    15071542                return template;
    15081543        }
     1544
     1545        @Override
     1546        public boolean isNear(int x, int y) {
     1547                if (super.isNear(x, y)) {
     1548                        // TODO check that it is actually near one of the lines of space
     1549                        // return contains(x, y, getGravity() * 2 + NEAR_DISTANCE);
     1550                        // at the moment contains ignores gravity when checking the top and
     1551                        // bottom of text lines... so the cursor must be between two text
     1552                        // lines
     1553                        int textY = getY();
     1554                        int textX = getX();
     1555
     1556                        for (TextLayout text : _textLayouts) {
     1557                                // check left and right of each box
     1558                                Rectangle textOutline = text.getLogicalHighlightShape(0,
     1559                                                text.getCharacterCount()).getBounds();
     1560                               
     1561                                // check if the cursor is within the top, bottom and within the
     1562                                // gravity of right
     1563                                if (y - textY > textOutline.y - NEAR_DISTANCE
     1564                                                && y - textY < textOutline.y + textOutline.height + NEAR_DISTANCE
     1565                                                && x - textX < textOutline.width + NEAR_DISTANCE)
     1566                                        return true;
     1567                                textY += getLineDrop(text);
     1568                        }
     1569                }
     1570                return false;
     1571        }
     1572       
     1573        @Override
     1574        public void delete() {
     1575                setVisible(false);
     1576        }
    15091577}
  • trunk/src/org/expeditee/simple/Context.java

    r4 r7  
    11package org.expeditee.simple;
    22
     3import java.io.BufferedReader;
    34import java.io.BufferedWriter;
    45import java.io.File;
     6import java.io.FileReader;
    57import java.io.FileWriter;
    68
     
    810import org.expeditee.gui.FrameGraphics;
    911import org.expeditee.gui.FrameIO;
     12import org.expeditee.items.Text;
    1013
    1114public class Context {
     
    9295                // Get the values to be set
    9396                Frame frame = (Frame) pointers_.getVariable(frameVar).getValue();
     97                frame.change();
    9498                String contents = FrameIO.SaveFrame(frame, false);
    9599
     
    104108                                .getValue();
    105109                bw.close();
     110        }
     111
     112        public void closeReadFile(String fileVar) throws Exception {
     113                BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar)
     114                                .getValue();
     115                br.close();
    106116        }
    107117
     
    128138                if (successVar != null) {
    129139                        Boolean success = currentFile != null;
     140                        primitives_.setValue(successVar, new SBoolean(success));
     141                }
     142        }
     143
     144        public void readLineFile(String fileVar, String textVar) throws Exception {
     145                readLineFile(fileVar, fileVar, null);
     146        }
     147
     148        public void readLineFile(String fileVar, String textVar, String successVar)
     149                        throws Exception {
     150
     151                BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar)
     152                                .getValue();
     153
     154                String text = br.readLine();
     155                boolean success = text != null;
     156                primitives_.setValue(textVar, text);
     157
     158                if (successVar != null) {
     159                        primitives_.setValue(successVar, new SBoolean(success));
     160                }
     161        }
     162
     163        public void readItemFile(String fileVar, String itemVar) throws Exception {
     164                readItemFile(fileVar, fileVar, null);
     165        }
     166
     167        public void readItemFile(String fileVar, String itemVar, String successVar)
     168                        throws Exception {
     169
     170                BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar)
     171                                .getValue();
     172                boolean success = true;
     173                try {
     174                        Text item = (Text) pointers_.getVariable(itemVar).getValue();
     175                        String nextLine = br.readLine();
     176                        String text = nextLine;
     177                        success = (text != null);
     178                        while ((nextLine = br.readLine()) != null)
     179                                text += '\n' + nextLine;
     180                        item.setText(text);
     181                } catch (Exception e) {
     182                        success = false;
     183                }
     184
     185                if (successVar != null) {
     186                        primitives_.setValue(successVar, new SBoolean(success));
     187                }
     188        }
     189
     190        public void openReadFile(String fileNameVar, String fileVar)
     191                        throws Exception {
     192                openReadFile(fileNameVar, fileVar, null);
     193        }
     194
     195        public void openReadFile(String fileNameVar, String fileVar,
     196                        String successVar) throws Exception {
     197                // Get the values to be set
     198                File filePath = new File(primitives_.getStringValue(fileNameVar));
     199                Boolean success = true;
     200                BufferedReader currentFile = null;
     201                try {
     202                        currentFile = new BufferedReader(new FileReader(filePath));
     203                } catch (Exception e) {
     204                        success = false;
     205                }
     206                pointers_.setObject(fileVar, currentFile);
     207
     208                if (successVar != null) {
    130209                        primitives_.setValue(successVar, new SBoolean(success));
    131210                }
     
    144223                }
    145224        }
     225
     226        public void createFrameset(String framesetNameVar, String successVar)
     227                        throws Exception {
     228                // Get the values to be set
     229                String framesetName = primitives_.getStringValue(framesetNameVar);
     230                Frame firstFrame = FrameIO.CreateNewFrameset(framesetName);
     231
     232                if (successVar != null) {
     233                        Boolean success = firstFrame != null;
     234                        primitives_.setValue(successVar, new SBoolean(success));
     235                }
     236
     237        }
    146238}
  • trunk/src/org/expeditee/stats/SessionStats.java

    r4 r7  
    1616public class SessionStats {
    1717
    18         private static final long MILLISECONDS_PER_MINUTE = 6000;
     18        private static final long MILLISECONDS_PER_MINUTE = 60000;
    1919
    2020        private static Date _FrameAccessTime = new Date();
     
    2323
    2424        // statistics counters
    25         private static final int MOUSE_BUTTONS = 3;
     25        private static final int MOUSE_BUTTONS = 4;
    2626
    2727        private static StringBuffer _FramesEdited = new StringBuffer();
     
    5959                stats.append(Logger.EasyDateFormat("ddMMMyyyy")).append("\n");
    6060                stats.append("SessionTime: ").append(getTimeElapsed()).append("\n");
    61                 stats.append("DarkTime: ").append( new SimpleDateFormat("m").format(_DarkTime) ).append("\n");
     61               
     62                long elapsedTime = (new Date()).getTime()-_StartTime.getTime();
     63                stats.append("DarkTime: ").append(_DarkTime.getTime()/MILLISECONDS_PER_MINUTE).append("-->" +
     64                                _DarkTime.getTime() * 100 / elapsedTime + "%\n");
    6265               
    6366                stats.append(getFrameStats());
     
    7477                SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
    7578                Date currentTime = new Date();
    76                 Time elapsedTime = new Time(currentTime.getTime()-_StartTime.getTime());
     79                long elapsedTime = currentTime.getTime()-_StartTime.getTime();
    7780                String time = formatter.format(_StartTime);
    7881                time += " --> " + formatter.format(currentTime);
    79                 time += " = " + (new SimpleDateFormat("m").format(elapsedTime));
     82                time += " = " + (int)(elapsedTime / MILLISECONDS_PER_MINUTE);   //(new SimpleDateFormat("m").format(elapsedTime));
    8083
    8184                return time;
     
    109112        }
    110113
    111         private static int getMinutesUsed() {
     114        private static double getMinutesUsed() {
    112115                long elapsedTime = new Date().getTime() - _StartTime.getTime() - _DarkTime.getTime();
    113116               
    114                 return (int) (elapsedTime / MILLISECONDS_PER_MINUTE);
     117                return (double) elapsedTime / MILLISECONDS_PER_MINUTE;
    115118        }
    116119
     
    145148                appendStat(stats, "Frames", _CreatedFrames);
    146149                appendStat(stats, "Escape", _EscapeCount);
    147                 appendStat(stats, "Left", _MouseCounters[MouseEvent.BUTTON1 - 1]);
    148                 appendStat(stats, "Middle", _MouseCounters[MouseEvent.BUTTON2 - 1]);
    149                 appendStat(stats, "Right", _MouseCounters[MouseEvent.BUTTON3 - 1]);
     150                appendStat(stats, "Left", _MouseCounters[MouseEvent.BUTTON1]);
     151                appendStat(stats, "Middle", _MouseCounters[MouseEvent.BUTTON2]);
     152                appendStat(stats, "Right", _MouseCounters[MouseEvent.BUTTON3]);
    150153
    151154                return stats.toString();
     
    169172                        value = 0;
    170173
    171                 int perHour = value * 60 / Math.max(1, getMinutesUsed());
     174                int perHour = (int)(value * 60 / getMinutesUsed());
    172175
    173176                stats.append(value).append(" ").append(name).append(" @ ").append(perHour).append("/hour");
     
    262265        public static void MouseClicked(int button) {
    263266                UserEvent();
    264                 _MouseCounters[button - 1]++;
     267                _MouseCounters[button]++;
    265268        }
    266269
     
    277280                return _FramesEdited.toString();
    278281        }
     282
     283        public static StringBuffer getShortStats() {
     284                StringBuffer sb = new StringBuffer();
     285                sb.append("FramesA:").append(_AccessedFrames);
     286                sb.append(", FramesE:").append(_SavedFrames);
     287                sb.append(", ").append(getResponseStats());
     288                return sb;
     289        }
    279290}
Note: See TracChangeset for help on using the changeset viewer.