KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > model > FileSelection


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.designer.model;
5
6 import java.io.File JavaDoc;
7 import java.util.Observable JavaDoc;
8 import java.util.Observer JavaDoc;
9
10
11 /**
12  * A model for a visual component is a file name that can be populated via a
13  * file selection.
14  */

15 public class FileSelection extends Observable JavaDoc
16 implements DesignDefinition, FormDefinition {
17
18     private final String JavaDoc heading;
19     private final SimpleAttribute designElement;
20     
21     public FileSelection(String JavaDoc heading, SimpleAttribute de) {
22         this.heading = heading;
23         this.designElement = de;
24         designElement.addObserver(new Observer JavaDoc() {
25             public void update(Observable JavaDoc o, Object JavaDoc arg) {
26                 setChanged();
27                 notifyObservers();
28             }
29         });
30     }
31
32     public String JavaDoc getTitle() {
33         return heading;
34     }
35
36     /**
37      * Used by the view to set text value of the field.
38      *
39      * @param text The file name text.
40      */

41     public void setFile(File JavaDoc file) {
42         if (file == null) {
43             designElement.attribute(null);
44         }
45         else {
46             designElement.attribute(file.getPath());
47         }
48     }
49
50     /**
51      * Used by the view to get the text value for the field.
52      *
53      * @return The file name text.
54      */

55     public File JavaDoc getFile() {
56         if (designElement.attribute() == null) {
57             return null;
58         }
59         return new File JavaDoc(designElement.attribute());
60     }
61     
62     /* (non-Javadoc)
63      * @see org.oddjob.designer.model.DialogDefinition#accept(org.oddjob.designer.model.DialogProcessor)
64      */

65     public void accept(DesignProcessor processor) {
66         processor.onFileSelection(this);
67     }
68     
69     /* (non-Javadoc)
70      * @see org.oddjob.designer.model.DesignDefinition#isPopulated()
71      */

72     public boolean isPopulated() {
73         return designElement.attribute() != null;
74     }
75 }
76
Popular Tags