use of com.biglybt.ui.mdi.MdiEntryVitalityImage in project BiglyBT by BiglySoftware.
the class SideBarToolTips method getToolTip.
/**
* @return
*
* @since 3.1.1.1
*/
private String getToolTip(Point mousePos_RelativeToItem) {
MdiEntryVitalityImage[] vitalityImages = mdiEntry.getVitalityImages();
for (int i = 0; i < vitalityImages.length; i++) {
SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
if (vitalityImage == null) {
continue;
}
String indicatorToolTip = vitalityImage.getToolTip();
if (indicatorToolTip == null || !vitalityImage.isVisible()) {
continue;
}
Rectangle hitArea = vitalityImage.getHitArea();
if (hitArea == null) {
continue;
}
if (hitArea.contains(mousePos_RelativeToItem)) {
return indicatorToolTip;
}
}
if (mdiEntry.getViewTitleInfo() != null) {
String tt = (String) mdiEntry.getViewTitleInfo().getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT_TOOLTIP);
return tt;
}
return null;
}
use of com.biglybt.ui.mdi.MdiEntryVitalityImage in project BiglyBT by BiglySoftware.
the class DevicesFTUX method _doInstall.
protected void _doInstall(Core core, boolean itunes) {
List<InstallablePlugin> plugins = new ArrayList<>(2);
final PluginInstaller installer = core.getPluginManager().getPluginInstaller();
StandardPlugin vuze_plugin = null;
try {
vuze_plugin = installer.getStandardPlugin("vuzexcode");
} catch (Throwable ignored) {
}
if (vuze_plugin != null && !vuze_plugin.isAlreadyInstalled()) {
plugins.add(vuze_plugin);
}
if (itunes) {
StandardPlugin itunes_plugin = null;
try {
itunes_plugin = installer.getStandardPlugin("azitunes");
} catch (Throwable ignored) {
}
if (itunes_plugin != null && !itunes_plugin.isAlreadyInstalled()) {
plugins.add(itunes_plugin);
}
}
if (plugins.size() == 0) {
close();
return;
}
InstallablePlugin[] installablePlugins = plugins.toArray(new InstallablePlugin[0]);
try {
install_area_parent.setVisible(true);
install_area_parent.moveAbove(null);
Map<Integer, Object> properties = new HashMap<>();
properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_SIMPLE);
properties.put(UpdateCheckInstance.PT_UI_PARENT_SWT_COMPOSITE, install_area);
properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
installer.install(installablePlugins, false, properties, new PluginInstallationListener() {
@Override
public void completed() {
close();
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
MdiEntry entry = mdi.getEntry(SideBar.SIDEBAR_HEADER_DEVICES);
MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
for (MdiEntryVitalityImage vi : vitalityImages) {
if (vi.getImageID().contains("turnon")) {
vi.setVisible(false);
}
}
List<Runnable> to_fire;
synchronized (to_fire_on_complete) {
to_fire = new ArrayList<>(to_fire_on_complete);
to_fire_on_complete.clear();
}
for (Runnable r : to_fire) {
if (r != null) {
try {
Utils.execSWTThread(r);
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
@Override
public void cancelled() {
close();
}
@Override
public void failed(PluginException e) {
Debug.out(e);
// Utils.openMessageBox(Utils.findAnyShell(), SWT.OK, "Error",
// e.toString());
close();
}
});
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
use of com.biglybt.ui.mdi.MdiEntryVitalityImage in project BiglyBT by BiglySoftware.
the class TabbedMDI_Ren method setupTabFolderRenderer.
static void setupTabFolderRenderer(final TabbedMDI mdi, final CTabFolder tabFolder) {
CTabFolderRenderer renderer = new CTabFolderRenderer(tabFolder) {
/* (non-Javadoc)
* @see org.eclipse.swt.custom.CTabFolderRenderer#computeSize(int, int, org.eclipse.swt.graphics.GC, int, int)
*/
@Override
protected Point computeSize(int part, int state, GC gc, int wHint, int hHint) {
gc.setAntialias(SWT.ON);
Point pt = super.computeSize(part, state, gc, wHint, hHint);
if (tabFolder.isDisposed()) {
return pt;
}
if (part >= 0) {
TabbedEntry entry = mdi.getEntryFromTabItem(tabFolder.getItem(part));
if (entry != null) {
ViewTitleInfo viewTitleInfo = entry.getViewTitleInfo();
if (viewTitleInfo != null) {
Object titleRight = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
if (titleRight != null) {
Point size = gc.textExtent(titleRight.toString(), 0);
pt.x += size.x + 10 + 2;
}
}
MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
com.biglybt.ui.swt.imageloader.ImageLoader imageLoader = com.biglybt.ui.swt.imageloader.ImageLoader.getInstance();
for (MdiEntryVitalityImage mdiEntryVitalityImage : vitalityImages) {
if (mdiEntryVitalityImage != null && mdiEntryVitalityImage.isVisible()) {
String imageID = mdiEntryVitalityImage.getImageID();
Image image = imageLoader.getImage(imageID);
if (com.biglybt.ui.swt.imageloader.ImageLoader.isRealImage(image)) {
pt.x += image.getBounds().x + 1;
}
}
}
}
}
return pt;
}
/* (non-Javadoc)
* @see org.eclipse.swt.custom.CTabFolderRenderer#draw(int, int, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC)
*/
@Override
protected void draw(int part, int state, Rectangle bounds, GC parent_gc) {
try {
// super.draw(part, state & ~(SWT.FOREGROUND), bounds, gc);
super.draw(part, state, bounds, parent_gc);
} catch (Throwable t) {
Debug.out(t);
}
if (part < 0) {
return;
}
try {
CTabItem item = mdi.getTabFolder().getItem(part);
TabbedEntry entry = mdi.getEntryFromTabItem(item);
if (entry == null) {
return;
}
ViewTitleInfo viewTitleInfo = entry.getViewTitleInfo();
if (viewTitleInfo != null) {
Object titleRight = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
if (titleRight != null) {
String textIndicator = titleRight.toString();
int x1IndicatorOfs = 0;
int SIDEBAR_SPACING = 0;
int x2 = bounds.x + bounds.width;
if (item.getShowClose()) {
try {
Field fldCloseRect = item.getClass().getDeclaredField("closeRect");
fldCloseRect.setAccessible(true);
Rectangle closeBounds = (Rectangle) fldCloseRect.get(item);
if (closeBounds != null && closeBounds.x > 0) {
x2 = closeBounds.x;
}
} catch (Exception e) {
x2 -= 20;
}
}
// gc.setAntialias(SWT.ON); FAIL ON WINDOWS 7 AT LEAST
Point textSize = parent_gc.textExtent(textIndicator);
// Point minTextSize = gc.textExtent("99");
// if (textSize.x < minTextSize.x + 2) {
// textSize.x = minTextSize.x + 2;
// }
int width = textSize.x + 10;
x1IndicatorOfs += width + SIDEBAR_SPACING;
int startX = x2 - x1IndicatorOfs;
int textOffsetY = 0;
int height = textSize.y + 1;
int startY = bounds.y + ((bounds.height - height) / 2) + 1;
Image image = new Image(parent_gc.getDevice(), width + 1, height + 1);
GC gc = new GC(image);
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
gc.setBackground(mdi.getTabFolder().getBackground());
gc.fillRectangle(new Rectangle(0, 0, width + 1, height + 1));
// gc.setBackground(((state & SWT.SELECTED) != 0 ) ? item.getParent().getSelectionBackground() : item.getParent().getBackground());
// gc.fillRectangle(startX - 5, startY, width + 5, height);
// Pattern pattern;
// Color color1;
// Color color2;
// gc.fillRectangle(startX, startY, width, height);
Color default_color = ColorCache.getSchemedColor(gc.getDevice(), "#5b6e87");
Object color = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
if (color instanceof int[]) {
gc.setBackground(ColorCache.getColor(gc.getDevice(), (int[]) color));
} else {
gc.setBackground(default_color);
}
Color text_color = Colors.white;
gc.fillRoundRectangle(0, 0, width, height, textSize.y * 2 / 3, height * 2 / 3);
if (color != null) {
Color bg = gc.getBackground();
int red = bg.getRed();
int green = bg.getGreen();
int blue = bg.getBlue();
double brightness = Math.sqrt(red * red * 0.299 + green * green * 0.587 + blue * blue * 0.114);
if (brightness >= 130) {
text_color = Colors.black;
}
gc.setBackground(default_color);
gc.drawRoundRectangle(0, 0, width, height, textSize.y * 2 / 3, height * 2 / 3);
}
gc.setForeground(text_color);
GCStringPrinter.printString(gc, textIndicator, new Rectangle(0, 0 + textOffsetY, width, height), true, false, SWT.CENTER);
gc.dispose();
parent_gc.drawImage(image, startX, startY);
image.dispose();
}
}
} catch (Throwable t) {
Debug.out(t);
}
}
};
tabFolder.setRenderer(renderer);
}
use of com.biglybt.ui.mdi.MdiEntryVitalityImage in project BiglyBT by BiglySoftware.
the class SideBar method swt_updateSideBarHitAreasY.
/**
* @since 3.1.1.1
*/
private void swt_updateSideBarHitAreasY(SideBarEntrySWT[] entries) {
for (int x = 0; x < entries.length; x++) {
SideBarEntrySWT entry = entries[x];
TreeItem treeItem = entry.getTreeItem();
if (treeItem == null || treeItem.isDisposed()) {
continue;
}
Rectangle itemBounds = entry.swt_getBounds();
if (itemBounds != null) {
if (entry.isCloseable()) {
Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
if (closeArea != null) {
closeArea.y = itemBounds.y + (itemBounds.height - closeArea.height) / 2;
}
}
MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
for (int i = 0; i < vitalityImages.length; i++) {
SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
if (!vitalityImage.isVisible()) {
continue;
}
Image image = vitalityImage.getImage();
if (image != null) {
Rectangle bounds = vitalityImage.getHitArea();
if (bounds == null) {
continue;
}
bounds.y = (itemBounds.height - bounds.height) / 2;
}
}
}
}
}
use of com.biglybt.ui.mdi.MdiEntryVitalityImage in project BiglyBT by BiglySoftware.
the class SideBarEntrySWT method swt_paintSideBar.
protected void swt_paintSideBar(Event event) {
neverPainted = false;
// System.out.println(System.currentTimeMillis() + "] paint " + getId() + ";sel? " + ((event.detail & SWT.SELECTED) > 0));
TreeItem treeItem = (TreeItem) event.item;
if (treeItem.isDisposed() || isDisposed()) {
return;
}
Rectangle itemBounds = treeItem.getBounds();
Rectangle drawBounds = event.gc.getClipping();
if (drawBounds.isEmpty()) {
drawBounds = event.getBounds();
}
Rectangle treeArea = treeItem.getParent().getClientArea();
if (Utils.isGTK3) {
// workaround bug
if (treeArea.width > itemBounds.width) {
itemBounds.width = treeArea.width;
}
if (treeArea.x < itemBounds.x) {
itemBounds.x = treeArea.x;
}
drawBounds = itemBounds;
}
String text = getTitle();
if (text == null)
text = "";
// Point size = event.gc.textExtent(text);
// Rectangle treeBounds = tree.getBounds();
GC gc = event.gc;
gc.setAntialias(SWT.ON);
gc.setAdvanced(true);
Utils.setClipping(gc, null);
boolean selected = (event.detail & SWT.SELECTED) > 0;
Color fgText = swt_paintEntryBG(event.detail, gc, drawBounds);
Tree tree = (Tree) event.widget;
Font font = tree.getFont();
if (font != null && !font.isDisposed()) {
gc.setFont(font);
}
if (SideBar.USE_NATIVE_EXPANDER && Utils.isGTK3) {
itemBounds.x = treeItem.getBounds().x;
} else if (DO_OUR_OWN_TREE_INDENT) {
TreeItem tempItem = treeItem.getParentItem();
int indent;
if (!isCollapseDisabled() && tempItem == null && !Utils.isGTK) {
indent = 22;
} else {
indent = 10;
}
while (tempItem != null) {
indent += 10;
tempItem = tempItem.getParentItem();
}
if (SideBar.USE_NATIVE_EXPANDER && Utils.isGTK) {
indent += 5;
}
itemBounds.x = indent;
}
int x1IndicatorOfs = SIDEBAR_SPACING;
int x0IndicatorOfs = itemBounds.x;
// System.out.println(System.currentTimeMillis() + "] refresh " + getId() + "; " + itemBounds + ";clip=" + event.gc.getClipping() + ";eb=" + event.getBounds());
if (viewTitleInfo != null) {
String textIndicator = null;
try {
textIndicator = (String) viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
} catch (Exception e) {
Debug.out(e);
}
if (textIndicator != null) {
Point textSize = gc.textExtent(textIndicator);
// Point minTextSize = gc.textExtent("99");
// if (textSize.x < minTextSize.x + 2) {
// textSize.x = minTextSize.x + 2;
// }
int width = textSize.x + Utils.adjustPXForDPI(10);
x1IndicatorOfs += width + SIDEBAR_SPACING;
int startX = treeArea.width - x1IndicatorOfs;
int textOffsetY = 0;
int height = textSize.y + 1;
int startY = itemBounds.y + (itemBounds.height - height) / 2;
// gc.fillRectangle(startX, startY, width, height);
// Pattern pattern;
// Color color1;
// Color color2;
Color default_color = ColorCache.getSchemedColor(gc.getDevice(), "#5b6e87");
Object color = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
if (color instanceof int[]) {
gc.setBackground(ColorCache.getColor(gc.getDevice(), (int[]) color));
} else {
gc.setBackground(default_color);
}
/*
if (selected) {
color1 = ColorCache.getColor(gc.getDevice(), colors[0]);
color2 = ColorCache.getColor(gc.getDevice(), colors[1]);
pattern = new Pattern(gc.getDevice(), 0, startY, 0, startY + height,
color1, 127, color2, 4);
} else {
color1 = ColorCache.getColor(gc.getDevice(), colors[2]);
color2 = ColorCache.getColor(gc.getDevice(), colors[3]);
pattern = new Pattern(gc.getDevice(), 0, startY, 0, startY + height,
color1, color2);
}
gc.setBackgroundPattern(pattern);
*/
Color text_color = Colors.white;
gc.fillRoundRectangle(startX, startY, width, height, textSize.y * 2 / 3, height * 2 / 3);
if (color != null) {
Color bg = gc.getBackground();
int red = bg.getRed();
int green = bg.getGreen();
int blue = bg.getBlue();
double brightness = Math.sqrt(red * red * 0.299 + green * green * 0.587 + blue * blue * 0.114);
if (brightness >= 130) {
text_color = Colors.black;
}
gc.setBackground(default_color);
gc.drawRoundRectangle(startX, startY, width, height, textSize.y * 2 / 3, height * 2 / 3);
}
// pattern.dispose();
if (maxIndicatorWidth > width) {
maxIndicatorWidth = width;
}
gc.setForeground(text_color);
GCStringPrinter.printString(gc, textIndicator, new Rectangle(startX, startY + textOffsetY, width, height), true, false, SWT.CENTER);
}
}
if (isCloseable()) {
Image img = selected ? imgCloseSelected : imgClose;
Rectangle closeArea = img.getBounds();
closeArea.x = treeArea.width - closeArea.width - SIDEBAR_SPACING - x1IndicatorOfs;
closeArea.y = itemBounds.y + (itemBounds.height - closeArea.height) / 2;
x1IndicatorOfs += closeArea.width + SIDEBAR_SPACING;
// gc.setBackground(treeItem.getBackground());
// gc.fillRectangle(closeArea);
gc.drawImage(img, closeArea.x, closeArea.y);
treeItem.setData("closeArea", closeArea);
}
MdiEntryVitalityImage[] vitalityImages = getVitalityImages();
for (int i = 0; i < vitalityImages.length; i++) {
SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
if (vitalityImage == null || !vitalityImage.isVisible() || vitalityImage.getAlignment() != SWT.RIGHT) {
continue;
}
vitalityImage.switchSuffix(selected ? "-selected" : "");
Image image = vitalityImage.getImage();
if (image != null && !image.isDisposed()) {
Rectangle bounds = image.getBounds();
bounds.x = treeArea.width - bounds.width - SIDEBAR_SPACING - x1IndicatorOfs;
bounds.y = itemBounds.y + (itemBounds.height - bounds.height) / 2;
x1IndicatorOfs += bounds.width + SIDEBAR_SPACING;
gc.drawImage(image, bounds.x, bounds.y);
// setHitArea needs it relative to entry
bounds.y -= itemBounds.y;
vitalityImage.setHitArea(bounds);
}
}
boolean greyScale = false;
if (viewTitleInfo != null) {
Object active_state = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_ACTIVE_STATE);
if (active_state instanceof Long) {
greyScale = (Long) active_state == 2;
}
}
String suffix = selected ? "-selected" : null;
Image imageLeft = getImageLeft(suffix);
if (imageLeft == null && selected) {
releaseImageLeft(suffix);
suffix = null;
imageLeft = getImageLeft(null);
}
if (imageLeft != null) {
Rectangle clipping = gc.getClipping();
Utils.setClipping(gc, new Rectangle(x0IndicatorOfs, itemBounds.y, IMAGELEFT_SIZE, itemBounds.height));
if (greyScale) {
greyScale = false;
String imageLeftID = getImageLeftID();
if (imageLeftID != null) {
Image grey = ImageLoader.getInstance().getImage(imageLeftID + "-gray");
if (grey != null) {
imageLeft = grey;
gc.setAlpha(160);
greyScale = true;
}
}
}
Rectangle bounds = imageLeft.getBounds();
int w = bounds.width;
int h = bounds.height;
if (w > IMAGELEFT_SIZE) {
float pct = IMAGELEFT_SIZE / (float) w;
w = IMAGELEFT_SIZE;
h *= pct;
}
int x = x0IndicatorOfs + ((IMAGELEFT_SIZE - w) / 2);
int y = itemBounds.y + ((itemBounds.height - h) / 2);
gc.setAdvanced(true);
gc.setInterpolation(SWT.HIGH);
gc.drawImage(imageLeft, 0, 0, bounds.width, bounds.height, x, y, w, h);
if (greyScale) {
String imageLeftID = getImageLeftID();
gc.setAlpha(255);
ImageLoader.getInstance().releaseImage(imageLeftID + "-gray");
}
releaseImageLeft(suffix);
Utils.setClipping(gc, clipping);
// 0, 0, bounds.width, bounds.height,
// x0IndicatorOfs, itemBounds.y
// + ((itemBounds.height - IMAGELEFT_SIZE) / 2), IMAGELEFT_SIZE,
// IMAGELEFT_SIZE);
x0IndicatorOfs += IMAGELEFT_SIZE + IMAGELEFT_GAP;
releaseImageLeft(suffix);
} else if (ALWAYS_IMAGE_GAP) {
if (isSelectable()) {
x0IndicatorOfs += IMAGELEFT_SIZE + IMAGELEFT_GAP;
}
} else {
if (treeItem.getParentItem() != null) {
x0IndicatorOfs += 30 - 18;
}
}
// Main Text
// //////////
Rectangle clipping = new Rectangle(x0IndicatorOfs, itemBounds.y, treeArea.width - x1IndicatorOfs - SIDEBAR_SPACING - x0IndicatorOfs, itemBounds.height);
if (drawBounds.intersects(clipping)) {
int style = SWT.NONE;
if (!isSelectable()) {
Font headerFont = sidebar.getHeaderFont();
if (headerFont != null && !headerFont.isDisposed()) {
gc.setFont(headerFont);
}
// text = text.toUpperCase();
gc.setForeground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
gc.setAlpha(100);
clipping.x++;
clipping.y++;
// style = SWT.TOP;
GCStringPrinter sp = new GCStringPrinter(gc, text, clipping, true, false, style);
sp.printString();
gc.setAlpha(255);
clipping.x--;
clipping.y--;
gc.setForeground(fgText);
} else {
if (treeItem.getItemCount() > 0 || id.equals(MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD)) {
Font headerFont = sidebar.getHeaderFont();
if (headerFont != null && !headerFont.isDisposed()) {
gc.setFont(headerFont);
}
}
gc.setForeground(fgText);
}
// Utils.setClipping(gc, clipping);
GCStringPrinter sp = new GCStringPrinter(gc, text, clipping, true, false, style);
sp.printString();
clipping.x += sp.getCalculatedSize().x + 5;
// Utils.setClipping(gc, (Rectangle) null);
}
for (int i = 0; i < vitalityImages.length; i++) {
SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
if (!vitalityImage.isVisible() || vitalityImage.getAlignment() != SWT.LEFT) {
continue;
}
vitalityImage.switchSuffix(selected ? "-selected" : "");
Image image = vitalityImage.getImage();
if (image != null && !image.isDisposed()) {
Rectangle bounds = image.getBounds();
bounds.x = clipping.x;
bounds.y = itemBounds.y + (itemBounds.height - bounds.height) / 2;
clipping.x += bounds.width + SIDEBAR_SPACING;
if (clipping.x > (treeArea.width - x1IndicatorOfs)) {
vitalityImage.setHitArea(null);
continue;
}
gc.drawImage(image, bounds.x, bounds.y);
vitalityImage.setHitArea(bounds);
}
}
// on Windows because it doesn't have transparency and looks ugly
if (treeItem.getItemCount() > 0 && !isCollapseDisabled() && !SideBar.USE_NATIVE_EXPANDER) {
gc.setAntialias(SWT.ON);
Color oldBG = gc.getBackground();
gc.setBackground(Colors.getSystemColor(event.display, SWT.COLOR_LIST_FOREGROUND));
// itemBounds.x;
int baseX = 22;
if (treeItem.getExpanded()) {
int xStart = 12;
int arrowSize = 8;
int yStart = itemBounds.height - (itemBounds.height + arrowSize) / 2;
gc.fillPolygon(new int[] { baseX - xStart, itemBounds.y + yStart, baseX - xStart + arrowSize, itemBounds.y + yStart, baseX - xStart + (arrowSize / 2), itemBounds.y + yStart + arrowSize });
} else {
int xStart = 12;
int arrowSize = 8;
int yStart = itemBounds.height - (itemBounds.height + arrowSize) / 2;
gc.fillPolygon(new int[] { baseX - xStart, itemBounds.y + yStart, baseX - xStart + arrowSize, itemBounds.y + yStart + 4, baseX - xStart, itemBounds.y + yStart + 8 });
}
gc.setBackground(oldBG);
Font headerFont = sidebar.getHeaderFont();
if (headerFont != null && !headerFont.isDisposed()) {
gc.setFont(headerFont);
}
}
}
Aggregations