Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/KeyHole/src/org/litesoft/aokeyhole/toolkit/BoxedText.java

Diff revisions: vs.
  @@ -6,8 +6,7 @@
6 6 import java.awt.*;
7 7 import java.awt.geom.*;
8 8
9 - public class BoxedText
10 - {
9 + public class BoxedText {
11 10 public static final BoxedText[] EMPTY_ARRAY = new BoxedText[0];
12 11
13 12 private static int sNextID = 0;
  @@ -33,68 +32,56 @@
33 32 private int mBoxAtX;
34 33 private int mBoxAtY;
35 34
36 - public BoxedText( int pType, Color pBackGround, String pName )
37 - {
35 + public BoxedText( int pType, Color pBackGround, String pName ) {
38 36 mID = getNextID();
39 37 mType = pType;
40 38 mBackGround = pBackGround;
41 39 setName( pName );
42 40 }
43 41
44 - private static synchronized int getNextID()
45 - {
42 + private static synchronized int getNextID() {
46 43 return sNextID++;
47 44 }
48 45
49 - public int getID()
50 - {
46 + public int getID() {
51 47 return mID;
52 48 }
53 49
54 - public int getType()
55 - {
50 + public int getType() {
56 51 return mType;
57 52 }
58 53
59 - public String getName()
60 - {
54 + public String getName() {
61 55 return mName;
62 56 }
63 57
64 - public void setName( String pName )
65 - {
58 + public void setName( String pName ) {
66 59 pName = (pName == null) ? "" : pName.trim();
67 - if ( !mName.equals( pName ) )
68 - {
60 + if ( !mName.equals( pName ) ) {
69 61 mUnfinished = true;
70 62 mName = pName;
71 - if ( mControllingSet != null )
72 - {
63 + if ( mControllingSet != null ) {
73 64 mControllingSet.setChanged();
74 65 }
75 66 }
76 67 }
77 68
78 - public void setControllingSet( BoxedSet pControllingSet )
79 - {
69 + public void setControllingSet( BoxedSet pControllingSet ) {
80 70 mControllingSet = pControllingSet;
81 71 }
82 72
83 - public void dispose()
84 - {
73 + public void dispose() {
85 74 mControllingSet = null;
86 75 }
87 76
88 - public void finish( Graphics pGraphics )
89 - {
90 - if ( mUnfinished )
91 - {
77 + public void finish( Graphics pGraphics ) {
78 + if ( mUnfinished ) {
92 79 mUnfinished = false;
93 80
94 81 FontMetrics metrics = pGraphics.getFontMetrics();
95 82 Font zFont = metrics.getFont();
96 83 mFont = AdjustFont.common( zFont );
97 - if (mFont != zFont) {
84 + if ( mFont != zFont ) {
98 85 metrics = pGraphics.getFontMetrics( mFont );
99 86 }
100 87 mFontDecent = metrics.getDescent();
  @@ -104,55 +91,42 @@
104 91 }
105 92 }
106 93
107 - public int getBoxWidth()
108 - {
94 + public int getBoxWidth() {
109 95 return mBoxWidth;
110 96 }
111 97
112 - public void setBoxWidth( int pBoxWidth )
113 - {
98 + public void setBoxWidth( int pBoxWidth ) {
114 99 mBoxWidth = pBoxWidth;
115 100 }
116 101
117 - public int getBoxHeight()
118 - {
102 + public int getBoxHeight() {
119 103 return mBoxHeight;
120 104 }
121 105
122 - public int getAtX()
123 - {
106 + public int getAtX() {
124 107 return mAtX;
125 108 }
126 109
127 - public int getAtY()
128 - {
110 + public int getAtY() {
129 111 return mAtY;
130 112 }
131 113
132 - public void setAtXY( int pAtX, int pAtY )
133 - {
114 + public void setAtXY( int pAtX, int pAtY ) {
134 115 mAtX = pAtX;
135 116 mAtY = pAtY;
136 117 }
137 118
138 - public void drawConnection( Graphics pGraphics, BoxedText pToBoxedText )
139 - {
140 - if ( pToBoxedText == null )
141 - {
119 + public void drawConnection( Graphics pGraphics, BoxedText pToBoxedText ) {
120 + if ( pToBoxedText == null ) {
142 121 drawConnectionToSelf( pGraphics );
143 - }
144 - else if ( this.getAtX() < pToBoxedText.getAtX() )
145 - {
122 + } else if ( this.getAtX() < pToBoxedText.getAtX() ) {
146 123 drawConnectionLeftToRight( pGraphics, pToBoxedText );
147 - }
148 - else
149 - {
124 + } else {
150 125 pToBoxedText.drawConnectionLeftToRight( pGraphics, this );
151 126 }
152 127 }
153 128
154 - private void drawConnectionToSelf( Graphics pGraphics )
155 - {
129 + private void drawConnectionToSelf( Graphics pGraphics ) {
156 130 int fromX = this.getAtX() + (this.mBoxWidth / 2);
157 131 int fromY = this.getAtY();
158 132 int toX = fromX + 10;
  @@ -172,24 +146,20 @@
172 146 pGraphics.drawLine( fromX, fromY, toX, toY );
173 147 }
174 148
175 - private void drawConnectionLeftToRight( Graphics pGraphics, BoxedText pToBoxedText )
176 - {
149 + private void drawConnectionLeftToRight( Graphics pGraphics, BoxedText pToBoxedText ) {
177 150 pGraphics.drawLine( this.getAtX() + (this.mBoxWidth / 2), this.getAtY(), pToBoxedText.getAtX() - (pToBoxedText.mBoxWidth / 2), pToBoxedText.getAtY() );
178 151 }
179 152
180 - public void drawConnectionCenterToCenter( Graphics pGraphics, BoxedText pToBoxedText )
181 - {
153 + public void drawConnectionCenterToCenter( Graphics pGraphics, BoxedText pToBoxedText ) {
182 154 pGraphics.drawLine( this.getAtX(), this.getAtY(), pToBoxedText.getAtX(), pToBoxedText.getAtY() );
183 155 }
184 156
185 - public void draw( Graphics pGraphics )
186 - {
157 + public void draw( Graphics pGraphics ) {
187 158 drawBox( pGraphics );
188 159 drawText( pGraphics );
189 160 }
190 161
191 - public void drawBox( Graphics pGraphics )
192 - {
162 + public void drawBox( Graphics pGraphics ) {
193 163 mBoxAtX = (mAtX - (mBoxWidth + 1) / 2);
194 164 mBoxAtY = (mAtY - (mBoxHeight + 1) / 2);
195 165
  @@ -202,33 +172,27 @@
202 172 pGraphics.drawRect( mBoxAtX, mBoxAtY, mBoxWidth, mBoxHeight );
203 173 }
204 174
205 - public void drawText( Graphics pGraphics )
206 - {
175 + public void drawText( Graphics pGraphics ) {
207 176 int atX = (mAtX - (mTextWidth + 1) / 2) + 1;
208 177 int atY = (mAtY - (mTextHeight + 1) / 2) + mTextHeight - (mFontDecent + 1);
209 178
210 179 Font curFont = AdjustFont.common( pGraphics.getFont() );
211 - if ( mFont.equals( curFont ) )
212 - {
180 + if ( mFont.equals( curFont ) ) {
213 181 pGraphics.drawString( mName, atX, atY );
214 - }
215 - else
216 - {
182 + } else {
217 183 pGraphics.setFont( mFont );
218 184 pGraphics.drawString( mName, atX, atY );
219 185 pGraphics.setFont( curFont );
220 186 }
221 187 }
222 188
223 - public boolean isClickedOn( Point pAt )
224 - {
189 + public boolean isClickedOn( Point pAt ) {
225 190 return
226 191 isBetween( mBoxAtX, pAt.x, mBoxAtX + mBoxWidth ) &&
227 192 isBetween( mBoxAtY, pAt.y, mBoxAtY + mBoxHeight );
228 193 }
229 194
230 - private boolean isBetween( int pLow, int pToCheck, int pHi )
231 - {
195 + private boolean isBetween( int pLow, int pToCheck, int pHi ) {
232 196 return (pLow < pToCheck) && (pToCheck < pHi);
233 197 }
234 198 }