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