use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.
the class ColumnActivityText method cellMouseTrigger.
// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
String tooltip = null;
boolean invalidateAndRefresh = false;
ActivitiesEntry entry = (ActivitiesEntry) event.cell.getDataSource();
// Rectangle bounds = getDrawBounds((TableCellSWT) event.cell);
Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
String text = entry.getText();
GC gc = new GC(Display.getDefault());
GCStringPrinter sp = null;
try {
sp = setupStringPrinter(gc, (TableCellSWT) event.cell);
} catch (Exception e) {
Debug.out(e);
} finally {
gc.dispose();
}
if (sp != null) {
URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
int newCursor;
if (hitUrl != null) {
String url = hitUrl.url;
boolean ourUrl = UrlFilter.getInstance().urlCanRPC(url) || url.startsWith("/") || url.startsWith("#");
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN && event.button == 1) {
if (!ourUrl) {
if (UrlUtils.isInternalProtocol(url)) {
try {
UIFunctionsManagerSWT.getUIFunctionsSWT().doSearch(url);
} catch (Throwable e) {
Debug.out(e);
}
} else {
Utils.launch(url);
}
} else {
UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uif != null) {
String target = hitUrl.target;
if (target == null) {
target = SkinConstants.VIEWID_BROWSER_BROWSE;
}
uif.viewURL(hitUrl.url, target, "column.activity.text");
return;
}
}
}
newCursor = SWT.CURSOR_HAND;
if (ourUrl) {
try {
tooltip = hitUrl.title == null ? null : URLDecoder.decode(hitUrl.title, "utf-8");
} catch (UnsupportedEncodingException e) {
}
} else {
tooltip = hitUrl.url;
}
} else {
newCursor = SWT.CURSOR_ARROW;
}
int oldCursor = ((TableCellSWT) event.cell).getCursorID();
if (oldCursor != newCursor) {
invalidateAndRefresh = true;
((TableCellSWT) event.cell).setCursorID(newCursor);
}
}
Object o = event.cell.getToolTip();
if ((o == null) || (o instanceof String)) {
String oldTooltip = (String) o;
if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
invalidateAndRefresh = true;
event.cell.setToolTip(tooltip);
}
}
if (invalidateAndRefresh) {
event.cell.invalidate();
((TableCellSWT) event.cell).redraw();
}
}
use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.
the class ShellFactory method createMainShell.
public static Shell createMainShell(int styles) {
Shell parent = null;
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
parent = uiFunctions.getMainShell();
}
if (parent == null) {
return createShell(Utils.getDisplay());
}
return (createShell(parent, styles));
}
use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.
the class MainWindowDelayStub method fixup.
private void fixup(Fixup3 f) {
core_sem.reserve();
checkMainWindow();
UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uif == delayed_uif) {
Debug.out("eh?");
} else {
f.fix(uif);
}
}
use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.
the class MessageSlideShell method create.
private void create(final Display display, final PopupParams popupParams, boolean bSlide) {
// Reset the last read message counter.
firstUnreadMessage = -1;
GridData gridData;
int style = SWT.ON_TOP;
boolean bDisableSliding = COConfigurationManager.getBooleanParameter("GUI_SWT_DisableAlertSliding");
if (bDisableSliding) {
bSlide = false;
style = SWT.NONE;
}
if (DEBUG)
System.out.println("create " + (bSlide ? "SlideIn" : "") + ";" + historyList.indexOf(popupParams) + ";");
idxHistory = historyList.indexOf(popupParams);
// 2 Assertions
if (idxHistory < 0) {
System.err.println("Not in popup history list");
return;
}
if (currentPopupIndex == idxHistory) {
System.err.println("Trying to open already opened!! " + idxHistory);
return;
}
try {
monitor.enter();
currentPopupIndex = idxHistory;
} finally {
monitor.exit();
}
if (DEBUG)
System.out.println("set currIdx = " + idxHistory);
sDetails = popupParams.details;
// Load Images
Image imgIcon = popupParams.iconID <= 0 ? null : display.getSystemImage(popupParams.iconID);
/*
* If forceTimer is true then we always show the counter for auto-closing the shell;
* otherwise proceed to the more fine-grained logic
*/
// if there's a link, or the info is non-information,
// disable timer and mouse watching
bDelayPaused = popupParams.iconID != SWT.ICON_INFORMATION || !bSlide;
// Pause the auto-close delay when mouse is over slidey
// This will be applies to every control
final MouseTrackAdapter mouseAdapter = bDelayPaused ? null : new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
bDelayPaused = true;
}
@Override
public void mouseExit(MouseEvent e) {
bDelayPaused = false;
}
};
// Create shell & widgets
if (bDisableSliding) {
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
Shell mainShell = uiFunctions.getMainShell();
if (mainShell != null) {
shell = new Shell(mainShell, style);
}
}
}
if (shell == null) {
shell = new Shell(display, style);
}
try {
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
} catch (NoSuchMethodError e) {
// Ignore
} catch (NoSuchFieldError e2) {
// ignore
}
Utils.setShellIcon(shell);
if (popupParams.title != null) {
shell.setText(popupParams.title);
}
shellWidth = Utils.adjustPXForDPI(SHELL_DEF_WIDTH);
UISkinnableSWTListener[] listeners = UISkinnableManagerSWT.getInstance().getSkinnableListeners(MessageSlideShell.class.toString());
for (int i = 0; i < listeners.length; i++) {
try {
listeners[i].skinBeforeComponents(shell, this, popupParams.relatedTo);
} catch (Exception e) {
Debug.out(e);
}
}
if (colorFG == null) {
colorFG = Colors.getSystemColor(display, SWT.COLOR_BLACK);
}
FormLayout shellLayout = new FormLayout();
shell.setLayout(shellLayout);
cShell = new Composite(shell, SWT.NULL);
GridLayout layout = new GridLayout(3, false);
cShell.setLayout(layout);
FormData formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
cShell.setLayoutData(formData);
Label lblIcon = new Label(cShell, SWT.NONE);
lblIcon.setImage(imgIcon);
lblIcon.setLayoutData(new GridData());
if (popupParams.title != null) {
Label lblTitle = new Label(cShell, SWT.getVersion() < 3100 ? SWT.NONE : SWT.WRAP);
gridData = new GridData(GridData.FILL_HORIZONTAL);
if (SWT.getVersion() < 3100)
gridData.widthHint = 140;
lblTitle.setLayoutData(gridData);
lblTitle.setForeground(colorFG);
lblTitle.setText(popupParams.title);
FontData[] fontData = lblTitle.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
fontData[0].setHeight((int) (fontData[0].getHeight() * 1.5));
Font boldFont = new Font(display, fontData);
disposeList.add(boldFont);
lblTitle.setFont(boldFont);
}
final Button btnDetails = new Button(cShell, SWT.TOGGLE);
btnDetails.setForeground(colorFG);
Messages.setLanguageText(btnDetails, "label.details");
gridData = new GridData();
btnDetails.setLayoutData(gridData);
btnDetails.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
try {
boolean bShow = btnDetails.getSelection();
if (bShow) {
Shell detailsShell = new Shell(display, SWT.BORDER | SWT.ON_TOP);
Utils.setShellIcon(detailsShell);
detailsShell.setLayout(new FillLayout());
StyledText textDetails = new StyledText(detailsShell, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
textDetails.setBackground(Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND));
textDetails.setForeground(Colors.getSystemColor(display, SWT.COLOR_LIST_FOREGROUND));
textDetails.setWordWrap(true);
textDetails.setText(sDetails);
detailsShell.layout();
Rectangle shellBounds = shell.getBounds();
int detailsWidth = Utils.adjustPXForDPI(DETAILS_WIDTH);
int detailsHeight = Utils.adjustPXForDPI(DETAILS_HEIGHT);
detailsShell.setBounds(shellBounds.x + shellBounds.width - detailsWidth, shellBounds.y - detailsHeight, detailsWidth, detailsHeight);
detailsShell.open();
shell.setData("detailsShell", detailsShell);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Shell detailsShell = (Shell) shell.getData("detailsShell");
if (detailsShell != null && !detailsShell.isDisposed()) {
detailsShell.dispose();
}
}
});
// disable auto-close on opening of details
bDelayPaused = true;
removeMouseTrackListener(shell, mouseAdapter);
} else {
Shell detailsShell = (Shell) shell.getData("detailsShell");
if (detailsShell != null && !detailsShell.isDisposed()) {
detailsShell.dispose();
}
}
} catch (Exception e) {
Logger.log(new LogEvent(LogIDs.GUI, "Mr. Slidey DetailsButton", e));
}
}
});
createLinkLabel(cShell, popupParams);
lblCloseIn = new Label(cShell, SWT.TRAIL);
lblCloseIn.setForeground(colorFG);
// Ensure computeSize computes for 2 lined label
lblCloseIn.setText(" \n ");
gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
gridData.horizontalSpan = 3;
lblCloseIn.setLayoutData(gridData);
final Composite cButtons = new Composite(cShell, SWT.NULL);
GridLayout gridLayout = new GridLayout();
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.verticalSpacing = 0;
if (Constants.isOSX)
gridLayout.horizontalSpacing = 0;
gridLayout.numColumns = (idxHistory > 0) ? 3 : 2;
cButtons.setLayout(gridLayout);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
gridData.horizontalSpan = 3;
cButtons.setLayoutData(gridData);
btnHideAll = new Button(cButtons, SWT.PUSH);
Messages.setLanguageText(btnHideAll, "popup.error.hideall");
btnHideAll.setVisible(false);
btnHideAll.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
// XXX SWT.Selection doesn't work on latest GTK (2.8.17) & SWT3.2 for ON_TOP
btnHideAll.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
cButtons.setEnabled(false);
shell.dispose();
}
});
if (idxHistory > 0) {
final Button btnPrev = new Button(cButtons, SWT.PUSH);
btnPrev.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
btnPrev.setText(MessageText.getString("popup.previous", new String[] { "" + idxHistory }));
btnPrev.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
disposeShell(shell);
int idx = historyList.indexOf(popupParams) - 1;
if (idx >= 0) {
PopupParams item = historyList.get(idx);
showPopup(display, item, false);
disposeShell(shell);
}
}
});
}
btnNext = new Button(cButtons, SWT.PUSH);
btnNext.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
int numAfter = historyList.size() - idxHistory - 1;
setButtonNextText(numAfter);
btnNext.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
if (DEBUG)
System.out.println("Next Pressed");
if (idxHistory + 1 < historyList.size()) {
showPopup(display, historyList.get(idxHistory + 1), false);
}
disposeShell(shell);
}
});
// Image has gap for text at the top (with image at bottom left)
// trim top to height of shell
Point bestSize = cShell.computeSize(shellWidth, SWT.DEFAULT);
int minHeight = Utils.adjustPXForDPI(SHELL_MIN_HEIGHT);
int maxHeight = Utils.adjustPXForDPI(SHELL_MAX_HEIGHT);
if (bestSize.y < minHeight)
bestSize.y = minHeight;
else if (bestSize.y > maxHeight) {
bestSize.y = maxHeight;
if (sDetails == null) {
sDetails = popupParams.text;
} else {
sDetails = popupParams.text + "\n===============\n" + sDetails;
}
}
Rectangle bounds = null;
try {
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
Shell mainShell = uiFunctions.getMainShell();
if (mainShell != null) {
bounds = mainShell.getMonitor().getClientArea();
}
} else {
Shell shell = display.getActiveShell();
if (shell != null) {
bounds = shell.getMonitor().getClientArea();
}
}
if (bounds == null) {
bounds = shell.getMonitor().getClientArea();
}
} catch (Exception e) {
}
if (bounds == null) {
bounds = display.getClientArea();
}
Rectangle endBounds;
if (bDisableSliding) {
endBounds = new Rectangle(((bounds.x + bounds.width) / 2) - (bestSize.x / 2), ((bounds.y + bounds.height) / 2) - (bestSize.y / 2), bestSize.x, bestSize.y);
} else {
int boundsX2 = bounds.x + bounds.width;
int boundsY2 = bounds.y + bounds.height;
endBounds = shell.computeTrim(boundsX2 - bestSize.x, boundsY2 - bestSize.y, bestSize.x, bestSize.y);
// bottom and right trim will be off the edge, calulate this trim
// and adjust it up and left (trim may not be the same size on all sides)
int diff = (endBounds.x + endBounds.width) - boundsX2;
if (diff >= 0)
endBounds.x -= diff + EDGE_GAP;
diff = (endBounds.y + endBounds.height) - boundsY2;
if (diff >= 0) {
endBounds.y -= diff + EDGE_GAP;
}
// System.out.println("best" + bestSize + ";mon" + bounds + ";end" + endBounds);
}
FormData data = new FormData(bestSize.x, bestSize.y);
cShell.setLayoutData(data);
btnDetails.setVisible(sDetails != null);
if (sDetails == null) {
gridData = new GridData();
gridData.widthHint = 0;
btnDetails.setLayoutData(gridData);
}
shell.layout();
btnNext.setFocus();
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
Utils.disposeSWTObjects(disposeList);
if (currentPopupIndex == idxHistory) {
if (DEBUG)
System.out.println("Clear #" + currentPopupIndex + "/" + idxHistory);
try {
monitor.enter();
currentPopupIndex = -1;
} finally {
monitor.exit();
}
}
}
});
shell.addListener(SWT.Traverse, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.detail == SWT.TRAVERSE_ESCAPE) {
disposeShell(shell);
event.doit = false;
}
}
});
if (mouseAdapter != null)
addMouseTrackListener(shell, mouseAdapter);
for (int i = 0; i < listeners.length; i++) {
try {
listeners[i].skinAfterComponents(shell, this, popupParams.relatedTo);
} catch (Exception e) {
Debug.out(e);
}
}
int timeoutSecs;
if (popupParams.timeoutSecs < 0) {
timeoutSecs = COConfigurationManager.getIntParameter("Message Popup Autoclose in Seconds");
} else {
timeoutSecs = popupParams.timeoutSecs;
}
runPopup(endBounds, idxHistory, bSlide, timeoutSecs);
}
use of com.biglybt.ui.swt.UIFunctionsSWT in project BiglyBT by BiglySoftware.
the class CocoaUIEnhancer method initialize.
private void initialize() throws Exception {
// Get the Mac OS X Application menu.
Object sharedApplication = invoke(nsapplicationCls, "sharedApplication");
Object mainMenu = invoke(sharedApplication, "mainMenu");
Object mainMenuItem = invoke(nsmenuCls, mainMenu, "itemAtIndex", new Object[] { wrapPointer(0) });
Object appMenu = invoke(mainMenuItem, "submenu");
// disable services menu
Object servicesMenuItem = invoke(nsmenuCls, appMenu, "itemAtIndex", new Object[] { wrapPointer(kServicesMenuItem) });
invoke(nsmenuitemCls, servicesMenuItem, "setEnabled", new Object[] { false });
Menu systemMenu = Display.getCurrent().getSystemMenu();
if (systemMenu != null) {
MenuItem sysItem = getItem(systemMenu, SWT.ID_ABOUT);
if (sysItem != null) {
sysItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AboutWindow.show();
}
});
}
sysItem = getItem(systemMenu, SWT.ID_PREFERENCES);
if (sysItem != null) {
sysItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG);
}
}
});
}
int quitIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_QUIT));
MenuItem restartItem = new MenuItem(systemMenu, SWT.CASCADE, quitIndex);
Messages.setLanguageText(restartItem, "MainWindow.menu.file.restart");
restartItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(true, false);
}
}
});
// Add other menus
boolean isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
if (!isAZ3) {
// add Wizard, NAT Test, Speed Test
int prefIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_PREFERENCES)) + 1;
MenuItem wizItem = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(wizItem, "MainWindow.menu.file.configure");
wizItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new ConfigureWizard(false, ConfigureWizard.WIZARD_MODE_FULL);
}
});
MenuItem natMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(natMenu, "MainWindow.menu.tools.nattest");
natMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new NatTestWindow();
}
});
MenuItem netstatMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(netstatMenu, "MainWindow.menu.tools.netstat");
netstatMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
PluginsMenuHelper.IViewInfo[] views = PluginsMenuHelper.getInstance().getPluginViewsInfo();
for (PluginsMenuHelper.IViewInfo view : views) {
String viewID = view.viewID;
if (viewID != null && viewID.equals("aznetstatus")) {
view.openView(uiFunctions);
}
}
}
}
});
MenuItem speedMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(speedMenu, "MainWindow.menu.tools.speedtest");
speedMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new SpeedTestWizard();
}
});
}
}
// Register names in objective-c.
if (sel_applicationShouldHandleReopen_ == 0) {
sel_applicationShouldHandleReopen_ = registerName(osCls, "applicationShouldHandleReopen:hasVisibleWindows:");
}
// Add the action callbacks for menu items.
invoke(osCls, "class_addMethod", new Object[] { wrapPointer(delegateIdSWTApplication), wrapPointer(sel_applicationShouldHandleReopen_), wrapPointer(callBack4Addr), "@:@c" });
initialized = true;
}
Aggregations