11package paintcomponents ;
22
3+ import java .awt .BasicStroke ;
34import java .awt .Color ;
45import java .awt .Graphics ;
6+ import java .awt .Graphics2D ;
57
68import settings .Defaults ;
79
810public class DataInputTextfieldPaintComponent extends TextPaintComponent {
911
12+ private static final int HORIZONTAL_OFFSET = 10 ;
1013 DataFromPoint <String > fromPoint ;
1114 Color boundColor ;
1215 Color selectedColor ;
@@ -24,21 +27,35 @@ public DataInputTextfieldPaintComponent(String displayingText, int x,
2427
2528 @ Override
2629 protected void paintNotSelected (Graphics g ) {
27- super .paintNotSelected (g );
2830 g .setColor (boundColor );
31+ ((Graphics2D )g ).setStroke (new BasicStroke (1 ));
32+ super .paintNotSelected (g );
33+ updateFromPointPosition ();
2934 g .drawRect (getX (), getY (), (int )this .bounds .getWidth (), (int )this .bounds .getHeight ());
3035 fromPoint .paintNotSelected (g );
3136
3237 }
38+
3339
3440 @ Override
3541 protected void paintSelected (Graphics g ) {
36- super . paintSelected ( g ); ;
42+ (( Graphics2D ) g ). setStroke ( new BasicStroke ( 1 )) ;
3743 g .setColor (selectedColor );
44+ super .paintSelected (g );;
45+ updateFromPointPosition ();
3846 g .drawRect (getX (), getY (), (int )this .bounds .getWidth (), (int )this .bounds .getHeight ());
3947 fromPoint .paintSelected (g );
4048 }
4149
50+ /**
51+ * This method will use the protected bounds, which will be updated in super.paint[Not]Selected.
52+ * Make sure you've already invoked super's paintNotSelectedMethod before invoking this one.
53+ */
54+ private void updateFromPointPosition (){
55+ this .fromPoint .setX ((int ) (getX () + this .bounds .getWidth () + HORIZONTAL_OFFSET ));
56+ this .fromPoint .setY ((int ) (getY () + this .bounds .getHeight () / 2 ));
57+ }
58+
4259 @ Override
4360 public void translate (int i , int j ) {
4461 super .translate (i , j );
@@ -50,4 +67,9 @@ public boolean contains(int x, int y) {
5067
5168 return fromPoint .contains (x , y ) || super .contains (x , y );
5269 }
70+
71+ public void inputData (String s ) {
72+ fromPoint .offer (s );
73+ this .setDisplayingText (s );
74+ }
5375}
0 commit comments