blob: 3163be9bef2a79b3d538245889a0efd774b3aed5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006 Sybase, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sybase, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.property;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.w3c.dom.css.CSSValue;
/**
* The result value will always be integer, range 100-900 This class has already
* translate things like "normal", "bold", "bolder", "lighter" into integer
* value.
*
* @author mengbo
*/
public class FontWeightMeta extends CSSPropertyMeta {
public static final Integer NORMAL_WEIGHT = new Integer(400);
public static final Integer BOLD_WEIGHT = new Integer(700);
static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NORMAL,
ICSSPropertyID.VAL_BOLD, ICSSPropertyID.VAL_BOLDER,
ICSSPropertyID.VAL_LIGHTER };
private Logger _log = PDPlugin.getLogger(FontWeightMeta.class);
/**
* @param inherit
* @param initvalue
*/
public FontWeightMeta() {
super(true, NORMAL_WEIGHT);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
*/
protected String[] getKeywordValues() {
return KEYWORDS;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue,
* java.lang.String,
* org.eclipse.jst.pagedesigner.css2.style.AbstractStyle)
*/
public Object calculateCSSValueResult(CSSValue value, String propertyName,
ICSSStyle style) {
String text = value.getCssText();
String result = checkKeywordValues(text);
if (result == null) {
try {
int i = Integer.parseInt(text);
if (i < 100) {
i = 100;
}
if (i > 900) {
i = 900;
}
return new Integer(i);
} catch (Exception ex) {
// Error in integer processing.
_log.error("Info.FontWeightMeta.0", ex); //$NON-NLS-1$
return NORMAL_WEIGHT;
}
} else if (ICSSPropertyID.VAL_NORMAL.equals(result)) {
return NORMAL_WEIGHT;
} else if (ICSSPropertyID.VAL_BOLD.equals(result)) {
return BOLD_WEIGHT;
} else if (ICSSPropertyID.VAL_BOLDER.equals(result)) {
// int i = style.getParentStyle().getCSSFont().getWeight() + 100;
// if (i < 100)
// i = 100;
// if (i > 900)
// i = 900;
// return new Integer(i);
return BOLD_WEIGHT;
} else if (ICSSPropertyID.VAL_LIGHTER.equals(result)) {
int i = style.getParentStyle().getCSSFont().getWeight() - 100;
if (i < 100) {
i = 100;
}
if (i > 900) {
i = 900;
}
return new Integer(i);
}
return NORMAL_WEIGHT;
}
}