Beispiel #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);
 }
 protected void setTheme(ITheme theme) {
   positiveForeground = theme.getColorRegistry().get(POSITIVE_FOREGROUND);
   negativeForeground = theme.getColorRegistry().get(NEGATIVE_FOREGROUND);
   foreground = theme.getColorRegistry().get(FOREGROUND);
   background = theme.getColorRegistry().get(BACKGROUND);
   theme.addPropertyChangeListener(themeChangeListener);
 }
  public void dispose() {
    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    themeManager.removePropertyChangeListener(themeChangeListener);
    ITheme theme = themeManager.getCurrentTheme();
    theme.removePropertyChangeListener(themeChangeListener);

    if (content != null) content.dispose();

    up.dispose();
    down.dispose();
    equal.dispose();
  }
  public static void populateRegistry(
      ITheme theme, FontDefinition[] definitions, IPreferenceStore store) {
    // sort the definitions by dependant ordering so that we process
    // ancestors before children.
    FontDefinition[] copyOfDefinitions = null;

    // the colors to set a default value for, but not a registry value
    FontDefinition[] defaults = null;
    if (!theme.getId().equals(IThemeManager.DEFAULT_THEME)) {
      definitions = addDefaulted(definitions);
      // compute the defaults only if we're setting preferences at this time
      if (store != null) {
        defaults = getDefaults(definitions);
      }
    }

    copyOfDefinitions = new FontDefinition[definitions.length];
    System.arraycopy(definitions, 0, copyOfDefinitions, 0, definitions.length);
    Arrays.sort(copyOfDefinitions, new IThemeRegistry.HierarchyComparator(definitions));

    for (int i = 0; i < copyOfDefinitions.length; i++) {
      FontDefinition definition = copyOfDefinitions[i];
      installFont(definition, theme, store, true);
    }

    if (defaults != null) {
      for (int i = 0; i < defaults.length; i++) {
        installFont(defaults[i], theme, store, false);
      }
    }
  }
  /**
   * 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);
    }
  }
  @Override
  public void initialize(IWorkbenchConfigurer configurer) {
    //  윈도우 위치와 크기 저장
    configurer.setSaveAndRestore(true);

    // 색상변경
    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    ITheme currentTheme = themeManager.getCurrentTheme();
    ColorRegistry colorRegistry = currentTheme.getColorRegistry();
    colorRegistry.put(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START, new RGB(16, 86, 100));
    colorRegistry.put(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END, new RGB(219, 238, 241));
    colorRegistry.put(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR, new RGB(0, 0, 255));

    colorRegistry.put(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT, new RGB(255, 0, 0));

    super.initialize(configurer);
  }
  /**
   * @param theme
   * @param id
   * @return
   */
  public static String createPreferenceKey(ITheme theme, String id) {
    String themeId = theme.getId();
    if (themeId.equals(IThemeManager.DEFAULT_THEME)) {
      return id;
    }

    return themeId + '.' + id;
  }
        public void propertyChange(PropertyChangeEvent event) {
          if (event.getProperty().equals(IThemeManager.CHANGE_CURRENT_THEME)) {
            ((ITheme) event.getOldValue()).removePropertyChangeListener(this);
            setTheme((ITheme) event.getNewValue());
          } else {
            IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
            ITheme theme = themeManager.getCurrentTheme();

            if (event.getProperty().equals(BACKGROUND))
              background = theme.getColorRegistry().get(event.getProperty());
            else if (event.getProperty().equals(FOREGROUND))
              foreground = theme.getColorRegistry().get(event.getProperty());
            else if (event.getProperty().equals(POSITIVE_FOREGROUND))
              positiveForeground = theme.getColorRegistry().get(event.getProperty());
            else if (event.getProperty().equals(NEGATIVE_FOREGROUND))
              negativeForeground = theme.getColorRegistry().get(event.getProperty());
          }

          updateView();
        }
  /* (non-Javadoc)
   * @see org.eclipse.ui.IPresentationPreview#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.themes.ITheme)
   */
  public void createControl(Composite parent, ITheme currentTheme) {
    this.theme = currentTheme;
    folder = new CTabFolder(parent, SWT.BORDER);
    folder.setUnselectedCloseVisible(false);
    folder.setEnabled(false);
    folder.setMaximizeVisible(true);
    folder.setMinimizeVisible(true);

    viewForm = new ViewForm(folder, SWT.NONE);
    viewForm.marginHeight = 0;
    viewForm.marginWidth = 0;
    viewForm.verticalSpacing = 0;
    viewForm.setBorderVisible(false);
    toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.WRAP);
    ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);

    Image hoverImage = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
    toolItem.setImage(hoverImage);

    viewForm.setTopRight(toolBar);

    viewMessage = new CLabel(viewForm, SWT.NONE);
    viewMessage.setText("Etu?"); // $NON-NLS-1$
    viewForm.setTopLeft(viewMessage);

    CTabItem item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Lorem"); // $NON-NLS-1$
    Label text = new Label(viewForm, SWT.NONE);
    viewForm.setContent(text);
    text.setText("Lorem ipsum dolor sit amet"); // $NON-NLS-1$
    text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Ipsum"); // $NON-NLS-1$
    item.setControl(viewForm);
    item.setImage(WorkbenchImages.getImage(ISharedImages.IMG_TOOL_COPY));

    folder.setSelection(item);

    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Dolor"); // $NON-NLS-1$
    item = new CTabItem(folder, SWT.CLOSE);
    item.setText("Sit"); // $NON-NLS-1$

    currentTheme.addPropertyChangeListener(fontAndColorListener);
    setColorsAndFonts();
    setTabPosition();
    setTabStyle();
  }
  /** Set the folder colors and fonts */
  private void setColorsAndFonts() {
    folder.setSelectionForeground(
        theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR));
    folder.setForeground(
        theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR));

    Color[] colors = new Color[2];
    colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
    colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
    colors[0] = theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
    colors[1] = theme.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
    folder.setSelectionBackground(
        colors,
        new int[] {theme.getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT)},
        theme.getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL));

    folder.setFont(theme.getFontRegistry().get(IWorkbenchThemeConstants.TAB_TEXT_FONT));
    viewMessage.setFont(
        theme.getFontRegistry().get(IWorkbenchThemeConstants.VIEW_MESSAGE_TEXT_FONT));
  }
  /**
   * Installs the given font in the preference store and optionally the font registry.
   *
   * @param definition the font definition
   * @param registry the font registry
   * @param store the preference store from which to set and obtain font data
   * @param setInRegistry whether the color should be put into the registry as well as having its
   *     default preference set
   */
  private static void installFont(
      FontDefinition definition, ITheme theme, IPreferenceStore store, boolean setInRegistry) {
    FontRegistry registry = theme.getFontRegistry();

    String id = definition.getId();
    String key = createPreferenceKey(theme, id);
    FontData[] prefFont = store != null ? PreferenceConverter.getFontDataArray(store, key) : null;
    FontData[] defaultFont = null;
    if (definition.getValue() != null) {
      defaultFont = definition.getValue();
    } else if (definition.getDefaultsTo() != null) {
      defaultFont =
          registry.filterData(
              registry.getFontData(definition.getDefaultsTo()),
              Workbench.getInstance().getDisplay());
    } else {
      // values pushed in from jface property files.  Very ugly.
      Display display = Workbench.getInstance().getDisplay();

      // If in high contrast, ignore the defaults in jface and use the default (system) font.
      // This is a hack to address bug #205474. See bug #228207 for a future fix.
      FontData[] fontData =
          JFaceResources.getFontRegistry()
              .getFontData(display.getHighContrast() ? JFaceResources.DEFAULT_FONT : id);
      defaultFont = registry.bestDataArray(fontData, display);
    }

    if (setInRegistry) {
      if (prefFont == null || prefFont == PreferenceConverter.FONTDATA_ARRAY_DEFAULT_DEFAULT) {
        prefFont = defaultFont;
      }

      if (prefFont != null) {
        registry.put(id, prefFont);
      }
    }

    if (defaultFont != null && store != null) {
      PreferenceConverter.setDefault(store, key, defaultFont);
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.ui.IPresentationPreview#dispose()
  */
 public void dispose() {
   disposed = true;
   theme.removePropertyChangeListener(fontAndColorListener);
 }
Beispiel #13
0
  public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH);

    queryViewer = new SourceViewer(sash, null, SWT.MULTI | SWT.WRAP);
    queryString = queryViewer.getTextWidget();
    queryString.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    Color background = queryString.getBackground();
    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    ITheme current = themeManager.getCurrentTheme();
    ColorRegistry colorRegistry = current.getColorRegistry();
    commentCol = colorRegistry.get(ColorProvider.COMMENT_COLOR_PREF);
    keywordCol = colorRegistry.get(ColorProvider.KEYWORD_COLOR_PREF);
    IDocument d = createDocument();
    d.set(Messages.OQLPane_F1ForHelp);

    queryViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            updateActions();
          }
        });

    queryViewer.setDocument(d);
    queryViewer.configure(new OQLTextViewerConfiguration(getSnapshot(), commentCol, keywordCol));
    // Eclipse 4 seems to need this otherwise in high contrast mode the background is white
    queryString.setBackground(background);
    queryString.selectAll();

    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(queryString, "org.eclipse.mat.ui.help.oql"); // $NON-NLS-1$
    queryString.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.keyCode == '\r' && (e.stateMask & SWT.MOD1) != 0) {
              executeAction.run();
              e.doit = false;
            } else if (e.keyCode == ' ' && (e.stateMask & SWT.CTRL) != 0) {
              // ctrl space combination for content assist
              contentAssistAction.run();
            } else if (e.keyCode == SWT.F5) {
              executeAction.run();
              e.doit = false;
            }
          }
        });

    queryString.addFocusListener(
        new FocusListener() {

          public void focusGained(FocusEvent e) {
            IActionBars actionBars = getEditor().getEditorSite().getActionBars();
            actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyQueryStringAction);
            actionBars.updateActionBars();
          }

          public void focusLost(FocusEvent e) {}
        });
    queryString.setFocus();

    createContainer(sash);

    sash.setWeights(new int[] {1, 4});

    makeActions();
    hookContextMenu();
  }