Skip to content

Commit 193791b

Browse files
committed
Merge branch 'develop' into addCDEFbykaic
2 parents bbdcca5 + a082739 commit 193791b

31 files changed

Lines changed: 407 additions & 79 deletions

TODOList.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
1. File Save/Close Operations
22
2. Edit Undo/Redo Operations
3+
<<<<<<< HEAD
34
3. More usable SelectTools x
45
4. Remove Functinoality x
56
5. Zooming and Scrolling and Moving Function x
7+
=======
8+
//3. More usable SelectTools
9+
//4. Remove Functinoality
10+
//5. Zooming and Scrolling and Moving Function
11+
>>>>>>> develop
612
6. Data Point Connection Types
713
7. Available Class Search
814
8. Auto-Update Display Box Affected by Recent Changes
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package actions;
2+
3+
import java.util.ArrayList;
4+
5+
import javax.swing.JOptionPane;
6+
7+
import actions.menu.ActionsMenuBarTitles;
8+
import paintcomponents.PaintComponent;
9+
import paintcomponents.annotations.TextAnnotation;
10+
import paintcomponents.data.DataTextPaintComponent;
11+
import ui.PaintPanel;
12+
13+
public class AddAnnotationAction extends PaintAction{
14+
15+
public AddAnnotationAction(PaintPanel panel) {
16+
super(panel);
17+
}
18+
19+
@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;
31+
}
32+
33+
@Override
34+
public void performAction() {
35+
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
36+
String annotations = JOptionPane
37+
.showInputDialog("Please specify the annotation of the component");
38+
new TextAnnotation(items.get(0), annotations);
39+
40+
panel.repaint();
41+
}
42+
43+
@Override
44+
public String locationString() {
45+
return ActionsMenuBarTitles.Data().Annotations().Add().toString();
46+
}
47+
48+
49+
}

src/actions/AddLazyJavaClassAction.java

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package actions;
22

3+
import java.awt.Dimension;
4+
35
import javax.swing.JOptionPane;
46

57
import actions.edit.undoredo.SharedUndoRedoActionManager;
68
import actions.edit.undoredo.UndoRedoableInterface;
79
import actions.menu.ActionsMenuBarTitles;
8-
import actions.menu.PaintActionMenuItem;
910
import paintcomponents.java.lazy.ClassPaintComponent;
1011
import ui.PaintPanel;
12+
import ui.helper.classsearch.ClassSearchFrame;
13+
import ui.helper.classsearch.ClassSearchFrameDelegateInterface;
1114

1215
public class AddLazyJavaClassAction extends PaintAction {
1316

@@ -19,37 +22,51 @@ public AddLazyJavaClassAction(PaintPanel panel) {
1922
public boolean canPerformAction() {
2023
return true;
2124
}
22-
25+
2326
@Override
2427
public void performAction() {
25-
String className = JOptionPane
26-
.showInputDialog("Please specify the name of the Java Class");
27-
try {
28-
Class classObj = Class.forName(className);
29-
ClassPaintComponent comp = new ClassPaintComponent(classObj,
30-
panel.getWidth() / 2, panel.getHeight() / 2);
31-
panel.addPaintComponent(comp);
32-
// add action to undo redo manager
33-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
28+
29+
ClassSearchFrame classSearchFrame = new ClassSearchFrame();
30+
classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() {
31+
32+
@Override
33+
public void didSelectClass(String classname) {
3434

35-
@Override
36-
public void undoAction() {
37-
comp.remove(panel);
38-
panel.repaint();
39-
}
40-
41-
@Override
42-
public void redoAction() {
35+
try {
36+
Class classObj = Class.forName(classname);
37+
ClassPaintComponent comp = new ClassPaintComponent(classObj,
38+
panel.getWidth() / 2, panel.getHeight() / 2);
4339
panel.addPaintComponent(comp);
40+
// add action to undo redo manager
41+
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
42+
43+
@Override
44+
public void undoAction() {
45+
comp.remove(panel);
46+
panel.repaint();
47+
}
48+
49+
@Override
50+
public void redoAction() {
51+
panel.addPaintComponent(comp);
52+
panel.repaint();
53+
}
54+
});
4455
panel.repaint();
56+
} catch (ClassNotFoundException e) {
57+
e.printStackTrace();
58+
JOptionPane.showMessageDialog(panel,
59+
classname + " :: Class Not Found");
4560
}
46-
});
47-
panel.repaint();
48-
} catch (ClassNotFoundException e) {
49-
e.printStackTrace();
50-
JOptionPane.showMessageDialog(panel,
51-
className + " :: Class Not Found");
52-
}
61+
}
62+
});
63+
64+
65+
classSearchFrame.setVisible(true);
66+
classSearchFrame.setSize(new Dimension(300, 200));
67+
68+
69+
5370

5471
}
5572

src/actions/ConstructDataLineSegmentAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void performAction() {
4949
.getSelectedComponents();
5050
DataFromPoint fromPoint = (DataFromPoint) comps.get(0);
5151
DataToPoint toPoint = (DataToPoint) comps.get(1);
52-
if (!fromPoint.getExpectedType().equals(toPoint.getExpectedType())) {
52+
//if (!fromPoint.getExpectedType().equals(toPoint.getExpectedType())) {
53+
if(!toPoint.getExpectedType().canBeAssignedFrom(fromPoint.getExpectedType())){
5354
int result = JOptionPane.showConfirmDialog(panel,
5455
"The source type is " + fromPoint.getExpectedType()
5556
+ ", the destination type is "

src/actions/FileOpen.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import file.PanelIO;
1212
import ui.PaintPanel;
1313

14+
import javax.swing.JFileChooser;
15+
import java.io.File;
16+
1417
public class FileOpen extends PaintAction {
1518

1619
public FileOpen(PaintPanel panel) {
@@ -24,7 +27,18 @@ public boolean canPerformAction() {
2427

2528
@Override
2629
public void performAction() {
27-
String filePath = JOptionPane.showInputDialog("Please input file path");
30+
JFileChooser fileChooser = new JFileChooser();
31+
fileChooser.setDialogTitle("Select the file to open");
32+
int userSelection = fileChooser.showOpenDialog(panel);
33+
34+
String filePath;
35+
if (userSelection == JFileChooser.APPROVE_OPTION) {
36+
File fileToSave = fileChooser.getSelectedFile();
37+
filePath = fileToSave.getAbsolutePath();
38+
} else {
39+
return;
40+
}
41+
2842
PanelIO io = new PanelIO();
2943
try {
3044
io.constructPanelFromDocument(panel, filePath, true);

src/actions/FileSaveAs.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import file.PanelIO;
1616
import ui.PaintPanel;
1717

18+
import javax.swing.JFileChooser;
19+
import java.io.File;
20+
1821
public class FileSaveAs extends PaintAction {
1922

2023
public FileSaveAs(PaintPanel panel) {
@@ -25,10 +28,25 @@ public FileSaveAs(PaintPanel panel) {
2528
public boolean canPerformAction() {
2629
return true;
2730
}
28-
31+
32+
/**
33+
* Use a JFileChooser to save the file
34+
* @author xy gong
35+
*/
2936
@Override
3037
public void performAction() {
31-
String filePath = JOptionPane.showInputDialog("Please input file path");
38+
JFileChooser fileChooser = new JFileChooser();
39+
fileChooser.setDialogTitle("Specify a file to save");
40+
int userSelection = fileChooser.showSaveDialog(panel);
41+
42+
String filePath;
43+
if (userSelection == JFileChooser.APPROVE_OPTION) {
44+
File fileToSave = fileChooser.getSelectedFile();
45+
filePath = fileToSave.getAbsolutePath();
46+
} else {
47+
return;
48+
}
49+
3250
PanelIO io = new PanelIO();
3351
try {
3452
io.constructDocumentFromPanel(panel, filePath);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package actions;
2+
3+
import java.util.ArrayList;
4+
5+
import actions.menu.ActionsMenuBarTitles;
6+
import paintcomponents.PaintComponent;
7+
import ui.PaintPanel;
8+
9+
public class RemoveAnnotationAction extends PaintAction{
10+
11+
public RemoveAnnotationAction(PaintPanel panel) {
12+
super(panel);
13+
}
14+
15+
@Override
16+
public boolean canPerformAction() {
17+
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
18+
19+
if(items.size() != 1){
20+
return false;
21+
}
22+
if(items.get(0).getOptionalAnnotation() == null){
23+
return false;
24+
}
25+
return true;
26+
}
27+
28+
@Override
29+
public void performAction() {
30+
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
31+
items.get(0).setOptionalAnnotation(null);
32+
panel.repaint();
33+
}
34+
35+
@Override
36+
public String locationString() {
37+
return ActionsMenuBarTitles.Data().Annotations().Remove().toString();
38+
}
39+
40+
}

src/actions/menu/ActionsMenuBar.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import painttools.tools.SelectionToolListener;
1111
import ui.PaintPanel;
12+
import actions.AddAnnotationAction;
1213
import actions.AddDataDisplayBoxAction;
1314
import actions.AddDataInputBoxAction;
1415
import actions.AddHaskellComponent;
@@ -27,6 +28,7 @@
2728
import actions.GeneratePolygonSourceJava;
2829
import actions.InputDataForDataInputBoxAction;
2930
import actions.PaintAction;
31+
import actions.RemoveAnnotationAction;
3032
import actions.RemovePaintComponent;
3133
import actions.UpdateDataDisplayBoxAction;
3234
import actions.singleinstanceoperations.SetPointSizeOperation;
@@ -79,6 +81,9 @@ public ActionsMenuBar(PaintPanel panel){
7981
addAction(new UpdateFontSizeOperation(panel));
8082
addAction(new SetPointSizeOperation(panel));
8183

84+
// add data annotation
85+
addAction(new AddAnnotationAction(panel));
86+
addAction(new RemoveAnnotationAction(panel));
8287
}
8388

8489
private void addAction(PaintAction action) {

src/actions/menu/ActionsMenuBarTitles.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,9 @@ public ActionsMenuBarTitles Zoom_Out() {
138138
return this;
139139
}
140140

141+
public ActionsMenuBarTitles Annotations() {
142+
append("Annotations");
143+
return this;
144+
}
145+
141146
}

src/paintcomponents/PaintComponent.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.w3c.dom.Node;
88
import org.w3c.dom.NodeList;
99

10+
import paintcomponents.annotations.PaintComponentAnnotation;
1011
import painttools.tools.SelectTool;
1112
import ui.PaintPanel;
1213

@@ -38,6 +39,7 @@ public abstract class PaintComponent {
3839
static private long UNIQUE_ID = 0;
3940
long uid = ++UNIQUE_ID;
4041

42+
private PaintComponentAnnotation optionalAnnotation;
4143
/**
4244
* Get a Unique ID of this component. IDs resets to zero when JVM starts;
4345
*
@@ -95,6 +97,10 @@ public void paint(Graphics g) {
9597
paintNotSelected(g);
9698
}
9799

100+
//paint annotation
101+
if(optionalAnnotation != null){
102+
optionalAnnotation.paint(g);
103+
}
98104
}
99105

100106
/**
@@ -166,7 +172,11 @@ public boolean isSelected() {
166172
public void translate(int i, int j) {
167173
this.x += i;
168174
this.y += j;
169-
175+
176+
//if attached component is not null, translate it as well
177+
if(optionalAnnotation != null){
178+
optionalAnnotation.translate(i, j);
179+
}
170180
}
171181

172182
public abstract boolean contains(int x2, int y2);
@@ -220,4 +230,18 @@ public PaintComponent(Element rootElement, PaintPanel panel) {
220230
this.x = Integer.parseInt(pos.getElementsByTagName("xcoordinate").item(0).getTextContent());
221231
this.y = Integer.parseInt(pos.getElementsByTagName("ycoordinate").item(0).getTextContent());
222232
}
233+
234+
/**
235+
* @return the optionalAnnotation
236+
*/
237+
public PaintComponentAnnotation getOptionalAnnotation() {
238+
return optionalAnnotation;
239+
}
240+
241+
/**
242+
* @param optionalAnnotation the optionalAnnotation to set
243+
*/
244+
public void setOptionalAnnotation(PaintComponentAnnotation optionalAnnotation) {
245+
this.optionalAnnotation = optionalAnnotation;
246+
}
223247
}

0 commit comments

Comments
 (0)