You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/16 17:16:58 UTC

svn commit: r754926 [32/38] - in /incubator/pivot/tags/v1.0: ./ charts-test/ charts-test/src/ charts-test/src/pivot/ charts-test/src/pivot/charts/ charts-test/src/pivot/charts/test/ charts/ charts/lib/ charts/src/ charts/src/pivot/ charts/src/pivot/cha...

Added: incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPaletteSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPaletteSkin.java?rev=754926&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPaletteSkin.java (added)
+++ incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPaletteSkin.java Mon Mar 16 16:16:40 2009
@@ -0,0 +1,476 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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.
+ */
+package pivot.wtk.skin.terra;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+
+import pivot.collections.Dictionary;
+import pivot.wtk.Bounds;
+import pivot.wtk.Button;
+import pivot.wtk.ButtonPressListener;
+import pivot.wtk.Component;
+import pivot.wtk.ComponentMouseButtonListener;
+import pivot.wtk.ComponentMouseListener;
+import pivot.wtk.Dimensions;
+import pivot.wtk.Display;
+import pivot.wtk.FlowPane;
+import pivot.wtk.HorizontalAlignment;
+import pivot.wtk.Insets;
+import pivot.wtk.Label;
+import pivot.wtk.LinkButton;
+import pivot.wtk.Mouse;
+import pivot.wtk.Palette;
+import pivot.wtk.Point;
+import pivot.wtk.Theme;
+import pivot.wtk.VerticalAlignment;
+import pivot.wtk.Window;
+import pivot.wtk.WindowListener;
+import pivot.wtk.effects.DropShadowDecorator;
+import pivot.wtk.media.Image;
+import pivot.wtk.skin.WindowSkin;
+
+/**
+ * Palette skin class.
+ *
+ * @author gbrown
+ */
+public class TerraPaletteSkin extends WindowSkin {
+    /**
+     * Close button image.
+     *
+     * @author gbrown
+     */
+    protected class CloseImage extends Image {
+        public int getWidth() {
+            return 6;
+        }
+
+        public int getHeight() {
+            return 6;
+        }
+
+        public void paint(Graphics2D graphics) {
+            graphics.setPaint(titleBarColor);
+            graphics.setStroke(new BasicStroke(2));
+
+            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                RenderingHints.VALUE_ANTIALIAS_ON);
+
+            graphics.drawLine(0, 0, 5, 5);
+            graphics.drawLine(0, 5, 5, 0);
+        }
+    }
+
+    private class MoveMouseHandler implements ComponentMouseListener, ComponentMouseButtonListener {
+        public boolean mouseMove(Component component, int x, int y) {
+            Display display = (Display)component;
+
+            // Pretend that the mouse can't move off screen (off the display)
+            x = Math.min(Math.max(x, 0), display.getWidth() - 1);
+            y = Math.min(Math.max(y, 0), display.getHeight() - 1);
+
+            // Calculate the would-be new window location
+            int windowX = x - dragOffset.x;
+            int windowY = y - dragOffset.y;
+
+            Window window = (Window)getComponent();
+            window.setLocation(windowX, windowY);
+
+            return false;
+        }
+
+        public void mouseOver(Component component) {
+            // No-op
+        }
+
+        public void mouseOut(Component component) {
+            // No-op
+        }
+
+        public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
+            return false;
+        }
+
+        public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
+            assert (component instanceof Display);
+            component.getComponentMouseListeners().remove(this);
+            component.getComponentMouseButtonListeners().remove(this);
+
+            return false;
+        }
+
+        public void mouseClick(Component component, Mouse.Button button, int x, int y,
+            int count) {
+        }
+    }
+
+    private Image closeImage = new CloseImage();
+
+    private FlowPane titleBarFlowPane = new FlowPane();
+    private FlowPane titleFlowPane = new FlowPane();
+    private FlowPane buttonFlowPane = new FlowPane();
+
+    private Label titleLabel = new Label();
+    private LinkButton closeButton = new LinkButton(closeImage);
+
+    private DropShadowDecorator dropShadowDecorator = null;
+
+    private Point dragOffset = null;
+    private MoveMouseHandler moveMouseHandler = new MoveMouseHandler();
+
+    private Insets padding = new Insets(4);
+
+    private WindowListener ownerListener = new WindowListener() {
+        public void titleChanged(Window window, String previousTitle) {
+            // No-op
+        }
+
+        public void iconChanged(Window window, Image previousIcon) {
+            // No-op
+        }
+
+        public void contentChanged(Window window, Component previousContent) {
+            // No-op
+        }
+
+        public void ownerChanged(Window window, Window previousOwner) {
+            // No-op
+        }
+
+        public void activeChanged(Window window) {
+            getComponent().setDisplayable(window.isActive());
+        }
+
+        public void maximizedChanged(Window window) {
+            // No-op
+        }
+    };
+
+    private Color titleBarColor;
+    private Color titleBarBackgroundColor;
+    private Color titleBarBorderColor;
+    private Color contentBorderColor;
+
+    // Derived colors
+    private Color titleBarBevelColor;
+    private Color contentBevelColor;
+
+    public TerraPaletteSkin() {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setBackgroundColor(theme.getColor(10));
+
+        titleBarColor = theme.getColor(4);
+        titleBarBackgroundColor = theme.getColor(16);
+        titleBarBorderColor = theme.getColor(13);
+        contentBorderColor = theme.getColor(7);
+
+        // Set the derived colors
+        titleBarBevelColor = TerraTheme.brighten(titleBarBackgroundColor);
+
+        // The title bar flow pane contains two nested flow panes: one for
+        // the title contents and the other for the buttons
+        titleBarFlowPane.add(titleFlowPane);
+        titleBarFlowPane.add(buttonFlowPane);
+
+        titleBarFlowPane.getStyles().put("horizontalAlignment", HorizontalAlignment.JUSTIFY);
+        titleBarFlowPane.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+        titleBarFlowPane.getStyles().put("padding", new Insets(2, 3, 2, 3));
+
+        // Initialize the title flow pane
+        titleFlowPane.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+        titleFlowPane.add(titleLabel);
+
+        Font font = theme.getFont();
+        titleLabel.getStyles().put("fontBold", true);
+        titleLabel.getStyles().put("fontSize", Math.round(font.getSize2D() * 0.8f));
+        titleLabel.getStyles().put("color", titleBarColor);
+
+        // Initialize the button flow pane
+        buttonFlowPane.getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+        buttonFlowPane.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+        buttonFlowPane.add(closeButton);
+
+        closeButton.getButtonPressListeners().add(new ButtonPressListener() {
+            public void buttonPressed(Button button) {
+                Palette palette = (Palette)getComponent();
+                palette.close();
+            }
+        });
+    }
+
+    @Override
+    public void install(Component component) {
+        super.install(component);
+
+        Palette palette = (Palette)component;
+        palette.add(titleBarFlowPane);
+
+        // Attach the drop-shadow decorator
+        dropShadowDecorator = new DropShadowDecorator(3, 3, 3);
+        palette.getDecorators().add(dropShadowDecorator);
+
+        ownerChanged(palette, null);
+        titleChanged(palette, null);
+    }
+
+    @Override
+    public void uninstall() {
+        Palette palette = (Palette)getComponent();
+        palette.remove(titleBarFlowPane);
+
+        // Detach the drop shadow decorator
+        palette.getDecorators().remove(dropShadowDecorator);
+        dropShadowDecorator = null;
+
+        super.uninstall();
+    }
+
+    public int getPreferredWidth(int height) {
+        int preferredWidth = 0;
+
+        Palette palette = (Palette)getComponent();
+        Component content = palette.getContent();
+
+        Dimensions preferredTitleBarSize = titleBarFlowPane.getPreferredSize();
+        preferredWidth = preferredTitleBarSize.width;
+
+        if (content != null
+            && content.isDisplayable()) {
+            if (height != -1) {
+                height = Math.max(height - preferredTitleBarSize.height - 4 -
+                    padding.top - padding.bottom, 0);
+            }
+
+            preferredWidth = Math.max(preferredWidth,
+                content.getPreferredWidth(height));
+        }
+
+        preferredWidth += (padding.left + padding.right) + 2;
+
+        return preferredWidth;
+    }
+
+    public int getPreferredHeight(int width) {
+        int preferredHeight = 0;
+
+        Palette palette = (Palette)getComponent();
+        Component content = palette.getContent();
+
+        if (width != -1) {
+            width = Math.max(width - 2, 0);
+        }
+
+        preferredHeight = titleBarFlowPane.getPreferredHeight(width);
+
+        if (content != null
+            && content.isDisplayable()) {
+            if (width != -1) {
+                width = Math.max(width - padding.left - padding.right, 0);
+            }
+
+            preferredHeight += content.getPreferredHeight(width);
+        }
+
+        preferredHeight += (padding.top + padding.bottom) + 4;
+
+        return preferredHeight;
+    }
+
+    public Dimensions getPreferredSize() {
+        int preferredWidth = 0;
+        int preferredHeight = 0;
+
+        Palette palette = (Palette)getComponent();
+        Component content = palette.getContent();
+
+        Dimensions preferredTitleBarSize = titleBarFlowPane.getPreferredSize();
+
+        preferredWidth = preferredTitleBarSize.width;
+        preferredHeight = preferredTitleBarSize.height;
+
+        if (content != null
+            && content.isDisplayable()) {
+            Dimensions preferredContentSize = content.getPreferredSize();
+
+            preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
+            preferredHeight += preferredContentSize.height;
+        }
+
+        preferredWidth += (padding.left + padding.right) + 2;
+        preferredHeight += (padding.top + padding.bottom) + 4;
+
+        return new Dimensions(preferredWidth, preferredHeight);
+    }
+
+    public void layout() {
+        Palette palette = (Palette)getComponent();
+
+        int width = getWidth();
+        int height = getHeight();
+
+        // Size/position title bar
+        titleBarFlowPane.setLocation(1, 1);
+        titleBarFlowPane.setSize(Math.max(width - 2, 0),
+            Math.max(titleBarFlowPane.getPreferredHeight(width - 2), 0));
+
+        // Size/position content
+        Component content = palette.getContent();
+
+        if (content != null) {
+            if (content.isDisplayable()) {
+                content.setVisible(true);
+
+                content.setLocation(padding.left + 1,
+                    titleBarFlowPane.getHeight() + padding.top + 3);
+
+                int contentWidth = Math.max(width - (padding.left + padding.right + 2), 0);
+                int contentHeight = Math.max(height - (titleBarFlowPane.getHeight()
+                    + padding.top + padding.bottom + 4), 0);
+
+                content.setSize(contentWidth, contentHeight);
+            } else {
+                content.setVisible(false);
+            }
+        }
+    }
+
+    @Override
+    public void paint(Graphics2D graphics) {
+        // Call the base class to paint the background
+        super.paint(graphics);
+
+        int width = getWidth();
+        int height = getHeight();
+        Dimensions titleBarSize = titleBarFlowPane.getSize();
+
+        // Draw the borders with a 1px solid stroke
+        graphics.setStroke(new BasicStroke());
+
+        // Draw the title area
+        Bounds titleBarRectangle = new Bounds(0, 0, width - 1, titleBarSize.height + 1);
+        graphics.setPaint(titleBarBackgroundColor);
+        graphics.fillRect(titleBarRectangle.x, titleBarRectangle.y,
+            titleBarRectangle.width, titleBarRectangle.height);
+
+        graphics.setPaint(titleBarBorderColor);
+        graphics.drawRect(titleBarRectangle.x, titleBarRectangle.y,
+            titleBarRectangle.width, titleBarRectangle.height);
+
+        graphics.setPaint(titleBarBevelColor);
+        graphics.drawLine(titleBarRectangle.x + 1, titleBarRectangle.y + 1,
+            titleBarRectangle.width - 1, titleBarRectangle.y + 1);
+
+        // Draw the content area
+        Bounds contentAreaRectangle = new Bounds(0, titleBarSize.height + 2,
+            width - 1, height - (titleBarSize.height + 3));
+        graphics.setPaint(contentBorderColor);
+        graphics.drawRect(contentAreaRectangle.x, contentAreaRectangle.y,
+            contentAreaRectangle.width, contentAreaRectangle.height);
+
+        graphics.setPaint(contentBevelColor);
+        graphics.drawLine(contentAreaRectangle.x + 1, contentAreaRectangle.y + 1,
+            contentAreaRectangle.width - 1, contentAreaRectangle.y + 1);
+    }
+
+    @Override
+    public void setBackgroundColor(Color backgroundColor) {
+        super.setBackgroundColor(backgroundColor);
+        contentBevelColor = TerraTheme.brighten(backgroundColor);
+    }
+
+    public Insets getPadding() {
+        return padding;
+    }
+
+    public void setPadding(Insets padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        this.padding = padding;
+        invalidateComponent();
+    }
+
+    public final void setPadding(Dictionary<String, ?> padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        setPadding(new Insets(padding));
+    }
+
+    public final void setPadding(int padding) {
+        setPadding(new Insets(padding));
+    }
+
+    public final void setPadding(Number padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        setPadding(padding.intValue());
+    }
+
+    @Override
+    public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
+        boolean consumed = super.mouseDown(component, button, x, y);
+
+        Window window = (Window)getComponent();
+        boolean maximized = window.isMaximized();
+
+        if (button == Mouse.Button.LEFT
+            && !maximized) {
+            Bounds titleBarBounds = titleBarFlowPane.getBounds();
+
+            if (titleBarBounds.contains(x, y)) {
+                dragOffset = new Point(x, y);
+
+                Display display = window.getDisplay();
+                display.getComponentMouseListeners().add(moveMouseHandler);
+                display.getComponentMouseButtonListeners().add(moveMouseHandler);
+            }
+        }
+
+        return consumed;
+    }
+
+    @Override
+    public void ownerChanged(Window window, Window previousOwner) {
+        super.ownerChanged(window, previousOwner);
+
+        if (previousOwner != null) {
+            previousOwner.getWindowListeners().remove(ownerListener);
+        }
+
+        Window owner = window.getOwner();
+        if (owner != null) {
+            owner.getWindowListeners().add(ownerListener);
+        }
+    }
+
+    @Override
+    public void titleChanged(Window window, String previousTitle) {
+        super.titleChanged(window, previousTitle);
+
+        String title = window.getTitle();
+        titleLabel.setDisplayable(title != null);
+        titleLabel.setText(title);
+    }
+}

Added: incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPanoramaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPanoramaSkin.java?rev=754926&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPanoramaSkin.java (added)
+++ incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPanoramaSkin.java Mon Mar 16 16:16:40 2009
@@ -0,0 +1,587 @@
+package pivot.wtk.skin.terra;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import pivot.wtk.ApplicationContext;
+import pivot.wtk.Button;
+import pivot.wtk.Component;
+import pivot.wtk.ComponentMouseListener;
+import pivot.wtk.Dimensions;
+import pivot.wtk.Keyboard;
+import pivot.wtk.Mouse;
+import pivot.wtk.Panorama;
+import pivot.wtk.Bounds;
+import pivot.wtk.Theme;
+import pivot.wtk.Viewport;
+import pivot.wtk.ViewportListener;
+import pivot.wtk.content.ButtonDataRenderer;
+import pivot.wtk.skin.ButtonSkin;
+import pivot.wtk.skin.ContainerSkin;
+import pivot.wtk.media.Image;
+
+/**
+ * Panorama skin.
+ *
+ * @author gbrown
+ */
+public class TerraPanoramaSkin extends ContainerSkin implements Viewport.Skin, ViewportListener {
+    /**
+     * Abstract base class for button images.
+     */
+    protected abstract class ScrollButtonImage extends Image {
+        public int getWidth() {
+            return BUTTON_SIZE;
+        }
+
+        public int getHeight() {
+            return BUTTON_SIZE;
+        }
+
+        public void paint(Graphics2D graphics) {
+            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                RenderingHints.VALUE_ANTIALIAS_ON);
+
+            graphics.setStroke(new BasicStroke(0));
+            graphics.setPaint(buttonColor);
+        }
+    }
+
+    /**
+     * North button image.
+     */
+    protected class NorthButtonImage extends ScrollButtonImage {
+        public void paint(Graphics2D graphics) {
+            super.paint(graphics);
+
+            int[] xPoints = {0, 3, 6};
+            int[] yPoints = {5, 1, 5};
+            graphics.fillPolygon(xPoints, yPoints, 3);
+            graphics.drawPolygon(xPoints, yPoints, 3);
+        }
+    }
+
+    /**
+     * South button image.
+     */
+    protected class SouthButtonImage extends ScrollButtonImage {
+        public void paint(Graphics2D graphics) {
+            super.paint(graphics);
+
+            int[] xPoints = {0, 3, 6};
+            int[] yPoints = {1, 5, 1};
+            graphics.fillPolygon(xPoints, yPoints, 3);
+            graphics.drawPolygon(xPoints, yPoints, 3);
+        }
+    }
+
+    /**
+     * East button image.
+     */
+    protected class EastButtonImage extends ScrollButtonImage {
+        public void paint(Graphics2D graphics) {
+            super.paint(graphics);
+
+            int[] xPoints = {1, 5, 1};
+            int[] yPoints = {0, 3, 6};
+            graphics.fillPolygon(xPoints, yPoints, 3);
+            graphics.drawPolygon(xPoints, yPoints, 3);
+        }
+    }
+
+    /**
+     * West button image.
+     */
+    protected class WestButtonImage extends ScrollButtonImage {
+        public void paint(Graphics2D graphics) {
+            super.paint(graphics);
+
+            int[] xPoints = {5, 1, 5};
+            int[] yPoints = {0, 3, 6};
+            graphics.fillPolygon(xPoints, yPoints, 3);
+            graphics.drawPolygon(xPoints, yPoints, 3);
+        }
+    }
+
+    protected class ScrollButton extends Button {
+        public ScrollButton(Object buttonData) {
+            super(buttonData);
+
+            setDataRenderer(DEFAULT_DATA_RENDERER);
+            setSkin(new ScrollButtonSkin());
+        }
+
+        @Override
+        public void setToggleButton(boolean toggleButton) {
+            throw new UnsupportedOperationException("Link buttons cannot be toggle buttons.");
+        }
+    }
+
+    public class ScrollButtonSkin extends ButtonSkin {
+        public int getPreferredWidth(int height) {
+            return BUTTON_SIZE + buttonPadding;
+        }
+
+        public int getPreferredHeight(int width) {
+            return BUTTON_SIZE + buttonPadding;
+        }
+
+        public Dimensions getPreferredSize() {
+            return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
+        }
+
+        public void paint(Graphics2D graphics) {
+            ScrollButton scrollButton = (ScrollButton)getComponent();
+            int width = getWidth();
+            int height = getHeight();
+
+            if (buttonBackgroundColor != null) {
+                graphics.setColor(buttonBackgroundColor);
+                graphics.fillRect(0, 0, width, height);
+            }
+
+            Button.DataRenderer dataRenderer = scrollButton.getDataRenderer();
+            dataRenderer.render(scrollButton.getButtonData(), scrollButton, false);
+            dataRenderer.setSize(width - buttonPadding * 2, height - buttonPadding * 2);
+
+            graphics.translate(buttonPadding, buttonPadding);
+            dataRenderer.paint(graphics);
+        }
+
+        /**
+         * @return
+         * <tt>false</tt>; link buttons are not focusable.
+         */
+        @Override
+        public boolean isFocusable() {
+            return false;
+        }
+    }
+
+    private class ScrollCallback implements Runnable {
+        public void run() {
+            Panorama panorama = (Panorama)getComponent();
+
+            if (northButton.isMouseOver()) {
+                int scrollTop = Math.max(panorama.getScrollTop()
+                    - (int)scrollDistance, 0);
+                if (scrollTop == 0) {
+                    ApplicationContext.clearInterval(scrollIntervalID);
+                }
+
+                panorama.setScrollTop(scrollTop);
+            } else if (southButton.isMouseOver()) {
+                int maxScrollTop = getMaxScrollTop();
+                int scrollTop = Math.min(panorama.getScrollTop()
+                    + (int)scrollDistance, maxScrollTop);
+                if (scrollTop == maxScrollTop) {
+                    ApplicationContext.clearInterval(scrollIntervalID);
+                }
+
+                panorama.setScrollTop(scrollTop);
+            } else if (eastButton.isMouseOver()) {
+                System.out.println(eastButton.isVisible());
+                int maxScrollLeft = getMaxScrollLeft();
+                int scrollLeft = Math.min(panorama.getScrollLeft()
+                    + (int)scrollDistance, maxScrollLeft);
+                if (scrollLeft == maxScrollLeft) {
+                    ApplicationContext.clearInterval(scrollIntervalID);
+                }
+
+                System.out.println(scrollLeft + ", " + maxScrollLeft);
+                panorama.setScrollLeft(scrollLeft);
+            } else if (westButton.isMouseOver()) {
+                int scrollLeft = Math.max(panorama.getScrollLeft()
+                    - (int)scrollDistance, 0);
+                if (scrollLeft == 0) {
+                    ApplicationContext.clearInterval(scrollIntervalID);
+                }
+
+                System.out.println(scrollLeft);
+                panorama.setScrollLeft(scrollLeft);
+            }
+
+            scrollDistance = Math.min(scrollDistance * SCROLL_ACCELERATION,
+                MAXIMUM_SCROLL_DISTANCE);
+        }
+    }
+
+    private Color buttonColor;
+    private Color buttonBackgroundColor;
+    private int buttonPadding;
+
+    private ScrollButton northButton = new ScrollButton(new NorthButtonImage());
+    private ScrollButton southButton = new ScrollButton(new SouthButtonImage());
+    private ScrollButton eastButton = new ScrollButton(new EastButtonImage());
+    private ScrollButton westButton = new ScrollButton(new WestButtonImage());
+
+    private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new ButtonDataRenderer();
+
+    public TerraPanoramaSkin() {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        buttonColor = theme.getColor(1);
+        buttonBackgroundColor = null;
+        buttonPadding = 4;
+    }
+
+    private ComponentMouseListener buttonMouseListener = new ComponentMouseListener() {
+        public boolean mouseMove(Component component, int x, int y) {
+            return false;
+        }
+
+        public void mouseOver(Component component) {
+            // Start scroll timer
+            scrollDistance = INITIAL_SCROLL_DISTANCE;
+            scrollIntervalID = ApplicationContext.setInterval(scrollCallback, SCROLL_RATE);
+        }
+
+        public void mouseOut(Component component) {
+            // Stop scroll timer
+            ApplicationContext.clearInterval(scrollIntervalID);
+        }
+    };
+
+    private float scrollDistance = 0;
+    private ScrollCallback scrollCallback = new ScrollCallback();
+    private int scrollIntervalID = -1;
+
+    private static final int SCROLL_RATE = 50;
+    private static final float INITIAL_SCROLL_DISTANCE = 10;
+    private static final float SCROLL_ACCELERATION = 1.06f;
+    private static final float MAXIMUM_SCROLL_DISTANCE = 150f;
+
+    private static final int BUTTON_SIZE = 7;
+
+    @Override
+    public void install(Component component) {
+        super.install(component);
+
+        Panorama panorama = (Panorama)component;
+        panorama.getViewportListeners().add(this);
+
+        // Add scroll arrow link buttons and attach mouse listeners
+        // to them; the mouse handlers should call setScrollTop() and
+        // setScrollLeft() on the panorama as appropriate
+        panorama.add(northButton);
+        northButton.getComponentMouseListeners().add(buttonMouseListener);
+
+        panorama.add(southButton);
+        southButton.getComponentMouseListeners().add(buttonMouseListener);
+
+        panorama.add(eastButton);
+        eastButton.getComponentMouseListeners().add(buttonMouseListener);
+
+        panorama.add(westButton);
+        westButton.getComponentMouseListeners().add(buttonMouseListener);
+
+        updateScrollButtonVisibility();
+    }
+
+    @Override
+    public void uninstall() {
+        Panorama panorama = (Panorama)getComponent();
+        panorama.getViewportListeners().remove(this);
+
+        // Remove scroll arrow link buttons
+        panorama.remove(northButton);
+        panorama.remove(southButton);
+        panorama.remove(eastButton);
+        panorama.remove(westButton);
+    }
+
+    @Override
+    public int getPreferredWidth(int height) {
+        int preferredWidth = 0;
+
+        // The panorama's preferred width is the preferred width of the view
+        Panorama panorama = (Panorama)getComponent();
+        Component view = panorama.getView();
+        if (view != null) {
+            preferredWidth = view.getPreferredWidth(height);
+        }
+
+        return preferredWidth;
+    }
+
+    @Override
+    public int getPreferredHeight(int width) {
+        int preferredHeight = 0;
+
+        // The panorama's preferred height is the preferred height of the view
+        Panorama panorama = (Panorama)getComponent();
+        Component view = panorama.getView();
+        if (view != null) {
+            preferredHeight = view.getPreferredHeight(width);
+        }
+
+        return preferredHeight;
+    }
+
+    @Override
+    public Dimensions getPreferredSize() {
+        Dimensions preferredSize = null;
+
+        // The panorama's preferred size is the preferred size of the view
+        Panorama panorama = (Panorama)getComponent();
+        Component view = panorama.getView();
+        if (view == null) {
+            preferredSize = new Dimensions(0, 0);
+        } else {
+            preferredSize = view.getPreferredSize();
+        }
+
+        return preferredSize;
+    }
+
+    public void layout() {
+        Panorama panorama = (Panorama)getComponent();
+        int width = getWidth();
+        int height = getHeight();
+
+        Component view = panorama.getView();
+        if (view != null) {
+            view.setSize(view.getPreferredSize());
+            int viewWidth = view.getWidth();
+            int viewHeight = view.getHeight();
+
+            int scrollTop = panorama.getScrollTop();
+            int maxScrollTop = getMaxScrollTop();
+            if (scrollTop > maxScrollTop) {
+                panorama.setScrollTop(maxScrollTop);
+                scrollTop = maxScrollTop;
+            }
+
+            int scrollLeft = panorama.getScrollLeft();
+            int maxScrollLeft = getMaxScrollLeft();
+            if (scrollLeft > maxScrollLeft) {
+                panorama.setScrollLeft(maxScrollLeft);
+                scrollLeft = maxScrollLeft;
+            }
+
+            if (width < viewWidth) {
+                // Show east/west buttons
+                eastButton.setSize(eastButton.getPreferredWidth(), height);
+                eastButton.setLocation(width - eastButton.getWidth(), 0);
+
+                westButton.setSize(westButton.getPreferredWidth(), height);
+                westButton.setLocation(0, 0);
+            }
+
+            if (height < viewHeight) {
+                // Show north/south buttons
+                northButton.setSize(width, northButton.getPreferredHeight());
+                northButton.setLocation(0, 0);
+
+                southButton.setSize(width, southButton.getPreferredHeight());
+                southButton.setLocation(0, height - southButton.getHeight());
+            }
+        }
+    }
+
+    public Bounds getViewportBounds() {
+        // The viewport bounds is simply the skin's bounding rectangle
+        return new Bounds(0, 0, getWidth(), getHeight());
+    }
+
+    @Override
+    public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount,
+        int wheelRotation, int x, int y) {
+        boolean consumed = false;
+
+        Panorama panorama = (Panorama)getComponent();
+        Component view = panorama.getView();
+
+        if (view != null) {
+            // The scroll orientation is tied to whether the shift key was
+            // presssed while the mouse wheel was scrolled
+            if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
+                // Treat the mouse wheel as a horizontal scroll event
+                int previousScrollLeft = panorama.getScrollLeft();
+                int newScrollLeft = previousScrollLeft + (scrollAmount * wheelRotation *
+                    (int)INITIAL_SCROLL_DISTANCE);
+
+                if (wheelRotation > 0) {
+                    int maxScrollLeft = getMaxScrollLeft();
+                    newScrollLeft = Math.min(newScrollLeft, maxScrollLeft);
+
+                    if (previousScrollLeft < maxScrollLeft) {
+                        consumed = true;
+                    }
+                } else {
+                    newScrollLeft = Math.max(newScrollLeft, 0);
+
+                    if (previousScrollLeft > 0) {
+                        consumed = true;
+                    }
+                }
+
+                panorama.setScrollLeft(newScrollLeft);
+            } else {
+                // Treat the mouse wheel as a vertical scroll event
+                int previousScrollTop = panorama.getScrollTop();
+                int newScrollTop = previousScrollTop + (scrollAmount * wheelRotation *
+                    (int)INITIAL_SCROLL_DISTANCE);
+
+                if (wheelRotation > 0) {
+                    int maxScrollTop = getMaxScrollTop();
+                    newScrollTop = Math.min(newScrollTop, maxScrollTop);
+
+                    if (previousScrollTop < maxScrollTop) {
+                        consumed = true;
+                    }
+                } else {
+                    newScrollTop = Math.max(newScrollTop, 0);
+
+                    if (previousScrollTop > 0) {
+                        consumed = true;
+                    }
+                }
+
+                panorama.setScrollTop(newScrollTop);
+            }
+        }
+
+        return consumed;
+    }
+
+    public Color getButtonColor() {
+        return buttonColor;
+    }
+
+    public void setButtonColor(Color buttonColor) {
+        if (buttonColor == null) {
+            throw new IllegalArgumentException("buttonColor is null.");
+        }
+
+        this.buttonColor = buttonColor;
+        repaintComponent();
+    }
+
+    public final void setButtonColor(String buttonColor) {
+        if (buttonColor == null) {
+            throw new IllegalArgumentException("buttonColor is null.");
+        }
+
+        setButtonColor(decodeColor(buttonColor));
+    }
+
+    public Color getButtonBackgroundColor() {
+        return buttonBackgroundColor;
+    }
+
+    public void setButtonBackgroundColor(Color buttonBackgroundColor) {
+        if (buttonBackgroundColor == null) {
+            throw new IllegalArgumentException("buttonBackgroundColor is null.");
+        }
+
+        this.buttonBackgroundColor = buttonBackgroundColor;
+        repaintComponent();
+    }
+
+    public final void setButtonBackgroundColor(String buttonBackgroundColor) {
+        if (buttonBackgroundColor == null) {
+            throw new IllegalArgumentException("buttonBackgroundColor is null.");
+        }
+
+        setButtonBackgroundColor(decodeColor(buttonBackgroundColor));
+    }
+
+    public int getButtonPadding() {
+        return buttonPadding;
+    }
+
+    public void setButtonPadding(int buttonPadding) {
+        if (buttonPadding < 0) {
+            throw new IllegalArgumentException("buttonPadding is negative.");
+        }
+
+        this.buttonPadding = buttonPadding;
+        invalidateComponent();
+    }
+
+    protected int getMaxScrollTop() {
+        int maxScrollTop = 0;
+
+        Panorama panorama = (Panorama)getComponent();
+        int height = getHeight();
+
+        Component view = panorama.getView();
+        if (view != null) {
+            maxScrollTop = Math.max(view.getHeight() - height, 0);
+        }
+
+        return maxScrollTop;
+    }
+
+    protected int getMaxScrollLeft() {
+        int maxScrollLeft = 0;
+
+        Panorama panorama = (Panorama)getComponent();
+        int width = getWidth();
+
+        Component view = panorama.getView();
+        if (view != null) {
+            maxScrollLeft = Math.max(view.getWidth() - width, 0);
+        }
+
+        return maxScrollLeft;
+    }
+
+    protected void updateScrollButtonVisibility() {
+        Panorama panorama = (Panorama)getComponent();
+        boolean mouseOver = panorama.isMouseOver();
+
+        int scrollTop = panorama.getScrollTop();
+        int maxScrollTop = getMaxScrollTop();
+        northButton.setVisible(mouseOver
+            && scrollTop > 0);
+        southButton.setVisible(mouseOver
+            && scrollTop < maxScrollTop);
+
+        int scrollLeft = panorama.getScrollLeft();
+        int maxScrollLeft = getMaxScrollLeft();
+        westButton.setVisible(mouseOver
+            && scrollLeft > 0);
+        eastButton.setVisible(mouseOver
+            && scrollLeft < maxScrollLeft);
+    }
+
+    // User input
+    @Override
+    public void mouseOver(Component component) {
+        super.mouseOver(component);
+        updateScrollButtonVisibility();
+    }
+
+    @Override
+    public void mouseOut(Component component) {
+        super.mouseOut(component);
+        updateScrollButtonVisibility();
+    }
+
+    // Viewport events
+    public void scrollTopChanged(Viewport panorama, int previousScrollTop) {
+        Component view = panorama.getView();
+        if (view != null) {
+            int maxScrollTop = getMaxScrollTop();
+            int scrollTop = Math.min(panorama.getScrollTop(), maxScrollTop);
+            view.setLocation(view.getX(), -scrollTop);
+            updateScrollButtonVisibility();
+        }
+    }
+
+    public void scrollLeftChanged(Viewport panorama, int previousScrollLeft) {
+        Component view = panorama.getView();
+        if (view != null) {
+            int maxScrollLeft = getMaxScrollLeft();
+            int scrollLeft = Math.min(panorama.getScrollLeft(), maxScrollLeft);
+            view.setLocation(-scrollLeft, view.getY());
+            updateScrollButtonVisibility();
+        }
+    }
+
+    public void viewChanged(Viewport panorama, Component previousView) {
+        invalidateComponent();
+    }
+}

Added: incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPromptSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPromptSkin.java?rev=754926&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPromptSkin.java (added)
+++ incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPromptSkin.java Mon Mar 16 16:16:40 2009
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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.
+ */
+package pivot.wtk.skin.terra;
+
+import pivot.collections.ArrayList;
+import pivot.collections.HashMap;
+import pivot.wtk.Button;
+import pivot.wtk.ButtonPressListener;
+import pivot.wtk.Component;
+import pivot.wtk.FlowPane;
+import pivot.wtk.ImageView;
+import pivot.wtk.Label;
+import pivot.wtk.Prompt;
+import pivot.wtk.PromptListener;
+import pivot.wtk.PushButton;
+import pivot.wtk.Theme;
+import pivot.wtk.Window;
+import pivot.wtkx.WTKXSerializer;
+
+/**
+ * Prompt skin.
+ *
+ * @author tvolkert
+ * @author gbrown
+ */
+public class TerraPromptSkin extends TerraSheetSkin
+    implements PromptListener {
+    private ArrayList<Button> optionButtons = new ArrayList<Button>();
+
+    public TerraPromptSkin() {
+        setResizable(false);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void install(Component component) {
+        super.install(component);
+
+        Prompt prompt = (Prompt)component;
+        prompt.getPromptListeners().add(this);
+
+        // Load the prompt content
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        Component content = null;
+
+        try {
+            content = (Component)wtkxSerializer.readObject(getClass().getResource("prompt_skin.wtkx"));
+        } catch(Exception exception) {
+            throw new RuntimeException(exception);
+        }
+
+        prompt.setContent(content);
+
+        // Set the type image
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+
+        ImageView typeImageView = (ImageView)wtkxSerializer.getObjectByName("typeImageView");
+        typeImageView.setImage(theme.getMessageIcon(prompt.getMessageType()));
+
+        // Set the message
+        Label messageLabel = (Label)wtkxSerializer.getObjectByName("messageLabel");
+        String message = prompt.getMessage();
+        messageLabel.setText(message);
+
+        // Set the body
+        FlowPane messageFlowPane = (FlowPane)wtkxSerializer.getObjectByName("messageFlowPane");
+        Component body = prompt.getBody();
+        if (body != null) {
+            messageFlowPane.add(body);
+        }
+
+        // Add the option buttons
+        FlowPane buttonFlowPane = (FlowPane)wtkxSerializer.getObjectByName("buttonFlowPane");
+
+        for (int i = 0, n = prompt.getOptionCount(); i < n; i++) {
+            Object option = prompt.getOption(i);
+
+            PushButton optionButton = new PushButton(option);
+            HashMap<String, Object> optionButtonStyles = new HashMap<String, Object>();
+            optionButtonStyles.put("color", theme.getColor(4));
+            optionButtonStyles.put("backgroundColor", theme.getColor(16));
+            optionButtonStyles.put("borderColor", theme.getColor(13));
+
+            optionButton.setStyles(optionButtonStyles);
+            optionButton.getStyles().put("preferredAspectRatio", 3);
+
+            optionButton.getButtonPressListeners().add(new ButtonPressListener() {
+                public void buttonPressed(Button button) {
+                    int optionIndex = optionButtons.indexOf(button);
+
+                    if (optionIndex >= 0) {
+                        Prompt prompt = (Prompt)getComponent();
+                        prompt.setSelectedOption(optionIndex);
+                        prompt.close(true);
+                    }
+                }
+            });
+
+            buttonFlowPane.add(optionButton);
+            optionButtons.add(optionButton);
+        }
+    }
+
+    @Override
+    public void uninstall() {
+        Prompt prompt = (Prompt)getComponent();
+        prompt.getPromptListeners().remove(this);
+
+        prompt.setContent(null);
+
+        super.uninstall();
+    }
+
+    @Override
+    public void windowOpened(Window window) {
+        super.windowOpened(window);
+
+        Prompt prompt = (Prompt)window;
+        int index = prompt.getSelectedOption();
+
+        if (index >= 0) {
+            optionButtons.get(index).requestFocus();
+        }
+    }
+
+    public void selectedOptionChanged(Prompt prompt, int previousSelectedOption) {
+        int index = prompt.getSelectedOption();
+
+        if (prompt.isOpen()
+            && index >= 0) {
+            optionButtons.get(index).requestFocus();
+        }
+    }
+}

Added: incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPushButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPushButtonSkin.java?rev=754926&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPushButtonSkin.java (added)
+++ incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraPushButtonSkin.java Mon Mar 16 16:16:40 2009
@@ -0,0 +1,495 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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.
+ */
+package pivot.wtk.skin.terra;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+
+import pivot.collections.Dictionary;
+import pivot.wtk.Button;
+import pivot.wtk.Component;
+import pivot.wtk.Dimensions;
+import pivot.wtk.Insets;
+import pivot.wtk.PushButton;
+import pivot.wtk.Theme;
+import pivot.wtk.skin.PushButtonSkin;
+
+/**
+ * Terra push button skin.
+ *
+ * @author gbrown
+ */
+public class TerraPushButtonSkin extends PushButtonSkin {
+    private Font font;
+    private Color color;
+    private Color disabledColor;
+    private Color backgroundColor;
+    private Color disabledBackgroundColor;
+    private Color borderColor;
+    private Color disabledBorderColor;
+    private Insets padding;
+    private float preferredAspectRatio;
+    private boolean toolbar;
+
+    // Derived colors
+    private Color bevelColor;
+    private Color pressedBevelColor;
+    private Color disabledBevelColor;
+
+    public TerraPushButtonSkin() {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+
+        font = theme.getFont();
+        color = theme.getColor(1);
+        disabledColor = theme.getColor(7);
+        backgroundColor = theme.getColor(10);
+        disabledBackgroundColor = theme.getColor(10);
+        borderColor = theme.getColor(7);
+        disabledBorderColor = theme.getColor(7);
+        padding = new Insets(3);
+        preferredAspectRatio = Float.NaN;
+        toolbar = false;
+
+        // Set the derived colors
+        bevelColor = TerraTheme.brighten(backgroundColor);
+        pressedBevelColor = TerraTheme.darken(backgroundColor);
+        disabledBevelColor = disabledBackgroundColor;
+    }
+
+    public int getPreferredWidth(int height) {
+        PushButton pushButton = (PushButton)getComponent();
+        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
+
+        dataRenderer.render(pushButton.getButtonData(), pushButton, false);
+
+        // Include padding in constraint
+        int contentHeight = height;
+        if (contentHeight != -1) {
+            contentHeight = Math.max(contentHeight - (padding.top + padding.bottom + 2), 0);
+        }
+
+        int preferredWidth = dataRenderer.getPreferredWidth(contentHeight)
+            + padding.left + padding.right + 2;
+
+        // Adjust for preferred aspect ratio
+        if (!Float.isNaN(preferredAspectRatio)
+            && preferredAspectRatio >= 1) {
+            if (height != -1
+                && (float)preferredWidth / (float)height < preferredAspectRatio) {
+                preferredWidth = (int)((float)height * preferredAspectRatio);
+            }
+        }
+
+        return preferredWidth;
+    }
+
+    public int getPreferredHeight(int width) {
+        PushButton pushButton = (PushButton)getComponent();
+        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
+
+        dataRenderer.render(pushButton.getButtonData(), pushButton, false);
+
+        // Include padding in constraint
+        int contentWidth = width;
+        if (contentWidth != -1) {
+            contentWidth = Math.max(contentWidth - (padding.left + padding.right + 2), 0);
+        }
+
+        int preferredHeight = dataRenderer.getPreferredHeight(contentWidth)
+            + padding.top + padding.bottom + 2;
+
+        // Adjust for preferred aspect ratio
+        if (!Float.isNaN(preferredAspectRatio)
+            && preferredAspectRatio >= 1) {
+            if (width != -1
+                && (float)width / (float)preferredHeight < preferredAspectRatio) {
+                preferredHeight = (int)((float)width / preferredAspectRatio);
+            }
+        }
+
+        return preferredHeight;
+    }
+
+    public Dimensions getPreferredSize() {
+        PushButton pushButton = (PushButton)getComponent();
+        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
+
+        dataRenderer.render(pushButton.getButtonData(), pushButton, false);
+
+        Dimensions preferredContentSize = dataRenderer.getPreferredSize();
+
+        int preferredWidth = preferredContentSize.width
+            + padding.left + padding.right + 2;
+
+        int preferredHeight = preferredContentSize.height
+            + padding.top + padding.bottom + 2;
+
+        // Adjust for preferred aspect ratio
+        if (!Float.isNaN(preferredAspectRatio)) {
+            if (preferredAspectRatio >= 1) {
+                if ((float)preferredWidth / (float)preferredHeight < preferredAspectRatio) {
+                    preferredWidth = (int)((float)preferredHeight * preferredAspectRatio);
+                }
+            } else {
+                if ((float)preferredWidth / (float)preferredHeight > preferredAspectRatio) {
+                    preferredHeight = (int)((float)preferredWidth / preferredAspectRatio);
+                }
+            }
+        }
+
+        return new Dimensions(preferredWidth, preferredHeight);
+    }
+
+    public void paint(Graphics2D graphics) {
+        PushButton pushButton = (PushButton)getComponent();
+
+        int width = getWidth();
+        int height = getHeight();
+
+        Color backgroundColor = null;
+        Color bevelColor = null;
+        Color borderColor = null;
+
+        if (!toolbar
+            || highlighted) {
+            if (pushButton.isEnabled()) {
+                backgroundColor = this.backgroundColor;
+                bevelColor = (pressed
+                    || pushButton.isSelected()) ? pressedBevelColor : this.bevelColor;
+                borderColor = this.borderColor;
+            } else {
+                backgroundColor = disabledBackgroundColor;
+                bevelColor = disabledBevelColor;
+                borderColor = disabledBorderColor;
+            }
+        }
+
+        // Paint the background
+        if (backgroundColor != null) {
+            graphics.setPaint(backgroundColor);
+            graphics.fillRect(0, 0, width, height);
+        }
+
+        // Draw all lines with a 1px solid stroke
+        graphics.setStroke(new BasicStroke());
+
+        // Paint the border
+        if (borderColor != null) {
+            graphics.setPaint(borderColor);
+            graphics.drawRect(0, 0, width - 1, height - 1);
+        }
+
+        // Paint the bevel
+        if (bevelColor != null) {
+            graphics.setPaint(bevelColor);
+            graphics.drawLine(1, 1, width - 2, 1);
+        }
+
+        // Paint the content
+        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
+        dataRenderer.render(pushButton.getButtonData(), pushButton, highlighted);
+        dataRenderer.setSize(Math.max(width - (padding.left + padding.right + 2), 0),
+            Math.max(getHeight() - (padding.top + padding.bottom + 2), 0));
+
+        Graphics2D contentGraphics = (Graphics2D)graphics.create();
+        contentGraphics.translate(padding.left + 1, padding.top + 1);
+        contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
+        dataRenderer.paint(contentGraphics);
+        contentGraphics.dispose();
+
+        // Paint the focus state
+        if (pushButton.isFocused()) {
+            BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
+                BasicStroke.JOIN_ROUND, 1.0f, new float[] {0.0f, 2.0f}, 0.0f);
+
+            graphics.setStroke(dashStroke);
+            graphics.setColor(this.borderColor);
+
+            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                RenderingHints.VALUE_ANTIALIAS_ON);
+
+            graphics.drawRect(2, 2, Math.max(width - 5, 0),
+                Math.max(height - 5, 0));
+        }
+    }
+
+    @Override
+    public boolean isFocusable() {
+        return !toolbar;
+    }
+
+    public Font getFont() {
+        return font;
+    }
+
+    public void setFont(Font font) {
+        if (font == null) {
+            throw new IllegalArgumentException("font is null.");
+        }
+
+        this.font = font;
+        invalidateComponent();
+    }
+
+    public final void setFont(String font) {
+        if (font == null) {
+            throw new IllegalArgumentException("font is null.");
+        }
+
+        setFont(Font.decode(font));
+    }
+
+    public boolean isFontBold() {
+        return ((font.getStyle() & Font.BOLD) == Font.BOLD);
+    }
+
+    public void setFontBold(boolean fontBold) {
+        if (isFontBold() != fontBold) {
+            if (fontBold) {
+                font = font.deriveFont(Font.BOLD);
+            } else {
+                font = font.deriveFont(font.getStyle() & (~Font.BOLD));
+            }
+        }
+    }
+
+    public Color getColor() {
+        return color;
+    }
+
+    public void setColor(Color color) {
+        if (color == null) {
+            throw new IllegalArgumentException("color is null.");
+        }
+
+        this.color = color;
+        repaintComponent();
+    }
+
+    public final void setColor(String color) {
+        if (color == null) {
+            throw new IllegalArgumentException("color is null.");
+        }
+
+        setColor(decodeColor(color));
+    }
+
+    public final void setColor(int color) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setColor(theme.getColor(color));
+    }
+
+    public Color getDisabledColor() {
+        return disabledColor;
+    }
+
+    public void setDisabledColor(Color disabledColor) {
+        if (disabledColor == null) {
+            throw new IllegalArgumentException("disabledColor is null.");
+        }
+
+        this.disabledColor = disabledColor;
+        repaintComponent();
+    }
+
+    public final void setDisabledColor(String disabledColor) {
+        if (disabledColor == null) {
+            throw new IllegalArgumentException("disabledColor is null.");
+        }
+
+        setDisabledColor(decodeColor(disabledColor));
+    }
+
+    public final void setDisabledColor(int disabledColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setDisabledColor(theme.getColor(disabledColor));
+    }
+
+    public Color getBackgroundColor() {
+        return backgroundColor;
+    }
+
+    public void setBackgroundColor(Color backgroundColor) {
+        if (backgroundColor == null) {
+            throw new IllegalArgumentException("backgroundColor is null.");
+        }
+
+        this.backgroundColor = backgroundColor;
+        bevelColor = TerraTheme.brighten(backgroundColor);
+        pressedBevelColor = TerraTheme.darken(backgroundColor);
+        repaintComponent();
+    }
+
+    public final void setBackgroundColor(String backgroundColor) {
+        if (backgroundColor == null) {
+            throw new IllegalArgumentException("backgroundColor is null.");
+        }
+
+        setBackgroundColor(decodeColor(backgroundColor));
+    }
+
+    public final void setBackgroundColor(int backgroundColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setBackgroundColor(theme.getColor(backgroundColor));
+    }
+
+    public Color getDisabledBackgroundColor() {
+        return disabledBackgroundColor;
+    }
+
+    public void setDisabledBackgroundColor(Color disabledBackgroundColor) {
+        if (disabledBackgroundColor == null) {
+            throw new IllegalArgumentException("disabledBackgroundColor is null.");
+        }
+
+        this.disabledBackgroundColor = disabledBackgroundColor;
+        disabledBevelColor = disabledBackgroundColor;
+        repaintComponent();
+    }
+
+    public final void setDisabledBackgroundColor(String disabledBackgroundColor) {
+        if (disabledBackgroundColor == null) {
+            throw new IllegalArgumentException("disabledBackgroundColor is null.");
+        }
+
+        setDisabledBackgroundColor(decodeColor(disabledBackgroundColor));
+    }
+
+    public final void setDisabledBackgroundColor(int disabledBackgroundColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setDisabledBackgroundColor(theme.getColor(disabledBackgroundColor));
+    }
+
+    public Color getBorderColor() {
+        return borderColor;
+    }
+
+    public void setBorderColor(Color borderColor) {
+        if (borderColor == null) {
+            throw new IllegalArgumentException("borderColor is null.");
+        }
+
+        this.borderColor = borderColor;
+        repaintComponent();
+    }
+
+    public final void setBorderColor(String borderColor) {
+        if (borderColor == null) {
+            throw new IllegalArgumentException("borderColor is null.");
+        }
+
+        setBorderColor(decodeColor(borderColor));
+    }
+
+    public final void setBorderColor(int borderColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setBorderColor(theme.getColor(borderColor));
+    }
+
+    public Color getDisabledBorderColor() {
+        return disabledBorderColor;
+    }
+
+    public void setDisabledBorderColor(Color disabledBorderColor) {
+        if (disabledBorderColor == null) {
+            throw new IllegalArgumentException("disabledBorderColor is null.");
+        }
+
+        this.disabledBorderColor = disabledBorderColor;
+        repaintComponent();
+    }
+
+    public final void setDisabledBorderColor(String disabledBorderColor) {
+        if (disabledBorderColor == null) {
+            throw new IllegalArgumentException("disabledBorderColor is null.");
+        }
+
+        setDisabledBorderColor(decodeColor(disabledBorderColor));
+    }
+
+    public final void setDisabledBorderColor(int disabledBorderColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setDisabledBorderColor(theme.getColor(disabledBorderColor));
+    }
+
+    public Insets getPadding() {
+        return padding;
+    }
+
+    public void setPadding(Insets padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        this.padding = padding;
+        invalidateComponent();
+    }
+
+    public final void setPadding(Dictionary<String, ?> padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        setPadding(new Insets(padding));
+    }
+
+    public final void setPadding(int padding) {
+        setPadding(new Insets(padding));
+    }
+
+    public final void setPadding(Number padding) {
+        if (padding == null) {
+            throw new IllegalArgumentException("padding is null.");
+        }
+
+        setPadding(padding.intValue());
+    }
+
+    public float getPreferredAspectRatio() {
+        return preferredAspectRatio;
+    }
+
+    public void setPreferredAspectRatio(float preferredAspectRatio) {
+        this.preferredAspectRatio = preferredAspectRatio;
+        invalidateComponent();
+    }
+
+    public final void setPreferredAspectRatio(Number preferredAspectRatio) {
+        if (preferredAspectRatio == null) {
+            throw new IllegalArgumentException("preferredAspectRatio is null.");
+        }
+
+        setPreferredAspectRatio(preferredAspectRatio.floatValue());
+    }
+
+    public boolean isToolbar() {
+        return toolbar;
+    }
+
+    public void setToolbar(boolean toolbar) {
+        this.toolbar = toolbar;
+
+        if (toolbar &&
+            getComponent().isFocused()) {
+            Component.clearFocus();
+        }
+
+        repaintComponent();
+    }
+}

Added: incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraRadioButtonSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraRadioButtonSkin.java?rev=754926&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraRadioButtonSkin.java (added)
+++ incubator/pivot/tags/v1.0/wtk/src/pivot/wtk/skin/terra/TerraRadioButtonSkin.java Mon Mar 16 16:16:40 2009
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed 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.
+ */
+package pivot.wtk.skin.terra;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.Ellipse2D;
+
+import pivot.wtk.Button;
+import pivot.wtk.Dimensions;
+import pivot.wtk.RadioButton;
+import pivot.wtk.Theme;
+import pivot.wtk.skin.RadioButtonSkin;
+
+/**
+ * Terra radio button skin.
+ * <p>
+ * TODO Button alignment style (vertical only).
+ *
+ * @author gbrown
+ */
+public class TerraRadioButtonSkin extends RadioButtonSkin {
+    private Font font;
+    private Color color;
+    private Color disabledColor;
+    private int spacing;
+
+    private Color buttonColor;
+    private Color buttonBorderColor;
+    private Color buttonSelectionColor;
+    private Color disabledButtonColor;
+    private Color disabledButtonBorderColor;
+    private Color disabledButtonSelectionColor;
+
+    private static final int BUTTON_DIAMETER = 14;
+    private static final int BUTTON_SELECTION_DIAMETER = 6;
+
+    public TerraRadioButtonSkin() {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        font = theme.getFont();
+        color = theme.getColor(1);
+        disabledColor = theme.getColor(7);
+        spacing = 3;
+
+        buttonColor = theme.getColor(4);
+        buttonBorderColor = theme.getColor(7);
+        buttonSelectionColor = theme.getColor(13);
+        disabledButtonColor = theme.getColor(4);
+        disabledButtonBorderColor = theme.getColor(7);
+        disabledButtonSelectionColor = theme.getColor(7);
+    }
+
+    public int getPreferredWidth(int height) {
+        RadioButton radioButton = (RadioButton)getComponent();
+        Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
+
+        dataRenderer.render(radioButton.getButtonData(), radioButton, false);
+
+        int preferredWidth = BUTTON_DIAMETER
+            + dataRenderer.getPreferredWidth(height)
+            + spacing * 2;
+
+        return preferredWidth;
+    }
+
+    public int getPreferredHeight(int width) {
+        RadioButton radioButton = (RadioButton)getComponent();
+        Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
+
+        dataRenderer.render(radioButton.getButtonData(), radioButton, false);
+
+        if (width != -1) {
+            width = Math.max(width - (BUTTON_DIAMETER + spacing), 0);
+        }
+
+        int preferredHeight = Math.max(BUTTON_DIAMETER,
+            dataRenderer.getPreferredHeight(width));
+
+        return preferredHeight;
+    }
+
+    public Dimensions getPreferredSize() {
+        RadioButton radioButton = (RadioButton)getComponent();
+        Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
+
+        dataRenderer.render(radioButton.getButtonData(), radioButton, false);
+
+        int preferredWidth = BUTTON_DIAMETER
+            + dataRenderer.getPreferredWidth(-1)
+            + spacing * 2;
+
+        int preferredHeight = Math.max(BUTTON_DIAMETER,
+            dataRenderer.getPreferredHeight(-1));
+
+        return new Dimensions(preferredWidth, preferredHeight);
+    }
+
+    public void paint(Graphics2D graphics) {
+        RadioButton radioButton = (RadioButton)getComponent();
+        int width = getWidth();
+        int height = getHeight();
+
+        // Paint the button
+        Graphics2D buttonGraphics = (Graphics2D)graphics.create();
+        paintButton(buttonGraphics, radioButton, height);
+        buttonGraphics.dispose();
+
+        // Paint the content
+        Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
+        dataRenderer.render(radioButton.getButtonData(), radioButton, false);
+        dataRenderer.setSize(Math.max(width - (BUTTON_DIAMETER + spacing * 2), 0), height);
+
+        Graphics2D contentGraphics = (Graphics2D)graphics.create();
+        contentGraphics.translate(BUTTON_DIAMETER + spacing, 0);
+        contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
+        dataRenderer.paint(contentGraphics);
+        contentGraphics.dispose();
+
+        // Paint the focus state
+        if (radioButton.isFocused()) {
+            BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
+                BasicStroke.JOIN_ROUND, 1.0f, new float[] {0.0f, 2.0f}, 0.0f);
+
+            graphics.setStroke(dashStroke);
+            graphics.setColor(buttonBorderColor);
+
+            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                RenderingHints.VALUE_ANTIALIAS_ON);
+
+            graphics.drawRect(BUTTON_DIAMETER + 1, 0,
+                dataRenderer.getWidth() + spacing * 2 - 2,
+                dataRenderer.getHeight() - 1);
+        }
+    }
+
+    private void paintButton(Graphics2D graphics, RadioButton radioButton, int height) {
+        Color buttonColor = null;
+        Color buttonBorderColor = null;
+        Color buttonSelectionColor = null;
+
+        if (radioButton.isEnabled()) {
+            buttonColor = this.buttonColor;
+            buttonBorderColor = this.buttonBorderColor;
+            buttonSelectionColor = this.buttonSelectionColor;
+        }
+        else {
+            buttonColor = disabledButtonColor;
+            buttonBorderColor = disabledButtonBorderColor;
+            buttonSelectionColor = disabledButtonSelectionColor;
+        }
+
+        // Center the button vertically
+        graphics.translate(0, (height - BUTTON_DIAMETER) / 2);
+
+        // Paint the border
+        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+            RenderingHints.VALUE_ANTIALIAS_ON);
+
+        Ellipse2D buttonCircle = new Ellipse2D.Double(0, 0,
+            BUTTON_DIAMETER - 1, BUTTON_DIAMETER - 1);
+        graphics.setColor(buttonBorderColor);
+        graphics.fill(buttonCircle);
+
+        Ellipse2D innerButtonCircle = new Ellipse2D.Double(1, 1,
+            BUTTON_DIAMETER - 3, BUTTON_DIAMETER - 3);
+        graphics.setColor(buttonBorderColor);
+        graphics.fill(buttonCircle);
+
+        graphics.setColor(buttonColor);
+        graphics.fill(innerButtonCircle);
+
+        if (radioButton.isSelected()) {
+            Ellipse2D buttonSelectionCircle = new Ellipse2D.Double((BUTTON_DIAMETER
+                - (BUTTON_SELECTION_DIAMETER - 1)) / 2,
+                (BUTTON_DIAMETER - (BUTTON_SELECTION_DIAMETER - 1)) / 2,
+                BUTTON_SELECTION_DIAMETER - 1, BUTTON_SELECTION_DIAMETER - 1);
+            graphics.setColor(buttonSelectionColor);
+            graphics.fill(buttonSelectionCircle);
+        }
+    }
+
+    public Font getFont() {
+        return font;
+    }
+
+    public void setFont(Font font) {
+        if (font == null) {
+            throw new IllegalArgumentException("font is null.");
+        }
+
+        this.font = font;
+        invalidateComponent();
+    }
+
+    public final void setFont(String font) {
+        if (font == null) {
+            throw new IllegalArgumentException("font is null.");
+        }
+
+        setFont(Font.decode(font));
+    }
+
+    public Color getColor() {
+        return color;
+    }
+
+    public void setColor(Color color) {
+        if (color == null) {
+            throw new IllegalArgumentException("color is null.");
+        }
+
+        this.color = color;
+        repaintComponent();
+    }
+
+    public final void setColor(String color) {
+        if (color == null) {
+            throw new IllegalArgumentException("color is null.");
+        }
+
+        setColor(decodeColor(color));
+    }
+
+    public Color getDisabledColor() {
+        return disabledColor;
+    }
+
+    public void setDisabledColor(Color disabledColor) {
+        if (disabledColor == null) {
+            throw new IllegalArgumentException("disabledColor is null.");
+        }
+
+        this.disabledColor = disabledColor;
+        repaintComponent();
+    }
+
+    public final void setDisabledColor(String disabledColor) {
+        if (disabledColor == null) {
+            throw new IllegalArgumentException("disabledColor is null.");
+        }
+
+        setDisabledColor(decodeColor(disabledColor));
+    }
+
+    public int getSpacing() {
+        return spacing;
+    }
+
+    public void setSpacing(int spacing) {
+        this.spacing = spacing;
+        invalidateComponent();
+    }
+
+    public final void setSpacing(Number spacing) {
+        if (spacing == null) {
+            throw new IllegalArgumentException("spacing is null.");
+        }
+
+        setSpacing(spacing.intValue());
+    }
+}