use of com.biglybt.ui.swt.mdi.BaseMDI in project BiglyBT by BiglySoftware.
the class MainWindowImpl method createWindow.
/**
* @param uiInitializer
*
* called in both delayedCore and !delayedCore
*/
private void createWindow(IUIIntializer uiInitializer) {
// System.out.println("MainWindow: createWindow)");
long startTime = SystemTime.getCurrentTime();
UIFunctionsSWT existing_uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
uiFunctions = new UIFunctionsImpl(this);
UIFunctionsManager.setUIFunctions(uiFunctions);
Utils.disposeComposite(shell);
increaseProgress(uiInitializer, "splash.initializeGui");
System.out.println("UIFunctions/ImageLoad took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
shell = existing_uif == null ? new Shell(Utils.getDisplay(), SWT.SHELL_TRIM) : existing_uif.getMainShell();
if (Constants.isWindows) {
try {
Class<?> ehancerClass = Class.forName("com.biglybt.ui.swt.win32.Win32UIEnhancer");
Method method = ehancerClass.getMethod("initMainShell", Shell.class);
method.invoke(null, shell);
} catch (Exception e) {
Debug.outNoStack(Debug.getCompressedStackTrace(e, 0, 30), true);
}
}
try {
shell.setData("class", this);
shell.setText(UIFunctions.MAIN_WINDOW_NAME);
Utils.setShellIcon(shell);
Utils.linkShellMetricsToConfig(shell, "window");
// Shell activeShell = display.getActiveShell();
// shell.setVisible(true);
// shell.moveBelow(activeShell);
System.out.println("new shell took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
increaseProgress(uiInitializer, "v3.splash.initSkin");
skin = SWTSkinFactory.getInstance();
if (Utils.isAZ2UI()) {
SWTSkinProperties skinProperties = skin.getSkinProperties();
String skinPath = SkinPropertiesImpl.PATH_SKIN_DEFS + "skin3_classic";
ResourceBundle rb = ResourceBundle.getBundle(skinPath);
skinProperties.addResourceBundle(rb, skinPath);
}
/*
* KN: passing the skin to the uifunctions so it can be used by UIFunctionsSWT.createMenu()
*/
uiFunctions.setSkin(skin);
System.out.println("new shell setup took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
initSkinListeners();
increaseProgress(uiInitializer, "v3.splash.initSkin");
// 0ms
// System.out.println("skinlisteners init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
String startID = Utils.isAZ2UI() ? "classic.shell" : "main.shell";
skin.initialize(shell, startID, uiInitializer);
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("skin init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
menu = uiFunctions.createMainMenu(shell);
shell.setData("MainMenu", menu);
System.out.println("MainMenu init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
increaseProgress(uiInitializer, "v3.splash.initSkin");
skin.layout();
try {
DragDropUtils.createTorrentDropTarget(shell, false);
} catch (Throwable e) {
Logger.log(new LogEvent(LOGID, "Drag and Drop not available", e));
}
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (configIconBarEnabledListener != null) {
COConfigurationManager.removeParameterListener("IconBar.enabled", configIconBarEnabledListener);
}
if (configShowStatusInTitleListener != null) {
COConfigurationManager.removeParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
}
if (configShowDLBasketListener != null) {
COConfigurationManager.removeParameterListener("Show Download Basket", configShowDLBasketListener);
}
if (configMonitorClipboardListener != null) {
COConfigurationManager.removeParameterListener("Monitor Clipboard For Torrents", configMonitorClipboardListener);
}
if (gmListener != null) {
GlobalManager gm = core.getGlobalManager();
if (gm != null) {
gm.removeListener(gmListener);
}
gmListener = null;
}
if (uiFunctions != null) {
uiFunctions.dispose();
}
if (navigationListener != null) {
NavigationHelper.removeListener(navigationListener);
navigationListener = null;
}
StimulusRPC.unhookListeners();
UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
skinnableManagerSWT.removeSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
// comment out: shell can dispose without us wanting core to be..
// dispose(false, false);
}
});
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent event) {
if (disposedOrDisposing) {
return;
}
if (COConfigurationManager.getBooleanParameter("Close To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
minimizeToTray(event);
} else {
dispose(false);
// don't allow shell to close at this point, the disposal code
event.doit = false;
// will close it when ready to
}
}
@Override
public void shellActivated(ShellEvent e) {
Shell shellAppModal = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
if (shellAppModal != null) {
shellAppModal.forceActive();
} else {
shell.forceActive();
}
}
@Override
public void shellIconified(ShellEvent event) {
if (disposedOrDisposing) {
return;
}
if (COConfigurationManager.getBooleanParameter("Minimize To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
minimizeToTray(event);
}
}
@Override
public void shellDeiconified(ShellEvent e) {
if (Constants.isOSX && COConfigurationManager.getBooleanParameter("Password enabled")) {
shell.setVisible(false);
if (PasswordWindow.showPasswordWindow(Utils.getDisplay())) {
shell.setVisible(true);
}
}
}
});
Utils.getDisplay().addFilter(SWT.KeyDown, new Listener() {
@Override
public void handleEvent(Event event) {
// Another window has control, skip filter
Control focus_control = event.display.getFocusControl();
if (focus_control != null && focus_control.getShell() != shell)
return;
int key = event.character;
if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
key += 'a' - 1;
if (key == 'l' && (event.stateMask & SWT.MOD1) != 0) {
// Ctrl-L: Open URL
if (core == null) {
return;
}
GlobalManager gm = core.getGlobalManager();
if (gm != null) {
UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
event.doit = false;
}
} else if (key == 'd' && (event.stateMask & SWT.MOD1) != 0) {
// dump
if (Constants.isCVSVersion()) {
Utils.dump(shell);
}
} else if (key == 'f' && (event.stateMask & (SWT.MOD1 + SWT.SHIFT)) == SWT.MOD1 + SWT.SHIFT) {
shell.setFullScreen(!shell.getFullScreen());
} else if (event.keyCode == SWT.F1) {
Utils.launch(Constants.URL_WIKI);
}
}
});
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("pre skin widgets init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
if (core != null) {
StimulusRPC.hookListeners(core, this);
}
increaseProgress(uiInitializer, "v3.splash.initSkin");
// 0ms
// System.out.println("hooks init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
BaseMDI mdi = initMDI();
System.out.println("skin widgets (1/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
initWidgets2(mdi);
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("skin widgets (2/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
System.out.println("pre SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
startTime = SystemTime.getCurrentTime();
TableColumnCreatorV3.initCoreColumns();
System.out.println("Init Core Columns took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
startTime = SystemTime.getCurrentTime();
// attach the UI to plugins
// Must be done before initializing views, since plugins may register
// table columns and other objects
uiSWTInstanceImpl = new UISWTInstanceImpl();
uiSWTInstanceImpl.init(uiInitializer);
System.out.println("SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "splash.initializeGui");
startTime = SystemTime.getCurrentTime();
} catch (Throwable t) {
Debug.out(t);
} finally {
String configID = SkinConstants.VIEWID_PLUGINBAR + ".visible";
if (!ConfigurationDefaults.getInstance().doesParameterDefaultExist(configID)) {
COConfigurationManager.setBooleanDefault(configID, true);
}
setVisible(WINDOW_ELEMENT_TOPBAR, COConfigurationManager.getBooleanParameter(configID) && COConfigurationManager.getIntParameter("User Mode") > 1);
setVisible(WINDOW_ELEMENT_RIGHTBAR, COConfigurationManager.getBooleanParameter(SkinConstants.VIEWID_RIGHTBAR + ".visible"));
setVisible(WINDOW_ELEMENT_TOOLBAR, COConfigurationManager.getBooleanParameter("IconBar.enabled"));
shell.layout(true, true);
System.out.println("shell.layout took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
showMainWindow();
// ================
increaseProgress(uiInitializer, "splash.initializeGui");
System.out.println("shell.open took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
processStartupDMS();
System.out.println("processStartupDMS took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
if (core != null) {
postPluginSetup(core);
}
System.out.println("postPluginSetup init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
navigationListener = new navigationListener() {
@Override
public void processCommand(final int type, final String[] args) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (type == NavigationHelper.COMMAND_SWITCH_TO_TAB) {
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi == null) {
return;
}
mdi.showEntryByID(args[0]);
if (uif != null) {
uif.bringToFront();
}
} else if (type == NavigationHelper.COMMAND_CONDITION_CHECK) {
}
}
});
}
};
NavigationHelper.addListener(navigationListener);
if (!Constants.isOSX) {
configShowStatusInTitleListener = new ParameterListener() {
private TimerEventPeriodic timer;
private String old_text;
private String my_last_text;
@Override
public void parameterChanged(final String name) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
boolean enable = COConfigurationManager.getBooleanParameter(name);
if (enable) {
if (timer == null) {
timer = SimpleTimer.addPeriodicEvent("window.title.updater", 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (shell.isDisposed()) {
return;
}
String current_txt = shell.getText();
if (current_txt != null && !current_txt.equals(my_last_text)) {
old_text = current_txt;
}
String txt = getCurrentTitleText();
if (txt != null) {
if (!txt.equals(current_txt)) {
shell.setText(txt);
}
my_last_text = txt;
}
}
});
}
});
}
} else {
if (timer != null) {
timer.cancel();
timer = null;
}
if (old_text != null && !shell.isDisposed()) {
shell.setText(old_text);
}
}
}
});
}
};
COConfigurationManager.addAndFireParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
}
}
}
use of com.biglybt.ui.swt.mdi.BaseMDI in project BiglyBT by BiglySoftware.
the class MainWindowImpl method initMDI.
private BaseMDI initMDI() {
SWTSkinObject skinObject = skin.getSkinObject(SkinConstants.VIEWID_MDI);
if (null != skinObject) {
BaseMDI mdi = Utils.isAZ2UI() ? new TabbedMDI() : new SideBar();
mdi.buildMDI(skinObject);
MainMDISetup.setupSideBar(mdi);
return (mdi);
}
return (null);
}
use of com.biglybt.ui.swt.mdi.BaseMDI in project BiglyBT by BiglySoftware.
the class FileInfoView method eventOccurred.
@Override
public boolean eventOccurred(UISWTViewEvent event) {
switch(event.getType()) {
case UISWTViewEvent.TYPE_CREATE:
swtView = (UISWTView) event.getData();
if (swtView instanceof MdiEntry) {
MultipleDocumentInterface mdi = ((MdiEntry) swtView).getMDI();
// We should always have an MDI, since this view goes under the "Files" tab
if (mdi instanceof BaseMDI) {
// Is our Files tab also in an MDI (MyTorrents and Torrent Details View)?
UISWTView parentView = ((BaseMDI) mdi).getParentView();
if (!(parentView instanceof MdiEntry)) {
return false;
}
}
}
swtView.setTitle(getFullTitle());
break;
case UISWTViewEvent.TYPE_DESTROY:
delete();
break;
case UISWTViewEvent.TYPE_INITIALIZE:
initialize((Composite) event.getData());
break;
case UISWTViewEvent.TYPE_LANGUAGEUPDATE:
Messages.updateLanguageForControl(getComposite());
swtView.setTitle(getFullTitle());
break;
case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
dataSourceChanged(event.getData());
break;
case UISWTViewEvent.TYPE_FOCUSGAINED:
refreshInfoCanvas();
break;
case UISWTViewEvent.TYPE_REFRESH:
refresh();
break;
}
return true;
}
use of com.biglybt.ui.swt.mdi.BaseMDI in project BiglyBT by BiglySoftware.
the class QuickLinksView method init.
public static void init(BaseMDI mdi, SWTSkinObject so) {
skinObject = so;
Composite parent = (Composite) so.getControl();
GridLayout layout = new GridLayout();
layout.marginWidth = layout.marginHeight = layout.marginBottom = layout.marginTop = 1;
parent.setLayout(layout);
toolBar = new ToolBar(parent, SWT.FLAT);
toolBar.addListener(SWT.Dispose, ev -> {
toolBar = null;
qlItems.clear();
});
GridData gridData = new GridData(GridData.FILL_BOTH);
toolBar.setLayoutData(gridData);
toolBar.addListener(SWT.MenuDetect, ev -> {
Menu menu = new Menu(toolBar);
toolBar.setMenu(menu);
if (toolBar.getItemCount() > 0) {
menu.addListener(SWT.Show, (e) -> {
Point loc = toolBar.toControl(toolBar.getDisplay().getCursorLocation());
toolBar.setData("current_qli", toolBar.getItem(loc));
});
Menu popMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem popItem = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(popItem, "label.pop.out");
popItem.setMenu(popMenu);
MenuItem itemPopIndependent = new MenuItem(popMenu, SWT.PUSH);
Messages.setLanguageText(itemPopIndependent, "menu.independent");
MenuItem itemPopOnTop = new MenuItem(popMenu, SWT.PUSH);
Messages.setLanguageText(itemPopOnTop, "menu.on.top");
Listener popListener = (e) -> {
ToolItem ti = (ToolItem) toolBar.getData("current_qli");
if (ti != null) {
MenuItem mi = (MenuItem) e.widget;
boolean onTop = mi == itemPopOnTop;
QuickLinkItem qli = (QuickLinkItem) ti.getData("qli");
if (qli != null) {
qli.popOut(mdi, onTop);
}
}
};
itemPopIndependent.addListener(SWT.Selection, popListener);
itemPopOnTop.addListener(SWT.Selection, popListener);
MenuItem itemRemove = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRemove, "Button.remove");
Utils.setMenuItemImage(itemRemove, "delete");
itemRemove.addListener(SWT.Selection, (e) -> {
ToolItem ti = (ToolItem) toolBar.getData("current_qli");
if (ti != null) {
QuickLinkItem qli = (QuickLinkItem) ti.getData("qli");
if (qli != null) {
synchronized (qlItems) {
qlItems.remove(qli);
saveConfig();
}
}
ti.dispose();
if (toolBar.getItemCount() == 0) {
setVisible(false);
} else {
relayout();
}
}
});
new MenuItem(menu, SWT.SEPARATOR);
}
MenuItem itemReset = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemReset, "Button.reset");
itemReset.addListener(SWT.Selection, (e) -> {
synchronized (qlItems) {
qlItems.clear();
COConfigurationManager.removeParameter(CONFIG_KEY);
for (ToolItem ti : toolBar.getItems()) {
ti.dispose();
}
addDefaults(mdi);
}
relayout();
});
MenuItem itemHide = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemHide, "Button.bar.hide");
itemHide.addListener(SWT.Selection, (e) -> {
setVisible(false);
});
});
toolBar.addListener(SWT.MouseDoubleClick, ev -> {
if (toolBar.getItemCount() > 0) {
Point loc = toolBar.toControl(toolBar.getDisplay().getCursorLocation());
ToolItem ti = toolBar.getItem(loc);
if (ti != null) {
QuickLinkItem qli = (QuickLinkItem) ti.getData("qli");
if (qli != null) {
qli.popOut(mdi, true);
}
}
}
});
synchronized (qlItems) {
Map<String, Object> config = COConfigurationManager.getMapParameter(CONFIG_KEY, null);
if (config == null) {
addDefaults(mdi);
} else {
config = BDecoder.decodeStrings(BEncoder.cloneMap(config));
try {
List<Map<String, Object>> items = (List<Map<String, Object>>) config.get("items");
if (items != null) {
for (Map<String, Object> item : items) {
addItem(mdi, toolBar, item);
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
if (!COConfigurationManager.getBooleanParameter(SkinConstants.VIEWID_QUICK_LINKS + ".visible", true)) {
setVisible(false);
}
}
Aggregations