├── .classpath ├── .gitignore ├── .project ├── .travis.yml ├── README.md ├── build.xml ├── c.xml ├── images ├── addCursor.png ├── arrow.png ├── arrowselected.png ├── c.png ├── cselected.png ├── dot.png ├── dotselected.png ├── inputbox.png ├── inputboxselected.png ├── line.png ├── lineselected.png ├── outputbox.png ├── outputboxselected.png ├── redo.png └── undo.png ├── lib ├── hamcrest-core-1.3.jar └── junit-4.12.jar └── src ├── actions ├── AddComponentActions.java ├── AddDataDisplayBoxAction.java ├── AddDataDisplayBoxActionTest.java ├── AddDataInputBoxAction.java ├── AddDataInputBoxActionTest.java ├── AddHaskellComponent.java ├── AddHaskellEvaluatorComponentAction.java ├── AddInstanceMethodAction.java ├── AddInstanceOperationAction.java ├── AddLazyJavaClassAction.java ├── AddLazyJavaConstructorAction.java ├── AddLazyJavaFieldsComponentAction.java ├── AddLazyJavaMethodComponentAction.java ├── AddTextBoxAction.java ├── ConstructDataLineSegmentAction.java ├── ConstructDataLineSegmentActionTest.java ├── ConstructLineSegmentAction.java ├── ConstructLineSegmentActionTest.java ├── DialogInputChecker.java ├── DialogInputCheckerTest.java ├── EditAnnotationSizeAction.java ├── ExecuteInstanceConstructorAction.java ├── ExecuteInstanceMethodAction.java ├── ExecuteScriptAction.java ├── FileOpen.java ├── FileSaveAs.java ├── GeneratePolygonSourceJava.java ├── InputDataForDataInputBoxAction.java ├── MenuBarPaintAction.java ├── RedoAction.java ├── RedoActionTest.java ├── RemoveAnnotationAction.java ├── RemoveAnnotationActionTest.java ├── RemovePaintComponent.java ├── ShowHistory.java ├── UndoAction.java ├── UndoActionTest.java ├── UpdateDataDisplayBoxAction.java ├── ZoomAction.java ├── ZoomInAction.java ├── ZoomOutAction.java ├── edit │ └── undoredo │ │ ├── SharedUndoRedoActionManager.java │ │ ├── SharedUndoRedoActionManagerDelegate.java │ │ └── UndoRedoableInterface.java ├── global │ ├── ActionName.java │ ├── GlobalPaintAction.java │ ├── GlobalPaintActionExecuter.java │ └── globalactions │ │ ├── AddAnnotationGlobalAction.java │ │ ├── AddAnnotationGlobalActionTest.java │ │ ├── AddDataDisplayBoxGlobalAction.java │ │ ├── AddDataDisplayBoxGlobalActionTest.java │ │ ├── AddHaskellComponentGlobalAction.java │ │ ├── AddHaskellComponentGlobalActionTest.java │ │ ├── AddHaskellEvaluatorComponentGlobalAction.java │ │ ├── AddHaskellEvaluatorComponentGlobalActionTest.java │ │ ├── AddInstanceMethodGlobalAction.java │ │ ├── AddInstanceMethodGlobalActionTest.java │ │ ├── AddInstanceOperationGlobalAction.java │ │ ├── AddInstanceOperationGlobalActionTest.java │ │ ├── AddLazyJavaClassGlobalAction.java │ │ ├── AddLazyJavaClassGlobalActionTest.java │ │ ├── AddLazyJavaConstructorGlobalAction.java │ │ ├── AddLazyJavaConstructorGlobalActionTest.java │ │ ├── AddLazyJavaFieldsComponentGlobalAction.java │ │ ├── AddLazyJavaFieldsComponentGlobalActionTest.java │ │ ├── AddLazyJavaMethodComponentGlobalAction.java │ │ ├── AddLazyJavaMethodComponentGlobalActionTest.java │ │ ├── AddTextBoxGlobalAction.java │ │ ├── AddTextBoxGlobalActionTest.java │ │ ├── ConstructDataLineSegmentGlobalAction.java │ │ ├── ConstructDataLineSegmentGlobalActionTest.java │ │ ├── ConstructLineSegmentGlobalAction.java │ │ ├── ConstructLineSegmentGlobalActionTest.java │ │ ├── EditAnnotationSizeGlobalAction.java │ │ ├── EditAnnotationSizeGlobalActionTest.java │ │ ├── EditRedoGlobalAction.java │ │ ├── EditUndoActionTest.java │ │ ├── EditUndoGlobalAction.java │ │ ├── ExecuteInstanceConstructorGlobalAction.java │ │ ├── ExecuteInstanceMethodGlobalAction.java │ │ ├── ExecuteInstanceMethodGlobalActionTest.java │ │ ├── ExecuteScriptGlobalAction.java │ │ ├── ExecuteScriptGlobalActionTest.java │ │ ├── FileOpenAndSaveGlobalActionTest.java │ │ ├── FileOpenGlobalAction.java │ │ ├── FileSaveAsGlobalAction.java │ │ ├── GeneratePolygonSourceJavaGlobalAction.java │ │ ├── GeneratePolygonSourceJavaGlobalActionTest.java │ │ ├── NameGlobalAction.java │ │ ├── RedoActionGlobalTest.java │ │ ├── RemoveAnnotationGlobalAction.java │ │ ├── RemoveAnnotationGlobalActionTest.java │ │ ├── SingleInstanceOperationGlobalAction.java │ │ └── UpdateDataInputBoxGlobalAction.java ├── menu │ ├── ActionsMenuBar.java │ ├── ActionsMenuBarTitles.java │ └── PaintActionMenuItem.java └── singleinstanceoperations │ ├── AddAnnotationAction.java │ ├── SetPointSizeOperation.java │ ├── SingleInstanceOperation.java │ └── UpdateFontSizeOperation.java ├── buttons ├── CustomJButton.java └── ToolButton.java ├── classpathutil ├── ClassFinder.java ├── ClassSearch.java ├── ClassSearchTest.java └── Visitor.java ├── file └── PanelIO.java ├── paintcomponents ├── LineSegment.java ├── NoConnectingLineSegmentException.java ├── PaintComponent.java ├── RectanglePaintComponent.java ├── SimplePoint.java ├── TextPaintComponent.java ├── XMLEncodingUtilForPaintComponents.java ├── annotations │ ├── PaintComponentAnnotation.java │ └── TextAnnotation.java ├── data │ ├── DataDisplayPaintComponent.java │ ├── DataFromPoint.java │ ├── DataFromPointDataProvider.java │ ├── DataFromPointNoDataProviderException.java │ ├── DataFromPointProviderCannotProvideDataException.java │ ├── DataInputTextfieldPaintComponent.java │ ├── DataLineSegment.java │ ├── DataTextIOPaintComponent.java │ ├── DataTextPaintComponent.java │ └── DataToPoint.java ├── haskell │ ├── EvaluateHaskellPaintComponent.java │ ├── HaskellEngine.java │ ├── HaskellExpressionPaintComponent.java │ ├── HaskellTypeParser.java │ └── ParenthesisParser.java └── java │ ├── interactive │ ├── ClassConstructorPaintComponent.java │ ├── InstanceOperationComponent.java │ └── MethodPaintComponent.java │ └── lazy │ ├── ClassConstructorPaintComponent.java │ ├── ClassPaintComponent.java │ ├── FieldsPaintComponent.java │ └── MethodPaintComponent.java ├── painttools ├── toolbar │ ├── ToolBar.java │ └── ToolBarListener.java └── tools │ ├── ActionToolsInterface.java │ ├── AddClassTool.java │ ├── AddInputBoxTool.java │ ├── AddMethodTool.java │ ├── AddOutputBoxTool.java │ ├── DefaultPaintTool.java │ ├── DotTool.java │ ├── LineTool.java │ ├── PaintToolsInterface.java │ ├── RemoveComponentTool.java │ ├── SelectTool.java │ └── SelectionToolListener.java ├── script ├── ComponentMap.java ├── ExecutionErrorException.java ├── Interpreter.java ├── InterpreterAddActions.java ├── InterpreterAddData.java ├── InterpreterAddHaskell.java ├── InterpreterAddLazy.java ├── InterpreterAddLazyJavaClass.java ├── InterpreterConstructActions.java ├── InterpreterEditActions.java ├── InterpreterFileActions.java ├── InterpreterGeneratePolygonAction.java ├── InterpreterNameAction.java ├── InterpreterRemoveAction.java ├── InterpreterSelectAction.java ├── InterpreterUpdateActions.java ├── Tokenizer.java └── TokenizerTest.java ├── settings └── Defaults.java ├── typesystem ├── HaskellType.java ├── JavaType.java └── Type.java └── ui ├── JavaSketchPad.java ├── KeyHandler.java ├── PaintPanel.java ├── ShortcutHandler.java ├── cursor └── CustomCursors.java ├── general ├── InputManager.java └── InputManagerDelegate.java ├── helper ├── classsearch │ ├── ClassSearchFrame.java │ ├── ClassSearchFrameDelegateInterface.java │ └── ClassSearchFrameTest.java ├── historyui │ ├── TableUIDataObject.java │ ├── TableUITemplate.java │ ├── TableUITemplateInterface.java │ ├── TableUITest.java │ └── undoredoLog │ │ └── UndoredoDialog.java └── methodinput │ ├── MethodInputFrame.java │ ├── MethodSearch.java │ └── MethodSearchFrameDelegateInterface.java └── icons ├── CustomIcons.java ├── LeftArrow.java └── LineToolIcon.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | /bin/ 3 | .DS_Store 4 | .settings 5 | .settings/* 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | JavaSketchPad 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | 5 | before_script: 6 | - "export DISPLAY=:99.0" 7 | - "sh -e /etc/init.d/xvfb start" 8 | - sleep 3 # give xvfb some time to start 9 | 10 | notifications: 11 | email: false 12 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /images/addCursor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/addCursor.png -------------------------------------------------------------------------------- /images/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/arrow.png -------------------------------------------------------------------------------- /images/arrowselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/arrowselected.png -------------------------------------------------------------------------------- /images/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/c.png -------------------------------------------------------------------------------- /images/cselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/cselected.png -------------------------------------------------------------------------------- /images/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/dot.png -------------------------------------------------------------------------------- /images/dotselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/dotselected.png -------------------------------------------------------------------------------- /images/inputbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/inputbox.png -------------------------------------------------------------------------------- /images/inputboxselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/inputboxselected.png -------------------------------------------------------------------------------- /images/line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/line.png -------------------------------------------------------------------------------- /images/lineselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/lineselected.png -------------------------------------------------------------------------------- /images/outputbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/outputbox.png -------------------------------------------------------------------------------- /images/outputboxselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/outputboxselected.png -------------------------------------------------------------------------------- /images/redo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/redo.png -------------------------------------------------------------------------------- /images/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/images/undo.png -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UCSDOalads/JavaSketchPad/0e5dfe712ba27e90e8f30832dd7a8eb0bb5ffa14/lib/junit-4.12.jar -------------------------------------------------------------------------------- /src/actions/AddComponentActions.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | 5 | public class AddComponentActions extends MenuBarPaintAction{ 6 | 7 | protected int x; 8 | protected int y; 9 | 10 | public AddComponentActions(PaintPanel panel) { 11 | super(panel); 12 | 13 | setDefaultXY(); 14 | } 15 | 16 | /** 17 | * set the default point to the middle of paint panel 18 | */ 19 | public void setDefaultXY(){ 20 | x = panel.getWidth()/2; 21 | y = panel.getHeight()/2; 22 | 23 | } 24 | 25 | 26 | public void setX(int newX){ 27 | x = newX; 28 | } 29 | 30 | public void setY(int newY){ 31 | y = newY; 32 | } 33 | 34 | public void setXY(int newX, int newY){ 35 | x = newX; 36 | y = newY; 37 | } 38 | 39 | @Override 40 | public boolean canPerformAction() { 41 | // TODO Auto-generated method stub 42 | return false; 43 | } 44 | 45 | @Override 46 | public void performAction() { 47 | // TODO Auto-generated method stub 48 | 49 | } 50 | 51 | @Override 52 | public String locationString() { 53 | // TODO Auto-generated method stub 54 | return null; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/actions/AddDataDisplayBoxAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import actions.edit.undoredo.SharedUndoRedoActionManager; 4 | import actions.edit.undoredo.UndoRedoableInterface; 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.AddDataDisplayBoxGlobalAction; 8 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 9 | import actions.menu.ActionsMenuBarTitles; 10 | import paintcomponents.data.DataDisplayPaintComponent; 11 | import ui.PaintPanel; 12 | import ui.general.InputManager; 13 | import ui.general.InputManagerDelegate; 14 | 15 | public class AddDataDisplayBoxAction extends AddComponentActions { 16 | 17 | public AddDataDisplayBoxAction(PaintPanel panel) { 18 | super(panel); 19 | } 20 | 21 | @Override 22 | public boolean canPerformAction() { 23 | 24 | return true; 25 | } 26 | 27 | @Override 28 | public void performAction() { 29 | 30 | AddDataDisplayBoxGlobalAction associatedAction = (AddDataDisplayBoxGlobalAction) ActionName.ADD_DATA_DISPLAY_BOX 31 | .getAssociatedAction(); 32 | associatedAction.setDisplayString("Data Display"); 33 | associatedAction.setX(x); 34 | associatedAction.setY(y); 35 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 36 | 37 | } 38 | 39 | @Override 40 | public String locationString() { 41 | return ActionsMenuBarTitles.Data().Display_Box().Add().toString(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/actions/AddDataDisplayBoxActionTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.data.DataDisplayPaintComponent; 9 | import ui.PaintPanel; 10 | 11 | /** 12 | * AddDataDisplayBoxAction tester 13 | * 14 | * @author Joe Helen test getPaintcomponents size. paintComponents goes from 0 15 | * to 1 when it performs the action. 16 | */ 17 | public class AddDataDisplayBoxActionTest { 18 | 19 | @Test 20 | public void test() { 21 | PaintPanel panel = new PaintPanel(); 22 | 23 | AddDataDisplayBoxAction action = new AddDataDisplayBoxAction(panel); 24 | 25 | // panel has 0 component 26 | assertEquals(0, panel.getPaintComponents().size()); 27 | 28 | action.performAction(); 29 | 30 | // after perform action, panel now has 1 component 31 | assertEquals(1, panel.getPaintComponents().size()); 32 | 33 | // check if the component is a DataDisplayPaintComponent 34 | assertTrue(panel.getPaintComponents().get(0) instanceof DataDisplayPaintComponent); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/actions/AddDataInputBoxAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import actions.edit.undoredo.SharedUndoRedoActionManager; 4 | import actions.edit.undoredo.UndoRedoableInterface; 5 | import actions.menu.ActionsMenuBarTitles; 6 | import paintcomponents.data.DataInputTextfieldPaintComponent; 7 | import ui.PaintPanel; 8 | 9 | public class AddDataInputBoxAction extends AddComponentActions { 10 | 11 | 12 | public AddDataInputBoxAction(PaintPanel panel) { 13 | super(panel); 14 | } 15 | 16 | 17 | @Override 18 | public boolean canPerformAction() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public void performAction() { 24 | DataInputTextfieldPaintComponent comp = new DataInputTextfieldPaintComponent("Data Input", x,y); 25 | 26 | // auto-select the component just created by the user 27 | if (panel.getSelectTool() != null) { 28 | panel.getSelectTool().clearSelection(); 29 | panel.getSelectTool().selectComponent(comp); 30 | } 31 | panel.addPaintComponent(comp); 32 | 33 | 34 | 35 | //push action to the manager 36 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() { 37 | 38 | @Override 39 | public void undoAction() { 40 | comp.remove(panel); 41 | panel.repaint(); 42 | } 43 | 44 | @Override 45 | public void redoAction() { 46 | panel.addPaintComponent(comp); 47 | panel.repaint(); 48 | 49 | } 50 | 51 | @Override 52 | protected String commandName() { 53 | return "add data inputBox"; 54 | } 55 | 56 | @Override 57 | protected String commandDescription() { 58 | // TODO Auto-generated method stub 59 | return "add a string input"; 60 | } 61 | }); 62 | panel.repaint(); 63 | } 64 | 65 | @Override 66 | public String locationString() { 67 | return ActionsMenuBarTitles.Data().Input_Box().Add().toString(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/actions/AddDataInputBoxActionTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.data.DataInputTextfieldPaintComponent; 9 | import ui.PaintPanel; 10 | 11 | public class AddDataInputBoxActionTest { 12 | 13 | @Test 14 | public void test() { 15 | PaintPanel panel = new PaintPanel(); 16 | 17 | AddDataInputBoxAction action = new AddDataInputBoxAction(panel); 18 | 19 | // panel has 0 component 20 | assertEquals(0, panel.getPaintComponents().size()); 21 | 22 | action.performAction(); 23 | 24 | // after perform action, panel now has 1 component 25 | assertEquals(1, panel.getPaintComponents().size()); 26 | 27 | // check if the component is a DataDisplayPaintComponent 28 | assertTrue(panel.getPaintComponents().get(0) instanceof DataInputTextfieldPaintComponent); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/actions/AddHaskellComponent.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.AddHaskellComponentGlobalAction; 8 | import actions.menu.ActionsMenuBarTitles; 9 | import ui.PaintPanel; 10 | 11 | public class AddHaskellComponent extends MenuBarPaintAction { 12 | 13 | public AddHaskellComponent(PaintPanel panel) { 14 | super(panel); 15 | } 16 | 17 | @Override 18 | public boolean canPerformAction() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public void performAction() { 24 | String expr = JOptionPane.showInputDialog("Please enter the haskell expression"); 25 | AddHaskellComponentGlobalAction associatedAction = (AddHaskellComponentGlobalAction) ActionName.ADD_HASKELL_EXPRESSION_COMPONENT 26 | .getAssociatedAction(); 27 | associatedAction.setHaskellExpression(expr); 28 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 29 | 30 | } 31 | 32 | @Override 33 | public String locationString() { 34 | return ActionsMenuBarTitles.Developer("Haskell/Add Haskell Expression").toString(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/actions/AddHaskellEvaluatorComponentAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | import actions.global.ActionName; 5 | import actions.global.GlobalPaintActionExecuter; 6 | import actions.global.globalactions.AddHaskellEvaluatorComponentGlobalAction; 7 | import actions.menu.ActionsMenuBarTitles; 8 | 9 | public class AddHaskellEvaluatorComponentAction extends MenuBarPaintAction { 10 | 11 | public AddHaskellEvaluatorComponentAction(PaintPanel panel) { 12 | super(panel); 13 | } 14 | 15 | @Override 16 | public boolean canPerformAction() { 17 | return true; 18 | } 19 | 20 | @Override 21 | public void performAction() { 22 | AddHaskellEvaluatorComponentGlobalAction associatedAction = (AddHaskellEvaluatorComponentGlobalAction) ActionName.ADD_HASKELL_EVALUATOR_COMPONENT 23 | .getAssociatedAction(); 24 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 25 | panel); 26 | } 27 | 28 | @Override 29 | public String locationString() { 30 | return ActionsMenuBarTitles.Developer("Haskell/Add Evaluator").toString(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/actions/AddInstanceMethodAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import actions.global.ActionName; 8 | import actions.global.GlobalPaintActionExecuter; 9 | import actions.global.globalactions.AddInstanceMethodGlobalAction; 10 | import actions.menu.ActionsMenuBarTitles; 11 | import paintcomponents.java.interactive.InstanceOperationComponent; 12 | import ui.PaintPanel; 13 | 14 | /** 15 | * These two are instance methods (Together not seperate) for operation. 16 | * 17 | * @author chenzb 18 | * 19 | */ 20 | public class AddInstanceMethodAction extends MenuBarPaintAction { 21 | 22 | public AddInstanceMethodAction(PaintPanel panel) { 23 | super(panel); 24 | } 25 | 26 | @Override 27 | public boolean canPerformAction() { 28 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 29 | return false; 30 | } 31 | if (panel.getSelectTool().getSelectedComponents() 32 | .get(0) instanceof InstanceOperationComponent) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | @Override 39 | public void performAction() { 40 | InstanceOperationComponent insComp = 41 | (InstanceOperationComponent)panel.getSelectTool(). 42 | getSelectedComponents().get(0); 43 | Method[] methods = insComp.getDisplayingClass().getMethods(); 44 | 45 | String desiaredConstructorIndex = JOptionPane.showInputDialog( 46 | "Please enter the index of the constructor you would like to use: \n\n\n" 47 | + getMethodsSelectionUI(methods)); 48 | 49 | //call DialogInputChecker to check input 50 | DialogInputChecker inputChecker = new DialogInputChecker(); 51 | if(inputChecker.isValidNumber(desiaredConstructorIndex, 0, methods.length -1)){ 52 | AddInstanceMethodGlobalAction associatedAction = 53 | (AddInstanceMethodGlobalAction) ActionName.ADD_INSTANCE_METHOD_ACTION 54 | .getAssociatedAction(); 55 | associatedAction.setInsComp(insComp); 56 | associatedAction.setMethodToSet(methods[Integer.parseInt(desiaredConstructorIndex)]); 57 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 58 | } 59 | } 60 | 61 | @Override 62 | public String locationString() { 63 | // TODO Auto-generated method stub 64 | return ActionsMenuBarTitles.Lazy().Add().Add_Instance_Method().toString(); 65 | } 66 | 67 | public String getMethodsSelectionUI(Method[] methods) { 68 | StringBuilder builder = new StringBuilder(); 69 | for (int i = 0; i < methods.length; i++) { 70 | Method constructor = methods[i]; 71 | builder.append(i + " : " + constructor.toString() + "\n"); 72 | } 73 | return builder.toString(); 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/actions/AddInstanceOperationAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import actions.global.ActionName; 8 | import actions.global.GlobalPaintActionExecuter; 9 | import actions.global.globalactions.AddInstanceOperationGlobalAction; 10 | import actions.menu.ActionsMenuBarTitles; 11 | import paintcomponents.java.lazy.ClassPaintComponent; 12 | import ui.PaintPanel; 13 | 14 | 15 | public class AddInstanceOperationAction extends MenuBarPaintAction { 16 | 17 | 18 | public AddInstanceOperationAction(PaintPanel panel) { 19 | super(panel); 20 | } 21 | 22 | @Override 23 | public boolean canPerformAction() { 24 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 25 | return false; 26 | } 27 | if (panel.getSelectTool().getSelectedComponents() 28 | .get(0) instanceof ClassPaintComponent) { 29 | return true; 30 | } 31 | return false; 32 | } 33 | 34 | @Override 35 | public void performAction() { 36 | ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool() 37 | .getSelectedComponents().get(0); 38 | Constructor[] cons = comp.getDisplayingClass().getConstructors(); 39 | 40 | String desiaredConstructorIndex = JOptionPane.showInputDialog( 41 | "Please enter the index of the constructor you would like to use: \n\n\n" 42 | + getConstructorsSelectionUI(cons)); 43 | //call inputChecker to check if input is valid 44 | DialogInputChecker inputChecker = new DialogInputChecker(); 45 | if(inputChecker.isValidNumber(desiaredConstructorIndex, 0, cons.length -1)){ 46 | AddInstanceOperationGlobalAction associatedAction = 47 | (AddInstanceOperationGlobalAction) ActionName.ADD_INSTANCE_OPERATION_ACTION 48 | .getAssociatedAction(); 49 | associatedAction.setConstructorToSet(cons[Integer.parseInt(desiaredConstructorIndex)]); 50 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 51 | } 52 | 53 | } 54 | 55 | public String getConstructorsSelectionUI(Constructor[] cons) { 56 | StringBuilder builder = new StringBuilder(); 57 | for (int i = 0; i < cons.length; i++) { 58 | Constructor constructor = cons[i]; 59 | builder.append(i + " : " + constructor.toString() + "\n"); 60 | } 61 | return builder.toString(); 62 | 63 | } 64 | 65 | @Override 66 | public String locationString() { 67 | return ActionsMenuBarTitles.Lazy().Add().Instance_Operation().toString(); 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/actions/AddLazyJavaClassAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | import ui.general.InputManager; 5 | import ui.general.InputManagerDelegate; 6 | import actions.global.ActionName; 7 | import actions.global.GlobalPaintActionExecuter; 8 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 9 | import actions.menu.ActionsMenuBarTitles; 10 | 11 | public class AddLazyJavaClassAction extends AddComponentActions { 12 | 13 | public AddLazyJavaClassAction(PaintPanel panel) { 14 | super(panel); 15 | } 16 | 17 | @Override 18 | public boolean canPerformAction() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public void performAction() { 24 | InputManager im = new InputManager(); 25 | im.askForClass(panel, new InputManagerDelegate() { 26 | 27 | @Override 28 | public void didFinishInput(Class input) { 29 | AddLazyJavaClassGlobalAction associatedAction = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 30 | .getAssociatedAction(); 31 | associatedAction.setClassToCreate(input); 32 | associatedAction.setCoord(x, y); 33 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 34 | 35 | } 36 | }); 37 | 38 | } 39 | 40 | @Override 41 | public String locationString() { 42 | return ActionsMenuBarTitles.Lazy().Add().Java_Class().toString(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/actions/AddLazyJavaConstructorAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import paintcomponents.java.lazy.ClassPaintComponent; 8 | import ui.PaintPanel; 9 | import actions.global.ActionName; 10 | import actions.global.GlobalPaintActionExecuter; 11 | import actions.global.globalactions.AddLazyJavaConstructorGlobalAction; 12 | import actions.menu.ActionsMenuBarTitles; 13 | 14 | public class AddLazyJavaConstructorAction extends MenuBarPaintAction { 15 | 16 | public AddLazyJavaConstructorAction(PaintPanel panel) { 17 | super(panel); 18 | } 19 | 20 | @Override 21 | public boolean canPerformAction() { 22 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 23 | return false; 24 | } 25 | if (panel.getSelectTool().getSelectedComponents().get(0) instanceof ClassPaintComponent) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | @Override 32 | public void performAction() { 33 | ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool() 34 | .getSelectedComponents().get(0); 35 | 36 | AddLazyJavaConstructorGlobalAction associatedAction = (AddLazyJavaConstructorGlobalAction) ActionName.ADD_LAZY_JAVA_CONSTRUCTOR_ACTION 37 | .getAssociatedAction(); 38 | associatedAction.setComponent(comp); 39 | String desiaredConstructorIndex = JOptionPane 40 | .showInputDialog("Please enter the index of the constructor you would like to use: \n\n\n" 41 | + getConstructorsSelectionUI(associatedAction 42 | .getConstructor())); 43 | //call DialogInputChecker to check input 44 | DialogInputChecker inputChecker = new DialogInputChecker(); 45 | if(inputChecker.isValidNumber(desiaredConstructorIndex)){ 46 | associatedAction.setConstructorIndex(Integer.parseInt(desiaredConstructorIndex)); 47 | associatedAction.setCoord(panel.getWidth() / 2, panel.getHeight() / 2); 48 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 49 | panel); 50 | } 51 | } 52 | 53 | @Override 54 | public String locationString() { 55 | return ActionsMenuBarTitles.Lazy().Add().Java_Constructor().toString(); 56 | } 57 | 58 | public String getConstructorsSelectionUI(Constructor[] cons) { 59 | StringBuilder builder = new StringBuilder(); 60 | for (int i = 0; i < cons.length; i++) { 61 | Constructor constructor = cons[i]; 62 | builder.append(i + " : " + constructor.toString() + "\n"); 63 | } 64 | return builder.toString(); 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/actions/AddLazyJavaFieldsComponentAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import paintcomponents.java.lazy.ClassPaintComponent; 4 | import ui.PaintPanel; 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.AddLazyJavaFieldsComponentGlobalAction; 8 | import actions.menu.ActionsMenuBarTitles; 9 | 10 | public class AddLazyJavaFieldsComponentAction extends MenuBarPaintAction { 11 | 12 | public AddLazyJavaFieldsComponentAction(PaintPanel panel) { 13 | super(panel); 14 | } 15 | 16 | // TODO 17 | // NOTE: I am copying from Constructor and Methods, consider refinement 18 | @Override 19 | public boolean canPerformAction() { 20 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 21 | return false; 22 | } 23 | if (panel.getSelectTool().getSelectedComponents().get(0) instanceof ClassPaintComponent) { 24 | return true; 25 | } 26 | return false; 27 | } 28 | 29 | @Override 30 | public void performAction() { 31 | ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool() 32 | .getSelectedComponents().get(0); 33 | 34 | AddLazyJavaFieldsComponentGlobalAction associatedAction = (AddLazyJavaFieldsComponentGlobalAction) ActionName.ADD_LAZY_JAVA_FIELDS_ACTION 35 | .getAssociatedAction(); 36 | associatedAction.setComponent(comp); 37 | associatedAction.setCoord(panel.getWidth() / 2, panel.getHeight() / 2); 38 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 39 | panel); 40 | } 41 | 42 | @Override 43 | public String locationString() { 44 | return ActionsMenuBarTitles.Lazy().Add().Java_Fields().toString(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/actions/AddLazyJavaMethodComponentAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import paintcomponents.java.lazy.ClassPaintComponent; 8 | import ui.PaintPanel; 9 | import ui.general.InputManager; 10 | import ui.general.InputManagerDelegate; 11 | import ui.helper.methodinput.MethodInputFrame; 12 | import actions.global.ActionName; 13 | import actions.global.GlobalPaintActionExecuter; 14 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 15 | import actions.global.globalactions.AddLazyJavaMethodComponentGlobalAction; 16 | import actions.menu.ActionsMenuBarTitles; 17 | 18 | public class AddLazyJavaMethodComponentAction extends MenuBarPaintAction { 19 | 20 | public AddLazyJavaMethodComponentAction(PaintPanel panel) { 21 | super(panel); 22 | } 23 | 24 | //TODO 25 | //NOTE: I am copying from Constructor, consider refinement 26 | @Override 27 | public boolean canPerformAction() { 28 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 29 | return false; 30 | } 31 | if (panel.getSelectTool().getSelectedComponents() 32 | .get(0) instanceof ClassPaintComponent) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | @Override 39 | public void performAction() { 40 | ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool().getSelectedComponents().get(0); 41 | 42 | InputManager im = new InputManager(); 43 | im.askForMethod(panel, new InputManagerDelegate() { 44 | 45 | @Override 46 | public void didFinishInput(Method input) { 47 | AddLazyJavaMethodComponentGlobalAction associatedAction = (AddLazyJavaMethodComponentGlobalAction) 48 | ActionName.ADD_LAZY_JAVA_METHOD_ACTION.getAssociatedAction(); 49 | associatedAction.setMethodComponent(comp); 50 | associatedAction.setMethod(input); 51 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 52 | } 53 | }, comp.getDisplayingClass()); 54 | } 55 | 56 | public String getMethodsSelectionUI(Method[] methods) { 57 | StringBuilder builder = new StringBuilder(); 58 | for (int i = 0; i < methods.length; i++) { 59 | Method constructor = methods[i]; 60 | builder.append(i + " : " + constructor.toString() + "\n"); 61 | } 62 | return builder.toString(); 63 | 64 | } 65 | @Override 66 | public String locationString() { 67 | return ActionsMenuBarTitles.Lazy().Add().Java_Method().toString(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/actions/AddTextBoxAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import actions.edit.undoredo.SharedUndoRedoActionManager; 6 | import actions.edit.undoredo.UndoRedoableInterface; 7 | import actions.global.ActionName; 8 | import actions.global.GlobalPaintActionExecuter; 9 | import actions.global.globalactions.AddDataDisplayBoxGlobalAction; 10 | import actions.global.globalactions.AddTextBoxGlobalAction; 11 | import actions.menu.ActionsMenuBarTitles; 12 | import paintcomponents.TextPaintComponent; 13 | import ui.PaintPanel; 14 | 15 | /** 16 | * add textbox to the panel 17 | * 18 | * @author Bingjie Zhou 19 | */ 20 | public class AddTextBoxAction extends MenuBarPaintAction { 21 | 22 | /** 23 | * constructor to create object 24 | * 25 | * @param panel 26 | * panel to add component on 27 | */ 28 | public AddTextBoxAction(PaintPanel panel) { 29 | super(panel); 30 | } 31 | 32 | /** 33 | * check whether can be performed or not 34 | */ 35 | @Override 36 | public boolean canPerformAction() { 37 | return true; 38 | } 39 | 40 | /** 41 | * add the text box component to panel 42 | */ 43 | @Override 44 | public void performAction() { 45 | String s = JOptionPane 46 | .showInputDialog("Please enter the text to display"); 47 | 48 | //call DialogInputChecker to check input 49 | DialogInputChecker inputChecker = new DialogInputChecker(); 50 | if(!inputChecker.isEmpty(s)){ 51 | AddTextBoxGlobalAction associatedAction = (AddTextBoxGlobalAction) ActionName.ADD_TEXT_BOX_ACTION 52 | .getAssociatedAction(); 53 | associatedAction.setDisplayString(s); 54 | associatedAction.setX(panel.getWidth() / 2); 55 | associatedAction.setY(panel.getHeight() / 2); 56 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 57 | panel); 58 | } 59 | } 60 | 61 | /** 62 | * return local strings in the text box 63 | */ 64 | @Override 65 | public String locationString() { 66 | return ActionsMenuBarTitles.Developer("Add/Text Box...").toString(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/actions/ConstructDataLineSegmentAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.util.ArrayList; 4 | 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.ConstructDataLineSegmentGlobalAction; 8 | import actions.menu.ActionsMenuBarTitles; 9 | import paintcomponents.PaintComponent; 10 | import paintcomponents.data.DataFromPoint; 11 | import paintcomponents.data.DataToPoint; 12 | import ui.PaintPanel; 13 | 14 | public class ConstructDataLineSegmentAction extends ConstructLineSegmentAction { 15 | 16 | public ConstructDataLineSegmentAction(PaintPanel panel) { 17 | super(panel); 18 | // TODO Auto-generated constructor stub 19 | } 20 | 21 | @Override 22 | public boolean canPerformAction() { 23 | if (super.canPerformAction() == false) 24 | return false; 25 | // we must connect from a DataFromPoint to DataToPoint 26 | // assume ConstructLineSegment is doing correctly, there is two 27 | // corrently selected points 28 | ArrayList comps = this.panel.getSelectTool() 29 | .getSelectedComponents(); 30 | // TODO IMPORTANT Generic Argument is erased, may cause unexpected 31 | // behavior when types dont match in the future 32 | if (comps.get(0) instanceof DataFromPoint 33 | && comps.get(1) instanceof DataToPoint) { 34 | // allow connection only when no segment has no existing connections 35 | // to the data 36 | if (((DataToPoint) comps.get(1)).getLineSegment() == null) { 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | @Override 44 | public void performAction() { 45 | 46 | ArrayList comps = this.panel.getSelectTool() 47 | .getSelectedComponents(); 48 | 49 | ConstructDataLineSegmentGlobalAction associatedAction = (ConstructDataLineSegmentGlobalAction) ActionName.CONSTRUCT_DATA_LINE_SEGMENT_ACTION 50 | .getAssociatedAction(); 51 | 52 | DataFromPoint fromPoint = (DataFromPoint) comps.get(0); 53 | DataToPoint toPoint = (DataToPoint) comps.get(1); 54 | 55 | associatedAction.setFromPoint((DataFromPoint) (comps.get(0))); 56 | associatedAction.setToPoint((DataToPoint) (comps.get(1))); 57 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 58 | 59 | panel.repaint(); 60 | 61 | } 62 | 63 | @Override 64 | public String locationString() { 65 | // TODO Auto-generated method stub 66 | return ActionsMenuBarTitles.Data().Construct().Line_Segment() 67 | .toString(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/actions/ConstructLineSegmentAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.util.ArrayList; 4 | 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.ConstructLineSegmentGlobalAction; 8 | import actions.menu.ActionsMenuBarTitles; 9 | import paintcomponents.LineSegment; 10 | import paintcomponents.PaintComponent; 11 | import paintcomponents.SimplePoint; 12 | import ui.PaintPanel; 13 | 14 | public class ConstructLineSegmentAction extends MenuBarPaintAction { 15 | 16 | public ConstructLineSegmentAction(PaintPanel panel) { 17 | super(panel); 18 | } 19 | 20 | @Override 21 | public boolean canPerformAction() { 22 | //get selected components 23 | ArrayList items = panel.getSelectTool().getSelectedComponents(); 24 | //only two points can be selected 25 | if(items.size() != 2) return false; 26 | //selected component must be of type point 27 | 28 | for (PaintComponent paintComponent : items) { 29 | if(!(paintComponent instanceof SimplePoint)){ 30 | return false; 31 | } 32 | } 33 | 34 | //check if line segment already exist 35 | // if exists, then it will not form a new line segment 36 | ArrayList components = panel.getPaintComponents(); 37 | LineSegment line = null; 38 | 39 | //get all paintComponents 40 | for(PaintComponent paintComponent : components) { 41 | if( paintComponent instanceof LineSegment ) { 42 | line = (LineSegment) paintComponent; 43 | //check front point and to point similarities 44 | if(items.get(0) == line.getFromPoint() && 45 | items.get(1) == line.getToPoint()) 46 | return false; 47 | if(items.get(1) == line.getFromPoint() && 48 | items.get(0) == line.getToPoint()) 49 | return false; 50 | } 51 | } 52 | 53 | //TODO Do not allow adding two line segments connecting the same point 54 | return true; 55 | 56 | } 57 | 58 | @Override 59 | public void performAction() { 60 | 61 | ArrayList items = panel.getSelectTool().getSelectedComponents(); 62 | 63 | ConstructLineSegmentGlobalAction associatedAction = 64 | (ConstructLineSegmentGlobalAction) 65 | ActionName.CONSTRUCT_LINE_SEGMENT_ACTION.getAssociatedAction(); 66 | 67 | associatedAction.setFromPoint((SimplePoint)(items.get(0))); 68 | associatedAction.setToPoint((SimplePoint)(items.get(1))); 69 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 70 | 71 | //change selection 72 | panel.getSelectTool().clearSelection(); 73 | panel.getSelectTool().selectComponent(associatedAction.getLineSeg()); 74 | 75 | panel.repaint(); 76 | } 77 | 78 | @Override 79 | public String locationString() { 80 | return ActionsMenuBarTitles.Developer("Construct/Line Segment").toString(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/actions/ConstructLineSegmentActionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package actions; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | import org.junit.Test; 9 | 10 | import actions.global.globalactions.ConstructLineSegmentGlobalAction; 11 | import paintcomponents.SimplePoint; 12 | import painttools.tools.SelectTool; 13 | import ui.PaintPanel; 14 | 15 | /** 16 | * 17 | * Test local line segment action. 18 | * @author Shanfeng Feng 19 | * 20 | */ 21 | public class ConstructLineSegmentActionTest { 22 | 23 | @Test 24 | public void test() { 25 | PaintPanel panel = new PaintPanel(); 26 | SelectTool selectTool = new SelectTool(panel); 27 | panel.setSelectTool(selectTool); 28 | 29 | ConstructLineSegmentAction action = new ConstructLineSegmentAction(panel); 30 | 31 | SimplePoint testFromPt = new SimplePoint(50,50); 32 | SimplePoint testToPt = new SimplePoint(50, 125); 33 | 34 | panel.addPaintComponent(testFromPt); 35 | panel.addPaintComponent(testToPt); 36 | 37 | //should be false, no points selected 38 | assertTrue(!action.canPerformAction()); 39 | testFromPt.select(selectTool); 40 | 41 | // should be false, only one point selected 42 | assertTrue(!action.canPerformAction()); 43 | testToPt.select(selectTool); 44 | 45 | // should be true, two points selected 46 | assertTrue(action.canPerformAction()); 47 | 48 | action.performAction(); 49 | 50 | // should be false, since segment already exist 51 | assertTrue(!action.canPerformAction()); 52 | 53 | // panel should now have 3 component 54 | assertEquals(3,panel.getPaintComponents().size()); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/actions/DialogInputChecker.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | /** 4 | * DialogInput Class check if a dialog input is valid 5 | * @author kaijiecai 6 | * 7 | */ 8 | public class DialogInputChecker { 9 | 10 | final int DECIMAL_BASE=10; 11 | public DialogInputChecker(){ 12 | 13 | } 14 | 15 | /** 16 | * check if input is valid 17 | * @param str String to be checked 18 | * @return true if it is not empty, false otherwise 19 | */ 20 | public boolean isEmpty(String str){ 21 | if(str == null || str.isEmpty()){ 22 | return true; 23 | } 24 | return false; 25 | } 26 | 27 | 28 | /** 29 | * check if str is a valid number input 30 | * @param str String to be checked 31 | * @return true if input is valid number, false otherwise 32 | */ 33 | public boolean isValidNumber(String str){ 34 | if(!isEmpty(str)){ 35 | try{ 36 | Integer.parseInt(str,DECIMAL_BASE); 37 | return true; 38 | } 39 | catch(Exception e){ 40 | } 41 | } 42 | return false; 43 | } 44 | 45 | /** 46 | * Check if str is a valid number input within min and max (inclusive) 47 | * @param str string to be checked 48 | * @param min 49 | * @param max 50 | * @return true if input is valid, false otherwise 51 | */ 52 | public boolean isValidNumber(String str, int min, int max){ 53 | if(isValidNumber(str)){ 54 | if(max >= min){ 55 | int num = Integer.parseInt(str,DECIMAL_BASE); 56 | if(num >= min && num <= max) 57 | return true; 58 | } 59 | } 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/actions/DialogInputCheckerTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | public class DialogInputCheckerTest { 9 | 10 | DialogInputChecker dialogInputChcker; 11 | 12 | @Before 13 | public void setUp(){ 14 | dialogInputChcker = new DialogInputChecker(); 15 | } 16 | @Test 17 | public void testIsEmpty() { 18 | //true cases 19 | assertTrue(dialogInputChcker.isEmpty("")); 20 | assertTrue(dialogInputChcker.isEmpty(null)); 21 | 22 | //false cases 23 | assertTrue(!dialogInputChcker.isEmpty("1")); 24 | assertTrue(!dialogInputChcker.isEmpty("sa")); 25 | } 26 | 27 | @Test 28 | public void testIsValidNumber(){ 29 | //true cases 30 | assertTrue(dialogInputChcker.isValidNumber("1")); 31 | assertTrue(dialogInputChcker.isValidNumber("10")); 32 | assertTrue(dialogInputChcker.isValidNumber("0")); 33 | assertTrue(dialogInputChcker.isValidNumber("-10")); 34 | assertTrue(dialogInputChcker.isValidNumber("1000")); 35 | 36 | 37 | //false cases 38 | assertTrue(!dialogInputChcker.isValidNumber("a")); 39 | assertTrue(!dialogInputChcker.isValidNumber("")); 40 | assertTrue(!dialogInputChcker.isValidNumber(null)); 41 | assertTrue(!dialogInputChcker.isValidNumber("abc")); 42 | 43 | } 44 | 45 | @Test 46 | public void testIsValidNumberRange(){ 47 | 48 | //true cases 49 | assertTrue(dialogInputChcker.isValidNumber("1",1,100)); 50 | assertTrue(dialogInputChcker.isValidNumber("10",0,10)); 51 | assertTrue(dialogInputChcker.isValidNumber("1",-1,100)); 52 | assertTrue(dialogInputChcker.isValidNumber("-1",-1,1)); 53 | 54 | 55 | //fasel cases 56 | assertTrue(!dialogInputChcker.isValidNumber("",0,100)); 57 | assertTrue(!dialogInputChcker.isValidNumber("a",0,100)); 58 | assertTrue(!dialogInputChcker.isValidNumber("-1",0,100)); 59 | assertTrue(!dialogInputChcker.isValidNumber("0",1,100)); 60 | 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/actions/ExecuteInstanceConstructorAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import actions.global.ActionName; 4 | import actions.global.GlobalPaintActionExecuter; 5 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 6 | import actions.global.globalactions.ExecuteInstanceConstructorGlobalAction; 7 | import actions.menu.ActionsMenuBarTitles; 8 | import paintcomponents.java.interactive.InstanceOperationComponent; 9 | import ui.PaintPanel; 10 | import ui.general.InputManager; 11 | import ui.general.InputManagerDelegate; 12 | 13 | public class ExecuteInstanceConstructorAction extends MenuBarPaintAction { 14 | 15 | public ExecuteInstanceConstructorAction(PaintPanel panel) { 16 | super(panel); 17 | } 18 | 19 | @Override 20 | public boolean canPerformAction() { 21 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 22 | return false; 23 | } 24 | if (panel.getSelectTool().getSelectedComponents() 25 | .get(0) instanceof InstanceOperationComponent) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | @Override 32 | public void performAction() { 33 | ExecuteInstanceConstructorGlobalAction associatedAction 34 | = (ExecuteInstanceConstructorGlobalAction) ActionName.EXECUTE_INSTANCE_CONSTRUCTOR_ACTION 35 | .getAssociatedAction(); 36 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 37 | 38 | 39 | } 40 | 41 | @Override 42 | public String locationString() { 43 | // TODO Auto-generated method stub 44 | return ActionsMenuBarTitles.Lazy().Add().Execute_Instance_Constructor().toString(); 45 | } 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/actions/ExecuteInstanceMethodAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import actions.global.ActionName; 4 | import actions.global.GlobalPaintActionExecuter; 5 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 6 | import actions.global.globalactions.ExecuteInstanceMethodGlobalAction; 7 | import actions.menu.ActionsMenuBarTitles; 8 | import paintcomponents.java.interactive.MethodPaintComponent; 9 | import ui.PaintPanel; 10 | import ui.general.InputManager; 11 | import ui.general.InputManagerDelegate; 12 | 13 | public class ExecuteInstanceMethodAction extends MenuBarPaintAction { 14 | 15 | public ExecuteInstanceMethodAction(PaintPanel panel) { 16 | super(panel); 17 | } 18 | 19 | @Override 20 | public boolean canPerformAction() { 21 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 22 | return false; 23 | } 24 | if (panel.getSelectTool().getSelectedComponents() 25 | .get(0) instanceof MethodPaintComponent) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | 32 | 33 | @Override 34 | public void performAction() { 35 | ExecuteInstanceMethodGlobalAction associatedAction 36 | = (ExecuteInstanceMethodGlobalAction)ActionName.EXECUTE_INSTANCE_METHOD_ACTION.getAssociatedAction(); 37 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 38 | } 39 | 40 | @Override 41 | public String locationString() { 42 | // TODO Auto-generated method stub 43 | return ActionsMenuBarTitles.Lazy().Add().Execute_Instance_Method().toString(); 44 | } 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/actions/ExecuteScriptAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import ui.PaintPanel; 6 | import actions.global.ActionName; 7 | import actions.global.GlobalPaintActionExecuter; 8 | import actions.global.globalactions.ExecuteScriptGlobalAction; 9 | import actions.menu.ActionsMenuBarTitles; 10 | 11 | public class ExecuteScriptAction extends MenuBarPaintAction { 12 | 13 | public ExecuteScriptAction(PaintPanel panel) { 14 | super(panel); 15 | } 16 | 17 | @Override 18 | public boolean canPerformAction() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public void performAction() { 24 | /* 25 | * Scanner scanner = new Scanner(System.in); 26 | * 27 | * System.out.println("Enter script:"); while (scanner.hasNextLine()) { 28 | * try { interpreter.interpreteLine(scanner.nextLine()); } catch 29 | * (ExecutionErrorException e) { System.out.println("Invalid script"); } 30 | * System.out.println("Enter script:"); } scanner.close(); 31 | */ 32 | String command = JOptionPane.showInputDialog(panel, "Enter Script: "); 33 | ExecuteScriptGlobalAction associatedAction = (ExecuteScriptGlobalAction) ActionName.EXECUTE_SCRIPT_ACTION 34 | .getAssociatedAction(); 35 | 36 | associatedAction.setCommand(command); 37 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 38 | panel); 39 | 40 | } 41 | 42 | @Override 43 | public String locationString() { 44 | return ActionsMenuBarTitles.Script().Enter_Script().toString(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/actions/FileOpen.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | import javax.swing.JOptionPane; 7 | import javax.xml.parsers.ParserConfigurationException; 8 | import org.xml.sax.SAXException; 9 | 10 | import actions.global.ActionName; 11 | import actions.global.GlobalPaintActionExecuter; 12 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 13 | import actions.global.globalactions.FileOpenGlobalAction; 14 | import actions.menu.ActionsMenuBarTitles; 15 | import file.PanelIO; 16 | import ui.PaintPanel; 17 | 18 | import javax.swing.JFileChooser; 19 | import java.io.File; 20 | 21 | public class FileOpen extends MenuBarPaintAction { 22 | 23 | public FileOpen(PaintPanel panel) { 24 | super(panel); 25 | } 26 | 27 | @Override 28 | public boolean canPerformAction() { 29 | return true; 30 | } 31 | 32 | @Override 33 | public void performAction() { 34 | JFileChooser fileChooser = new JFileChooser(); 35 | fileChooser.setDialogTitle("Select the file to open"); 36 | int userSelection = fileChooser.showOpenDialog(panel); 37 | 38 | String filePath; 39 | if (userSelection == JFileChooser.APPROVE_OPTION) { 40 | File fileToSave = fileChooser.getSelectedFile(); 41 | filePath = fileToSave.getAbsolutePath(); 42 | } else { 43 | return; 44 | } 45 | 46 | FileOpenGlobalAction associatedAction 47 | = (FileOpenGlobalAction) ActionName.FILE_OPEN_GLOBAL_ACTION 48 | .getAssociatedAction(); 49 | associatedAction.setFileToOpen(filePath); 50 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 51 | } 52 | 53 | @Override 54 | public String locationString() { 55 | return ActionsMenuBarTitles.File().Open().toString(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/actions/FileSaveAs.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.nio.channels.ShutdownChannelGroupException; 4 | 5 | import javax.swing.JOptionPane; 6 | import javax.xml.parsers.DocumentBuilder; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | import javax.xml.transform.TransformerException; 10 | 11 | import org.w3c.dom.Document; 12 | import org.w3c.dom.Element; 13 | 14 | import actions.global.ActionName; 15 | import actions.global.GlobalPaintActionExecuter; 16 | import actions.global.globalactions.FileOpenGlobalAction; 17 | import actions.global.globalactions.FileSaveAsGlobalAction; 18 | import actions.menu.ActionsMenuBarTitles; 19 | import file.PanelIO; 20 | import ui.PaintPanel; 21 | 22 | import javax.swing.JFileChooser; 23 | import java.io.File; 24 | 25 | public class FileSaveAs extends MenuBarPaintAction { 26 | 27 | public FileSaveAs(PaintPanel panel) { 28 | super(panel); 29 | } 30 | 31 | @Override 32 | public boolean canPerformAction() { 33 | return true; 34 | } 35 | 36 | /** 37 | * Use a JFileChooser to save the file 38 | * @author xy gong 39 | */ 40 | @Override 41 | public void performAction() { 42 | JFileChooser fileChooser = new JFileChooser(); 43 | fileChooser.setDialogTitle("Specify a file to save"); 44 | int userSelection = fileChooser.showSaveDialog(panel); 45 | 46 | String filePath; 47 | if (userSelection == JFileChooser.APPROVE_OPTION) { 48 | File fileToSave = fileChooser.getSelectedFile(); 49 | filePath = fileToSave.getAbsolutePath(); 50 | } else { 51 | return; 52 | } 53 | 54 | FileSaveAsGlobalAction associatedAction 55 | = (FileSaveAsGlobalAction) ActionName.FILE_SAVE_AS_GLOBAL_ACTION 56 | .getAssociatedAction(); 57 | associatedAction.setFilePath(filePath); 58 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 59 | } 60 | 61 | @Override 62 | public String locationString() { 63 | return ActionsMenuBarTitles.File().Save().toString(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/actions/InputDataForDataInputBoxAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.util.ArrayList; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import actions.edit.undoredo.SharedUndoRedoActionManager; 8 | import actions.edit.undoredo.UndoRedoableInterface; 9 | import actions.menu.ActionsMenuBarTitles; 10 | import paintcomponents.PaintComponent; 11 | import paintcomponents.data.DataInputTextfieldPaintComponent; 12 | import ui.PaintPanel; 13 | 14 | public class InputDataForDataInputBoxAction extends MenuBarPaintAction { 15 | 16 | public InputDataForDataInputBoxAction(PaintPanel panel) { 17 | super(panel); 18 | } 19 | 20 | @Override 21 | public boolean canPerformAction() { 22 | ArrayList comps = panel.getSelectTool().getSelectedComponents(); 23 | if(comps.size()!= 1) return false; 24 | Object comp = comps.get(0); 25 | if (comp instanceof DataInputTextfieldPaintComponent) { 26 | //Make sure this is not a class box 27 | if( ((DataInputTextfieldPaintComponent) comp).canUpdate()){ 28 | return true; 29 | } 30 | } 31 | return false; 32 | } 33 | 34 | @Override 35 | public void performAction() { 36 | DataInputTextfieldPaintComponent inputComp = (DataInputTextfieldPaintComponent) panel.getSelectTool().getSelectedComponents().get(0); 37 | String s = JOptionPane.showInputDialog("Please specify the message to push to the data input"); 38 | //call DialogInputChecker to check input 39 | DialogInputChecker inputChecker = new DialogInputChecker(); 40 | if(!inputChecker.isEmpty(s)){ 41 | String original = inputComp.getDisplayingText(); 42 | inputComp.inputData(s); 43 | // add action to undo redo manager 44 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() { 45 | 46 | @Override 47 | public void undoAction() { 48 | inputComp.inputData(original); 49 | panel.repaint(); 50 | } 51 | 52 | @Override 53 | public void redoAction() { 54 | inputComp.inputData(s); 55 | panel.repaint(); 56 | } 57 | 58 | @Override 59 | protected String commandName() { 60 | return "update inputBox"; 61 | } 62 | 63 | @Override 64 | protected String commandDescription() { 65 | return "Input a string into the text input box"; 66 | } 67 | }); 68 | 69 | panel.repaint(); 70 | } 71 | } 72 | 73 | @Override 74 | public String locationString() { 75 | return ActionsMenuBarTitles.Data().Input_Box().Update().toString(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/actions/MenuBarPaintAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | 5 | /** 6 | * Paint Action abstracts a particular menu action 7 | * 8 | * Override this class to create a new Action. 9 | * 10 | * Perfrom action will only be called when can perform action returns true. 11 | * 12 | * Most of the cases, you have to call panel.repaint() as the last statement of 13 | * perform action 14 | * 15 | * @author chenzb 16 | * 17 | */ 18 | public abstract class MenuBarPaintAction { 19 | 20 | protected PaintPanel panel; 21 | 22 | public MenuBarPaintAction(PaintPanel panel) { 23 | this.panel = panel; 24 | } 25 | 26 | /** 27 | * Whether this action can perform. Subclasses generally base the return 28 | * value on the current selection on screen 29 | * panel.getSelectTool().getSelectedComponents 30 | * 31 | * @return true if the action can be performed 32 | */ 33 | public abstract boolean canPerformAction(); 34 | 35 | /** 36 | * Performs this action Subclassess must invoke panel.repaint if the action 37 | * changes the panel 38 | */ 39 | public abstract void performAction(); 40 | 41 | /** 42 | * The location of this item in the menu bar. 43 | * For example, "File/Save As..", "File/Open Recent/Clear Menu" 44 | * @return 45 | */ 46 | public abstract String locationString(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/actions/RedoAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | import actions.edit.undoredo.SharedUndoRedoActionManager; 5 | import actions.menu.ActionsMenuBarTitles; 6 | 7 | public class RedoAction extends MenuBarPaintAction { 8 | 9 | 10 | 11 | 12 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager.getSharedInstance(); 13 | 14 | public RedoAction(PaintPanel panel) { 15 | super(panel); 16 | } 17 | 18 | @Override 19 | public boolean canPerformAction() { 20 | return manager.canRedo(); 21 | } 22 | 23 | @Override 24 | public void performAction() { 25 | manager.redo(); 26 | } 27 | 28 | @Override 29 | public String locationString() { 30 | return ActionsMenuBarTitles.Edit().Redo().toString(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/actions/RedoActionTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import ui.PaintPanel; 9 | import actions.global.ActionName; 10 | import actions.global.GlobalPaintActionExecuter; 11 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 12 | 13 | /** 14 | * RedoActionTest 15 | * 16 | * @author DYB Test the functionality of redo 17 | */ 18 | public class RedoActionTest { 19 | 20 | @Test 21 | public void test() { 22 | PaintPanel panel = new PaintPanel(); 23 | 24 | // perform one action 25 | AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 26 | .getAssociatedAction(); 27 | action.setClassToCreate(this.getClass()); 28 | GlobalPaintActionExecuter.getSharedInstance().execute(action, panel); 29 | 30 | // new redo action 31 | RedoAction action1 = new RedoAction(panel); 32 | 33 | // determine whether can redo or not 34 | assertFalse(action1.canPerformAction()); 35 | // do an undo action 36 | 37 | new UndoAction(panel).performAction(); 38 | // can redo now 39 | assertTrue(action1.canPerformAction()); 40 | // do a redo 41 | action1.performAction(); 42 | // cannot redo 43 | assertFalse(action1.canPerformAction()); 44 | 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/actions/RemoveAnnotationActionTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import paintcomponents.SimplePoint; 8 | import paintcomponents.annotations.TextAnnotation; 9 | import painttools.tools.SelectTool; 10 | import ui.PaintPanel; 11 | import actions.global.ActionName; 12 | import actions.global.globalactions.AddAnnotationGlobalAction; 13 | 14 | /** 15 | * test the removeAnnotationAction by adding and then deleting the annotation. 16 | * Then check if the annotation is null 17 | * 18 | * @author muchi 19 | */ 20 | public class RemoveAnnotationActionTest { 21 | 22 | @Test 23 | public void test() { 24 | PaintPanel panel = new PaintPanel(); 25 | SelectTool tool = new SelectTool(panel); 26 | panel.setSelectTool(tool); 27 | SimplePoint test = new SimplePoint (0, 0); 28 | panel.addPaintComponent(test); 29 | 30 | // add the annotation to be removed 31 | AddAnnotationGlobalAction addAnnotationGlobalAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 32 | .getAssociatedAction(); 33 | 34 | addAnnotationGlobalAction.setAnnotationToAdd("hello"); 35 | addAnnotationGlobalAction.setOperatingInstance(test); 36 | 37 | addAnnotationGlobalAction.execute(panel); 38 | test.select(tool); 39 | 40 | // perform the remove action 41 | RemoveAnnotationAction action = new RemoveAnnotationAction(panel); 42 | 43 | action.performAction(); 44 | 45 | assertEquals(((TextAnnotation)test.getOptionalAnnotation()), null); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/actions/RemovePaintComponent.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.util.ArrayList; 4 | 5 | import paintcomponents.PaintComponent; 6 | import ui.PaintPanel; 7 | import actions.edit.undoredo.SharedUndoRedoActionManager; 8 | import actions.edit.undoredo.UndoRedoableInterface; 9 | import actions.menu.ActionsMenuBarTitles; 10 | 11 | public class RemovePaintComponent extends MenuBarPaintAction{ 12 | 13 | public RemovePaintComponent(PaintPanel panel) { 14 | super(panel); 15 | // TODO Auto-generated constructor stub 16 | } 17 | 18 | @Override 19 | public boolean canPerformAction() { 20 | if (panel.getSelectTool().getSelectedComponents().size() <= 0) { 21 | return false; 22 | } 23 | return true; 24 | } 25 | 26 | @Override 27 | public void performAction() { 28 | ArrayList comps = new ArrayList<>(); 29 | for ( PaintComponent comp: panel.getSelectTool().getSelectedComponents()) { 30 | comps.add(comp); 31 | } 32 | for( PaintComponent comp: comps ) comp.remove(panel); 33 | 34 | //push action to the manager 35 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() { 36 | 37 | @Override 38 | public void undoAction() { 39 | for( PaintComponent comp: comps ) 40 | panel.addPaintComponent(comp); 41 | panel.repaint(); 42 | 43 | } 44 | @Override 45 | public void redoAction() { 46 | for( PaintComponent comp: comps ) 47 | comp.remove(panel); 48 | panel.repaint(); 49 | } 50 | @Override 51 | protected String commandName() { 52 | return "remove"; 53 | } 54 | @Override 55 | protected String commandDescription() { 56 | return "removes a paint component"; 57 | } 58 | }); 59 | panel.repaint(); 60 | } 61 | 62 | @Override 63 | public String locationString() { 64 | // TODO Auto-generated method stub 65 | return ActionsMenuBarTitles.Data().Remove().toString(); } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/actions/ShowHistory.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import java.awt.Dimension; 4 | 5 | import ui.PaintPanel; 6 | import ui.helper.historyui.undoredoLog.UndoredoDialog; 7 | 8 | public class ShowHistory extends MenuBarPaintAction { 9 | 10 | 11 | public ShowHistory(PaintPanel panel) { 12 | super(panel); 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | @Override 17 | public boolean canPerformAction() { 18 | // TODO Auto-generated method stub 19 | return true; 20 | } 21 | 22 | @Override 23 | public void performAction() { 24 | // TODO Auto-generated method stub 25 | 26 | UndoredoDialog.sharedInstance().setVisible(true); 27 | 28 | } 29 | 30 | @Override 31 | public String locationString() { 32 | // TODO Auto-generated method stub 33 | return "View/Show/History"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/actions/UndoAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | import actions.edit.undoredo.SharedUndoRedoActionManager; 5 | import actions.menu.ActionsMenuBarTitles; 6 | 7 | public class UndoAction extends MenuBarPaintAction { 8 | 9 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager.getSharedInstance(); 10 | 11 | public UndoAction(PaintPanel panel) { 12 | super(panel); 13 | } 14 | 15 | @Override 16 | public boolean canPerformAction() { 17 | return manager.canUndo(); 18 | } 19 | 20 | @Override 21 | public void performAction() { 22 | manager.undo(); 23 | } 24 | 25 | @Override 26 | public String locationString() { 27 | return ActionsMenuBarTitles.Edit().Undo().toString(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/actions/UndoActionTest.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import ui.PaintPanel; 9 | import actions.global.ActionName; 10 | import actions.global.GlobalPaintActionExecuter; 11 | import actions.global.globalactions.AddLazyJavaClassGlobalAction; 12 | 13 | /** 14 | * UndoActionTest 15 | * 16 | * @author DYB Test the functionality of undo 17 | */ 18 | public class UndoActionTest { 19 | 20 | @Test 21 | public void test() { 22 | PaintPanel panel = new PaintPanel(); 23 | 24 | // perform one action 25 | AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 26 | .getAssociatedAction(); 27 | action.setClassToCreate(this.getClass()); 28 | GlobalPaintActionExecuter.getSharedInstance().execute(action, panel); 29 | 30 | // new undo action 31 | UndoAction action1 = new UndoAction(panel); 32 | // determine whether can undo or not 33 | assertTrue(action1.canPerformAction()); 34 | // perform one undo action 35 | action1.performAction(); 36 | // determine again whether can undo or not 37 | assertFalse(action1.canPerformAction()); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/ZoomAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import paintcomponents.PaintComponent; 4 | import ui.PaintPanel; 5 | 6 | public abstract class ZoomAction extends MenuBarPaintAction{ 7 | 8 | private double zoomValue; 9 | private int centerX, centerY; 10 | 11 | public ZoomAction(PaintPanel panel) { 12 | super(panel); 13 | centerX = panel.getWidth() / 2; 14 | centerY = panel.getHeight() / 2; 15 | 16 | } 17 | 18 | public boolean canPerformAction() { 19 | return true; 20 | } 21 | 22 | public void performAction() { 23 | 24 | 25 | for ( PaintComponent com: panel.getPaintComponents() ) { 26 | int xDifference = com.getX() - centerX; 27 | int yDifference = com.getY() - centerY; 28 | com.translate((int)(xDifference * getZoomValue()), (int)(yDifference * getZoomValue())); 29 | } 30 | panel.repaint(); 31 | } 32 | 33 | public int getCenterX() { 34 | return centerX; 35 | } 36 | 37 | public void setCenterX(int centerX) { 38 | this.centerX = centerX; 39 | } 40 | 41 | public int getCenterY() { 42 | return centerY; 43 | } 44 | 45 | public void setCenterY(int centerY) { 46 | this.centerY = centerY; 47 | } 48 | 49 | public double getZoomValue() { 50 | return zoomValue; 51 | } 52 | 53 | public void setZoomValue(double value) { 54 | zoomValue = value; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/actions/ZoomInAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import actions.menu.ActionsMenuBarTitles; 4 | import ui.PaintPanel; 5 | 6 | public class ZoomInAction extends ZoomAction { 7 | 8 | public ZoomInAction (PaintPanel panel) { 9 | super(panel); 10 | this.setZoomValue(0.1); 11 | } 12 | 13 | @Override 14 | public void performAction() { 15 | super.performAction(); 16 | } 17 | 18 | @Override 19 | public String locationString() { 20 | return ActionsMenuBarTitles.Edit().Zoom_In().toString(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/actions/ZoomOutAction.java: -------------------------------------------------------------------------------- 1 | package actions; 2 | 3 | import ui.PaintPanel; 4 | import actions.menu.ActionsMenuBarTitles; 5 | 6 | public class ZoomOutAction extends ZoomAction { 7 | 8 | public ZoomOutAction (PaintPanel panel) { 9 | super(panel); 10 | this.setZoomValue(-0.1); 11 | } 12 | 13 | @Override 14 | public void performAction() { 15 | super.performAction(); 16 | } 17 | 18 | @Override 19 | public String locationString() { 20 | return ActionsMenuBarTitles.Edit().Zoom_Out().toString(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/actions/edit/undoredo/SharedUndoRedoActionManager.java: -------------------------------------------------------------------------------- 1 | package actions.edit.undoredo; 2 | 3 | import java.util.Stack; 4 | 5 | /** 6 | * 7 | * @author cs12wagn 8 | * add to stack 9 | * 10 | */ 11 | public class SharedUndoRedoActionManager { 12 | private static SharedUndoRedoActionManager sharedInstance = new SharedUndoRedoActionManager(); 13 | private Stack undoStack; 14 | private Stack redoStack; 15 | private SharedUndoRedoActionManagerDelegate delegate; 16 | 17 | /** Static instance method */ 18 | public static SharedUndoRedoActionManager getSharedInstance(){ 19 | return sharedInstance; 20 | } 21 | 22 | /** 23 | * A private Constructor prevents any other 24 | * class from instantiating. 25 | */ 26 | private SharedUndoRedoActionManager() { 27 | undoStack = new Stack<>(); 28 | redoStack = new Stack<>(); 29 | } 30 | 31 | public void undo() { 32 | if(canUndo()){ 33 | UndoRedoableInterface undoableAction = undoStack.pop(); 34 | undoableAction.undoAction(); 35 | redoStack.add(undoableAction); 36 | if (delegate != null) { 37 | delegate.didUndoAction(undoableAction); 38 | } 39 | } 40 | else { 41 | System.out.println("empty undo stack"); 42 | } 43 | } 44 | 45 | public void redo() { 46 | if(canRedo()){ 47 | UndoRedoableInterface redoableAction = redoStack.pop(); 48 | redoableAction.redoAction(); 49 | undoStack.add(redoableAction); 50 | if (delegate != null) { 51 | delegate.didRedoAction(redoableAction); 52 | } 53 | } 54 | else { 55 | System.out.println("empty redo stack"); 56 | } 57 | } 58 | 59 | public boolean canUndo() { 60 | return !undoStack.isEmpty(); 61 | } 62 | 63 | public boolean canRedo() { 64 | return !redoStack.isEmpty(); 65 | } 66 | 67 | public void pushUndoableAction( UndoRedoableInterface undoredoableAction ) { 68 | undoStack.push(undoredoableAction); 69 | redoStack.clear(); 70 | if( delegate != null){ 71 | delegate.didAddNewAction(undoredoableAction); 72 | } 73 | } 74 | 75 | 76 | 77 | public void setDelegate(SharedUndoRedoActionManagerDelegate delegate) { 78 | this.delegate = delegate; 79 | } 80 | 81 | /** 82 | * @return the undoStack 83 | */ 84 | public Stack getUndoStack() { 85 | return undoStack; 86 | } 87 | 88 | /** 89 | * @return the redoStack 90 | */ 91 | public Stack getRedoStack() { 92 | return redoStack; 93 | } 94 | 95 | /** 96 | * return the last item in undoStack 97 | */ 98 | public UndoRedoableInterface undoPeek(){ 99 | return undoStack.peek(); 100 | } 101 | 102 | /** 103 | * return last item in redoStack 104 | */ 105 | public UndoRedoableInterface redoPeek(){ 106 | return redoStack.peek(); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/actions/edit/undoredo/SharedUndoRedoActionManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package actions.edit.undoredo; 2 | 3 | public interface SharedUndoRedoActionManagerDelegate { 4 | 5 | public void didUndoAction(UndoRedoableInterface obj); 6 | public void didRedoAction(UndoRedoableInterface obj); 7 | public void didAddNewAction(UndoRedoableInterface undoredoableAction); 8 | } 9 | -------------------------------------------------------------------------------- /src/actions/edit/undoredo/UndoRedoableInterface.java: -------------------------------------------------------------------------------- 1 | package actions.edit.undoredo; 2 | 3 | import ui.helper.historyui.TableUIDataObject; 4 | 5 | public abstract class UndoRedoableInterface extends TableUIDataObject { 6 | 7 | public abstract void undoAction(); 8 | public abstract void redoAction(); 9 | public String description(){ 10 | return commandName() + " -- " + commandDescription(); 11 | } 12 | protected abstract String commandName(); 13 | protected abstract String commandDescription(); 14 | } 15 | -------------------------------------------------------------------------------- /src/actions/global/GlobalPaintAction.java: -------------------------------------------------------------------------------- 1 | package actions.global; 2 | 3 | import ui.PaintPanel; 4 | 5 | /** 6 | * Global paint Action corresponds to any event happening on the paint panel. 7 | * 8 | * @author chenzb 9 | * 10 | */ 11 | public abstract class GlobalPaintAction> { 12 | 13 | protected abstract void execute(PaintPanel panel); 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/actions/global/GlobalPaintActionExecuter.java: -------------------------------------------------------------------------------- 1 | package actions.global; 2 | 3 | import ui.PaintPanel; 4 | 5 | /** 6 | * Every instance uses the executer to execute an action from the action factory. 7 | * @author chenzb 8 | * 9 | */ 10 | public class GlobalPaintActionExecuter { 11 | 12 | private static GlobalPaintActionExecuter sharedInstance = new GlobalPaintActionExecuter(); 13 | 14 | 15 | public void execute(GlobalPaintAction action, PaintPanel panel){ 16 | action.execute(panel); 17 | } 18 | 19 | 20 | /** 21 | * @return the sharedInstance 22 | */ 23 | public static GlobalPaintActionExecuter getSharedInstance() { 24 | return sharedInstance; 25 | } 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddAnnotationGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import paintcomponents.PaintComponent; 6 | import paintcomponents.annotations.TextAnnotation; 7 | import ui.PaintPanel; 8 | 9 | public class AddAnnotationGlobalAction extends SingleInstanceOperationGlobalAction { 10 | 11 | private String annotationToAdd; 12 | @Override 13 | public void execute(PaintPanel panel){ 14 | new TextAnnotation(getOperatingInstance(), annotationToAdd); 15 | } 16 | /** 17 | * @return the annotationToAdd 18 | */ 19 | public String getAnnotationToAdd() { 20 | return annotationToAdd; 21 | } 22 | 23 | /** 24 | * @param annotationToAdd the annotationToAdd to set 25 | */ 26 | public void setAnnotationToAdd(String annotationToAdd) { 27 | this.annotationToAdd = annotationToAdd; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddAnnotationGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import paintcomponents.annotations.TextAnnotation; 8 | import paintcomponents.data.DataDisplayPaintComponent; 9 | import actions.AddDataInputBoxAction; 10 | import actions.global.ActionName; 11 | import ui.PaintPanel; 12 | 13 | public class AddAnnotationGlobalActionTest { 14 | 15 | @Test 16 | public void testExecute() { 17 | PaintPanel panel = new PaintPanel(); 18 | 19 | AddAnnotationGlobalAction addAnnotationGlobalAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 20 | .getAssociatedAction(); 21 | 22 | DataDisplayPaintComponent test = new DataDisplayPaintComponent("", 0, 0); 23 | addAnnotationGlobalAction.setAnnotationToAdd("hello"); 24 | addAnnotationGlobalAction.setOperatingInstance(test); 25 | 26 | panel.addPaintComponent(test); 27 | 28 | addAnnotationGlobalAction.execute(panel); 29 | 30 | assertEquals(((TextAnnotation)test.getOptionalAnnotation()).getStringContent(), "hello"); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddDataDisplayBoxGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.data.DataDisplayPaintComponent; 4 | import ui.PaintPanel; 5 | import actions.edit.undoredo.SharedUndoRedoActionManager; 6 | import actions.edit.undoredo.UndoRedoableInterface; 7 | import actions.global.GlobalPaintAction; 8 | 9 | public class AddDataDisplayBoxGlobalAction extends GlobalPaintAction { 10 | 11 | private String dataDisplay; 12 | private int x; 13 | private int y; 14 | 15 | private DataDisplayPaintComponent comp; 16 | 17 | public void setDisplayString(String dataDisplay) { 18 | this.dataDisplay = dataDisplay; 19 | } 20 | 21 | /** 22 | * @param x 23 | * the x to set 24 | */ 25 | public void setX(int x) { 26 | this.x = x; 27 | } 28 | 29 | /** 30 | * @param y 31 | * the y to set 32 | */ 33 | public void setY(int y) { 34 | this.y = y; 35 | } 36 | 37 | @Override 38 | protected void execute(PaintPanel panel) { 39 | comp = new DataDisplayPaintComponent( 40 | // DataDisplayPaintComponent comp = new DataDisplayPaintComponent( 41 | dataDisplay, x, y); 42 | 43 | if (panel.getSelectTool() != null) { 44 | panel.getSelectTool().clearSelection(); 45 | panel.getSelectTool().selectComponent(comp); 46 | } 47 | 48 | panel.addPaintComponent(comp); 49 | 50 | // push action to manager 51 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 52 | new UndoRedoableInterface() { 53 | 54 | @Override 55 | public void undoAction() { 56 | comp.remove(panel); 57 | panel.repaint(); 58 | } 59 | 60 | @Override 61 | public void redoAction() { 62 | panel.addPaintComponent(comp); 63 | panel.repaint(); 64 | } 65 | 66 | @Override 67 | protected String commandName() { 68 | return "add data displayBox"; 69 | } 70 | 71 | @Override 72 | protected String commandDescription() { 73 | return "add a string display"; 74 | } 75 | 76 | }); 77 | panel.repaint(); 78 | } 79 | 80 | public DataDisplayPaintComponent getComponent() { 81 | return comp; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddDataDisplayBoxGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import paintcomponents.data.DataDisplayPaintComponent; 8 | import ui.PaintPanel; 9 | import actions.AddDataDisplayBoxAction; 10 | 11 | /** 12 | * AddDataDisplayBoxGlobalAction tester 13 | * 14 | * @author Joe Helen We test getPaintComponents size for performing 15 | * addDataDisplayBoxGlobalAction It will go from 0 to 1 when we perform 16 | * addDataDisplayBoxGlobalAction 17 | */ 18 | public class AddDataDisplayBoxGlobalActionTest { 19 | 20 | @Test 21 | public void test() { 22 | PaintPanel panel = new PaintPanel(); 23 | 24 | AddDataDisplayBoxGlobalAction action = new AddDataDisplayBoxGlobalAction(); 25 | 26 | assertEquals(0, panel.getPaintComponents().size()); 27 | 28 | action.execute(panel); 29 | 30 | assertEquals(1, panel.getPaintComponents().size()); 31 | 32 | assertTrue(panel.getPaintComponents().get(0) instanceof DataDisplayPaintComponent); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddHaskellComponentGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.global.GlobalPaintAction; 4 | import paintcomponents.haskell.HaskellExpressionPaintComponent; 5 | import ui.PaintPanel; 6 | 7 | public class AddHaskellComponentGlobalAction extends GlobalPaintAction { 8 | 9 | 10 | private String haskellExpression; 11 | @Override 12 | protected void execute(PaintPanel panel) { 13 | // TODO Auto-generated method stub 14 | 15 | String expr = haskellExpression; 16 | panel.addPaintComponent(new HaskellExpressionPaintComponent(expr, panel.getWidth() / 2, panel.getHeight() / 2)); 17 | 18 | panel.repaint(); 19 | } 20 | 21 | /** 22 | * @param haskellExpression 23 | * the haskellExpression to set 24 | */ 25 | public void setHaskellExpression(String haskellExpression) { 26 | this.haskellExpression = haskellExpression; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddHaskellComponentGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import actions.global.ActionName; 10 | import paintcomponents.haskell.HaskellExpressionPaintComponent; 11 | import ui.PaintPanel; 12 | 13 | public class AddHaskellComponentGlobalActionTest { 14 | 15 | PaintPanel panel; 16 | AddHaskellComponentGlobalAction action; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | panel = new PaintPanel(); 21 | 22 | action = (AddHaskellComponentGlobalAction) ActionName.ADD_HASKELL_EXPRESSION_COMPONENT 23 | .getAssociatedAction(); 24 | action.setHaskellExpression("2"); 25 | } 26 | 27 | @Test 28 | public void testExecute() { 29 | 30 | assertEquals(0, panel.getPaintComponents().size()); 31 | 32 | action.execute(panel); 33 | 34 | assertEquals(1, panel.getPaintComponents().size()); 35 | 36 | assertTrue(panel.getPaintComponents().get(0) instanceof HaskellExpressionPaintComponent); 37 | } 38 | 39 | 40 | // TODO 41 | // currently it is giving out error: 42 | // Cannot run program "ghci": error=2, No such file or directory 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddHaskellEvaluatorComponentGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.haskell.EvaluateHaskellPaintComponent; 4 | import ui.PaintPanel; 5 | import actions.global.GlobalPaintAction; 6 | 7 | public class AddHaskellEvaluatorComponentGlobalAction 8 | extends GlobalPaintAction { 9 | 10 | // currently cannot be evaluated by creating the line seg 11 | // Error: typesystem.HaskellType cannot be cast to typesystem.JavaType 12 | 13 | @Override 14 | protected void execute(PaintPanel panel) { 15 | 16 | EvaluateHaskellPaintComponent comp = new EvaluateHaskellPaintComponent( 17 | "Use Data Display/Update to compute expression result", panel.getWidth() / 2, panel.getHeight() / 2); 18 | panel.addPaintComponent(comp); 19 | panel.repaint(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddHaskellEvaluatorComponentGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import actions.global.ActionName; 10 | import paintcomponents.haskell.EvaluateHaskellPaintComponent; 11 | import ui.PaintPanel; 12 | 13 | public class AddHaskellEvaluatorComponentGlobalActionTest { 14 | 15 | PaintPanel panel; 16 | AddHaskellEvaluatorComponentGlobalAction action; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | panel = new PaintPanel(); 21 | 22 | action = (AddHaskellEvaluatorComponentGlobalAction) ActionName.ADD_HASKELL_EVALUATOR_COMPONENT 23 | .getAssociatedAction(); 24 | } 25 | 26 | @Test 27 | public void testExecute() { 28 | assertEquals(0, panel.getPaintComponents().size()); 29 | 30 | action.execute(panel); 31 | 32 | assertEquals(1, panel.getPaintComponents().size()); 33 | 34 | assertTrue(panel.getPaintComponents().get(0) instanceof EvaluateHaskellPaintComponent); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddInstanceMethodGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import actions.global.GlobalPaintAction; 6 | import paintcomponents.java.interactive.InstanceOperationComponent; 7 | import ui.PaintPanel; 8 | 9 | public class AddInstanceMethodGlobalAction extends GlobalPaintAction { 10 | 11 | private InstanceOperationComponent insComp; 12 | private Method methodToSet; 13 | 14 | @Override 15 | protected void execute(PaintPanel panel) { 16 | insComp.addMethodPaintComponent(methodToSet, panel); 17 | panel.repaint(); 18 | } 19 | 20 | public void setInsComp(InstanceOperationComponent insComp) { 21 | this.insComp = insComp; 22 | } 23 | 24 | public void setMethodToSet(Method methodToSet) { 25 | this.methodToSet = methodToSet; 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddInstanceMethodGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.interactive.InstanceOperationComponent; 9 | import paintcomponents.java.interactive.MethodPaintComponent; 10 | import ui.PaintPanel; 11 | 12 | public class AddInstanceMethodGlobalActionTest { 13 | 14 | /** 15 | * Test adding instance method to an instance operation component 16 | */ 17 | @Test 18 | public void test() { 19 | 20 | //first add a instance operation component 21 | //Same as the test case in AddInstanceOperationGlobalActionTest 22 | PaintPanel panel = new PaintPanel(); 23 | AddInstanceOperationGlobalAction addInsCompAction = new AddInstanceOperationGlobalAction(); 24 | assertEquals(0, panel.getPaintComponents().size()); 25 | addInsCompAction.setConstructorToSet(String.class.getConstructors()[0]); 26 | addInsCompAction.execute(panel); 27 | assertEquals(1, panel.getPaintComponents().size()); 28 | assertTrue(panel.getPaintComponents().get(0) instanceof InstanceOperationComponent); 29 | 30 | //add a method based on the operation component 31 | AddInstanceMethodGlobalAction addInsMthAction = new AddInstanceMethodGlobalAction(); 32 | //specify the instance operation component to add method on 33 | addInsMthAction.setInsComp(addInsCompAction.getInsComp()); 34 | //take the first method of String for example 35 | addInsMthAction.setMethodToSet(String.class.getMethods()[0]); 36 | addInsMthAction.execute(panel); 37 | assertEquals(2, panel.getPaintComponents().size()); 38 | assertTrue(panel.getPaintComponents().get(1) instanceof MethodPaintComponent); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddInstanceOperationGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import actions.global.GlobalPaintAction; 6 | import paintcomponents.java.interactive.InstanceOperationComponent; 7 | import ui.PaintPanel; 8 | 9 | public class AddInstanceOperationGlobalAction extends GlobalPaintAction { 10 | 11 | private Constructor constructorToSet; 12 | private InstanceOperationComponent insComp; 13 | 14 | @Override 15 | protected void execute(PaintPanel panel) { 16 | insComp = new InstanceOperationComponent(constructorToSet, 17 | panel.getWidth() / 2, panel.getHeight() / 2); 18 | panel.addPaintComponent(insComp); 19 | //TODO: add action to undo redo manager 20 | panel.repaint(); 21 | } 22 | 23 | public void setConstructorToSet(Constructor constructorToSet) { 24 | this.constructorToSet = constructorToSet; 25 | } 26 | 27 | public InstanceOperationComponent getInsComp() { 28 | return insComp; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddInstanceOperationGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.interactive.InstanceOperationComponent; 9 | import ui.PaintPanel; 10 | 11 | public class AddInstanceOperationGlobalActionTest { 12 | 13 | /** 14 | * Add an instance operation component: 15 | * String object, using the first constructor 16 | */ 17 | @Test 18 | public void test() { 19 | PaintPanel panel = new PaintPanel(); 20 | 21 | AddInstanceOperationGlobalAction action = new AddInstanceOperationGlobalAction(); 22 | 23 | assertEquals(0, panel.getPaintComponents().size()); 24 | 25 | //use the first constructor of String as example 26 | action.setConstructorToSet(String.class.getConstructors()[0]); 27 | 28 | action.execute(panel); 29 | 30 | assertEquals(1, panel.getPaintComponents().size()); 31 | 32 | assertTrue(panel.getPaintComponents().get(0) instanceof InstanceOperationComponent); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaClassGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.java.lazy.ClassPaintComponent; 4 | import ui.PaintPanel; 5 | import actions.edit.undoredo.SharedUndoRedoActionManager; 6 | import actions.edit.undoredo.UndoRedoableInterface; 7 | import actions.global.GlobalPaintAction; 8 | 9 | public class AddLazyJavaClassGlobalAction extends GlobalPaintAction { 10 | 11 | private Class classToCreate; 12 | private int x; 13 | private int y; 14 | 15 | /** 16 | * @param classToCreate 17 | * the classToCreate to set 18 | */ 19 | public void setClassToCreate(Class classToCreate) { 20 | this.classToCreate = classToCreate; 21 | } 22 | 23 | @Override 24 | protected void execute(PaintPanel panel) { 25 | ClassPaintComponent comp = new ClassPaintComponent(classToCreate, x, y); 26 | //The class input box shouldn't be updatable. 27 | comp.setCannotUpdate(); 28 | panel.addPaintComponent(comp); 29 | 30 | if (panel.getSelectTool() != null) { 31 | panel.getSelectTool().clearSelection(); 32 | panel.getSelectTool().selectComponent(comp); 33 | } 34 | 35 | // add action to undo redo manager 36 | UndoRedoableInterface undoRedoBlock = new UndoRedoableInterface() { 37 | 38 | @Override 39 | public void undoAction() { 40 | comp.remove(panel); 41 | panel.repaint(); 42 | } 43 | 44 | @Override 45 | public void redoAction() { 46 | panel.addPaintComponent(comp); 47 | panel.repaint(); 48 | } 49 | 50 | @Override 51 | protected String commandName() { 52 | return "add lazy javaClass"; 53 | } 54 | 55 | @Override 56 | protected String commandDescription() { 57 | return "add a java class component"; 58 | } 59 | }; 60 | 61 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 62 | undoRedoBlock); 63 | panel.repaint(); 64 | 65 | } 66 | 67 | public void setCoord(int x, int y) { 68 | this.x = x; 69 | this.y = y; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaClassGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.lazy.ClassPaintComponent; 9 | import ui.PaintPanel; 10 | import actions.global.ActionName; 11 | import actions.global.GlobalPaintActionExecuter; 12 | 13 | /** 14 | * AddLazyJavaConstructorClassGlobalActionTest. Author: Xiaoquan Jiang Test 15 | * AddLazyJavaConstructorClassGlobalAction 16 | */ 17 | public class AddLazyJavaClassGlobalActionTest { 18 | 19 | /** 20 | * Test the number of components on the panel and the type of component 21 | * added to verify adding a component 22 | */ 23 | @Test 24 | public void test() { 25 | PaintPanel panel = new PaintPanel(); 26 | AddLazyJavaClassGlobalAction assiciatedAction = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 27 | .getAssociatedAction(); 28 | assiciatedAction.setClassToCreate("string".getClass()); 29 | 30 | assertEquals("test number of components before", 0, panel 31 | .getPaintComponents().size()); 32 | GlobalPaintActionExecuter.getSharedInstance().execute(assiciatedAction, 33 | panel); 34 | assertEquals("test number of components before", 1, panel 35 | .getPaintComponents().size()); 36 | assertTrue("test type of component added", panel.getPaintComponents() 37 | .get(0) instanceof ClassPaintComponent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaConstructorGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | import paintcomponents.java.lazy.ClassConstructorPaintComponent; 6 | import paintcomponents.java.lazy.ClassPaintComponent; 7 | import ui.PaintPanel; 8 | import actions.edit.undoredo.SharedUndoRedoActionManager; 9 | import actions.edit.undoredo.UndoRedoableInterface; 10 | import actions.global.GlobalPaintAction; 11 | 12 | public class AddLazyJavaConstructorGlobalAction extends GlobalPaintAction { 13 | 14 | private ClassPaintComponent comp; 15 | private int desiaredConstructorIndex; 16 | private int x; 17 | private int y; 18 | 19 | @Override 20 | protected void execute(PaintPanel panel) { 21 | Constructor[] cons = comp.getDisplayingClass().getConstructors(); 22 | ClassConstructorPaintComponent consComp = new ClassConstructorPaintComponent( 23 | cons[desiaredConstructorIndex], x, y); 24 | panel.addPaintComponent(consComp); 25 | // add action to undo redo manager 26 | UndoRedoableInterface undoRedoBlock = new UndoRedoableInterface() { 27 | 28 | @Override 29 | public void undoAction() { 30 | consComp.remove(panel); 31 | panel.repaint(); 32 | } 33 | 34 | @Override 35 | public void redoAction() { 36 | panel.addPaintComponent(consComp); 37 | panel.repaint(); 38 | } 39 | 40 | @Override 41 | protected String commandName() { 42 | return "add lazy javaConstructor"; 43 | } 44 | 45 | @Override 46 | protected String commandDescription() { 47 | return "add a lazily evaludated java constructor"; 48 | } 49 | }; 50 | 51 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 52 | undoRedoBlock); 53 | panel.repaint(); 54 | } 55 | 56 | public void setConstructorIndex(int index) { 57 | this.desiaredConstructorIndex = index; 58 | } 59 | 60 | public void setComponent(ClassPaintComponent comp) { 61 | this.comp = comp; 62 | } 63 | 64 | public Constructor[] getConstructor() { 65 | return comp.getDisplayingClass().getConstructors(); 66 | } 67 | 68 | public void setCoord(int x, int y) { 69 | this.x = x; 70 | this.y = y; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaConstructorGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.lazy.ClassConstructorPaintComponent; 9 | import paintcomponents.java.lazy.ClassPaintComponent; 10 | import ui.PaintPanel; 11 | import actions.global.ActionName; 12 | import actions.global.GlobalPaintActionExecuter; 13 | 14 | /** 15 | * AddLazyJavaConstructorGlobalActionTest. Author: Xiaoquan Jiang Test 16 | * AddLazyJavaConstructorGlobalAction 17 | */ 18 | public class AddLazyJavaConstructorGlobalActionTest { 19 | 20 | /** 21 | * Test the number of components on the panel and the type of component 22 | * added to verify adding a component 23 | */ 24 | @Test 25 | public void test() { 26 | PaintPanel panel = new PaintPanel(); 27 | 28 | // add a class 29 | AddLazyJavaClassGlobalAction classAction = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 30 | .getAssociatedAction(); 31 | classAction.setClassToCreate("string".getClass()); 32 | GlobalPaintActionExecuter.getSharedInstance().execute(classAction, 33 | panel); 34 | 35 | // set up 36 | ClassPaintComponent comp = (ClassPaintComponent) panel 37 | .getPaintComponents().get(0); 38 | AddLazyJavaConstructorGlobalAction assiciatedAction = (AddLazyJavaConstructorGlobalAction) ActionName.ADD_LAZY_JAVA_CONSTRUCTOR_ACTION 39 | .getAssociatedAction(); 40 | assiciatedAction.setComponent(comp); 41 | assiciatedAction.setConstructorIndex(0); 42 | 43 | // test 44 | assertEquals("test number of components before", 1, panel 45 | .getPaintComponents().size()); 46 | GlobalPaintActionExecuter.getSharedInstance().execute(assiciatedAction, 47 | panel); 48 | assertEquals("test number of components after", 2, panel 49 | .getPaintComponents().size()); 50 | assertTrue("test type of component added", panel.getPaintComponents() 51 | .get(1) instanceof ClassConstructorPaintComponent); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaFieldsComponentGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.java.lazy.ClassPaintComponent; 4 | import paintcomponents.java.lazy.FieldsPaintComponent; 5 | import ui.PaintPanel; 6 | import actions.edit.undoredo.SharedUndoRedoActionManager; 7 | import actions.edit.undoredo.UndoRedoableInterface; 8 | import actions.global.GlobalPaintAction; 9 | 10 | public class AddLazyJavaFieldsComponentGlobalAction extends GlobalPaintAction { 11 | 12 | 13 | private ClassPaintComponent comp; 14 | private int x; 15 | private int y; 16 | 17 | @Override 18 | protected void execute(PaintPanel panel) { 19 | FieldsPaintComponent fieldsComp = new FieldsPaintComponent( 20 | comp.getDisplayingClass(), x, y); 21 | panel.addPaintComponent(fieldsComp); 22 | // push action to the manager 23 | UndoRedoableInterface undoRedoBlock = new UndoRedoableInterface() { 24 | 25 | @Override 26 | public void undoAction() { 27 | fieldsComp.remove(panel); 28 | panel.repaint(); 29 | } 30 | 31 | @Override 32 | public void redoAction() { 33 | panel.addPaintComponent(fieldsComp); 34 | panel.repaint(); 35 | 36 | } 37 | 38 | @Override 39 | protected String commandName() { 40 | return "add lazy javaFieldsComponent"; 41 | } 42 | 43 | @Override 44 | protected String commandDescription() { 45 | return "add a java fields component"; 46 | } 47 | }; 48 | 49 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 50 | undoRedoBlock); 51 | panel.repaint(); 52 | } 53 | 54 | public void setComponent(ClassPaintComponent comp) { 55 | this.comp = comp; 56 | } 57 | 58 | public void setCoord(int x, int y) { 59 | this.x = x; 60 | this.y = y; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaFieldsComponentGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.lazy.ClassPaintComponent; 9 | import paintcomponents.java.lazy.FieldsPaintComponent; 10 | import ui.PaintPanel; 11 | import actions.global.ActionName; 12 | import actions.global.GlobalPaintActionExecuter; 13 | 14 | /** 15 | * AddLazyJavaFieldsComponentGlobalActionTest. Author: Xiaoquan Jiang Test 16 | * AddLazyJavaFieldsComponentGlobalAction 17 | */ 18 | public class AddLazyJavaFieldsComponentGlobalActionTest { 19 | 20 | /** 21 | * Test the number of components on the panel and the type of component 22 | * added to verify adding a component 23 | */ 24 | @Test 25 | public void test() { 26 | PaintPanel panel = new PaintPanel(); 27 | 28 | // add a class 29 | AddLazyJavaClassGlobalAction classAction = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 30 | .getAssociatedAction(); 31 | classAction.setClassToCreate("string".getClass()); 32 | GlobalPaintActionExecuter.getSharedInstance().execute(classAction, 33 | panel); 34 | 35 | // set up 36 | ClassPaintComponent comp = (ClassPaintComponent) panel 37 | .getPaintComponents().get(0); 38 | AddLazyJavaFieldsComponentGlobalAction assiciatedAction = (AddLazyJavaFieldsComponentGlobalAction) ActionName.ADD_LAZY_JAVA_FIELDS_ACTION 39 | .getAssociatedAction(); 40 | assiciatedAction.setComponent(comp); 41 | 42 | // test 43 | assertEquals("test number of components before", 1, panel 44 | .getPaintComponents().size()); 45 | GlobalPaintActionExecuter.getSharedInstance().execute(assiciatedAction, 46 | panel); 47 | assertEquals("test number of components after", 2, panel 48 | .getPaintComponents().size()); 49 | assertTrue("test type of component added", panel.getPaintComponents() 50 | .get(1) instanceof FieldsPaintComponent); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaMethodComponentGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | import paintcomponents.java.lazy.ClassPaintComponent; 8 | import paintcomponents.java.lazy.MethodPaintComponent; 9 | import actions.edit.undoredo.SharedUndoRedoActionManager; 10 | import actions.edit.undoredo.UndoRedoableInterface; 11 | import actions.global.GlobalPaintAction; 12 | import ui.PaintPanel; 13 | 14 | public class AddLazyJavaMethodComponentGlobalAction extends GlobalPaintAction { 15 | private ClassPaintComponent comp; 16 | private Method methodToSet; 17 | @Override 18 | protected void execute(PaintPanel panel) { 19 | 20 | 21 | MethodPaintComponent methodComp = new MethodPaintComponent( 22 | methodToSet, panel.getWidth() / 2, 23 | panel.getHeight() / 2); 24 | panel.addPaintComponent(methodComp); 25 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() { 26 | 27 | 28 | @Override 29 | public void undoAction() { 30 | methodComp.remove(panel); 31 | panel.repaint(); 32 | } 33 | 34 | @Override 35 | public void redoAction() { 36 | panel.addPaintComponent(methodComp); 37 | panel.repaint(); 38 | } 39 | 40 | @Override 41 | protected String commandName() { 42 | return "add lazy javaMethodComponent"; 43 | } 44 | 45 | @Override 46 | protected String commandDescription() { 47 | return "add a lazily evaluated java method component"; 48 | } 49 | }); 50 | panel.repaint(); 51 | } 52 | public void setMethod(Method methodToSet){ 53 | this.methodToSet = methodToSet; 54 | } 55 | 56 | public void setMethodComponent(ClassPaintComponent comp){ 57 | this.comp = comp; 58 | } 59 | 60 | public ClassPaintComponent getComp(){ 61 | return comp; 62 | } 63 | 64 | 65 | public String getMethodsSelectionUI(Method[] methods) { 66 | StringBuilder builder = new StringBuilder(); 67 | for (int i = 0; i < methods.length; i++) { 68 | Method constructor = methods[i]; 69 | builder.append(i + " : " + constructor.toString() + "\n"); 70 | } 71 | return builder.toString(); 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddLazyJavaMethodComponentGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.java.lazy.ClassPaintComponent; 9 | import paintcomponents.java.lazy.MethodPaintComponent; 10 | import ui.PaintPanel; 11 | import actions.global.ActionName; 12 | import actions.global.GlobalPaintActionExecuter; 13 | 14 | public class AddLazyJavaMethodComponentGlobalActionTest { 15 | 16 | @Test 17 | public void test() { 18 | 19 | PaintPanel panel = new PaintPanel(); 20 | 21 | AddLazyJavaMethodComponentGlobalAction action = new AddLazyJavaMethodComponentGlobalAction(); 22 | assertEquals(0, panel.getPaintComponents().size()); 23 | 24 | //use first method to test 25 | action.setMethod(String.class.getMethods()[0]); 26 | action.execute(panel); 27 | assertEquals(1, panel.getPaintComponents().size()); 28 | assertTrue(panel.getPaintComponents().get(0) instanceof MethodPaintComponent); 29 | 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddTextBoxGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.TextPaintComponent; 4 | import ui.PaintPanel; 5 | import actions.edit.undoredo.SharedUndoRedoActionManager; 6 | import actions.edit.undoredo.UndoRedoableInterface; 7 | import actions.global.GlobalPaintAction; 8 | 9 | /** 10 | * add text box to panel in global 11 | * 12 | * @author Bingjie Zhou 13 | */ 14 | public class AddTextBoxGlobalAction extends GlobalPaintAction { 15 | 16 | private String textDisplay; 17 | private int x; 18 | private int y; 19 | 20 | /** 21 | * set text to display 22 | */ 23 | public void setDisplayString(String text) { 24 | this.textDisplay = text; 25 | } 26 | 27 | /** 28 | * set x 29 | */ 30 | public void setX(int x) { 31 | this.x = x; 32 | } 33 | 34 | /** 35 | * set y 36 | */ 37 | public void setY(int y) { 38 | this.y = y; 39 | } 40 | 41 | /** 42 | * execute the add function 43 | * 44 | * @param panel 45 | * add component to this panel 46 | */ 47 | @Override 48 | protected void execute(PaintPanel panel) { 49 | TextPaintComponent comp = new TextPaintComponent(textDisplay, x, y); 50 | panel.addPaintComponent(comp); 51 | // push action to the manager 52 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 53 | new UndoRedoableInterface() { 54 | 55 | @Override 56 | public void undoAction() { 57 | comp.remove(panel); 58 | panel.repaint(); 59 | } 60 | 61 | @Override 62 | public void redoAction() { 63 | panel.addPaintComponent(comp); 64 | panel.repaint(); 65 | } 66 | 67 | @Override 68 | protected String commandName() { 69 | return "add textBox"; 70 | } 71 | 72 | @Override 73 | protected String commandDescription() { 74 | return "[Deprecated] add a generic textbox"; 75 | } 76 | }); 77 | panel.repaint(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/AddTextBoxGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | 8 | import paintcomponents.TextPaintComponent; 9 | import ui.PaintPanel; 10 | 11 | /** 12 | * test the addTextBoxGlobalAction class 13 | * 14 | * @author Bingjie Zhou 15 | * 16 | */ 17 | public class AddTextBoxGlobalActionTest { 18 | 19 | /** 20 | * test the type and size of component and panel 21 | */ 22 | @Test 23 | public void test() { 24 | 25 | PaintPanel panel = new PaintPanel(); 26 | 27 | AddTextBoxGlobalAction action = new AddTextBoxGlobalAction(); 28 | 29 | // panel should now hold nothing and hence be size of 0 30 | assertEquals(0, panel.getPaintComponents().size()); 31 | 32 | action.execute(panel); 33 | 34 | // the size should now be 1 35 | assertEquals(1, panel.getPaintComponents().size()); 36 | 37 | // assert the first component of the panel is a TextPaintComponent 38 | assertTrue(panel.getPaintComponents().get(0) instanceof TextPaintComponent); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ConstructLineSegmentGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.edit.undoredo.SharedUndoRedoActionManager; 4 | import actions.edit.undoredo.UndoRedoableInterface; 5 | import actions.global.GlobalPaintAction; 6 | import paintcomponents.LineSegment; 7 | import paintcomponents.SimplePoint; 8 | import ui.PaintPanel; 9 | 10 | public class ConstructLineSegmentGlobalAction extends GlobalPaintAction { 11 | 12 | private SimplePoint fromPoint, toPoint; 13 | private LineSegment lineSegment; 14 | 15 | public void setFromPoint(SimplePoint inputFromPt) { 16 | fromPoint = inputFromPt; 17 | } 18 | 19 | public void setToPoint(SimplePoint inputToPt){ 20 | toPoint = inputToPt; 21 | } 22 | 23 | public LineSegment getLineSeg(){ 24 | 25 | return lineSegment; 26 | 27 | } 28 | 29 | @Override 30 | protected void execute(PaintPanel panel) { 31 | 32 | //construct line segment 33 | lineSegment = new LineSegment(fromPoint,toPoint ); 34 | 35 | 36 | //add to panel 37 | panel.addPaintComponent(lineSegment); 38 | 39 | //push action to the manager 40 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() { 41 | 42 | @Override 43 | public void undoAction() { 44 | lineSegment.remove(panel); 45 | panel.repaint(); 46 | } 47 | 48 | @Override 49 | public void redoAction() { 50 | panel.addPaintComponent(lineSegment); 51 | panel.repaint(); 52 | } 53 | 54 | @Override 55 | protected String commandName() { 56 | return "construct lineSegment"; 57 | } 58 | 59 | @Override 60 | protected String commandDescription() { 61 | return "[Deprecated] construct a generic line segment"; 62 | } 63 | }); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ConstructLineSegmentGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package actions.global.globalactions; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | import org.junit.Test; 9 | 10 | import paintcomponents.LineSegment; 11 | import paintcomponents.SimplePoint; 12 | import ui.PaintPanel; 13 | 14 | /** 15 | * @author Shanfeng Feng 16 | * 17 | */ 18 | public class ConstructLineSegmentGlobalActionTest { 19 | 20 | @Test 21 | public void test() { 22 | 23 | PaintPanel panel = new PaintPanel(); 24 | ConstructLineSegmentGlobalAction action = new ConstructLineSegmentGlobalAction(); 25 | 26 | SimplePoint testFromPt = new SimplePoint(50,50); 27 | SimplePoint testToPt = new SimplePoint(50, 125); 28 | panel.addPaintComponent(testFromPt); 29 | panel.addPaintComponent(testToPt); 30 | 31 | action.setFromPoint(testFromPt); 32 | action.setToPoint(testToPt); 33 | 34 | action.execute(panel); 35 | 36 | assertEquals(3,panel.getPaintComponents().size()); 37 | assertTrue(panel.getPaintComponents().get(2) instanceof LineSegment); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/EditAnnotationSizeGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.PaintComponent; 4 | import ui.PaintPanel; 5 | import actions.global.GlobalPaintAction; 6 | 7 | /** 8 | * the global action of editting annotation size 9 | * @author muchi 10 | * 11 | */ 12 | public class EditAnnotationSizeGlobalAction extends GlobalPaintAction { 13 | 14 | private Float textSize; 15 | private PaintComponent instance; 16 | 17 | /** 18 | * @param instance the instance to set 19 | */ 20 | public void setInstance(PaintComponent instance) { 21 | this.instance = instance; 22 | } 23 | 24 | /** 25 | * edit the size of the annotation 26 | * 27 | * @param panel the panel 28 | */ 29 | @Override 30 | protected void execute(PaintPanel panel) { 31 | instance.getOptionalAnnotation().setFontSize(textSize); 32 | } 33 | 34 | /** 35 | * @param input the input to set 36 | */ 37 | public void setTextSize(Float newTextSize) { 38 | this.textSize = newTextSize; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/EditAnnotationSizeGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import paintcomponents.annotations.TextAnnotation; 8 | import paintcomponents.data.DataDisplayPaintComponent; 9 | import ui.PaintPanel; 10 | import actions.global.ActionName; 11 | 12 | /** 13 | * Test editAnnotationSizeGlobalAction by adding annotations and then edit the 14 | * size. Then check if the size changes as desired 15 | * 16 | * @author muchi 17 | * 18 | */ 19 | public class EditAnnotationSizeGlobalActionTest { 20 | 21 | @Test 22 | public void test() { 23 | PaintPanel panel = new PaintPanel(); 24 | 25 | AddAnnotationGlobalAction addAnnotationGlobalAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 26 | .getAssociatedAction(); 27 | 28 | // add component and annotations 29 | DataDisplayPaintComponent add = new DataDisplayPaintComponent("", 0, 0); 30 | addAnnotationGlobalAction.setAnnotationToAdd("hello"); 31 | addAnnotationGlobalAction.setOperatingInstance(add); 32 | addAnnotationGlobalAction.execute(panel); 33 | 34 | panel.addPaintComponent(add); 35 | 36 | // edit the size 37 | EditAnnotationSizeGlobalAction associatedAction = (EditAnnotationSizeGlobalAction) ActionName.EDIT_ANNOTATION_SIZE_ACTION 38 | .getAssociatedAction(); 39 | associatedAction.setTextSize((float) 40.0); 40 | associatedAction.setInstance(add); 41 | 42 | associatedAction.execute(panel); 43 | 44 | assertEquals(((TextAnnotation) add.getOptionalAnnotation()) 45 | .getTextPaintComponent().getFontSize(), (float) 40.0, 0.1); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/EditRedoGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import ui.PaintPanel; 4 | import actions.edit.undoredo.SharedUndoRedoActionManager; 5 | import actions.global.GlobalPaintAction; 6 | 7 | public class EditRedoGlobalAction extends GlobalPaintAction { 8 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager 9 | .getSharedInstance(); 10 | @Override 11 | protected void execute(PaintPanel panel) { 12 | manager.redo(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/EditUndoActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import ui.PaintPanel; 8 | import actions.global.ActionName; 9 | import actions.global.GlobalPaintActionExecuter; 10 | 11 | /** 12 | * EditUndoActionTest 13 | * 14 | * @author cs30xsd Test the functionality of global undo 15 | */ 16 | public class EditUndoActionTest { 17 | 18 | @Test 19 | public void test() { 20 | PaintPanel panel = new PaintPanel(); 21 | 22 | // perform one action 23 | AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 24 | .getAssociatedAction(); 25 | action.setClassToCreate(this.getClass()); 26 | GlobalPaintActionExecuter.getSharedInstance().execute(action, panel); 27 | 28 | // new undo action 29 | EditRedoGlobalAction action1 = new EditRedoGlobalAction(); 30 | EditUndoGlobalAction action2 = new EditUndoGlobalAction(); 31 | 32 | assertEquals(1, panel.getPaintComponents().size()); 33 | // perform one undo action 34 | action2.execute(panel); 35 | assertEquals(0, panel.getPaintComponents().size()); 36 | action1.execute(panel); 37 | assertEquals(1, panel.getPaintComponents().size()); 38 | action2.execute(panel); 39 | assertEquals(0, panel.getPaintComponents().size()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/EditUndoGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import ui.PaintPanel; 4 | import actions.edit.undoredo.SharedUndoRedoActionManager; 5 | import actions.global.GlobalPaintAction; 6 | 7 | public class EditUndoGlobalAction extends GlobalPaintAction { 8 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager 9 | .getSharedInstance(); 10 | @Override 11 | protected void execute(PaintPanel panel) { 12 | manager.undo(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ExecuteInstanceConstructorGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.global.GlobalPaintAction; 4 | import actions.menu.ActionsMenuBarTitles; 5 | import paintcomponents.java.interactive.InstanceOperationComponent; 6 | import paintcomponents.java.lazy.ClassPaintComponent; 7 | import ui.PaintPanel; 8 | 9 | public class ExecuteInstanceConstructorGlobalAction extends GlobalPaintAction { 10 | 11 | private Class classToCreate; 12 | 13 | public void setClassToCreate(Class classToCreate) { 14 | this.classToCreate = classToCreate; 15 | } 16 | 17 | @Override 18 | protected void execute(PaintPanel panel) { 19 | // TODO Auto-generated method stub 20 | 21 | InstanceOperationComponent insComp = 22 | (InstanceOperationComponent)panel.getSelectTool(). 23 | getSelectedComponents().get(0); 24 | insComp.executeConstructor(); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ExecuteInstanceMethodGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.global.GlobalPaintAction; 4 | import actions.menu.ActionsMenuBarTitles; 5 | import paintcomponents.java.interactive.InstanceOperationComponent; 6 | import paintcomponents.java.interactive.MethodPaintComponent; 7 | import ui.PaintPanel; 8 | 9 | public class ExecuteInstanceMethodGlobalAction extends GlobalPaintAction { 10 | 11 | 12 | 13 | @Override 14 | protected void execute(PaintPanel panel) { 15 | // TODO Auto-generated method stub 16 | doExecute(panel); 17 | 18 | } 19 | 20 | 21 | protected Object doExecute(PaintPanel panel){ 22 | 23 | 24 | MethodPaintComponent methodComp = 25 | (MethodPaintComponent)panel.getSelectTool(). 26 | getSelectedComponents().get(0); 27 | return methodComp.executeMethod(); 28 | 29 | } 30 | 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ExecuteScriptGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.awt.HeadlessException; 4 | 5 | import script.ExecutionErrorException; 6 | import script.Interpreter; 7 | import ui.PaintPanel; 8 | import actions.global.GlobalPaintAction; 9 | 10 | public class ExecuteScriptGlobalAction extends GlobalPaintAction { 11 | 12 | String command; 13 | 14 | @Override 15 | protected void execute(PaintPanel panel) { 16 | 17 | Interpreter interpreter = new Interpreter(panel); 18 | 19 | try { 20 | interpreter.interpreteLine(command); 21 | } catch (HeadlessException e) { 22 | e.printStackTrace(); 23 | } catch (ExecutionErrorException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | public void setCommand(String command) { 29 | this.command = command; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/ExecuteScriptGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package actions.global.globalactions; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | import org.junit.Test; 9 | 10 | import ui.PaintPanel; 11 | 12 | /** 13 | * @author Tianyiz 14 | * 15 | */ 16 | public class ExecuteScriptGlobalActionTest { 17 | 18 | /** 19 | * Test method for 20 | * {@link actions.global.globalactions.ExecuteScriptGlobalAction#execute(ui.PaintPanel)} 21 | * . 22 | */ 23 | @Test 24 | public void testExecute() { 25 | ExecuteScriptGlobalAction action = new ExecuteScriptGlobalAction(); 26 | PaintPanel panel = new PaintPanel(); 27 | assertEquals(0, panel.getPaintComponents().size()); 28 | action.setCommand("add data displayBox"); 29 | action.execute(panel); 30 | assertEquals(1, panel.getPaintComponents().size()); 31 | // action.setCommand("construct dataLineSegment"); this line create null 32 | // pointer exception bug 33 | action.execute(panel); 34 | assertEquals(2, panel.getPaintComponents().size()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/FileOpenAndSaveGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This test file tests the functionalities of global file save 3 | * and file open by first: create some paint components, second: 4 | * save it to a file, third: clear the panel and open the file, 5 | * last: check whether the components have been restored. 6 | */ 7 | package actions.global.globalactions; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import org.junit.Test; 12 | 13 | import actions.global.ActionName; 14 | import actions.global.GlobalPaintActionExecuter; 15 | import paintcomponents.java.lazy.ClassPaintComponent; 16 | import ui.PaintPanel; 17 | import java.io.File; 18 | import java.nio.file.Files; 19 | 20 | /* 21 | * @author Yidong Luo 22 | */ 23 | public class FileOpenAndSaveGlobalActionTest { 24 | 25 | @Test 26 | public void test() { 27 | PaintPanel panel = new PaintPanel(); 28 | 29 | //Add string class to the panel 30 | AddLazyJavaClassGlobalAction associatedAction 31 | = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 32 | .getAssociatedAction(); 33 | associatedAction.setClassToCreate("string".getClass()); 34 | 35 | assertEquals(0, panel.getPaintComponents().size()); 36 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, panel); 37 | assertEquals(1, panel.getPaintComponents().size()); 38 | assertTrue(panel.getPaintComponents().get(0) instanceof ClassPaintComponent); 39 | 40 | //Save them 41 | FileSaveAsGlobalAction fileSaveAssociatedAction 42 | = (FileSaveAsGlobalAction) ActionName.FILE_SAVE_AS_GLOBAL_ACTION 43 | .getAssociatedAction(); 44 | 45 | fileSaveAssociatedAction.setFilePath("JSPFileSaveOpenTest.xml"); 46 | 47 | fileSaveAssociatedAction.execute(panel); 48 | 49 | 50 | //Remove all the current components 51 | panel = new PaintPanel(); 52 | panel.updateUI(); 53 | 54 | //Nothing should be on the panel now 55 | assertEquals(0, panel.getPaintComponents().size()); 56 | 57 | //Try to open them again 58 | FileOpenGlobalAction fileOpenAssociatedAction 59 | = (FileOpenGlobalAction) ActionName.FILE_OPEN_GLOBAL_ACTION 60 | .getAssociatedAction(); 61 | 62 | fileOpenAssociatedAction.setFileToOpen("JSPFileSaveOpenTest.xml"); 63 | 64 | fileOpenAssociatedAction.execute(panel); 65 | 66 | //Components on the panel should be the same as what was saved to be 67 | assertEquals(1, panel.getPaintComponents().size()); 68 | assertTrue(panel.getPaintComponents().get(0) 69 | instanceof ClassPaintComponent); 70 | 71 | File xml = new File("JSPFileSaveOpenTest.xml"); 72 | 73 | xml.delete(); 74 | 75 | 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /src/actions/global/globalactions/FileOpenGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | import javax.swing.JOptionPane; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | 10 | import org.xml.sax.SAXException; 11 | 12 | import actions.FileOpen; 13 | import actions.global.GlobalPaintAction; 14 | import file.PanelIO; 15 | import ui.PaintPanel; 16 | 17 | public class FileOpenGlobalAction extends GlobalPaintAction { 18 | 19 | private String filePath; 20 | 21 | /** 22 | * @param filePath the filePath to set 23 | */ 24 | public void setFileToOpen(String filePath){ 25 | //Use JFileChooser.APPROVE_OPTION by default 26 | this.filePath = filePath; 27 | } 28 | 29 | @Override 30 | protected void execute(PaintPanel panel) { 31 | 32 | //This is copied directly from FileOpen.java performAction method 33 | PanelIO io = new PanelIO(); 34 | try { 35 | io.constructPanelFromDocument(panel, filePath, true); 36 | panel.repaint(); 37 | } catch (ParserConfigurationException | SAXException | IOException 38 | | ClassNotFoundException | NoSuchMethodException 39 | | SecurityException | InstantiationException 40 | | IllegalAccessException | IllegalArgumentException 41 | | InvocationTargetException e) { 42 | e.printStackTrace(); 43 | JOptionPane.showMessageDialog(panel, e.toString()); 44 | } 45 | 46 | panel.repaint(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/FileSaveAsGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import javax.swing.JOptionPane; 4 | import javax.xml.parsers.ParserConfigurationException; 5 | import javax.xml.transform.TransformerException; 6 | 7 | import actions.global.GlobalPaintAction; 8 | import file.PanelIO; 9 | import ui.PaintPanel; 10 | 11 | public class FileSaveAsGlobalAction extends GlobalPaintAction { 12 | 13 | private String filePath; 14 | 15 | /** 16 | * @param filePath the filePath to set 17 | */ 18 | public void setFilePath(String filePath){ 19 | this.filePath = filePath; 20 | } 21 | 22 | @Override 23 | protected void execute(PaintPanel panel) { 24 | //Copied from FileSaveAs.java 25 | PanelIO io = new PanelIO(); 26 | try { 27 | io.constructDocumentFromPanel(panel, filePath); 28 | } catch (ParserConfigurationException | TransformerException e) { 29 | e.printStackTrace(); 30 | JOptionPane.showMessageDialog(panel, e.toString()); 31 | } 32 | 33 | panel.repaint(); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/GeneratePolygonSourceJavaGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import java.awt.Polygon; 4 | import java.awt.Rectangle; 5 | import java.io.File; 6 | import java.io.FileNotFoundException; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | 11 | import paintcomponents.SimplePoint; 12 | import actions.global.GlobalPaintAction; 13 | import ui.PaintPanel; 14 | 15 | public class GeneratePolygonSourceJavaGlobalAction extends GlobalPaintAction { 16 | 17 | private int width; 18 | private int height; 19 | private String name; 20 | private ArrayList selectedComponents; 21 | private String result; 22 | 23 | public void setSelectedComponents(ArrayList selectedComponents) { 24 | this.selectedComponents = selectedComponents; 25 | } 26 | 27 | public void setWidth(int w) { 28 | width = w; 29 | } 30 | 31 | public void setHeight(int h) { 32 | height = h; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getResult() { 40 | return result; 41 | } 42 | 43 | @Override 44 | protected void execute(PaintPanel panel) { 45 | StringBuilder builder = new StringBuilder(); 46 | builder.append("import java.awt.Polygon;\npublic class " + name 47 | + "{\n\n\n"); 48 | builder.append("\tpublic static Polygon getPolygon(){\n\n\t\tPolygon p = new Polygon();\n\n"); 49 | 50 | // get a bounds for current polygon 51 | Polygon poly = new Polygon(); 52 | for (SimplePoint paintComponent : selectedComponents) { 53 | poly.addPoint(paintComponent.getX(), paintComponent.getY()); 54 | 55 | } 56 | Rectangle actual = poly.getBounds(); 57 | 58 | double xfactor = (double) actual.getWidth() / width; 59 | double yfactor = (double) actual.getHeight() / height; 60 | 61 | for (SimplePoint paintComponent : selectedComponents) { 62 | int x = (int) ((paintComponent.getX() - actual.getX()) / xfactor); 63 | int y = (int) ((paintComponent.getY() - actual.getY()) / yfactor); 64 | builder.append("\t\tp.addPoint(" + x + ", " + y + ");\n"); 65 | } 66 | 67 | builder.append("\n\n\t\treturn p;\n\t}\n\n}"); 68 | 69 | String home = System.getProperty("user.home"); 70 | File file = new File(home + "/Downloads/" + name + ".java"); 71 | try { 72 | FileOutputStream fileOutputStream = new FileOutputStream(file); 73 | fileOutputStream.write(builder.toString().getBytes()); 74 | fileOutputStream.close(); 75 | } catch (FileNotFoundException e) { 76 | // TODO Auto-generated catch block 77 | e.printStackTrace(); 78 | } catch (IOException e) { 79 | // TODO Auto-generated catch block 80 | e.printStackTrace(); 81 | } 82 | 83 | result = builder.toString(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/GeneratePolygonSourceJavaGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | 7 | import org.junit.Test; 8 | 9 | import paintcomponents.SimplePoint; 10 | import ui.PaintPanel; 11 | 12 | /** 13 | * GeneratePolygonSourceJavaGlobalAction Tester. 14 | * 15 | * We test GeneratePolygonSourceJavaGlobalAction by comparing the actual out put 16 | * with an expected output. 17 | * 18 | * @author Tan Su 19 | */ 20 | public class GeneratePolygonSourceJavaGlobalActionTest { 21 | 22 | @Test 23 | public void test() { 24 | PaintPanel panel = new PaintPanel(); 25 | GeneratePolygonSourceJavaGlobalAction action = new GeneratePolygonSourceJavaGlobalAction(); 26 | 27 | action.setWidth(108); 28 | action.setHeight(72); 29 | action.setName("GeneratedPolygon"); 30 | 31 | ArrayList selectedComponents = new ArrayList<>(); 32 | selectedComponents.add(new SimplePoint(100, 100)); 33 | selectedComponents.add(new SimplePoint(200, 100)); 34 | selectedComponents.add(new SimplePoint(200, 200)); 35 | selectedComponents.add(new SimplePoint(100, 200)); 36 | 37 | String expectedOutput = 38 | "import java.awt.Polygon;\n" 39 | + "public class GeneratedPolygon{\n" 40 | + "\n" 41 | + "\n" 42 | + "\tpublic static Polygon getPolygon(){\n" 43 | + "\n" 44 | + "\t\tPolygon p = new Polygon();\n" 45 | + "\n" 46 | + "\t\tp.addPoint(0, 0);\n" 47 | + "\t\tp.addPoint(108, 0);\n" 48 | + "\t\tp.addPoint(108, 72);\n" 49 | + "\t\tp.addPoint(0, 72);\n" 50 | + "\n" 51 | + "\n" 52 | + "\t\treturn p;\n" 53 | + "\t}\n" 54 | + "\n" 55 | + "}"; 56 | 57 | action.setSelectedComponents(selectedComponents); 58 | action.execute(panel); 59 | 60 | System.out.println(action.getResult()); 61 | assertTrue(expectedOutput.compareTo(action.getResult()) == 0); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/NameGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.PaintComponent; 4 | import paintcomponents.annotations.TextAnnotation; 5 | import script.ComponentMap; 6 | import ui.PaintPanel; 7 | import actions.edit.undoredo.SharedUndoRedoActionManager; 8 | import actions.edit.undoredo.UndoRedoableInterface; 9 | import actions.global.ActionName; 10 | import actions.global.GlobalPaintActionExecuter; 11 | 12 | public class NameGlobalAction extends SingleInstanceOperationGlobalAction { 13 | 14 | private PaintComponent comp; 15 | private String token = ""; 16 | 17 | @Override 18 | public void execute(PaintPanel panel) { 19 | comp = panel.getPaintComponents().get( 20 | panel.getPaintComponents().size() - 1); 21 | 22 | // add action to undo redo manager 23 | UndoRedoableInterface undoRedoBlock = new UndoRedoableInterface() { 24 | 25 | @Override 26 | public void undoAction() { 27 | ComponentMap.map.remove(token); 28 | comp.setOptionalAnnotation(null); 29 | panel.repaint(); 30 | } 31 | 32 | @Override 33 | public void redoAction() { 34 | ComponentMap.map.put(token, comp); 35 | new TextAnnotation(comp, token); 36 | panel.repaint(); 37 | } 38 | 39 | @Override 40 | protected String commandName() { 41 | return "name"; 42 | } 43 | 44 | @Override 45 | protected String commandDescription() { 46 | return "name a component"; 47 | } 48 | 49 | }; 50 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 51 | undoRedoBlock); 52 | 53 | } 54 | 55 | /** 56 | * @param annotationToAdd 57 | * the annotationToAdd to set 58 | */ 59 | public void setName(String token, PaintPanel panel) { 60 | this.token = token; 61 | ComponentMap.map.put(token, comp); 62 | 63 | // Add annotation 64 | AddAnnotationGlobalAction associatedAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 65 | .getAssociatedAction(); 66 | associatedAction.setAnnotationToAdd(token); 67 | associatedAction.setOperatingInstance(comp); 68 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 69 | panel); 70 | new TextAnnotation(comp, token); 71 | panel.repaint(); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /src/actions/global/globalactions/RedoActionGlobalTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import ui.PaintPanel; 8 | import actions.global.ActionName; 9 | import actions.global.GlobalPaintActionExecuter; 10 | 11 | /** 12 | * RedoActionGlobalTest 13 | * 14 | * @author cs30xsd Test the functionality of global redo action 15 | * 16 | */ 17 | public class RedoActionGlobalTest { 18 | 19 | @Test 20 | public void test() { 21 | PaintPanel panel = new PaintPanel(); 22 | 23 | // perform one action 24 | AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION 25 | .getAssociatedAction(); 26 | action.setClassToCreate(this.getClass()); 27 | GlobalPaintActionExecuter.getSharedInstance().execute(action, panel); 28 | 29 | // new redo action 30 | EditRedoGlobalAction action1 = new EditRedoGlobalAction(); 31 | EditUndoGlobalAction action2 = new EditUndoGlobalAction(); 32 | 33 | assertEquals(1, panel.getPaintComponents().size()); 34 | // perform one redo action 35 | action2.execute(panel); 36 | assertEquals(0, panel.getPaintComponents().size()); 37 | action1.execute(panel); 38 | assertEquals(1, panel.getPaintComponents().size()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/RemoveAnnotationGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import paintcomponents.PaintComponent; 4 | import actions.global.GlobalPaintAction; 5 | import ui.PaintPanel; 6 | 7 | public class RemoveAnnotationGlobalAction extends GlobalPaintAction { 8 | 9 | PaintComponent instance; 10 | 11 | public void setInstance(PaintComponent instance) { 12 | this.instance = instance; 13 | } 14 | 15 | @Override 16 | protected void execute(PaintPanel panel) { 17 | instance.setOptionalAnnotation(null); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/RemoveAnnotationGlobalActionTest.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import paintcomponents.annotations.TextAnnotation; 8 | import paintcomponents.data.DataDisplayPaintComponent; 9 | import ui.PaintPanel; 10 | import actions.global.ActionName; 11 | /** 12 | * test the removeAnnotationAction by adding and then deleting the annotation. 13 | * Then check if the annotation is null 14 | * 15 | * @author muchi 16 | */ 17 | public class RemoveAnnotationGlobalActionTest { 18 | 19 | @Test 20 | public void test() { 21 | PaintPanel panel = new PaintPanel(); 22 | 23 | AddAnnotationGlobalAction addAnnotationGlobalAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 24 | .getAssociatedAction(); 25 | 26 | // add annotations 27 | DataDisplayPaintComponent add = new DataDisplayPaintComponent("", 0, 0); 28 | addAnnotationGlobalAction.setAnnotationToAdd("hello"); 29 | addAnnotationGlobalAction.setOperatingInstance(add); 30 | addAnnotationGlobalAction.execute(panel); 31 | 32 | panel.addPaintComponent(add); 33 | 34 | // remove annotations 35 | RemoveAnnotationGlobalAction associatedAction = (RemoveAnnotationGlobalAction) ActionName.REMOVE_ANNOTATION_ACTION 36 | .getAssociatedAction(); 37 | associatedAction.setInstance(add); 38 | 39 | associatedAction.execute(panel); 40 | 41 | assertEquals(((TextAnnotation)add.getOptionalAnnotation()), null); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/SingleInstanceOperationGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.global.GlobalPaintAction; 4 | import paintcomponents.PaintComponent; 5 | import ui.PaintPanel; 6 | 7 | public abstract class SingleInstanceOperationGlobalAction extends GlobalPaintAction{ 8 | 9 | private PaintComponent operatingInstance; 10 | 11 | 12 | 13 | public PaintComponent getOperatingInstance() { 14 | return operatingInstance; 15 | } 16 | 17 | 18 | /** 19 | * @param operatingInstance the operatingInstance to set 20 | */ 21 | public void setOperatingInstance(PaintComponent operatingInstance) { 22 | this.operatingInstance = operatingInstance; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/actions/global/globalactions/UpdateDataInputBoxGlobalAction.java: -------------------------------------------------------------------------------- 1 | package actions.global.globalactions; 2 | 3 | import actions.global.GlobalPaintAction; 4 | import ui.PaintPanel; 5 | 6 | public class UpdateDataInputBoxGlobalAction extends GlobalPaintAction { 7 | 8 | @Override 9 | protected void execute(PaintPanel panel) { 10 | // TODO Auto-generated method stub 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/actions/menu/PaintActionMenuItem.java: -------------------------------------------------------------------------------- 1 | package actions.menu; 2 | 3 | import javax.swing.JMenuItem; 4 | 5 | import actions.MenuBarPaintAction; 6 | 7 | public class PaintActionMenuItem extends JMenuItem{ 8 | 9 | 10 | private MenuBarPaintAction associatedAction; 11 | private ActionsMenuBar actionsMenuBar; 12 | 13 | public PaintActionMenuItem(MenuBarPaintAction associatedAction, ActionsMenuBar actionsMenuBar) { 14 | this.setAssociatedAction(associatedAction); 15 | this.actionsMenuBar = actionsMenuBar; 16 | 17 | } 18 | 19 | public MenuBarPaintAction getAssociatedAction() { 20 | return associatedAction; 21 | } 22 | 23 | public void setAssociatedAction(MenuBarPaintAction associatedAction) { 24 | this.associatedAction = associatedAction; 25 | } 26 | 27 | public void performAction() { 28 | associatedAction.performAction(); 29 | //update menu bar status 30 | actionsMenuBar.updateEnableStatusForAllMenuItems(); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/actions/singleinstanceoperations/AddAnnotationAction.java: -------------------------------------------------------------------------------- 1 | package actions.singleinstanceoperations; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import paintcomponents.PaintComponent; 6 | import paintcomponents.annotations.TextAnnotation; 7 | import ui.PaintPanel; 8 | import actions.edit.undoredo.SharedUndoRedoActionManager; 9 | import actions.edit.undoredo.UndoRedoableInterface; 10 | import actions.global.ActionName; 11 | import actions.global.GlobalPaintActionExecuter; 12 | import actions.global.globalactions.AddAnnotationGlobalAction; 13 | import actions.menu.ActionsMenuBarTitles; 14 | 15 | /** 16 | * add the annotation to a component 17 | * 18 | * @author muchi 19 | * 20 | */ 21 | public class AddAnnotationAction extends 22 | SingleInstanceOperation { 23 | 24 | /** 25 | * ctor 26 | * 27 | * @param panel 28 | * the panel 29 | */ 30 | public AddAnnotationAction(PaintPanel panel) { 31 | super(panel); 32 | } 33 | 34 | /** 35 | * @return the location of the button 36 | */ 37 | @Override 38 | public String locationString() { 39 | return ActionsMenuBarTitles.Data().Annotations().Add().toString(); 40 | } 41 | 42 | @Override 43 | protected void performActionOnInstance(PaintComponent instance) { 44 | // TODO Auto-generated method stub 45 | String annotations = JOptionPane 46 | .showInputDialog("Please specify the annotation of the component"); 47 | // perform the action 48 | AddAnnotationGlobalAction associatedAction = (AddAnnotationGlobalAction) ActionName.ADD_ANNOTATION_ACTION 49 | .getAssociatedAction(); 50 | associatedAction.setAnnotationToAdd(annotations); 51 | associatedAction.setOperatingInstance(instance); 52 | GlobalPaintActionExecuter.getSharedInstance().execute(associatedAction, 53 | panel); 54 | // push action to manager 55 | SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction( 56 | new UndoRedoableInterface() { 57 | 58 | @Override 59 | public void undoAction() { 60 | instance.setOptionalAnnotation(null); 61 | panel.repaint(); 62 | } 63 | 64 | @Override 65 | public void redoAction() { 66 | new TextAnnotation(instance, annotations); 67 | panel.repaint(); 68 | } 69 | 70 | @Override 71 | protected String commandName() { 72 | return "add an annotation"; 73 | } 74 | 75 | @Override 76 | protected String commandDescription() { 77 | return "add an annotation"; 78 | } 79 | 80 | }); 81 | panel.repaint(); 82 | } 83 | 84 | protected Class getGenericClassType() { 85 | return PaintComponent.class; 86 | 87 | } 88 | 89 | /* 90 | * @Override protected void performActionOnInstance(PaintComponent instance) 91 | * { // ask for user input String annotations = JOptionPane 92 | * .showInputDialog("Please specify the annotation of the component"); 93 | * 94 | * 95 | * } 96 | */ 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/actions/singleinstanceoperations/SetPointSizeOperation.java: -------------------------------------------------------------------------------- 1 | package actions.singleinstanceoperations; 2 | 3 | import actions.menu.ActionsMenuBarTitles; 4 | import paintcomponents.SimplePoint; 5 | import ui.PaintPanel; 6 | import ui.general.InputManager; 7 | import ui.general.InputManagerDelegate; 8 | 9 | public class SetPointSizeOperation extends SingleInstanceOperation { 10 | 11 | public SetPointSizeOperation(PaintPanel panel) { 12 | super(panel); 13 | } 14 | 15 | 16 | @Override 17 | public String locationString() { 18 | return ActionsMenuBarTitles.Edit().Point_Size().toString(); 19 | } 20 | 21 | 22 | protected void performActionOnInstance(SimplePoint instance) { 23 | InputManager.sharedInstance().askForInt(panel, new InputManagerDelegate() { 24 | 25 | @Override 26 | public void didFinishInput(Integer input) { 27 | instance.setRadius(input); 28 | } 29 | }); 30 | 31 | } 32 | 33 | 34 | @Override 35 | protected Class getGenericClassType() { 36 | return SimplePoint.class; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/actions/singleinstanceoperations/SingleInstanceOperation.java: -------------------------------------------------------------------------------- 1 | package actions.singleinstanceoperations; 2 | 3 | import actions.MenuBarPaintAction; 4 | import paintcomponents.PaintComponent; 5 | import ui.PaintPanel; 6 | 7 | /** 8 | * Single Instance Operation defines operation on a single instance. 9 | * 10 | * i.e., 11 | * 1. 12 | * One and Only One Instance must be selected to perform operaion. 13 | * 14 | * 2. The 15 | * operation only changes the instance itself but nothing else 16 | * 17 | * 18 | * After updating, the subclass do not need to call paintcomponent.repaint method 19 | * 20 | * 21 | * @author chenzb 22 | * 23 | */ 24 | public abstract class SingleInstanceOperation extends MenuBarPaintAction { 25 | 26 | public SingleInstanceOperation(PaintPanel panel) { 27 | super(panel); 28 | } 29 | 30 | @Override 31 | public boolean canPerformAction() { 32 | if (panel.getSelectTool().getSelectedComponents().size() != 1) { 33 | return false; 34 | } 35 | PaintComponent paintComponent = panel.getSelectTool() 36 | .getSelectedComponents().get(0); 37 | 38 | 39 | //return if the object is kind of the desired class 40 | return getGenericClassType().isInstance(paintComponent); 41 | 42 | } 43 | 44 | @Override 45 | public void performAction() { 46 | @SuppressWarnings("unchecked") 47 | T comp = (T) panel.getSelectTool().getSelectedComponents().get(0); 48 | performActionOnInstance(comp); 49 | panel.repaint(); 50 | } 51 | 52 | protected abstract void performActionOnInstance(T instance); 53 | 54 | /** 55 | * Due to constraint in Java API, subclass MUST override this method 56 | * 57 | * with method body :: return T.class; 58 | * @return 59 | */ 60 | protected abstract Class getGenericClassType(); 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/actions/singleinstanceoperations/UpdateFontSizeOperation.java: -------------------------------------------------------------------------------- 1 | package actions.singleinstanceoperations; 2 | 3 | import paintcomponents.TextPaintComponent; 4 | import ui.PaintPanel; 5 | import ui.general.InputManager; 6 | import ui.general.InputManagerDelegate; 7 | import actions.menu.ActionsMenuBarTitles; 8 | 9 | public class UpdateFontSizeOperation extends SingleInstanceOperation{ 10 | 11 | public UpdateFontSizeOperation(PaintPanel panel) { 12 | super(panel); 13 | } 14 | 15 | 16 | protected void performActionOnInstance(TextPaintComponent instance) { 17 | InputManager.sharedInstance().askForFloat(panel, new InputManagerDelegate() { 18 | 19 | @Override 20 | public void didFinishInput(Float input) { 21 | instance.setFontSize(input); 22 | panel.repaint(); 23 | } 24 | }); 25 | 26 | } 27 | 28 | @Override 29 | public String locationString() { 30 | return ActionsMenuBarTitles.Edit().Font_Size().toString(); 31 | } 32 | 33 | @Override 34 | protected Class getGenericClassType() { 35 | return TextPaintComponent.class; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/buttons/CustomJButton.java: -------------------------------------------------------------------------------- 1 | package buttons; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | 6 | import javax.swing.ImageIcon; 7 | import javax.swing.JButton; 8 | 9 | public class CustomJButton extends JButton{ 10 | 11 | private String buttonTitle; 12 | 13 | public CustomJButton(String title){ 14 | buttonTitle = title; 15 | setOpaque(false); 16 | setFocusPainted(false); 17 | setBorderPainted(false); 18 | } 19 | public void setCustomImageIcon(ImageIcon i){ 20 | setIcon(i); 21 | setText(""); 22 | 23 | } 24 | 25 | public void setButtonTitle(String title){ 26 | buttonTitle = title; 27 | } 28 | 29 | public String getButtonTitle(){ 30 | return buttonTitle; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/buttons/ToolButton.java: -------------------------------------------------------------------------------- 1 | package buttons; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.Image; 5 | 6 | import javax.swing.ImageIcon; 7 | import javax.swing.JButton; 8 | import javax.swing.JToggleButton; 9 | 10 | public class ToolButton extends JToggleButton { 11 | Dimension d = new Dimension(50,50); 12 | 13 | public ToolButton(String str){ 14 | super(str); 15 | 16 | 17 | } 18 | 19 | public ToolButton(){ 20 | setOpaque(false); 21 | setFocusPainted(false); 22 | setBorderPainted(false); 23 | setButtonSize(d); 24 | } 25 | 26 | 27 | public void setSelectedImage(ImageIcon icon){ 28 | Image img = icon.getImage() ; 29 | Image newimg = img.getScaledInstance( this.getWidth(), this.getHeight(), java.awt.Image.SCALE_SMOOTH ) ; 30 | icon = new ImageIcon( newimg ); 31 | setSelectedIcon(icon); 32 | } 33 | 34 | public void setOriginalImage(ImageIcon icon){ 35 | Image img = icon.getImage() ; 36 | Image newimg = img.getScaledInstance( this.getWidth(), this.getHeight(), java.awt.Image.SCALE_SMOOTH ) ; 37 | icon = new ImageIcon( newimg ); 38 | setIcon(icon); 39 | } 40 | 41 | public void setButtonSize(Dimension d){ 42 | setSize(d); 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/classpathutil/ClassSearch.java: -------------------------------------------------------------------------------- 1 | package classpathutil; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ClassSearch { 6 | private static ClassSearch sharedInstance = new ClassSearch(); 7 | 8 | public static ClassSearch sharedInstance() { 9 | return sharedInstance; 10 | } 11 | 12 | private ArrayList allClasses; 13 | 14 | /** 15 | * Constructs a ClassSearch Instance The method 16 | */ 17 | private ClassSearch() { 18 | // load classes 19 | 20 | allClasses = new ArrayList<>(); 21 | ClassFinder.findClasses(new Visitor() { 22 | 23 | @Override 24 | public boolean visit(String t) { 25 | allClasses.add(t); 26 | return true; 27 | } 28 | }); 29 | 30 | } 31 | 32 | public ArrayList classesForName(String name) { 33 | 34 | ArrayList result = new ArrayList<>(); 35 | for (String string : allClasses) { 36 | if (string.contains(name)) { 37 | result.add(string); 38 | } 39 | } 40 | 41 | return sortAccordingToPrecedence(result, name); 42 | } 43 | 44 | private ArrayList sortAccordingToPrecedence( 45 | ArrayList result, String name) { 46 | ArrayList sorted = new ArrayList<>(); 47 | 48 | for (String string : result) { 49 | String[] comps = string.split("\\."); 50 | if (comps.length == 0) 51 | continue; 52 | 53 | if (comps[comps.length - 1].startsWith(name)) { 54 | sorted.add(0, string); 55 | } else { 56 | sorted.add(string); 57 | } 58 | } 59 | 60 | ArrayList ret = new ArrayList<>(); 61 | for (String string : sorted) { 62 | String[] comps = string.split("\\."); 63 | 64 | if (comps.length > 1) { 65 | string = comps[comps.length - 1]; 66 | string += " ("; 67 | 68 | for (int i = 0; i < comps.length - 1; i++) { 69 | string += comps[i]; 70 | 71 | if (i < comps.length - 2) { 72 | string += "."; 73 | } 74 | } 75 | 76 | string += ")"; 77 | } 78 | 79 | ret.add(string); 80 | } 81 | 82 | return ret; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/classpathutil/ClassSearchTest.java: -------------------------------------------------------------------------------- 1 | package classpathutil; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | 7 | import org.junit.Test; 8 | 9 | public class ClassSearchTest { 10 | 11 | @Test 12 | public void test() { 13 | ClassSearch search = ClassSearch.sharedInstance(); 14 | ArrayList classesForName = search.classesForName("System"); 15 | 16 | assertTrue(classesForName.contains("System (java.lang)")); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/classpathutil/Visitor.java: -------------------------------------------------------------------------------- 1 | package classpathutil; 2 | 3 | public interface Visitor { 4 | /** 5 | * @return {@code true} if the algorithm should visit more results, 6 | * {@code false} if it should terminate now. 7 | */ 8 | public boolean visit(T t); 9 | } -------------------------------------------------------------------------------- /src/paintcomponents/NoConnectingLineSegmentException.java: -------------------------------------------------------------------------------- 1 | package paintcomponents; 2 | 3 | public class NoConnectingLineSegmentException extends Exception { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/paintcomponents/XMLEncodingUtilForPaintComponents.java: -------------------------------------------------------------------------------- 1 | package paintcomponents; 2 | 3 | import java.awt.Color; 4 | 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | 8 | public class XMLEncodingUtilForPaintComponents { 9 | 10 | private static final String TAG_NAME_BLUE = "blue"; 11 | private static final String TAG_NAME_GREEN = "green"; 12 | private static final String TAG_NAME_RED = "red"; 13 | 14 | /** 15 | * attach (append to child) RGB to the element, in the format 12 etc 16 | * @param rgb 17 | * @param elem 18 | * @param doc 19 | */ 20 | public static void attachRGB(Color rgb, Element elem, Document doc){ 21 | int r = rgb.getRed(); 22 | int g = rgb.getGreen(); 23 | int b = rgb.getBlue(); 24 | 25 | //create element 26 | Element red = doc.createElement(TAG_NAME_RED); 27 | Element green = doc.createElement(TAG_NAME_GREEN); 28 | Element blue = doc.createElement(TAG_NAME_BLUE); 29 | 30 | //fill the content 31 | red.appendChild(doc.createTextNode(Integer.toString(r))); 32 | green.appendChild(doc.createTextNode(Integer.toString(g))); 33 | blue.appendChild(doc.createTextNode(Integer.toString(b))); 34 | 35 | //structure the content 36 | elem.appendChild(red); 37 | elem.appendChild(green); 38 | elem.appendChild(blue); 39 | } 40 | 41 | /** 42 | * Constructs a rgb value from given document 43 | * @param elem 44 | * @return 45 | */ 46 | public static Color getRGB(Element elem){ 47 | int r = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_RED).item(0).getTextContent()); 48 | int g = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_GREEN).item(0).getTextContent()); 49 | int b = Integer.parseInt(elem.getElementsByTagName(TAG_NAME_BLUE).item(0).getTextContent()); 50 | return new Color(r, g, b); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/paintcomponents/annotations/PaintComponentAnnotation.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.annotations; 2 | 3 | import paintcomponents.PaintComponent; 4 | 5 | /** 6 | * Annotations is part of the paint panel that is attached to a particular paint 7 | * component Annotations does not mainly impact the behavior of underlying paint 8 | * components, but extends the component to be more extensible 9 | * 10 | * @author chenzb 11 | * 12 | */ 13 | public abstract class PaintComponentAnnotation extends PaintComponent { 14 | 15 | private PaintComponent attachedComponent; 16 | 17 | public PaintComponentAnnotation(PaintComponent attachedComponent) { 18 | super(attachedComponent.getX(), attachedComponent.getY()); 19 | this.setAttachedComponent(attachedComponent); 20 | attachedComponent.setOptionalAnnotation(this); 21 | } 22 | 23 | /** 24 | * @return the attachedComponent 25 | */ 26 | public PaintComponent getAttachedComponent() { 27 | return attachedComponent; 28 | } 29 | 30 | /** 31 | * @param attachedComponent 32 | * the attachedComponent to set 33 | */ 34 | public void setAttachedComponent(PaintComponent attachedComponent) { 35 | this.attachedComponent = attachedComponent; 36 | } 37 | 38 | /** 39 | * set the font size of the annotation 40 | * 41 | * @param input 42 | * the new size 43 | */ 44 | abstract public void setFontSize(float input); 45 | } 46 | -------------------------------------------------------------------------------- /src/paintcomponents/annotations/TextAnnotation.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.annotations; 2 | 3 | import java.awt.Graphics; 4 | 5 | import paintcomponents.PaintComponent; 6 | import paintcomponents.TextPaintComponent; 7 | 8 | /** 9 | * the text annotation of the component 10 | * @author muchi 11 | * 12 | */ 13 | public class TextAnnotation extends PaintComponentAnnotation { 14 | 15 | private TextPaintComponent textPaintComponent; 16 | 17 | /** 18 | * create the annotation of a component with information 19 | * 20 | * @param attachedComponent the component attached to the annotation 21 | * @param displayingText the information to be displayed 22 | */ 23 | public TextAnnotation(PaintComponent attachedComponent, String displayingText) { 24 | super(attachedComponent); 25 | this.textPaintComponent = new TextPaintComponent(displayingText, attachedComponent.getX(), 26 | attachedComponent.getY()); 27 | } 28 | 29 | @Override 30 | protected void paintNotSelected(Graphics g) { 31 | textPaintComponent.updateBounds(g); 32 | textPaintComponent.setY(getAttachedComponent().getY() - textPaintComponent.getRowHeight()); 33 | textPaintComponent.paint(g); 34 | } 35 | 36 | @Override 37 | protected void paintSelected(Graphics g) { 38 | // TODO Auto-generated method stub 39 | textPaintComponent.updateBounds(g); 40 | textPaintComponent.setY(getAttachedComponent().getY() - textPaintComponent.getRowHeight()); 41 | textPaintComponent.paint(g); 42 | } 43 | 44 | /** 45 | * @return true if the given position is contained, otherwise false 46 | */ 47 | @Override 48 | public boolean contains(int x2, int y2) { 49 | // TODO Auto-generated method stub 50 | return textPaintComponent.contains(x2, y2); 51 | } 52 | 53 | /** 54 | * move the text 55 | * 56 | * @param x the movement on x-position 57 | * @param y the movement on y-position 58 | */ 59 | public void translate(int x, int y){ 60 | textPaintComponent.translate(x, y); 61 | } 62 | 63 | /** 64 | * set the font size of the given annotation 65 | * 66 | * @param input the size 67 | */ 68 | @Override 69 | public void setFontSize(float input) { 70 | textPaintComponent.setFontSize(input); 71 | } 72 | 73 | /** 74 | * 75 | */ 76 | public String getStringContent(){ 77 | return textPaintComponent.getStringContent(); 78 | } 79 | 80 | public TextPaintComponent getTextPaintComponent() { 81 | return textPaintComponent; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataDisplayPaintComponent.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | import java.util.NoSuchElementException; 4 | 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | 8 | import paintcomponents.NoConnectingLineSegmentException; 9 | import typesystem.JavaType; 10 | import ui.PaintPanel; 11 | 12 | /** 13 | * The data display paint component displays the data with a asoociated DataToPoint 14 | * @author chenzb 15 | * 16 | */ 17 | //TODO THIS class is a copy of DataInputTextfieldPaintComponent class, please consider abstraction 18 | public class DataDisplayPaintComponent extends DataTextIOPaintComponent { 19 | 20 | 21 | public DataDisplayPaintComponent(String displayingText, int x, int y) { 22 | super(displayingText, x, y); 23 | addToPoint(0, new JavaType(String.class)); 24 | } 25 | 26 | /** 27 | * Update the current display. 28 | * 29 | * This class will try to fetch the data from the toPointClass 30 | * @throws DataFromPointProviderCannotProvideDataException 31 | * @throws DataFromPointNoDataProviderException 32 | * @throws NoConnectingLineSegmentException 33 | * @throws NoSuchElementException 34 | * @see DataToPoint.fetchData for exception details 35 | */ 36 | public void updateDisplayText() throws NoSuchElementException, NoConnectingLineSegmentException, 37 | DataFromPointNoDataProviderException, DataFromPointProviderCannotProvideDataException{ 38 | Object data = getToPoints().get(0).fetchData(); 39 | this.setDisplayingText(data.toString()); 40 | /*if(data instanceof String){ 41 | this.setDisplayingText(data.toString()); 42 | } else { 43 | this.setDisplayingText("Error: Not A String :: " + "Type : " + 44 | data.getClass().toString() + " Value: " + data.toString()); 45 | }*/ 46 | } 47 | 48 | public boolean canUpdate() { 49 | return true; // temporary 50 | /* 51 | * try { Object data = getToPoints().get(0).fetchData(); if (data 52 | * instanceof String) { return true; } } catch (Exception e) { return 53 | * false; } return false; 54 | */ 55 | } 56 | 57 | @Override 58 | public void saveToElement(Element rootElement, Document doc) { 59 | super.saveToElement(rootElement, doc); 60 | //since the original class already saved the displaying text, there is no need for us to do the same thing 61 | } 62 | 63 | public DataDisplayPaintComponent(Element rootElement, PaintPanel panel) { 64 | super(rootElement, panel); 65 | //we only need to do the same thing as our designated constructor 66 | addToPoint(0, new JavaType(String.class)); 67 | //we have to link the points 68 | linkPoints(rootElement); 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataFromPoint.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | import org.w3c.dom.Document; 4 | import org.w3c.dom.Element; 5 | 6 | import paintcomponents.SimplePoint; 7 | import typesystem.Type; 8 | import ui.PaintPanel; 9 | 10 | /** 11 | * This point consumes data and tries to pass the data along a connecting line 12 | * segment 13 | * 14 | * @author chenzb 15 | * 16 | */ 17 | public class DataFromPoint extends SimplePoint { 18 | 19 | private DataLineSegment lineSegment; 20 | private DataFromPointDataProvider provider; 21 | private Type expectedType; 22 | 23 | /** 24 | * @return the lineSegment 25 | */ 26 | public DataLineSegment getLineSegment() { 27 | return lineSegment; 28 | } 29 | 30 | /** 31 | * @param lineSegment 32 | * the lineSegment to set 33 | */ 34 | public void setLineSegment(DataLineSegment lineSegment) { 35 | this.lineSegment = lineSegment; 36 | } 37 | 38 | public DataFromPoint(int x, int y, Type expectedType) { 39 | super(x, y); 40 | this.expectedType = expectedType; 41 | } 42 | 43 | /** 44 | * Fetches the data, users should not try to call this method, except from 45 | * DataToPoint class 46 | * 47 | * @param data 48 | * @throws DataFromPointNoDataProviderException if provider for this method is not set 49 | * @throws DataFromPointProviderCannotProvideDataException if the provider cannot provide such information 50 | */ 51 | protected Object getData() throws DataFromPointNoDataProviderException, DataFromPointProviderCannotProvideDataException { 52 | if (this.provider == null){ 53 | throw new DataFromPointNoDataProviderException(); 54 | } 55 | if (!this.provider.canProvideInformationToDataFromPoint(this)){ 56 | throw new DataFromPointProviderCannotProvideDataException(); 57 | } 58 | return this.provider.provideInformationToDataFromPoint(this); 59 | } 60 | 61 | public DataFromPointDataProvider getProvider() { 62 | return provider; 63 | } 64 | 65 | public void setProvider(DataFromPointDataProvider provider) { 66 | this.provider = provider; 67 | } 68 | 69 | public Type getExpectedType() { 70 | return expectedType; 71 | } 72 | 73 | public void setExpectedType(Type expectedType) { 74 | this.expectedType = expectedType; 75 | } 76 | 77 | @Override 78 | public void saveToElement(Element rootElement, Document doc) { 79 | // TODO Auto-generated method stub 80 | super.saveToElement(rootElement, doc); 81 | } 82 | 83 | public DataFromPoint(Element rootElement, PaintPanel panel) { 84 | super(rootElement, panel); 85 | // TODO Auto-generated constructor stub 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataFromPointDataProvider.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | 4 | public interface DataFromPointDataProvider { 5 | 6 | public Object provideInformationToDataFromPoint(DataFromPoint dataFromPoint); 7 | public boolean canProvideInformationToDataFromPoint(DataFromPoint dataFromPoint); 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataFromPointNoDataProviderException.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | public class DataFromPointNoDataProviderException extends Exception { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataFromPointProviderCannotProvideDataException.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | public class DataFromPointProviderCannotProvideDataException extends Exception { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataInputTextfieldPaintComponent.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | import org.w3c.dom.Document; 4 | import org.w3c.dom.Element; 5 | 6 | import typesystem.JavaType; 7 | import ui.PaintPanel; 8 | 9 | /** 10 | * A data text with a point on the right 11 | * 12 | * @author chenzb 13 | * 14 | */ 15 | public class DataInputTextfieldPaintComponent extends DataTextIOPaintComponent 16 | implements DataFromPointDataProvider{ 17 | 18 | 19 | //Protect the class box from being updated 20 | boolean canUpdate = true; 21 | 22 | public DataInputTextfieldPaintComponent(String displayingText, int x, 23 | int y) { 24 | super(displayingText, x, y); 25 | addFromPoint(this, 0, new JavaType(String.class)); 26 | } 27 | 28 | public void inputData(String s) { 29 | this.setDisplayingText(s); 30 | } 31 | 32 | @Override 33 | public Object provideInformationToDataFromPoint( 34 | DataFromPoint dataFromPoint) { 35 | return getDisplayingText(); 36 | } 37 | 38 | @Override 39 | public boolean canProvideInformationToDataFromPoint( 40 | DataFromPoint dataFromPoint) { 41 | return getDisplayingText() != null; 42 | } 43 | 44 | @Override 45 | public void saveToElement(Element rootElement, Document doc) { 46 | super.saveToElement(rootElement, doc); 47 | //save does nothing as this particular class does not have any instance properties 48 | } 49 | 50 | public DataInputTextfieldPaintComponent(Element rootElement, PaintPanel panel) { 51 | super(rootElement, panel); 52 | //do the same thing as the designated constructor 53 | addFromPoint(this, 0, new JavaType(String.class)); 54 | //link the points 55 | linkPoints(rootElement); 56 | } 57 | 58 | /* 59 | * Set this input box to be "in-updatable" 60 | * Now this should only be used by the class input box 61 | */ 62 | public void setCannotUpdate(){ 63 | this.canUpdate = false; 64 | } 65 | 66 | /* 67 | * Getter for whether it's updatable. 68 | */ 69 | public boolean canUpdate(){ 70 | return this.canUpdate; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataTextPaintComponent.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | import java.awt.BasicStroke; 4 | import java.awt.Graphics; 5 | import java.awt.Graphics2D; 6 | 7 | import org.w3c.dom.Document; 8 | import org.w3c.dom.Element; 9 | 10 | import paintcomponents.RectanglePaintComponent; 11 | import paintcomponents.TextPaintComponent; 12 | import painttools.tools.SelectTool; 13 | import ui.PaintPanel; 14 | 15 | /** 16 | * A text component with a bounding box, this.bounds is updated in paint method 17 | * 18 | * @author chenzb 19 | * 20 | */ 21 | public class DataTextPaintComponent extends TextPaintComponent { 22 | 23 | private RectanglePaintComponent rect; 24 | 25 | public DataTextPaintComponent(String displayingText, int x, int y) { 26 | super(displayingText, x, y); 27 | rect = new RectanglePaintComponent(x, y, 0, 0); 28 | } 29 | 30 | @Override 31 | protected void paintNotSelected(Graphics g) { 32 | ((Graphics2D) g).setStroke(new BasicStroke(1)); 33 | super.paintNotSelected(g); 34 | updateAndPaintBoudingRectangle(g); 35 | 36 | } 37 | 38 | @Override 39 | protected void paintSelected(Graphics g) { 40 | ((Graphics2D) g).setStroke(new BasicStroke(1)); 41 | super.paintSelected(g); 42 | ; 43 | updateAndPaintBoudingRectangle(g); 44 | } 45 | 46 | private void updateAndPaintBoudingRectangle(Graphics g) { 47 | rect.setWidth((int) getBounds().getWidth()); 48 | rect.setHeight((int) getBounds().getHeight()); 49 | rect.paint(g); 50 | } 51 | 52 | @Override 53 | public void translate(int i, int j) { 54 | super.translate(i, j); 55 | this.rect.translate(i, j); 56 | } 57 | 58 | @Override 59 | public void select(SelectTool selectTool) { 60 | super.select(selectTool); 61 | // pass in null to prevent current selection from being modified 62 | // only causes changes in apperance 63 | rect.select(null); 64 | } 65 | 66 | @Override 67 | public void deselect(SelectTool selectTool) { 68 | // TODO Auto-generated method stub 69 | super.deselect(selectTool); 70 | rect.deselect(null); 71 | } 72 | 73 | @Override 74 | public void saveToElement(Element rootElement, Document doc) { 75 | super.saveToElement(rootElement, doc); 76 | 77 | Element main = doc.createElement("datatextpaintcomponent"); 78 | Element rectElem = doc.createElement("rect"); 79 | 80 | rect.saveToElement(rectElem, doc); 81 | main.appendChild(rectElem); 82 | 83 | rootElement.appendChild(main); 84 | } 85 | 86 | public DataTextPaintComponent(Element rootElement, PaintPanel panel) { 87 | super(rootElement, panel); 88 | Element main = (Element) rootElement.getElementsByTagName( 89 | "datatextpaintcomponent").item(0); 90 | Element rectElem = (Element) main.getElementsByTagName("rect").item(0); 91 | this.rect = new RectanglePaintComponent(rectElem, panel); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/paintcomponents/data/DataToPoint.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.data; 2 | 3 | import java.util.NoSuchElementException; 4 | 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | 8 | import paintcomponents.NoConnectingLineSegmentException; 9 | import paintcomponents.SimplePoint; 10 | import typesystem.Type; 11 | import ui.PaintPanel; 12 | 13 | /** 14 | * Data to point is the point where data is flowing to. 15 | * You can "get" data from this point 16 | * @author chenzb 17 | * 18 | */ 19 | public class DataToPoint extends SimplePoint { 20 | 21 | 22 | DataLineSegment lineSegment; 23 | private Type expectedType; 24 | 25 | /** 26 | * @return the lineSegment 27 | */ 28 | public DataLineSegment getLineSegment() { 29 | return lineSegment; 30 | } 31 | 32 | /** 33 | * @param lineSegment the lineSegment to set 34 | */ 35 | public void setLineSegment(DataLineSegment lineSegment) { 36 | this.lineSegment = lineSegment; 37 | } 38 | 39 | public DataToPoint(int x, int y, Type expectedType) { 40 | super(x, y); 41 | this.expectedType = expectedType; 42 | } 43 | 44 | 45 | /** 46 | * Try to fetch a data from a connecting point 47 | * 48 | * @throws NoConnectingLineSegmentException when this point is not connected to a valid line segment 49 | * @throws NoSuchElementException when the connecting in point does not have a data to offer 50 | * @throws DataFromPointProviderCannotProvideDataException when the connecting dataInputPoint's data provider cannot provide a information 51 | * @throws DataFromPointNoDataProviderException when the connecting DataInputPoint does not have a data provider associated 52 | */ 53 | public Object fetchData() throws NoConnectingLineSegmentException, NoSuchElementException, 54 | DataFromPointNoDataProviderException, DataFromPointProviderCannotProvideDataException{ 55 | if(this.lineSegment == null) throw new NoConnectingLineSegmentException(); 56 | 57 | Object returnVal = lineSegment.getFromPoint().getData();// .toString(); 58 | if(returnVal == null) throw new NoSuchElementException(); 59 | return returnVal; 60 | 61 | } 62 | 63 | public Type getExpectedType() { 64 | return expectedType; 65 | } 66 | 67 | public void setExpectedType(Type expectedType) { 68 | this.expectedType = expectedType; 69 | } 70 | 71 | @Override 72 | public void saveToElement(Element rootElement, Document doc) { 73 | // TODO Auto-generated method stub 74 | super.saveToElement(rootElement, doc); 75 | } 76 | 77 | public DataToPoint(Element rootElement, PaintPanel panel) { 78 | super(rootElement, panel); 79 | // TODO Auto-generated constructor stub 80 | } 81 | 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/paintcomponents/haskell/EvaluateHaskellPaintComponent.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.haskell; 2 | 3 | import java.util.NoSuchElementException; 4 | 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Element; 7 | 8 | import paintcomponents.NoConnectingLineSegmentException; 9 | import paintcomponents.data.DataDisplayPaintComponent; 10 | import paintcomponents.data.DataFromPointNoDataProviderException; 11 | import paintcomponents.data.DataFromPointProviderCannotProvideDataException; 12 | import ui.PaintPanel; 13 | 14 | public class EvaluateHaskellPaintComponent extends DataDisplayPaintComponent{ 15 | 16 | HaskellEngine engine; 17 | public EvaluateHaskellPaintComponent(String displayingText, int x, int y) { 18 | super(displayingText, x, y); 19 | engine = new HaskellEngine(); 20 | 21 | } 22 | 23 | @Override 24 | public void updateDisplayText() 25 | throws NoSuchElementException, NoConnectingLineSegmentException, 26 | DataFromPointNoDataProviderException, 27 | DataFromPointProviderCannotProvideDataException { 28 | super.updateDisplayText(); 29 | setDisplayingText(engine.valueForExpression(this.getDisplayingText())); 30 | 31 | } 32 | 33 | @Override 34 | public void saveToElement(Element rootElement, Document doc) { 35 | super.saveToElement(rootElement, doc); 36 | //the default implementation does nothing` 37 | } 38 | 39 | public EvaluateHaskellPaintComponent(Element rootElement, 40 | PaintPanel panel) { 41 | super(rootElement, panel); 42 | this.engine = new HaskellEngine(); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/paintcomponents/haskell/ParenthesisParser.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.haskell; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ParenthesisParser { 6 | 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/paintcomponents/java/lazy/ClassPaintComponent.java: -------------------------------------------------------------------------------- 1 | package paintcomponents.java.lazy; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import org.w3c.dom.DOMException; 6 | import org.w3c.dom.Document; 7 | import org.w3c.dom.Element; 8 | 9 | import paintcomponents.data.DataFromPoint; 10 | import paintcomponents.data.DataInputTextfieldPaintComponent; 11 | import typesystem.JavaType; 12 | import ui.PaintPanel; 13 | 14 | public class ClassPaintComponent extends DataInputTextfieldPaintComponent{ 15 | 16 | Class displayingClass; 17 | 18 | /** 19 | * @return the displayingClass 20 | */ 21 | public Class getDisplayingClass() { 22 | return displayingClass; 23 | } 24 | 25 | public ClassPaintComponent(Class displayingClass, int x, int y) { 26 | super("class " + displayingClass.getName(), x, y); 27 | this.displayingClass = displayingClass; 28 | //make sure we set correct type for outgoint edges 29 | this.getFromPoints().get(0).setExpectedType(new JavaType(displayingClass.getClass())); 30 | } 31 | 32 | @Override 33 | public boolean canProvideInformationToDataFromPoint( 34 | DataFromPoint dataFromPoint) { 35 | return displayingClass != null; 36 | } 37 | 38 | @Override 39 | public Object provideInformationToDataFromPoint( 40 | DataFromPoint dataFromPoint) { 41 | return this.displayingClass; 42 | } 43 | 44 | @Override 45 | public void saveToElement(Element rootElement, Document doc) { 46 | super.saveToElement(rootElement, doc); 47 | 48 | //build structure 49 | Element main = doc.createElement("classpaintcomponent"); 50 | Element classNameElem = doc.createElement("classname"); 51 | 52 | rootElement.appendChild(main); 53 | main.appendChild(classNameElem); 54 | 55 | classNameElem.appendChild(doc.createTextNode(displayingClass.getName())); 56 | } 57 | 58 | public ClassPaintComponent(Element rootElement, PaintPanel panel) { 59 | super(rootElement, panel); 60 | Element main = (Element) rootElement.getElementsByTagName("classpaintcomponent").item(0); 61 | Element classNameElem = (Element) main.getElementsByTagName("classname").item(0); 62 | 63 | try { 64 | this.displayingClass = Class.forName(classNameElem.getTextContent()); 65 | this.setDisplayingText(this.displayingClass.getName()); 66 | //make sure we set correct type for outgoint edges 67 | this.getFromPoints().get(0).setExpectedType(new JavaType(displayingClass.getClass())); 68 | 69 | //no linking since Data Text filed already linked 70 | 71 | } catch (ClassNotFoundException | DOMException e) { 72 | JOptionPane.showMessageDialog(panel, e.toString()); 73 | e.printStackTrace(); 74 | } 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/painttools/toolbar/ToolBarListener.java: -------------------------------------------------------------------------------- 1 | package painttools.toolbar; 2 | 3 | import painttools.tools.PaintToolsInterface; 4 | 5 | public interface ToolBarListener { 6 | 7 | public abstract void toolSelected(PaintToolsInterface tool); 8 | } 9 | -------------------------------------------------------------------------------- /src/painttools/tools/ActionToolsInterface.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | import java.awt.event.ActionListener; 4 | 5 | 6 | /** 7 | * This is a interface for Action buttons in tool bar 8 | */ 9 | public interface ActionToolsInterface extends PaintToolsInterface, ActionListener { 10 | 11 | /** 12 | * If you implement add paint action tools: 13 | * 14 | * 1. make sure override the actionPeformed method to define actions when 15 | * button is clicked. 16 | * 17 | * 2. modify mouseClicked method to defined actions to perform when click 18 | * on paintPanel 19 | * 20 | * 3. you can call setX and setY to set the starting point for paintComponent 21 | * 22 | * 4. you may need to call createButton in constructor to create a button for 23 | * this tool, and you can set icons for button in createButton. 24 | * 25 | * 26 | */ 27 | } 28 | -------------------------------------------------------------------------------- /src/painttools/tools/AddMethodTool.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.awt.event.MouseEvent; 6 | import java.awt.event.MouseWheelEvent; 7 | 8 | import javax.swing.ImageIcon; 9 | 10 | import actions.AddLazyJavaMethodComponentAction; 11 | import buttons.ToolButton; 12 | import ui.PaintPanel; 13 | import ui.cursor.CustomCursors; 14 | 15 | public class AddMethodTool implements ActionToolsInterface { 16 | 17 | private ToolButton button; 18 | private PaintPanel panel; 19 | public AddMethodTool(PaintPanel panel) { 20 | this.panel = panel; 21 | createButton(); 22 | 23 | 24 | } 25 | 26 | 27 | @Override 28 | public void start(PaintPanel panel) { 29 | } 30 | 31 | @Override 32 | public void createButton() { 33 | // TODO Auto-generated method stub 34 | button = new ToolButton(); 35 | 36 | ImageIcon icon = new ImageIcon("./images/dot.png"); 37 | button.setOriginalImage(icon); 38 | 39 | ImageIcon icon2 = new ImageIcon("./images/dotselected.png"); 40 | button.setSelectedImage(icon2); 41 | AddLazyJavaMethodComponentAction action = new AddLazyJavaMethodComponentAction(panel); 42 | 43 | button.addActionListener(new ActionListener() { 44 | @Override 45 | public void actionPerformed(ActionEvent e) { 46 | 47 | if (action.canPerformAction()) { 48 | action.performAction(); 49 | } 50 | 51 | } 52 | }); 53 | 54 | 55 | 56 | } 57 | @Override 58 | public ToolButton getButton() { 59 | 60 | return button; 61 | } 62 | 63 | @Override 64 | public void reset() { 65 | 66 | } 67 | 68 | @Override 69 | public void mouseClicked(MouseEvent e) { 70 | // TODO Auto-generated method stub 71 | 72 | } 73 | 74 | @Override 75 | public void mouseEntered(MouseEvent e) { 76 | // TODO Auto-generated method stub 77 | 78 | } 79 | 80 | @Override 81 | public void mouseExited(MouseEvent e) { 82 | // TODO Auto-generated method stub 83 | 84 | } 85 | 86 | @Override 87 | public void mousePressed(MouseEvent e) { 88 | // TODO Auto-generated method stub 89 | 90 | } 91 | 92 | @Override 93 | public void mouseReleased(MouseEvent e) { 94 | // TODO Auto-generated method stub 95 | 96 | } 97 | 98 | @Override 99 | public void mouseDragged(MouseEvent e) { 100 | // TODO Auto-generated method stub 101 | 102 | } 103 | 104 | @Override 105 | public void mouseMoved(MouseEvent e) { 106 | } 107 | 108 | 109 | @Override 110 | public void actionPerformed(ActionEvent e) { 111 | 112 | panel.setNewCursor (CustomCursors.addComponentcursor()); 113 | 114 | } 115 | 116 | @Override 117 | public void mouseWheelMoved(MouseWheelEvent e) { 118 | // TODO Auto-generated method stub 119 | 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /src/painttools/tools/DefaultPaintTool.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | public @interface DefaultPaintTool { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/painttools/tools/DotTool.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | import java.awt.event.MouseEvent; 4 | import java.awt.event.MouseWheelEvent; 5 | 6 | import javax.swing.SwingUtilities; 7 | 8 | import buttons.ToolButton; 9 | import paintcomponents.SimplePoint; 10 | import ui.PaintPanel; 11 | import ui.icons.CustomIcons; 12 | 13 | public class DotTool implements PaintToolsInterface { 14 | 15 | SimplePoint p; 16 | private PaintPanel panel; 17 | private ToolButton button; 18 | 19 | public DotTool(){ 20 | createButton(); 21 | } 22 | @Override 23 | public void start(PaintPanel panel) { 24 | this.panel = panel; 25 | 26 | panel.hideCursor(); 27 | p = new SimplePoint(0, 0); 28 | panel.setTempComponent(p); 29 | 30 | } 31 | @Override 32 | public void createButton() { 33 | button = new ToolButton(); 34 | button.setOriginalImage(CustomIcons.dot()); 35 | button.setSelectedImage(CustomIcons.selectedDot()); 36 | 37 | } 38 | @Override 39 | public ToolButton getButton() { 40 | 41 | return button; 42 | } 43 | 44 | @Override 45 | public void mouseClicked(MouseEvent e) { 46 | 47 | SimplePoint pointToAdd = new SimplePoint(p); 48 | 49 | // change selection to be only the added point 50 | panel.getSelectTool().clearSelection(); 51 | panel.getSelectTool().selectComponent(pointToAdd); 52 | 53 | panel.addPaintComponent(pointToAdd); 54 | if (!SwingUtilities.isRightMouseButton(e)) { 55 | panel.setDefaultSelectTool(); 56 | } 57 | 58 | } 59 | 60 | @Override 61 | public void mousePressed(MouseEvent e) { 62 | // TODO Auto-generated method stub 63 | 64 | } 65 | 66 | @Override 67 | public void mouseReleased(MouseEvent e) { 68 | // TODO Auto-generated method stub 69 | 70 | } 71 | 72 | @Override 73 | public void mouseEntered(MouseEvent e) { 74 | // TODO Auto-generated method stub 75 | 76 | } 77 | 78 | @Override 79 | public void mouseExited(MouseEvent e) { 80 | // TODO Auto-generated method stub 81 | 82 | } 83 | 84 | @Override 85 | public void mouseDragged(MouseEvent e) { 86 | // TODO Auto-generated method stub 87 | 88 | } 89 | 90 | @Override 91 | public void mouseMoved(MouseEvent e) { 92 | p.setX(e.getX()); 93 | p.setY(e.getY()); 94 | panel.repaint(); 95 | } 96 | 97 | @Override 98 | public void reset() { 99 | // do nothing on reset 100 | // temporary component will automatically be removed 101 | 102 | } 103 | 104 | @Override 105 | public void mouseWheelMoved(MouseWheelEvent e) { 106 | // TODO Auto-generated method stub 107 | 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/painttools/tools/PaintToolsInterface.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | import java.awt.event.MouseListener; 3 | import java.awt.event.MouseMotionListener; 4 | import java.awt.event.MouseWheelListener; 5 | 6 | import buttons.ToolButton; 7 | import ui.PaintPanel; 8 | 9 | public interface PaintToolsInterface extends MouseListener, MouseMotionListener, MouseWheelListener { 10 | 11 | 12 | /** 13 | * Set the start condition of this paint tool 14 | */ 15 | public abstract void start(PaintPanel panel); 16 | 17 | /** 18 | * Resets all the pending states, called when a new tool is selected 19 | * or when esc is pressed. 20 | */ 21 | public abstract void reset(); 22 | 23 | public ToolButton getButton(); 24 | 25 | public void createButton(); 26 | } 27 | -------------------------------------------------------------------------------- /src/painttools/tools/RemoveComponentTool.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | import java.awt.event.MouseEvent; 4 | import java.awt.event.MouseWheelEvent; 5 | 6 | import buttons.ToolButton; 7 | import ui.PaintPanel; 8 | 9 | public class RemoveComponentTool implements PaintToolsInterface { 10 | 11 | @Override 12 | public void mouseClicked(MouseEvent e) { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public void mousePressed(MouseEvent e) { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | @Override 24 | public void mouseReleased(MouseEvent e) { 25 | // TODO Auto-generated method stub 26 | 27 | } 28 | 29 | @Override 30 | public void mouseEntered(MouseEvent e) { 31 | // TODO Auto-generated method stub 32 | 33 | } 34 | 35 | @Override 36 | public void mouseExited(MouseEvent e) { 37 | // TODO Auto-generated method stub 38 | 39 | } 40 | 41 | @Override 42 | public void mouseDragged(MouseEvent e) { 43 | // TODO Auto-generated method stub 44 | 45 | } 46 | 47 | @Override 48 | public void mouseMoved(MouseEvent e) { 49 | // TODO Auto-generated method stub 50 | 51 | } 52 | 53 | @Override 54 | public void start(PaintPanel panel) { 55 | // TODO Auto-generated method stub 56 | 57 | } 58 | 59 | @Override 60 | public void reset() { 61 | // TODO Auto-generated method stub 62 | 63 | } 64 | 65 | @Override 66 | public ToolButton getButton() { 67 | // TODO Auto-generated method stub 68 | return null; 69 | } 70 | 71 | @Override 72 | public void createButton() { 73 | // TODO Auto-generated method stub 74 | 75 | } 76 | 77 | @Override 78 | public void mouseWheelMoved(MouseWheelEvent e) { 79 | // TODO Auto-generated method stub 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/painttools/tools/SelectionToolListener.java: -------------------------------------------------------------------------------- 1 | package painttools.tools; 2 | 3 | public interface SelectionToolListener { 4 | 5 | public void selectionChanged() ; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/script/ComponentMap.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import java.util.HashMap; 4 | 5 | import paintcomponents.PaintComponent; 6 | 7 | public class ComponentMap { 8 | public static HashMap map = new HashMap(); 9 | } 10 | -------------------------------------------------------------------------------- /src/script/ExecutionErrorException.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | public class ExecutionErrorException extends Exception { 4 | 5 | public ExecutionErrorException(String message) { 6 | super(message); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/script/Interpreter.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | 5 | /** 6 | * Interpret and execute scripts 7 | * 8 | * @author Xiaoquan Jiang 9 | */ 10 | public class Interpreter { 11 | 12 | private static final String SELECT = "select"; 13 | private static final String ZOOM = "zoom"; 14 | private static final String REMOVE = "remove"; 15 | private static final String UPDATE = "update"; 16 | private static final String GENERATE_POLYGON = "generatePolygon"; 17 | private static final String FILE = "file"; 18 | private static final String EDIT = "edit"; 19 | private static final String CONSTRUCT = "construct"; 20 | private static final String ADD = "add"; 21 | private static final String NAME = "name"; 22 | protected PaintPanel panel; 23 | 24 | public Interpreter(PaintPanel panel) { 25 | this.panel = panel; 26 | } 27 | 28 | public void interpreteLine(String script) throws ExecutionErrorException { 29 | 30 | Tokenizer tokenizer = new Tokenizer(script); 31 | 32 | // interpret the first token and pass the tokenizer to a sub interpreter 33 | if (tokenizer.hasNext()) { 34 | switch (tokenizer.next()) { 35 | case ADD: 36 | new InterpreterAddActions(tokenizer, panel); 37 | break; 38 | 39 | case CONSTRUCT: 40 | new InterpreterConstructActions(tokenizer, panel); 41 | break; 42 | 43 | case EDIT: 44 | new InterpreterEditActions(tokenizer, panel); 45 | break; 46 | 47 | case FILE: 48 | new InterpreterFileActions(tokenizer, panel); 49 | break; 50 | 51 | case GENERATE_POLYGON: 52 | new InterpreterGeneratePolygonAction(tokenizer, panel); 53 | break; 54 | 55 | case UPDATE: 56 | new InterpreterUpdateActions(tokenizer, panel); 57 | break; 58 | 59 | case REMOVE: 60 | new InterpreterRemoveAction(tokenizer, panel); 61 | break; 62 | 63 | case SELECT: 64 | new InterpreterSelectAction(tokenizer, panel); 65 | break; 66 | 67 | case NAME: 68 | new InterpreterNameAction(tokenizer, panel); 69 | break; 70 | 71 | default: 72 | throw new ExecutionErrorException("invalid script"); 73 | } 74 | } else { 75 | throw new ExecutionErrorException("Script is empty"); 76 | } 77 | } 78 | } 79 | 80 | /* 81 | * Scripts: add data displayBox inputBox haskell component haskellCompoment lazy 82 | * javaClass javaConstructor javaFieldsComponent javaMethodComponent textBox 83 | * construct dataLineSegment lineSegment edit redo undo file saveAs == save open 84 | * generatePolygon update dataBox inputBox remove 85 | */ -------------------------------------------------------------------------------- /src/script/InterpreterAddActions.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | import actions.AddTextBoxAction; 5 | 6 | /** 7 | * Interpret and execute 'add' scripts 8 | * 9 | * @author Xiaoquan Jiang 10 | */ 11 | public class InterpreterAddActions { 12 | 13 | private static final String TEXT_BOX = "textBox"; 14 | private static final String LAZY = "lazy"; 15 | private static final String HASKELL = "haskell"; 16 | private static final String DATA = "data"; 17 | private PaintPanel panel; 18 | 19 | public InterpreterAddActions(Tokenizer tokenizer, PaintPanel panel) 20 | throws ExecutionErrorException { 21 | this.panel = panel; 22 | 23 | if (tokenizer.hasNext()) { 24 | switch (tokenizer.next()) { 25 | case DATA: 26 | new InterpreterAddData(tokenizer, panel); 27 | break; 28 | 29 | case HASKELL: 30 | new InterpreterAddHaskell(tokenizer, panel); 31 | break; 32 | 33 | case LAZY: 34 | new InterpreterAddLazy(tokenizer, panel); 35 | break; 36 | 37 | case TEXT_BOX: 38 | performAddTextBox(); 39 | break; 40 | 41 | default: 42 | throw new ExecutionErrorException("invalid script"); 43 | } 44 | } else { 45 | throw new ExecutionErrorException("incomplete script"); 46 | } 47 | } 48 | 49 | private void performAddTextBox() { 50 | AddTextBoxAction action = new AddTextBoxAction(panel); 51 | action.performAction(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/script/InterpreterAddData.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | import actions.AddDataDisplayBoxAction; 5 | import actions.AddDataInputBoxAction; 6 | 7 | /** 8 | * Interpret and execute 'add data' scripts 9 | * 10 | * @author Xiaoquan Jiang 11 | */ 12 | public class InterpreterAddData { 13 | private static final String INPUT_BOX = "inputBox"; 14 | private static final String DISPLAY_BOX = "displayBox"; 15 | private PaintPanel panel; 16 | 17 | public InterpreterAddData(Tokenizer tokenizer, PaintPanel panel) 18 | throws ExecutionErrorException { 19 | 20 | this.panel = panel; 21 | 22 | if (tokenizer.hasNext()) { 23 | switch (tokenizer.next()) { 24 | case DISPLAY_BOX: 25 | performAddDisplayBoxAction(); 26 | break; 27 | 28 | case INPUT_BOX: 29 | performAddInputBoxAction(); 30 | break; 31 | 32 | default: 33 | throw new ExecutionErrorException("invalid script"); 34 | } 35 | } else { 36 | throw new ExecutionErrorException("incomplete script"); 37 | } 38 | } 39 | 40 | private void performAddDisplayBoxAction() { 41 | AddDataDisplayBoxAction action = new AddDataDisplayBoxAction(panel); 42 | action.performAction(); 43 | } 44 | 45 | private void performAddInputBoxAction() { 46 | AddDataInputBoxAction action = new AddDataInputBoxAction(panel); 47 | action.performAction(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/script/InterpreterAddHaskell.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | import paintcomponents.haskell.EvaluateHaskellPaintComponent; 6 | import paintcomponents.haskell.HaskellExpressionPaintComponent; 7 | import ui.PaintPanel; 8 | 9 | /** 10 | * Interpret and execute 'add haskell' scripts 11 | * @author Xiaoquan Jiang 12 | */ 13 | public class InterpreterAddHaskell { 14 | 15 | private static final String EVALUATOR_COMPONENT = "evaluatorComponent"; 16 | private static final String COMPONENT = "component"; 17 | private PaintPanel panel; 18 | 19 | public InterpreterAddHaskell(Tokenizer tokenizer, PaintPanel panel) 20 | throws ExecutionErrorException { 21 | 22 | this.panel = panel; 23 | 24 | if (tokenizer.hasNext()) { 25 | switch (tokenizer.next()) { 26 | case COMPONENT: 27 | performAddComponentAction(); 28 | break; 29 | 30 | case EVALUATOR_COMPONENT: 31 | performAddEvaluatorComponentAction(); 32 | break; 33 | 34 | default: 35 | throw new ExecutionErrorException("invalid script"); 36 | } 37 | } else { 38 | throw new ExecutionErrorException("incomplete script"); 39 | } 40 | } 41 | 42 | private void performAddComponentAction() { 43 | String expr = JOptionPane 44 | .showInputDialog("Please enter the haskell expression"); 45 | panel.addPaintComponent(new HaskellExpressionPaintComponent(expr, panel 46 | .getWidth() / 2, panel.getHeight() / 2)); 47 | 48 | panel.repaint(); 49 | } 50 | 51 | private void performAddEvaluatorComponentAction() { 52 | EvaluateHaskellPaintComponent comp = new EvaluateHaskellPaintComponent( 53 | "Use Data Display/Update to compute expression result", 54 | panel.getWidth() / 2, panel.getHeight() / 2); 55 | panel.addPaintComponent(comp); 56 | panel.repaint(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/script/InterpreterAddLazy.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | import actions.AddLazyJavaConstructorAction; 5 | import actions.AddLazyJavaFieldsComponentAction; 6 | import actions.AddLazyJavaMethodComponentAction; 7 | 8 | /** 9 | * Interpret and execute 'add_lazy' scripts 10 | * 11 | * @author Xiaoquan Jiang 12 | */ 13 | public class InterpreterAddLazy { 14 | 15 | private static final String JAVA_METHOD_COMPONENT = "javaMethodComponent"; 16 | private static final String JAVA_FIELDS_COMPONENT = "javaFieldsComponent"; 17 | private static final String JAVA_CONSTRUCTOR = "javaConstructor"; 18 | private static final String JAVA_CLASS = "javaClass"; 19 | private PaintPanel panel; 20 | 21 | public InterpreterAddLazy(Tokenizer tokenizer, PaintPanel panel) 22 | throws ExecutionErrorException { 23 | String token; 24 | String nextToken; 25 | this.panel = panel; 26 | 27 | if (tokenizer.hasNext()) { 28 | token = tokenizer.next(); 29 | 30 | // check if the component to add is a java class 31 | if (token.equals(JAVA_CLASS)) { 32 | new InterpreterAddLazyJavaClass(tokenizer, panel); 33 | } else { 34 | if (tokenizer.hasNext()) { 35 | nextToken = tokenizer.next(); 36 | // select class 37 | if (nextToken.equals("-c")) { 38 | panel.getSelectTool().clearSelection(); 39 | new InterpreterSelectAction(tokenizer, panel); 40 | } 41 | } 42 | 43 | switch (token) { 44 | case JAVA_CONSTRUCTOR: 45 | performAddJavaConstructorAction(); 46 | break; 47 | 48 | case JAVA_FIELDS_COMPONENT: 49 | performAddJavaFieldsComponentAction(); 50 | break; 51 | 52 | case JAVA_METHOD_COMPONENT: 53 | performAddJavaMethodComponentAction(); 54 | break; 55 | 56 | default: 57 | throw new ExecutionErrorException("invalid script"); 58 | } 59 | } 60 | } else { 61 | throw new ExecutionErrorException("invalid script"); 62 | } 63 | } 64 | 65 | private void performAddJavaConstructorAction() { 66 | AddLazyJavaConstructorAction consAct = new AddLazyJavaConstructorAction( 67 | panel); 68 | consAct.performAction(); 69 | } 70 | 71 | private void performAddJavaFieldsComponentAction() { 72 | AddLazyJavaFieldsComponentAction filedAct = new AddLazyJavaFieldsComponentAction( 73 | panel); 74 | filedAct.performAction(); 75 | } 76 | 77 | private void performAddJavaMethodComponentAction() { 78 | AddLazyJavaMethodComponentAction metAct = new AddLazyJavaMethodComponentAction( 79 | panel); 80 | metAct.performAction(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/script/InterpreterAddLazyJavaClass.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | import actions.AddLazyJavaClassAction; 5 | 6 | public class InterpreterAddLazyJavaClass { 7 | 8 | private PaintPanel panel; 9 | 10 | public InterpreterAddLazyJavaClass(Tokenizer tokenizer, PaintPanel panel) 11 | throws ExecutionErrorException { 12 | this.panel = panel; 13 | performAddJavaClassAction(); 14 | } 15 | 16 | private void performAddJavaClassAction() { 17 | AddLazyJavaClassAction action = new AddLazyJavaClassAction(panel); 18 | action.performAction(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/script/InterpreterEditActions.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import actions.edit.undoredo.SharedUndoRedoActionManager; 4 | import ui.PaintPanel; 5 | 6 | /** 7 | * Interpret and execute 'edit' scripts 8 | * @author Xiaoquan Jiang 9 | */ 10 | public class InterpreterEditActions { 11 | 12 | private static final String UNDO = "undo"; 13 | private static final String REDO = "redo"; 14 | 15 | public InterpreterEditActions(Tokenizer tokenizer, PaintPanel panel) 16 | throws ExecutionErrorException { 17 | 18 | if (tokenizer.hasNext()) { 19 | switch (tokenizer.next()) { 20 | case REDO: 21 | performRedo(); 22 | break; 23 | 24 | case UNDO: 25 | performUndo(); 26 | break; 27 | 28 | default: 29 | throw new ExecutionErrorException("invalid script"); 30 | } 31 | } else { 32 | throw new ExecutionErrorException("incomplete script"); 33 | } 34 | } 35 | 36 | private void performRedo() { 37 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager.getSharedInstance(); 38 | manager.redo(); 39 | } 40 | 41 | private void performUndo() { 42 | SharedUndoRedoActionManager manager = SharedUndoRedoActionManager.getSharedInstance(); 43 | manager.undo(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/script/InterpreterFileActions.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | import javax.swing.JOptionPane; 7 | import javax.xml.parsers.ParserConfigurationException; 8 | import javax.xml.transform.TransformerException; 9 | 10 | import org.xml.sax.SAXException; 11 | 12 | import actions.AddLazyJavaClassAction; 13 | import actions.FileOpen; 14 | import actions.FileSaveAs; 15 | import file.PanelIO; 16 | import ui.PaintPanel; 17 | 18 | /** 19 | * Interpret and execute 'file' scripts 20 | * @author Xiaoquan Jiang 21 | */ 22 | public class InterpreterFileActions { 23 | 24 | private static final String SAVE = "save"; 25 | private static final String SAVE_AS = "saveAs"; 26 | private static final String OPEN = "open"; 27 | private PaintPanel panel; 28 | 29 | public InterpreterFileActions(Tokenizer tokenizer, PaintPanel panel) 30 | throws ExecutionErrorException { 31 | this.panel = panel; 32 | 33 | if (tokenizer.hasNext()) { 34 | switch (tokenizer.next()) { 35 | case OPEN: 36 | performOpen(panel); 37 | break; 38 | 39 | case SAVE_AS: 40 | performSaveAs(panel); 41 | break; 42 | 43 | case SAVE: 44 | performSaveAs(panel); 45 | break; 46 | 47 | default: 48 | throw new ExecutionErrorException("invalid script"); 49 | } 50 | } else { 51 | throw new ExecutionErrorException("incomplete script"); 52 | } 53 | } 54 | 55 | private void performOpen(PaintPanel panel2) { 56 | FileOpen action = new FileOpen(panel); 57 | action.performAction(); 58 | } 59 | 60 | private void performSaveAs(PaintPanel panel2) { 61 | FileSaveAs action = new FileSaveAs(panel); 62 | action.performAction(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/script/InterpreterNameAction.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | //import actions.singleinstanceoperations.AddAnnotationAction; 4 | import ui.PaintPanel; 5 | import actions.global.ActionName; 6 | import actions.global.GlobalPaintActionExecuter; 7 | import actions.global.globalactions.NameGlobalAction; 8 | 9 | public class InterpreterNameAction { 10 | 11 | public InterpreterNameAction(Tokenizer tokenizer, PaintPanel panel) 12 | throws ExecutionErrorException { 13 | String token = tokenizer.next(); 14 | 15 | NameGlobalAction assiciatedAction = (NameGlobalAction) ActionName.NAME 16 | .getAssociatedAction(); 17 | GlobalPaintActionExecuter.getSharedInstance().execute(assiciatedAction, 18 | panel); 19 | assiciatedAction.setName(token, panel); 20 | 21 | // AddAnnotationAction annoAct = new AddAnnotationAction(panel); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/script/InterpreterRemoveAction.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import java.util.ArrayList; 4 | 5 | import paintcomponents.PaintComponent; 6 | import ui.PaintPanel; 7 | import actions.RemovePaintComponent; 8 | 9 | /** 10 | * Interpret and execute 'remove' script 11 | * 12 | * @author Xiaoquan Jiang 13 | */ 14 | public class InterpreterRemoveAction { 15 | 16 | private PaintPanel panel; 17 | private ArrayList comps = new ArrayList<>(); 18 | 19 | public InterpreterRemoveAction(Tokenizer tokenizer, PaintPanel panel) 20 | throws ExecutionErrorException { 21 | 22 | // check if name of a component is specified 23 | if (tokenizer.hasNext()) { 24 | panel.getSelectTool().clearSelection(); 25 | new InterpreterSelectAction(tokenizer, panel); 26 | } 27 | 28 | for (PaintComponent comp : panel.getSelectTool() 29 | .getSelectedComponents()) { 30 | comps.add(comp); 31 | } 32 | 33 | this.panel = panel; 34 | performRemoveSelected(); 35 | } 36 | 37 | private void performRemoveSelected() { 38 | for (PaintComponent comp : comps) { 39 | if (ComponentMap.map.containsValue(comp)) { 40 | ComponentMap.map.values().remove(comp); 41 | } 42 | } 43 | 44 | RemovePaintComponent remAct = new RemovePaintComponent(panel); 45 | remAct.performAction(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/script/InterpreterSelectAction.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import ui.PaintPanel; 4 | 5 | public class InterpreterSelectAction { 6 | 7 | public InterpreterSelectAction(Tokenizer tokenizer, PaintPanel panel) 8 | throws ExecutionErrorException { 9 | String token = tokenizer.next(); 10 | if (ComponentMap.map.containsKey(token)) { 11 | ComponentMap.map.get(token).select(panel.getSelectTool()); 12 | } else { 13 | throw new ExecutionErrorException("component not found"); 14 | } 15 | panel.repaint(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/script/TokenizerTest.java: -------------------------------------------------------------------------------- 1 | package script; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | 7 | import org.junit.Test; 8 | 9 | public class TokenizerTest { 10 | 11 | @Test 12 | public void testBaseCase() { 13 | Tokenizer tokenizer = new Tokenizer("a b c d"); 14 | ArrayList tokens = tokenizer.getTokens(); 15 | for (int i = 0; i < tokens.size(); i++) { 16 | System.out.print(tokens.get(i)); 17 | } 18 | assertArrayEquals(new String[] { "a", "b", "c", "d" }, tokens.toArray()); 19 | } 20 | 21 | @Test 22 | public void testSlash() { 23 | Tokenizer tokenizer = new Tokenizer("a\\ b c d"); 24 | ArrayList tokens = tokenizer.getTokens(); 25 | assertArrayEquals(new String[] { "a b", "c", "d" }, tokens.toArray()); 26 | } 27 | 28 | @Test 29 | public void testQuote() { 30 | Tokenizer tokenizer = new Tokenizer("\"a b\" c d"); 31 | ArrayList tokens = tokenizer.getTokens(); 32 | assertArrayEquals(new String[] { "a b", "c", "d" }, tokens.toArray()); 33 | } 34 | 35 | @Test 36 | public void testSlashAndQuote() { 37 | // User input: --> "a\" b" c d 38 | Tokenizer tokenizer = new Tokenizer("\"a\\\" b\" c d"); 39 | ArrayList tokens = tokenizer.getTokens(); 40 | assertArrayEquals(new String[] { "a\" b", "c", "d" }, tokens.toArray()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/settings/Defaults.java: -------------------------------------------------------------------------------- 1 | package settings; 2 | 3 | import java.awt.Color; 4 | 5 | public class Defaults { 6 | 7 | private static final Color SELECT_TOOL_ICON_COLOR = Color.BLACK; 8 | 9 | 10 | public static Defaults defaults = new Defaults(); 11 | 12 | private static Color SIMPLE_POINT_COLOR = new Color(200, 41, 47); 13 | private static Color SIMPLE_POINT_SELECTED_COLOR = new Color(0, 0, 132); 14 | private static int SIMPLE_POINT_DEFAULT_SIZE = 10; 15 | private static final Color LINE_SEGMENT_COLOR = SIMPLE_POINT_COLOR; 16 | private static final Color LINE_SEGMENT_SELECTED_COLOR = SIMPLE_POINT_SELECTED_COLOR; 17 | private static final int LINE_SEGMENT_STROKE_WIDTH = 5; 18 | 19 | 20 | private static final Color DATA_TEXTFIELD_COLOR = LINE_SEGMENT_COLOR; 21 | private static final Color DATA_TEXTFIELD_SELECTED_COLOR = LINE_SEGMENT_SELECTED_COLOR; 22 | 23 | 24 | private static final Color TEXT_COMPONENT_COLOR = Color.BLACK; 25 | 26 | 27 | private static final Color TEXT_COMPONENT_SELECTED_COLOR = LINE_SEGMENT_SELECTED_COLOR; 28 | 29 | 30 | private static final float TEXT_COMPONENT_TEXT_SIZE = 16; 31 | 32 | private Defaults(){ 33 | 34 | } 35 | 36 | public static Defaults sharedDefaults(){ 37 | 38 | return defaults; 39 | } 40 | 41 | public int defaultSimplePointSize(){ 42 | return SIMPLE_POINT_DEFAULT_SIZE; 43 | } 44 | 45 | public Color defaultSimplePointColor(){ 46 | return SIMPLE_POINT_COLOR; 47 | } 48 | public Color defaultSimplePointSelectedColor(){ 49 | return SIMPLE_POINT_SELECTED_COLOR; 50 | } 51 | 52 | public Color defaultColorForSelectToolIcon() { 53 | return SELECT_TOOL_ICON_COLOR; 54 | } 55 | 56 | public Color defaultColorForLineSegment(){ 57 | return LINE_SEGMENT_COLOR; 58 | } 59 | public Color defaultColorForSelectedLineSegment(){ 60 | return LINE_SEGMENT_SELECTED_COLOR; 61 | } 62 | 63 | public int defaultStrokeWidthForLineSegment() { 64 | return LINE_SEGMENT_STROKE_WIDTH; 65 | } 66 | 67 | public Color defaultColorForDataTextComponent() { 68 | return DATA_TEXTFIELD_COLOR; 69 | } 70 | 71 | public Color defaultColorForSelectedDataTextComponent(){ 72 | return DATA_TEXTFIELD_SELECTED_COLOR; 73 | } 74 | public Color defaultColorForRectanglePaintComponent() { 75 | return DATA_TEXTFIELD_COLOR; 76 | } 77 | 78 | public Color defaultColorForSelectedRectanglePaintComponent(){ 79 | return DATA_TEXTFIELD_SELECTED_COLOR; 80 | } 81 | 82 | public Color defaultColorForTextPaintComponent() { 83 | return TEXT_COMPONENT_COLOR; 84 | } 85 | 86 | public Color defaultColorForSelectedTextPaintComponent() { 87 | return TEXT_COMPONENT_SELECTED_COLOR; 88 | } 89 | 90 | public float defaultFontSizeForPaintComponent() { 91 | return TEXT_COMPONENT_TEXT_SIZE; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/typesystem/HaskellType.java: -------------------------------------------------------------------------------- 1 | package typesystem; 2 | 3 | public class HaskellType extends Type { 4 | 5 | public HaskellType(String s) { 6 | // TODO Auto-generated constructor stub 7 | } 8 | 9 | @Override 10 | public boolean canBeAssignedFrom(Type type) { 11 | // TODO Auto-generated method stub 12 | return false; 13 | } 14 | 15 | @Override 16 | public Class getCurClass() { 17 | // TODO Auto-generated method stub 18 | return null; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/typesystem/JavaType.java: -------------------------------------------------------------------------------- 1 | package typesystem; 2 | 3 | /** 4 | * the java type 5 | */ 6 | public class JavaType extends Type { 7 | 8 | private Class curClass; 9 | 10 | /** 11 | * check if the current type can be assigned from another type 12 | * 13 | * @param the type to be checked 14 | * @return true if it can, otherwise false 15 | */ 16 | @Override 17 | public boolean canBeAssignedFrom(Type type) { 18 | // TODO 19 | // ASSUMING JAVA TYPE 20 | JavaType jtype = (JavaType) type; 21 | // TODO Auto-generated method stub 22 | boolean res = false; 23 | try { 24 | res = curClass.isAssignableFrom(((JavaType) type).getCurClass()); 25 | 26 | // do the primitive & complex type check 27 | if (res == false) { 28 | if (this.getCurClass().isPrimitive()) { 29 | res = isPrimitiveAssignableFromClass(curClass, jtype.curClass); 30 | } else if (jtype.curClass.isPrimitive()) { 31 | res = isPrimitiveAssignableFromClass(jtype.curClass, curClass); 32 | } 33 | } 34 | } catch (ClassCastException e) { 35 | res = false; 36 | } 37 | return res; 38 | } 39 | 40 | public JavaType(Class cls) { 41 | curClass = cls; 42 | } 43 | 44 | public Class getCurClass() { 45 | return curClass; 46 | } 47 | 48 | /** 49 | * check if the primitive type can be assigned by the complex type 50 | * 51 | * @param primitive the primitive type 52 | * @param complex the complex type 53 | * @return true if it can, otherwise false 54 | */ 55 | private boolean isPrimitiveAssignableFromClass(Class primitive, 56 | Class complex) { 57 | if (primitive == int.class) { 58 | return complex == Integer.class; 59 | } 60 | if (primitive == double.class) { 61 | return complex == Double.class; 62 | } 63 | if (primitive == float.class) { 64 | return complex == Float.class; 65 | } 66 | if (primitive == char.class) { 67 | return complex == Character.class; 68 | } 69 | if (primitive == boolean.class) { 70 | return complex == Boolean.class; 71 | } 72 | if (primitive == byte.class) { 73 | return complex == Byte.class; 74 | } 75 | if (primitive == short.class) { 76 | return complex == Short.class; 77 | } 78 | if (primitive == long.class) { 79 | return complex == Long.class; 80 | } 81 | return false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/typesystem/Type.java: -------------------------------------------------------------------------------- 1 | package typesystem; 2 | 3 | public abstract class Type { 4 | 5 | public abstract boolean canBeAssignedFrom(Type type); 6 | public abstract Class getCurClass(); 7 | } 8 | -------------------------------------------------------------------------------- /src/ui/JavaSketchPad.java: -------------------------------------------------------------------------------- 1 | package ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | import java.awt.Dimension; 6 | import java.awt.Font; 7 | import java.awt.Toolkit; 8 | import java.util.ArrayList; 9 | 10 | import javax.swing.BorderFactory; 11 | import javax.swing.JFrame; 12 | import javax.swing.JPanel; 13 | 14 | import actions.menu.ActionsMenuBar; 15 | import painttools.toolbar.ToolBar; 16 | import ui.helper.historyui.undoredoLog.UndoredoDialog; 17 | 18 | public class JavaSketchPad extends JFrame { 19 | Color backgroundColor = new Color(240, 240, 240); 20 | Color toolBarColor = new Color(210,210,210); 21 | 22 | ArrayList panelList; 23 | 24 | public JavaSketchPad() { 25 | panelList = new ArrayList(); 26 | 27 | // meke the frame full screen 28 | setSize(Toolkit.getDefaultToolkit().getScreenSize()); 29 | //set menu bar to Mac menuBar 30 | System.setProperty("apple.laf.useScreenMenuBar", "true"); 31 | 32 | 33 | // set up paintPanel 34 | PaintPanel paintPanel = new PaintPanel(); 35 | paintPanel.setBorder(null); 36 | paintPanel.setBackground(backgroundColor); 37 | panelList.add(paintPanel); 38 | getContentPane().add(paintPanel, BorderLayout.CENTER); 39 | 40 | // set up toolBar panel 41 | ToolBar toolBar = new ToolBar(paintPanel); 42 | toolBar.setBackground(toolBarColor); 43 | panelList.add(toolBar); 44 | getContentPane().add(toolBar, BorderLayout.NORTH); 45 | 46 | // set up undoredoDialog panel 47 | UndoredoDialog undoredoDialog = UndoredoDialog.sharedInstance(); 48 | undoredoDialog.setPreferredSize(new Dimension(300, MAXIMIZED_VERT)); 49 | panelList.add(undoredoDialog); 50 | getContentPane().add(undoredoDialog, BorderLayout.WEST); 51 | 52 | // link select tool 53 | paintPanel.setSelectTool(toolBar.getSelectTool()); 54 | 55 | // menubar 56 | ActionsMenuBar menuBar = new ActionsMenuBar(paintPanel); 57 | menuBar.setOpaque(true); 58 | menuBar.setFont(new Font("Apple LiSung", Font.PLAIN, 14)); 59 | menuBar.setBorderPainted(false); 60 | menuBar.setForeground(Color.BLACK); 61 | menuBar.setBackground(Color.GRAY); 62 | setJMenuBar(menuBar); 63 | 64 | // tool bar 65 | toolBar.getSelectTool().addSelectionToolListener(menuBar); 66 | toolBar.addToolBarListener(paintPanel); 67 | toolBar.setBorder(BorderFactory.createLineBorder(Color.black)); 68 | 69 | // change backgrounds setting 70 | changeTheme(); 71 | 72 | setDefaultCloseOperation(EXIT_ON_CLOSE); 73 | paintPanel.toolSelected(paintPanel.getSelectTool()); 74 | } 75 | 76 | public static void main(String[] args) { 77 | new JavaSketchPad().setVisible(true); 78 | } 79 | 80 | /* change the background setting for JPanels */ 81 | public void changeTheme() { 82 | setForeground(backgroundColor); 83 | setBackground(backgroundColor); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/ui/ShortcutHandler.java: -------------------------------------------------------------------------------- 1 | package ui; 2 | 3 | import java.awt.event.KeyAdapter; 4 | import java.awt.event.KeyEvent; 5 | 6 | import actions.AddDataDisplayBoxAction; 7 | import actions.AddDataInputBoxAction; 8 | import actions.AddLazyJavaClassAction; 9 | import actions.FileSaveAs; 10 | import actions.RemovePaintComponent; 11 | 12 | /** 13 | * Shortcuts for some actions 14 | * 15 | * Ctrl + s: save 16 | * Ctrl + r: remove 17 | * Ctrl + i: add input box 18 | * Ctrl + o: add output display box 19 | * Ctrl + c: add a class 20 | * @author Xiangyi Gong 21 | */ 22 | public class ShortcutHandler extends KeyAdapter { 23 | 24 | private PaintPanel panel; 25 | 26 | public ShortcutHandler(PaintPanel panel) { 27 | this.panel = panel; 28 | } 29 | 30 | @Override 31 | public void keyPressed(KeyEvent e) { 32 | // CTRL is not being pressed, return 33 | if ((e.getModifiers() & KeyEvent.CTRL_MASK) == 0) { 34 | return; 35 | } 36 | 37 | switch (e.getKeyCode()) { 38 | case KeyEvent.VK_S: 39 | save(); 40 | break; 41 | case KeyEvent.VK_C: 42 | addClass(); 43 | break; 44 | case KeyEvent.VK_R: 45 | remove(); 46 | break; 47 | case KeyEvent.VK_I: 48 | addInput(); 49 | break; 50 | case KeyEvent.VK_O: 51 | addOutput(); 52 | break; 53 | } 54 | 55 | } 56 | 57 | 58 | private void save() { 59 | FileSaveAs action = new FileSaveAs(panel); 60 | if (action.canPerformAction()) { 61 | action.performAction(); 62 | } 63 | } 64 | 65 | private void remove() { 66 | RemovePaintComponent action = new RemovePaintComponent(panel); 67 | if (action.canPerformAction()) { 68 | action.performAction(); 69 | } 70 | } 71 | 72 | private void addInput() { 73 | AddDataInputBoxAction action = new AddDataInputBoxAction(panel); 74 | if (action.canPerformAction()) { 75 | action.performAction(); 76 | } 77 | } 78 | 79 | private void addOutput() { 80 | AddDataDisplayBoxAction action = new AddDataDisplayBoxAction(panel); 81 | if (action.canPerformAction()) { 82 | action.performAction(); 83 | } 84 | } 85 | 86 | private void addClass() { 87 | AddLazyJavaClassAction action = new AddLazyJavaClassAction(panel); 88 | if (action.canPerformAction()) { 89 | action.performAction(); 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/ui/cursor/CustomCursors.java: -------------------------------------------------------------------------------- 1 | package ui.cursor; 2 | 3 | import java.awt.Cursor; 4 | import java.awt.Image; 5 | import java.awt.Point; 6 | import java.awt.Toolkit; 7 | 8 | public class CustomCursors { 9 | static Toolkit toolkit = Toolkit.getDefaultToolkit(); 10 | 11 | 12 | public static Cursor addComponentcursor(){ 13 | Image image = toolkit.getImage("./images/addCursor.png"); 14 | Cursor c = toolkit.createCustomCursor(image, new Point(0,0), "cursor"); 15 | return c; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/ui/general/InputManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package ui.general; 2 | 3 | public interface InputManagerDelegate { 4 | 5 | void didFinishInput(T input); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/ui/helper/classsearch/ClassSearchFrameDelegateInterface.java: -------------------------------------------------------------------------------- 1 | package ui.helper.classsearch; 2 | 3 | public interface ClassSearchFrameDelegateInterface { 4 | 5 | public void didSelectClass(String classname); 6 | } 7 | -------------------------------------------------------------------------------- /src/ui/helper/classsearch/ClassSearchFrameTest.java: -------------------------------------------------------------------------------- 1 | package ui.helper.classsearch; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.awt.Dimension; 6 | 7 | import javax.swing.SwingUtilities; 8 | 9 | import org.junit.Test; 10 | 11 | public class ClassSearchFrameTest { 12 | 13 | @Test 14 | public void test() throws InterruptedException { 15 | Runnable t = (new Runnable() { 16 | 17 | @Override 18 | public void run() { 19 | ClassSearchFrame classSearchFrame = new ClassSearchFrame(); 20 | classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() { 21 | 22 | @Override 23 | public void didSelectClass(String classname) { 24 | System.out.println(classname); 25 | } 26 | }); 27 | 28 | 29 | classSearchFrame.setVisible(true); 30 | classSearchFrame.setSize(new Dimension(300, 200)); 31 | 32 | /* Comment below to test the framework */ 33 | /* Added for the purpose of continuous integration */ 34 | new Thread(new Runnable() { 35 | 36 | @Override 37 | public void run() { 38 | try { 39 | Thread.sleep(5000); 40 | classSearchFrame.setVisible(false); 41 | classSearchFrame.dispose(); 42 | } catch (InterruptedException e) { 43 | e.printStackTrace(); 44 | } 45 | 46 | } 47 | }).start(); 48 | 49 | } 50 | }); 51 | SwingUtilities.invokeLater(t); 52 | Thread.sleep(10000); 53 | 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/ui/helper/historyui/TableUIDataObject.java: -------------------------------------------------------------------------------- 1 | package ui.helper.historyui; 2 | 3 | import java.security.UnrecoverableEntryException; 4 | 5 | /** 6 | * 7 | * HistoryDataOjbect 8 | * 9 | */ 10 | public class TableUIDataObject { 11 | 12 | String data; 13 | int row; 14 | boolean untraced; 15 | public TableUIDataObject(){ 16 | 17 | } 18 | 19 | public TableUIDataObject(String data){ 20 | this.data = data; 21 | untraced = false; 22 | } 23 | 24 | 25 | public String toString(){ 26 | if(untraced){ 27 | return "[untraced] " + data; 28 | } 29 | return data; 30 | } 31 | 32 | public void setRow(int i){ 33 | row = i; 34 | } 35 | 36 | public int getRow(){ 37 | return row; 38 | } 39 | 40 | public void setUntraced(boolean truth){ 41 | untraced = truth; 42 | } 43 | 44 | public boolean getUntraced(){ 45 | return untraced; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/ui/helper/historyui/TableUITemplateInterface.java: -------------------------------------------------------------------------------- 1 | package ui.helper.historyui; 2 | 3 | public interface TableUITemplateInterface { 4 | 5 | /** 6 | * Called when a button is pressed. 7 | * @param buttonName The name of the button 8 | * @param selectedRow the index of selected row. -1 if no row selected 9 | */ 10 | 11 | public void didPressButton(String buttonName, int selectedRow); 12 | 13 | 14 | /** 15 | * implement addButtons method to add buttons to the button_panel 16 | */ 17 | public abstract void addButtons(); 18 | 19 | /** 20 | * implement updateButtonStatus to update button when button actions performanced 21 | */ 22 | public abstract void updateButtonStatus(); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/ui/helper/historyui/TableUITest.java: -------------------------------------------------------------------------------- 1 | package ui.helper.historyui; 2 | 3 | 4 | 5 | import java.awt.Dimension; 6 | 7 | import javax.swing.SwingUtilities; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | public class TableUITest { 13 | 14 | TableUITemplate historyUI; 15 | 16 | 17 | @Before 18 | public void setUp(){ 19 | String[] arr = {"delete","exit","clear","revert","confirm"}; 20 | historyUI = new TableUITemplate(arr); 21 | historyUI.insert(new TableUIDataObject("AAAA")); 22 | historyUI.insert(new TableUIDataObject("BBB")); 23 | historyUI.insert(new TableUIDataObject("Test 1")); 24 | historyUI.insert(new TableUIDataObject("This is a item")); 25 | historyUI.insert(new TableUIDataObject("turn right")); 26 | historyUI.insert(new TableUIDataObject("112345")); 27 | 28 | } 29 | 30 | @Test 31 | public void test() throws InterruptedException { 32 | SwingUtilities.invokeLater(new Runnable() { 33 | 34 | @Override 35 | public void run() { 36 | //ClassSearchFrame classSearchFrame = new ClassSearchFrame(); 37 | 38 | historyUI.setDelegate(new TableUITemplateInterface() { 39 | 40 | @Override 41 | public void didPressButton(String buttonName, int selectedRow) { 42 | System.out.println("buttonname = " + buttonName + "; selectedRow = " + selectedRow); 43 | 44 | } 45 | 46 | @Override 47 | public void addButtons() { 48 | // TODO Auto-generated method stub 49 | 50 | } 51 | 52 | @Override 53 | public void updateButtonStatus() { 54 | // TODO Auto-generated method stub 55 | 56 | } 57 | }); 58 | 59 | 60 | historyUI.setVisible(true); 61 | historyUI.setSize(new Dimension(500, 400)); 62 | 63 | 64 | /* Comment below to test the framework */ 65 | /* Added for the purpose of continuous integration */ 66 | new Thread(new Runnable() { 67 | 68 | @Override 69 | public void run() { 70 | 71 | try { 72 | Thread.sleep(50); 73 | 74 | } catch (InterruptedException e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | }).start(); 79 | 80 | 81 | 82 | } 83 | }); 84 | Thread.sleep(50); 85 | } 86 | 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/ui/helper/methodinput/MethodSearch.java: -------------------------------------------------------------------------------- 1 | package ui.helper.methodinput; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.ArrayList; 5 | 6 | public class MethodSearch { 7 | 8 | private ArrayList allMethods; 9 | 10 | /** 11 | * Constructs a MethodSearch Instance 12 | * The method 13 | */ 14 | public MethodSearch(Class mtdClass) { 15 | //load classes 16 | allMethods = new ArrayList<>(); 17 | 18 | Method[] methods = mtdClass.getMethods(); 19 | 20 | for (Method mtd : methods) { 21 | allMethods.add(mtd.toString()); 22 | } 23 | 24 | } 25 | 26 | public ArrayList methodsForName(String name) { 27 | 28 | ArrayList result = new ArrayList<>(); 29 | for (String string : allMethods) { 30 | if(string.toUpperCase().contains(name.toUpperCase())){ 31 | result.add(string); 32 | } 33 | } 34 | 35 | return sortAccordingToPrecedence(result, name); 36 | } 37 | 38 | private ArrayList sortAccordingToPrecedence(ArrayList result, 39 | String name) { 40 | ArrayList ret = new ArrayList<>(); 41 | 42 | 43 | for (String string : result) { 44 | String[] comps = string.split("\\."); 45 | if(comps.length == 0) continue; 46 | 47 | if(comps[comps.length - 1].startsWith(name)){ 48 | ret.add(0, string); 49 | } else { 50 | ret.add(string); 51 | } 52 | } 53 | 54 | return ret; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/ui/helper/methodinput/MethodSearchFrameDelegateInterface.java: -------------------------------------------------------------------------------- 1 | package ui.helper.methodinput; 2 | 3 | public interface MethodSearchFrameDelegateInterface { 4 | public void didSelectMethod(String methodName); 5 | } 6 | -------------------------------------------------------------------------------- /src/ui/icons/CustomIcons.java: -------------------------------------------------------------------------------- 1 | package ui.icons; 2 | 3 | import javax.swing.ImageIcon; 4 | 5 | public class CustomIcons { 6 | 7 | 8 | public static ImageIcon arrow(){ 9 | return new ImageIcon("./images/arrow.png"); 10 | } 11 | 12 | public static ImageIcon selectedArrow(){ 13 | return new ImageIcon("./images/arrowselected.png"); 14 | } 15 | 16 | public static ImageIcon line(){ 17 | return new ImageIcon("./images/line.png"); 18 | 19 | } 20 | 21 | public static ImageIcon selectedLine(){ 22 | return new ImageIcon("./images/lineselected.png"); 23 | } 24 | 25 | public static ImageIcon dot(){ 26 | return new ImageIcon("./images/dot.png"); 27 | } 28 | 29 | public static ImageIcon selectedDot(){ 30 | return new ImageIcon("./images/dotselected.png"); 31 | } 32 | 33 | public static ImageIcon undo(){ 34 | return new ImageIcon("./images/undo.png"); 35 | } 36 | 37 | public static ImageIcon redo(){ 38 | return new ImageIcon("./images/redo.png"); 39 | } 40 | 41 | public static ImageIcon classIcon(){ 42 | return new ImageIcon("./images/c.png"); 43 | } 44 | 45 | public static ImageIcon selectedClassIcon(){ 46 | return new ImageIcon("./images/cselected.png"); 47 | } 48 | 49 | public static ImageIcon inputBox(){ 50 | return new ImageIcon("./images/inputbox.png"); 51 | } 52 | 53 | public static ImageIcon selectedInputBox(){ 54 | return new ImageIcon("./images/inputboxselected.png"); 55 | } 56 | 57 | public static ImageIcon outputBox(){ 58 | return new ImageIcon("./images/outputbox.png"); 59 | } 60 | 61 | public static ImageIcon selectedOutputBox(){ 62 | return new ImageIcon("./images/outputboxselected.png"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/ui/icons/LineToolIcon.java: -------------------------------------------------------------------------------- 1 | package ui.icons; 2 | 3 | import java.awt.Polygon; 4 | public class LineToolIcon{ 5 | 6 | 7 | public static Polygon getPolygon(){ 8 | 9 | Polygon p = new Polygon(); 10 | 11 | p.addPoint(17, 5); 12 | p.addPoint(8, 0); 13 | p.addPoint(0, 8); 14 | p.addPoint(2, 19); 15 | p.addPoint(9, 20); 16 | p.addPoint(17, 21); 17 | p.addPoint(31, 33); 18 | p.addPoint(52, 47); 19 | p.addPoint(73, 60); 20 | p.addPoint(75, 73); 21 | p.addPoint(82, 80); 22 | p.addPoint(91, 80); 23 | p.addPoint(96, 68); 24 | p.addPoint(100, 55); 25 | p.addPoint(92, 52); 26 | p.addPoint(75, 47); 27 | p.addPoint(62, 41); 28 | p.addPoint(38, 30); 29 | p.addPoint(22, 13); 30 | 31 | 32 | return p; 33 | } 34 | 35 | } --------------------------------------------------------------------------------