COM 3362 Winter 2002 Hw 3: Due Jan. 29, 2002 Mouse Problem: From OOP to AOP Designed and tested by Therapon Skotiniotis The goal of the exercise is to show that OOP does need an extension to tackle the problem of tangling. AOP being a technology that gives a solution. The program that you have to write requires a parser for parsing the mouse actions. It is recommended that you use DemeterJ to generate a parser. When you write your class dictionary you are allowed to adjust the the language, if needed, to make it easily expressible by a class dictionary (the language should be LL(1)). The two students who have not taken COM 3360 should borrow a parser from a COM 3360 student with proper acknowledgement. Please can the first COM 3360 student who has the cd send it to me and I will post the parser. PART I: ------- You are asked to implement the actions of a mouse Simulator. In this exercise we have 3 types of mice: 1) Mouse (2-button mouse) 2) ThreeButton (3-button mouse) 3) WheelMouse (2-buttons and a "wheel" in the middle) The development will be iterative. First you are asked to implement the Mouse class with the following interface : class Mouse{ Coordinates curr_position; Button left; Button right; Integer buffer; public void LeftClick(int x, int y){ } public void LeftPress(int x, int y){ } public void LeftRelease(int x, int y){ } public void RightClick(int x, int y){ } } where the classes Coordinate and Button have the following interface: class Coordinates { int x; int y; public void setX(int new_x){ } public void setY(int new_y){ } public int getX(){ } public int getY(){ } } class Button { } Operations : ----------- LeftClick updates the current position To the values x & y that are passed as arguments to the method LeftPress marks the position (x,y) passed as arguments, as the starting place of a rectangle whose area will be stored inside buffer. LeftRelease marks the end position of the rectangle whose area will be stored in the buffer. The buffer holds the quadrilateral area denoted by the points (x1,y1) (x2,y2). (x1,y1) are the arguments to the LeftPress method and (x2,y2) are the arguments to the LeftRelease method call. RightClick checks to see that the buffer value is not zero, and if it is not zero it simply outputs the area of the buffer. If it is zero then a message should be displayed that the buffer is empty. Then we move to the ThreeButton mouse which has the interface : class ThreeButton extends Mouse { Button middle; public void MiddleClick(int x, int y){ } } The ThreeButton mouse extends the simple Mouse class and introduces the 'middle' button. On 'MiddleClick' a pop-up menu should appear at position x,y that are given as arguments to MiddleClick. Finally the WheelMouse : class WheelMouse extends Mouse { Button wheel; public void WheelClick(int x, int y){ public void WheelRollup(){ } public void WheelRolldown(){ } } The WheelMouse extends the simple Mouse and adds a "Wheel" that, if clicked using the WheelClick method, then it behaves as a ThreeButton mouse middle button. Hoewever it also provides WheelRollup that moves your current position 10 points up in the horizontal and WheelRolldown that moves your current position 10 points down in the horizontal direction. PART II ------- You are now asked to implement, using the same class structure as PART I, the double click operation. This is simply for testing purposes so all you have to do is simply report back when the same button of any of the 3 different mice is pressed twice in consecutive order. This logging feature is to only track the following operations for double clicks: Mouse : LeftClick and RightClick ( exclude press and releases ) ThreeButton: no tracking WheelMouse : WheelClick and LeftClick ( exclude press and releases ) Alter your code so that the above logging features are implemented. You are not allowed to use anything but OOP techniques to achieve this behavior. Applying the visitor pattern using DJ counts as an OO technique, although it is also AOP. PART III -------- Repeat PART I and PART II using the same class structure as defined in PART I and PART II this time using AOSD techniques with AspectJ. Try to design your solution so that you end up with less tangled code, and so that you can achieve any alteration with minimal code changes to your original design. Parsing ------- For the purpose of testing use a very simple grammar that can be used to run tests on your code. Sample test files : twobutton left click at (2,2) twobutton left press at (10,10) twobutton left release at (20,20) twobutton right click at (20,20) threebutton left click at (2,2) threebutton left press at (10,10) threebutton left release at (20,20) threebutton right click at (20,20) threebutton middle click at (4,4) wbutton left click at (2,2) wbutton left press at (10,10) wbutton left release at (20,20) wbutton right click at (20,20) wbutton wheel click at (4,4) wbutton wheel roll up at () wbutton wheel roll down at () To denote the mouse button use : twobutton threebutton wbutton Button Names are : left right wheel Operations are : click press release roll up roll down Coordinates are : at (INT,INT)