|
From: <mai...@ce...> - 2009-03-14 20:53:19
|
From: Johannes Schneider <js...@ce...>
---
spring-richclient-integrations/pom.xml | 2 +-
.../spring-richclient-jide/pom.xml | 7 +++++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/spring-richclient-integrations/pom.xml b/spring-richclient-integrations/pom.xml
index 4d6ec47..5fcdc82 100644
--- a/spring-richclient-integrations/pom.xml
+++ b/spring-richclient-integrations/pom.xml
@@ -20,7 +20,7 @@
<module>spring-richclient-flexdock</module>
<module>spring-richclient-swingdocking</module>
<!-- JIDE integration isn't built automatically due to licensing -->
- <!--<module>spring-richclient-jide</module>-->
+ <module>spring-richclient-jide</module>
</modules>
<dependencies>
diff --git a/spring-richclient-integrations/spring-richclient-jide/pom.xml b/spring-richclient-integrations/spring-richclient-jide/pom.xml
index 6f3a080..1beccf3 100644
--- a/spring-richclient-integrations/spring-richclient-jide/pom.xml
+++ b/spring-richclient-integrations/spring-richclient-jide/pom.xml
@@ -31,6 +31,13 @@
<jide.version>[2.2.0, 3.0.0)</jide.version>
</properties>
+ <dependencies>
+ <dependency>
+ <groupId>com.jidesoft</groupId>
+ <artifactId>jide-common</artifactId>
+ </dependency>
+ </dependencies>
+
<dependencyManagement>
<dependencies>
<dependency>
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:17
|
From: Johannes Schneider <js...@ce...>
(createLabelFor and accesor for backing form)
---
.../richclient/wizard/FormBackedWizardPage.java | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/wizard/FormBackedWizardPage.java b/spring-richclient-core/src/main/java/org/springframework/richclient/wizard/FormBackedWizardPage.java
index 627ea1e..4e77fb9 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/wizard/FormBackedWizardPage.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/wizard/FormBackedWizardPage.java
@@ -59,7 +59,7 @@ public class FormBackedWizardPage extends AbstractWizardPage {
this.backingForm = backingForm;
}
- protected Form getBackingForm() {
+ public Form getBackingForm() {
return backingForm;
}
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:20
|
From: Johannes Schneider <js...@ce...>
---
.../richclient/form/builder/TableFormBuilder.java | 4 ++++
1 files changed, 4 insertions(+), 0 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 fd79d70..98613d7 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
@@ -72,6 +72,10 @@ public class TableFormBuilder extends AbstractFormBuilder {
getLayoutBuilder().relatedGapRow();
}
+ public void unrelatedRow() {
+ getLayoutBuilder().unrelatedGapRow();
+ }
+
/**
* Adds the field to the form. {@link #createDefaultBinding(String)} is used to create the binding for the field
*
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:21
|
From: Johannes Schneider <js...@ce...>
---
.../richclient/form/builder/TableFormBuilder.java | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 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 7a4238c..b1e20f5 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
@@ -127,7 +127,11 @@ public class TableFormBuilder extends AbstractFormBuilder {
* @return an array containing the label and the component which where added to the form
*/
public JComponent[] add(String fieldName, String attributes) {
- return addBinding(createDefaultBinding(fieldName), attributes, getLabelAttributes());
+ return add( fieldName, attributes, getLabelAttributes() );
+ }
+
+ public JComponent[] add(String fieldName, String attributes, String customLabelAttributes) {
+ return addBinding(createDefaultBinding(fieldName), attributes, customLabelAttributes);
}
public JComponent addDescription(String fieldName) {
@@ -181,7 +185,11 @@ public class TableFormBuilder extends AbstractFormBuilder {
* @return an array containing the label and the component which where added to the form
*/
public JComponent[] add(String fieldName, JComponent component, String attributes) {
- return addBinding(createBinding(fieldName, component), attributes, getLabelAttributes());
+ return add( fieldName, component, attributes, getLabelAttributes() );
+ }
+
+ public JComponent[] add(String fieldName, JComponent component, String attributes, String customLabelAttributes) {
+ return addBinding(createBinding(fieldName, component), attributes, customLabelAttributes);
}
/**
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:22
|
From: Johannes Schneider <js...@ce...>
---
.../form/binding/swing/EnumRadioButtonBinder.java | 88 +++++++++--
.../form/binding/swing/EnumRadioButtonBinding.java | 156 +++++++++-----------
2 files changed, 138 insertions(+), 106 deletions(-)
diff --git a/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinder.java b/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinder.java
index feb1e97..807ab02 100644
--- a/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinder.java
+++ b/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinder.java
@@ -1,27 +1,28 @@
package org.springframework.richclient.form.binding.swing;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-
import org.springframework.binding.form.FormModel;
+import org.springframework.context.support.MessageSourceAccessor;
+import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.form.binding.Binding;
import org.springframework.richclient.form.binding.support.AbstractBinder;
+import org.springframework.richclient.selection.binding.support.LabelProvider;
+
+import javax.swing.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
/**
* Radio button binder for enum values.
- *
+ * <p/>
* Use this in your Application Context to configure the binder:
- *
+ * <p/>
* <pre>
* <bean name="enumRadioButtonBinder" class="org.springframework.richclient.form.binding.swing.EnumRadioButtonBinder" />
* </pre>
- *
+ * <p/>
* Or when you need an additional null value that can be selected:
- *
+ * <p/>
* <pre>
* <bean name="enumRadioButtonBinder" class="org.springframework.richclient.form.binding.swing.EnumRadioButtonBinder" >
* <property name="nullable" value="true" />
@@ -32,7 +33,9 @@ import org.springframework.richclient.form.binding.support.AbstractBinder;
*/
public class EnumRadioButtonBinder extends AbstractBinder {
- private boolean nullable = false;
+ private boolean nullable=false;
+
+ private LabelProvider labelProvider;
/**
* Creates a new binder
@@ -50,16 +53,35 @@ public class EnumRadioButtonBinder extends AbstractBinder {
* Sets whether this control can contain a <code>null</code> value
*
* @param nullable <code>true</code> if the binder needs to contain a
- * <code>null</code> value
+ * <code>null</code> value
*/
public void setNullable(boolean nullable) {
- this.nullable = nullable;
+ this.nullable=nullable;
+ }
+
+ public LabelProvider getLabelProvider() {
+ return labelProvider;
+ }
+
+ /**
+ * May be used to set an own label provider
+ *
+ * @param labelProvider the label provider that will be used for the enum
+ */
+ public void setLabelProvider(LabelProvider labelProvider) {
+ this.labelProvider=labelProvider;
}
@Override
protected Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context) {
- EnumRadioButtonBinding binding = new EnumRadioButtonBinding((JPanel) control, formModel, formPropertyPath,
- getPropertyType(formModel, formPropertyPath), getSelectableEnumsList(formModel, formPropertyPath));
+ Class type=getPropertyType(formModel, formPropertyPath);
+
+ if (labelProvider==null) {
+ labelProvider=new DefaultLabelProvider(type);
+ }
+
+ EnumRadioButtonBinding binding=new EnumRadioButtonBinding((JPanel) control, formModel, formPropertyPath,
+ type, labelProvider, getSelectableEnumsList(formModel, formPropertyPath));
return binding;
}
@@ -68,7 +90,7 @@ public class EnumRadioButtonBinder extends AbstractBinder {
* Adds the <code>null</code> value if this binder is nullable.
*/
private List<Enum> getSelectableEnumsList(FormModel formModel, String formPropertyPath) {
- List<Enum> out = new ArrayList<Enum>();
+ List<Enum> out=new ArrayList<Enum>();
if (nullable) {
out.add(null);
}
@@ -78,4 +100,36 @@ public class EnumRadioButtonBinder extends AbstractBinder {
return out;
}
+ /**
+ * Default label provider for my type of enums
+ */
+ protected static class DefaultLabelProvider<T extends Enum<?>> implements LabelProvider {
+ private final MessageSourceAccessor messageSourceAccessor=(MessageSourceAccessor) ApplicationServicesLocator.services().getService(MessageSourceAccessor.class);
+
+ private final Class<T> propertyType;
+
+ private DefaultLabelProvider(Class<T> propertyType) {
+ this.propertyType=propertyType;
+ }
+
+ @Override
+ public String getLabel(Object item) {
+ T enumValue=(T) item;
+
+ String text;
+ if (enumValue==null) {
+ text=messageSourceAccessor.getMessage(propertyType.getName()+".null", "null");
+ if (text==null) {
+ text=propertyType.getName()+".null"; //fallback
+ }
+ } else {
+ text=messageSourceAccessor.getMessage(propertyType.getName()+"."+enumValue.name(), enumValue.name());
+ if (text==null) {
+ text=propertyType.getName()+"."+enumValue.name();
+ }
+ }
+ return text;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinding.java b/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinding.java
index 8d77480..dbce47b 100644
--- a/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinding.java
+++ b/spring-richclient-jdk6/src/main/java/org/springframework/richclient/form/binding/swing/EnumRadioButtonBinding.java
@@ -1,5 +1,18 @@
package org.springframework.richclient.form.binding.swing;
+import com.jgoodies.forms.factories.FormFactory;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.ColumnSpec;
+import com.jgoodies.forms.layout.FormLayout;
+import com.jgoodies.forms.layout.RowSpec;
+import org.springframework.binding.form.FormModel;
+import org.springframework.context.support.MessageSourceAccessor;
+import org.springframework.richclient.application.ApplicationServicesLocator;
+import org.springframework.richclient.form.binding.support.CustomBinding;
+import org.springframework.richclient.selection.binding.support.LabelProvider;
+import org.springframework.util.Assert;
+
+import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
@@ -7,79 +20,56 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import javax.swing.ButtonGroup;
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-
-import org.springframework.binding.form.FormModel;
-import org.springframework.context.support.MessageSourceAccessor;
-import org.springframework.richclient.form.binding.support.CustomBinding;
-import org.springframework.util.Assert;
-
-import com.jgoodies.forms.factories.FormFactory;
-import com.jgoodies.forms.layout.CellConstraints;
-import com.jgoodies.forms.layout.ColumnSpec;
-import com.jgoodies.forms.layout.FormLayout;
-import com.jgoodies.forms.layout.RowSpec;
-
/**
* Radiobutton binding for Enum values.
- *
+ * <p/>
* Labels for the radio buttons can be configured in the messages:
- *
+ * <p/>
* <pre>
* my.package.MyClass.MY_ENUM = My Enum Label
* my.package.MyClass.null = None
* </pre>
*
* @author Lieven Doclo
- *
*/
-public class EnumRadioButtonBinding extends CustomBinding {
+public class EnumRadioButtonBinding<T extends Enum<?>> extends CustomBinding {
private JPanel contentPanel;
- private List<Enum> selectableEnumsList;
-
- private Map<String, ContainerJRadioButton<Enum>> radioButtons;
+ private final List<T> selectableEnumsList;
- private Class propertyType;
+ /**
+ * Contains the radio buttons.
+ */
+ private final Map<T, JRadioButton> radioButtons=new LinkedHashMap<T, JRadioButton>();
private ButtonGroup group;
- private MessageSourceAccessor messageSourceAccessor;
+ private final LabelProvider labelProvider;
- public EnumRadioButtonBinding(JPanel contentPanel, FormModel formModel, String formPropertyPath,
- Class<?> propertyType, List<Enum> selectableEnumsList) {
+ public EnumRadioButtonBinding(JPanel contentPanel, FormModel formModel, String formPropertyPath, Class<T> propertyType, LabelProvider labelProvider, List<T> selectableEnumsList) {
super(formModel, formPropertyPath, propertyType);
- this.contentPanel = contentPanel;
- this.propertyType = propertyType;
- radioButtons = new LinkedHashMap<String, ContainerJRadioButton<Enum>>();
- messageSourceAccessor = getMessages();
- this.selectableEnumsList = selectableEnumsList;
+ this.contentPanel=contentPanel;
+ this.labelProvider=labelProvider;
+ this.selectableEnumsList=selectableEnumsList;
createRadioButtons();
}
@Override
protected void valueModelChanged(Object newValue) {
deselectAll();
- Enum enumValue = (Enum) newValue;
- ContainerJRadioButton<Enum> button;
- if (enumValue == null) {
- button = radioButtons.get(null);
- }
- else {
- button = radioButtons.get(enumValue.name());
- }
- if (button != null) {
+ T enumValue=(T) newValue;
+
+ JRadioButton button=radioButtons.get(enumValue);
+ if (button!=null) {
button.setSelected(true);
}
}
private void deselectAll() {
- if (group != null)
+ if (group!=null) {
group.clearSelection();
+ }
}
@Override
@@ -89,87 +79,75 @@ public class EnumRadioButtonBinding extends CustomBinding {
}
private JPanel createBindingControl() {
- group = new ButtonGroup();
- FormLayout layout = new FormLayout(new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC },
- getDefaultRowsWithGap(radioButtons.keySet().size()));
- int count = 1;
+ group=new ButtonGroup();
+ FormLayout layout=new FormLayout(new ColumnSpec[] {FormFactory.DEFAULT_COLSPEC}, getDefaultRowsWithGap(radioButtons.keySet().size()));
+ int count=1;
contentPanel.setLayout(layout);
- for (ContainerJRadioButton<Enum> button : radioButtons.values()) {
+ for (JRadioButton button : radioButtons.values()) {
group.add(button);
contentPanel.add(button, new CellConstraints(1, count));
- count += 2;
+ count+=2;
}
valueModelChanged(getValue());
return contentPanel;
}
private static RowSpec[] getDefaultRowsWithGap(int rowCount) {
- List<RowSpec> rows = new ArrayList<RowSpec>();
- for (int i = 0; i < rowCount; i++) {
+ List<RowSpec> rows=new ArrayList<RowSpec>();
+ for (int i=0; i<rowCount; i++) {
rows.add(new RowSpec("fill:pref:nogrow"));
rows.add(FormFactory.LINE_GAP_ROWSPEC);
}
- rows.remove(rows.size() - 1);
- return rows.toArray(new RowSpec[] {});
+ rows.remove(rows.size()-1);
+ return rows.toArray(new RowSpec[rows.size()]);
}
@Override
protected void enabledChanged() {
- for (ContainerJRadioButton<Enum> button : radioButtons.values()) {
+ for (JRadioButton button : radioButtons.values()) {
button.setEnabled(isEnabled());
}
-
}
@Override
protected void readOnlyChanged() {
- for (ContainerJRadioButton<Enum> button : radioButtons.values()) {
+ for (JRadioButton button : radioButtons.values()) {
button.setEnabled(isReadOnly());
}
}
private void createRadioButtons() {
- for (Enum enumValue : selectableEnumsList) {
- ContainerJRadioButton<Enum> button = new ContainerJRadioButton<Enum>();
- String text;
- if (enumValue == null) {
- text = messageSourceAccessor.getMessage(propertyType.getName() + ".null", "null");
- button.setText(text == null ? propertyType.getName() + ".null" : text);
- }
- else {
- text = messageSourceAccessor.getMessage(propertyType.getName() + "." + enumValue.name(), enumValue
- .name());
- button.setText(text == null ? propertyType.getName() + "." + enumValue.name() : text);
- }
- button.setContainedObject(enumValue);
- button.addActionListener(new ActionListener() {
+ for (final T enumValue : selectableEnumsList) {
+ JRadioButton button=new JRadioButton();
+ String text=getText(enumValue);
+ button.setText(text);
+ button.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
- ContainerJRadioButton<Enum> button = (ContainerJRadioButton<Enum>) e.getSource();
- controlValueChanged(button.getContainedObject());
+ controlValueChanged(enumValue);
}
-
});
- if (enumValue == null)
- radioButtons.put(null, button);
- else
- radioButtons.put(enumValue.name(), button);
-
+ radioButtons.put(enumValue, button);
}
}
- private class ContainerJRadioButton<T> extends JRadioButton {
-
- private T containedObject;
-
- public T getContainedObject() {
- return containedObject;
- }
-
- public void setContainedObject(T containedObject) {
- this.containedObject = containedObject;
- }
-
+ /**
+ * Returns the text for the given enum value
+ *
+ * @param enumValue the enum value
+ * @return the text for the enum value
+ */
+ private String getText(T enumValue) {
+ return labelProvider.getLabel(enumValue);
}
+ /**
+ * Returns the label provider
+ *
+ * @return
+ */
+ public LabelProvider getLabelProvider() {
+ return labelProvider;
+ }
}
\ No newline at end of file
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:22
|
From: Johannes Schneider <js...@ce...>
---
.../richclient/components/FileChooser.java | 37 ++++++++++++++++
.../form/binding/swing/FileChooserBinder.java | 27 +++++++++++-
.../form/binding/swing/FileChooserBinding.java | 45 +++++++++++++++-----
3 files changed, 97 insertions(+), 12 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/components/FileChooser.java b/spring-richclient-core/src/main/java/org/springframework/richclient/components/FileChooser.java
index ce7f08e..81cc651 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/components/FileChooser.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/components/FileChooser.java
@@ -1,9 +1,14 @@
package org.springframework.richclient.components;
import javax.swing.*;
+import javax.swing.text.Document;
+import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.io.File;
+import java.util.*;
+import java.util.List;
/**
* A component that shows a filesystem view and in which the user can either choose a file or a directory,
@@ -99,6 +104,10 @@ public class FileChooser extends JComponent
nameField.setText(text);
}
+ public Document getDocument() {
+ return nameField.getDocument();
+ }
+
/**
* Get the text of the file textfield
*/
@@ -148,6 +157,26 @@ public class FileChooser extends JComponent
return nameField.isEnabled() & openDialogButton.isEnabled();
}
+ private FileFilter fileFilter;
+
+ public FileFilter getFileFilter() {
+ return fileFilter;
+ }
+
+ public void setFileFilter(FileFilter fileFilter) {
+ this.fileFilter=fileFilter;
+ }
+
+ private File currentDir;
+
+ public File getCurrentDir() {
+ return currentDir;
+ }
+
+ public void setCurrentDir(File currentDir) {
+ this.currentDir=currentDir;
+ }
+
private class Handler extends MouseAdapter
{
@@ -157,6 +186,14 @@ public class FileChooser extends JComponent
if (isEnabled())
{
JFileChooser chooser = new JFileChooser();
+ if (fileFilter!=null) {
+ chooser.setFileFilter(fileFilter);
+ }
+
+ if (currentDir!=null) {
+ chooser.setCurrentDirectory(currentDir);
+ }
+
switch (mode)
{
case FILE:
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinder.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinder.java
index 4b44d6a..31de36a 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinder.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinder.java
@@ -7,7 +7,9 @@ import org.springframework.binding.form.FormModel;
import org.springframework.util.Assert;
import javax.swing.*;
+import javax.swing.filechooser.FileFilter;
import java.util.Map;
+import java.io.File;
public class FileChooserBinder implements Binder
{
@@ -21,10 +23,33 @@ public class FileChooserBinder implements Binder
{
}
+ private FileFilter fileFilter;
+
+ public FileFilter getFileFilter() {
+ return fileFilter;
+ }
+
+ public void setFileFilter(FileFilter fileFilter) {
+ this.fileFilter=fileFilter;
+ }
+
+ private File currentDir;
+
+ public File getCurrentDir() {
+ return currentDir;
+ }
+
+ public void setCurrentDir(File currentDir) {
+ this.currentDir=currentDir;
+ }
+
@SuppressWarnings("unchecked")
protected JComponent createControl(Map context)
{
- return new FileChooser();
+ FileChooser fileChooser=new FileChooser();
+ fileChooser.setCurrentDir(currentDir);
+ fileChooser.setFileFilter(fileFilter);
+ return fileChooser;
}
@SuppressWarnings("unchecked")
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinding.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinding.java
index 607bfc9..f6c4041 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinding.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FileChooserBinding.java
@@ -5,6 +5,8 @@ import org.springframework.richclient.form.binding.support.CustomBinding;
import org.springframework.richclient.components.FileChooser;
import javax.swing.*;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.DocumentEvent;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
@@ -49,6 +51,23 @@ public class FileChooserBinding extends CustomBinding
{
field.setText("");
}
+ field.getDocument().addDocumentListener(new DocumentListener() {
+ @Override
+ public void insertUpdate(DocumentEvent e) {
+ updateControlValue();
+ }
+
+ @Override
+ public void removeUpdate(DocumentEvent e) {
+ updateControlValue();
+ }
+
+ @Override
+ public void changedUpdate(DocumentEvent e) {
+ updateControlValue();
+ }
+ });
+
field.addFocusListener(new FocusListener()
{
@@ -58,22 +77,26 @@ public class FileChooserBinding extends CustomBinding
public void focusLost(FocusEvent e)
{
- if (field.isEditable())
- {
- if (useFile)
- {
- controlValueChanged(new java.io.File(field.getText()));
- }
- else
- {
- controlValueChanged(field.getText());
- }
- }
+ updateControlValue();
}
});
return field;
}
+ private void updateControlValue() {
+ if (field.isEditable())
+ {
+ if (useFile)
+ {
+ controlValueChanged(new java.io.File(field.getText()));
+ }
+ else
+ {
+ controlValueChanged(field.getText());
+ }
+ }
+ }
+
protected void readOnlyChanged()
{
field.setEditable(isEnabled() && !isReadOnly());
--
1.6.2
|
|
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
|
|
From: <mai...@ce...> - 2009-03-14 20:53:33
|
From: Johannes Schneider <js...@ce...>
---
.../form/binding/swing/TextComponentBinding.java | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/TextComponentBinding.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/TextComponentBinding.java
index e66c250..850e27d 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/TextComponentBinding.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/TextComponentBinding.java
@@ -22,6 +22,7 @@ import org.springframework.binding.form.FormModel;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.swing.AsYouTypeTextComponentAdapter;
import org.springframework.richclient.form.binding.support.AbstractBinding;
+import org.springframework.context.NoSuchMessageException;
/**
* @author Oliver Hutchison
@@ -36,7 +37,12 @@ public class TextComponentBinding extends AbstractBinding {
}
protected JComponent doBindControl() {
- final ValueModel valueModel = getValueModel();
+ try {
+ textComponent.setToolTipText( getMessages().getMessage( getProperty() + ".tooltip" ) );
+ } catch ( NoSuchMessageException ignore ) {
+ }
+
+ final ValueModel valueModel = getValueModel();
try {
textComponent.setText((String) valueModel.getValue());
}
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:31
|
From: Johannes Schneider <js...@ce...>
---
.../date/AbstractDateFieldBindingTestCase.java | 14 +++++++++++++-
.../swing/date/JCalendarDateFieldBinderTests.java | 7 ++++++-
.../date/JXDatePickerDateFieldBinderTests.java | 7 ++++++-
.../date/NachoCalendarDateFieldBinderTests.java | 8 ++++++--
4 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/AbstractDateFieldBindingTestCase.java b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/AbstractDateFieldBindingTestCase.java
index 2c1b1c6..614fa10 100644
--- a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/AbstractDateFieldBindingTestCase.java
+++ b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/AbstractDateFieldBindingTestCase.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.swing.JComponent;
+import javax.swing.JTextField;
import org.springframework.binding.form.FieldMetadata;
import org.springframework.richclient.form.binding.swing.BindingAbstractTests;
@@ -58,6 +59,15 @@ public abstract class AbstractDateFieldBindingTestCase extends BindingAbstractTe
assertNotNull(vm.getValue());
}
+ public void testNullValue() {
+ Date date = createDate(1981, 10, 16);
+ vm.setValue(date);
+
+ assertNotNull(vm.getValue());
+ setValue( dateField, "" );
+ assertNull( vm.getValue() );
+ }
+
private Date createDate(int year, int month, int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, 0, 0, 0);
@@ -88,11 +98,13 @@ public abstract class AbstractDateFieldBindingTestCase extends BindingAbstractTe
protected abstract void setValue(JComponent dateField, Date date);
+ protected abstract void setValue(JComponent dateField, String value);
+
public final void testComponentUpdatesValueModel() {
Date date1 = createDate(1981, 10, 16);
setValue(dateField, date1);
assertEquals(date1, (Date)vm.getValue());
- setValue(dateField, null);
+ setValue(dateField, (Date)null);
assertEquals(null, (Date)vm.getValue());
Date date2 = createDate(1999, 11, 31);
setValue(dateField, date2);
diff --git a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JCalendarDateFieldBinderTests.java b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JCalendarDateFieldBinderTests.java
index c01cafd..2c705fe 100644
--- a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JCalendarDateFieldBinderTests.java
+++ b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JCalendarDateFieldBinderTests.java
@@ -6,6 +6,7 @@ import java.util.Date;
import javax.swing.JComponent;
import com.toedter.calendar.JDateChooser;
+import net.sf.nachocalendar.components.DateField;
/**
* Testcase for <code>JCalendarDateFieldBinder</code> and
@@ -23,7 +24,11 @@ public class JCalendarDateFieldBinderTests extends AbstractDateFieldBindingTestC
return ((JDateChooser) dateField).getDate();
}
- protected boolean isReadOnly(JComponent dateField) {
+ protected void setValue( JComponent dateField, String value ) {
+ ( ( JDateChooser ) dateField ).getDateEditor().setDateFormatString( value );
+ }
+
+ protected boolean isReadOnly(JComponent dateField) {
return !((JDateChooser) dateField).isEnabled();
}
diff --git a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JXDatePickerDateFieldBinderTests.java b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JXDatePickerDateFieldBinderTests.java
index d313701..90a274a 100644
--- a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JXDatePickerDateFieldBinderTests.java
+++ b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/JXDatePickerDateFieldBinderTests.java
@@ -20,6 +20,7 @@ import java.util.Date;
import javax.swing.JComponent;
import org.jdesktop.swingx.JXDatePicker;
+import net.sf.nachocalendar.components.DateField;
/**
* Testcase for <code>JXDatePickerDateFieldBinder</code> and
@@ -37,7 +38,11 @@ public class JXDatePickerDateFieldBinderTests extends AbstractDateFieldBindingTe
return ((JXDatePicker) dateField).getDate();
}
- protected void setValue(JComponent dateField, Date date) {
+ protected void setValue( JComponent dateField, String value ) {
+ ( ( JXDatePicker ) dateField ).getEditor().setText( value );
+ }
+
+ protected void setValue(JComponent dateField, Date date) {
((JXDatePicker) dateField).setDate(date);
}
diff --git a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
index 6479444..d4f5956 100644
--- a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
+++ b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
@@ -33,10 +33,14 @@ public class NachoCalendarDateFieldBinderTests extends AbstractDateFieldBindingT
}
protected Date getValue(JComponent dateField) {
- return (Date) ((DateField) dateField).getValue();
+ return (Date) ((NullableDateField) dateField).getValue();
}
- protected void setValue(JComponent dateField, Date date) {
+ protected void setValue( JComponent dateField, String value ) {
+ ( ( DateField ) dateField ).getFormattedTextField().setText( value );
+ }
+
+ protected void setValue(JComponent dateField, Date date) {
((DateField) dateField).setValue(date);
}
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:23
|
From: Johannes Schneider <js...@ce...>
---
.../swing/date/NachoCalendarDateFieldBinder.java | 36 +-
.../swing/date/NachoCalendarDateFieldBinding.java | 4 +-
.../form/binding/swing/date/NullableDateField.java | 652 ++++++++++++++++++++
.../date/NachoCalendarDateFieldBinderTests.java | 4 +-
4 files changed, 678 insertions(+), 18 deletions(-)
create mode 100644 spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NullableDateField.java
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinder.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinder.java
index d2f5def..24ebc2e 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinder.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinder.java
@@ -15,6 +15,17 @@
*/
package org.springframework.richclient.form.binding.swing.date;
+import java.awt.Dimension;
+import java.util.Map;
+import java.util.Locale;
+import java.util.Date;
+import java.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+
+import javax.swing.JComponent;
+import javax.swing.text.DateFormatter;
+
import net.sf.nachocalendar.components.DateField;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
@@ -54,8 +65,8 @@ public class NachoCalendarDateFieldBinder extends AbstractDateFieldBinder {
}
protected Binding doBind(JComponent control, FormModel formModel, String formPropertyPath, Map context) {
- Assert.isTrue(control instanceof DateField, "Control must be an instance of DateField.");
- NachoCalendarDateFieldBinding binding = new NachoCalendarDateFieldBinding((DateField) control, formModel,
+ Assert.isTrue(control instanceof NullableDateField, "Control must be an instance of DateField.");
+ NachoCalendarDateFieldBinding binding = new NachoCalendarDateFieldBinding((NullableDateField) control, formModel,
formPropertyPath);
applyContext(binding, context);
return binding;
@@ -83,19 +94,16 @@ public class NachoCalendarDateFieldBinder extends AbstractDateFieldBinder {
context.remove(SHOW_WEEKNUMBERS_KEY);
}
+ // FIXME dirty hack so the DateField has the correct height
+ return new NullableDateField(showWeekNumbers){
+ private static final long serialVersionUID = 1L;
- DateField dateField = new DateField(showWeekNumbers) {
-
- private static final long serialVersionUID = 1L;
-
- public Dimension getPreferredSize() {
- Dimension size = super.getPreferredSize();
- size.height = preferredHeight;
-
- return size;
- }
- };
+ public Dimension getPreferredSize() {
+ Dimension size = super.getPreferredSize();
+ size.height = preferredHeight;
- return dateField;
+ return size;
+ }
+ };
}
}
\ No newline at end of file
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinding.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinding.java
index ffaacbf..a923803 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinding.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinding.java
@@ -33,11 +33,11 @@ import org.springframework.binding.form.FormModel;
*/
public class NachoCalendarDateFieldBinding extends AbstractDateFieldBinding {
- private final DateField dateField;
+ private final NullableDateField dateField;
private Boolean showOkCancel;
- public NachoCalendarDateFieldBinding(DateField dateField, FormModel formModel, String formPropertyPath) {
+ public NachoCalendarDateFieldBinding(NullableDateField dateField, FormModel formModel, String formPropertyPath) {
super(formModel, formPropertyPath);
this.dateField = dateField;
}
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NullableDateField.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NullableDateField.java
new file mode 100644
index 0000000..301baa0
--- /dev/null
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/date/NullableDateField.java
@@ -0,0 +1,652 @@
+package org.springframework.richclient.form.binding.swing.date;
+
+import net.sf.nachocalendar.components.ArrowButton;
+import net.sf.nachocalendar.components.CalendarUtils;
+import net.sf.nachocalendar.components.DatePanel;
+import net.sf.nachocalendar.components.DayRenderer;
+import net.sf.nachocalendar.components.DefaultDayRenderer;
+import net.sf.nachocalendar.components.DefaultHeaderRenderer;
+import net.sf.nachocalendar.components.HeaderRenderer;
+import net.sf.nachocalendar.model.DataModel;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.DateFormatter;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ *
+ */
+public class NullableDateField extends JPanel implements ActionListener, PropertyChangeListener {
+ private WindowPanel windowpanel;
+ //private Date fecha;
+ private DatePanel datepanel;
+ private JFormattedTextField field;
+ private JButton button;
+ private Calendar calendar;
+ private boolean showWeekNumbers;
+ private DateFormatter formatter;
+ private boolean antiAliased;
+ private boolean printMoon;
+ private Locale locale;
+ private DateFormat dateFormat;
+ private Date baseDate;
+
+ private JFormattedTextField.AbstractFormatterFactory formatterFactory = new JFormattedTextField.AbstractFormatterFactory() {
+ public JFormattedTextField.AbstractFormatter getFormatter( JFormattedTextField tf ) {
+ return new DateFormatter( dateFormat );
+ }
+ };
+
+ /**
+ * Utility field holding list of ChangeListeners.
+ */
+ private transient java.util.ArrayList changeListenerList;
+
+ /**
+ * Holds value of property showOkCancel.
+ */
+ private boolean showOkCancel;
+
+ /**
+ * Holds value of property firstDayOfWeek.
+ */
+ private int firstDayOfWeek;
+
+ /**
+ * Holds value of property workingDays.
+ */
+ private boolean[] workingDays;
+
+ /**
+ * Creates a new instance of DateField.
+ *
+ * @param showWeekNumbers true if the week numbers must be shown
+ */
+ public NullableDateField( boolean showWeekNumbers ) {
+ //panel = new WindowPanel(parent, showWeekNumbers);
+ this.showWeekNumbers = showWeekNumbers;
+ init();
+ }
+
+ /**
+ * Constructs a default DateField.
+ */
+ public NullableDateField() {
+ this( false );
+ }
+
+ /**
+ * Constructor with a custom formatter.
+ *
+ * @param formatter formatter used for the textfield
+ */
+ public NullableDateField( DateFormatter formatter ) {
+ this.formatter = formatter;
+ init();
+ }
+
+ public NullableDateField( DateFormat dateFormat ) {
+ this.dateFormat = dateFormat;
+ init();
+ }
+
+ /**
+ * Constructor with a custom locale.
+ *
+ * @param locale Locale to use
+ */
+ public NullableDateField( Locale locale ) {
+ this.locale = locale;
+ init();
+ }
+
+ private void init() {
+ if ( locale == null ) locale = Locale.getDefault();
+ calendar = Calendar.getInstance();
+ calendar.set( Calendar.HOUR, 0 );
+ calendar.set( Calendar.MINUTE, 0 );
+ calendar.set( Calendar.MILLISECOND, 0 );
+ datepanel = new DatePanel( showWeekNumbers );
+ datepanel.setFirstDayOfWeek( firstDayOfWeek );
+ datepanel.setWorkingDays( workingDays );
+ datepanel.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+ setRenderer( new DefaultDayRenderer() );
+ setHeaderRenderer( new DefaultHeaderRenderer() );
+ setLayout( new BorderLayout() );
+ if ( dateFormat != null ) {
+ field = new JFormattedTextField( dateFormat );
+ } else {
+ if ( formatter == null ) formatter = new DateFormatter( DateFormat.getDateInstance( DateFormat.SHORT, locale ) );
+ field = new JFormattedTextField( formatter );
+ }
+ add( field, BorderLayout.CENTER );
+ button = new ArrowButton( SwingConstants.SOUTH );
+ add( button, BorderLayout.EAST );
+ button.addActionListener( this );
+ field.setValue( new Date() );
+ field.addPropertyChangeListener( "value", this );
+ Border border = field.getBorder();
+ field.setBorder( null );
+ setBorder( border );
+
+ field.addPropertyChangeListener( new PropertyChangeListener() {
+ public void propertyChange( PropertyChangeEvent evt ) {
+ if ( "editValid".equals( evt.getPropertyName() ) && evt.getNewValue()==Boolean.FALSE ) {
+ if ( field.getText().length() == 0 ) {
+ field.setValue( null );
+ }
+ }
+
+ firePropertyChange( evt.getPropertyName(), evt.getOldValue(), evt.getNewValue() );
+ }
+ } );
+ }
+
+ private void aceptar() {
+ windowpanel.setVisible( false );
+ field.setValue( windowpanel.getDate() );
+ }
+
+ private void cancelar() {
+ windowpanel.setVisible( false );
+ }
+
+ private void createWindow() {
+ Component c = this;
+ //Dialog d = null;
+ while ( !( c instanceof Dialog ) && ( c != null ) ) {
+ c = c.getParent();
+ }
+ if ( c != null ) {
+ windowpanel = new WindowPanel( ( Dialog ) c, showWeekNumbers );
+ return;
+ }
+
+ Frame f = JOptionPane.getFrameForComponent( this );
+ windowpanel = new WindowPanel( f, showWeekNumbers );
+ }
+
+ /**
+ * Invoked when an action occurs.
+ *
+ * @param e the event fired
+ */
+ public void actionPerformed( ActionEvent e ) {
+ if ( windowpanel == null ) {
+ createWindow();
+ }
+
+ Date da = ( Date ) field.getValue();
+ if ( da == null ) {
+ da = baseDate;
+ }
+ if ( da == null ) {
+ da = calendar.getTime();
+ }
+ windowpanel.setDate( da );
+ Point p = getLocationOnScreen();
+ p.y += getHeight();
+ windowpanel.setLocation( p );
+ windowpanel.setVisible( true );
+ }
+
+ /**
+ * Sets the current Date.
+ *
+ * @param value current Date
+ */
+ public void setValue( Object value ) {
+ try {
+ field.setValue( CalendarUtils.convertToDate( value ) );
+ } catch ( ParseException e ) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns the current Date.
+ *
+ * @return current Date
+ */
+ public Object getValue() {
+ return field.getValue();
+ }
+
+ /**
+ * Registers ChangeListener to receive events.
+ *
+ * @param listener The listener to register.
+ */
+ public synchronized void addChangeListener( ChangeListener listener ) {
+ if ( changeListenerList == null ) {
+ changeListenerList = new java.util.ArrayList();
+ }
+ changeListenerList.add( listener );
+ }
+
+ /**
+ * Removes ChangeListener from the list of listeners.
+ *
+ * @param listener The listener to remove.
+ */
+ public synchronized void removeChangeListener( ChangeListener listener ) {
+ if ( changeListenerList != null ) {
+ changeListenerList.remove( listener );
+ }
+ }
+
+ /**
+ * Notifies all registered listeners about the event.
+ *
+ * @param event The event to be fired
+ */
+ private void fireChangeListenerStateChanged( ChangeEvent event ) {
+ java.util.ArrayList list;
+ synchronized ( this ) {
+ if ( changeListenerList == null ) {
+ return;
+ }
+ list = ( java.util.ArrayList ) changeListenerList.clone();
+ }
+ for ( int i = 0; i < list.size(); i++ ) {
+ ( ( javax.swing.event.ChangeListener ) list.get( i ) ).stateChanged( event );
+ }
+ }
+
+ /**
+ * Event fired when a property changes.
+ *
+ * @param evt event fired
+ */
+ public void propertyChange( PropertyChangeEvent evt ) {
+ fireChangeListenerStateChanged( new ChangeEvent( this ) );
+ }
+
+ /**
+ * Getter for property renderer.
+ *
+ * @return Value of property renderer.
+ */
+ public DayRenderer getRenderer() {
+ return datepanel.getRenderer();
+ }
+
+ /**
+ * Setter for property renderer.
+ *
+ * @param renderer New value of property renderer.
+ */
+ public void setRenderer( DayRenderer renderer ) {
+ datepanel.setRenderer( renderer );
+ }
+
+ /**
+ * Getter for property model.
+ *
+ * @return Value of property model.
+ */
+ public DataModel getModel() {
+ return datepanel.getModel();
+ }
+
+ /**
+ * Setter for property model.
+ *
+ * @param model New value of property model.
+ */
+ public void setModel( DataModel model ) {
+ datepanel.setModel( model );
+ }
+
+ /**
+ * Getter for property headerRenderer.
+ *
+ * @return Value of property headerRenderer.
+ */
+ public HeaderRenderer getHeaderRenderer() {
+ return datepanel.getHeaderRenderer();
+ }
+
+ /**
+ * Setter for property headerRenderer.
+ *
+ * @param headerRenderer New value of property headerRenderer.
+ */
+ public void setHeaderRenderer( HeaderRenderer headerRenderer ) {
+ datepanel.setHeaderRenderer( headerRenderer );
+ }
+
+ /**
+ * Getter for property showOkCancel.
+ *
+ * @return Value of property showOkCancel.
+ */
+ public boolean getShowOkCancel() {
+ return this.showOkCancel;
+ }
+
+ /**
+ * Setter for property showOkCancel.
+ *
+ * @param showOkCancel New value of property showOkCancel.
+ */
+ public void setShowOkCancel( boolean showOkCancel ) {
+ if ( this.showOkCancel == showOkCancel ) {
+ return;
+ }
+ boolean old = this.showOkCancel;
+ this.showOkCancel = showOkCancel;
+ windowpanel = null;
+ firePropertyChange( "showOkCancel", old, showOkCancel );
+ }
+
+ /**
+ * Getter for property allowsInvalid.
+ *
+ * @return Value of property showOkCancel.
+ */
+ public boolean getAllowsInvalid() {
+ return formatter.getAllowsInvalid();
+ }
+
+ /**
+ * Setter for property allowsInvalid.
+ *
+ * @param showOkCancel New value of property showOkCancel.
+ */
+ public void setAllowsInvalid( boolean b ) {
+ boolean old = formatter.getAllowsInvalid();
+ formatter.setAllowsInvalid( b );
+ firePropertyChange( "allowsInvalid", old, b );
+ }
+
+ /**
+ * Getter for property firstDayOfWeek.
+ *
+ * @return Value of property firstDayOfWeek.
+ */
+ public int getFirstDayOfWeek() {
+ return this.firstDayOfWeek;
+ }
+
+ /**
+ * Setter for property firstDayOfWeek.
+ *
+ * @param firstDayOfWeek New value of property firstDayOfWeek.
+ */
+ public void setFirstDayOfWeek( int firstDayOfWeek ) {
+ int old = this.firstDayOfWeek;
+ if ( datepanel != null ) datepanel.setFirstDayOfWeek( firstDayOfWeek );
+ this.firstDayOfWeek = firstDayOfWeek;
+ firePropertyChange( "firstDayOfWeek", old, firstDayOfWeek );
+ }
+
+ /**
+ * Getter for property workingDays.
+ *
+ * @return Value of property workingDays.
+ */
+ public boolean[] getWorkingDays() {
+ return this.workingDays;
+ }
+
+ /**
+ * Setter for property workingDays.
+ *
+ * @param workingDays New value of property workingDays.
+ */
+ public void setWorkingDays( boolean[] workingDays ) {
+ boolean[] old = this.workingDays;
+ if ( datepanel != null ) datepanel.setWorkingDays( workingDays );
+ this.workingDays = workingDays;
+ firePropertyChange( "workingDays", old, workingDays );
+ }
+
+ /**
+ * Enables or disables the component
+ *
+ * @param enabled true for enabling
+ */
+ public void setEnabled( boolean enabled ) {
+ button.setEnabled( enabled );
+ field.setEnabled( enabled );
+ super.setEnabled( enabled );
+ }
+
+ /**
+ * Getter for enabled property
+ *
+ * @return true if it's enabled
+ */
+ public boolean isEnabled() {
+ return button.isEnabled();
+ }
+
+ /**
+ * Returns the JFormattedTextField for further customization
+ *
+ * @return the JFormattedTextField
+ */
+ public JFormattedTextField getFormattedTextField() {
+ return field;
+ }
+
+ class WindowPanel extends JDialog {
+ public WindowPanel( Frame parent, boolean showWeekNumbers ) {
+ super( parent, false );
+ init( showWeekNumbers );
+ }
+
+ public WindowPanel( Dialog parent, boolean showWeekNumbers ) {
+ super( parent, false );
+ init( showWeekNumbers );
+ }
+
+ private void init( boolean showWeekNumbers ) {
+ setUndecorated( true );
+ setFocusable( true );
+ JPanel todo = new JPanel( new BorderLayout() );
+ getContentPane().add( todo );
+ todo.add( datepanel );
+ todo.setBorder( BorderFactory.createLineBorder( Color.black ) );
+
+ if ( showOkCancel ) {
+ JPanel abajo = new JPanel();
+ todo.add( abajo, BorderLayout.SOUTH );
+ JButton ok = new JButton( "Ok" );
+ JButton cancel = new JButton( "Cancel" );
+ abajo.add( ok );
+ abajo.add( cancel );
+ getRootPane().setDefaultButton( ok );
+ ok.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent e ) {
+ aceptar();
+ }
+ } );
+ cancel.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent e ) {
+ cancelar();
+ }
+ } );
+ } else {
+ /*datepanel.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ aceptar();
+ }
+ });*/
+ datepanel.addActionListener( new ActionListener() {
+ public void actionPerformed( ActionEvent e ) {
+ aceptar();
+ }
+ } );
+ }
+
+ KeyListener klistener = new KeyAdapter() {
+ public void keyTyped( KeyEvent e ) {
+ if ( e.getKeyChar() == 10 ) {
+ aceptar();
+ }
+ if ( e.getKeyChar() == 27 ) {
+ cancelar();
+ }
+ }
+ };
+
+ datepanel.addKeyListener( klistener );
+ addKeyListener( klistener );
+
+
+ addWindowListener( new WindowAdapter() {
+ public void windowDeactivated( WindowEvent e ) {
+ cancelar();
+ }
+ } );
+
+
+ pack();
+ }
+
+ public Date getDate() {
+ return datepanel.getDate();
+ }
+
+ public void setDate( Date d ) {
+ datepanel.setDate( d );
+ }
+ }
+
+ /**
+ * @return Returns the antiAliased.
+ */
+ public boolean isAntiAliased() {
+ return antiAliased;
+ }
+
+ /**
+ * @param antiAliased The antiAliased to set.
+ */
+ public void setAntiAliased( boolean antiAliased ) {
+ boolean old = this.antiAliased;
+ this.antiAliased = antiAliased;
+ datepanel.setAntiAliased( antiAliased );
+ firePropertyChange( "antiAliased", old, antiAliased );
+ }
+
+ /**
+ * @return Returns the printMoon.
+ */
+ public boolean isPrintMoon() {
+ return printMoon;
+ }
+
+ /**
+ * @param printMoon The printMoon to set.
+ */
+ public void setPrintMoon( boolean printMoon ) {
+ datepanel.setPrintMoon( printMoon );
+ repaint();
+ this.printMoon = printMoon;
+ }
+
+ /**
+ * Sets the Today button visibility.
+ *
+ * @param show
+ */
+ public void setShowToday( boolean show ) {
+ datepanel.setShowToday( show );
+ repaint();
+ }
+
+ /**
+ * Returns the Today button visibility.
+ *
+ * @return
+ */
+ public boolean getShowToday() {
+ return datepanel.getShowToday();
+ }
+
+ /**
+ * Sets the today button text.
+ *
+ * @param caption
+ */
+ public void setTodayCaption( String caption ) {
+ datepanel.setTodayCaption( caption );
+ }
+
+ /**
+ * Returns the today button text.
+ *
+ * @return
+ */
+ public String getTodayCaption() {
+ return datepanel.getTodayCaption();
+ }
+
+ /**
+ * @return Returns the dateFormat.
+ */
+ public DateFormat getDateFormat() {
+ return dateFormat;
+ }
+
+ /**
+ * @param dateFormat The dateFormat to set.
+ */
+ public void setDateFormat( DateFormat dateFormat ) {
+ this.dateFormat = dateFormat;
+ field.setFormatterFactory( formatterFactory );
+ }
+
+ /**
+ * @return Returns the baseDate.
+ */
+ public Date getBaseDate() {
+ return baseDate;
+ }
+
+ /**
+ * A base date may different from "today" and will be the date
+ * shown on the Date Window when it is launched. Basically, a user
+ * can have an empty textfield but when the window is open, it won't show
+ * today by default but whatever baseDate is. It is backward compatible, ie
+ * if you do not have a baseDate, the window will open with "today".
+ *
+ * @param baseDate The baseDate to set.
+ */
+ public void setBaseDate( Date baseDate ) {
+ this.baseDate = baseDate;
+ }
+}
+
diff --git a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
index d4f5956..de49248 100644
--- a/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
+++ b/spring-richclient-core/src/test/java/org/springframework/richclient/form/binding/swing/date/NachoCalendarDateFieldBinderTests.java
@@ -37,11 +37,11 @@ public class NachoCalendarDateFieldBinderTests extends AbstractDateFieldBindingT
}
protected void setValue( JComponent dateField, String value ) {
- ( ( DateField ) dateField ).getFormattedTextField().setText( value );
+ ( ( NullableDateField ) dateField ).getFormattedTextField().setText( value );
}
protected void setValue(JComponent dateField, Date date) {
- ((DateField) dateField).setValue(date);
+ ((NullableDateField) dateField).setValue(date);
}
protected boolean isReadOnly(JComponent dateField) {
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:27
|
From: Johannes Schneider <js...@ce...>
---
.../config/ApplicationLifecycleAdvisor.java | 41 ++++++++++++++------
.../jide/JideApplicationLifecycleAdvisor.java | 24 -----------
2 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/application/config/ApplicationLifecycleAdvisor.java b/spring-richclient-core/src/main/java/org/springframework/richclient/application/config/ApplicationLifecycleAdvisor.java
index 59ecff2..74629d9 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/application/config/ApplicationLifecycleAdvisor.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/application/config/ApplicationLifecycleAdvisor.java
@@ -28,6 +28,8 @@ import org.springframework.richclient.command.CommandGroup;
import org.springframework.richclient.exceptionhandling.DefaultRegisterableExceptionHandler;
import org.springframework.richclient.exceptionhandling.RegisterableExceptionHandler;
+import javax.swing.RepaintManager;
+
/**
* <p>
* Advisor for the Application. This class provides the startingPageId, an
@@ -89,6 +91,8 @@ public abstract class ApplicationLifecycleAdvisor implements InitializingBean {
/** ExceptionHandler to catch all uncaught exceptions. */
private RegisterableExceptionHandler registerableExceptionHandler;
+ private StatusBar statusBar;
+
/**
* This is used to allow the ViewDescriptor to be lazily created when the
* ApplicationWindow is opened. Useful when the ApplicationAdvisor needs to
@@ -165,7 +169,6 @@ public abstract class ApplicationLifecycleAdvisor implements InitializingBean {
* Hook called right after the applicationWindow is created.
*/
public void onPostStartup() {
-
}
/**
@@ -226,16 +229,29 @@ public abstract class ApplicationLifecycleAdvisor implements InitializingBean {
return new CommandGroup();
}
- /**
- * Create the statusBar for the application.
- *
- * @return a statusBar.
- */
- public StatusBar getStatusBar() {
- return new DefaultStatusBar();
- }
-
- /**
+ /**
+ * Returns the current status bar. If one is
+ * not injected in the configuration file the default
+ * is used.
+ */
+ public StatusBar getStatusBar(){
+ if(statusBar == null){
+ statusBar = new DefaultStatusBar();
+ }
+ return statusBar;
+ }
+
+ /**
+ * Change the default StatusBarCommandGroup by
+ * providing another implementation.
+ *
+ * @param statusBar
+ */
+ public void setStatusBar( StatusBar statusBar ) {
+ this.statusBar = statusBar;
+ }
+
+ /**
* Hook called right after commands are initialized. Typically the next step
* after the get*CommandGroup() methods are called.
*
@@ -298,8 +314,9 @@ public abstract class ApplicationLifecycleAdvisor implements InitializingBean {
return applicationSessionInitializer;
}
+
public void setApplicationSessionInitializer(ApplicationSessionInitializer applicationSessionInitializer)
{
this.applicationSessionInitializer = applicationSessionInitializer;
}
-}
\ No newline at end of file
+}
diff --git a/spring-richclient-integrations/spring-richclient-jide/spring-richclient-jide-docking/src/main/java/org/springframework/richclient/application/docking/jide/JideApplicationLifecycleAdvisor.java b/spring-richclient-integrations/spring-richclient-jide/spring-richclient-jide-docking/src/main/java/org/springframework/richclient/application/docking/jide/JideApplicationLifecycleAdvisor.java
index bddf5c5..fd3891d 100644
--- a/spring-richclient-integrations/spring-richclient-jide/spring-richclient-jide-docking/src/main/java/org/springframework/richclient/application/docking/jide/JideApplicationLifecycleAdvisor.java
+++ b/spring-richclient-integrations/spring-richclient-jide/spring-richclient-jide-docking/src/main/java/org/springframework/richclient/application/docking/jide/JideApplicationLifecycleAdvisor.java
@@ -33,7 +33,6 @@ import javax.swing.*;
public class JideApplicationLifecycleAdvisor extends
DefaultApplicationLifecycleAdvisor {
- private StatusBar statusBar = null;
private RepaintManager repaintManager;
public CommandGroup getSpecificCommandGroup(String name){
@@ -59,33 +58,10 @@ public class JideApplicationLifecycleAdvisor extends
public void setRepaintManager(RepaintManager repaintManager){
this.repaintManager = repaintManager;
}
-
- /**
- * Change the default StatusBarCommandGroup by
- * providing another implementation.
- *
- * @param statusBar
- */
- public void setStatusBar(StatusBar statusBar){
- this.statusBar = statusBar;
- }
-
- /**
- * Returns the current status bar. If one is
- * not injected in the configuration file the default
- * is used.
- */
- public StatusBar getStatusBar(){
- if(statusBar == null){
- statusBar = new DefaultStatusBar();
- }
- return statusBar;
- }
private void initializeRepaintManager(){
if(repaintManager != null){
RepaintManager.setCurrentManager(repaintManager);
}
}
-
}
--
1.6.2
|
|
From: <mai...@ce...> - 2009-03-14 20:53:19
|
From: Johannes Schneider <js...@ce...>
---
.../form/builder/AbstractFormBuilder.java | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/AbstractFormBuilder.java b/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/AbstractFormBuilder.java
index c3b1991..1a4639f 100644
--- a/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/AbstractFormBuilder.java
+++ b/spring-richclient-core/src/main/java/org/springframework/richclient/form/builder/AbstractFormBuilder.java
@@ -209,7 +209,7 @@ public abstract class AbstractFormBuilder {
* label.
* @return a {@link JLabel} for the property.
*/
- protected JLabel createLabelFor(String fieldName, JComponent component) {
+ public JLabel createLabelFor(String fieldName, JComponent component) {
JLabel label = getComponentFactory().createLabel("");
getFormModel().getFieldFace(fieldName).configure(label);
label.setLabelFor(component);
--
1.6.2
|