use of org.eclipse.swt.events.KeyListener in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method buildSupport2.
private void buildSupport2(Composite parent) {
boolean public_chat = !chat.isPrivateChat();
if (chat.getViewType() == BuddyPluginBeta.VIEW_TYPE_DEFAULT || chat.isReadOnly()) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
GridData grid_data = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(parent, grid_data);
Composite sash_area = new Composite(parent, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
sash_area.setLayout(layout);
grid_data = new GridData(GridData.FILL_BOTH);
grid_data.horizontalSpan = 2;
Utils.setLayoutData(sash_area, grid_data);
final SashForm sash = new SashForm(sash_area, SWT.HORIZONTAL);
grid_data = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(sash, grid_data);
final Composite lhs = new Composite(sash, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 4;
layout.marginLeft = 4;
lhs.setLayout(layout);
grid_data = new GridData(GridData.FILL_BOTH);
grid_data.widthHint = 300;
Utils.setLayoutData(lhs, grid_data);
buildStatus(parent, lhs);
Composite log_holder = buildFTUX(lhs, SWT.BORDER);
// LOG panel
layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginLeft = 4;
log_holder.setLayout(layout);
// grid_data = new GridData(GridData.FILL_BOTH );
// grid_data.horizontalSpan = 2;
// Utils.setLayoutData(log_holder, grid_data);
log = new StyledText(log_holder, SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP | SWT.NO_FOCUS);
grid_data = new GridData(GridData.FILL_BOTH);
grid_data.horizontalSpan = 1;
// grid_data.horizontalIndent = 4;
Utils.setLayoutData(log, grid_data);
// log.setIndent( 4 );
log.setEditable(false);
log_holder.setBackground(log.getBackground());
final Menu log_menu = new Menu(log);
log.setMenu(log_menu);
log.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
e.doit = false;
boolean handled = false;
for (MenuItem mi : log_menu.getItems()) {
mi.dispose();
}
try {
Point mapped = log.getDisplay().map(null, log, new Point(e.x, e.y));
int offset = log.getOffsetAtLocation(mapped);
final StyleRange sr = log.getStyleRangeAtOffset(offset);
if (sr != null) {
Object data = sr.data;
if (data instanceof ChatParticipant) {
ChatParticipant cp = (ChatParticipant) data;
List<ChatParticipant> cps = new ArrayList<>();
cps.add(cp);
buildParticipantMenu(log_menu, cps);
handled = true;
} else if (data instanceof String) {
String url_str = (String) sr.data;
String str = url_str;
if (str.length() > 50) {
str = str.substring(0, 50) + "...";
}
if (chat.isAnonymous() && url_str.toLowerCase(Locale.US).startsWith("magnet:")) {
String[] magnet_uri = { url_str };
Set<String> networks = UrlUtils.extractNetworks(magnet_uri);
String i2p_only_uri = magnet_uri[0] + "&net=" + UrlUtils.encode(AENetworkClassifier.AT_I2P);
String i2p_only_str = i2p_only_uri;
if (i2p_only_str.length() > 50) {
i2p_only_str = i2p_only_str.substring(0, 50) + "...";
}
i2p_only_str = lu.getLocalisedMessageText("azbuddy.dchat.open.i2p.magnet") + ": " + i2p_only_str;
final MenuItem mi_open_i2p_vuze = new MenuItem(log_menu, SWT.PUSH);
mi_open_i2p_vuze.setText(i2p_only_str);
mi_open_i2p_vuze.setData(i2p_only_uri);
mi_open_i2p_vuze.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_open_i2p_vuze.getData();
if (url_str != null) {
TorrentOpener.openTorrent(url_str);
}
}
});
if (networks.size() == 1 && networks.iterator().next() == AENetworkClassifier.AT_I2P) {
// already done above
} else {
str = lu.getLocalisedMessageText("azbuddy.dchat.open.magnet") + ": " + str;
final MenuItem mi_open_vuze = new MenuItem(log_menu, SWT.PUSH);
mi_open_vuze.setText(str);
mi_open_vuze.setData(url_str);
mi_open_vuze.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_open_vuze.getData();
if (url_str != null) {
TorrentOpener.openTorrent(url_str);
}
}
});
}
} else {
str = lu.getLocalisedMessageText("azbuddy.dchat.open.in.vuze") + ": " + str;
final MenuItem mi_open_vuze = new MenuItem(log_menu, SWT.PUSH);
mi_open_vuze.setText(str);
mi_open_vuze.setData(url_str);
mi_open_vuze.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_open_vuze.getData();
if (url_str != null) {
String lc_url_str = url_str.toLowerCase(Locale.US);
if (lc_url_str.startsWith("chat:")) {
try {
beta.handleURI(url_str, true);
} catch (Throwable f) {
Debug.out(f);
}
} else {
TorrentOpener.openTorrent(url_str);
}
}
}
});
}
final MenuItem mi_open_ext = new MenuItem(log_menu, SWT.PUSH);
mi_open_ext.setText(lu.getLocalisedMessageText("azbuddy.dchat.open.in.browser"));
mi_open_ext.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_open_ext.getData();
Utils.launch(url_str);
}
});
new MenuItem(log_menu, SWT.SEPARATOR);
if (chat.isAnonymous() && url_str.toLowerCase(Locale.US).startsWith("magnet:")) {
String[] magnet_uri = { url_str };
Set<String> networks = UrlUtils.extractNetworks(magnet_uri);
String i2p_only_uri = magnet_uri[0] + "&net=" + UrlUtils.encode(AENetworkClassifier.AT_I2P);
final MenuItem mi_copy_i2p_clip = new MenuItem(log_menu, SWT.PUSH);
mi_copy_i2p_clip.setText(lu.getLocalisedMessageText("azbuddy.dchat.copy.i2p.magnet"));
mi_copy_i2p_clip.setData(i2p_only_uri);
mi_copy_i2p_clip.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_copy_i2p_clip.getData();
if (url_str != null) {
ClipboardCopy.copyToClipBoard(url_str);
}
}
});
if (networks.size() == 1 && networks.iterator().next() == AENetworkClassifier.AT_I2P) {
// already done above
} else {
final MenuItem mi_copy_clip = new MenuItem(log_menu, SWT.PUSH);
mi_copy_clip.setText(lu.getLocalisedMessageText("azbuddy.dchat.copy.magnet"));
mi_copy_clip.setData(url_str);
mi_copy_clip.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_copy_clip.getData();
if (url_str != null) {
ClipboardCopy.copyToClipBoard(url_str);
}
}
});
}
} else {
final MenuItem mi_copy_clip = new MenuItem(log_menu, SWT.PUSH);
mi_copy_clip.setText(lu.getLocalisedMessageText("label.copy.to.clipboard"));
mi_copy_clip.setData(url_str);
mi_copy_clip.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String url_str = (String) mi_copy_clip.getData();
if (url_str != null) {
ClipboardCopy.copyToClipBoard(url_str);
}
}
});
}
if (url_str.toLowerCase().startsWith("http")) {
mi_open_ext.setData(url_str);
mi_open_ext.setEnabled(true);
} else {
mi_open_ext.setEnabled(false);
}
handled = true;
} else {
if (Constants.isCVSVersion()) {
if (sr instanceof MyStyleRange) {
final MyStyleRange msr = (MyStyleRange) sr;
MenuItem item = new MenuItem(log_menu, SWT.NONE);
item.setText(MessageText.getString("label.copy.to.clipboard"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(msr.message.getMessage());
}
});
handled = true;
}
}
}
}
} catch (Throwable f) {
}
if (!handled) {
final String text = log.getSelectionText();
if (text != null && text.length() > 0) {
MenuItem item = new MenuItem(log_menu, SWT.NONE);
item.setText(MessageText.getString("label.copy.to.clipboard"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ClipboardCopy.copyToClipBoard(text);
}
});
handled = true;
}
}
if (handled) {
e.doit = true;
}
}
});
log.addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event e) {
try {
final int offset = log.getOffsetAtLocation(new Point(e.x, e.y));
for (int i = 0; i < log_styles.length; i++) {
StyleRange sr = log_styles[i];
Object data = sr.data;
if (data != null && offset >= sr.start && offset < sr.start + sr.length) {
boolean anon_chat = chat.isAnonymous();
if (data instanceof String) {
final String url_str = (String) data;
String lc_url_str = url_str.toLowerCase(Locale.US);
if (lc_url_str.startsWith("chat:")) {
if (anon_chat && !lc_url_str.startsWith("chat:anon:")) {
return;
}
try {
beta.handleURI(url_str, true);
} catch (Throwable f) {
Debug.out(f);
}
} else {
if (anon_chat) {
try {
String host = new URL(lc_url_str).getHost();
if (AENetworkClassifier.categoriseAddress(host) == AENetworkClassifier.AT_PUBLIC) {
return;
}
} catch (Throwable f) {
return;
}
}
if (lc_url_str.contains(".torrent") || UrlUtils.parseTextForMagnets(url_str) != null) {
TorrentOpener.openTorrent(url_str);
} else {
if (url_str.toLowerCase(Locale.US).startsWith("http")) {
// without this backoff we end up with the text widget
// being left in a 'mouse down' state when returning to it :(
Utils.execSWTThreadLater(100, new Runnable() {
@Override
public void run() {
Utils.launch(url_str);
}
});
} else {
TorrentOpener.openTorrent(url_str);
}
}
}
log.setSelection(offset);
e.doit = false;
} else if (data instanceof ChatParticipant) {
ChatParticipant participant = (ChatParticipant) data;
addNickString(participant);
}
}
}
} catch (Throwable f) {
}
}
});
log.addMouseTrackListener(new MouseTrackListener() {
private StyleRange old_range;
private StyleRange temp_range;
private int temp_index;
@Override
public void mouseHover(MouseEvent e) {
boolean active = false;
try {
int offset = log.getOffsetAtLocation(new Point(e.x, e.y));
for (int i = 0; i < log_styles.length; i++) {
StyleRange sr = log_styles[i];
Object data = sr.data;
if (data != null && offset >= sr.start && offset < sr.start + sr.length) {
if (old_range != null) {
if (temp_index < log_styles.length && log_styles[temp_index] == temp_range) {
log_styles[temp_index] = old_range;
old_range = null;
}
}
sr = log_styles[i];
String tt_extra = "";
if (data instanceof String) {
try {
URL url = new URL((String) data);
String query = url.getQuery();
if (query != null) {
String[] bits = query.split("&");
int seeds = -1;
int leechers = -1;
for (String bit : bits) {
String[] temp = bit.split("=");
String lhs = temp[0];
if (lhs.equals("_s")) {
seeds = Integer.parseInt(temp[1]);
} else if (lhs.equals("_l")) {
leechers = Integer.parseInt(temp[1]);
}
}
if (seeds != -1 && leechers != -1) {
tt_extra = ": seeds=" + seeds + ", leechers=" + leechers;
}
}
} catch (Throwable f) {
}
}
log.setToolTipText(MessageText.getString("label.right.click.for.options") + tt_extra);
StyleRange derp;
if (sr instanceof MyStyleRange) {
derp = new MyStyleRange((MyStyleRange) sr);
} else {
derp = new StyleRange(sr);
}
derp.start = sr.start;
derp.length = sr.length;
derp.borderStyle = SWT.BORDER_DASH;
old_range = sr;
temp_range = derp;
temp_index = i;
log_styles[i] = derp;
log.setStyleRanges(log_styles);
active = true;
break;
}
}
} catch (Throwable f) {
}
if (!active) {
log.setToolTipText("");
if (old_range != null) {
if (temp_index < log_styles.length && log_styles[temp_index] == temp_range) {
log_styles[temp_index] = old_range;
old_range = null;
log.setStyleRanges(log_styles);
}
}
}
}
@Override
public void mouseExit(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEnter(MouseEvent e) {
// TODO Auto-generated method stub
}
});
log.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
int key = event.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a' && event.stateMask == SWT.MOD1) {
event.doit = false;
log.selectAll();
}
}
});
Composite rhs = new Composite(sash, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 4;
layout.marginRight = 4;
rhs.setLayout(layout);
grid_data = new GridData(GridData.FILL_VERTICAL);
int rhs_width = Constants.isWindows ? 150 : 160;
grid_data.widthHint = rhs_width;
Utils.setLayoutData(rhs, grid_data);
// options
Composite top_right = buildHelp(rhs);
// nick name
Composite nick_area = new Composite(top_right, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 4;
layout.marginHeight = 0;
layout.marginWidth = 0;
if (!Constants.isWindows) {
layout.horizontalSpacing = 2;
layout.verticalSpacing = 2;
}
nick_area.setLayout(layout);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 3;
Utils.setLayoutData(nick_area, grid_data);
Label label = new Label(nick_area, SWT.NULL);
label.setText(lu.getLocalisedMessageText("azbuddy.dchat.nick"));
grid_data = new GridData();
// grid_data.horizontalIndent=4;
Utils.setLayoutData(label, grid_data);
nickname = new Text(nick_area, SWT.BORDER);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 1;
Utils.setLayoutData(nickname, grid_data);
nickname.setText(chat.getNickname(false));
nickname.setMessage(chat.getDefaultNickname());
label = new Label(nick_area, SWT.NULL);
label.setText(lu.getLocalisedMessageText("label.shared"));
label.setToolTipText(lu.getLocalisedMessageText("azbuddy.dchat.shared.tooltip"));
shared_nick_button = new Button(nick_area, SWT.CHECK);
shared_nick_button.setSelection(chat.isSharedNickname());
shared_nick_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
boolean shared = shared_nick_button.getSelection();
chat.setSharedNickname(shared);
}
});
nickname.addListener(SWT.FocusOut, new Listener() {
@Override
public void handleEvent(Event event) {
String nick = nickname.getText().trim();
if (chat.isSharedNickname()) {
if (chat.getNetwork() == AENetworkClassifier.AT_PUBLIC) {
beta.setSharedPublicNickname(nick);
} else {
beta.setSharedAnonNickname(nick);
}
} else {
chat.setInstanceNickname(nick);
}
}
});
table_header_left = new BufferedLabel(top_right, SWT.DOUBLE_BUFFERED);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 2;
if (!Constants.isWindows) {
grid_data.horizontalIndent = 2;
}
Utils.setLayoutData(table_header_left, grid_data);
table_header_left.setText(MessageText.getString("PeersView.state.pending"));
LinkLabel link = new LinkLabel(top_right, "Views.plugins.azbuddy.title", new Runnable() {
@Override
public void run() {
if (!plugin.isClassicEnabled()) {
plugin.setClassicEnabled(true);
}
beta.selectClassicTab();
}
});
// table
buddy_table = new Table(rhs, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
String[] headers = { "azbuddy.ui.table.name" };
int[] sizes = { rhs_width - 10 };
int[] aligns = { SWT.LEFT };
for (int i = 0; i < headers.length; i++) {
TableColumn tc = new TableColumn(buddy_table, aligns[i]);
tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
Messages.setLanguageText(tc, headers[i]);
}
buddy_table.setHeaderVisible(true);
grid_data = new GridData(GridData.FILL_BOTH);
// grid_data.heightHint = buddy_table.getHeaderHeight() * 3;
Utils.setLayoutData(buddy_table, grid_data);
buddy_table.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
setItemData(item);
}
});
final Menu menu = new Menu(buddy_table);
buddy_table.setMenu(menu);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
MenuItem[] items = menu.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
final TableItem[] selection = buddy_table.getSelection();
List<ChatParticipant> participants = new ArrayList<>(selection.length);
for (int i = 0; i < selection.length; i++) {
TableItem item = selection[i];
ChatParticipant participant = (ChatParticipant) item.getData();
if (participant == null) {
// item data won't be set yet for items that haven't been
// visible...
participant = setItemData(item);
}
if (participant != null) {
participants.add(participant);
}
}
buildParticipantMenu(menu, participants);
}
@Override
public void menuHidden(MenuEvent e) {
}
});
buddy_table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
int key = event.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a' && event.stateMask == SWT.MOD1) {
event.doit = false;
buddy_table.selectAll();
}
}
});
buddy_table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TableItem[] selection = buddy_table.getSelection();
if (selection.length != 1) {
return;
}
TableItem item = selection[0];
ChatParticipant participant = (ChatParticipant) item.getData();
addNickString(participant);
}
});
Utils.maintainSashPanelWidth(sash, rhs, new int[] { 700, 300 }, "azbuddy.dchat.ui.sash.pos");
/*
Listener sash_listener=
new Listener()
{
private int lhs_weight;
private int lhs_width;
public void
handleEvent(
Event ev )
{
if ( ev.widget == lhs ){
int[] weights = sash.getWeights();
if ( lhs_weight != weights[0] ){
// sash has moved
lhs_weight = weights[0];
// keep track of the width
lhs_width = lhs.getBounds().width;
}
}else{
// resize
if ( lhs_width > 0 ){
int width = sash.getClientArea().width;
double ratio = (double)lhs_width/width;
lhs_weight = (int)(ratio*1000 );
sash.setWeights( new int[]{ lhs_weight, 1000 - lhs_weight });
}
}
}
};
lhs.addListener(SWT.Resize, sash_listener );
sash.addListener(SWT.Resize, sash_listener );
*/
// bottom area
Composite bottom_area = new Composite(parent, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
bottom_area.setLayout(layout);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 2;
bottom_area.setLayoutData(grid_data);
// Text
input_area = new Text(bottom_area, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 1;
grid_data.heightHint = 30;
grid_data.horizontalIndent = 4;
Utils.setLayoutData(input_area, grid_data);
// input_area.setIndent( 4 );
input_area.setTextLimit(MAX_MSG_OVERALL_LENGTH);
input_area.addVerifyListener(new VerifyListener() {
@Override
public void verifyText(VerifyEvent ev) {
if (ev.text.equals("\t")) {
ev.doit = false;
}
}
});
input_area.addKeyListener(new KeyListener() {
private LinkedList<String> history = new LinkedList<>();
private int history_pos = -1;
private String buffered_message = "";
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
e.doit = false;
if ((e.stateMask & SWT.ALT) != 0) {
input_area.insert("\n");
return;
}
String message = input_area.getText().trim();
if (message.length() > 0) {
sendMessage(message, true);
history.addFirst(message);
if (history.size() > 32) {
history.removeLast();
}
history_pos = -1;
buffered_message = "";
input_area.setText("");
text_cache.put(chat.getNetAndKey(), "");
}
} else if (e.keyCode == SWT.ARROW_UP) {
history_pos++;
if (history_pos < history.size()) {
if (history_pos == 0) {
buffered_message = input_area.getText().trim();
}
String msg = history.get(history_pos);
input_area.setText(msg);
input_area.setSelection(msg.length());
} else {
history_pos = history.size() - 1;
}
e.doit = false;
} else if (e.keyCode == SWT.ARROW_DOWN) {
history_pos--;
if (history_pos >= 0) {
String msg = history.get(history_pos);
input_area.setText(msg);
input_area.setSelection(msg.length());
} else {
if (history_pos == -1) {
input_area.setText(buffered_message);
if (buffered_message.length() > 0) {
input_area.setSelection(buffered_message.length());
buffered_message = "";
}
} else {
history_pos = -1;
}
}
e.doit = false;
} else {
if (e.stateMask == SWT.MOD1) {
int key = e.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a') {
input_area.selectAll();
} else if (key == 'b' || key == 'i') {
String emp = key == 'b' ? "**" : "*";
String sel = input_area.getSelectionText();
Point p = input_area.getSelection();
while (sel.endsWith(" ")) {
sel = sel.substring(0, sel.length() - 1);
p.y--;
}
if (!sel.isEmpty()) {
/*
int[] range = input_area.getSelectionRanges();
int emp_len = emp.length();
if ( sel.startsWith( emp ) && sel.endsWith( emp ) && sel.length() >= emp_len * 2 ){
input_area.replaceTextRange( range[0], range[1], sel.substring(emp_len, sel.length() - emp_len ));
input_area.setSelection( range[0], range[0] + range[1] - emp_len*2 );
}else{
input_area.replaceTextRange( range[0], range[1], emp + sel + emp );
input_area.setSelection( range[0], range[0] + range[1] + emp_len*2 );
}
*/
int emp_len = emp.length();
String text = input_area.getText();
if (sel.startsWith(emp) && sel.endsWith(emp) && sel.length() >= emp_len * 2) {
input_area.setText(text.substring(0, p.x) + sel.substring(emp_len, sel.length() - emp_len) + text.substring(p.y));
p.y -= emp_len * 2;
} else {
input_area.setText(text.substring(0, p.x) + emp + sel + emp + text.substring(p.y));
p.y += emp_len * 2;
}
input_area.setSelection(p);
}
}
}
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
input_area.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
if (input_area != null) {
String text = input_area.getText();
text_cache.put(chat.getNetAndKey(), text);
}
}
});
String cached_text = text_cache.get(chat.getNetAndKey());
if (cached_text != null && !cached_text.isEmpty()) {
input_area.setText(cached_text);
input_area.setSelection(cached_text.length());
}
Composite button_area = new Composite(bottom_area, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginRight = 4;
button_area.setLayout(layout);
buildRSSButton(button_area);
hookFTUXListener();
if (chat.isReadOnly()) {
input_area.setText(MessageText.getString("azbuddy.dchat.ro"));
}
setInputAvailability(true);
if (!chat.isReadOnly()) {
drop_targets = new DropTarget[] { new DropTarget(log, DND.DROP_COPY), new DropTarget(input_area, DND.DROP_COPY) };
for (DropTarget drop_target : drop_targets) {
drop_target.setTransfer(new Transfer[] { FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
drop_target.addDropListener(new DropTargetAdapter() {
@Override
public void dropAccept(DropTargetEvent event) {
event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
}
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
if ((event.operations & DND.DROP_LINK) > 0)
event.detail = DND.DROP_LINK;
else if ((event.operations & DND.DROP_COPY) > 0)
event.detail = DND.DROP_COPY;
else if ((event.operations & DND.DROP_DEFAULT) > 0)
event.detail = DND.DROP_COPY;
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
}
@Override
public void dragLeave(DropTargetEvent event) {
}
@Override
public void drop(DropTargetEvent event) {
handleDrop(event.data, new DropAccepter() {
@Override
public void accept(String link) {
input_area.setText(input_area.getText() + link);
}
});
}
});
}
}
Control[] focus_controls = { log, input_area, buddy_table, nickname, shared_nick_button };
Listener focus_listener = new Listener() {
@Override
public void handleEvent(Event event) {
activate();
}
};
for (Control c : focus_controls) {
c.addListener(SWT.FocusIn, focus_listener);
}
BuddyPluginBeta.ChatParticipant[] existing_participants = chat.getParticipants();
synchronized (participants) {
participants.addAll(Arrays.asList(existing_participants));
}
table_resort_required = true;
updateTable(false);
BuddyPluginBeta.ChatMessage[] history = chat.getHistory();
logChatMessages(history);
boolean can_popout = shell == null && public_chat;
if (can_popout && !ftux_ok && !auto_ftux_popout_done) {
auto_ftux_popout_done = true;
try {
createChatWindow(view, plugin, chat.getClone(), true);
} catch (Throwable e) {
}
}
} else {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
GridData grid_data = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(parent, grid_data);
Composite status_area = new Composite(parent, SWT.NULL);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
status_area.setLayoutData(grid_data);
layout = new GridLayout();
layout.numColumns = 3;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 4;
layout.marginLeft = 4;
status_area.setLayout(layout);
buildStatus(parent, status_area);
buildHelp(status_area);
Composite ftux_parent = new Composite(parent, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
ftux_parent.setLayout(layout);
grid_data = new GridData(GridData.FILL_BOTH);
grid_data.horizontalSpan = 2;
ftux_parent.setLayoutData(grid_data);
Composite share_area_holder = buildFTUX(ftux_parent, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0;
share_area_holder.setLayout(layout);
Canvas share_area = new Canvas(share_area_holder, SWT.NO_BACKGROUND);
grid_data = new GridData(GridData.FILL_BOTH);
share_area.setLayoutData(grid_data);
share_area.setBackground(Colors.white);
share_area.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
Rectangle bounds = share_area.getBounds();
int width = bounds.width;
int height = bounds.height;
gc.setBackground(Colors.white);
gc.fillRectangle(0, 0, width, height);
Rectangle text_area = new Rectangle(50, 50, width - 100, height - 100);
gc.setLineWidth(8);
gc.setLineStyle(SWT.LINE_DOT);
gc.setForeground(Colors.light_grey);
gc.drawRoundRectangle(40, 40, width - 80, height - 80, 25, 25);
gc.setForeground(Colors.dark_grey);
gc.setFont(big_font);
String msg = MessageText.getString("dchat.share.dnd.info", new String[] { MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_PUBLIC ? "label.publicly" : "label.anonymously"), chat.getName() });
GCStringPrinter p = new GCStringPrinter(gc, msg, text_area, 0, SWT.CENTER | SWT.WRAP);
p.printString();
}
});
input_area = new Text(share_area, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
input_area.setVisible(false);
hookFTUXListener();
drop_targets = new DropTarget[] { new DropTarget(share_area, DND.DROP_COPY) };
for (DropTarget drop_target : drop_targets) {
drop_target.setTransfer(new Transfer[] { FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
drop_target.addDropListener(new DropTargetAdapter() {
@Override
public void dropAccept(DropTargetEvent event) {
event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
}
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
if ((event.operations & DND.DROP_LINK) > 0)
event.detail = DND.DROP_LINK;
else if ((event.operations & DND.DROP_COPY) > 0)
event.detail = DND.DROP_COPY;
else if ((event.operations & DND.DROP_DEFAULT) > 0)
event.detail = DND.DROP_COPY;
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
}
@Override
public void dragLeave(DropTargetEvent event) {
}
@Override
public void drop(DropTargetEvent event) {
if (!chat_available) {
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("dchat.share.dnd.wait.title"), MessageText.getString("dchat.share.dnd.wait.text"));
mb.setButtons(0, new String[] { MessageText.getString("Button.ok") }, new Integer[] { 0 });
mb.open(null);
return;
}
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("dchat.share.dnd.prompt.title"), MessageText.getString("dchat.share.dnd.prompt.text", new String[] { MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_PUBLIC ? "label.publicly" : "label.anonymously"), chat.getName() }));
mb.setRemember("chat.dnd." + chat.getKey(), false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
mb.setButtons(0, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 0, 1 });
mb.setRememberOnlyIfButton(0);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
handleDrop(event.data, new DropAccepter() {
@Override
public void accept(String link) {
link = link.trim();
sendMessage(link, false);
String rendered = renderMessage(link);
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("dchat.share.dnd.shared.title"), MessageText.getString("dchat.share.dnd.shared.text", new String[] { rendered }));
mb.setButtons(0, new String[] { MessageText.getString("Button.ok") }, new Integer[] { 0 });
mb.open(null);
checkSubscriptions(false);
}
});
}
}
});
}
});
}
}
}
use of org.eclipse.swt.events.KeyListener in project BiglyBT by BiglySoftware.
the class TagSettingsView method swt_initialize.
private void swt_initialize(Composite parent) {
if (cMainComposite == null || cMainComposite.isDisposed()) {
if (parent == null || parent.isDisposed()) {
return;
}
sc = new ScrolledComposite(parent, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(16);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
Utils.setLayoutData(sc, gd);
} else if (parentLayout instanceof FormLayout) {
Utils.setLayoutData(sc, Utils.getFilledFormData());
}
cMainComposite = new Composite(sc, SWT.NONE);
sc.setContent(cMainComposite);
} else {
Utils.disposeComposite(cMainComposite, false);
}
if (tags == null) {
params = null;
cMainComposite.setLayout(new FillLayout());
Label label = new Label(cMainComposite, SWT.NONE);
label.setText(MessageText.getString("tag.settings.select.tag"));
} else {
final int numTags = tags.length;
int isTagVisible = -1;
int canBePublic = -1;
int[] tagColor = tags[0].getColor();
boolean tagsAreTagFeatureRateLimit = true;
Set<String> listTagTypes = new HashSet<>();
for (Tag tag : tags) {
TagType tt = tag.getTagType();
String s = tt.getTagTypeName(true);
listTagTypes.add(s);
if (tagsAreTagFeatureRateLimit && !(tag instanceof TagFeatureRateLimit)) {
tagsAreTagFeatureRateLimit = false;
}
isTagVisible = updateIntBoolean(tag.isVisible(), isTagVisible);
canBePublic = updateIntBoolean(tag.canBePublic(), canBePublic);
if (tagColor != null) {
int[] color = tag.getColor();
if (!Arrays.areEqual(tagColor, color)) {
tagColor = null;
}
}
}
String tagTypes = GeneralUtils.stringJoin(listTagTypes, ", ");
params = new Params();
GridData gd;
GridLayout gridLayout;
gridLayout = new GridLayout(1, false);
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = gridLayout.marginWidth = 0;
cMainComposite.setLayout(gridLayout);
Composite cSection1 = new Composite(cMainComposite, SWT.NONE);
gridLayout = new GridLayout(4, false);
gridLayout.marginHeight = 0;
cSection1.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
cSection1.setLayoutData(gd);
Composite cSection2 = new Composite(cMainComposite, SWT.NONE);
gridLayout = new GridLayout(4, false);
cSection2.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
cSection2.setLayoutData(gd);
Label label;
// Field: Tag Type
label = new Label(cSection1, SWT.NONE);
FontUtils.setFontHeight(label, 12, SWT.BOLD);
gd = new GridData();
gd.horizontalSpan = 4;
Utils.setLayoutData(label, gd);
label.setText(tagTypes);
// Field: Name
label = new Label(cSection1, SWT.NONE);
Messages.setLanguageText(label, "MinimizedWindow.name");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
if (numTags == 1 && !tags[0].getTagType().isTagTypeAuto()) {
Text txtName = new Text(cSection1, SWT.BORDER);
params.cName = txtName;
gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
Utils.setLayoutData(txtName, gd);
txtName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
try {
String newName = ((Text) e.widget).getText();
if (!tags[0].getTagName(true).equals(newName)) {
tags[0].setTagName(newName);
}
} catch (TagException e1) {
Debug.out(e1);
}
}
});
} else {
label = new Label(cSection1, SWT.WRAP);
gd = Utils.getWrappableLabelGridData(1, GridData.GRAB_HORIZONTAL);
Utils.setLayoutData(label, gd);
params.cName = label;
}
// Field: Color
label = new Label(cSection1, SWT.NONE);
Messages.setLanguageText(label, "label.color");
if (tagColor == null) {
tagColor = new int[] { 0, 0, 0 };
}
params.tagColor = new ColorParameter(cSection1, null, tagColor[0], tagColor[1], tagColor[2]) {
// @see com.biglybt.ui.swt.config.ColorParameter#newColorChosen(org.eclipse.swt.graphics.RGB)
@Override
public void newColorChosen(RGB newColor) {
for (Tag tag : tags) {
tag.setColor(new int[] { newColor.red, newColor.green, newColor.blue });
}
}
};
// Field: Visible
params.viewInSideBar = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int isTagVisible = -1;
for (Tag tag : tags) {
isTagVisible = updateIntBoolean(tag.isVisible(), isTagVisible);
}
return isTagVisible == 2 ? null : (isTagVisible == 1);
}
@Override
public void setBooleanValue(String key, boolean value) {
for (Tag tag : tags) {
tag.setVisible(value);
}
}
}, cSection2, null, "TagSettings.viewInSideBar");
gd = new GridData();
gd.horizontalSpan = 4;
params.viewInSideBar.setLayoutData(gd);
// Field: Public
if (canBePublic == 1) {
params.isPublic = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int val = -1;
for (Tag tag : tags) {
val = updateIntBoolean(tag.isPublic(), val);
}
return val == 2 ? null : (val == 1);
}
@Override
public void setBooleanValue(String key, boolean value) {
for (Tag tag : tags) {
tag.setPublic(value);
}
}
}, cSection2, null, "TagAddWindow.public.checkbox");
gd = new GridData();
gd.horizontalSpan = 4;
params.isPublic.setLayoutData(gd);
}
// //////////////////
Group gTransfer = new Group(cMainComposite, SWT.NONE);
gTransfer.setText(MessageText.getString("label.transfer.settings"));
gridLayout = new GridLayout(6, false);
gTransfer.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gTransfer.setLayoutData(gd);
if (tagsAreTagFeatureRateLimit) {
final TagFeatureRateLimit[] rls = new TagFeatureRateLimit[tags.length];
System.arraycopy(tags, 0, rls, 0, tags.length);
boolean supportsTagDownloadLimit = true;
boolean supportsTagUploadLimit = true;
boolean hasTagUploadPriority = true;
for (TagFeatureRateLimit rl : rls) {
supportsTagDownloadLimit &= rl.supportsTagDownloadLimit();
supportsTagUploadLimit &= rl.supportsTagUploadLimit();
hasTagUploadPriority &= rl.getTagUploadPriority() >= 0;
}
String k_unit = DisplayFormatters.getRateUnitBase10(DisplayFormatters.UNIT_KB).trim();
int cols_used = 0;
// Field: Download Limit
if (supportsTagDownloadLimit) {
gd = new GridData();
label = new Label(gTransfer, SWT.NULL);
Utils.setLayoutData(label, gd);
label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxdownloadspeed.tooltip"));
gd = new GridData();
// gd.horizontalSpan = 3;
params.maxDownloadSpeed = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
int limit = rls[0].getTagDownloadLimit();
if (numTags > 1) {
for (int i = 1; i < rls.length; i++) {
int nextLimit = rls[i].getTagDownloadLimit();
if (nextLimit != limit) {
return 0;
}
}
}
return limit < 0 ? limit : limit / DisplayFormatters.getKinB();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
for (TagFeatureRateLimit rl : rls) {
if (value == -1) {
rl.setTagDownloadLimit(-1);
} else {
rl.setTagDownloadLimit(value * DisplayFormatters.getKinB());
}
}
}
@Override
public boolean resetIntDefault(String key) {
return false;
}
}, gTransfer, null, -1, Integer.MAX_VALUE);
params.maxDownloadSpeed.setLayoutData(gd);
params.maxDownloadSpeed.setZeroHidden(numTags > 1);
cols_used += 2;
}
// Upload Limit
if (supportsTagUploadLimit) {
gd = new GridData();
label = new Label(gTransfer, SWT.NULL);
Utils.setLayoutData(label, gd);
label.setText(k_unit + " " + MessageText.getString("GeneralView.label.maxuploadspeed.tooltip"));
gd = new GridData();
// gd.horizontalSpan = 3;
params.maxUploadSpeed = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
int limit = rls[0].getTagUploadLimit();
if (numTags > 1) {
for (int i = 1; i < rls.length; i++) {
int nextLimit = rls[i].getTagUploadLimit();
if (nextLimit != limit) {
return 0;
}
}
}
return limit < 0 ? limit : limit / DisplayFormatters.getKinB();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
for (TagFeatureRateLimit rl : rls) {
if (value == -1) {
rl.setTagUploadLimit(value);
} else {
rl.setTagUploadLimit(value * DisplayFormatters.getKinB());
}
}
}
@Override
public boolean resetIntDefault(String key) {
return false;
}
}, gTransfer, null, -1, Integer.MAX_VALUE);
params.maxUploadSpeed.setLayoutData(gd);
params.maxUploadSpeed.setZeroHidden(numTags > 1);
cols_used += 2;
}
// Field: Upload Priority
if (hasTagUploadPriority) {
params.uploadPriority = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
int value = -1;
for (TagFeatureRateLimit rl : rls) {
value = updateIntBoolean(rl.getTagUploadPriority() > 0, value);
}
return value == 2 ? null : value == 1;
}
@Override
public void setBooleanValue(String key, boolean value) {
for (TagFeatureRateLimit rl : rls) {
rl.setTagUploadPriority(value ? 1 : 0);
}
}
}, gTransfer, null, "cat.upload.priority");
gd = new GridData();
gd.horizontalSpan = 6 - cols_used;
params.uploadPriority.setLayoutData(gd);
}
// Field: Min Share
if (numTags == 1 && rls[0].getTagMinShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.min_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.min_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMinShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMinShareRatio((int) (value * 1000));
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.min_sr.setLayoutData(gd);
}
// Field: Max Share
if (numTags == 1 && rls[0].getTagMaxShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMaxShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMaxShareRatio((int) (value * 1000));
updateTagSRParams(params);
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.max_sr.setLayoutData(gd);
// max sr action
String[] ST_ACTION_VALUES = { "" + TagFeatureRateLimit.SR_ACTION_QUEUE, "" + TagFeatureRateLimit.SR_ACTION_PAUSE, "" + TagFeatureRateLimit.SR_ACTION_STOP };
String[] ST_ACTION_LABELS = { MessageText.getString("ConfigView.section.queue"), MessageText.getString("v3.MainWindow.button.pause"), MessageText.getString("v3.MainWindow.button.stop") };
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.when.exceeded");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_sr_action = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
return ("" + rls[0].getTagMaxShareRatioAction());
}
@Override
public void setStringListValue(String key, String value) {
rls[0].setTagMaxShareRatioAction(Integer.parseInt(value));
}
}, gTransfer, "max_sr_action", "" + TagFeatureRateLimit.SR_INDIVIDUAL_ACTION_DEFAULT, ST_ACTION_LABELS, ST_ACTION_VALUES);
}
// Field: Max Aggregate Share
if (numTags == 1 && rls[0].getTagAggregateShareRatio() >= 0) {
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_aggregate_sr");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr = new GenericFloatParameter(new GenericParameterAdapter() {
@Override
public float getFloatValue(String key) {
return rls[0].getTagMaxAggregateShareRatio() / 1000f;
}
@Override
public void setFloatValue(String key, float value) {
rls[0].setTagMaxAggregateShareRatio((int) (value * 1000));
updateTagSRParams(params);
}
}, gTransfer, null, 0, Float.MAX_VALUE, true, 3);
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 75;
params.max_aggregate_sr.setLayoutData(gd);
// max sr action
String[] ST_ACTION_VALUES = { "" + TagFeatureRateLimit.SR_ACTION_PAUSE, "" + TagFeatureRateLimit.SR_ACTION_STOP };
String[] ST_ACTION_LABELS = { MessageText.getString("v3.MainWindow.button.pause"), MessageText.getString("v3.MainWindow.button.stop") };
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.when.exceeded");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr_action = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
return ("" + rls[0].getTagMaxAggregateShareRatioAction());
}
@Override
public void setStringListValue(String key, String value) {
rls[0].setTagMaxAggregateShareRatioAction(Integer.parseInt(value));
}
}, gTransfer, "max_aggregate_sr_action", "" + TagFeatureRateLimit.SR_AGGREGATE_ACTION_DEFAULT, ST_ACTION_LABELS, ST_ACTION_VALUES);
// aggregate has priority
label = new Label(gTransfer, SWT.NONE);
Messages.setLanguageText(label, "label.aggregate.has.priority");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.max_aggregate_sr_priority = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return (rls[0].getTagMaxAggregateShareRatioHasPriority());
}
@Override
public void setBooleanValue(String key, boolean value) {
rls[0].setTagMaxAggregateShareRatioHasPriority(value);
}
}, gTransfer, "max_aggregate_sr_priority", TagFeatureRateLimit.AT_RATELIMIT_MAX_AGGREGATE_SR_PRIORITY_DEFAULT);
updateTagSRParams(params);
}
}
if (numTags == 1 && (tags[0] instanceof TagFeatureFileLocation)) {
final TagFeatureFileLocation fl = (TagFeatureFileLocation) tags[0];
if (fl.supportsTagCopyOnComplete() || fl.supportsTagInitialSaveFolder() || fl.supportsTagMoveOnComplete()) {
Group gFiles = new Group(cMainComposite, SWT.NONE);
gFiles.setText(MessageText.getString("label.file.settings"));
gridLayout = new GridLayout(6, false);
gFiles.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, 4, 1);
Utils.setLayoutData(gFiles, gd);
if (fl.supportsTagInitialSaveFolder()) {
params.initalSaveFolder = new folderOption(gFiles, "label.init.save.loc") {
@Override
public void setFolder(File folder) {
params.initalSaveData.setEnabled(folder != null);
params.initalSaveTorrent.setEnabled(folder != null);
fl.setTagInitialSaveFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagInitialSaveFolder();
params.initalSaveData.setEnabled(result != null);
params.initalSaveTorrent.setEnabled(result != null);
return (result);
}
};
params.initalSaveData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagInitialSaveOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagInitialSaveOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagInitialSaveOptions(flags);
}
}, gFiles, null, "label.move.data");
params.initalSaveTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagInitialSaveOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagInitialSaveOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagInitialSaveOptions(flags);
}
}, gFiles, null, "label.move.torrent");
}
if (fl.supportsTagMoveOnComplete()) {
params.moveOnCompleteFolder = new folderOption(gFiles, "label.move.on.comp") {
@Override
public void setFolder(File folder) {
params.moveOnCompleteData.setEnabled(folder != null);
params.moveOnCompleteTorrent.setEnabled(folder != null);
fl.setTagMoveOnCompleteFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagMoveOnCompleteFolder();
params.moveOnCompleteData.setEnabled(result != null);
params.moveOnCompleteTorrent.setEnabled(result != null);
return (result);
}
};
params.moveOnCompleteData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagMoveOnCompleteOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagMoveOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagMoveOnCompleteOptions(flags);
}
}, gFiles, null, "label.move.data");
params.moveOnCompleteTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagMoveOnCompleteOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagMoveOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagMoveOnCompleteOptions(flags);
}
}, gFiles, null, "label.move.torrent");
}
if (fl.supportsTagCopyOnComplete()) {
params.copyOnCompleteFolder = new folderOption(gFiles, "label.copy.on.comp") {
@Override
public void setFolder(File folder) {
params.copyOnCompleteData.setEnabled(folder != null);
params.copyOnCompleteTorrent.setEnabled(folder != null);
fl.setTagCopyOnCompleteFolder(folder);
}
@Override
public File getFolder() {
File result = fl.getTagCopyOnCompleteFolder();
params.copyOnCompleteData.setEnabled(result != null);
params.copyOnCompleteTorrent.setEnabled(result != null);
return (result);
}
};
params.copyOnCompleteData = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagCopyOnCompleteOptions() & TagFeatureFileLocation.FL_DATA) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagCopyOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_DATA;
} else {
flags &= ~TagFeatureFileLocation.FL_DATA;
}
fl.setTagCopyOnCompleteOptions(flags);
}
}, gFiles, null, "label.copy.data");
params.copyOnCompleteTorrent = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((fl.getTagCopyOnCompleteOptions() & TagFeatureFileLocation.FL_TORRENT) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
long flags = fl.getTagCopyOnCompleteOptions();
if (value) {
flags |= TagFeatureFileLocation.FL_TORRENT;
} else {
flags &= ~TagFeatureFileLocation.FL_TORRENT;
}
fl.setTagCopyOnCompleteOptions(flags);
}
}, gFiles, null, "label.copy.torrent");
}
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_PROPERTIES) && (tags[0] instanceof TagFeatureProperties)) {
TagFeatureProperties tfp = (TagFeatureProperties) tags[0];
final TagProperty propConstraint = tfp.getProperty(TagFeatureProperties.PR_CONSTRAINT);
if (propConstraint != null) {
Group gConstraint = new Group(cMainComposite, SWT.NONE);
Messages.setLanguageText(gConstraint, "tag.property.constraint");
int columns = 6;
gridLayout = new GridLayout(columns, false);
gConstraint.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, 4, 1);
Utils.setLayoutData(gConstraint, gd);
params.constraints = new Text(gConstraint, SWT.WRAP | SWT.BORDER | SWT.MULTI);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, columns, 1);
gd.heightHint = 40;
Utils.setLayoutData(params.constraints, gd);
params.constraints.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
params.constraints.setData("skipset", 1);
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(true);
btnResetConstraint.setEnabled(true);
}
}
});
params.constraintError = new Label(gConstraint, SWT.NULL);
params.constraintError.setForeground(Colors.colorError);
gd = new GridData(SWT.FILL, SWT.NONE, true, false, columns, 1);
Utils.setLayoutData(params.constraintError, gd);
btnSaveConstraint = new Button(gConstraint, SWT.PUSH);
btnSaveConstraint.setEnabled(false);
btnSaveConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String constraint = params.constraints.getText().trim();
String[] old_value = propConstraint.getStringList();
if (constraint.length() == 0) {
propConstraint.setStringList(null);
} else {
String old_options = old_value.length > 1 && old_value[1] != null ? old_value[1] : "";
if (old_options.length() == 0) {
old_options = CM_ADD_REMOVE;
}
propConstraint.setStringList(new String[] { constraint, old_options });
}
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(false);
btnResetConstraint.setEnabled(false);
}
}
});
Messages.setLanguageText(btnSaveConstraint, "Button.save");
btnResetConstraint = new Button(gConstraint, SWT.PUSH);
btnResetConstraint.setEnabled(false);
btnResetConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
params.constraints.setData("skipset", null);
swt_updateFields();
if (btnSaveConstraint != null && !btnSaveConstraint.isDisposed()) {
btnSaveConstraint.setEnabled(false);
btnResetConstraint.setEnabled(false);
}
}
});
Messages.setLanguageText(btnResetConstraint, "Button.reset");
params.constraintEnabled = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return (propConstraint.isEnabled());
}
@Override
public void setBooleanValue(String key, boolean value) {
propConstraint.setEnabled(value);
}
}, gConstraint, null, "label.enabled");
Label constraintMode = new Label(gConstraint, SWT.NULL);
Messages.setLanguageText(constraintMode, "label.scope");
String[] CM_VALUES = { CM_ADD_REMOVE, CM_ADD_ONLY, CM_REMOVE_ONLY };
String[] CM_LABELS = { MessageText.getString("label.addition.and.removal"), MessageText.getString("label.addition.only"), MessageText.getString("label.removal.only") };
params.constraintMode = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public String getStringListValue(String key) {
String[] list = propConstraint.getStringList();
if (list.length > 1 && list[1] != null) {
return (list[1]);
} else {
return (CM_ADD_REMOVE);
}
}
@Override
public void setStringListValue(String key, String value) {
if (value == null || value.length() == 0) {
value = CM_ADD_REMOVE;
}
String[] list = propConstraint.getStringList();
propConstraint.setStringList(new String[] { list != null && list.length > 0 ? list[0] : "", value });
}
}, gConstraint, "tag_constraint_action_mode", CM_ADD_REMOVE, CM_LABELS, CM_VALUES);
Link lblAboutConstraint = new Link(gConstraint, SWT.WRAP);
Utils.setLayoutData(lblAboutConstraint, Utils.getWrappableLabelGridData(1, GridData.GRAB_HORIZONTAL));
lblAboutConstraint.setText(MessageText.getString("tag.constraints.info"));
lblAboutConstraint.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_LIMITS)) {
final TagFeatureLimits tfl = (TagFeatureLimits) tags[0];
if (tfl.getMaximumTaggables() >= 0) {
// ///////////////////////////// limits
Group gLimits = new Group(cMainComposite, SWT.NONE);
gLimits.setText(MessageText.getString("label.limit.settings"));
gridLayout = new GridLayout(6, false);
gLimits.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gLimits.setLayoutData(gd);
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "TableColumn.header.max_taggables");
gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
Utils.setLayoutData(label, gd);
params.tfl_max_taggables = new GenericIntParameter(new GenericParameterAdapter() {
@Override
public int getIntValue(String key) {
return tfl.getMaximumTaggables();
}
@Override
public int getIntValue(String key, int def) {
return getIntValue(key);
}
@Override
public void setIntValue(String key, int value) {
tfl.setMaximumTaggables(value);
}
}, gLimits, null, 0, Integer.MAX_VALUE);
// we really don't want partial values to be set as the consequences may be very
// unwanted if a removal policy is already set...
params.tfl_max_taggables.disableTimedSave();
gd = new GridData();
// gd.horizontalSpan = 3;
gd.widthHint = 50;
params.tfl_max_taggables.setLayoutData(gd);
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "label.removal.policy");
params.tfl_removal_policy = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key) {
return (String.valueOf(tfl.getRemovalStrategy()));
}
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public void setStringListValue(String key, String value) {
tfl.setRemovalStrategy(value == null ? TagFeatureLimits.RS_DEFAULT : Integer.parseInt(value));
}
}, gLimits, null, new String[] { "", MessageText.getString("MyTorrentsView.menu.archive"), MessageText.getString("Button.deleteContent.fromLibrary"), MessageText.getString("Button.deleteContent.fromComputer"), MessageText.getString("label.move.to.old.tag") }, new String[] { "0", "1", "2", "3", "4" });
label = new Label(gLimits, SWT.NONE);
Messages.setLanguageText(label, "label.ordering");
params.tfl_ordering = new GenericStringListParameter(new GenericParameterAdapter() {
@Override
public String getStringListValue(String key) {
return (String.valueOf(tfl.getOrdering()));
}
@Override
public String getStringListValue(String key, String def) {
return (getStringListValue(key));
}
@Override
public void setStringListValue(String key, String value) {
tfl.setOrdering(value == null ? TagFeatureLimits.OP_DEFAULT : Integer.parseInt(value));
}
}, gLimits, null, new String[] { MessageText.getString("label.time.added.to.vuze"), MessageText.getString("label.time.added.to.tag") }, new String[] { "0", "1" });
}
}
if (numTags == 1 && tags[0].getTagType().hasTagTypeFeature(TagFeature.TF_NOTIFICATIONS)) {
final TagFeatureNotifications tfn = (TagFeatureNotifications) tags[0];
// notifications
Group gNotifications = new Group(cMainComposite, SWT.NONE);
gNotifications.setText(MessageText.getString("v3.MainWindow.tab.events"));
gridLayout = new GridLayout(6, false);
gNotifications.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.NONE, false, false, 4, 1);
gNotifications.setLayoutData(gd);
label = new Label(gNotifications, SWT.NONE);
label.setText(MessageText.getString("tag.notification.post") + ":");
params.notification_post_add = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((tfn.getPostingNotifications() & TagFeatureNotifications.NOTIFY_ON_ADD) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
int flags = tfn.getPostingNotifications();
if (value) {
flags |= TagFeatureNotifications.NOTIFY_ON_ADD;
} else {
flags &= ~TagFeatureNotifications.NOTIFY_ON_ADD;
}
tfn.setPostingNotifications(flags);
}
}, gNotifications, null, "label.on.addition");
params.notification_post_remove = new GenericBooleanParameter(new BooleanParameterAdapter() {
@Override
public Boolean getBooleanValue(String key) {
return ((tfn.getPostingNotifications() & TagFeatureNotifications.NOTIFY_ON_REMOVE) != 0);
}
@Override
public void setBooleanValue(String key, boolean value) {
int flags = tfn.getPostingNotifications();
if (value) {
flags |= TagFeatureNotifications.NOTIFY_ON_REMOVE;
} else {
flags &= ~TagFeatureNotifications.NOTIFY_ON_REMOVE;
}
tfn.setPostingNotifications(flags);
}
}, gNotifications, null, "label.on.removal");
}
swt_updateFields();
}
cMainComposite.layout();
Rectangle r = sc.getClientArea();
sc.setMinSize(cMainComposite.computeSize(r.width, SWT.DEFAULT));
}
use of org.eclipse.swt.events.KeyListener in project BiglyBT by BiglySoftware.
the class SubscriptionsView method initialize.
private void initialize(Composite parent) {
viewComposite = new Composite(parent, SWT.NONE);
viewComposite.setLayout(new FormLayout());
TableColumnCore[] columns = new TableColumnCore[] { new ColumnSubscriptionNew(TABLE_ID), new ColumnSubscriptionName(TABLE_ID), new ColumnSubscriptionNbNewResults(TABLE_ID), new ColumnSubscriptionNbResults(TABLE_ID), new ColumnSubscriptionMaxResults(TABLE_ID), new ColumnSubscriptionLastChecked(TABLE_ID), new ColumnSubscriptionSubscribers(TABLE_ID), new ColumnSubscriptionEnabled(TABLE_ID), new ColumnSubscriptionAutoDownload(TABLE_ID), new ColumnSubscriptionCategory(TABLE_ID), new ColumnSubscriptionTag(TABLE_ID), new ColumnSubscriptionParent(TABLE_ID), new ColumnSubscriptionError(TABLE_ID) };
TableColumnManager tcm = TableColumnManager.getInstance();
tcm.setDefaultColumnNames(TABLE_ID, new String[] { ColumnSubscriptionNew.COLUMN_ID, ColumnSubscriptionName.COLUMN_ID, ColumnSubscriptionNbNewResults.COLUMN_ID, ColumnSubscriptionNbResults.COLUMN_ID, ColumnSubscriptionAutoDownload.COLUMN_ID });
view = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_ID, TABLE_ID, columns, "name", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
view.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
switch(eventType) {
case EVENT_TABLELIFECYCLE_INITIALIZED:
SubscriptionManagerFactory.getSingleton().addListener(SubscriptionsView.this);
view.addDataSources(SubscriptionManagerFactory.getSingleton().getSubscriptions(true));
break;
case EVENT_TABLELIFECYCLE_DESTROYED:
SubscriptionManagerFactory.getSingleton().removeListener(SubscriptionsView.this);
break;
}
}
});
view.addSelectionListener(new TableSelectionAdapter() {
PluginInterface pi = PluginInitializer.getDefaultInterface();
UIManager uim = pi.getUIManager();
MenuManager menu_manager = uim.getMenuManager();
TableManager table_manager = uim.getTableManager();
ArrayList<TableContextMenuItem> menu_items = new ArrayList<>();
SubscriptionManagerUI.MenuCreator menu_creator = new SubscriptionManagerUI.MenuCreator() {
@Override
public com.biglybt.pif.ui.menus.MenuItem createMenu(String resource_id) {
TableContextMenuItem menu = table_manager.addContextMenuItem(TABLE_ID, resource_id);
menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_items.add(menu);
return (menu);
}
@Override
public void refreshView() {
}
};
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
TableRowCore row = rows[0];
Subscription sub = (Subscription) row.getDataSource();
if (sub == null) {
return;
}
if (sub.isSearchTemplate()) {
try {
VuzeFile vf = sub.getSearchTemplateVuzeFile();
if (vf != null) {
sub.setSubscribed(true);
VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
for (VuzeFileComponent comp : vf.getComponents()) {
Engine engine = (Engine) comp.getData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY);
if (engine != null && (engine.getSelectionState() == Engine.SEL_STATE_DESELECTED || engine.getSelectionState() == Engine.SEL_STATE_FORCE_DESELECTED)) {
engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
} else {
String key = "Subscription_" + ByteFormatter.encodeString(sub.getPublicKey());
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi != null) {
mdi.showEntryByID(key);
}
}
}
}
@Override
public void selected(TableRowCore[] rows) {
rows = view.getSelectedRows();
ISelectedContent[] sels = new ISelectedContent[rows.length];
java.util.List<Subscription> subs = new ArrayList<>();
for (int i = 0; i < rows.length; i++) {
Subscription sub = (Subscription) rows[i].getDataSource();
sels[i] = new SubscriptionSelectedContent(sub);
if (sub != null) {
subs.add(sub);
}
}
SelectedContentManager.changeCurrentlySelectedContent(view.getTableID(), sels, view);
for (TableContextMenuItem mi : menu_items) {
mi.remove();
}
if (subs.size() > 0) {
SubscriptionManagerUI.createMenus(menu_manager, menu_creator, subs.toArray(new Subscription[0]));
}
}
}, false);
view.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent event) {
}
@Override
public void keyReleased(KeyEvent event) {
if (event.keyCode == SWT.DEL) {
removeSelected();
}
}
});
view.setRowDefaultHeightEM(1.4f);
view.initialize(viewComposite);
final Composite composite = new Composite(viewComposite, SWT.BORDER);
composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
composite.setBackground(ColorCache.getColor(composite.getDisplay(), "#F1F9F8"));
Font font = composite.getFont();
FontData[] fDatas = font.getFontData();
for (int i = 0; i < fDatas.length; i++) {
fDatas[i].setHeight(150 * fDatas[i].getHeight() / 100);
if (Constants.isWindows) {
fDatas[i].setStyle(SWT.BOLD);
}
}
textFont1 = new Font(composite.getDisplay(), fDatas);
fDatas = font.getFontData();
for (int i = 0; i < fDatas.length; i++) {
fDatas[i].setHeight(120 * fDatas[i].getHeight() / 100);
}
textFont2 = new Font(composite.getDisplay(), fDatas);
Label preText = new Label(composite, SWT.NONE);
preText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
preText.setFont(textFont1);
preText.setText(MessageText.getString("subscriptions.view.help.1"));
Label image = new Label(composite, SWT.NONE);
ImageLoader.getInstance().setLabelImage(image, "btn_rss_add");
Link postText = new Link(composite, SWT.NONE);
postText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
postText.setFont(textFont2);
postText.setText(MessageText.getString("subscriptions.view.help.2"));
postText.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
Label close = new Label(composite, SWT.NONE);
ImageLoader.getInstance().setLabelImage(close, "image.dismissX");
close.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
close.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
COConfigurationManager.setParameter("subscriptions.view.showhelp", false);
composite.setVisible(false);
FormData data = (FormData) view.getComposite().getLayoutData();
data.bottom = new FormAttachment(100, 0);
viewComposite.layout(true);
}
});
FormLayout layout = new FormLayout();
composite.setLayout(layout);
FormData data;
data = new FormData();
data.left = new FormAttachment(0, 15);
data.top = new FormAttachment(0, 20);
data.bottom = new FormAttachment(postText, -5);
preText.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(preText, 5);
data.top = new FormAttachment(preText, 0, SWT.CENTER);
image.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(preText, 0, SWT.LEFT);
// data.top = new FormAttachment(preText,5);
data.bottom = new FormAttachment(100, -20);
postText.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -10);
data.top = new FormAttachment(0, 10);
close.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(0, 0);
data.bottom = new FormAttachment(composite, 0);
viewComposite.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
composite.setLayoutData(data);
COConfigurationManager.setBooleanDefault("subscriptions.view.showhelp", true);
if (!COConfigurationManager.getBooleanParameter("subscriptions.view.showhelp")) {
composite.setVisible(false);
data = (FormData) viewComposite.getLayoutData();
data.bottom = new FormAttachment(100, 0);
viewComposite.layout(true);
}
}
use of org.eclipse.swt.events.KeyListener in project BiglyBT by BiglySoftware.
the class SBC_ActivityTableView method skinObjectInitialShow.
// @see SkinView#skinObjectInitialShow(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
skinObject.addListener(new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, getCurrentlySelectedContent(), view);
} else if (eventType == SWTSkinObjectListener.EVENT_HIDE) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, null, view);
}
return null;
}
});
SWTSkinObject soParent = skinObject.getParent();
Object data = soParent.getControl().getData("ViewMode");
if (data instanceof Long) {
viewMode = (int) ((Long) data).longValue();
}
boolean big = viewMode == SBC_ActivityView.MODE_BIGTABLE;
tableID = big ? TableManager.TABLE_ACTIVITY_BIG : TableManager.TABLE_ACTIVITY;
TableColumnCore[] columns = big ? TableColumnCreatorV3.createActivityBig(tableID) : TableColumnCreatorV3.createActivitySmall(tableID);
view = TableViewFactory.createTableViewSWT(ActivitiesEntry.class, tableID, tableID, columns, "name", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
view.setRowDefaultHeightEM(big ? 3 : 2);
view.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
removeSelected();
} else if (e.keyCode == SWT.F5) {
if ((e.stateMask & SWT.SHIFT) != 0) {
ActivitiesManager.resetRemovedEntries();
}
if ((e.stateMask & SWT.CONTROL) != 0) {
System.out.println("pull all vuze news entries");
ActivitiesManager.clearLastPullTimes();
ActivitiesManager.pullActivitiesNow(0, "^F5", true);
} else {
System.out.println("pull latest vuze news entries");
ActivitiesManager.pullActivitiesNow(0, "F5", true);
}
}
}
});
view.addSelectionListener(new TableSelectionAdapter() {
// @see TableSelectionAdapter#selected(TableRowCore[])
@Override
public void selected(TableRowCore[] rows) {
selectionChanged();
for (int i = 0; i < rows.length; i++) {
ActivitiesEntry entry = (ActivitiesEntry) rows[i].getDataSource(true);
if (entry != null && !entry.isRead() && entry.canFlipRead()) {
entry.setRead(true);
}
}
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
ActivitiesEntry ds = (ActivitiesEntry) rows[0].getDataSource();
if (ds.getTypeID().equals(ActivitiesConstants.TYPEID_LOCALNEWS)) {
String[] actions = ds.getActions();
if (actions.length == 1) {
ds.invokeCallback(actions[0]);
}
} else {
TorrentListViewsUtils.playOrStreamDataSource(ds, false);
}
}
}
@Override
public void deselected(TableRowCore[] rows) {
selectionChanged();
}
public void selectionChanged() {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
ISelectedContent[] contents = getCurrentlySelectedContent();
if (soMain.isVisible()) {
SelectedContentManager.changeCurrentlySelectedContent(tableID, contents, view);
}
}
});
}
}, false);
view.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
switch(eventType) {
case EVENT_TABLELIFECYCLE_INITIALIZED:
view.addDataSources(ActivitiesManager.getAllEntries().toArray(new ActivitiesEntry[0]));
ActivitiesManager.addListener(SBC_ActivityTableView.this);
break;
case EVENT_TABLELIFECYCLE_DESTROYED:
ActivitiesManager.removeListener(SBC_ActivityTableView.this);
break;
}
}
});
SWTSkinObjectContainer soContents = new SWTSkinObjectContainer(skin, skin.getSkinProperties(), getUpdateUIName(), "", soMain);
skin.layout();
viewComposite = soContents.getComposite();
viewComposite.setBackground(Colors.getSystemColor(viewComposite.getDisplay(), SWT.COLOR_WIDGET_BACKGROUND));
viewComposite.setForeground(Colors.getSystemColor(viewComposite.getDisplay(), SWT.COLOR_WIDGET_FOREGROUND));
viewComposite.setLayoutData(Utils.getFilledFormData());
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
viewComposite.setLayout(gridLayout);
view.initialize(viewComposite);
return null;
}
use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class DataClusterComposite method createFirstPart.
protected void createFirstPart(Composite composite) {
FormToolkit toolkit = WidgetFactory.getWidgetFactory();
// We do not implement IFormPart: we do not care about lifecycle management
Composite compFirstLine = toolkit.createComposite(composite, SWT.NONE);
compFirstLine.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
compFirstLine.setLayout(new GridLayout(10, false));
// from
Label fromLabel = toolkit.createLabel(compFirstLine, Messages.DataClusterBrowserMainPage_1, SWT.NULL);
fromLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
CalendarSelectWidget fromCalendar = new CalendarSelectWidget(toolkit, compFirstLine, true);
fromText = fromCalendar.getText();
fromText.addKeyListener(keylistener);
// to
Label toLabel = toolkit.createLabel(compFirstLine, Messages.DataClusterBrowserMainPage_2, SWT.NULL);
toLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
CalendarSelectWidget toCalendar = new CalendarSelectWidget(toolkit, compFirstLine, false);
toText = toCalendar.getText();
toText.addKeyListener(keylistener);
Label conceptLabel = toolkit.createLabel(compFirstLine, Messages.DataClusterBrowserMainPage_3, SWT.NULL);
conceptLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
conceptCombo = new Combo(compFirstLine, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.MULTI);
conceptCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
// ((GridData) conceptCombo.getLayoutData()).widthHint = 180;
conceptCombo.addKeyListener(keylistener);
// refresh
// search
// $NON-NLS-1$
Button refreshBun = toolkit.createButton(compFirstLine, "", SWT.CENTER);
refreshBun.setImage(ImageCache.getCreatedImage(EImage.REFRESH.getPath()));
refreshBun.setToolTipText(Messages.XObjectBrowser_Refresh);
refreshBun.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
refreshBun.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
refreshData();
}
});
// search
// $NON-NLS-1$
Button bSearch = toolkit.createButton(compFirstLine, "", SWT.CENTER);
bSearch.setImage(ImageCache.getCreatedImage(EImage.BROWSE.getPath()));
bSearch.setToolTipText(Messages.DataClusterBrowserMainPage_4);
bSearch.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
bSearch.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
pageToolBar.reset();
doSearch();
}
});
}
Aggregations