Changeset 162
- Timestamp:
- 07/28/08 15:08:13 (16 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r161 r162 25 25 import org.expeditee.gui.FrameIO; 26 26 import org.expeditee.gui.FrameMouseActions; 27 import org.expeditee.gui.FrameUtils; 27 28 import org.expeditee.gui.MessageBay; 28 29 import org.expeditee.gui.TimeKeeper; 29 30 import org.expeditee.items.Item; 31 import org.expeditee.items.ItemUtils; 30 32 import org.expeditee.items.Text; 31 33 import org.expeditee.simple.ExpediteeJEP; … … 155 157 getFromChildFrame(current, false); 156 158 } 159 160 public static void GetItemsFromChildFrame(Item current) { 161 getItemsFromChildFrame(current, false); 162 } 157 163 158 164 /** … … 180 186 item.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY()); 181 187 item.setParent(null); 182 183 188 FrameMouseActions.pickup(item); 189 FrameGraphics.Repaint(); 190 } 191 192 private static void getItemsFromChildFrame(Item current, boolean textOnly) { 193 Collection<Item> items = getItemsOnChildFrame(current, textOnly); 194 // if no item was found 195 if (items == null || items.size() == 0) { 196 return; 197 } 198 199 // copy the item and switch 200 Collection<Item> copies = ItemUtils.CopyItems(items); 201 float deltaX = DisplayIO.getMouseX(); 202 float deltaY = FrameMouseActions.getY(); 203 for(Item i: copies){ 204 i.setXY(i.getX() + deltaX, i.getY() + deltaY); 205 i.setParent(null); 206 } 207 FrameMouseActions.pickup(copies); 184 208 FrameGraphics.Repaint(); 185 209 } … … 657 681 return item; 658 682 } 683 684 private static Collection<Item> getItemsOnChildFrame(Item current, 685 boolean textOnly) { 686 // the item must link to a frame 687 if (current.getLink() == null) { 688 MessageBay 689 .displayMessage("Cannot get item from child - this item has no link"); 690 return null; 691 } 692 Frame child = FrameIO.LoadFrame(current.getAbsoluteLink()); 693 694 // if the frame could not be loaded 695 if (child == null) { 696 MessageBay.errorMessage("Could not load child frame."); 697 return null; 698 } 699 700 // find the first non-title and non-name item 701 Collection<Item> body = new ArrayList<Item>(); 702 if (textOnly) 703 body.addAll(child.getBodyTextItems(false)); 704 else 705 body.addAll(child.getItems()); 706 707 return body; 708 } 659 709 660 710 public static void calculate(Frame frame, Item toCalculate) { … … 667 717 myParser.addVariables(FrameIO.LoadFrame(linkedFrame)); 668 718 } 669 myParser. addObserver();719 myParser.resetObserver(); 670 720 671 721 // Do the calculation … … 677 727 String result = myParser.getResult(); 678 728 if (result == null) { 679 MessageBay.errorMessage(myParser.getErrorInfo().replace( "\n",680 ""));729 MessageBay.errorMessage(myParser.getErrorInfo().replace( 730 "\n", "")); 681 731 } else { 682 732 text.setText(result); … … 685 735 FrameMouseActions.MouseY); 686 736 FrameMouseActions.resetOffset(); 737 } else { 738 text.getParentOrCurrentFrame().change(); 687 739 } 688 740 } -
trunk/src/org/expeditee/actions/NavigationActions.java
r121 r162 5 5 import org.expeditee.gui.DisplayIO; 6 6 import org.expeditee.gui.Frame; 7 import org.expeditee.gui.FrameCreator; 8 import org.expeditee.gui.FrameGraphics; 7 9 import org.expeditee.gui.FrameIO; 8 10 import org.expeditee.gui.FrameUtils; 9 11 import org.expeditee.gui.MessageBay; 10 12 import org.expeditee.items.Item; 13 import org.expeditee.items.Text; 11 14 12 15 /** -
trunk/src/org/expeditee/actions/Simple.java
r161 r162 162 162 do { 163 163 next = FrameIO.LoadNext(next); 164 } while (next != null && next.isTestFrame());164 } while (next != null && !next.isTestFrame()); 165 165 FrameUtils.DisplayFrame(next, true); 166 166 } … … 170 170 do { 171 171 prev = FrameIO.LoadPrevious(prev); 172 } while (prev != null && prev.isTestFrame());172 } while (prev != null && !prev.isTestFrame()); 173 173 174 174 FrameUtils.DisplayFrame(prev, true); … … 783 783 // Check for set statements 784 784 } else if (tokens[0].startsWith("calculatestring")) { 785 assertMinParametreCount(tokens, 2); 786 String toCalculate = context.getPrimitives().getStringValue(tokens[1]); 785 assertMinParametreCount(tokens, 1); 786 String toCalculate = context.getPrimitives().getStringValue( 787 tokens[1]); 787 788 boolean result = true; 789 String error = ""; 788 790 ExpediteeJEP myParser = new ExpediteeJEP(); 789 // Add the variables in the system791 // Add the variables in the system 790 792 context.getPrimitives().addToParser(myParser); 791 793 Node equation = myParser.parseExpression(toCalculate); 792 //TODO get the answer 793 794 // TODO get the answer 795 if (equation == null) { 796 result = false; 797 error = myParser.getErrorInfo().replace("\n", ""); 798 } else { 799 double value = myParser.getValue(); 800 if (myParser.hasError()) { 801 result = false; 802 error = myParser.getErrorInfo().replace("\n", ""); 803 } else { 804 // Add a new variable if its an assignment statement 805 String newVar = myParser.getNewVariable(); 806 if (newVar.length() > 0) { 807 try { 808 context.getPrimitives().setValue(newVar, 809 new SReal(value)); 810 } catch (IncorrectTypeException e) { 811 result = false; 812 error = e.getMessage(); 813 } 814 } 815 if (tokens.length > 2) { 816 context.getPrimitives().setValue(tokens[2], 817 new SReal(value)); 818 } 819 } 820 } 821 // Set the result variable if there is one 822 if (tokens.length > 3) { 823 context.getPrimitives().setValue(tokens[3], 824 new SBoolean(result)); 825 // Set the result variable if there is one 826 if (tokens.length > 4 && !result) { 827 context.getPrimitives().setValue(tokens[4], error); 828 } 829 } 794 830 } else if (tokens[0].startsWith("calculateitem")) { 795 831 assertMinParametreCount(tokens, 1); 796 832 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 797 Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue(); 833 Item item = (Item) context.getPointers().getVariable(tokens[1]) 834 .getValue(); 798 835 Frame frame = null; 799 if (tokens.length > 2){836 if (tokens.length > 2) { 800 837 assertVariableType(tokens[2], 2, SPointer.framePrefix); 801 frame = (Frame)context.getPointers().getVariable(tokens[2]).getValue(); 838 frame = (Frame) context.getPointers().getVariable(tokens[2]) 839 .getValue(); 802 840 } 803 841 Misc.calculate(frame, item); 804 } else if (tokens[0].startsWith("issearchpatternvalid")) {842 } else if (tokens[0].startsWith("issearchpatternvalid")) { 805 843 assertExactParametreCount(tokens, 2); 806 844 boolean result = true; … … 885 923 String pattern = context.getPrimitives().getStringValue( 886 924 tokens[2]); 887 SearchAgent searchAgent = new SearchFrameset(); 925 long firstFrame = 1; 926 long maxFrame = Long.MAX_VALUE; 927 if(tokens.length > 7){ 928 firstFrame = context.getPrimitives().getIntegerValue(tokens[7]); 929 if(tokens.length > 8){ 930 maxFrame = context.getPrimitives().getIntegerValue(tokens[8]); 931 } 932 } 933 934 SearchAgent searchAgent = new SearchFrameset(firstFrame, maxFrame); 888 935 searchAgent.initialise(null, null, frameset, resultsFrameset, 889 936 replacementString, pattern); … … 1187 1234 .getStringValue(tokens[1]), context.getPrimitives() 1188 1235 .getStringValue(tokens[2])); 1236 } else if (tokens[0].equals("assertequalframes")) { 1237 assertExactParametreCount(tokens, 2); 1238 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1239 assertVariableType(tokens[2], 2, SPointer.framePrefix); 1240 Frame frame1 = (Frame) context.getPointers().getVariable( 1241 tokens[1]).getValue(); 1242 Frame frame2 = (Frame) context.getPointers().getVariable( 1243 tokens[2]).getValue(); 1244 // Check that all the items on the frame are the same 1245 List<Item> items1 = frame1.getVisibleItems(); 1246 List<Item> items2 = frame2.getVisibleItems(); 1247 if (items1.size() != items2.size()) { 1248 throw new UnitTestFailedException(items1.size() + " items", 1249 items2.size() + " items"); 1250 } else { 1251 for (int i = 0; i < items1.size(); i++) { 1252 Item i1 = items1.get(i); 1253 Item i2 = items2.get(i); 1254 String s1 = i1.getText(); 1255 String s2 = i2.getText(); 1256 if (!s1.equals(s2)) { 1257 throw new UnitTestFailedException(s1, s2); 1258 } 1259 } 1260 } 1189 1261 } else if (tokens[0].equals("assertdefined")) { 1190 1262 assertExactParametreCount(tokens, 1); … … 1193 1265 "not defined"); 1194 1266 } 1267 } else { 1268 throw new RuntimeException("Invalid Assert statement"); 1195 1269 } 1196 1270 } else if (tokens[0].startsWith("goto")) { … … 1957 2031 freshCopy.setFrameset(destinationFrameset); 1958 2032 }// Otherwise add it to the end of this frameset 1959 freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy 1960 .getFramesetName()) + 1); 1961 context.getPointers().setObject(tokens[2], freshCopy); 1962 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 2033 int nextNumber = FrameIO.getLastNumber(freshCopy.getFramesetName()) + 1; 2034 // if the frameset doesnt already exist then create it 2035 if (nextNumber <= 0) { 2036 try { 2037 FrameIO.CreateFrameset(freshCopy.getFramesetName(), 2038 frameToCopy.path); 2039 nextNumber = 1; 2040 } catch (Exception e) { 2041 } 2042 } 2043 boolean success = false; 2044 if (nextNumber > 0) { 2045 freshCopy.setFrameNumber(nextNumber); 2046 context.getPointers().setObject(tokens[2], freshCopy); 2047 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 2048 success = fileContents != null; 2049 } 1963 2050 FrameIO.ResumeCache(); 1964 // Need to add the new copy to the cache in case it is edited by 1965 // other simple statements 1966 FrameIO.addToCache(freshCopy); 1967 boolean success = fileContents != null; 2051 if (success) { 2052 // Need to add the new copy to the cache in case it is edited by 2053 // other simple statements 2054 FrameIO.addToCache(freshCopy); 2055 } 1968 2056 if (!success && _verbose) 1969 2057 MessageBay.warningMessage("Error copying " -
trunk/src/org/expeditee/agents/SearchAgent.java
r156 r162 11 11 public abstract class SearchAgent extends DefaultAgent { 12 12 13 private static final String DEFAULT_RESULTS_FRAMESET = "SearchResults"; 14 13 15 protected FrameCreator _results; 14 16 … … 26 28 //TODO use a results frame specified on the profile frame 27 29 if (item.getLink() == null) { 28 resultFrameset = frame.getFramesetName();30 resultFrameset = DEFAULT_RESULTS_FRAMESET; 29 31 } else { 30 32 resultFrameset = Conversion.getFramesetName(item.getAbsoluteLink(), … … 36 38 public boolean initialise(Frame frame, Item item, String startName, String resultsFrameset, 37 39 String replacementString, String pattern) { 38 _pattern = pattern ;40 _pattern = pattern.toLowerCase(); 39 41 _replacementString = replacementString; 40 42 _startName = startName; … … 58 60 String replacementString) { 59 61 String searchStr = itemToSearch.getText().toLowerCase(); 60 String[] result = searchStr.split(pattern.toLowerCase(), 2); 61 boolean bFound = result.length > 1; 62 boolean bFound = searchStr.matches(pattern.toLowerCase()); 62 63 // If it is a find and replace... then replace with the replacement 63 64 // string -
trunk/src/org/expeditee/agents/SearchFrameset.java
r134 r162 5 5 6 6 public class SearchFrameset extends SearchAgent { 7 private long _firstFrame = 1; 8 private long _maxFrame = Integer.MAX_VALUE; 9 10 public SearchFrameset(long firstFrame, long maxFrame) { 11 _firstFrame = firstFrame; 12 _maxFrame = maxFrame; 13 } 14 15 public SearchFrameset() { 16 super(); 17 } 7 18 8 19 @Override 9 20 protected Frame process(Frame frame) { 10 21 int count = FrameIO.getLastNumber(_startName); 11 for ( int i = 1;i < count; i++) {22 for (long i = _firstFrame;i <= _maxFrame && i < count; i++) { 12 23 if (_stop) { 13 24 break; -
trunk/src/org/expeditee/gui/DisplayIO.java
r156 r162 62 62 * The title to display in the Title bar. 63 63 */ 64 public static final String TITLE = "Exp2 2Jul2008A";64 public static final String TITLE = "Exp28Jul2008A"; 65 65 66 66 private DisplayIO() { … … 605 605 Frame frame = FrameIO.LoadFrame(_VisitedFrames[side].pop()); 606 606 // If the top frame on the backup stack is the current frame go back 607 // again... 608 if (frame.equals(getCurrentFrame())) { 607 // again... or if it has been deleted 608 //Recursively backup the stack 609 if(frame == null || frame.equals(getCurrentFrame())) { 609 610 Back(); 610 611 return; -
trunk/src/org/expeditee/gui/FrameIO.java
r156 r162 5 5 import java.io.File; 6 6 import java.io.FileInputStream; 7 import java.io.FileNotFoundException; 7 8 import java.io.FileOutputStream; 8 9 import java.io.FileReader; … … 10 11 import java.io.IOException; 11 12 import java.sql.Time; 13 import java.util.Collection; 12 14 import java.util.HashMap; 15 import java.util.LinkedList; 13 16 14 17 import org.expeditee.agents.ExistingFramesetException; … … 239 242 } 240 243 244 public static Collection<String> searchFrame(String frameName, 245 String pattern, String path) { 246 String fullPath = null; 247 if (path == null) { 248 for (String possiblePath : UserSettings.FrameDirs) { 249 fullPath = getFrameFullPathName(possiblePath, frameName); 250 if (fullPath != null) 251 break; 252 } 253 } else { 254 fullPath = getFrameFullPathName(path, frameName); 255 assert(fullPath != null); 256 } 257 // If the frame was not located return null 258 if (fullPath == null) 259 return null; 260 Collection<String> results = new LinkedList<String>(); 261 // Open the file and search the text items 262 try { 263 BufferedReader reader = new BufferedReader(new FileReader(fullPath)); 264 String next; 265 while (reader.ready() && ((next = reader.readLine()) != null)) { 266 if (next.startsWith("T")) { 267 String toSearch = next.substring(2); 268 if (toSearch.toLowerCase().matches(pattern)) 269 results.add(toSearch); 270 } 271 } 272 } catch (FileNotFoundException e) { 273 e.printStackTrace(); 274 return null; 275 } catch (IOException e) { 276 e.printStackTrace(); 277 } 278 return results; 279 } 280 241 281 private static Frame LoadFrame(String path, String frameName) { 242 282 String fullPath = getFrameFullPathName(path, frameName); … … 349 389 // if we did not find another Frame then this one must be the last one 350 390 // in the frameset 351 MessageBay 352 .displayMessageOnce("This is the last frame in the frameset"); 391 MessageBay.displayMessageOnce("This is the last frame in the frameset"); 353 392 return null; 354 393 } … … 421 460 * @param toDelete 422 461 * The Frame to be deleted 423 * @return The name the deleted frame was changed to, or null if the delete failed 462 * @return The name the deleted frame was changed to, or null if the delete 463 * failed 424 464 */ 425 465 public static String DeleteFrame(Frame toDelete) throws IOException, … … 468 508 ff.close(); 469 509 470 if ( del.delete()){510 if (del.delete()) { 471 511 return toDelete.getName(); 472 512 } 473 513 474 514 return null; 475 515 } … … 552 592 i.setLink(null); 553 593 } 554 594 555 595 // do auto shrinking of the title IF not in twin frames mode 556 596 Item titleItem = template.getTitleItem(); … … 676 716 boolean checkBackup) { 677 717 678 // TODO When loading a frame maybe append onto the event history too- with a 718 // TODO When loading a frame maybe append onto the event history too- 719 // with a 679 720 // break to indicate the end of a session 680 721 681 if (toSave == null || !toSave.hasChanged() || toSave.isSaved()){722 if (toSave == null || !toSave.hasChanged() || toSave.isSaved()) { 682 723 SessionStats.NewFrameSession(); 683 724 return ""; … … 691 732 692 733 // Dont save if the frame is protected and it exists 693 if (checkBackup 694 && toSave.isReadOnly()) { 734 if (checkBackup && toSave.isReadOnly()) { 695 735 _Cache.remove(toSave.getName().toLowerCase()); 696 736 SessionStats.NewFrameSession(); … … 776 816 toSave.setActiveTime(activeTime); 777 817 778 // int oldMode = FrameGraphics.getMode();779 // if (oldMode != FrameGraphics.MODE_XRAY)780 // 818 // int oldMode = FrameGraphics.getMode(); 819 // if (oldMode != FrameGraphics.MODE_XRAY) 820 // FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true); 781 821 writer.writeFrame(toSave); 782 // FrameGraphics.setMode(oldMode, true);822 // FrameGraphics.setMode(oldMode, true); 783 823 toSave.setSaved(); 784 824 if (inc) { -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r156 r162 797 797 refreshHighlights(); 798 798 } 799 FrameGraphics.requestRefresh(true); 799 800 return; 800 801 // otherwise, anchor the items -
trunk/src/org/expeditee/simple/ExpediteeJEP.java
r161 r162 13 13 14 14 public class ExpediteeJEP extends JEP { 15 Observer observer = new Observer() { 16 private String _attribute = ""; 17 18 public void update(Observable ob, Object o) { 19 _attribute = ((Variable) o).getName() + ": "; 20 } 21 22 @Override 23 public String toString() { 24 return _attribute; 25 } 26 }; 15 Observer observer = null; 27 16 28 17 public ExpediteeJEP() { … … 33 22 setAllowAssignment(true); 34 23 setAllowUndeclared(true); 24 resetObserver(); 35 25 } 36 26 37 public void addObserver() { 27 public void resetObserver() { 28 observer = new Observer() { 29 private String _attribute = ""; 30 31 public void update(Observable ob, Object o) { 32 _attribute = ((Variable) o).getName(); 33 } 34 35 @Override 36 public String toString() { 37 return _attribute; 38 } 39 }; 38 40 getSymbolTable().addObserver(observer); 39 41 getSymbolTable().addObserverToExistingVariables(observer); … … 48 50 nf.setMinimumFractionDigits(0); 49 51 nf.setMaximumFractionDigits(15); 50 return observer.toString() + nf.format(result);52 return observer.toString()+ ": " + nf.format(result); 51 53 } 52 54 … … 63 65 } 64 66 } 67 68 public String getNewVariable() { 69 return observer.toString(); 70 } 65 71 }
Note:
See TracChangeset
for help on using the changeset viewer.