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/10/30 04:00:06 UTC
svn commit: r831188 - in /incubator/pivot/trunk/wtk:
src/org/apache/pivot/wtk/ColorChooser.java
src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java
test/org/apache/pivot/wtk/test/color_chooser_test.wtkx
Author: tvolkert
Date: Fri Oct 30 03:00:06 2009
New Revision: 831188
URL: http://svn.apache.org/viewvc?rev=831188&view=rev
Log:
More work towards color chooser (PIVOT-77)
Added:
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/color_chooser_test.wtkx
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooser.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooser.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooser.java?rev=831188&r1=831187&r2=831188&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooser.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooser.java Fri Oct 30 03:00:06 2009
@@ -63,6 +63,10 @@
private ColorChooserSelectionListenerList colorChooserSelectionListeners =
new ColorChooserSelectionListenerList();
+ public ColorChooser() {
+ installThemeSkin(ColorChooser.class);
+ }
+
/**
* Gets the currently selected color, or <tt>null</tt> if no color is
* selected.
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java?rev=831188&r1=831187&r2=831188&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraColorChooserSkin.java Fri Oct 30 03:00:06 2009
@@ -19,24 +19,137 @@
import java.awt.Color;
import java.awt.Graphics2D;
+import org.apache.pivot.wtk.Border;
import org.apache.pivot.wtk.ColorChooser;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.GraphicsUtilities;
+import org.apache.pivot.wtk.TablePane;
import org.apache.pivot.wtk.Theme;
import org.apache.pivot.wtk.skin.ColorChooserSkin;
+import org.apache.pivot.wtk.skin.ComponentSkin;
/**
* Terra color chooser skin.
*/
public class TerraColorChooserSkin extends ColorChooserSkin {
- private Color borderColor;
- private int spacing;
+ private class SaturationValueChooser extends Component {
+ private float saturation = 0f;
+ private float value = 0f;
+
+ public SaturationValueChooser() {
+ setSkin(new SaturationValueChooserSkin());
+ }
+
+ public float getSaturation() {
+ return saturation;
+ }
+
+ public void setSaturation(float saturation) {
+ this.saturation = saturation;
+ }
+
+ public float getValue() {
+ return value;
+ }
+
+ public void setValue(float value) {
+ this.value = value;
+ }
+ }
+
+ private class SaturationValueChooserSkin extends ComponentSkin {
+ @Override
+ public int getPreferredWidth(int height) {
+ return 140;
+ }
+
+ @Override
+ public int getPreferredHeight(int width) {
+ return 185;
+ }
+
+ @Override
+ public void layout() {
+ // No-op
+ }
+
+ @Override
+ public void paint(Graphics2D graphics) {
+ // TODO
+ }
+ }
+
+ private class HueChooser extends Component {
+ private float hue = 0f;
+
+ public HueChooser() {
+ setSkin(new HueChooserSkin());
+ }
+
+ public float getHue() {
+ return hue;
+ }
+
+ public void setHue(float hue) {
+ this.hue = hue;
+ }
+ }
+
+ private class HueChooserSkin extends ComponentSkin {
+ @Override
+ public int getPreferredWidth(int height) {
+ return 18;
+ }
+
+ @Override
+ public int getPreferredHeight(int width) {
+ return 185;
+ }
+
+ @Override
+ public void layout() {
+ // No-op
+ }
+
+ @Override
+ public void paint(Graphics2D graphics) {
+ int width = getWidth();
+ int height = getHeight();
+
+ for (int y = 0; y < height; y++) {
+ Color color = Color.getHSBColor(1f - (y / (float)height), 1f, 1f);
+ graphics.setColor(color);
+ graphics.fillRect(0, y, width, 1);
+ }
+ }
+ }
+
+ private TablePane tablePane = new TablePane();
+ private Border hueBorder = new Border();
+ private Border saturationValueBorder = new Border();
+
+ private SaturationValueChooser saturationValueChooser = new SaturationValueChooser();
+ private HueChooser hueChooser = new HueChooser();
public TerraColorChooserSkin() {
TerraTheme theme = (TerraTheme)Theme.getTheme();
- borderColor = theme.getColor(9);
- spacing = 4;
+
+ tablePane.getStyles().put("horizontalSpacing", 4);
+ tablePane.getColumns().add(new TablePane.Column(15, true));
+ tablePane.getColumns().add(new TablePane.Column(2, true));
+
+ TablePane.Row row = new TablePane.Row(1, true);
+ tablePane.getRows().add(row);
+
+ row.add(saturationValueBorder);
+ row.add(hueBorder);
+
+ hueBorder.getStyles().put("color", theme.getColor(9));
+ saturationValueBorder.getStyles().put("color", theme.getColor(9));
+
+ hueBorder.setContent(hueChooser);
+ saturationValueBorder.setContent(saturationValueChooser);
}
@Override
@@ -44,42 +157,34 @@
super.install(component);
ColorChooser colorChooser = (ColorChooser)component;
+ colorChooser.add(tablePane);
selectedColorChanged(colorChooser, null);
}
@Override
public int getPreferredWidth(int height) {
- // TODO
- return 0;
+ return tablePane.getPreferredWidth(height);
}
@Override
public int getPreferredHeight(int width) {
- // TODO
- return 0;
+ return tablePane.getPreferredHeight(width);
}
@Override
public Dimensions getPreferredSize() {
- // TODO
- return new Dimensions(0, 0);
+ return tablePane.getPreferredSize();
}
@Override
public void layout() {
- // TODO
- }
-
- @Override
- public void paint(Graphics2D graphics) {
- super.paint(graphics);
-
- // TODO
+ tablePane.setSize(getWidth(), getHeight());
+ tablePane.setLocation(0, 0);
}
public Color getBorderColor() {
- return borderColor;
+ return (Color)hueBorder.getStyles().get("color");
}
public void setBorderColor(Color borderColor) {
@@ -87,8 +192,8 @@
throw new IllegalArgumentException("borderColor is null.");
}
- this.borderColor = borderColor;
- repaintComponent();
+ hueBorder.getStyles().put("color", borderColor);
+ saturationValueBorder.getStyles().put("color", borderColor);
}
public final void setBorderColor(String borderColor) {
@@ -96,11 +201,12 @@
throw new IllegalArgumentException("borderColor is null.");
}
- setBorderColor(GraphicsUtilities.decodeColor(borderColor));
+ hueBorder.getStyles().put("color", borderColor);
+ saturationValueBorder.getStyles().put("color", borderColor);
}
public int getSpacing() {
- return spacing;
+ return (Integer)tablePane.getStyles().get("horizontalSpacing");
}
public void setSpacing(int spacing) {
@@ -108,8 +214,7 @@
throw new IllegalArgumentException("spacing is negative.");
}
- this.spacing = spacing;
- invalidateComponent();
+ tablePane.getStyles().put("horizontalSpacing", spacing);
}
public final void setSpacing(Number spacing) {
@@ -117,6 +222,15 @@
throw new IllegalArgumentException("spacing is null.");
}
- setSpacing(spacing.intValue());
+ tablePane.getStyles().put("horizontalSpacing", spacing);
+ }
+
+ @Override
+ public void selectedColorChanged(ColorChooser colorChooser, Color previousSelectedColor) {
+ Color color = colorChooser.getSelectedColor();
+ float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
+ hueChooser.setHue(hsb[0]);
+ saturationValueChooser.setSaturation(hsb[1]);
+ saturationValueChooser.setValue(hsb[2]);
}
}
Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/color_chooser_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/color_chooser_test.wtkx?rev=831188&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/color_chooser_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/color_chooser_test.wtkx Fri Oct 30 03:00:06 2009
@@ -0,0 +1,27 @@
+<?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="Color Chooser Test" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <BoxPane orientation="vertical" styles="{padding:10}">
+ <ColorChooser selectedColor="#cc0000"/>
+ </BoxPane>
+ </content>
+</Window>