예제 #1
0
    @Override
    public void run() {
      try {
        final Map<String, ImageData> urlToImageData = new HashMap<>();
        for (ImageAnnotation annotation : annotations) {
          final String imgSrc = annotation.getUrl();
          if (imgSrc != null && !urlToImageData.containsKey(imgSrc)) {
            try {
              URL location =
                  imageCache.getBase() == null
                      ? new URL(imgSrc)
                      : new URL(imageCache.getBase(), imgSrc);

              try {
                InputStream in = new BufferedInputStream(location.openStream());
                try {
                  urlToImageData.put(imgSrc, new ImageData(in));
                } catch (SWTException e) {
                  if (e.code != SWT.ERROR_INVALID_IMAGE) {
                    throw e;
                  }
                  urlToImageData.put(imgSrc, null);
                } finally {
                  in.close();
                }
              } catch (Exception e) {
                if (WikiTextUiPlugin.getDefault() != null) {
                  WikiTextUiPlugin.getDefault()
                      .log(
                          IStatus.ERROR,
                          NLS.bind(Messages.ImageManager_accessFailed, new Object[] {location}),
                          e);
                }
                urlToImageData.put(imgSrc, null);
              }
            } catch (MalformedURLException e) {
              urlToImageData.put(imgSrc, null);
            }
            display.asyncExec(
                new Runnable() {
                  public void run() {
                    updateImage(imgSrc, urlToImageData.get(imgSrc));
                  }
                });
          }
          if (Thread.currentThread().isInterrupted()) {
            break;
          }
        }
      } finally {
        imageResolver = null;
      }
    }
 /**
  * Initialize default fonts. Causes this to re-read font preferences from the preference store.
  * Calling this method should only be necessary if font preferences have changed, or if the font
  * preference keys have changed.
  *
  * @since 1.3
  * @see #getFontPreference()
  * @see #getMonospaceFontPreference()
  */
 public void initializeDefaultFonts() {
   Font defaultFont = null;
   Font defaultMonospaceFont = null;
   if (WikiTextUiPlugin.getDefault() != null) {
     IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
     FontRegistry fontRegistry = themeManager.getCurrentTheme().getFontRegistry();
     defaultFont = fontRegistry.get(fontPreference);
     defaultMonospaceFont = fontRegistry.get(monospaceFontPreference);
   }
   if (defaultFont == null) {
     // could be the case when running stand-alone
     defaultFont = JFaceResources.getDefaultFont();
   }
   if (this.defaultFont != defaultFont || this.defaultMonospaceFont != defaultMonospaceFont) {
     this.defaultFont = defaultFont;
     this.defaultMonospaceFont = defaultMonospaceFont;
     if (scanner != null) {
       scanner.resetFonts(defaultFont, defaultMonospaceFont);
     }
   }
 }
 public void setMarkupLanguage(MarkupLanguage markupLanguage) {
   templates =
       markupLanguage == null
           ? null
           : WikiTextUiPlugin.getDefault().getTemplates().get(markupLanguage.getName());
 }