Skip to content

Commit e5082ea

Browse files
committed
Add <Add Input Box Action>, Add Defaults settings for Data Input Textfield
1 parent 655f8c6 commit e5082ea

5 files changed

Lines changed: 102 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package actions;
2+
3+
import paintcomponents.DataInputTextfieldPaintComponent;
4+
import ui.PaintPanel;
5+
6+
public class AddDataInputBoxAction extends PaintAction {
7+
8+
public AddDataInputBoxAction(PaintPanel panel) {
9+
super(panel);
10+
}
11+
12+
@Override
13+
public boolean canPerformAction() {
14+
return true;
15+
}
16+
17+
@Override
18+
public void performAction() {
19+
DataInputTextfieldPaintComponent comp = new DataInputTextfieldPaintComponent("Data Input", panel.getWidth() /2, panel.getHeight()/2);
20+
panel.addPaintComponent(comp);
21+
panel.repaint();
22+
23+
}
24+
25+
@Override
26+
public String locationString() {
27+
return "Add/Data Input Box...";
28+
}
29+
30+
}

src/actions/menu/ActionsMenuBar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.swing.JMenuBar;
88
import javax.swing.JMenuItem;
99

10+
import actions.AddDataInputBoxAction;
1011
import actions.AddTextBoxAction;
1112
import actions.ConstructLineSegmentAction;
1213
import actions.GeneratePolygonSourceJava;
@@ -20,6 +21,7 @@ public ActionsMenuBar(PaintPanel panel){
2021
addAction(new GeneratePolygonSourceJava(panel));
2122
addAction(new ConstructLineSegmentAction(panel));
2223
addAction(new AddTextBoxAction(panel));
24+
addAction(new AddDataInputBoxAction(panel));
2325

2426
}
2527

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package paintcomponents;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics;
5+
6+
import settings.Defaults;
7+
8+
public class DataInputTextfieldPaintComponent extends TextPaintComponent {
9+
10+
DataFromPoint<String> fromPoint;
11+
Color boundColor;
12+
Color selectedColor;
13+
14+
15+
public DataInputTextfieldPaintComponent(String displayingText, int x,
16+
int y) {
17+
super(displayingText, x, y);
18+
fromPoint = new DataFromPoint<>(x - 50, y);
19+
boundColor = Defaults.sharedDefaults().defaultColorForDataInputTextfield();
20+
selectedColor = Defaults.sharedDefaults().defaultColorForSelectedDataInputTextfield();
21+
}
22+
23+
24+
25+
@Override
26+
protected void paintNotSelected(Graphics g) {
27+
super.paintNotSelected(g);
28+
g.setColor(boundColor);
29+
g.drawRect(getX(), getY(), (int)this.bounds.getWidth(), (int)this.bounds.getHeight());
30+
fromPoint.paintNotSelected(g);
31+
32+
}
33+
34+
@Override
35+
protected void paintSelected(Graphics g) {
36+
super.paintSelected(g);;
37+
g.setColor(selectedColor);
38+
g.drawRect(getX(), getY(), (int)this.bounds.getWidth(), (int)this.bounds.getHeight());
39+
fromPoint.paintSelected(g);
40+
}
41+
42+
@Override
43+
public void translate(int i, int j) {
44+
super.translate(i, j);
45+
this.fromPoint.translate(i, j);
46+
}
47+
48+
@Override
49+
public boolean contains(int x, int y) {
50+
51+
return fromPoint.contains(x, y) || super.contains(x, y);
52+
}
53+
}

src/paintcomponents/TextPaintComponent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
public class TextPaintComponent extends PaintComponent{
1010

1111
public String displayingText;
12-
private Rectangle2D bounds;
12+
/**
13+
* The bounds of the text area, this property is updated when paint method is invoked.
14+
* This class uses Graphics2D's font matrices to determine the bounds
15+
*/
16+
protected Rectangle2D bounds;
1317

1418
/**
1519
* @return the displayingText

src/settings/Defaults.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class Defaults {
1515
private static final Color LINE_SEGMENT_COLOR = SIMPLE_POINT_COLOR;
1616
private static final Color LINE_SEGMENT_SELECTED_COLOR = SIMPLE_POINT_SELECTED_COLOR;
1717
private static final int LINE_SEGMENT_STROKE_WIDTH = 5;
18+
19+
20+
private static final Color DATA_INPUT_TEXTFIELD_COLOR = LINE_SEGMENT_COLOR;
21+
private static final Color DATA_INPUT_TEXTFIELD_SELECTED_COLOR = LINE_SEGMENT_SELECTED_COLOR;
1822

1923
private Defaults(){
2024

@@ -50,4 +54,12 @@ public Color defaultColorForSelectedLineSegment(){
5054
public int defaultStrokeWidthForLineSegment() {
5155
return LINE_SEGMENT_STROKE_WIDTH;
5256
}
57+
58+
public Color defaultColorForDataInputTextfield() {
59+
return DATA_INPUT_TEXTFIELD_COLOR;
60+
}
61+
62+
public Color defaultColorForSelectedDataInputTextfield(){
63+
return DATA_INPUT_TEXTFIELD_SELECTED_COLOR;
64+
}
5365
}

0 commit comments

Comments
 (0)