|
From: <mai...@ce...> - 2009-03-14 20:53:22
|
From: Johannes Schneider <js...@ce...>
---
.../richclient/form/builder/TableFormBuilder.java | 37 +++++++++++++++++--
1 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/TableFormBuilder.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/TableFormBuilder.java
index 98613d7..7a4238c 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/TableFormBuilder.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/TableFormBuilder.java
@@ -17,6 +17,7 @@ package org.springframework.richclient.form.builder;
import java.util.HashMap;
import java.util.Map;
+import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@@ -29,6 +30,8 @@ import org.springframework.richclient.form.binding.BindingFactory;
import org.springframework.richclient.form.binding.swing.ComboBoxBinder;
import org.springframework.richclient.layout.TableLayoutBuilder;
import org.springframework.util.Assert;
+import com.jgoodies.forms.layout.RowSpec;
+import com.jgoodies.forms.layout.ConstantSize;
/**
* A TableFormBuilder builds a form by using a {@link TableLayoutBuilder}
@@ -37,14 +40,24 @@ import org.springframework.util.Assert;
* @author Mathias Broekelmann
*/
public class TableFormBuilder extends AbstractFormBuilder {
+ private static final RowSpec DESCRIPTION_ROW_SPEC = RowSpec.createGap( new ConstantSize( 2, ConstantSize.PX ) );
- private static final String VALIGN_TOP = TableLayoutBuilder.VALIGN + "=top";
+ private static final String VALIGN_TOP = TableLayoutBuilder.VALIGN + "=top";
- private TableLayoutBuilder builder;
+ private Font descriptionFont;
- private String labelAttributes = TableLayoutBuilder.DEFAULT_LABEL_ATTRIBUTES;
+ {
+ Font labelFont = new JLabel().getFont();
+ descriptionFont = labelFont.deriveFont( Font.ITALIC, labelFont.getSize() - 2 );
+ }
- /**
+ private TableLayoutBuilder builder;
+
+ private String labelAttributes = TableLayoutBuilder.DEFAULT_LABEL_ATTRIBUTES;
+
+ private String descriptionLabelAttributes = TableLayoutBuilder.DEFAULT_LABEL_ATTRIBUTES;
+
+ /**
* Creates an instances of the TableFormBuilder by using a {@link BindingFactory}
*
* @param bindingFactory
@@ -76,6 +89,10 @@ public class TableFormBuilder extends AbstractFormBuilder {
getLayoutBuilder().unrelatedGapRow();
}
+ public void descriptionRow() {
+ getLayoutBuilder().row( DESCRIPTION_ROW_SPEC );
+ }
+
/**
* Adds the field to the form. {@link #createDefaultBinding(String)} is used to create the binding for the field
*
@@ -113,6 +130,18 @@ public class TableFormBuilder extends AbstractFormBuilder {
return addBinding(createDefaultBinding(fieldName), attributes, getLabelAttributes());
}
+ public JComponent addDescription(String fieldName) {
+ return addDescription( fieldName, descriptionLabelAttributes );
+ }
+
+ public JComponent addDescription(String fieldName, String attributes) {
+ JLabel label = getComponentFactory().createLabel( new String[]{getFormModel().getId() + '.' + fieldName + ".description", fieldName + ".description"} );
+ label.setFont( descriptionFont );
+ label.setFont( label.getFont().deriveFont( Font.ITALIC ) );
+ builder.cell( label, attributes );
+ return label;
+ }
+
/**
* Adds the field binding to the form.
*
--
1.6.2
|