Skip to content

Commit c647504

Browse files
committed
Seperate updateBounds and drawString of TextPaintComponents
1 parent 26fc1e9 commit c647504

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/paintcomponents/TextPaintComponent.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ protected void paintNotSelected(Graphics g) {
102102
//draw string starts from bottom left corner, shift to top left
103103
updateBoundsAndDrawString(g);
104104
}
105-
public void updateBoundsAndDrawString(Graphics g) {
105+
private void updateBoundsAndDrawString(Graphics g) {
106+
updateBounds(g);
107+
drawString(g);
108+
109+
}
110+
111+
/**
112+
* Update bounds updates the width and row height of this text paint component
113+
* @param g Graphics Object
114+
*/
115+
public void updateBounds(Graphics g) {
106116
//reset bounds to begin calculation
107117
width = 0;
108118
//derive row Height
@@ -120,6 +130,20 @@ public void updateBoundsAndDrawString(Graphics g) {
120130
if( curStringWidth > width){
121131
width = curStringWidth;
122132
}
133+
}
134+
}
135+
136+
/**
137+
* Draws the string, do not update bounds
138+
* @param g
139+
*/
140+
private void drawString(Graphics g){
141+
142+
//get number of rows
143+
String[] rows = this.displayingText.split("\n");
144+
145+
for (int i = 0; i < rows.length; i++) {
146+
String string = rows[i];
123147

124148
g.drawString(string, getX(), (int) (getY() + rowHeight * (i + 1)));
125149
}

0 commit comments

Comments
 (0)