📄 bufferedtablerow.java
字号:
if ( index >= foreground_colors.length ){
int new_size = Math.max( index+1, foreground_colors.length+VALUE_SIZE_INC );
Color[] new_colors = new Color[new_size];
System.arraycopy( foreground_colors, 0, new_colors, 0, foreground_colors.length );
foreground_colors = new_colors;
}
Color value = foreground_colors[index];
if ( new_color == value ){
return false;
}
if ( new_color != null &&
value != null &&
new_color.equals( value )){
return false;
}
foreground_colors[index] = new_color;
try {
item.setForeground(index, new_color);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
return true;
}
public Color getForeground(int index)
{
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
if (index >= foreground_colors.length)
return item.getForeground();
return foreground_colors[index];
}
protected String
getText(
int index )
{
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return "";
// SWT >= 3041(Win),3014(GTK),3002(Carbon) and returns "" if range check
// fails
return item.getText(index);
}
/**
* @param index
* @param new_value
* @return true if the item has been updated
*/
public boolean
setText(
int index,
String new_value )
{
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return false;
if (index < 0 || index >= table.getColumnCount())
return false;
if (new_value == null)
new_value = "";
if (item.getText(index).equals(new_value))
return false;
item.setText( index, new_value );
return true;
}
public Rectangle getBounds(int index) {
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
// Some Platforms (OSX) don't handle getBounds properly (3.2M4) when
// item doesn't exist in table
if (table.indexOf(item) == -1)
return null;
Rectangle r = item.getBounds(index);
if (r == null || r.width == 0 || r.height == 0)
return null;
return r;
}
protected Table getTable() {
return table;
}
public Color getBackground() {
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
return item.getBackground();
}
/**
* The Index is this item's the position in list.
*
* @return Item's Position
*/
public int getIndex() {
if (!checkWidget(REQUIRE_TABLEITEM))
return -1;
return table.indexOf(item);
}
private void copyToItem(TableItem newItem) {
Table table = getTable();
if (table == null || item == null)
return;
// newItem.setText(text_values);
newItem.setImage(image_values);
Color colorFG = item.getForeground();
Color colorBG = item.getBackground();
newItem.setForeground(colorFG);
newItem.setBackground(colorBG);
int numColumns = table.getColumnCount();
for (int i = 0; i < numColumns; i++) {
try {
newItem.setText(i, item.getText(i));
Color colorColumnFG = item.getForeground(i);
Color colorColumnBG = item.getBackground(i);
if (!colorColumnFG.equals(colorFG))
newItem.setForeground(i, colorColumnFG);
if (!colorColumnBG.equals(colorBG))
newItem.setBackground(i, colorColumnBG);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
}
if (isSelected())
table.select(table.indexOf(newItem));
else
table.deselect(table.indexOf(newItem));
newItem.setData("TableRow", item.getData("TableRow"));
}
public boolean isSelected() {
if (!checkWidget(REQUIRE_TABLEITEM))
return false;
// Invalid Indexes are checked/ignored by SWT.
return table.isSelected(table.indexOf(item));
}
public void setSelected(boolean bSelected) {
if (!checkWidget(REQUIRE_TABLEITEM))
return;
if (bSelected)
table.select(getIndex());
else
table.deselect(getIndex());
}
/**
* Set the TableItem associated with this row to the TableItem at the
* specified index.
*
* @param newIndex Index of TableItem that will be associated with this row
* @param bCopyFromOld True: Copy the visuals from the old TableItem to
* the new TableItem
* @return success level
*/
public boolean setTableItem(int newIndex, boolean bCopyFromOld) {
TableItem newRow;
try {
newRow = table.getItem(newIndex);
} catch (IllegalArgumentException er) {
if (item == null || item.isDisposed()) {
return false;
}
item = null;
return true;
} catch (Throwable e) {
System.out.println("setTableItem(" + newIndex + ", " + bCopyFromOld + ")");
e.printStackTrace();
return false;
}
if (newRow == item) {
if (newRow == null || newRow.getData("TableRow") == this) {
setAlternatingBGColor(false);
return false;
}
}
if (newRow != null) {
if (newRow.getParent() != table)
return false;
if (bCopyFromOld) {
copyToItem(newRow);
} else if (newRow.getData("SD") != null) {
// clear causes too much flicker
//table.clear(table.indexOf(newRow));
newRow.setForeground(null);
//newRow.setBackground(null);
int numColumns = table.getColumnCount();
for (int i = 0; i < numColumns; i++) {
try {
newRow.setImage(i, null);
newRow.setForeground(i, null);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
}
} else {
newRow.setData("SD", "1");
setIconSize(ptIconSize);
}
setAlternatingBGColor(false);
try {
newRow.setData("TableRow", this);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Disposed? " + newRow.isDisposed());
if (!newRow.isDisposed()) {
System.out.println("TR? " + newRow.getData("TableRow"));
System.out.println("SD? " + newRow.getData("SD"));
}
}
}
image_values = new Image[0];
foreground_colors = new Color[0];
foreground = null;
// unlink old item from tablerow
if (item != null && !item.isDisposed() && item.getData("TableRow") == this)
item.setData("TableRow", null);
item = newRow;
invalidate();
return true;
}
public boolean setHeight(int iHeight) {
return setIconSize(new Point(1, iHeight));
}
public boolean setIconSize(Point pt) {
ptIconSize = pt;
if (pt == null)
return false;
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return false;
Image oldImage = item.getImage(0);
if (oldImage != null) {
Rectangle r = oldImage.getBounds();
if (r.width == pt.x && r.height == pt.y)
return false;
}
// set row height by setting image
Image image = new Image(item.getDisplay(), pt.x, pt.y);
item.setImage(0, image);
item.setImage(0, null);
image.dispose();
return true;
}
/**
* Whether the row is currently visible to the user
*
* @return visibility
*/
public boolean isVisible() {
return checkWidget(REQUIRE_VISIBILITY);
}
/**
* Overridable function that is called when row needs invalidation.
*
*/
public void invalidate() {
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED | REQUIRE_VISIBILITY))
return;
Rectangle r = item.getBounds(0);
table.redraw(0, r.y, table.getClientArea().width, r.height, true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -