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 102 103 104 105 106 107 108 109 110 111 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.ui.def.nonpublic.support; import org.litesoft.core.simpletypes.*; import org.litesoft.ui.def.*; import org.litesoft.ui.def.nonpublic.*; public class ComponentGridCell { private int mRow; private int mColumn; private UiDef mComponent; private int mHsize = 1; private int mVsize = 1; private ComponentGridCell mSpanedFrom = null; public ComponentGridCell( int pRow, int pColumn, UiDef pComponent ) { mRow = pRow; mColumn = pColumn; mComponent = pComponent; } public int getRow() { return mRow; } public int getColumn() { return mColumn; } public UiDef getComponent() { return mComponent; } public int getHsize() { return mHsize; } public int getVsize() { return mVsize; } public boolean overlapsWith( ComponentGridCell pThem ) { return (pThem != null) && // (this.mHsize != 0) && (this.mVsize != 0) && (pThem.mHsize != 0) && (pThem.mVsize != 0) && new PointArea( this.mColumn, this.mRow, this.mHsize, this.mVsize ).hasOverlapWith( new PointArea( pThem.mColumn, pThem.mRow, pThem.mHsize, pThem.mVsize ) ); } public void setSpanedFromLeft( ComponentGrid pGrid ) { ComponentGridCell spanGroupRoot = chkCellAndGetRoot( "Left", pGrid.getCell( mRow, mColumn - 1 ) ); spanGroupRoot.forceWidthToIncludeColumn( mColumn ); } public void setSpanedFromAbove( ComponentGrid pGrid ) { ComponentGridCell spanGroupRoot = chkCellAndGetRoot( "Above", pGrid.getCell( mRow - 1, mColumn ) ); spanGroupRoot.forceHeightToIncludeRow( mRow ); } public boolean isEffectivelyEmpty() { return (mSpanedFrom != null) || (mComponent == null) || (mComponent instanceof UiSpacerDef); } private void forceWidthToIncludeColumn( int pColumn ) { while ( mColumn + (mHsize - 1) < pColumn ) { mHsize++; } } private void forceHeightToIncludeRow( int pRow ) { while ( mRow + (mVsize - 1) < pRow ) { mVsize++; } } private ComponentGridCell getSpanGroupRoot() // Left most & Upper most member of a real cell and its spans { return (mSpanedFrom != null) ? mSpanedFrom.getSpanGroupRoot() : this; } private ComponentGridCell chkCellAndGetRoot( String pFromWhere, ComponentGridCell pCell ) { if ( pCell == null ) { throw new IllegalStateException( "Unable to Span from " + pFromWhere + " for cell (" + mRow + "," + mColumn + ")" ); } mSpanedFrom = pCell; mHsize = mVsize = 0; return pCell.getSpanGroupRoot(); } public String toString() { return mComponent.toString() + " @ (" + mRow + "," + mColumn + ")"; } } |