use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.
the class UISWTStatusEntryImpl method setImage.
@Override
public void setImage(int image_id) {
// release the old
if (imageID != null) {
imageIDstoDispose.add(imageID);
}
switch(image_id) {
case IMAGE_LED_GREEN:
imageID = "greenled";
break;
case IMAGE_LED_RED:
imageID = "redled";
break;
case IMAGE_LED_YELLOW:
imageID = "yellowled";
break;
default:
imageID = "grayled";
break;
}
ImageLoader imageLoader = ImageLoader.getInstance();
this.setImage(imageLoader.getImage(imageID));
}
use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.
the class TorrentUIUtilsV3 method getContentImage.
/**
* Retrieves the thumbnail for the content, pulling it from the web if
* it can
*
* @param datasource
* @param l When the thumbnail is available, this listener is triggered
* @return If the image is immediately available, the image will be returned
* as well as the trigger being fired. If the image isn't available
* null will be returned and the listener will trigger when avail
*
* @since 4.0.0.5
*/
public static Image[] getContentImage(Object datasource, boolean big, final ContentImageLoadedListener l) {
if (l == null) {
return null;
}
TOTorrent torrent = DataSourceUtils.getTorrent(datasource);
if (torrent == null) {
l.contentImageLoaded(null, true);
return null;
}
if (imageLoaderThumb == null) {
imageLoaderThumb = new ImageLoader(null, null);
}
String thumbnailUrl = PlatformTorrentUtils.getContentThumbnailUrl(torrent);
// System.out.println("thumburl= " + thumbnailUrl);
if (thumbnailUrl != null && imageLoaderThumb.imageExists(thumbnailUrl)) {
// System.out.println("return thumburl");
Image image = imageLoaderThumb.getImage(thumbnailUrl);
l.contentImageLoaded(image, true);
return new Image[] { image };
}
String hash = null;
try {
hash = torrent.getHashWrapper().toBase32String();
} catch (TOTorrentException e) {
}
if (hash == null) {
l.contentImageLoaded(null, true);
return null;
}
int thumbnailVersion = PlatformTorrentUtils.getContentVersion(torrent);
// add torrent size here to differentiate meta-data downloads from actuals
final String id = "Thumbnail." + hash + "." + torrent.getSize() + "." + thumbnailVersion;
Image image = imageLoaderThumb.imageAdded(id) ? imageLoaderThumb.getImage(id) : null;
// System.out.println("image = " + image);
if (image != null && !image.isDisposed()) {
l.contentImageLoaded(image, true);
return new Image[] { image };
}
final byte[] imageBytes = PlatformTorrentUtils.getContentThumbnail(torrent);
// System.out.println("imageBytes = " + imageBytes);
if (imageBytes != null) {
image = (Image) Utils.execSWTThreadWithObject("thumbcreator", new AERunnableObject() {
@Override
public Object runSupport() {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
Image image = new Image(Display.getDefault(), bis);
return image;
} catch (Throwable e) {
return (null);
}
}
}, 500);
}
/**
* if ((image == null || image.isDisposed()) && thumbnailUrl != null) {
* //System.out.println("get image from " + thumbnailUrl);
* image = imageLoader.getUrlImage(thumbnailUrl,
* new ImageDownloaderListener() {
* public void imageDownloaded(Image image, boolean returnedImmediately) {
* l.contentImageLoaded(image, returnedImmediately);
* //System.out.println("got image from thumburl");
* }
* });
* //System.out.println("returning " + image + " (url loading)");
* return image == null ? null : new Image[] { image };
* }
*/
if (image == null || image.isDisposed()) {
// System.out.println("build image from files");
DownloadManager dm = DataSourceUtils.getDM(datasource);
/*
* Try to get an image from the OS
*/
String path = null;
if (dm == null) {
TOTorrentFile[] files = torrent.getFiles();
if (files.length > 0) {
path = files[0].getRelativePath();
}
} else {
DiskManagerFileInfo primaryFile = dm.getDownloadState().getPrimaryFile();
path = primaryFile == null ? null : primaryFile.getFile(true).getName();
}
if (path != null) {
image = ImageRepository.getPathIcon(path, big, false);
if (image != null && !torrent.isSimpleTorrent()) {
Image[] images = new Image[] { image, ImageRepository.getPathIcon(new File(path).getParent(), false, false) };
return images;
}
}
if (image == null) {
imageLoaderThumb.addImageNoDipose(id, ImageLoader.noImage);
} else {
imageLoaderThumb.addImageNoDipose(id, image);
}
} else {
// System.out.println("has mystery image");
imageLoaderThumb.addImage(id, image);
}
l.contentImageLoaded(image, true);
return new Image[] { image };
}
use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.
the class Utils method setMenuItemImage.
/**
* <p>
* Set a MenuItem's image with the given ImageRepository key. In compliance with platform
* human interface guidelines, the images are not set under Mac OS X.
* </p>
* @param item SWT MenuItem
* @param repoKey ImageRepository image key
* @see <a href="http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGMenus/chapter_7_section_3.html#//apple_ref/doc/uid/TP30000356/TPXREF116">Apple HIG</a>
*/
public static void setMenuItemImage(final MenuItem item, final String repoKey) {
if (Constants.isOSX || repoKey == null) {
return;
}
ImageLoader imageLoader = ImageLoader.getInstance();
item.setImage(imageLoader.getImage(repoKey));
item.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.releaseImage(repoKey);
}
});
}
use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.
the class TranscodeChooser method addImageBox.
/**
* @since 4.1.0.5
*/
public static void addImageBox(Composite parent, Listener clickListener, Listener listenerMouseInout, Object obj, String iconURL, String name) {
GridData gridData;
final Shell shell = parent.getShell();
final Composite c = new Composite(parent, SWT.NONE);
GridLayout clayout = new GridLayout();
clayout.marginWidth = clayout.horizontalSpacing = 0;
c.setLayout(clayout);
c.setCursor(c.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
c.addListener(SWT.MouseUp, clickListener);
c.addListener(SWT.MouseDown, clickListener);
c.setData("obj", obj);
if (listenerMouseInout != null) {
c.addListener(SWT.MouseEnter, listenerMouseInout);
c.addListener(SWT.MouseExit, listenerMouseInout);
}
final Canvas lblImage = new Canvas(c, SWT.DOUBLE_BUFFERED);
if (listenerMouseInout != null) {
lblImage.addListener(SWT.MouseEnter, listenerMouseInout);
lblImage.addListener(SWT.MouseExit, listenerMouseInout);
}
lblImage.addListener(SWT.MouseUp, clickListener);
lblImage.addListener(SWT.MouseDown, clickListener);
lblImage.setData("obj", obj);
lblImage.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event event) {
Rectangle area = lblImage.getBounds();
Rectangle carea = c.getBounds();
Point ptInDisplay = c.toDisplay(0, 0);
event.gc.setAdvanced(true);
event.gc.setAntialias(SWT.ON);
event.gc.setLineWidth(2);
if (new Rectangle(ptInDisplay.x, ptInDisplay.y, carea.width, carea.height).contains(event.display.getCursorLocation())) {
// if (event.display.getCursorControl() == lblImage) {
Color color1 = ColorCache.getColor(event.gc.getDevice(), 252, 253, 255);
Color color2 = ColorCache.getColor(event.gc.getDevice(), 169, 195, 252);
Pattern pattern = new Pattern(event.gc.getDevice(), 0, 0, 0, area.height, color1, 0, color2, 200);
event.gc.setBackgroundPattern(pattern);
event.gc.fillRoundRectangle(0, 0, area.width - 1, area.height - 1, 20, 20);
event.gc.setBackgroundPattern(null);
pattern.dispose();
pattern = new Pattern(event.gc.getDevice(), 0, 0, 0, area.height, color2, 50, color2, 255);
event.gc.setForegroundPattern(pattern);
event.gc.drawRoundRectangle(0, 0, area.width - 1, area.height - 1, 20, 20);
event.gc.setForegroundPattern(null);
pattern.dispose();
}
Image image = (Image) lblImage.getData("Image");
if (image != null) {
Rectangle bounds = image.getBounds();
event.gc.drawImage(image, bounds.x, bounds.y, bounds.width, bounds.height, 8, 5, bounds.width, bounds.height);
} else {
Rectangle ca = lblImage.getClientArea();
event.gc.setAdvanced(true);
event.gc.setAntialias(SWT.ON);
event.gc.setAlpha(50);
event.gc.setBackground(event.gc.getForeground());
event.gc.fillRoundRectangle(ca.x + 10, ca.y + 5, ca.width - 21, ca.height - 11, 20, 20);
}
}
});
gridData = new GridData(GridData.FILL_VERTICAL);
gridData.heightHint = 50;
gridData.widthHint = 100;
if (iconURL != null && iconURL.length() > 0) {
ImageLoader imageLoader = ImageLoader.getInstance();
Image image = imageLoader.getUrlImage(iconURL, new ImageLoader.ImageDownloaderListener() {
@Override
public void imageDownloaded(Image image, boolean returnedImmediately) {
if (!returnedImmediately) {
if (lblImage.isDisposed()) {
return;
}
lblImage.setData("Image", image);
Rectangle bounds = image.getBounds();
GridData gridData = (GridData) lblImage.getLayoutData();
gridData.heightHint = bounds.height + 10;
gridData.widthHint = bounds.width + 16;
Utils.setLayoutData(lblImage, gridData);
lblImage.getShell().layout(new Control[] { lblImage });
Point computeSize = shell.computeSize(600, SWT.DEFAULT, true);
shell.setSize(computeSize);
}
}
});
if (image != null) {
lblImage.setData("Image", image);
Rectangle bounds = image.getBounds();
gridData.heightHint = bounds.height + 10;
gridData.widthHint = bounds.width + 16;
}
}
Utils.setLayoutData(lblImage, gridData);
Label label = new Label(c, SWT.WRAP | SWT.CENTER);
if (listenerMouseInout != null) {
label.addListener(SWT.MouseEnter, listenerMouseInout);
}
label.addListener(SWT.MouseUp, clickListener);
label.addListener(SWT.MouseDown, clickListener);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(label, gridData);
String s = name;
// s += " (via " + profile.getProvider().getName() + ")";
label.setText(s);
label.setCursor(c.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
}
use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.
the class SystemWarningWindow method openWindow.
protected void openWindow() {
Display display = parent.getDisplay();
// shell = new Shell(parent, SWT.TOOL | SWT.TITLE | SWT.CLOSE);
// shell.setText("Warning (X of X)");
shell = new Shell(parent, SWT.TOOL);
shell.setLayout(new FormLayout());
shell.setBackground(Colors.getSystemColor(display, SWT.COLOR_INFO_BACKGROUND));
shell.setForeground(Colors.getSystemColor(display, SWT.COLOR_INFO_FOREGROUND));
Menu menu = new Menu(shell);
MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(menuItem, "MyTorrentsView.menu.thisColumn.toClipboard");
menuItem.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(logAlert.text + (logAlert.details == null ? "" : "\n" + logAlert.details));
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.setMenu(menu);
ImageLoader imageLoader = ImageLoader.getInstance();
imgClose = imageLoader.getImage("image.systemwarning.closeitem");
boundsClose = imgClose.getBounds();
GC gc = new GC(shell);
FontData[] fontdata = gc.getFont().getFontData();
fontdata[0].setHeight(fontdata[0].getHeight() + 1);
fontdata[0].setStyle(SWT.BOLD);
fontTitle = new Font(display, fontdata);
fontdata = gc.getFont().getFontData();
fontdata[0].setHeight(fontdata[0].getHeight() - 1);
fontCount = new Font(display, fontdata);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Utils.disposeSWTObjects(new Object[] { fontTitle, fontCount });
numWarningWindowsOpen--;
}
});
Rectangle printArea = new Rectangle(BORDER_X, 0, WIDTH - (BORDER_X * 2), 5000);
spText = new GCStringPrinter(gc, text, printArea, true, false, SWT.WRAP);
spText.setUrlColor(Colors.blues[Colors.FADED_DARKEST]);
spText.calculateMetrics();
gc.setFont(fontCount);
String sCount = MessageText.getString("label.xOfTotal", new String[] { "" + historyPosition + 1, "" + getWarningCount() });
spCount = new GCStringPrinter(gc, sCount, printArea, true, false, SWT.WRAP);
spCount.calculateMetrics();
gc.setFont(fontTitle);
spTitle = new GCStringPrinter(gc, title, printArea, true, false, SWT.WRAP);
spTitle.calculateMetrics();
gc.dispose();
sizeText = spText.getCalculatedSize();
sizeTitle = spTitle.getCalculatedSize();
sizeCount = spCount.getCalculatedSize();
FormData fd;
Button btnDismiss = new Button(shell, SWT.PUSH);
Messages.setLanguageText(btnDismiss, "Button.dismiss");
final int btnHeight = btnDismiss.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
Button btnPrev = new Button(shell, SWT.PUSH);
btnPrev.setText("<");
Button btnNext = new Button(shell, SWT.PUSH);
btnNext.setText(">");
fd = new FormData();
fd.bottom = new FormAttachment(100, -BORDER_Y1);
fd.right = new FormAttachment(100, -BORDER_X);
btnNext.setLayoutData(fd);
fd = new FormData();
fd.bottom = new FormAttachment(100, -BORDER_Y1);
fd.right = new FormAttachment(btnNext, -BORDER_X);
btnPrev.setLayoutData(fd);
fd = new FormData();
fd.bottom = new FormAttachment(100, -BORDER_Y1);
fd.right = new FormAttachment(btnPrev, -BORDER_X);
btnDismiss.setLayoutData(fd);
height = BORDER_Y0 + sizeTitle.y + GAP_Y + sizeText.y + GAP_Y_TITLE_COUNT + sizeCount.y + GAP_BUTTON_Y + btnHeight + BORDER_Y1;
Rectangle area = shell.computeTrim(ptBottomRight.x - WIDTH, ptBottomRight.y - height, WIDTH, height);
shell.setBounds(area);
shell.setLocation(ptBottomRight.x - area.width, ptBottomRight.y - area.height - 2);
rectX = new Rectangle(area.width - BORDER_X - boundsClose.width, BORDER_Y0, boundsClose.width, boundsClose.height);
shell.addMouseMoveListener(new MouseMoveListener() {
int lastCursor = SWT.CURSOR_ARROW;
@Override
public void mouseMove(MouseEvent e) {
if (shell == null || shell.isDisposed()) {
return;
}
URLInfo hitUrl = spText.getHitUrl(e.x, e.y);
int cursor = (rectX.contains(e.x, e.y)) || hitUrl != null ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW;
if (cursor != lastCursor) {
lastCursor = cursor;
shell.setCursor(e.display.getSystemCursor(cursor));
}
}
});
shell.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
if (shell == null || shell.isDisposed()) {
return;
}
if (rectX.contains(e.x, e.y)) {
shell.dispose();
}
URLInfo hitUrl = spText.getHitUrl(e.x, e.y);
if (hitUrl != null) {
if (hitUrl.url.equals("details")) {
MessageBoxShell mb = new MessageBoxShell(Constants.APP_NAME, logAlert.details, new String[] { MessageText.getString("Button.ok") }, 0);
mb.setUseTextBox(true);
mb.setParent(Utils.findAnyShell());
mb.open(null);
} else {
Utils.launch(hitUrl.url);
}
}
}
@Override
public void mouseDown(MouseEvent e) {
}
@Override
public void mouseDoubleClick(MouseEvent e) {
}
});
shell.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.drawImage(imgClose, WIDTH - BORDER_X - boundsClose.width, BORDER_Y0);
Rectangle printArea;
printArea = new Rectangle(BORDER_X, BORDER_Y0 + sizeTitle.y + GAP_Y_TITLE_COUNT, WIDTH, 100);
String sCount = MessageText.getString("label.xOfTotal", new String[] { "" + (historyPosition + 1), "" + getWarningCount() });
e.gc.setAlpha(180);
Font lastFont = e.gc.getFont();
e.gc.setFont(fontCount);
spCount = new GCStringPrinter(e.gc, sCount, printArea, true, false, SWT.WRAP | SWT.TOP);
spCount.printString();
e.gc.setAlpha(255);
sizeCount = spCount.getCalculatedSize();
e.gc.setFont(lastFont);
spText.printString(e.gc, new Rectangle(BORDER_X, BORDER_Y0 + sizeTitle.y + GAP_Y_TITLE_COUNT + sizeCount.y + GAP_Y, WIDTH - BORDER_X - BORDER_X, 5000), SWT.WRAP | SWT.TOP);
e.gc.setFont(fontTitle);
e.gc.setForeground(ColorCache.getColor(e.gc.getDevice(), "#54728c"));
spTitle.printString(e.gc, new Rectangle(BORDER_X, BORDER_Y0, WIDTH - BORDER_X - BORDER_X, 5000), SWT.WRAP | SWT.TOP);
e.gc.setLineStyle(SWT.LINE_DOT);
e.gc.setLineWidth(1);
e.gc.setAlpha(180);
e.gc.drawLine(BORDER_X, height - btnHeight - (GAP_BUTTON_Y / 2) - BORDER_Y1, WIDTH - BORDER_X, height - btnHeight - (GAP_BUTTON_Y / 2) - BORDER_Y1);
}
});
shell.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE) {
shell.dispose();
return;
}
}
});
btnPrev.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
int pos = historyPosition - 1;
if (pos < 0 || pos >= alerts.size()) {
return;
}
new SystemWarningWindow(alerts.get(pos), ptBottomRight, parent, pos);
shell.dispose();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
btnPrev.setEnabled(historyPosition > 0);
btnNext.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
int pos = historyPosition + 1;
if (pos >= alerts.size()) {
return;
}
new SystemWarningWindow(alerts.get(pos), ptBottomRight, parent, pos);
shell.dispose();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
btnNext.setEnabled(alerts.size() != historyPosition + 1);
btnDismiss.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
for (int i = 0; i < alerts.size() && i <= historyPosition; i++) {
Alerts.markAlertAsViewed(alerts.get(i));
}
shell.dispose();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.open();
numWarningWindowsOpen++;
}
Aggregations