use of com.biglybt.ui.swt.pif.UISWTInputReceiver in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method buildStatus.
private void buildStatus(Composite main_component, Composite component) {
boolean public_chat = !chat.isPrivateChat();
final Label menu_drop = new Label(component, SWT.NULL);
Messages.setLanguageTooltip(menu_drop, "TagSettingsView.title");
FontData fontData = menu_drop.getFont().getFontData()[0];
Display display = menu_drop.getDisplay();
italic_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC));
bold_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
big_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 1.5), SWT.BOLD));
small_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 0.5), SWT.BOLD));
ftux_dark_bg = new Color(display, 183, 200, 212);
ftux_dark_fg = new Color(display, 0, 81, 134);
ftux_light_bg = new Color(display, 236, 242, 246);
component.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
Font[] fonts = { italic_font, bold_font, big_font, small_font };
for (Font f : fonts) {
if (f != null) {
f.dispose();
}
}
Color[] colours = { ftux_dark_bg, ftux_dark_fg, ftux_light_bg };
for (Color c : colours) {
if (c != null) {
c.dispose();
}
}
if (drop_targets != null) {
for (DropTarget dt : drop_targets) {
dt.dispose();
}
}
closed();
}
});
status = new BufferedLabel(component, SWT.LEFT | SWT.DOUBLE_BUFFERED);
GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(status, grid_data);
status.setText(MessageText.getString("PeersView.state.pending"));
Image image = ImageLoader.getInstance().getImage("cog_down");
menu_drop.setImage(image);
grid_data = new GridData();
grid_data.widthHint = image.getBounds().width;
grid_data.heightHint = image.getBounds().height;
Utils.setLayoutData(menu_drop, grid_data);
menu_drop.setCursor(menu_drop.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
Control status_control = status.getControl();
final Menu status_menu = new Menu(status_control);
status.getControl().setMenu(status_menu);
menu_drop.setMenu(status_menu);
menu_drop.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
try {
Point p = status_menu.getDisplay().map(menu_drop, null, event.x, event.y);
status_menu.setLocation(p);
status_menu.setVisible(true);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (public_chat) {
Menu status_clip_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_clip_item = new MenuItem(status_menu, SWT.CASCADE);
status_clip_item.setMenu(status_clip_menu);
status_clip_item.setText(MessageText.getString("label.copy.to.clipboard"));
MenuItem status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.key"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getKey());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.getURL());
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.rss.url"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard("azplug:?id=azbuddy&arg=" + UrlUtils.encode(chat.getURL() + "&format=rss"));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.pk"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(Base32.encode(chat.getPublicKey()));
}
});
status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.export"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(chat.export());
}
});
if (!chat.isManaged()) {
Menu status_channel_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_channel_item = new MenuItem(status_menu, SWT.CASCADE);
status_channel_item.setMenu(status_channel_menu);
status_channel_item.setText(MessageText.getString("azbuddy.dchat.rchans"));
// Managed channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.managed"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getManagedChannel();
BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// RO channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.ro"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = chat.getReadOnlyChannel();
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
// Random sub-channel
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.rand"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
byte[] rand = new byte[20];
RandomUtils.nextSecureBytes(rand);
ChatInstance inst = beta.getChat(chat.getNetwork(), chat.getKey() + " {" + Base32.encode(rand) + "}");
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
if (beta.isI2PAvailable()) {
status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
status_mi.setText(MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_I2P ? "azbuddy.dchat.rchans.pub" : "azbuddy.dchat.rchans.anon"));
status_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
ChatInstance inst = beta.getChat(chat.getNetwork() == AENetworkClassifier.AT_I2P ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P, chat.getKey());
createChatWindow(view, plugin, inst);
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
}
final MenuItem fave_mi = new MenuItem(status_menu, SWT.CHECK);
fave_mi.setText(MessageText.getString("label.fave"));
fave_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setFavourite(fave_mi.getSelection());
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString(Utils.isAZ2UI() ? "label.show.in.tab" : "label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
addFriendsMenu(status_menu);
// advanced
final Menu advanced_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem advanced_menu_item = new MenuItem(status_menu, SWT.CASCADE);
advanced_menu_item.setMenu(advanced_menu);
advanced_menu_item.setText(MessageText.getString("MyTorrentsView.menu.advancedmenu"));
// rename
final MenuItem rename_mi = new MenuItem(advanced_menu, SWT.PUSH);
rename_mi.setText(MessageText.getString("MyTorrentsView.menu.rename"));
rename_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String name = chat.getDisplayName();
if (name == null) {
name = chat.getName();
}
UISWTInputReceiver entry = new SimpleTextEntryWindow();
entry.setPreenteredText(name, false);
entry.maintainWhitespace(false);
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { name }));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
if (input.length() > 0) {
try {
chat.setDisplayName(input);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
});
}
});
// view type
final Menu vt_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
MenuItem vt_menu_item = new MenuItem(advanced_menu, SWT.CASCADE);
vt_menu_item.setMenu(vt_menu);
vt_menu_item.setText(MessageText.getString("menu.view.options"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int vt = -1;
for (MenuItem mi : vt_menu.getItems()) {
if (mi.getSelection()) {
vt = (Integer) mi.getData();
}
}
if (vt != -1) {
chat.setViewType(vt);
buildSupport(main_component);
main_component.layout(true, true);
}
}
};
MenuItem vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("label.full"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_DEFAULT);
vt_mi.addSelectionListener(listener);
vt_mi = new MenuItem(vt_menu, SWT.RADIO);
vt_mi.setText(MessageText.getString("ConfigView.section.sharing"));
vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_SHARING);
if (chat.isReadOnly()) {
vt_mi.setEnabled(false);
}
vt_mi.addSelectionListener(listener);
vt_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int vt = chat.getViewType();
for (MenuItem mi : vt_menu.getItems()) {
mi.setSelection(vt == (Integer) mi.getData());
}
}
});
// persist messages
final MenuItem persist_mi = new MenuItem(advanced_menu, SWT.CHECK);
persist_mi.setText(MessageText.getString("azbuddy.dchat.save.messages"));
persist_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setSaveMessages(persist_mi.getSelection());
}
});
final MenuItem log_mi = new MenuItem(advanced_menu, SWT.CHECK);
log_mi.setText(MessageText.getString("azbuddy.dchat.log.messages"));
log_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setLogMessages(log_mi.getSelection());
}
});
final MenuItem automute_mi = new MenuItem(advanced_menu, SWT.CHECK);
automute_mi.setText(MessageText.getString("azbuddy.dchat.auto.mute"));
automute_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setAutoMute(automute_mi.getSelection());
}
});
final MenuItem postnotifications_mi = new MenuItem(advanced_menu, SWT.CHECK);
postnotifications_mi.setText(MessageText.getString("azbuddy.dchat.post.to.notifcations"));
postnotifications_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setEnableNotificationsPost(postnotifications_mi.getSelection());
}
});
final MenuItem disableindicators_mi = new MenuItem(advanced_menu, SWT.CHECK);
disableindicators_mi.setText(MessageText.getString("azbuddy.dchat.disable.msg.indicators"));
disableindicators_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chat.setDisableNewMsgIndications(disableindicators_mi.getSelection());
}
});
// setup menu
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
fave_mi.setSelection(chat.isFavourite());
persist_mi.setSelection(chat.getSaveMessages());
log_mi.setSelection(chat.getLogMessages());
automute_mi.setSelection(chat.getAutoMute());
postnotifications_mi.setSelection(chat.getEnableNotificationsPost());
boolean disable_indications = chat.getDisableNewMsgIndications();
disableindicators_mi.setSelection(disable_indications);
postnotifications_mi.setEnabled(!disable_indications);
}
});
} else {
final Menu status_priv_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
MenuItem status_priv_item = new MenuItem(status_menu, SWT.CASCADE);
status_priv_item.setMenu(status_priv_menu);
status_priv_item.setText(MessageText.getString("label.private.chat"));
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
beta.setPrivateChatState((Integer) ((MenuItem) e.widget).getData());
}
};
MenuItem status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.enabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.pinned.only"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
status_mi.addSelectionListener(listener);
status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
status_mi.setText(MessageText.getString("label.disabled"));
status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
status_mi.addSelectionListener(listener);
status_priv_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int pc_state = beta.getPrivateChatState();
for (MenuItem mi : status_priv_menu.getItems()) {
mi.setSelection(pc_state == (Integer) mi.getData());
}
}
});
addFriendsMenu(status_menu);
final MenuItem keep_alive_mi = new MenuItem(status_menu, SWT.CHECK);
keep_alive_mi.setText(MessageText.getString("label.keep.alive"));
status_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
keep_alive_mi.setSelection(chat.getUserData("AC:KeepAlive") != null);
}
});
keep_alive_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ChatInstance clone = (ChatInstance) chat.getUserData("AC:KeepAlive");
if (clone != null) {
clone.destroy();
clone = null;
} else {
try {
clone = chat.getClone();
} catch (Throwable f) {
}
}
chat.setUserData("AC:KeepAlive", clone);
}
});
final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
sis_mi.setText(MessageText.getString("label.show.in.sidebar"));
sis_mi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
}
});
}
}
use of com.biglybt.ui.swt.pif.UISWTInputReceiver in project BiglyBT by BiglySoftware.
the class MenuFactory method addSpeedLimitsToMenu.
public static MenuItem addSpeedLimitsToMenu(final Menu menuParent) {
MenuItem speedLimitsMenuItem = createTopLevelMenuItem(menuParent, MENU_ID_SPEED_LIMITS);
MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenuItem.getMenu(), new MenuBuildUtils.MenuBuilder() {
@Override
public void buildMenu(Menu menu, MenuEvent menuEvent) {
if (CoreFactory.isCoreRunning()) {
Core core = CoreFactory.getSingleton();
final SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
MenuItem viewCurrentItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(viewCurrentItem, "MainWindow.menu.speed_limits.view_current");
viewCurrentItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.getCurrent());
}
});
java.util.List<String> profiles = slh.getProfileNames();
Menu profiles_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
MenuItem profiles_item = new MenuItem(menu, SWT.CASCADE);
profiles_item.setMenu(profiles_menu);
Messages.setLanguageText(profiles_item, "MainWindow.menu.speed_limits.profiles");
if (profiles.size() == 0) {
profiles_item.setEnabled(false);
} else {
for (final String p : profiles) {
Menu profile_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
MenuItem profile_item = new MenuItem(profiles_menu, SWT.CASCADE);
profile_item.setMenu(profile_menu);
profile_item.setText(p);
MenuItem loadItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(loadItem, "MainWindow.menu.speed_limits.load");
loadItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.loadProfile(p));
}
});
MenuItem viewItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(viewItem, "MainWindow.menu.speed_limits.view");
viewItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
}
});
addSeparatorMenuItem(profile_menu);
MenuItem deleteItem = new MenuItem(profile_menu, SWT.PUSH);
Messages.setLanguageText(deleteItem, "MainWindow.menu.speed_limits.delete");
deleteItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
slh.deleteProfile(p);
}
});
}
}
MenuItem saveItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(saveItem, "MainWindow.menu.speed_limits.save_current");
saveItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
UISWTInputReceiver entry = new SimpleTextEntryWindow();
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("MainWindow.menu.speed_limits.profile"));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
if (input.length() > 0) {
showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { input }), slh.saveProfile(input));
}
}
});
}
});
addSeparatorMenuItem(menu);
MenuItem resetItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(resetItem, "MainWindow.menu.speed_limits.reset");
resetItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.reset());
}
});
addSeparatorMenuItem(menu);
MenuItem scheduleItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(scheduleItem, "MainWindow.menu.speed_limits.schedule");
scheduleItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
Utils.execSWTThreadLater(1, new Runnable() {
@Override
public void run() {
java.util.List<String> lines = slh.getSchedule();
StringBuilder text = new StringBuilder(80 * lines.size());
for (String s : lines) {
if (text.length() > 0) {
text.append("\n");
}
text.append(s);
}
final TextViewerWindow viewer = new TextViewerWindow("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.msg", text.toString(), false);
viewer.setEditable(true);
viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {
@Override
public void closed() {
if (viewer.getOKPressed()) {
String text = viewer.getText();
String[] lines = text.split("\n");
java.util.List<String> updated_lines = new ArrayList<>(Arrays.asList(lines));
java.util.List<String> result = slh.setSchedule(updated_lines);
if (result != null && result.size() > 0) {
showText("MainWindow.menu.speed_limits.schedule.title", "MainWindow.menu.speed_limits.schedule.err", result);
}
}
}
});
}
});
}
});
addSeparatorMenuItem(menu);
MenuItem helpItem = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(helpItem, "MainWindow.menu.speed_limits.wiki");
helpItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
Utils.launch(MessageText.getString("MainWindow.menu.speed_limits.wiki.url"));
}
});
}
}
});
return (speedLimitsMenuItem);
}
Aggregations