Skip to content

Commit b6260d1

Browse files
committed
add and remove annotations
1 parent c647504 commit b6260d1

5 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/actions/AddAnnotationAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import actions.menu.ActionsMenuBarTitles;
88
import paintcomponents.PaintComponent;
9-
import paintcomponents.TextPaintComponent;
109
import paintcomponents.annotations.TextAnnotation;
1110
import paintcomponents.data.DataTextPaintComponent;
1211
import ui.PaintPanel;
@@ -36,9 +35,8 @@ public void performAction() {
3635
ArrayList<PaintComponent> items = panel.getSelectTool().getSelectedComponents();
3736
String annotations = JOptionPane
3837
.showInputDialog("Please specify the annotation of the component");
39-
TextAnnotation textAnnotation = new TextAnnotation(items.get(0), annotations);
40-
items.get(0).setOptionalAnnotation(textAnnotation);
41-
panel.addPaintComponent(textAnnotation);
38+
new TextAnnotation(items.get(0), annotations);
39+
4240
panel.repaint();
4341
}
4442

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import actions.GeneratePolygonSourceJava;
2929
import actions.InputDataForDataInputBoxAction;
3030
import actions.PaintAction;
31+
import actions.RemoveAnnotationAction;
3132
import actions.RemovePaintComponent;
3233
import actions.UpdateDataDisplayBoxAction;
3334
import actions.singleinstanceoperations.SetPointSizeOperation;
@@ -82,6 +83,7 @@ public ActionsMenuBar(PaintPanel panel){
8283

8384
// add data annotation
8485
addAction(new AddAnnotationAction(panel));
86+
addAction(new RemoveAnnotationAction(panel));
8587
}
8688

8789
private void addAction(PaintAction action) {

src/paintcomponents/PaintComponent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public void paint(Graphics g) {
9797
paintNotSelected(g);
9898
}
9999

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

102106
/**

src/paintcomponents/annotations/TextAnnotation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ public TextAnnotation(PaintComponent attachedComponent, String displayingText) {
1414
super(attachedComponent);
1515
this.textPaintComponent = new TextPaintComponent(displayingText, attachedComponent.getX(),
1616
attachedComponent.getY());
17+
1718
}
1819

1920
@Override
2021
protected void paintNotSelected(Graphics g) {
2122
// TODO Auto-generated method stub
22-
textPaintComponent.updateBoundsAndDrawString(g);
23+
textPaintComponent.updateBounds(g);
2324
textPaintComponent.setY(getAttachedComponent().getY() - textPaintComponent.getRowHeight());
2425
textPaintComponent.paint(g);
2526
}
2627

2728
@Override
2829
protected void paintSelected(Graphics g) {
2930
// TODO Auto-generated method stub
30-
textPaintComponent.updateBoundsAndDrawString(g);
31+
textPaintComponent.updateBounds(g);
3132
textPaintComponent.setY(getAttachedComponent().getY() - textPaintComponent.getRowHeight());
3233
textPaintComponent.paint(g);
3334
}

0 commit comments

Comments
 (0)