use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.
the class ColumnActivityText method cellMouseTrigger.
// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
String tooltip = null;
boolean invalidateAndRefresh = false;
ActivitiesEntry entry = (ActivitiesEntry) event.cell.getDataSource();
// Rectangle bounds = getDrawBounds((TableCellSWT) event.cell);
Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
String text = entry.getText();
GC gc = new GC(Display.getDefault());
GCStringPrinter sp = null;
try {
sp = setupStringPrinter(gc, (TableCellSWT) event.cell);
} catch (Exception e) {
Debug.out(e);
} finally {
gc.dispose();
}
if (sp != null) {
URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
int newCursor;
if (hitUrl != null) {
String url = hitUrl.url;
boolean ourUrl = UrlFilter.getInstance().urlCanRPC(url) || url.startsWith("/") || url.startsWith("#");
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN && event.button == 1) {
if (!ourUrl) {
if (UrlUtils.isInternalProtocol(url)) {
try {
UIFunctionsManagerSWT.getUIFunctionsSWT().doSearch(url);
} catch (Throwable e) {
Debug.out(e);
}
} else {
Utils.launch(url);
}
} else {
UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uif != null) {
String target = hitUrl.target;
if (target == null) {
target = SkinConstants.VIEWID_BROWSER_BROWSE;
}
uif.viewURL(hitUrl.url, target, "column.activity.text");
return;
}
}
}
newCursor = SWT.CURSOR_HAND;
if (ourUrl) {
try {
tooltip = hitUrl.title == null ? null : URLDecoder.decode(hitUrl.title, "utf-8");
} catch (UnsupportedEncodingException e) {
}
} else {
tooltip = hitUrl.url;
}
} else {
newCursor = SWT.CURSOR_ARROW;
}
int oldCursor = ((TableCellSWT) event.cell).getCursorID();
if (oldCursor != newCursor) {
invalidateAndRefresh = true;
((TableCellSWT) event.cell).setCursorID(newCursor);
}
}
Object o = event.cell.getToolTip();
if ((o == null) || (o instanceof String)) {
String oldTooltip = (String) o;
if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
invalidateAndRefresh = true;
event.cell.setToolTip(tooltip);
}
}
if (invalidateAndRefresh) {
event.cell.invalidate();
((TableCellSWT) event.cell).redraw();
}
}
use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.
the class DoubleBufferedLabel method paintControl.
@Override
public void paintControl(PaintEvent e) {
e.gc.setAdvanced(true);
Rectangle clientArea = getClientArea();
GCStringPrinter sp = new GCStringPrinter(e.gc, getText(), clientArea, true, true, style);
sp.printString(e.gc, clientArea, style);
}
use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.
the class DoubleBufferedLabel method computeSize.
public Point computeSize(int wHint, int hHint, boolean changed, boolean realWidth) {
if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
return new Point(wHint, hHint);
}
Point pt = new Point(wHint, hHint);
Point lastSize = new Point(0, 0);
GC gc = new GC(this);
GCStringPrinter sp = new GCStringPrinter(gc, getText(), new Rectangle(0, 0, 10000, 20), true, true, SWT.LEFT);
sp.calculateMetrics();
Point lastTextSize = sp.getCalculatedSize();
gc.dispose();
lastSize.x += lastTextSize.x + 10;
lastSize.y = Math.max(lastSize.y, lastTextSize.y);
if (wHint == SWT.DEFAULT) {
pt.x = lastSize.x;
}
if (hHint == SWT.DEFAULT) {
pt.y = lastSize.y;
}
return pt;
}
use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.
the class TableRowPainted method swt_paintCell.
private boolean swt_paintCell(GC gc, Rectangle cellBounds, TableCellSWTBase cell, Color shadowColor) {
// Only called from swt_PaintGC, so we can assume GC, cell are valid
if (cellBounds == null) {
return false;
}
boolean gcChanged = false;
try {
gc.setTextAntialias(SWT.DEFAULT);
TableViewSWT<?> view = (TableViewSWT<?>) getView();
TableColumnCore column = (TableColumnCore) cell.getTableColumn();
view.invokePaintListeners(gc, this, column, cellBounds);
int fontStyle = getFontStyle();
Font oldFont = null;
if (fontStyle == SWT.BOLD) {
oldFont = gc.getFont();
gc.setFont(FontUtils.getAnyFontBold(gc));
gcChanged = true;
} else if (fontStyle == SWT.ITALIC) {
oldFont = gc.getFont();
gc.setFont(FontUtils.getAnyFontItalic(gc));
gcChanged = true;
}
if (!cell.isUpToDate()) {
// System.out.println("R " + rowIndex + ":" + iColumnNo);
cell.refresh(true, true);
// return;
}
String text = cell.getText();
Color fg = cell.getForegroundSWT();
if (fg != null) {
gcChanged = true;
if (isSelected()) {
shadowColor = fg;
} else {
gc.setForeground(fg);
}
}
Color bg = cell.getBackgroundSWT();
if (bg != null) {
gcChanged = true;
gc.setBackground(bg);
}
// }
if (cell.needsPainting()) {
Image graphicSWT = cell.getGraphicSWT();
if (graphicSWT != null && !graphicSWT.isDisposed()) {
Rectangle imageBounds = graphicSWT.getBounds();
Rectangle graphicBounds = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
if (cell.getFillCell()) {
if (!graphicBounds.isEmpty()) {
gc.setAdvanced(true);
// System.out.println(imageBounds + ";" + graphicBounds);
gc.drawImage(graphicSWT, 0, 0, imageBounds.width, imageBounds.height, graphicBounds.x, graphicBounds.y, graphicBounds.width, graphicBounds.height);
}
} else {
if (imageBounds.width < graphicBounds.width) {
int alignment = column.getAlignment();
if ((alignment & TableColumn.ALIGN_CENTER) > 0) {
graphicBounds.x += (graphicBounds.width - imageBounds.width) / 2;
} else if ((alignment & TableColumn.ALIGN_TRAIL) > 0) {
graphicBounds.x = (graphicBounds.x + graphicBounds.width) - imageBounds.width;
}
}
if (imageBounds.height < graphicBounds.height) {
graphicBounds.y += (graphicBounds.height - imageBounds.height) / 2;
}
gc.drawImage(graphicSWT, graphicBounds.x, graphicBounds.y);
}
}
cell.doPaint(gc);
gcChanged = true;
}
if (text.length() > 0) {
int ofsx = 0;
Image image = cell.getIcon();
Rectangle imageBounds = null;
if (image != null && !image.isDisposed()) {
imageBounds = image.getBounds();
int ofs = imageBounds.width;
ofsx += ofs;
cellBounds.x += ofs;
cellBounds.width -= ofs;
}
// System.out.println("PS " + getIndex() + ";" + cellBounds + ";" + cell.getText());
int style = TableColumnSWTUtils.convertColumnAlignmentToSWT(column.getAlignment());
if (cellBounds.height > 20) {
style |= SWT.WRAP;
}
int textOpacity = cell.getTextAlpha();
// textOpacity = 130;
if (textOpacity < 255) {
// gc.setTextAntialias(SWT.ON);
gc.setAlpha(textOpacity);
gcChanged = true;
} else if (textOpacity > 255) {
boolean is_italic = (gc.getFont().getFontData()[0].getStyle() & SWT.ITALIC) != 0;
if (is_italic) {
gc.setFont(FontUtils.getAnyFontBoldItalic(gc));
} else {
gc.setFont(FontUtils.getAnyFontBold(gc));
}
// gc.setTextAntialias(SWT.ON);
// gc.setAlpha(textOpacity & 255);
gcChanged = true;
}
// put some padding on text
ofsx += 6;
cellBounds.x += 3;
cellBounds.width -= 6;
cellBounds.y += 2;
cellBounds.height -= 4;
if (!cellBounds.isEmpty()) {
GCStringPrinter sp = new GCStringPrinter(gc, text, cellBounds, true, cellBounds.height > 20, style);
boolean fit;
if (shadowColor != null) {
Color oldFG = gc.getForeground();
gc.setForeground(shadowColor);
cellBounds.x += 1;
cellBounds.y += 1;
int alpha = gc.getAlpha();
gc.setAlpha(0x40);
sp.printString(gc, cellBounds, style);
gc.setAlpha(alpha);
gc.setForeground(oldFG);
cellBounds.x -= 1;
cellBounds.y -= 1;
fit = sp.printString2(gc, cellBounds, style);
} else {
fit = sp.printString();
}
if (fit) {
cell.setDefaultToolTip(null);
} else {
cell.setDefaultToolTip(text);
}
Point psize = sp.getCalculatedPreferredSize();
psize.x += ofsx;
TableColumn tableColumn = cell.getTableColumn();
if (tableColumn != null && tableColumn.getPreferredWidth() < psize.x) {
tableColumn.setPreferredWidth(psize.x);
}
if (imageBounds != null) {
int drawToY = cellBounds.y + (cellBounds.height / 2) - (imageBounds.height / 2);
boolean hack_adv = Constants.isWindows8OrHigher && gc.getAdvanced();
if (hack_adv) {
// problem with icon transparency on win8
gc.setAdvanced(false);
}
if ((style & SWT.RIGHT) != 0) {
Point size = sp.getCalculatedSize();
size.x += ofsx;
int drawToX = cellBounds.x + cellBounds.width - size.x;
gc.drawImage(image, drawToX, drawToY);
} else {
if (imageBounds.height > cellBounds.height) {
float pct = cellBounds.height / (float) imageBounds.height;
gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height, cellBounds.x - imageBounds.width - 3, cellBounds.y, (int) (imageBounds.width * pct), (int) (imageBounds.height * pct));
} else {
gc.drawImage(image, cellBounds.x - imageBounds.width - 3, drawToY);
}
}
if (hack_adv) {
gc.setAdvanced(true);
}
}
} else {
cell.setDefaultToolTip(null);
}
}
cell.clearVisuallyChangedSinceRefresh();
if (oldFont != null) {
gc.setFont(oldFont);
}
} catch (Exception e) {
Debug.out(cell.getTableID() + ":" + cell.getTableColumn().getName(), e);
}
return gcChanged;
}
use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.
the class TableViewPainted method paintHeader.
private void paintHeader(PaintEvent e) {
Rectangle ca = cHeaderArea.getClientArea();
Color c1, c2, fg;
if (cTable.isEnabled()) {
c1 = Colors.getSystemColor(e.display, SWT.COLOR_LIST_BACKGROUND);
c2 = Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_BACKGROUND);
fg = Colors.getSystemColor(e.display, SWT.COLOR_LIST_FOREGROUND);
} else {
c1 = Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_BACKGROUND);
c2 = Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_LIGHT_SHADOW);
fg = Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_NORMAL_SHADOW);
}
Color line = c2;
Pattern patternUp = new Pattern(e.display, 0, 0, 0, ca.height, c1, c2);
Pattern patternDown = new Pattern(e.display, 0, -ca.height, 0, 0, c2, c1);
// e.gc.setBackgroundPattern(patternUp);
// e.gc.fillRectangle(ca);
e.gc.setForeground(line);
// e.gc.drawLine(0, 0, clientArea.width, 0);
e.gc.drawLine(0, headerHeight - 1, clientArea.width, headerHeight - 1);
TableColumnCore[] visibleColumns = getVisibleColumns();
GCStringPrinter sp;
TableColumnCore sortColumn = getSortColumn();
int x = -clientArea.x;
for (TableColumnCore column : visibleColumns) {
int w = column.getWidth();
// squeeze last column's text into available visible space
if (x + w > ca.width) {
w = ca.width - x;
if (w <= 16) {
break;
}
}
boolean isSortColumn = column.equals(sortColumn);
e.gc.setBackgroundPattern(isSortColumn ? patternDown : patternUp);
e.gc.fillRectangle(x, 1, w, headerHeight - 2);
e.gc.setForeground(line);
e.gc.drawLine(x + w - 1, 0, x + w - 1, headerHeight - 1);
e.gc.setForeground(fg);
int yOfs = 0;
int wText = w;
/* Top Center
if (isSortColumn) {
int arrowY = 2;
int arrowHeight = 6;
yOfs = 8;
// draw sort indicator
int middle = w / 2;
int y1, y2;
int arrowHalfW = 4;
if (column.isSortAscending()) {
y2 = arrowY;
y1 = y2 + arrowHeight;
} else {
y1 = arrowY;
y2 = y1 + arrowHeight;
}
e.gc.setAntialias(SWT.ON);
e.gc.setBackground(ColorCache.getColor(e.display, 0, 0, 0));
e.gc.fillPolygon(new int[] {
x + middle - arrowHalfW,
y1,
x + middle + arrowHalfW,
y1,
x + middle,
y2
});
}
*/
if (isSortColumn) {
// draw sort indicator
int arrowHeight = Utils.adjustPXForDPI(6);
int arrowY = (headerHeight / 2) - (arrowHeight / 2);
int arrowHalfW = Utils.adjustPXForDPI(4);
int middle = w - arrowHalfW - 4;
wText = w - (arrowHalfW * 2) - 5;
int y1, y2;
if (column.isSortAscending()) {
y2 = arrowY;
y1 = y2 + arrowHeight;
} else {
y1 = arrowY;
y2 = y1 + arrowHeight;
}
e.gc.setAntialias(SWT.ON);
e.gc.setBackground(fg);
e.gc.fillPolygon(new int[] { x + middle - arrowHalfW, y1, x + middle + arrowHalfW, y1, x + middle, y2 });
}
int xOfs = x + 2;
boolean onlyShowImage = column.showOnlyImage();
String text = "";
if (!onlyShowImage) {
text = MessageText.getString(column.getTitleLanguageKey());
}
int style = SWT.WRAP | SWT.CENTER;
Image image = null;
String imageID = column.getIconReference();
if (imageID != null) {
image = ImageLoader.getInstance().getImage(imageID);
if (ImageLoader.isRealImage(image)) {
if (onlyShowImage) {
text = null;
Rectangle imageBounds = image.getBounds();
e.gc.drawImage(image, (int) (x + (w / 2.0) - (imageBounds.width / 2.0) + 0.5), (headerHeight / 2) - (imageBounds.height / 2));
} else {
text = "%0 " + text;
}
} else {
image = null;
}
}
if (text != null) {
sp = new GCStringPrinter(e.gc, text, new Rectangle(xOfs, yOfs - 1, wText - 4, headerHeight - yOfs + 2), true, false, style);
if (image != null) {
sp.setImages(new Image[] { image });
}
sp.calculateMetrics();
if (sp.isWordCut() || sp.isCutoff()) {
Font font = e.gc.getFont();
e.gc.setFont(fontHeaderSmall);
sp.printString();
e.gc.setFont(font);
} else {
sp.printString();
}
}
if (imageID != null) {
ImageLoader.getInstance().releaseImage(imageID);
}
x += w;
}
e.gc.setBackgroundPattern(patternUp);
e.gc.fillRectangle(x, 1, clientArea.width - x, headerHeight - 2);
patternUp.dispose();
patternDown.dispose();
e.gc.setBackgroundPattern(null);
}
Aggregations