< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalUtils.java

Print this page




 170 
 171     static int getInt(Object key, int defaultValue) {
 172         Object value = UIManager.get(key);
 173 
 174         if (value instanceof Integer) {
 175             return ((Integer)value).intValue();
 176         }
 177         if (value instanceof String) {
 178             try {
 179                 return Integer.parseInt((String)value);
 180             } catch (NumberFormatException nfe) {}
 181         }
 182         return defaultValue;
 183     }
 184 
 185     //
 186     // Ocean specific stuff.
 187     //
 188     /**
 189      * Draws a radial type gradient. The gradient will be drawn vertically if
 190      * <code>vertical</code> is true, otherwise horizontally.
 191      * The UIManager key consists of five values:
 192      * r1 r2 c1 c2 c3. The gradient is broken down into four chunks drawn
 193      * in order from the origin.
 194      * <ol>
 195      * <li>Gradient r1 % of the size from c1 to c2
 196      * <li>Rectangle r2 % of the size in c2.
 197      * <li>Gradient r1 % of the size from c2 to c1
 198      * <li>The remaining size will be filled with a gradient from c1 to c3.
 199      * </ol>
 200      *
 201      * @param c Component rendering to
 202      * @param g Graphics to draw to.
 203      * @param key UIManager key used to look up gradient values.
 204      * @param x X coordinate to draw from
 205      * @param y Y coordinate to draw from
 206      * @param w Width to draw to
 207      * @param h Height to draw to
 208      * @param vertical Direction of the gradient
 209      * @return true if <code>key</code> exists, otherwise false.
 210      */
 211     static boolean drawGradient(Component c, Graphics g, String key,
 212                                 int x, int y, int w, int h, boolean vertical) {
 213         @SuppressWarnings("unchecked")
 214         java.util.List<?> gradient = (java.util.List)UIManager.get(key);
 215         if (gradient == null || !(g instanceof Graphics2D)) {
 216             return false;
 217         }
 218 
 219         if (w <= 0 || h <= 0) {
 220             return true;
 221         }
 222 
 223         GradientPainter.INSTANCE.paint(
 224                 c, (Graphics2D)g, gradient, x, y, w, h, vertical);
 225         return true;
 226     }
 227 
 228 
 229     private static class GradientPainter extends CachedPainter {




 170 
 171     static int getInt(Object key, int defaultValue) {
 172         Object value = UIManager.get(key);
 173 
 174         if (value instanceof Integer) {
 175             return ((Integer)value).intValue();
 176         }
 177         if (value instanceof String) {
 178             try {
 179                 return Integer.parseInt((String)value);
 180             } catch (NumberFormatException nfe) {}
 181         }
 182         return defaultValue;
 183     }
 184 
 185     //
 186     // Ocean specific stuff.
 187     //
 188     /**
 189      * Draws a radial type gradient. The gradient will be drawn vertically if
 190      * {@code vertical} is true, otherwise horizontally.
 191      * The UIManager key consists of five values:
 192      * r1 r2 c1 c2 c3. The gradient is broken down into four chunks drawn
 193      * in order from the origin.
 194      * <ol>
 195      * <li>Gradient r1 % of the size from c1 to c2
 196      * <li>Rectangle r2 % of the size in c2.
 197      * <li>Gradient r1 % of the size from c2 to c1
 198      * <li>The remaining size will be filled with a gradient from c1 to c3.
 199      * </ol>
 200      *
 201      * @param c Component rendering to
 202      * @param g Graphics to draw to.
 203      * @param key UIManager key used to look up gradient values.
 204      * @param x X coordinate to draw from
 205      * @param y Y coordinate to draw from
 206      * @param w Width to draw to
 207      * @param h Height to draw to
 208      * @param vertical Direction of the gradient
 209      * @return true if {@code key} exists, otherwise false.
 210      */
 211     static boolean drawGradient(Component c, Graphics g, String key,
 212                                 int x, int y, int w, int h, boolean vertical) {
 213         @SuppressWarnings("unchecked")
 214         java.util.List<?> gradient = (java.util.List)UIManager.get(key);
 215         if (gradient == null || !(g instanceof Graphics2D)) {
 216             return false;
 217         }
 218 
 219         if (w <= 0 || h <= 0) {
 220             return true;
 221         }
 222 
 223         GradientPainter.INSTANCE.paint(
 224                 c, (Graphics2D)g, gradient, x, y, w, h, vertical);
 225         return true;
 226     }
 227 
 228 
 229     private static class GradientPainter extends CachedPainter {


< prev index next >