You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/05 17:31:51 UTC

svn commit: r821850 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtk/GraphicsUtilities.java src/org/apache/pivot/wtk/skin/ContainerSkin.java src/org/apache/pivot/wtk/skin/LabelSkin.java test/org/apache/pivot/wtk/test/font_test.wtkx

Author: gbrown
Date: Mon Oct  5 15:31:50 2009
New Revision: 821850

URL: http://svn.apache.org/viewvc?rev=821850&view=rev
Log:
Add decodeFont() methods to GraphicsUtilities; update LabelSkin to use these methods (fontBold, fontItalic, and fontSize are still supported but will be removed in a later update).

Added:
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/font_test.wtkx
Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java?rev=821850&r1=821849&r2=821850&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GraphicsUtilities.java Mon Oct  5 15:31:50 2009
@@ -17,6 +17,7 @@
 package org.apache.pivot.wtk;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.GradientPaint;
 import java.awt.Graphics2D;
 import java.awt.LinearGradientPaint;
@@ -65,6 +66,11 @@
     public static final String STOPS_KEY = "stops";
     public static final String OFFSET_KEY = "offset";
 
+    public static final String NAME_KEY = "name";
+    public static final String SIZE_KEY = "size";
+    public static final String BOLD_KEY = "bold";
+    public static final String ITALIC_KEY = "italic";
+
     private GraphicsUtilities() {
     }
 
@@ -317,4 +323,61 @@
 
         return paint;
     }
+
+    public static Font decodeFont(String value) {
+        Font font;
+        if (value.startsWith("{")) {
+            try {
+                font = decodeFont(JSONSerializer.parseMap(value));
+            } catch (SerializationException exception) {
+                throw new IllegalArgumentException(exception);
+            }
+        } else {
+            font = Font.decode(value);
+        }
+
+        return font;
+    }
+
+    public static Font decodeFont(Dictionary<String, ?> value) {
+        Font font = Theme.getTheme().getFont();
+
+        String name;
+        if (value.containsKey(NAME_KEY)) {
+            name = (String)value.get(NAME_KEY);
+        } else {
+            name = font.getName();
+        }
+
+        int size;
+        if (value.containsKey(SIZE_KEY)) {
+            size = (Integer)value.get(SIZE_KEY);
+        } else {
+            size = font.getSize();
+        }
+
+        int style = font.getStyle();
+
+        if (value.containsKey(BOLD_KEY)) {
+            boolean bold = (Boolean)value.get(BOLD_KEY);
+
+            if (bold) {
+                style |= Font.BOLD;
+            } else {
+                style &= ~Font.BOLD;
+            }
+        }
+
+        if (value.containsKey(ITALIC_KEY)) {
+            boolean italic = (Boolean)value.get(ITALIC_KEY);
+
+            if (italic) {
+                style |= Font.ITALIC;
+            } else {
+                style &= ~Font.ITALIC;
+            }
+        }
+
+        return new Font(name, style, size);
+    }
 }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java?rev=821850&r1=821849&r2=821850&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java Mon Oct  5 15:31:50 2009
@@ -177,6 +177,14 @@
         repaintComponent();
     }
 
+    public final void setBackgroundPaint(String backgroundPaint) {
+        if (backgroundPaint == null) {
+            throw new IllegalArgumentException("backgroundPaint is null");
+        }
+
+        setBackgroundPaint(GraphicsUtilities.decodePaint(backgroundPaint));
+    }
+
     public final void setBackgroundPaint(Dictionary<String, ?> backgroundPaint) {
         if (backgroundPaint == null) {
             throw new IllegalArgumentException("backgroundPaint is null");

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java?rev=821850&r1=821849&r2=821850&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/LabelSkin.java Mon Oct  5 15:31:50 2009
@@ -333,7 +333,15 @@
             throw new IllegalArgumentException("font is null.");
         }
 
-        setFont(Font.decode(font));
+        setFont(GraphicsUtilities.decodeFont(font));
+    }
+
+    public final void setFont(Dictionary<String, ?> font) {
+        if (font == null) {
+            throw new IllegalArgumentException("font is null.");
+        }
+
+        setFont(GraphicsUtilities.decodeFont(font));
     }
 
     public int getFontSize() {

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/font_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/font_test.wtkx?rev=821850&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/font_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/font_test.wtkx Mon Oct  5 15:31:50 2009
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Font Test" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Label text="Hello, World!"
+            styles="{font:{name:'Times New Roman', size:24, bold:true, italic:true}}"/>
+    </content>
+</Window>