use of com.biglybt.ui.common.table.TableCellCore in project BiglyBT by BiglySoftware.
the class ColumnTC_NameInfo method cellMouseTrigger.
// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.button == 1 && event.eventType == TableRowMouseEvent.EVENT_MOUSEUP && (event.cell instanceof TableCellCore)) {
Object data = event.cell.getTableRow().getData("AddHitArea");
if (data instanceof Rectangle) {
Rectangle hitArea = (Rectangle) data;
if (hitArea.contains(event.x, event.y)) {
TableView<?> tv = ((TableCellCore) event.cell).getTableRowCore().getView();
TableColumnSetupWindow tvs = (TableColumnSetupWindow) tv.getParentDataSource();
Object dataSource = event.cell.getDataSource();
if (dataSource instanceof TableColumnCore) {
TableColumnCore column = (TableColumnCore) dataSource;
tvs.chooseColumn(column);
}
}
}
} else if (event.eventType == TableRowMouseEvent.EVENT_MOUSEMOVE) {
Object data = event.cell.getTableRow().getData("AddHitArea");
if (data instanceof Rectangle) {
Rectangle hitArea = (Rectangle) data;
if (hitArea.contains(event.x, event.y)) {
((TableCellSWT) event.cell).setCursorID(SWT.CURSOR_HAND);
return;
}
}
((TableCellSWT) event.cell).setCursorID(SWT.CURSOR_ARROW);
}
}
use of com.biglybt.ui.common.table.TableCellCore in project BiglyBT by BiglySoftware.
the class TableTooltips method handleEvent.
@Override
public void handleEvent(Event event) {
switch(event.type) {
case SWT.MouseHover:
{
if (toolTipShell != null && !toolTipShell.isDisposed())
toolTipShell.dispose();
TableCellCore cell = tv.getTableCell(event.x, event.y);
if (cell == null)
return;
cell.invokeToolTipListeners(TableCellSWT.TOOLTIPLISTENER_HOVER);
Object oToolTip = cell.getToolTip();
if (oToolTip == null) {
oToolTip = cell.getDefaultToolTip();
}
// TODO: support composite, image, etc
if (oToolTip == null || oToolTip.toString().length() == 0)
return;
Display d = composite.getDisplay();
if (d == null)
return;
// We don't get mouse down notifications on trim or borders..
toolTipShell = new Shell(composite.getShell(), SWT.ON_TOP);
FillLayout f = new FillLayout();
try {
f.marginWidth = 3;
f.marginHeight = 1;
} catch (NoSuchFieldError e) {
/* Ignore for Pre 3.0 SWT.. */
}
toolTipShell.setLayout(f);
toolTipShell.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
Point size = new Point(0, 0);
if (oToolTip instanceof String) {
String sToolTip = (String) oToolTip;
toolTipLabel = new CLabel(toolTipShell, SWT.WRAP);
toolTipLabel.setForeground(Colors.getSystemColor(d, SWT.COLOR_INFO_FOREGROUND));
toolTipLabel.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
toolTipShell.setData("TableCellSWT", cell);
toolTipLabel.setText(sToolTip.replaceAll("&", "&&"));
// compute size on label instead of shell because label
// calculates wrap, while shell doesn't
size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (size.x > 600) {
size = toolTipLabel.computeSize(600, SWT.DEFAULT, true);
}
} else if (oToolTip instanceof Image) {
Image image = (Image) oToolTip;
toolTipLabel = new CLabel(toolTipShell, SWT.CENTER);
toolTipLabel.setForeground(Colors.getSystemColor(d, SWT.COLOR_INFO_FOREGROUND));
toolTipLabel.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
toolTipShell.setData("TableCellSWT", cell);
toolTipLabel.setImage(image);
size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
size.x += toolTipShell.getBorderWidth() * 2 + 2;
size.y += toolTipShell.getBorderWidth() * 2;
try {
size.x += toolTipShell.getBorderWidth() * 2 + (f.marginWidth * 2);
size.y += toolTipShell.getBorderWidth() * 2 + (f.marginHeight * 2);
} catch (NoSuchFieldError e) {
/* Ignore for Pre 3.0 SWT.. */
}
Point pt = composite.toDisplay(event.x, event.y);
Rectangle displayRect;
try {
displayRect = composite.getMonitor().getClientArea();
} catch (NoSuchMethodError e) {
displayRect = composite.getDisplay().getClientArea();
}
if (pt.x + size.x > displayRect.x + displayRect.width) {
pt.x = displayRect.x + displayRect.width - size.x;
}
if (pt.y + size.y > displayRect.y + displayRect.height) {
pt.y -= size.y + 2;
} else {
pt.y += 21;
}
if (pt.y < displayRect.y)
pt.y = displayRect.y;
toolTipShell.setBounds(pt.x, pt.y, size.x, size.y);
toolTipShell.setVisible(true);
break;
}
case SWT.Dispose:
if (mainShell != null && !mainShell.isDisposed())
mainShell.removeListener(SWT.Deactivate, this);
if (tv.getComposite() != null && !tv.getComposite().isDisposed())
tv.getComposite().removeListener(SWT.Deactivate, this);
default:
if (toolTipShell != null) {
toolTipShell.dispose();
toolTipShell = null;
toolTipLabel = null;
}
break;
}
// switch
}
use of com.biglybt.ui.common.table.TableCellCore in project BiglyBT by BiglySoftware.
the class TableRowPainted method buildCells.
private void buildCells() {
// debug("buildCells " + Debug.getCompressedStackTrace());
TableColumnCore[] visibleColumns = getView().getVisibleColumns();
if (visibleColumns == null) {
return;
}
synchronized (lock) {
mTableCells = new LinkedHashMap<>(visibleColumns.length, 1);
TableColumn currentSortColumn = null;
if (cellSort != null) {
currentSortColumn = cellSort.getTableColumn();
}
TableRowCore parentRow = getParentRowCore();
// create all the cells for the column
for (int i = 0; i < visibleColumns.length; i++) {
if (visibleColumns[i] == null) {
continue;
}
if (parentRow != null && !visibleColumns[i].handlesDataSourceType(getDataSource(false).getClass())) {
mTableCells.put(visibleColumns[i].getName(), null);
continue;
}
// System.out.println(dataSource + ": " + tableColumns[i].getName() + ": " + tableColumns[i].getPosition());
TableCellCore cell = (currentSortColumn != null && visibleColumns[i].equals(currentSortColumn)) ? cellSort : new TableCellPainted(TableRowPainted.this, visibleColumns[i], i);
mTableCells.put(visibleColumns[i].getName(), cell);
// if (i == 10) cell.bDebug = true;
}
}
}
use of com.biglybt.ui.common.table.TableCellCore in project BiglyBT by BiglySoftware.
the class TableRowPainted method swt_paintGC.
/**
* @param gc GC to draw to
* @param drawBounds Area that needs redrawing
* @param rowStartX where in the GC this row's x-axis starts
* @param rowStartY where in the GC this row's y-axis starts
* @param pos
*/
public void swt_paintGC(GC gc, Rectangle drawBounds, int rowStartX, int rowStartY, int pos, boolean isTableSelected, boolean isTableEnabled) {
if (isRowDisposed() || gc == null || gc.isDisposed() || drawBounds == null || isHidden) {
return;
}
// done by caller
// if (!drawBounds.intersects(rowStartX, rowStartY, 9999, getHeight())) {
// return;
// }
TableColumnCore[] visibleColumns = getView().getVisibleColumns();
if (visibleColumns == null || visibleColumns.length == 0) {
return;
}
boolean isSelected = isSelected();
boolean isSelectedNotFocused = isSelected && !isTableSelected;
Color origBG = gc.getBackground();
Color origFG = gc.getForeground();
Color fg = getForeground();
Color shadowColor = null;
Color altColor;
Color bg;
if (isTableEnabled) {
altColor = Colors.alternatingColors[pos >= 0 ? pos % 2 : 0];
if (altColor == null) {
altColor = gc.getDevice().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
}
if (isSelected) {
Color color;
color = gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION);
gc.setBackground(color);
} else {
gc.setBackground(altColor);
}
bg = getBackground();
if (bg == null) {
bg = gc.getBackground();
} else {
gc.setBackground(bg);
}
if (isSelected) {
shadowColor = fg;
fg = gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
} else {
if (fg == null) {
fg = gc.getDevice().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
}
}
} else {
Device device = gc.getDevice();
altColor = Colors.getSystemColor(device, SWT.COLOR_WIDGET_BACKGROUND);
if (isSelected) {
bg = Colors.getSystemColor(device, SWT.COLOR_WIDGET_LIGHT_SHADOW);
} else {
bg = altColor;
}
gc.setBackground(bg);
fg = Colors.getSystemColor(device, SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
gc.setForeground(fg);
int rowAlpha = getAlpha();
Font font = gc.getFont();
Rectangle clipping = gc.getClipping();
int x = rowStartX;
// boolean paintedRow = false;
synchronized (lock) {
if (mTableCells == null) {
// not sure if this is wise, but visibleRows seems to keep up to date.. so, it must be ok!
setShown(true, true);
}
if (mTableCells != null) {
for (TableColumn tc : visibleColumns) {
TableCellCore cell = mTableCells.get(tc.getName());
int w = tc.getWidth();
Rectangle r = new Rectangle(x, rowStartY, w, getHeight());
TableCellPainted cellSWT = null;
if (cell instanceof TableCellPainted && !cell.isDisposed()) {
cellSWT = (TableCellPainted) cell;
cellSWT.setBoundsRaw(r);
}
if (drawBounds.intersects(r)) {
// paintedRow = true;
gc.setAlpha(255);
if (isSelectedNotFocused) {
gc.setBackground(altColor);
gc.fillRectangle(r);
gc.setAlpha(100);
gc.setBackground(bg);
gc.fillRectangle(r);
} else {
gc.setBackground(bg);
gc.fillRectangle(r);
if (isSelected) {
gc.setAlpha(80);
gc.setForeground(altColor);
gc.fillGradientRectangle(r.x, r.y, r.width, r.height, true);
gc.setForeground(fg);
}
}
gc.setAlpha(rowAlpha);
if (cellSWT == null) {
x += w;
continue;
}
if (swt_paintCell(gc, cellSWT.getBounds(), cellSWT, shadowColor)) {
// row color may have changed; this would update the color
// for all new cells. However, setting color triggers a
// row redraw that will fix up the UI
// Color fgNew = getForeground();
// if (fgNew != null && fgNew != fg) {
// fg = fgNew;
// }
gc.setBackground(bg);
gc.setForeground(fg);
gc.setFont(font);
Utils.setClipping(gc, clipping);
}
if (DEBUG_ROW_PAINT) {
((TableCellSWTBase) cell).debug("painted " + (cell.getVisuallyChangedSinceRefresh() ? "VC" : "!P") + " @ " + r);
}
} else {
if (DEBUG_ROW_PAINT) {
((TableCellSWTBase) cell).debug("Skip paintItem; no intersects; r=" + r + ";dB=" + drawBounds + " from " + Debug.getCompressedStackTrace(4));
}
}
x += w;
}
}
int w = drawBounds.width - x;
if (w > 0) {
Rectangle r = new Rectangle(x, rowStartY, w, getHeight());
if (clipping.intersects(r)) {
gc.setAlpha(255);
if (isSelectedNotFocused) {
gc.setBackground(altColor);
gc.fillRectangle(r);
gc.setAlpha(100);
gc.setBackground(bg);
gc.fillRectangle(r);
} else {
gc.fillRectangle(r);
if (isSelected) {
gc.setAlpha(80);
gc.setForeground(altColor);
gc.fillGradientRectangle(r.x, r.y, r.width, r.height, true);
gc.setForeground(fg);
}
}
gc.setAlpha(rowAlpha);
}
}
}
if (isFocused()) {
gc.setAlpha(40);
gc.setForeground(origFG);
gc.setLineDash(new int[] { 1, 2 });
gc.drawRectangle(rowStartX, rowStartY, getViewPainted().getClientArea().width - 1, getHeight() - 1);
gc.setLineStyle(SWT.LINE_SOLID);
}
gc.setAlpha(255);
gc.setBackground(origBG);
gc.setForeground(origFG);
}
use of com.biglybt.ui.common.table.TableCellCore in project BiglyBT by BiglySoftware.
the class TableRowSWTBase method delete.
/* (non-Javadoc)
* @see TableRowCore#delete()
*/
@Override
public void delete() {
synchronized (lock) {
if (bDisposed) {
return;
}
if (mTableCells != null) {
for (TableCellCore cell : mTableCells.values()) {
try {
if (cell != null && !cell.isDisposed()) {
cell.dispose();
}
} catch (Exception e) {
Debug.out(e);
}
}
}
setHeight(0);
bDisposed = true;
}
}
Aggregations