001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing.enhanced;
032:
033: import java.awt.*;
034: import java.util.*;
035:
036: import javax.swing.*;
037: import javax.swing.plaf.basic.*;
038: import javax.swing.table.*;
039:
040: import de.ug2t.unifiedGui.*;
041:
042: /**
043: * Enhanced Tabel widget which is able to span cells and columns
044: * */
045: public class SpansJTable extends JTable {
046:
047: /**
048: * A bean-type inner-class that contains the span information for
049: * each defined span.
050: * @date 26.05.2006
051: */
052: private HashMap pem_Spans = null;
053:
054: /**
055: * Default Constructor.
056: */
057: public SpansJTable() {
058: super ();
059: }
060:
061: /**
062: * Default Constructor.
063: *
064: * @param dm
065: */
066: public SpansJTable(TableModel dm) {
067: super (dm);
068: }
069:
070: /**
071: * Default Constructor.
072: *
073: * @param dm
074: * @param cm
075: */
076: public SpansJTable(TableModel dm, TableColumnModel cm) {
077: super (dm, cm);
078: }
079:
080: /**
081: * Default Constructor.
082: *
083: * @param dm
084: * @param cm
085: * @param sm
086: */
087: public SpansJTable(TableModel dm, TableColumnModel cm,
088: ListSelectionModel sm) {
089: super (dm, cm, sm);
090: }
091:
092: /**
093: * Default Constructor.
094: *
095: * @param numRows
096: * @param numColumns
097: */
098: public SpansJTable(int numRows, int numColumns) {
099: super (numRows, numColumns);
100: }
101:
102: /**
103: * Default Constructor.
104: *
105: * @param rowData
106: * @param columnNames
107: */
108: public SpansJTable(Vector rowData, Vector columnNames) {
109: super (rowData, columnNames);
110: }
111:
112: public UnTableCellSpan pcmf_getSpan(int xRow, int xColumn) {
113: return ((UnTableCellSpan) this .pem_Spans.get(UnTableCellSpan
114: .pcmf_getKey(xRow, xColumn)));
115: }
116:
117: public Rectangle getCellRect(int row, int column,
118: boolean includeSpacing) {
119: if (this .pem_Spans == null)
120: return (super .getCellRect(row, column, includeSpacing));
121:
122: UnTableCellSpan l_span = (UnTableCellSpan) this .pem_Spans
123: .get(UnTableCellSpan.pcmf_getKey(row, column));
124: if (l_span == null)
125: return (super .getCellRect(row, column, includeSpacing));
126: else {
127: int l_rowSpanOffs = l_span.pcmf_getRowSpan() - 1;
128: int l_colSpanOffs = l_span.pcmf_getColumnSpan() - 1;
129:
130: Rectangle l_rectBeg = super .getCellRect(row, column,
131: includeSpacing);
132: Rectangle l_rectEnd = super .getCellRect(
133: row + l_rowSpanOffs, column + l_colSpanOffs,
134: includeSpacing);
135: Rectangle l_maxRect = new Rectangle(l_rectBeg.x,
136: l_rectBeg.y, l_rectEnd.x + l_rectEnd.width
137: - l_rectBeg.x, l_rectEnd.y
138: + l_rectEnd.height - l_rectBeg.y);
139:
140: return (l_maxRect);
141: }
142: }
143:
144: /**
145: * Default Constructor.
146: *
147: * @param rowData
148: * @param columnNames
149: */
150: public SpansJTable(Object[][] rowData, Object[] columnNames) {
151: super (rowData, columnNames);
152: }
153:
154: /**
155: * Create and store a span defintion upon the table.
156: *
157: * @param xRow
158: * @param xColumn
159: * @param xRowSpan
160: * @param xColumnSpan
161: */
162: public void pcmf_setSpan(int xRow, int xColumn, int xRowSpan,
163: int xColumnSpan) {
164: if (this .pem_Spans == null) {
165: pem_Spans = new HashMap();
166: setUI(new SpanTableUI());
167: }
168: ((SpanTableUI) this .getUI()).pcmf_clearSpans();
169: UnTableCellSpan lspan = new UnTableCellSpan(xRow, xColumn,
170: xRowSpan, xColumnSpan);
171: pem_Spans.put(lspan.pcmf_getKey(), lspan);
172: this .getTableHeader().setReorderingAllowed(false);
173: this .repaint();
174: }
175:
176: /**
177: * Removes a column span for the given row (if present)
178: *
179: * @param xRow
180: * @param xColumn
181: */
182: public void pcmf_removeSpan(int xRow, int xColumn) {
183: pem_Spans.remove(UnTableCellSpan.pcmf_getKey(xRow, xColumn));
184: ((SpanTableUI) this .getUI()).pcmf_clearSpans();
185: if (this .pem_Spans.size() == 0) {
186: this .getTableHeader().setReorderingAllowed(true);
187: this .setUI(new BasicTableUI());
188: this .pem_Spans = null;
189: }
190: this .repaint();
191: }
192:
193: /**
194: * Overriden to account for the column spans.
195: *
196: * @see javax.swing.JTable#columnAtPoint(java.awt.Point)
197: */
198: public int columnAtPoint(Point p) {
199: if (this .pem_Spans == null)
200: return (super .columnAtPoint(p));
201:
202: int l_col = super .columnAtPoint(p);
203: int l_row = super .rowAtPoint(p);
204: UnTableCellSpan l_span = ((SpanTableUI) this .getUI())
205: .pcmf_convert(l_row, l_col);
206: if (l_span != null)
207: return (l_span.pcmf_getColumnIndex());
208: else
209: return (l_col);
210: }
211:
212: /**
213: * Overriden to allow for Row spanning
214: * @see javax.swing.JTable#rowAtPoint(java.awt.Point)
215: */
216: public int rowAtPoint(Point p) {
217: if (this .pem_Spans == null)
218: return (super .rowAtPoint(p));
219:
220: int l_col = super .columnAtPoint(p);
221: int l_row = super .rowAtPoint(p);
222: UnTableCellSpan l_span = ((SpanTableUI) this .getUI())
223: .pcmf_convert(l_row, l_col);
224: if (l_span != null)
225: return (l_span.pcmf_getRowIndex());
226: else
227: return (l_row);
228: }
229:
230: public boolean pcmf_hasSpans() {
231: return (this .pem_Spans == null ? false : true);
232: }
233: }
|