use of com.biglybt.ui.swt.skin.SWTSkinObject in project BiglyBT by BiglySoftware.
the class ToolBarView method createItemSO.
private void createItemSO(Map<UIToolBarItem, ToolBarItemSO> newMap, ToolBarItem item, String templatePrefix, int position) {
ToolBarItemSO existingItemSO = newMap.get(item);
if (existingItemSO != null) {
SWTSkinObject so = existingItemSO.getSO();
if (so != null) {
so.dispose();
}
}
String templateID = templatePrefix;
if (position == SWT.RIGHT) {
templateID += ".right";
} else if (position == SWT.LEFT) {
templateID += ".left";
} else if (position == SWT.SINGLE) {
templateID += ".lr";
}
Control attachToControl = getLastControl(item.getGroupID());
String id = "toolbar:" + item.getID();
SWTSkinObject so = skin.createSkinObject(id, templateID, getGroupSO(item.getGroupID()));
if (so != null) {
ToolBarItemSO itemSO;
itemSO = new ToolBarItemSO((UIToolBarItemImpl) item, so);
if (attachToControl != null) {
FormData fd = (FormData) so.getControl().getLayoutData();
fd.left = new FormAttachment(attachToControl);
}
initSO(newMap, so, itemSO);
if (initComplete) {
Utils.relayout(so.getControl().getParent());
}
}
}
use of com.biglybt.ui.swt.skin.SWTSkinObject in project BiglyBT by BiglySoftware.
the class SBC_GenericBrowsePage method skinObjectInitialShow.
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
Object creationParams = skinObject.getData("CreationParams");
browserSkinObject = SWTSkinUtils.findBrowserSO(soMain);
final MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi != null) {
entry = mdi.getEntryBySkinView(this);
if (entry != null) {
vitalityImage = entry.addVitalityImage("image.sidebar.vitality.dots");
vitalityImage.setVisible(false);
mdi.addListener(new MdiListener() {
long lastSelect = 0;
@Override
public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
if (entry == newEntry) {
if (entry == oldEntry) {
if (lastSelect < SystemTime.getOffsetTime(-1000)) {
if (browserSkinObject != null) {
browserSkinObject.restart();
}
}
} else {
lastSelect = SystemTime.getCurrentTime();
}
}
}
@Override
public void mdiDisposed(MultipleDocumentInterface mdi) {
}
});
}
}
browserSkinObject.addListener(new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == EVENT_SHOW) {
browserSkinObject.removeListener(this);
browserSkinObject.addListener(new BrowserContext.loadingListener() {
@Override
public void browserLoadingChanged(boolean loading, String url) {
if (vitalityImage != null) {
vitalityImage.setVisible(loading);
}
}
});
} else if (eventType == EVENT_DATASOURCE_CHANGED) {
if (params instanceof String) {
browserSkinObject.setURL((String) params);
}
}
return null;
}
});
openURL();
return null;
}
use of com.biglybt.ui.swt.skin.SWTSkinObject in project BiglyBT by BiglySoftware.
the class SkinViewManager method remove.
public static void remove(SkinView skinView) {
if (skinView == null) {
return;
}
mon_skinViews.enter();
try {
List<SkinView> list = mapSkinViews.get(skinView.getClass());
if (list != null) {
list.remove(skinView);
if (list.isEmpty()) {
mapSkinViews.remove(skinView.getClass());
}
}
} finally {
mon_skinViews.exit();
}
SWTSkinObject mainSkinObject = skinView.getMainSkinObject();
if (mainSkinObject != null) {
skinIDs.remove(mainSkinObject.getSkinObjectID());
skinViewIDs.remove(mainSkinObject.getViewID());
}
}
use of com.biglybt.ui.swt.skin.SWTSkinObject in project BiglyBT by BiglySoftware.
the class ToolBarView method bulkSetupItems.
private void bulkSetupItems(Map<UIToolBarItem, ToolBarItemSO> newMap, String groupID, String templatePrefix) {
String[] idsByGroupAll = tbm.getToolBarIDsByGroup(groupID);
SWTSkinObjectContainer groupSO = peekGroupSO(groupID);
if (groupSO != null) {
SWTSkinObject[] children = groupSO.getChildren();
for (SWTSkinObject so : children) {
so.dispose();
}
}
List<String> idsByGroup = new ArrayList<>();
for (String id : idsByGroupAll) {
if (visible_items.contains(id)) {
idsByGroup.add(id);
}
}
int size = idsByGroup.size();
if (size > 0) {
// only peeked above, create now as group is required
groupSO = getGroupSO(groupID);
for (int i = 0; i < size; i++) {
String itemID = idsByGroup.get(i);
UIToolBarItem item = tbm.getToolBarItem(itemID);
if (item instanceof ToolBarItem) {
int position = 0;
if (size == 1) {
position = SWT.SINGLE;
} else if (i == 0) {
position = SWT.LEFT;
} else if (i == size - 1) {
addSeperator(groupID);
position = SWT.RIGHT;
} else {
addSeperator(groupID);
}
createItemSO(newMap, (ToolBarItem) item, templatePrefix, position);
}
}
addNonToolBar("toolbar.area.sitem.left2", groupID);
}
}
use of com.biglybt.ui.swt.skin.SWTSkinObject in project BiglyBT by BiglySoftware.
the class TopBarView method buildTopBarViews.
/**
* @param skinObject
*
* @since 3.0.1.1
*/
public void buildTopBarViews() {
SWTSkinObject skinObject = skin.getSkinObject("topbar-plugins");
if (skinObject == null) {
return;
}
try {
cPluginArea = (Composite) skinObject.getControl();
final UIUpdatable updatable = new UIUpdatable() {
@Override
public void updateUI() {
Object[] views = topbarViews.toArray();
for (int i = 0; i < views.length; i++) {
try {
UISWTViewCore view = (UISWTViewCore) views[i];
if (view.getComposite().isVisible()) {
view.triggerEvent(UISWTViewEvent.TYPE_REFRESH, null);
}
} catch (Exception e) {
Debug.out(e);
}
}
}
@Override
public String getUpdateUIName() {
return "TopBar";
}
};
try {
UIUpdater updater = UIUpdaterSWT.getInstance();
if (updater != null) {
updater.addUpdater(updatable);
}
} catch (Exception e) {
Debug.out(e);
}
skinObject.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
try {
UIUpdater updater = UIUpdaterSWT.getInstance();
if (updater != null) {
updater.removeUpdater(updatable);
}
} catch (Exception ex) {
Debug.out(ex);
}
Object[] views = topbarViews.toArray();
topbarViews.clear();
for (int i = 0; i < views.length; i++) {
UISWTViewCore view = (UISWTViewCore) views[i];
if (view != null) {
view.triggerEvent(UISWTViewEvent.TYPE_DESTROY, null);
}
}
}
});
/*
SWTSkinObject soPrev = skin.getSkinObject("topbar-plugin-prev");
if (soPrev != null) {
SWTSkinButtonUtility btnPrev = new SWTSkinButtonUtility(soPrev);
btnPrev.addSelectionListener(new ButtonListenerAdapter() {
public void pressed(SWTSkinButtonUtility buttonUtility,
SWTSkinObject skinObject, int stateMask) {
//System.out.println("prev click " + activeTopBar + " ; "
// + topbarViews.size());
if (activeTopBar == null || topbarViews.size() <= 1) {
return;
}
int i = topbarViews.indexOf(activeTopBar) - 1;
if (i < 0) {
i = topbarViews.size() - 1;
}
activateTopBar((UISWTViewCore) topbarViews.get(i));
}
});
}
SWTSkinObject soNext = skin.getSkinObject("topbar-plugin-next");
if (soNext != null) {
SWTSkinButtonUtility btnNext = new SWTSkinButtonUtility(soNext);
btnNext.addSelectionListener(new ButtonListenerAdapter() {
public void pressed(SWTSkinButtonUtility buttonUtility,
SWTSkinObject skinObject, int stateMask) {
//System.out.println("next click");
if (activeTopBar == null || topbarViews.size() <= 1) {
return;
}
int i = topbarViews.indexOf(activeTopBar) + 1;
if (i >= topbarViews.size()) {
i = 0;
}
activateTopBar((UISWTViewCore) topbarViews.get(i));
}
});
}
SWTSkinObject soTitle = skin.getSkinObject("topbar-plugin-title");
if (soTitle != null) {
final Composite cTitle = (Composite) soTitle.getControl();
cTitle.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setAdvanced(true);
//Font font = new Font(e.gc.getDevice(), "Sans", 8, SWT.NORMAL);
//e.gc.setFont(font);
if (e.gc.getAdvanced() && activeTopBar != null) {
try {
e.gc.setTextAntialias(SWT.ON);
} catch (Exception ex) {
// Ignore ERROR_NO_GRAPHICS_LIBRARY error or any others
}
try {
Transform transform = new Transform(e.gc.getDevice());
transform.rotate(270);
e.gc.setTransform(transform);
String s = activeTopBar.getFullTitle();
Point size = e.gc.textExtent(s);
e.gc.drawText(s, -size.x, 0, true);
//e.gc.drawText(s, 0,0, true);
transform.dispose();
} catch (Exception ex) {
// setTransform can trhow a ERROR_NO_GRAPHICS_LIBRARY error
// no use trying to draw.. it would look weird
}
//font.dispose();
}
}
});
}
*/
SWTSkinObject soList = skin.getSkinObject("topbar-plugin-list");
if (soList != null) {
final Composite cList = (Composite) soList.getControl();
listPlugins = new org.eclipse.swt.widgets.List(cList, SWT.V_SCROLL);
listPlugins.setLayoutData(Utils.getFilledFormData());
listPlugins.setBackground(cList.getBackground());
listPlugins.setForeground(cList.getForeground());
listPlugins.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
String[] selection = listPlugins.getSelection();
if (selection.length > 0) {
String name = selection[0];
for (UISWTViewCore view : topbarViews) {
if (getViewName(view).equals(name)) {
activateTopBar(view);
}
}
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
Messages.setLanguageTooltip(listPlugins, "label.right.click.for.options.tooltip");
final Menu menu = new Menu(listPlugins);
listPlugins.setMenu(menu);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
for (MenuItem mi : menu.getItems()) {
mi.dispose();
}
for (final UISWTViewCore view : topbarViews) {
final String name = getViewName(view);
final MenuItem mi = new MenuItem(menu, SWT.CHECK);
mi.setText(name);
boolean enabled = isEnabled(view);
mi.setSelection(enabled);
mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean enabled = mi.getSelection();
setEnabled(view, enabled);
if (enabled) {
activateTopBar(view);
} else {
listPlugins.remove(name);
activateTopBar(null);
}
Utils.relayout(cPluginArea);
}
});
}
}
@Override
public void menuHidden(MenuEvent e) {
}
});
}
skinObject = skin.getSkinObject(SkinConstants.VIEWID_PLUGINBAR);
if (skinObject != null) {
Listener l = new Listener() {
private int mouseDownAt = 0;
@Override
public void handleEvent(Event event) {
Composite c = (Composite) event.widget;
if (event.type == SWT.MouseDown) {
Rectangle clientArea = c.getClientArea();
if (event.y > clientArea.height - 10) {
mouseDownAt = event.y;
}
} else if (event.type == SWT.MouseUp && mouseDownAt > 0) {
int diff = event.y - mouseDownAt;
mouseDownAt = 0;
FormData formData = (FormData) c.getLayoutData();
formData.height += diff;
if (formData.height < 50) {
formData.height = 50;
} else {
Rectangle clientArea = c.getShell().getClientArea();
int max = clientArea.height - 350;
if (formData.height > max) {
formData.height = max;
}
}
COConfigurationManager.setParameter("v3.topbar.height", formData.height);
Utils.relayout(c);
} else if (event.type == SWT.MouseMove) {
Rectangle clientArea = c.getClientArea();
boolean draggable = (event.y > clientArea.height - 10);
c.setCursor(draggable ? c.getDisplay().getSystemCursor(SWT.CURSOR_SIZENS) : null);
} else if (event.type == SWT.MouseExit) {
c.setCursor(null);
}
}
};
Control control = skinObject.getControl();
control.addListener(SWT.MouseDown, l);
control.addListener(SWT.MouseUp, l);
control.addListener(SWT.MouseMove, l);
control.addListener(SWT.MouseExit, l);
skinObject.addListener(new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == EVENT_SHOW) {
int h = COConfigurationManager.getIntParameter("v3.topbar.height");
Control control = skinObject.getControl();
FormData formData = (FormData) control.getLayoutData();
formData.height = h;
control.setLayoutData(formData);
Utils.relayout(control);
}
return null;
}
});
}
ViewManagerSWT vi = ViewManagerSWT.getInstance();
if (!vi.areCoreViewsRegistered(VIEW_ID)) {
vi.registerView(VIEW_ID, new UISWTViewBuilderCore("ViewDownSpeedGraph", null, ViewDownSpeedGraph.class));
vi.registerView(VIEW_ID, new UISWTViewBuilderCore("ViewUpSpeedGraph", null, ViewUpSpeedGraph.class));
vi.registerView(VIEW_ID, new UISWTViewBuilderCore("ViewQuickConfig", null, ViewQuickConfig.class));
vi.registerView(VIEW_ID, new UISWTViewBuilderCore("ViewQuickNetInfo", null, ViewQuickNetInfo.class));
vi.registerView(VIEW_ID, new UISWTViewBuilderCore("ViewQuickNotifications", null, ViewQuickNotifications.class));
vi.setCoreViewsRegistered(VIEW_ID);
}
List<UISWTViewBuilderCore> pluginViews = vi.getBuilders(VIEW_ID);
for (UISWTViewBuilderCore builder : pluginViews) {
if (builder == null) {
continue;
}
try {
UISWTViewCore view = new UISWTViewImpl(builder, true);
view.setDestroyOnDeactivate(false);
addTopBarView(view, cPluginArea);
} catch (Throwable e) {
Debug.out(e);
}
}
String active_view_id = COConfigurationManager.getStringParameter("topbar.active.view.id", "");
boolean activated = false;
UISWTViewCore first_enabled = null;
for (UISWTViewCore view : topbarViews) {
if (isEnabled(view)) {
if (first_enabled == null) {
first_enabled = view;
}
if (active_view_id.equals(view.getViewID())) {
activateTopBar(view);
activated = true;
break;
}
}
}
if (!activated && first_enabled != null) {
activateTopBar(first_enabled);
activated = true;
}
if (!activated && topbarViews.size() > 0) {
UISWTViewCore view = topbarViews.get(0);
setEnabled(view, true);
activateTopBar(view);
}
if (skinObject != null) {
skinObject.getControl().getParent().layout(true);
}
} catch (Throwable e) {
Debug.out(e);
}
}
Aggregations