Exemple #1
0
 public String getCssText(int index) {
   CSSValue value = getProperty(index);
   if (value != null) {
     return value.getCssText();
   }
   return null;
 }
 /*
  * (non-Javadoc)
  * @see org.w3c.dom.css.CSSValue#getCssText()
  */
 public String getCssText() {
   StringBuffer buffer = new StringBuffer();
   for (CSSValue value : values) {
     buffer.append(value.toString());
     buffer.append(" ");
   }
   return buffer.toString();
 }
 public static String getCSSValueKey(CSSValue value) {
   if (value instanceof CSS2FontProperties)
     return getCSSFontPropertiesKey((CSS2FontProperties) value);
   if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)
     return getCSSPrimitiveValueKey((CSSPrimitiveValue) value);
   return null;
 }
 public Object convert(CSSValue value, CSSEngine engine, Object context) throws Exception {
   if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
     CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
     if ("true".equals(primitiveValue.getStringValue())) return Boolean.TRUE;
   }
   return Boolean.FALSE;
 }
    @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;
    }
Exemple #6
0
  public String getCssText() {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < NUMBER_OF_STYLE; i++) {
      // we don't return the format in css as the format
      // is a complex object which can't be represented as
      // css string.
      if (i == IStyle.STYLE_DATA_FORMAT) continue;
      CSSValue value = getProperty(i);
      if (value != null) {
        sb.append(engine.getPropertyName(i));
        sb.append(": ");
        short type = value.getCssValueType();
        switch (type) {
          case CSSValue.CSS_PRIMITIVE_VALUE:
            {
              CSSPrimitiveValue pv = (CSSPrimitiveValue) value;
              short unitType = pv.getPrimitiveType();
              switch (unitType) {
                case CSSPrimitiveValue.CSS_STRING:
                  sb.append("'");
                  sb.append(pv.getStringValue());
                  sb.append("'");
                  break;
                case CSSPrimitiveValue.CSS_URI:
                  sb.append("url('");
                  sb.append(pv.getStringValue());
                  sb.append("')");
                  break;
                default:
                  sb.append(value.getCssText());
              }
            }
            break;
          default:
            sb.append(value.getCssText());
        }
        sb.append("; ");
      }
    }
    if (sb.length() > 2) {
      sb.setLength(sb.length() - 2);
    }
    return sb.toString();
  }
Exemple #7
0
 protected void writeCSSValue(DataOutputStream out, String propertyName, CSSValue value)
     throws IOException {
   int index = getPropertyIndex(propertyName);
   if (index == StyleConstants.STYLE_DATA_FORMAT) {
     DataFormatValue.write(out, (DataFormatValue) value);
   } else {
     IOUtil.writeString(out, value.getCssText());
   }
 }
 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"));
 }
 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());
 }
 @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;
     }
   }
 }
  @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"))
    // {
    //
    //                    }
    //                }
    //            }
    //        }
  }
  @Override
  public boolean applyCSSProperty(
      Object element, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    TipiElement te = (TipiElement) element;
    //		TipiComponent tc = (TipiComponent) element;
    TipiComponent tc = (TipiComponent) te.getNativeWidget();
    //		Object parsed = tc.evaluateExpression(value.getCssText());
    //		String valueString = value.getCssText();
    Operand o = tc.getContext().evaluate(stripQuotes(value.getCssText()), tc, tipiEvent);
    if (o == null) {
      return false;
    }
    Object parsed = o.value;
    //		Object parsed = tc.getContext().evaluateExpression(value.getCssText(), tc, tipiEvent);
    tc.setValue(property, parsed);

    return true;
  }
  @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);
    }
  }
  @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});
    }
  }
Exemple #15
0
 protected String getCssText(CSSValue value) {
   if (value == null) {
     return null;
   }
   return value.getCssText();
 }
 public void testFloat() throws Exception {
   CSSValue value = engine.parsePropertyValue("2.0");
   assertTrue(value instanceof Measure);
   assertEquals("2.0", value.getCssText());
 }
 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());
 }
Exemple #18
0
  public HighlightColor(CSSValue value) {

    Highlight shd = Context.getWmlObjectFactory().createHighlight();
    shd.setVal(value.getCssText());
    this.setObject(shd);
  }
 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());
 }
 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());
 }
 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());
 }
 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());
 }
 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());
 }