コード例 #1
0
  /** Rewrite "/css/jeeeyul-custom.css" with user preference. */
  public void rewrite() {
    try {
      CSSEngine cssEngine = WidgetElement.getEngine(display);
      ExtendedDocumentCSS documentCSS = (ExtendedDocumentCSS) cssEngine.getDocumentCSS();

      StyleSheet customThemeSheet = findCustomThemeSheet(documentCSS);

      CustomThemeGenerator generator =
          new CustomThemeGenerator(JThemesCore.getDefault().getPreferenceStore());

      String newCSSContent = generator.generate().toString();
      StyleSheet newSheet = cssEngine.parseStyleSheet(new StringReader(newCSSContent));

      StyleSheetList oldSheetList = documentCSS.getStyleSheets();
      List<StyleSheet> newSheetList = new ArrayList<StyleSheet>();

      for (int i = 0; i < oldSheetList.getLength(); i++) {
        StyleSheet oldSheet = oldSheetList.item(i);
        if (oldSheet != customThemeSheet) {
          if (!newSheetList.contains(oldSheet)) newSheetList.add(oldSheet);
        } else {
          if (!newSheetList.contains(newSheet)) newSheetList.add(newSheet);
        }
      }

      documentCSS.removeAllStyleSheets();
      for (StyleSheet each : newSheetList) {
        documentCSS.addStyleSheet(each);
      }

      cssEngine.reapply();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  @Override
  public boolean applyCSSProperty(
      Object element, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    Widget widget = SWTElementHelpers.getWidget(element);
    if (widget instanceof CTabItem) {
      Item item = (Item) widget;
      boolean showClose = ((Boolean) engine.convert(value, Boolean.class, null)).booleanValue();
      if ("selected".equals(pseudo)) {
        Control parent = getParent(widget);

        ShowCloseSelectionListener listener =
            (ShowCloseSelectionListener)
                parent.getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY);
        if (listener == null) {
          listener = new ShowCloseSelectionListener(engine);
          parent.addListener(SWT.Paint, listener);
          parent.setData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY, listener);
        } else {
          listener.setEngine(engine);
        }
        item = getSelection(getParent(widget));

        listener.setSelection(item);
        if (item != null) {
          setShowClose(item, showClose);
        }
      } else {
        setShowClose(item, showClose);
      }
      return true;
    }
    return false;
  }
 @Override
 public void applyCSSProperty(Object element, CSSValue value, String pseudo, CSSEngine engine)
     throws Exception {
   if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
     CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
     short type = primitiveValue.getPrimitiveType();
     switch (type) {
       case CSSPrimitiveValue.CSS_IDENT:
       case CSSPrimitiveValue.CSS_RGBCOLOR:
         engine.applyCSSProperty(element, "background-color", value, pseudo);
         break;
       case CSSPrimitiveValue.CSS_URI:
         engine.applyCSSProperty(element, "background-image", value, pseudo);
         break;
     }
   }
 }
コード例 #4
0
    @Override
    public void handleEvent(Event e) {

      Item selection = getSelection(e.widget);

      if (selection == null || selection.isDisposed() || this.selection == selection) {
        return;
      }

      Item[] items = getItems(e.widget);
      int selectionIndex = getSelectionIndex(e.widget);

      boolean selectionSet = false;

      CSSStyleDeclaration selectedStyle =
          engine.getViewCSS().getComputedStyle(engine.getElement(selection), "selected");
      if (selectedStyle != null) {
        CSSValue value = selectedStyle.getPropertyCSSValue("show-close");
        if (value != null) {
          setShowClose(selection, Boolean.parseBoolean(value.getCssText()));
          selectionSet = true;
        }
      }

      CSSStyleDeclaration unselectedStyle =
          engine.getViewCSS().getComputedStyle(engine.getElement(selection), null);
      if (unselectedStyle == null) {
        for (int i = 0; i < items.length; i++) {
          if (selectionSet && i != selectionIndex) {
            setShowClose(items[i], false);
          }
        }
      } else {
        CSSValue value = unselectedStyle.getPropertyCSSValue("show-close");
        boolean unselectedShowClose =
            value == null ? false : Boolean.parseBoolean(value.getCssText());
        for (int i = 0; i < items.length; i++) {
          if (selectionSet && i != selectionIndex) {
            setShowClose(items[i], unselectedShowClose);
          }
        }
      }

      this.selection = selection;
    }
コード例 #5
0
 public void applyCSSProperty(
     Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
     throws Exception {
   boolean isSingle = (Boolean) engine.convert(value, Boolean.class, null);
   if (control instanceof CTabFolder) {
     CTabFolder folder = (CTabFolder) control;
     folder.setSingle(isSingle);
   }
 }
コード例 #6
0
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof FormText)) return;

    FormText formText = (FormText) control;
    if (ICathyConstants.PROPERTY_HYPERLINK_COLOR.equals(property)) {
      if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        Color hyperlinkColor = (Color) engine.convert(value, Color.class, formText.getDisplay());
        HyperlinkSettings hyperlinkSettings = formText.getHyperlinkSettings();
        hyperlinkSettings.setForeground(hyperlinkColor);
      }
    } else if (ICathyConstants.PROPERTY_ACTIVE_HYPERLINK_COLOR.equals(property)) {
      Color activeHyperlinkColor =
          (Color) engine.convert(value, Color.class, formText.getDisplay());
      formText.getHyperlinkSettings().setActiveForeground(activeHyperlinkColor);
    }
  }
コード例 #7
0
 @Override
 protected String retrieveCSSProperty(
     Control control, String property, String pseudo, CSSEngine engine) throws Exception {
   if (control instanceof ToolBar) {
     if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
       Color fgColor = ((ToolBar) control).getForeground();
       return engine.convert(fgColor, Color.class, null);
     }
   }
   return null;
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.e4.ui.css.core.dom.properties.providers.
  * AbstractCSSPropertyHandlerProvider
  * #getDefaultCSSStyleDeclaration(org.eclipse
  * .e4.ui.css.core.engine.CSSEngine,
  * org.eclipse.e4.ui.css.core.dom.CSSStylableElement,
  * org.w3c.dom.css.CSSStyleDeclaration)
  */
 protected CSSStyleDeclaration getDefaultCSSStyleDeclaration(
     CSSEngine engine,
     CSSStylableElement stylableElement,
     CSSStyleDeclaration newStyle,
     String pseudoE)
     throws Exception {
   if (stylableElement.getDefaultStyleDeclaration(pseudoE) != null)
     return stylableElement.getDefaultStyleDeclaration(pseudoE);
   if (newStyle != null) {
     StringBuffer style = null;
     int length = newStyle.getLength();
     for (int i = 0; i < length; i++) {
       String propertyName = newStyle.item(i);
       String[] compositePropertiesNames = engine.getCSSCompositePropertiesNames(propertyName);
       if (compositePropertiesNames != null) {
         for (int j = 0; j < compositePropertiesNames.length; j++) {
           propertyName = compositePropertiesNames[j];
           String s = getCSSPropertyStyle(engine, stylableElement, propertyName, pseudoE);
           if (s != null) {
             if (style == null) style = new StringBuffer();
             style.append(s);
           }
         }
       } else {
         String s = getCSSPropertyStyle(engine, stylableElement, propertyName, pseudoE);
         if (s != null) {
           if (style == null) style = new StringBuffer();
           style.append(s);
         }
       }
     }
     if (style != null) {
       CSSStyleDeclaration defaultStyleDeclaration =
           engine.parseStyleDeclaration(style.toString());
       stylableElement.setDefaultStyleDeclaration(pseudoE, defaultStyleDeclaration);
       return defaultStyleDeclaration;
     }
   }
   return stylableElement.getDefaultStyleDeclaration(pseudoE);
 }
コード例 #9
0
 public void testCommaSeparatedList() throws Exception {
   CSSValue value = engine.parsePropertyValue("34, 34, 34");
   assertTrue(value instanceof CSSValueList);
   CSSValueList list = (CSSValueList) value;
   assertEquals(list.getCssValueType(), CSSValue.CSS_VALUE_LIST);
   assertEquals(5, list.getLength());
   // FIXME: see comments in bug 278139
   for (int i = 0; i < list.getLength(); i++) {
     assertTrue(list.item(i) instanceof Measure);
   }
   assertEquals(CSSPrimitiveValue.CSS_NUMBER, ((Measure) list.item(0)).getPrimitiveType());
   assertEquals(CSSPrimitiveValue.CSS_CUSTOM, ((Measure) list.item(1)).getPrimitiveType());
   assertEquals(CSSPrimitiveValue.CSS_NUMBER, ((Measure) list.item(2)).getPrimitiveType());
   assertEquals(CSSPrimitiveValue.CSS_CUSTOM, ((Measure) list.item(3)).getPrimitiveType());
   assertEquals(CSSPrimitiveValue.CSS_NUMBER, ((Measure) list.item(4)).getPrimitiveType());
   // use String#matches() as there may be white-space differences
   assertTrue(value.getCssText().matches("34\\s*,\\s*34\\s*,\\s*34"));
 }
コード例 #10
0
 public void testList() throws Exception {
   CSSValue value = engine.parsePropertyValue("34 34 34");
   assertTrue(value instanceof CSSValueList);
   assertEquals(((CSSValueList) value).getCssValueType(), CSSValue.CSS_VALUE_LIST);
   assertEquals(3, ((CSSValueList) value).getLength());
   assertTrue(((CSSValueList) value).item(0) instanceof Measure);
   assertEquals(
       CSSPrimitiveValue.CSS_NUMBER,
       ((Measure) ((CSSValueList) value).item(0)).getPrimitiveType());
   assertTrue(((CSSValueList) value).item(1) instanceof Measure);
   assertEquals(
       CSSPrimitiveValue.CSS_NUMBER,
       ((Measure) ((CSSValueList) value).item(1)).getPrimitiveType());
   assertTrue(((CSSValueList) value).item(2) instanceof Measure);
   assertEquals(
       CSSPrimitiveValue.CSS_NUMBER,
       ((Measure) ((CSSValueList) value).item(2)).getPrimitiveType());
   assertEquals("34 34 34", value.getCssText());
 }
コード例 #11
0
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof ToolBar)) return;

    ToolBar toolBar = (ToolBar) control;
    if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
      Color color = (Color) engine.convert(value, Color.class, toolBar.getDisplay());
      toolBar.setForeground(color);

      ToolItem[] items = toolBar.getItems();
      for (ToolItem each : items) {
        String text = each.getText();
        each.setText(text);
      }
    } else if (ICathyConstants.PROPERTY_VIEW_MENU.equals(property)) {
      if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
          String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
          ImageDescriptor imageDescriptor =
              ImageDescriptor.createFromURL(new URL(imageUrl.toString()));
          Image image = JFaceResources.getResources().createImage(imageDescriptor);
          if (TOOLBAR_TAG_VIEW_MENU.equals(toolBar.getData())) {
            toolBar.getItem(0).setImage(image);
          }
        }
      }
    }
    //        else if ("xswt-view-properties-pin".equals(property)) {
    //            ToolItem[] items = toolBar.getItems();
    //            for (ToolItem each : items) {
    //                Object data = each.getData();
    //                if (data instanceof ActionContributionItem) {
    //                    String id = ((ActionContributionItem) data).getId();
    //                    if (id.contains("org.eclipse.ui.views.properties.PinPropertySheetAction"))
    // {
    //
    //                    }
    //                }
    //            }
    //        }
  }
コード例 #12
0
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof CTabFolder)) {
      return;
    }
    CTabFolder folder = (CTabFolder) control;
    CTabFolderRenderer renderer = folder.getRenderer();
    if (!(renderer instanceof ICTabFolderRendering)) return;

    ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;

    Image image = null;
    if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
      if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
        String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
        ImageDescriptor imageDescriptor =
            ImageDescriptor.createFromURL(new URL(imageUrl.toString()));
        image = JFaceResources.getResources().createImage(imageDescriptor);
      }
    }

    if (ICathyConstants.PROPERTY_MAXIMIZE_IMAGE.equals(property)) {
      tabFolderRendering.setMaximizeImage(image);
    } else if (ICathyConstants.PROPERTY_MINIMIZE_IMAGE.equals(property)) {
      tabFolderRendering.setMinimizeImage(image);
    } else if (ICathyConstants.PROPERTY_CLOSE_IMAGE.equals(property)) {
      tabFolderRendering.setCloseImage(image);
    } else if (ICathyConstants.PROPERTY_CLOSE_HOVER_IMAGE.equals(property)) {
      tabFolderRendering.setClsoeHoverImage(image);
    } else if (ICathyConstants.PROPERTY_CHEVRON_VISIBLE.equals(property)) {
      ReflectionSupport<CTabFolder> reflect = new ReflectionSupport<CTabFolder>(CTabFolder.class);
      boolean chevronVisible = (Boolean) engine.convert(value, Boolean.class, null);
      Method setChevronVisible =
          reflect.getMethod(METHOD_SET_CHEVRON_VISIBLE, new Class<?>[] {boolean.class});
      reflect.executeMethod(setChevronVisible, folder, new Object[] {chevronVisible});
    }
  }
コード例 #13
0
 public void testURI() throws Exception {
   CSSValue value = engine.parsePropertyValue("url(./somepath/picture.gif)");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_URI);
   assertEquals("url(./somepath/picture.gif)", value.getCssText());
 }
コード例 #14
0
 @Override
 public Object convert(CSSValue value, CSSEngine engine, Object context) throws Exception {
   Display display = (Display) context;
   return CSSSWTImageHelper.getImage(value, engine.getResourcesLocatorManager(), display);
 }
コード例 #15
0
 public void testIdentifier() throws Exception {
   CSSValue value = engine.parsePropertyValue("SomeWord");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_IDENT);
   assertEquals("SomeWord", value.getCssText());
 }
コード例 #16
0
 public void testPercent() throws Exception {
   CSSValue value = engine.parsePropertyValue("30%");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_PERCENTAGE);
   assertEquals("30.0%", value.getCssText());
 }
コード例 #17
0
 public void testPixel() throws Exception {
   CSSValue value = engine.parsePropertyValue("26px");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_PX);
   assertEquals("26.0px", value.getCssText());
 }
コード例 #18
0
 public void testInch() throws Exception {
   CSSValue value = engine.parsePropertyValue("88in");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_IN);
   assertEquals("88.0in", value.getCssText());
 }
コード例 #19
0
 public void testEm() throws Exception {
   CSSValue value = engine.parsePropertyValue("75em");
   assertTrue(value instanceof Measure);
   assertEquals(((Measure) value).getPrimitiveType(), CSSPrimitiveValue.CSS_EMS);
   assertEquals("75.0em", value.getCssText());
 }
コード例 #20
0
 public void testFloat() throws Exception {
   CSSValue value = engine.parsePropertyValue("2.0");
   assertTrue(value instanceof Measure);
   assertEquals("2.0", value.getCssText());
 }