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: * The UI class used in the treetable to allow for column expansions.
044: */
045: public class SpanTableUI extends BasicTableUI {
046: private HashMap pem_covered = new HashMap();
047:
048: public UnTableCellSpan pcmf_convert(int xRow, int xColumn) {
049: return ((UnTableCellSpan) this .pem_covered.get(UnTableCellSpan
050: .pcmf_getKey(xRow, xColumn)));
051: }
052:
053: public void pcmf_clearSpans() {
054: this .pem_covered.clear();
055: }
056:
057: /**
058: * Default Constructor.
059: */
060: public SpanTableUI() {
061: super ();
062: }
063:
064: /**
065: * Overridden to change the painting routine so that cell and row spans may be painted.
066: *
067: * @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics, javax.swing.JComponent)
068: */
069: public void paint(Graphics g, JComponent c) {
070: rendererPane.removeAll();
071: int firstRow = 0;
072: int lastRow = table.getRowCount();
073: // -1 is a flag that the ending point is outside the table
074: if (lastRow < 0)
075: lastRow = table.getRowCount() - 1;
076: for (int i = firstRow; i <= lastRow; i++)
077: paintRow(i, g);
078:
079: }
080:
081: /**
082: * Handles the painting of each table row.
083: * @param row
084: * @param g
085: */
086: private void paintRow(int row, Graphics g) {
087: Rectangle r = g.getClipBounds();
088: for (int i = 0; i < table.getColumnCount(); i++) {
089: Rectangle r1 = table.getCellRect(row, i, true);
090: if (r1.intersects(r)) // at least a part is visible
091: {
092: paintCell(row, i, g, r1);
093: }
094: }
095: }
096:
097: /**
098: * Paints each table cell.
099: * @param row
100: * @param column
101: * @param g
102: * @param area
103: */
104: private void paintCell(int row, int column, Graphics g,
105: Rectangle area) {
106: int verticalMargin = table.getRowMargin();
107: int horizontalMargin = table.getColumnModel().getColumnMargin();
108:
109: Color c = g.getColor();
110:
111: g.setColor(table.getGridColor());
112:
113: int width = area.width - 1;
114: int height = area.height - 1;
115:
116: UnTableCellSpan l_span = ((SpansJTable) table).pcmf_getSpan(
117: row, column);
118: if (l_span != null) {
119: int x = column;
120: int y = row;
121: int xMax = x + l_span.pcmf_getColumnSpan() - 1;
122: int yMax = y + l_span.pcmf_getRowSpan() - 1;
123: for (; x <= xMax; x++) {
124: for (; y <= yMax; y++)
125: this .pem_covered.put(UnTableCellSpan.pcmf_getKey(y,
126: x), l_span);
127:
128: y = row;
129: }
130: } else if (this .pem_covered.get(UnTableCellSpan.pcmf_getKey(
131: row, column)) != null)
132: return;
133:
134: if (table.getShowVerticalLines()) {
135: if (column == 0)
136: g.drawLine(area.x, area.y, area.x, area.y + height);
137:
138: g.drawLine(area.x + width, area.y, area.x + width, area.y
139: + height);
140: }
141: if (table.getShowHorizontalLines())
142: g.drawLine(area.x, area.y + height, area.x + width, area.y
143: + height);
144:
145: g.setColor(c);
146:
147: area.setBounds(area.x + horizontalMargin / 2, area.y
148: + verticalMargin / 2, area.width - horizontalMargin,
149: area.height - verticalMargin);
150:
151: if (table.isEditing() && table.getEditingRow() == row
152: && table.getEditingColumn() == column) {
153: Component component = table.getEditorComponent();
154: component.setBounds(area);
155: component.validate();
156: } else {
157: TableCellRenderer renderer = table.getCellRenderer(row,
158: column);
159: Component component = table.prepareRenderer(renderer, row,
160: column);
161: if (component.getParent() == null)
162: rendererPane.add(component);
163: rendererPane.paintComponent(g, component, table, area.x,
164: area.y, area.width, area.height, true);
165: }
166: }
167: }
|