KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > io > swing > AbstractFileView


1 /*
2  * DecoratingFileView.java
3  *
4  * Created on 7. Dezember 2006, 14:49
5  */

6 /*
7  * Copyright 2006 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.io.swing;
23
24 import java.io.*;
25
26 import javax.swing.*;
27 import javax.swing.filechooser.FileView JavaDoc;
28
29 /**
30  * An abstract decorator which simply delegates to another instance of
31  * {@link FileView}.
32  * If the delegate is <code>null</code>, the methods in this class return
33  * <code>null</code>.
34  * Subclasses should override individual methods to implement some specific
35  * behaviour.
36  * Note that this class does not override any methods in {@link Object}
37  * - this may be done in a subclass.
38  *
39  * @author Christian Schlichtherle
40  */

41 abstract class AbstractFileView extends FileView {
42
43     /**
44      * The file view to be decorated - may be <code>null</code>.
45      */

46     private FileView delegate;
47
48     /**
49      * Constructs a new decorating file view.
50      *
51      * @param delegate The file view to be decorated - may be <code>null</code>.
52      */

53     protected AbstractFileView(final FileView delegate) {
54         this.delegate = delegate;
55     }
56
57     /**
58      * Returns the file view to be decorated - may be <code>null</code>.
59      */

60     public FileView getDelegate() {
61         return delegate;
62     }
63
64     /**
65      * Sets the file view to be decorated - may be <code>null</code>.
66      *
67      * @throws IllegalArgumentException If <code>delegate</code> is this
68      * instance.
69      */

70     public void setDelegate(final FileView delegate) {
71         if (delegate == this)
72             throw new IllegalArgumentException JavaDoc();
73         this.delegate = delegate;
74     }
75
76     public String JavaDoc getDescription(File f) {
77         return delegate != null ? delegate.getDescription(f) : null;
78     }
79
80     public Icon getIcon(File f) {
81         return delegate != null ? delegate.getIcon(f) : null;
82     }
83
84     public String JavaDoc getName(File f) {
85         return delegate != null ? delegate.getName(f) : null;
86     }
87
88     public String JavaDoc getTypeDescription(File f) {
89         return delegate != null ? delegate.getTypeDescription(f) : null;
90     }
91
92     public Boolean JavaDoc isTraversable(File f) {
93         return delegate != null ? delegate.isTraversable(f) : null;
94     }
95 }
96
Popular Tags