Example #1
0
 private void setAndTest(String themeId, IPropertyChangeListener listener) {
   JFaceResources.getFontRegistry().addListener(listener);
   JFaceResources.getColorRegistry().addListener(listener);
   fManager.setCurrentTheme(themeId);
   ITheme theme = fManager.getTheme(themeId);
   assertEquals(theme, fManager.getCurrentTheme());
   {
     FontRegistry jfaceFonts = JFaceResources.getFontRegistry();
     FontRegistry themeFonts = theme.getFontRegistry();
     // don't test for equality - other tests (or clients) may be pushing
     // new items into jface
     assertTrue(jfaceFonts.getKeySet().containsAll(themeFonts.getKeySet()));
     for (Iterator i = themeFonts.getKeySet().iterator(); i.hasNext(); ) {
       String key = (String) i.next();
       assertArrayEquals(themeFonts.getFontData(key), jfaceFonts.getFontData(key));
     }
   }
   {
     ColorRegistry jfaceColors = JFaceResources.getColorRegistry();
     ColorRegistry themeColors = theme.getColorRegistry();
     assertTrue(jfaceColors.getKeySet().containsAll(themeColors.getKeySet()));
     for (Iterator i = themeColors.getKeySet().iterator(); i.hasNext(); ) {
       String key = (String) i.next();
       assertEquals(themeColors.getRGB(key), jfaceColors.getRGB(key));
     }
   }
   JFaceResources.getFontRegistry().removeListener(listener);
   JFaceResources.getColorRegistry().removeListener(listener);
 }
  /**
   * Installs the given color in the preference store and optionally the color registry.
   *
   * @param definition the color definition
   * @param theme the theme defining the color
   * @param store the preference store from which to set and obtain color data
   * @param setInRegistry whether the color should be put into the registry
   */
  private static void installColor(
      ColorDefinition definition, ITheme theme, IPreferenceStore store, boolean setInRegistry) {

    // TODO: store shouldn't be null, should assert instead of checking null all over

    ColorRegistry registry = theme.getColorRegistry();

    String id = definition.getId();
    String key = createPreferenceKey(theme, id);
    RGB prefColor = store != null ? PreferenceConverter.getColor(store, key) : null;
    RGB defaultColor =
        (definition.getValue() != null)
            ? definition.getValue()
            : registry.getRGB(definition.getDefaultsTo());

    if (prefColor == null || prefColor == PreferenceConverter.COLOR_DEFAULT_DEFAULT) {
      prefColor = defaultColor;
    }

    // if the preference value isn't the default then retain that pref value
    RGB colorToUse = !store.isDefault(key) ? prefColor : defaultColor;

    if (setInRegistry) {
      registry.put(id, colorToUse);
    }

    if (store != null) {
      PreferenceConverter.setDefault(store, key, defaultColor);
    }
  }
 private void inititalizeColors() {
   if (getSite().getShell().isDisposed()) return;
   Display display = getSite().getShell().getDisplay();
   if (display == null || display.isDisposed()) return;
   setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
   ColorRegistry registry = JFaceResources.getColorRegistry();
   registry.addListener(this);
   fBackgroundColorRGB = registry.getRGB(getBackgroundColorKey());
   Color bgColor;
   if (fBackgroundColorRGB == null) {
     bgColor = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
     fBackgroundColorRGB = bgColor.getRGB();
   } else {
     bgColor = new Color(display, fBackgroundColorRGB);
     fBackgroundColor = bgColor;
   }
   setBackground(bgColor);
 }