use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class ColumnFileCount method openFilesMiniView.
private void openFilesMiniView(DownloadManager dm, TableCell cell) {
Shell shell = ShellFactory.createShell(Utils.findAnyShell(), SWT.SHELL_TRIM);
FillLayout fillLayout = new FillLayout();
fillLayout.marginHeight = 2;
fillLayout.marginWidth = 2;
shell.setLayout(fillLayout);
Rectangle bounds = ((TableCellSWT) cell).getBoundsOnDisplay();
bounds.y += bounds.height;
bounds.width = 630;
bounds.height = (16 * dm.getNumFileInfos()) + 60;
Rectangle realBounds = shell.computeTrim(0, 0, bounds.width, bounds.height);
realBounds.width -= realBounds.x;
realBounds.height -= realBounds.y;
realBounds.x = bounds.x;
realBounds.y = bounds.y;
if (bounds.height > 500) {
bounds.height = 500;
}
shell.setBounds(realBounds);
shell.setAlpha(230);
Utils.verifyShellRect(shell, true);
final FilesView view = new FilesView(false);
view.dataSourceChanged(dm);
view.initialize(shell);
Composite composite = view.getComposite();
// composite.setLayoutData(null);
// shell.setLayout(new FillLayout());
view.viewActivated();
view.refresh();
final UIUpdatable viewUpdater = new UIUpdatable() {
@Override
public void updateUI() {
view.refresh();
}
@Override
public String getUpdateUIName() {
return view.getFullTitle();
}
};
UIUpdaterSWT.getInstance().addUpdater(viewUpdater);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
UIUpdaterSWT.getInstance().removeUpdater(viewUpdater);
view.delete();
}
});
shell.layout(true, true);
shell.setText(dm.getDisplayName());
shell.open();
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class SizeItem method refresh.
@Override
public void refresh(TableCell cell) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
boolean internal = fileInfo instanceof FilesView.FilesViewTreeNode && !((FilesView.FilesViewTreeNode) fileInfo).isLeaf();
long value = (fileInfo == null) ? 0 : fileInfo.getLength();
if (!cell.setSortValue(value) && cell.isValid()) {
return;
}
String text;
if (value < 0) {
text = "";
} else {
text = DisplayFormatters.formatByteCountToKiBEtc(value);
if (internal) {
// text = "(" + text + ")";
}
}
cell.setText(text);
if (Utils.getUserMode() > 0 && (cell instanceof TableCellSWT)) {
if (value >= 0x40000000l) {
((TableCellSWT) cell).setTextAlpha(200 | 0x100);
} else if (value < 0x100000) {
((TableCellSWT) cell).setTextAlpha(180);
} else {
((TableCellSWT) cell).setTextAlpha(255);
}
}
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class PathNameItem method refresh.
@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
String file_name = (fileInfo == null) ? "" : fileInfo.getFile(true).getName();
if (file_name == null)
file_name = "";
String file_path = PathItem.determinePath(fileInfo, show_full_path);
if (!file_path.isEmpty()) {
if (!file_path.endsWith(File.separator)) {
file_path += File.separator;
}
file_name = file_path + file_name;
}
// setText returns true only if the text is updated
if (cell.setText(file_name) || !cell.isValid()) {
if (bShowIcon && !sortOnlyRefresh) {
Image icon = null;
final TableCellSWT _cell = (TableCellSWT) cell;
if (fileInfo == null) {
icon = null;
} else {
if (Utils.isSWTThread()) {
icon = ImageRepository.getPathIcon(fileInfo.getFile(true).getPath(), cell.getHeight() > 32, false);
} else {
// happens rarely (seen of filtering of file-view rows
// when a new row is added )
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
Image icon = ImageRepository.getPathIcon(fileInfo.getFile(true).getPath(), _cell.getHeight() > 32, false);
_cell.setIcon(icon);
_cell.redraw();
}
});
}
}
if (icon != null) {
_cell.setIcon(icon);
}
}
}
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class PiecesItem method refresh.
@Override
public void refresh(TableCell cell) {
/* Notes:
* We store our image and imageBufer in DownloadManager using
* setData & getData.
*/
// Named infoObj so code can be copied easily to the other PiecesItem
DownloadManager infoObj = (DownloadManager) cell.getDataSource();
long lCompleted = (infoObj == null) ? 0 : infoObj.getStats().getCompleted();
boolean bForce = infoObj != null && infoObj.getUserData("PiecesImage") == null;
if (!cell.setSortValue(lCompleted) && cell.isValid() && !bForce) {
return;
}
if (infoObj == null)
return;
// Compute bounds ...
int newWidth = cell.getWidth();
if (newWidth <= 0)
return;
int newHeight = cell.getHeight();
int x0 = borderVerticalSize;
int x1 = newWidth - 1 - borderVerticalSize;
int y0 = completionHeight + borderHorizontalSize + borderSplit;
int y1 = newHeight - 1 - borderHorizontalSize;
int drawWidth = x1 - x0 + 1;
if (drawWidth < 10 || y1 < 3)
return;
boolean bImageBufferValid = true;
int[] imageBuffer = (int[]) infoObj.getUserData("PiecesImageBuffer");
if (imageBuffer == null || imageBuffer.length != drawWidth) {
imageBuffer = new int[drawWidth];
bImageBufferValid = false;
}
Image image = (Image) infoObj.getUserData("PiecesImage");
GC gcImage;
boolean bImageChanged;
Rectangle imageBounds;
if (image == null || image.isDisposed()) {
bImageChanged = true;
} else {
imageBounds = image.getBounds();
bImageChanged = imageBounds.width != newWidth || imageBounds.height != newHeight;
}
if (bImageChanged) {
if (image != null && !image.isDisposed()) {
image.dispose();
}
image = new Image(Utils.getDisplay(), newWidth, newHeight);
imageBounds = image.getBounds();
bImageBufferValid = false;
// draw border
gcImage = new GC(image);
gcImage.setForeground(Colors.grey);
if (borderHorizontalSize > 0) {
if (borderVerticalSize > 0) {
gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
} else {
gcImage.drawLine(0, 0, newWidth - 1, 0);
gcImage.drawLine(0, newHeight - 1, newWidth - 1, newHeight - 1);
}
} else if (borderVerticalSize > 0) {
gcImage.drawLine(0, 0, 0, newHeight - 1);
gcImage.drawLine(newWidth - 1, 0, newWidth - 1, newHeight - 1);
}
if (borderSplit > 0) {
gcImage.setForeground(Colors.white);
gcImage.drawLine(x0, completionHeight + borderHorizontalSize, x1, completionHeight + borderHorizontalSize);
}
} else {
gcImage = new GC(image);
}
DiskManager disk_manager = infoObj.getDiskManager();
DiskManagerPiece[] pieces = disk_manager == null ? null : disk_manager.getPieces();
int nbPieces = infoObj.getNbPieces();
try {
int nbComplete = 0;
int a0;
int a1 = 0;
for (int i = 0; i < drawWidth; i++) {
if (i == 0) {
// always start out with one piece
a0 = 0;
a1 = nbPieces / drawWidth;
if (a1 == 0)
a1 = 1;
} else {
// the last iteration, a1 will be nbPieces
a0 = a1;
a1 = ((i + 1) * nbPieces) / (drawWidth);
}
int index;
if (a1 <= a0) {
index = imageBuffer[i - 1];
} else {
int nbAvailable = 0;
for (int j = a0; j < a1; j++) if (pieces != null && pieces[j].isDone())
nbAvailable++;
nbComplete += nbAvailable;
index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
// System.out.println("i="+i+";nbAvailable="+nbAvailable+";nbComplete="+nbComplete+";nbPieces="+nbPieces+";a0="+a0+";a1="+a1);
}
if (!bImageBufferValid || imageBuffer[i] != index) {
imageBuffer[i] = index;
bImageChanged = true;
gcImage.setForeground(index == INDEX_COLOR_NONEAVAIL ? Colors.red : Colors.blues[index]);
gcImage.drawLine(i + x0, y0, i + x0, y1);
}
}
// pieces can sometimes be 0 due to timing or bad torrent (well, there's a bug with a /0 error
// so it can happen somehow :)
int limit = nbPieces == 0 ? 0 : ((drawWidth * nbComplete) / nbPieces);
if (limit < drawWidth) {
gcImage.setBackground(Colors.blues[Colors.BLUES_LIGHTEST]);
gcImage.fillRectangle(limit + x0, borderHorizontalSize, x1 - limit, completionHeight);
}
gcImage.setBackground(Colors.colorProgressBar);
gcImage.fillRectangle(x0, borderHorizontalSize, limit, completionHeight);
} catch (Exception e) {
System.out.println("Error Drawing PiecesItem");
Debug.printStackTrace(e);
}
gcImage.dispose();
Image oldImage = null;
Graphic graphic = cell.getGraphic();
if (graphic instanceof UISWTGraphic) {
oldImage = ((UISWTGraphic) graphic).getImage();
}
if (bImageChanged || image != oldImage || !cell.isValid()) {
if (cell instanceof TableCellSWT) {
((TableCellSWT) cell).setGraphic(image);
} else {
cell.setGraphic(new UISWTGraphicImpl(image));
}
if (bImageChanged) {
cell.invalidate();
}
infoObj.setUserData("PiecesImage", image);
infoObj.setUserData("PiecesImageBuffer", imageBuffer);
}
}
use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.
the class RankItem method refresh.
@Override
public void refresh(TableCell cell) {
bInvalidByTrigger = false;
DownloadManager dm = (DownloadManager) cell.getDataSource();
long value = (dm == null) ? 0 : dm.getPosition();
String text = "" + value;
boolean complete = dm == null ? false : dm.getAssumedComplete();
if (complete) {
value += 0x10000;
}
cell.setSortValue(value);
cell.setText(text);
if (cell instanceof TableCellSWT) {
if (showIcon && dm != null) {
Image img = dm.getAssumedComplete() ? imgUp : imgDown;
((TableCellSWT) cell).setIcon(img);
} else {
((TableCellSWT) cell).setIcon(null);
}
}
}
Aggregations