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/08/31 20:01:22 UTC
svn commit: r809679 -
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java
Author: tvolkert
Date: Mon Aug 31 18:01:21 2009
New Revision: 809679
URL: http://svn.apache.org/viewvc?rev=809679&view=rev
Log:
PIVOT-258 :: Change LinkButtonDataRenderer to extend TablePane so that the label text can wrap
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java?rev=809679&r1=809678&r2=809679&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/LinkButtonDataRenderer.java Mon Aug 31 18:01:21 2009
@@ -16,20 +16,93 @@
*/
package org.apache.pivot.wtk.content;
+import java.awt.Color;
+import java.awt.Font;
+
import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ImageView;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.TablePane;
import org.apache.pivot.wtk.TextDecoration;
+import org.apache.pivot.wtk.media.Image;
/**
* Default link button data renderer.
*/
-public class LinkButtonDataRenderer extends ButtonDataRenderer {
+public class LinkButtonDataRenderer extends TablePane implements Button.DataRenderer {
+ protected ImageView imageView = new ImageView();
+ protected Label label = new Label();
+
public LinkButtonDataRenderer() {
+ getStyles().put("horizontalSpacing", 4);
+
+ getColumns().add(new TablePane.Column());
+ getColumns().add(new TablePane.Column(1, true));
+
+ TablePane.Row row = new TablePane.Row();
+ row.add(imageView);
+ row.add(label);
+
+ getRows().add(row);
+
label.getStyles().put("wrapText", true);
}
@Override
+ public void setSize(int width, int height) {
+ super.setSize(width, height);
+
+ // Since this component doesn't have a parent, it won't be validated
+ // via layout; ensure that it is valid here
+ validate();
+ }
+
public void render(Object data, Button button, boolean highlighted) {
- super.render(data, button, highlighted);
+ Image icon = null;
+ String text = null;
+
+ if (data instanceof ButtonData) {
+ ButtonData buttonData = (ButtonData)data;
+ icon = buttonData.getIcon();
+ text = buttonData.getText();
+ } else if (data instanceof Image) {
+ icon = (Image)data;
+ } else {
+ if (data != null) {
+ text = data.toString();
+ }
+ }
+
+ // Update the image view
+ if (icon == null) {
+ imageView.setVisible(false);
+ } else {
+ imageView.setVisible(true);
+ imageView.setImage(icon);
+
+ imageView.getStyles().put("opacity", button.isEnabled() ? 1.0f : 0.5f);
+ }
+
+ // Update the label
+ label.setText(text);
+
+ if (text == null) {
+ label.setVisible(false);
+ } else {
+ label.setVisible(true);
+
+ Font font = (Font)button.getStyles().get("font");
+ label.getStyles().put("font", font);
+
+ Color color;
+ if (button.isEnabled()) {
+ color = (Color)button.getStyles().get("color");
+ } else {
+ color = (Color)button.getStyles().get("disabledColor");
+ }
+
+ label.getStyles().put("color", color);
+ }
label.getStyles().put("textDecoration", highlighted ?
TextDecoration.UNDERLINE : null);