Revision: 590
http://svn.sourceforge.net/magicmap/?rev=590&view=rev
Author: Jan_fride
Date: 2007-03-02 13:18:24 -0800 (Fri, 02 Mar 2007)
Log Message:
-----------
private memebers possible
Modified Paths:
--------------
trunk/magicmapclient/src/net/sf/magicmap/client/gui/forms/AbstractAttributeForm.java
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/gui/forms/AbstractAttributeForm.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/gui/forms/AbstractAttributeForm.java 2007-03-02 20:55:13 UTC (rev 589)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/gui/forms/AbstractAttributeForm.java 2007-03-02 21:18:24 UTC (rev 590)
@@ -15,31 +15,20 @@
*/
public abstract class AbstractAttributeForm<T extends UserInterface> {
- private final Map<String, Field> uiAttributeMap = new HashMap<String, Field>();
+
public AbstractAttributeForm() {
super();
- getAttributes();
}
- private void getAttributes() {
- Field[] fields = this.getClass().getDeclaredFields();
- for (Field field: fields){
- if (field.isAnnotationPresent(UIAttribute.class)){
- String attributeName = field.getAnnotation(UIAttribute.class).name();
- uiAttributeMap.put(attributeName, field);
- }
- }
- }
-
/**
*
* @param model
* @return
*/
public final JComponent attattch(T model) {
- initComponents(model);
+ initComponents(this, model);
return doAttattch(model);
}
@@ -52,22 +41,25 @@
* @param model the model containing the attributes.
* @throws IllegalArgumentException if an annotated field is not accessable.
*/
- private void initComponents(UserInterface model) throws IllegalArgumentException {
- for (String attributeName: uiAttributeMap.keySet()){
+ private void initComponents(Object object, UserInterface model) throws IllegalArgumentException {
+ Field[] fields = object.getClass().getDeclaredFields();
+ for (Field field: fields){
+ if (field.isAnnotationPresent(UIAttribute.class)){
+ String attributeName = field.getAnnotation(UIAttribute.class).name();
+ Class fieldClass = field.getType();
- Field field = uiAttributeMap.get(attributeName);
- Class fieldClass = field.getType();
-
- JComponent component = model.visualProxy(attributeName, null);
- Class<? extends JComponent> componentClass = component.getClass();
- if (fieldClass.isAssignableFrom(componentClass)){
- try {
- field.set(this, component);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
+ JComponent component = model.visualProxy(attributeName, null);
+ Class<? extends JComponent> componentClass = component.getClass();
+ if (fieldClass.isAssignableFrom(componentClass)){
+ try {
+ field.setAccessible(true);
+ field.set(object, component);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
}
+ else throw new IllegalArgumentException("Form und Userinteface classes incompatible: " + fieldClass + " - " + componentClass);
}
- else throw new IllegalArgumentException("Form und Userinteface classes incompatible: " + fieldClass + " - " + componentClass);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|