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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| /*
* FusionTableUI.java
*
* Created on 12. octobre 2006, 11:31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package dmind.ihm;
import ihm.Ihm_creation_questionnaire;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.plaf.basic.*;
/**
* @version 1.0 11/26/98
*/
public class FusionTableUI extends BasicTableUI {
public void paint(Graphics g, JComponent c) {
//get the rectangle bounds of the current graphic to be drawn
Rectangle oldClipBounds = g.getClipBounds();
//makes a new rectangle the same size as the current rectangle
Rectangle clipBounds = new Rectangle(oldClipBounds);
//gets the width of all combined columns and assigns to tableWidth
int tableWidth = table.getColumnModel().getTotalColumnWidth();
//sets the width of the new rectangle to equal the either the current rect size of the table width
clipBounds.width = Math.min(clipBounds.width, tableWidth);
//Sets the current clip to the rectangle specified by the given coordinates
g.setClip(clipBounds);
//define the first and last rows that are visible
int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y));
int lastIndex = table.getRowCount()-1;
//define a rowRect. This is a rectangle spanning the entire visible part of the table
Rectangle rowRect = new Rectangle(0,0,tableWidth, table.getRowHeight() + table.getRowMargin());
rowRect.y = firstIndex*rowRect.height;
//for every row that is visible, paint it
for (int index = firstIndex; index <= lastIndex; index++) {
//is the clipBounds of the current object to be drawn in this row?
if (rowRect.intersects(clipBounds)) {
paintRow(g, index);
}
//move to next row
rowRect.y += rowRect.height;
}
g.setClip(oldClipBounds);
}
private void paintRow(Graphics g, int row) {
//define rect as the current graphic objects bounds
Rectangle rect = g.getClipBounds();
//the graphic has not been drawn yet
boolean drawn = false;
//define how many columns we have to draw for this row
int numColumns = table.getColumnCount();
//for every column in the row, paint it
for (int column = 0; column < numColumns; column++) {
//define cellRect
Rectangle cellRect = table.getCellRect(row,column,true);
int cellRow;
int cellColumn;
cellRow = row;
cellColumn = column;
if (cellRect.intersects(rect)) {
drawn = true;
try {
//is this a statement row? If so, apply special treatment to the cell,
//otherwise paint the cell normally
if (Ihm_creation_questionnaire.fusion) {
//We are on a row we want to span. If its the 1st column, increase
//the width of the rectangle to span the entire table width and
//call paintCell. Otherwise, do not even paint the cell.
if (cellColumn==0) {
cellRect.width=table.getColumnModel().getTotalColumnWidth();
paintCell(g, cellRect, cellRow, cellColumn);
}
} else
paintCell(g, cellRect, cellRow, cellColumn);
} catch(Exception e) {
e.printStackTrace();
}
} else {
if (drawn)
break;
}
}
}
private void paintCell(Graphics g, Rectangle cellRect, int row, int column) {
int spacingHeight = table.getRowMargin();
int spacingWidth = table.getColumnModel().getColumnMargin();
Color c = g.getColor();
g.setColor(table.getGridColor());
g.drawRect(cellRect.x,cellRect.y,cellRect.width-1,cellRect.height-1);
g.setColor(c);
cellRect.setBounds(cellRect.x + spacingWidth/2, cellRect.y + spacingHeight/2,
cellRect.width - spacingWidth, cellRect.height - spacingHeight);
if (table.isEditing() && table.getEditingRow()==row &&
table.getEditingColumn()==column) {
Component component = table.getEditorComponent();
component.setBounds(cellRect);
component.validate();
} else {
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component component = table.prepareRenderer(renderer, row, column);
if (component.getParent() == null) {
rendererPane.add(component);
}
rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y,
cellRect.width, cellRect.height, true);
}
}
} |
Partager