📄 tableviewswtimpl.java
字号:
final TableItem item = table.getItem(row);
String cellName = (String)tcColumn.getData("Name");
final TableRowSWT rowSWT = (TableRowSWT)getRow(row);
final TableCellSWT cell = rowSWT.getTableCellSWT(cellName);
final Text newInput = oldInput != null && !oldInput.isDisposed() ? oldInput : new Text(table, Constants.isOSX ? 0 : 2048);
Object datasource = cell.getDataSource();
if (cellEditNotifier != null)
cellEditNotifier.cleanup(newInput);
table.showItem(item);
table.showColumn(tcColumn);
newInput.setText(cell.getText());
newInput.setSelection(0);
newInput.selectAll();
newInput.setFocus();
class 1QuickEditListener
implements ModifyListener, SelectionListener, KeyListener, TraverseListener, SourceReplaceListener, ControlListener
{
boolean resizing;
final TableItem val$item;
final TableCellSWT val$cell;
final Text val$newInput;
final TableRowSWT val$rowSWT;
final int val$column;
final int val$row;
final Object val$datasource;
final TableViewSWTImpl this$0;
public void modifyText(ModifyEvent e)
{
if (item.isDisposed())
{
sourcesChanged();
return;
}
if (((TableColumnCore)cell.getTableColumn()).inplaceValueSet(cell, newInput.getText(), false))
newInput.setBackground(null);
else
newInput.setBackground(Colors.colorErrorBG);
}
public void widgetDefaultSelected(SelectionEvent e)
{
if (item.isDisposed())
{
sourcesChanged();
newInput.traverse(4);
return;
} else
{
((TableColumnCore)cell.getTableColumn()).inplaceValueSet(cell, newInput.getText(), true);
rowSWT.invalidate();
editCell(column, row + 1);
return;
}
}
public void widgetSelected(SelectionEvent selectionevent)
{
}
public void keyPressed(KeyEvent e)
{
if (e.keyCode == 0x1000002 || e.keyCode == 0x1000001)
{
e.doit = false;
editCell(column, row + (e.keyCode != 0x1000002 ? -1 : 1));
}
}
public void keyReleased(KeyEvent keyevent)
{
}
public void keyTraversed(TraverseEvent e)
{
if (e.detail == 2)
{
e.doit = false;
editCell(column, -1);
}
}
public void sourcesChanged()
{
if (getRow(datasource) == rowSWT || getRow(datasource) == null || newInput.isDisposed())
return;
String newVal = newInput.getText();
Point sel = newInput.getSelection();
editCell(column, getRow(datasource).getIndex());
if (newInput.isDisposed())
{
return;
} else
{
newInput.setText(newVal);
newInput.setSelection(sel);
return;
}
}
public void cleanup(Text oldText)
{
if (!oldText.isDisposed())
{
oldText.removeModifyListener(this);
oldText.removeSelectionListener(this);
oldText.removeKeyListener(this);
oldText.removeTraverseListener(this);
oldText.removeControlListener(this);
}
}
public void controlMoved(ControlEvent e)
{
table.showItem(item);
if (resizing)
return;
resizing = true;
Point sel = newInput.getSelection();
editor.setEditor(newInput, item, column);
editor.minimumWidth = newInput.computeSize(-1, -1).x;
Rectangle leftAlignedBounds = item.getBounds(column);
leftAlignedBounds.width = editor.minimumWidth = newInput.computeSize(-1, -1).x;
if (leftAlignedBounds.intersection(clientArea).equals(leftAlignedBounds))
editor.horizontalAlignment = 16384;
else
editor.horizontalAlignment = 0x20000;
editor.layout();
newInput.setSelection(0);
newInput.setSelection(sel);
resizing = false;
}
public void controlResized(ControlEvent controlevent)
{
}
public 1QuickEditListener(Object obj)
{
this$0 = TableViewSWTImpl.this;
item = tableitem;
cell = tablecellswt;
newInput = text;
rowSWT = tablerowswt;
column = i;
row = j;
datasource = obj;
super();
resizing = true;
toAttach.addModifyListener(this);
toAttach.addSelectionListener(this);
toAttach.addKeyListener(this);
toAttach.addTraverseListener(this);
toAttach.addControlListener(this);
cellEditNotifier = this;
}
}
1QuickEditListener l = new 1QuickEditListener(datasource);
l.modifyText(null);
editor.setEditor(newInput, item, column);
table.deselectAll();
table.select(row);
updateSelectedRowIndexes();
l.resizing = false;
l.controlMoved(null);
}
private TableCellMouseEvent createMouseEvent(TableCellSWT cell, MouseEvent e, int type)
{
TableCellMouseEvent event = new TableCellMouseEvent();
event.cell = cell;
if (cell != null)
event.row = cell.getTableRow();
event.eventType = type;
event.button = e.button;
event.keyboardState = e.stateMask;
event.skipCoreFunctionality = false;
if (cell != null)
{
Rectangle r = cell.getBounds();
event.x = (e.x - r.x) + VerticalAligner.getTableAdjustHorizontallyBy(table);
if (event.x < 0)
return null;
event.y = (e.y - r.y) + VerticalAligner.getTableAdjustVerticalBy(table);
if (event.y < 0)
return null;
}
return event;
}
protected void paintItem(Event event)
{
if (event.gc.getClipping().isEmpty())
return;
TableItem item;
item = (TableItem)event.item;
if (item == null || item.isDisposed())
return;
int iColumnNo;
iColumnNo = event.index;
if (!bSkipFirstColumn)
break MISSING_BLOCK_LABEL_54;
if (iColumnNo == 0)
return;
iColumnNo--;
if (iColumnNo >= columnsOrdered.length)
{
System.out.println((new StringBuilder()).append("Col #").append(iColumnNo).append(" >= ").append(columnsOrdered.length).append(" count").toString());
return;
}
if (!isColumnVisible(columnsOrdered[iColumnNo]))
return;
TableRowSWT row;
row = (TableRowSWT)getRow(item);
if (row == null)
return;
int rowAlpha;
Rectangle cellBounds;
int rowPos = indexOf(row);
if (rowPos < lastTopIndex || rowPos > lastBottomIndex)
visibleRowsChanged();
rowAlpha = row.getAlpha();
int fontStyle = row.getFontStyle();
if (fontStyle == 1)
{
if (fontBold == null)
{
FontData fontData[] = event.gc.getFont().getFontData();
for (int i = 0; i < fontData.length; i++)
{
FontData fd = fontData[i];
fd.setStyle(1);
}
fontBold = new Font(event.gc.getDevice(), fontData);
}
event.gc.setFont(fontBold);
}
cellBounds = item.getBounds(event.index);
if (cellBounds.width <= 0 || cellBounds.height <= 0)
return;
TableCellSWT cell;
cell = row.getTableCellSWT(columnsOrdered[iColumnNo].getName());
if (cell == null)
return;
String text;
Rectangle clipping;
if (!cell.isUpToDate())
cell.refresh(true, true);
text = cell.getText();
clipping = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
int headerHeight = table.getHeaderHeight();
int iMinY = headerHeight + clientArea.y;
if (clipping.y < iMinY)
{
clipping.height -= iMinY - clipping.y;
clipping.y = iMinY;
}
int iMaxY = clientArea.height + clientArea.y;
if (clipping.y + clipping.height > iMaxY)
clipping.height = (iMaxY - clipping.y) + 1;
if (clipping.width <= 0 || clipping.height <= 0)
return;
try
{
event.gc.setClipping(clipping);
if (rowAlpha < 255)
event.gc.setAlpha(rowAlpha);
if (cell.needsPainting())
cell.doPaint(event.gc);
else
if (text.length() > 0)
{
int ofsx = 0;
Image image = item.getImage(event.index);
if (image != null)
{
int ofs = image.getBounds().width;
ofsx += ofs;
cellBounds.x += ofs;
cellBounds.width -= ofs;
}
int style = TableColumnSWTUtils.convertColumnAlignmentToSWT(columnsOrdered[iColumnNo].getAlignment());
if (cellBounds.height > 20)
style |= 0x40;
int textOpacity = cell.getTextAlpha();
if (textOpacity < 255)
event.gc.setAlpha(textOpacity);
ofsx += 6;
cellBounds.x += 3;
cellBounds.width -= 6;
if (!cellBounds.isEmpty())
{
GCStringPrinter sp = new GCStringPrinter(event.gc, text, cellBounds, true, cellBounds.height > 20, style);
boolean fit = sp.printString();
if (!fit)
cell.setToolTip(text);
Point size = sp.getCalculatedSize();
size.x += ofsx;
if (cell.getTableColumn().getPreferredWidth() < size.x)
cell.getTableColumn().setPreferredWidth(size.x);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return;
}
public void runDefaultAction(int stateMask)
{
if (lCancelSelectionTriggeredOn > 0L && System.currentTimeMillis() - lCancelSelectionTriggeredOn < 200L)
{
lCancelSelectionTriggeredOn = -1L;
} else
{
TableRowCore selectedRows[] = getSelectedRows();
triggerDefaultSelectedListeners(selectedRows, stateMask);
}
}
private void updateColumnVisibilities()
{
TableColumn columns[] = table.getColumns();
int topIdx = table.getTopIndex();
if (topIdx < 0 || table.getItemCount() < 1)
return;
columnVisibilitiesChanged = false;
TableItem topRow = table.getItem(topIdx);
for (int i = 0; i < columns.length; i++)
{
final TableColumnCore tc = (TableColumnCore)columns[i].getData("TableColumnCore");
if (tc == null)
continue;
int position = tc.getPosition();
if (position < 0 || position >= columnsVisible.length)
continue;
Rectangle size = topRow.getBounds(i);
size.intersect(clientArea);
boolean nowVisible = !size.isEmpty();
if (columnsVisible[position] == nowVisible)
continue;
columnsVisible[position] = nowVisible;
if (nowVisible)
runForVisibleRows(new TableGroupRowRunner() {
final TableColumnCore val$tc;
final TableViewSWTImpl this$0;
public void run(TableRowCore row)
{
TableCellCore cell = row.getTableCellCore(tc.getName());
cell.invalidate();
cell.redraw();
}
{
this$0 = TableViewSWTImpl.this;
tc = tablecolumncore;
super();
}
});
}
}
public boolean isColumnVisible(org.gudy.azureus2.plugins.ui.tables.TableColumn column)
{
int position = column.getPosition();
if (position < 0 || position >= columnsVisible.length)
return false;
else
return columnsVisible[position];
}
protected void initializeTableColumns(final Table table)
{
TableColumn oldColumns[] = table.getColumns();
if (SWT.getVersion() >= 3100)
{
for (int i = 0; i < oldColumns.length; i++)
oldColumns[i].removeListener(10, columnMoveListener);
}
for (int i = oldColumns.length - 1; i >= 0; i--)
oldColumns[i].dispose();
columnPaddingAdjusted = false;
ControlListener resizeListener = new ControlAdapter() {
private boolean bInFunction;
final Table val$table;
final TableViewSWTImpl this$0;
public void controlResized(ControlEvent e)
{
TableColumn column;
column = (TableColumn)e.widget;
if (column == null || column.isDisposed() || bInFunction)
return;
bInFunction = true;
TableColumnCore tc = (TableColumnCore)column.getData("TableColumnCore");
if (tc != null)
{
Long lPadding = (Long)column.getData("widthOffset");
int padding = lPadding != null ? lPadding.intValue() : 0;
tc.setWidth(column.getWidth() - padding);
}
int columnNumber = table.indexOf(column);
locationChanged(columnNumber);
bInFunction = false;
break MISSING_BLOCK_LABEL_123;
Exception exception;
exception;
bInFunction = false;
throw exception;
}
{
this$0 = TableViewSWTImpl.this;
table = table1;
super();
bInFunction = false;
}
};
bSkipFirstColumn = bSkipFirstColumn && !Constants.isOSX;
if (bSkipFirstColumn)
{
TableColumn tc = new TableColumn(table, 0);
tc.setWidth(0);
tc.setResizable(false);
tc.setMoveable(false);
}
TableColumnCore tmpColumnsOrdered[] = new TableColumnCore[tableColumns.length];
int columnOrderPos = 0;
Arrays.sort(tableColumns, TableColumnManager.getTableColumnOrderComparator());
for (int i = 0; i < tableColumns.length; i++)
{
int position = tableColumns[i].getPosition();
if (position != -1 && tableColumns[i].isVisible())
{
new TableColumn(table, 0);
tmpColumnsOrdered[columnOrderPos++] = tableColumns[i];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -