List of usage examples for org.eclipse.jface.resource DataFormatException DataFormatException
public DataFormatException(String message)
From source file:com.aptana.ide.core.ui.ColorPair.java
License:Open Source License
/** * Converts the given value into an SWT RGB color value. This method fails if the value does not * represent an RGB color value.//from w w w.j a v a2s. co m * <p> * A valid RGB color value representation is a string of the form * <code><it>red</it>,<it>green</it></code>,<it>blue</it></code> where <code><it>red</it></code>, * <it>green</it></code>, and <code><it>blue</it></code> are valid ints. ColorPairs are a * combination of two colors, separated (in string form), be a ';' * </p> * * @param value * the value to be converted * @return the value as an RGB color value * @exception DataFormatException * if the given value does not represent an RGB color value */ public static ColorPair asColorPair(String value) throws DataFormatException { if (value == null) { throw new DataFormatException("Null doesn't represent a valid ColorPair"); //$NON-NLS-1$ } StringTokenizer stok = new StringTokenizer(value, ";"); //$NON-NLS-1$ try { String color1 = stok.nextToken(); String color2 = null; if (stok.hasMoreTokens()) { color2 = stok.nextToken(); return new ColorPair(StringConverter.asRGB(color1), StringConverter.asRGB(color2)); } else { return new ColorPair(StringConverter.asRGB(color1), null); } } catch (NoSuchElementException e) { throw new DataFormatException(e.getMessage()); } }
From source file:org.codecover.eclipse.preferences.RGBWithBoundaries.java
License:Open Source License
/** * Sets the values of this RGBWithBoundaries according to the given string, * which can be created by calling toString(). UpperBoundary & lowerBoundary * are set so lowerBoundary <= upperBoundary * // w ww. j av a 2s.co m * @param string * an encoding of a RGBWithBoundaries * @throws DataFormatException * thrown, if stringformat doesn't fit */ public void setValues(String string) throws DataFormatException { String[] elements = string.split(SEPERATOR); if (elements.length == 3) { this.setValues(StringConverter.asRGB(elements[0]), StringConverter.asInt(elements[1]), StringConverter.asInt(elements[2])); } else { throw new DataFormatException("Invalid data format. " //$NON-NLS-1$ + string + " doesn't consist of three parts devided by \"" //$NON-NLS-1$ + SEPERATOR + "\""); //$NON-NLS-1$ } }