Changeset 161
- Timestamp:
- 07/25/08 16:37:58 (16 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r160 r161 29 29 import org.expeditee.items.Item; 30 30 import org.expeditee.items.Text; 31 import org.expeditee.simple.ExpediteeJEP; 31 32 import org.expeditee.stats.CometStats; 32 33 import org.expeditee.stats.SessionStats; … … 660 661 if (toCalculate instanceof Text) { 661 662 Text text = (Text) toCalculate; 662 org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP(); 663 myParser.addStandardFunctions(); 664 myParser.addStandardConstants(); 665 myParser.setImplicitMul(true); 666 667 Observer observer = new Observer() { 668 private String _attribute = ""; 669 670 public void update(Observable ob, Object o) { 671 _attribute = ((Variable) o).getName() + ": "; 672 } 673 674 @Override 675 public String toString() { 676 return _attribute; 677 } 678 }; 679 680 // Check for variables 681 for (Text t : frame.getTextItems()) { 682 AttributeValuePair avp = AttributeUtils.getPair(t.getText()); 683 if (avp != null) { 684 myParser.addVariable(avp.getAttribute(), avp 685 .getDoubleValue()); 686 } 663 ExpediteeJEP myParser = new ExpediteeJEP(); 664 myParser.addVariables(frame); 665 String linkedFrame = toCalculate.getAbsoluteLink(); 666 if (linkedFrame != null) { 667 myParser.addVariables(FrameIO.LoadFrame(linkedFrame)); 687 668 } 688 689 myParser.getSymbolTable().addObserver(observer); 690 myParser.setAllowAssignment(true); 691 myParser.setAllowUndeclared(true); 669 myParser.addObserver(); 692 670 693 671 // Do the calculation 694 672 Node node = myParser.parseExpression(text.getText()); 695 673 if (node == null) { 696 for (String s : myParser.getErrorInfo().split("\n")) { 697 MessageBay.errorMessage(s); 674 MessageBay.errorMessage(myParser.getErrorInfo().replace("\n", 675 "")); 676 } else { 677 String result = myParser.getResult(); 678 if (result == null) { 679 MessageBay.errorMessage(myParser.getErrorInfo().replace("\n", 680 "")); 681 } else { 682 text.setText(result); 683 if (text.isFloating()) { 684 text.setPosition(FrameMouseActions.MouseX, 685 FrameMouseActions.MouseY); 686 FrameMouseActions.resetOffset(); 687 } 698 688 } 699 } else {700 Double result = myParser.getValue();701 NumberFormat nf = NumberFormat.getInstance();702 nf.setMinimumFractionDigits(0);703 nf.setMaximumFractionDigits(15);704 text.setText(observer.toString() + nf.format(result));705 text.setPosition(FrameMouseActions.MouseX,706 FrameMouseActions.MouseY);707 FrameMouseActions.resetOffset();708 689 } 709 690 -
trunk/src/org/expeditee/actions/Simple.java
r156 r161 44 44 import org.expeditee.simple.BelowMinParametreCountException; 45 45 import org.expeditee.simple.Context; 46 import org.expeditee.simple.ExpediteeJEP; 46 47 import org.expeditee.simple.IncorrectParametreCountException; 47 48 import org.expeditee.simple.IncorrectTypeException; … … 59 60 import org.expeditee.stats.AgentStats; 60 61 import org.expeditee.stats.SessionStats; 62 import org.nfunk.jep.Node; 61 63 62 64 public class Simple implements Runnable { … … 313 315 t.start(); 314 316 } else { 315 if (!testSuite.runSuite()) {317 if (!testSuite.runSuite()) { 316 318 throw new RuntimeException(frameset + " failed"); 317 319 } … … 780 782 // Check if the user wants to display a message 781 783 // Check for set statements 782 } else if (tokens[0].startsWith("issearchpatternvalid")) { 784 } else if (tokens[0].startsWith("calculatestring")) { 785 assertMinParametreCount(tokens, 2); 786 String toCalculate = context.getPrimitives().getStringValue(tokens[1]); 787 boolean result = true; 788 ExpediteeJEP myParser = new ExpediteeJEP(); 789 //Add the variables in the system 790 context.getPrimitives().addToParser(myParser); 791 Node equation = myParser.parseExpression(toCalculate); 792 //TODO get the answer 793 794 } else if (tokens[0].startsWith("calculateitem")) { 795 assertMinParametreCount(tokens, 1); 796 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 797 Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue(); 798 Frame frame = null; 799 if(tokens.length > 2){ 800 assertVariableType(tokens[2], 2, SPointer.framePrefix); 801 frame = (Frame)context.getPointers().getVariable(tokens[2]).getValue(); 802 } 803 Misc.calculate(frame, item); 804 }else if (tokens[0].startsWith("issearchpatternvalid")) { 783 805 assertExactParametreCount(tokens, 2); 784 806 boolean result = true; … … 901 923 SearchAgent searchAgent = new SearchTree(); 902 924 _agent = searchAgent; 903 searchAgent.initialise(null, null, topFrameName, resultsFrameset,904 re placementString, pattern);925 searchAgent.initialise(null, null, topFrameName, 926 resultsFrameset, replacementString, pattern); 905 927 searchAgent.run(); 906 928 _agent = null; … … 964 986 Item valueItem = null; 965 987 // Begin the search 966 for (Text text : targetFrame.getTextItems()) {988 for (Text text : targetFrame.getTextItems()) { 967 989 String s = text.getText().toLowerCase(); 968 990 … … 1271 1293 context.getPointers().setObject(frameTitleVar, 1272 1294 frame.getTitleItem()); 1273 } else if (tokens[0].startsWith("getframefilepath")) {1295 } else if (tokens[0].startsWith("getframefilepath")) { 1274 1296 assertExactParametreCount(tokens, 2); 1275 1297 String frameName = context.getPrimitives().getStringValue( … … 1999 2021 } else 2000 2022 context.readFrame(frameName, frameVar, null); 2001 } else if (tokens[0].equals("exitexpeditee")) {2023 } else if (tokens[0].equals("exitexpeditee")) { 2002 2024 Browser._theBrowser.exit(); 2003 } else if (tokens[0].equals("readkbdcond")) {2025 } else if (tokens[0].equals("readkbdcond")) { 2004 2026 2005 2027 String nextCharVarName = DEFAULT_CHAR; … … 2483 2505 assertExactParametreCount(tokens, 0); 2484 2506 FrameMouseActions.leftButton(); 2485 // DisplayIO.clickMouse(InputEvent.BUTTON1_MASK);2507 // DisplayIO.clickMouse(InputEvent.BUTTON1_MASK); 2486 2508 } else if (tokens[0].equals("clickmiddlebutton")) { 2487 2509 assertExactParametreCount(tokens, 0); 2488 2510 FrameMouseActions.middleButton(); 2489 // DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);2511 // DisplayIO.clickMouse(InputEvent.BUTTON2_MASK); 2490 2512 } else if (tokens[0].equals("clickrightbutton")) { 2491 2513 assertExactParametreCount(tokens, 0); 2492 2514 FrameMouseActions.rightButton(); 2493 // DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);2515 // DisplayIO.clickMouse(InputEvent.BUTTON3_MASK); 2494 2516 } else if (tokens[0].equals("repaint")) { 2495 2517 assertExactParametreCount(tokens, 0); -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r156 r161 19 19 20 20 import org.expeditee.actions.Actions; 21 import org.expeditee.actions.Misc; 21 22 import org.expeditee.actions.NavigationActions; 22 23 import org.expeditee.actions.Simple; … … 380 381 case KeyEvent.VK_ESCAPE: 381 382 // Do escape after control so Ctl+Escape does not perform DropDown 382 functionKey(FunctionKey.DropDown, false, false); 383 functionKey(FunctionKey.DropDown, e.isShiftDown(), e 384 .isControlDown()); 383 385 SessionStats.Escape(); 384 386 break; … … 588 590 int distance = isShiftDown ? 5 : 20; 589 591 switch (key) { 592 case KeyEvent.VK_TAB: 593 Misc.calculate(DisplayIO.getCurrentFrame(), FrameUtils.getCurrentItem()); 594 break; 595 case KeyEvent.VK_ESCAPE: 596 // Do escape after control so Ctl+Escape does not perform DropDown 597 functionKey(FunctionKey.DropDown, isShiftDown, true); 598 SessionStats.Escape(); 599 break; 590 600 case KeyEvent.VK_1: 591 601 FrameMouseActions.leftButton(); … … 896 906 // get whatever the user is pointing at 897 907 Item on = FrameUtils.getCurrentItem(); 898 908 899 909 // check for enclosed mode 900 910 if (on == null && key.ordinal() < FunctionKey.AudienceMode.ordinal()) { 901 911 Collection<Item> enclosed = FrameUtils.getCurrentItems(on); 902 912 903 913 if (enclosed != null && enclosed.size() > 0) { 904 914 // ensure only one dot\line is present in the list … … 961 971 switch (key) { 962 972 case DropDown: 973 if (isShiftDown || isControlDown) { 974 Misc.calculate(DisplayIO.getCurrentFrame(), on); 975 } 963 976 Drop(on); 964 977 return; -
trunk/src/org/expeditee/simple/Primitives.java
r115 r161 139 139 // If one of them is a real and one is an integer then do a numeric 140 140 // comparison 141 if ((var1.startsWith(SReal.prefix) || var2 142 .startsWith(SReal.prefix))) { 141 if ((var1.startsWith(SReal.prefix) || var2.startsWith(SReal.prefix))) { 143 142 double v1 = getDoubleValue(var1); 144 143 double v2 = getDoubleValue(var2); … … 182 181 /** 183 182 * Adds two variables to gether returning the value in the first. 183 * 184 184 * @param toSet 185 185 * @param amount … … 265 265 setValue(answer, new SBoolean(!getVariable(variable).booleanValue())); 266 266 } 267 268 public void addToParser(ExpediteeJEP myParser) { 269 for (SPrimitive var : list_) { 270 try { 271 Double value = var.doubleValue(); 272 myParser.addVariable(var.getName(), value); 273 } catch (Exception e) { 274 } 275 } 276 } 267 277 }
Note:
See TracChangeset
for help on using the changeset viewer.