You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.7 KiB
101 lines
2.7 KiB
package com.connor.jd.plm.table;
|
|
|
|
import java.awt.Dimension;
|
|
import java.util.Vector;
|
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
|
public class DefaultModel extends DefaultTableModel implements CellSpan {
|
|
protected int rowSize;
|
|
protected int columnSize;
|
|
protected int[][][] span; // CellSpan
|
|
@Override
|
|
public int[] getSpan(int row, int column) {
|
|
// TODO Auto-generated method stub
|
|
if (isOutOfBounds(row, column)) {
|
|
int[] ret_code = { 1, 1 };
|
|
return ret_code;
|
|
}
|
|
return span[row][column];
|
|
}
|
|
|
|
@Override
|
|
public void setSpan(int[] span, int row, int column) {
|
|
// TODO Auto-generated method stub
|
|
if (isOutOfBounds(row, column))
|
|
return;
|
|
this.span[row][column] = span;
|
|
}
|
|
|
|
@Override
|
|
public boolean isVisible(int row, int column) {
|
|
// TODO Auto-generated method stub
|
|
if (isOutOfBounds(row, column))
|
|
return false;
|
|
if ((span[row][column][CellSpan.COLUMN] < 1) || (span[row][column][CellSpan.ROW] < 1))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void combine(int[] rows, int[] columns) {
|
|
// TODO Auto-generated method stub
|
|
int rowSpan = rows.length;
|
|
int columnSpan = columns.length;
|
|
int startRow = rows[0];
|
|
int startColumn = columns[0];
|
|
for (int i = 0; i < rowSpan; i++) {
|
|
for (int j = 0; j < columnSpan; j++) {
|
|
if ((span[startRow + i][startColumn + j][CellSpan.COLUMN] != 1)
|
|
|| (span[startRow + i][startColumn + j][CellSpan.ROW] != 1)) {
|
|
// System.out.println("can't combine");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0, ii = 0; i < rowSpan; i++, ii--) {
|
|
for (int j = 0, jj = 0; j < columnSpan; j++, jj--) {
|
|
span[startRow + i][startColumn + j][CellSpan.COLUMN] = jj;
|
|
span[startRow + i][startColumn + j][CellSpan.ROW] = ii;
|
|
// System.out.println("r " +ii +" c " +jj);
|
|
}
|
|
}
|
|
span[startRow][startColumn][CellSpan.COLUMN] = columnSpan;
|
|
span[startRow][startColumn][CellSpan.ROW] = rowSpan;
|
|
}
|
|
|
|
public void setSize(Dimension size) {
|
|
columnSize = size.width;
|
|
rowSize = size.height;
|
|
span = new int[rowSize][columnSize][2]; // 2: COLUMN,ROW
|
|
initValue();
|
|
}
|
|
|
|
protected void initValue() {
|
|
System.out.println(span.length);
|
|
for (int i = 0; i < span.length; i++) {
|
|
for (int j = 0; j < span[i].length; j++) {
|
|
span[i][j][CellSpan.COLUMN] = 1;
|
|
span[i][j][CellSpan.ROW] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected boolean isOutOfBounds(int row, int column) {
|
|
if ((row < 0) || (rowSize <= row) || (column < 0) || (columnSize <= column)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public DefaultModel(int numRows, int numColumns) {
|
|
Vector names = new Vector(numColumns);
|
|
names.setSize(numColumns);
|
|
setColumnIdentifiers(names);
|
|
dataVector = new Vector();
|
|
setNumRows(numRows);
|
|
setSize(new Dimension(numColumns, numRows));
|
|
}
|
|
|
|
}
|