Skip to content

Commit fda39ab

Browse files
committed
Merge branch 'develop' into addCDEFbykaic
2 parents 59d4bb8 + b98205a commit fda39ab

46 files changed

Lines changed: 2752 additions & 143 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

build.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<project name="JavaSketchPad" default="run" basedir=".">
2+
<property name="build.dir" location="ant_build" />
3+
<property name="src.dir" location="src" />
4+
5+
<target name="init" description="Creating directory">
6+
<mkdir dir="${build.dir}" />
7+
</target>
8+
9+
<target name="compile" depends="init" description="Compiling Sources">
10+
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false">
11+
<classpath refid="classpath.test" />
12+
</javac>
13+
</target>
14+
15+
<target name="run" depends="compile" description="Running the program">
16+
</target>
17+
18+
<target name="clean">
19+
<delete dir="${build.dir}" />
20+
</target>
21+
22+
23+
<path id="classpath.test">
24+
<pathelement location="lib/junit-4.12.jar" />
25+
<pathelement location="lib/hamcrest-core-1.3.jar" />
26+
<pathelement location="${build.dir}" />
27+
</path>
28+
29+
30+
<target name="test" depends="compile">
31+
<junit printsummary="on" haltonfailure="yes" fork="true">
32+
<classpath>
33+
<path refid="classpath.test" />
34+
<pathelement location="${test.build.dir}" />
35+
</classpath>
36+
<formatter type="brief" usefile="false" />
37+
<batchtest>
38+
<fileset dir="${src.dir}" includes="**/*Test.java" />
39+
</batchtest>
40+
</junit>
41+
</target>
42+
</project>

lib/hamcrest-core-1.3.jar

44 KB
Binary file not shown.

lib/junit-4.12.jar

308 KB
Binary file not shown.

src/actions/AddAnnotationAction.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,48 @@
55
import javax.swing.JOptionPane;
66

77
import actions.menu.ActionsMenuBarTitles;
8+
import actions.singleinstanceoperations.SingleInstanceOperation;
89
import paintcomponents.PaintComponent;
910
import paintcomponents.annotations.TextAnnotation;
1011
import paintcomponents.data.DataTextPaintComponent;
1112
import ui.PaintPanel;
1213

13-
public class AddAnnotationAction extends PaintAction{
14-
14+
/**
15+
* add the annotation to a component
16+
*
17+
* @author muchi
18+
*
19+
*/
20+
public class AddAnnotationAction extends SingleInstanceOperation<PaintComponent>{
21+
22+
/**
23+
* ctor
24+
* @param panel the panel
25+
*/
1526
public AddAnnotationAction(PaintPanel panel) {
1627
super(panel);
1728
}
1829

30+
/**
31+
* @return the location of the button
32+
*/
1933
@Override
20-
public boolean canPerformAction() {
21-
//get selected components
22-
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
23-
24-
if(items.size() != 1){
25-
return false;
26-
}
27-
if(!(items.get(0) instanceof DataTextPaintComponent)){
28-
return false;
29-
}
30-
return true;
34+
public String locationString() {
35+
return ActionsMenuBarTitles.Data().Annotations().Add().toString();
3136
}
3237

3338
@Override
34-
public void performAction() {
35-
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
39+
protected void performActionOnInstance(PaintComponent instance) {
40+
// TODO Auto-generated method stub
3641
String annotations = JOptionPane
3742
.showInputDialog("Please specify the annotation of the component");
38-
new TextAnnotation(items.get(0), annotations);
43+
new TextAnnotation(instance, annotations);
3944

40-
panel.repaint();
4145
}
4246

4347
@Override
44-
public String locationString() {
45-
return ActionsMenuBarTitles.Data().Annotations().Add().toString();
48+
protected Class<PaintComponent> getGenericClassType() {
49+
return PaintComponent.class;
4650
}
4751

4852

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package actions;
2+
3+
import ui.PaintPanel;
4+
5+
import java.lang.reflect.Method;
6+
7+
import javax.swing.JOptionPane;
8+
9+
import actions.menu.ActionsMenuBarTitles;
10+
import paintcomponents.java.lazy.ClassPaintComponent;
11+
import paintcomponents.java.lazy.InstanceOperationComponent;
12+
import paintcomponents.java.lazy.MethodPaintComponent;
13+
14+
public class AddInstanceMethodAction extends PaintAction {
15+
16+
public AddInstanceMethodAction(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()
26+
.get(0) instanceof InstanceOperationComponent) {
27+
return true;
28+
}
29+
return false;
30+
}
31+
32+
@Override
33+
public void performAction() {
34+
InstanceOperationComponent insComp =
35+
(InstanceOperationComponent)panel.getSelectTool().
36+
getSelectedComponents().get(0);
37+
Method[] methods = insComp.getDisplayingClass().getMethods();
38+
39+
int desiaredConstructorIndex = Integer
40+
.parseInt(JOptionPane.showInputDialog(
41+
"Please enter the index of the constructor you would like to use: \n\n\n"
42+
+ getMethodsSelectionUI(methods)));
43+
insComp.addMethodPaintComponent(methods[desiaredConstructorIndex], panel);
44+
panel.repaint();
45+
}
46+
47+
@Override
48+
public String locationString() {
49+
// TODO Auto-generated method stub
50+
return ActionsMenuBarTitles.Lazy().Add().Add_Instance_Method().toString();
51+
}
52+
53+
public String getMethodsSelectionUI(Method[] methods) {
54+
StringBuilder builder = new StringBuilder();
55+
for (int i = 0; i < methods.length; i++) {
56+
Method constructor = methods[i];
57+
builder.append(i + " : " + constructor.toString() + "\n");
58+
}
59+
return builder.toString();
60+
61+
}
62+
63+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package actions;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.Method;
5+
6+
import actions.edit.undoredo.SharedUndoRedoActionManager;
7+
import actions.edit.undoredo.UndoRedoableInterface;
8+
import actions.menu.ActionsMenuBarTitles;
9+
import paintcomponents.java.lazy.InstanceOperationComponent;
10+
import paintcomponents.java.lazy.ClassPaintComponent;
11+
import ui.PaintPanel;
12+
13+
import javax.swing.JOptionPane;
14+
15+
16+
public class AddInstanceOperationAction extends PaintAction {
17+
18+
19+
public AddInstanceOperationAction(PaintPanel panel) {
20+
super(panel);
21+
}
22+
23+
@Override
24+
public boolean canPerformAction() {
25+
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
26+
return false;
27+
}
28+
if (panel.getSelectTool().getSelectedComponents()
29+
.get(0) instanceof ClassPaintComponent) {
30+
return true;
31+
}
32+
return false;
33+
}
34+
35+
@Override
36+
public void performAction() {
37+
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
38+
.getSelectedComponents().get(0);
39+
Constructor[] cons = comp.getDisplayingClass().getConstructors();
40+
41+
int desiaredConstructorIndex = Integer
42+
.parseInt(JOptionPane.showInputDialog(
43+
"Please enter the index of the constructor you would like to use: \n\n\n"
44+
+ getConstructorsSelectionUI(cons)));
45+
InstanceOperationComponent consComp = new InstanceOperationComponent(
46+
cons[desiaredConstructorIndex], panel.getWidth() / 2,
47+
panel.getHeight() / 2);
48+
panel.addPaintComponent(consComp);
49+
// // add action to undo redo manager
50+
// SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
51+
//
52+
// @Override
53+
// public void undoAction() {
54+
// consComp.remove(panel);
55+
// panel.repaint();
56+
// }
57+
//
58+
// @Override
59+
// public void redoAction() {
60+
// panel.addPaintComponent(consComp);
61+
// panel.repaint();
62+
// }
63+
// });
64+
panel.repaint();
65+
}
66+
67+
public String getConstructorsSelectionUI(Constructor[] cons) {
68+
StringBuilder builder = new StringBuilder();
69+
for (int i = 0; i < cons.length; i++) {
70+
Constructor constructor = cons[i];
71+
builder.append(i + " : " + constructor.toString() + "\n");
72+
}
73+
return builder.toString();
74+
75+
}
76+
77+
@Override
78+
public String locationString() {
79+
return ActionsMenuBarTitles.Lazy().Add().Instance_Operation().toString();
80+
}
81+
82+
83+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package actions;
2+
3+
import java.lang.reflect.Constructor;
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.java.interactive.ClassConstructorPaintComponent;
11+
import paintcomponents.java.lazy.ClassPaintComponent;
12+
import ui.PaintPanel;
13+
14+
public class AddInteractiveConstructorAction extends PaintAction {
15+
16+
public AddInteractiveConstructorAction(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()
26+
.get(0) instanceof ClassPaintComponent) {
27+
return true;
28+
}
29+
return false;
30+
}
31+
32+
@Override
33+
public void performAction() {
34+
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
35+
.getSelectedComponents().get(0);
36+
Constructor[] cons = comp.getDisplayingClass().getConstructors();
37+
38+
int desiaredConstructorIndex = Integer
39+
.parseInt(JOptionPane.showInputDialog(
40+
"Please enter the index of the constructor you would like to use: \n\n\n"
41+
+ getConstructorsSelectionUI(cons)));
42+
ClassConstructorPaintComponent consComp = new ClassConstructorPaintComponent(
43+
cons[desiaredConstructorIndex], panel.getWidth() / 2,
44+
panel.getHeight() / 2);
45+
panel.addPaintComponent(consComp);
46+
// add action to undo redo manager
47+
// SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
48+
//
49+
// @Override
50+
// public void undoAction() {
51+
// consComp.remove(panel);
52+
// panel.repaint();
53+
// }
54+
//
55+
// @Override
56+
// public void redoAction() {
57+
// panel.addPaintComponent(consComp);
58+
// panel.repaint();
59+
// }
60+
// });
61+
panel.repaint();
62+
}
63+
64+
public String getConstructorsSelectionUI(Constructor[] cons) {
65+
StringBuilder builder = new StringBuilder();
66+
for (int i = 0; i < cons.length; i++) {
67+
Constructor constructor = cons[i];
68+
builder.append(i + " : " + constructor.toString() + "\n");
69+
}
70+
return builder.toString();
71+
72+
}
73+
74+
@Override
75+
public String locationString() {
76+
return ActionsMenuBarTitles.Developer("Interactive/Constructor").toString();
77+
}
78+
79+
}

0 commit comments

Comments
 (0)