use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class TabbedMDI method creatMDI.
private void creatMDI() {
if (soMain instanceof SWTSkinObjectTabFolder) {
tabFolder = ((SWTSkinObjectTabFolder) soMain).getTabFolder();
} else {
tabFolder = new CTabFolder((Composite) soMain.getControl(), SWT.TOP | SWT.BORDER | SWT.CLOSE);
}
iFolderHeightAdj = tabFolder.computeSize(SWT.DEFAULT, 0).y;
if (isMainMDI) {
paramFancyTabListener = new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
boolean simple = !COConfigurationManager.getBooleanParameter("GUI_SWT_bFancyTab");
tabFolder.setSimple(simple);
}
});
}
};
COConfigurationManager.addAndFireParameterListener("GUI_SWT_bFancyTab", paramFancyTabListener);
tabFolder.setSimple(!COConfigurationManager.getBooleanParameter("GUI_SWT_bFancyTab"));
} else {
tabFolder.setSimple(true);
tabFolder.setMaximizeVisible(maximizeVisible);
tabFolder.setMinimizeVisible(minimizeVisible);
tabFolder.setUnselectedCloseVisible(false);
}
Display display = tabFolder.getDisplay();
float[] hsb = tabFolder.getBackground().getRGB().getHSB();
hsb[2] *= (Constants.isOSX) ? 0.9 : 0.97;
tabFolder.setBackground(ColorCache.getColor(display, hsb));
hsb = tabFolder.getForeground().getRGB().getHSB();
hsb[2] *= (Constants.isOSX) ? 1.1 : 0.03;
tabFolder.setForeground(ColorCache.getColor(display, hsb));
tabFolder.setSelectionBackground(new Color[] { Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND), Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND), Colors.getSystemColor(display, SWT.COLOR_WIDGET_BACKGROUND) }, new int[] { 10, 90 }, true);
tabFolder.setSelectionForeground(Colors.getSystemColor(display, SWT.COLOR_LIST_FOREGROUND));
if (minimumCharacters > 0) {
tabFolder.setMinimumCharacters(minimumCharacters);
}
// XXX TVSWT_Common had SWT.Activate too
tabFolder.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
CTabItem item = (CTabItem) event.item;
TabbedEntry entry = (TabbedEntry) item.getData("TabbedEntry");
if (!isMainMDI && !soMain.isDisposed() && item.getData(KEY_AUTO_CLOSE) == null) {
String id = entry.getViewID();
String key = props_prefix + ".selectedTab";
COConfigurationManager.setParameter(key, id);
}
showEntry(entry);
}
});
tabFolder.addMouseMoveListener(e -> {
MdiEntryVitalityImageSWT vitalityImage = getVitalityImageAtPos(e.x, e.y);
String tooltip = null;
Cursor cursor = null;
if (vitalityImage != null && vitalityImage.isVisible()) {
if (vitalityImage.hasListeners()) {
cursor = e.display.getSystemCursor(SWT.CURSOR_HAND);
}
tooltip = vitalityImage.getToolTip();
}
if (tabFolder.getCursor() != cursor) {
tabFolder.setCursor(cursor);
}
CTabItem item = tabFolder.getItem(new Point(e.x, e.y));
if (item != null && item.getToolTipText() != tooltip) {
item.setToolTipText(tooltip);
}
});
// CTabFolder focuses tab on mouse down before any of our events are fired,
// so we are unable to detect if the user clicked a spot that didn't have
// a vitality image, but does now that the tab is selected
// Remove their listener and add it after ours.
Listener[] mouseDownListeners = tabFolder.getListeners(SWT.MouseDown);
for (Listener mouseDownListener : mouseDownListeners) {
tabFolder.removeListener(SWT.MouseDown, mouseDownListener);
}
Utils.addSafeMouseUpListener(tabFolder, e -> e.widget.setData("downedVI", getVitalityImageAtPos(e.x, e.y)), e -> {
MdiEntryVitalityImageSWT vi = (MdiEntryVitalityImageSWT) e.widget.getData("downedVI");
e.widget.setData("downedVI", null);
if (e.button != 1) {
return;
}
if (vi != null && vi.hasListeners()) {
MdiEntryVitalityImageSWT viUp = getVitalityImageAtPos(e.x, e.y);
if (vi != viUp) {
// 3) Mouse up within tabFolder (up outside tabfolder already eaten)
return;
}
vi.triggerClickedListeners(e.x, e.y);
return;
}
if (tabFolder.getMinimized()) {
restore();
// If the user clicked down on the restore button, and we restore
// before the CTabFolder does, CTabFolder will minimize us again
// There's no way that I know of to determine if the mouse is
// on that button!
// one of these will tell tabFolder to cancel
e.button = 0;
tabFolder.notifyListeners(SWT.MouseExit, null);
}
});
for (Listener mouseDownListener : mouseDownListeners) {
tabFolder.addListener(SWT.MouseDown, mouseDownListener);
}
tabFolder.addListener(SWT.MouseDoubleClick, e -> {
if (!tabFolder.getMinimized() && tabFolder.getMinimizeVisible()) {
minimize();
}
});
tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
@Override
public void minimize(CTabFolderEvent event) {
TabbedMDI.this.minimize();
}
@Override
public void maximize(CTabFolderEvent event) {
if (maximizeListener != null) {
maximizeListener.maximizePressed();
}
}
@Override
public void restore(CTabFolderEvent event_maybe_null) {
TabbedMDI.this.restore();
}
@Override
public void close(CTabFolderEvent event) {
TabbedEntry entry = (TabbedEntry) event.item.getData("TabbedEntry");
UISWTViewBuilderCore builder = entry == null ? null : entry.getEventListenerBuilder();
if (entry != null) {
entry.setUserInitiatedClose();
}
TabbedEntry prev = getPrevious(entry);
if (prev != null) {
showEntry(prev);
}
// the "next" tab would select.
if (props_prefix != null) {
Utils.execSWTThreadLater(0, () -> {
String view_id = entry.getViewID();
String key = props_prefix + ".closedtabs";
Map closedtabs = COConfigurationManager.getMapParameter(key, new HashMap());
if (closedtabs.containsKey(view_id)) {
return;
}
closedtabs.put(view_id, entry.getTitle());
// Set location if there is none.
if (builder != null && builder.getPreferredAfterID() == null) {
MdiEntrySWT[] entries = getEntries();
if (entries.length > 1 && entries[0] == entry) {
builder.setPreferredAfterID("~" + entries[1].getViewID());
} else {
for (int i = 1; i < entries.length; i++) {
MdiEntrySWT e = entries[i];
if (e == entry) {
builder.setPreferredAfterID(entries[i - 1].getViewID());
break;
}
}
}
}
// this will trigger listener which will remove the tab
COConfigurationManager.setParameter(key, closedtabs);
});
}
}
});
if (isMainMDI) {
tabFolder.getDisplay().addFilter(SWT.KeyDown, new Listener() {
@Override
public void handleEvent(Event event) {
if (tabFolder.isDisposed()) {
return;
}
// Another window has control, skip filter
Control focus_control = tabFolder.getDisplay().getFocusControl();
if (focus_control != null && focus_control.getShell() != tabFolder.getShell()) {
return;
}
int key = event.character;
if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
key += 'a' - 1;
// ESC or CTRL+F4 closes current Tab
if (key == SWT.ESC || (event.keyCode == SWT.F4 && event.stateMask == SWT.CTRL)) {
closeEntry(getCurrentEntry(), true);
event.doit = false;
} else if (event.keyCode == SWT.F6 || (event.character == SWT.TAB && (event.stateMask & SWT.CTRL) != 0)) {
// what other OSes do, so the code is here in case we get TAB
if ((event.stateMask & SWT.SHIFT) == 0) {
event.doit = false;
selectNextTab(true);
// Shift+F6 or Ctrl+Shift+Tab selects previous Tab
} else if (event.stateMask == SWT.SHIFT) {
selectNextTab(false);
event.doit = false;
}
} else {
if (focus_control == tabFolder) {
TabbedEntry current = getCurrentEntry();
if (current != null) {
if (current.processAccelerator(event.character, event.stateMask)) {
event.doit = false;
}
}
}
}
}
});
}
tabFolder.getTabHeight();
final Menu menu = new Menu(tabFolder);
tabFolder.setMenu(menu);
MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuilder() {
@Override
public void buildMenu(Menu root_menu, MenuEvent event) {
Point cursorLocation = event.display.getCursorLocation();
Point ptOnControl = tabFolder.toControl(cursorLocation.x, cursorLocation.y);
if (ptOnControl.y > tabFolder.getTabHeight()) {
return;
}
final CTabItem item = tabFolder.getItem(tabFolder.toControl(cursorLocation.x, cursorLocation.y));
if (item == null) {
for (Object id : mapUserClosedTabs.keySet()) {
final String view_id = (String) id;
org.eclipse.swt.widgets.MenuItem mi = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
String title;
Object oTitle = mapUserClosedTabs.get(id);
if (oTitle instanceof String && ((String) oTitle).length() > 0) {
title = (String) oTitle;
} else {
title = MessageText.getString(getViewTitleID(view_id));
}
if (title.contains(".")) {
String temp = MessageText.getString(title);
if (temp != null && !temp.isEmpty()) {
title = temp;
}
}
mi.setText(title);
mi.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String key = props_prefix + ".closedtabs";
Map closedtabs = COConfigurationManager.getMapParameter(key, new HashMap());
if (closedtabs.containsKey(view_id)) {
closedtabs.remove(view_id);
COConfigurationManager.setParameter(key, closedtabs);
}
if (!isMainMDI) {
CTabItem[] items = tabFolder.getItems();
List<String> ids = new ArrayList<>();
for (CTabItem item : items) {
TabbedEntry e = getEntryFromTabItem(item);
if (e != null) {
ids.add(e.getViewID());
}
}
if (!ids.contains(view_id)) {
ids.add(view_id);
}
setPreferredOrder(ids.toArray(new String[0]));
String key2 = props_prefix + ".tabOrder";
COConfigurationManager.setParameter(key2, ids);
}
showEntryByID(view_id);
}
});
}
if (!mapUserClosedTabs.isEmpty()) {
new org.eclipse.swt.widgets.MenuItem(menu, SWT.SEPARATOR);
}
org.eclipse.swt.widgets.MenuItem miReset = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
miReset.setText(MessageText.getString("menu.reset.tabs"));
miReset.addListener(SWT.Selection, (ev) -> {
mapUserClosedTabs.clear();
String key = props_prefix + ".closedtabs";
COConfigurationManager.setParameter(key, mapUserClosedTabs);
setPreferredOrder(new String[0]);
String key2 = props_prefix + ".tabOrder";
COConfigurationManager.setParameter(key2, new ArrayList<>());
buildTabs();
});
new org.eclipse.swt.widgets.MenuItem(menu, SWT.SEPARATOR);
}
TabbedEntry entry = null;
if (item != null) {
entry = getEntryFromTabItem(item);
showEntry(entry);
}
fillMenu(menu, entry, props_prefix);
}
});
if (SWT.getVersion() > 3600) {
TabbedMDI_Ren.setupTabFolderRenderer(this, tabFolder);
}
if (minimizeVisible) {
boolean toMinimize = ConfigurationManager.getInstance().getBooleanParameter(props_prefix + ".subViews.minimized");
setMinimized(toMinimize);
}
if (!isMainMDI) {
addDragDropListeners();
}
// Create views registered to this tab
buildTabs();
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class TabbedMDI method buildTabs.
private void buildTabs() {
CTabItem[] items = tabFolder.getItems();
for (CTabItem item : items) {
item.setData(KEY_AUTO_CLOSE, true);
}
for (CTabItem item : items) {
item.dispose();
}
ViewManagerSWT vm = ViewManagerSWT.getInstance();
List<UISWTViewBuilderCore> builders = vm.getBuilders(getViewID(), getDataSourceType());
for (UISWTViewBuilderCore builder : builders) {
try {
createEntry(builder, true);
} catch (Exception ignore) {
}
}
if (!isMainMDI) {
Utils.execSWTThreadLater(0, () -> {
String key = props_prefix + ".selectedTab";
String id = COConfigurationManager.getStringParameter(key, null);
if (id != null) {
int index = indexOf(id);
if (index != -1) {
tabFolder.setSelection(index);
return;
}
}
if (tabFolder.getItemCount() > 0) {
tabFolder.setSelection(0);
}
});
}
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class MyTorrentsSuperView method createTorrentView.
/**
* Returns an instance of <code>MyTorrentsView</code>
* Subclasses my override to return a different instance of MyTorrentsView
* @param _core
* @param isSeedingView
* @param columns
* @param c
* @return
*/
protected MyTorrentsView createTorrentView(Core _core, String tableID, boolean isSeedingView, TableColumnCore[] columns, Composite c) {
boolean split_horizontally = SPLIT_MODE == 0 || SPLIT_MODE == 2;
boolean switch_kids = SPLIT_MODE == 2 || SPLIT_MODE == 3;
boolean support_tabs;
if (split_horizontally) {
if (switch_kids) {
support_tabs = !isSeedingView;
} else {
support_tabs = isSeedingView;
}
} else {
support_tabs = true;
}
MyTorrentsView view = new MyTorrentsView(_core, tableID, isSeedingView, columns, filterBox, cCats, support_tabs);
try {
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(tableID, null, view).setInitialDatasource(ds);
UISWTViewImpl swtView = new UISWTViewImpl(builder, true);
swtView.setDestroyOnDeactivate(false);
swtView.setDelayInitializeToFirstActivate(false);
swtView.initialize(c);
} catch (Exception e) {
Debug.out(e);
}
c.layout();
return view;
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class TrackerView method registerPluginViews.
private static void registerPluginViews() {
ViewManagerSWT vm = ViewManagerSWT.getInstance();
if (vm.areCoreViewsRegistered(PLUGIN_DS_TYPE)) {
return;
}
vm.registerView(PLUGIN_DS_TYPE, new UISWTViewBuilderCore("ScrapeInfoView", null, ScrapeInfoView.class));
vm.setCoreViewsRegistered(PLUGIN_DS_TYPE);
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class ViewManagerSWT method dispose.
public void dispose(PluginInterface pi) {
List<UISWTViewBuilderCore> listBuildersToDispose = new ArrayList<>();
synchronized (mapDataSourceTypeToBuilder) {
Collection<Map<String, UISWTViewBuilderCore>> values = mapDataSourceTypeToBuilder.values();
for (Map<String, UISWTViewBuilderCore> value : values) {
for (Iterator<String> iterator = value.keySet().iterator(); iterator.hasNext(); ) {
String key = iterator.next();
UISWTViewBuilderCore builder = value.get(key);
if (builder != null && builder.getPluginInterface() == pi) {
listBuildersToDispose.add(builder);
iterator.remove();
}
}
}
}
for (UISWTViewBuilderCore builder : listBuildersToDispose) {
builder.dispose();
}
}
Aggregations