use of com.biglybt.ui.swt.MenuBuildUtils.MenuBuilder 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) {
TabbedEntry entry = (TabbedEntry) event.item.getData("TabbedEntry");
showEntry(entry);
}
});
tabFolder.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
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);
}
}
@Override
public void mouseDoubleClick(MouseEvent e) {
if (!tabFolder.getMinimized() && tabFolder.getMaximizeVisible()) {
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) {
final TabbedEntry entry = (TabbedEntry) event.item.getData("TabbedEntry");
if (select_history.remove(entry)) {
if (select_history.size() > 0) {
final MdiEntry next = select_history.getLast();
if (!next.isDisposed() && next != entry) {
// If tabfolder's selected entry is the one we are closing,
// CTabFolder will try to move to next CTabItem. Disable
// this feature by moving tabfolder's selection away from us
CTabItem[] items = tabFolder.getItems();
for (int i = 0; i < items.length; i++) {
CTabItem item = items[i];
TabbedEntry scanEntry = getEntryFromTabItem(item);
if (scanEntry == next) {
tabFolder.setSelection(item);
break;
}
}
showEntry(next);
}
}
}
// the "next" tab would select.
if (props_prefix != null) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
String view_id = entry.getViewID();
String key = props_prefix + ".closedtabs";
Map closedtabs = COConfigurationManager.getMapParameter(key, new HashMap());
if (!closedtabs.containsKey(view_id)) {
closedtabs.put(view_id, entry.getTitle());
// 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)) {
MdiEntry entry = getCurrentEntry();
if (entry != null) {
entry.close(false);
}
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;
}
}
}
});
}
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));
boolean need_sep = false;
if (item == null) {
need_sep = mapUserClosedTabs.size() > 0;
if (need_sep) {
for (Object id : mapUserClosedTabs.keySet()) {
final String view_id = (String) id;
MenuItem mi = new 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));
}
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);
}
showEntryByID(view_id);
}
});
}
}
}
if (need_sep) {
new 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);
}
}
use of com.biglybt.ui.swt.MenuBuildUtils.MenuBuilder in project BiglyBT by BiglySoftware.
the class TagButtonsUI method buildTagGroup.
public void buildTagGroup(List<Tag> tags, Composite cMainComposite, final TagButtonTrigger trigger) {
this.cMainComposite = cMainComposite;
cMainComposite.setLayout(new GridLayout(1, false));
buttons = new ArrayList<>();
SelectionListener selectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
Button button = (Button) e.widget;
Tag tag = (Tag) button.getData("Tag");
if (button.getGrayed()) {
button.setGrayed(false);
button.setSelection(!button.getSelection());
button.getParent().redraw();
}
boolean doTag = button.getSelection();
trigger.tagButtonTriggered(tag, doTag);
button.getParent().redraw();
button.getParent().update();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
};
Listener menuDetectListener = new Listener() {
@Override
public void handleEvent(Event event) {
final Button button = (Button) event.widget;
Menu menu = new Menu(button);
button.setMenu(menu);
MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuilder() {
@Override
public void buildMenu(final Menu menu, MenuEvent menuEvent) {
Tag tag = (Tag) button.getData("Tag");
TagUIUtils.createSideBarMenuItems(menu, tag);
}
});
}
};
tags = TagUIUtils.sortTags(tags);
Composite g = null;
String group = null;
for (Tag tag : tags) {
String newGroup = tag.getGroup();
if (g == null || (group != null && !group.equals(newGroup)) || (group == null && newGroup != null)) {
group = newGroup;
g = group == null ? new Composite(cMainComposite, SWT.DOUBLE_BUFFERED) : new Group(cMainComposite, SWT.DOUBLE_BUFFERED);
if (group != null) {
((Group) g).setText(group);
}
g.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
RowLayout rowLayout = new RowLayout();
rowLayout.pack = true;
rowLayout.spacing = 5;
Utils.setLayout(g, rowLayout);
}
Composite p = new Composite(g, SWT.DOUBLE_BUFFERED);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 3;
if (Constants.isWindows) {
layout.marginWidth = 6;
layout.marginLeft = 2;
layout.marginTop = 1;
} else {
layout.marginWidth = 0;
layout.marginLeft = 3;
layout.marginRight = 11;
}
p.setLayout(layout);
p.addPaintListener(this);
Button button = new Button(p, SWT.CHECK);
buttons.add(button);
boolean[] auto = tag.isTagAuto();
if (auto[0] && auto[1]) {
button.setEnabled(false);
} else {
button.addSelectionListener(selectionListener);
}
button.setData("Tag", tag);
button.addListener(SWT.MenuDetect, menuDetectListener);
button.addPaintListener(this);
}
}
Aggregations