Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/KeyHole/src/org/litesoft/aokeyhole/toolkit/BoxedSet.java

Diff revisions: vs.
  @@ -1,84 +1,84 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.aokeyhole.toolkit;
3 -
4 - import java.awt.*;
5 -
6 - public abstract class BoxedSet {
7 - protected BoxedText[] mBoxes = BoxedText.EMPTY_ARRAY;
8 -
9 - private View mView = ViewNull.INSTANCE;
10 -
11 - public int size() {
12 - return mBoxes.length;
13 - }
14 -
15 - public void draw( Graphics pGraphics ) {
16 - for ( BoxedText box : mBoxes ) {
17 - box.draw( pGraphics );
18 - }
19 - }
20 -
21 - public boolean remove( int pID ) {
22 - for ( int i = 0; i < mBoxes.length; i++ ) {
23 - if ( mBoxes[i].getID() == pID ) {
24 - mBoxes[i].dispose();
25 - innerRemove( i );
26 - setChanged();
27 - return true;
28 - }
29 - }
30 - return false;
31 - }
32 -
33 - public BoxedText add( BoxedText pNew ) {
34 - if ( pNew != null ) {
35 - innerAdd( pNew );
36 - setChanged();
37 - }
38 - return pNew;
39 - }
40 -
41 - public void setView( View pView ) {
42 - mView = (pView != null) ? pView : ViewNull.INSTANCE;
43 - }
44 -
45 - public void setChanged() {
46 - mView.update();
47 - }
48 -
49 - public BoxedText[] getBoxes() {
50 - return mBoxes;
51 - }
52 -
53 - public BoxedText getLastBox() {
54 - return (mBoxes.length == 0) ? null : mBoxes[mBoxes.length - 1];
55 - }
56 -
57 - public void dispose() {
58 - for ( BoxedText box : mBoxes ) {
59 - box.dispose();
60 - }
61 - mBoxes = BoxedText.EMPTY_ARRAY;
62 - mView = ViewNull.INSTANCE;
63 - }
64 -
65 - protected void innerAdd( BoxedText pNew ) {
66 - BoxedText[] extended = new BoxedText[mBoxes.length + 1];
67 - System.arraycopy( mBoxes, 0, extended, 0, mBoxes.length );
68 - extended[mBoxes.length] = pNew;
69 - mBoxes = extended;
70 - }
71 -
72 - private void innerRemove( int pIndex ) {
73 - BoxedText[] shrunk = new BoxedText[mBoxes.length - 1];
74 - if ( pIndex != 0 ) // Not First
75 - {
76 - System.arraycopy( mBoxes, 0, shrunk, 0, pIndex );
77 - }
78 - if ( pIndex != mBoxes.length - 1 ) // Not Last
79 - {
80 - System.arraycopy( mBoxes, pIndex + 1, shrunk, pIndex, shrunk.length - pIndex );
81 - }
82 - mBoxes = shrunk;
83 - }
84 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.aokeyhole.toolkit;
3 +
4 + import java.awt.*;
5 +
6 + public abstract class BoxedSet {
7 + protected BoxedText[] mBoxes = BoxedText.EMPTY_ARRAY;
8 +
9 + private View mView = ViewNull.INSTANCE;
10 +
11 + public int size() {
12 + return mBoxes.length;
13 + }
14 +
15 + public void draw( Graphics pGraphics ) {
16 + for ( BoxedText box : mBoxes ) {
17 + box.draw( pGraphics );
18 + }
19 + }
20 +
21 + public boolean remove( int pID ) {
22 + for ( int i = 0; i < mBoxes.length; i++ ) {
23 + if ( mBoxes[i].getID() == pID ) {
24 + mBoxes[i].dispose();
25 + innerRemove( i );
26 + setChanged();
27 + return true;
28 + }
29 + }
30 + return false;
31 + }
32 +
33 + public BoxedText add( BoxedText pNew ) {
34 + if ( pNew != null ) {
35 + innerAdd( pNew );
36 + setChanged();
37 + }
38 + return pNew;
39 + }
40 +
41 + public void setView( View pView ) {
42 + mView = (pView != null) ? pView : ViewNull.INSTANCE;
43 + }
44 +
45 + public void setChanged() {
46 + mView.update();
47 + }
48 +
49 + public BoxedText[] getBoxes() {
50 + return mBoxes;
51 + }
52 +
53 + public BoxedText getLastBox() {
54 + return (mBoxes.length == 0) ? null : mBoxes[mBoxes.length - 1];
55 + }
56 +
57 + public void dispose() {
58 + for ( BoxedText box : mBoxes ) {
59 + box.dispose();
60 + }
61 + mBoxes = BoxedText.EMPTY_ARRAY;
62 + mView = ViewNull.INSTANCE;
63 + }
64 +
65 + protected void innerAdd( BoxedText pNew ) {
66 + BoxedText[] extended = new BoxedText[mBoxes.length + 1];
67 + System.arraycopy( mBoxes, 0, extended, 0, mBoxes.length );
68 + extended[mBoxes.length] = pNew;
69 + mBoxes = extended;
70 + }
71 +
72 + private void innerRemove( int pIndex ) {
73 + BoxedText[] shrunk = new BoxedText[mBoxes.length - 1];
74 + if ( pIndex != 0 ) // Not First
75 + {
76 + System.arraycopy( mBoxes, 0, shrunk, 0, pIndex );
77 + }
78 + if ( pIndex != mBoxes.length - 1 ) // Not Last
79 + {
80 + System.arraycopy( mBoxes, pIndex + 1, shrunk, pIndex, shrunk.length - pIndex );
81 + }
82 + mBoxes = shrunk;
83 + }
84 + }