Search in sources :

Example 31 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project eclipse.platform.swt by eclipse.

the class Tab method log.

/**
 * Logs an untyped event to the event console.
 */
void log(Event event) {
    int i = 0;
    while (i < EVENT_INFO.length) {
        if (EVENT_INFO[i].type == event.type)
            break;
        i++;
    }
    String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
    if (!untypedEvents) {
        switch(event.type) {
            case SWT.KeyDown:
            case SWT.KeyUp:
                toString += new KeyEvent(event).toString();
                break;
            case SWT.MouseDown:
            case SWT.MouseUp:
            case SWT.MouseMove:
            case SWT.MouseEnter:
            case SWT.MouseExit:
            case SWT.MouseDoubleClick:
            case SWT.MouseWheel:
            case SWT.MouseHover:
                toString += new MouseEvent(event).toString();
                break;
            case SWT.Paint:
                toString += new PaintEvent(event).toString();
                break;
            case SWT.Move:
            case SWT.Resize:
                toString += new ControlEvent(event).toString();
                break;
            case SWT.Dispose:
                toString += new DisposeEvent(event).toString();
                break;
            case SWT.Selection:
            case SWT.DefaultSelection:
                toString += new SelectionEvent(event).toString();
                break;
            case SWT.FocusIn:
            case SWT.FocusOut:
                toString += new FocusEvent(event).toString();
                break;
            case SWT.Expand:
            case SWT.Collapse:
                toString += new TreeEvent(event).toString();
                break;
            case SWT.Iconify:
            case SWT.Deiconify:
            case SWT.Close:
            case SWT.Activate:
            case SWT.Deactivate:
                toString += new ShellEvent(event).toString();
                break;
            case SWT.Show:
            case SWT.Hide:
                toString += (event.widget instanceof Menu) ? new MenuEvent(event).toString() : event.toString();
                break;
            case SWT.Modify:
                toString += new ModifyEvent(event).toString();
                break;
            case SWT.Verify:
                toString += new VerifyEvent(event).toString();
                break;
            case SWT.Help:
                toString += new HelpEvent(event).toString();
                break;
            case SWT.Arm:
                toString += new ArmEvent(event).toString();
                break;
            case SWT.Traverse:
                toString += new TraverseEvent(event).toString();
                break;
            case SWT.HardKeyDown:
            case SWT.HardKeyUp:
            case SWT.DragDetect:
            case SWT.MenuDetect:
            case SWT.SetData:
            default:
                toString += event.toString();
        }
    } else {
        toString += event.toString();
    }
    log(toString);
    /* Return values for event fields. */
    int mask = EVENT_INFO[i].setFields;
    if (!ignore && mask != 0) {
        Event setFieldsEvent = EVENT_INFO[i].event;
        if ((mask & DOIT) != 0)
            event.doit = setFieldsEvent.doit;
        if ((mask & DETAIL) != 0)
            event.detail = setFieldsEvent.detail;
        if ((mask & TEXT) != 0)
            event.text = setFieldsEvent.text;
        if ((mask & X) != 0)
            event.x = setFieldsEvent.x;
        if ((mask & Y) != 0)
            event.y = setFieldsEvent.y;
        if ((mask & WIDTH) != 0)
            event.width = setFieldsEvent.width;
        if ((mask & HEIGHT) != 0)
            event.height = setFieldsEvent.height;
        eventConsole.append(ControlExample.getResourceString("Returning"));
        ignore = true;
        log(event);
        ignore = false;
    }
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TypedEvent(org.eclipse.swt.events.TypedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 32 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project eclipse.platform.swt by eclipse.

the class TextEditor method createMenuBar.

void createMenuBar() {
    Menu menu = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menu);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    // $NON-NLS-1$
    fileItem.setText(getResourceString("File_menuitem"));
    fileItem.setMenu(fileMenu);
    MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    openItem.setText(getResourceString("Open_menuitem"));
    openItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
        // $NON-NLS-1$
        dialog.setFilterNames(new String[] { getResourceString("Text_Documents") });
        // $NON-NLS-1$
        dialog.setFilterExtensions(new String[] { "*.txt" });
        String name = dialog.open();
        if (name == null)
            return;
        fileName = name;
        try (FileInputStream file = new FileInputStream(name)) {
            styledText.setText(openFile(file));
        } catch (IOException e) {
            // $NON-NLS-1$
            showError(getResourceString("Error"), e.getMessage());
        }
    }));
    final MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    saveItem.setText(getResourceString("Save_menuitem"));
    saveItem.addSelectionListener(widgetSelectedAdapter(event -> saveFile()));
    fileMenu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent event) {
            saveItem.setEnabled(fileName != null);
        }
    });
    MenuItem saveAsItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    saveAsItem.setText(getResourceString("SaveAs_menuitem"));
    saveAsItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        // $NON-NLS-1$
        dialog.setFilterNames(new String[] { getResourceString("Text_Documents") });
        // $NON-NLS-1$
        dialog.setFilterExtensions(new String[] { "*.txt" });
        if (fileName != null)
            dialog.setFileName(fileName);
        String name = dialog.open();
        if (name != null) {
            fileName = name;
            saveFile();
        }
    }));
    new MenuItem(fileMenu, SWT.SEPARATOR);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    // $NON-NLS-1$
    exitItem.setText(getResourceString("Exit_menuitem"));
    exitItem.addSelectionListener(widgetSelectedAdapter(event -> shell.dispose()));
    MenuItem editItem = new MenuItem(menu, SWT.CASCADE);
    final Menu editMenu = new Menu(shell, SWT.DROP_DOWN);
    // $NON-NLS-1$
    editItem.setText(getResourceString("Edit_menuitem"));
    editItem.setMenu(editMenu);
    final MenuItem cutItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    cutItem.setText(getResourceString("Cut_menuitem"));
    cutItem.setImage(iCut);
    cutItem.setAccelerator(SWT.MOD1 | 'x');
    cutItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.cut()));
    final MenuItem copyItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    copyItem.setText(getResourceString("Copy_menuitem"));
    copyItem.setImage(iCopy);
    copyItem.setAccelerator(SWT.MOD1 | 'c');
    copyItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.copy()));
    MenuItem pasteItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    pasteItem.setText(getResourceString("Paste_menuitem"));
    pasteItem.setImage(iPaste);
    pasteItem.setAccelerator(SWT.MOD1 | 'v');
    pasteItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.paste()));
    new MenuItem(editMenu, SWT.SEPARATOR);
    final MenuItem selectAllItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    selectAllItem.setText(getResourceString("SelectAll_menuitem"));
    selectAllItem.setAccelerator(SWT.MOD1 | 'a');
    selectAllItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.selectAll()));
    editMenu.addMenuListener(menuShownAdapter(event -> {
        int selectionCount = styledText.getSelectionCount();
        cutItem.setEnabled(selectionCount > 0);
        copyItem.setEnabled(selectionCount > 0);
        selectAllItem.setEnabled(selectionCount < styledText.getCharCount());
    }));
    MenuItem wrapItem = new MenuItem(editMenu, SWT.CHECK);
    // $NON-NLS-1$
    wrapItem.setText(getResourceString("Wrap_menuitem"));
    wrapItem.addSelectionListener(widgetSelectedAdapter(event -> {
        MenuItem item = (MenuItem) event.widget;
        boolean enabled = item.getSelection();
        styledText.setWordWrap(enabled);
        editMenu.getItem(6).setEnabled(enabled);
        editMenu.getItem(8).setEnabled(enabled);
        leftAlignmentItem.setEnabled(enabled);
        centerAlignmentItem.setEnabled(enabled);
        rightAlignmentItem.setEnabled(enabled);
        justifyAlignmentItem.setEnabled(enabled);
        blockSelectionItem.setEnabled(!enabled);
    }));
    MenuItem justifyItem = new MenuItem(editMenu, SWT.CHECK);
    // $NON-NLS-1$
    justifyItem.setText(getResourceString("Justify_menuitem"));
    justifyItem.addSelectionListener(widgetSelectedAdapter(event -> {
        MenuItem item = (MenuItem) event.widget;
        styledText.setJustify(item.getSelection());
        updateToolBar();
    }));
    justifyItem.setEnabled(false);
    MenuItem setFontItem = new MenuItem(editMenu, SWT.PUSH);
    // $NON-NLS-1$
    setFontItem.setText(getResourceString("SetFont_menuitem"));
    setFontItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FontDialog fontDialog = new FontDialog(shell);
        fontDialog.setFontList(styledText.getFont().getFontData());
        FontData data = fontDialog.open();
        if (data != null) {
            Font newFont = new Font(display, data);
            styledText.setFont(newFont);
            if (font != null)
                font.dispose();
            font = newFont;
            updateToolBar();
        }
    }));
    MenuItem alignmentItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    alignmentItem.setText(getResourceString("Alignment_menuitem"));
    Menu alignmentMenu = new Menu(shell, SWT.DROP_DOWN);
    alignmentItem.setMenu(alignmentMenu);
    final MenuItem leftAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    leftAlignmentItem.setText(getResourceString("Left_menuitem"));
    leftAlignmentItem.setSelection(true);
    leftAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.LEFT);
        updateToolBar();
    }));
    alignmentItem.setEnabled(false);
    final MenuItem centerAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    centerAlignmentItem.setText(getResourceString("Center_menuitem"));
    centerAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.CENTER);
        updateToolBar();
    }));
    MenuItem rightAlignmentItem = new MenuItem(alignmentMenu, SWT.RADIO);
    // $NON-NLS-1$
    rightAlignmentItem.setText(getResourceString("Right_menuitem"));
    rightAlignmentItem.addSelectionListener(widgetSelectedAdapter(event -> {
        styledText.setAlignment(SWT.RIGHT);
        updateToolBar();
    }));
    MenuItem editOrientationItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    editOrientationItem.setText(getResourceString("Orientation_menuitem"));
    Menu editOrientationMenu = new Menu(shell, SWT.DROP_DOWN);
    editOrientationItem.setMenu(editOrientationMenu);
    MenuItem leftToRightItem = new MenuItem(editOrientationMenu, SWT.RADIO);
    // $NON-NLS-1$
    leftToRightItem.setText(getResourceString("LeftToRight_menuitem"));
    leftToRightItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.LEFT_TO_RIGHT)));
    leftToRightItem.setSelection(true);
    MenuItem rightToLeftItem = new MenuItem(editOrientationMenu, SWT.RADIO);
    // $NON-NLS-1$
    rightToLeftItem.setText(getResourceString("RightToLeft_menuitem"));
    rightToLeftItem.addSelectionListener(widgetSelectedAdapter(event -> styledText.setOrientation(SWT.RIGHT_TO_LEFT)));
    new MenuItem(editMenu, SWT.SEPARATOR);
    MenuItem insertObjectItem = new MenuItem(editMenu, SWT.CASCADE);
    // $NON-NLS-1$
    insertObjectItem.setText(getResourceString("InsertObject_menuitem"));
    Menu insertObjectMenu = new Menu(shell, SWT.DROP_DOWN);
    insertObjectItem.setMenu(insertObjectMenu);
    MenuItem insertControlItem = new MenuItem(insertObjectMenu, SWT.CASCADE);
    // $NON-NLS-1$
    insertControlItem.setText(getResourceString("Controls_menuitem"));
    Menu controlChoice = new Menu(shell, SWT.DROP_DOWN);
    insertControlItem.setMenu(controlChoice);
    MenuItem buttonItem = new MenuItem(controlChoice, SWT.PUSH);
    // $NON-NLS-1$
    buttonItem.setText(getResourceString("Button_menuitem"));
    MenuItem comboItem = new MenuItem(controlChoice, SWT.PUSH);
    // $NON-NLS-1$
    comboItem.setText(getResourceString("Combo_menuitem"));
    buttonItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Button button = new Button(styledText, SWT.PUSH);
        // $NON-NLS-1$
        button.setText(getResourceString("Button_menuitem"));
        addControl(button);
    }));
    comboItem.addSelectionListener(widgetSelectedAdapter(event -> {
        Combo combo = new Combo(styledText, SWT.NONE);
        // $NON-NLS-1$
        combo.setText(getResourceString("Combo_menuitem"));
        addControl(combo);
    }));
    MenuItem insertImageItem = new MenuItem(insertObjectMenu, SWT.PUSH);
    // $NON-NLS-1$
    insertImageItem.setText(getResourceString("Image_menuitem"));
    insertImageItem.addSelectionListener(widgetSelectedAdapter(event -> {
        FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
        String fileName = fileDialog.open();
        if (fileName != null) {
            try {
                Image image = new Image(display, fileName);
                addImage(image);
            } catch (Exception e) {
                // $NON-NLS-1$
                showError(getResourceString("Bad_image"), e.getMessage());
            }
        }
    }));
    if (SAMPLE_TEXT) {
        new MenuItem(editMenu, SWT.SEPARATOR);
        MenuItem loadProfileItem = new MenuItem(editMenu, SWT.CASCADE);
        // $NON-NLS-1$
        loadProfileItem.setText(getResourceString("LoadProfile_menuitem"));
        Menu loadProfileMenu = new Menu(shell, SWT.DROP_DOWN);
        loadProfileItem.setMenu(loadProfileMenu);
        SelectionListener adapter = widgetSelectedAdapter(event -> {
            int profile = Integer.parseInt((String) event.widget.getData());
            loadProfile(profile);
        });
        MenuItem profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile1_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("1");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile2_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("2");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile3_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("3");
        profileItem.addSelectionListener(adapter);
        profileItem = new MenuItem(loadProfileMenu, SWT.PUSH);
        // $NON-NLS-1$
        profileItem.setText(getResourceString("Profile4_menuitem"));
        // $NON-NLS-1$
        profileItem.setData("4");
        profileItem.addSelectionListener(adapter);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) CoolBar(org.eclipse.swt.widgets.CoolBar) ToolBar(org.eclipse.swt.widgets.ToolBar) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ColorDialog(org.eclipse.swt.widgets.ColorDialog) MenuEvent(org.eclipse.swt.events.MenuEvent) Composite(org.eclipse.swt.widgets.Composite) Bullet(org.eclipse.swt.custom.Bullet) Text(org.eclipse.swt.widgets.Text) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) MissingResourceException(java.util.MissingResourceException) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) ToolItem(org.eclipse.swt.widgets.ToolItem) MenuListener.menuShownAdapter(org.eclipse.swt.events.MenuListener.menuShownAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) PaintObjectEvent(org.eclipse.swt.custom.PaintObjectEvent) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Spinner(org.eclipse.swt.widgets.Spinner) ControlListener(org.eclipse.swt.events.ControlListener) MenuAdapter(org.eclipse.swt.events.MenuAdapter) ImageData(org.eclipse.swt.graphics.ImageData) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) VerifyEvent(org.eclipse.swt.events.VerifyEvent) ResourceBundle(java.util.ResourceBundle) StringTokenizer(java.util.StringTokenizer) Listener(org.eclipse.swt.widgets.Listener) RGB(org.eclipse.swt.graphics.RGB) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Resource(org.eclipse.swt.graphics.Resource) Browser(org.eclipse.swt.browser.Browser) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) FileWriter(java.io.FileWriter) StyleRange(org.eclipse.swt.custom.StyleRange) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FontDialog(org.eclipse.swt.widgets.FontDialog) InputStreamReader(java.io.InputStreamReader) CoolItem(org.eclipse.swt.widgets.CoolItem) Color(org.eclipse.swt.graphics.Color) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) MessageBox(org.eclipse.swt.widgets.MessageBox) BufferedReader(java.io.BufferedReader) Menu(org.eclipse.swt.widgets.Menu) Control(org.eclipse.swt.widgets.Control) InputStream(java.io.InputStream) GridLayout(org.eclipse.swt.layout.GridLayout) FontDialog(org.eclipse.swt.widgets.FontDialog) FontData(org.eclipse.swt.graphics.FontData) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Combo(org.eclipse.swt.widgets.Combo) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) FileInputStream(java.io.FileInputStream) Font(org.eclipse.swt.graphics.Font) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) Button(org.eclipse.swt.widgets.Button) Menu(org.eclipse.swt.widgets.Menu) FileDialog(org.eclipse.swt.widgets.FileDialog) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 33 with MenuEvent

use of org.eclipse.swt.events.MenuEvent 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);
                                    }
                                });
                            }
                        }
                    });
                }
            });
        }
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableItem(org.eclipse.swt.widgets.TableItem) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) Label(org.eclipse.swt.widgets.Label) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledText(org.eclipse.swt.custom.StyledText) VerifyListener(org.eclipse.swt.events.VerifyListener) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) DisposeListener(org.eclipse.swt.events.DisposeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) PaintListener(org.eclipse.swt.events.PaintListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DisposeListener(org.eclipse.swt.events.DisposeListener) VerifyListener(org.eclipse.swt.events.VerifyListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) MenuListener(org.eclipse.swt.events.MenuListener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) KeyListener(org.eclipse.swt.events.KeyListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) MenuListener(org.eclipse.swt.events.MenuListener) StyleRange(org.eclipse.swt.custom.StyleRange) URL(java.net.URL) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Menu(org.eclipse.swt.widgets.Menu) GC(org.eclipse.swt.graphics.GC) VerifyEvent(org.eclipse.swt.events.VerifyEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Table(org.eclipse.swt.widgets.Table) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MenuItem(org.eclipse.swt.widgets.MenuItem) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) MessageText(com.biglybt.core.internat.MessageText) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener)

Example 34 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class UISWTStatusEntryImpl method update0.

private void update0(CLabelPadding label) {
    label.setText(text);
    label.setToolTipText(tooltip);
    if (check_scaled_image) {
        check_scaled_image = false;
        if (scaled_image != null) {
            scaled_image.dispose();
            scaled_image = null;
        }
        if (original_image != null && Utils.adjustPXForDPIRequired(original_image)) {
            scaled_image = Utils.adjustPXForDPI(label.getDisplay(), original_image);
        }
    }
    label.setImage(image_enabled ? (scaled_image == null ? original_image : scaled_image) : null);
    label.setVisible(this.is_visible);
    releaseOldImages();
    MenuItem[] items = MenuItemManager.getInstance().getAllAsArray(menu_context.context);
    if (items.length > 0 & menu == null) {
        menu = new Menu(label);
        label.setMenu(menu);
        MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuildUtils.MenuBuilder() {

            @Override
            public void buildMenu(Menu menu, MenuEvent menuEvent) {
                MenuItem[] items = MenuItemManager.getInstance().getAllAsArray(menu_context.context);
                MenuBuildUtils.addPluginMenuItems(items, menu, true, true, MenuBuildUtils.BASIC_MENU_ITEM_CONTROLLER);
            }
        });
    } else if (menu != null && items.length == 0) {
        label.setMenu(null);
        if (!menu.isDisposed()) {
            menu.dispose();
        }
        this.menu = null;
    }
    this.needs_update = false;
}
Also used : MenuItem(com.biglybt.pif.ui.menus.MenuItem) Menu(org.eclipse.swt.widgets.Menu) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 35 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class AllTransfersBar method buildMenu.

@Override
public void buildMenu(Menu menu, MenuEvent menuEvent) {
    // Start All
    MenuItem start_all = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(start_all, "MainWindow.menu.transfers.startalltransfers");
    Utils.setMenuItemImage(start_all, "start");
    start_all.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            ManagerUtils.asyncStartAll();
        }
    });
    start_all.setEnabled(true);
    // Stop All
    MenuItem stop_all = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(stop_all, "MainWindow.menu.transfers.stopalltransfers");
    Utils.setMenuItemImage(stop_all, "stop");
    stop_all.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            ManagerUtils.asyncStopAll();
        }
    });
    stop_all.setEnabled(true);
    // Pause All
    MenuItem pause_all = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(pause_all, "MainWindow.menu.transfers.pausetransfers");
    Utils.setMenuItemImage(pause_all, "pause");
    pause_all.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            ManagerUtils.asyncPause();
        }
    });
    pause_all.setEnabled(g_manager.canPauseDownloads());
    // Resume All
    MenuItem resume_all = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(resume_all, "MainWindow.menu.transfers.resumetransfers");
    Utils.setMenuItemImage(resume_all, "resume");
    resume_all.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            ManagerUtils.asyncResume();
        }
    });
    resume_all.setEnabled(g_manager.canResumeDownloads());
    new MenuItem(menu, SWT.SEPARATOR);
    super.buildMenu(menu);
}
Also used : CoreRunningListener(com.biglybt.core.CoreRunningListener) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

MenuEvent (org.eclipse.swt.events.MenuEvent)45 Menu (org.eclipse.swt.widgets.Menu)37 MenuItem (org.eclipse.swt.widgets.MenuItem)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 MenuAdapter (org.eclipse.swt.events.MenuAdapter)24 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)21 MenuListener (org.eclipse.swt.events.MenuListener)18 Point (org.eclipse.swt.graphics.Point)14 MenuManager (org.eclipse.jface.action.MenuManager)13 Event (org.eclipse.swt.widgets.Event)11 Listener (org.eclipse.swt.widgets.Listener)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 FocusEvent (org.eclipse.swt.events.FocusEvent)7 Composite (org.eclipse.swt.widgets.Composite)7 TableItem (org.eclipse.swt.widgets.TableItem)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 GridData (org.eclipse.swt.layout.GridData)6