Search in sources :

Example 96 with CLabel

use of org.eclipse.swt.custom.CLabel in project BiglyBT by BiglySoftware.

the class TorrentInfoView method initialize.

private void initialize(Composite composite) {
    this.parent = composite;
    // cheap trick to allow datasource changes.  Normally we'd just
    // refill the components with new info, but I didn't write this and
    // I don't want to waste my time :) [tux]
    Utils.disposeComposite(parent, false);
    if (download_manager == null) {
        ViewUtils.setViewRequiresOneDownload(composite);
        return;
    }
    Composite panel = Utils.createScrolledComposite(composite);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    panel.setLayout(layout);
    // int userMode = COConfigurationManager.getIntParameter("User Mode");
    // header
    boolean showHeader = true;
    if (swtView instanceof TabbedEntry) {
        showHeader = ((TabbedEntry) swtView).getMDI().getAllowSubViews();
    }
    if (showHeader) {
        Composite cHeader = new Composite(panel, SWT.BORDER);
        GridLayout configLayout = new GridLayout();
        configLayout.marginHeight = 3;
        configLayout.marginWidth = 0;
        cHeader.setLayout(configLayout);
        GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
        cHeader.setLayoutData(gridData);
        Display d = panel.getDisplay();
        cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
        cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
        Label lHeader = new Label(cHeader, SWT.NULL);
        lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
        lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
        FontData[] fontData = lHeader.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        int fontHeight = (int) (fontData[0].getHeight() * 1.2);
        fontData[0].setHeight(fontHeight);
        headerFont = new Font(d, fontData);
        lHeader.setFont(headerFont);
        lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
        gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
        lHeader.setLayoutData(gridData);
    }
    Composite gTorrentInfo = new Composite(panel, SWT.NULL);
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gTorrentInfo.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentInfo.setLayout(layout);
    // torrent encoding
    Label label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    label.setLayoutData(gridData);
    label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
    TOTorrent torrent = download_manager.getTorrent();
    BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    blabel.setLayoutData(gridData);
    if (torrent == null) {
        blabel.setText("");
    } else {
        int tt = torrent.getTorrentType();
        String tt_str = MessageText.getString("label.torrent.type") + ": " + MessageText.getString("label.torrent.type." + tt);
        int ett = torrent.getEffectiveTorrentType();
        if (ett != tt) {
            tt_str += ", " + MessageText.getString("label.effective") + ": " + MessageText.getString("label.torrent.type." + ett);
        }
        blabel.setText(LocaleTorrentUtil.getCurrentTorrentEncoding(torrent) + "; " + tt_str);
    }
    // trackers
    label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    label.setLayoutData(gridData);
    label.setText(MessageText.getString("label.tracker") + ": ");
    String trackers = "";
    if (torrent != null) {
        TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
        TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
        List<String> tracker_list = new ArrayList<>();
        URL url = torrent.getAnnounceURL();
        tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
        for (int i = 0; i < sets.length; i++) {
            TOTorrentAnnounceURLSet set = sets[i];
            URL[] urls = set.getAnnounceURLs();
            for (int j = 0; j < urls.length; j++) {
                url = urls[j];
                String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
                if (!tracker_list.contains(str)) {
                    tracker_list.add(str);
                }
            }
        }
        TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
        URL active_url = null;
        if (announcer != null) {
            active_url = announcer.getTrackerURL();
        } else {
            TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
            if (scrape != null) {
                active_url = scrape.getURL();
            }
        }
        if (active_url == null) {
            active_url = torrent.getAnnounceURL();
        }
        trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
        tracker_list.remove(trackers);
        if (tracker_list.size() > 0) {
            trackers += " (";
            for (int i = 0; i < tracker_list.size(); i++) {
                trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
            }
            trackers += ")";
        }
    }
    blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
    blabel.setLayoutData(Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
    blabel.setText(trackers);
    // columns
    Group gColumns = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
    gridData = new GridData(GridData.FILL_BOTH);
    gColumns.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    gColumns.setLayout(layout);
    Map<String, FakeTableCell> usable_cols = new HashMap<>();
    TableColumnManager col_man = TableColumnManager.getInstance();
    TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
    for (int i = 0; i < cols_sets.length; i++) {
        TableColumnCore[] cols = cols_sets[i];
        for (int j = 0; j < cols.length; j++) {
            TableColumnCore col = cols[j];
            String id = col.getName();
            if (usable_cols.containsKey(id)) {
                continue;
            }
            FakeTableCell fakeTableCell = null;
            try {
                fakeTableCell = new FakeTableCell(col, download_manager);
                fakeTableCell.setOrentation(SWT.LEFT);
                fakeTableCell.setWrapText(false);
                col.invokeCellAddedListeners(fakeTableCell);
                // One refresh to see if it throws up
                fakeTableCell.refresh();
                usable_cols.put(id, fakeTableCell);
            } catch (Throwable t) {
                // System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
                try {
                    if (fakeTableCell != null) {
                        fakeTableCell.dispose();
                    }
                } catch (Throwable t2) {
                // ignore;
                }
            }
        }
    }
    Collection<FakeTableCell> values = usable_cols.values();
    cells = new FakeTableCell[values.size()];
    values.toArray(cells);
    Arrays.sort(cells, new Comparator<FakeTableCell>() {

        @Override
        public int compare(FakeTableCell o1, FakeTableCell o2) {
            TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
            TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
            String key1 = MessageText.getString(c1.getTitleLanguageKey());
            String key2 = MessageText.getString(c2.getTitleLanguageKey());
            return key1.compareToIgnoreCase(key2);
        }
    });
    for (int i = 0; i < cells.length; i++) {
        final FakeTableCell cell = cells[i];
        CLabel cLabel = new CLabel(gColumns, SWT.NULL);
        gridData = new GridData();
        if (i % 2 == 1) {
            gridData.horizontalIndent = 16;
        }
        cLabel.setLayoutData(gridData);
        TableColumnCore tc = (TableColumnCore) cell.getTableColumn();
        String key = tc.getTitleLanguageKey();
        cLabel.setText(MessageText.getString(key) + ": ");
        Utils.setTT(cLabel, MessageText.getString(key + ".info", ""));
        String iconReference = tc.getIconReference();
        if (iconReference != null) {
            Utils.setMenuItemImage(cLabel, iconReference);
        }
        cLabel.setData("ColumnName", tc.getName());
        DragSource dragSource = DragDropUtils.createDragSource(cLabel, DND.DROP_MOVE | DND.DROP_COPY);
        dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        dragSource.addDragListener(this);
        final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 16;
        c.setLayoutData(gridData);
        cell.setControl(c);
        cell.invalidate();
        cell.refresh();
        c.addListener(SWT.MouseHover, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Object toolTip = cell.getToolTip();
                if (toolTip instanceof String) {
                    String s = (String) toolTip;
                    Utils.setTT(c, s);
                }
            }
        });
    }
    refresh();
    composite.layout();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) CLabel(org.eclipse.swt.custom.CLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) FakeTableCell(com.biglybt.ui.swt.views.table.impl.FakeTableCell) Font(org.eclipse.swt.graphics.Font) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) URL(java.net.URL) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) GridLayout(org.eclipse.swt.layout.GridLayout) TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) TabbedEntry(com.biglybt.ui.swt.mdi.TabbedEntry) FontData(org.eclipse.swt.graphics.FontData) DownloadTypeComplete(com.biglybt.pif.download.DownloadTypeComplete) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) DownloadTypeIncomplete(com.biglybt.pif.download.DownloadTypeIncomplete) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 97 with CLabel

use of org.eclipse.swt.custom.CLabel in project BiglyBT by BiglySoftware.

the class SideBarToolTips method handleHover.

// handlEvent()
/**
 * @since 3.1.1.1
 */
private void handleHover(Point mousePos) {
    if (toolTipShell != null && !toolTipShell.isDisposed())
        toolTipShell.dispose();
    if (!Utils.getTTEnabled()) {
        return;
    }
    if (tree.getItemCount() == 0) {
        return;
    }
    int indent = SideBar.END_INDENT ? tree.getClientArea().width - 1 : 0;
    TreeItem treeItem = tree.getItem(new Point(indent, mousePos.y));
    if (treeItem == null) {
        return;
    }
    mdiEntry = (BaseMdiEntry) treeItem.getData("MdiEntry");
    if (mdiEntry == null) {
        return;
    }
    Rectangle itemBounds = treeItem.getBounds();
    Point relPos = new Point(mousePos.x, mousePos.y - itemBounds.y);
    String sToolTip = getToolTip(relPos);
    if (sToolTip == null || sToolTip.length() == 0) {
        return;
    }
    lastRelMouseHoverPos = relPos;
    Display d = tree.getDisplay();
    if (d == null)
        return;
    // We don't get mouse down notifications on trim or borders..
    toolTipShell = new Shell(tree.getShell(), SWT.ON_TOP);
    UIUpdaterSWT.getInstance().addUpdater(this);
    toolTipShell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UIUpdaterSWT.getInstance().removeUpdater(SideBarToolTips.this);
        }
    });
    FillLayout f = new FillLayout();
    try {
        f.marginWidth = 3;
        f.marginHeight = 1;
    } catch (NoSuchFieldError e) {
    /* Ignore for Pre 3.0 SWT.. */
    }
    toolTipShell.setLayout(f);
    toolTipShell.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
    toolTipLabel = new CLabel(toolTipShell, SWT.WRAP);
    toolTipLabel.setForeground(Colors.getSystemColor(d, SWT.COLOR_INFO_FOREGROUND));
    toolTipLabel.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
    toolTipLabel.setText(sToolTip.replaceAll("&", "&&"));
    // compute size on label instead of shell because label
    // calculates wrap, while shell doesn't
    Point size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    if (size.x > 600) {
        size = toolTipLabel.computeSize(600, SWT.DEFAULT, true);
    }
    size.x += toolTipShell.getBorderWidth() * 2 + 2;
    size.y += toolTipShell.getBorderWidth() * 2;
    try {
        size.x += toolTipShell.getBorderWidth() * 2 + (f.marginWidth * 2);
        size.y += toolTipShell.getBorderWidth() * 2 + (f.marginHeight * 2);
    } catch (NoSuchFieldError e) {
    /* Ignore for Pre 3.0 SWT.. */
    }
    Point pt = tree.toDisplay(mousePos.x, mousePos.y);
    Rectangle displayRect;
    try {
        displayRect = tree.getMonitor().getClientArea();
    } catch (NoSuchMethodError e) {
        displayRect = tree.getDisplay().getClientArea();
    }
    if (pt.x + size.x > displayRect.x + displayRect.width) {
        pt.x = displayRect.x + displayRect.width - size.x;
    }
    if (pt.y + size.y > displayRect.y + displayRect.height) {
        pt.y -= size.y + 2;
    } else {
        pt.y += 21;
    }
    if (pt.y < displayRect.y)
        pt.y = displayRect.y;
    toolTipShell.setBounds(pt.x, pt.y, size.x, size.y);
    toolTipShell.setVisible(true);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point)

Example 98 with CLabel

use of org.eclipse.swt.custom.CLabel in project BiglyBT by BiglySoftware.

the class TableTooltips method handleEvent.

@Override
public void handleEvent(Event event) {
    switch(event.type) {
        case SWT.MouseHover:
            {
                if (toolTipShell != null && !toolTipShell.isDisposed())
                    toolTipShell.dispose();
                if (!Utils.getTTEnabled()) {
                    return;
                }
                TableCellCore cell = tv.getTableCell(event.x, event.y);
                if (cell == null)
                    return;
                cell.invokeToolTipListeners(TableCellSWT.TOOLTIPLISTENER_HOVER);
                Object oToolTip = cell.getToolTip();
                if (oToolTip == null) {
                    oToolTip = cell.getDefaultToolTip();
                }
                // TODO: support composite, image, etc
                if (oToolTip == null || oToolTip.toString().length() == 0)
                    return;
                Display d = composite.getDisplay();
                if (d == null)
                    return;
                // We don't get mouse down notifications on trim or borders..
                toolTipShell = new Shell(composite.getShell(), SWT.ON_TOP);
                FillLayout f = new FillLayout();
                try {
                    f.marginWidth = 3;
                    f.marginHeight = 1;
                } catch (NoSuchFieldError e) {
                /* Ignore for Pre 3.0 SWT.. */
                }
                toolTipShell.setLayout(f);
                toolTipShell.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
                Point size = new Point(0, 0);
                if (oToolTip instanceof String) {
                    String sToolTip = (String) oToolTip;
                    toolTipLabel = new CLabel(toolTipShell, SWT.WRAP);
                    toolTipLabel.setForeground(Colors.getSystemColor(d, SWT.COLOR_INFO_FOREGROUND));
                    toolTipLabel.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
                    toolTipShell.setData("TableCellSWT", cell);
                    toolTipLabel.setText(sToolTip.replaceAll("&", "&&"));
                    // compute size on label instead of shell because label
                    // calculates wrap, while shell doesn't
                    size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    if (size.x > 600) {
                        size = toolTipLabel.computeSize(600, SWT.DEFAULT, true);
                    }
                } else if (oToolTip instanceof Image) {
                    Image image = (Image) oToolTip;
                    toolTipLabel = new CLabel(toolTipShell, SWT.CENTER);
                    toolTipLabel.setForeground(Colors.getSystemColor(d, SWT.COLOR_INFO_FOREGROUND));
                    toolTipLabel.setBackground(Colors.getSystemColor(d, SWT.COLOR_INFO_BACKGROUND));
                    toolTipShell.setData("TableCellSWT", cell);
                    toolTipLabel.setImage(image);
                    size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                }
                size.x += toolTipShell.getBorderWidth() * 2 + 2;
                size.y += toolTipShell.getBorderWidth() * 2;
                try {
                    size.x += toolTipShell.getBorderWidth() * 2 + (f.marginWidth * 2);
                    size.y += toolTipShell.getBorderWidth() * 2 + (f.marginHeight * 2);
                } catch (NoSuchFieldError e) {
                /* Ignore for Pre 3.0 SWT.. */
                }
                Point pt = composite.toDisplay(event.x, event.y);
                Rectangle displayRect;
                try {
                    displayRect = composite.getMonitor().getClientArea();
                } catch (NoSuchMethodError e) {
                    displayRect = composite.getDisplay().getClientArea();
                }
                if (pt.x + size.x > displayRect.x + displayRect.width) {
                    pt.x = displayRect.x + displayRect.width - size.x;
                }
                if (pt.y + size.y > displayRect.y + displayRect.height) {
                    pt.y -= size.y + 2;
                } else {
                    pt.y += 21;
                }
                if (pt.y < displayRect.y)
                    pt.y = displayRect.y;
                toolTipShell.setBounds(pt.x, pt.y, size.x, size.y);
                toolTipShell.setVisible(true);
                break;
            }
        case SWT.Dispose:
            if (mainShell != null && !mainShell.isDisposed())
                mainShell.removeListener(SWT.Deactivate, this);
            if (tv.getComposite() != null && !tv.getComposite().isDisposed())
                tv.getComposite().removeListener(SWT.Deactivate, this);
        default:
            if (toolTipShell != null) {
                toolTipShell.dispose();
                toolTipShell = null;
                toolTipLabel = null;
            }
            break;
    }
// switch
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image)

Example 99 with CLabel

use of org.eclipse.swt.custom.CLabel in project BiglyBT by BiglySoftware.

the class ManagerUtils method locateFilesSupport.

private static void locateFilesSupport(final DownloadManager[] dms, final DiskManagerFileInfo[][] dm_files, Shell shell) {
    ClassLoader loader = null;
    if (Constants.isCVSVersion()) {
        try {
            // allow skin file reloading to test
            File file = new File("C:\\Users\\Paul\\git\\BiglyBT\\uis\\src");
            if (file.exists()) {
                URL[] urls = { file.toURI().toURL() };
                loader = new URLClassLoader(urls);
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    final SkinnedDialog dialog = new SkinnedDialog(loader, "skin3_dlg_findfiles", "shell", shell, SWT.DIALOG_TRIM | SWT.RESIZE);
    SWTSkin skin = dialog.getSkin();
    SWTSkinObjectList so_def_locs = (SWTSkinObjectList) skin.getSkinObject("roots-list");
    org.eclipse.swt.widgets.List def_locs = so_def_locs.getListControl();
    List<String> roots = COConfigurationManager.getStringListParameter("find.files.search.roots");
    if (!roots.isEmpty()) {
        def_locs.setItems(roots.toArray(new String[roots.size()]));
    }
    SWTSkinObjectTextbox so_exp_text = (SWTSkinObjectTextbox) skin.getSkinObject("exp-text");
    SWTSkinObjectButton so_exp_but = (SWTSkinObjectButton) skin.getSkinObject("exp-but");
    SWTSkinObjectButton so_add_but = (SWTSkinObjectButton) skin.getSkinObject("add-but");
    SWTSkinObjectCheckbox so_use_def = (SWTSkinObjectCheckbox) skin.getSkinObject("use-def");
    SWTSkinObjectContainer so_mode = (SWTSkinObjectContainer) skin.getSkinObject("mode");
    SWTSkinObjectCheckbox so_include_skipped = (SWTSkinObjectCheckbox) skin.getSkinObject("skip-inc");
    Composite c_mode = so_mode.getComposite();
    c_mode.setLayoutData(Utils.getFilledFormData());
    FormLayout layout = new FormLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    c_mode.setLayout(layout);
    // mode
    Combo mode_combo = new Combo(c_mode, SWT.READ_ONLY);
    FormData fd = new FormData();
    fd.top = new FormAttachment(c_mode, 0);
    fd.bottom = new FormAttachment(100);
    mode_combo.setLayoutData(fd);
    mode_combo.setItems(// shitty layout doesn't give sufficient width for all options
    MessageText.getString("label.link") + "    ", MessageText.getString("label.copy") + "    ", MessageText.getString("label.move") + "    ", MessageText.getString("Peers.column.piece") + "    ");
    // link mode
    Combo link_combo = new Combo(c_mode, SWT.READ_ONLY);
    fd = new FormData();
    fd.top = new FormAttachment(c_mode, 0);
    fd.bottom = new FormAttachment(100);
    fd.left = new FormAttachment(mode_combo, 2);
    link_combo.setLayoutData(fd);
    link_combo.setItems("    ", // shitty layout doesn't give sufficient width for all options
    MessageText.getString("tag.type.internal") + "    ", MessageText.getString("label.hard") + "    ");
    Utils.setTT(link_combo, MessageText.getString("label.link.type"));
    // tolerance
    CLabel tolerance = new CLabel(c_mode, SWT.CENTER);
    fd = new FormData();
    fd.top = new FormAttachment(c_mode, 0);
    fd.bottom = new FormAttachment(100, -2);
    fd.left = new FormAttachment(link_combo);
    tolerance.setLayoutData(fd);
    tolerance.setText(MessageText.getString("label.tolerance.pct"));
    Spinner spinner = new Spinner(c_mode, SWT.BORDER | SWT.RIGHT);
    fd = new FormData();
    fd.top = new FormAttachment(c_mode, 0);
    fd.bottom = new FormAttachment(100);
    fd.left = new FormAttachment(tolerance, 2);
    fd.right = new FormAttachment(100);
    spinner.setLayoutData(fd);
    spinner.setMinimum(0);
    spinner.setMaximum(10);
    SWTSkinObjectContainer soButtonArea = (SWTSkinObjectContainer) skin.getSkinObject("bottom-area");
    StandardButtonsArea buttonsArea = new StandardButtonsArea() {

        @Override
        protected void clicked(int buttonValue) {
            if (buttonValue == SWT.OK) {
                String[] roots;
                if (so_use_def.isChecked()) {
                    roots = def_locs.getItems();
                } else {
                    roots = new String[] { so_exp_text.getText().trim() };
                }
                int mode = mode_combo.getSelectionIndex();
                int link_type = link_combo.getSelectionIndex();
                int tolerance = spinner.getSelection();
                boolean include_skipped = so_include_skipped.isChecked();
                dialog.close();
                Utils.execSWTThreadLater(1, new Runnable() {

                    public void run() {
                        locateFiles(dms, dm_files, shell, roots, mode, link_type, tolerance, include_skipped);
                    }
                });
            } else {
                dialog.close();
            }
        }
    };
    buttonsArea.setButtonIDs(new String[] { MessageText.getString("Button.search"), MessageText.getString("Button.cancel") });
    buttonsArea.setButtonVals(new Integer[] { SWT.OK, SWT.CANCEL });
    buttonsArea.swt_createButtons(((SWTSkinObjectContainer) soButtonArea).getComposite());
    Runnable state_changed = new Runnable() {

        public void run() {
            String exp_text = so_exp_text.getText().trim();
            boolean is_explicit = !exp_text.isEmpty();
            boolean has_default = def_locs.getItemCount() > 0;
            boolean can_search = is_explicit || has_default;
            so_use_def.setEnabled(has_default);
            if (is_explicit) {
                so_use_def.setChecked(false);
            } else {
                if (has_default) {
                    so_use_def.setChecked(true);
                }
            }
            so_add_but.getButton().setEnabled(is_explicit && !Arrays.asList(def_locs.getItems()).contains(exp_text));
            buttonsArea.setButtonEnabled(SWT.OK, can_search);
            int mode = COConfigurationManager.getIntParameter("find.files.search.mode", LOCATE_MODE_LINK);
            mode_combo.select(mode);
            int link_mode = COConfigurationManager.getIntParameter("find.files.search.mode.link", LOCATE_MODE_LINK_INTERNAL);
            boolean link_enabled = mode == LOCATE_MODE_LINK;
            link_combo.select(link_enabled ? link_mode : LOCATE_MODE_LINK_BLANK);
            link_combo.setEnabled(link_enabled);
        }
    };
    state_changed.run();
    final Menu menu = new Menu(def_locs);
    def_locs.setMenu(menu);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            MenuItem[] items = menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }
            String[] selected = def_locs.getSelection();
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(mi, "MySharesView.menu.remove");
            Utils.setMenuItemImage(mi, "delete");
            mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    List<String> temp = new ArrayList<>(Arrays.asList(def_locs.getItems()));
                    temp.removeAll(Arrays.asList(selected));
                    def_locs.setItems(temp.toArray(new String[temp.size()]));
                    COConfigurationManager.setParameter("find.files.search.roots", temp);
                    state_changed.run();
                }
            });
            mi.setEnabled(selected.length > 0);
        }

        public void menuHidden(MenuEvent arg0) {
        }
    });
    def_locs.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
                String[] selected = def_locs.getSelection();
                if (selected.length > 0) {
                    List<String> temp = new ArrayList<>(Arrays.asList(def_locs.getItems()));
                    temp.removeAll(Arrays.asList(selected));
                    def_locs.setItems(temp.toArray(new String[temp.size()]));
                    COConfigurationManager.setParameter("find.files.search.roots", temp);
                    state_changed.run();
                }
            } else {
                int key = event.character;
                if (key <= 26 && key > 0) {
                    key += 'a' - 1;
                }
                if (event.stateMask == SWT.MOD1) {
                    switch(key) {
                        case 'a':
                            {
                                // CTRL+A select all Torrents
                                def_locs.selectAll();
                                event.doit = false;
                                break;
                            }
                    }
                }
            }
        }
    });
    mode_combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = mode_combo.getSelectionIndex();
            COConfigurationManager.setParameter("find.files.search.mode", index);
            state_changed.run();
        }
    });
    link_combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = link_combo.getSelectionIndex();
            if (index == LOCATE_MODE_LINK_BLANK) {
                index = LOCATE_MODE_LINK_INTERNAL;
            }
            COConfigurationManager.setParameter("find.files.search.mode.link", index);
            state_changed.run();
        }
    });
    spinner.addListener(SWT.Selection, (e) -> {
        int value = spinner.getSelection();
        if (value != 0) {
            int index = mode_combo.getSelectionIndex();
            if (index == LOCATE_MODE_LINK) {
                index = LOCATE_MODE_COPY;
                mode_combo.select(index);
                COConfigurationManager.setParameter("find.files.search.mode", index);
                state_changed.run();
            }
        }
    });
    so_exp_text.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            state_changed.run();
        }
    });
    so_exp_but.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

        @Override
        public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
            DirectoryDialog dd = new DirectoryDialog(shell);
            dd.setFilterPath(TorrentOpener.getFilterPathData());
            dd.setText(MessageText.getString("MyTorrentsView.menu.locatefiles.dialog"));
            String path = dd.open();
            if (path != null) {
                TorrentOpener.setFilterPathData(path);
                so_exp_text.setText(new File(path).getAbsolutePath());
                state_changed.run();
            }
        }
    });
    so_add_but.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

        @Override
        public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
            String loc = so_exp_text.getText().trim();
            String[] existing = def_locs.getItems();
            String[] locs = new String[existing.length + 1];
            int pos = 0;
            for (String e : existing) {
                if (loc.equals(e)) {
                    return;
                }
                locs[pos++] = e;
            }
            locs[pos] = loc;
            def_locs.setItems(locs);
            COConfigurationManager.setParameter("find.files.search.roots", Arrays.asList(locs));
            state_changed.run();
        }
    });
    so_use_def.addSelectionListener(new SWTSkinCheckboxListener() {

        @Override
        public void checkboxChanged(SWTSkinObjectCheckbox so, boolean checked) {
            if (checked) {
                so_exp_text.setText("");
            }
            state_changed.run();
        }
    });
    so_include_skipped.setChecked(COConfigurationManager.getBooleanParameter("find.files.include.skipped"));
    so_include_skipped.addSelectionListener(new SWTSkinCheckboxListener() {

        @Override
        public void checkboxChanged(SWTSkinObjectCheckbox so, boolean checked) {
            COConfigurationManager.setParameter("find.files.include.skipped", checked);
        }
    });
    dialog.open();
}
Also used : KeyAdapter(org.eclipse.swt.events.KeyAdapter) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SWTSkinObjectList(com.biglybt.ui.swt.skin.SWTSkinObjectList) List(java.util.List) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) SWTSkinObjectCheckbox(com.biglybt.ui.swt.skin.SWTSkinObjectCheckbox) SWTSkinObjectButton(com.biglybt.ui.swt.skin.SWTSkinObjectButton) SWTSkinObjectList(com.biglybt.ui.swt.skin.SWTSkinObjectList) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CLabel(org.eclipse.swt.custom.CLabel) SWTSkinCheckboxListener(com.biglybt.ui.swt.skin.SWTSkinCheckboxListener) ModifyListener(org.eclipse.swt.events.ModifyListener) MenuListener(org.eclipse.swt.events.MenuListener) org.eclipse.swt.widgets(org.eclipse.swt.widgets) URL(java.net.URL) KeyEvent(org.eclipse.swt.events.KeyEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTSkinObjectTextbox(com.biglybt.ui.swt.skin.SWTSkinObjectTextbox) URLClassLoader(java.net.URLClassLoader) MenuEvent(org.eclipse.swt.events.MenuEvent) FormLayout(org.eclipse.swt.layout.FormLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) SWTSkinButtonUtility(com.biglybt.ui.swt.skin.SWTSkinButtonUtility) URLClassLoader(java.net.URLClassLoader) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) StandardButtonsArea(com.biglybt.ui.swt.views.skin.StandardButtonsArea)

Example 100 with CLabel

use of org.eclipse.swt.custom.CLabel in project translationstudio8 by heartsome.

the class TerminologyViewPart method createPartControl.

/**
	 * 创建控件。
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    createAction();
    GridLayout parentGl = new GridLayout(1, false);
    parentGl.marginWidth = 0;
    parentGl.marginHeight = 0;
    parent.setLayout(parentGl);
    final Composite contentPanel = new Composite(parent, SWT.NONE);
    GridLayout secondPageCompositeGl = new GridLayout(1, false);
    secondPageCompositeGl.marginBottom = -1;
    secondPageCompositeGl.marginLeft = -1;
    secondPageCompositeGl.marginRight = -1;
    secondPageCompositeGl.marginTop = -1;
    secondPageCompositeGl.marginWidth = 0;
    secondPageCompositeGl.marginHeight = 0;
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    contentPanel.setLayout(secondPageCompositeGl);
    contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // firstPageComposite = new Composite(contentPanel, SWT.NONE);
    // firstPageComposite.setLayout(new GridLayout(1, false));
    // secondPageComposite = new Composite(contentPanel, SWT.NONE);
    // GridLayout secondPageCompositeGl = new GridLayout(1, false);
    // secondPageCompositeGl.marginBottom = -1;
    // secondPageCompositeGl.marginLeft = -1;
    // secondPageCompositeGl.marginRight = -1;
    // secondPageCompositeGl.marginTop = -1;
    // secondPageCompositeGl.marginWidth = 0;
    // secondPageCompositeGl.marginHeight = 0;
    // secondPageComposite.setLayout(secondPageCompositeGl);
    // secondPageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable = new Grid(contentPanel, SWT.BORDER | SWT.V_SCROLL);
    gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    gridTable.setHeaderVisible(true);
    gridTable.setAutoHeight(true);
    gridTable.setRowsResizeable(true);
    gridTable.setData("selectedBgColor", selectedBgColor);
    final GridColumn idItem = new GridColumn(gridTable, SWT.NONE);
    idItem.setText(Messages.getString("view.TerminologyViewPart.idItem"));
    idColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    idColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
    idItem.setCellRenderer(idColumnCellRenderer);
    idItem.setWordWrap(true);
    srcTableColumn = new GridColumn(gridTable, SWT.NONE);
    srcTableColumn.setText(Messages.getString("view.TerminologyViewPart.srcTableColumn"));
    srcColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    srcTableColumn.setCellRenderer(srcColumnCellRenderer);
    srcTableColumn.setWordWrap(true);
    tgtTableColumn = new GridColumn(gridTable, SWT.NONE);
    tgtTableColumn.setText(Messages.getString("view.TerminologyViewPart.tgtTableColumn"));
    tgtColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    tgtTableColumn.setCellRenderer(tgtColumnCellRenderer);
    tgtTableColumn.setWordWrap(true);
    final GridColumn propertyColumn = new GridColumn(gridTable, SWT.NONE);
    propertyColumn.setText(Messages.getString("view.TerminologyViewPart.propertyColumn"));
    propColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
    propertyColumn.setCellRenderer(propColumnCellRenderer);
    propertyColumn.setWordWrap(true);
    copyEnable = new GridCopyEnable(gridTable);
    srcColumnCellRenderer.setCopyEnable(copyEnable);
    tgtColumnCellRenderer.setCopyEnable(copyEnable);
    // 设置列宽按比例
    contentPanel.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle area = contentPanel.getClientArea();
            Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // - 2 * gridTable.getBorderWidth();
            int width = area.width;
            if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
                Point vBarSize = gridTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            gridTable.setSize(area.width, area.height);
            width -= 45;
            idItem.setWidth(45);
            srcTableColumn.setWidth((int) (width * 0.4));
            tgtTableColumn.setWidth((int) (width * 0.4));
            propertyColumn.setWidth((int) (width * 0.2));
        }
    });
    Composite statusComposite = new Composite(contentPanel, SWT.NONE);
    GridLayout statusComptGridLayout = new GridLayout(2, false);
    statusComptGridLayout.marginBottom = -1;
    statusComptGridLayout.marginLeft = -1;
    statusComptGridLayout.marginRight = -1;
    statusComptGridLayout.marginTop = -1;
    statusComptGridLayout.marginWidth = 0;
    statusComptGridLayout.marginHeight = 0;
    statusComposite.setLayout(statusComptGridLayout);
    statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tipLabel = new CLabel(statusComposite, SWT.NONE);
    tipLabel.setAlignment(SWT.LEFT);
    CLabel label = new CLabel(statusComposite, SWT.None);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd.heightHint = 20;
    label.setLayoutData(gd);
    gridTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectItem();
        }
    });
    gridTable.addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            firstAction.run();
        }
    });
    initHookMenu();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

CLabel (org.eclipse.swt.custom.CLabel)205 Composite (org.eclipse.swt.widgets.Composite)89 GridData (org.eclipse.swt.layout.GridData)86 FormAttachment (org.eclipse.swt.layout.FormAttachment)85 FormData (org.eclipse.swt.layout.FormData)85 Point (org.eclipse.swt.graphics.Point)78 GridLayout (org.eclipse.swt.layout.GridLayout)71 GC (org.eclipse.swt.graphics.GC)49 Button (org.eclipse.swt.widgets.Button)43 Node (org.talend.designer.core.ui.editor.nodes.Node)43 Control (org.eclipse.swt.widgets.Control)39 Label (org.eclipse.swt.widgets.Label)37 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)30 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)29 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)27 Text (org.eclipse.swt.widgets.Text)27 CCombo (org.eclipse.swt.custom.CCombo)18 INode (org.talend.core.model.process.INode)14 ModifyListener (org.eclipse.swt.events.ModifyListener)13