예제 #1
0
  // @see
  // org.gudy.azureus2.plugins.ui.tables.TableCellMouseListener#cellMouseTrigger(org.gudy.azureus2.plugins.ui.tables.TableCellMouseEvent)
  public void cellMouseTrigger(TableCellMouseEvent event) {
    VuzeActivitiesEntry entry = (VuzeActivitiesEntry) event.cell.getDataSource();

    String tooltip = null;
    boolean invalidateAndRefresh = false;

    Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
    String text = (String) event.cell.getTableRow().getData("text");
    if (text == null) {
      return;
    }

    GCStringPrinter sp = null;
    GC gc = new GC(Display.getDefault());
    try {
      if (font != null) {
        gc.setFont(font);
      }
      Rectangle drawBounds = getDrawBounds((TableCellSWT) event.cell);
      sp = new GCStringPrinter(gc, text, drawBounds, true, true, SWT.WRAP | SWT.CENTER);
      sp.calculateMetrics();
    } catch (Exception e) {
      Debug.out(e);
    } finally {
      gc.dispose();
    }

    if (sp != null) {
      URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
      int newCursor;
      if (hitUrl != null) {
        if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
          if (hitUrl.url.equals("download")) {
            String referal = null;
            Object ds = event.cell.getDataSource();
            if (ds instanceof VuzeActivitiesEntry) {
              referal =
                  DLReferals.DL_REFERAL_DASHACTIVITY + "-" + ((VuzeActivitiesEntry) ds).getTypeID();
            }
            TorrentListViewsUtils.downloadDataSource(ds, false, referal);

          } else if (hitUrl.url.equals("play")) {
            String referal = null;
            Object ds = event.cell.getDataSource();
            if (ds instanceof VuzeActivitiesEntry) {
              referal =
                  DLReferals.DL_REFERAL_PLAYDASHACTIVITY
                      + "-"
                      + ((VuzeActivitiesEntry) ds).getTypeID();
            }
            TorrentListViewsUtils.playOrStreamDataSource(ds, referal, false, true);

          } else if (hitUrl.url.equals("launch")) {
            // run via play or stream so we get the security warning
            Object ds = event.cell.getDataSource();
            TorrentListViewsUtils.playOrStreamDataSource(
                ds, DLReferals.DL_REFERAL_LAUNCH, false, true);

          } else if (!UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
            Utils.launch(hitUrl.url);
          } else {
            UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
            if (uif != null) {
              String target = hitUrl.target;
              if (target == null) {
                target = SkinConstants.VIEWID_BROWSER_BROWSE;
              }
              uif.viewURL(hitUrl.url, target, "column.activity.action");
              return;
            }
          }
        }
        Object ds = event.cell.getDataSource();

        newCursor = SWT.CURSOR_HAND;
        if (UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
          tooltip = hitUrl.title;
        } else {
          tooltip = hitUrl.url;
        }
      } else {
        newCursor = SWT.CURSOR_ARROW;
      }

      int oldCursor = ((TableCellSWT) event.cell).getCursorID();
      if (oldCursor != newCursor) {
        invalidateAndRefresh = true;
        ((TableCellSWT) event.cell).setCursorID(newCursor);
      }
    }

    Object o = event.cell.getToolTip();
    if ((o == null) || (o instanceof String)) {
      String oldTooltip = (String) o;
      if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
        invalidateAndRefresh = true;
        event.cell.setToolTip(tooltip);
      }
    }

    if (invalidateAndRefresh) {
      event.cell.invalidate();
      ((TableCellSWT) event.cell).redraw();
    }
  }
예제 #2
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }
  /**
   * @param url
   * @param target
   */
  private void showURL(final String url, String target) {

    if ("_blank".equalsIgnoreCase(target)) {
      Utils.launch(url);
      return;
    }

    if (target.startsWith("tab-")) {
      target = target.substring(4);
    }

    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();

    if (MultipleDocumentInterface.SIDEBAR_SECTION_PLUS.equals(target)) {
      SBC_PlusFTUX.setSourceRef(url.substring(1));
      mdi.showEntryByID(target);
      return;
    }

    // Note; We don't setSourceRef on ContentNetwork here like we do
    // everywhere else because the source ref should already be set
    // by the caller
    if (mdi == null || !mdi.showEntryByID(target)) {
      Utils.launch(url);
      return;
    }

    MdiEntry entry = mdi.getEntry(target);
    entry.addListener(
        new MdiEntryOpenListener() {

          public void mdiEntryOpen(MdiEntry entry) {
            entry.removeListener(this);

            mainWindow.setVisible(true, true);

            if (!(entry instanceof SideBarEntrySWT)) {
              return;
            }
            SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;

            SWTSkinObjectBrowser soBrowser = SWTSkinUtils.findBrowserSO(entrySWT.getSkinObject());

            if (soBrowser != null) {
              // ((SWTSkinObjectBrowser) skinObject).getBrowser().setVisible(false);
              if (url == null || url.length() == 0) {
                soBrowser.restart();
              } else {
                String fullURL = url;
                if (UrlFilter.getInstance().urlCanRPC(url)) {
                  // 4010 Tux: This shouldn't be.. either determine ContentNetwork from
                  //           url or target, or do something..
                  fullURL =
                      ConstantsVuze.getDefaultContentNetwork().appendURLSuffix(url, false, true);
                }

                soBrowser.setURL(fullURL);
              }
            }
          }
        });
  }