This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 40150
Collapse All | Expand All

(-)openidex/manifest.mf (-2 / +2 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openidex.util/2
2
OpenIDE-Module: org.openidex.util/3
3
OpenIDE-Module-Localizing-Bundle: org/openidex/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openidex/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.7
4
OpenIDE-Module-Specification-Version: 3.1
5
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
5
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
6
OpenIDE-Module-Layer: org/openidex/resources/mf-layer.xml
6
OpenIDE-Module-Layer: org/openidex/resources/mf-layer.xml
7
OpenIDE-Module-IDE-Dependencies: IDE/1 > 3.17
7
OpenIDE-Module-IDE-Dependencies: IDE/1 > 3.17
(-)openidex/looks/.cvsignore (-7 lines)
Removed Link Here
1
netbeans
2
looks.nbm
3
manifest-subst.mf
4
Info
5
LooksAPIs
6
LooksAPIs.zip
7
javadoc
(-)openidex/looks/build.xml (-147 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- sgml-indent-step: 2 -*- -->
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
15
<project name="looks" default="netbeans" basedir=".">
16
    <import file="../../nbbuild/default.xml"/> 
17
18
    <target name="init" depends="default.init">
19
        <patternset id="looks.files">
20
            <include name="${nb.modules/autoload.dir}/looks.jar"/>
21
        </patternset>
22
        <path id="cp">
23
            <pathelement location="../../openide/openide-13javac-workaround.jar"/>
24
	         <pathelement location="${core/naming.dir}/${nb.modules/autoload.dir}/naming.jar"/>
25
            <pathelement location="${openide.dir}/${nb.lib.dir}/openide.jar"/>
26
            <pathelement location="${openide/loaders.dir}/${nb.lib.dir}/openide-loaders.jar"/>
27
        </path>
28
    </target>
29
  
30
  <target name="compile" depends="init">
31
    <javac srcdir="src" destdir="src" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}">
32
      <classpath refid="cp"/>
33
    </javac>
34
  </target>
35
36
  <target name="jars" depends="compile">
37
    <mkdir dir="${netbeans.dest.dir}/${cluster.dir}/${nb.modules/autoload.dir}"/>
38
    <filter token="BUILD_NUMBER_SUBST" value="${buildnumber}"/>
39
    <copy file="manifest.mf" tofile="manifest-subst.mf" filtering="on"/>
40
    <jar jarfile="${netbeans.dest.dir}/${cluster.dir}/${nb.modules/autoload.dir}/looks.jar"
41
         manifest="manifest-subst.mf"
42
         basedir="src"
43
	      excludesfile="../../nbbuild/standard-jar-excludes.txt"
44
	      compress="false">
45
    </jar>
46
  </target>
47
48
  <target name="netbeans" depends="jars" description="Build everything.">
49
    <genlist outputfiledir="${netbeans.dest.dir}/${cluster.dir}" module="${nb.modules/autoload.dir}/looks.jar">
50
      <fileset dir="${netbeans.dest.dir}/${cluster.dir}">
51
        <include name="${nb.modules/autoload.dir}/looks.jar"/>
52
      </fileset>
53
    </genlist>
54
  </target>
55
56
  <target name="nbm" depends="netbeans" description="Build a distributable NBM.">
57
    <makenbm file="looks.nbm"
58
             productdir="${netbeans.dest.dir}/${cluster.dir}"
59
             module="${nb.modules/autoload.dir}/looks.jar"
60
             homepage="http://openidex.${homepage.base}/"
61
             distribution="http://${dist.base}/looks.nbm">
62
      <license file="${license.file}"/>
63
      <signature keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}"/>
64
    </makenbm>
65
  </target>
66
67
  <target name="clean" depends="init" description="Clean all build products.">
68
    <delete>
69
      <fileset dir="src">
70
        <include name="**/*.class"/>
71
      </fileset>
72
      <fileset dir="${netbeans.dest.dir}/${cluster.dir}">
73
        <patternset refID="looks.files"/>
74
      </fileset>
75
    </delete>
76
    <delete file="manifest-subst.mf"/>
77
    <delete file="looks.nbm"/>
78
    <delete dir="netbeans"/>
79
    <delete dir="Info"/>
80
    <delete dir="javadoc"/>
81
    <delete dir="LooksAPIs"/>
82
    <delete file="LooksAPIs.zip"/>
83
  </target>
84
85
  <!-- api changes documentation -->
86
  <target name="apichanges-check" description="Check syntax of API changes list. Requires Ant 1.4!">
87
      <xmlvalidate file="api/doc/changes/apichanges.xml" failonerror="true"/>
88
  </target>
89
  <target name="apichanges-generate" description="Regenerate HTML from XML API changes list.">
90
      <!-- Ant 1.3 and 1.4 disagree on style attribute. -->
91
      <!-- 1.3: treated as a name relative to XML file. -->
92
      <!-- 1.4: treated as a filename consistent with normal Ant usage. -->
93
      <!-- Be safe and give the absolute path here. -->
94
      <style in="api/doc/changes/apichanges.xml" out="../www/proposals/looks/apichanges.html" destdir="www" style="${basedir}/../../openide/api/doc/changes/apichanges.xsl"/>
95
  </target>
96
97
  <target name="javadoc" depends="looks-apis">
98
    <copy todir="javadoc">
99
      <fileset dir=".">
100
        <include name="LooksAPIs/**"/>
101
        <include name="LooksAPIs.zip"/>
102
      </fileset>
103
    </copy>
104
  </target>
105
106
  <!-- Looks API documentation -->
107
  <target name="looks-apis" description="Create Looks API documentation.">
108
    <property name="jdk-docs-location" value="http://java.sun.com/j2se/1.3/docs/api"/>
109
    <property name="openide-docs-location" value="http://www.netbeans.org/download/apis/"/>
110
    <property name="openide.package-list.loc" location="${nbroot}/openide/OpenAPIs"/>
111
    <echo message="Build Looks API documentation..."/>
112
    <delete dir="LooksAPIs"/>
113
    <mkdir dir="LooksAPIs"/>
114
    <javadoc destdir="LooksAPIs"
115
             packagenames="org.netbeans.api.*,org.netbeans.spi.*"
116
             doctitle="NetBeans Looks APIs"
117
             use="true"
118
             splitindex="true"
119
             author="false"
120
             version="false"
121
             maxmemory="64m"
122
    >
123
      <sourcepath>
124
        <pathelement location="api/doc"/>
125
        <pathelement location="src"/>
126
      </sourcepath>
127
      <classpath>
128
        <fileset dir="${nbroot}/openide/netbeans/lib">
129
          <include name="openide*.jar" />
130
        </fileset>
131
	<pathelement location="../../core/naming/netbeans/modules/autoload/naming.jar"/>
132
      </classpath>
133
      <link href="${jdk-docs-location}"
134
            offline="true"
135
            packagelistLoc="${nbroot}/openide/api/doc"
136
      />
137
      <link href="${openide-docs-location}"
138
            offline="true"
139
            packagelistLoc="${openide.package-list.loc}"
140
      />
141
    </javadoc>
142
    <zip zipfile="LooksAPIs.zip" basedir="LooksAPIs"/>
143
  </target>
144
145
146
  
147
</project>
(-)openidex/looks/manifest.mf (-10 lines)
Removed Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/looks/Bundle.properties
3
OpenIDE-Module-Specification-Version: 1.1
4
_OpenIDE-Module-IDE-Dependencies: IDE/1 > 1.24
5
OpenIDE-Module: org.netbeans.modules.looks/1
6
OpenIDE-Module-Layer: org/netbeans/modules/looks/mf-layer.xml
7
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
8
OpenIDE-Module-Module-Dependencies: org.netbeans.core.naming/1 > 1.1
9
OpenIDE-Module-Deprecated: true
10
(-)openidex/looks/api/doc/changes/apichanges.xml (-294 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8"?><!-- -*- sgml-indent-step: 2 -*- -->
2
<!--
3
   -                 Sun Public License Notice
4
   - 
5
   - The contents of this file are subject to the Sun Public License
6
   - Version 1.0 (the "License"). You may not use this file except in
7
   - compliance with the License. A copy of the License is available at
8
   - http://www.sun.com/
9
   - 
10
   - The Original Code is NetBeans. The Initial Developer of the Original
11
   - Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
12
   - Microsystems, Inc. All Rights Reserved.
13
  -->
14
<?xml-stylesheet type="text/xml" href="../../../../../openide/api/doc/changes/apichanges.xsl"?>
15
<!DOCTYPE apichanges PUBLIC 
16
	"-//NetBeans//DTD API changes list 1.0//EN" 
17
        "../../../../../openide/api/doc/changes/apichanges.dtd"
18
>
19
20
<!--
21
22
INFO FOR PEOPLE ADDING CHANGES:
23
24
Check the DTD (apichanges.dtd) for details on the syntax. You do not
25
need to regenerate the HTML, this will be done periodically; just
26
change the XML. If you can, validate the XML against the DTD, if not
27
do not worry about it. Rough syntax of a change (several parts optional):
28
29
<change>
30
    <api name="compiler"/>
31
    <summary>Some brief description here, can use <b>XHTML</b></summary>
32
    <version major="1" minor="99"/>
33
    <date day="13" month="6" year="2001"/>
34
    <author login="jrhacker"/>
35
    <compatibility addition="yes"/>
36
    <description>
37
        The main description of the change here.
38
        Again can use full <b>XHTML</b> as needed.
39
    </description>
40
    <class package="org.openide.compiler" name="DoWhatIWantCompiler"/>
41
    <issue number="14309"/>
42
</change>
43
44
Also permitted elements: <package>, <branch>. <version> is API spec
45
version, recommended for all new changes. <compatibility> should say
46
if things were added/modified/deprecated/etc. and give all information
47
related to upgrading old code. List affected top-level classes and
48
link to issue numbers if applicable. See the DTD for more details.
49
50
Changes need not be in any particular order, they are sorted in various
51
ways by the stylesheet anyway.
52
53
Dates are assumed to mean "on the trunk". If you *also* make the same
54
change on a stabilization branch, use the <branch> tag to indicate this
55
and explain why the change was made on a branch in the <description>.
56
57
Please only change this file on the trunk! Rather: you can change it
58
on branches if you want, but these changes will be ignored; only the
59
trunk version of this file is important.
60
61
Deprecations do not count as incompatible, assuming that code using the
62
deprecated calls continues to see their documented behavior. But do
63
specify deprecation="yes" in <compatibility>.
64
65
This file is not a replacement for Javadoc: it is intended to list changes,
66
not describe the complete current behavior, for which ordinary documentation
67
is the proper place.
68
69
-->
70
71
<apichanges>
72
73
  <!-- First, a list of API names you may use: -->
74
  <apidefs>
75
    <!-- org.netbeans.api.looks -->
76
    <apidef name="api">Looks API</apidef>
77
    <!-- org.netbeans.spi.looks -->
78
    <apidef name="spi">Looks SPI</apidef>
79
  </apidefs>
80
81
<!-- ACTUAL CHANGES BEGIN HERE: -->
82
83
  <changes>
84
<!--  
85
  <change id="ErrorManager.getDefault">
86
      <api name="util"/>
87
      <summary>Added accessibility method ErrorManager.getDefault () that always returns non-null values</summary>
88
      <version major="2" minor="1"/>
89
      <date day="17" month="1" year="2002"/>
90
      <author login="jtulach"/>
91
      <compatibility addition="yes" modification="yes" deprecation="yes"/>
92
      <description>
93
        <p>
94
          This method allows independent libraries (nodes, filesystems, utilities) to use the ErrorManager without 
95
          testing if it is really present. Just call <code>ErrorManager.getDefault ()</code> and you can be sure 
96
          that a valid instance will be returned.
97
        </p>
98
        <p>
99
          Also <code>TopManager.getErrorManager</code> is no longer useful (<a
100
          href="#ErrorManager.getDefault">see change</a>) and is now deprecated.
101
          It is also not abstract as it just delegates.
102
          <code>notifyException</code> is similarly deprecated.
103
        </p>
104
      </description>
105
      <class package="org.openide" name="ErrorManager"/>
106
      <issue number="16854"/>
107
  </change>
108
-->  
109
  <change id="Look.getAttachedData">
110
    <api name="api"/>
111
    <summary>Look.getAttachedData added as a convenience method for accessing data attached to a 
112
        <code>NodeSubstitute</code>.
113
    </summary>
114
    <version major="0" minor="2"/>
115
    <author login="sdedic"/>
116
    <compatibility addition="yes"/>
117
    <description>
118
        This method is introduced as a counterpart for <code>Look.createAttachedData</code>, 
119
        it allows a convenient access to the <code>Object</code> returned from that method.
120
        <code>Look</code> subclasses are now advised to use this method to obtain data
121
        returned during initialization from <code>createAttachedData</code>
122
    </description>
123
    <class package="org.netbeans.api.looks" name="Look"/>
124
  </change>
125
  <change id="Look.createAttachedData">
126
    <api name="api"/>
127
    <summary>Look.createAttachedData added as a convenience method for attaching data to a
128
        <code>NodeSubstitute</code>
129
    </summary>
130
    <version major="0" minor="2"/>
131
    <author login="sdedic"/>
132
    <compatibility addition="yes"/>
133
    <description>
134
        The method allows to attach custom data to a <code>NodeSubstitute</code>.
135
        It should be overriden rather than <code>Look.attachTo</code>, which is
136
        declared <code>final</code> in some SPI classes.
137
        Subclasses are advised to override this method to return data to be attachedÿ
138
        to the <code>NodeSubstitute</code>. They may retrieve the data later using
139
        <code>getAttachedData</code>.
140
    </description>
141
    <class package="org.netbeans.api.looks" name="Look"/>
142
  </change>
143
  <change id="Look.attachTo">
144
    <api name="api"/>
145
    <summary>Look.attachTo delegates to <code>createAttachedData</code> in the
146
        default implementation.</summary>
147
    <version major="0" minor="2"/>
148
    <author login="sdedic"/>
149
    <compatibility modification="yes"/>
150
    <description>
151
        For most subclasses, it is now advised to override <code>createAttachedData</code>
152
        rather than <code>attachTo</code>. This method was changed to delegate to
153
        the <code>createAttachedData</code> for convenience.
154
    </description>
155
    <class package="org.netbeans.api.looks" name="Look"/>
156
  </change>
157
  <change id="Look.NodeSubstitute.getAttachedData">
158
    <api name="api"/>
159
    <summary><code>NodeSubstitute.getAttachedData</code> was made package private
160
    </summary>
161
    <version major="0" minor="2"/>
162
    <author login="sdedic"/>
163
    <compatibility modification="yes" source="incompatible" binary="incompatible"/>
164
    <description>
165
        The method was hidden (= package private). Clients are advised to use
166
        <code>Look.getAttachedData</code> instead.
167
    </description>
168
    <class package="org.netbeans.api.looks" name="Look"/>
169
  </change>
170
  <change id="NamespaceLook.namesFor">
171
    <api name="spi"/>
172
    <summary>NamespaceLook.namesFor has now default implementation</summary>
173
    <version major="0" minor="2"/>
174
    <author login="sdedic"/>
175
    <compatibility modification="yes"/>
176
    <description>
177
        A convenient implementation was added, which enumerates object's types
178
        from the runtime type information. This may serve as a basic extensibility
179
        point for Looks.
180
    </description>
181
    <class package="org.netbeans.spi" name="NamespaceLook"/>
182
  </change>
183
  <change id="ProxyLook.ATTACH_TO">
184
    <api name="spi"/>
185
    <summary>ProxyLook.ATTACH_TO constant was removed</summary>
186
    <version major="0" minor="2"/>
187
    <author login="sdedic"/>
188
    <compatibility deletion="yes" binary="compatible" source="incompatible"/>
189
    <description>
190
        ProxyLooks are no longer required nor called to return delegates to
191
        be attached to <code>NodeSubstitute</code>s from their <code>delegateTo</code>
192
        method. This is achieved by another less restrictive means.
193
    </description>
194
    <class package="org.netbeans.spi" name="ProxyLook"/>
195
  </change>
196
  <change id="ProxyLook.delegateTo">
197
    <api name="spi"/>
198
    <summary>ProxyLook.delegateTo can introduce new delegate Looks</summary>
199
    <version major="0" minor="2"/>
200
    <author login="sdedic"/>
201
    <compatibility deletion="yes" binary="compatible" source="incompatible"/>
202
    <description>
203
        Subclass may introduce new delegates in the returned array, even if
204
        the delegates for the particular operation were already asked for. 
205
        Subclasses are advised to maintain the position of returned delegates,
206
        as ProxyLook uses that property to improve CPU performance.
207
    </description>
208
    <class package="org.netbeans.spi" name="ProxyLook"/>
209
  </change>
210
  <!-- Now the surrounding HTML text and document structure: -->
211
  </changes>
212
213
  <htmlcontents>
214
<!--
215
216
                            NO NO NO NO NO!
217
218
         ==============>    DO NOT EDIT ME!  <======================
219
220
          AUTOMATICALLY GENERATED FROM APICHANGES.XML, DO NOT EDIT
221
222
                SEE openidex/looks/api/doc/changes/apichanges.xml
223
224
-->
225
    <head>
226
      <title>Looks API Changes by Date</title>
227
      <link rel="stylesheet" href="http://www.netbeans.org/netbeans.css" type="text/css"/>
228
      <meta name="CATEGORY" content="OtherDevelopmentDoc"/>
229
      <meta name="DESCRIPTION" content="A cross-indexed list of all changes made to the Looks API."/>
230
    </head>
231
    <body>
232
233
<h1>Introduction</h1>
234
235
<p>This document lists changes made to the <a href="http://openidex.netbeans.org/proposals/looks/">Looks
236
API</a>. Please ask on the <code>nbdev@netbeans.org</code> mailing list
237
if you have any questions about the details of a
238
change, or are wondering how to convert existing code to be compatible.</p>
239
240
241
<h2>What do the Dates Mean?</h2>
242
243
<p>The supplied dates indicate when the API change was made, on the CVS
244
trunk. From this you can generally tell whether the change should be
245
present in a given build or not; for trunk builds, simply whether it
246
was made before or after the change; for builds on a stabilization
247
branch, whether the branch was made before or after the given date. In
248
some cases corresponding API changes have been made both in the trunk
249
and in an in-progress stabilization branch, if they were needed for a
250
bug fix; this ought to be marked in this list.</p>
251
252
<ul>
253
254
<li>The <code>release33</code> branch was made on Nov 23 '01 for use in
255
the NetBeans 3.3.1 release, and later for development of Forte for Java (codename Orion).</li>
256
257
</ul>
258
259
<!-- The actual lists of changes, as summaries and details: -->
260
261
      <hr/><h1><a name="list-all-apis">Index of APIs</a></h1>
262
      <changelist style="list-all-apis"/>
263
264
      <h1><a name="incompat-by-date">Incompatible changes by date</a></h1>
265
      <p>Fuller descriptions of all changes can be found below (follow links).</p>
266
      <p>Not all deprecations are listed here, assuming that the deprecated
267
        APIs continue to essentially work. For a full deprecation list, please
268
        consult the
269
        Javadoc.</p>
270
      <changelist style="incompat-by-date"/>
271
272
      <h1><a name="all-by-date">All changes by date</a></h1>
273
      <changelist style="all-by-date"/>
274
275
      <h1><a name="all-by-version">Changes by version</a></h1>
276
      <p>
277
        These API specification versions may be used to indicate that a module
278
        requires a certain API feature in order to function. For example, if you
279
        see here a feature you need which is labelled <samp>1.2</samp>, your
280
        manifest should contain in its main attributes the line:
281
      </p>
282
      <pre>OpenIDE-Module-Module-Dependencies: org.netbeans.modules.looks<!--XXX /1 ?! --> &gt; 1.2</pre>
283
      <changelist style="all-by-version"/>
284
285
      <h1><a name="all-by-class">Changes by affected class</a></h1>
286
      <changelist style="all-by-class"/>
287
288
      <hr/><h1><a name="details-by-api">Details of all changes by API and date</a></h1>
289
      <changelist style="details-by-api"/>
290
291
    </body>
292
  </htmlcontents>
293
294
</apichanges>
(-)openidex/looks/src/org/netbeans/api/looks/BeanLook.java (-56 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
17
18
import org.openide.nodes.*;
19
20
21
import org.netbeans.spi.looks.FilterLook;
22
import org.openide.util.NbBundle;
23
24
/** A bean look to display an object as a JavaBean.
25
 * 
26
 * @author Jaroslav Tulach
27
 */
28
final class BeanLook extends FilterLook {
29
    
30
    /** Creates new NodeProxySupport */
31
    public BeanLook() {
32
        super (Look.NODES);
33
    }
34
    
35
    public String getName () {
36
        return "JavaBeans"; // NOI18N
37
    } 
38
     
39
    /** The human presentable name of the look.
40
     * @return human presentable name
41
     */
42
    public String getDisplayName() {
43
        return NbBundle.getMessage (BeanLook.class, "LAB_JavaBeans");
44
    }    
45
    
46
    /** Replaces each object with its bean node.
47
     */
48
    protected Object delegateObject (NodeSubstitute subst) {
49
        try {
50
            return new BeanNode (subst.getRepresentedObject ());
51
        } catch (java.beans.IntrospectionException ex) {
52
            return ex;
53
        }
54
    }
55
    
56
}
(-)openidex/looks/src/org/netbeans/api/looks/Bundle.properties (-33 lines)
Removed Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
#Name of the Look property sheet.
13
CTL_LookSheetSetName=Look
14
15
#Name of the Look property.
16
CTL_LookProperty=Look
17
18
#Short description of the look property
19
CTL_LookPropertyShortDescription=Sets the look on the node.
20
21
#Name of the Default look.
22
CTL_Default=Default
23
24
25
26
#Name of the SetLook Action
27
ACT_SetLook=View as
28
29
# Names of looks
30
LAB_NodeProxyLook=Nodes
31
LAB_Types=Default
32
LAB_JavaBeans=Java Beans
33
(-)openidex/looks/src/org/netbeans/api/looks/Look.java (-568 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
20
import javax.swing.Action;
21
22
import org.openide.nodes.*;
23
import org.openide.util.HelpCtx;
24
import org.openide.util.datatransfer.NewType;
25
import org.openide.util.datatransfer.PasteType;
26
import org.openide.util.Lookup;
27
28
import java.lang.ref.WeakReference;
29
import java.util.Enumeration;
30
import org.openide.util.enum.AlterEnumeration;
31
import org.openide.util.enum.FilterEnumeration;
32
import java.util.NoSuchElementException;
33
34
/** Base class for all looks. This class handles basic reading of properties
35
 * from XML description.
36
 * <P>
37
 * Notice the difference between the methods which take the parameter of
38
 * type NodeSubstitute and the methods which don't. The first methods are
39
 * those which implement the functionality of the look. The second are methods 
40
 * which represent properties of the Look itself.
41
 * <P>
42
 *
43
 * @author Petr Hrebejk
44
 */
45
public abstract class Look implements Node.Cookie, java.io.Serializable {
46
    /** Look that works with <link>Node</link>. If the represented object
47
     * is <code>Node</code> the look takes its name, actions, properties, etc.
48
     * Very useful for bridging to already written nodes.
49
     */
50
    public static final Look NODES = new NodeProxyLook ();
51
    
52
    /** Look that finds the correct look by the type of the 
53
     * represented object. It searches naming space of "Looks/Types/"
54
     * @see NamespaceLook
55
     */
56
    public static final Look DEFAULT = new TypesLook ();
57
    
58
    /** Look that presents an object as a JavaBean. Uses java.beans.Introspector
59
     * to get the properties and delegates to the object all other methods.
60
     */
61
    public static final Look BEANS = new BeanLook ();
62
    
63
    /** lock to synchronize access to substitute variable.
64
     */
65
    private static final String NLOCK = "NLock";
66
    
67
    /** reference to the NodeSubstitute link list. Lists all substitutes this
68
     * look is attached to.
69
     */
70
    private NLink substitutes;
71
    
72
    // Methods of look itself --------------------------------------------------
73
74
    /** Returns name of the look. This name should identify the look.
75
     * @return Name of the look.
76
     */
77
    public abstract String getName();
78
    
79
    /** The human presentable name of the look. 
80
     * @return human presentable name
81
     */
82
    public abstract String getDisplayName ();
83
    
84
    // General methods ---------------------------------------------------------
85
    
86
    /** 
87
     * Called on the current look when node is newly created or the look is
88
     * set on the Node. Overriding this 
89
     * method allows to register listners on represented objects and asociate
90
     * them with the node.
91
     * <p>
92
     * Implementors may not wait for any other threads at it may be potentially called
93
     * from LookNode's lock.
94
     * <P>
95
     * The look can return an instance of any object in order to store its 
96
     * own data with the substitute. The data can then be obtained by calling
97
     * <link>Look.NodeSubstitute.getAttachedData</link>. 
98
     * 
99
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the which was created.
100
     * @return the object that contains data of the look associated with the
101
     *      substitute or <code>null</code> if no such data are needed
102
     */ 
103
    protected Object attachTo( Look.NodeSubstitute substitute ) {
104
        return createAttachedData(substitute);
105
    }
106
107
    /**
108
     * This method is called during the process of attaching a Look to a 
109
     * <link>NodeSubstitute</link>. Subclasses can override this method to attach
110
     * custom data to the NodeSubstitute instance so they can retrieve it
111
     * later.<BR>
112
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the which was created.
113
     * @return the object that contains data of the look associated with the
114
     *      substitute or <code>null</code> if no such data are needed
115
     */
116
    protected Object createAttachedData(Look.NodeSubstitute subst) {
117
        return null;
118
    }
119
    
120
    /**
121
     * Retrieves the data, previously attached to the <link>NodeSubstitute</link>.
122
     * The method returns null, if this Look is no longer selected one for the 
123
     * <code>NodeSubstitute</code> or <link>createAttachedData</link> returned
124
     * null.
125
     * @see #createAttachedData
126
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
127
     * @return The instance previously returned from <link>createAttachedData</link>
128
     * or null if there was no data, or the Look is not selected on the <code>Node</code>
129
     */
130
    protected Object getAttachedData(Look.NodeSubstitute subst) {
131
        if (subst == null)
132
            return null;
133
        return subst.getAttachedData(this);
134
    }
135
    
136
    /** Creates lookup object with additional "cookies" for the LookNode using
137
     * the provided node substitute. The LookNode attaches calls this method just
138
     * once and attaches listener to the returned lookup so all changes in it
139
     * will result in PROP_COOKIE change in the LookNode.
140
     *
141
     *
142
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
143
     * @return the lookup to be used by the LookNode or null if no additional cookies are
144
     *      provided
145
     */
146
    public abstract Lookup createLookup (Look.NodeSubstitute substitute);
147
    
148
    /** A list of possible looks this look can be replaced with.
149
     * This list depends on the look itself and should contain looks 
150
     * a user might find meaningful to use instead of this one.
151
     *
152
     * @param substitute substitute to find modes for
153
     * @return the array of looks or null if the no switching is available
154
     */
155
    public abstract Look[] availableLooks ( Look.NodeSubstitute substitute );
156
    
157
    // Methods for STYLE -------------------------------------------------------
158
    
159
    /** Gets localized name of given Node. This name will be showed in the 
160
     * visual representation of the node. 
161
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
162
     * @return Localized name of the node. Implementation of {@link LookNode} 
163
     *         defaults this to the programmatic name of the node.
164
     */
165
    public abstract String getDisplayName( Look.NodeSubstitute substitute );
166
    
167
    /** Gets the progammatic name of given node. This name can be used for 
168
     * operations on node paths in the node hierarchy and thus shouldn't be
169
     * localized.
170
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
171
     * @return Programmatic name of the node. 
172
     */
173
    public abstract String getName( Look.NodeSubstitute substitute );
174
    
175
    /** This method is clalled when the user renames the node using inplace
176
     * editing in the view.
177
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the renamed node.
178
     * @param newName The new name set by the user.
179
     */
180
    public abstract void setName( Look.NodeSubstitute substitute, String newName );
181
    
182
    /** Gets short description of given node. The short description is usually
183
     * visualized as a tooltip, but may have another forms as well.
184
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
185
     * @return A localized short description associated with the node. 
186
     *         Implementation of {@link LookNode} defaults this to display name 
187
     *         of the node.
188
     */
189
    public abstract String getShortDescription( Look.NodeSubstitute substitute );
190
    
191
    /** Find an icon for this node (in the closed state).
192
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
193
     * @param type Constant from {@link java.beans.BeanInfo}
194
     * @return Icon to use to represent the node in the closed state. 
195
     *         Implementation of {@link LookNode} provides default icon for nodes.
196
     */
197
    public abstract Image getIcon( Look.NodeSubstitute substitute, int type );
198
    
199
    /** Find an icon for this node (in the open state).
200
     * This icon is used when the node may have children and is expanded.
201
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
202
     * @param type Constant from {@link java.beans.BeanInfo}
203
     * @return Icon to use to represent the node in the open state. 
204
     *        Implementation of {@link LookNode} defaults this to the closed
205
     *        state icon.
206
     */
207
    public abstract Image getOpenedIcon( Look.NodeSubstitute substitute, int type );
208
    
209
    /** Get context help associated with this node.
210
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
211
     * @return The context help object (could be <code>null</code> or 
212
     *         {@link HelpCtx#DEFAULT_HELP}) 
213
     */
214
    public abstract HelpCtx getHelpCtx( Look.NodeSubstitute substitute );
215
    
216
    // Methods for CHILDREN ----------------------------------------------------
217
    
218
    /** Gets objects which are children of object represented by the node in the
219
     * hierarchy represented by this Look.
220
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
221
     * @return Array of objects which should be represend as node children of 
222
     *         the node, can return <code>null</code> that is equivalant to empty array
223
     */
224
    public abstract Object[] getChildObjects( Look.NodeSubstitute substitute );
225
    
226
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
227
    
228
    /** Get the new types that can be created in given node.
229
     * For example, a node representing a Java package will permit classes to 
230
     * be added.
231
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
232
     * @return Array of new type operations that are allowed,
233
     *     can return <code>null</code> that is equivalant to empty array
234
     */
235
    public abstract NewType[] getNewTypes( Look.NodeSubstitute substitute );
236
    
237
    /** Get the set of actions associated with the node.
238
     * This may be used e.g. in constructing a {@link #getContextMenu context menu}.
239
     * <P>
240
     * If the look returns null, the implementation {@ling LookNode} returns 
241
     * the actions in {@link NodeOp#getDefaultActions} obtained by the super call.
242
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
243
     * @return Array of the Actions applicable to the node or <CODE>null</CODE>
244
     *         if actions in {@link NodeOp#getDefaultActions} should be used.
245
     */
246
    public abstract Action[] getActions( Look.NodeSubstitute substitute );
247
    
248
    /** Get a special set of actions for situations when this node is displayed 
249
     * as a context.
250
     * @see org.openide.nodes.Node#getContextActions For more detailed description.
251
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the The node to operate on.
252
     * @return Actions for a context. In the LookNode implementation, 
253
     *        same as {@link #getActions}.
254
     * 
255
     */
256
    public abstract Action[] getContextActions( Look.NodeSubstitute substitute );
257
    
258
    /** Get the default action for this node.
259
     * This action can but need not be one from the list returned
260
     * from {@link #getActions}. If so, the popup menu returned from 
261
     * {@link #getContextMenu} is encouraged to highlight the action.
262
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
263
     * @return Default action, or <code>null</code> if there should be none.
264
     */
265
    public abstract Action getDefaultAction( Look.NodeSubstitute substitute );
266
    
267
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
268
    
269
    /** Get the list of property sets for given node. E.g. typically there 
270
     * may be one for normal Bean properties, one for expert
271
     * properties, and one for hidden properties.
272
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the The node to operate on.
273
     * @return Property sets for the node, can return <code>null</code> that is equivalant to empty array
274
     */
275
    public abstract Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute );
276
    
277
    /** Is the customizer for represented object available? If so, the method
278
     * getCustomizer should return non-null value.
279
     *
280
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
281
     * @return true if the customizer is available, false otherwise
282
     */
283
    public abstract boolean hasCustomizer( Look.NodeSubstitute substitute );
284
    
285
    /** Get the customizer for represented object if available.
286
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
287
     * @return The component, or <CODE>null</CODE> if there is no customizer. 
288
     */
289
    public abstract java.awt.Component getCustomizer( Look.NodeSubstitute substitute );
290
    
291
    // public boolean hasCustomizer (); Not necesary
292
    
293
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
294
    
295
    /** Test whether this node can be renamed.
296
     * If true, {@link #setName} will be called when the user changes the name
297
     * of the node.
298
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
299
     * @return <code>true</code> if the node can be renamed.
300
     */
301
    public abstract boolean canRename( Look.NodeSubstitute substitute );
302
    
303
    /** Test whether this node can be deleted.
304
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
305
     * @return <CODE>True</CODE> if can be deleted.
306
     */
307
    public abstract boolean canDestroy( Look.NodeSubstitute substitute );
308
    
309
    /** Test whether this node permits copying.
310
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
311
     * @return <code>True</code> if so.
312
     */
313
    public abstract boolean canCopy( Look.NodeSubstitute substitute );
314
    
315
    /** Test whether this node permits cutting.
316
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
317
     * @return <code>True</code> if so.
318
     */
319
    public abstract boolean canCut( Look.NodeSubstitute substitute );
320
    
321
    /** Determine which paste operations are allowed when a given 
322
     * transferable is in the clipboard. For example, a node representing a 
323
     * Java package will permit classes to be pasted into it.
324
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
325
     * @param t The transferable in the clipboard.
326
     * @return Array of operations that are allowed, can return <code>null</code> that is equivalant to empty array
327
     */
328
    public abstract PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t);
329
    
330
    /** Determine if there is a paste operation that can be performed
331
     * on provided transferable. Used by drag'n'drop code to check
332
     * whether the drop is possible.
333
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
334
     * @param t The transferable.
335
     * @param action The drag'n'drop action to do DnDConstants.ACTION_MOVE, 
336
     *        ACTION_COPY, ACTION_LINK.
337
     * @param index Index between children the drop occured at or -1 if not specified.
338
     * @return <CODE>Null</CODE> if the transferable cannot be accepted or the paste type
339
     *         to execute when the drop occures.
340
     */
341
    public abstract PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index);
342
    
343
    /** Called when a node is to be copied to the clipboard.
344
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node Copy was invoked on.
345
     * @return The transferable object representing the content of the clipboard.
346
     * @throws IOException When the copy cannot be performed.
347
     */
348
    public abstract Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException;
349
    
350
    /** Called when the node is to be cut to the clipboard.
351
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to be cutted.
352
     * @return The transferable object representing the content of the clipboard.
353
     * @throws IOException When the copy cannot be performed.
354
     */
355
    public abstract Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException;
356
    
357
    /** Called when a drag is started with this node.
358
     * The node can attach a transfer listener to ExTransferable and
359
     * will be then notified about progress of the drag (accept/reject).
360
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node which was dragged.
361
     * @return Transferable to represent this node during a drag.
362
     * @throws IOException If a drag cannot be started.
363
     */
364
    public abstract Transferable drag( Look.NodeSubstitute substitute ) throws IOException;
365
    
366
    /** Called when node was destroyed.
367
     * @param substitute Look.NodeSubstitute of the destroyed ndoe.
368
     */
369
    public abstract void destroy( Look.NodeSubstitute substitute ) throws IOException;
370
    
371
    /** List of all NodeSubstitutes that use this look. Is useful when the look
372
     * changes some of its properties and needs to update all substitutes.
373
     *
374
     * @return enumeration of NodeSubstitute
375
     */
376
    protected final Enumeration nodeSubstitutes () {
377
        Enumeration en = new Enumeration () {
378
            private NLink current = substitutes;
379
            
380
            public boolean hasMoreElements () {
381
                return current != null;
382
            }
383
            
384
            public Object nextElement () {
385
                synchronized (NLOCK) {
386
                    if (current == null) {
387
                        throw new NoSuchElementException ();
388
                    }
389
                    
390
                    Object o = current;
391
                    current = current.next;
392
                    return o;
393
                }
394
            }
395
        };
396
        
397
        AlterEnumeration alt = new AlterEnumeration (en) {
398
            private NLink previous;
399
            
400
            public Object alter (Object o) {
401
                NLink n = (NLink)o;
402
                if (n == null) {
403
                    return null;
404
                }
405
406
                synchronized (NLOCK) {
407
                    NodeSubstitute subst = (NodeSubstitute)n.get ();
408
                    if (subst == null || subst.getLook () != Look.this) {
409
                        // need to exclude this object from the list
410
                
411
                        if (previous == null) {
412
                            // we need to change looks first substitute
413
                            Look.this.substitutes = n.next;
414
                        } else {
415
                            // need to skip this one from the previous 
416
                            previous.next = n.next;
417
                        }
418
                        
419
                        // anyway we will not accept the object
420
                        return null;
421
                    }
422
                    
423
                    return subst;
424
                }
425
            }
426
        };
427
        
428
        // exclude nulls
429
        return new FilterEnumeration (alt);
430
    }
431
    
432
    
433
    // Innerclasses ------------------------------------------------------------
434
    
435
    /** Class passed to the Look methods as parameter. Each LookNode contains 
436
     * exactly one instance of this class. Metods of the class allow access
437
     * to the properties and methods od the node needed for the Look.
438
     * @version 0.2
439
     */
440
    public static abstract class NodeSubstitute {
441
        /** the look this substitute is attached to or null */
442
        private Look look;
443
        /** data of the look attached to this substitute */
444
        private Object data;
445
        
446
        /** Attaches the substitute to a provided look. Does nothing if
447
         * the previously attached look is the same as the provided one.
448
         * If it is different, the substitute is detached from a look and
449
         * attached to the new one.
450
         *
451
         * <P>
452
         * Method attachTo is called on the look to let it know about this
453
         * substitute and to let it store additional data <link>getAttachedData</link>
454
         * with this NodeSubstitute.
455
         *
456
         * @param look look to attach to or null if we should detach
457
         */
458
        protected final void attachTo (Look look) {
459
            synchronized (NLOCK) {
460
                if (look == this.look) {
461
                    // ok no change
462
                    return;
463
                }
464
465
                this.look = look;
466
                if (look == null) {
467
                    // clear all values
468
                    data = null;
469
                    return;
470
                }
471
                
472
                
473
                NLink l = look.substitutes;
474
                look.substitutes = new NLink (this, l);
475
476
                this.data = look.attachTo (this);
477
            }
478
        }
479
        
480
        /** Access to the look this substitute is attached to.
481
         * @return the look we are attached to or null if not attached at all
482
         */
483
        public final Look getLook () {
484
            return look;
485
        }
486
        
487
        
488
        /** Fire a property change event on the associated node.
489
         * @param name name of changed property (from {@link #getPropertySets})
490
         * @param o old value
491
         * @param n new value
492
         */
493
        abstract public void firePropertyChange( String name, Object o, Object n );
494
495
        /** Fires the Event notificationg about name change.
496
         */
497
        abstract public void fireNameChange( String o, String n ); 
498
        
499
        /** Fires the Event notificationg about display name change.
500
         */
501
        abstract public void fireDisplayNameChange( String o, String n );
502
        
503
        /** Fires the Event notificationg about short description change.
504
         */
505
        abstract public void fireShortDescriptionChange(String o, String n); 
506
507
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
508
         * associated node.
509
         */
510
        abstract public void fireIconChange();
511
512
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
513
         * associated node.
514
         */
515
        abstract public void fireOpenedIconChange(); 
516
517
        /** Fires a (Bean) property change event (for 
518
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
519
         * @param o the old set
520
         * @param n the new set
521
         */
522
        abstract public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n );
523
       
524
        /** To all node listeners fire node destroyed notification.
525
         */
526
        abstract public void fireNodeDestroyed();
527
528
        /** Tells the node that the children have to be refreshed.
529
         */
530
        abstract public void refreshChildren(); 
531
        
532
        
533
        //
534
        // Informations for the Look
535
        //
536
        
537
        /** Returns the object represented by the node
538
         * @return Object represented by the node this interior belongs to.
539
         */
540
        public abstract Object getRepresentedObject(); 
541
        
542
        /** Returns the data associated with the substitute by the Look
543
         * Made package-private from version 0.2. Use <link>Look.getAttachedData</link>
544
         * instead.
545
         * @see Look.createAttachedData
546
         * @return the object provided by <code>Look.createAttachedData</code>
547
         */
548
        final Object getAttachedData(Look look) {
549
            synchronized (NLOCK) {
550
                if (getLook() != look)
551
                    return null;
552
            }
553
            return data;
554
        }
555
    } // end of NodeSubstitute
556
557
    /** NodeSubstitute linked list with weak references.
558
     */
559
    private static final class NLink extends WeakReference {
560
        /** link to next NLink or null */
561
        public NLink next;
562
        
563
        public NLink (NodeSubstitute substitute, NLink next) {
564
            super (substitute);
565
            this.next = next;
566
        }
567
    } // end of NLink
568
}
(-)openidex/looks/src/org/netbeans/api/looks/LookChildren.java (-95 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.util.*;
17
18
import org.openide.nodes.*;
19
20
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
21
 * Please don't use this API for other purposes than testing.
22
 * <P>
23
 * Temporary implementation of Children of a LookNode. The class contains
24
 * only code wich is necessary for testing looks and may be extended later.
25
 *
26
 * @author Petr Hrebejk
27
 */
28
final class LookChildren extends Children.Keys {
29
    /** Use this constant for returning empty KeySets. */
30
    private static final Object[] NO_KEYS = {};
31
    
32
    /** @param brutal needs clean */
33
    void refreshChildren( boolean brutal ) {            
34
        if (brutal) {
35
            setKeys (Collections.EMPTY_LIST);
36
        }
37
        
38
        final Object[] keys = getKeys();
39
        MUTEX.postWriteRequest(new Runnable() {
40
            public void run() {
41
                setKeys( keys );
42
            }
43
        });
44
    }
45
    
46
    protected void addNotify() {
47
        setKeys( getKeys() );
48
    }
49
    
50
    protected void removeNotify() {
51
        setKeys( Collections.EMPTY_LIST );
52
    }
53
    
54
    protected Node[] createNodes( Object key ) {
55
        if (key == null) return new Node[0];
56
        
57
        Node n = getNode ();
58
        if (! (n instanceof LookNode)) {
59
            Look l = (Look)n.getCookie (Look.class);
60
            
61
            if (l == null) {
62
                l = Look.DEFAULT;
63
            }
64
            
65
            return new Node[] { new LookNode (key, l) };
66
        }
67
        
68
        LookNode ln = (LookNode)n;
69
        LookNode node = new LookNode (key, ln.getBaseLook ());
70
71
        // is not there a better look?
72
        Look l = ln.findLookForChild (node);
73
        if (l != null && node.getLook () != l) {
74
            node.setLook (l);
75
        }
76
        
77
        return new Node[] { node };
78
    }
79
    
80
    
81
    // Private methods ---------------------------------------------------------
82
    
83
    private Object[] getKeys() {
84
        
85
        Object[] keys = ((LookNode)getNode ()).getChildObjects ();
86
        if ( keys == null ) {
87
            return NO_KEYS;
88
        }
89
        else {
90
            return keys;
91
        }
92
        
93
    }
94
        
95
}
(-)openidex/looks/src/org/netbeans/api/looks/LookNode.java (-925 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.beans.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.io.IOException;
20
import java.util.Map;
21
import javax.swing.Action;
22
23
import org.openide.nodes.*;
24
25
import org.openide.util.HelpCtx;
26
import org.openide.util.Utilities;
27
import org.openide.util.actions.SystemAction;
28
import org.openide.util.datatransfer.NewType;
29
import org.openide.util.datatransfer.PasteType;
30
import org.openide.util.Lookup;
31
import org.openide.util.LookupEvent;
32
import org.openide.util.LookupListener;
33
import org.openide.util.Mutex;
34
import org.openide.util.MutexException;
35
import java.util.HashMap;
36
import java.util.Iterator;
37
38
import org.netbeans.spi.looks.ProxyLook;
39
40
/** 
41
 * Node that represents an object using Looks.
42
 *
43
 * @author Petr Hrebejk
44
 */
45
public final class LookNode extends Node implements Node.Cookie {
46
    /** it is our private lock changes of delegates for given nodes */
47
    private final Mutex MUTEX = new Mutex ();
48
    
49
    /** Use this constant for returning no Actions. */
50
    private static final SystemAction[] NO_SYSTEM_ACTIONS = {};
51
    
52
    /** Use this constant for returning empty NewTypes. */
53
    private static final NewType[] NO_NEW_TYPES = {};
54
    
55
    /** Use this constant for returning empty PasteTypes. */
56
    private static final PasteType[] NO_PASTE_TYPES = {};
57
    
58
    /** Use this constant for returning empty PropertySets. */
59
    private static final Node.PropertySet[] NO_PROPERTY_SETS = {};
60
61
    /** Name of the default icon 16x16 */
62
    private static final String DEFAULT_ICON_16_NAME = 
63
        "org/netbeans/modules/looks/resources/defaultNode.gif"; // NOI18N
64
65
    /** Name of the default icon 32x32 */
66
    private static final String DEFAULT_ICON_32_NAME = 
67
        "org/netbeans/modules/looks/resources/defaultNode32.gif"; //NOI18N
68
    
69
    /** Maximum of looks that is kept in memory. This should not be
70
     * infihite, but it also should be adjusted to the user experience -
71
     * how many selections are important to the user!?
72
     */
73
    private static final int MAX_MEMORY = 30;
74
    
75
    /** the base look associated with this node */
76
    private Look base;
77
    
78
    /** the actual look associated with this node */
79
    private Look look;
80
    
81
    /** Object represented (delegeted) by interior */
82
    private SubstituteImpl substitute;
83
    
84
    /** represented object */
85
    private Object representedObject;
86
    
87
    /** mapping from names of nodes to names of looks. Each node can have
88
     * such mapping - it will influence the persistence of selected objects
89
     *
90
     * Map with <String, String>
91
     */
92
    private Map map;
93
    
94
    /** Creates new LookNode with <link>Look.DEFAULT</link> as associated look.
95
     *
96
     * @param representedObject The object which the node will represent.
97
     */
98
    public LookNode( Object representedObject ) {
99
        this (representedObject, Look.DEFAULT);
100
    }
101
    
102
    /** Creates new LookNode.
103
     * @param representedObject The object which the node will represent.
104
     * @param look explicit look that will be set
105
     */
106
    public LookNode( Object representedObject, Look look) {
107
        this (representedObject, look, look);
108
    }
109
    
110
    /** Creates new LookNode.
111
     * @param representedObject The object which the node will represent.
112
     * @param base the base look to use
113
     * @param look explicit look that will be set 
114
     */
115
    /*public*/ LookNode (Object representedObject, Look base, Look look) {
116
        super (new LookChildren ());
117
        
118
        this.base = base;
119
        this.look = look;
120
        
121
        this.representedObject = representedObject;
122
123
        // Create the interior
124
        substitute = new SubstituteImpl(this, look);
125
    }
126
127
    
128
    // Additional methods for LookNode -----------------------------------------
129
       
130
    /** Used to get Substitute of this LookNode
131
     * @return NodeSubstitute
132
     */
133
    final SubstituteImpl getSubstitute(){
134
        return (SubstituteImpl) MUTEX.readAccess (new Mutex.Action () {
135
            public Object run () {
136
                return substitute;
137
            }
138
        });
139
    }
140
141
    final Object[] getChildObjects() {
142
        return (Object []) MUTEX.readAccess (new Operation (ProxyLook.GET_CHILD_OBJECTS));
143
    }
144
    
145
    /** Returns represented object which this LookNode represents.
146
     * @return The object represented by this node.
147
     */
148
    public Object getRepresentedObject() {
149
        return representedObject;
150
    }
151
    
152
    /** Sets the actual look for this node. After changing the Look several property
153
     * changes are fired:
154
     * <CODE>PROP_COOKIE, PROP_NAME, PROP_NAME, PROP_DISPLAY_NAME, PROP_ICON,
155
     * PROP_OPENED_ICON</CODE> and children are refresehed.
156
     * @look New look of the node.
157
     */
158
    public void setLook( final Look look ) {        
159
        String name = look.getName ();
160
        
161
        MUTEX.writeAccess (new Runnable () {
162
            public void run () {
163
                LookNode.this.look = look; // new current look
164
165
                substitute.clean (); // not used anymore
166
                SubstituteImpl newsubst = new SubstituteImpl (LookNode.this, look);
167
168
                substitute = newsubst;
169
170
                // commented out as hotfix of #24424
171
                //recordLook (this, base, name);
172
            }
173
        });
174
        // fire possible change notifications
175
        
176
        fireCookieChange();
177
        refreshChildren(true);
178
        fireNameChange( null, null );
179
        fireDisplayNameChange( null, null );
180
        fireIconChange();
181
        fireOpenedIconChange();
182
    }
183
184
    /** Refreshes children on the node */
185
    void refreshChildren(boolean brutal) {
186
        ((LookChildren)getChildren()).refreshChildren(brutal);
187
    }
188
    
189
    // methods to track the state of the tree
190
    
191
    /** Stores the name of the selected look.
192
     * @param node node to store the name for
193
     * @param nameLook look that should be used to create node's names
194
     * @param look the name of the look
195
     */
196
    private static void recordLook (LookNode node, Look nameLook, String look) {
197
        StringBuffer buf = new StringBuffer (512);
198
        
199
        for (;;) {
200
            Node parent = node.getParentNode();
201
            if (parent == null) break;
202
            
203
            parent = (LookNode)parent.getCookie (LookNode.class);
204
            if (parent == null) break;
205
            
206
            node = (LookNode)parent;
207
            buf.insert (0, nameLook.getName (node.getSubstitute ()));
208
        }
209
        
210
        synchronized (node) {
211
            if (node.map == null) {
212
                node.map = new HashMap ();
213
            }
214
            
215
            if (node.map.size () > MAX_MEMORY) {
216
217
                int rand = (int)(Math.random() * MAX_MEMORY);
218
                
219
                Iterator it = node.map.entrySet ().iterator();
220
                while (rand-- > 0) {
221
                    it.next ();
222
                }
223
                it.remove();
224
            }
225
            
226
            node.map.put (buf.toString ().intern(), look);
227
        }
228
    }
229
    
230
    
231
    /** Finds proposed look in storage (if any) for this node.
232
     * @return name of suggested look for our current state or null
233
     */
234
    Look findLookForChild (LookNode child) {
235
        String name = child.getName ();
236
        LookNode node = this;
237
        
238
        StringBuffer buf = new StringBuffer (512);
239
        buf.append (name);
240
        
241
        for (;;) {
242
            if (node == null) {
243
                return null;
244
            }
245
            
246
            if (node.map != null) {
247
                name = (String)node.map.get (buf.toString ());
248
                
249
                if (name != null) {
250
                    // found a name now find the look
251
                    return child.lookByName (child.getBaseLook(), name);
252
                }
253
                
254
            }
255
            
256
            buf.insert (0, node.getName ());
257
            
258
            
259
            Node p = node.getParentNode ();
260
            if (p == null) {
261
                break;
262
            }
263
            
264
            node = (LookNode)p.getCookie(LookNode.class);
265
            if (node == null) {
266
                return null;
267
            }
268
        }
269
        
270
        return null;
271
    }
272
    
273
    /** Finds a look by name.
274
     * @param look the look to search in
275
     * @param name name to find
276
     * @return the look or null
277
     */
278
    private final Look lookByName (Look base, String name) {
279
        if (name.equals (base.getName ())) {
280
            return base;
281
        }
282
        
283
        Look[] arr = base.availableLooks (getSubstitute ());
284
        for (int i = 0; i < arr.length; i++) {
285
            base = lookByName (arr[i], name);
286
            if (base != null) {
287
                return base;
288
            }
289
        }
290
        return null;
291
    }
292
        
293
    // General methods ---------------------------------------------------------
294
    
295
    /** 
296
     * Gets the actual look set on this node. 
297
     * @return Look set on this Node
298
     * 
299
     */
300
    public Look getLook() {
301
        return look;
302
    }
303
    
304
    /** Getter for the base look.
305
     */
306
    final Look getBaseLook () {
307
        return base;
308
    }
309
310
    /** Gets Cookie of given type. The set of Cookies is determined by the
311
     * Look. Look of the node can allways be asked using <CODE>getCookie( 
312
     * Look.class )</CODE> and the LookNode self can be asked by 
313
     * <CODE>getCookie( LookNode.class )</CODE>.
314
     * @param type the representation class of the cookie
315
     * @return a cookie assignable to that class, or <code>null</code> 
316
     * the Look does not provide such cookie.
317
     */
318
    public Node.Cookie getCookie (Class type) {
319
        if ( type == Look.class ) {
320
            // Look is available in cookies
321
            return getLook();
322
        } else if ( type == LookNode.class ) {
323
            return this;
324
        } else {            
325
            // Ask the Looks for additional cookies
326
            Object c = getSubstitute ().getCookie (type);
327
328
            return c instanceof Node.Cookie ? (Node.Cookie)c : null;
329
        }
330
    }
331
332
    /** Determines Handle by querying the Look.
333
     * @return the handle, or <code>null</code> if this node is not persistable
334
     */
335
    public Node.Handle getHandle() {
336
        if (map != null) {
337
            return new H (map, getRepresentedObject ());
338
        } else {
339
            return DefaultHandle.createHandle (this);
340
        }
341
    }
342
    
343
    /** 
344
     * Returns a node representing the same object as the original node. Looks
345
     * passed in constructor and in setLook method are copied as well.
346
     *
347
     * @return LookNode representing the same object.
348
     */
349
    public Node cloneNode () {
350
        return new LookNode( getRepresentedObject(), base, look); 
351
    }
352
353
    
354
    // Methods for STYLE -------------------------------------------------------
355
    
356
    /** Determines displayName by querying the Look.
357
     * @return DisplayName provided by the Look or result 
358
     * of {@link #getName()}.
359
     */
360
    public String getDisplayName() {
361
        return (String) MUTEX.readAccess (new Mutex.Action () {
362
            public Object run () {
363
                String  displayName = getLook().getDisplayName( substitute );
364
365
                if ( displayName == null ) {
366
                    return getName();
367
                } else {
368
                    return displayName;
369
                }
370
            }
371
        });
372
    }
373
    
374
    /** Empty method, setting <CODE>displayName</CODE> on the 
375
     * <CODE>LookNode</CODE> has no efect. The <CODE>displayName</CODE> should
376
     * be determined by associated <CODE>Look</CODE>.
377
     * @param name Parameter is ignored. 
378
     */
379
    public void setDisplayName( String name ) {
380
    }
381
    
382
    /** Determines name by querying the Look.
383
     * @return Name provided by the Look or <CODE>null</CODE>.
384
     */
385
    public String getName() {
386
        return (String) MUTEX.readAccess (new Operation (ProxyLook.GET_NAME));
387
    }
388
    
389
    /** Invoking this method on LookNode invokes method {@link Look#setName( 
390
     * Look.NodeSubstitute, String )}. Look is responsible for handling the call.
391
     */
392
    public void setName( String s ) {
393
        MUTEX.readAccess (new Operation (ProxyLook.SET_NAME, s));
394
    }
395
    
396
    /** Empty method, setting <CODE>shortDescription</CODE> on the 
397
     * <CODE>LookNode</CODE> has no efect. The <CODE>shortDescription</CODE> 
398
     * should be determined by associated <CODE>Look</CODE>.
399
     * @param shortDescription Parameter is ignored.
400
     */
401
    public void setShortDescription( String shortDescription ) {
402
    }
403
    
404
    /** Determines shortDescription by querying the Look.
405
     * @return Name provided by the Look or result of {@link getDisplayName()}.
406
     */
407
    public String getShortDescription() {
408
        return (String) MUTEX.readAccess (new Mutex.Action () {
409
            public Object run () {
410
                String shortDescription = getLook().getShortDescription( substitute );
411
412
                if ( shortDescription == null ) {
413
                    return getDisplayName();
414
                } else {
415
                    return shortDescription;
416
                }
417
            }
418
        });
419
    }
420
    
421
    /** Determines icon for closed state by querying the Look.
422
     * @return Icon provided by the Look 
423
     */
424
    public Image getIcon( int type ) {
425
        Image icon = (Image) MUTEX.readAccess (new Operation (ProxyLook.GET_ICON, new Integer (type)));
426
        
427
        if ( icon == null ) {
428
            if ( type == BeanInfo.ICON_COLOR_32x32 || type == BeanInfo.ICON_MONO_32x32 ) {
429
                return Utilities.loadImage( DEFAULT_ICON_32_NAME );
430
            }
431
            return Utilities.loadImage( DEFAULT_ICON_16_NAME );
432
        }
433
        else {
434
            return icon;
435
        }
436
    }
437
    
438
    /** Determines icon for opened state by querying the Look.
439
     * @return Icon provided by the Look or the result of
440
     * {@link getIcon()}.
441
     */
442
    public Image getOpenedIcon( final int type ) {
443
        return (Image) MUTEX.readAccess (new Mutex.Action () {
444
            public Object run () {
445
                Image icon = getLook().getOpenedIcon( substitute, type );
446
447
                if ( icon == null ) {
448
                    return getIcon( type );
449
                } else {
450
                    return icon;
451
                }
452
            }
453
        });
454
    }
455
    
456
    /** Determines HelpCtx for opened state by querying the Look.
457
     * @return HelpCtx provided by the Look.
458
     */
459
    public HelpCtx getHelpCtx () {
460
        return (HelpCtx) MUTEX.readAccess (new Operation (ProxyLook.GET_HELP_CTX));
461
    }
462
    
463
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
464
    
465
    /** Determines NewTypes for opened state by querying the Look.
466
     * @return NewTypes provided by the Look.
467
     */
468
    public NewType[] getNewTypes() {
469
        NewType arr [] = (NewType []) MUTEX.readAccess (new Operation (ProxyLook.GET_NEW_TYPES));
470
        return arr == null ? NO_NEW_TYPES : arr;
471
    }
472
    
473
    public SystemAction[] getActions() {
474
        return toSA (getCommands ());
475
    }
476
    
477
    /** Implementation of the getActions command with the expected signature
478
     * of a method that will be used in future
479
     *
480
     * @return the actions supported by this node
481
     */
482
    private Action[] getCommands () {
483
        Action[] systemActions;
484
        Action[] mergedActions;
485
486
        systemActions = (Action[]) MUTEX.readAccess (new Operation (ProxyLook.GET_ACTIONS));
487
        
488
        if (systemActions == null) {
489
            systemActions = super.getActions();
490
        }
491
        
492
        int actlen = systemActions.length;
493
        mergedActions = new Action[actlen + 2];
494
        System.arraycopy( systemActions, 0, mergedActions, 0, actlen );
495
        Action sla = LookProperties.getSetLookAction ();
496
        
497
        System.arraycopy( new Action[]{
498
         null,
499
         sla
500
        }, 0, mergedActions, actlen, 2 );
501
        
502
        return mergedActions;
503
504
    }
505
    
506
    
507
    public SystemAction [] getContextActions() {
508
        Action[] arr = (Action[]) MUTEX.readAccess (new Operation (ProxyLook.GET_CONTEXT_ACTIONS));
509
        return arr != null ? toSA (arr) : NO_SYSTEM_ACTIONS;
510
    }
511
    
512
    public SystemAction getDefaultAction() {
513
        Action a = (Action) MUTEX.readAccess (new Operation (ProxyLook.GET_DEFAULT_ACTION));
514
        return a instanceof SystemAction ? (SystemAction)a : null;
515
    }
516
    
517
    /** A convertor that takes array of Actions and return array of SystemActions
518
     * @param arr array of Action
519
     * @return array of SystemActions
520
     */
521
    private static SystemAction[] toSA (Action[] arr) {
522
        SystemAction[] sa = new SystemAction[arr.length];
523
        
524
        for (int i = 0; i < arr.length; i++) {
525
            if (arr[i] instanceof SystemAction) {
526
                sa[i] = (SystemAction)arr[i];
527
            }
528
        }
529
        
530
        return sa;
531
    }
532
                
533
                
534
    
535
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
536
    
537
    public Node.PropertySet[] getPropertySets() {
538
        Node.PropertySet[] sets = (Node.PropertySet[]) MUTEX.readAccess (new Operation (ProxyLook.GET_PROPERTY_SETS));
539
        if (sets == null) {
540
            sets = NO_PROPERTY_SETS;
541
        }
542
        
543
        Node.PropertySet[] all = new Node.PropertySet[ sets.length + 1 ];
544
        System.arraycopy( sets, 0, all, 0, sets.length );
545
         
546
        Sheet.Set set = LookProperties.getLookPropertySet( this );
547
		/*
548
        set.setName( LookProperties.LOOK_SHEET_SET_NAME );
549
        set.setDisplayName( LookProperties.LOOK_SHEET_SET_NAME );
550
        set.put( new LookProperties.LookProperty( this ) ); 
551
        */
552
553
        all[ all.length - 1] = set;
554
         
555
        return all;
556
    }
557
    
558
    public java.awt.Component getCustomizer() {
559
        return (java.awt.Component) MUTEX.readAccess (new Operation (ProxyLook.GET_CUSTOMIZER));
560
    }
561
    
562
    public boolean hasCustomizer () {
563
        return ((Boolean) MUTEX.readAccess (new Operation (ProxyLook.HAS_CUSTOMIZER))).booleanValue();
564
    }
565
    
566
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
567
     
568
    public boolean canRename() {
569
        return ((Boolean) MUTEX.readAccess (new Operation (ProxyLook.CAN_RENAME))).booleanValue();
570
    }
571
    
572
    public boolean canDestroy() {
573
        return ((Boolean) MUTEX.readAccess (new Operation (ProxyLook.CAN_DESTROY))).booleanValue();
574
    }
575
    
576
    public boolean canCopy() {
577
        return ((Boolean) MUTEX.readAccess (new Operation (ProxyLook.CAN_COPY))).booleanValue();
578
    }
579
    
580
    public boolean canCut() {
581
        return ((Boolean) MUTEX.readAccess (new Operation (ProxyLook.CAN_CUT))).booleanValue();
582
    }
583
    
584
    public PasteType[] getPasteTypes( Transferable t) {
585
        PasteType[] arr = (PasteType[]) MUTEX.readAccess (new Operation (ProxyLook.GET_PASTE_TYPES, t));
586
        return arr != null ? arr : NO_PASTE_TYPES;
587
    }
588
    
589
    public PasteType getDropType( Transferable t, int action, int index) {
590
        return (PasteType) MUTEX.readAccess (new Operation (
591
            ProxyLook.GET_DROP_TYPE, t, new Integer (action), new Integer (index)));
592
    }
593
    
594
    public Transferable clipboardCopy() throws IOException {
595
        try {
596
            return (Transferable) MUTEX.readAccess (new OperationException (ProxyLook.CLIPBOARD_COPY));
597
        } catch (MutexException e) {
598
            throw (IOException) e.getException ();
599
        }
600
    }
601
    
602
    public Transferable clipboardCut() throws IOException {
603
        try {
604
            return (Transferable) MUTEX.readAccess (new OperationException (ProxyLook.CLIPBOARD_CUT));
605
        } catch (MutexException e) {
606
            throw (IOException) e.getException ();
607
        }
608
    }
609
    
610
    public Transferable drag() throws IOException {
611
        try {
612
            return (Transferable) MUTEX.readAccess (new OperationException (ProxyLook.DRAG));
613
        } catch (MutexException e) {
614
            throw (IOException) e.getException ();
615
        }
616
    }
617
    
618
    public void destroy () throws IOException {
619
        try {
620
            MUTEX.readAccess (new OperationException (ProxyLook.DESTROY));
621
        } catch (MutexException e) {
622
            throw (IOException) e.getException ();
623
        }
624
        super.destroy();
625
    }
626
627
/*    
628
    boolean hasLookNodeParent() {
629
        Node parent = getParentNode();
630
        return parent != null && parent instanceof LookNode;
631
    }
632
*/    
633
    // Operation innerclass -----------------------------------------------------
634
635
    private final class Operation implements Mutex.Action {
636
        private long method = 0;
637
        private Object param1 = null;
638
        private Object param2 = null;
639
        private Object param3 = null;
640
        
641
        public Operation (long method) {
642
            this (method, null);
643
        }
644
        
645
        public Operation (long method, Object param1) {
646
            this (method, param1, null, null);
647
        }
648
        
649
        public Operation (long method, Object param1, Object param2, Object param3) {
650
            this.method = method;
651
            this.param1 = param1;
652
            this.param2 = param2;
653
            this.param3 = param3;
654
        }
655
        
656
        public Object run () {
657
            if (method == ProxyLook.GET_CHILD_OBJECTS) {
658
                return getLook ().getChildObjects (substitute);
659
            } else if (method == ProxyLook.GET_NAME) {
660
                return getLook ().getName (substitute);
661
            } else if (method == ProxyLook.SET_NAME) {
662
                getLook ().setName (substitute, (String) param1);
663
                return null;
664
            } else if (method == ProxyLook.GET_ICON) {
665
                return getLook ().getIcon (substitute, ((Integer) param1).intValue());
666
            } else if (method == ProxyLook.GET_HELP_CTX) {
667
                return getLook ().getHelpCtx (substitute);
668
            } else if (method == ProxyLook.GET_NEW_TYPES) {
669
                return getLook ().getNewTypes (substitute);
670
            } else if (method == ProxyLook.GET_ACTIONS) {
671
                return getLook ().getActions (substitute);
672
            } else if (method == ProxyLook.GET_CONTEXT_ACTIONS) {
673
                return getLook ().getContextActions (substitute);
674
            } else if (method == ProxyLook.GET_DEFAULT_ACTION) {
675
                return getLook ().getDefaultAction (substitute);
676
            } else if (method == ProxyLook.GET_PROPERTY_SETS) {
677
                return getLook ().getPropertySets (substitute);
678
            } else if (method == ProxyLook.GET_CUSTOMIZER) {
679
                return getLook ().getCustomizer (substitute);
680
            } else if (method == ProxyLook.HAS_CUSTOMIZER) {
681
                return getLook ().hasCustomizer (substitute) ? Boolean.TRUE : Boolean.FALSE;
682
            } else if (method == ProxyLook.CAN_RENAME) {
683
                return getLook ().canRename (substitute) ? Boolean.TRUE : Boolean.FALSE;
684
            } else if (method == ProxyLook.CAN_DESTROY) {
685
                return getLook ().canDestroy (substitute) ? Boolean.TRUE : Boolean.FALSE;
686
            } else if (method == ProxyLook.CAN_COPY) {
687
                return getLook ().canCopy (substitute) ? Boolean.TRUE : Boolean.FALSE;
688
            } else if (method == ProxyLook.CAN_CUT) {
689
                return getLook ().canCut (substitute) ? Boolean.TRUE : Boolean.FALSE;
690
            } else if (method == ProxyLook.GET_PASTE_TYPES) {
691
                return getLook ().getPasteTypes (substitute, (Transferable) param1);
692
            } else if (method == ProxyLook.GET_DROP_TYPE) {
693
                return getLook ().getDropType (substitute, (Transferable) param1, ((Integer) param2).intValue(), ((Integer) param2).intValue());
694
            }
695
            
696
            throw new IllegalStateException ("Invalid method id " + method); //NOI18N
697
        }
698
    }
699
700
    private final class OperationException implements Mutex.ExceptionAction {
701
        private long method = 0;
702
        
703
        public OperationException (long method) {
704
            this.method = method;
705
        }
706
        
707
        public Object run () throws IOException {
708
            if (method == ProxyLook.CLIPBOARD_COPY) {
709
                return getLook ().clipboardCopy (substitute);
710
            } else if (method == ProxyLook.CLIPBOARD_CUT) {
711
                return getLook ().clipboardCut (substitute);
712
            } else if (method == ProxyLook.DRAG) {
713
                return getLook ().drag (substitute);
714
            } else if (method == ProxyLook.DESTROY) {
715
                getLook ().destroy (substitute);
716
                return null;
717
            }
718
            
719
            throw new IllegalStateException ("Invalid method id " + method); //NOI18N
720
        }
721
    }
722
    
723
    // Interior innerclass -----------------------------------------------------
724
    
725
    /** Class passed to the Look methods as parameter. Each LookNode contains 
726
     * exactly one instance of this class. Metods of the class allow access
727
     * to the properties and methods od the node needed for the Look.
728
     */
729
    static final class SubstituteImpl extends Look.NodeSubstitute
730
    implements LookupListener {
731
        /** node we are attached to */
732
        private LookNode lookNode;
733
        /** lookup for this substitute */
734
        private Lookup lookup;
735
        /** all objects in the lookup, hold to prevent the result
736
         * to be garbage collected */
737
        private Lookup.Result result;
738
        /** selected id for this impl */
739
        private String id;
740
        
741
        /** The constructor of the interior is private to prevent other classes
742
         * than LookNode and Look from firing events on the node
743
         */
744
        SubstituteImpl(LookNode lookNode, Look look) {
745
            // initializes the lookNode
746
            this.lookNode = lookNode;
747
            
748
            // attaches to the look
749
            this.attachTo (look);
750
            
751
            // initializes the lookup
752
            this.lookup = look.createLookup (this);
753
            if (lookup != null) {
754
                // attach a listener
755
                result = lookup.lookup (
756
                    new Lookup.Template (Object.class)
757
                );
758
                result.addLookupListener (this);
759
            }
760
        }
761
        
762
        /** Called when this substitute is not needed anymore
763
         */
764
        public void clean () {
765
            lookNode = null;
766
        }
767
        
768
        /** Method to access the lookup.
769
         */
770
        public LookNode getLookNode () {
771
            return lookNode;
772
        }
773
774
        /** Queries the lookup.
775
         */
776
        Object getCookie (Class clazz) {
777
            if (lookup == null) {
778
                return null;
779
            } else {
780
                if (result == null) {
781
                    // attache a listener
782
                    result = lookup.lookup (new Lookup.Template (Object.class));
783
                    result.addLookupListener (this);
784
                }
785
                return lookup.lookup (clazz);
786
            }
787
        }
788
        
789
        
790
       
791
        
792
        /** Returns the object represented by the node
793
         * @return Object represented by the node this interior belongs to.
794
         */
795
        public Object getRepresentedObject(){
796
            LookNode l = lookNode;
797
            return l == null ? null : l.getRepresentedObject ();
798
        }
799
        
800
        /** Fire a property change event on the associated node.
801
         * @param name name of changed property (from {@link #getPropertySets})
802
         * @param o old value
803
         * @param n new value
804
         */
805
        public final void firePropertyChange( String name, Object o, Object n ) {
806
            LookNode l = lookNode;
807
            if (l != null) {
808
                l.firePropertyChange( name, o, n );
809
            }
810
        }
811
812
        /** Fires the Event notificationg about name change.
813
         */
814
        public final void fireNameChange( String o, String n ) {
815
            LookNode l = lookNode;
816
            if (l != null) {
817
                l.fireNameChange( o, n );
818
            }
819
        }
820
821
        /** Fires the Event notificationg about display name change.
822
         */
823
        public final void fireDisplayNameChange( String o, String n ) {
824
            LookNode l = lookNode;
825
            if (l != null) {
826
                l.fireDisplayNameChange( o, n );
827
            }
828
        }
829
830
        /** Fires the Event notificationg about short description change.
831
         */
832
        public final void fireShortDescriptionChange(String o, String n) {
833
            LookNode l = lookNode;
834
            if (l != null) {
835
                l.fireShortDescriptionChange( o, n );
836
            }
837
        }
838
839
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
840
         * associated node.
841
         */
842
        public final void fireIconChange() {
843
            LookNode l = lookNode;
844
            if (l != null) {
845
                l.fireIconChange();
846
            }
847
        }
848
849
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
850
         * associated node.
851
         */
852
        public final void fireOpenedIconChange() {
853
            LookNode l = lookNode;
854
            if (l != null) {
855
                l.fireOpenedIconChange();
856
            }
857
        }
858
859
        /** Fires a (Bean) property change event (for 
860
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
861
         * @param o the old set
862
         * @param n the new set
863
         */
864
        public final void firePropertySetsChange( PropertySet[] o, PropertySet[] n ) {
865
            LookNode l = lookNode;
866
            if (l != null) {
867
                l.firePropertySetsChange( o, n );
868
            }
869
        }
870
871
        /** Fires a change event for {@link org.openode.nodes.Node#PROP_COOKIE}.
872
         * The old and new values are set to null.
873
         */
874
        public final void resultChanged (LookupEvent ev) {
875
            LookNode l = lookNode;
876
            if (l != null) {
877
                l.fireCookieChange();
878
            }
879
        }
880
881
        /** To all node listeners fire node destroyed notification.
882
         */
883
        public final void fireNodeDestroyed() {
884
            LookNode l = lookNode;
885
            if (l != null) {
886
                l.fireNodeDestroyed();
887
            }
888
        }
889
890
        /** Tells the node that the children have to be refreshed.
891
         */
892
        public final void refreshChildren() {
893
            LookNode l = lookNode;
894
            if (l != null) {
895
                l.refreshChildren(false);
896
            }
897
        }
898
        
899
        public final String getRepresentationId() {
900
            return id;
901
        }
902
        
903
    } // end of SubstituteImpl
904
905
    /** Handle that stores the map of names to look names and
906
     * creates look node after then.
907
     */
908
    private static final class H implements Node.Handle {
909
        static final long serialVersionUID = -435781367432893214L;
910
     
911
        private Map map;
912
        private Object repr;
913
        
914
        public H (Map map, Object repr) {
915
            this.map = map;
916
            this.repr = repr;
917
        }
918
        
919
        public Node getNode () throws IOException {
920
            LookNode node = new LookNode (repr);
921
            node.map = map;
922
            return node;
923
        }
924
    }
925
}
(-)openidex/looks/src/org/netbeans/api/looks/LookProperties.java (-396 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.util.*;
17
import java.beans.PropertyEditor;
18
import java.beans.PropertyEditorSupport;
19
import javax.swing.JMenuItem;
20
import javax.swing.JMenu;
21
22
23
import org.openide.nodes.*;
24
import org.openide.util.NbBundle;
25
import org.openide.util.actions.*;
26
import org.openide.awt.Actions;
27
import java.beans.PropertyChangeListener;
28
import java.lang.ref.Reference;
29
import java.awt.Component;
30
import org.openide.explorer.view.MenuView;
31
import org.openide.explorer.ExplorerPanel;
32
import org.openide.explorer.view.ChoiceView;
33
import java.lang.ref.WeakReference;
34
import java.lang.ref.SoftReference;
35
import org.openide.util.WeakListener;
36
37
38
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
39
 * Please don't use this API for other purposes than testing.
40
 * <P> 
41
 * Utility class for creating a SheetSet for switching looks. 
42
 *
43
 * @author Petr Hrebejk
44
 */
45
class LookProperties extends Object {
46
47
    private static final ResourceBundle bundle = NbBundle.getBundle( LookProperties.class );
48
49
    public static final String LOOK_SHEET_SET_NAME = "Look"; // NOI18N
50
   
51
    /** Name of the default look. I.e. when the look on the node is null*/
52
    private static final String DEFAULT = bundle.getString( "CTL_Default" ); //NOI18N
53
    
54
    public static Sheet.Set getLookPropertySet( LookNode node ) {
55
        
56
        Sheet.Set set = new Sheet.Set();
57
        set.setName( LOOK_SHEET_SET_NAME ); // NOI18N
58
        set.setDisplayName( bundle.getString( "CTL_LookSheetSetName" ) ); //NOI18N
59
        set.put( new LookProperty( node ) ); 
60
        return set;
61
    }
62
    
63
    public static SystemAction getSetLookAction () {
64
        return SystemAction.get (SetLookAction.class);
65
    }
66
    
67
    // INNER CLASSES -----------------------------------------------------------
68
    
69
    /** The property for changing look
70
     */
71
    static class LookProperty extends PropertySupport.ReadWrite {
72
        
73
        private final LookNode lookNode;
74
        
75
        LookProperty( LookNode lookNode ) {
76
            super( bundle.getString( "CTL_LookProperty" ), // NOI18N
77
				   Look.class, 
78
                   bundle.getString( "CTL_LookProperty" ), // NOI18N
79
                   bundle.getString( "CTL_LookPropertyShortDescription" ) // NOI18N
80
                   ); 
81
            this.lookNode = lookNode;
82
        }
83
        
84
            
85
        public Object getValue() {            
86
            return lookNode.getLook ();
87
        }
88
            
89
        public void setValue( Object value ) {
90
            lookNode.setLook( (Look) value );
91
        }
92
            
93
        public PropertyEditor getPropertyEditor () {
94
            return new LookEditor( lookNode );
95
        }
96
97
    }
98
    
99
    /** Editor for choosing looks */
100
    static class LookEditor extends PropertyEditorSupport { 
101
102
        /** The node */
103
        LookNode lookNode = null;
104
        
105
        /** Current value */
106
        private Look look = null;
107
108
        /** Creates new editor */
109
        public LookEditor ( LookNode lookNode ) {
110
            this.lookNode = lookNode;
111
        }
112
113
        /**
114
        * @return The property value as a human editable string.
115
        * <p>   Returns null if the value can't be expressed as an editable string.
116
        * <p>   If a non-null value is returned, then the PropertyEditor should
117
        *       be prepared to parse that string back in setAsText().
118
        */
119
        public String getAsText () {
120
            if ( getValue() == null ) {
121
                return DEFAULT;
122
            }
123
            return ((Look)getValue()).getDisplayName ();
124
        }
125
        
126
        /**
127
        * Set the property value by parsing a given String.
128
        * @param text  The string to be parsed.
129
        */
130
        public void setAsText ( String string ) throws IllegalArgumentException {
131
            if ( string.equals( DEFAULT ) ) {
132
                setValue( null );
133
            }
134
            
135
            ArrayList list = new ArrayList ();
136
            collectLooks (lookNode.getSubstitute(), lookNode.getBaseLook (), list);
137
            Iterator it = list.iterator ();
138
            
139
            while (it.hasNext ()) {
140
                Look l = (Look)it.next ();
141
                
142
                if (l.getDisplayName ().equals (string)) {
143
                    setValue (l);
144
                    return;
145
                }
146
            }
147
            throw new IllegalArgumentException( "No such look - " + string ); // NOI18N
148
        }
149
150
        /**
151
        * @return A fragment of Java code representing an initializer for the
152
        * current value.
153
        */
154
        public String getJavaInitializationString () {
155
            return (getValue() == null) ? "" : look.getName(); // NOI18N
156
        }
157
158
        /**
159
        * @return The tag values for this property.
160
        */
161
        public String[] getTags () {
162
            ArrayList list = new ArrayList ();
163
            collectLooks (lookNode.getSubstitute (), lookNode.getBaseLook (), list);
164
            
165
            String names[] = new String [list.size ()];
166
            for ( int i = 0; i < names.length ; i++ ) {
167
                Look l = (Look)list.get (i);
168
                
169
                names[i] = l.getDisplayName ();
170
            }            
171
            return names;
172
        }
173
174
        static void collectLooks (Look.NodeSubstitute subst, Look look, ArrayList list) {
175
            if (list.contains (look)) return;
176
            
177
            list.add (look);
178
            
179
            Look[] arr = look.availableLooks (subst);
180
            if (arr == null) return;
181
            
182
            for (int i = 0; i < arr.length; i++) {
183
                list.add (arr[i]);
184
            }
185
        }        
186
    }
187
    
188
    /** Popupmenu action for choosing looks 
189
     */
190
    static class SetLookAction extends NodeAction {
191
        /** name of property of last selected object */
192
        public static final String PROP_LAST = "last";
193
        
194
        /** reference to the last LookNode */
195
        private Reference last;
196
        
197
        public java.lang.String getName() {
198
            return bundle.getString( "ACT_SetLook" ); //NOI18N
199
        }
200
201
        public org.openide.util.HelpCtx getHelpCtx() {
202
            return org.openide.util.HelpCtx.DEFAULT_HELP;
203
        }
204
205
        /* Returns a submneu that will present this action in a PopupMenu.
206
        * @return the JMenuItem representation for this action
207
        */
208
        public JMenuItem getPopupPresenter() {            
209
            JMenu mainItem = new MenuView.Menu (Ch.globalNode ());
210
            Actions.connect (mainItem, this, true);
211
//            HelpCtx.setHelpIDString (mainItem, SetLookAction.class.getName ());
212
            return mainItem;
213
        }
214
215
        /** Presentation in menu */
216
        public JMenuItem getMenuPresenter () {
217
            JMenu mainItem = new MenuView.Menu (Ch.globalNode ());
218
            Actions.connect (mainItem, this, false);
219
            
220
            return mainItem;
221
        }
222
        
223
        /** Presentation in toolbar */
224
        public Component getToolbarPresenter () {
225
            isEnabled ();
226
            
227
            ExplorerPanel ep = new ExplorerPanel ();
228
            ep.add (new ChoiceView ());
229
            ep.getExplorerManager().setRootContext (Ch.globalNode ());
230
            
231
            return ep;
232
        }
233
        
234
        /** Getter for the last selected item.
235
         */
236
        public LookNode getLast () {
237
            Reference l = last;
238
            if (l != null) {
239
                return (LookNode)l.get ();
240
            } else {
241
                return null;
242
            }
243
        }
244
        
245
        protected boolean enable(org.openide.nodes.Node[] node) {
246
            if (node.length != 1) return false;
247
            
248
            LookNode n = (LookNode)node[0].getCookie (LookNode.class);
249
            
250
            if (n != getLast ()) {
251
                // update the last reference
252
                if (n == null) {
253
                    last = null;
254
                } else {
255
                    last = new WeakReference (n);
256
                }
257
                
258
                firePropertyChange (PROP_LAST, null, null);
259
            }
260
            
261
            return n != null;
262
        }
263
        
264
        protected void performAction(org.openide.nodes.Node[] node) {
265
            // called when a node presenting look is selected
266
            for (int i = 0; i < node.length; i++) {
267
                Object l = node[i].getValue ("look"); // NOI18N
268
                Object n = node[i].getValue ("node"); // NOI18N
269
                if (l instanceof Look && n instanceof LookNode) {
270
                    ((LookNode)n).setLook ((Look)l);
271
                }
272
            }
273
        }
274
    }        
275
276
    /** Children that for a look display nodes for all its sublooks.
277
     */
278
    private static final class Ch extends Children.Keys 
279
    implements PropertyChangeListener {
280
        /** global node */
281
        private static Reference globalNode;
282
        
283
        private LookNode node;
284
        private Look look;
285
        private boolean active;
286
        
287
        public Ch (LookNode node, Look l) {
288
            this.node = node;
289
            this.look = l;
290
        }
291
        
292
293
        
294
        protected void addNotify () {
295
            active = true;
296
            
297
            update ();
298
        }
299
        
300
        protected void removeNotify () {
301
            setKeys (Collections.EMPTY_LIST);
302
            
303
            active = false;
304
        }
305
306
        protected Collection initCollection() {
307
            return Collections.singleton (create (node, look, false));
308
        }
309
                
310
        
311
        protected Node[] createNodes(Object key) {
312
            Look l = (Look)key;
313
            return new Node[] { create (node, l, true) };
314
        }
315
        
316
        public void propertyChange(java.beans.PropertyChangeEvent ev) {
317
            if (SetLookAction.PROP_LAST == ev.getPropertyName()) {
318
                update ();
319
            }
320
        }
321
        
322
        /** Updates the state acording to current selected node.
323
         */
324
        public void update () {
325
            LookNode n = null;
326
            Look l = null;
327
            SetLookAction set = (SetLookAction)SystemAction.get (SetLookAction.class); 
328
            if (node != null && node.equals (set.getLast())) {      
329
                n = node;
330
                l = look;
331
            }
332
            else {
333
                n = set.getLast ();
334
                l = n == null ? null : n.getBaseLook ();
335
                node = n;
336
                look = l;
337
            }
338
339
            if (active) {
340
                // refresh
341
                if (l != null && n != null) {
342
                    setKeys (Collections.EMPTY_LIST);
343
                    setKeys (l.availableLooks (n.getSubstitute ()));
344
                } else {
345
                    setKeys (Collections.EMPTY_LIST);
346
                }
347
            }
348
        }
349
        
350
        /** Creates node that represents global state of the system.
351
         */
352
        public static synchronized Node globalNode () {
353
            if (globalNode != null) {
354
                Node n = (Node)globalNode.get ();
355
                
356
                if (n != null) {
357
                    ((Ch)n.getChildren ()).update ();
358
                    return n;
359
                }
360
            }
361
            
362
            Ch ch = new Ch (null, null);
363
            
364
            // attach listener to last selected node
365
            SystemAction action = SystemAction.get (SetLookAction.class);
366
            action.addPropertyChangeListener(
367
                WeakListener.propertyChange (ch, action)
368
            );
369
            
370
            Node n = new AbstractNode (ch);
371
            globalNode = new SoftReference (n);
372
            return n;
373
        }
374
        
375
        /** Creates new node for a look presentation.
376
         */
377
        private static Node create (LookNode subst, Look l, boolean submenu) {
378
            
379
            AbstractNode n;
380
            Look[] arr = l.availableLooks (subst.getSubstitute());
381
            if (submenu && arr != null && arr.length != 0) {
382
                n = new AbstractNode (new Ch (subst, l));
383
            } else {
384
                n = new AbstractNode (Children.LEAF);
385
            }
386
            
387
            n.setName (l.getName ());
388
            n.setDisplayName (l.getDisplayName ());
389
            n.setDefaultAction (SystemAction.get (SetLookAction.class));
390
            n.setValue("look", l); // NOI18N
391
            n.setValue("node", subst); // NOI18N
392
            return n;
393
        }
394
    }
395
}
396
(-)openidex/looks/src/org/netbeans/api/looks/NodeProxyLook.java (-539 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.util.Collection;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.io.IOException;
20
import java.beans.PropertyChangeListener;
21
import java.beans.PropertyChangeEvent;
22
import java.util.ArrayList;
23
24
import javax.swing.Action;
25
26
import org.openide.nodes.*;
27
import org.openide.util.HelpCtx;
28
import org.openide.util.datatransfer.NewType;
29
import org.openide.util.datatransfer.PasteType;
30
import org.openide.util.Lookup;
31
import org.openide.util.WeakSet;
32
import org.openide.util.lookup.InstanceContent;
33
import org.openide.util.lookup.AbstractLookup;
34
35
36
import org.netbeans.spi.looks.*;
37
import org.openide.util.NbBundle;
38
39
/** 
40
 * Utility Class which allows to use LookNodes on existing Nodes. 
41
 * The class assumes that represented object is a Node. If there is 
42
 * Node.Interior representing other object than a ndoe the look delegates
43
 * to {DefaultLook#INSTANCE} i.e. returns neutral values.<BR>
44
 * Recomended usage of this class is to be used as delegatee.
45
 * <CODE>
46
 * public class MyNodeLook extends AcceptorLook {  
47
 *  
48
 *     public MyNodeLook() {
49
 *         super( new NodeProxyLook(), MyNode.Class );
50
 *         // set mask or do other initializations
51
 *     }
52
 * }
53
 * </CODE>
54
 * 
55
 * @author Petr Hrebejk
56
 */
57
final class NodeProxyLook extends Look {
58
    
59
    /** Creates new NodeProxySupport */
60
    public NodeProxyLook() {
61
    }
62
63
    // Methods of look itself --------------------------------------------------
64
    
65
    /** Specifies the node to which the Look delegates. The default 
66
     * implementation returns <CODE>substitute.getRepresentedObject()</CODE> 
67
     * casted to Node in case the represented object is a Node in other cases 
68
     * it returns null. If you override this method you can provide delegation
69
     * nodes for different types of object. (E.g. by calling 
70
     * dataObject.getNodeDelegate() ).
71
     */
72
    protected Node getNodeDelegate( Look.NodeSubstitute substitute ) {
73
        
74
        if ( substitute.getRepresentedObject() instanceof Node ) {
75
            return (Node)substitute.getRepresentedObject();
76
        }
77
        else {
78
            return null;
79
        }
80
    }
81
    
82
    // General methods ---------------------------------------------------------
83
    
84
    public Object attachTo (Look.NodeSubstitute substitute) {
85
        Node dn = getNodeDelegate( substitute );
86
        if ( dn == null ) {
87
            return null;
88
        } else {
89
            // Register listener to the node to pass events forward
90
            NodeEventTranslator nt = new NodeEventTranslator(substitute, dn);
91
            dn.addNodeListener (nt);
92
            dn.addPropertyChangeListener (new NodePropertyChangeTranslator (substitute, dn));
93
            return nt;
94
        }
95
    }
96
    
97
    public Lookup createLookup(Look.NodeSubstitute substitute) {
98
        // lookup has been created in attachTo method
99
        Object obj = getAttachedData (substitute);
100
        if (obj instanceof NodeEventTranslator) {
101
            NodeEventTranslator nt = (NodeEventTranslator)obj;
102
            return nt.lookup;
103
        }
104
        return null;
105
    }
106
107
    public Look[] availableLooks(Look.NodeSubstitute substitute) {
108
        Node dn = getNodeDelegate( substitute );
109
//        if (dn == null) {
110
            return null;
111
//        } else {
112
//            return dn.getHandle();
113
//        }
114
    }
115
    
116
    // Methods for STYLE -------------------------------------------------------
117
    
118
    public String getDisplayName( Look.NodeSubstitute substitute ) {
119
        Node dn = getNodeDelegate( substitute );
120
        if (dn == null) {
121
            return null;
122
        } else {
123
            return dn.getDisplayName();
124
        }
125
    }
126
    
127
    public String getName( Look.NodeSubstitute substitute ) {
128
        Node dn = getNodeDelegate( substitute );
129
        if (dn == null) {
130
            return null;
131
        } else {
132
            return dn.getName();
133
        }
134
    }
135
    
136
    public void setName( Look.NodeSubstitute substitute, String newName ) {
137
        Node dn = getNodeDelegate( substitute );
138
        if (dn != null) {
139
            dn.setName( newName );
140
        }
141
    }
142
    
143
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
144
        Node dn = getNodeDelegate( substitute );
145
        if (dn == null) {
146
            return null;
147
        } else {
148
            return dn.getShortDescription();
149
        }
150
    }
151
    
152
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
153
        Node dn = getNodeDelegate( substitute );
154
        if (dn == null) {
155
            return null;
156
        } else {
157
            return dn.getIcon( type );
158
        }
159
    }
160
    
161
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
162
        Node dn = getNodeDelegate( substitute );
163
        if (dn == null) {
164
            return null;
165
        } else {
166
            return dn.getOpenedIcon( type );
167
        }
168
    }
169
    
170
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
171
        Node dn = getNodeDelegate( substitute );
172
        if (dn == null) {
173
            return null;
174
        } else {
175
            return dn.getHelpCtx();
176
        }
177
    }
178
    
179
    // Methods for CHILDREN ----------------------------------------------------
180
    
181
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
182
        Node dn = getNodeDelegate( substitute );
183
        if (dn == null) {
184
            return null;
185
        } else {
186
            return dn.getChildren().getNodes();
187
        }
188
    }
189
        
190
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
191
    
192
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
193
        Node dn = getNodeDelegate( substitute );
194
        if ( dn == null ) {
195
            return null;
196
        }
197
        else {
198
            return dn.getNewTypes();
199
        }
200
    }
201
    
202
    public Action[] getActions(Look.NodeSubstitute substitute) {
203
        Node dn = getNodeDelegate( substitute );
204
        if ( dn == null ) {
205
            return null;
206
        }
207
        else {
208
            return dn.getActions();
209
        }
210
    }
211
    
212
    public Action[] getContextActions(Look.NodeSubstitute substitute) {
213
        Node dn = getNodeDelegate( substitute );
214
        if ( dn == null ) {
215
            return null;
216
        }
217
        else {
218
            return dn.getContextActions();
219
        }
220
    }
221
    
222
    public Action getDefaultAction(Look.NodeSubstitute substitute) {
223
        Node dn = getNodeDelegate( substitute );
224
        if ( dn == null ) {
225
            return null;
226
        }
227
        else {
228
            return dn.getDefaultAction();
229
        }
230
    }
231
    
232
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
233
    
234
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
235
        Node dn = getNodeDelegate( substitute );
236
        if ( dn == null ) {
237
            return null;
238
        }
239
        else {
240
            return dn.getPropertySets();
241
        }
242
    }
243
    
244
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
245
        Node dn = getNodeDelegate( substitute );
246
        if ( dn == null || !dn.hasCustomizer() ) {
247
            return null;
248
        }
249
        else {
250
            return dn.getCustomizer();
251
        }
252
    }
253
254
    public boolean hasCustomizer( Look.NodeSubstitute substitute ) {        
255
        Node dn = getNodeDelegate( substitute );
256
        return dn != null && dn.hasCustomizer ();
257
    }
258
    
259
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
260
     
261
    public boolean canRename( Look.NodeSubstitute substitute ) {
262
        Node dn = getNodeDelegate( substitute );
263
        if ( dn == null ) {
264
            return false;
265
        }
266
        else {
267
            return dn.canRename();
268
        }
269
    }
270
    
271
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
272
        Node dn = getNodeDelegate( substitute );
273
        if ( dn == null ) {
274
            return false;
275
        }
276
        else {
277
            return dn.canDestroy();
278
        }
279
    }
280
    
281
    public boolean canCopy( Look.NodeSubstitute substitute ) {
282
        Node dn = getNodeDelegate( substitute );
283
        if ( dn == null ) {
284
            return false;
285
        }
286
        else {
287
            return dn.canCopy();
288
        }
289
    }
290
    
291
    public boolean canCut( Look.NodeSubstitute substitute ) {
292
        Node dn = getNodeDelegate( substitute );
293
        if ( dn == null ) {
294
            return false;
295
        }
296
        else {
297
            return dn.canCut();
298
        }
299
    }
300
    
301
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
302
        Node dn = getNodeDelegate( substitute );
303
        if ( dn == null ) {
304
            return null;
305
        }
306
        else {
307
            return dn.getPasteTypes( t );
308
        }
309
    }
310
    
311
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
312
        Node dn = getNodeDelegate( substitute );
313
        if ( dn == null ) {
314
            return null;
315
        }
316
        else {
317
            return dn.getDropType( t, action, index );
318
        }
319
    }
320
    
321
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
322
        Node dn = getNodeDelegate( substitute );
323
        if ( dn == null ) {
324
            return null;
325
        }
326
        else {
327
            return dn.clipboardCopy();
328
        }
329
    }
330
    
331
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
332
        Node dn = getNodeDelegate( substitute );
333
        if ( dn == null ) {
334
            return null;
335
        }
336
        else {
337
            return dn.clipboardCut();
338
        }
339
    }
340
    
341
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
342
        Node dn = getNodeDelegate( substitute );
343
        if ( dn == null ) {
344
            return null;
345
        }
346
        else {
347
            return dn.drag();
348
        }
349
    }      
350
    
351
    public void destroy( Look.NodeSubstitute substitute ) throws IOException {
352
        Node dn = getNodeDelegate( substitute );
353
        if ( dn != null ) {
354
            dn.destroy();
355
        }
356
    }
357
    
358
    /** The human presentable name of the look.
359
     * @return human presentable name
360
     */
361
    public String getDisplayName() {
362
        return NbBundle.getMessage (NodeProxyLook.class, "LAB_NodeProxyLook"); // NOI18N
363
    }    
364
    
365
    /** Returns name of the look. This name should identify the look.
366
     * @return Name of the look.
367
     */
368
    public String getName() {
369
        return "Nodes"; // NOI18N
370
    }
371
    
372
    // Innerclasses ------------------------------------------------------------
373
    
374
    private static class NodeEventTranslator  
375
        extends EventTranslator implements NodeListener {
376
        
377
        private Node node;    
378
        private NodeLookup lookup;
379
            
380
        NodeEventTranslator( Look.NodeSubstitute substitute, Node node) {
381
            super( substitute );
382
            this.node = node;
383
            this.lookup = new NodeLookup (node);
384
        }
385
            
386
        public void unregister() {
387
            node.removeNodeListener( this );
388
        }
389
        
390
        
391
        public void childrenAdded( NodeMemberEvent e ) {
392
            getSubstitute().refreshChildren();
393
        }
394
         
395
        public void childrenRemoved( NodeMemberEvent e ) {
396
            getSubstitute().refreshChildren();
397
        }
398
        
399
        public void childrenReordered( NodeReorderEvent e ) {
400
            getSubstitute().refreshChildren();
401
        }
402
        
403
        public void nodeDestroyed( NodeEvent e ) {
404
            getSubstitute().fireNodeDestroyed();
405
        }
406
        
407
        public void propertyChange( PropertyChangeEvent e ) {
408
        
409
            if ( Node.PROP_NAME.equals( e.getPropertyName() ) ) {
410
                getSubstitute().fireNameChange( (String)e.getOldValue(), (String)e.getNewValue() );
411
            }
412
            else if ( Node.PROP_DISPLAY_NAME.equals( e.getPropertyName() ) ) {
413
                getSubstitute().fireDisplayNameChange( (String)e.getOldValue(), (String)e.getNewValue() );
414
            }
415
            else if ( Node.PROP_SHORT_DESCRIPTION.equals( e.getPropertyName() ) ) {
416
                getSubstitute().fireShortDescriptionChange( (String)e.getOldValue(), (String)e.getNewValue() );
417
            }
418
            else if ( Node.PROP_ICON.equals( e.getPropertyName() ) ) {
419
                getSubstitute().fireIconChange();
420
            }
421
            else if ( Node.PROP_OPENED_ICON.equals( e.getPropertyName() ) ) {
422
                getSubstitute().fireOpenedIconChange();
423
            }
424
            /*
425
            else if ( Node.PROP_PARENT_NODE.equals( e.getPropertyName() ) ) {
426
                property
427
            }
428
            */
429
            else if ( Node.PROP_PROPERTY_SETS.equals( e.getPropertyName() ) ) {
430
                getSubstitute().firePropertySetsChange( (Node.PropertySet[])e.getOldValue(), 
431
                                        (Node.PropertySet[])e.getNewValue() );
432
            }
433
            else if ( Node.PROP_COOKIE.equals( e.getPropertyName() ) ) {
434
                lookup.cookieChanged ();
435
            }
436
        }
437
    }
438
    
439
    private static class NodePropertyChangeTranslator
440
        extends EventTranslator implements PropertyChangeListener {
441
         
442
        private Node node;    
443
            
444
        NodePropertyChangeTranslator( Look.NodeSubstitute substitute, Node node) {
445
            super( substitute );
446
            this.node = node;
447
        }
448
            
449
        public void unregister() {
450
            node.removePropertyChangeListener( this );
451
        }    
452
            
453
        public void propertyChange( PropertyChangeEvent e ) {
454
            getSubstitute().firePropertyChange( e.getPropertyName(), e.getOldValue(), e.getNewValue() ); 
455
        }
456
    }
457
458
    /** A lookup to delegate to the node */
459
    static final class NodeLookup extends AbstractLookup {
460
        /** node template to query for all registered nodes */
461
        private static Template TEMPL_NODE = new Template (Node.class);
462
463
        /** instance content to add new objects into */
464
        private InstanceContent ic;
465
        /** Set of Classes that we have already queried <type>Class</type> */
466
        private WeakSet queriedCookieClasses = new WeakSet (37);
467
468
        /** current objects assigned to the lookup */
469
        private Node node;
470
471
        /** New flat lookup.
472
         * @param node for given node
473
         */
474
        public NodeLookup (Node node) {
475
            this (new InstanceContent (), node);
476
        }
477
478
        private NodeLookup (InstanceContent ic, Node node) {
479
            super (ic);
480
481
            this.ic = ic;
482
            this.node = node;
483
        }
484
485
        /** Notifies subclasses that a query is about to be processed.
486
         * @param template the template 
487
         */
488
        protected final void beforeLookup (Template template) {
489
            Class type = template.getType ();
490
491
            if (Node.class == type) {
492
                return;
493
            }
494
495
            if (Node.Cookie.class.isAssignableFrom (type)) {
496
                if (!queriedCookieClasses.contains (type)) {
497
                    queriedCookieClasses.add (type);
498
                    queryCookie (new Class[] { type }, null);
499
                }
500
            }
501
        }
502
503
504
        /** Performs query on content of cookies in the nodes.
505
         *
506
         * @param types the classes to query
507
         * @param res result to add cookies to
508
         */
509
        private final void queryCookie (Class[] types, Collection res) {
510
            for (int i = 0; i < types.length; i++) {
511
                Object obj = node.getCookie (types[i]);
512
                if (obj != null) {
513
                    if (res != null) {
514
                        res.add (obj);
515
                    } else {
516
                        ic.add (obj);
517
                    }
518
                }
519
            }
520
        }
521
522
        public void cookieChanged () {
523
            ArrayList a2 = new ArrayList ();
524
            a2.add (node);
525
526
            // if a change in cookie, requery
527
            Class[] types = (Class[])queriedCookieClasses.toArray (new Class[0]);
528
529
            if (types.length != 0) {
530
                // add all cookies
531
                queryCookie (types, a2);
532
            }
533
534
            ic.set (a2, null);
535
        }
536
537
    }
538
    
539
}
(-)openidex/looks/src/org/netbeans/api/looks/TypesLook.java (-42 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
17
18
import org.openide.nodes.*;
19
20
import org.netbeans.spi.looks.NamespaceLook;
21
import org.openide.util.NbBundle;
22
23
/** Default look <link>Look.DEFAULT</link> finds the correct look
24
 * by searching namespace with the names of the superclasses and superinterfaces.
25
 *
26
 * @author Jaroslav Tulach
27
 */
28
final class TypesLook extends NamespaceLook {
29
    public TypesLook () {
30
        super ("Looks/Types/"); // NOI18N
31
    }
32
    
33
    /** Name */
34
    public String getName () {
35
        return "Types"; // NOI18N
36
    }
37
    
38
    /** DisplayName */
39
    public String getDisplayName () {
40
        return NbBundle.getMessage (TypesLook.class, "LAB_Types");
41
    }
42
}
(-)openidex/looks/src/org/netbeans/modules/looks/Bundle.properties (-16 lines)
Removed Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
OpenIDE-Module-Name: Old Looks API
13
OpenIDE-Module-Short-Description: Obsolete Looks API module.
14
OpenIDE-Module-Display-Category: Infrastructure
15
OpenIDE-Module-Long-Description: Do not use this module.
16
OpenIDE-Module-Deprecation-Message: Obsoleted by a rewritten Looks API, do not use.
(-)openidex/looks/src/org/netbeans/modules/looks/CompositeLook.java (-147 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.looks;
15
16
import java.beans.*;
17
import java.util.*;
18
19
import javax.naming.*;
20
21
import org.openide.util.datatransfer.*;
22
import org.openide.util.*;
23
import org.openide.nodes.*;
24
25
import org.netbeans.api.looks.Look;
26
import org.netbeans.spi.looks.ProxyLook;
27
import org.openide.ErrorManager;
28
import org.openide.filesystems.FileObject;
29
import org.openide.filesystems.Repository;
30
31
/** A composite look that composes itself from a content of JNDI namespace.
32
*
33
* @author Jaroslav Tulach
34
*/
35
public final class CompositeLook extends ProxyLook {
36
    /** attribute that identifies the context in FileObject */
37
    private static final String CONTEXT = "context"; // NOI18N
38
    /** a delay of periodic refresh of JNDI content */
39
    private static final long REFRESH = 15000;
40
41
    private static HashMap instances = new HashMap();
42
    
43
    /** name in the context */
44
    private String name;
45
    /** display name */
46
    private FileObject file;
47
    
48
    /** the current array of looks we delegate to */
49
    private Look[] arr;
50
    
51
    /** the last time we have refreshed the arr */
52
    private long last;
53
    
54
    private CompositeLook (String name, FileObject file) {
55
        this.name = name;
56
        this.file = file;
57
    }
58
    
59
    /** Getters for Look.NODES
60
     */
61
    public static Look lookNode () {
62
        return Look.NODES;
63
    }
64
    
65
    /** Getter for Look.BEANS
66
     */
67
    public static Look lookObject () {
68
        return Look.BEANS;
69
    }
70
    
71
    /** Creates new composite look from attributes of a file object.
72
     * @param fo file object
73
     */
74
    public static Look create (FileObject fo) throws java.io.IOException {
75
        // XXX: fo is from XML layer's filesystem, wee need to keep
76
        // FileObject from DefaultFileSystem, huh bug??
77
        FileObject f = Repository.getDefault ().getDefaultFileSystem ().findResource (fo.toString ());
78
        if (f != null) {
79
            fo = f;
80
        }
81
        
82
        Object name = fo.getAttribute (CONTEXT);
83
        if (name instanceof String) {
84
            Look look = (Look) instances.get(fo);
85
            if (look == null) {
86
                look = new CompositeLook ((String)name, fo);
87
                instances.put(fo, look);
88
            }
89
            return look;
90
        } else {
91
            throw new java.io.IOException ("Attribute " + CONTEXT + " is not string but: " + name); // NOI18N
92
        }
93
    }
94
        
95
        
96
    /** Identifier of the composite look.
97
     */
98
    public String getName () {
99
        return "Composite[" + name; // NOI18N
100
    }
101
    
102
    /** Display name. */
103
    public String getDisplayName () {
104
        try {
105
            return org.openide.loaders.DataObject.find (file).getNodeDelegate().getDisplayName ();
106
        } catch (org.openide.loaders.DataObjectNotFoundException ex) {
107
            return file.toString ();
108
        }
109
    }
110
111
    /** Delegates to all looks in the context.
112
     */
113
    protected Look[] delegateTo (long method, NodeSubstitute substitute) {
114
        if (arr == null || System.currentTimeMillis() - last > REFRESH) {
115
            arr = readContext (name);
116
        }
117
        
118
        return arr;
119
    }
120
    
121
    /** Reads list of looks from the context.
122
     */
123
    private static Look[] readContext (String name) {
124
        try {
125
            NamingEnumeration en = org.netbeans.api.naming.NamingSupport.createSFSInitialContext().listBindings (name);
126
127
            ArrayList l = new ArrayList ();
128
            while (en.hasMoreElements()) {
129
                Binding b = (Binding)en.nextElement();
130
131
                Object o = b.getObject ();
132
                if (o instanceof Look) {
133
                    l.add (o);
134
                }
135
            }
136
137
            return (Look[])l.toArray (new Look[0]);
138
        } catch (NamingException ev) {
139
            ErrorManager.getDefault ().notify (ev);
140
            return new Look[0];
141
        }
142
    }
143
144
    
145
}
146
147
(-)openidex/looks/src/org/netbeans/modules/looks/mf-layer.xml (-26 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
3
<filesystem>
4
    <folder name="Looks">
5
        <folder name="Types">
6
            <folder name="org">
7
                <folder name="openide">
8
                    <folder name="nodes">
9
                        <file name="Node.instance">
10
                            <attr name="instanceClass" stringvalue="org.netbeans.api.looks.Look" />
11
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.looks.CompositeLook.lookNode" />
12
                        </file>
13
                    </folder>
14
                </folder>
15
            </folder>
16
            <folder name="java">
17
                <folder name="lang">
18
                    <file name="Object.instance">
19
                        <attr name="instanceClass" stringvalue="org.netbeans.api.looks.Look" />
20
                        <attr name="instanceCreate" methodvalue="org.netbeans.modules.looks.CompositeLook.lookObject" />
21
                    </file>
22
                </folder>
23
            </folder>
24
        </folder>
25
    </folder>
26
</filesystem>
(-)openidex/looks/src/org/netbeans/spi/looks/Bundle.properties (-14 lines)
Removed Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
# Names of looks
13
LAB_Filter=Filter over {0}
14
(-)openidex/looks/src/org/netbeans/spi/looks/DefaultLook.java (-398 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
import java.text.MessageFormat;
20
import java.util.ArrayList;
21
22
import javax.naming.NamingEnumeration;
23
import javax.naming.InitialContext;
24
import javax.naming.NamingException;
25
import javax.naming.Binding;
26
import javax.swing.Action;
27
28
import org.openide.nodes.*;
29
import org.openide.util.Utilities;
30
import org.openide.util.HelpCtx;
31
import org.openide.util.Lookup;
32
import org.openide.util.datatransfer.NewType;
33
import org.openide.util.datatransfer.PasteType;
34
35
import org.netbeans.api.looks.*;
36
import org.openide.util.NbBundle;
37
38
/** 
39
 * This is a suitable base superclass for newly created looks. It implements all methods of the
40
 * abstract <code>Look</code> and by default does nothing and returns neutral 
41
 * values (nulls, false) from all its methods. 
42
 * <P>
43
 * Some methods are linked together to make it easier for subclasses to 
44
 * implement reasonable functionality (iconBase, actionBase), etc.
45
 *
46
 * @author Jaroslav Tulach
47
 */
48
public abstract class DefaultLook extends Look {
49
    /** messages to create a resource identification for each type of
50
    * icon from the base name for the icon.
51
    */
52
    private static final MessageFormat[] icons = {
53
        // color 16x16
54
        new MessageFormat ("{0}.gif"), // NOI18N
55
        // color 32x32
56
        new MessageFormat ("{0}32.gif"), // NOI18N
57
        // mono 16x16
58
        new MessageFormat ("{0}.gif"), // NOI18N
59
        // mono 32x32
60
        new MessageFormat ("{0}32.gif"), // NOI18N
61
        // opened color 16x16
62
        new MessageFormat ("{0}Open.gif"), // NOI18N
63
        // opened color 32x32
64
        new MessageFormat ("{0}Open32.gif"), // NOI18N
65
        // opened mono 16x16
66
        new MessageFormat ("{0}Open.gif"), // NOI18N
67
        // opened mono 32x32
68
        new MessageFormat ("{0}Open32.gif"), // NOI18N
69
    };
70
    /** To index normal icon from previous array use
71
    *  + ICON_BASE.
72
    */
73
    private static final int ICON_BASE = -1;
74
    /** for indexing opened icons */
75
    private static final int OPENED_ICON_BASE = 3;
76
    
77
    /** name of the look */
78
    private String name;
79
    
80
    /** Creates new instance of look does no work.
81
     * @param name the name to assign to the look
82
     * @see getName
83
     */
84
    public DefaultLook(String name) {
85
        this.name = name;
86
    }
87
88
    
89
    /** The human presentable name of the look. The default implementation
90
     * calls <code>NbBundle.getMessage (getClass (), "LAB_" + getName ()</code>
91
     * to simplify the work. That means one should put the token
92
     * <PRE>
93
     *      LAB_myname=localized name
94
     * </PRE>
95
     * into the <code>Bundle.properties</code> file defined in the same package
96
     * as this class (where myname is the name provided into the constructor).
97
     * <P>
98
     * Warning: If you expect to have subclasses, override this method with
99
     * better implementation!
100
     * <P>
101
     * @return human presentable name
102
     */
103
    public String getDisplayName() {
104
        return NbBundle.getMessage (getClass (), "LAB_" + name); // NOI18N
105
    }
106
    
107
    /** Returns name of the look as provided in constructor.
108
     * @return Name of the look.
109
     */
110
    public String getName() {
111
        return name;
112
    }
113
    
114
    // General methods ---------------------------------------------------------
115
    
116
    /** Does neutral behaviour (doing nothing, returning null)
117
     */
118
    public Lookup createLookup (Look.NodeSubstitute substitute) {
119
        return null;
120
    }
121
122
    
123
    /** Does neutral behaviour (doing nothing, returning null)
124
     */
125
    public Look[] availableLooks (Look.NodeSubstitute substitute) {
126
        return null;
127
    }
128
    
129
    // Methods for STYLE -------------------------------------------------------
130
    
131
    /** Does neutral behaviour (doing nothing, returning null)
132
     */
133
    public String getDisplayName( Look.NodeSubstitute substitute ) {
134
        return null;
135
    }
136
    
137
    /** Does neutral behaviour (doing nothing, returning null)
138
     */
139
    public String getName( Look.NodeSubstitute substitute ) {
140
        return null;
141
    }
142
    
143
    /** Does neutral behaviour (doing nothing, returning null)
144
     */
145
    public void setName(Look.NodeSubstitute substitute, String newName) {
146
    }
147
    
148
    /** Does neutral behaviour (doing nothing, returning null)
149
     */
150
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
151
        return null;
152
    }
153
    
154
    /** Finds icon using the value returned from <link>iconBase</link>
155
     * @return an icon or null if not found
156
     */
157
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
158
        return findIcon (substitute, type, ICON_BASE);
159
    }
160
161
    /** Finds icon using the value returned from <link>iconBase</link>
162
     * @return an icon or null if not found
163
    */
164
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
165
        return findIcon (substitute, type, OPENED_ICON_BASE);
166
    }
167
    
168
    /** Does neutral behaviour (doing nothing, returning null)
169
     */
170
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
171
        return null;
172
    }
173
    
174
    // Methods for CHILDREN ----------------------------------------------------
175
    
176
    /** Does neutral behaviour (doing nothing, returning null)
177
     */
178
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
179
        return null;
180
    }
181
    
182
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
183
    
184
    /** Does neutral behaviour (doing nothing, returning null)
185
     */
186
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
187
        return null;
188
    }
189
    
190
    /** Calls actionBase (substitute, false) and extracts actions
191
     * from that context.
192
     *
193
     * @return the actions at the context or null
194
     */
195
    public Action[] getActions( Look.NodeSubstitute substitute ) {
196
        return actionsForContext (actionBase (substitute, false));
197
    }
198
    
199
    /** Calls actionBase (substitute, true) and extracts actions
200
     * from that context.
201
     *
202
     * @return the actions at the context or null
203
     */
204
    public Action[] getContextActions( Look.NodeSubstitute substitute ) {
205
        return actionsForContext (actionBase (substitute, true));
206
    }
207
    
208
    /** Extracts the first action from getActions, if any.
209
     * @return the action or null
210
     */
211
    public Action getDefaultAction( Look.NodeSubstitute substitute ) {
212
        Action[] arr = getActions (substitute);
213
        return arr != null && arr.length > 0 ? arr[0] : null;
214
    }
215
    
216
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
217
    
218
    /** Does neutral behaviour (doing nothing, returning null)
219
     */
220
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
221
        return null;
222
    }
223
224
    /** Is the customizer for represented object available? Checks whether
225
     * getCustomizer (substitute) returns non-null value
226
     *
227
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
228
     * @return true if the customizer is available, false otherwise
229
     */
230
    public boolean hasCustomizer(Look.NodeSubstitute substitute) {
231
        return getCustomizer (substitute) != null;
232
    }
233
    
234
    /** Does neutral behaviour (doing nothing, returning null)
235
     */
236
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
237
        return null;
238
    }
239
    
240
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
241
     
242
    /** Does neutral behaviour (doing nothing, returning false)
243
     */
244
    public boolean canRename( Look.NodeSubstitute substitute ) {
245
        return false;
246
    }
247
    
248
    /** Does neutral behaviour (doing nothing, returning false)
249
     */
250
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
251
        return false;
252
    }
253
    
254
    /** Does neutral behaviour (doing nothing, returning false)
255
     */
256
    public boolean canCopy( Look.NodeSubstitute substitute ) {
257
        return false;
258
    }
259
    
260
    /** Does neutral behaviour (doing nothing, returning false)
261
     */
262
    public boolean canCut( Look.NodeSubstitute substitute ) {
263
        return false;
264
    }
265
    
266
    /** Does neutral behaviour (doing nothing, returning null)
267
     */
268
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
269
        return null;
270
    }
271
    
272
    /** Does neutral behaviour (doing nothing, returning null)
273
     */
274
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
275
        return null;
276
    }
277
    
278
    /** Does neutral behaviour (doing nothing, returning null)
279
     */
280
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
281
        return null;
282
    }
283
    
284
    /** Does neutral behaviour (doing nothing, returning null)
285
     */
286
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
287
        return null;
288
    }
289
    
290
    /** Does neutral behaviour (doing nothing, returning null)
291
     */
292
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
293
        return null;
294
    }
295
        
296
    /** Does neutral behaviour (doing nothing, returning null)
297
     */
298
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
299
    }
300
    
301
    
302
    //
303
    // Icon management
304
    //
305
    
306
    /** Allows subclasses to specify an icon in easier way without need to
307
    * load the actual objects.
308
    *
309
    * <p>For example, if the returned base is <code>/resource/MyIcon</code>, the
310
    * following images may be used according to the icon state and
311
    * {@link java.beans.BeanInfo#getIcon presentation type}:
312
    *
313
    * <ul><li><code>resource/MyIcon.gif</code><li><code>resource/MyIconOpen.gif</code>
314
    * <li><code>resource/MyIcon32.gif</code><li><code>resource/MyIconOpen32.gif</code></ul>
315
    *
316
    * <P>
317
    * The default implementation returns null.
318
    *
319
    * @param subst the substitute to locate icon for
320
    * @return the base for icon search (no initial slash) or <code>null</code> if this look does not provide an icon
321
    */
322
    protected String iconBase (NodeSubstitute subst) {
323
        return null;
324
    }
325
326
    /** Allows subclasses to specify actions in a easy way - by providing a
327
    * name of a JNDI context name where to find the javax.swing.Action objects.
328
    *
329
    * <p>By default the method returns name of this class (separated by slashes)
330
    * with a prefix Looks/Actions. So for a class <code>org.nb.mymod.MyLook</code>
331
    * the default action context is <em>Looks/Actions/org/nb/mymod/MyLook</em>.
332
    * As a result it is not necessary to override this method in many cases.
333
    * 
334
    * @param subst the substitute to locate actions for
335
    * @param context false if <code>getActions</code> was called, 
336
    *    true if <code>getContextActions</code> was called
337
    * @return the name of a context
338
    */
339
    protected String actionBase (NodeSubstitute subst, boolean context) {
340
        return "Looks/Actions/" + getClass ().getName ().replace ('.', '/');
341
    }
342
    
343
    /** Reads actions from a JNDI context.
344
     * @param name of the context.
345
     * @return array of actions
346
     */
347
    private static Action[] actionsForContext (String name) {
348
        try {
349
            NamingEnumeration en = org.netbeans.api.naming.NamingSupport.createSFSInitialContext().listBindings (name);
350
            if (!en.hasMoreElements ()) {
351
                return null;
352
            }
353
354
            ArrayList arr = new ArrayList ();
355
            while (en.hasMoreElements()) {
356
                Binding b = (Binding)en.nextElement ();
357
                arr.add (b.getObject());
358
            }
359
360
            return (Action[])arr.toArray (new Action[arr.size ()]);
361
        } catch (NamingException ex) {
362
            return null;
363
        }
364
    }
365
    
366
    /** Tries to find the right icon for the iconbase.
367
    * @param type type of icon (from BeanInfo constants)
368
    * @param ib base where to scan in the array
369
    * @return icon or null
370
    */
371
    private Image findIcon (NodeSubstitute subst, int type, int ib) {
372
        String[] base = { iconBase (subst) };
373
        if (base[0] == null) {
374
            return null;
375
        }
376
        
377
        String res = icons[type + ib].format (base);
378
        Image im = Utilities.loadImage (res);
379
380
        if (im != null) return im;
381
382
        // try the first icon
383
        res = icons[java.beans.BeanInfo.ICON_COLOR_16x16 + ib].format (base);
384
385
        im = Utilities.loadImage (res);
386
387
        if (im != null) return im;
388
389
        if (ib == OPENED_ICON_BASE) {
390
            // try closed icon also
391
            return findIcon (subst, type, ICON_BASE);
392
        }
393
394
        // if still not found return default icon
395
        return null;
396
    }
397
    
398
}
(-)openidex/looks/src/org/netbeans/spi/looks/EventTranslator.java (-139 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.lang.ref.WeakReference;
17
import java.lang.ref.ReferenceQueue;
18
19
import org.openide.nodes.Node;
20
import org.openide.util.RequestProcessor;
21
22
import org.netbeans.api.looks.*;
23
24
/** 
25
 * Utility class which allows to fire events on the LookNode according
26
 * to events of the represented object. This class should be used as a base
27
 * class for EventListener registered to represented objects.
28
 * <P>
29
 * The LookNode interior is hold by a WeakReference so the Node can be 
30
 * garbage collected even if the represented object still exists.<BR>
31
 * If you really want the node is not garbage collected while the 
32
 * represented object exists then hardreference the <CODE>Node.Interior</CODE>
33
 * from the subclass.
34
 * <P>
35
 * Helper methods allow automatic changes of Icon, Name and DisplayName
36
 * if some properies are changed.
37
 */
38
public abstract class EventTranslator extends WeakReference {
39
40
    /** Queue with all weak references */
41
    private static ReferenceQueue QUEUE = new ReferenceQueue ();
42
    /** How often clean */
43
    private static int CLEANER_TIME = 25000;
44
    /** Clearner task */
45
    private static RequestProcessor.Task CLEANER_TASK = RequestProcessor.postRequest(
46
        new Cleaner (), CLEANER_TIME, Thread.MIN_PRIORITY
47
        );
48
    
49
    /** Fake instance to fire event on when the node was garbage collected. */
50
    private static Look.NodeSubstitute NULL_SUBSTITUTE;
51
52
    /** Creates new EventTranslator for given LookNode.Interior
53
     * @param LookNode.Interior the node to fire events on.
54
     */
55
    public EventTranslator ( Look.NodeSubstitute substitute ) {
56
        super( substitute, QUEUE );
57
    }
58
59
    /** This method is called when the node was garbage collected. You shoud
60
     * unregister from all objects where this object was registered as a 
61
     * listener.
62
     */ 
63
    protected abstract void unregister();
64
65
    /** Gets the substitute to fire on
66
     */
67
    protected Look.NodeSubstitute getSubstitute() {
68
        Look.NodeSubstitute substitute = (Look.NodeSubstitute)get();
69
70
        if ( substitute == null || substitute.getRepresentedObject() == null ) {
71
            unregister();
72
73
            if ( NULL_SUBSTITUTE == null ) {
74
                NULL_SUBSTITUTE = new NullNodeSubstitute();
75
            }
76
            return NULL_SUBSTITUTE;
77
        }
78
        else {
79
            return substitute;
80
        }
81
    }
82
    
83
    
84
    // Innerclasses ------------------------------------------------------------
85
    
86
    /** Class that periodically runs cleaning of the queue.
87
    */
88
    private static final class Cleaner extends Object implements Runnable {
89
        public void run () {
90
            for (;;) {
91
                EventTranslator et = (EventTranslator)QUEUE.poll();
92
                if (et == null) 
93
                    break;
94
                et.unregister();
95
            }
96
97
            CLEANER_TASK.schedule (CLEANER_TIME);
98
        }
99
    }
100
    
101
    /** Empty Look.NodeSubstitute which does not fire any events
102
     */
103
    private static final class NullNodeSubstitute extends Look.NodeSubstitute {
104
        public NullNodeSubstitute () {
105
        }
106
        
107
        public Object getRepresentedObject() {
108
            return null;
109
        }; 
110
        
111
        public void firePropertyChange( String name, Object o, Object n ) {
112
        }
113
114
        public void fireNameChange( String o, String n ) {
115
        }
116
        
117
        public void fireDisplayNameChange( String o, String n ) {
118
        }
119
        
120
        public void fireShortDescriptionChange(String o, String n) {
121
        }
122
123
        public void fireIconChange() {
124
        }
125
126
        public void fireOpenedIconChange() {
127
        }
128
129
        public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n ) {
130
        }
131
       
132
        public void fireNodeDestroyed() {
133
        }
134
135
        public void refreshChildren() {
136
        }
137
    }
138
    
139
}
(-)openidex/looks/src/org/netbeans/spi/looks/FilterLook.java (-128 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
17
18
import org.openide.nodes.*;
19
20
import org.netbeans.api.looks.*;
21
import org.openide.util.NbBundle;
22
23
/** 
24
 * This is base class for delegating to other looks or nodes. All methods 
25
 * delegate to the delegate, unless they are masked.
26
 * <P>
27
 * All the methods contain  simple deleagation to the {@link Look} 
28
 * passed as parameter into the constructor, if the mask contains flag
29
 * for the method.<P>
30
 * Use the methods: {@link #setLookMask}, {@link #lookMask}, {@link #lookMask}, 
31
 * {@link #lookUnmask} for work with the mask.<BR> 
32
 * The default state is to delegate all methods (i.e. the mask is set to
33
 * {@link #ALL_METHODS}.)
34
 *
35
 * @author Petr Hrebejk
36
 */
37
public class FilterLook extends ProxyLook {
38
    /** Contains current mask of the node */
39
    private long mask;
40
    
41
    /** Contains the Look to delegate to. Array of one member */
42
    private Look[] delegate;
43
    
44
    /** Creates new filter and delegates all methods to the provided delegate
45
     * @param delegate The Look to delegate to.
46
     */
47
    public FilterLook (Look delegate) {
48
        this (delegate, ALL_METHODS);
49
    }
50
    
51
    /** Creates new filter look and sets its filtering
52
     * @param delegate look to delegate to
53
     * @param mask the mask to use (one of method contants)
54
     */
55
    public FilterLook (Look delegate, long mask) {
56
        this.delegate = new Look[] { delegate };
57
        this.mask = mask;
58
    }
59
    
60
    /** Name of the look. Composed from the name of the delegate.
61
     */
62
    public String getName () {
63
        return "Filter[" + delegate[0].getName ();
64
    }
65
    
66
    /** Display name of the look. Composed from the name of the delegate.
67
     */
68
    public String getDisplayName () {
69
        return NbBundle.getMessage (FilterLook.class, "LAB_Filter", delegate[0].getDisplayName ());
70
    }
71
    
72
    /** A method that checks whether given method should be delegated to 
73
     * the look provided in constructor or not. 
74
     * <P>
75
     * The default implementation ignores the context and just checks 
76
     * the mask which can be modified by <link>lookMask</link>, <link>lookUnmask</link>
77
     * methods.
78
     * <P>
79
     * Subclasses might override 
80
     * this method with implementation that bases its decision on different criteria.
81
     *
82
     * @param method one of the constants defined here that identifies the method
83
     *    we want to delegate to
84
     * @param substitute the substitute that the method will be called with or 
85
     *    null if we are in notification of changes and we have no substitute
86
     * @return either the delegate look or null
87
     */
88
    protected final Look[] delegateTo (long method, NodeSubstitute substitute) {
89
        return ( mask & method ) > 0 ? delegate : null;
90
    }
91
    
92
    // Methods of look itself -------------------------------------------------
93
    
94
    /** Sets mask for this look. Only methods contained in the mask
95
     * will be delegated. Other methods will return neutral values.
96
     * @param mask The mask to be set.
97
     */
98
    protected final void setLookMask( long mask ) {
99
        this.mask = mask;
100
    }
101
    
102
    /** Returns the current mask for this filter look.
103
     * @return Current mask.
104
     */
105
    protected final long getLookMask( ) {
106
        return mask;
107
    }
108
    
109
    /** Masks given methods. Removes given methods from given mask. 
110
     * The masked methods will be no longer delegated.
111
     * @param methods Logical <CODE>OR</CODE> of methods which have to be masked.
112
     * @return Current mask.
113
     */
114
    protected final long lookMask( long methods ) {
115
        mask |= methods;
116
        return mask;
117
    }
118
     
119
    /** Unmasks given methods. Adds given methods from given mask. 
120
     * The masked methods will start to be delegated.
121
     * @param methods Logical <CODE>OR</CODE> of methods which have to be unmasked.
122
     * @return Current mask.
123
     */
124
    protected final long lookUnmask( long methods ) {
125
        mask &= ~methods; 
126
        return mask;
127
    }
128
}
(-)openidex/looks/src/org/netbeans/spi/looks/NamespaceLook.java (-196 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.util.List;
17
import java.util.Enumeration;
18
19
import javax.naming.*;
20
21
import org.openide.nodes.*;
22
import org.openide.util.enum.*;
23
24
import org.netbeans.api.looks.*;
25
import java.util.ArrayList;
26
27
/** 
28
 * Searches for a look in namespace given name of context to search in
29
 * and a a possible set of names that should be checked.
30
 *
31
 * @author Jaroslav Tulach
32
 * @version 0.2
33
 */
34
public abstract class NamespaceLook extends ProxyLook {
35
    /** InitialContext or NamingException depending on how we succeded to find the correct look */
36
    private static Object context;
37
38
    /** Prefix to prepend to all namespace names */
39
    private String prefix;
40
    
41
    /** Constructs new namespace looks with provided subspace to search
42
     *
43
     * @param prefix prefix to search, e.g. <sample>Looks/Types/</sample>, etc.
44
     */
45
    public NamespaceLook (String prefix) {
46
        this.prefix = prefix;
47
    }
48
    
49
    /** Finds the correct look in namespace according to the enumeration
50
     * of possible names provided by <code>namesFor</code> method.
51
     *
52
     * @param method ignored
53
     * @param substitute the substitute which method will be called with or
54
     *   null if we are in notification of changes and we have no substitute
55
     * @return the look to delegate to or null
56
     */
57
    protected final Look[] delegateTo (long method, NodeSubstitute substitute) {
58
        return new Look[] { findLook (
59
            prefix, namesFor (substitute.getRepresentedObject ()), null
60
        ) };
61
    }
62
    
63
    /** Defines the list of names that should be searched for a given 
64
     * represented object.
65
     *
66
     *
67
     * <P>
68
     * Subclasses are allowed to provide different implementation which can
69
     * base the naming based on for example public ID
70
     * for <code>org.w3c.dom.Document</code>.
71
     *
72
     * <P>
73
     * The <link>Look.DEFAULT</link> uses the this class and returns enumeration
74
     * of all superclasses and superinterfaces for provided object.
75
     *
76
     * @param obj the represented object
77
     * @return enumeration of String
78
     * @see Look.DEFAULT
79
     * @since Made non abstract in version 0.2
80
     */
81
    protected Enumeration namesFor (Object obj) {
82
        return obj == null ? EmptyEnumeration.EMPTY : forClass (obj.getClass ());
83
    }
84
    
85
    /** Offers all looks available in the namespace. Takes input from
86
     * namesFor and finds all looks that represent some name in enumeration.
87
     * 
88
     * @param subst substitute to find looks for
89
     * @return array of available looks
90
     */
91
    public Look[] availableLooks (NodeSubstitute subst) {
92
        Enumeration en = namesFor (subst.getRepresentedObject ());
93
        ArrayList looks = new ArrayList ();
94
        
95
        // collects all looks into array list looks
96
        findLook (prefix, en, looks);
97
        
98
        return (Look[])looks.toArray (new Look[0]);
99
    }
100
        
101
    
102
    /** Finds look(s) for a class.
103
     * @param prefix prefix string to add to each name or null
104
     * @param names list of Strings to check their names (c1/c2/name)
105
     * @param looks list where to add all found looks or null if just find one
106
     * @return look found or null 
107
     */
108
    private static Look findLook (String prefix, Enumeration names, List looks) {
109
        if (context == null) {
110
            try {
111
                context = org.netbeans.api.naming.NamingSupport.createSFSInitialContext();
112
            } catch (NamingException ex) {
113
                context = ex;
114
            }
115
        }
116
        
117
        if (context instanceof Context) {
118
            return findLook ((Context)context, prefix, names, looks);
119
        } else {
120
            return null;
121
        }
122
    }
123
    
124
    /** Searches for a look in given namespace and in the order specified by
125
     * given names.
126
     *
127
     * @param namespace the root context to search from
128
     * @param prefix prefix string to add to each name or null
129
     * @param names list of Strings to check their names (c1/c2/name)
130
     * @param toAdd list where to add all found looks
131
     * @return the look or null
132
     */
133
    private static Look findLook (
134
        Context namespace, String prefix, Enumeration names, List toAdd
135
    ) {
136
        java.util.Collection checks = new java.util.HashSet();
137
        while (names.hasMoreElements ()) {
138
            try {
139
                String check = (String)names.nextElement ();
140
                if (!checks.add(check))
141
                    continue;
142
                if (prefix != null) {
143
                    check = prefix + check;
144
                }
145
                
146
                NamingEnumeration en = namespace.listBindings (check);
147
                while (en.hasMoreElements ()) {
148
                    Binding b = (Binding)en.next ();
149
                    Object o = b.getObject ();
150
                    if (o instanceof Look) {
151
                        if (toAdd != null) {
152
                            // we are searching for all looks
153
                            toAdd.add (o);
154
                        } else {
155
                            // we need just one
156
                            return (Look)o;
157
                        }
158
                    }
159
                }
160
            } catch (NamingException ex) {
161
            }
162
        }
163
        return null;
164
    }
165
166
    /** Enumeration for a java class.
167
     * @param c class 
168
     * @return enumeration of names of implemented/extended classes in form suitable
169
     *      for findLook
170
     */
171
    private static Enumeration forClass (Class c) {
172
        QueueEnumeration en = new QueueEnumeration () {
173
            protected void process (Object o) {
174
                Class x = (Class)o;
175
                Class s = x.getSuperclass();
176
                put (x.getInterfaces ());
177
                if (s != null && s != Object.class) {
178
                    // if not object process all interfaces and super classes
179
                    put (s);
180
                }
181
            }
182
        };
183
        if (c != Object.class) {
184
            en.put (c);
185
        }
186
        
187
        AlterEnumeration alter = new AlterEnumeration (en) {
188
            protected Object alter (Object clazz) {
189
                Class c = (Class)clazz;
190
                return c.getName ().replace ('.', '/');
191
            }
192
        };
193
        
194
        return new SequenceEnumeration (alter, new SingletonEnumeration ("java/lang/Object")); // NOI18N
195
    }
196
}
(-)openidex/looks/src/org/netbeans/spi/looks/ProxyLook.java (-1073 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
20
import javax.swing.Action;
21
22
import org.openide.nodes.*;
23
import org.openide.util.HelpCtx;
24
import org.openide.util.Lookup;
25
import org.openide.util.datatransfer.NewType;
26
import org.openide.util.datatransfer.PasteType;
27
28
import org.netbeans.api.looks.*;
29
import java.util.ArrayList;
30
import org.openide.util.lookup.ProxyLookup;
31
import java.util.Arrays;
32
import java.util.HashMap;
33
34
/** 
35
 * This is base class for delegating to other looks. All methods are 
36
 * enumerated by numeric constants and by overriding <link>delegateTo</link>
37
 * subclasses can easily decide which methods and where delegate.
38
 * <P>
39
 * It is safe to assume that some of the functionality will be delegated
40
 * and some of it will not, but it is desirable to delegate the
41
 * <link>ATTACH_TO</link> to all looks because it allows the proxied looks 
42
 * to store information needed later. On the other hand not delegating
43
 * this call is possible if it is known that the proxied to look will
44
 * not need such informations later.
45
 * <P>
46
 * Also it is not suggested to switch the looks that is being delegated to
47
 * during different calls, because it can also result in calls to a look 
48
 * that has not have been attached by calling attachTo.
49
 * <P>
50
 * It is also possible to change the represented object for a looks 
51
 * those are being delegated to (see method <link>delegateObject</link>)
52
 * but again it is necessary to allow delegation of <link>ATTACH_TO</link>.
53
 *
54
 * @author Jaroslav Tulach
55
 */
56
public abstract class ProxyLook extends Look {
57
    /** Mask for enabling (unmasking) all methods */
58
    public static final long ALL_METHODS = Long.MAX_VALUE;
59
    /** Mask for disabling (masking) all methods */
60
    public static final long NO_METHODS = 0;
61
    /** Mask for the method {@link #getCookie}. */
62
    public static final long CREATE_LOOKUP = 1;
63
    /** Mask for the method {@link #getHandle}. */
64
//    public static final long GET_HANDLE = CREATE_LOOKUP << 1;
65
    /** Mask for the method {@link #getDisplayName}. */
66
    public static final long GET_DISPLAY_NAME = CREATE_LOOKUP << 1;
67
    /** Mask for the method {@link #getName}. */
68
    public static final long GET_NAME = GET_DISPLAY_NAME << 1;
69
    /** Mask for the method {@link #setName}. */
70
    public static final long SET_NAME = GET_NAME << 1;
71
    /** Mask for the method {@link #getShortDescription}. */
72
    public static final long GET_SHORT_DESCRIPTION = SET_NAME << 1;
73
    /** Mask for the method {@link #getIcon}. */
74
    public static final long GET_ICON = GET_SHORT_DESCRIPTION << 1;
75
    /** Mask for the method {@link #getOpenedIcon}. */
76
    public static final long GET_OPENED_ICON = GET_ICON << 1;
77
    /** Mask for the method {@link #getHelpCtx}. */
78
    public static final long GET_HELP_CTX = GET_OPENED_ICON << 1;
79
    /** Mask for the method {@link #getChildObjects}. */
80
    public static final long GET_CHILD_OBJECTS = GET_HELP_CTX << 1;
81
    /** Mask for the method {@link #getNewTypes}. */
82
    public static final long GET_NEW_TYPES = GET_CHILD_OBJECTS << 1;
83
    /** Mask for the method {@link #getActions}. */
84
    public static final long GET_ACTIONS = GET_NEW_TYPES << 1;
85
    /** Mask for the method {@link #getContextActions}. */
86
    public static final long GET_CONTEXT_ACTIONS = GET_ACTIONS << 1;
87
    /** Mask for the method {@link #getDefaultAction}. */
88
    public static final long GET_DEFAULT_ACTION = GET_CONTEXT_ACTIONS << 1;
89
    /** Mask for the method {@link #getPropertySets}. */
90
    public static final long GET_PROPERTY_SETS = GET_DEFAULT_ACTION << 1;
91
    /** Mask for the method {@link #getCustomizer}. */
92
    public static final long GET_CUSTOMIZER = GET_PROPERTY_SETS << 1;
93
    /** Mask for the method {@link #canRename}. */
94
    public static final long CAN_RENAME = GET_CUSTOMIZER << 1;
95
    /** Mask for the method {@link #canDestroy}. */
96
    public static final long CAN_DESTROY = CAN_RENAME << 1;
97
    /** Mask for the method {@link #canCopy}. */
98
    public static final long CAN_COPY = CAN_DESTROY << 1;
99
    /** Mask for the method {@link #canCut}. */
100
    public static final long CAN_CUT = CAN_COPY << 1;
101
    /** Mask for the method {@link #getPasteTypes}. */
102
    public static final long GET_PASTE_TYPES = CAN_CUT << 1;
103
    /** Mask for the method {@link #getDropType}. */
104
    public static final long GET_DROP_TYPE = GET_PASTE_TYPES << 1;
105
    /** Mask for the method {@link #clipboardCopy}. */
106
    public static final long CLIPBOARD_COPY = GET_DROP_TYPE << 1;
107
    /** Mask for the method {@link #clipboardCut}. */
108
    public static final long CLIPBOARD_CUT = CLIPBOARD_COPY << 1;
109
    /** Mask for the method {@link #drag}. */
110
    public static final long DRAG = CLIPBOARD_CUT << 1;
111
    /** Mask for the method {@link #destroy}. */
112
    public static final long DESTROY = DRAG << 1;
113
    /** Mask for the method {@link #hasCustomizer}. */
114
    public static final long HAS_CUSTOMIZER = DESTROY << 1;
115
    
116
    /** Creates new instance of look does no work.
117
     */
118
    public ProxyLook() {
119
    }
120
    
121
    /** A heart of this class -
122
     * method that can decide where to delegate approriate call. 
123
     * 
124
     * <P>
125
     * The default implementation ignores all parameters and just returns null
126
     * so no action is ever done.
127
     * Subclasses might override 
128
     * this method with implementation that bases its decision on different criteria.
129
     *
130
     * @param method one of the constants defined here that identifies the method
131
     *    we want to delegate to
132
     * @param substitute the substitute which method will be called with
133
     * @return the array of looks that we want to delegate to (may contain nulls on 
134
     *      places of looks we do not want to delegate to) or null if no delegation needed
135
     *
136
     * @warning the caller should maintain the delegates' positions in the returned
137
     * array and rather pass a null at some position, if the Look should not be delegated to,
138
     * instead of compacting of the array. The ProxyLook takes performance advantage from the
139
     * fact, that delegate positions are mostly the same.
140
     */
141
    protected Look[] delegateTo (long method, NodeSubstitute substitute) {
142
        return null;
143
    }
144
145
    /** Controls whether we delegate to all looks provided by <link>delegateTo</link>
146
     * method or just the first one that returns a value. Useful for methods that 
147
     * return an array of objects.
148
     * 
149
     * <P>
150
     * The default implementation return true to signal that we delegate to all.
151
     *
152
     * @param method one of the constants defined here that identifies the method
153
     *    we want to delegate to
154
     * @param substitute the substitute which method will be called with
155
     * @return true of false
156
     */
157
    protected boolean delegateAll (long method, NodeSubstitute substitute) {
158
        return true;
159
    }
160
    
161
    /** Extracts represented object for provided substitute.
162
     * <P>
163
     * Default implementation just calls substitute.getRepresentedObject (), but 
164
     * subclasses might use this method to change the represented object
165
     * for the look they delegate to.
166
     *
167
     * @param substitute the substitute to find represented object for
168
     * @return the represented object for the substitute (not null)
169
     */
170
    protected Object delegateObject (NodeSubstitute substitute) {
171
        return substitute.getRepresentedObject ();
172
    }
173
    
174
    // General methods ---------------------------------------------------------
175
    
176
    /** Performs specialized setup for the ProxyLook. Subclasses may receive
177
     * attach notification when they override {@link #proxyAttachTo} instead of 
178
     * this method.
179
     * @return opaque data needed by the ProxyLook implementation.
180
     */
181
    protected final Object attachTo(Look.NodeSubstitute substitute) {
182
        // Cannot be overriden because it performs important action of 
183
        // creating substitute S, without it the look we delegate to will
184
        // not work correctly
185
        Object o = super.attachTo(substitute);
186
        return new Object[] {
187
            new Object[0], o
188
        };
189
    }
190
        
191
    /**
192
     * Retrieves the data attached to the particular NodeSubstitute for the
193
     * ProxyLook itself.
194
     * @return the attached data Object, or null if no data was attached.
195
     */
196
    protected final Object getAttachedData(Look.NodeSubstitute subst) {
197
        Object o = super.getAttachedData(subst);
198
        if (!(o instanceof Object[])) {
199
            return null;
200
        }
201
        
202
        Object[] a = (Object[])o;
203
        if (a.length > 1) {
204
            return a[1];
205
        } else
206
            return null;
207
    }
208
    
209
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
210
     */
211
    public Lookup createLookup (Look.NodeSubstitute substitute) {
212
        Look[] delegate = delegateTo (CREATE_LOOKUP, substitute);
213
        if (delegate != null && delegate.length > 0) {
214
            if (delegate.length == 1) {
215
                return delegate[0] == null ? null : delegate[0].createLookup (s (substitute, delegate[0], 0));
216
            } else {
217
                ArrayList ll = new ArrayList (delegate.length);
218
                for (int i = 0; i < delegate.length; i++) {
219
                    Lookup lookup = delegate[i] == null ? null : delegate[i].createLookup (s (substitute, delegate[i], i));
220
                    if (lookup != null) {
221
                        ll.add (lookup);
222
                    }
223
                }
224
                
225
                if (ll.size () > 0) {
226
                    Lookup[] arr = new Lookup[ll.size ()];
227
                    ll.toArray (arr);
228
                    return new ProxyLookup (arr);
229
                } else {
230
                    return null;
231
                }
232
            }
233
        } else {
234
            return null;
235
        }
236
    }
237
238
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
239
     */
240
    public Look[] availableLooks(Look.NodeSubstitute substitute) {
241
        return null;
242
    }
243
    
244
    // Methods for STYLE -------------------------------------------------------
245
    
246
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
247
     */
248
    public String getDisplayName( Look.NodeSubstitute substitute ) {
249
        Look[] delegate = delegateTo (GET_DISPLAY_NAME, substitute);
250
        if (delegate != null) {
251
            for (int i = 0; i < delegate.length; i++) {
252
                if (delegate[i] != null) {
253
                    String h = delegate[i].getDisplayName (s (substitute, delegate[i], i));
254
                    if (h != null) {
255
                        return h;
256
                    }
257
                }
258
            }
259
        }
260
        return null;
261
    }
262
    
263
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
264
     */
265
    public String getName( Look.NodeSubstitute substitute ) {
266
        Look[] delegate = delegateTo (GET_NAME, substitute);
267
        if (delegate != null) {
268
            for (int i = 0; i < delegate.length; i++) {
269
                if (delegate[i] != null) {
270
                    String h = delegate[i].getName (s (substitute, delegate[i], i));
271
                    if (h != null) {
272
                        return h;
273
                    }
274
                }
275
            }
276
        }
277
        return null;
278
    }
279
    
280
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
281
     */
282
    public void setName(Look.NodeSubstitute substitute, String newName) {
283
        Look[] delegate = delegateTo (SET_NAME, substitute);
284
        if (delegate != null) {
285
            for (int i = 0; i < delegate.length; i++) {
286
                if (delegate[i] != null) {
287
                    delegate[i].setName (s (substitute, delegate[i], i), newName);
288
                }
289
            }
290
        }
291
    }
292
    
293
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
294
     */
295
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
296
        Look[] delegate = delegateTo (GET_SHORT_DESCRIPTION, substitute);
297
        if (delegate != null) {
298
            for (int i = 0; i < delegate.length; i++) {
299
                if (delegate[i] != null) {
300
                    String h = delegate[i].getShortDescription (s (substitute, delegate[i], i));
301
                    if (h != null) {
302
                        return h;
303
                    }
304
                }
305
            }
306
        }
307
        return null;
308
    }
309
    
310
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
311
     */
312
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
313
        Look[] delegate = delegateTo (GET_ICON, substitute);
314
        if (delegate != null) {
315
            for (int i = 0; i < delegate.length; i++) {
316
                if (delegate[i] != null) {
317
                    Image h = delegate[i].getIcon (s (substitute, delegate[i], i), type);
318
                    if (h != null) {
319
                        return h;
320
                    }
321
                }
322
            }
323
        }
324
        return null;
325
    }
326
    
327
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
328
     */
329
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
330
        Look[] delegate = delegateTo (GET_OPENED_ICON, substitute);
331
        if (delegate != null) {
332
            for (int i = 0; i < delegate.length; i++) {
333
                if (delegate[i] != null) {
334
                    Image h = delegate[i].getOpenedIcon (s (substitute, delegate[i], i), type);
335
                    if (h != null) {
336
                        return h;
337
                    }
338
                }
339
            }
340
        }
341
        return null;
342
    }
343
    
344
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
345
     */
346
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
347
        Look[] delegate = delegateTo (GET_HELP_CTX, substitute);
348
        if (delegate != null) {
349
            for (int i = 0; i < delegate.length; i++) {
350
                if (delegate[i] != null) {
351
                    HelpCtx h = delegate[i].getHelpCtx (s (substitute, delegate[i], i));
352
                    if (h != null) {
353
                        return h;
354
                    }
355
                }
356
            }
357
        }
358
        return null;
359
    }
360
    
361
    // Methods for CHILDREN ----------------------------------------------------
362
    
363
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
364
     */
365
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
366
        Look[] delegate = delegateTo (GET_CHILD_OBJECTS, substitute);
367
368
        if (delegate == null) {
369
            return null;
370
        }
371
372
        boolean merge = delegateAll (GET_CHILD_OBJECTS, substitute);
373
        
374
        Object arrays = null;
375
        
376
        // Create list of subarrays        
377
        for (int i = 0; i < delegate.length; i++) {
378
            Look look = delegate[i];
379
            if (look == null) {
380
                continue;
381
            }
382
            
383
            Object data[] = look.getChildObjects (s (substitute, delegate[i], i));
384
            if (data == null || data.length == 0 ) {
385
                continue; 
386
            }
387
            
388
            if (!merge) {
389
                // we are not merging and need keys just by one look 
390
                return data;
391
            }
392
            
393
            // add all those objects into array
394
            if (arrays == null) {
395
                arrays = data;
396
            } else {
397
                ArrayList l;
398
                if (arrays instanceof Object[]) {
399
                    // arrays contains Object[] convert to ArrayList
400
                    Object[] arr = (Object[])arrays;
401
                    l = new ArrayList (arr.length * 2);
402
                    l.addAll (Arrays.asList (arr));
403
                    arrays = l;
404
                } else {
405
                    l = (ArrayList)arrays;
406
                }
407
                l.addAll (Arrays.asList (data));
408
            }
409
        }
410
        
411
        if (arrays == null) {
412
            // Return if there is nothing to merge
413
            return null;
414
        }
415
       
416
        return arrays instanceof Object[] ? (Object[])arrays : ((ArrayList)arrays).toArray ();
417
    }
418
    
419
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
420
    
421
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
422
     */
423
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
424
        Look[] delegate = delegateTo (GET_NEW_TYPES, substitute);
425
426
        if (delegate == null) {
427
            return null;
428
        }
429
430
        boolean merge = delegateAll (GET_NEW_TYPES, substitute);
431
        
432
        Object arrays = null;
433
        
434
        // Create list of subarrays        
435
        for (int i = 0; i < delegate.length; i++) {
436
            Look look = delegate[i];
437
            if (look == null) {
438
                continue;
439
            }
440
            
441
            NewType[] data = look.getNewTypes (s (substitute, delegate[i], i));
442
            if (data == null || data.length == 0 ) {
443
                continue; 
444
            }
445
            
446
            if (!merge) {
447
                // we are not merging and need keys just by one look 
448
                return data;
449
            }
450
            
451
            // add all those objects into array
452
            if (arrays == null) {
453
                arrays = data;
454
            } else {
455
                ArrayList l;
456
                if (arrays instanceof Object[]) {
457
                    // arrays contains Object[] convert to ArrayList
458
                    Object[] arr = (Object[])arrays;
459
                    l = new ArrayList (arr.length * 2);
460
                    l.addAll (Arrays.asList (arr));
461
                    arrays = l;
462
                } else {
463
                    l = (ArrayList)arrays;
464
                }
465
                l.addAll (Arrays.asList (data));
466
            }
467
        }
468
        
469
        if (arrays == null) {
470
            // Return if there is nothing to merge
471
            return null;
472
        }
473
       
474
        return arrays instanceof NewType[] ? (NewType[])arrays : (NewType[])((ArrayList)arrays).toArray (new NewType[0]);
475
    }
476
    
477
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
478
     */
479
    public Action[] getActions( Look.NodeSubstitute substitute ) {
480
        Look[] delegate = delegateTo (GET_ACTIONS, substitute);
481
482
        if (delegate == null) {
483
            return null;
484
        }
485
486
        boolean merge = delegateAll (GET_ACTIONS, substitute);
487
        
488
        Object arrays = null;
489
        
490
        // Create list of subarrays        
491
        for (int i = 0; i < delegate.length; i++) {
492
            Look look = delegate[i];
493
            if (look == null) {
494
                continue;
495
            }
496
            
497
            Action[] data = look.getActions (s (substitute, delegate[i], i));
498
            if (data == null || data.length == 0 ) {
499
                continue; 
500
            }
501
            
502
            if (!merge) {
503
                // we are not merging and need keys just by one look 
504
                return data;
505
            }
506
            
507
            // add all those objects into array
508
            if (arrays == null) {
509
                arrays = data;
510
            } else {
511
                ArrayList l;
512
                if (arrays instanceof Object[]) {
513
                    // arrays contains Object[] convert to ArrayList
514
                    Object[] arr = (Object[])arrays;
515
                    l = new ArrayList (arr.length * 2);
516
                    l.addAll (Arrays.asList (arr));
517
                    arrays = l;
518
                } else {
519
                    l = (ArrayList)arrays;
520
                }
521
                l.addAll (Arrays.asList (data));
522
            }
523
        }
524
        
525
        if (arrays == null) {
526
            // Return if there is nothing to merge
527
            return null;
528
        }
529
       
530
        return arrays instanceof Action[] ? (Action[])arrays : (Action[])((ArrayList)arrays).toArray (new Action[0]);
531
    }
532
    
533
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
534
     */
535
    public Action[] getContextActions( Look.NodeSubstitute substitute ) {
536
        Look[] delegate = delegateTo (GET_CONTEXT_ACTIONS, substitute);
537
538
        if (delegate == null) {
539
            return null;
540
        }
541
542
        boolean merge = delegateAll (GET_CONTEXT_ACTIONS, substitute);
543
        
544
        Object arrays = null;
545
        
546
        // Create list of subarrays        
547
        for (int i = 0; i < delegate.length; i++) {
548
            Look look = delegate[i];
549
            if (look == null) {
550
                continue;
551
            }
552
            
553
            Action[] data = look.getContextActions (s (substitute, delegate[i], i));
554
            if (data == null || data.length == 0 ) {
555
                continue; 
556
            }
557
            
558
            if (!merge) {
559
                // we are not merging and need keys just by one look 
560
                return data;
561
            }
562
            
563
            // add all those objects into array
564
            if (arrays == null) {
565
                arrays = data;
566
            } else {
567
                ArrayList l;
568
                if (arrays instanceof Object[]) {
569
                    // arrays contains Object[] convert to ArrayList
570
                    Object[] arr = (Object[])arrays;
571
                    l = new ArrayList (arr.length * 2);
572
                    l.addAll (Arrays.asList (arr));
573
                    arrays = l;
574
                } else {
575
                    l = (ArrayList)arrays;
576
                }
577
                l.addAll (Arrays.asList (data));
578
            }
579
        }
580
        
581
        if (arrays == null) {
582
            // Return if there is nothing to merge
583
            return null;
584
        }
585
       
586
        return arrays instanceof Action[] ? (Action[])arrays : (Action[])((ArrayList)arrays).toArray (new Action[0]);
587
    }
588
    
589
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
590
     */
591
    public Action getDefaultAction( Look.NodeSubstitute substitute ) {
592
        Look[] delegate = delegateTo (GET_DEFAULT_ACTION, substitute);
593
        if (delegate != null) {
594
            for (int i = 0; i < delegate.length; i++) {
595
                if (delegate[i] != null) {
596
                    Action h = delegate[i].getDefaultAction (s (substitute, delegate[i], i));
597
                    if (h != null) {
598
                        return h;
599
                    }
600
                }
601
            }
602
        }
603
        return null;
604
    }
605
    
606
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
607
    
608
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
609
     */
610
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
611
        Look[] delegate = delegateTo (GET_PROPERTY_SETS, substitute);
612
        if (delegate == null) {
613
            return null;
614
        }
615
        
616
        boolean merge = delegateAll (GET_PROPERTY_SETS, substitute);
617
        
618
        ArrayList setsList = null;
619
        HashMap nameMap = null;
620
        
621
        // Create list of property sets and the name map
622
        for (int index = 0; index < delegate.length; index++) {
623
            Look look = delegate[index];
624
            if (look == null) {
625
                continue;
626
            }
627
628
            Node.PropertySet[] sets = look.getPropertySets( s (substitute, delegate[index], index) );
629
            if ( sets == null || sets.length == 0 ) {
630
                continue; // Look does not provide any properties
631
            }
632
            
633
            if (!merge) {
634
                // no need to do merging, return the first reasonable value
635
                return sets;
636
            }
637
            
638
            if (setsList == null) {
639
                if (index + 1 == delegate.length) {
640
                    // I am the last look in the raw, no need to do merging
641
                    return sets;
642
                }
643
                setsList = new ArrayList ();
644
                nameMap = new HashMap (37);
645
            }
646
                
647
            
648
            // Merge the property sets. We use sheet sets for
649
            // more comfortable work with propertySets
650
            for ( int i = 0; i < sets.length; i++ ) {
651
                if ( sets[i].getName() == null ) {
652
                    continue; // Ignore unnamed lists
653
                }
654
                Sheet.Set es = (Sheet.Set)nameMap.get( sets[i].getName() );
655
                if ( es == null ) { //Such sheet does not exist yet
656
                    es = new Sheet.Set( );
657
                    es.setName( sets[i].getName() );
658
                    es.setDisplayName( sets[i].getDisplayName() );
659
                    es.setShortDescription( sets[i].getShortDescription() );
660
                    es.put( sets[i].getProperties() );
661
                    setsList.add( es );
662
                    nameMap.put( sets[i].getName(), es );
663
                }
664
                else { // Sheet exists => merge properties
665
                    Node.Property[] props = sets[i].getProperties();
666
                    if ( props == null || props.length == 0 ) {
667
                        continue;
668
                    }
669
                    else {
670
                        es.put( sets[i].getProperties() );
671
                    }
672
                }                
673
            }        
674
        }
675
        
676
        if ( setsList == null || setsList.size() == 0 ) {
677
            return null;
678
        }
679
        else {
680
            Node.PropertySet[] result = new Node.PropertySet[ setsList.size() ];
681
            setsList.toArray( result );
682
            return result;
683
        }
684
    }
685
    
686
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
687
     */
688
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
689
        Look[] delegate = delegateTo (GET_CUSTOMIZER, substitute);
690
        if (delegate != null) {
691
            for (int i = 0; i < delegate.length; i++) {
692
                if (delegate[i] != null) {
693
                    java.awt.Component h = delegate[i].getCustomizer (s (substitute, delegate[i], i));
694
                    if (h != null) {
695
                        return h;
696
                    }
697
                }
698
            }
699
        }
700
        return null;
701
    }
702
    
703
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
704
     */
705
    public boolean hasCustomizer( Look.NodeSubstitute substitute ) {        
706
        Look[] delegate = delegateTo (HAS_CUSTOMIZER, substitute);
707
        if (delegate != null) {
708
            for (int i = 0; i < delegate.length; i++) {
709
                if (delegate[i] != null) {
710
                    if (delegate[i].hasCustomizer (s (substitute, delegate[i], i))) {
711
                        return true;
712
                    }
713
                }
714
            }
715
        }
716
        return false;
717
    }
718
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
719
     
720
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning false)
721
     */
722
    public boolean canRename( Look.NodeSubstitute substitute ) {
723
        Look[] delegate = delegateTo (CAN_RENAME, substitute);
724
        if (delegate != null) {
725
            for (int i = 0; i < delegate.length; i++) {
726
                if (delegate[i] != null) {
727
                    boolean b = delegate[i].canRename (s (substitute, delegate[i], i));
728
                    if (b) {
729
                        return true;
730
                    }
731
                }
732
            }
733
        }
734
        return false;
735
    }
736
    
737
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning false)
738
     */
739
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
740
        Look[] delegate = delegateTo (CAN_DESTROY, substitute);
741
        if (delegate != null) {
742
            for (int i = 0; i < delegate.length; i++) {
743
                if (delegate[i] != null) {
744
                    boolean b = delegate[i].canDestroy (s (substitute, delegate[i], i));
745
                    if (b) {
746
                        return true;
747
                    }
748
                }
749
            }
750
        }
751
        return false;
752
    }
753
    
754
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning false)
755
     */
756
    public boolean canCopy( Look.NodeSubstitute substitute ) {
757
        Look[] delegate = delegateTo (CAN_COPY, substitute);
758
        if (delegate != null) {
759
            for (int i = 0; i < delegate.length; i++) {
760
                if (delegate[i] != null) {
761
                    boolean b = delegate[i].canCopy (s (substitute, delegate[i], i));
762
                    if (b) {
763
                        return true;
764
                    }
765
                }
766
            }
767
        }
768
        return false;
769
    }
770
    
771
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning false)
772
     */
773
    public boolean canCut( Look.NodeSubstitute substitute ) {
774
        Look[] delegate = delegateTo (CAN_CUT, substitute);
775
        if (delegate != null) {
776
            for (int i = 0; i < delegate.length; i++) {
777
                if (delegate[i] != null) {
778
                    boolean b = delegate[i].canCut (s (substitute, delegate[i], i));
779
                    if (b) {
780
                        return true;
781
                    }
782
                }
783
            }
784
        }
785
        return false;
786
    }
787
    
788
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
789
     */
790
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
791
        Look[] delegate = delegateTo (GET_PASTE_TYPES, substitute);
792
793
        if (delegate == null) {
794
            return null;
795
        }
796
797
        boolean merge = delegateAll (GET_PASTE_TYPES, substitute);
798
        
799
        Object arrays = null;
800
        
801
        // Create list of subarrays        
802
        for (int i = 0; i < delegate.length; i++) {
803
            Look look = delegate[i];
804
            if (look == null) {
805
                continue;
806
            }
807
            
808
            PasteType[] data = look.getPasteTypes (s (substitute, delegate[i], i), t);
809
            if (data == null || data.length == 0 ) {
810
                continue; 
811
            }
812
            
813
            if (!merge) {
814
                // we are not merging and need keys just by one look 
815
                return data;
816
            }
817
            
818
            // add all those objects into array
819
            if (arrays == null) {
820
                arrays = data;
821
            } else {
822
                ArrayList l;
823
                if (arrays instanceof Object[]) {
824
                    // arrays contains Object[] convert to ArrayList
825
                    Object[] arr = (Object[])arrays;
826
                    l = new ArrayList (arr.length * 2);
827
                    l.addAll (Arrays.asList (arr));
828
                    arrays = l;
829
                } else {
830
                    l = (ArrayList)arrays;
831
                }
832
                l.addAll (Arrays.asList (data));
833
            }
834
        }
835
        
836
        if (arrays == null) {
837
            // Return if there is nothing to merge
838
            return null;
839
        }
840
       
841
        return arrays instanceof PasteType[] ? (PasteType[])arrays : (PasteType[])((ArrayList)arrays).toArray (new PasteType[0]);
842
    }
843
    
844
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
845
     */
846
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
847
        Look[] delegate = delegateTo (GET_DROP_TYPE, substitute);
848
        if (delegate != null) {
849
            for (int i = 0; i < delegate.length; i++) {
850
                if (delegate[i] != null) {
851
                    PasteType b = delegate[i].getDropType (s (substitute, delegate[i], i), t, action, index);
852
                    if (b != null) {
853
                        return b;
854
                    }
855
                }
856
            }
857
        }
858
        return null;
859
    }
860
    
861
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
862
     */
863
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
864
        Look[] delegate = delegateTo (CLIPBOARD_COPY, substitute);
865
        if (delegate != null) {
866
            for (int i = 0; i < delegate.length; i++) {
867
                if (delegate[i] != null) {
868
                    Transferable b = delegate[i].clipboardCopy (s (substitute, delegate[i], i));
869
                    if (b != null) {
870
                        return b;
871
                    }
872
                }
873
            }
874
        }
875
        return null;
876
    }
877
    
878
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
879
     */
880
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
881
        Look[] delegate = delegateTo (CLIPBOARD_CUT, substitute);
882
        if (delegate != null) {
883
            for (int i = 0; i < delegate.length; i++) {
884
                if (delegate[i] != null) {
885
                    Transferable b = delegate[i].clipboardCut (s (substitute, delegate[i], i));
886
                    if (b != null) {
887
                        return b;
888
                    }
889
                }
890
            }
891
        }
892
        return null;
893
    }
894
    
895
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
896
     */
897
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
898
        Look[] delegate = delegateTo (DRAG, substitute);
899
        if (delegate != null) {
900
            for (int i = 0; i < delegate.length; i++) {
901
                if (delegate[i] != null) {
902
                    Transferable b = delegate[i].drag (s (substitute, delegate[i], i));
903
                    if (b != null) {
904
                        return b;
905
                    }
906
                }
907
            }
908
        }
909
        return null;
910
    }
911
        
912
    /** Delegates to delegate or does neutral behaviour (doing nothing, returning null)
913
     */
914
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
915
        Look[] delegate = delegateTo (DESTROY, substitute);
916
        if (delegate != null) {
917
            for (int i = 0; i < delegate.length; i++) {
918
                if (delegate[i] != null) {
919
                    delegate[i].destroy (s (substitute, delegate[i], i));
920
                }
921
            }
922
        }
923
    }
924
925
    /** Method that tries to get the right substitute S from given substitute.
926
     */
927
    private Look.NodeSubstitute s (Look.NodeSubstitute subst, Look l, int index) {
928
        Object[] holder = (Object[])ProxyLook.super.getAttachedData(subst);
929
        synchronized (holder) {
930
            Object[] arr = (Object[])holder[0];
931
            if (index < arr.length) {
932
                Look.NodeSubstitute ns = (Look.NodeSubstitute)arr[index];
933
                if (ns != null && ns.getLook() == l ) {
934
                    // we already have seen/initialized this Look.
935
                    return ns;
936
                }
937
            } else {
938
                Object[] newSubst = new Object[index + 1];
939
                System.arraycopy(arr, 0, newSubst, 0, arr.length);
940
                holder[0] = arr = newSubst;
941
            }
942
            S s = new S (l, subst);
943
            arr[index] = s;
944
            return s;
945
        }
946
    }
947
    
948
    // Innerclasses ------------------------------------------------------------
949
    
950
    /** Our special substitute to filter events fired from the underlaying look
951
     * and also to store its special attached data.
952
     */
953
    final class S extends Look.NodeSubstitute {
954
        /** substitute we represent it will contain reference to us in getAttachedData */
955
        private Look.NodeSubstitute substitute;
956
        
957
        S (Look look, Look.NodeSubstitute substitute) {
958
            this.substitute = substitute;
959
            
960
            super.attachTo (look);
961
        }
962
        
963
        /** Returns the object represented by the node
964
         * @return Object represented by the node this interior belongs to.
965
         */
966
        public Object getRepresentedObject() {
967
            return delegateObject (substitute);
968
        }        
969
        
970
        /** Fires a (Bean) property change event (for
971
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
972
         * @param o the old set
973
         * @param n the new set
974
         */
975
        public void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n) {
976
            Look[] delegate = delegateTo (GET_PROPERTY_SETS, this) ;
977
            if (doFire (delegate)) {
978
                substitute.firePropertySetsChange( o, n );
979
            }
980
        }
981
        
982
        /** Fires the Event notificationg about name change.
983
         */
984
        public void fireNameChange(String o, String n) {
985
            Look[] delegate = delegateTo (GET_NAME, this) ;
986
            if (doFire (delegate)) {
987
                substitute.fireNameChange( o, n );
988
            }
989
        }
990
        
991
        /** Fires the Event notificationg about display name change.
992
         */
993
        public void fireDisplayNameChange(String o, String n) {
994
            Look[] delegate = delegateTo (GET_DISPLAY_NAME, this) ;
995
            if (doFire (delegate)) {
996
                substitute.fireDisplayNameChange( o, n );
997
            }
998
        }
999
        
1000
        /** Tells the node that the children have to be refreshed.
1001
         */
1002
        public void refreshChildren() {
1003
            Look[] delegate = delegateTo (GET_CHILD_OBJECTS, this) ;
1004
            if (doFire (delegate)) {
1005
                substitute.refreshChildren( );
1006
            }
1007
        }
1008
        
1009
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
1010
         * associated node.
1011
         */
1012
        public void fireOpenedIconChange() {
1013
            Look[] delegate = delegateTo (GET_OPENED_ICON, this) ;
1014
            if (doFire (delegate)) {
1015
                substitute.fireOpenedIconChange();
1016
            }
1017
        }
1018
        
1019
        /** To all node listeners fire node destroyed notification.
1020
         */
1021
        public void fireNodeDestroyed() {
1022
            Look[] delegate = delegateTo (DESTROY, this) ;
1023
            if (doFire (delegate)) {
1024
                substitute.fireNodeDestroyed();
1025
            }
1026
        }
1027
        
1028
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
1029
         * associated node.
1030
         */
1031
        public void fireIconChange() {
1032
            Look[] delegate = delegateTo (GET_ICON, this) ;
1033
            if (doFire (delegate)) {
1034
                substitute.fireIconChange();
1035
            }
1036
        }
1037
        
1038
        /** Fires the Event notificationg about short description change.
1039
         */
1040
        public void fireShortDescriptionChange(String o, String n) {
1041
            Look[] delegate = delegateTo (GET_SHORT_DESCRIPTION, this) ;
1042
            if (doFire (delegate)) {
1043
                substitute.fireShortDescriptionChange( o, n );
1044
            }
1045
        }
1046
        
1047
        /** Fire a property change event on the associated node.
1048
         * @param name name of changed property (from {@link #getPropertySets})
1049
         * @param o old value
1050
         * @param n new value
1051
         */
1052
        public void firePropertyChange(String name, Object o, Object n) {
1053
            Look[] delegate = delegateTo (GET_PROPERTY_SETS, this) ;
1054
            if (doFire (delegate)) {
1055
                substitute.firePropertyChange( name, o, n );
1056
            }
1057
        }
1058
        
1059
        /** Do fire. 
1060
         */
1061
        private boolean doFire (Look[] arr) {
1062
            if (arr == null) return false;
1063
            
1064
            for (int i = 0; i < arr.length; i++) {
1065
                if (arr[i] != null) return true;
1066
            }
1067
            return false;
1068
        }
1069
        
1070
    } // end of S
1071
    
1072
1073
}
(-)openidex/looks/test/.cvsignore (-4 lines)
Removed Link Here
1
CVS
2
lib
3
results
4
work
(-)openidex/looks/test/build.xml (-249 lines)
Removed Link Here
1
<?xml version="1.0"?>
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
15
<project name="looks tests" basedir="." default="all">
16
17
    <property name="build.sysclasspath" value="ignore"/>
18
19
    <property name="netbeans.home" location="../../../nbbuild/netbeans"/>
20
    <property name="netbeans.test.home" value="${netbeans.home}"/>
21
    
22
    <!-- says how to create classpath for code tests -->
23
    <!-- can have values src, jar, ide               -->
24
    <property name="xtest.source.location" value="src"/>
25
    
26
    <property name="xtest.home" location="../../../xtest"/>
27
28
    <property name="xtest.build" location="."/>    
29
    <property name="xtest.file.name" value="test.jar"/>
30
    <property name="xtest.file.location" value="lib"/>
31
    
32
    <!-- default testtypes, attributes and executors -->
33
    <property name="xtest.testtype" value="unit"/>
34
    <property name="xtest.attribs" value="stable"/>
35
    <property name="xtest.executors" value="code"/>
36
    
37
    <!-- properties just for compiler -->
38
    <property name="build.compiler.deprecation" value="off"/>
39
    <!-- should be default ON, because it helps to find problems -->
40
    <property name="build.compiler.debug" value="on"/>
41
    
42
    <!-- These in/excludes will be added to xtest.pattern    -->
43
    <!-- if you want to use these properties, you should use -->
44
    <!-- config with empty testbag                           -->
45
    <property name="xtest.includes" value=""/>
46
    <property name="xtest.excludes" value=""/>   
47
    
48
    <property name="xtest.general.antfile" location="${xtest.home}/lib/module_harness.xml"/>
49
    
50
    <!-- =========== -->
51
    <!-- Init target -->
52
    <!-- =========== -->
53
    
54
    <target name="init">
55
        <taskdef name="nbpath" classname="org.netbeans.xtest.NbPath" classpath="${xtest.home}/lib/xtest.jar"/>
56
        <nbpath nbhome="${netbeans.test.home}" xthome="${xtest.home}" xtexhome="${xtest.home}"/>
57
    </target>
58
    
59
    <!-- ============ -->
60
    <!-- Main targets -->
61
    <!-- ============ -->
62
    
63
    <target name="all" depends="runtests"/>
64
    
65
    <!-- This target builds tests -->
66
    <target name="buildtests" depends="prepare-compile-classpath">
67
       <!-- This calls common build process. -->
68
       <!-- You can write your own is you need something special -->
69
       <property name="compiletest.classpath" refid="compiletest.classpath"/>
70
       <ant dir="." antfile="${xtest.general.antfile}"
71
             target="buildtests">
72
           <property name="compile.srcdir" value="unit/src"/>
73
       </ant>
74
    </target>
75
    
76
    <!-- This target cleans tests -->
77
    <target name="cleantests">
78
       <!-- This calls common clean process. -->
79
       <!-- You can write your own is you need something special -->
80
       <ant dir="." antfile="${xtest.general.antfile}"
81
             target="cleantests">
82
       </ant>
83
    </target> 
84
85
    <!-- This target runs tests. You should not change this --> 
86
    <!-- target unless you realy know what you are doing -->
87
    <target name="runtests" depends="cleanresults,buildtests">
88
        <ant dir="." antfile="${xtest.general.antfile}"
89
             target="runtests"/>
90
    </target>
91
    
92
    <!-- This target is executed from test-executor in newly created Project -->
93
    <!-- Name of this task is defined in cfg-xxx.xml -->
94
    <!-- This target executes tests inside IDE -->
95
    <target name="runidetest">
96
        <property name="idetest.classpath" value=""/>
97
        <ant dir="." antfile="${xtest.general.antfile}"
98
             target="test">
99
           <property name="xtest.exectype" value="ide"/>
100
           <property name="xtest.ide.commandline.suffix" value="-J-Dxtest.useclassloader=org.openidex.util -J-Xdebug"/>
101
        </ant>
102
    </target>
103
    
104
    <!-- This target is executed from test-executor in newly created Project -->
105
    <!-- Name of this task is defined in cfg-xxx.xml -->
106
    <!-- This target executes standalone tests -->
107
    <target name="runcodetest" depends="prepare-codetest-classpath">
108
        <path id="codetest.complete.classpath">
109
          <path refid="codetest.classpath"/>
110
          <pathelement path="${tbag.classpath}"/>
111
        </path>
112
        <property name="codetest.classpath" refid="codetest.complete.classpath"/>
113
        <ant dir="." antfile="${xtest.general.antfile}"
114
             target="test">
115
           <property name="xtest.exectype" value="code"/>
116
        </ant>
117
    </target>
118
    
119
    <!-- This target is executed from test-executor in newly created Project -->
120
    <!-- Name of this task is defined in cfg-xxx.xml -->
121
    <target name="test_report">
122
        <ant dir="." antfile="${xtest.general.antfile}"
123
             target="test_report"/>
124
    </target>
125
    
126
    <target name="cleanresults">
127
        <ant dir="." antfile="${xtest.general.antfile}"
128
             target="cleanresults"/>
129
    </target>
130
    
131
    <target name="realclean" depends="cleantests,cleanresults">
132
        <ant dir="." antfile="${xtest.general.antfile}"
133
             target="realclean"/>
134
    </target>
135
    
136
    <target name="printconfig">
137
        <echo message="Default config is testtype: ${xtest.testtype}, attributes: ${xtest.attribs}."/>
138
    </target>
139
140
   <!-- ========================================================== -->
141
   <!-- ========================================================== -->
142
143
    <target name="which-classpath">
144
        <!-- this "switch" will decide how to create classpath for code tests -->
145
        <condition property="jarcode.classpath">
146
            <equals arg1="${xtest.source.location}" arg2="jar"/>
147
        </condition>
148
        <condition property="srccode.classpath">
149
            <equals arg1="${xtest.source.location}" arg2="src"/>
150
        </condition>
151
        <condition property="idecode.classpath">
152
            <equals arg1="${xtest.source.location}" arg2="ide"/>
153
        </condition>
154
    </target>
155
156
    <!-- ========================= -->
157
    <!-- Classpath for compilation -->
158
    <!-- ========================= -->
159
    
160
    <target name="prepare-compile-classpath"
161
         depends="jarcompile-classpath,srccompile-classpath,idecompile-classpath"/>
162
    
163
    <target name="jarcompile-classpath" depends="init,which-classpath" if="jarcode.classpath">
164
        <echo message="Using jars classpath for compilation."/>
165
    	<!-- this classpath will be used for compiling tests against jars -->
166
	<path id="compiletest.classpath">        
167
	    <pathelement location="../netbeans/modules/autoload/looks.jar"/>
168
	        <fileset dir="../../../openide/netbeans/lib">
169
                    <include name="openide*.jar"/>
170
                </fileset>
171
	    <pathelement path="${junit.path}"/>
172
	    <pathelement path="${xerces.path}"/>
173
	</path>
174
    </target>
175
        
176
    <target name="srccompile-classpath" depends="init,which-classpath" if="srccode.classpath">
177
        <echo message="Using srcs classpath for compilation."/>
178
    	<!-- this classpath will be used for compiling tests against sources -->
179
    	<path id="compiletest.classpath">        
180
	        <pathelement location="../src"/>
181
	        <fileset dir="../../../openide/netbeans/lib">
182
                    <include name="openide*.jar"/>
183
                </fileset>
184
	        <pathelement path="${junit.path}"/>
185
		<pathelement path="${xerces.path}"/>
186
	</path>
187
    </target>
188
    
189
    <target name="idecompile-classpath" depends="init,which-classpath" if="idecode.classpath">
190
        <echo message="Using IDE classpath for compilation."/>
191
    	<!-- this classpath will be used for compiling tests against installed IDE -->
192
    	<path id="compiletest.classpath">        
193
	        <pathelement location="${netbeans.home}/modules/autoload/looks.jar"/>
194
	        <fileset dir="${netbeans.home}/lib">
195
                    <include name="openide*.jar"/>
196
                </fileset>
197
	        <pathelement path="${junit.path}"/>
198
		<pathelement path="${xerces.path}"/>
199
   	</path>
200
    </target>
201
    
202
    <!-- ================================== -->
203
    <!-- Classpath for execution code tests -->
204
    <!-- ================================== -->
205
    
206
    <target name="prepare-codetest-classpath" 
207
            depends="jartest-classpath,srctest-classpath,idetest-classpath"/>
208
    
209
    <target name="jartest-classpath" depends="which-classpath" if="jarcode.classpath">
210
        <echo message="Using jars classpath."/>
211
        <!-- this classpath will be used for executing tests against jars -->
212
	<path id="codetest.classpath">
213
	        <pathelement location="../netbeans/modules/autoload/looks.jar"/>
214
	        <pathelement location="../../../openide/netbeans/lib/openide.jar"/>
215
	        <fileset dir="../../../core/netbeans/lib">
216
            		<include name="core.jar"/>
217
            		<include name="ext/*.jar"/>
218
        	</fileset>
219
    	</path>
220
    </target>
221
        
222
    <target name="srctest-classpath" depends="which-classpath" if="srccode.classpath">
223
        <echo message="Using srcs classpath."/>
224
        <!-- this classpath will be used for executing tests against sources -->
225
    	<path id="codetest.classpath">
226
	        <pathelement location="../src"/>
227
	        <pathelement location="../../../openide/netbeans/lib/openide.jar"/>
228
	        <fileset dir="../../../core/netbeans/lib">
229
            		<include name="core.jar"/>
230
            		<include name="ext/*.jar"/>
231
        	</fileset>
232
    	</path>
233
    </target>
234
    
235
    <target name="idetest-classpath" depends="which-classpath" if="idecode.classpath">
236
        <echo message="Using IDE classpath."/>
237
        <!-- this classpath will be used for executing tests against installed IDE -->
238
    	<path id="codetest.classpath">
239
	        <pathelement location="${netbeans.home}/modules/autoload/looks.jar"/>
240
	        <pathelement location="${netbeans.home}/lib/openide.jar"/>
241
          	<fileset dir="${netbeans.home}/lib">
242
	            	<include name="core.jar"/>
243
            		<include name="ext/*.jar"/>
244
	    	</fileset>
245
    	</path>
246
    </target>
247
    
248
</project>
249
(-)openidex/looks/test/cfg-unit.xml (-67 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE mconfig PUBLIC "-//NetBeans//DTD XTest cfg 1.0//EN" "http://www.netbeans.org/dtds/xtest-cfg-1_0.dtd">
3
<!--
4
                Sun Public License Notice
5
6
The contents of this file are subject to the Sun Public License
7
Version 1.0 (the "License"). You may not use this file except in
8
compliance with the License. A copy of the License is available at
9
http://www.sun.com/
10
11
The Original Code is NetBeans. The Initial Developer of the Original
12
Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
13
Microsystems, Inc. All Rights Reserved.
14
-->
15
16
<!-- 
17
  These classes are excluded by default (defined in build.xml):
18
    "**/*Suite.class"
19
    "**/*$$*.class"
20
    "**/data/**"
21
    "**/hidden/**"
22
    "**/*Hidden.*"
23
    "**/*Hid.*"
24
-->
25
26
<mconfig name="looks unit test config">
27
    
28
    <testbag testattribs="stable" executor="code" name="testbag_1" resultsprocessor="unit">
29
        <testset dir="unit/src">
30
            <patternset>
31
                <include name="**/*.class"/>
32
                <exclude name="**/LookNodeTest.class/testGetActions"/>
33
                <exclude name="**/LookNodeTest.class/testGetPropertySets"/>
34
            </patternset>
35
        </testset>
36
    </testbag>
37
    
38
    <testbag testattribs="failing" executor="code" name="testbag_2" resultsprocessor="unit">
39
        <testset dir="unit/src">
40
            <patternset>
41
                <include name="**/LookNodeTest.class/testGetActions"/>
42
                <include name="**/LookNodeTest.class/testGetPropertySets"/>
43
            </patternset>
44
        </testset>
45
    </testbag>
46
    
47
    <!-- If you want to use this testbag you *must* provide xtest.includes property, -->
48
    <!-- (either on cmd line or in the script) to explicitly define which test       -->
49
    <!-- you want to run. This will run *only* tests from unit/src folder !!!        -->
50
    <testbag testattribs="empty" executor="code" name="testbag_empty" resultsprocessor="unit">
51
        <testset dir="unit/src"/>
52
    </testbag>
53
54
    <testbag testattribs="dev" executor="code" name="testbag_dev" resultsprocessor="unit">
55
        <testset dir="unit/src">
56
            <patternset>
57
                <!-- Add your own code tests -->
58
            </patternset>
59
        </testset>
60
    </testbag>
61
    
62
    <executor name="code" antfile="build.xml" target="runcodetest"/>
63
    <executor name="ide" antfile="build.xml" target="runidetest"/>
64
    
65
    <resultsprocessor name="unit" antfile="build.xml" target="test_report"/>
66
67
</mconfig>
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/DefaultLookTest.java (-444 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.lang.ref.*;
17
import java.util.*;
18
19
//import junit.framework.*;
20
import org.netbeans.junit.*;
21
22
import java.util.List;
23
import java.awt.Image;
24
import java.awt.datatransfer.Transferable;
25
import java.io.IOException;
26
import javax.swing.Action;
27
28
29
import org.openide.nodes.*;
30
import org.openide.loaders.XMLDataObject;
31
import org.openide.util.actions.SystemAction;
32
import org.openide.util.HelpCtx;
33
import org.openide.util.datatransfer.NewType;
34
import org.openide.util.datatransfer.PasteType;
35
36
import org.netbeans.api.looks.*;
37
import org.netbeans.spi.looks.*;
38
import org.openide.filesystems.FileUtil;
39
import org.openide.filesystems.FileObject;
40
import org.openide.filesystems.Repository;
41
42
43
44
45
public class DefaultLookTest extends NbTestCase {
46
    
47
    /** Instance of tested DefaultLook */
48
    private Look defaultLook;
49
    
50
    /** Message for unexpected value */
51
    private static final String MSSG_UNEXPECTED_VALUE_RETURNED = 
52
        "Unexpected value returned : ";
53
    
54
    private static final String MSSG_EXCEPTION_THROWN =
55
        "Exception thrown.";
56
    
57
    public DefaultLookTest(java.lang.String testName) {
58
        super(testName);
59
    }
60
    
61
    public static void main(java.lang.String[] args) {
62
        junit.textui.TestRunner.run(suite());
63
    }
64
    
65
    public static NbTest suite() {
66
        NbTestSuite suite = new NbTestSuite(DefaultLookTest.class);
67
        
68
        return suite;
69
    }    
70
    
71
    protected void setUp() throws Exception {
72
        super.setUp();
73
        
74
        // add specific setup code here
75
        defaultLook = new DefaultLook("AnyName") {
76
            public String getDisplayName () {
77
                return "AnyName";
78
            }
79
        };
80
    }
81
    
82
    protected void tearDown() throws Exception {
83
        // add specific tear-down code here
84
        defaultLook = null;
85
        
86
        super.tearDown();
87
    }
88
89
    
90
    /** Test of attachTo method, of class org.openidex.nodes.looks.DefaultLook. */
91
    // Nothing to test
92
    /*
93
    public void testAttachTo() {
94
        System.out.println("testAttachTo");
95
        
96
        // Add your test code below by replacing the default call to fail.
97
        fail("The test case is empty.");
98
    }
99
    */
100
    
101
    /** Test of getCookie method, of class org.openidex.nodes.looks.DefaultLook. */
102
    /*
103
    public void testGetCookie() {
104
        System.out.println("testGetCookie");
105
        
106
        // Add your test code below by replacing the default call to fail.
107
        
108
        Node.Cookie cookie = defaultLook.getCookie( null, null );
109
        
110
        if ( cookie != null ) {
111
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + cookie );
112
        }
113
    }
114
     */
115
    
116
    /** Test of getHandle method, of class org.openidex.nodes.looks.DefaultLook. *
117
    public void testGetHandle() {
118
        System.out.println("testGetHandle");
119
        
120
        // Add your test code below by replacing the default call to fail.
121
        Node.Handle handle = defaultLook.getHandle( null );
122
        
123
        if ( handle != null ) {
124
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + handle );
125
        }
126
    }
127
     */
128
    
129
    /** Test of getDisplayName method, of class org.openidex.nodes.looks.DefaultLook. */
130
    public void testGetDisplayName() {
131
        System.out.println("testGetDisplayName");
132
        
133
        // Add your test code below by replacing the default call to fail.
134
        String displayName = defaultLook.getDisplayName( null );
135
        
136
        if ( displayName != null ) {
137
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + displayName );
138
        }
139
    }
140
    
141
    /** Test of getName method, of class org.openidex.nodes.looks.DefaultLook. */
142
    public void testGetName() {
143
        System.out.println("testGetName");
144
        
145
        // Add your test code below by replacing the default call to fail.
146
        String name = defaultLook.getName( null );
147
        
148
        if ( name != null ) {
149
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + name );
150
        }
151
    }
152
    
153
    /** Test of setName method, of class org.openidex.nodes.looks.DefaultLook. */
154
    // Nothing to test
155
    /*
156
    public void testSetName() {
157
        System.out.println("testSetName");
158
        
159
        // Add your test code below by replacing the default call to fail.
160
        fail("The test case is empty.");
161
    }
162
    */
163
    
164
    /** Test of getShortDescription method, of class org.openidex.nodes.looks.DefaultLook. */
165
    public void testGetShortDescription() {
166
        System.out.println("testGetShortDescription");
167
        
168
        // Add your test code below by replacing the default call to fail.
169
        String shortDescription = defaultLook.getShortDescription( null );
170
        
171
        if ( shortDescription != null ) {
172
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + shortDescription );
173
        }
174
    }
175
    
176
    /** Test of getIcon method, of class org.openidex.nodes.looks.DefaultLook. */
177
    public void testGetIcon() {
178
        System.out.println("testGetIcon");
179
        
180
        // Add your test code below by replacing the default call to fail.
181
        Image icon = defaultLook.getIcon( null, 0 );
182
        
183
        if ( icon != null ) {
184
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + icon );
185
        }
186
    }
187
    
188
    /** Test of getOpenedIcon method, of class org.openidex.nodes.looks.DefaultLook. */
189
    public void testGetOpenedIcon() {
190
        System.out.println("testGetOpenedIcon");
191
        
192
        // Add your test code below by replacing the default call to fail.
193
        Image openedIcon = defaultLook.getOpenedIcon( null, 0 );
194
        
195
        if ( openedIcon != null ) {
196
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + openedIcon );
197
        }
198
    }
199
    
200
    /** Test of getHelpCtx method, of class org.openidex.nodes.looks.DefaultLook. */
201
    public void testGetHelpCtx() {
202
        System.out.println("testGetHelpCtx");
203
        
204
        // Add your test code below by replacing the default call to fail.
205
        HelpCtx helpCtx = defaultLook.getHelpCtx( null  );
206
        
207
        if ( helpCtx != null ) {
208
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + helpCtx );
209
        }
210
    }
211
    
212
    /** Test of getChildObjects method, of class org.openidex.nodes.looks.DefaultLook. */
213
    public void testGetChildObjects() {
214
        System.out.println("testGetChildObjects");
215
        
216
        // Add your test code below by replacing the default call to fail.
217
        Object[] children = defaultLook.getChildObjects( null );
218
        
219
        if ( children != null ) {
220
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + children );
221
        }
222
    }
223
    
224
    /** Test of getNewTypes method, of class org.openidex.nodes.looks.DefaultLook. */
225
    public void testGetNewTypes() {
226
        System.out.println("testGetNewTypes");
227
        
228
        // Add your test code below by replacing the default call to fail.
229
        NewType[] newTypes = defaultLook.getNewTypes( null );
230
        
231
        if ( newTypes != null ) {
232
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + newTypes );
233
        }
234
    }
235
    
236
    /** Test of getActions method, of class org.openidex.nodes.looks.DefaultLook. */
237
    public void testGetActions() throws Exception {
238
        System.out.println("testGetActions");
239
        
240
        // Add your test code below by replacing the default call to fail.
241
        Action[] actions = defaultLook.getActions( null );
242
        
243
        if ( actions != null ) {
244
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + actions );
245
        }
246
        
247
        FileObject fo = FileUtil.createData (
248
            Repository.getDefault ().getDefaultFileSystem().getRoot(),
249
            "Looks/Actions/org/netbeans/spi/looks/DefaultLook/org-openide-actions-NewAction.instance"
250
        );
251
        
252
        actions = defaultLook.getActions ( null );
253
        
254
        assertNotNull ("Not null", actions);
255
        assertEquals ("One action", actions.length, 1);
256
        assertTrue ("NewAction", actions[0] instanceof org.openide.actions.NewAction);
257
        
258
        fo.delete ();
259
    }
260
    
261
    /** Test of getContextActions method, of class org.openidex.nodes.looks.DefaultLook. */
262
    public void testGetContextActions() {
263
        System.out.println("testGetContextActions");
264
        
265
        // Add your test code below by replacing the default call to fail.
266
        Action[] contextActions = defaultLook.getContextActions( null );
267
        
268
        if ( contextActions != null ) {
269
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + contextActions );
270
        }
271
    }
272
    
273
    /** Test of getDefaultAction method, of class org.openidex.nodes.looks.DefaultLook. */
274
    public void testGetDefaultAction() {
275
        System.out.println("testGetDefaultAction");
276
        
277
        // Add your test code below by replacing the default call to fail.
278
        Action defaultAction = defaultLook.getDefaultAction( null );
279
        
280
        if ( defaultAction != null ) {
281
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + defaultAction );
282
        }
283
    }
284
    
285
    /** Test of getPropertySets method, of class org.openidex.nodes.looks.DefaultLook. */
286
    public void testGetPropertySets() {
287
        System.out.println("testGetPropertySets");
288
        
289
        // Add your test code below by replacing the default call to fail.
290
        Node.PropertySet[] propertySets = defaultLook.getPropertySets( null );
291
        
292
        if ( propertySets != null ) {
293
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + propertySets );
294
        }
295
    }
296
    
297
    /** Test of getCustomizer method, of class org.openidex.nodes.looks.DefaultLook. */
298
    public void testGetCustomizer() {
299
        System.out.println("testGetCustomizer");
300
        
301
        // Add your test code below by replacing the default call to fail.
302
        java.awt.Component customizer = defaultLook.getCustomizer( null );
303
        
304
        if ( customizer != null ) {
305
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + customizer );
306
        }
307
    }
308
    
309
    /** Test of canRename method, of class org.openidex.nodes.looks.DefaultLook. */
310
    public void testCanRename() {
311
        System.out.println("testCanRename");
312
        
313
        // Add your test code below by replacing the default call to fail.
314
        boolean canRename = defaultLook.canRename( null );
315
        
316
        if ( canRename != false ) {
317
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canRename );
318
        }
319
    }
320
    
321
    /** Test of canDestroy method, of class org.openidex.nodes.looks.DefaultLook. */
322
    public void testCanDestroy() {
323
        System.out.println("testCanDestroy");
324
        
325
        // Add your test code below by replacing the default call to fail.
326
        boolean canDestroy = defaultLook.canDestroy( null );
327
        
328
        if ( canDestroy != false ) {
329
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canDestroy );
330
        }
331
    }
332
    
333
    /** Test of canCopy method, of class org.openidex.nodes.looks.DefaultLook. */
334
    public void testCanCopy() {
335
        System.out.println("testCanCopy");
336
        
337
        // Add your test code below by replacing the default call to fail.
338
        boolean canCopy = defaultLook.canCopy( null );
339
        
340
        if ( canCopy != false ) {
341
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canCopy );
342
        }
343
    }
344
    
345
    /** Test of canCut method, of class org.openidex.nodes.looks.DefaultLook. */
346
    public void testCanCut() {
347
        System.out.println("testCanCut");
348
        
349
        // Add your test code below by replacing the default call to fail.
350
        boolean canCut = defaultLook.canCut( null );
351
        
352
        if ( canCut != false ) {
353
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canCut );
354
        }
355
    }
356
    
357
    /** Test of getPasteTypes method, of class org.openidex.nodes.looks.DefaultLook. */
358
    public void testGetPasteTypes() {
359
        System.out.println("testGetPasteTypes");
360
        
361
        // Add your test code below by replacing the default call to fail.
362
        PasteType pasteTypes[] = defaultLook.getPasteTypes( null, null );
363
        
364
        if ( pasteTypes != null ) {
365
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + pasteTypes );
366
        }
367
    }
368
    
369
    /** Test of getDropType method, of class org.openidex.nodes.looks.DefaultLook. */
370
    public void testGetDropType() {
371
        System.out.println("testGetDropType");
372
        
373
        // Add your test code below by replacing the default call to fail.
374
        PasteType dropType = defaultLook.getDropType( null, null, 0, 0 );
375
        
376
        if ( dropType != null ) {
377
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + dropType );
378
        }
379
    }
380
    
381
    /** Test of clipboardCopy method, of class org.openidex.nodes.looks.DefaultLook. */
382
    public void testClipboardCopy() {
383
        System.out.println("testClipboardCopy");
384
        
385
        // Add your test code below by replacing the default call to fail.
386
        try {
387
            Transferable transferable = defaultLook.clipboardCopy( null );
388
389
            if ( transferable != null ) {
390
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
391
            }
392
        }
393
        catch ( java.io.IOException e ) {
394
            fail ( MSSG_EXCEPTION_THROWN );
395
        }
396
    }
397
    
398
    /** Test of clipboardCut method, of class org.openidex.nodes.looks.DefaultLook. */
399
    public void testClipboardCut() {
400
        System.out.println("testClipboardCut");
401
        
402
        // Add your test code below by replacing the default call to fail.
403
        try {
404
            Transferable transferable = defaultLook.clipboardCut( null );
405
            
406
            if ( transferable != null ) {
407
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
408
            }
409
        }
410
        catch ( java.io.IOException e ) {
411
            fail ( MSSG_EXCEPTION_THROWN );
412
        }
413
        
414
    }
415
    
416
    /** Test of drag method, of class org.openidex.nodes.looks.DefaultLook. */
417
    public void testDrag() {
418
        System.out.println("testDrag");
419
        
420
        // Add your test code below by replacing the default call to fail.
421
        try {
422
            Transferable transferable = defaultLook.drag( null );
423
424
            if ( transferable != null ) {
425
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
426
            }
427
        }
428
        catch ( java.io.IOException e ) {
429
            fail ( MSSG_EXCEPTION_THROWN );
430
        }
431
    }
432
    
433
    /** Test of destroy method, of class org.openidex.nodes.looks.DefaultLook. */
434
    // Nothing to test
435
    /*
436
    public void testDestroy() {
437
        System.out.println("testDestroy");
438
        
439
        // Add your test code below by replacing the default call to fail.
440
        fail("The test case is empty.");
441
    }
442
    */
443
    
444
}
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/HierarchyTest.java (-217 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.beans.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.awt.event.ActionListener;
20
import java.awt.event.ActionEvent;
21
import java.io.IOException;
22
import java.util.*;
23
24
import javax.swing.event.ChangeListener;
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.JMenuItem;
27
import javax.swing.JMenu;
28
import javax.swing.event.MenuListener;
29
import javax.swing.event.MenuEvent;
30
31
import org.openide.nodes.*;
32
import org.openide.util.HelpCtx;
33
import org.openide.util.NbBundle;
34
import org.openide.util.actions.SystemAction;
35
import org.openide.util.datatransfer.NewType;
36
import org.openide.util.datatransfer.PasteType;
37
import org.openide.awt.JMenuPlus;
38
import org.openide.util.actions.CallableSystemAction;
39
import org.openide.util.actions.Presenter;
40
import org.openide.awt.Actions;
41
import org.openide.util.HelpCtx;
42
import org.openide.actions.SaveAllAction;
43
import org.openide.util.actions.NodeAction;
44
//import junit.framework.*;
45
import org.netbeans.junit.*;
46
import org.openide.util.Utilities;
47
import junit.framework.*;
48
49
50
import org.netbeans.spi.looks.DefaultLook;
51
import java.lang.ref.Reference;
52
import java.lang.ref.WeakReference;
53
54
public class HierarchyTest extends NbTestCase {
55
    private LookNode node;
56
    
57
    
58
    public HierarchyTest(java.lang.String testName) {
59
        super(testName);
60
    }
61
    
62
    public static void main(java.lang.String[] args) {
63
        junit.textui.TestRunner.run(new NbTestSuite(HierarchyTest.class));
64
    }
65
    
66
    protected void setUp() throws Exception {
67
        ArrayList l1 = new ArrayList ();
68
        
69
        ArrayList l2 = new ArrayList ();
70
        l2.add ("1");
71
        l2.add ("2");
72
        
73
        l1.add (l2);
74
        
75
        l2 = new ArrayList ();
76
        l2.add ("A");
77
        l2.add ("B");
78
        
79
        l1.add (l2);
80
81
        node = new LookNode (l1, CL.FIRST);
82
    }
83
    
84
    
85
    protected void tearDown() throws Exception {
86
        node = null;
87
    }
88
    
89
    /** Checks the hierarchy of nodes.
90
     */
91
    public void testHierarchy () {
92
        checkLook (node, node.getLook ());
93
    }
94
95
    
96
    /** Tests the look on clone.
97
     */
98
    public void testClonedHierarchy () {
99
        checkLook (node.cloneNode (), node.getLook ());
100
    }
101
    
102
    
103
    /** Changes the look and check the result.
104
     */
105
    public void testChangedLookOnHierarchy () {
106
        LookNode n = (LookNode)node.cloneNode ();
107
        
108
        CL look = CL.SECOND;
109
        
110
        n.setLook (look);
111
        checkLook (n, look);
112
        
113
        n.setLook (node.getLook ());
114
        checkLook (n, node.getLook ());
115
    }
116
        
117
    /** Selects a look on a subnode, waits till the node is garbage collected
118
     * and checks whether the look is stays there.
119
     */
120
    public void testLookSelector () {
121
        CL look = CL.SECOND;
122
     
123
        LookNode n = (LookNode)node.cloneNode ();
124
        Node[] arr = n.getChildren ().getNodes ();
125
        
126
        assertTrue ("Must be look node", arr[0] instanceof LookNode);
127
        
128
        LookNode ln = (LookNode)arr[0];
129
        ln.setLook (look);
130
        checkLook (ln, look);
131
        
132
        WeakReference ref = new WeakReference (ln);
133
        
134
        ln = null;
135
        arr = null;
136
        
137
        assertGC ("The node must disapear", ref);
138
        
139
        arr = n.getChildren ().getNodes ();
140
        
141
        assertTrue ("Must be look node", arr[0] instanceof LookNode);
142
        
143
        ln = (LookNode)arr[0];
144
        
145
        assertEquals ("Look should remain changed", ln.getLook (), look);
146
        
147
        checkLook (ln, look);
148
    }
149
        
150
        
151
    /** Assert GC.
152
     */
153
    private static void assertGC (String text, Reference ref) {
154
        for (int i = 0; i < 10; i++) {
155
            if (ref.get () == null) {
156
                return;
157
            }
158
            System.gc ();
159
        }
160
        fail (text + " " + ref.get ());
161
    }
162
    
163
    
164
    /** Checks the look */
165
    private static void checkLook (Node from, Look look) {
166
        Node[] arr = from.getChildren ().getNodes ();
167
        
168
        for (int i = 0; i < arr.length; i++) {
169
            assertTrue ("Must be LookNode", arr[i] instanceof LookNode);
170
            LookNode l = (LookNode)arr[i];
171
         
172
            assertEquals ("Inherits the look", l.getLook(), look);
173
            
174
            checkLook (l, look);
175
        }
176
    }
177
        
178
    
179
    
180
    /** A look that represent java.util.Collection.
181
     */
182
    private static final class CL extends DefaultLook {
183
        public static final CL FIRST = new CL ("First");
184
        public static final CL SECOND = new CL ("Second");
185
        
186
        
187
        private CL (String name) {
188
            super (name);
189
        }
190
        
191
        public Look[] availableLooks (NodeSubstitute s) {
192
            if (this == FIRST) {
193
                return new Look[] { SECOND };
194
            } else {
195
                return null;
196
            }
197
        }
198
        
199
        public Object[] getChildObjects (NodeSubstitute s) {
200
            if ("Empty".equals (getName ())) return null;
201
            
202
            if (s.getRepresentedObject () instanceof Collection) {
203
                Collection c = (Collection)s.getRepresentedObject ();
204
                return c.toArray ();
205
            } else {
206
                return null;
207
            }
208
        }
209
        
210
        public String toString () {
211
            return "CL[" + getName () + "]";
212
        }
213
    }
214
}
215
216
217
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/LookNodeEventsTest.java (-547 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
15
package org.netbeans.api.looks;
16
17
import java.beans.*;
18
import java.awt.Image;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.event.ActionListener;
21
import java.awt.event.ActionEvent;
22
import java.io.IOException;
23
import java.util.ArrayList;
24
25
import javax.swing.event.ChangeListener;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.JMenuItem;
28
import javax.swing.JMenu;
29
import javax.swing.event.MenuListener;
30
import javax.swing.event.MenuEvent;
31
32
import org.openide.nodes.*;
33
import org.openide.util.HelpCtx;
34
import org.openide.util.NbBundle;
35
import org.openide.util.actions.SystemAction;
36
import org.openide.util.datatransfer.NewType;
37
import org.openide.util.datatransfer.PasteType;
38
import org.openide.awt.JMenuPlus;
39
import org.openide.util.actions.CallableSystemAction;
40
import org.openide.util.actions.Presenter;
41
import org.openide.awt.Actions;
42
import org.openide.util.HelpCtx;
43
import org.openide.actions.SaveAllAction;
44
import org.openide.util.actions.NodeAction;
45
46
//import junit.framework.*;
47
import org.netbeans.junit.*;
48
49
public class LookNodeEventsTest extends NbTestCase {
50
    
51
    /** Sample look we test against */
52
    SampleLook1Hid sampleLook;
53
    
54
    /** The node to test on */
55
    LookNode lookNode;
56
    
57
    /** NodeSubstitute for the lookNode */
58
    Look.NodeSubstitute nodeSubstitute;
59
    
60
    /** Represented object of the tested node */
61
    String representedObject;
62
    
63
    /** The test listener used for the node */
64
    TestNodeListener testNodeListener;
65
    
66
    /** Property change listener */
67
    TestPropertyChangeListener testPcl;
68
    
69
    // Constants for testing
70
    
71
    String TEST_PROP_NAME = "TestPropName";
72
    String TEST_PROP_OLD = "TestPropOld";
73
    String TEST_PROP_NEW = "TestPropNew";
74
    
75
    
76
    String OLD_NAME = "OldName";
77
    String NEW_NAME = "NewName";
78
    
79
    String OLD_DISPLAY_NAME = "OldDisplayName";
80
    String NEW_DISPLAY_NAME = "NewDisplayName";
81
    
82
    String OLD_SHORT_DESCRIPTION = "OldShortDescription";
83
    String NEW_SHORT_DESCRIPTION = "NewShortDescription";
84
    
85
    static final Node.PropertySet[] OLD_PROPERTY_SETS = new Node.PropertySet[] {
86
        new Sheet.Set(),
87
        new Sheet.Set()
88
    };
89
    
90
    static final Node.PropertySet[] NEW_PROPERTY_SETS = new Node.PropertySet[] {
91
        new Sheet.Set(),
92
        new Sheet.Set()
93
    };
94
    
95
    public LookNodeEventsTest(java.lang.String testName) {
96
        super(testName);
97
    }
98
    
99
    public static void main(java.lang.String[] args) {
100
        junit.textui.TestRunner.run(suite());
101
    }
102
    
103
    public static NbTest suite() {
104
        NbTestSuite suite = new NbTestSuite(LookNodeEventsTest.class);
105
        //suite.addTest(SetLookActionTest.suite());
106
        
107
        return suite;
108
    }
109
    
110
    protected void setUp() throws Exception {
111
        super.setUp();
112
        
113
        // add specific setup code here
114
        sampleLook = new SampleLook1Hid();
115
        representedObject = "RepresentedObject";
116
        lookNode = new LookNode( representedObject, sampleLook );
117
        
118
        nodeSubstitute = sampleLook.substitute;
119
        sampleLook.substitute = null;
120
        
121
        testNodeListener = new TestNodeListener();
122
        lookNode.addNodeListener( testNodeListener );
123
        testPcl = new TestPropertyChangeListener();
124
        lookNode.addPropertyChangeListener( testPcl );
125
    }
126
    
127
    protected void tearDown() throws Exception {
128
        // add specific tear-down code here
129
        nodeSubstitute = null;
130
        sampleLook = null;
131
        lookNode = null;
132
        representedObject = null;
133
        
134
        super.tearDown();
135
    }
136
        
137
    
138
    public void testGetRepresentedObject() {
139
        System.out.println("testGetRepresentedObject");
140
        
141
        // Add your test code below by replacing the default call to fail.
142
        if ( nodeSubstitute.getRepresentedObject() != representedObject )  {
143
            fail( "Bad represented object." );
144
        }
145
    }
146
147
   
148
    public void testFirePropertyChange() {
149
        System.out.println("testFirePropertyChange");
150
        
151
        // Add your test code below by replacing the default call to fail.
152
        testNodeListener.clearTestData();
153
        nodeSubstitute.firePropertyChange( TEST_PROP_NAME, TEST_PROP_OLD, TEST_PROP_NEW );
154
        
155
        ArrayList testData = testPcl.getTestData();
156
        
157
        if ( testData.size() != 1 ) {
158
            fail( "Bad number of events : " + testData.size() );
159
        }
160
        
161
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
162
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
163
        }
164
        
165
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
166
        String evntEv = evaluatePropertyChangeEvent( 
167
            pev, lookNode, TEST_PROP_NAME, TEST_PROP_OLD, TEST_PROP_NEW );
168
        
169
        if ( evntEv != null ) {
170
            fail( evntEv );
171
        }
172
    }
173
    
174
175
    public void testFireNameChange() {
176
        System.out.println("testFireNameChange");
177
        
178
        // Add your test code below by replacing the default call to fail.
179
        testNodeListener.clearTestData();
180
        nodeSubstitute.fireNameChange( OLD_NAME, NEW_NAME );
181
        
182
        ArrayList testData = testNodeListener.getTestData();
183
        
184
        if ( testData.size() != 1 ) {
185
            fail( "Bad number of events : " + testData.size() );
186
        }
187
        
188
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
189
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
190
        }
191
        
192
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
193
        String evntEv = evaluatePropertyChangeEvent( 
194
            pev, lookNode, Node.PROP_NAME, OLD_NAME, NEW_NAME );
195
        
196
        if ( evntEv != null ) {
197
            fail( evntEv );
198
        }
199
    }
200
201
    public void testFireDisplayNameChange() {
202
        System.out.println("testFireDisplayNameChange");
203
        
204
        // Add your test code below by replacing the default call to fail.
205
        testNodeListener.clearTestData();
206
        nodeSubstitute.fireDisplayNameChange( OLD_DISPLAY_NAME, NEW_DISPLAY_NAME );
207
        
208
        ArrayList testData = testNodeListener.getTestData();
209
        
210
        if ( testData.size() != 1 ) {
211
            fail( "Bad number of events : " + testData.size() );
212
        }
213
        
214
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
215
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
216
        }
217
        
218
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
219
        String evntEv = evaluatePropertyChangeEvent( 
220
            pev, lookNode, Node.PROP_DISPLAY_NAME, OLD_DISPLAY_NAME, NEW_DISPLAY_NAME );
221
        
222
        if ( evntEv != null ) {
223
            fail( evntEv );
224
        }
225
    }
226
227
    public void testFireShortDescriptionChange() {
228
        System.out.println("testFireShortDescriptionChange");
229
        
230
        // Add your test code below by replacing the default call to fail.
231
        testNodeListener.clearTestData();
232
        nodeSubstitute.fireShortDescriptionChange( OLD_SHORT_DESCRIPTION, NEW_SHORT_DESCRIPTION );
233
        
234
        ArrayList testData = testNodeListener.getTestData();
235
        
236
        if ( testData.size() != 1 ) {
237
            fail( "Bad number of events : " + testData.size() );
238
        }
239
        
240
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
241
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
242
        }
243
        
244
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
245
        String evntEv = evaluatePropertyChangeEvent( 
246
            pev, lookNode, Node.PROP_SHORT_DESCRIPTION, OLD_SHORT_DESCRIPTION, NEW_SHORT_DESCRIPTION );
247
        
248
        if ( evntEv != null ) {
249
            fail( evntEv );
250
        }
251
    }
252
253
    public void testFireIconChange() {
254
        System.out.println("testFireIconChange");
255
        
256
        // Add your test code below by replacing the default call to fail.
257
        testNodeListener.clearTestData();
258
        nodeSubstitute.fireIconChange();
259
        
260
        ArrayList testData = testNodeListener.getTestData();
261
        
262
        if ( testData.size() != 1 ) {
263
            fail( "Bad number of events : " + testData.size() );
264
        }
265
        
266
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
267
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
268
        }
269
        
270
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
271
        String evntEv = evaluatePropertyChangeEvent( 
272
            pev, lookNode, Node.PROP_ICON, null, null );
273
        
274
        if ( evntEv != null ) {
275
            fail( evntEv );
276
        }
277
    }
278
279
    public void testFireOpenedIconChange() {
280
        System.out.println("testFireOpenedIconChange");
281
        
282
        // Add your test code below by replacing the default call to fail.
283
        testNodeListener.clearTestData();
284
        nodeSubstitute.fireOpenedIconChange();
285
        
286
        ArrayList testData = testNodeListener.getTestData();
287
        
288
        if ( testData.size() != 1 ) {
289
            fail( "Bad number of events : " + testData.size() );
290
        }
291
        
292
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
293
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
294
        }
295
        
296
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
297
        String evntEv = evaluatePropertyChangeEvent( 
298
            pev, lookNode, Node.PROP_OPENED_ICON, null, null );
299
        
300
        if ( evntEv != null ) {
301
            fail( evntEv );
302
        }
303
    }
304
305
    public void testFirePropertySetsChange() {
306
        System.out.println("testFirePropertySetsChange");
307
        
308
        // Add your test code below by replacing the default call to fail.
309
        testNodeListener.clearTestData();
310
        nodeSubstitute.firePropertySetsChange( OLD_PROPERTY_SETS, NEW_PROPERTY_SETS );
311
        
312
        ArrayList testData = testNodeListener.getTestData();
313
        
314
        if ( testData.size() != 1 ) {
315
            fail( "Bad number of events : " + testData.size() );
316
        }
317
        
318
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
319
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
320
        }
321
        
322
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
323
        String evntEv = evaluatePropertyChangeEvent( 
324
            pev, lookNode, Node.PROP_PROPERTY_SETS, OLD_PROPERTY_SETS, NEW_PROPERTY_SETS );
325
        
326
        if ( evntEv != null ) {
327
            fail( evntEv );
328
        }
329
330
    }
331
332
    public void testFireCookieChange() {
333
        System.out.println("testFireCookieChange");
334
        
335
        // Add your test code below by replacing the default call to fail.
336
        testNodeListener.clearTestData();
337
        
338
        
339
        // will fire a cookie change
340
        Object obj = new Node.Cookie () {};
341
        try {
342
            SampleLook1Hid.VAL_INSTANCES.add (obj);
343
            //nodeSubstitute.fireCookieChange();
344
345
            ArrayList testData = testNodeListener.getTestData();
346
347
            if ( testData.size() != 1 ) {
348
                fail( "Bad number of events : " + testData.size() );
349
            }
350
351
            if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
352
                fail( "Bad event type : " + testData.get( 0 ).getClass() );
353
            }
354
355
            PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
356
            String evntEv = evaluatePropertyChangeEvent( 
357
                pev, lookNode, Node.PROP_COOKIE, null, null );
358
359
            if ( evntEv != null ) {
360
                fail( evntEv );
361
            }
362
        } finally {
363
            SampleLook1Hid.VAL_INSTANCES.remove (obj);
364
        }
365
    }
366
367
    public void testFireNodeDestroyed() {
368
        System.out.println("testFireNodeDestroyed");
369
        
370
        // Add your test code below by replacing the default call to fail.
371
        testNodeListener.clearTestData();
372
        nodeSubstitute.fireNodeDestroyed();
373
        
374
        ArrayList testData = testNodeListener.getTestData();
375
        
376
        if ( testData.size() != 1 ) {
377
            fail( "Bad number of events : " + testData.size() );
378
        }
379
        
380
        if ( !(testData.get( 0 ) instanceof NodeEvent ) ) {
381
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
382
        }
383
        
384
        NodeEvent nev = (NodeEvent)testData.get( 0 );        
385
        if ( nev.getNode() != lookNode ) {
386
            fail( "bad node : " + nev.getNode() );
387
        }
388
    }
389
    
390
    public void testAddChildren() {
391
        System.out.println("testAddChildren");
392
        
393
        // Add your test code below by replacing the default call to fail.
394
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
395
        lookNode.getChildren().getNodes();
396
397
        testNodeListener.clearTestData();
398
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_ADDED );
399
        nodeSubstitute.refreshChildren();
400
        
401
        ArrayList testData = testNodeListener.getTestData();
402
        
403
        if ( testData.size() != 1 ) {
404
            fail( "Bad number of events : " + testData.size() );
405
        }
406
        
407
    }
408
    
409
    public void testRemoveChildren() {
410
        System.out.println("testRemoveChildren");
411
        
412
        // Add your test code below by replacing the default call to fail.
413
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_ADDED );
414
        lookNode.getChildren().getNodes();
415
        
416
        testNodeListener.clearTestData();
417
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_REMOVED );
418
        nodeSubstitute.refreshChildren();
419
        
420
        ArrayList testData = testNodeListener.getTestData();
421
        
422
        if ( testData.size() != 1 ) {
423
            fail( "Bad number of events : " + testData.size() );
424
        }
425
    }
426
    
427
    public void testReorderChildren() {
428
        System.out.println("testReorderChildren");
429
        
430
        // Add your test code below by replacing the default call to fail.
431
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
432
        lookNode.getChildren().getNodes();
433
        
434
        testNodeListener.clearTestData();
435
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_REORDERED );
436
        nodeSubstitute.refreshChildren();
437
        
438
        ArrayList testData = testNodeListener.getTestData();
439
        
440
        if ( testData.size() != 1 ) {
441
            fail( "Bad number of events : " + testData.size() );
442
        }
443
    }
444
    
445
    public void testNoChildrenChange() {
446
        System.out.println("testNoChildrenChange");
447
        
448
        // Add your test code below by replacing the default call to fail.
449
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
450
        lookNode.getChildren().getNodes();
451
        
452
        testNodeListener.clearTestData();
453
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_NO_CHANGE );
454
        nodeSubstitute.refreshChildren();
455
        
456
        ArrayList testData = testNodeListener.getTestData();
457
        
458
        if ( testData.size() != 0 ) {
459
            fail( "Bad number of events : " + testData.size() );
460
        }
461
    }
462
    
463
    // private methods ---------------------------------------------------------
464
    
465
    private String evaluatePropertyChangeEvent( PropertyChangeEvent pev,
466
        Object source, String name, Object oldValue, Object newValue ) {
467
        
468
        if ( pev.getSource() != source ) {
469
            return "Bad event source : " + pev.getSource();
470
        }
471
        if ( pev.getPropertyName() != name ) {
472
            return "Bad propertyName : " + pev.getPropertyName();
473
        }
474
        if ( pev.getOldValue() != oldValue ) {
475
            return "Bad old name : " + pev.getOldValue();
476
        }
477
        if ( pev.getNewValue() != newValue ) {
478
            return "Bad new name : " + pev.getOldValue();
479
        }
480
        
481
        return null;
482
    }
483
    
484
    // private classes ---------------------------------------------------------
485
    
486
    private static class TestNodeListener implements NodeListener {
487
        
488
        private ArrayList eventsList;
489
        
490
        TestNodeListener() {
491
            clearTestData();
492
        }
493
        
494
        public void nodeDestroyed( NodeEvent ev ) {
495
            eventsList.add( ev );
496
        }
497
        
498
        public void childrenRemoved( NodeMemberEvent ev ) {
499
            eventsList.add( ev );
500
        }
501
        
502
        public void childrenReordered( NodeReorderEvent ev ) {
503
            eventsList.add( ev );
504
        }
505
        
506
        public void propertyChange( PropertyChangeEvent ev ) {
507
            eventsList.add( ev );
508
        }
509
        
510
        public void childrenAdded( NodeMemberEvent ev ) {
511
            eventsList.add( ev );
512
        }
513
        
514
        void clearTestData() {
515
            eventsList = new ArrayList();
516
        }
517
        
518
        ArrayList getTestData() {
519
            return eventsList;
520
        }
521
        
522
    }
523
    
524
    
525
    private static class TestPropertyChangeListener implements PropertyChangeListener {
526
        
527
        ArrayList eventsList;
528
        
529
        TestPropertyChangeListener() {
530
            clearTestData();
531
        }
532
        
533
        public void propertyChange(PropertyChangeEvent pce ) {
534
            eventsList.add( pce );
535
        }
536
        
537
        void clearTestData() {
538
            eventsList = new ArrayList();
539
        }
540
        
541
        ArrayList getTestData() {
542
            return eventsList;
543
        }
544
        
545
    }
546
}
547
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/LookNodeTest.java (-449 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.beans.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.awt.event.ActionListener;
20
import java.awt.event.ActionEvent;
21
import java.io.IOException;
22
import javax.swing.event.ChangeListener;
23
import javax.swing.event.ChangeEvent;
24
import javax.swing.JMenuItem;
25
import javax.swing.JMenu;
26
import javax.swing.event.MenuListener;
27
import javax.swing.event.MenuEvent;
28
import org.openide.nodes.*;
29
import org.openide.util.HelpCtx;
30
import org.openide.util.NbBundle;
31
import org.openide.util.actions.SystemAction;
32
import org.openide.util.datatransfer.NewType;
33
import org.openide.util.datatransfer.PasteType;
34
import org.openide.awt.JMenuPlus;
35
import org.openide.util.actions.CallableSystemAction;
36
import org.openide.util.actions.Presenter;
37
import org.openide.awt.Actions;
38
import org.openide.util.HelpCtx;
39
import org.openide.actions.SaveAllAction;
40
import org.openide.util.actions.NodeAction;
41
//import junit.framework.*;
42
import org.netbeans.junit.*;
43
import org.openide.util.Utilities;
44
import junit.framework.*;
45
46
public class LookNodeTest extends NbTestCase {
47
    
48
    /** Sample look we test against */
49
    SampleLook1Hid sampleLook;
50
    
51
    /** Second sample look for testing */
52
    SampleLook2Hid sampleLook2;
53
    
54
    /** The node to test on */
55
    LookNode lookNode;
56
    
57
    /** Represented object of the tested node */
58
    String representedObject;
59
    
60
    public LookNodeTest(java.lang.String testName) {
61
        super(testName);
62
    }
63
    
64
    public static void main(java.lang.String[] args) {
65
        junit.textui.TestRunner.run(suite());
66
    }
67
    
68
    protected void setUp() throws Exception {
69
        super.setUp();
70
        
71
        // add specific setup code here
72
        sampleLook = new SampleLook1Hid();
73
        sampleLook2 = new SampleLook2Hid();
74
        representedObject = "RepresentedObject";
75
        lookNode = new LookNode( representedObject, sampleLook );
76
        //look is hard set by this contructor
77
        //assert("Too eager initialization!", lookNode.getHardLook() == null);
78
    }
79
    
80
    protected void tearDown() throws Exception {
81
        // add specific tear-down code here
82
        sampleLook = null;
83
        lookNode = null;
84
        representedObject = null;
85
        
86
        super.tearDown();
87
    }
88
    
89
    /** Test of getSubstitute method, of class org.openidex.nodes.looks.LookNode. */
90
    public void testGetSubstitute() {
91
        // Add your test code below by replacing the default call to fail.
92
        Look.NodeSubstitute substitute = lookNode.getSubstitute( );
93
        assertTrue ("Not even substitute", substitute instanceof LookNode.SubstituteImpl);
94
        LookNode.SubstituteImpl impl = (LookNode.SubstituteImpl)substitute;
95
        assertEquals (lookNode, impl.getLookNode ());
96
    }
97
    
98
    
99
    /** Test of getRepresentedObject method, of class org.openidex.nodes.looks.LookNode. */
100
    
101
    public void testGetRepresentedObject() {
102
        // Add your test code below by replacing the default call to fail.
103
        String ro = (String)lookNode.getRepresentedObject( );
104
        if ( ro != representedObject ) {
105
            fail("Bad represented object.");
106
        }
107
    }
108
    
109
    
110
    /** Test of setLook method, of class org.openidex.nodes.looks.LookNode. */
111
    public void testSetLook() {
112
        // Add your test code below by replacing the default call to fail.
113
        lookNode.setLook( sampleLook2 );
114
        if ( lookNode.getLook() != sampleLook2 ) {
115
            fail( "look not set" );
116
        }
117
        
118
        lookNode.setLook( sampleLook );
119
        if ( lookNode.getLook() != sampleLook ) {
120
            fail( "look not set" );
121
        }
122
    }
123
    
124
    
125
    /** Test of refreshChildren method, of class org.openidex.nodes.looks.LookNode. */
126
    // Tested in LookNodeEventsTest
127
    /*
128
    public void testRefreshChildren() {
129
        System.out.println("testRefreshChildren");
130
        
131
        // Add your test code below by replacing the default call to fail.
132
        fail("The test case is empty.");
133
    }
134
    */
135
    
136
    /** Test of getLook method, of class org.openidex.nodes.looks.LookNode. */
137
    public void testGetLook() {
138
        // Add your test code below by replacing the default call to fail.
139
        
140
        Look look = lookNode.getLook();
141
        if ( look != sampleLook ) {
142
            fail("Look not returned.");
143
        }
144
    }
145
    
146
    /** Test of getCookie method, of class org.openidex.nodes.looks.LookNode. */
147
    public void testGetCookie() {
148
        // Add your test code below by replacing the default call to fail.
149
        Node.Cookie cookie = lookNode.getCookie( Object.class );
150
        if ( cookie != SampleLook1Hid.VAL_COOKIE ) {
151
            fail("Bad cookie.");
152
        }
153
    }
154
    
155
    /** Test of getHandle method, of class org.openidex.nodes.looks.LookNode. *
156
    public void testAvailableLooks () {
157
        System.out.println("testGetHandle");
158
        
159
        // Add your test code below by replacing the default call to fail.
160
        Object handle = lookNode.testAvailableLooks ( );
161
        if ( handle != SampleLook1Hid.VAL_LOOKS ) {
162
            fail("Bad handle.");
163
        }
164
    }*/
165
    
166
    /** Test of cloneNode method, of class org.openidex.nodes.looks.LookNode. */
167
    public void testCloneNode() {
168
        // Add your test code below by replacing the default call to fail.
169
        Look look = sampleLook2;
170
        LookNode lookNode = new LookNode(new Object(), look);
171
        
172
        LookNode clonedNode = (LookNode)lookNode.cloneNode();
173
        LookNode secondLevelClone = (LookNode) clonedNode.cloneNode();
174
        
175
        assertTrue ("Cloned node must not be null!", clonedNode != null );        
176
        assertTrue ("Cloned node must be a chameleon!", clonedNode.getBaseLook() == lookNode.getBaseLook ());
177
        assertTrue ("Second level clone has different hard look!", clonedNode.getBaseLook() == secondLevelClone.getBaseLook());
178
//        assert("Second level clone has different hard look candidate!", clonedNode.getHardLookCandidate() == secondLevelClone.getHardLookCandidate());
179
180
        // we do not have any parent node so we do not use chameleon look but rather hard look candidate
181
        
182
        assertTrue ("Both clones must result in same getLook()!", clonedNode.getLook() == secondLevelClone.getLook());
183
        
184
    }
185
    
186
    
187
    /** Test of getDisplayName method, of class org.openidex.nodes.looks.LookNode. */
188
    public void testGetDisplayName() {
189
        // Add your test code below by replacing the default call to fail.
190
        String displayName = lookNode.getDisplayName( );
191
        if ( displayName != SampleLook1Hid.VAL_DISPLAY_NAME ) {
192
            fail("Bad displayName.");
193
        }
194
    }
195
    
196
    /** Test of setDisplayName method, of class org.openidex.nodes.looks.LookNode. */
197
    public void testSetDisplayName() {
198
        // Add your test code below by replacing the default call to fail.
199
        // fail("The test case is empty.");
200
    }
201
    
202
    /** Test of getName method, of class org.openidex.nodes.looks.LookNode. */
203
    public void testGetName() {
204
        // Add your test code below by replacing the default call to fail.
205
        String name = lookNode.getName( );
206
        if ( name != SampleLook1Hid.VAL_NAME ) {
207
            fail("Bad name.");
208
        }
209
    }
210
    
211
    /** Test of setName method, of class org.openidex.nodes.looks.LookNode. */
212
    public void testSetName() {
213
        // Add your test code below by replacing the default call to fail.
214
        lookNode.setName( "Some name" );
215
        if ( !sampleLook.getSetNameCalled() ) {
216
            fail("setName not called.");
217
        }
218
    }
219
    
220
    /** Test of getShortDescription method, of class org.openidex.nodes.looks.LookNode. */
221
    public void testGetShortDescription() {
222
        // Add your test code below by replacing the default call to fail.
223
        String shortDescription = lookNode.getShortDescription( );
224
        if ( shortDescription != SampleLook1Hid.VAL_SHORT_DESCRIPTION ) {
225
            fail("Bad shortDescription.");
226
        }
227
    }
228
    
229
    /** Test of getIcon method, of class org.openidex.nodes.looks.LookNode. */
230
    public void testGetIcon() {
231
        // Add your test code below by replacing the default call to fail.
232
        Image icon = lookNode.getIcon( 0 );
233
        if ( icon != SampleLook1Hid.VAL_ICON ) {
234
            fail("Bad icon.");
235
        }
236
    }
237
    
238
    /** Test of getOpenedIcon method, of class org.openidex.nodes.looks.LookNode. */
239
    public void testGetOpenedIcon() {
240
        // Add your test code below by replacing the default call to fail.
241
        Image openedIcon = lookNode.getOpenedIcon( 0 );
242
        if ( openedIcon != SampleLook1Hid.VAL_OPENED_ICON ) {
243
            fail("Bad openedIcon.");
244
        }
245
    }
246
    
247
    /** Test of getHelpCtx method, of class org.openidex.nodes.looks.LookNode. */
248
    public void testGetHelpCtx() {
249
        // Add your test code below by replacing the default call to fail.
250
        HelpCtx helpCtx = lookNode.getHelpCtx( );
251
        if ( helpCtx != SampleLook1Hid.VAL_HELP_CTX ) {
252
            fail("Bad helpCtx.");
253
        }
254
    }
255
    
256
    /** Test of getNewTypes method, of class org.openidex.nodes.looks.LookNode. */
257
    public void testGetNewTypes() {
258
        // Add your test code below by replacing the default call to fail.
259
        NewType[] newTypes = lookNode.getNewTypes( );
260
        if ( newTypes != SampleLook1Hid.VAL_NEW_TYPES ) {
261
            fail("Bad newTypes.");
262
        }
263
    }
264
    
265
    /** Test of getActions method, of class org.openidex.nodes.looks.LookNode. */
266
    public void testGetActions() {
267
        // Add your test code below by replacing the default call to fail.
268
        SystemAction[] actions = lookNode.getActions( );
269
        if ( !java.util.Arrays.equals (actions, SampleLook1Hid.VAL_ACTIONS )) {
270
            fail("Bad actions.");
271
        }
272
    }
273
    
274
    /** Test of getContextActions method, of class org.openidex.nodes.looks.LookNode. */
275
    public void testGetContextActions() {
276
        // Add your test code below by replacing the default call to fail.
277
        SystemAction[] contextActions = lookNode.getContextActions( );
278
        if ( !java.util.Arrays.equals (contextActions, SampleLook1Hid.VAL_CONTEXT_ACTIONS )) {
279
            fail("Bad contextActions.");
280
        }
281
    }
282
    
283
    /** Test of getDefaultAction method, of class org.openidex.nodes.looks.LookNode. */
284
    public void testGetDefaultAction() {
285
        // Add your test code below by replacing the default call to fail.
286
        SystemAction defaultAction = lookNode.getDefaultAction( );
287
        if ( defaultAction != SampleLook1Hid.VAL_DEFAULT_ACTION ) {
288
            fail("Bad defaultAction.");
289
        }
290
    }
291
    
292
    /** Test of getPropertySets method, of class org.openidex.nodes.looks.LookNode. */
293
    public void testGetPropertySets() {
294
        // Add your test code below by replacing the default call to fail.
295
        Node.PropertySet[] propertySets = lookNode.getPropertySets( );
296
        if ( propertySets != SampleLook1Hid.VAL_PROPERTY_SETS ) {
297
            fail("Bad propertySets.");
298
        }
299
    }
300
    
301
    /** Test of getCustomizer method, of class org.openidex.nodes.looks.LookNode. */
302
    public void testGetCustomizer() {
303
        // Add your test code below by replacing the default call to fail.
304
        java.awt.Component customizer = lookNode.getCustomizer( );
305
        if ( customizer != SampleLook1Hid.VAL_CUSTOMIZER ) {
306
            fail("Bad customizer.");
307
        }
308
    }
309
    
310
    /** Test of hasCustomizer method, of class org.openidex.nodes.looks.LookNode. */
311
    public void testHasCustomizer() {
312
        // Add your test code below by replacing the default call to fail.
313
        boolean hasCustomizer = lookNode.hasCustomizer();
314
        if ( hasCustomizer != true ) {
315
            fail("Bad hasCustomizedr value");
316
        }
317
        
318
        LookNode extraNode = new LookNode( representedObject, Look.DEFAULT );
319
        hasCustomizer = extraNode.hasCustomizer();
320
        if ( hasCustomizer != false ) {
321
            fail("Bad hasCustomizedr value");
322
        }    
323
    }
324
    
325
    /** Test of canRename method, of class org.openidex.nodes.looks.LookNode. */
326
    public void testCanRename() {
327
        // Add your test code below by replacing the default call to fail.
328
        boolean canRename = lookNode.canRename();
329
        if ( canRename != true ) {
330
            fail("Bad value canRename");
331
        }
332
    }
333
    
334
    /** Test of canDestroy method, of class org.openidex.nodes.looks.LookNode. */
335
    public void testCanDestroy() {
336
        // Add your test code below by replacing the default call to fail.
337
        boolean canDestroy = lookNode.canDestroy();
338
        if ( canDestroy != true ) {
339
            fail("Bad value canDestroy");
340
        }
341
    }
342
    
343
    /** Test of canCopy method, of class org.openidex.nodes.looks.LookNode. */
344
    public void testCanCopy() {
345
        // Add your test code below by replacing the default call to fail.
346
        boolean canCopy = lookNode.canCopy();
347
        if ( canCopy != true ) {
348
            fail("Bad value canCopy");
349
        }
350
    }
351
    
352
    /** Test of canCut method, of class org.openidex.nodes.looks.LookNode. */
353
    public void testCanCut() {
354
        // Add your test code below by replacing the default call to fail.
355
        boolean canCut = lookNode.canCut();
356
        if ( canCut != true ) {
357
            fail("Bad value canCut");
358
        }
359
    }
360
    
361
    /** Test of getPasteTypes method, of class org.openidex.nodes.looks.LookNode. */
362
    public void testGetPasteTypes() {
363
        // Add your test code below by replacing the default call to fail.
364
        PasteType pasteTypes[] = lookNode.getPasteTypes( null );
365
        if ( pasteTypes != SampleLook1Hid.VAL_PASTE_TYPES ) {            
366
            fail("Bad value pasteTypes");
367
        }
368
    }
369
    
370
    /** Test of getDropType method, of class org.openidex.nodes.looks.LookNode. */
371
    public void testGetDropType() {
372
        // Add your test code below by replacing the default call to fail.
373
        PasteType dropType = lookNode.getDropType( null, 0, 0 );
374
        if ( dropType != SampleLook1Hid.VAL_DROP_TYPE ) {            
375
            fail("Bad value dropType");
376
        }
377
    }
378
    
379
    /** Test of clipboardCopy method, of class org.openidex.nodes.looks.LookNode. */
380
    public void testClipboardCopy() {
381
        // Add your test code below by replacing the default call to fail.
382
        try {
383
            Transferable clipboardCopy= lookNode.clipboardCopy( );
384
            if ( clipboardCopy != SampleLook1Hid.VAL_CLIPBOARD_COPY ) {            
385
                fail("Bad value clipboardCopy");
386
            }
387
        }
388
        catch ( IOException e ) {
389
            fail("Exception thrown : " + e);
390
        }
391
    }
392
    
393
    /** Test of clipboardCut method, of class org.openidex.nodes.looks.LookNode. */
394
    public void testClipboardCut() {
395
        // Add your test code below by replacing the default call to fail.
396
        try {
397
            Transferable clipboardCut= lookNode.clipboardCut( );
398
            if ( clipboardCut != SampleLook1Hid.VAL_CLIPBOARD_CUT ) {            
399
                fail("Bad value clipboardCut");
400
            }
401
        }
402
        catch ( IOException e ) {
403
            fail("Exception thrown : " + e);
404
        }
405
    }
406
    
407
    /** Test of drag method, of class org.openidex.nodes.looks.LookNode. */
408
    public void testDrag() {
409
        // Add your test code below by replacing the default call to fail.
410
        try {
411
            Transferable drag = lookNode.drag( );
412
            if ( drag != SampleLook1Hid.VAL_DRAG ) {            
413
                fail("Bad value drag");
414
            }
415
        }
416
        catch ( IOException e ) {
417
            fail("Exception thrown : " + e);
418
        }
419
    }
420
    
421
    /** Test of destroy method, of class org.openidex.nodes.looks.LookNode. */
422
    public void testDestroy() {
423
        // Add your test code below by replacing the default call to fail.
424
        try {
425
            lookNode.destroy();
426
            if ( !sampleLook.getDestroyCalled() ) {
427
                fail("Destroy not called.");
428
            }
429
        }
430
        catch ( IOException e ) {
431
            fail("Exception thrown : " + e);
432
        }
433
    }
434
    
435
    
436
    
437
    
438
    
439
    public static Test suite() {
440
        TestSuite suite = new NbTestSuite(LookNodeTest.class);
441
        
442
        return suite;
443
    }    
444
445
    
446
}
447
448
449
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/SampleLook1Hid.java (-492 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.util.List;
17
import java.awt.Image;
18
import java.awt.image.BufferedImage;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.datatransfer.StringSelection;
21
import java.io.IOException;
22
import java.lang.reflect.*;
23
import java.util.Hashtable;
24
import javax.swing.JPanel;
25
import javax.swing.Action;
26
27
import org.openide.nodes.*;
28
import org.openide.loaders.XMLDataObject;
29
import org.openide.util.actions.SystemAction;
30
import org.openide.util.actions.CallableSystemAction;
31
import org.openide.util.HelpCtx;
32
import org.openide.util.datatransfer.NewType;
33
import org.openide.util.datatransfer.PasteType;
34
import org.openide.util.Lookup;
35
import org.openide.util.lookup.InstanceContent;
36
import org.openide.util.lookup.AbstractLookup;
37
38
import org.netbeans.api.looks.*;
39
import org.netbeans.spi.looks.*;
40
41
/** Class used for testing. Every method returns some value. Usefull for testing 
42
 * FilterLook.
43
 *
44
 * @author Petr Hrebejk
45
 */
46
public class SampleLook1Hid extends Look {
47
    
48
    // Flags for method calls which do not return any value.
49
    boolean attachToCalled = false;
50
    boolean setNameCalled = false;
51
    boolean destroyCalled = false;
52
       
53
    // The values which are returned from this Look
54
    static final Node.Cookie VAL_COOKIE = new Node.Cookie() {};
55
56
    // initializes the lookup
57
    static final InstanceContent VAL_INSTANCES = new InstanceContent ();
58
    static final Lookup VAL_LOOKUP = new AbstractLookup (VAL_INSTANCES);
59
    static {
60
        VAL_INSTANCES.add (VAL_COOKIE);
61
    }
62
    
63
    static final Look[] VAL_LOOKS = new Look [0];
64
    
65
    static final String VAL_NAME = "Node.Name";
66
    
67
    static final String VAL_DISPLAY_NAME = "Node.DisplayName";
68
    
69
    static final String VAL_SHORT_DESCRIPTION = "Node.ShortDescription";
70
    
71
    static final String[] VAL_KEYS = new String[] {
72
        "Child.1",
73
        "Child.2"
74
    };
75
    
76
    static final String[] VAL_KEYS_ADDED = new String[] {
77
        VAL_KEYS[0],
78
        "Child.1.a",
79
        VAL_KEYS[1]
80
    };
81
    
82
    static final String[] VAL_KEYS_REMOVED = new String[] {
83
        VAL_KEYS[0],
84
    };
85
    
86
    static final String[] VAL_KEYS_REORDERED = new String[] {
87
        VAL_KEYS[1],
88
        VAL_KEYS[0]
89
    };
90
    
91
    static final String[] VAL_KEYS_NO_CHANGE = new String[] {
92
        VAL_KEYS[0],
93
        VAL_KEYS[1]
94
    };
95
    
96
    static final Image VAL_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
97
    
98
    static final Image VAL_OPENED_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
99
    
100
    static final HelpCtx VAL_HELP_CTX = new HelpCtx( SampleLook1Hid.class );
101
    
102
    static final SystemAction[] VAL_ACTIONS = new SystemAction[] {
103
        new TestingAction1( "SystemAction1" ),
104
        new TestingAction2( "SystemAction2" )
105
    };
106
    
107
    static final SystemAction[] VAL_CONTEXT_ACTIONS = new SystemAction[] {
108
        new TestingAction3( "ContextAction1" ),
109
        new TestingAction4( "ContextAction2" )
110
    };
111
    
112
    static final SystemAction VAL_DEFAULT_ACTION = new TestingAction5( "DefaultAction" );
113
    
114
    static final JPanel VAL_CUSTOMIZER = new JPanel();
115
    
116
    static final Node.PropertySet[] VAL_PROPERTY_SETS = new Node.PropertySet[] {
117
        new Sheet.Set(),
118
        new Sheet.Set()
119
    };
120
    
121
    static final NewType[] VAL_NEW_TYPES = new NewType[] {
122
        new NewType() { 
123
            public void create() {  }
124
        },
125
        
126
        new NewType() { 
127
            public void create() {  }
128
        }
129
    };
130
    
131
    static final PasteType[] VAL_PASTE_TYPES = new PasteType[] {
132
        new PasteType() { 
133
            public Transferable paste() { return null; }
134
        },
135
        
136
        new PasteType() { 
137
            public Transferable paste() { return null; }
138
        }
139
    };
140
    
141
    static final PasteType VAL_DROP_TYPE = new PasteType() { 
142
        public Transferable paste() { return null; }
143
    };
144
    
145
    static final Transferable VAL_CLIPBOARD_COPY = new StringSelection( "ClipboardCopy" );
146
147
    static final Transferable VAL_CLIPBOARD_CUT = new StringSelection( "ClipboardCut" );
148
    
149
    static final Transferable VAL_DRAG = new StringSelection( "Drag" );
150
    
151
    // Hashtable which holds the relation Node - NodeSubstitute
152
    //private Hashtable nodes2Substitutes = new Hashtable(); 
153
    
154
    // The value of keys which has to be returned
155
    private String[] keys = VAL_KEYS;
156
    
157
    /** Name of the look. 
158
     */
159
    private String name;
160
    
161
    static {
162
        VAL_PROPERTY_SETS[0].setName("SetA");
163
        VAL_PROPERTY_SETS[1].setName("SetB");
164
        Node n = new AbstractNode(Children.LEAF);
165
        ((Sheet.Set)VAL_PROPERTY_SETS[0]).put(new Node.Property[] {
166
            new PropertySupport.ReadOnly("PropA-1", String.class, "PropertyA-1", 
167
                "Property 1 from sheet A") {
168
                    public Object getValue() {
169
                        return "";
170
                    }
171
            }
172
        });
173
        ((Sheet.Set)VAL_PROPERTY_SETS[0]).put(new Node.Property[] {
174
            new PropertySupport.ReadOnly("PropA-2", String.class, "PropertyA-2", 
175
                "Property 2 from sheet A") {
176
                    public Object getValue() {
177
                        return "";
178
                    }
179
            }
180
        });
181
        ((Sheet.Set)VAL_PROPERTY_SETS[1]).put(new Node.Property[] {
182
            new PropertySupport.ReadOnly("PropB-1", String.class, "PropertyB-1", 
183
                "Property 1 from sheet B") {
184
                    public Object getValue() {
185
                        return "";
186
                    }
187
            }
188
        });
189
        ((Sheet.Set)VAL_PROPERTY_SETS[1]).put(new Node.Property[] {
190
            new PropertySupport.ReadOnly("PropB-2", String.class, "PropertyB-2", 
191
                "Property 1 from sheet B") {
192
                    public Object getValue() {
193
                        return "";
194
                    }
195
            }
196
        });
197
    }
198
    
199
    /** substitute associated with this look (should be just one) */
200
    public NodeSubstitute substitute;
201
    
202
    /** Creates new DefaultLook. The costructor is protected, there should 
203
     * be no need for creating new <CODE> DefaultLooks</CODE>. You can delegate
204
     * to {@link #INSTANCE} instead.
205
     */
206
    public SampleLook1Hid() {
207
    }
208
    
209
    // Additional methods for testing ------------------------------------------
210
    
211
    public boolean getAttachToCalled() {
212
        boolean r = attachToCalled;
213
        attachToCalled = false;
214
        return r;
215
    }
216
        
217
    public boolean getSetNameCalled() {
218
        boolean r = setNameCalled;
219
        setNameCalled = false;
220
        return r;
221
    }
222
        
223
        
224
    public boolean getDestroyCalled() {
225
        boolean r = destroyCalled;
226
        destroyCalled = false;
227
        return r;
228
    }
229
    
230
    /*Look.NodeSubstitute getSubstituteForNode( LookNode node ) {
231
        return (Look.NodeSubstitute) nodes2Substitutes.get( node );
232
    }*/
233
    
234
    void setKeys( String[] val ) {
235
        keys = val;
236
    }
237
    
238
    // Private helper methods --------------------------------------------------
239
    
240
    private LookNode getNodeFromSubstitute( LookNode.SubstituteImpl subst ) {
241
        return subst.getLookNode ();
242
    }
243
    
244
    // Methods of look itself --------------------------------------------------
245
    
246
    
247
    // General methods ---------------------------------------------------------
248
249
    /** Sets the flag to be able to test wether the method was called. It 
250
     * also stores the Look.NodeSubstitutes in a hash table (indexed by the
251
     * node to provide them by the getNodeSubstitute( Node node ) method.
252
     */    
253
    public Object attachTo(Look.NodeSubstitute substitute) {
254
        attachToCalled = true;
255
        /*
256
        if (this.substitute != null) {
257
            throw new IllegalStateException ("Attaching to the same look for second time");
258
        }
259
         */
260
        this.substitute = substitute;
261
        /*
262
        if ( substitute instanceof LookNode.SubstituteImpl ) {
263
            LookNode lookNode = getNodeFromSubstitute( (LookNode.SubstituteImpl )substitute );
264
            nodes2Substitutes.put( lookNode, substitute );
265
        }
266
         */
267
        
268
        return null;
269
    }
270
    
271
    public Lookup createLookup (Look.NodeSubstitute substitute) {
272
        return VAL_LOOKUP;
273
    }
274
275
    
276
    /** A list of possible modes this look can be switched into.
277
     *
278
     * @param substitute substitute to find modes for
279
     * @return the Mode or null if the switching is not available
280
     */
281
    public Look[] availableLooks(Look.NodeSubstitute substitute) {
282
        return VAL_LOOKS;
283
    }
284
    
285
    // Methods for STYLE -------------------------------------------------------
286
    
287
    public String getDisplayName( Look.NodeSubstitute substitute ) {
288
        return VAL_DISPLAY_NAME;
289
    }
290
    
291
    public String getName( Look.NodeSubstitute substitute ) {
292
        return VAL_NAME;
293
    }
294
    
295
    public void setName(Look.NodeSubstitute substitute, String newName ) {
296
        setNameCalled = true;
297
    }
298
    
299
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
300
        return VAL_SHORT_DESCRIPTION;
301
    }
302
    
303
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
304
        return VAL_ICON;
305
    }
306
    
307
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
308
        return VAL_OPENED_ICON;
309
    }
310
    
311
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
312
        return VAL_HELP_CTX;
313
    }
314
    
315
    // Methods for CHILDREN ----------------------------------------------------
316
    
317
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
318
        return keys;
319
    }
320
        
321
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
322
    
323
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
324
        return VAL_NEW_TYPES;
325
    }
326
    
327
    public Action[] getActions( Look.NodeSubstitute substitute ) {
328
        return VAL_ACTIONS;
329
    }
330
    
331
    public Action[] getContextActions( Look.NodeSubstitute substitute ) {
332
        return VAL_CONTEXT_ACTIONS;
333
    }
334
    
335
    public Action getDefaultAction( Look.NodeSubstitute substitute ) {
336
        return VAL_DEFAULT_ACTION;
337
    }
338
    
339
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
340
    
341
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
342
        return VAL_PROPERTY_SETS;
343
    }
344
    
345
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
346
        return VAL_CUSTOMIZER;
347
    }
348
    
349
    public boolean hasCustomizer( Look.NodeSubstitute substitute ) {
350
        return VAL_CUSTOMIZER != null;
351
    }
352
    
353
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
354
     
355
    public boolean canRename( Look.NodeSubstitute substitute ) {
356
        return true;
357
    }
358
    
359
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
360
        return true;
361
    }
362
    
363
    public boolean canCopy( Look.NodeSubstitute substitute ) {
364
        return true;
365
    }
366
    
367
    public boolean canCut( Look.NodeSubstitute substitute ) {
368
        return true;
369
    }
370
    
371
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
372
        return VAL_PASTE_TYPES;
373
    }
374
    
375
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
376
        return VAL_DROP_TYPE;
377
    }
378
    
379
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
380
        return VAL_CLIPBOARD_COPY;
381
    }
382
    
383
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
384
        return VAL_CLIPBOARD_CUT;
385
    }
386
    
387
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
388
        return VAL_DRAG;
389
    }
390
          
391
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
392
        destroyCalled = true;
393
    }
394
    
395
    /** The human presentable name of the look.
396
     * @return human presentable name
397
     */
398
    public String getDisplayName() {
399
        return "Disp1";
400
    }
401
    
402
    /** Returns name of the look. This name should identify the look.
403
     * @return Name of the look.
404
     */
405
    public String getName() {
406
        return "Name1";
407
    }
408
    
409
    /*
410
    public static class NodeSubstitute extends Look.NodeSubstitute {
411
           
412
        public Object getRepresentedObject() { return null; }
413
        
414
        public void firePropertyChange( String name, Object o, Object n ) {}
415
416
        public void fireNameChange( String o, String n ) {}
417
        
418
        public void fireDisplayNameChange( String o, String n ) {}
419
        
420
        public void fireShortDescriptionChange(String o, String n) {}
421
422
        public void fireIconChange() {}
423
424
        public void fireOpenedIconChange() {}
425
426
        public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n ) {}
427
       
428
        public void fireCookieChange() {}
429
430
        public void fireNodeDestroyed() {}
431
432
        public void refreshChildren() {}
433
        
434
        public Object getAttachedData() {
435
            return null;
436
        }
437
        
438
    }
439
    */
440
    
441
    private static class TestingAction extends CallableSystemAction {
442
443
        private String name;
444
        
445
        TestingAction( String name ) {
446
            super();
447
            this.name = name;
448
        }
449
        
450
        public HelpCtx getHelpCtx() {
451
            return null;
452
        }
453
        
454
        public String getName() {
455
            return name;
456
        }
457
        
458
        public void performAction() {
459
        }
460
        
461
    }
462
    
463
    private static class TestingAction1 extends TestingAction {
464
        TestingAction1( String name ) {
465
            super( name );
466
        }
467
    }
468
    
469
    private static class TestingAction2 extends TestingAction {
470
        TestingAction2( String name ) {
471
            super( name );
472
        }
473
    }
474
    
475
    private static class TestingAction3 extends TestingAction {
476
        TestingAction3( String name ) {
477
            super( name );
478
        }
479
    }
480
    
481
    private static class TestingAction4 extends TestingAction {
482
        TestingAction4( String name ) {
483
            super( name );
484
        }
485
    }
486
    
487
    private static class TestingAction5 extends TestingAction {
488
        TestingAction5( String name ) {
489
            super( name );
490
        }
491
    }
492
}
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/SampleLook2Hid.java (-465 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.util.List;
17
import java.awt.Image;
18
import java.awt.image.BufferedImage;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.datatransfer.StringSelection;
21
import java.io.IOException;
22
import java.lang.reflect.*;
23
import java.util.Hashtable;
24
import javax.swing.JPanel;
25
import javax.swing.Action;
26
27
import org.openide.nodes.*;
28
import org.openide.loaders.XMLDataObject;
29
import org.openide.util.actions.SystemAction;
30
import org.openide.util.actions.CallableSystemAction;
31
import org.openide.util.HelpCtx;
32
import org.openide.util.datatransfer.NewType;
33
import org.openide.util.datatransfer.PasteType;
34
import org.openide.util.Lookup;
35
import org.openide.util.lookup.InstanceContent;
36
import org.openide.util.lookup.AbstractLookup;
37
38
/** Class used for testing. Every method returns some value. Usefull for testing 
39
 * FilterLook.
40
 *
41
 * @author Petr Hrebejk
42
 */
43
public class SampleLook2Hid extends Look {
44
    
45
    // Flags for method calls which do not return any value.
46
    boolean attachToCalled = false;
47
    boolean setNameCalled = false;
48
    boolean destroyCalled = false;
49
       
50
    // The values which are returned from this Look
51
    static final Node.Cookie VAL_COOKIE = new Node.Cookie() {};
52
    
53
    static final Look[] VAL_LOOKS = new Look[0];
54
    
55
    static final String VAL_NAME = "Node.Name";
56
    
57
    static final String VAL_DISPLAY_NAME = "Node.DisplayName";
58
    
59
    static final String VAL_SHORT_DESCRIPTION = "Node.ShortDescription";
60
    
61
    static final String[] VAL_KEYS = new String[] {
62
        "Child.1",
63
        "Child.2"
64
    };
65
    
66
    static final String[] VAL_KEYS_ADDED = new String[] {
67
        VAL_KEYS[0],
68
        "Child.1.a",
69
        VAL_KEYS[1]
70
    };
71
    
72
    static final String[] VAL_KEYS_REMOVED = new String[] {
73
        VAL_KEYS[0],
74
    };
75
    
76
    static final String[] VAL_KEYS_REORDERED = new String[] {
77
        VAL_KEYS[1],
78
        VAL_KEYS[0]
79
    };
80
    
81
    static final String[] VAL_KEYS_NO_CHANGE = new String[] {
82
        VAL_KEYS[0],
83
        VAL_KEYS[1]
84
    };
85
    
86
    static final Image VAL_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
87
    
88
    static final Image VAL_OPENED_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
89
    
90
    static final HelpCtx VAL_HELP_CTX = new HelpCtx( SampleLook1Hid.class );
91
    
92
    static final SystemAction[] VAL_ACTIONS = new SystemAction[] {
93
        new TestingAction1( "SystemAction1" ),
94
        new TestingAction2( "SystemAction2" )
95
    };
96
    
97
    static final SystemAction[] VAL_CONTEXT_ACTIONS = new SystemAction[] {
98
        new TestingAction3( "ContextAction1" ),
99
        new TestingAction4( "ContextAction2" )
100
    };
101
    
102
    static final SystemAction VAL_DEFAULT_ACTION = new TestingAction5( "DefaultAction" );
103
    
104
    static final JPanel VAL_CUSTOMIZER = new JPanel();
105
    
106
    static final Node.PropertySet[] VAL_PROPERTY_SETS = new Node.PropertySet[] {
107
        new Sheet.Set(),
108
        new Sheet.Set()
109
    };
110
    
111
    static final NewType[] VAL_NEW_TYPES = new NewType[] {
112
        new NewType() { 
113
            public void create() {  }
114
        },
115
        
116
        new NewType() { 
117
            public void create() {  }
118
        }
119
    };
120
    
121
    static final PasteType[] VAL_PASTE_TYPES = new PasteType[] {
122
        new PasteType() { 
123
            public Transferable paste() { return null; }
124
        },
125
        
126
        new PasteType() { 
127
            public Transferable paste() { return null; }
128
        }
129
    };
130
    
131
    static final PasteType VAL_DROP_TYPE = new PasteType() { 
132
        public Transferable paste() { return null; }
133
    };
134
    
135
    static final Transferable VAL_CLIPBOARD_COPY = new StringSelection( "ClipboardCopy" );
136
137
    static final Transferable VAL_CLIPBOARD_CUT = new StringSelection( "ClipboardCut" );
138
    
139
    static final Transferable VAL_DRAG = new StringSelection( "Drag" );
140
    
141
    // Hashtable which holds the relation Node - NodeSubstitute
142
    private Hashtable nodes2Substitutes = new Hashtable(); 
143
    
144
    // The value of keys which has to be returned
145
    private String[] keys = VAL_KEYS;
146
    
147
    /** Name of the look. 
148
     */
149
    private String name;
150
    
151
    static {
152
        VAL_PROPERTY_SETS[0].setName("SetC");
153
        VAL_PROPERTY_SETS[1].setName("SetD");
154
        Node n = new AbstractNode(Children.LEAF);
155
        ((Sheet.Set)VAL_PROPERTY_SETS[0]).put(new Node.Property[] {
156
            new PropertySupport.ReadOnly("PropC-1", String.class, "PropertyC-1", 
157
                "Property 1 from sheet C") {
158
                    public Object getValue() {
159
                        return "";
160
                    }
161
            }
162
        });
163
        ((Sheet.Set)VAL_PROPERTY_SETS[0]).put(new Node.Property[] {
164
            new PropertySupport.ReadOnly("PropC-2", String.class, "PropertyC-2", 
165
                "Property 2 from sheet C") {
166
                    public Object getValue() {
167
                        return "";
168
                    }
169
            }
170
        });
171
        ((Sheet.Set)VAL_PROPERTY_SETS[1]).put(new Node.Property[] {
172
            new PropertySupport.ReadOnly("PropD-1", String.class, "PropertyD-1", 
173
                "Property 1 from sheet D") {
174
                    public Object getValue() {
175
                        return "";
176
                    }
177
            }
178
        });
179
        ((Sheet.Set)VAL_PROPERTY_SETS[1]).put(new Node.Property[] {
180
            new PropertySupport.ReadOnly("PropD-2", String.class, "PropertyD-2", 
181
                "Property 1 from sheet D") {
182
                    public Object getValue() {
183
                        return "";
184
                    }
185
            }
186
        });
187
    }
188
189
    /** Creates new DefaultLook. The costructor is protected, there should 
190
     * be no need for creating new <CODE> DefaultLooks</CODE>. You can delegate
191
     * to {@link #INSTANCE} instead.
192
     */
193
    public SampleLook2Hid() {
194
    }
195
    
196
    // Additional methods for testing ------------------------------------------
197
    
198
    boolean getAttachToCalled() {
199
        boolean r = attachToCalled;
200
        attachToCalled = false;
201
        return r;
202
    }
203
        
204
    boolean getSetNameCalled() {
205
        boolean r = setNameCalled;
206
        setNameCalled = false;
207
        return r;
208
    }
209
        
210
        
211
    boolean getDestroyCalled() {
212
        boolean r = destroyCalled;
213
        destroyCalled = false;
214
        return r;
215
    }
216
    
217
    void setKeys( String[] val ) {
218
        keys = val;
219
    }
220
    
221
    // Private helper methods --------------------------------------------------
222
    
223
    private LookNode getNodeFromSubstitute( LookNode.SubstituteImpl subst ) {
224
        return subst.getLookNode ();
225
    }
226
    
227
    // Methods of look itself --------------------------------------------------
228
    
229
    
230
    // General methods ---------------------------------------------------------
231
232
    /** Sets the flag to be able to test wether the method was called. It 
233
     * also stores the Look.NodeSubstitutes in a hash table (indexed by the
234
     * node to provide them by the getNodeSubstitute( Node node ) method.
235
     */    
236
    public Object attachTo(Look.NodeSubstitute substitute) {
237
        attachToCalled = true;
238
        return null;
239
    }
240
    
241
    public Lookup createLookup (Look.NodeSubstitute substitute) {
242
        InstanceContent ic = new InstanceContent ();
243
        AbstractLookup lookup = new AbstractLookup (ic);
244
        ic.add (VAL_COOKIE);
245
        return lookup;
246
    }
247
248
    /** A list of possible modes this look can be switched into.
249
     *
250
     * @param substitute substitute to find modes for
251
     * @return the Mode or null if the switching is not available
252
     */
253
    public Look[] availableLooks(Look.NodeSubstitute substitute) {
254
        return VAL_LOOKS;
255
    }
256
    
257
    // Methods for STYLE -------------------------------------------------------
258
    
259
    public String getDisplayName( Look.NodeSubstitute substitute ) {
260
        return VAL_DISPLAY_NAME;
261
    }
262
    
263
    public String getName( Look.NodeSubstitute substitute ) {
264
        return VAL_NAME;
265
    }
266
    
267
    public void setName(Look.NodeSubstitute substitute, String newName ) {
268
        setNameCalled = true;
269
    }
270
    
271
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
272
        return VAL_SHORT_DESCRIPTION;
273
    }
274
    
275
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
276
        return VAL_ICON;
277
    }
278
    
279
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
280
        return VAL_OPENED_ICON;
281
    }
282
    
283
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
284
        return VAL_HELP_CTX;
285
    }
286
    
287
    // Methods for CHILDREN ----------------------------------------------------
288
    
289
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
290
        return keys;
291
    }
292
        
293
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
294
    
295
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
296
        return VAL_NEW_TYPES;
297
    }
298
    
299
    public Action[] getActions(Look.NodeSubstitute substitute) {
300
        return VAL_ACTIONS;
301
    }
302
    
303
    public Action[] getContextActions(Look.NodeSubstitute substitute) {
304
        return VAL_CONTEXT_ACTIONS;
305
    }
306
    
307
    public 
308
    Action getDefaultAction(Look.NodeSubstitute substitute) {
309
        return VAL_DEFAULT_ACTION;
310
    }
311
    
312
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
313
    
314
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
315
        return VAL_PROPERTY_SETS;
316
    }
317
    
318
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
319
        return VAL_CUSTOMIZER;
320
    }
321
    
322
    public boolean hasCustomizer( Look.NodeSubstitute substitute ) {
323
        return VAL_CUSTOMIZER != null;
324
    }
325
    
326
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
327
     
328
    public boolean canRename( Look.NodeSubstitute substitute ) {
329
        return true;
330
    }
331
    
332
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
333
        return true;
334
    }
335
    
336
    public boolean canCopy( Look.NodeSubstitute substitute ) {
337
        return true;
338
    }
339
    
340
    public boolean canCut( Look.NodeSubstitute substitute ) {
341
        return true;
342
    }
343
    
344
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
345
        return VAL_PASTE_TYPES;
346
    }
347
    
348
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
349
        return VAL_DROP_TYPE;
350
    }
351
    
352
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
353
        return VAL_CLIPBOARD_COPY;
354
    }
355
    
356
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
357
        return VAL_CLIPBOARD_CUT;
358
    }
359
    
360
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
361
        return VAL_DRAG;
362
    }
363
          
364
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
365
        destroyCalled = true;
366
    }
367
    
368
    /** The human presentable name of the look.
369
     * @return human presentable name
370
     */
371
    public String getDisplayName() {
372
        return "Disp1";
373
    }    
374
    
375
    /** Returns name of the look. This name should identify the look.
376
     * @return Name of the look.
377
     */
378
    public String getName() {
379
        return "Name1";
380
    }
381
    
382
    /*
383
    public static class NodeSubstitute extends Look.NodeSubstitute {
384
           
385
        public Object getRepresentedObject() { return null; }
386
        
387
        public void firePropertyChange( String name, Object o, Object n ) {}
388
389
        public void fireNameChange( String o, String n ) {}
390
        
391
        public void fireDisplayNameChange( String o, String n ) {}
392
        
393
        public void fireShortDescriptionChange(String o, String n) {}
394
395
        public void fireIconChange() {}
396
397
        public void fireOpenedIconChange() {}
398
399
        public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n ) {}
400
       
401
        public void fireCookieChange() {}
402
403
        public void fireNodeDestroyed() {}
404
405
        public void refreshChildren() {}
406
        
407
        public Object getAttachedData() {
408
            return null;
409
        }
410
        
411
    }*/
412
    
413
    
414
    private static class TestingAction extends CallableSystemAction {
415
416
        private String name;
417
        
418
        TestingAction( String name ) {
419
            super();
420
            this.name = name;
421
        }
422
        
423
        public HelpCtx getHelpCtx() {
424
            return null;
425
        }
426
        
427
        public String getName() {
428
            return name;
429
        }
430
        
431
        public void performAction() {
432
        }
433
        
434
    }
435
    
436
    private static class TestingAction1 extends TestingAction {
437
        TestingAction1( String name ) {
438
            super( name );
439
        }
440
    }
441
    
442
    private static class TestingAction2 extends TestingAction {
443
        TestingAction2( String name ) {
444
            super( name );
445
        }
446
    }
447
    
448
    private static class TestingAction3 extends TestingAction {
449
        TestingAction3( String name ) {
450
            super( name );
451
        }
452
    }
453
    
454
    private static class TestingAction4 extends TestingAction {
455
        TestingAction4( String name ) {
456
            super( name );
457
        }
458
    }
459
    
460
    private static class TestingAction5 extends TestingAction {
461
        TestingAction5( String name ) {
462
            super( name );
463
        }
464
    }
465
}
(-)openidex/looks/test/unit/src/org/netbeans/api/looks/SubstituteAccessTest.java (-211 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.api.looks;
15
16
import java.lang.ref.*;
17
import java.util.*;
18
19
//import junit.framework.*;
20
import org.netbeans.junit.*;
21
22
import java.util.List;
23
import java.awt.Image;
24
import java.awt.datatransfer.Transferable;
25
import java.io.IOException;
26
import javax.swing.Action;
27
28
29
import org.openide.nodes.*;
30
import org.openide.loaders.XMLDataObject;
31
import org.openide.util.actions.SystemAction;
32
import org.openide.util.HelpCtx;
33
import org.openide.util.datatransfer.NewType;
34
import org.openide.util.datatransfer.PasteType;
35
36
import org.netbeans.api.looks.*;
37
import org.netbeans.spi.looks.*;
38
39
40
41
42
public class SubstituteAccessTest extends NbTestCase {
43
    public SubstituteAccessTest(java.lang.String testName) {
44
        super(testName);
45
    }
46
    
47
    public static void main(java.lang.String[] args) {
48
        junit.textui.TestRunner.run(new NbTestSuite (SubstituteAccessTest.class));
49
    }
50
    
51
    /** Checks whether substitutes are garbage collected when not needed
52
     * anymore.
53
     */
54
    public void testLifeCycleOfSubstitutes () {
55
        MyLook look = new MyLook ();
56
57
        for (int cnt = 0; cnt < 5; cnt++) {
58
59
            MySubst s1 = new MySubst (look);
60
            MySubst s2 = new MySubst (look);
61
            MySubst s3 = new MySubst (look);
62
63
            HashSet all = new HashSet ();
64
            all.add (s1);
65
            all.add (s2);
66
            all.add (s3);
67
68
            HashSet temp = readEnum (3, look.allSubsts ());
69
            assertEquals ("Both sets should be equal", all, temp);
70
            // empty all references
71
            temp.clear();
72
73
            // disappearing one in the middle
74
            WeakReference ref = new WeakReference (s2);
75
            all.remove (s2);
76
            s2 = null;
77
            assertGC ("Should disappear", ref);
78
79
            temp = readEnum (2, look.allSubsts ());
80
            assertEquals ("Should contain just two elements", all, temp);
81
            temp.clear ();
82
83
            ref = new WeakReference (s3);
84
            all.remove (s3);
85
            s3 = null;
86
            assertGC ("Should disappear II", ref);
87
            
88
            temp = readEnum (1, look.allSubsts ());
89
            assertEquals ("Just one element", all, temp);
90
            temp.clear ();
91
92
            ref = new WeakReference (s1);
93
            all.remove (s1);
94
            s1 = null;
95
            assertGC ("Should disappear III", ref);
96
            
97
            assertTrue ("Empty", !look.allSubsts ().hasMoreElements ());
98
        }
99
    }
100
    
101
    /** Tests whether substitutes are not listed when they change look.
102
     */
103
    public void testChangeOfLook () {
104
        MyLook one = new MyLook ();
105
        MyLook two = new MyLook ();
106
        
107
        MySubst s1 = new MySubst (one);
108
109
        assertEquals ("S1 is attached to look one", one.allSubsts ().nextElement (), s1);
110
        assertTrue ("look two is empty", !two.allSubsts ().hasMoreElements());
111
        
112
        s1.setLook (two);
113
        
114
        assertEquals ("S1 is attached to look two", two.allSubsts ().nextElement (), s1);
115
        assertTrue ("look one is empty", !one.allSubsts ().hasMoreElements());
116
        
117
        s1.setLook (one);
118
        
119
        assertEquals ("S1 is attached to look one", one.allSubsts ().nextElement (), s1);
120
        assertTrue ("look two is empty", !two.allSubsts ().hasMoreElements());
121
122
        s1.setLook (null);
123
        
124
        assertTrue ("look one is empty", !one.allSubsts ().hasMoreElements());
125
        assertTrue ("look two is empty", !two.allSubsts ().hasMoreElements());
126
    }
127
    
128
    /** Extracts content of enumeration to a set
129
     */
130
    private HashSet readEnum (int expectSize, Enumeration en) {
131
        HashSet set = new HashSet ();
132
        
133
        for (int i = 1; i <= expectSize; i++) {
134
            assertTrue ("Expecting " + i + "th element", en.hasMoreElements());
135
            set.add (en.nextElement ());
136
        }
137
138
        assertTrue ("There should be just " + expectSize + " elements", !en.hasMoreElements ());
139
        
140
        return set;   
141
    }
142
    
143
    /** Do GC, waiting for ref to become null.
144
     */
145
    private void assertGC (String text, Reference ref) {
146
        for (int i = 0; i < 10; i++) {
147
            System.gc ();
148
            if (ref.get () == null) return;
149
        }
150
        
151
        assertNull (text, ref.get ());
152
    }
153
    
154
155
    private static final class MyLook extends DefaultLook {
156
        
157
        public MyLook () {
158
            super ("MyLook");
159
        }
160
        
161
        public String getDisplayName () {
162
            return "MyLook";
163
        }
164
        
165
        public Enumeration allSubsts () {
166
            return nodeSubstitutes ();
167
        }
168
    }
169
    
170
    private static final class MySubst extends Look.NodeSubstitute {
171
        public MySubst (Look look) {
172
            super.attachTo (look);
173
        }
174
        
175
        public void setLook (Look look) {
176
            super.attachTo (look);
177
        }
178
        
179
        
180
        public void fireDisplayNameChange(String o, String n) {
181
        }
182
        
183
        public void fireIconChange() {
184
        }
185
        
186
        public void fireNameChange(String o, String n) {
187
        }
188
        
189
        public void fireNodeDestroyed() {
190
        }
191
        
192
        public void fireOpenedIconChange() {
193
        }
194
        
195
        public void firePropertyChange(String name, Object o, Object n) {
196
        }
197
        
198
        public void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n) {
199
        }
200
        
201
        public void fireShortDescriptionChange(String o, String n) {
202
        }
203
        
204
        public Object getRepresentedObject() {
205
            return null;
206
        }
207
        
208
        public void refreshChildren() {
209
        }
210
    }
211
}
(-)openidex/looks/test/unit/src/org/netbeans/spi/looks/FilterLookTest.java (-653 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.util.Collection;
17
import java.util.List;
18
import java.awt.Image;
19
import java.awt.datatransfer.Transferable;
20
import java.io.IOException;
21
import javax.swing.Action;
22
23
import org.openide.nodes.*;
24
import org.openide.util.actions.SystemAction;
25
import org.openide.util.HelpCtx;
26
import org.openide.util.datatransfer.NewType;
27
import org.openide.util.datatransfer.PasteType;
28
29
import org.netbeans.api.looks.*;
30
import org.netbeans.spi.looks.*;
31
32
//import junit.framework.*;
33
import org.netbeans.junit.*;
34
35
public class FilterLookTest extends NbTestCase {
36
    
37
    private static final String MSSG_UNEXPECTED_EXCEPTION =  "Unexpected exception caught : ";
38
    
39
    /** Array with masks and results */
40
    private TestingItem[] testingItems = new TestingItem[] {
41
//        new TestingItem( FilterLook.ATTACH_TO, "ATTACH_TO" ), 
42
        new TestingItem( FilterLook.CREATE_LOOKUP, "CREATE_LOOKUP" ),
43
//        new TestingItem( FilterLook.GET_HANDLE, "GET_HANDLE" ),
44
        new TestingItem( FilterLook.GET_DISPLAY_NAME, "GET_DISPLAY_NAME" ),
45
        new TestingItem( FilterLook.GET_NAME, "GET_NAME" ),
46
        new TestingItem( FilterLook.SET_NAME, "SET_NAME" ),
47
        new TestingItem( FilterLook.GET_SHORT_DESCRIPTION, "GET_SHORT_DESCRIPTION" ),
48
        new TestingItem( FilterLook.GET_ICON, "GET_ICON" ),
49
        new TestingItem( FilterLook.GET_OPENED_ICON, "GET_OPENED_ICON" ),
50
        new TestingItem( FilterLook.GET_HELP_CTX, "GET_HELP_CTX" ),
51
        new TestingItem( FilterLook.GET_CHILD_OBJECTS, "GET_CHILD_OBJECTS" ),
52
        new TestingItem( FilterLook.GET_NEW_TYPES, "GET_NEW_TYPES" ),
53
        new TestingItem( FilterLook.GET_ACTIONS, "GET_ACTIONS" ),
54
        new TestingItem( FilterLook.GET_CONTEXT_ACTIONS, "GET_CONTEXT_ACTIONS" ),
55
        new TestingItem( FilterLook.GET_DEFAULT_ACTION, "GET_DEFAULT_ACTION" ),
56
        new TestingItem( FilterLook.GET_PROPERTY_SETS, "GET_PROPERTY_SETS" ),
57
        new TestingItem( FilterLook.GET_CUSTOMIZER, "GET_CUSTOMIZER" ),
58
        new TestingItem( FilterLook.CAN_RENAME, "CAN_RENAME" ),
59
        new TestingItem( FilterLook.CAN_DESTROY, "CAN_DESTROY" ),
60
        new TestingItem( FilterLook.CAN_COPY, "CAN_COPY" ),
61
        new TestingItem( FilterLook.CAN_CUT, "CAN_CUT" ),
62
        new TestingItem( FilterLook.GET_PASTE_TYPES, "GET_PASTE_TYPES" ),
63
        new TestingItem( FilterLook.GET_DROP_TYPE, "GET_DROP_TYPE" ),
64
        new TestingItem( FilterLook.CLIPBOARD_COPY, "CLIPBOARD_COPY" ),
65
        new TestingItem( FilterLook.CLIPBOARD_CUT, "CLIPBOARD_CUT" ),
66
        new TestingItem( FilterLook.DRAG, "DRAG" ),
67
        new TestingItem( FilterLook.DESTROY, "DESTROY" )
68
    };
69
    
70
    /** Filter look to test on */
71
    private FilterLook filterLook;
72
    
73
    /** Look which will be filtered */
74
    private SampleLook1Hid sampleLook;
75
    
76
    /** Node substitute to test on */
77
    private FilterLook.S substitute;
78
    
79
    /** Name to be set */
80
    private static final String NAME_TO_SET = "SomeName";
81
    
82
    int ICON_TYPE = 0;
83
    
84
    int OPENED_ICON_TYPE = 0;
85
    
86
    Transferable PASTE_TYPE = null;
87
    
88
    Transferable DROP_TYPE = null;
89
    int DROP_INDEX = 0;
90
    int DROP_ACTION = 0;
91
    
92
    
93
    
94
    public FilterLookTest(java.lang.String testName) {
95
        super(testName);
96
    }
97
    
98
    public static void main(java.lang.String[] args) {
99
        junit.textui.TestRunner.run(suite());
100
    }
101
    
102
    public static NbTest suite() {
103
        NbTestSuite suite = new NbTestSuite(FilterLookTest.class);
104
        
105
        return suite;
106
    }
107
    
108
    protected void setUp() throws Exception {
109
        super.setUp();
110
        
111
        // add specific setup code here
112
        sampleLook = new SampleLook1Hid();
113
        filterLook = new FilterLook( sampleLook );
114
        
115
116
        LookNode n = new LookNode (new Object (), sampleLook);
117
        assertNotNull("A substitute should be assigned", sampleLook.substitute);
118
        
119
        substitute = filterLook.new S (filterLook, sampleLook.substitute);
120
    }
121
    
122
    protected void tearDown() throws Exception {
123
        // add specific tear-down code here
124
        filterLook = null; 
125
        substitute = null;
126
        sampleLook = null;
127
        
128
        super.tearDown();
129
    }
130
    
131
    
132
    /** Test of setLookMask method, of class org.openidex.nodes.looks.FilterLook. */
133
    /*
134
    public void testSetLookMask() {
135
        System.out.println("testSetLookMask");
136
        
137
        // Add your test code below by replacing the default call to fail.
138
        fail("The test case is empty.");
139
    }
140
    */
141
    /** Test of getLookMask method, of class org.openidex.nodes.looks.FilterLook. */
142
    /*
143
    public void testGetLookMask() {
144
        System.out.println("testGetLookMask");
145
        
146
        // Add your test code below by replacing the default call to fail.
147
        fail("The test case is empty.");
148
    }
149
    */
150
    
151
    /** Test of lookMask method, of class org.openidex.nodes.looks.FilterLook. */
152
    /*
153
    public void testLookMask() {
154
        System.out.println("testLookMask");
155
        
156
        // Add your test code below by replacing the default call to fail.
157
        fail("The test case is empty.");
158
    }
159
    */
160
    
161
    /** Test of lookUnmask method, of class org.openidex.nodes.looks.FilterLook. */
162
    /*
163
    public void testLookUnmask() {
164
        System.out.println("testLookUnmask");
165
        
166
        // Add your test code below by replacing the default call to fail.
167
        fail("The test case is empty.");
168
    }
169
    */
170
    /** Test of attachTo method, of class org.openidex.nodes.looks.FilterLook. */
171
    /*
172
    public void testAttachTo() {
173
        System.out.println("testAttachTo");
174
        
175
        // Add your test code below by replacing the default call to fail.
176
        fail("The test case is empty.");
177
    }
178
    */
179
    
180
    /** Tests whether the constants defined in the right order and whether
181
     * there is no owerflow.
182
     */
183
    public void testMaskOrder() {
184
        System.out.println("testMaskOrder");
185
        
186
        // Add your test code below by replacing the default call to fail.
187
        
188
        for ( int i = 0, j = 1; i < testingItems.length; i++ ) {
189
            if ( testingItems[i].mask != j ) {
190
                fail("Ordering failed : " + i );
191
            }
192
            j *= 2;
193
        }               
194
    }
195
/*    
196
    public void test_ATTACH_TO() {
197
        System.out.println("test_ATTACH_TO");
198
        
199
        // Add your test code below by replacing the default call to fail.
200
        int failIndex = doTestingWithMask( FilterLook.ATTACH_TO );
201
        if ( failIndex > -1 ) {
202
            fail( getFailMessage( failIndex) );
203
        }
204
    }
205
*/    
206
    public void test_CREATE_LOOKUP () {
207
        System.out.println("test_GET_COOKIE");
208
        
209
        // Add your test code below by replacing the default call to fail.
210
        int failIndex = doTestingWithMask( FilterLook.CREATE_LOOKUP );
211
        if ( failIndex > -1 ) {
212
            fail( getFailMessage( failIndex ) );
213
        }
214
    }
215
/*    
216
    public void test_GET_HANDLE() {
217
        System.out.println("test_GET_HANDLE");
218
        
219
        // Add your test code below by replacing the default call to fail.
220
        int failIndex = doTestingWithMask( FilterLook.GET_HANDLE );
221
        if ( failIndex > -1 ) {
222
            fail( getFailMessage( failIndex ) );
223
        }
224
    }
225
*/    
226
    public void test_GET_DISPLAY_NAME() {
227
        System.out.println("test_GET_DISPLAY_NAME");
228
        
229
        // Add your test code below by replacing the default call to fail.
230
        int failIndex = doTestingWithMask( FilterLook.GET_DISPLAY_NAME );
231
        if ( failIndex > -1 ) {
232
            fail( getFailMessage( failIndex ) );
233
        }
234
    }
235
    
236
    public void test_GET_NAME() {
237
        System.out.println("test_GET_NAME");
238
        
239
        // Add your test code below by replacing the default call to fail.
240
        int failIndex = doTestingWithMask( FilterLook.GET_NAME );
241
        if ( failIndex > -1 ) {
242
            fail( getFailMessage( failIndex ) );
243
        }
244
    }
245
    
246
    public void test_SET_NAME() {
247
        System.out.println("test_SET_NAME");
248
        
249
        // Add your test code below by replacing the default call to fail.
250
        int failIndex = doTestingWithMask( FilterLook.SET_NAME );
251
        if ( failIndex > -1 ) {
252
            fail( getFailMessage( failIndex ) );
253
        }
254
    }
255
    
256
    public void test_GET_SHORT_DESCRIPTION () {
257
        System.out.println("test_GET_SHORT_DESCRIPTION");
258
        
259
        // Add your test code below by replacing the default call to fail.
260
        int failIndex = doTestingWithMask( FilterLook.GET_SHORT_DESCRIPTION );
261
        if ( failIndex > -1 ) {
262
            fail( getFailMessage( failIndex ) );
263
        }
264
    }
265
    
266
    public void test_GET_ICON() {
267
        System.out.println("test_GET_ICON");
268
        
269
        // Add your test code below by replacing the default call to fail.
270
        int failIndex = doTestingWithMask( FilterLook.GET_ICON );
271
        if ( failIndex > -1 ) {
272
            fail( getFailMessage( failIndex ) );
273
        }
274
    }
275
    public void test_GET_OPENED_ICON () {
276
        System.out.println("test_GET_OPENED_ICON");
277
        
278
        // Add your test code below by replacing the default call to fail.
279
        int failIndex = doTestingWithMask( FilterLook.GET_OPENED_ICON );
280
        if ( failIndex > -1 ) {
281
            fail( getFailMessage( failIndex ) );
282
        }
283
    }
284
    public void test_GET_HELP_CTX () {
285
        System.out.println("test_GET_HELP_CTX");
286
        
287
        // Add your test code below by replacing the default call to fail.
288
        int failIndex = doTestingWithMask( FilterLook.GET_HELP_CTX );
289
        if ( failIndex > -1 ) {
290
            fail( getFailMessage( failIndex ) );
291
        }
292
    }
293
    
294
    public void test_GET_CHILD_OBJECTS () {
295
        System.out.println("test_GET_CHILD_OBJECTS");
296
        
297
        // Add your test code below by replacing the default call to fail.
298
        int failIndex = doTestingWithMask( FilterLook.GET_CHILD_OBJECTS );
299
        if ( failIndex > -1 ) {
300
            fail( getFailMessage( failIndex ) );
301
        }
302
    }
303
    
304
    public void test_GET_NEW_TYPES () {
305
        System.out.println("test_GET_NEW_TYPES");
306
        
307
        // Add your test code below by replacing the default call to fail.
308
        int failIndex = doTestingWithMask( FilterLook.GET_NEW_TYPES );
309
        if ( failIndex > -1 ) {
310
            fail( getFailMessage( failIndex ) );
311
        }
312
    }
313
    
314
    public void test_GET_ACTIONS () {
315
        System.out.println("test_GET_ACTIONS");
316
        
317
        // Add your test code below by replacing the default call to fail.
318
        int failIndex = doTestingWithMask( FilterLook.GET_ACTIONS );
319
        if ( failIndex > -1 ) {
320
            fail( getFailMessage( failIndex ) );
321
        }
322
    }
323
    
324
    public void test_GET_CONTEXT_ACTIONS () {
325
        System.out.println("test_GET_CONTEXT_ACTIONS");
326
        
327
        // Add your test code below by replacing the default call to fail.
328
        int failIndex = doTestingWithMask( FilterLook.GET_CONTEXT_ACTIONS );
329
        if ( failIndex > -1 ) {
330
            fail( getFailMessage( failIndex ) );
331
        }
332
    }
333
    
334
    public void test_GET_DEFAULT_ACTION () {
335
        System.out.println("test_GET_DEFAULT_ACTION");
336
        
337
        // Add your test code below by replacing the default call to fail.
338
        int failIndex = doTestingWithMask( FilterLook.GET_DEFAULT_ACTION );
339
        if ( failIndex > -1 ) {
340
            fail( getFailMessage( failIndex ) );
341
        }
342
    }
343
    
344
    public void test_GET_PROPERTY_SETS () {
345
        System.out.println("test_GET_PROPERTY_SETS");
346
        
347
        // Add your test code below by replacing the default call to fail.
348
        int failIndex = doTestingWithMask( FilterLook.GET_PROPERTY_SETS );
349
        if ( failIndex > -1 ) {
350
            fail( getFailMessage( failIndex ) );
351
        }
352
    }
353
    
354
    public void test_GET_CUSTOMIZER () {
355
        System.out.println("test_GET_CUSTOMIZER");
356
        
357
        // Add your test code below by replacing the default call to fail.
358
        int failIndex = doTestingWithMask( FilterLook.GET_CUSTOMIZER );
359
        if ( failIndex > -1 ) {
360
            fail( getFailMessage( failIndex ) );
361
        }
362
    }
363
    
364
    public void test_CAN_RENAME () {
365
        System.out.println("test_CAN_RENAME");
366
        
367
        // Add your test code below by replacing the default call to fail.
368
        int failIndex = doTestingWithMask( FilterLook.CAN_RENAME );
369
        if ( failIndex > -1 ) {
370
            fail( getFailMessage( failIndex ) );
371
        }
372
    }
373
    
374
    public void test_CAN_DESTROY () {
375
        System.out.println("test_CAN_DESTROY");
376
        
377
        // Add your test code below by replacing the default call to fail.
378
        int failIndex = doTestingWithMask( FilterLook.CAN_DESTROY );
379
        if ( failIndex > -1 ) {
380
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
381
        }
382
    }
383
    
384
    public void test_CAN_COPY () {
385
        System.out.println("test_CAN_COPY");
386
        
387
        // Add your test code below by replacing the default call to fail.
388
        int failIndex = doTestingWithMask( FilterLook.CAN_COPY );
389
        if ( failIndex > -1 ) {
390
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
391
        }
392
    }
393
    
394
    public void test_CAN_CUT () {
395
        System.out.println("test_CAN_CUT");
396
        
397
        // Add your test code below by replacing the default call to fail.
398
        int failIndex = doTestingWithMask( FilterLook.CAN_CUT );
399
        if ( failIndex > -1 ) {
400
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
401
        }
402
    }
403
    
404
    public void test_GET_PASTE_TYPES () {
405
        System.out.println("test_GET_PASTE_TYPES");
406
        
407
        // Add your test code below by replacing the default call to fail.
408
        int failIndex = doTestingWithMask( FilterLook.GET_PASTE_TYPES );
409
        if ( failIndex > -1 ) {
410
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
411
        }
412
    }
413
    
414
    public void test_GET_DROP_TYPE () {
415
        System.out.println("test_GET_DROP_TYPE");
416
        
417
        // Add your test code below by replacing the default call to fail.
418
        int failIndex = doTestingWithMask( FilterLook.GET_DROP_TYPE );
419
        if ( failIndex > -1 ) {
420
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
421
        }
422
    }
423
    
424
    public void test_CLIPBOARD_COPY () {
425
        System.out.println("test_CLIPBOARD_COPY");
426
        
427
        // Add your test code below by replacing the default call to fail.
428
        int failIndex = doTestingWithMask( FilterLook.CLIPBOARD_COPY );
429
        if ( failIndex > -1 ) {
430
            fail( getFailMessage( failIndex ) );
431
        }
432
    }
433
    
434
    public void test_CLIPBOARD_CUT () {
435
        System.out.println("test_CLIPBOARD_CUT");
436
        
437
        // Add your test code below by replacing the default call to fail.
438
        int failIndex = doTestingWithMask( FilterLook.CLIPBOARD_CUT );
439
        if ( failIndex > -1 ) {
440
            fail( getFailMessage( failIndex ) );
441
        }
442
    }
443
    
444
    public void test_DRAG () {
445
        System.out.println("test_DRAG");
446
        
447
        // Add your test code below by replacing the default call to fail.
448
        int failIndex = doTestingWithMask( FilterLook.DRAG );
449
        if ( failIndex > -1 ) {
450
            fail( getFailMessage( failIndex ));
451
        }
452
    }
453
    
454
    public void test_DESTROY () {
455
        System.out.println("test_DESTROY");
456
        
457
        // Add your test code below by replacing the default call to fail.
458
        int failIndex = doTestingWithMask( FilterLook.DESTROY );
459
        if ( failIndex > -1 ) {
460
            fail( getFailMessage( failIndex ) );
461
        }
462
    }
463
    
464
    // Private methods ---------------------------------------------------------    
465
    
466
    private int doTestingWithMask( long mask ) {
467
        filterLook.setLookMask( mask );
468
        clearTestArray();
469
        fillTestArray();
470
        
471
        for( int i = 0; i < testingItems.length; i ++ ) {
472
            if ( ( ( testingItems[i].mask & mask ) > 0 && testingItems[i].value == null ) || 
473
                 ( ( testingItems[i].mask & mask ) == 0 && testingItems[i].value != null )) {
474
                return i;
475
            }
476
        }
477
        
478
        return -1;
479
    }
480
    
481
    private void clearTestArray() {
482
        for ( int i = 0; i < testingItems.length; i++ ) {
483
            testingItems[i].value = null;
484
        }
485
    }
486
        
487
    private void fillTestArray() {
488
         
489
        int i = 0;
490
            
491
        
492
        filterLook.attachTo( substitute );
493
        Boolean attachTo = sampleLook.getAttachToCalled( ) ? Boolean.TRUE : null;
494
        
495
        org.openide.util.Lookup lookup = filterLook.createLookup ( substitute );
496
        
497
        Object handle = filterLook.availableLooks ( substitute );
498
        
499
        String displayName = filterLook.getDisplayName( substitute );
500
        
501
        String name = filterLook.getName( substitute );
502
        
503
        filterLook.setName(substitute, NAME_TO_SET );
504
        String setName = sampleLook.getSetNameCalled() ? NAME_TO_SET : null;
505
        
506
        String shortDescription = filterLook.getShortDescription( substitute );
507
        
508
        Image icon = filterLook.getIcon( substitute, ICON_TYPE );
509
        
510
        Image openedIcon = filterLook.getOpenedIcon( substitute, OPENED_ICON_TYPE );
511
        
512
        HelpCtx helpCtx = filterLook.getHelpCtx( substitute );
513
        
514
        Object[] children = filterLook.getChildObjects( substitute );
515
        
516
        NewType[] newTypes = filterLook.getNewTypes( substitute );
517
        
518
        Action[] systemActions = filterLook.getActions( substitute );
519
        
520
        Action[] contextActions = filterLook.getContextActions( substitute );
521
        
522
        Action defaultAction = filterLook.getDefaultAction( substitute );
523
        
524
        Node.PropertySet[] propertySets = filterLook.getPropertySets( substitute );
525
        
526
        java.awt.Component customizer = filterLook.getCustomizer( substitute );
527
        
528
        Boolean canRename = filterLook.canRename( substitute ) ? Boolean.TRUE : null;
529
        
530
        Boolean canDestroy = filterLook.canDestroy( substitute )? Boolean.TRUE : null;
531
        
532
        Boolean canCopy = filterLook.canCopy( substitute )? Boolean.TRUE : null;
533
        
534
        Boolean canCut = filterLook.canCut( substitute )? Boolean.TRUE : null;
535
        
536
        PasteType[] pasteTypes = filterLook.getPasteTypes( substitute, PASTE_TYPE );
537
        
538
        PasteType dropType = filterLook.getDropType( substitute, DROP_TYPE, DROP_ACTION, DROP_INDEX );
539
        Transferable copy = null;
540
        try {
541
             copy = filterLook.clipboardCopy( substitute );
542
        }
543
        catch ( java.io.IOException e ) {
544
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
545
        }
546
        Transferable cut  = null;
547
        try {
548
            cut = filterLook.clipboardCut( substitute );
549
        }
550
        catch ( java.io.IOException e ) {
551
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
552
        }    
553
        Transferable drag = null;
554
        try {
555
            drag = filterLook.drag( substitute );
556
        }
557
        catch ( java.io.IOException e ) {
558
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
559
        }    
560
        Boolean destroy = null;
561
        try {
562
            filterLook.destroy( substitute );
563
            destroy = sampleLook.getDestroyCalled() ? Boolean.TRUE : null;
564
        }        
565
        catch ( java.io.IOException e ) {
566
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
567
        }   
568
        
569
        
570
//        testingItems[i].value = attachTo; 
571
//        i++;
572
        testingItems[i].value = lookup; 
573
        i++;
574
//        testingItems[i].value = handle; 
575
//        i++;
576
        testingItems[i].value = displayName; 
577
        i++;
578
        testingItems[i].value = name; 
579
        i++;
580
        testingItems[i].value = setName; 
581
        i++;
582
        testingItems[i].value = shortDescription; 
583
        i++;
584
        testingItems[i].value = icon; 
585
        i++;
586
        testingItems[i].value = openedIcon; 
587
        i++;
588
        testingItems[i].value = helpCtx; 
589
        i++;
590
        testingItems[i].value = children; 
591
        i++;
592
        testingItems[i].value = newTypes; 
593
        i++;
594
        testingItems[i].value = systemActions; 
595
        i++;
596
        testingItems[i].value = contextActions; 
597
        i++;
598
        testingItems[i].value = defaultAction; 
599
        i++;
600
        testingItems[i].value = propertySets; 
601
        i++;
602
        testingItems[i].value = customizer; 
603
        i++;
604
        testingItems[i].value = canRename; 
605
        i++;
606
        testingItems[i].value = canDestroy; 
607
        i++;
608
        testingItems[i].value = canCopy; 
609
        i++;
610
        testingItems[i].value = canCut; 
611
        i++;
612
        testingItems[i].value = pasteTypes; 
613
        i++;
614
        testingItems[i].value = dropType; 
615
        i++;
616
        testingItems[i].value = copy; 
617
        i++;
618
        testingItems[i].value = cut; 
619
        i++;
620
        testingItems[i].value = drag; 
621
        i++;
622
        testingItems[i].value = destroy; 
623
        i++;
624
        
625
    }
626
    
627
    private String getFailMessage( int failIndex ) {
628
        return "Failed on method index : " + failIndex + " :  " +
629
            testingItems[ failIndex ].name +  " = " +
630
            testingItems[ failIndex ].value;
631
    }
632
        
633
    // Innerclasses ------------------------------------------------------------
634
  
635
    /** Represents one item in the test array.
636
     */     
637
    private class TestingItem {
638
639
        private long mask;
640
641
        private Object value;
642
643
        private String name;
644
        
645
        
646
        TestingItem( long mask, String name  ) {
647
            this.mask = mask;
648
            this.name = name;
649
        }
650
651
    }    
652
   
653
}
(-)openidex/looks/test/unit/src/org/netbeans/spi/looks/NamespaceLookTest.java (-122 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.lang.reflect.*;
17
import java.util.*;
18
import java.awt.*;
19
import java.awt.datatransfer.Transferable;
20
import java.io.IOException;
21
import javax.swing.Action;
22
23
import org.openide.nodes.*;
24
import org.openide.util.actions.SystemAction;
25
import org.openide.util.HelpCtx;
26
import org.openide.util.datatransfer.NewType;
27
import org.openide.util.datatransfer.PasteType;
28
import org.openide.util.Lookup;
29
30
import org.netbeans.api.looks.*;
31
import org.netbeans.spi.looks.*;
32
33
import org.netbeans.junit.*;
34
import java.beans.PropertyChangeListener;
35
36
/**
37
 *
38
 * @author  Jaroslav Tulach
39
 */
40
public class NamespaceLookTest extends NbTestCase {
41
    
42
    public NamespaceLookTest (java.lang.String testName) {
43
        super(testName);
44
    }
45
    
46
    public static void main(java.lang.String[] args) {
47
        junit.textui.TestRunner.run(new NbTestSuite (NamespaceLookTest.class));
48
    }
49
    
50
    /** For object an object is found.
51
     */
52
    public void testObjectIsFound () {
53
        Enumeration en = new L ().names (new Object ());
54
        assertClass ("Object is found", Object.class, en.nextElement ());
55
        assertTrue ("No more items", !en.hasMoreElements());
56
    }
57
    
58
    /** Test that the default namespace look works correctly on a hierarchy 
59
     * of objects.
60
     */
61
    public void testInterfaceBeforeObject () {
62
        class O extends Object implements Runnable {
63
            public void run () {};
64
        }
65
        
66
        Enumeration en = new L ().names (new O ());
67
        assertClass ("Actual class is allways first", O.class, en.nextElement ());
68
        assertClass ("Interface takes precedence", Runnable.class, en.nextElement());
69
        assertClass ("Object is the last fallback", Object.class, en.nextElement ());
70
        assertTrue ("No more items", !en.hasMoreElements());
71
    }
72
    
73
    /** All interfaces are introspected.
74
     */
75
    public void testAllInterfacesAreChecked () {
76
        // Action is a interface that extends another interface
77
        class O extends Object implements javax.swing.Action {
78
            public void actionPerformed (java.awt.event.ActionEvent ev) {}
79
            public Object getValue (String s) { return null; }
80
            public void putValue (String s, Object o) {}
81
            public void setEnabled (boolean b) {}
82
            public boolean isEnabled () { return false; }
83
            public void addPropertyChangeListener (PropertyChangeListener l) {}
84
            public void removePropertyChangeListener (PropertyChangeListener l) {}
85
        }
86
        
87
        Enumeration en = new L ().names (new O ());
88
        assertClass ("Actual class is always first", O.class, en.nextElement ());
89
        assertClass ("It implements Action interface", javax.swing.Action.class, en.nextElement ());
90
        assertClass ("And the interfaces extends ActionListener", java.awt.event.ActionListener.class, en.nextElement ());
91
        assertClass ("ActionListener is a listener", java.util.EventListener.class, en.nextElement ());
92
        assertClass ("Last is as usually Object", Object.class, en.nextElement ());
93
        assertTrue ("And we are done", !en.hasMoreElements ());
94
        
95
    }
96
        
97
    /** Asserts name of class with a name in a namespace
98
     */
99
    private static final void assertClass (String txt, Class c, Object obj) {
100
        assertEquals (txt, c.getName ().replace ('.', '/'), obj);
101
    }
102
    
103
    
104
    /** Innerclass to get access to namesFor method */
105
    private static final class L extends NamespaceLook {
106
        public L () {
107
            super ("");
108
        }
109
        
110
        public String getName () {
111
            return "";
112
        }
113
        public String getDisplayName () {
114
            return "";
115
        }
116
        
117
        public Enumeration names (Object obj) {
118
            return namesFor (obj);
119
        }
120
        
121
    }
122
}
(-)openidex/looks/test/unit/src/org/netbeans/spi/looks/ProxyLookTest.java (-980 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.looks;
15
16
import java.lang.reflect.*;
17
import java.util.*;
18
import java.awt.*;
19
import java.awt.datatransfer.Transferable;
20
import java.io.IOException;
21
import javax.swing.Action;
22
23
import org.openide.nodes.*;
24
import org.openide.util.actions.SystemAction;
25
import org.openide.util.HelpCtx;
26
import org.openide.util.datatransfer.NewType;
27
import org.openide.util.datatransfer.PasteType;
28
import org.openide.util.Lookup;
29
30
import org.netbeans.api.looks.*;
31
import org.netbeans.spi.looks.*;
32
33
import org.netbeans.junit.*;
34
/**
35
 *
36
 * @author  Svata Dedic
37
 */
38
public class ProxyLookTest extends NbTestCase {
39
    static final Object DATA = new Object();
40
    
41
    /**
42
     * The Look being tested
43
     */
44
    Prx   look;
45
    
46
    MySubst mySubst;
47
    
48
    Look.NodeSubstitute     proxySubst;
49
    
50
    ProxyDel[]  maskDelegates;
51
    
52
    Object[] customData;
53
    
54
    Object[] actualDelegateData;
55
    
56
    Look.NodeSubstitute[] delegateSubsts;
57
    
58
    int delegateCount;
59
    /**
60
     * Delegates, which will be returned from delegateTo
61
     */
62
    Look[]  forceDelegates;
63
    
64
    Method substAccessor;
65
    
66
    int testedMethodIndex = -1;
67
    
68
    String fakeName;
69
    
70
    static final int FAKE = 39;
71
    
72
    /** Creates a new instance of ProxyLookTest */
73
    public ProxyLookTest(String n) {
74
        super(n);
75
    }
76
    
77
    public String name() {
78
        if (fakeName != null)
79
            return fakeName;
80
        else
81
            return super.name();
82
    }
83
    
84
    public void setUp() {
85
        look = new Prx();
86
        setupDelegates();
87
    }
88
    
89
    public void tearDown() {
90
    }
91
    
92
    public static void main(java.lang.String[] args) {
93
        junit.textui.TestRunner.run(suite());
94
    }
95
    
96
    public static NbTest suite() {
97
        NbTestSuite suite = new NbTestSuite(ProxyLookTest.class);
98
        return suite;
99
    }
100
    
101
    private void setupDelegates() {
102
        maskDelegates = new ProxyDel[40];
103
        customData = new Object[40];
104
        delegateSubsts = new Look.NodeSubstitute[40];
105
        int count = 0;
106
        Look del = new SampleLook1Hid();
107
        for (int i = 1; i <= ProxyLook.HAS_CUSTOMIZER; i <<= 1, count++) {
108
            maskDelegates[count] = new ProxyDel(del, count, 1 << count, customData[count] = new Object());
109
        }
110
        delegateCount = count;
111
        mySubst = new MySubst(look);
112
    }
113
    
114
    /**
115
     * Tests whether the createData was called
116
     */
117
    public void testProxySubstitute() {
118
        assertSame("Incorrect substitute on the proxy look", mySubst, proxySubst);
119
    }
120
    
121
    /**
122
     * Tests whether the createData was called
123
     */
124
    public void testCreateData() {
125
        if (!look.createCalled) {
126
            fail("Create was not called");
127
        }
128
    }
129
    
130
    /**
131
     * Checks whether there are correct data attached to the Look.
132
     */
133
    public void testOwnAttachedData() {
134
        if (look.getAttachedData(mySubst) != DATA) {
135
            fail("ProxyLook got incorrect attached data");
136
        }
137
    }
138
    
139
    public void testDelegateSubstitutes() {
140
        forceDelegates = maskDelegates;
141
        look.delAll = true;
142
        Object[] children = look.getChildObjects(mySubst);
143
        for (int i = 0; i < delegateCount; i++) {
144
            assertNotNull("Delegate " + maskDelegates[i] + " reported null substitute",
145
            delegateSubsts[i]);
146
            // check the substitute the ProxyLook knows is
147
            // the same as reported by the delegate
148
            assertSame("ProxyLook recorded incorrect substitute for " + maskDelegates[i],
149
            getSubstitute(mySubst, maskDelegates[i], i), delegateSubsts[i]);
150
        }
151
    }
152
    
153
    public void testDelegateAttachedData() {
154
        forceDelegates = maskDelegates;
155
        actualDelegateData = new Object[delegateCount];
156
        look.delAll = true;
157
        Object[] x = look.getChildObjects(mySubst);
158
        for (int i = 0; i < delegateCount; i++) {
159
            assertSame("Attached data mismatch for delegate " + maskDelegates[i],
160
            actualDelegateData[i], customData[i]);
161
        }
162
    }
163
164
    public void testCanCopy() {
165
        ProxyDel del = createDelegate(ProxyLook.CAN_COPY);
166
        boolean b = look.canCopy(mySubst);
167
        assertTrue("Incorrect value", b);
168
        ensureQueried(ProxyLook.CAN_COPY, getIndex(ProxyLook.CAN_COPY));
169
        assertTrue("Fake delegate queried", del.queried == 0);
170
    }
171
    
172
    public void testCanCut() {
173
        ProxyDel del = createDelegate(ProxyLook.CAN_CUT);
174
        boolean b = look.canCut(mySubst);
175
        assertTrue("Incorrect value", b);
176
        ensureQueried(ProxyLook.CAN_CUT, getIndex(ProxyLook.CAN_CUT));
177
        assertTrue("Fake delegate queried", del.queried == 0);
178
    }
179
    
180
    public void testCanDestroy() {
181
        ProxyDel del = createDelegate(ProxyLook.CAN_DESTROY);
182
        boolean b = look.canDestroy(mySubst);
183
        assertTrue("Incorrect value", b);
184
        ensureQueried(ProxyLook.CAN_DESTROY, getIndex(ProxyLook.CAN_DESTROY));
185
        assertTrue("Fake delegate queried", del.queried == 0);
186
    }
187
    
188
    public void testCanRename() {
189
        ProxyDel del = createDelegate(ProxyLook.CAN_RENAME);
190
        boolean b = look.canRename(mySubst);
191
        assertTrue("Incorrect value", b);
192
        ensureQueried(ProxyLook.CAN_RENAME, getIndex(ProxyLook.CAN_RENAME));
193
        assertTrue("Fake delegate queried", del.queried == 0);
194
    }
195
    
196
    public void testClipboardCut() {
197
        ProxyDel del = createDelegate(ProxyLook.CLIPBOARD_CUT);
198
        try {
199
            Transferable t = look.clipboardCut(mySubst);
200
            int index = getIndex(ProxyLook.CLIPBOARD_CUT);
201
            assertSame("Incorrect transferable: ", t,
202
            maskDelegates[index].clipboardCut(delegateSubsts[index]));
203
            ensureQueried(ProxyLook.CLIPBOARD_CUT, index);
204
            assertTrue("Fake delegate queried", del.queried == 0);
205
        } catch (IOException ex) {
206
            fail(ex.getMessage());
207
        }
208
    }
209
    
210
    public void testDrag() {
211
        ProxyDel del = createDelegate(ProxyLook.DRAG);
212
        try {
213
            Transferable t = look.drag(mySubst);
214
            int index = getIndex(ProxyLook.DRAG);
215
            assertSame("Incorrect transferable: ", t,
216
            maskDelegates[index].drag(delegateSubsts[index]));
217
            ensureQueried(ProxyLook.DRAG, index);
218
            assertTrue("Fake delegate queried", del.queried == 0);
219
        } catch (IOException ex) {
220
            fail(ex.getMessage());
221
        }
222
    }
223
224
    public void testClipboardCopy() {
225
        ProxyDel del = createDelegate(ProxyLook.CLIPBOARD_COPY);
226
        try {
227
            Transferable t = look.clipboardCopy(mySubst);
228
            int index = getIndex(ProxyLook.CLIPBOARD_COPY);
229
            assertSame("Incorrect transferable: ", t,
230
            maskDelegates[index].clipboardCopy(delegateSubsts[index]));
231
            ensureQueried(ProxyLook.CLIPBOARD_COPY, index);
232
            assertTrue("Fake delegate queried", del.queried == 0);
233
        } catch (IOException ex) {
234
            fail(ex.getMessage());
235
        }
236
    }
237
    
238
    public void testGetCustomizer() {
239
        ProxyDel del = createDelegate(ProxyLook.GET_CUSTOMIZER);
240
        Component c = look.getCustomizer(mySubst);
241
        int index = getIndex(ProxyLook.GET_CUSTOMIZER);
242
        assertSame("Incorrect customizer", c,
243
        maskDelegates[index].getCustomizer(delegateSubsts[index]));
244
        ensureQueried(ProxyLook.GET_CUSTOMIZER, index);
245
        assertTrue("Fake delegate queried", del.queried == 0);
246
    }
247
248
    public void testGetDefaultAction() {
249
        ProxyDel del = createDelegate(ProxyLook.GET_DEFAULT_ACTION);
250
        Object n = look.getDefaultAction(mySubst);
251
        int index = getIndex(ProxyLook.GET_DEFAULT_ACTION);
252
        assertSame(maskDelegates[index].getDefaultAction(delegateSubsts[index]), n);
253
        assertTrue("Fake delegate queried", del.queried == 0);
254
    }
255
    
256
    public void testGetName() {
257
        ProxyDel del = createDelegate(ProxyLook.GET_NAME);
258
        String n = look.getName(mySubst);
259
        int index = getIndex(ProxyLook.GET_NAME);
260
        assertEquals(maskDelegates[index].getName(delegateSubsts[index]), n);
261
        assertTrue("Fake delegate queried", del.queried == 0);
262
    }
263
    
264
    public void testGetDisplayName() {
265
        ProxyDel del = createDelegate(ProxyLook.GET_DISPLAY_NAME);
266
        String n = look.getDisplayName(mySubst);
267
        int index = getIndex(ProxyLook.GET_DISPLAY_NAME);
268
        assertEquals(maskDelegates[index].getDisplayName(delegateSubsts[index]), n);
269
        assertTrue("Fake delegate queried", del.queried == 0);
270
    }
271
    
272
    public void testGetShortDescription() {
273
        ProxyDel del = createDelegate(ProxyLook.GET_SHORT_DESCRIPTION);
274
        String n = look.getShortDescription(mySubst);
275
        int index = getIndex(ProxyLook.GET_SHORT_DESCRIPTION);
276
        assertEquals(maskDelegates[index].getShortDescription(delegateSubsts[index]), n);
277
        assertTrue("Fake delegate queried", del.queried == 0);
278
    }
279
280
    public void testGetDropType() {
281
        ProxyDel del = createDelegate(ProxyLook.GET_DROP_TYPE);
282
        PasteType t = look.getDropType(mySubst, null, 0, 0);
283
        int index = getIndex(ProxyLook.GET_DROP_TYPE);
284
        assertSame(maskDelegates[index].getDropType(delegateSubsts[index], null, 0, 0), 
285
            t);
286
        assertTrue("Fake delegate queried", del.queried == 0);
287
    }
288
    
289
    public void testGetIcon() {
290
        ProxyDel del = createDelegate(ProxyLook.GET_ICON);
291
        int index = getIndex(ProxyLook.GET_ICON);
292
        assertSame(maskDelegates[index].getIcon(delegateSubsts[index], 0), look.getIcon(mySubst, 0));
293
        assertTrue("Fake delegate queried", del.queried == 0);
294
    }
295
    
296
    public void testGetOpenedIcon() {
297
        ProxyDel del = createDelegate(ProxyLook.GET_OPENED_ICON);
298
        int index = getIndex(ProxyLook.GET_OPENED_ICON);
299
        assertSame(maskDelegates[index].getOpenedIcon(delegateSubsts[index], 0), look.getOpenedIcon(mySubst, 0));
300
        assertTrue("Fake delegate queried", del.queried == 0);
301
    }
302
    
303
    public void testDestroy() {
304
        try {
305
            look.destroy(mySubst);
306
            for (int i = 0; i < delegateCount; i++) {
307
                assertTrue("Destroy not called on #" + i,
308
                (maskDelegates[i].queried & ProxyLook.DESTROY) > 0);
309
            }
310
        } catch (IOException ex) {
311
            fail(ex.getMessage());
312
        }
313
    }
314
    
315
    public void testGetActions() {
316
        int index = getIndex(ProxyLook.GET_ACTIONS);
317
        ProxyDel del;
318
        ProxyDel first = maskDelegates[index];
319
        Object[] result;
320
321
        maskDelegates[index] = null;
322
        result = look.getActions(mySubst);
323
        assertNull(result);
324
        maskDelegates[index] = first;
325
326
        del = createDelegate(ProxyLook.GET_ACTIONS);
327
        result = look.getActions(mySubst);
328
        Object[] expected = first.getActions(delegateSubsts[index]);
329
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
330
    }
331
    
332
    public void testGetAllActions() {
333
        int index = getIndex(ProxyLook.GET_ACTIONS);
334
        look.delAll = true;
335
        
336
        // check that no response will yield an empty array:
337
        ProxyDel del;
338
        Object[] result;
339
        
340
        del = maskDelegates[index];
341
        maskDelegates[index] = null;
342
        result = look.getActions(mySubst);
343
        assertNull(result);
344
        maskDelegates[index] = del;
345
        
346
        result = look.getActions(mySubst);
347
        Object[] expected1 = del.getActions(delegateSubsts[index]);
348
        // exactly one Look providing an action
349
        assertEquals(expected1.length, result.length);
350
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
351
        ensureQueried(ProxyLook.GET_ACTIONS, delegateCount);
352
        
353
        // test merge from two Looks
354
        del = createDelegate(ProxyLook.GET_ACTIONS);
355
        
356
        ProxyDel first = maskDelegates[index];
357
        result = look.getActions(mySubst);
358
        expected1 = first.getActions(delegateSubsts[index]);
359
        Object[] expected2 = del.getActions(delegateSubsts[delegateCount]);
360
        assertEquals(expected1.length
361
            + expected2.length, 
362
            result.length);
363
        Collection c = new ArrayList(Arrays.asList(expected1));
364
        c.addAll(Arrays.asList(expected2));
365
        assertEquals(c, Arrays.asList(result));
366
    }
367
    
368
    public void testGetChildObjects() {
369
        int index = getIndex(ProxyLook.GET_CHILD_OBJECTS);
370
        ProxyDel del;
371
        ProxyDel first = maskDelegates[index];
372
        Object[] result;
373
374
        maskDelegates[index] = null;
375
        result = look.getChildObjects(mySubst);
376
        assertNull(result);
377
        maskDelegates[index] = first;
378
379
        del = createDelegate(ProxyLook.GET_CHILD_OBJECTS);
380
        result = look.getChildObjects(mySubst);
381
        Object[] expected = first.getChildObjects(delegateSubsts[index]);
382
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
383
    }
384
    
385
    public void testGetAllChildObjects() {
386
        int index = getIndex(ProxyLook.GET_CHILD_OBJECTS);
387
        look.delAll = true;
388
        
389
        // check that no response will yield an empty array:
390
        ProxyDel del;
391
        Object[] result;
392
        
393
        del = maskDelegates[index];
394
        maskDelegates[index] = null;
395
        result = look.getChildObjects(mySubst);
396
        assertNull(result);
397
        maskDelegates[index] = del;
398
        
399
        result = look.getChildObjects(mySubst);
400
        Object[] expected1 = del.getChildObjects(delegateSubsts[index]);
401
        // exactly one Look providing an action
402
        assertEquals(expected1.length, result.length);
403
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
404
        ensureQueried(ProxyLook.GET_CHILD_OBJECTS, delegateCount);
405
        
406
        // test merge from two Looks
407
        del = createDelegate(ProxyLook.GET_CHILD_OBJECTS);
408
        
409
        ProxyDel first = maskDelegates[index];
410
        result = look.getChildObjects(mySubst);
411
        expected1 = first.getChildObjects(delegateSubsts[index]);
412
        Object[] expected2 = del.getChildObjects(delegateSubsts[delegateCount]);
413
        assertEquals(expected1.length
414
            + expected2.length, 
415
            result.length);
416
        Collection c = new ArrayList(Arrays.asList(expected1));
417
        c.addAll(Arrays.asList(expected2));
418
        assertEquals(c, Arrays.asList(result));
419
    }
420
    
421
    public void testGetContextActions() {
422
        int index = getIndex(ProxyLook.GET_CONTEXT_ACTIONS);
423
        ProxyDel del;
424
        ProxyDel first = maskDelegates[index];
425
        Object[] result;
426
427
        maskDelegates[index] = null;
428
        result = look.getContextActions(mySubst);
429
        assertNull(result);
430
        maskDelegates[index] = first;
431
432
        del = createDelegate(ProxyLook.GET_CONTEXT_ACTIONS);
433
        result = look.getContextActions(mySubst);
434
        Object[] expected = first.getContextActions(delegateSubsts[index]);
435
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
436
    }
437
    
438
    public void testGetAllContextActions() {
439
        int index = getIndex(ProxyLook.GET_CONTEXT_ACTIONS);
440
        look.delAll = true;
441
        
442
        // check that no response will yield an empty array:
443
        ProxyDel del;
444
        Object[] result;
445
        
446
        del = maskDelegates[index];
447
        maskDelegates[index] = null;
448
        result = look.getContextActions(mySubst);
449
        assertNull(result);
450
        maskDelegates[index] = del;
451
        
452
        result = look.getContextActions(mySubst);
453
        Object[] expected1 = del.getContextActions(delegateSubsts[index]);
454
        // exactly one Look providing an action
455
        assertEquals(expected1.length, result.length);
456
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
457
        ensureQueried(ProxyLook.GET_CONTEXT_ACTIONS, delegateCount);
458
        
459
        // test merge from two Looks
460
        del = createDelegate(ProxyLook.GET_CONTEXT_ACTIONS);
461
        
462
        ProxyDel first = maskDelegates[index];
463
        result = look.getContextActions(mySubst);
464
        expected1 = first.getContextActions(delegateSubsts[index]);
465
        Object[] expected2 = del.getContextActions(delegateSubsts[delegateCount]);
466
        assertEquals(expected1.length
467
            + expected2.length, 
468
            result.length);
469
        Collection c = new ArrayList(Arrays.asList(expected1));
470
        c.addAll(Arrays.asList(expected2));
471
        assertEquals(c, Arrays.asList(result));
472
    }
473
474
    public void testGetPasteTypes() {
475
        int index = getIndex(ProxyLook.GET_PASTE_TYPES);
476
        ProxyDel del;
477
        ProxyDel first = maskDelegates[index];
478
        Object[] result;
479
480
        maskDelegates[index] = null;
481
        result = look.getPasteTypes(mySubst, null);
482
        assertNull(result);
483
        maskDelegates[index] = first;
484
485
        del = createDelegate(ProxyLook.GET_PASTE_TYPES);
486
        result = look.getPasteTypes(mySubst, null);
487
        Object[] expected = first.getPasteTypes(delegateSubsts[index], null);
488
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
489
    }
490
    
491
    public void testGetAllPasteTypes() {
492
        int index = getIndex(ProxyLook.GET_PASTE_TYPES);
493
        look.delAll = true;
494
        
495
        // check that no response will yield an empty array:
496
        ProxyDel del;
497
        Object[] result;
498
        
499
        del = maskDelegates[index];
500
        maskDelegates[index] = null;
501
        result = look.getPasteTypes(mySubst, null);
502
        assertNull(result);
503
        maskDelegates[index] = del;
504
        
505
        result = look.getPasteTypes(mySubst, null);
506
        Object[] expected1 = del.getPasteTypes(delegateSubsts[index], null);
507
        // exactly one Look providing an action
508
        assertEquals(expected1.length, result.length);
509
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
510
        ensureQueried(ProxyLook.GET_PASTE_TYPES, delegateCount);
511
        
512
        // test merge from two Looks
513
        del = createDelegate(ProxyLook.GET_PASTE_TYPES);
514
        
515
        ProxyDel first = maskDelegates[index];
516
        result = look.getPasteTypes(mySubst, null);
517
        expected1 = first.getPasteTypes(delegateSubsts[index], null);
518
        Object[] expected2 = del.getPasteTypes(delegateSubsts[delegateCount], null);
519
        assertEquals(expected1.length
520
            + expected2.length, 
521
            result.length);
522
        Collection c = new ArrayList(Arrays.asList(expected1));
523
        c.addAll(Arrays.asList(expected2));
524
        assertEquals(c, Arrays.asList(result));
525
    }
526
    
527
    
528
    public void testGetNewTypes() {
529
        int index = getIndex(ProxyLook.GET_NEW_TYPES);
530
        ProxyDel del;
531
        ProxyDel first = maskDelegates[index];
532
        Object[] result;
533
534
        maskDelegates[index] = null;
535
        result = look.getNewTypes(mySubst);
536
        assertNull(result);
537
        maskDelegates[index] = first;
538
539
        del = createDelegate(ProxyLook.GET_NEW_TYPES);
540
        result = look.getNewTypes(mySubst);
541
        Object[] expected = first.getNewTypes(delegateSubsts[index]);
542
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
543
    }
544
    
545
    public void testGetAllNewTypes() {
546
        int index = getIndex(ProxyLook.GET_NEW_TYPES);
547
        look.delAll = true;
548
        
549
        // check that no response will yield an empty array:
550
        ProxyDel del;
551
        Object[] result;
552
        
553
        del = maskDelegates[index];
554
        maskDelegates[index] = null;
555
        result = look.getNewTypes(mySubst);
556
        assertNull(result);
557
        maskDelegates[index] = del;
558
        
559
        result = look.getNewTypes(mySubst);
560
        Object[] expected1 = del.getNewTypes(delegateSubsts[index]);
561
        // exactly one Look providing an action
562
        assertEquals(expected1.length, result.length);
563
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
564
        ensureQueried(ProxyLook.GET_NEW_TYPES, delegateCount);
565
        
566
        // test merge from two Looks
567
        del = createDelegate(ProxyLook.GET_NEW_TYPES);
568
        
569
        ProxyDel first = maskDelegates[index];
570
        result = look.getNewTypes(mySubst);
571
        expected1 = first.getNewTypes(delegateSubsts[index]);
572
        Object[] expected2 = del.getNewTypes(delegateSubsts[delegateCount]);
573
        assertEquals(expected1.length
574
            + expected2.length, 
575
            result.length);
576
        Collection c = new ArrayList(Arrays.asList(expected1));
577
        c.addAll(Arrays.asList(expected2));
578
        assertEquals(c, Arrays.asList(result));
579
    }
580
    
581
    public void testGetPropertySets() {
582
        int index = getIndex(ProxyLook.GET_PROPERTY_SETS);
583
        ProxyDel del;
584
        ProxyDel first = maskDelegates[index];
585
        Object[] result;
586
587
        maskDelegates[index] = null;
588
        result = look.getPropertySets(mySubst);
589
        assertNull(result);
590
        maskDelegates[index] = first;
591
592
        del = createDelegate(ProxyLook.GET_PROPERTY_SETS);
593
        result = look.getPropertySets(mySubst);
594
        Object[] expected = first.getPropertySets(delegateSubsts[index]);
595
        assertEquals(Arrays.asList(expected), Arrays.asList(result));
596
    }
597
    
598
    public void testGetAllPropertySets() {
599
        int index = getIndex(ProxyLook.GET_PROPERTY_SETS);
600
        look.delAll = true;
601
        
602
        // check that no response will yield an empty array:
603
        ProxyDel del;
604
        Object[] result;
605
        
606
        del = maskDelegates[index];
607
        maskDelegates[index] = null;
608
        result = look.getPropertySets(mySubst);
609
        assertNull(result);
610
        maskDelegates[index] = del;
611
        
612
        result = look.getPropertySets(mySubst);
613
        Object[] expected1 = del.getPropertySets(delegateSubsts[index]);
614
        // exactly one Look providing an action
615
        assertEquals(expected1.length, result.length);
616
        assertEquals(Arrays.asList(expected1), Arrays.asList(result));
617
        ensureQueried(ProxyLook.GET_PROPERTY_SETS, delegateCount);
618
        
619
        // test merge from two Looks
620
        del = createDelegate(ProxyLook.GET_PROPERTY_SETS);
621
        
622
        ProxyDel first = maskDelegates[index];
623
        result = look.getPropertySets(mySubst);
624
        expected1 = first.getPropertySets(delegateSubsts[index]);
625
        Object[] expected2 = del.getPropertySets(delegateSubsts[delegateCount]);
626
        assertEquals(expected1.length
627
            + expected2.length, 
628
            result.length);
629
        Collection c = new ArrayList(Arrays.asList(expected1));
630
        c.addAll(Arrays.asList(expected2));
631
        assertEquals(c, Arrays.asList(result));
632
    }
633
    
634
    public void testGetDuplicatePropertySets() {
635
        int index = getIndex(ProxyLook.GET_PROPERTY_SETS);
636
        look.delAll = true;
637
        
638
        // check that no response will yield an empty array:
639
        ProxyDel del;
640
        Object[] result;
641
        Object[] expected1;
642
        
643
        maskDelegates[0] = maskDelegates[index];
644
        
645
        // test merge from two Looks
646
        del = createDelegate(ProxyLook.GET_PROPERTY_SETS);
647
648
        ProxyDel first = maskDelegates[index];
649
        result = look.getPropertySets(mySubst);
650
        expected1 = first.getPropertySets(delegateSubsts[index]);
651
        Object[] expected2 = del.getPropertySets(delegateSubsts[delegateCount]);
652
        assertEquals(expected1.length
653
            + expected2.length, 
654
            result.length);
655
        Collection c = new ArrayList(Arrays.asList(expected1));
656
        c.addAll(Arrays.asList(expected2));
657
        assertEquals(c, Arrays.asList(result));
658
}
659
660
    private void ensureQueried(long mask, int lastIndex) {
661
        int end = lastIndex == -1 ? maskDelegates.length : lastIndex;
662
        for (int index = 0; index <= end; index++) {
663
            if (maskDelegates[index] == null)
664
                continue;
665
            assertTrue("Delegate #" + index + " not queried",
666
            (maskDelegates[index].queried & mask) > 0);
667
        }
668
    }
669
    
670
    private int getIndex(long mask) {
671
        int i = 0;
672
        while (mask > 1) {
673
            mask >>= 1;
674
            i++;
675
        }
676
        return i;
677
    }
678
    
679
    private ProxyDel createDelegate(long mask) {
680
        Look del = new SampleLook2Hid();
681
        ProxyDel p = new ProxyDel(del, delegateCount, mask, null);
682
        maskDelegates[delegateCount] = p;
683
        return p;
684
    }
685
    
686
    Look.NodeSubstitute getSubstitute(Look.NodeSubstitute s, Look l, int index) {
687
        try {
688
            if (substAccessor == null) {
689
                substAccessor = ProxyLook.class.getDeclaredMethod(
690
                "s", new Class[] {
691
                    Look.NodeSubstitute.class, Look.class, Integer.TYPE
692
                });
693
                substAccessor.setAccessible(true);
694
            }
695
            return (Look.NodeSubstitute)substAccessor.invoke(look, new Object[] {
696
                s, l, new Integer(index)
697
            });
698
        } catch (Exception ex) {
699
            fail("Unexpected exception: " + ex.getMessage());
700
            return null;
701
        }
702
    }
703
704
    class ProxyDel extends Look {
705
        long mask;
706
        Look del;
707
        int index;
708
        NodeSubstitute substitute;
709
        Object data;
710
        long queried;
711
        
712
        ProxyDel(Look delegate, int index, long mask, Object data) {
713
            this.index = index;
714
            this.mask = mask;
715
            this.del = delegate;
716
            this.data = data;
717
        }
718
        
719
        protected Object createAttachedData(NodeSubstitute s) {
720
            if (s == null) {
721
                assertNotNull(s);
722
            }
723
            delegateSubsts[index] = s;
724
            return data;
725
        }
726
        
727
        boolean isEnabled(long action) {
728
            return (mask & action) > 0;
729
        }
730
        
731
        public boolean canCopy(Look.NodeSubstitute substitute) {
732
            queried |= ProxyLook.CAN_COPY;
733
            return isEnabled(ProxyLook.CAN_COPY) ?
734
            del.canCopy(substitute) : false;
735
        }
736
        
737
        public boolean canCut(Look.NodeSubstitute substitute) {
738
            queried |= ProxyLook.CAN_CUT;
739
            return isEnabled(ProxyLook.CAN_CUT) ?
740
            del.canCut(substitute) : false;
741
        }
742
        
743
        public boolean canDestroy(Look.NodeSubstitute substitute) {
744
            queried |= ProxyLook.CAN_DESTROY;
745
            return isEnabled(ProxyLook.CAN_DESTROY) ?
746
            del.canDestroy(substitute) : false;
747
        }
748
        
749
        public boolean canRename(Look.NodeSubstitute substitute) {
750
            queried |= ProxyLook.CAN_RENAME;
751
            return isEnabled(ProxyLook.CAN_RENAME) ?
752
            del.canRename(substitute) : false;
753
        }
754
        
755
        public Transferable clipboardCopy(Look.NodeSubstitute substitute) throws IOException {
756
            queried |= ProxyLook.CLIPBOARD_COPY;
757
            return isEnabled(ProxyLook.CLIPBOARD_COPY) ?
758
            del.clipboardCopy(substitute) : null;
759
        }
760
        
761
        public Transferable clipboardCut(Look.NodeSubstitute substitute) throws IOException {
762
            queried |= ProxyLook.CLIPBOARD_CUT;
763
            return isEnabled(ProxyLook.CLIPBOARD_CUT) ?
764
            del.clipboardCut(substitute) : null;
765
        }
766
        
767
        public Lookup createLookup(Look.NodeSubstitute substitute) {
768
            queried |= ProxyLook.CREATE_LOOKUP;
769
            return isEnabled(ProxyLook.CREATE_LOOKUP) ?
770
            del.createLookup(substitute) : null;
771
        }
772
        
773
        public void destroy(Look.NodeSubstitute substitute) throws IOException {
774
            queried |= ProxyLook.DESTROY;
775
            if (isEnabled(ProxyLook.DESTROY))
776
                del.destroy(substitute);
777
        }
778
        
779
        public Transferable drag(Look.NodeSubstitute substitute) throws IOException {
780
            queried |= ProxyLook.DRAG;
781
            return isEnabled(ProxyLook.DRAG) ?
782
            del.drag(substitute) : null;
783
        }
784
        
785
        public Action[] getActions(Look.NodeSubstitute substitute) {
786
            queried |= ProxyLook.GET_ACTIONS;
787
            return isEnabled(ProxyLook.GET_ACTIONS) ?
788
            del.getActions(substitute) : null;
789
        }
790
        
791
        public Object[] getChildObjects(Look.NodeSubstitute substitute) {
792
            queried |= ProxyLook.GET_CHILD_OBJECTS;
793
            // for testing purposes --
794
            if (actualDelegateData != null) {
795
                actualDelegateData[index] = getAttachedData(substitute);
796
            }
797
            return isEnabled(ProxyLook.GET_CHILD_OBJECTS) ?
798
            del.getChildObjects(substitute) : null;
799
        }
800
        
801
        public Action[] getContextActions(Look.NodeSubstitute substitute) {
802
            queried |= ProxyLook.GET_CONTEXT_ACTIONS;
803
            return isEnabled(ProxyLook.GET_CONTEXT_ACTIONS) ?
804
            del.getContextActions(substitute) : null;
805
        }
806
        
807
        public java.awt.Component getCustomizer(Look.NodeSubstitute substitute) {
808
            queried |= ProxyLook.GET_CUSTOMIZER;
809
            return isEnabled(ProxyLook.GET_CUSTOMIZER) ?
810
            del.getCustomizer(substitute) : null;
811
        }
812
        
813
        public Action getDefaultAction(Look.NodeSubstitute substitute) {
814
            queried |= ProxyLook.GET_DEFAULT_ACTION;
815
            return isEnabled(ProxyLook.GET_DEFAULT_ACTION) ?
816
            del.getDefaultAction(substitute) : null;
817
        }
818
        
819
        public String getDisplayName() {
820
            return "Proxy Delegate (" + mask + ")";
821
        }
822
        
823
        public String getDisplayName(Look.NodeSubstitute substitute) {
824
            queried |= ProxyLook.GET_DISPLAY_NAME;
825
            return isEnabled(ProxyLook.GET_DISPLAY_NAME) ?
826
            del.getDisplayName(substitute) : null;
827
        }
828
        
829
        public PasteType getDropType(Look.NodeSubstitute substitute, Transferable t, int action, int index) {
830
            queried |= ProxyLook.GET_DROP_TYPE;
831
            return isEnabled(ProxyLook.GET_DROP_TYPE) ?
832
            del.getDropType(substitute, t, action, index) : null;
833
        }
834
        
835
        public HelpCtx getHelpCtx(Look.NodeSubstitute substitute) {
836
            queried |= ProxyLook.GET_HELP_CTX;
837
            return isEnabled(ProxyLook.GET_HELP_CTX) ?
838
            del.getHelpCtx(substitute) : null;
839
        }
840
        
841
        public Image getIcon(Look.NodeSubstitute substitute, int type) {
842
            queried |= ProxyLook.GET_ICON;
843
            return isEnabled(ProxyLook.GET_ICON) ?
844
            del.getIcon(substitute, type) : null;
845
        }
846
        
847
        public String getName() {
848
            return "ProxyDelegate(" + mask + ")";
849
        }
850
        
851
        public String getName(Look.NodeSubstitute substitute) {
852
            queried |= ProxyLook.GET_NAME;
853
            return isEnabled(ProxyLook.GET_NAME) ?
854
            del.getName(substitute) : null;
855
        }
856
        
857
        public NewType[] getNewTypes(Look.NodeSubstitute substitute) {
858
            queried |= ProxyLook.GET_NEW_TYPES;
859
            return isEnabled(ProxyLook.GET_NEW_TYPES) ?
860
            del.getNewTypes(substitute) : null;
861
        }
862
        
863
        public Image getOpenedIcon(Look.NodeSubstitute substitute, int type) {
864
            queried |= ProxyLook.GET_OPENED_ICON;
865
            return isEnabled(ProxyLook.GET_OPENED_ICON) ?
866
            del.getOpenedIcon(substitute, type) : null;
867
        }
868
        
869
        public PasteType[] getPasteTypes(Look.NodeSubstitute substitute, Transferable t) {
870
            queried |= ProxyLook.GET_PASTE_TYPES;
871
            return isEnabled(ProxyLook.GET_PASTE_TYPES) ?
872
            del.getPasteTypes(substitute, t) : null;
873
        }
874
        
875
        public Node.PropertySet[] getPropertySets(Look.NodeSubstitute substitute) {
876
            queried |= ProxyLook.GET_PROPERTY_SETS;
877
            return isEnabled(ProxyLook.GET_PROPERTY_SETS) ?
878
            del.getPropertySets(substitute) : null;
879
        }
880
        
881
        public String getShortDescription(Look.NodeSubstitute substitute) {
882
            queried |= ProxyLook.GET_SHORT_DESCRIPTION;
883
            return isEnabled(ProxyLook.GET_SHORT_DESCRIPTION) ?
884
            del.getShortDescription(substitute) : null;
885
        }
886
        
887
        public boolean hasCustomizer(Look.NodeSubstitute substitute) {
888
            queried |= ProxyLook.HAS_CUSTOMIZER;
889
            return isEnabled(ProxyLook.HAS_CUSTOMIZER) ?
890
            del.hasCustomizer(substitute) : false;
891
        }
892
        
893
        public void setName(Look.NodeSubstitute substitute, String newName) {
894
            queried |= ProxyLook.SET_NAME;
895
            if (isEnabled(ProxyLook.SET_NAME))
896
                del.setName(substitute, newName);
897
        }
898
        
899
        public Look[] availableLooks(Look.NodeSubstitute substitute) {
900
            return null;
901
        }
902
        
903
        public String toString() {
904
            return Integer.toString(index);
905
        }
906
    }
907
    
908
    class Prx extends ProxyLook {
909
        boolean createCalled = false;
910
        long    delegateMask;
911
        boolean delAll;
912
        
913
        protected Object createAttachedData(NodeSubstitute s) {
914
            proxySubst = s;
915
            createCalled = true;
916
            return DATA;
917
        }
918
        
919
        protected boolean delegateAll(long mask, NodeSubstitute s) {
920
            return delAll;
921
        }
922
        
923
        public String getDisplayName() {
924
            return "Test look";
925
        }
926
        
927
        public String getName() {
928
            return "TestName";
929
        }
930
        
931
        public Look[] delegateTo(long method, NodeSubstitute s) {
932
            delegateMask |= method;
933
            if (forceDelegates != null)
934
                return forceDelegates;
935
            return maskDelegates;
936
        }
937
    }
938
    
939
    private static final class MySubst extends Look.NodeSubstitute {
940
        public MySubst(Look look) {
941
            super.attachTo(look);
942
        }
943
        
944
        public void setLook(Look look) {
945
            super.attachTo(look);
946
        }
947
        
948
        
949
        public void fireDisplayNameChange(String o, String n) {
950
        }
951
        
952
        public void fireIconChange() {
953
        }
954
        
955
        public void fireNameChange(String o, String n) {
956
        }
957
        
958
        public void fireNodeDestroyed() {
959
        }
960
        
961
        public void fireOpenedIconChange() {
962
        }
963
        
964
        public void firePropertyChange(String name, Object o, Object n) {
965
        }
966
        
967
        public void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n) {
968
        }
969
        
970
        public void fireShortDescriptionChange(String o, String n) {
971
        }
972
        
973
        public Object getRepresentedObject() {
974
            return null;
975
        }
976
        
977
        public void refreshChildren() {
978
        }
979
    }
980
}
(-)openidex/src/org/openidex/nodes/looks/AcceptorLook.java (-360 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
20
import org.openide.nodes.*;
21
import org.openide.util.actions.SystemAction;
22
import org.openide.util.HelpCtx;
23
import org.openide.util.datatransfer.NewType;
24
import org.openide.util.datatransfer.PasteType;
25
26
/** Helper class to provide values only for some type of nodes.
27
 * If the method boolean accept( Node node ) returns true the call
28
 * is delegated to the delegate Look. If not the call is delegated to
29
 * {@link DefaultLook#ISTANCE} interface returns a netutral value.<BR>
30
 *
31
 * <P>
32
 * <I>Notice: There is no extra Javadoc for the methods now. All behave as 
33
 * described</I>
34
 *
35
 * @author Petr Hrebejk
36
 */
37
public abstract class AcceptorLook extends FilterLook {
38
    
39
    
40
    /** Creates new Acceptor 
41
     * @param delegate The Look to delegate to when the node was accepted.
42
     */
43
    public AcceptorLook(Look delegate) {
44
        super( delegate );
45
    }
46
47
    /** Override this method for enabling the Look for some 
48
     * type of nodes.
49
     *
50
     * @node Node which is asking
51
     * @return True if Node should be accepted false otherwise.
52
     */
53
    protected abstract boolean accept( Look.NodeSubstitute substitute );
54
    
55
    // Methods of look itself --------------------------------------------------
56
    
57
    public boolean isLookStandalone( Object representedObject ) {
58
        return delegate.isLookStandalone( representedObject );
59
    }
60
            
61
    // General methods ---------------------------------------------------------
62
63
    public void attachTo( Look.NodeSubstitute substitute ) {
64
        if ( accept( substitute ) ) {
65
            super.attachTo( substitute );
66
        }
67
    }
68
    
69
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
70
        if ( accept( substitute ) ) {
71
            return super.getCookie( substitute, type );
72
        }
73
        else {
74
            return DefaultLook.INSTANCE.getCookie( substitute, type );
75
        }
76
    }
77
78
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
79
        if ( accept( substitute ) ) {
80
            return super.getHandle( substitute );
81
        }
82
        else {
83
            return DefaultLook.INSTANCE.getHandle( substitute );
84
        }
85
    }
86
    
87
    // Methods for STYLE -------------------------------------------------------
88
    
89
    public String getDisplayName( Look.NodeSubstitute substitute ) {
90
        if ( accept( substitute ) ) {
91
            return super.getDisplayName( substitute );
92
        }
93
        else {
94
            return DefaultLook.INSTANCE.getDisplayName( substitute );
95
        }
96
    }
97
    
98
    public String getName( Look.NodeSubstitute substitute ) {
99
        if ( accept( substitute ) ) {
100
            return super.getName( substitute );
101
        }
102
        else {
103
            return DefaultLook.INSTANCE.getName( substitute );
104
        }
105
    }
106
    
107
    public void setName( Look.NodeSubstitute substitute, String newName ) {
108
        if ( accept( substitute ) ) {
109
            super.setName( substitute, newName );
110
        }
111
        else {
112
            DefaultLook.INSTANCE.setName( substitute, newName );
113
        }
114
    }
115
    
116
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
117
        if ( accept( substitute ) ) {
118
            return super.getShortDescription( substitute );
119
        }
120
        else {
121
            return DefaultLook.INSTANCE.getShortDescription( substitute );
122
        }
123
    }
124
    
125
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
126
        if ( accept( substitute ) ) {
127
            return super.getIcon( substitute, type );
128
        }
129
        else {
130
            return DefaultLook.INSTANCE.getIcon( substitute, type );
131
        }
132
    }
133
    
134
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
135
        if ( accept( substitute ) ) {
136
            return super.getOpenedIcon( substitute, type );
137
        }
138
        else {
139
            return DefaultLook.INSTANCE.getOpenedIcon( substitute, type );
140
        }
141
    }
142
    
143
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
144
        if ( accept( substitute ) ) {
145
            return super.getHelpCtx( substitute );
146
        }
147
        else {
148
            return DefaultLook.INSTANCE.getHelpCtx( substitute );
149
        }
150
    }
151
    
152
    // Methods for CHILDREN ----------------------------------------------------
153
    
154
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
155
        if ( accept( substitute ) ) {
156
            return super.getChildObjects( substitute );
157
        }
158
        else {
159
            return DefaultLook.INSTANCE.getChildObjects( substitute );
160
        }
161
    }
162
         
163
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
164
    
165
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
166
        if ( accept( substitute ) ) {
167
            return super.getNewTypes( substitute );
168
        }
169
        else {
170
            return DefaultLook.INSTANCE.getNewTypes( substitute );
171
        }
172
    }
173
    
174
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
175
        if ( accept( substitute ) ) {
176
            return super.getActions( substitute );
177
        }
178
        else {
179
            return DefaultLook.INSTANCE.getActions( substitute );
180
        }
181
    }
182
    
183
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
184
        if ( accept( substitute ) ) {
185
            return super.getContextActions( substitute );
186
        }
187
        else {
188
            return DefaultLook.INSTANCE.getContextActions( substitute );
189
        }
190
    }
191
    
192
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
193
        if ( accept( substitute ) ) {
194
            return super.getDefaultAction( substitute );
195
        }
196
        else {
197
            return DefaultLook.INSTANCE.getDefaultAction( substitute );
198
        }
199
    }
200
    
201
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
202
    
203
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
204
        if ( accept( substitute ) ) {
205
            return super.getPropertySets( substitute );
206
        }
207
        else {
208
            return DefaultLook.INSTANCE.getPropertySets( substitute );
209
        }
210
    }
211
    
212
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
213
        if ( accept( substitute ) ) {
214
            return super.getCustomizer( substitute );
215
        }
216
        else {
217
            return DefaultLook.INSTANCE.getCustomizer( substitute );
218
        }
219
    }
220
    
221
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
222
     
223
    public boolean canRename( Look.NodeSubstitute substitute ) {
224
        if ( accept( substitute ) ) {
225
            return super.canRename( substitute );
226
        }
227
        else {
228
            return DefaultLook.INSTANCE.canRename( substitute );
229
        }
230
    }
231
    
232
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
233
        if ( accept( substitute ) ) {
234
            return super.canDestroy( substitute );
235
        }
236
        else {
237
            return DefaultLook.INSTANCE.canDestroy( substitute );
238
        }
239
    }
240
    
241
    public boolean canCopy( Look.NodeSubstitute substitute ) {
242
        if ( accept( substitute ) ) {
243
            return super.canCopy( substitute );
244
        }
245
        else {
246
            return DefaultLook.INSTANCE.canCopy( substitute );
247
        }
248
    }
249
    
250
    public boolean canCut( Look.NodeSubstitute substitute ) {
251
        if ( accept( substitute ) ) {
252
            return super.canCut( substitute );
253
        }
254
        else {
255
            return DefaultLook.INSTANCE.canCut( substitute );
256
        }
257
    }
258
    
259
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
260
        if ( accept( substitute ) ) {
261
            return super.getPasteTypes( substitute, t );
262
        }
263
        else {
264
            return DefaultLook.INSTANCE.getPasteTypes( substitute, t );
265
        }
266
    }
267
    
268
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
269
        if ( accept( substitute ) ) {
270
            return super.getDropType( substitute, t, action, index );
271
        }
272
        else {
273
            return DefaultLook.INSTANCE.getDropType( substitute, t, action, index );
274
        }
275
    }
276
    
277
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
278
        if ( accept( substitute ) ) {
279
            return super.clipboardCopy( substitute );
280
        }
281
        else {
282
            return DefaultLook.INSTANCE.clipboardCopy( substitute );
283
        }
284
    }
285
    
286
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
287
        if ( accept( substitute ) ) {
288
            return super.clipboardCut( substitute );
289
        }
290
        else {
291
            return DefaultLook.INSTANCE.clipboardCut( substitute );
292
        }
293
    }
294
    
295
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
296
        if ( accept( substitute ) ) {
297
            return super.drag( substitute );
298
        }
299
        else {
300
            return DefaultLook.INSTANCE.drag( substitute );
301
        }
302
    }
303
    
304
    public void destroy( Look.NodeSubstitute substitute ) throws IOException {
305
        if ( accept( substitute ) ) {
306
            super.destroy( substitute );
307
        }
308
        else {
309
            DefaultLook.INSTANCE.destroy( substitute );
310
        }
311
    }
312
       
313
    public static abstract class Type extends AcceptorLook {
314
        /** Class which has to be accepted */
315
        private Class type;
316
317
        /** Should also superclasses be accepted? Default is false */
318
        private boolean subclasses;
319
320
321
        /** Creates new TypeAcceptor where subclasses are accepted.
322
         * @param delegate The look to delegate to.
323
         * @param type Class of represented object which has to be accepted.
324
         */
325
        public Type( Look delegate, Class type ) {
326
            this( delegate, type, true);
327
        }
328
329
        /** Creates new TypeAcceptor where user can specify whether subclasses 
330
         * should be accepted or not.
331
         * @param delegate The look to delegate to.
332
         * @param type Class of represented object which has to be accepted.
333
         * @param superclasses True if also subclasses should be accepted.
334
         */
335
        public Type( Look delegate, Class type, boolean subclasses ) {
336
            super( delegate );
337
            this.type = type;
338
            this.subclasses = subclasses;
339
        }
340
341
        /** Accepts only if represented object is of given type.
342
         * @node Node about which should be decided.
343
         * @return True if the node represents object of given type false otherwise.
344
         */
345
        protected boolean accept( Look.NodeSubstitute substitute ) {
346
347
            if ( type == null ) {
348
                return false;
349
            }
350
351
            if ( subclasses ) {
352
                return type.isInstance( substitute.getRepresentedObject() );
353
            }
354
            else {
355
                return type == substitute.getRepresentedObject().getClass();
356
            }
357
        }        
358
    }
359
    
360
}
(-)openidex/src/org/openidex/nodes/looks/Bundle.properties (-29 lines)
Removed Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
### Resource bundle for package org.openide.nodes.looks
13
14
#Name of the Look property sheet.
15
CTL_LookSheetSetName=Look
16
17
#Name of the Look property.
18
CTL_LookProperty=Look
19
20
#Short description of the look property
21
CTL_LookPropertyShortDescription=Sets the look on the node.
22
23
#Name of the Default look.
24
CTL_Default=Default
25
26
27
28
#Name of the SetLook Action
29
ACT_SetLook=Set Look
(-)openidex/src/org/openidex/nodes/looks/CompositeLook.java (-871 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.io.IOException;
20
21
import org.w3c.dom.NodeList;
22
import org.w3c.dom.Element;
23
24
import org.openide.nodes.*;
25
import org.openide.loaders.XMLDataObject;
26
import org.openide.util.actions.SystemAction;
27
import org.openide.util.HelpCtx;
28
import org.openide.util.Lookup;
29
import org.openide.util.datatransfer.NewType;
30
import org.openide.util.datatransfer.PasteType;
31
32
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
33
 * Please don't use this API for other purposes than testing.
34
 * <P>
35
 * Look which combines more looks together. The attributes of Node are divided
36
 * into two groups for purposes of the CompositeLook: singlevalued
37
 * and multivalued. If value for a singlevalued attribute is determined the 
38
 * first look which returns a non-neutral value from the method wins and the 
39
 * value is used on the node. For multivalued attributes the values are merged
40
 * the merging strategy may vary for different attributes.
41
 *
42
 * @author Petr Hrebejk
43
 */
44
public class CompositeLook extends Look {
45
    
46
    /** Sublook element used in the XML descrition */
47
    public static final String TAG_SUBLOOK = "Sublook"; // NOI18N
48
49
	/** Attribute name for the defined sublook */
50
    public static final String ATTR_LOOKID = "lookid"; //NOI18N
51
    
52
    /** MergeLast element used in the XML descrition */
53
    public static final String TAG_MERGE_LAST = "MergeLast"; //NOI18N
54
55
	
56
57
    
58
    /** ArrayList of looks */
59
    private ArrayList looks;
60
    
61
    /** The mergeLast flag for the multivalued attributes */
62
    private boolean mergeLast = true;
63
    
64
    /** This array is filled on the readPropertiesFromXML call. 
65
     * It is later transoformed into sublloks when needed
66
     */
67
    private NodeList sublooksTags; 
68
     
69
    /** Creates new Composite Look.
70
     */
71
    public CompositeLook() {
72
    }
73
  
74
    /** Adds a sublook at given index
75
     * @param index The index to add the Look at.
76
     * @param look The look which has to be added.
77
     */
78
    public void setLook( Look[] looksArray ) {
79
        
80
        looks = new ArrayList( looksArray.length );
81
        
82
        if( looksArray != null ){
83
            for( int i = 0; i < looksArray.length; i++){
84
                looks.add( looksArray[i] );
85
            }
86
        }
87
    }
88
    
89
    /** Adds a sublook at the end of the list of sublooks.
90
     * @param look The shublook which has to be added.
91
     */
92
    public void setLook( Collection look ) {
93
        if( look != null )
94
            looks.add( look );
95
    }
96
    
97
    /** Removes the given sublook.
98
     * @param look The sublook to remove.
99
     */
100
    public void removeLook( Look[] look ) {
101
        looks.remove( Arrays.asList(look) );
102
    }
103
104
    /** Removes the sublook 
105
     * @param index The index of sublook which has to be removed.
106
     */
107
    public void removeLook( Collection look ) {
108
        looks.remove( look );
109
    }
110
    
111
    /** Gets iterator of all contained sublooks.
112
     * @return Iterator containing all sublooks.
113
     */
114
    public Iterator iterator() {
115
116
        if ( looks == null ) {
117
            
118
            if ( sublooksTags != null && sublooksTags.getLength() > 0 ) {
119
                // Transform tags to looks
120
                Lookup.Template t = new Lookup.Template( Look.class );
121
                Lookup.Result r = Lookup.getDefault().lookup( t );
122
                Collection lc = r.allInstances();
123
                
124
                looks = new ArrayList( sublooksTags.getLength() );
125
                                
126
                for( int i = 0; i < sublooksTags.getLength(); i++ ) {
127
                    if ( sublooksTags.item( i ).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE ) {
128
                        continue;
129
                    }
130
                    Element e = (Element)sublooksTags.item( i );
131
                    String lookName = e.getAttribute( ATTR_LOOKID );
132
                    int nameIndex = lookName.indexOf('$');
133
                    lookName = lookName.substring( nameIndex + 1 );
134
                    
135
                    
136
                    for ( Iterator it = lc.iterator(); it.hasNext(); ) {
137
                        Look look = (Look)it.next();
138
                        if ( look.getName().equals( lookName ) ) {
139
                            looks.add( look );
140
                            break;
141
                        }
142
                    }
143
                }
144
            }
145
            else { 
146
                return java.util.Collections.EMPTY_LIST.iterator();
147
            }
148
        }
149
        
150
        return looks.iterator();
151
        
152
    }
153
    
154
    /** Tells the look whether the multivalued properties from last sublook
155
     * should be merged or not. Default value is true.
156
     * @param merge Value for the merge to be set.
157
     */
158
    public void setMergeLast( boolean mergeLast ) {
159
        this.mergeLast = mergeLast;
160
    }
161
    
162
    /** Does the look merge the multivalued attributes from the last?
163
     * sublook? Default value is true.
164
     * @return Current value of the merge flag.
165
     */
166
    public boolean getMergeLast() {
167
        return mergeLast;
168
    }
169
    
170
    /** Reads the Look options from the XMLDataObject. If you override this
171
     * method you'll
172
     * probably want to call super.readPropertiesFromXML( xdo );
173
     */
174
    public void readPropertiesFromXML(XMLDataObject xdo) {
175
        
176
        // Read the name
177
        super.readPropertiesFromXML( xdo );
178
        
179
        try {
180
            Element de = xdo.getDocument().getDocumentElement();
181
            
182
            // Read the sublooks
183
            sublooksTags = de.getElementsByTagName( TAG_SUBLOOK );
184
            
185
            // Set the looks to null;
186
            looks = null;
187
            
188
            // Read the MergeLast tag 
189
            NodeList ml = de.getElementsByTagName( TAG_MERGE_LAST );
190
            
191
            if ( ml.getLength() > 0 ) {
192
                org.w3c.dom.Node n = ml.item( ml.getLength() - 1 );
193
                org.w3c.dom.Node nc = n.getFirstChild();
194
                String value = nc.getNodeValue();
195
                if ( value != null && value.toLowerCase().equals( "false" ) ) { // NOI18N
196
                    mergeLast = false;
197
                }
198
            }
199
            
200
        }        
201
        catch ( java.io.IOException e ) {
202
            e.printStackTrace();
203
            System.out.println( e );
204
            // Do nothing
205
        }
206
        catch ( org.xml.sax.SAXException e ) {
207
            e.printStackTrace();
208
            System.out.println( e );
209
            // Do nothing
210
        }
211
    }
212
    
213
    // Methods of look itself --------------------------------------------------
214
    
215
        
216
    // General methods ---------------------------------------------------------
217
    
218
    /** Notifyies all sublooks about node creation.
219
     * @param node The node to operate on.  
220
     */    
221
    public void attachTo(Look.NodeSubstitute substitute) {
222
        for ( Iterator it = iterator(); it.hasNext(); ) { 
223
            Look look = (Look)it.next();            
224
            look.attachTo( substitute );
225
        }
226
    }
227
    
228
    /** Finds cookie for the node betwen the sblooks.
229
     * @param node The node to operate on.
230
     * @param type Type of the desired cookie.
231
     * @return First cookie returned from the sublooks. 
232
     */    
233
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
234
        for ( Iterator it = iterator(); it.hasNext(); ) { 
235
            Look look = (Look)it.next();
236
            
237
            Node.Cookie cookie = look.getCookie( substitute, type );
238
            if ( cookie != null ) {
239
                return cookie;
240
            }
241
        }
242
        return null;
243
    }
244
245
    /** Finds a handle for given node among sublooks.
246
     * @param node The node to operate on.
247
     * @return First handle found among the sublooks. 
248
     */    
249
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
250
        for ( Iterator it = iterator(); it.hasNext(); ) { 
251
            Look look = (Look)it.next();
252
            
253
            Node.Handle handle = look.getHandle( substitute );
254
            if ( handle != null ) {
255
                return handle;
256
            }
257
        }
258
        return null;
259
    }
260
    
261
    public String toString() {
262
        String result = getName() + " [ \n"; //NOI18N
263
        
264
        for ( Iterator it = iterator(); it.hasNext(); ) {
265
            result = result + "  " + ((Look)it.next()).getName() + "\n"; //NOI18N
266
        }
267
        
268
        return result + "]\nMergeLast = " + mergeLast + "\n"; // NOI18N
269
    }
270
    
271
    // Methods for STYLE -------------------------------------------------------
272
    
273
    /** Finds the display name for given node among the sublooks.
274
     * @param node The node to operate on.
275
     * @return The first displayname found.
276
     */    
277
    public String getDisplayName( Look.NodeSubstitute substitute ) {
278
        for ( Iterator it = iterator(); it.hasNext(); ) { 
279
            Look look = (Look)it.next();
280
            
281
            String displayName = look.getDisplayName( substitute );
282
            if ( displayName != null ) {
283
                return displayName;
284
            }
285
        }
286
        return null;
287
    }
288
    
289
    /** Finds the programmatic name for the node among the sblooks.
290
     * @param node The node to operate on.
291
     * @return The first name found.
292
     */    
293
    public String getName( Look.NodeSubstitute substitute ) {
294
        for ( Iterator it = iterator(); it.hasNext(); ) { 
295
            Object o = it.next();
296
            Look look = (Look)o;
297
            
298
            String name = look.getName( substitute );
299
            if ( name != null ) {
300
                return name;
301
            }
302
        }
303
        return null;
304
    }
305
    
306
    /** Calls <CODE>setName()</CODE> on all sblooks.
307
     * @param node The node to operate on.
308
     */    
309
    public void setName(Look.NodeSubstitute substitute, String newName) {
310
        for ( Iterator it = iterator(); it.hasNext(); ) { 
311
            Look look = (Look)it.next();
312
            look.setName( substitute, newName );
313
        }
314
    }
315
    
316
    
317
    /** Finds the short description for given node among the sublooks.
318
     * @param node The node to operate on.
319
     * @return Fisrt shortdescriprion found.
320
     */    
321
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
322
        for ( Iterator it = iterator(); it.hasNext(); ) { 
323
            Look look = (Look)it.next();
324
            
325
            String shortDescription = look.getShortDescription( substitute );
326
            if ( shortDescription != null ) {
327
                return shortDescription;
328
            }
329
        }
330
        return null;
331
    }
332
    
333
    /** Finds closed state icon among the sublooks.
334
     * @param node The node to operate on.
335
     * @param type Type of the icon as specified in BeanInfo
336
     * @return The first closed state icon found.
337
     */    
338
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
339
        for ( Iterator it = iterator(); it.hasNext(); ) { 
340
            Look look = (Look)it.next();
341
            
342
            Image icon = look.getIcon( substitute, type );
343
            if ( icon != null ) {
344
                return icon;
345
            }
346
        }
347
        return null;
348
    }
349
    
350
    /** Finds opened state icon among the sublooks.
351
     * @param node The node to operate on.
352
     * @param type Type of the icon as specified in BeanInfo
353
     * @return The first closed state icon found.
354
     */    
355
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
356
        for ( Iterator it = iterator(); it.hasNext(); ) { 
357
            Look look = (Look)it.next();
358
            
359
            Image openedIcon = look.getOpenedIcon( substitute, type );
360
            if ( openedIcon != null ) {
361
                return openedIcon;
362
            }
363
        }
364
        return null;
365
    }
366
    
367
    /** Finds the HelpCtx for given node among the sublooks.
368
     * @param node The node to operate on.
369
     * @return The first HelpCtx found.
370
     */    
371
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
372
        for ( Iterator it = iterator(); it.hasNext(); ) { 
373
            Look look = (Look)it.next();
374
            
375
            HelpCtx helpCtx = look.getHelpCtx( substitute );
376
            if ( helpCtx != null ) {
377
                return helpCtx;
378
            }
379
        }
380
        return null;
381
    }
382
    
383
    // Methods for CHILDREN ----------------------------------------------------
384
    
385
    /** Acxcumulated child objects for given node. The objects are merged from 
386
     * all the sublooks. The ordering is the same as ordering of the sublooks.
387
     * @param node The node to operate on. 
388
     * @return Merged array of all child objects of the node (of object 
389
     * represented by the node).
390
     */
391
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
392
        ArrayList arrays = new ArrayList();
393
        int count = 0;
394
        
395
        // Create list of subarrays        
396
        for( Iterator it = iterator(); it.hasNext(); ) {
397
            Look look = (Look)it.next();
398
            
399
            Object childKeys[] = look.getChildObjects( substitute );
400
            if ( childKeys.length == 0 ) {
401
                continue; 
402
            }
403
            else if ( !mergeLast && !it.hasNext() && count > 0 ) { 
404
                break; // if we don't merge stop if this is last look
405
            }
406
            else {
407
                count += childKeys.length;
408
                arrays.add( childKeys );
409
            }
410
        }
411
        
412
        if ( count == 0 ) {
413
            // Return if there is nothing to merge
414
            return Look.NO_KEYS;
415
        }
416
       
417
        // Merge the result and return it
418
        Object allChildKeys[] = new Object[ count ];
419
        int i = 0;
420
        for( Iterator it = arrays.iterator(); it.hasNext(); ) { 
421
            Object[] array = (Object[])it.next();
422
            System.arraycopy( array, 0,
423
                              allChildKeys, i, array.length );
424
            i += array.length;
425
        }
426
        
427
        return allChildKeys;
428
    }
429
        
430
    /* Not implemented yet
431
    
432
    public Ordering getOrdering( Look.NodeSubstitute substitute ) {
433
        return null;
434
    }
435
    
436
    public Filter getFilter( Look.NodeSubstitute substitute ) {
437
        return null;
438
    }
439
    
440
    public Grouping getGrouping( Look.NodeSubstitute substitute ) {
441
        return null;
442
    }
443
    
444
    */
445
     
446
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
447
    
448
    /** Merges all possible NewTypes from the sublooks. The ordering is the same 
449
     * as ordering of the sublooks.
450
     * @param node The node to operate on.
451
     * @return Merged array of NewTypes.
452
     */    
453
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
454
        ArrayList arrays = new ArrayList();
455
        int count = 0;
456
        
457
        // Create list of subarrays        
458
        for( Iterator it = iterator(); it.hasNext(); ) {
459
            Look look = (Look)it.next();
460
            
461
            NewType newTypes[] = look.getNewTypes( substitute );
462
            if ( newTypes.length == 0 ) {
463
                continue; 
464
            }
465
            else if ( !mergeLast && !it.hasNext() && count > 0 ) { 
466
                break; // We don't want to merge the last sublook
467
            }
468
            else {
469
                count += newTypes.length;
470
                arrays.add( newTypes );
471
            }
472
        }
473
        
474
        if ( count == 0 ) {
475
            // Return if there is nothing to merge
476
            return Look.NO_NEW_TYPES;
477
        }
478
       
479
        // Merge the result and return it
480
        NewType allNewTypes[] = new NewType[ count ];
481
        int i = 0;
482
        for( Iterator it = arrays.iterator(); it.hasNext(); ) { 
483
            NewType[] array = (NewType[]) it.next();
484
            System.arraycopy( array, 0,
485
                              allNewTypes, i, array.length );
486
            i += array.length;
487
        }
488
        return allNewTypes;
489
    }
490
    
491
    /** Merges all actions applicable to the node ffrom all subloks. The 
492
     * ordering is the same as ordering of the sublooks.
493
     * @param node The node to operate on.
494
     * @return Merged array of all actions.
495
     */    
496
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
497
        ArrayList arrays = new ArrayList();
498
        int count = 0;
499
        
500
        // Create list of subarrays        
501
        for( Iterator it = iterator(); it.hasNext(); ) {
502
            Look look = (Look)it.next();
503
            
504
            SystemAction actions[] = look.getActions( substitute );
505
            if ( actions.length == 0 ) {
506
                continue; 
507
            }
508
            else if ( !mergeLast && !it.hasNext() && count > 0 ) { 
509
                break; // We don't want to merge the last sublook
510
            }
511
            else {
512
                count += actions.length;
513
                arrays.add( actions );
514
            }
515
        }
516
        
517
        if ( count == 0 ) {
518
            // Return if there is nothing to merge
519
            return Look.NO_SYSTEM_ACTIONS;
520
        }
521
       
522
        // Merge the result and return it
523
        SystemAction allActions[] = new SystemAction[ count ];
524
        int i = 0;
525
        for( Iterator it = arrays.iterator(); it.hasNext(); ) { 
526
            SystemAction[] array = (SystemAction[]) it.next();
527
            System.arraycopy( array, 0,
528
                              allActions, i, array.length );
529
            i += array.length;
530
        }
531
        return allActions;
532
    }
533
    
534
    /** Merges all context actionss from the sublooks. The ordering is the same 
535
     * as ordering of the sublooks.
536
     * @param node The node to operate on.
537
     * @return Merged array of context actions.
538
     */    
539
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
540
        ArrayList arrays = new ArrayList();
541
        int count = 0;
542
        
543
        // Create list of subarrays        
544
        for( Iterator it = iterator(); it.hasNext(); ) {
545
            Look look = (Look)it.next();
546
            
547
            SystemAction contextActions[] = look.getContextActions( substitute );
548
            if ( contextActions.length == 0 ) {
549
                continue; 
550
            }
551
            else if ( !mergeLast && !it.hasNext() && count > 0 ) {
552
                break; // We don't want to merge the last sublook
553
            }
554
            count += contextActions.length;
555
            arrays.add( contextActions );
556
        }
557
        
558
        if ( count == 0 ) {
559
            // Return if there is nothing to merge
560
            return Look.NO_SYSTEM_ACTIONS;
561
        }
562
       
563
        // Merge the result and return it
564
        SystemAction allContextActions[] = new SystemAction[ count ];
565
        int i = 0;
566
        for( Iterator it = arrays.iterator(); it.hasNext(); ) { 
567
            SystemAction[] array = (SystemAction[]) it.next();
568
            System.arraycopy( array, 0,
569
                              allContextActions, i, array.length );
570
            i += array.length;
571
        }
572
        return allContextActions;
573
    }
574
    
575
    /** Finds default action for given node among the sublooks.
576
     * @param node The node to operate on.
577
     * @return The first default action found. 
578
     */    
579
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
580
        for ( Iterator it = iterator(); it.hasNext(); ) { 
581
            Look look = (Look)it.next();
582
            
583
            SystemAction systemAction = look.getDefaultAction( substitute );
584
            if ( systemAction != null ) {
585
                return systemAction;
586
            }
587
        }
588
        return null;
589
    }
590
    
591
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
592
    
593
    /** Merged property sets. The sets are mered in the order as they ar found 
594
     * among the sublooks. If there is more than one set with the same name then
595
     * properties in that set are merged with respect to the ordering of the 
596
     * sublooks.
597
     * @param node The node to operate on.
598
     * @return Merged property sets.
599
     */    
600
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
601
        
602
        ArrayList setsList = new ArrayList();
603
        Hashtable nameMap = new Hashtable();
604
        
605
        // Create list of property sets and the name map
606
        for( Iterator it = iterator(); it.hasNext(); ) {
607
            Look look = (Look)it.next();
608
609
            Node.PropertySet[] sets = look.getPropertySets( substitute );
610
            if ( sets.length == 0 ) {
611
                continue; // Look does not provide any properties
612
            }
613
            else if ( !mergeLast && !it.hasNext() && setsList.size() > 0 ) { // if we don't merge stop after first look 
614
                break; // we don't want to merge the last look
615
            }
616
            
617
            
618
            // Merge the property sets. We use sheet sets for
619
            // more comfortable work with propertySets
620
            for ( int i = 0; i < sets.length; i++ ) {
621
                if ( sets[i].getName() == null ) {
622
                    continue; // Ignore unnamed lists
623
                }
624
                Sheet.Set es = (Sheet.Set)nameMap.get( sets[i].getName() );
625
                if ( es == null ) { //Such sheet does not exist yet
626
                    es = new Sheet.Set( );
627
                    es.setName( sets[i].getName() );
628
                    es.setDisplayName( sets[i].getDisplayName() );
629
                    es.setShortDescription( sets[i].getShortDescription() );
630
                    es.put( sets[i].getProperties() );
631
                    Enumeration en = sets[i].attributeNames ();
632
                    while (en.hasMoreElements ()) {
633
                        String attr = (String)en.nextElement ();
634
                        es.setValue (attr, sets[i].getValue (attr));
635
                    }
636
                    setsList.add( es );
637
                    nameMap.put( sets[i].getName(), es );
638
                }
639
                else { // Sheet exists => merge properties
640
                    Node.Property[] props = sets[i].getProperties();
641
                    if ( props == null || props.length == 0 ) {
642
                        continue;
643
                    }
644
                    else {
645
                        es.put( sets[i].getProperties() );
646
                    }
647
                }                
648
            }        
649
        }
650
        
651
        if ( setsList.size() == 0 ) {
652
            return Look.NO_PROPERTY_SETS;
653
        }
654
        else {
655
            Node.PropertySet[] result = new Node.PropertySet[ setsList.size() ];
656
            setsList.toArray( result );
657
            return result;
658
        }
659
            
660
    }
661
    
662
    /** Finds the customizer among the sublooks.
663
     * @param node The node to operate on.
664
     * @return First customizer found among the sublooks.   
665
     */    
666
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
667
        for ( Iterator it = iterator(); it.hasNext(); ) { 
668
            Look look = (Look)it.next();
669
            
670
            java.awt.Component customizer = look.getCustomizer( substitute );
671
            if ( customizer != null ) {
672
                return customizer;
673
            }
674
        }
675
        return null;
676
    }
677
    
678
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
679
     
680
    /** Figures out whether some look is capable of renaming given node.
681
     * @param node The node to operate on.
682
     * @return False if all sublooks return false, true otherwise.
683
     */    
684
    public boolean canRename( Look.NodeSubstitute substitute ) {
685
        for ( Iterator it = iterator(); it.hasNext(); ) { 
686
            Look look = (Look)it.next();
687
            
688
            if ( look.canRename( substitute ) ) {
689
                return true;
690
            }
691
        }
692
        return false;
693
    }
694
    
695
    /** Figures out whether some look is capable of destroying given node.
696
     * @param node The node to operate on.
697
     * @return False if all sublooks return false, true otherwise.
698
     */    
699
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
700
        for ( Iterator it = iterator(); it.hasNext(); ) { 
701
            Look look = (Look)it.next();
702
            
703
            if ( look.canDestroy( substitute ) ) {
704
                return true;
705
            }
706
        }
707
        return false;
708
    }
709
    
710
    /** Figures out whether some look is capable of copying given node.
711
     * @param node The node to operate on.
712
     * @return False if all sublooks return false, true otherwise.
713
     */    
714
    public boolean canCopy( Look.NodeSubstitute substitute ) {
715
        for ( Iterator it = iterator(); it.hasNext(); ) { 
716
            Look look = (Look)it.next();
717
            
718
            if ( look.canCopy( substitute ) ) {
719
                return true;
720
            }
721
        }
722
        return false;
723
    }
724
    
725
    /** Figures out whether some look is capable of cutting given node.
726
     * @param node The node to operate on.
727
     * @return False if all sublooks return false, true otherwise.
728
     */    
729
    public boolean canCut( Look.NodeSubstitute substitute ) {
730
        for ( Iterator it = iterator(); it.hasNext(); ) { 
731
            Look look = (Look)it.next();
732
            
733
            if ( look.canCut( substitute ) ) {
734
                return true;
735
            }
736
        }
737
        return false;
738
    }
739
    
740
    /** Merges all pastetypes for given node.
741
     * @param node The node to operate on.
742
     * @param t The tranferable
743
     * @return Merged array of paste types.
744
     */    
745
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
746
        ArrayList arrays = new ArrayList();
747
        int count = 0;
748
        
749
        // Create list of subarrays        
750
        for( Iterator it = iterator(); it.hasNext(); ) {
751
            Look look = (Look)it.next();
752
            
753
            PasteType pasteTypes[] = look.getPasteTypes( substitute, t );
754
            if ( pasteTypes.length == 0 ) {
755
                continue; 
756
            }
757
            else if ( !mergeLast && !it.hasNext() && count > 0 ) { // if we don't merge stop after first look 
758
                break; // We don't want to merge the last sublook
759
            }
760
            else {
761
                count += pasteTypes.length;
762
                arrays.add( pasteTypes );
763
            }
764
        }
765
        
766
        if ( count == 0 ) {
767
            // Return if there is nothing to merge
768
            return Look.NO_PASTE_TYPES;
769
        }
770
       
771
        // Merge the result and return it
772
        PasteType allPasteTypes[] = new PasteType[ count ];
773
        int i = 0;
774
        for( Iterator it = arrays.iterator(); it.hasNext(); ) { 
775
            PasteType[] array = (PasteType[]) it.next();
776
            System.arraycopy( array, 0,
777
                              allPasteTypes, i, array.length );
778
            i += array.length;
779
        }
780
        return allPasteTypes;
781
    }
782
    
783
    /** Determine if there is a look capable of the paste operation that can 
784
     * be performed  on provided transferable. Used by drag'n'drop code to 
785
     * check whether the drop is possible.
786
     * @param node The node to operate on.
787
     * @param t The transferable.
788
     * @param action The drag'n'drop action to do DnDConstants.ACTION_MOVE, 
789
     *        ACTION_COPY, ACTION_LINK.
790
     * @param index Index between children the drop occured at or -1 if not specified.
791
     * @return <CODE>Null</CODE> if no look can accept the transferable  or the paste type
792
     *         to execute when the drop occures.
793
     */    
794
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
795
        for ( Iterator it = iterator(); it.hasNext(); ) { 
796
            Look look = (Look)it.next();
797
            
798
            PasteType pasteType = look.getDropType( substitute, t, action, index );
799
            if ( pasteType != null ) {
800
                return pasteType;
801
            }
802
        }
803
        return null;
804
    }
805
    
806
    /** Notifies all sublooks that the node was copyied to the clipboard until
807
     * some look does not return a tranfrable.
808
     * @param node The node to operate on.
809
     * @return The transferable object representing the content of the clipboard.
810
     * @throws IOException When the copy cannot be performed.
811
     */    
812
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
813
        for ( Iterator it = iterator(); it.hasNext(); ) { 
814
            Look look = (Look)it.next();
815
            
816
            Transferable transferable = look.clipboardCopy( substitute );
817
            if ( transferable != null ) {
818
                return transferable;
819
            }
820
        }
821
        return null;
822
    }
823
    
824
    /** Notifies all sublooks that the node was cutted to the clipboard until
825
     * some look does not return a tranfrable.
826
     * @param node The node to operate on.
827
     * @throws IOException When the cut cannot be performed.
828
     * @return The transferable object representing the content of the clipboard.
829
     */    
830
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
831
        for ( Iterator it = iterator(); it.hasNext(); ) { 
832
            Look look = (Look)it.next();
833
            
834
            Transferable transferable = look.clipboardCut( substitute );
835
            if ( transferable != null ) {
836
                return transferable;
837
            }
838
        }
839
        return null;
840
    }
841
    
842
   /** Notifies all sublooks that the node was dragged until some look does not 
843
     * return a tranfrable.
844
     * @param node The node to operate on.
845
     * @throws IOException If a drag cannot be started.
846
     * @return Transferable to represent this node during a drag.
847
     */    
848
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
849
        for ( Iterator it = iterator(); it.hasNext(); ) { 
850
            Look look = (Look)it.next();
851
            
852
            Transferable transferable = look.drag( substitute );
853
            if ( transferable != null ) {
854
                return transferable;
855
            }
856
        }
857
        return null;
858
    }
859
    
860
    /** Calls <CODE>destroy()</CODE> on all sublooks.
861
     * @param substitute Node.Interior of the destroyed ndoe.
862
     */
863
    public void destroy(Look.NodeSubstitute substitute) throws IOException{
864
        for ( Iterator it = iterator(); it.hasNext(); ) { 
865
            Look look = (Look)it.next();
866
            
867
            look.destroy( substitute );
868
        }
869
    }
870
    
871
}
(-)openidex/src/org/openidex/nodes/looks/DefaultLook.java (-289 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
20
import org.openide.nodes.*;
21
import org.openide.util.actions.SystemAction;
22
import org.openide.util.HelpCtx;
23
import org.openide.util.datatransfer.NewType;
24
import org.openide.util.datatransfer.PasteType;
25
26
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
27
 * Please don't use this API for other purposes than testing.
28
 * <P>
29
 * Adaptor class which returns neutral values from all methods.
30
 * <P>
31
 * This class can be either subclassed or calls may be delegated to the
32
 * {@link #INSTANCE}.
33
 *
34
 * @author Petr Hrebejk
35
 */
36
public class DefaultLook extends Look {
37
    
38
    /** Default instance of <CODE>DefaultLook</CODE>. This 
39
     * instance can be used to delegate to.
40
     */
41
    public static final DefaultLook INSTANCE = new DefaultLook();
42
    
43
    /** Creates new DefaultLook. The costructor is protected, there should 
44
     * be no need for creating new <CODE>DefaultLook</CODE>s. You can delegate
45
     * to {@link #INSTANCE} instead.
46
     */
47
    protected DefaultLook() {
48
    }
49
  
50
    // Methods of look itself --------------------------------------------------
51
    
52
    
53
    // General methods ---------------------------------------------------------
54
55
    /** Empty - simply returns.
56
     * @param substitute The parameter is ignored.  
57
     */    
58
    public void attachTo(Look.NodeSubstitute substitute) {
59
    }
60
    
61
    /** Returns neutral value.
62
     * @param substitute The parameter is ignored.
63
     * @param substitute The parameter is ignored.
64
     * @return Neutral value - <CODE>null</CODE>.  
65
     */    
66
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
67
        return null;
68
    }
69
70
    /** Returns neutral value.
71
     * @param substitute The parameter is ignored.
72
     * @return Neutral value - <CODE>null</CODE>.
73
     */    
74
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
75
        return null;
76
    }
77
    
78
    // Methods for STYLE -------------------------------------------------------
79
    
80
    /** Returns neutral value.
81
     * @param substitute The parameter is ignored.
82
     * @return Neutral value - <CODE>null</CODE>. 
83
     */    
84
    public String getDisplayName( Look.NodeSubstitute substitute ) {
85
        return null;
86
    }
87
    
88
    /** Returns neutral value.
89
     * @param substitute The parameter is ignored.
90
     * @return Neutral value - <CODE>null</CODE>. 
91
     */    
92
    public String getName( Look.NodeSubstitute substitute ) {
93
        return null;
94
    }
95
    
96
    /** Does nothing - empty implementation.
97
     * @param substitute The parameter is ignored.
98
     * @param newName The parameter is ignored.
99
     */
100
    public void setName(Look.NodeSubstitute substitute, String newName ) {
101
    }
102
    
103
    /** Returns neutral value.
104
     * @param substitute The parameter is ignored.
105
     * @return Neutral value - <CODE>null</CODE>. 
106
     */    
107
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
108
        return null;
109
    }
110
    
111
    /** Returns neutral value.
112
     * @param substitute The parameter is ignored.
113
     * @param substitute The parameter is ignored.
114
     * @return Neutral value - <CODE>null</CODE>.
115
     */    
116
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
117
        return null;
118
    }
119
    
120
    /** Returns neutral value.
121
     * @param substitute The parameter is ignored.
122
     * @param substitute The parameter is ignored.
123
     * @return Neutral value - <CODE>null</CODE>.
124
     */    
125
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
126
        return null;
127
    }
128
    
129
    /** Returns neutral value.
130
     * @param substitute The parameter is ignored.
131
     * @return Neutral value - <CODE>null</CODE>. 
132
     */    
133
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
134
        return null;
135
    }
136
    
137
    // Methods for CHILDREN ----------------------------------------------------
138
    
139
    /** Returns neutral value.
140
     * @param substitute The parameter is ignored.
141
     * @return Neutral value - {@link Look#NO_KEYS}. 
142
     */    
143
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
144
        return Look.NO_KEYS;
145
    }
146
             
147
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
148
    
149
    /** Returns neutral value.
150
     * @param substitute The parameter is ignored.
151
     * @return Neutral value - {@link Look#NO_NEW_TYPES}. 
152
     */    
153
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
154
        return Look.NO_NEW_TYPES;
155
    }
156
    
157
    /** Returns neutral value.
158
     * @param substitute The parameter is ignored.
159
     * @return Neutral value - {@link Look#NO_SYSTEM_ACTIONS}.
160
     */    
161
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
162
        return Look.NO_SYSTEM_ACTIONS;
163
    }
164
    
165
    /** Returns neutral value.
166
     * @param substitute The parameter is ignored.
167
     * @return Neutral value - {@link Look#NO_SYSTEM_ACTIONS}. 
168
     */    
169
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
170
        return Look.NO_SYSTEM_ACTIONS;
171
    }
172
    
173
    /** Returns neutral value.
174
     * @param substitute The parameter is ignored.
175
     * @return Neutral value - <CODE>null</CODE>. 
176
     */    
177
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
178
        return null;
179
    }
180
    
181
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
182
    
183
    /** Returns neutral value.
184
     * @param substitute The parameter is ignored.
185
     * @return Neutral value - {@link Look#NO_PROPERTY_SETS}. 
186
     */    
187
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
188
        return Look.NO_PROPERTY_SETS;
189
    }
190
    
191
    /** Returns neutral value.
192
     * @param substitute The parameter is ignored.
193
     * @return Neutral value - <CODE>null</CODE>. 
194
     */    
195
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
196
        return null;
197
    }
198
    
199
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
200
     
201
    /** Returns neutral value.
202
     * @param substitute The parameter is ignored.
203
     * @return Neutral value - <CODE>false</CODE>.
204
     */    
205
    public boolean canRename( Look.NodeSubstitute substitute ) {
206
        return false;
207
    }
208
    
209
    /** Returns neutral value.
210
     * @param substitute The parameter is ignored.
211
     * @return Neutral value - <CODE>false</CODE>. 
212
     */    
213
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
214
        return false;
215
    }
216
    
217
    /** Returns neutral value.
218
     * @param substitute The parameter is ignored.
219
     * @return Neutral value - <CODE>false</CODE>. 
220
     */    
221
    public boolean canCopy( Look.NodeSubstitute substitute ) {
222
        return false;
223
    }
224
    
225
    /** Returns neutral value.
226
     * @param substitute The parameter is ignored.
227
     * @return Neutral value - <CODE>false</CODE>. 
228
     */    
229
    public boolean canCut( Look.NodeSubstitute substitute ) {
230
        return false;
231
    }
232
    
233
    /** Returns neutral value.
234
     * @param substitute The parameter is ignored.
235
     * @param t The parameter is ignored.
236
     * @return Neutral value - {@link Look#NO_PASTE_TYPES}. 
237
     */    
238
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
239
        return Look.NO_PASTE_TYPES;
240
    }
241
    
242
    /** Returns neutral value.
243
     * @param substitute The parameter is ignored.
244
     * @param t The parameter is ignored.
245
     * @param action The parameter is ignored.
246
     * @param index The parameter is ignored.
247
     * @return Neutral value - <CODE>null</CODE>. 
248
     */    
249
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
250
        return null;
251
    }
252
    
253
    /** Returns neutral value.
254
     * @param substitute The parameter is ignored.
255
     * @throws IOException The exception is never thrown.
256
     * @return Neutral value - <CODE>null</CODE>. 
257
     */    
258
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
259
        return null;
260
    }
261
    
262
    /** Returns neutral value.
263
     * @param substitute The parameter is ignored.
264
     * @throws IOException The exception is never thrown.
265
     * @return Neutral value - <CODE>null</CODE>. 
266
     */    
267
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
268
        return null;
269
    }
270
    
271
    /** Returns neutral value.
272
     * @param substitute The parameter is ignored.
273
     * @throws IOException The exception is never thrown.
274
     * @return Neutral value - <CODE>null</CODE>.
275
     */    
276
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
277
        return null;
278
    }
279
          
280
    /** Does nothing - empty implementation.
281
     * @param substitute The parameter is ignored.
282
     * @throws IOException The exception is never thrown.
283
     */
284
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
285
    }
286
    
287
    
288
    
289
}
(-)openidex/src/org/openidex/nodes/looks/EventTranslator.java (-95 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.lang.ref.WeakReference;
17
import java.lang.ref.ReferenceQueue;
18
19
import org.openide.util.RequestProcessor;
20
21
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
22
 * Please don't use this API for other purposes than testing.
23
 * <P>
24
 * Utility class which allows to fire events on the LookNode according
25
 * to events of the represented object. This class should be used as a base
26
 * class for EventListener registered to represented objects.
27
 * <P>
28
 * The LookNode interior is hold by a WeakReference so the Node can be 
29
 * garbage collected even if the represented object still exists.<BR>
30
 * If you really want the node is not garbage collected while the 
31
 * represented object exists then hardreference the <CODE>Node.Interior</CODE>
32
 * from the subclass.
33
 * <P>
34
 * Helper methods allow automatic changes of Icon, Name and DisplayName
35
 * if some properies are changed.
36
 */
37
public abstract class EventTranslator extends WeakReference {
38
39
    /** Queue with all weak references */
40
    private static ReferenceQueue QUEUE = new ReferenceQueue ();
41
    /** How often clean */
42
    private static int CLEANER_TIME = 25000;
43
    /** Clearner task */
44
    private static RequestProcessor.Task CLEANER_TASK = RequestProcessor.postRequest(
45
        new Cleaner (), CLEANER_TIME, Thread.MIN_PRIORITY
46
        );
47
    
48
    /** Fake instance to fire event on when the node was garbage collected. */
49
    private static final LookNode NULL_NODE = new LookNode( null );
50
51
    /** Creates new EventTranslator for given LookNode.Interior
52
     * @param LookNode.Interior the node to fire events on.
53
     */
54
    public EventTranslator ( Look.NodeSubstitute substitute ) {
55
        super( substitute, QUEUE );
56
    }
57
58
    /** This method is called when the node was garbage colledted. You shoud
59
     * unregister from all objects where this object was registered as a 
60
     * listener.
61
     */ 
62
    protected abstract void unregister();
63
64
    /** Gets the substitute to fire on
65
     */
66
    protected Look.NodeSubstitute getSubstitute() {
67
        Look.NodeSubstitute substitute = (Look.NodeSubstitute)get();
68
        if ( substitute == null ) {
69
            unregister();
70
            return NULL_NODE.getSubstitute();
71
        }
72
        else {
73
            return substitute;
74
        }
75
    }
76
    
77
    
78
    // Innerclasses ------------------------------------------------------------
79
    
80
    /** Class that periodically runs cleaning of the queue.
81
    */
82
    private static final class Cleaner extends Object implements Runnable {
83
        public void run () {
84
            for (;;) {
85
                EventTranslator et = (EventTranslator)QUEUE.poll();
86
                if (et == null) 
87
                    break;
88
                et.unregister();
89
            }
90
91
            CLEANER_TASK.schedule (CLEANER_TIME);
92
        }
93
    }
94
    
95
}
(-)openidex/src/org/openidex/nodes/looks/FilterLook.java (-534 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
20
import org.openide.nodes.*;
21
import org.openide.util.actions.SystemAction;
22
import org.openide.util.HelpCtx;
23
import org.openide.util.datatransfer.NewType;
24
import org.openide.util.datatransfer.PasteType;
25
26
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
27
 * Please don't use this API for other purposes than testing.
28
 * <P> 
29
 * This is base class for delegating to other looks. All methods 
30
 * delegate to the delegate, unless they are masked.
31
 * <P>
32
 * All the methods contain  simple deleagation to the {@link Look} 
33
 * passed as parameter into the constructor, if the mask contains flag
34
 * for the method.<P>
35
 * Use the methods: {@link #setLookMask}, {@link #lookMask}, {@link #lookMask}, 
36
 * {@link #lookUnmask} for work with the mask.<BR> 
37
 * The default state is to delegate all methods (i.e. the mask is set to
38
 * {@link #ALL_METHODS}.)
39
 *
40
 * @author Petr Hrebejk
41
 */
42
public class FilterLook extends DefaultLook {
43
    
44
    /** Mask for enabling (unmasking) all methods */
45
    public static final long ALL_METHODS = Integer.MAX_VALUE;
46
    /** Mask for disabling (masking) all methods */
47
    public static final long NO_METHODS = 0;
48
    /** Mask for the method {@link #attachTo}. */
49
    public static final long ATTACH_TO = 1;
50
    /** Mask for the method {@link #getCookie}. */
51
    public static final long GET_COOKIE = ATTACH_TO << 1;
52
    /** Mask for the method {@link #getHandle}. */
53
    public static final long GET_HANDLE = GET_COOKIE << 1;
54
    /** Mask for the method {@link #getDisplayName}. */
55
    public static final long GET_DISPLAY_NAME = GET_HANDLE << 1;
56
    /** Mask for the method {@link #getName}. */
57
    public static final long GET_NAME = GET_DISPLAY_NAME << 1;
58
    /** Mask for the method {@link #setName}. */
59
    public static final long SET_NAME = GET_NAME << 1;
60
    /** Mask for the method {@link #getShortDescription}. */
61
    public static final long GET_SHORT_DESCRIPTION = SET_NAME << 1;
62
    /** Mask for the method {@link #getIcon}. */
63
    public static final long GET_ICON = GET_SHORT_DESCRIPTION << 1;
64
    /** Mask for the method {@link #getOpenedIcon}. */
65
    public static final long GET_OPENED_ICON = GET_ICON << 1;
66
    /** Mask for the method {@link #getHelpCtx}. */
67
    public static final long GET_HELP_CTX = GET_OPENED_ICON << 1;
68
    /** Mask for the method {@link #getChildObjects}. */
69
    public static final long GET_CHILD_OBJECTS = GET_HELP_CTX << 1;
70
    /** Mask for the method {@link #getNewTypes}. */
71
    public static final long GET_NEW_TYPES = GET_CHILD_OBJECTS << 1;
72
    /** Mask for the method {@link #getActions}. */
73
    public static final long GET_ACTIONS = GET_NEW_TYPES << 1;
74
    /** Mask for the method {@link #getContextActions}. */
75
    public static final long GET_CONTEXT_ACTIONS = GET_ACTIONS << 1;
76
    /** Mask for the method {@link #getDefaultAction}. */
77
    public static final long GET_DEFAULT_ACTION = GET_CONTEXT_ACTIONS << 1;
78
    /** Mask for the method {@link #getPropertySets}. */
79
    public static final long GET_PROPERTY_SETS = GET_DEFAULT_ACTION << 1;
80
    /** Mask for the method {@link #getCustomizer}. */
81
    public static final long GET_CUSTOMIZER = GET_PROPERTY_SETS << 1;
82
    /** Mask for the method {@link #canRename}. */
83
    public static final long CAN_RENAME = GET_CUSTOMIZER << 1;
84
    /** Mask for the method {@link #canDestroy}. */
85
    public static final long CAN_DESTROY = CAN_RENAME << 1;
86
    /** Mask for the method {@link #canCopy}. */
87
    public static final long CAN_COPY = CAN_DESTROY << 1;
88
    /** Mask for the method {@link #canCut}. */
89
    public static final long CAN_CUT = CAN_COPY << 1;
90
    /** Mask for the method {@link #getPasteTypes}. */
91
    public static final long GET_PASTE_TYPES = CAN_CUT << 1;
92
    /** Mask for the method {@link #getDropType}. */
93
    public static final long GET_DROP_TYPE = GET_PASTE_TYPES << 1;
94
    /** Mask for the method {@link #clipboardCopy}. */
95
    public static final long CLIPBOARD_COPY = GET_DROP_TYPE << 1;
96
    /** Mask for the method {@link #clipboardCut}. */
97
    public static final long CLIPBOARD_CUT = CLIPBOARD_COPY << 1;
98
    /** Mask for the method {@link #drag}. */
99
    public static final long DRAG = CLIPBOARD_CUT << 1;
100
    /** Mask for the method {@link #destroy}. */
101
    public static final long DESTROY = DRAG << 1;
102
    
103
    /** Contains current mask of the node */
104
    protected long mask = ALL_METHODS;
105
    
106
    /** Contains the Look to delegate to. */
107
    protected Look delegate;
108
    
109
    /** Creates new Delegating look 
110
     * @param delegate The Look to delegate to.
111
     */
112
    public FilterLook(Look delegate) {
113
        this.delegate = delegate;
114
    }
115
    
116
    private boolean filterMethod( long method ) {
117
        return ( mask & method ) > 0;
118
    }
119
    
120
    // Methods of look itself -------------------------------------------------
121
    
122
    public boolean isLookStandalone( Object representedObject  ) {
123
        return delegate.isLookStandalone( representedObject  );
124
    }
125
    
126
    /** Sets mask for this look. Only methods contained in the mask
127
     * will be delegated. Other methods will return neutral values.
128
     * @param mask The mask to be set.
129
     */
130
    public void setLookMask( long mask ) {
131
        this.mask = mask;
132
    }
133
    
134
    /** Returns the current mask for this filter look.
135
     * @return Current mask.
136
     */
137
    public long getLookMask( ) {
138
        return mask;
139
    }
140
    
141
    /** Masks given methods. Removes given methods from given mask. 
142
     * The masked methods will be no longer delegated.
143
     * @param methods Logical <CODE>OR</CODE> of methods which have to be masked.
144
     * @return Current mask.
145
     */
146
    public long lookMask( long methods ) {
147
        mask |= methods;
148
        return mask;
149
    }
150
     
151
    /** Unmasks given methods. Adds given methods from given mask. 
152
     * The masked methods will start to be delegated.
153
     * @param methods Logical <CODE>OR</CODE> of methods which have to be unmasked.
154
     * @return Current mask.
155
     */
156
    public long lookUnmask( long methods ) {
157
        mask &= ~methods; 
158
        return mask;
159
    }
160
    
161
    // General methods ---------------------------------------------------------
162
    
163
    public void attachTo( Look.NodeSubstitute substitute ) {
164
        if ( filterMethod( ATTACH_TO ) ) {
165
            delegate.attachTo( new FilterNodeSubstitute( substitute, this ) );
166
        }
167
        else {
168
            super.attachTo( substitute );
169
        }
170
    }
171
    
172
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
173
        if ( filterMethod( GET_COOKIE ) ) {
174
            return delegate.getCookie( substitute, type );
175
        }
176
        else {
177
            return super.getCookie( substitute, type );
178
        }
179
    }
180
181
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
182
        if ( filterMethod( GET_HANDLE ) ) {
183
            return delegate.getHandle( substitute );
184
        }
185
        else {
186
            return super.getHandle( substitute );
187
        }
188
    }
189
    
190
    // Methods for STYLE -------------------------------------------------------
191
    
192
    public String getDisplayName( Look.NodeSubstitute substitute ) {
193
        if ( filterMethod( GET_DISPLAY_NAME ) ) {
194
            return delegate.getDisplayName( substitute );
195
        }
196
        else {
197
            return super.getDisplayName( substitute );
198
        }
199
    }
200
    
201
    public String getName( Look.NodeSubstitute substitute ) {
202
        if ( filterMethod( GET_NAME ) ) {
203
            return delegate.getName( substitute );
204
        }
205
        else {
206
            return super.getName( substitute );
207
        }
208
    }
209
    
210
    public void setName(Look.NodeSubstitute substitute, String newName) {
211
        if ( filterMethod( SET_NAME ) ) {
212
            delegate.setName( substitute, newName );
213
        }
214
        else {
215
            super.setName( substitute, newName );
216
        }
217
    }
218
    
219
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
220
        if ( filterMethod( GET_SHORT_DESCRIPTION ) ) {
221
            return delegate.getShortDescription( substitute );
222
        }
223
        else {
224
            return super.getShortDescription( substitute );
225
        }
226
    }
227
    
228
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
229
        if ( filterMethod( GET_ICON ) ) {
230
            return delegate.getIcon( substitute, type );
231
        }
232
        else {
233
            return super.getIcon( substitute, type );
234
        }
235
    }
236
    
237
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
238
        if ( filterMethod( GET_OPENED_ICON ) ) {
239
            return delegate.getOpenedIcon( substitute, type );
240
        }
241
        else {
242
            return super.getOpenedIcon( substitute, type );
243
        }
244
    }
245
    
246
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
247
        if ( filterMethod( GET_HELP_CTX ) ) {
248
            return delegate.getHelpCtx( substitute );
249
        }
250
        else {
251
            return super.getHelpCtx( substitute );
252
        }
253
    }
254
    
255
    // Methods for CHILDREN ----------------------------------------------------
256
    
257
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
258
        if ( filterMethod( GET_CHILD_OBJECTS ) ) {
259
            return delegate.getChildObjects( substitute );
260
        }
261
        else {
262
            return super.getChildObjects( substitute );
263
        }
264
    }
265
    
266
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
267
    
268
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
269
        if ( filterMethod( GET_NEW_TYPES ) ) {
270
            return delegate.getNewTypes( substitute );
271
        }
272
        else {
273
            return super.getNewTypes( substitute );
274
        }
275
    }
276
    
277
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
278
        if ( filterMethod( GET_ACTIONS ) ) {
279
            return delegate.getActions( substitute );
280
        }
281
        else {
282
            return super.getActions( substitute );
283
        }
284
    }
285
    
286
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
287
        if ( filterMethod( GET_CONTEXT_ACTIONS ) ) {
288
            return delegate.getContextActions( substitute );
289
        }
290
        else {
291
            return super.getContextActions( substitute );
292
        }
293
    }
294
    
295
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
296
        if ( filterMethod( GET_DEFAULT_ACTION ) ) {
297
            return delegate.getDefaultAction( substitute );
298
        }
299
        else {
300
            return super.getDefaultAction( substitute );
301
        }
302
    }
303
    
304
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
305
    
306
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
307
        if ( filterMethod( GET_PROPERTY_SETS ) ) {
308
            return delegate.getPropertySets( substitute );
309
        }
310
        else {
311
            return super.getPropertySets( substitute );
312
        }
313
    }
314
    
315
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
316
        if ( filterMethod( GET_CUSTOMIZER ) ) {
317
            return delegate.getCustomizer( substitute );
318
        }
319
        else {
320
            return super.getCustomizer( substitute );
321
        }
322
    }
323
    
324
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
325
     
326
    public boolean canRename( Look.NodeSubstitute substitute ) {
327
        if ( filterMethod( CAN_RENAME ) ) {
328
            return delegate.canRename( substitute );
329
        }
330
        else {
331
            return super.canRename( substitute );
332
        }
333
    }
334
    
335
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
336
        if ( filterMethod( CAN_DESTROY ) ) {
337
            return delegate.canDestroy( substitute );
338
        }
339
        else {
340
            return super.canDestroy( substitute );
341
        }
342
    }
343
    
344
    public boolean canCopy( Look.NodeSubstitute substitute ) {
345
        if ( filterMethod( CAN_COPY ) ) {
346
            return delegate.canCopy( substitute );
347
        }
348
        else {
349
            return super.canCopy( substitute );
350
        }
351
    }
352
    
353
    public boolean canCut( Look.NodeSubstitute substitute ) {
354
        if ( filterMethod( CAN_CUT ) ) {
355
            return delegate.canCut( substitute );
356
        }
357
        else {
358
            return super.canCut( substitute );
359
        }
360
    }
361
    
362
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
363
        if ( filterMethod( GET_PASTE_TYPES ) ) {
364
            return delegate.getPasteTypes( substitute, t );
365
        }
366
        else {
367
            return super.getPasteTypes( substitute, t );
368
        }
369
    }
370
    
371
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
372
        if ( filterMethod( GET_DROP_TYPE ) ) {
373
            return delegate.getDropType( substitute, t, action, index );
374
        }
375
        else {
376
            return super.getDropType( substitute, t, action, index );
377
        }
378
    }
379
    
380
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
381
        if ( filterMethod( CLIPBOARD_COPY ) ) {
382
            return delegate.clipboardCopy( substitute );
383
        }
384
        else {
385
            return super.clipboardCopy( substitute );
386
        }
387
    }
388
    
389
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
390
        if ( filterMethod( CLIPBOARD_CUT ) ) {
391
            return delegate.clipboardCut( substitute );
392
        }
393
        else {
394
            return super.clipboardCut( substitute );
395
        }
396
    }
397
    
398
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
399
        if ( filterMethod( DRAG ) ) {
400
            return delegate.drag( substitute );
401
        }
402
        else {
403
            return super.drag( substitute );
404
        }
405
    }
406
        
407
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
408
        if ( filterMethod( DESTROY ) ) {
409
            delegate.destroy( substitute );
410
        }
411
        else {
412
            super.destroy( substitute );
413
        }
414
    }
415
    
416
    // Innerclasses ------------------------------------------------------------
417
    
418
    static class FilterNodeSubstitute extends Look.NodeSubstitute {
419
        
420
        private FilterLook filterLook;
421
        private Look.NodeSubstitute substitute;
422
        
423
        FilterNodeSubstitute( Look.NodeSubstitute substitute, FilterLook filterLook ) {
424
            this.substitute = substitute;
425
            this.filterLook = filterLook;
426
        }
427
        
428
        /** Returns the object represented by the node
429
         * @return Object represented by the node this interior belongs to.
430
         */
431
        public Object getRepresentedObject() {
432
            return substitute.getRepresentedObject();
433
        }        
434
        
435
        /** Fires a (Bean) property change event (for
436
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
437
         * @param o the old set
438
         * @param n the new set
439
         */
440
        public void firePropertySetsChange(Node.PropertySet[] o, Node.PropertySet[] n) {
441
            if ( filterLook.filterMethod( GET_PROPERTY_SETS ) ) {
442
                substitute.firePropertySetsChange( o, n );
443
            }
444
        }
445
        
446
        /** Fires the Event notificationg about name change.
447
         */
448
        public void fireNameChange(String o, String n) {
449
            if ( filterLook.filterMethod( GET_NAME ) ) {
450
                substitute.fireNameChange( o, n );
451
            }
452
        }
453
        
454
        /** Fires a change event for {@link org.openode.nodes.Node#PROP_COOKIE}.
455
         * The old and new values are set to null.
456
         */
457
        public void fireCookieChange() {
458
            if ( filterLook.filterMethod( GET_COOKIE ) ) {
459
                substitute.fireCookieChange( );
460
            }
461
        }
462
        
463
        /** Fires the Event notificationg about display name change.
464
         */
465
        public void fireDisplayNameChange(String o, String n) {
466
            if ( filterLook.filterMethod( GET_DISPLAY_NAME ) ) {
467
                substitute.fireDisplayNameChange( o, n );
468
            }
469
        }
470
        
471
        /** Tells the node that the children have to be refreshed.
472
         */
473
        public void refreshChildren() {
474
            if ( filterLook.filterMethod( GET_CHILD_OBJECTS ) ) {
475
                substitute.refreshChildren( );
476
            }
477
        }
478
        
479
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
480
         * associated node.
481
         */
482
        public void fireOpenedIconChange() {
483
            if ( filterLook.filterMethod( GET_OPENED_ICON ) ) {
484
                substitute.fireOpenedIconChange();
485
            }
486
        }
487
        
488
        /** To all node listeners fire node destroyed notification.
489
         */
490
        public void fireNodeDestroyed() {
491
            if ( filterLook.filterMethod( DESTROY ) ) {
492
                substitute.fireNodeDestroyed();
493
            }
494
        }
495
        
496
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
497
         * associated node.
498
         */
499
        public void fireIconChange() {
500
            if ( filterLook.filterMethod( GET_ICON ) ) {
501
                substitute.fireIconChange();
502
            }
503
        }
504
        
505
        /** Fires the Event notificationg about short description change.
506
         */
507
        public void fireShortDescriptionChange(String o, String n) {
508
            if ( filterLook.filterMethod( GET_SHORT_DESCRIPTION ) ) {
509
                substitute.fireShortDescriptionChange( o, n );
510
            }
511
        }
512
        
513
        /** Fire a property change event on the associated node.
514
         * @param name name of changed property (from {@link #getPropertySets})
515
         * @param o old value
516
         * @param n new value
517
         */
518
        public void firePropertyChange(String name, Object o, Object n) {
519
            if ( filterLook.filterMethod( GET_PROPERTY_SETS ) ) {
520
                substitute.firePropertyChange( name, o, n );
521
            }
522
        }
523
        
524
        /** Allowes to store Cookies for given node. This method could be
525
         *
526
         */
527
        public CookieSet getCookieSet() {
528
            return substitute.getCookieSet();
529
        }
530
        
531
    }
532
    
533
    
534
}
(-)openidex/src/org/openidex/nodes/looks/JndiLook.java (-105 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
17
import javax.naming.*;
18
19
import org.openide.nodes.*;
20
import org.openide.util.enum.*;
21
import java.util.Enumeration;
22
23
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
24
 * Please don't use this API for other purposes than testing.
25
 * <P>
26
 * Searches for a look in JNDI namespace given name of context to search in
27
 * and a a possible set of names that should be checked.
28
 *
29
 * @author Jaroslav Tulach
30
 */
31
final class JndiLook extends Object {
32
    private static Object context;
33
    
34
    /** Finds look for a class.
35
     * @param c clazz to search for 
36
     * @return look found or null 
37
     */
38
    public static Look findLook (Class c) {
39
        if (context == null) {
40
            try {
41
                context = new InitialContext ().lookup ("Looks/Types"); // NOI18N
42
            } catch (NamingException ex) {
43
                context = ex;
44
            }
45
        }
46
        
47
        if (context instanceof Context) {
48
            return findLook ((Context)context, forClass (c));
49
        } else {
50
            return null;
51
        }
52
    }
53
    
54
    /** Searches for a look in given namespace and in the order specified by
55
     * given names.
56
     *
57
     * @param namespace the root context to search from
58
     * @param names list of Strings to check their names (c1/c2/name)
59
     * @return the look or null
60
     */
61
    private static Look findLook (Context namespace, Enumeration names) {
62
        while (names.hasMoreElements ()) {
63
            try {
64
                String check = (String)names.nextElement ();
65
                NamingEnumeration en = namespace.listBindings (check);
66
                while (en.hasMoreElements ()) {
67
                    Binding b = (Binding)en.next ();
68
                    Object o = b.getObject ();
69
                    if (o instanceof Look) {
70
                        return (Look)o;
71
                    }
72
                }
73
            } catch (NamingException ex) {
74
            }
75
        }
76
        return null;
77
    }
78
    
79
    /** Enumeration for a java class.
80
     * @param c class 
81
     * @return enumeration of names of implemented/extended classes in form suitable
82
     *      for findLook
83
     */
84
    private static Enumeration forClass (Class c) {
85
        QueueEnumeration en = new QueueEnumeration () {
86
            protected void process (Object o) {
87
                Class x = (Class)o;
88
                Class s = x.getSuperclass();
89
                if (s != null) {
90
                    // if not object process all interfaces and super classes
91
                    put (s);
92
                    put (x.getInterfaces ());
93
                }
94
            }
95
        };
96
        en.put (c);
97
        
98
        return new AlterEnumeration (en) {
99
            protected Object alter (Object clazz) {
100
                Class c2 = (Class)clazz;
101
                return c2.getName ().replace ('.', '/');
102
            }
103
        };
104
    }
105
}
(-)openidex/src/org/openidex/nodes/looks/Look.java (-480 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.ArrayList;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.io.IOException;
20
21
import org.w3c.dom.NodeList;
22
import org.w3c.dom.Element;
23
24
import org.openide.nodes.*;
25
import org.openide.loaders.XMLDataObject;
26
import org.openide.util.actions.SystemAction;
27
import org.openide.util.HelpCtx;
28
import org.openide.util.Lookup;
29
import org.openide.util.datatransfer.NewType;
30
import org.openide.util.datatransfer.PasteType;
31
32
/** Base class for all looks. This class handles basic reading of properties
33
 * from XML description.
34
 * <P>
35
 * Notice the difference between the methods which take the parameter of
36
 * type NodeSubstitute and the methods which don't. The first methods are
37
 * those which implement the functionality of the look. The second are methods 
38
 * which represent properties of the Look itself.
39
 * <P>
40
 *
41
 * @author Petr Hrebejk
42
 */
43
public abstract class Look implements  Node.Cookie, java.io.Serializable {
44
    
45
    /** Use this constant for returning no Actions. */
46
    public static final SystemAction[] NO_SYSTEM_ACTIONS = {};
47
    
48
    /** Use this constant for returning empty NewTypes. */
49
    public static final NewType[] NO_NEW_TYPES = {};
50
    
51
    /** Use this constant for returning empty PasteTypes. */
52
    public static final PasteType[] NO_PASTE_TYPES = {};
53
    
54
    /** Use this constant for returning empty PropertySets. */
55
    public static final Node.PropertySet[] NO_PROPERTY_SETS = {};
56
    
57
    /** Use this constant for returning empty KeySets. */
58
    public static final Object[] NO_KEYS = {};
59
    
60
    /** Name of XML attrubute describing name */
61
    public static final String ATTR_NAME = "name"; // NOI18N
62
    
63
    /** Name of the XML tag for standalone; value="Standalone". */
64
    private static final String TAG_STANDALONE = "Standalone"; // NOI18N
65
    
66
    /** Name of the XML tag for standalone; value="class". */
67
    private static final String ATTR_CLASS = "class"; // NOI18N
68
    
69
    /** Name of the look */
70
    private String name;
71
    
72
    /** The XML data object for the look */
73
    protected XMLDataObject lookDataObject;
74
    
75
    /** Classes for which this look is standalone */
76
    ArrayList standaloneClasses;
77
    
78
    
79
    // Methods of look itself --------------------------------------------------
80
81
    /** Returns name of the look.
82
     * @return Name of the look.
83
     */
84
    public String getName() {
85
        return name;
86
    }
87
    
88
    /** Sets name of the Look
89
     * @param name Name of the look.
90
     */
91
    public void setName( String name ) {
92
        this.name = name;
93
    }
94
    
95
    /** Determines whether the Look can be used as standalone Look for given node.
96
     * E.g. Should be an item in the list of possible looks for the node.
97
     * The default implementation works with the information gathered from the
98
     * XML data object - tag <CODE>Standalone</CODE>.
99
     * @param object Object represented by the node.
100
     * @return <code>true</code> if user should be allowed to switch to this look on given node.
101
     */
102
    public boolean isLookStandalone( Object representedObject ) {
103
        
104
        if ( standaloneClasses == null ) {
105
            // We have to prepare the list
106
            if ( lookDataObject == null ) {
107
                standaloneClasses = new ArrayList( 0 );
108
            }
109
            else {
110
                try {
111
                    Element de = lookDataObject.getDocument().getDocumentElement();
112
                    NodeList standaloneTags = de.getElementsByTagName( TAG_STANDALONE );
113
                    standaloneClasses = new ArrayList( standaloneTags.getLength() );
114
115
                    for( int i = 0; i < standaloneTags.getLength(); i++ ) {
116
                        if ( standaloneTags.item( i ).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE ) {
117
                            continue;
118
                        }
119
                        Element e = (Element)standaloneTags.item( i );
120
                        String className = e.getAttribute( ATTR_CLASS );
121
                        ClassLoader l = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class);
122
                        standaloneClasses.add( Class.forName( className, true, l) );
123
                    }
124
                }
125
                catch ( java.io.IOException e  ) {
126
                    System.out.println( name + e );
127
                    return false;
128
                }
129
                catch ( ClassNotFoundException e  ) {
130
                    System.out.println( name + e );
131
                    return false;
132
                }
133
                catch ( org.xml.sax.SAXException e  ) {
134
                    System.out.println( name + e );
135
                    return false;
136
                }
137
            }
138
        }
139
        
140
        for ( int i = 0; i < standaloneClasses.size(); i++ ) {
141
            if ( ((Class)standaloneClasses.get( i )).isInstance ( representedObject ) ) {
142
                return true;
143
            }
144
        }
145
        
146
        return false;
147
    }
148
    
149
    /** Reads the Look options from the XMLDataObject. If you override this 
150
     * method you'll probably want to call super.readPropertiesFromXML( xdo );
151
     * Implementation of the method in the Look class handles the look name
152
     * tag and the tags standalone.
153
     * @param xdo The <CODE>XMLDataObject</CODE> which contains configuration of
154
     * the look.
155
     */
156
    public void readPropertiesFromXML( XMLDataObject xdo ) {
157
        lookDataObject = xdo;
158
        String xdoName = xdo.getName();
159
        int nameIndex = xdoName.indexOf('$');
160
        setName( xdoName.substring( nameIndex + 1 ) );
161
    }
162
    
163
    // General methods ---------------------------------------------------------
164
    
165
    /** 
166
     * Called on the current look when node is newly created or the look is
167
     * set on the Node. Overriding this 
168
     * method allows to register listners on represented objects and asociate
169
     * them with the node.
170
     * <p>
171
     * Implementors may not wait for any other threads at it may be potentially called
172
     * from LookNode's lock.
173
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the which was created.
174
     */ 
175
    public abstract void attachTo( Look.NodeSubstitute substitute );
176
    
177
    /** Get additional cookie for the node. This method should be used to return
178
     * cookies from represented object.
179
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
180
     * @param type the representation class of the cookie
181
     * @return  a cookie assignable to that class, or <code>null</code> if this 
182
     *          node has no such cookie
183
     */
184
    public abstract Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type);
185
    
186
    /** Obtain handle for this node (for serialization).
187
     * The handle can be serialized and {@link Handle#getNode} used after
188
     * deserialization to obtain the original node.
189
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
190
     * @return the handle, or <code>null</code> if this node is not persistable. 
191
     */
192
    public abstract Node.Handle getHandle( Look.NodeSubstitute substitute );
193
    
194
    // Methods for STYLE -------------------------------------------------------
195
    
196
    /** Gets localized name of given Node. This name will be showed in the 
197
     * visual representation of the node. 
198
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
199
     * @return Localized name of the node. Implementation of {@link LookNode} 
200
     *         defaults this to the programmatic name of the node.
201
     */
202
    public abstract String getDisplayName( Look.NodeSubstitute substitute );
203
    
204
    /** Gets the progammatic name of given node. This name can be used for 
205
     * operations on node paths in the node hierarchy and thus shouldn't be
206
     * localized.
207
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
208
     * @return Programmatic name of the node. 
209
     */
210
    public abstract String getName( Look.NodeSubstitute substitute );
211
    
212
    /** This method is clalled when the user renames the node using inplace
213
     * editing in the view.
214
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the renamed node.
215
     * @param newName The new name set by the user.
216
     */
217
    public abstract void setName( Look.NodeSubstitute substitute, String newName );
218
    
219
    /** Gets short description of given node. The short description is usually
220
     * visualized as a tooltip, but may have another forms as well.
221
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
222
     * @return A localized short description associated with the node. 
223
     *         Implementation of {@link LookNode} defaults this to display name 
224
     *         of the node.
225
     */
226
    public abstract String getShortDescription( Look.NodeSubstitute substitute );
227
    
228
    /** Find an icon for this node (in the closed state).
229
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
230
     * @param type Constant from {@link java.beans.BeanInfo}
231
     * @return Icon to use to represent the node in the closed state. 
232
     *         Implementation of {@link LookNode} provides default icon for nodes.
233
     */
234
    public abstract Image getIcon( Look.NodeSubstitute substitute, int type );
235
    
236
    /** Find an icon for this node (in the open state).
237
     * This icon is used when the node may have children and is expanded.
238
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
239
     * @param type Constant from {@link java.beans.BeanInfo}
240
     * @return Icon to use to represent the node in the open state. 
241
     *        Implementation of {@link LookNode} defaults this to the closed
242
     *        state icon.
243
     */
244
    public abstract Image getOpenedIcon( Look.NodeSubstitute substitute, int type );
245
    
246
    /** Get context help associated with this node.
247
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
248
     * @return The context help object (could be <code>null</code> or 
249
     *         {@link HelpCtx#DEFAULT_HELP}) 
250
     */
251
    public abstract HelpCtx getHelpCtx( Look.NodeSubstitute substitute );
252
    
253
    // Methods for CHILDREN ----------------------------------------------------
254
    
255
    /** Gets objects which are children of object represented by the node in the
256
     * hierarchy represented by this Look.
257
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
258
     * @return Array of objects which should be represend as node children of 
259
     *         the node.  
260
     */
261
    public abstract Object[] getChildObjects( Look.NodeSubstitute substitute );
262
    
263
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
264
    
265
    /** Get the new types that can be created in given node.
266
     * For example, a node representing a Java package will permit classes to 
267
     * be added.
268
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
269
     * @return Array of new type operations that are allowed. 
270
     */
271
    public abstract NewType[] getNewTypes( Look.NodeSubstitute substitute );
272
    
273
    /** Get the set of actions associated with the node.
274
     * This may be used e.g. in constructing a {@link #getContextMenu context menu}.
275
     * <P>
276
     * If the look returns null, the implementation {@ling LookNode} returns 
277
     * the actions in {@link NodeOp#getDefaultActions} obtained by the super call.
278
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
279
     * @return Array of the Actions applicable to the node or <CODE>null</CODE>
280
     *         if actions in {@link NodeOp#getDefaultActions} should be used.
281
     */
282
    public abstract SystemAction[] getActions( Look.NodeSubstitute substitute );
283
    
284
    /** Get a special set of actions for situations when this node is displayed 
285
     * as a context.
286
     * @see org.openide.nodes.Node#getContextActions For more detailed description.
287
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the The node to operate on.
288
     * @return Actions for a context. In the LookNode implementation, 
289
     *        same as {@link #getActions}.
290
     * 
291
     */
292
    public abstract SystemAction[] getContextActions( Look.NodeSubstitute substitute );
293
    
294
    /** Get the default action for this node.
295
     * This action can but need not be one from the list returned
296
     * from {@link #getActions}. If so, the popup menu returned from 
297
     * {@link #getContextMenu} is encouraged to highlight the action.
298
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
299
     * @return Default action, or <code>null</code> if there should be none.
300
     */
301
    public abstract SystemAction getDefaultAction( Look.NodeSubstitute substitute );
302
    
303
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
304
    
305
    /** Get the list of property sets for given node. E.g. typically there 
306
     * may be one for normal Bean properties, one for expert
307
     * properties, and one for hidden properties.
308
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the The node to operate on.
309
     * @return Property sets for the node.
310
     */
311
    public abstract Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute );
312
    
313
    /** Get the customizer for represented object if available.
314
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
315
     * @return The component, or <CODE>null</CODE> if there is no customizer. 
316
     */
317
    public abstract java.awt.Component getCustomizer( Look.NodeSubstitute substitute );
318
    
319
    /**
320
     * Test whether there is a customizer for this node. If true,
321
     * the customizer can be obtained via {@link #getCustomizer}.
322
     * @return <CODE>true</CODE> if there is a customizer
323
     *
324
     * <!--It is a big performace gain when reasonably rewritten.-->
325
     */
326
    public boolean hasCustomizer (Look.NodeSubstitute substitute) {        
327
        return getCustomizer(substitute) != null;
328
    }
329
    
330
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
331
    
332
    /** Test whether this node can be renamed.
333
     * If true, {@link #setName} will be called when the user changes the name
334
     * of the node.
335
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
336
     * @return <code>true</code> if the node can be renamed.
337
     */
338
    public abstract boolean canRename( Look.NodeSubstitute substitute );
339
    
340
    /** Test whether this node can be deleted.
341
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
342
     * @return <CODE>True</CODE> if can be deleted.
343
     */
344
    public abstract boolean canDestroy( Look.NodeSubstitute substitute );
345
    
346
    /** Test whether this node permits copying.
347
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
348
     * @return <code>True</code> if so.
349
     */
350
    public abstract boolean canCopy( Look.NodeSubstitute substitute );
351
    
352
    /** Test whether this node permits cutting.
353
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
354
     * @return <code>True</code> if so.
355
     */
356
    public abstract boolean canCut( Look.NodeSubstitute substitute );
357
    
358
    /** Determine which paste operations are allowed when a given 
359
     * transferable is in the clipboard. For example, a node representing a 
360
     * Java package will permit classes to be pasted into it.
361
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
362
     * @param t The transferable in the clipboard.
363
     * @return Array of operations that are allowed 
364
     */
365
    public abstract PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t);
366
    
367
    /** Determine if there is a paste operation that can be performed
368
     * on provided transferable. Used by drag'n'drop code to check
369
     * whether the drop is possible.
370
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to operate on.
371
     * @param t The transferable.
372
     * @param action The drag'n'drop action to do DnDConstants.ACTION_MOVE, 
373
     *        ACTION_COPY, ACTION_LINK.
374
     * @param index Index between children the drop occured at or -1 if not specified.
375
     * @return <CODE>Null</CODE> if the transferable cannot be accepted or the paste type
376
     *         to execute when the drop occures.
377
     */
378
    public abstract PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index);
379
    
380
    /** Called when a node is to be copied to the clipboard.
381
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node Copy was invoked on.
382
     * @return The transferable object representing the content of the clipboard.
383
     * @throws IOException When the copy cannot be performed.
384
     */
385
    public abstract Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException;
386
    
387
    /** Called when the node is to be cut to the clipboard.
388
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node to be cutted.
389
     * @return The transferable object representing the content of the clipboard.
390
     * @throws IOException When the copy cannot be performed.
391
     */
392
    public abstract Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException;
393
    
394
    /** Called when a drag is started with this node.
395
     * The node can attach a transfer listener to ExTransferable and
396
     * will be then notified about progress of the drag (accept/reject).
397
     * @param substitute The <CODE>Look.NodeSubstitute</CODE> of the node which was dragged.
398
     * @return Transferable to represent this node during a drag.
399
     * @throws IOException If a drag cannot be started.
400
     */
401
    public abstract Transferable drag( Look.NodeSubstitute substitute ) throws IOException;
402
    
403
    /** Called when node was destroyed.
404
     * @param substitute Look.NodeSubstitute of the destroyed ndoe.
405
     */
406
    public abstract void destroy( Look.NodeSubstitute substitute ) throws IOException;
407
    
408
    // Innerclasses ------------------------------------------------------------
409
    
410
    /** Class passed to the Look methods as parameter. Each LookNode contains 
411
     * exactly one instance of this class. Metods of the class allow access
412
     * to the properties and methods od the node needed for the Look.
413
     */
414
    public static abstract class NodeSubstitute {
415
        
416
        
417
        /** Returns the object represented by the node
418
         * @return Object represented by the node this interior belongs to.
419
         */
420
        abstract public Object getRepresentedObject(); 
421
        
422
        /** Fire a property change event on the associated node.
423
         * @param name name of changed property (from {@link #getPropertySets})
424
         * @param o old value
425
         * @param n new value
426
         */
427
        abstract public void firePropertyChange( String name, Object o, Object n );
428
429
        /** Fires the Event notificationg about name change.
430
         */
431
        abstract public void fireNameChange( String o, String n ); 
432
        
433
        /** Fires the Event notificationg about display name change.
434
         */
435
        abstract public void fireDisplayNameChange( String o, String n );
436
        
437
        /** Fires the Event notificationg about short description change.
438
         */
439
        abstract public void fireShortDescriptionChange(String o, String n); 
440
441
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
442
         * associated node.
443
         */
444
        abstract public void fireIconChange();
445
446
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
447
         * associated node.
448
         */
449
        abstract public void fireOpenedIconChange(); 
450
451
        /** Fires a (Bean) property change event (for 
452
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
453
         * @param o the old set
454
         * @param n the new set
455
         */
456
        abstract public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n );
457
       
458
        /** Fires a change event for {@link org.openode.nodes.Node#PROP_COOKIE}.
459
         * The old and new values are set to null.
460
         */
461
        abstract public void fireCookieChange(); 
462
463
        /** To all node listeners fire node destroyed notification.
464
         */
465
        abstract public void fireNodeDestroyed();
466
467
        /** Tells the node that the children have to be refreshed.
468
         */
469
        abstract public void refreshChildren(); 
470
        
471
        /** Allowes to store Cookies for given node. This method might be
472
         * replaced by getLookup later.
473
         * @return CookieSet for this NodeSubstitute.
474
         */
475
        abstract public CookieSet getCookieSet(); 
476
        
477
    }
478
    
479
    
480
}
(-)openidex/src/org/openidex/nodes/looks/LookChildren.java (-77 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.*;
17
18
import org.openide.nodes.Children;
19
import org.openide.nodes.*;
20
21
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
22
 * Please don't use this API for other purposes than testing.
23
 * <P>
24
 * Temporary implementation of Children of a LookNode. The class contains
25
 * only code wich is necessary for testing looks and may be extended later.
26
 *
27
 * @author Petr Hrebejk
28
 */
29
class LookChildren extends Children.Keys {
30
    
31
    void refreshChildren( ) {            
32
        setKeys( getKeys() );
33
    }
34
    
35
    protected void addNotify() {
36
        setKeys( getKeys() );
37
    }
38
    
39
    protected void removeNotify() {
40
        setKeys( Collections.EMPTY_LIST );
41
    }
42
    
43
    protected Node[] createNodes( Object key ) {
44
        
45
        Look look = (Look)getNode().getCookie( Look.class );
46
        
47
        if ( key == null ) {
48
            return new Node[0];
49
//        } else if (key instanceof LookNode) {
50
//            return new Node[] {new FilterNode((Node)key)};  // ??? what if it has to derive look from parent?
51
        }
52
        else {
53
            LookNode node = new LookNode( key );
54
            look.attachTo( node.getSubstitute() );
55
            return new Node[] { node };
56
        }
57
               
58
    }
59
    
60
    
61
    // Private methods ---------------------------------------------------------
62
    
63
    private Object[] getKeys() {
64
        
65
        Look look = (Look)getNode().getCookie( Look.class );
66
67
        Object[] keys = look.getChildObjects( ((LookNode)getNode()).getSubstitute() );
68
        if ( keys == null ) {
69
            return new Object [0];
70
        }
71
        else {
72
            return keys;
73
        }
74
        
75
    }
76
        
77
}
(-)openidex/src/org/openidex/nodes/looks/LookEnvironmentProvider.java (-229 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import org.w3c.dom.*;
17
18
import org.openide.cookies.InstanceCookie;
19
import org.openide.loaders.XMLDataObject;
20
import org.openide.loaders.DataObject;
21
import org.openide.loaders.Environment;
22
import org.openide.util.Lookup;
23
import org.openide.util.lookup.AbstractLookup;
24
import org.openide.util.lookup.InstanceContent;
25
import org.openide.nodes.BeanNode;
26
27
import org.openidex.nodes.looks.Look;
28
29
/** Class which allowes to store the Looks into the XML layer.
30
 *
31
 * @author Petr Hrebejk
32
 */
33
public class LookEnvironmentProvider implements Environment.Provider {
34
35
    /** DataObject for given look */
36
    private DataObject dobj;
37
    private AbstractLookup lookup;
38
    
39
    /** Charater used to delimit the Look name and the look class in
40
     * the name of the XML file describing the Look; value = '$'.
41
     */
42
    public static final char NAME_DELIMITER = '$'; // NOI18N
43
    
44
    /** Charater used to delimit the package names  in
45
     * the name of the XML file describing the Look; value = '-'.
46
     */
47
    public static final char PACKAGE_DELIMITER = '-'; // NOI18N
48
    
49
    /** Class name delimiter */
50
    private static final char DOT = '.'; //NOI18N
51
    
52
    /** The node convertor */
53
    private static NodeConvertor nodeConvertor = new NodeConvertor();
54
    
55
    // Implementation of EnvronmentProvider ------------------------------------
56
    
57
    /** Returns a lookup that represents environment.
58
     * @return the lookup
59
     */
60
    public Lookup getEnvironment(DataObject obj) {
61
        dobj = obj;
62
        
63
        InstanceContent ic = new InstanceContent();
64
        lookup = new AbstractLookup( ic );
65
        LookInstanceCookie lic;
66
        
67
        ic.add( lic = new LookInstanceCookie( dobj ) );
68
        
69
        ic.add( lic, nodeConvertor );
70
        
71
        return lookup;
72
    }
73
    
74
    // Innerclasses ------------------------------------------------------------
75
    
76
    /** Class for postponing creation of the Look node */
77
    public  static class NodeConvertor implements InstanceContent.Convertor {
78
        
79
        /** Convert obj to other object. There is no need to implement
80
         * cache mechanism. It is provided by InstanceLookup.Item.getInstance().
81
         * Method should be called more than once because Lookup holds
82
         * just weak reference.
83
         *
84
         * @param obj the registered object
85
         * @return the object converted from this object
86
         */
87
        public Object convert(Object obj) {
88
            try {
89
                BeanNode bn = new BeanNode( ((LookInstanceCookie)obj).instanceCreate() );
90
                bn.setName( ((LookInstanceCookie)obj).instanceName() );
91
                bn.setIconBase( "org/openidex/nodes/looks/resources/Look" ); // NOI18N
92
                return bn;
93
            }
94
            catch ( java.io.IOException e ) {
95
                return null;
96
            }
97
            catch ( ClassNotFoundException e ) {
98
                return null;
99
            }
100
            catch ( java.beans.IntrospectionException e ) {
101
                return null;
102
            }
103
        }        
104
        
105
        /** Computes the ID of the resulted object.
106
         * @param obj the registered object
107
         * @return the ID for the object
108
         */
109
        public String id(Object obj) {
110
            return ((LookInstanceCookie)obj).instanceName();
111
        }        
112
        
113
        /** Return type of converted object.
114
         * @param obj the registered object
115
         * @return the class that will be produced from this object (class or
116
         *     superclass of convert (obj))
117
         */
118
        public Class type(Object obj) {
119
            return BeanNode.class;
120
        }
121
        
122
        /** The human presentable name for the object.
123
         * @param obj the registered object
124
         * @return the name representing the object for the user
125
         */
126
        public String displayName(Object obj) {
127
            return ((LookInstanceCookie)obj).instanceName();
128
        }
129
        
130
    }
131
    
132
    
133
    /** InstanceCookie for creation of Instances of the Look
134
     */
135
    private class LookInstanceCookie implements InstanceCookie {
136
    
137
        /** DataObject where the Look is created from */
138
        private DataObject dobj;
139
        
140
        private String lookName;
141
        
142
        // Holds the look when already created
143
        private Look look;
144
        
145
        /** Creates new LookInstanceCookie for given data object
146
         */
147
        LookInstanceCookie( DataObject dobj ) {
148
            this.dobj = dobj;
149
        }
150
        
151
        /** The name of {@link #instanceClass}.
152
         * @return the instance class name
153
         */
154
        public String instanceName() {
155
            return getLookName();
156
        }
157
158
        /** Create an instance.
159
         * @return the instance of type {@link #instanceClass} (or a subclass)
160
         * @exception IOException if an I/O error occured
161
         * @exception ClassNotFoundException if a class was not found
162
         */
163
        public Object instanceCreate() throws java.io.IOException, ClassNotFoundException {
164
            Class clazz = instanceClass();
165
        
166
            if ( look == null ) {
167
                try {
168
                    java.lang.reflect.Constructor constructor = clazz.getConstructor( new Class[] {} );
169
                    look = (Look)constructor.newInstance( new Object[] {} );
170
                    //System.out.println("Creating instance" + dobj.getName() ); // NOI18N
171
                    look.readPropertiesFromXML( (XMLDataObject)dobj );
172
                    //return look;
173
                }
174
                catch (  InstantiationException e  ) {
175
                    throw new ClassNotFoundException( e.toString() );
176
                }
177
                catch (  IllegalAccessException e  ) {
178
                    throw new ClassNotFoundException( e.toString() );
179
                }
180
                catch (  NoSuchMethodException e  ) {
181
                    throw new ClassNotFoundException( e.toString() );
182
                }
183
                catch (  java.lang.reflect.InvocationTargetException  e  ) {
184
                    throw new ClassNotFoundException( e.toString() );
185
                }
186
            }
187
            return look;
188
        }
189
190
        /** The representation type that may be created as instances.
191
         * Can be used to test whether the instance is of an appropriate
192
         * class without actually creating it.
193
         *
194
         * @return the representation class of the instance
195
         * @exception IOException if an I/O error occurred
196
         * @exception ClassNotFoundException if a class was not found
197
         */
198
        public Class instanceClass() throws java.io.IOException, ClassNotFoundException {
199
            return getLookClass();
200
        }
201
        
202
        // Private Methods ---------------------------------------------------------
203
    
204
        /** Returns the class of the instance, based on name of the file
205
         */
206
        private Class getLookClass() throws ClassNotFoundException {
207
208
            String objName = dobj.getName();
209
            int nameIndex = objName.indexOf( NAME_DELIMITER );
210
            String className = nameIndex == -1 ? 
211
                objName.replace( PACKAGE_DELIMITER, DOT ) :
212
                objName.substring(0, nameIndex ).replace( PACKAGE_DELIMITER, DOT );
213
            ClassLoader l = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class);
214
            return Class.forName( className, false, l);
215
        }
216
217
        /** Returns the look name 
218
         */
219
        private String getLookName() {
220
221
            if ( lookName == null ) {
222
                String objName = dobj.getName();
223
                int nameIndex = objName.indexOf( NAME_DELIMITER );
224
                lookName = objName.substring( nameIndex + 1 );
225
            }
226
            return lookName;
227
        }   
228
    }
229
}
(-)openidex/src/org/openidex/nodes/looks/LookNode.java (-593 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.beans.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.io.IOException;
20
import javax.swing.event.ChangeListener;
21
import javax.swing.event.ChangeEvent;
22
23
import org.openide.nodes.*;
24
25
import org.openide.util.HelpCtx;
26
import org.openide.util.Utilities;
27
import org.openide.util.actions.SystemAction;
28
import org.openide.util.datatransfer.NewType;
29
import org.openide.util.datatransfer.PasteType;
30
31
32
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
33
 * Please don't use this API for other purposes than testing.
34
 * <P>
35
 * Node which can be used with Looks.
36
 *
37
 * @author Petr Hrebejk
38
 */
39
public final class LookNode extends Node implements Node.Cookie {
40
41
    /** Default Icon 16x16 */
42
    private static Image DEFAULT_ICON_16;
43
    
44
    /** Default Icon 32x32 */
45
    private static Image DEFAULT_ICON_32;
46
    
47
    /** Name of the default icon 16x16 */
48
    private static final String DEFAULT_ICON_16_NAME = 
49
        "org/openidex/nodes/looks/resources/defaultNode.gif"; // NOI18N
50
51
    /** Name of the default icon 32x32 */
52
    private static final String DEFAULT_ICON_32_NAME = 
53
        "org/openidex/nodes/looks/resources/defaultNode32.gif"; //NOI18N
54
    
55
    /** Object represented (delegeted) by interior */
56
    private SubstituteImpl substitute = null;
57
    
58
    // it is our private lock guarding look and lookCandidate fields
59
    private final String lock = "LookNode.lock";
60
    
61
    /** Look <b>set and attached</b> on this node or null if derived. */
62
    private Look look = null;
63
64
    // A look prepared for attaching (to become a hard look). It is used if it is added as a child of
65
    // a node that is not instance of LookNode and therefore actual look cannot
66
    // be derived from the new parent node look.
67
    private Look lookCandidate = null;
68
    
69
    /** CookieSet for this node */
70
    private CookieSet cookieSet = null;
71
    
72
    /** Creates new LookNode.
73
     * @param representedObject The object which the node will represent.
74
     */
75
    public LookNode( Object representedObject ) {
76
        this( representedObject, null );
77
    }
78
    
79
    /** Creates new LookNode.
80
     * @param representedObject The object which the node will represent.
81
     * @param look explicit look that will be set
82
     */
83
    public LookNode( Object representedObject, Look look ) {
84
        super( new LookChildren( ) );
85
        // Create the interior
86
        substitute = new SubstituteImpl(representedObject);
87
        // set hard look (or null)
88
        this.look = look;
89
        if (look != null) look.attachTo(substitute);
90
    }
91
92
    
93
    // Additional methods for LookNode -----------------------------------------
94
       
95
    /** Used to get Substitute of this LookNode
96
     * @return NodeSubstitute
97
     */
98
    Look.NodeSubstitute getSubstitute(){
99
        return substitute;
100
    }
101
    
102
    /** Returns represented object which this LookNode represents.
103
     * @return The object represented by this node.
104
     */
105
    public Object getRepresentedObject() {
106
        return substitute.getRepresentedObject();
107
    }
108
    
109
    /** Sets look for this node. After changing the Look several property
110
     * changes are fired:
111
     * <CODE>PROP_COOKIE, PROP_NAME, PROP_NAME, PROP_DISPLAY_NAME, PROP_ICON,
112
     * PROP_OPENED_ICON</CODE> and children are refresehed.
113
     * @look New look of the node.
114
     */
115
    public void setLook( Look look ) {        
116
        
117
        this.lookCandidate = look;
118
        this.look = look; // make it hard look immediatelly            
119
        getLook().attachTo( getSubstitute( ) );  
120
        
121
        // fire possible change notifications
122
        
123
        fireCookieChange();
124
        refreshChildren();
125
        fireNameChange( null, null );
126
        fireDisplayNameChange( null, null );
127
        fireIconChange();
128
        fireOpenedIconChange();
129
    }
130
131
    /** Returns cookie set on this node
132
     */
133
    private CookieSet getCookieSet() {
134
        CookieSet cs = cookieSet;
135
        if (cs != null) { 
136
            return cs;
137
        }
138
        
139
        synchronized (this) {
140
            if (cookieSet != null) {
141
                return cookieSet;
142
            }
143
144
            // sets empty sheet and adds a listener to it
145
            cookieSet = new CookieSet();
146
            cookieSet.addChangeListener( new ChangeListener() { 
147
                    public void stateChanged (ChangeEvent ev) {
148
                        LookNode.this.fireCookieChange ();
149
                    }
150
                } ); 
151
            return cookieSet;
152
        }
153
    }
154
    
155
    /** Refreshes children on the node */
156
    void refreshChildren() {
157
        ((LookChildren)getChildren()).refreshChildren();
158
    }
159
        
160
    // General methods ---------------------------------------------------------
161
    
162
    /** 
163
     * Gets look set on this node. 
164
     * @return Look set on this Node. Or Look set on the nearest parent Node of
165
     * this Node with some Look set. If no such node exists this method returns
166
     * (i.e. this is a root node or some of the parent nodes is not a LookNode)
167
     * {@link DefaultLook#INSTANCE} unless the node represents a cloned <code>LookNode</code>. 
168
     * In such case a look of original is returned instead.
169
     * 
170
     */
171
    public Look getLook() {
172
        
173
        // do we have a hard set look
174
175
        if ( look != null ) return look;
176
177
        // get parent or candidate look (while making it hard look)
178
179
        Node parentNode = getParentNode();
180
181
        if ( parentNode == null || (parentNode instanceof LookNode) == false ) {
182
183
            // If it is a LookNode clone then use original look as a look cannot 
184
            // be derived from parent node otherwise use DefaultLook
185
186
            if (lookCandidate != null) {
187
                look = lookCandidate;
188
                look.attachTo(substitute);
189
                return look;
190
            } else {
191
                return DefaultLook.INSTANCE;
192
            }
193
194
        } else {
195
            // softly "set" look
196
            return ((LookNode)parentNode).getLook();
197
        }
198
        
199
    }
200
201
    /**
202
     * @return Look that is set hardly or <code>null</code> if look will be get from parents
203
     * of hard look candidate.
204
     */
205
    final Look getHardLook() {
206
//        synchronized (lock) {  // no sync neccessary IMO
207
            return look;
208
//        }
209
    }
210
    
211
    /** Gets Cookie of given type. The set of Cookies is determined by the
212
     * Look. Look of the node can allways be asked using <CODE>getCookie( 
213
     * Look.class )</CODE> and the LookNode self can be asked by 
214
     * <CODE>getCookie( LookNode.class )</CODE>.
215
     * @param type the representation class of the cookie
216
     * @return a cookie assignable to that class, or <code>null</code> 
217
     * the Look does not provide such cookie.
218
     */
219
    public Node.Cookie getCookie( Class type ) {
220
        if ( type == Look.class ) {
221
            // Look is available in cookies
222
            return getLook();
223
        }
224
        else if ( type == LookNode.class ) {
225
            return this;
226
        }
227
        else {            
228
            Node.Cookie cookie = getCookieSet().getCookie( type );
229
            
230
            if ( cookie == null ) {
231
                // Ask the Looks for additional cookies
232
                return getLook().getCookie( substitute, type );
233
            }
234
            else {
235
                // Return found cookie
236
                return cookie;
237
            }
238
        }
239
    }
240
241
    /** Determines Handle by querying the Look.
242
     * @return the handle, or <code>null</code> if this node is not persistable
243
     */
244
    public Node.Handle getHandle() {
245
        return getLook().getHandle( substitute );
246
    }
247
    
248
    /** 
249
     * Returns a node representing the same object as the original node. The Look
250
     * of the original node becomes look candidate.
251
     *
252
     * @return LookNode representing the same object.
253
     */
254
    public Node cloneNode () {
255
        
256
        LookNode clone = new LookNode( getRepresentedObject() );
257
        clone.lookCandidate = look != null ? look : lookCandidate;  // survive double cloning
258
        
259
//        new RuntimeException("LookNode " + this + " cloned to " + clone + ".").printStackTrace();
260
        return clone;
261
    }
262
263
    
264
    // Methods for STYLE -------------------------------------------------------
265
    
266
    /** Determines displayName by querying the Look.
267
     * @return DisplayName provided by the Look or result 
268
     * of {@link #getName()}.
269
     */
270
    public String getDisplayName() {
271
        String displayName = getLook().getDisplayName( substitute );
272
        
273
        if ( displayName == null ) {
274
            return getName();
275
        }
276
        else 
277
            return displayName;
278
    }
279
    
280
    /** Empty method, setting <CODE>displayName</CODE> on the 
281
     * <CODE>LookNode</CODE> has no efect. The <CODE>displayName</CODE> should
282
     * be determined by associated <CODE>Look</CODE>.
283
     * @param name Parameter is ignored. 
284
     */
285
    public void setDisplayName( String name ) {
286
    }
287
    
288
    /** Determines name by querying the Look.
289
     * @return Name provided by the Look or <CODE>null</CODE>.
290
     */
291
    public String getName() {
292
        return getLook().getName( substitute );
293
    }
294
    
295
    /** Invoking this method on LookNode invokes method {@link Look#setName( 
296
     * Look.NodeSubstitute, String )}. Look is responsible for handling the call.
297
     */
298
    public void setName( String s ) {
299
        getLook().setName( substitute, s );
300
    }
301
    
302
    /** Empty method, setting <CODE>shortDescription</CODE> on the 
303
     * <CODE>LookNode</CODE> has no efect. The <CODE>shortDescription</CODE> 
304
     * should be determined by associated <CODE>Look</CODE>.
305
     * @param shortDescription Parameter is ignored.
306
     */
307
    public void setShortDescription( String shortDescription ) {
308
    }
309
    
310
    /** Determines shortDescription by querying the Look.
311
     * @return Name provided by the Look or result of {@link getDisplayName()}.
312
     */
313
    public String getShortDescription() {
314
        String shortDescription = getLook().getShortDescription( substitute );
315
        if ( shortDescription == null ) {
316
            return getDisplayName();
317
        }
318
        else {
319
            return shortDescription;
320
        }
321
    }
322
    
323
    /** Determines icon for closed state by querying the Look.
324
     * @return Icon provided by the Look or the icon which can be found on:
325
     * org/netbeans/modules/freestyle/nodes/resources/defaultNode(32).gif
326
     */
327
    public Image getIcon( int type ) {
328
        Image icon = getLook().getIcon( substitute, type );
329
        
330
        if ( icon == null ) {
331
            if ( type == BeanInfo.ICON_COLOR_32x32 || type == BeanInfo.ICON_MONO_32x32 ) {
332
                if ( DEFAULT_ICON_32 == null ) {
333
                    DEFAULT_ICON_32 = Utilities.loadImage( DEFAULT_ICON_32_NAME );
334
                }
335
                return DEFAULT_ICON_32;
336
            }
337
            if ( DEFAULT_ICON_16 == null ) {
338
                DEFAULT_ICON_16 = Utilities.loadImage( DEFAULT_ICON_16_NAME );
339
            }
340
            return DEFAULT_ICON_16;
341
        }
342
        else {
343
            return icon;
344
        }
345
    }
346
    
347
    /** Determines icon for opened state by querying the Look.
348
     * @return Icon provided by the Look or the result of
349
     * {@link getIcon()}.
350
     */
351
    public Image getOpenedIcon( int type ) {
352
        Image icon = getLook().getOpenedIcon( substitute, type );
353
        
354
        if ( icon == null ) {
355
            return getIcon( type );
356
        }
357
        else {
358
            return icon;
359
        }
360
    }
361
    
362
    /** Determines HelpCtx for opened state by querying the Look.
363
     * @return HelpCtx provided by the Look.
364
     */
365
    public HelpCtx getHelpCtx () {
366
        return getLook().getHelpCtx( substitute );
367
    }
368
    
369
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
370
    
371
    /** Determines NewTypes for opened state by querying the Look.
372
     * @return NewTypes provided by the Look.
373
     */
374
    public NewType[] getNewTypes() {
375
        return getLook().getNewTypes( substitute );
376
    }
377
    
378
    public SystemAction[] getActions() {
379
        SystemAction[] systemActions = getLook().getActions( substitute ); 
380
        SystemAction[] mergedActions;
381
 
382
        if ( systemActions == null ) {
383
         systemActions = super.getActions();
384
        }
385
        
386
        int actlen = systemActions.length;
387
        mergedActions = new SystemAction[actlen + 2];
388
        System.arraycopy( systemActions, 0, mergedActions, 0, actlen );
389
        SystemAction sla = LookProperties.getSetLookAction( this );
390
        
391
        System.arraycopy( new SystemAction[]{
392
         null,
393
         sla
394
        }, 0, mergedActions, actlen, 2 );
395
        return mergedActions;
396
397
    }
398
    
399
    public SystemAction[] getContextActions() {
400
        return getLook().getContextActions( substitute );
401
    }
402
    
403
    public SystemAction getDefaultAction() {
404
        return getLook().getDefaultAction( substitute );
405
    }
406
    
407
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
408
    
409
    public Node.PropertySet[] getPropertySets() {
410
        Node.PropertySet[] sets = getLook().getPropertySets( substitute );
411
        
412
        Node.PropertySet[] all = new Node.PropertySet[ sets.length + 1 ];
413
        System.arraycopy( sets, 0, all, 0, sets.length );
414
         
415
        Sheet.Set set = LookProperties.getLookPropertySet( this );
416
		/*
417
        set.setName( LookProperties.LOOK_SHEET_SET_NAME );
418
        set.setDisplayName( LookProperties.LOOK_SHEET_SET_NAME );
419
        set.put( new LookProperties.LookProperty( this ) ); 
420
        */
421
422
        all[ all.length - 1] = set;
423
         
424
        return all;
425
    }
426
    
427
    public java.awt.Component getCustomizer() {
428
        return getLook().getCustomizer( substitute );
429
    }
430
    
431
    public boolean hasCustomizer () {
432
        return getLook().hasCustomizer( substitute );
433
    }
434
    
435
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
436
     
437
    public boolean canRename() {
438
        return getLook().canRename( substitute );
439
    }
440
    
441
    public boolean canDestroy() {
442
        return getLook().canDestroy( substitute );
443
    }
444
    
445
    public boolean canCopy() {
446
        return getLook().canCopy( substitute );
447
    }
448
    
449
    public boolean canCut() {
450
        return getLook().canCut( substitute );
451
    }
452
    
453
    public PasteType[] getPasteTypes( Transferable t) {
454
        return getLook().getPasteTypes( substitute, t );
455
    }
456
    
457
    public PasteType getDropType( Transferable t, int action, int index) {
458
        return getLook().getDropType( substitute, t, action, index );
459
    }
460
    
461
    public Transferable clipboardCopy() throws IOException {
462
        return getLook().clipboardCopy( substitute );
463
    }
464
    
465
    public Transferable clipboardCut() throws IOException {
466
        return getLook().clipboardCut( substitute );
467
    }
468
    
469
    public Transferable drag() throws IOException {
470
        return getLook().drag( substitute );
471
    }
472
    
473
    public void destroy () throws IOException {
474
        getLook().destroy( substitute );
475
        super.destroy();
476
    }
477
478
    boolean hasLookNodeParent() {
479
        Node parent = getParentNode();
480
        return parent != null && parent instanceof LookNode;
481
    }
482
    
483
    // Interior innerclass -----------------------------------------------------
484
    
485
    /** Class passed to the Look methods as parameter. Each LookNode contains 
486
     * exactly one instance of this class. Metods of the class allow access
487
     * to the properties and methods od the node needed for the Look.
488
     */
489
    class SubstituteImpl extends Look.NodeSubstitute {
490
        
491
        private Object representedObject;
492
        
493
        private CookieSet cookieSet;  // a cache
494
        
495
        
496
        /** The constructor of the interior is private to prevent other classes
497
         * then LookNode and Look from firing events on the node
498
         */
499
        private SubstituteImpl(Object representedObject ){
500
            this.representedObject = representedObject;
501
        }
502
       
503
        
504
        /** Returns the object represented by the node
505
         * @return Object represented by the node this interior belongs to.
506
         */
507
        public Object getRepresentedObject(){
508
            return representedObject;
509
        }
510
        
511
        /** Fire a property change event on the associated node.
512
         * @param name name of changed property (from {@link #getPropertySets})
513
         * @param o old value
514
         * @param n new value
515
         */
516
        public final void firePropertyChange( String name, Object o, Object n ) {
517
            LookNode.this.firePropertyChange( name, o, n );
518
        }
519
520
        /** Fires the Event notificationg about name change.
521
         */
522
        public final void fireNameChange( String o, String n ) {
523
            LookNode.this.fireNameChange( o, n );
524
        }
525
526
        /** Fires the Event notificationg about display name change.
527
         */
528
        public final void fireDisplayNameChange( String o, String n ) {
529
            LookNode.this.fireDisplayNameChange( o, n );
530
        }
531
532
        /** Fires the Event notificationg about short description change.
533
         */
534
        public final void fireShortDescriptionChange(String o, String n) {
535
            LookNode.this.fireShortDescriptionChange( o, n );
536
        }
537
538
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_ICON} on
539
         * associated node.
540
         */
541
        public final void fireIconChange() {
542
            LookNode.this.fireIconChange();
543
        }
544
545
        /** Fire a change event for {@link org.openide.nodes.Node#PROP_OPENED_ICON} on
546
         * associated node.
547
         */
548
        public final void fireOpenedIconChange() {
549
            LookNode.this.fireOpenedIconChange();
550
        }
551
552
        /** Fires a (Bean) property change event (for 
553
         * {@link org.openide.node.Node#PROP_PROPERTY_SETS}).
554
         * @param o the old set
555
         * @param n the new set
556
         */
557
        public final void firePropertySetsChange( PropertySet[] o, PropertySet[] n ) {
558
            LookNode.this.firePropertySetsChange( o, n );
559
        }
560
561
        /** Fires a change event for {@link org.openode.nodes.Node#PROP_COOKIE}.
562
         * The old and new values are set to null.
563
         */
564
        public final void fireCookieChange() {
565
            LookNode.this.fireCookieChange();
566
        }
567
568
        /** To all node listeners fire node destroyed notification.
569
         */
570
        public final void fireNodeDestroyed() {
571
            LookNode.this.fireNodeDestroyed();
572
        }
573
574
        /** Tells the node that the children have to be refreshed.
575
         */
576
        public final void refreshChildren() {
577
            LookNode.this.refreshChildren();
578
        }
579
        
580
        /** Allowes to store Cookies for given node. This method could be
581
         *
582
         */
583
        public CookieSet getCookieSet() {
584
            if ( cookieSet == null ) {
585
                cookieSet = new CookieSet();
586
            }
587
            return cookieSet;
588
        }
589
        
590
    }
591
592
    
593
}
(-)openidex/src/org/openidex/nodes/looks/LookProperties.java (-303 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.*;
17
import java.beans.PropertyEditor;
18
import java.beans.PropertyEditorSupport;
19
import java.awt.event.ActionListener;
20
import java.awt.event.ActionEvent;
21
import javax.swing.JMenuItem;
22
import javax.swing.JMenu;
23
import javax.swing.event.MenuListener;
24
import javax.swing.event.MenuEvent;
25
26
27
import org.openide.nodes.*;
28
import org.openide.util.NbBundle;
29
import org.openide.util.Lookup;
30
import org.openide.util.HelpCtx;
31
import org.openide.util.actions.*;
32
import org.openide.awt.JMenuPlus;
33
import org.openide.awt.Actions;
34
35
36
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
37
 * Please don't use this API for other purposes than testing.
38
 * <P> 
39
 * Utility class for creating a SheetSet for switching looks. 
40
 *
41
 * @author Petr Hrebejk
42
 */
43
class LookProperties extends Object {
44
45
    private static final ResourceBundle bundle = NbBundle.getBundle( LookProperties.class );
46
47
    public static final String LOOK_SHEET_SET_NAME = "Look"; // NOI18N
48
   
49
    /** Name of the default look. I.e. when the look on the node is null*/
50
    private static final String DEFAULT = bundle.getString( "CTL_Default" ); //NOI18N
51
    
52
    public static SystemAction getSetLookAction( LookNode node ) {
53
        SetLookAction setLookAction = (SetLookAction)SystemAction.get( SetLookAction.class );
54
        setLookAction.setLookNode( node );
55
        return setLookAction;
56
    }
57
    
58
    public static Sheet.Set getLookPropertySet( LookNode node ) {
59
        
60
        Sheet.Set set = new Sheet.Set();
61
        set.setName( LOOK_SHEET_SET_NAME ); // NOI18N
62
        set.setDisplayName( bundle.getString( "CTL_LookSheetSetName" ) ); //NOI18N
63
        set.put( new LookProperty( node ) ); 
64
        return set;
65
    }
66
    
67
    // INNER CLASSES -----------------------------------------------------------
68
    
69
    /** The property for changing look
70
     */
71
    static class LookProperty extends PropertySupport.ReadWrite {
72
        
73
        private final LookNode lookNode;
74
        
75
        LookProperty( LookNode lookNode ) {
76
            super( bundle.getString( "CTL_LookProperty" ), // NOI18N
77
				   Look.class, 
78
                   bundle.getString( "CTL_LookProperty" ), // NOI18N
79
                   bundle.getString( "CTL_LookPropertyShortDescription" ) // NOI18N
80
                   ); 
81
            this.lookNode = lookNode;
82
        }
83
        
84
            
85
        public Object getValue() {            
86
            return lookNode.getHardLook();
87
        }
88
            
89
        public void setValue( Object value ) {
90
            lookNode.setLook( (Look) value );
91
        }
92
            
93
        public PropertyEditor getPropertyEditor () {
94
            return new LookEditor( lookNode );
95
        }
96
97
    }
98
    
99
    /** Editor for choosing looks */
100
    static class LookEditor extends PropertyEditorSupport { 
101
102
        /** The node */
103
        LookNode lookNode = null;
104
        
105
        /** Current value */
106
        private Look look = null;
107
108
        /** Creates new editor */
109
        public LookEditor ( LookNode lookNode ) {
110
            this.lookNode = lookNode;
111
        }
112
113
        /**
114
        * @return The property value as a human editable string.
115
        * <p>   Returns null if the value can't be expressed as an editable string.
116
        * <p>   If a non-null value is returned, then the PropertyEditor should
117
        *       be prepared to parse that string back in setAsText().
118
        */
119
        public String getAsText () {
120
            if ( getValue() == null ) {
121
                return DEFAULT;
122
            }
123
            return ((Look)getValue()).getName();
124
        }
125
        
126
        /**
127
        * Set the property value by parsing a given String.
128
        * @param text  The string to be parsed.
129
        */
130
        public void setAsText ( String string ) throws IllegalArgumentException {
131
            if ( string.equals( DEFAULT ) ) {
132
                setValue( null );
133
            }
134
            Look[] allLooks = getAllLooks( lookNode );
135
            for( int i = 0; i < allLooks.length; i++ ) {
136
                if ( allLooks[i].getName().equals( string ) ) {
137
                    setValue( allLooks[i] );
138
                    return;
139
                }
140
            }
141
            throw new IllegalArgumentException( "No such look - " + string ); // NOI18N
142
        }
143
144
        /**
145
        * @return A fragment of Java code representing an initializer for the
146
        * current value.
147
        */
148
        public String getJavaInitializationString () {
149
            return (getValue() == null) ? "" : look.getName(); // NOI18N
150
        }
151
152
        /**
153
        * @return The tag values for this property.
154
        */
155
        public String[] getTags () {
156
            
157
            Look[] allLooks = getAllLooks( lookNode );
158
            String names[];
159
            
160
            int offset = 0;
161
            if (lookNode.hasLookNodeParent()) {                
162
                names = new String[ allLooks.length + 1];
163
                names[0] = DEFAULT;
164
                offset = 1;
165
            } else {
166
                names = new String[ allLooks.length];
167
            }                         
168
                                    
169
            for ( int i = 0; i < allLooks.length ; i++ ) {
170
                names[ i+ offset] = allLooks[i].getName();
171
            }            
172
            return names;
173
        }
174
175
        static Look[] getAllLooks( LookNode lookNode ) {
176
            Lookup.Template t = new Lookup.Template( Look.class );
177
            
178
            Lookup.Result r = Lookup.getDefault().lookup( t );
179
            Collection lc = r.allInstances();
180
            
181
            ArrayList looks = new ArrayList( lc.size() );
182
            int i = 0;
183
            for ( Iterator it = lc.iterator(); it.hasNext(); i++ ) {
184
                Look look = (Look)it.next();
185
                if ( look.isLookStandalone( lookNode.getRepresentedObject() ) ) {
186
                    looks.add( look );
187
                }
188
            }
189
            
190
            return (Look[])looks.toArray( new Look[0] );
191
        }        
192
    }
193
    
194
    /** Popupmenu action for choosing looks 
195
     */
196
    public static class SetLookAction extends NodeAction {
197
        
198
        private LookNode lookNode = null;
199
        
200
        public java.lang.String getName() {
201
            return bundle.getString( "ACT_SetLook" ); //NOI18N
202
        }
203
204
        public org.openide.util.HelpCtx getHelpCtx() {
205
            return org.openide.util.HelpCtx.DEFAULT_HELP;
206
        }
207
208
        public void setLookNode(LookNode lookNode){
209
            this.lookNode = lookNode;
210
        }
211
        
212
        /* Returns a submneu that will present this action in a PopupMenu.
213
        * @return the JMenuItem representation for this action
214
        */
215
        public JMenuItem getPopupPresenter() {            
216
            JMenu mainItem = new JMenuPlus();
217
            Actions.setMenuText(mainItem, getName(), true); 
218
            HelpCtx.setHelpIDString (mainItem, SetLookAction.class.getName ());
219
            mainItem.addMenuListener(new MainItemListener(lookNode));
220
            return mainItem;
221
        }
222
        
223
        protected boolean enable(org.openide.nodes.Node[] node) {
224
            if( node.length == 1 )
225
                return true;
226
            return false;
227
        }
228
        
229
        protected void performAction(org.openide.nodes.Node[] node) {
230
            //do nothing
231
        }
232
        
233
    }        
234
235
        /** Listens to selecting of main item and expands it to the
236
         * submenu of exiting and new modes
237
         */
238
        private static final class MainItemListener implements MenuListener {
239
240
            /** Source of the events */
241
            private JMenu menu;
242
243
            private LookNode lookNode;
244
245
            public MainItemListener(LookNode lookNode){
246
                this.lookNode = lookNode;
247
            }
248
249
            public void menuCanceled (MenuEvent e) {
250
            }
251
252
            public void menuDeselected (MenuEvent e) {
253
                JMenu menu = (JMenu)e.getSource();
254
                menu.removeAll();
255
            }
256
257
            public void menuSelected (MenuEvent e) {
258
                this.menu = (JMenu)e.getSource();            
259
260
                if (lookNode.hasLookNodeParent()) {
261
                    menu.add(createMenuItem(lookNode, null));
262
                }
263
                // create look list
264
                if( lookNode != null ){
265
                    Look[] looks  = LookProperties.LookEditor.getAllLooks( lookNode );
266
                    for( int i = 0; i < looks.length; i++ ){
267
                        menu.add(createMenuItem(lookNode, looks[i]));
268
                    }
269
                }
270
            }
271
        
272
        /**Creates menu item for existing mode. If mode has split TCC then use menu
273
         * instead of menu item. Adds listener to menu item.
274
         */
275
        private JMenuItem createMenuItem(LookNode lookNode, Look look) {
276
            JMenuItem curMenu = new JMenuItem();
277
            if( look == null ){
278
                Actions.setMenuText(curMenu, DEFAULT , true);  // NOI18N
279
                curMenu.addActionListener(new LookItemListener(lookNode, null));
280
            }
281
            else {
282
                Actions.setMenuText(curMenu, look.getName(), true); 
283
                curMenu.addActionListener(new LookItemListener(lookNode, look));
284
            }
285
            
286
            return curMenu;
287
        }        
288
    } // end of MainItemListener inner class
289
290
    private static final class LookItemListener implements ActionListener {
291
        private LookNode lookNode;
292
        private Look look;
293
        LookItemListener(LookNode lookNode, Look look){
294
            this.lookNode = lookNode;
295
            this.look     = look;
296
        }
297
        
298
        public void actionPerformed(ActionEvent evt) {
299
            lookNode.setLook(look);
300
        }
301
    }
302
}
303
(-)openidex/src/org/openidex/nodes/looks/NodeProxyLook.java (-467 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.awt.Image;
17
import java.awt.datatransfer.Transferable;
18
import java.io.IOException;
19
import java.beans.PropertyChangeListener;
20
import java.beans.PropertyChangeEvent;
21
22
import org.openide.nodes.*;
23
import org.openide.util.actions.SystemAction;
24
import org.openide.util.HelpCtx;
25
import org.openide.util.datatransfer.NewType;
26
import org.openide.util.datatransfer.PasteType;
27
28
/** <B>WARNING</B> - This API is not finished and is subject to change<BR> 
29
 * Please don't use this API for other purposes than testing.
30
 * <P>
31
 * Utility Class which allows to use LookNodes on existing Nodes. 
32
 * The class assumes that represented object is a Node. If there is 
33
 * Node.Interior representing other object than a ndoe the look delegates
34
 * to {DefaultLook#INSTANCE} i.e. returns neutral values.<BR>
35
 * Recomended usage of this class is to be used as delegatee.
36
 * <CODE>
37
 * public class MyNodeLook extends AcceptorLook {  
38
 *  
39
 *     public MyNodeLook() {
40
 *         super( new NodeProxyLook(), MyNode.Class );
41
 *         // set mask or do other initializations
42
 *     }
43
 * }
44
 * </CODE>
45
 * 
46
 * @author Petr Hrebejk
47
 */
48
public class NodeProxyLook extends Look {
49
    
50
    /** Creates new NodeProxySupport */
51
    public NodeProxyLook() {
52
    }
53
54
    // Methods of look itself --------------------------------------------------
55
    
56
    /** Specifies the node to which the Look delegates. The default 
57
     * implementation returns <CODE>substitute.getRepresentedObject()</CODE> 
58
     * casted to Node in case the represented object is a Node in other cases 
59
     * it returns null. If you override this method you can provide delegation
60
     * nodes for different types of object. (E.g. by calling 
61
     * dataObject.getNodeDelegate() ).
62
     */
63
    protected Node getNodeDelegate( Look.NodeSubstitute substitute ) {
64
        
65
        if ( substitute.getRepresentedObject() instanceof Node ) {
66
            return (Node)substitute.getRepresentedObject();
67
        }
68
        else {
69
            return null;
70
        }
71
    }
72
            
73
    // General methods ---------------------------------------------------------
74
    
75
    public void attachTo(Look.NodeSubstitute substitute) {
76
        Node dn = getNodeDelegate( substitute );
77
        if ( dn == null ) {
78
            DefaultLook.INSTANCE.attachTo( substitute );
79
        }
80
        else {
81
            // Register listener to the node to pass events forward
82
            dn.addNodeListener( new NodeEventTranslator( substitute, dn ) );
83
            dn.addPropertyChangeListener( new NodePropertyChangeTranslator( substitute, dn ) );
84
        }
85
    }
86
    
87
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
88
        Node dn = getNodeDelegate( substitute );
89
        if ( dn == null ) {
90
            return DefaultLook.INSTANCE.getCookie( substitute, type );
91
        }
92
        else {
93
            return dn.getCookie( type );
94
        }
95
    }
96
97
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
98
        Node dn = getNodeDelegate( substitute );
99
        if ( dn == null ) {
100
            return DefaultLook.INSTANCE.getHandle( substitute );
101
        }
102
        else {
103
            return dn.getHandle();
104
        }
105
    }
106
    
107
    // Methods for STYLE -------------------------------------------------------
108
    
109
    public String getDisplayName( Look.NodeSubstitute substitute ) {
110
        Node dn = getNodeDelegate( substitute );
111
        if ( dn == null ) {
112
            return DefaultLook.INSTANCE.getDisplayName( substitute );
113
        }
114
        else {
115
            return dn.getDisplayName();
116
        }
117
    }
118
    
119
    public String getName( Look.NodeSubstitute substitute ) {
120
        Node dn = getNodeDelegate( substitute );
121
        if ( dn == null ) {
122
            return DefaultLook.INSTANCE.getName( substitute );
123
        }
124
        else {
125
            return dn.getName();
126
        }
127
    }
128
    
129
    public void setName( Look.NodeSubstitute substitute, String newName ) {
130
        Node dn = getNodeDelegate( substitute );
131
        if ( dn == null ) {
132
            DefaultLook.INSTANCE.setName( substitute, newName );
133
        }
134
        else {
135
            dn.setName( newName );
136
        }
137
    }
138
    
139
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
140
        Node dn = getNodeDelegate( substitute );
141
        if ( dn == null ) {
142
            return DefaultLook.INSTANCE.getShortDescription( substitute );
143
        }
144
        else {
145
            return dn.getShortDescription();
146
        }
147
    }
148
    
149
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
150
        Node dn = getNodeDelegate( substitute );
151
        if ( dn == null ) {
152
            return DefaultLook.INSTANCE.getIcon( substitute, type );
153
        }
154
        else {
155
            return dn.getIcon( type );
156
        }
157
    }
158
    
159
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
160
        Node dn = getNodeDelegate( substitute );
161
        if ( dn == null ) {
162
            return DefaultLook.INSTANCE.getOpenedIcon( substitute, type );
163
        }
164
        else {
165
            return dn.getOpenedIcon( type );
166
        }
167
    }
168
    
169
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
170
        Node dn = getNodeDelegate( substitute );
171
        if ( dn == null ) {
172
            return DefaultLook.INSTANCE.getHelpCtx( substitute );
173
        }
174
        else {
175
            return dn.getHelpCtx();
176
        }
177
    }
178
    
179
    // Methods for CHILDREN ----------------------------------------------------
180
    
181
    public Object[] getChildObjects( Look.NodeSubstitute substitute ) {
182
        Node dn = getNodeDelegate( substitute );
183
        if ( dn == null ) {
184
            return DefaultLook.INSTANCE.getChildObjects( substitute );
185
        }
186
        else {
187
            return dn.getChildren().getNodes();
188
        }
189
    }
190
        
191
    /* Not implemented yet
192
    
193
    public Ordering getOrdering( Look.NodeSubstitute substitute ) {
194
        return null;
195
    }
196
    
197
    public Filter getFilter( Look.NodeSubstitute substitute ) {
198
        return null;
199
    }
200
    
201
    public Grouping getGrouping( Look.NodeSubstitute substitute ) {
202
        return null;
203
    }
204
    
205
    */
206
     
207
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
208
    
209
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
210
        Node dn = getNodeDelegate( substitute );
211
        if ( dn == null ) {
212
            return DefaultLook.INSTANCE.getNewTypes( substitute );
213
        }
214
        else {
215
            return dn.getNewTypes();
216
        }
217
    }
218
    
219
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
220
        Node dn = getNodeDelegate( substitute );
221
        if ( dn == null ) {
222
            return DefaultLook.INSTANCE.getActions( substitute );
223
        }
224
        else {
225
            return dn.getActions();
226
        }
227
    }
228
    
229
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
230
        Node dn = getNodeDelegate( substitute );
231
        if ( dn == null ) {
232
            return DefaultLook.INSTANCE.getContextActions( substitute );
233
        }
234
        else {
235
            return dn.getContextActions();
236
        }
237
    }
238
    
239
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
240
        Node dn = getNodeDelegate( substitute );
241
        if ( dn == null ) {
242
            return DefaultLook.INSTANCE.getDefaultAction( substitute );
243
        }
244
        else {
245
            return dn.getDefaultAction();
246
        }
247
    }
248
    
249
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
250
    
251
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
252
        Node dn = getNodeDelegate( substitute );
253
        if ( dn == null ) {
254
            return DefaultLook.INSTANCE.getPropertySets( substitute );
255
        }
256
        else {
257
            return dn.getPropertySets();
258
        }
259
    }
260
    
261
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {        
262
        Node dn = getNodeDelegate( substitute );
263
        if ( dn == null || !dn.hasCustomizer() ) {
264
            return DefaultLook.INSTANCE.getCustomizer( substitute );
265
        }
266
        else {
267
            return dn.getCustomizer();
268
        }
269
    }
270
    
271
    public boolean hasCustomizer( Look.NodeSubstitute substitute ) {
272
        Node dn = getNodeDelegate( substitute );
273
         if (dn == null) {
274
             return DefaultLook.INSTANCE.hasCustomizer( substitute );
275
         } else {
276
             return dn.hasCustomizer();
277
         }
278
                
279
    }
280
    
281
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
282
     
283
    public boolean canRename( Look.NodeSubstitute substitute ) {
284
        Node dn = getNodeDelegate( substitute );
285
        if ( dn == null ) {
286
            return DefaultLook.INSTANCE.canRename( substitute );
287
        }
288
        else {
289
            return dn.canRename();
290
        }
291
    }
292
    
293
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
294
        Node dn = getNodeDelegate( substitute );
295
        if ( dn == null ) {
296
            return DefaultLook.INSTANCE.canDestroy( substitute );
297
        }
298
        else {
299
            return dn.canDestroy();
300
        }
301
    }
302
    
303
    public boolean canCopy( Look.NodeSubstitute substitute ) {
304
        Node dn = getNodeDelegate( substitute );
305
        if ( dn == null ) {
306
            return DefaultLook.INSTANCE.canCopy( substitute );
307
        }
308
        else {
309
            return dn.canCopy();
310
        }
311
    }
312
    
313
    public boolean canCut( Look.NodeSubstitute substitute ) {
314
        Node dn = getNodeDelegate( substitute );
315
        if ( dn == null ) {
316
            return DefaultLook.INSTANCE.canCut( substitute );
317
        }
318
        else {
319
            return dn.canCut();
320
        }
321
    }
322
    
323
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
324
        Node dn = getNodeDelegate( substitute );
325
        if ( dn == null ) {
326
            return DefaultLook.INSTANCE.getPasteTypes( substitute, t );
327
        }
328
        else {
329
            return dn.getPasteTypes( t );
330
        }
331
    }
332
    
333
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
334
        Node dn = getNodeDelegate( substitute );
335
        if ( dn == null ) {
336
            return DefaultLook.INSTANCE.getDropType( substitute, t, action, index );
337
        }
338
        else {
339
            return dn.getDropType( t, action, index );
340
        }
341
    }
342
    
343
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
344
        Node dn = getNodeDelegate( substitute );
345
        if ( dn == null ) {
346
            return DefaultLook.INSTANCE.clipboardCopy( substitute );
347
        }
348
        else {
349
            return dn.clipboardCopy();
350
        }
351
    }
352
    
353
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
354
        Node dn = getNodeDelegate( substitute );
355
        if ( dn == null ) {
356
            return DefaultLook.INSTANCE.clipboardCut( substitute );
357
        }
358
        else {
359
            return dn.clipboardCut();
360
        }
361
    }
362
    
363
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
364
        Node dn = getNodeDelegate( substitute );
365
        if ( dn == null ) {
366
            return DefaultLook.INSTANCE.drag( substitute );
367
        }
368
        else {
369
            return dn.drag();
370
        }
371
    }      
372
    
373
    public void destroy( Look.NodeSubstitute substitute ) throws IOException {
374
        Node dn = getNodeDelegate( substitute );
375
        if ( dn == null ) {
376
            DefaultLook.INSTANCE.destroy( substitute );
377
        }
378
        else {
379
            dn.destroy();
380
        }
381
    }
382
    
383
    
384
    // Innerclasses ------------------------------------------------------------
385
    
386
    public static class NodeEventTranslator  
387
        extends EventTranslator implements NodeListener {
388
        
389
        private Node node;    
390
            
391
        NodeEventTranslator( Look.NodeSubstitute substitute, Node node) {
392
            super( substitute );
393
            this.node = node;
394
        }
395
            
396
        public void unregister() {
397
            node.removeNodeListener( this );
398
        }
399
        
400
        public void childrenAdded( NodeMemberEvent e ) {
401
            getSubstitute().refreshChildren();
402
        }
403
         
404
        public void childrenRemoved( NodeMemberEvent e ) {
405
            getSubstitute().refreshChildren();
406
        }
407
        
408
        public void childrenReordered( NodeReorderEvent e ) {
409
            getSubstitute().refreshChildren();
410
        }
411
        
412
        public void nodeDestroyed( NodeEvent e ) {
413
            getSubstitute().fireNodeDestroyed();
414
        }
415
        
416
        public void propertyChange( PropertyChangeEvent e ) {
417
        
418
            if ( Node.PROP_NAME.equals( e.getPropertyName() ) ) {
419
                getSubstitute().fireNameChange( (String)e.getOldValue(), (String)e.getNewValue() );
420
            }
421
            else if ( Node.PROP_DISPLAY_NAME.equals( e.getPropertyName() ) ) {
422
                getSubstitute().fireDisplayNameChange( (String)e.getOldValue(), (String)e.getNewValue() );
423
            }
424
            else if ( Node.PROP_SHORT_DESCRIPTION.equals( e.getPropertyName() ) ) {
425
                getSubstitute().fireShortDescriptionChange( (String)e.getOldValue(), (String)e.getNewValue() );
426
            }
427
            else if ( Node.PROP_ICON.equals( e.getPropertyName() ) ) {
428
                getSubstitute().fireIconChange();
429
            }
430
            else if ( Node.PROP_OPENED_ICON.equals( e.getPropertyName() ) ) {
431
                getSubstitute().fireOpenedIconChange();
432
            }
433
            /*
434
            else if ( Node.PROP_PARENT_NODE.equals( e.getPropertyName() ) ) {
435
                property
436
            }
437
            */
438
            else if ( Node.PROP_PROPERTY_SETS.equals( e.getPropertyName() ) ) {
439
                getSubstitute().firePropertySetsChange( (Node.PropertySet[])e.getOldValue(), 
440
                                        (Node.PropertySet[])e.getNewValue() );
441
            }
442
            else if ( Node.PROP_COOKIE.equals( e.getPropertyName() ) ) {
443
                getSubstitute().fireCookieChange();
444
            }
445
        }
446
    }
447
    
448
    public static class NodePropertyChangeTranslator
449
        extends EventTranslator implements PropertyChangeListener {
450
         
451
        private Node node;    
452
            
453
        NodePropertyChangeTranslator( Look.NodeSubstitute substitute, Node node) {
454
            super( substitute );
455
            this.node = node;
456
        }
457
            
458
        public void unregister() {
459
            node.removePropertyChangeListener( this );
460
        }    
461
            
462
        public void propertyChange( PropertyChangeEvent e ) {
463
            getSubstitute().firePropertyChange( e.getPropertyName(), e.getOldValue(), e.getNewValue() ); 
464
        }
465
    }
466
467
}
(-)openidex/src/org/openidex/nodes/looks/resources/look.dtd (-4 lines)
Removed Link Here
1
<!-- Document type declaration for look configurations -->
2
3
<!ELEMENT Look ANY >
4
(-)openidex/test/unit/src/org/openidex/nodes/looks/DefaultLookTest.java (-418 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.lang.ref.*;
17
import java.util.*;
18
19
//import junit.framework.*;
20
import org.netbeans.junit.*;
21
22
import java.util.List;
23
import java.awt.Image;
24
import java.awt.datatransfer.Transferable;
25
import java.io.IOException;
26
import org.openide.nodes.*;
27
import org.openide.loaders.XMLDataObject;
28
import org.openide.util.actions.SystemAction;
29
import org.openide.util.HelpCtx;
30
import org.openide.util.datatransfer.NewType;
31
import org.openide.util.datatransfer.PasteType;
32
33
//import org.openide.ErrorManager;
34
35
36
37
public class DefaultLookTest extends NbTestCase {
38
    
39
    /** Instance of tested DefaultLook */
40
    private DefaultLook defaultLook;
41
    
42
    /** Message for unexpected value */
43
    private static final String MSSG_UNEXPECTED_VALUE_RETURNED = 
44
        "Unexpected value returned : ";
45
    
46
    private static final String MSSG_EXCEPTION_THROWN =
47
        "Exception thrown.";
48
    
49
    public DefaultLookTest(java.lang.String testName) {
50
        super(testName);
51
    }
52
    
53
    public static void main(java.lang.String[] args) {
54
        junit.textui.TestRunner.run(suite());
55
    }
56
    
57
    public static NbTest suite() {
58
        NbTestSuite suite = new NbTestSuite(DefaultLookTest.class);
59
        
60
        return suite;
61
    }    
62
    
63
    protected void setUp() throws Exception {
64
        super.setUp();
65
        
66
        // add specific setup code here
67
        defaultLook = new DefaultLook();
68
    }
69
    
70
    protected void tearDown() throws Exception {
71
        // add specific tear-down code here
72
        defaultLook = null;
73
        
74
        super.tearDown();
75
    }
76
77
    
78
    /** Test of attachTo method, of class org.openidex.nodes.looks.DefaultLook. */
79
    // Nothing to test
80
    /*
81
    public void testAttachTo() {
82
        System.out.println("testAttachTo");
83
        
84
        // Add your test code below by replacing the default call to fail.
85
        fail("The test case is empty.");
86
    }
87
    */
88
    
89
    /** Test of getCookie method, of class org.openidex.nodes.looks.DefaultLook. */
90
    /*
91
    public void testGetCookie() {
92
        System.out.println("testGetCookie");
93
        
94
        // Add your test code below by replacing the default call to fail.
95
        
96
        Node.Cookie cookie = defaultLook.getCookie( null, null );
97
        
98
        if ( cookie != null ) {
99
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + cookie );
100
        }
101
    }
102
     */
103
    
104
    /** Test of getHandle method, of class org.openidex.nodes.looks.DefaultLook. */
105
    public void testGetHandle() {
106
        System.out.println("testGetHandle");
107
        
108
        // Add your test code below by replacing the default call to fail.
109
        Node.Handle handle = defaultLook.getHandle( null );
110
        
111
        if ( handle != null ) {
112
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + handle );
113
        }
114
    }
115
    
116
    /** Test of getDisplayName method, of class org.openidex.nodes.looks.DefaultLook. */
117
    public void testGetDisplayName() {
118
        System.out.println("testGetDisplayName");
119
        
120
        // Add your test code below by replacing the default call to fail.
121
        String displayName = defaultLook.getDisplayName( null );
122
        
123
        if ( displayName != null ) {
124
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + displayName );
125
        }
126
    }
127
    
128
    /** Test of getName method, of class org.openidex.nodes.looks.DefaultLook. */
129
    public void testGetName() {
130
        System.out.println("testGetName");
131
        
132
        // Add your test code below by replacing the default call to fail.
133
        String name = defaultLook.getName( null );
134
        
135
        if ( name != null ) {
136
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + name );
137
        }
138
    }
139
    
140
    /** Test of setName method, of class org.openidex.nodes.looks.DefaultLook. */
141
    // Nothing to test
142
    /*
143
    public void testSetName() {
144
        System.out.println("testSetName");
145
        
146
        // Add your test code below by replacing the default call to fail.
147
        fail("The test case is empty.");
148
    }
149
    */
150
    
151
    /** Test of getShortDescription method, of class org.openidex.nodes.looks.DefaultLook. */
152
    public void testGetShortDescription() {
153
        System.out.println("testGetShortDescription");
154
        
155
        // Add your test code below by replacing the default call to fail.
156
        String shortDescription = defaultLook.getShortDescription( null );
157
        
158
        if ( shortDescription != null ) {
159
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + shortDescription );
160
        }
161
    }
162
    
163
    /** Test of getIcon method, of class org.openidex.nodes.looks.DefaultLook. */
164
    public void testGetIcon() {
165
        System.out.println("testGetIcon");
166
        
167
        // Add your test code below by replacing the default call to fail.
168
        Image icon = defaultLook.getIcon( null, 0 );
169
        
170
        if ( icon != null ) {
171
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + icon );
172
        }
173
    }
174
    
175
    /** Test of getOpenedIcon method, of class org.openidex.nodes.looks.DefaultLook. */
176
    public void testGetOpenedIcon() {
177
        System.out.println("testGetOpenedIcon");
178
        
179
        // Add your test code below by replacing the default call to fail.
180
        Image openedIcon = defaultLook.getOpenedIcon( null, 0 );
181
        
182
        if ( openedIcon != null ) {
183
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + openedIcon );
184
        }
185
    }
186
    
187
    /** Test of getHelpCtx method, of class org.openidex.nodes.looks.DefaultLook. */
188
    public void testGetHelpCtx() {
189
        System.out.println("testGetHelpCtx");
190
        
191
        // Add your test code below by replacing the default call to fail.
192
        HelpCtx helpCtx = defaultLook.getHelpCtx( null  );
193
        
194
        if ( helpCtx != null ) {
195
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + helpCtx );
196
        }
197
    }
198
    
199
    /** Test of getChildObjects method, of class org.openidex.nodes.looks.DefaultLook. */
200
    public void testGetChildObjects() {
201
        System.out.println("testGetChildObjects");
202
        
203
        // Add your test code below by replacing the default call to fail.
204
        Object[] children = defaultLook.getChildObjects( null );
205
        
206
        if ( children != DefaultLook.INSTANCE.NO_KEYS ) {
207
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + children );
208
        }
209
    }
210
    
211
    /** Test of getNewTypes method, of class org.openidex.nodes.looks.DefaultLook. */
212
    public void testGetNewTypes() {
213
        System.out.println("testGetNewTypes");
214
        
215
        // Add your test code below by replacing the default call to fail.
216
        NewType[] newTypes = defaultLook.getNewTypes( null );
217
        
218
        if ( newTypes != DefaultLook.INSTANCE.NO_NEW_TYPES ) {
219
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + newTypes );
220
        }
221
    }
222
    
223
    /** Test of getActions method, of class org.openidex.nodes.looks.DefaultLook. */
224
    public void testGetActions() {
225
        System.out.println("testGetActions");
226
        
227
        // Add your test code below by replacing the default call to fail.
228
        SystemAction[] actions = defaultLook.getActions( null );
229
        
230
        if ( actions != DefaultLook.INSTANCE.NO_SYSTEM_ACTIONS ) {
231
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + actions );
232
        }
233
    }
234
    
235
    /** Test of getContextActions method, of class org.openidex.nodes.looks.DefaultLook. */
236
    public void testGetContextActions() {
237
        System.out.println("testGetContextActions");
238
        
239
        // Add your test code below by replacing the default call to fail.
240
        SystemAction[] contextActions = defaultLook.getContextActions( null );
241
        
242
        if ( contextActions != DefaultLook.INSTANCE.NO_SYSTEM_ACTIONS ) {
243
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + contextActions );
244
        }
245
    }
246
    
247
    /** Test of getDefaultAction method, of class org.openidex.nodes.looks.DefaultLook. */
248
    public void testGetDefaultAction() {
249
        System.out.println("testGetDefaultAction");
250
        
251
        // Add your test code below by replacing the default call to fail.
252
        SystemAction defaultAction = defaultLook.getDefaultAction( null );
253
        
254
        if ( defaultAction != null ) {
255
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + defaultAction );
256
        }
257
    }
258
    
259
    /** Test of getPropertySets method, of class org.openidex.nodes.looks.DefaultLook. */
260
    public void testGetPropertySets() {
261
        System.out.println("testGetPropertySets");
262
        
263
        // Add your test code below by replacing the default call to fail.
264
        Node.PropertySet[] propertySets = defaultLook.getPropertySets( null );
265
        
266
        if ( propertySets != DefaultLook.INSTANCE.NO_PROPERTY_SETS ) {
267
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + propertySets );
268
        }
269
    }
270
    
271
    /** Test of getCustomizer method, of class org.openidex.nodes.looks.DefaultLook. */
272
    public void testGetCustomizer() {
273
        System.out.println("testGetCustomizer");
274
        
275
        // Add your test code below by replacing the default call to fail.
276
        java.awt.Component customizer = defaultLook.getCustomizer( null );
277
        
278
        if ( customizer != null ) {
279
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + customizer );
280
        }
281
    }
282
    
283
    /** Test of canRename method, of class org.openidex.nodes.looks.DefaultLook. */
284
    public void testCanRename() {
285
        System.out.println("testCanRename");
286
        
287
        // Add your test code below by replacing the default call to fail.
288
        boolean canRename = defaultLook.canRename( null );
289
        
290
        if ( canRename != false ) {
291
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canRename );
292
        }
293
    }
294
    
295
    /** Test of canDestroy method, of class org.openidex.nodes.looks.DefaultLook. */
296
    public void testCanDestroy() {
297
        System.out.println("testCanDestroy");
298
        
299
        // Add your test code below by replacing the default call to fail.
300
        boolean canDestroy = defaultLook.canDestroy( null );
301
        
302
        if ( canDestroy != false ) {
303
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canDestroy );
304
        }
305
    }
306
    
307
    /** Test of canCopy method, of class org.openidex.nodes.looks.DefaultLook. */
308
    public void testCanCopy() {
309
        System.out.println("testCanCopy");
310
        
311
        // Add your test code below by replacing the default call to fail.
312
        boolean canCopy = defaultLook.canCopy( null );
313
        
314
        if ( canCopy != false ) {
315
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canCopy );
316
        }
317
    }
318
    
319
    /** Test of canCut method, of class org.openidex.nodes.looks.DefaultLook. */
320
    public void testCanCut() {
321
        System.out.println("testCanCut");
322
        
323
        // Add your test code below by replacing the default call to fail.
324
        boolean canCut = defaultLook.canCut( null );
325
        
326
        if ( canCut != false ) {
327
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + canCut );
328
        }
329
    }
330
    
331
    /** Test of getPasteTypes method, of class org.openidex.nodes.looks.DefaultLook. */
332
    public void testGetPasteTypes() {
333
        System.out.println("testGetPasteTypes");
334
        
335
        // Add your test code below by replacing the default call to fail.
336
        PasteType pasteTypes[] = defaultLook.getPasteTypes( null, null );
337
        
338
        if ( pasteTypes != DefaultLook.INSTANCE.NO_PASTE_TYPES ) {
339
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + pasteTypes );
340
        }
341
    }
342
    
343
    /** Test of getDropType method, of class org.openidex.nodes.looks.DefaultLook. */
344
    public void testGetDropType() {
345
        System.out.println("testGetDropType");
346
        
347
        // Add your test code below by replacing the default call to fail.
348
        PasteType dropType = defaultLook.getDropType( null, null, 0, 0 );
349
        
350
        if ( dropType != null ) {
351
            fail( MSSG_UNEXPECTED_VALUE_RETURNED + dropType );
352
        }
353
    }
354
    
355
    /** Test of clipboardCopy method, of class org.openidex.nodes.looks.DefaultLook. */
356
    public void testClipboardCopy() {
357
        System.out.println("testClipboardCopy");
358
        
359
        // Add your test code below by replacing the default call to fail.
360
        try {
361
            Transferable transferable = defaultLook.clipboardCopy( null );
362
363
            if ( transferable != null ) {
364
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
365
            }
366
        }
367
        catch ( java.io.IOException e ) {
368
            fail ( MSSG_EXCEPTION_THROWN );
369
        }
370
    }
371
    
372
    /** Test of clipboardCut method, of class org.openidex.nodes.looks.DefaultLook. */
373
    public void testClipboardCut() {
374
        System.out.println("testClipboardCut");
375
        
376
        // Add your test code below by replacing the default call to fail.
377
        try {
378
            Transferable transferable = defaultLook.clipboardCut( null );
379
            
380
            if ( transferable != null ) {
381
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
382
            }
383
        }
384
        catch ( java.io.IOException e ) {
385
            fail ( MSSG_EXCEPTION_THROWN );
386
        }
387
        
388
    }
389
    
390
    /** Test of drag method, of class org.openidex.nodes.looks.DefaultLook. */
391
    public void testDrag() {
392
        System.out.println("testDrag");
393
        
394
        // Add your test code below by replacing the default call to fail.
395
        try {
396
            Transferable transferable = defaultLook.drag( null );
397
398
            if ( transferable != null ) {
399
                fail( MSSG_UNEXPECTED_VALUE_RETURNED + transferable );
400
            }
401
        }
402
        catch ( java.io.IOException e ) {
403
            fail ( MSSG_EXCEPTION_THROWN );
404
        }
405
    }
406
    
407
    /** Test of destroy method, of class org.openidex.nodes.looks.DefaultLook. */
408
    // Nothing to test
409
    /*
410
    public void testDestroy() {
411
        System.out.println("testDestroy");
412
        
413
        // Add your test code below by replacing the default call to fail.
414
        fail("The test case is empty.");
415
    }
416
    */
417
    
418
}
(-)openidex/test/unit/src/org/openidex/nodes/looks/FilterLookTest.java (-653 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.Collection;
17
import java.util.List;
18
import java.awt.Image;
19
import java.awt.datatransfer.Transferable;
20
import java.io.IOException;
21
import org.openide.nodes.*;
22
import org.openide.util.actions.SystemAction;
23
import org.openide.util.HelpCtx;
24
import org.openide.util.datatransfer.NewType;
25
import org.openide.util.datatransfer.PasteType;
26
//import junit.framework.*;
27
import org.netbeans.junit.*;
28
29
public class FilterLookTest extends NbTestCase {
30
    
31
    private static final String MSSG_UNEXPECTED_EXCEPTION =  "Unexpected exception caught : ";
32
    
33
    /** Array with masks and results */
34
    private TestingItem[] testingItems = new TestingItem[] {
35
        new TestingItem( FilterLook.ATTACH_TO, "ATTACH_TO" ), 
36
        new TestingItem( FilterLook.GET_COOKIE, "GET_COOKIE" ),
37
        new TestingItem( FilterLook.GET_HANDLE, "GET_HANDLE" ),
38
        new TestingItem( FilterLook.GET_DISPLAY_NAME, "GET_DISPLAY_NAME" ),
39
        new TestingItem( FilterLook.GET_NAME, "GET_NAME" ),
40
        new TestingItem( FilterLook.SET_NAME, "SET_NAME" ),
41
        new TestingItem( FilterLook.GET_SHORT_DESCRIPTION, "GET_SHORT_DESCRIPTION" ),
42
        new TestingItem( FilterLook.GET_ICON, "GET_ICON" ),
43
        new TestingItem( FilterLook.GET_OPENED_ICON, "GET_OPENED_ICON" ),
44
        new TestingItem( FilterLook.GET_HELP_CTX, "GET_HELP_CTX" ),
45
        new TestingItem( FilterLook.GET_CHILD_OBJECTS, "GET_CHILD_OBJECTS" ),
46
        new TestingItem( FilterLook.GET_NEW_TYPES, "GET_NEW_TYPES" ),
47
        new TestingItem( FilterLook.GET_ACTIONS, "GET_ACTIONS" ),
48
        new TestingItem( FilterLook.GET_CONTEXT_ACTIONS, "GET_CONTEXT_ACTIONS" ),
49
        new TestingItem( FilterLook.GET_DEFAULT_ACTION, "GET_DEFAULT_ACTION" ),
50
        new TestingItem( FilterLook.GET_PROPERTY_SETS, "GET_PROPERTY_SETS" ),
51
        new TestingItem( FilterLook.GET_CUSTOMIZER, "GET_CUSTOMIZER" ),
52
        new TestingItem( FilterLook.CAN_RENAME, "CAN_RENAME" ),
53
        new TestingItem( FilterLook.CAN_DESTROY, "CAN_DESTROY" ),
54
        new TestingItem( FilterLook.CAN_COPY, "CAN_COPY" ),
55
        new TestingItem( FilterLook.CAN_CUT, "CAN_CUT" ),
56
        new TestingItem( FilterLook.GET_PASTE_TYPES, "GET_PASTE_TYPES" ),
57
        new TestingItem( FilterLook.GET_DROP_TYPE, "GET_DROP_TYPE" ),
58
        new TestingItem( FilterLook.CLIPBOARD_COPY, "CLIPBOARD_COPY" ),
59
        new TestingItem( FilterLook.CLIPBOARD_CUT, "CLIPBOARD_CUT" ),
60
        new TestingItem( FilterLook.DRAG, "DRAG" ),
61
        new TestingItem( FilterLook.DESTROY, "DESTROY" )
62
    };
63
    
64
    /** Filter look to test on */
65
    private FilterLook filterLook;
66
    
67
    /** Look which will be filtered */
68
    private SampleLook1Hid sampleLook;
69
    
70
    /** Node substitute to test on */
71
    private FilterLook.FilterNodeSubstitute substitute;
72
    
73
    /** Name to be set */
74
    private static final String NAME_TO_SET = "SomeName";
75
    
76
    Class COOKIE = Object.class;
77
    
78
    int ICON_TYPE = 0;
79
    
80
    int OPENED_ICON_TYPE = 0;
81
    
82
    Transferable PASTE_TYPE = null;
83
    
84
    Transferable DROP_TYPE = null;
85
    int DROP_INDEX = 0;
86
    int DROP_ACTION = 0;
87
    
88
    
89
    
90
    public FilterLookTest(java.lang.String testName) {
91
        super(testName);
92
    }
93
    
94
    public static void main(java.lang.String[] args) {
95
        junit.textui.TestRunner.run(suite());
96
    }
97
    
98
    public static NbTest suite() {
99
        NbTestSuite suite = new NbTestSuite(FilterLookTest.class);
100
        
101
        return suite;
102
    }
103
    
104
    protected void setUp() throws Exception {
105
        super.setUp();
106
        
107
        // add specific setup code here
108
        sampleLook = new SampleLook1Hid();
109
        filterLook = new FilterLook( sampleLook );
110
        
111
        substitute = new FilterLook.FilterNodeSubstitute( 
112
            new SampleLook1Hid.NodeSubstitute(), 
113
            filterLook );
114
    }
115
    
116
    protected void tearDown() throws Exception {
117
        // add specific tear-down code here
118
        filterLook = null; 
119
        substitute = null;
120
        sampleLook = null;
121
        
122
        super.tearDown();
123
    }
124
    
125
    
126
    /** Test of setLookMask method, of class org.openidex.nodes.looks.FilterLook. */
127
    /*
128
    public void testSetLookMask() {
129
        System.out.println("testSetLookMask");
130
        
131
        // Add your test code below by replacing the default call to fail.
132
        fail("The test case is empty.");
133
    }
134
    */
135
    /** Test of getLookMask method, of class org.openidex.nodes.looks.FilterLook. */
136
    /*
137
    public void testGetLookMask() {
138
        System.out.println("testGetLookMask");
139
        
140
        // Add your test code below by replacing the default call to fail.
141
        fail("The test case is empty.");
142
    }
143
    */
144
    
145
    /** Test of lookMask method, of class org.openidex.nodes.looks.FilterLook. */
146
    /*
147
    public void testLookMask() {
148
        System.out.println("testLookMask");
149
        
150
        // Add your test code below by replacing the default call to fail.
151
        fail("The test case is empty.");
152
    }
153
    */
154
    
155
    /** Test of lookUnmask method, of class org.openidex.nodes.looks.FilterLook. */
156
    /*
157
    public void testLookUnmask() {
158
        System.out.println("testLookUnmask");
159
        
160
        // Add your test code below by replacing the default call to fail.
161
        fail("The test case is empty.");
162
    }
163
    */
164
    /** Test of attachTo method, of class org.openidex.nodes.looks.FilterLook. */
165
    /*
166
    public void testAttachTo() {
167
        System.out.println("testAttachTo");
168
        
169
        // Add your test code below by replacing the default call to fail.
170
        fail("The test case is empty.");
171
    }
172
    */
173
    
174
    /** Tests whether the constants defined in the right order and whether
175
     * there is no owerflow.
176
     */
177
    public void testMaskOrder() {
178
        System.out.println("testMaskOrder");
179
        
180
        // Add your test code below by replacing the default call to fail.
181
        
182
        for ( int i = 0, j = 1; i < testingItems.length; i++ ) {
183
            if ( testingItems[i].mask != j ) {
184
                fail("Ordering failed : " + i );
185
            }
186
            j *= 2;
187
        }               
188
    }
189
    
190
    public void test_ATTACH_TO() {
191
        System.out.println("test_ATTACH_TO");
192
        
193
        // Add your test code below by replacing the default call to fail.
194
        int failIndex = doTestingWithMask( FilterLook.ATTACH_TO );
195
        if ( failIndex > -1 ) {
196
            fail( getFailMessage( failIndex) );
197
        }
198
    }
199
    
200
    public void test_GET_COOKIE() {
201
        System.out.println("test_GET_COOKIE");
202
        
203
        // Add your test code below by replacing the default call to fail.
204
        int failIndex = doTestingWithMask( FilterLook.GET_COOKIE );
205
        if ( failIndex > -1 ) {
206
            fail( getFailMessage( failIndex ) );
207
        }
208
    }
209
    
210
    public void test_GET_HANDLE() {
211
        System.out.println("test_GET_HANDLE");
212
        
213
        // Add your test code below by replacing the default call to fail.
214
        int failIndex = doTestingWithMask( FilterLook.GET_HANDLE );
215
        if ( failIndex > -1 ) {
216
            fail( getFailMessage( failIndex ) );
217
        }
218
    }
219
    
220
    public void test_GET_DISPLAY_NAME() {
221
        System.out.println("test_GET_DISPLAY_NAME");
222
        
223
        // Add your test code below by replacing the default call to fail.
224
        int failIndex = doTestingWithMask( FilterLook.GET_DISPLAY_NAME );
225
        if ( failIndex > -1 ) {
226
            fail( getFailMessage( failIndex ) );
227
        }
228
    }
229
    
230
    public void test_GET_NAME() {
231
        System.out.println("test_GET_NAME");
232
        
233
        // Add your test code below by replacing the default call to fail.
234
        int failIndex = doTestingWithMask( FilterLook.GET_NAME );
235
        if ( failIndex > -1 ) {
236
            fail( getFailMessage( failIndex ) );
237
        }
238
    }
239
    
240
    public void test_SET_NAME() {
241
        System.out.println("test_SET_NAME");
242
        
243
        // Add your test code below by replacing the default call to fail.
244
        int failIndex = doTestingWithMask( FilterLook.SET_NAME );
245
        if ( failIndex > -1 ) {
246
            fail( getFailMessage( failIndex ) );
247
        }
248
    }
249
    
250
    public void test_GET_SHORT_DESCRIPTION () {
251
        System.out.println("test_GET_SHORT_DESCRIPTION");
252
        
253
        // Add your test code below by replacing the default call to fail.
254
        int failIndex = doTestingWithMask( FilterLook.GET_SHORT_DESCRIPTION );
255
        if ( failIndex > -1 ) {
256
            fail( getFailMessage( failIndex ) );
257
        }
258
    }
259
    
260
    public void test_GET_ICON() {
261
        System.out.println("test_GET_ICON");
262
        
263
        // Add your test code below by replacing the default call to fail.
264
        int failIndex = doTestingWithMask( FilterLook.GET_ICON );
265
        if ( failIndex > -1 ) {
266
            fail( getFailMessage( failIndex ) );
267
        }
268
    }
269
    public void test_GET_OPENED_ICON () {
270
        System.out.println("test_GET_OPENED_ICON");
271
        
272
        // Add your test code below by replacing the default call to fail.
273
        int failIndex = doTestingWithMask( FilterLook.GET_OPENED_ICON );
274
        if ( failIndex > -1 ) {
275
            fail( getFailMessage( failIndex ) );
276
        }
277
    }
278
    public void test_GET_HELP_CTX () {
279
        System.out.println("test_GET_HELP_CTX");
280
        
281
        // Add your test code below by replacing the default call to fail.
282
        int failIndex = doTestingWithMask( FilterLook.GET_HELP_CTX );
283
        if ( failIndex > -1 ) {
284
            fail( getFailMessage( failIndex ) );
285
        }
286
    }
287
    
288
    public void test_GET_CHILD_OBJECTS () {
289
        System.out.println("test_GET_CHILD_OBJECTS");
290
        
291
        // Add your test code below by replacing the default call to fail.
292
        int failIndex = doTestingWithMask( FilterLook.GET_CHILD_OBJECTS );
293
        if ( failIndex > -1 ) {
294
            fail( getFailMessage( failIndex ) );
295
        }
296
    }
297
    
298
    public void test_GET_NEW_TYPES () {
299
        System.out.println("test_GET_NEW_TYPES");
300
        
301
        // Add your test code below by replacing the default call to fail.
302
        int failIndex = doTestingWithMask( FilterLook.GET_NEW_TYPES );
303
        if ( failIndex > -1 ) {
304
            fail( getFailMessage( failIndex ) );
305
        }
306
    }
307
    
308
    public void test_GET_ACTIONS () {
309
        System.out.println("test_GET_ACTIONS");
310
        
311
        // Add your test code below by replacing the default call to fail.
312
        int failIndex = doTestingWithMask( FilterLook.GET_ACTIONS );
313
        if ( failIndex > -1 ) {
314
            fail( getFailMessage( failIndex ) );
315
        }
316
    }
317
    
318
    public void test_GET_CONTEXT_ACTIONS () {
319
        System.out.println("test_GET_CONTEXT_ACTIONS");
320
        
321
        // Add your test code below by replacing the default call to fail.
322
        int failIndex = doTestingWithMask( FilterLook.GET_CONTEXT_ACTIONS );
323
        if ( failIndex > -1 ) {
324
            fail( getFailMessage( failIndex ) );
325
        }
326
    }
327
    
328
    public void test_GET_DEFAULT_ACTION () {
329
        System.out.println("test_GET_DEFAULT_ACTION");
330
        
331
        // Add your test code below by replacing the default call to fail.
332
        int failIndex = doTestingWithMask( FilterLook.GET_DEFAULT_ACTION );
333
        if ( failIndex > -1 ) {
334
            fail( getFailMessage( failIndex ) );
335
        }
336
    }
337
    
338
    public void test_GET_PROPERTY_SETS () {
339
        System.out.println("test_GET_PROPERTY_SETS");
340
        
341
        // Add your test code below by replacing the default call to fail.
342
        int failIndex = doTestingWithMask( FilterLook.GET_PROPERTY_SETS );
343
        if ( failIndex > -1 ) {
344
            fail( getFailMessage( failIndex ) );
345
        }
346
    }
347
    
348
    public void test_GET_CUSTOMIZER () {
349
        System.out.println("test_GET_CUSTOMIZER");
350
        
351
        // Add your test code below by replacing the default call to fail.
352
        int failIndex = doTestingWithMask( FilterLook.GET_CUSTOMIZER );
353
        if ( failIndex > -1 ) {
354
            fail( getFailMessage( failIndex ) );
355
        }
356
    }
357
    
358
    public void test_CAN_RENAME () {
359
        System.out.println("test_CAN_RENAME");
360
        
361
        // Add your test code below by replacing the default call to fail.
362
        int failIndex = doTestingWithMask( FilterLook.CAN_RENAME );
363
        if ( failIndex > -1 ) {
364
            fail( getFailMessage( failIndex ) );
365
        }
366
    }
367
    
368
    public void test_CAN_DESTROY () {
369
        System.out.println("test_CAN_DESTROY");
370
        
371
        // Add your test code below by replacing the default call to fail.
372
        int failIndex = doTestingWithMask( FilterLook.CAN_DESTROY );
373
        if ( failIndex > -1 ) {
374
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
375
        }
376
    }
377
    
378
    public void test_CAN_COPY () {
379
        System.out.println("test_CAN_COPY");
380
        
381
        // Add your test code below by replacing the default call to fail.
382
        int failIndex = doTestingWithMask( FilterLook.CAN_COPY );
383
        if ( failIndex > -1 ) {
384
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
385
        }
386
    }
387
    
388
    public void test_CAN_CUT () {
389
        System.out.println("test_CAN_CUT");
390
        
391
        // Add your test code below by replacing the default call to fail.
392
        int failIndex = doTestingWithMask( FilterLook.CAN_CUT );
393
        if ( failIndex > -1 ) {
394
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
395
        }
396
    }
397
    
398
    public void test_GET_PASTE_TYPES () {
399
        System.out.println("test_GET_PASTE_TYPES");
400
        
401
        // Add your test code below by replacing the default call to fail.
402
        int failIndex = doTestingWithMask( FilterLook.GET_PASTE_TYPES );
403
        if ( failIndex > -1 ) {
404
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
405
        }
406
    }
407
    
408
    public void test_GET_DROP_TYPE () {
409
        System.out.println("test_GET_DROP_TYPE");
410
        
411
        // Add your test code below by replacing the default call to fail.
412
        int failIndex = doTestingWithMask( FilterLook.GET_DROP_TYPE );
413
        if ( failIndex > -1 ) {
414
            fail( "Failed on method index : " + failIndex + " : "  + testingItems[ failIndex ].value );
415
        }
416
    }
417
    
418
    public void test_CLIPBOARD_COPY () {
419
        System.out.println("test_CLIPBOARD_COPY");
420
        
421
        // Add your test code below by replacing the default call to fail.
422
        int failIndex = doTestingWithMask( FilterLook.CLIPBOARD_COPY );
423
        if ( failIndex > -1 ) {
424
            fail( getFailMessage( failIndex ) );
425
        }
426
    }
427
    
428
    public void test_CLIPBOARD_CUT () {
429
        System.out.println("test_CLIPBOARD_CUT");
430
        
431
        // Add your test code below by replacing the default call to fail.
432
        int failIndex = doTestingWithMask( FilterLook.CLIPBOARD_CUT );
433
        if ( failIndex > -1 ) {
434
            fail( getFailMessage( failIndex ) );
435
        }
436
    }
437
    
438
    public void test_DRAG () {
439
        System.out.println("test_DRAG");
440
        
441
        // Add your test code below by replacing the default call to fail.
442
        int failIndex = doTestingWithMask( FilterLook.DRAG );
443
        if ( failIndex > -1 ) {
444
            fail( getFailMessage( failIndex ));
445
        }
446
    }
447
    
448
    public void test_DESTROY () {
449
        System.out.println("test_DESTROY");
450
        
451
        // Add your test code below by replacing the default call to fail.
452
        int failIndex = doTestingWithMask( FilterLook.DESTROY );
453
        if ( failIndex > -1 ) {
454
            fail( getFailMessage( failIndex ) );
455
        }
456
    }
457
    
458
    // Private methods ---------------------------------------------------------    
459
    
460
    private int doTestingWithMask( long mask ) {
461
        filterLook.setLookMask( mask );
462
        clearTestArray();
463
        fillTestArray();
464
        
465
        for( int i = 0; i < testingItems.length; i ++ ) {
466
            if ( ( ( testingItems[i].mask & mask ) > 0 && testingItems[i].value == null ) || 
467
                 ( ( testingItems[i].mask & mask ) == 0 && testingItems[i].value != null )) {
468
                return i;
469
            }
470
        }
471
        
472
        return -1;
473
    }
474
    
475
    private void clearTestArray() {
476
        for ( int i = 0; i < testingItems.length; i++ ) {
477
            testingItems[i].value = null;
478
        }
479
    }
480
        
481
    private void fillTestArray() {
482
         
483
        int i = 0;
484
            
485
        
486
        filterLook.attachTo( substitute );
487
        Boolean attachTo = sampleLook.getAttachToCalled( ) ? Boolean.TRUE : null;
488
        
489
        Node.Cookie cookie = filterLook.getCookie( substitute, COOKIE );
490
        
491
        Node.Handle handle = filterLook.getHandle( substitute );
492
        
493
        String displayName = filterLook.getDisplayName( substitute );
494
        
495
        String name = filterLook.getName( substitute );
496
        
497
        filterLook.setName(substitute, NAME_TO_SET );
498
        String setName = sampleLook.getSetNameCalled() ? NAME_TO_SET : null;
499
        
500
        String shortDescription = filterLook.getShortDescription( substitute );
501
        
502
        Image icon = filterLook.getIcon( substitute, ICON_TYPE );
503
        
504
        Image openedIcon = filterLook.getOpenedIcon( substitute, OPENED_ICON_TYPE );
505
        
506
        HelpCtx helpCtx = filterLook.getHelpCtx( substitute );
507
        
508
        Object[] children = filterLook.getChildObjects( substitute );
509
        children = children == Look.NO_KEYS ? null : children;
510
        
511
        NewType[] newTypes = filterLook.getNewTypes( substitute );
512
        newTypes = newTypes == Look.NO_NEW_TYPES ? null : newTypes;
513
        
514
        SystemAction[] systemActions = filterLook.getActions( substitute );
515
        systemActions = systemActions == Look.NO_SYSTEM_ACTIONS ? null : systemActions;
516
        
517
        SystemAction[] contextActions = filterLook.getContextActions( substitute );
518
        contextActions = contextActions == Look.NO_SYSTEM_ACTIONS ? null : contextActions;
519
        
520
        SystemAction defaultAction = filterLook.getDefaultAction( substitute );
521
        
522
        Node.PropertySet[] propertySets = filterLook.getPropertySets( substitute );
523
        propertySets = propertySets == Look.NO_PROPERTY_SETS ? null : propertySets;
524
        
525
        java.awt.Component customizer = filterLook.getCustomizer( substitute );
526
        
527
        Boolean canRename = filterLook.canRename( substitute ) ? Boolean.TRUE : null;
528
        
529
        Boolean canDestroy = filterLook.canDestroy( substitute )? Boolean.TRUE : null;
530
        
531
        Boolean canCopy = filterLook.canCopy( substitute )? Boolean.TRUE : null;
532
        
533
        Boolean canCut = filterLook.canCut( substitute )? Boolean.TRUE : null;
534
        
535
        PasteType[] pasteTypes = filterLook.getPasteTypes( substitute, PASTE_TYPE );
536
        pasteTypes = pasteTypes == Look.NO_PASTE_TYPES ? null : pasteTypes;
537
        
538
        PasteType dropType = filterLook.getDropType( substitute, DROP_TYPE, DROP_ACTION, DROP_INDEX );
539
        Transferable copy = null;
540
        try {
541
             copy = filterLook.clipboardCopy( substitute );
542
        }
543
        catch ( java.io.IOException e ) {
544
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
545
        }
546
        Transferable cut  = null;
547
        try {
548
            cut = filterLook.clipboardCut( substitute );
549
        }
550
        catch ( java.io.IOException e ) {
551
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
552
        }    
553
        Transferable drag = null;
554
        try {
555
            drag = filterLook.drag( substitute );
556
        }
557
        catch ( java.io.IOException e ) {
558
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
559
        }    
560
        Boolean destroy = null;
561
        try {
562
            filterLook.destroy( substitute );
563
            destroy = sampleLook.getDestroyCalled() ? Boolean.TRUE : null;
564
        }        
565
        catch ( java.io.IOException e ) {
566
            fail( MSSG_UNEXPECTED_EXCEPTION + e );
567
        }   
568
        
569
        
570
        testingItems[i].value = attachTo; 
571
        i++;
572
        testingItems[i].value = cookie; 
573
        i++;
574
        testingItems[i].value = handle; 
575
        i++;
576
        testingItems[i].value = displayName; 
577
        i++;
578
        testingItems[i].value = name; 
579
        i++;
580
        testingItems[i].value = setName; 
581
        i++;
582
        testingItems[i].value = shortDescription; 
583
        i++;
584
        testingItems[i].value = icon; 
585
        i++;
586
        testingItems[i].value = openedIcon; 
587
        i++;
588
        testingItems[i].value = helpCtx; 
589
        i++;
590
        testingItems[i].value = children; 
591
        i++;
592
        testingItems[i].value = newTypes; 
593
        i++;
594
        testingItems[i].value = systemActions; 
595
        i++;
596
        testingItems[i].value = contextActions; 
597
        i++;
598
        testingItems[i].value = defaultAction; 
599
        i++;
600
        testingItems[i].value = propertySets; 
601
        i++;
602
        testingItems[i].value = customizer; 
603
        i++;
604
        testingItems[i].value = canRename; 
605
        i++;
606
        testingItems[i].value = canDestroy; 
607
        i++;
608
        testingItems[i].value = canCopy; 
609
        i++;
610
        testingItems[i].value = canCut; 
611
        i++;
612
        testingItems[i].value = pasteTypes; 
613
        i++;
614
        testingItems[i].value = dropType; 
615
        i++;
616
        testingItems[i].value = copy; 
617
        i++;
618
        testingItems[i].value = cut; 
619
        i++;
620
        testingItems[i].value = drag; 
621
        i++;
622
        testingItems[i].value = destroy; 
623
        i++;
624
        
625
    }
626
    
627
    private String getFailMessage( int failIndex ) {
628
        return "Failed on method index : " + failIndex + " :  " +
629
            testingItems[ failIndex ].name +  " = " +
630
            testingItems[ failIndex ].value;
631
    }
632
        
633
    // Innerclasses ------------------------------------------------------------
634
  
635
    /** Represents one item in the test array.
636
     */     
637
    private class TestingItem {
638
639
        private long mask;
640
641
        private Object value;
642
643
        private String name;
644
        
645
        
646
        TestingItem( long mask, String name  ) {
647
            this.mask = mask;
648
            this.name = name;
649
        }
650
651
    }    
652
   
653
}
(-)openidex/test/unit/src/org/openidex/nodes/looks/LookNodeEventsTest.java (-535 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
15
package org.openidex.nodes.looks;
16
17
import java.beans.*;
18
import java.awt.Image;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.event.ActionListener;
21
import java.awt.event.ActionEvent;
22
import java.io.IOException;
23
import java.util.ArrayList;
24
25
import javax.swing.event.ChangeListener;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.JMenuItem;
28
import javax.swing.JMenu;
29
import javax.swing.event.MenuListener;
30
import javax.swing.event.MenuEvent;
31
32
import org.openide.nodes.*;
33
import org.openide.util.HelpCtx;
34
import org.openide.util.NbBundle;
35
import org.openide.util.actions.SystemAction;
36
import org.openide.util.datatransfer.NewType;
37
import org.openide.util.datatransfer.PasteType;
38
import org.openide.awt.JMenuPlus;
39
import org.openide.util.actions.CallableSystemAction;
40
import org.openide.util.actions.Presenter;
41
import org.openide.awt.Actions;
42
import org.openide.util.HelpCtx;
43
import org.openide.actions.SaveAllAction;
44
import org.openide.util.actions.NodeAction;
45
46
//import junit.framework.*;
47
import org.netbeans.junit.*;
48
49
public class LookNodeEventsTest extends NbTestCase {
50
    
51
    /** Sample look we test against */
52
    SampleLook1Hid sampleLook;
53
    
54
    /** The node to test on */
55
    LookNode lookNode;
56
    
57
    /** NodeSubstitute for the lookNode */
58
    Look.NodeSubstitute nodeSubstitute;
59
    
60
    /** Represented object of the tested node */
61
    String representedObject;
62
    
63
    /** The test listener used for the node */
64
    TestNodeListener testNodeListener;
65
    
66
    /** Property change listener */
67
    TestPropertyChangeListener testPcl;
68
    
69
    // Constants for testing
70
    
71
    String TEST_PROP_NAME = "TestPropName";
72
    String TEST_PROP_OLD = "TestPropOld";
73
    String TEST_PROP_NEW = "TestPropNew";
74
    
75
    
76
    String OLD_NAME = "OldName";
77
    String NEW_NAME = "NewName";
78
    
79
    String OLD_DISPLAY_NAME = "OldDisplayName";
80
    String NEW_DISPLAY_NAME = "NewDisplayName";
81
    
82
    String OLD_SHORT_DESCRIPTION = "OldShortDescription";
83
    String NEW_SHORT_DESCRIPTION = "NewShortDescription";
84
    
85
    static final Node.PropertySet[] OLD_PROPERTY_SETS = new Node.PropertySet[] {
86
        new Sheet.Set(),
87
        new Sheet.Set()
88
    };
89
    
90
    static final Node.PropertySet[] NEW_PROPERTY_SETS = new Node.PropertySet[] {
91
        new Sheet.Set(),
92
        new Sheet.Set()
93
    };
94
    
95
    public LookNodeEventsTest(java.lang.String testName) {
96
        super(testName);
97
    }
98
    
99
    public static void main(java.lang.String[] args) {
100
        junit.textui.TestRunner.run(suite());
101
    }
102
    
103
    public static NbTest suite() {
104
        NbTestSuite suite = new NbTestSuite(LookNodeEventsTest.class);
105
        //suite.addTest(SetLookActionTest.suite());
106
        
107
        return suite;
108
    }
109
    
110
    protected void setUp() throws Exception {
111
        super.setUp();
112
        
113
        // add specific setup code here
114
        sampleLook = new SampleLook1Hid();
115
        representedObject = "RepresentedObject";
116
        lookNode = new LookNode( representedObject, sampleLook );
117
        nodeSubstitute = sampleLook.getSubstituteForNode( lookNode );
118
        testNodeListener = new TestNodeListener();
119
        lookNode.addNodeListener( testNodeListener );
120
        testPcl = new TestPropertyChangeListener();
121
        lookNode.addPropertyChangeListener( testPcl );
122
    }
123
    
124
    protected void tearDown() throws Exception {
125
        // add specific tear-down code here
126
        nodeSubstitute = null;
127
        sampleLook = null;
128
        lookNode = null;
129
        representedObject = null;
130
        
131
        super.tearDown();
132
    }
133
        
134
    
135
    public void testGetRepresentedObject() {
136
        System.out.println("testGetRepresentedObject");
137
        
138
        // Add your test code below by replacing the default call to fail.
139
        if ( nodeSubstitute.getRepresentedObject() != representedObject )  {
140
            fail( "Bad represented object." );
141
        }
142
    }
143
144
   
145
    public void testFirePropertyChange() {
146
        System.out.println("testFirePropertyChange");
147
        
148
        // Add your test code below by replacing the default call to fail.
149
        testNodeListener.clearTestData();
150
        nodeSubstitute.firePropertyChange( TEST_PROP_NAME, TEST_PROP_OLD, TEST_PROP_NEW );
151
        
152
        ArrayList testData = testPcl.getTestData();
153
        
154
        if ( testData.size() != 1 ) {
155
            fail( "Bad number of events : " + testData.size() );
156
        }
157
        
158
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
159
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
160
        }
161
        
162
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
163
        String evntEv = evaluatePropertyChangeEvent( 
164
            pev, lookNode, TEST_PROP_NAME, TEST_PROP_OLD, TEST_PROP_NEW );
165
        
166
        if ( evntEv != null ) {
167
            fail( evntEv );
168
        }
169
    }
170
    
171
172
    public void testFireNameChange() {
173
        System.out.println("testFireNameChange");
174
        
175
        // Add your test code below by replacing the default call to fail.
176
        testNodeListener.clearTestData();
177
        nodeSubstitute.fireNameChange( OLD_NAME, NEW_NAME );
178
        
179
        ArrayList testData = testNodeListener.getTestData();
180
        
181
        if ( testData.size() != 1 ) {
182
            fail( "Bad number of events : " + testData.size() );
183
        }
184
        
185
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
186
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
187
        }
188
        
189
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
190
        String evntEv = evaluatePropertyChangeEvent( 
191
            pev, lookNode, Node.PROP_NAME, OLD_NAME, NEW_NAME );
192
        
193
        if ( evntEv != null ) {
194
            fail( evntEv );
195
        }
196
    }
197
198
    public void testFireDisplayNameChange() {
199
        System.out.println("testFireDisplayNameChange");
200
        
201
        // Add your test code below by replacing the default call to fail.
202
        testNodeListener.clearTestData();
203
        nodeSubstitute.fireDisplayNameChange( OLD_DISPLAY_NAME, NEW_DISPLAY_NAME );
204
        
205
        ArrayList testData = testNodeListener.getTestData();
206
        
207
        if ( testData.size() != 1 ) {
208
            fail( "Bad number of events : " + testData.size() );
209
        }
210
        
211
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
212
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
213
        }
214
        
215
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
216
        String evntEv = evaluatePropertyChangeEvent( 
217
            pev, lookNode, Node.PROP_DISPLAY_NAME, OLD_DISPLAY_NAME, NEW_DISPLAY_NAME );
218
        
219
        if ( evntEv != null ) {
220
            fail( evntEv );
221
        }
222
    }
223
224
    public void testFireShortDescriptionChange() {
225
        System.out.println("testFireShortDescriptionChange");
226
        
227
        // Add your test code below by replacing the default call to fail.
228
        testNodeListener.clearTestData();
229
        nodeSubstitute.fireShortDescriptionChange( OLD_SHORT_DESCRIPTION, NEW_SHORT_DESCRIPTION );
230
        
231
        ArrayList testData = testNodeListener.getTestData();
232
        
233
        if ( testData.size() != 1 ) {
234
            fail( "Bad number of events : " + testData.size() );
235
        }
236
        
237
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
238
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
239
        }
240
        
241
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
242
        String evntEv = evaluatePropertyChangeEvent( 
243
            pev, lookNode, Node.PROP_SHORT_DESCRIPTION, OLD_SHORT_DESCRIPTION, NEW_SHORT_DESCRIPTION );
244
        
245
        if ( evntEv != null ) {
246
            fail( evntEv );
247
        }
248
    }
249
250
    public void testFireIconChange() {
251
        System.out.println("testFireIconChange");
252
        
253
        // Add your test code below by replacing the default call to fail.
254
        testNodeListener.clearTestData();
255
        nodeSubstitute.fireIconChange();
256
        
257
        ArrayList testData = testNodeListener.getTestData();
258
        
259
        if ( testData.size() != 1 ) {
260
            fail( "Bad number of events : " + testData.size() );
261
        }
262
        
263
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
264
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
265
        }
266
        
267
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
268
        String evntEv = evaluatePropertyChangeEvent( 
269
            pev, lookNode, Node.PROP_ICON, null, null );
270
        
271
        if ( evntEv != null ) {
272
            fail( evntEv );
273
        }
274
    }
275
276
    public void testFireOpenedIconChange() {
277
        System.out.println("testFireOpenedIconChange");
278
        
279
        // Add your test code below by replacing the default call to fail.
280
        testNodeListener.clearTestData();
281
        nodeSubstitute.fireOpenedIconChange();
282
        
283
        ArrayList testData = testNodeListener.getTestData();
284
        
285
        if ( testData.size() != 1 ) {
286
            fail( "Bad number of events : " + testData.size() );
287
        }
288
        
289
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
290
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
291
        }
292
        
293
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
294
        String evntEv = evaluatePropertyChangeEvent( 
295
            pev, lookNode, Node.PROP_OPENED_ICON, null, null );
296
        
297
        if ( evntEv != null ) {
298
            fail( evntEv );
299
        }
300
    }
301
302
    public void testFirePropertySetsChange() {
303
        System.out.println("testFirePropertySetsChange");
304
        
305
        // Add your test code below by replacing the default call to fail.
306
        testNodeListener.clearTestData();
307
        nodeSubstitute.firePropertySetsChange( OLD_PROPERTY_SETS, NEW_PROPERTY_SETS );
308
        
309
        ArrayList testData = testNodeListener.getTestData();
310
        
311
        if ( testData.size() != 1 ) {
312
            fail( "Bad number of events : " + testData.size() );
313
        }
314
        
315
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
316
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
317
        }
318
        
319
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
320
        String evntEv = evaluatePropertyChangeEvent( 
321
            pev, lookNode, Node.PROP_PROPERTY_SETS, OLD_PROPERTY_SETS, NEW_PROPERTY_SETS );
322
        
323
        if ( evntEv != null ) {
324
            fail( evntEv );
325
        }
326
327
    }
328
329
    public void testFireCookieChange() {
330
        System.out.println("testFireCookieChange");
331
        
332
        // Add your test code below by replacing the default call to fail.
333
        testNodeListener.clearTestData();
334
        nodeSubstitute.fireCookieChange();
335
        
336
        ArrayList testData = testNodeListener.getTestData();
337
        
338
        if ( testData.size() != 1 ) {
339
            fail( "Bad number of events : " + testData.size() );
340
        }
341
        
342
        if ( !(testData.get( 0 ) instanceof PropertyChangeEvent ) ) {
343
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
344
        }
345
        
346
        PropertyChangeEvent pev = (PropertyChangeEvent)testData.get( 0 );
347
        String evntEv = evaluatePropertyChangeEvent( 
348
            pev, lookNode, Node.PROP_COOKIE, null, null );
349
        
350
        if ( evntEv != null ) {
351
            fail( evntEv );
352
        }
353
    }
354
355
    public void testFireNodeDestroyed() {
356
        System.out.println("testFireNodeDestroyed");
357
        
358
        // Add your test code below by replacing the default call to fail.
359
        testNodeListener.clearTestData();
360
        nodeSubstitute.fireNodeDestroyed();
361
        
362
        ArrayList testData = testNodeListener.getTestData();
363
        
364
        if ( testData.size() != 1 ) {
365
            fail( "Bad number of events : " + testData.size() );
366
        }
367
        
368
        if ( !(testData.get( 0 ) instanceof NodeEvent ) ) {
369
            fail( "Bad event type : " + testData.get( 0 ).getClass() );
370
        }
371
        
372
        NodeEvent nev = (NodeEvent)testData.get( 0 );        
373
        if ( nev.getNode() != lookNode ) {
374
            fail( "bad node : " + nev.getNode() );
375
        }
376
    }
377
    
378
    public void testAddChildren() {
379
        System.out.println("testAddChildren");
380
        
381
        // Add your test code below by replacing the default call to fail.
382
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
383
        lookNode.getChildren().getNodes();
384
385
        testNodeListener.clearTestData();
386
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_ADDED );
387
        nodeSubstitute.refreshChildren();
388
        
389
        ArrayList testData = testNodeListener.getTestData();
390
        
391
        if ( testData.size() != 1 ) {
392
            fail( "Bad number of events : " + testData.size() );
393
        }
394
        
395
    }
396
    
397
    public void testRemoveChildren() {
398
        System.out.println("testRemoveChildren");
399
        
400
        // Add your test code below by replacing the default call to fail.
401
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_ADDED );
402
        lookNode.getChildren().getNodes();
403
        
404
        testNodeListener.clearTestData();
405
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_REMOVED );
406
        nodeSubstitute.refreshChildren();
407
        
408
        ArrayList testData = testNodeListener.getTestData();
409
        
410
        if ( testData.size() != 1 ) {
411
            fail( "Bad number of events : " + testData.size() );
412
        }
413
    }
414
    
415
    public void testReorderChildren() {
416
        System.out.println("testReorderChildren");
417
        
418
        // Add your test code below by replacing the default call to fail.
419
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
420
        lookNode.getChildren().getNodes();
421
        
422
        testNodeListener.clearTestData();
423
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_REORDERED );
424
        nodeSubstitute.refreshChildren();
425
        
426
        ArrayList testData = testNodeListener.getTestData();
427
        
428
        if ( testData.size() != 1 ) {
429
            fail( "Bad number of events : " + testData.size() );
430
        }
431
    }
432
    
433
    public void testNoChildrenChange() {
434
        System.out.println("testNoChildrenChange");
435
        
436
        // Add your test code below by replacing the default call to fail.
437
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS );
438
        lookNode.getChildren().getNodes();
439
        
440
        testNodeListener.clearTestData();
441
        sampleLook.setKeys( SampleLook1Hid.VAL_KEYS_NO_CHANGE );
442
        nodeSubstitute.refreshChildren();
443
        
444
        ArrayList testData = testNodeListener.getTestData();
445
        
446
        if ( testData.size() != 0 ) {
447
            fail( "Bad number of events : " + testData.size() );
448
        }
449
    }
450
    
451
    // private methods ---------------------------------------------------------
452
    
453
    private String evaluatePropertyChangeEvent( PropertyChangeEvent pev,
454
        Object source, String name, Object oldValue, Object newValue ) {
455
        
456
        if ( pev.getSource() != source ) {
457
            return "Bad event source : " + pev.getSource();
458
        }
459
        if ( pev.getPropertyName() != name ) {
460
            return "Bad propertyName : " + pev.getPropertyName();
461
        }
462
        if ( pev.getOldValue() != oldValue ) {
463
            return "Bad old name : " + pev.getOldValue();
464
        }
465
        if ( pev.getNewValue() != newValue ) {
466
            return "Bad new name : " + pev.getOldValue();
467
        }
468
        
469
        return null;
470
    }
471
    
472
    // private classes ---------------------------------------------------------
473
    
474
    private static class TestNodeListener implements NodeListener {
475
        
476
        private ArrayList eventsList;
477
        
478
        TestNodeListener() {
479
            clearTestData();
480
        }
481
        
482
        public void nodeDestroyed( NodeEvent ev ) {
483
            eventsList.add( ev );
484
        }
485
        
486
        public void childrenRemoved( NodeMemberEvent ev ) {
487
            eventsList.add( ev );
488
        }
489
        
490
        public void childrenReordered( NodeReorderEvent ev ) {
491
            eventsList.add( ev );
492
        }
493
        
494
        public void propertyChange( PropertyChangeEvent ev ) {
495
            eventsList.add( ev );
496
        }
497
        
498
        public void childrenAdded( NodeMemberEvent ev ) {
499
            eventsList.add( ev );
500
        }
501
        
502
        void clearTestData() {
503
            eventsList = new ArrayList();
504
        }
505
        
506
        ArrayList getTestData() {
507
            return eventsList;
508
        }
509
        
510
    }
511
    
512
    
513
    private static class TestPropertyChangeListener implements PropertyChangeListener {
514
        
515
        ArrayList eventsList;
516
        
517
        TestPropertyChangeListener() {
518
            clearTestData();
519
        }
520
        
521
        public void propertyChange(PropertyChangeEvent pce ) {
522
            eventsList.add( pce );
523
        }
524
        
525
        void clearTestData() {
526
            eventsList = new ArrayList();
527
        }
528
        
529
        ArrayList getTestData() {
530
            return eventsList;
531
        }
532
        
533
    }
534
}
535
(-)openidex/test/unit/src/org/openidex/nodes/looks/LookNodeTest.java (-507 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.beans.*;
17
import java.awt.Image;
18
import java.awt.datatransfer.Transferable;
19
import java.awt.event.ActionListener;
20
import java.awt.event.ActionEvent;
21
import java.io.IOException;
22
import javax.swing.event.ChangeListener;
23
import javax.swing.event.ChangeEvent;
24
import javax.swing.JMenuItem;
25
import javax.swing.JMenu;
26
import javax.swing.event.MenuListener;
27
import javax.swing.event.MenuEvent;
28
import org.openide.nodes.*;
29
import org.openide.util.HelpCtx;
30
import org.openide.util.NbBundle;
31
import org.openide.util.actions.SystemAction;
32
import org.openide.util.datatransfer.NewType;
33
import org.openide.util.datatransfer.PasteType;
34
import org.openide.awt.JMenuPlus;
35
import org.openide.util.actions.CallableSystemAction;
36
import org.openide.util.actions.Presenter;
37
import org.openide.awt.Actions;
38
import org.openide.util.HelpCtx;
39
import org.openide.actions.SaveAllAction;
40
import org.openide.util.actions.NodeAction;
41
//import junit.framework.*;
42
import org.netbeans.junit.*;
43
import org.openide.util.Utilities;
44
import junit.framework.*;
45
46
public class LookNodeTest extends NbTestCase {
47
    
48
    /** Sample look we test against */
49
    SampleLook1Hid sampleLook;
50
    
51
    /** Second sample look for testing */
52
    SampleLook2Hid sampleLook2;
53
    
54
    /** The node to test on */
55
    LookNode lookNode;
56
    
57
    /** Represented object of the tested node */
58
    String representedObject;
59
    
60
    public LookNodeTest(java.lang.String testName) {
61
        super(testName);
62
    }
63
    
64
    public static void main(java.lang.String[] args) {
65
        junit.textui.TestRunner.run(suite());
66
    }
67
    
68
    protected void setUp() throws Exception {
69
        super.setUp();
70
        
71
        // add specific setup code here
72
        sampleLook = new SampleLook1Hid();
73
        sampleLook2 = new SampleLook2Hid();
74
        representedObject = "RepresentedObject";
75
        lookNode = new LookNode( representedObject, sampleLook );
76
        //look is hard set by this contructor
77
        //assert("Too eager initialization!", lookNode.getHardLook() == null);
78
    }
79
    
80
    protected void tearDown() throws Exception {
81
        // add specific tear-down code here
82
        sampleLook = null;
83
        lookNode = null;
84
        representedObject = null;
85
        
86
        super.tearDown();
87
    }
88
    
89
    /** Test of getSubstitute method, of class org.openidex.nodes.looks.LookNode. */
90
    public void testGetSubstitute() {
91
        System.out.println("testGetSubstitute");
92
        
93
        // Add your test code below by replacing the default call to fail.
94
        Look.NodeSubstitute substitute = lookNode.getSubstitute( );
95
        if ( substitute != sampleLook.getSubstituteForNode( lookNode)  ) {
96
            fail("Bad nodeSubstitute.");
97
        }
98
    }
99
    
100
    
101
    /** Test of getRepresentedObject method, of class org.openidex.nodes.looks.LookNode. */
102
    
103
    public void testGetRepresentedObject() {
104
        System.out.println("testGetRepresentedObject");
105
        
106
        // Add your test code below by replacing the default call to fail.
107
        String ro = (String)lookNode.getRepresentedObject( );
108
        if ( ro != representedObject ) {
109
            fail("Bad represented object.");
110
        }
111
    }
112
    
113
    
114
    /** Test of setLook method, of class org.openidex.nodes.looks.LookNode. */
115
    public void testSetLook() {
116
        System.out.println("testSetLook");
117
        
118
        // Add your test code below by replacing the default call to fail.
119
        lookNode.setLook( sampleLook2 );
120
        if ( lookNode.getLook() != sampleLook2 ) {
121
            fail( "look not set" );
122
        }
123
        
124
        lookNode.setLook( sampleLook );
125
        if ( lookNode.getLook() != sampleLook ) {
126
            fail( "look not set" );
127
        }
128
    }
129
    
130
    
131
    /** Test of refreshChildren method, of class org.openidex.nodes.looks.LookNode. */
132
    // Tested in LookNodeEventsTest
133
    /*
134
    public void testRefreshChildren() {
135
        System.out.println("testRefreshChildren");
136
        
137
        // Add your test code below by replacing the default call to fail.
138
        fail("The test case is empty.");
139
    }
140
    */
141
    
142
    /** Test of getLook method, of class org.openidex.nodes.looks.LookNode. */
143
    public void testGetLook() {
144
        System.out.println("testGetLook");
145
        
146
        // Add your test code below by replacing the default call to fail.
147
        
148
        Look look = lookNode.getLook();
149
        if ( look != sampleLook ) {
150
            fail("Look not returned.");
151
        }
152
    }
153
    
154
    /** Test of getCookie method, of class org.openidex.nodes.looks.LookNode. */
155
    public void testGetCookie() {
156
        System.out.println("testGetCookie");
157
        
158
        // Add your test code below by replacing the default call to fail.
159
        Node.Cookie cookie = lookNode.getCookie( Object.class );
160
        if ( cookie != SampleLook1Hid.VAL_COOKIE ) {
161
            fail("Bad cookie.");
162
        }
163
    }
164
    
165
    /** Test of getHandle method, of class org.openidex.nodes.looks.LookNode. */
166
    public void testGetHandle() {
167
        System.out.println("testGetHandle");
168
        
169
        // Add your test code below by replacing the default call to fail.
170
        Node.Handle handle = lookNode.getHandle( );
171
        if ( handle != SampleLook1Hid.VAL_HANDLE ) {
172
            fail("Bad handle.");
173
        }
174
    }
175
    
176
    /** Test of cloneNode method, of class org.openidex.nodes.looks.LookNode. */
177
    public void testCloneNode() {
178
        System.out.println("testCloneNode");
179
        
180
        // Add your test code below by replacing the default call to fail.
181
        Look look = sampleLook2;
182
        LookNode lookNode = new LookNode(new Object(), look);
183
        
184
        LookNode clonedNode = (LookNode)lookNode.cloneNode();
185
        LookNode secondLevelClone = (LookNode) clonedNode.cloneNode();
186
        
187
        assert("Cloned node must not be null!", clonedNode != null );        
188
        assert("Cloned node must be a chameleon!", clonedNode.getHardLook() == null);
189
        assert("Second level clone has different hard look!", clonedNode.getHardLook() == secondLevelClone.getHardLook());
190
//        assert("Second level clone has different hard look candidate!", clonedNode.getHardLookCandidate() == secondLevelClone.getHardLookCandidate());
191
192
        // we do not have any parent node so we do not use chameleon look but rather hard look candidate
193
        
194
        assert("Both clones must result in same getLook()!", clonedNode.getLook() == secondLevelClone.getLook());
195
        
196
    }
197
    
198
    
199
    /** Test of getDisplayName method, of class org.openidex.nodes.looks.LookNode. */
200
    public void testGetDisplayName() {
201
        System.out.println("testGetDisplayName");
202
        
203
        // Add your test code below by replacing the default call to fail.
204
        String displayName = lookNode.getDisplayName( );
205
        if ( displayName != SampleLook1Hid.VAL_DISPLAY_NAME ) {
206
            fail("Bad displayName.");
207
        }
208
    }
209
    
210
    /** Test of setDisplayName method, of class org.openidex.nodes.looks.LookNode. */
211
    public void testSetDisplayName() {
212
        System.out.println("testSetDisplayName");
213
        
214
        // Add your test code below by replacing the default call to fail.
215
        // fail("The test case is empty.");
216
    }
217
    
218
    /** Test of getName method, of class org.openidex.nodes.looks.LookNode. */
219
    public void testGetName() {
220
        System.out.println("testGetName");
221
        
222
        // Add your test code below by replacing the default call to fail.
223
        String name = lookNode.getName( );
224
        if ( name != SampleLook1Hid.VAL_NAME ) {
225
            fail("Bad name.");
226
        }
227
    }
228
    
229
    /** Test of setName method, of class org.openidex.nodes.looks.LookNode. */
230
    public void testSetName() {
231
        System.out.println("testSetName");
232
        
233
        // Add your test code below by replacing the default call to fail.
234
        lookNode.setName( "Some name" );
235
        if ( !sampleLook.getSetNameCalled() ) {
236
            fail("setName not called.");
237
        }
238
    }
239
    
240
    /** Test of getShortDescription method, of class org.openidex.nodes.looks.LookNode. */
241
    public void testGetShortDescription() {
242
        System.out.println("testGetShortDescription");
243
        
244
        // Add your test code below by replacing the default call to fail.
245
        String shortDescription = lookNode.getShortDescription( );
246
        if ( shortDescription != SampleLook1Hid.VAL_SHORT_DESCRIPTION ) {
247
            fail("Bad shortDescription.");
248
        }
249
    }
250
    
251
    /** Test of getIcon method, of class org.openidex.nodes.looks.LookNode. */
252
    public void testGetIcon() {
253
        System.out.println("testGetIcon");
254
        
255
        // Add your test code below by replacing the default call to fail.
256
        Image icon = lookNode.getIcon( 0 );
257
        if ( icon != SampleLook1Hid.VAL_ICON ) {
258
            fail("Bad icon.");
259
        }
260
    }
261
    
262
    /** Test of getOpenedIcon method, of class org.openidex.nodes.looks.LookNode. */
263
    public void testGetOpenedIcon() {
264
        System.out.println("testGetOpenedIcon");
265
        
266
        // Add your test code below by replacing the default call to fail.
267
        Image openedIcon = lookNode.getOpenedIcon( 0 );
268
        if ( openedIcon != SampleLook1Hid.VAL_OPENED_ICON ) {
269
            fail("Bad openedIcon.");
270
        }
271
    }
272
    
273
    /** Test of getHelpCtx method, of class org.openidex.nodes.looks.LookNode. */
274
    public void testGetHelpCtx() {
275
        System.out.println("testGetHelpCtx");
276
        
277
        // Add your test code below by replacing the default call to fail.
278
        HelpCtx helpCtx = lookNode.getHelpCtx( );
279
        if ( helpCtx != SampleLook1Hid.VAL_HELP_CTX ) {
280
            fail("Bad helpCtx.");
281
        }
282
    }
283
    
284
    /** Test of getNewTypes method, of class org.openidex.nodes.looks.LookNode. */
285
    public void testGetNewTypes() {
286
        System.out.println("testGetNewTypes");
287
        
288
        // Add your test code below by replacing the default call to fail.
289
        NewType[] newTypes = lookNode.getNewTypes( );
290
        if ( newTypes != SampleLook1Hid.VAL_NEW_TYPES ) {
291
            fail("Bad newTypes.");
292
        }
293
    }
294
    
295
    /** Test of getActions method, of class org.openidex.nodes.looks.LookNode. */
296
    public void testGetActions() {
297
        System.out.println("testGetActions");
298
        
299
        // Add your test code below by replacing the default call to fail.
300
        SystemAction[] actions = lookNode.getActions( );
301
        if ( actions != SampleLook1Hid.VAL_ACTIONS ) {
302
            fail("Bad actions.");
303
        }
304
    }
305
    
306
    /** Test of getContextActions method, of class org.openidex.nodes.looks.LookNode. */
307
    public void testGetContextActions() {
308
        System.out.println("testGetContextActions");
309
        
310
        // Add your test code below by replacing the default call to fail.
311
        SystemAction[] contextActions = lookNode.getContextActions( );
312
        if ( contextActions != SampleLook1Hid.VAL_CONTEXT_ACTIONS ) {
313
            fail("Bad contextActions.");
314
        }
315
    }
316
    
317
    /** Test of getDefaultAction method, of class org.openidex.nodes.looks.LookNode. */
318
    public void testGetDefaultAction() {
319
        System.out.println("testGetDefaultAction");
320
        
321
        // Add your test code below by replacing the default call to fail.
322
        SystemAction defaultAction = lookNode.getDefaultAction( );
323
        if ( defaultAction != SampleLook1Hid.VAL_DEFAULT_ACTION ) {
324
            fail("Bad defaultAction.");
325
        }
326
    }
327
    
328
    /** Test of getPropertySets method, of class org.openidex.nodes.looks.LookNode. */
329
    public void testGetPropertySets() {
330
        System.out.println("testGetPropertySets");
331
        
332
        // Add your test code below by replacing the default call to fail.
333
        Node.PropertySet[] propertySets = lookNode.getPropertySets( );
334
        if ( propertySets != SampleLook1Hid.VAL_PROPERTY_SETS ) {
335
            fail("Bad propertySets.");
336
        }
337
    }
338
    
339
    /** Test of getCustomizer method, of class org.openidex.nodes.looks.LookNode. */
340
    public void testGetCustomizer() {
341
        System.out.println("testGetCustomizer");
342
        
343
        // Add your test code below by replacing the default call to fail.
344
        java.awt.Component customizer = lookNode.getCustomizer( );
345
        if ( customizer != SampleLook1Hid.VAL_CUSTOMIZER ) {
346
            fail("Bad customizer.");
347
        }
348
    }
349
    
350
    /** Test of hasCustomizer method, of class org.openidex.nodes.looks.LookNode. */
351
    public void testHasCustomizer() {
352
        System.out.println("testHasCustomizer");
353
        
354
        // Add your test code below by replacing the default call to fail.
355
        boolean hasCustomizer = lookNode.hasCustomizer();
356
        if ( hasCustomizer != true ) {
357
            fail("Bad hasCustomizedr value");
358
        }
359
        
360
        LookNode extraNode = new LookNode( representedObject, new DefaultLook() );
361
        hasCustomizer = extraNode.hasCustomizer();
362
        if ( hasCustomizer != false ) {
363
            fail("Bad hasCustomizedr value");
364
        }    
365
    }
366
    
367
    /** Test of canRename method, of class org.openidex.nodes.looks.LookNode. */
368
    public void testCanRename() {
369
        System.out.println("testCanRename");
370
        
371
        // Add your test code below by replacing the default call to fail.
372
        boolean canRename = lookNode.canRename();
373
        if ( canRename != true ) {
374
            fail("Bad value canRename");
375
        }
376
    }
377
    
378
    /** Test of canDestroy method, of class org.openidex.nodes.looks.LookNode. */
379
    public void testCanDestroy() {
380
        System.out.println("testCanDestroy");
381
        
382
        // Add your test code below by replacing the default call to fail.
383
        boolean canDestroy = lookNode.canDestroy();
384
        if ( canDestroy != true ) {
385
            fail("Bad value canDestroy");
386
        }
387
    }
388
    
389
    /** Test of canCopy method, of class org.openidex.nodes.looks.LookNode. */
390
    public void testCanCopy() {
391
        System.out.println("testCanCopy");
392
        
393
        // Add your test code below by replacing the default call to fail.
394
        boolean canCopy = lookNode.canCopy();
395
        if ( canCopy != true ) {
396
            fail("Bad value canCopy");
397
        }
398
    }
399
    
400
    /** Test of canCut method, of class org.openidex.nodes.looks.LookNode. */
401
    public void testCanCut() {
402
        System.out.println("testCanCut");
403
        
404
        // Add your test code below by replacing the default call to fail.
405
        boolean canCut = lookNode.canCut();
406
        if ( canCut != true ) {
407
            fail("Bad value canCut");
408
        }
409
    }
410
    
411
    /** Test of getPasteTypes method, of class org.openidex.nodes.looks.LookNode. */
412
    public void testGetPasteTypes() {
413
        System.out.println("testGetPasteTypes");
414
        
415
        // Add your test code below by replacing the default call to fail.
416
        PasteType pasteTypes[] = lookNode.getPasteTypes( null );
417
        if ( pasteTypes != SampleLook1Hid.VAL_PASTE_TYPES ) {            
418
            fail("Bad value pasteTypes");
419
        }
420
    }
421
    
422
    /** Test of getDropType method, of class org.openidex.nodes.looks.LookNode. */
423
    public void testGetDropType() {
424
        System.out.println("testGetDropType");
425
        
426
        // Add your test code below by replacing the default call to fail.
427
        PasteType dropType = lookNode.getDropType( null, 0, 0 );
428
        if ( dropType != SampleLook1Hid.VAL_DROP_TYPE ) {            
429
            fail("Bad value dropType");
430
        }
431
    }
432
    
433
    /** Test of clipboardCopy method, of class org.openidex.nodes.looks.LookNode. */
434
    public void testClipboardCopy() {
435
        System.out.println("testClipboardCopy");
436
        
437
        // Add your test code below by replacing the default call to fail.
438
        try {
439
            Transferable clipboardCopy= lookNode.clipboardCopy( );
440
            if ( clipboardCopy != SampleLook1Hid.VAL_CLIPBOARD_COPY ) {            
441
                fail("Bad value clipboardCopy");
442
            }
443
        }
444
        catch ( IOException e ) {
445
            fail("Exception thrown : " + e);
446
        }
447
    }
448
    
449
    /** Test of clipboardCut method, of class org.openidex.nodes.looks.LookNode. */
450
    public void testClipboardCut() {
451
        System.out.println("testClipboardCut");
452
        
453
        // Add your test code below by replacing the default call to fail.
454
        try {
455
            Transferable clipboardCut= lookNode.clipboardCut( );
456
            if ( clipboardCut != SampleLook1Hid.VAL_CLIPBOARD_CUT ) {            
457
                fail("Bad value clipboardCut");
458
            }
459
        }
460
        catch ( IOException e ) {
461
            fail("Exception thrown : " + e);
462
        }
463
    }
464
    
465
    /** Test of drag method, of class org.openidex.nodes.looks.LookNode. */
466
    public void testDrag() {
467
        System.out.println("testDrag");
468
        
469
        // Add your test code below by replacing the default call to fail.
470
        try {
471
            Transferable drag = lookNode.drag( );
472
            if ( drag != SampleLook1Hid.VAL_DRAG ) {            
473
                fail("Bad value drag");
474
            }
475
        }
476
        catch ( IOException e ) {
477
            fail("Exception thrown : " + e);
478
        }
479
    }
480
    
481
    /** Test of destroy method, of class org.openidex.nodes.looks.LookNode. */
482
    public void testDestroy() {
483
        System.out.println("testDestroy");
484
        
485
        // Add your test code below by replacing the default call to fail.
486
        try {
487
            lookNode.destroy();
488
            if ( !sampleLook.getDestroyCalled() ) {
489
                fail("Destroy not called.");
490
            }
491
        }
492
        catch ( IOException e ) {
493
            fail("Exception thrown : " + e);
494
        }
495
    }
496
    
497
    public static Test suite() {
498
        TestSuite suite = new NbTestSuite(LookNodeTest.class);
499
        
500
        return suite;
501
    }    
502
503
    
504
}
505
506
507
(-)openidex/test/unit/src/org/openidex/nodes/looks/SampleLook1Hid.java (-421 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.List;
17
import java.awt.Image;
18
import java.awt.image.BufferedImage;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.datatransfer.StringSelection;
21
import java.io.IOException;
22
import java.lang.reflect.*;
23
import java.util.Hashtable;
24
import javax.swing.JPanel;
25
26
import org.openide.nodes.*;
27
import org.openide.loaders.XMLDataObject;
28
import org.openide.util.actions.SystemAction;
29
import org.openide.util.actions.CallableSystemAction;
30
import org.openide.util.HelpCtx;
31
import org.openide.util.datatransfer.NewType;
32
import org.openide.util.datatransfer.PasteType;
33
34
/** Class used for testing. Every method returns some value. Usefull for testing 
35
 * FilterLook.
36
 *
37
 * @author Petr Hrebejk
38
 */
39
class SampleLook1Hid extends Look {
40
    
41
    // Flags for method calls which do not return any value.
42
    boolean attachToCalled = false;
43
    boolean setNameCalled = false;
44
    boolean destroyCalled = false;
45
       
46
    // The values which are returned from this Look
47
    static final Node.Cookie VAL_COOKIE = new Node.Cookie() {};
48
    
49
    static final Node.Handle VAL_HANDLE = new Node.Handle() {
50
        public Node getNode() {
51
            return null;
52
        }
53
    };
54
    
55
    static final String VAL_NAME = "Node.Name";
56
    
57
    static final String VAL_DISPLAY_NAME = "Node.DisplayName";
58
    
59
    static final String VAL_SHORT_DESCRIPTION = "Node.ShortDescription";
60
    
61
    static final String[] VAL_KEYS = new String[] {
62
        "Child.1",
63
        "Child.2"
64
    };
65
    
66
    static final String[] VAL_KEYS_ADDED = new String[] {
67
        VAL_KEYS[0],
68
        "Child.1.a",
69
        VAL_KEYS[1]
70
    };
71
    
72
    static final String[] VAL_KEYS_REMOVED = new String[] {
73
        VAL_KEYS[0],
74
    };
75
    
76
    static final String[] VAL_KEYS_REORDERED = new String[] {
77
        VAL_KEYS[1],
78
        VAL_KEYS[0]
79
    };
80
    
81
    static final String[] VAL_KEYS_NO_CHANGE = new String[] {
82
        VAL_KEYS[0],
83
        VAL_KEYS[1]
84
    };
85
    
86
    static final Image VAL_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
87
    
88
    static final Image VAL_OPENED_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
89
    
90
    static final HelpCtx VAL_HELP_CTX = new HelpCtx( SampleLook1Hid.class );
91
    
92
    static final SystemAction[] VAL_ACTIONS = new SystemAction[] {
93
        new TestingAction1( "SystemAction1" ),
94
        new TestingAction2( "SystemAction2" )
95
    };
96
    
97
    static final SystemAction[] VAL_CONTEXT_ACTIONS = new SystemAction[] {
98
        new TestingAction3( "ContextAction1" ),
99
        new TestingAction4( "ContextAction2" )
100
    };
101
    
102
    static final SystemAction VAL_DEFAULT_ACTION = new TestingAction5( "DefaultAction" );
103
    
104
    static final JPanel VAL_CUSTOMIZER = new JPanel();
105
    
106
    static final Node.PropertySet[] VAL_PROPERTY_SETS = new Node.PropertySet[] {
107
        new Sheet.Set(),
108
        new Sheet.Set()
109
    };
110
    
111
    static final NewType[] VAL_NEW_TYPES = new NewType[] {
112
        new NewType() { 
113
            public void create() {  }
114
        },
115
        
116
        new NewType() { 
117
            public void create() {  }
118
        }
119
    };
120
    
121
    static final PasteType[] VAL_PASTE_TYPES = new PasteType[] {
122
        new PasteType() { 
123
            public Transferable paste() { return null; }
124
        },
125
        
126
        new PasteType() { 
127
            public Transferable paste() { return null; }
128
        }
129
    };
130
    
131
    static final PasteType VAL_DROP_TYPE = new PasteType() { 
132
        public Transferable paste() { return null; }
133
    };
134
    
135
    static final Transferable VAL_CLIPBOARD_COPY = new StringSelection( "ClipboardCopy" );
136
137
    static final Transferable VAL_CLIPBOARD_CUT = new StringSelection( "ClipboardCut" );
138
    
139
    static final Transferable VAL_DRAG = new StringSelection( "Drag" );
140
    
141
    // Hashtable which holds the relation Node - NodeSubstitute
142
    private Hashtable nodes2Substitutes = new Hashtable(); 
143
    
144
    // The value of keys which has to be returned
145
    private String[] keys = VAL_KEYS;
146
    
147
    /** Name of the look. 
148
     */
149
    private String name;
150
    
151
    /** Creates new DefaultLook. The costructor is protected, there should 
152
     * be no need for creating new <CODE> DefaultLooks</CODE>. You can delegate
153
     * to {@link #INSTANCE} instead.
154
     */
155
    protected SampleLook1Hid() {
156
    }
157
    
158
    // Additional methods for testing ------------------------------------------
159
    
160
    boolean getAttachToCalled() {
161
        boolean r = attachToCalled;
162
        attachToCalled = false;
163
        return r;
164
    }
165
        
166
    boolean getSetNameCalled() {
167
        boolean r = setNameCalled;
168
        setNameCalled = false;
169
        return r;
170
    }
171
        
172
        
173
    boolean getDestroyCalled() {
174
        boolean r = destroyCalled;
175
        destroyCalled = false;
176
        return r;
177
    }
178
    
179
    Look.NodeSubstitute getSubstituteForNode( LookNode node ) {
180
        return (Look.NodeSubstitute) nodes2Substitutes.get( node );
181
    }
182
    
183
    void setKeys( String[] val ) {
184
        keys = val;
185
    }
186
    
187
    // Private helper methods --------------------------------------------------
188
    
189
    private LookNode getNodeFromSubstitute( LookNode.SubstituteImpl subst ) {
190
        try {
191
            Class clazz = subst.getClass();
192
            Field outerClass = clazz.getDeclaredField ( "this$0" );
193
            outerClass.setAccessible( true );
194
            LookNode lookNode = (LookNode)outerClass.get( subst );
195
            outerClass.setAccessible( false );
196
            return lookNode;
197
        }
198
        catch ( NoSuchFieldException e ) {
199
            System.out.println( "OuterInstance not found : " + e );
200
        }
201
        catch ( IllegalAccessException e ) {
202
            System.out.println( "OuterInstance not found : " + e );
203
        }
204
        
205
        return null;
206
    }
207
    
208
    // Methods of look itself --------------------------------------------------
209
    
210
    
211
    // General methods ---------------------------------------------------------
212
213
    /** Sets the flag to be able to test wether the method was called. It 
214
     * also stores the Look.NodeSubstitutes in a hash table (indexed by the
215
     * node to provide them by the getNodeSubstitute( Node node ) method.
216
     */    
217
    public void attachTo(Look.NodeSubstitute substitute) {
218
        attachToCalled = true;
219
        if ( substitute instanceof LookNode.SubstituteImpl ) {
220
            LookNode lookNode = getNodeFromSubstitute( (LookNode.SubstituteImpl )substitute );
221
            nodes2Substitutes.put( lookNode, substitute );
222
        }
223
    }
224
    
225
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
226
        return VAL_COOKIE;
227
    }
228
229
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
230
        return VAL_HANDLE;
231
    }
232
    
233
    // Methods for STYLE -------------------------------------------------------
234
    
235
    public String getDisplayName( Look.NodeSubstitute substitute ) {
236
        return VAL_DISPLAY_NAME;
237
    }
238
    
239
    public String getName( Look.NodeSubstitute substitute ) {
240
        return VAL_NAME;
241
    }
242
    
243
    public void setName(Look.NodeSubstitute substitute, String newName ) {
244
        setNameCalled = true;
245
    }
246
    
247
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
248
        return VAL_SHORT_DESCRIPTION;
249
    }
250
    
251
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
252
        return VAL_ICON;
253
    }
254
    
255
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
256
        return VAL_OPENED_ICON;
257
    }
258
    
259
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
260
        return VAL_HELP_CTX;
261
    }
262
    
263
    // Methods for CHILDREN ----------------------------------------------------
264
    
265
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
266
        return keys;
267
    }
268
        
269
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
270
    
271
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
272
        return VAL_NEW_TYPES;
273
    }
274
    
275
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
276
        return VAL_ACTIONS;
277
    }
278
    
279
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
280
        return VAL_CONTEXT_ACTIONS;
281
    }
282
    
283
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
284
        return VAL_DEFAULT_ACTION;
285
    }
286
    
287
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
288
    
289
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
290
        return VAL_PROPERTY_SETS;
291
    }
292
    
293
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
294
        return VAL_CUSTOMIZER;
295
    }
296
    
297
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
298
     
299
    public boolean canRename( Look.NodeSubstitute substitute ) {
300
        return true;
301
    }
302
    
303
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
304
        return true;
305
    }
306
    
307
    public boolean canCopy( Look.NodeSubstitute substitute ) {
308
        return true;
309
    }
310
    
311
    public boolean canCut( Look.NodeSubstitute substitute ) {
312
        return true;
313
    }
314
    
315
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
316
        return VAL_PASTE_TYPES;
317
    }
318
    
319
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
320
        return VAL_DROP_TYPE;
321
    }
322
    
323
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
324
        return VAL_CLIPBOARD_COPY;
325
    }
326
    
327
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
328
        return VAL_CLIPBOARD_CUT;
329
    }
330
    
331
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
332
        return VAL_DRAG;
333
    }
334
          
335
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
336
        destroyCalled = true;
337
    }
338
    
339
    public static class NodeSubstitute extends Look.NodeSubstitute {
340
           
341
        public Object getRepresentedObject() { return null; }
342
        
343
        public void firePropertyChange( String name, Object o, Object n ) {}
344
345
        public void fireNameChange( String o, String n ) {}
346
        
347
        public void fireDisplayNameChange( String o, String n ) {}
348
        
349
        public void fireShortDescriptionChange(String o, String n) {}
350
351
        public void fireIconChange() {}
352
353
        public void fireOpenedIconChange() {}
354
355
        public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n ) {}
356
       
357
        public void fireCookieChange() {}
358
359
        public void fireNodeDestroyed() {}
360
361
        public void refreshChildren() {}
362
        
363
        public CookieSet getCookieSet() {
364
            return null;
365
        }
366
        
367
    }
368
    
369
    
370
    private static class TestingAction extends CallableSystemAction {
371
372
        private String name;
373
        
374
        TestingAction( String name ) {
375
            super();
376
            this.name = name;
377
        }
378
        
379
        public HelpCtx getHelpCtx() {
380
            return null;
381
        }
382
        
383
        public String getName() {
384
            return name;
385
        }
386
        
387
        public void performAction() {
388
        }
389
        
390
    }
391
    
392
    private static class TestingAction1 extends TestingAction {
393
        TestingAction1( String name ) {
394
            super( name );
395
        }
396
    }
397
    
398
    private static class TestingAction2 extends TestingAction {
399
        TestingAction2( String name ) {
400
            super( name );
401
        }
402
    }
403
    
404
    private static class TestingAction3 extends TestingAction {
405
        TestingAction3( String name ) {
406
            super( name );
407
        }
408
    }
409
    
410
    private static class TestingAction4 extends TestingAction {
411
        TestingAction4( String name ) {
412
            super( name );
413
        }
414
    }
415
    
416
    private static class TestingAction5 extends TestingAction {
417
        TestingAction5( String name ) {
418
            super( name );
419
        }
420
    }
421
}
(-)openidex/test/unit/src/org/openidex/nodes/looks/SampleLook2Hid.java (-421 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is Forte for Java, Community Edition. The Initial
10
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
11
 * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openidex.nodes.looks;
15
16
import java.util.List;
17
import java.awt.Image;
18
import java.awt.image.BufferedImage;
19
import java.awt.datatransfer.Transferable;
20
import java.awt.datatransfer.StringSelection;
21
import java.io.IOException;
22
import java.lang.reflect.*;
23
import java.util.Hashtable;
24
import javax.swing.JPanel;
25
26
import org.openide.nodes.*;
27
import org.openide.loaders.XMLDataObject;
28
import org.openide.util.actions.SystemAction;
29
import org.openide.util.actions.CallableSystemAction;
30
import org.openide.util.HelpCtx;
31
import org.openide.util.datatransfer.NewType;
32
import org.openide.util.datatransfer.PasteType;
33
34
/** Class used for testing. Every method returns some value. Usefull for testing 
35
 * FilterLook.
36
 *
37
 * @author Petr Hrebejk
38
 */
39
class SampleLook2Hid extends Look {
40
    
41
    // Flags for method calls which do not return any value.
42
    boolean attachToCalled = false;
43
    boolean setNameCalled = false;
44
    boolean destroyCalled = false;
45
       
46
    // The values which are returned from this Look
47
    static final Node.Cookie VAL_COOKIE = new Node.Cookie() {};
48
    
49
    static final Node.Handle VAL_HANDLE = new Node.Handle() {
50
        public Node getNode() {
51
            return null;
52
        }
53
    };
54
    
55
    static final String VAL_NAME = "Node.Name";
56
    
57
    static final String VAL_DISPLAY_NAME = "Node.DisplayName";
58
    
59
    static final String VAL_SHORT_DESCRIPTION = "Node.ShortDescription";
60
    
61
    static final String[] VAL_KEYS = new String[] {
62
        "Child.1",
63
        "Child.2"
64
    };
65
    
66
    static final String[] VAL_KEYS_ADDED = new String[] {
67
        VAL_KEYS[0],
68
        "Child.1.a",
69
        VAL_KEYS[1]
70
    };
71
    
72
    static final String[] VAL_KEYS_REMOVED = new String[] {
73
        VAL_KEYS[0],
74
    };
75
    
76
    static final String[] VAL_KEYS_REORDERED = new String[] {
77
        VAL_KEYS[1],
78
        VAL_KEYS[0]
79
    };
80
    
81
    static final String[] VAL_KEYS_NO_CHANGE = new String[] {
82
        VAL_KEYS[0],
83
        VAL_KEYS[1]
84
    };
85
    
86
    static final Image VAL_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
87
    
88
    static final Image VAL_OPENED_ICON = new BufferedImage( 16, 16, BufferedImage.TYPE_INT_RGB );
89
    
90
    static final HelpCtx VAL_HELP_CTX = new HelpCtx( SampleLook1Hid.class );
91
    
92
    static final SystemAction[] VAL_ACTIONS = new SystemAction[] {
93
        new TestingAction1( "SystemAction1" ),
94
        new TestingAction2( "SystemAction2" )
95
    };
96
    
97
    static final SystemAction[] VAL_CONTEXT_ACTIONS = new SystemAction[] {
98
        new TestingAction3( "ContextAction1" ),
99
        new TestingAction4( "ContextAction2" )
100
    };
101
    
102
    static final SystemAction VAL_DEFAULT_ACTION = new TestingAction5( "DefaultAction" );
103
    
104
    static final JPanel VAL_CUSTOMIZER = new JPanel();
105
    
106
    static final Node.PropertySet[] VAL_PROPERTY_SETS = new Node.PropertySet[] {
107
        new Sheet.Set(),
108
        new Sheet.Set()
109
    };
110
    
111
    static final NewType[] VAL_NEW_TYPES = new NewType[] {
112
        new NewType() { 
113
            public void create() {  }
114
        },
115
        
116
        new NewType() { 
117
            public void create() {  }
118
        }
119
    };
120
    
121
    static final PasteType[] VAL_PASTE_TYPES = new PasteType[] {
122
        new PasteType() { 
123
            public Transferable paste() { return null; }
124
        },
125
        
126
        new PasteType() { 
127
            public Transferable paste() { return null; }
128
        }
129
    };
130
    
131
    static final PasteType VAL_DROP_TYPE = new PasteType() { 
132
        public Transferable paste() { return null; }
133
    };
134
    
135
    static final Transferable VAL_CLIPBOARD_COPY = new StringSelection( "ClipboardCopy" );
136
137
    static final Transferable VAL_CLIPBOARD_CUT = new StringSelection( "ClipboardCut" );
138
    
139
    static final Transferable VAL_DRAG = new StringSelection( "Drag" );
140
    
141
    // Hashtable which holds the relation Node - NodeSubstitute
142
    private Hashtable nodes2Substitutes = new Hashtable(); 
143
    
144
    // The value of keys which has to be returned
145
    private String[] keys = VAL_KEYS;
146
    
147
    /** Name of the look. 
148
     */
149
    private String name;
150
    
151
    /** Creates new DefaultLook. The costructor is protected, there should 
152
     * be no need for creating new <CODE> DefaultLooks</CODE>. You can delegate
153
     * to {@link #INSTANCE} instead.
154
     */
155
    protected SampleLook2Hid() {
156
    }
157
    
158
    // Additional methods for testing ------------------------------------------
159
    
160
    boolean getAttachToCalled() {
161
        boolean r = attachToCalled;
162
        attachToCalled = false;
163
        return r;
164
    }
165
        
166
    boolean getSetNameCalled() {
167
        boolean r = setNameCalled;
168
        setNameCalled = false;
169
        return r;
170
    }
171
        
172
        
173
    boolean getDestroyCalled() {
174
        boolean r = destroyCalled;
175
        destroyCalled = false;
176
        return r;
177
    }
178
    
179
    Look.NodeSubstitute getSubstituteForNode( LookNode node ) {
180
        return (Look.NodeSubstitute) nodes2Substitutes.get( node );
181
    }
182
    
183
    void setKeys( String[] val ) {
184
        keys = val;
185
    }
186
    
187
    // Private helper methods --------------------------------------------------
188
    
189
    private LookNode getNodeFromSubstitute( LookNode.SubstituteImpl subst ) {
190
        try {
191
            Class clazz = subst.getClass();
192
            Field outerClass = clazz.getDeclaredField ( "this$0" );
193
            outerClass.setAccessible( true );
194
            LookNode lookNode = (LookNode)outerClass.get( subst );
195
            outerClass.setAccessible( false );
196
            return lookNode;
197
        }
198
        catch ( NoSuchFieldException e ) {
199
            System.out.println( "OuterInstance not found : " + e );
200
        }
201
        catch ( IllegalAccessException e ) {
202
            System.out.println( "OuterInstance not found : " + e );
203
        }
204
        
205
        return null;
206
    }
207
    
208
    // Methods of look itself --------------------------------------------------
209
    
210
    
211
    // General methods ---------------------------------------------------------
212
213
    /** Sets the flag to be able to test wether the method was called. It 
214
     * also stores the Look.NodeSubstitutes in a hash table (indexed by the
215
     * node to provide them by the getNodeSubstitute( Node node ) method.
216
     */    
217
    public void attachTo(Look.NodeSubstitute substitute) {
218
        attachToCalled = true;
219
        if ( substitute instanceof LookNode.SubstituteImpl ) {
220
            LookNode lookNode = getNodeFromSubstitute( (LookNode.SubstituteImpl )substitute );
221
            nodes2Substitutes.put( lookNode, substitute );
222
        }
223
    }
224
    
225
    public Node.Cookie getCookie( Look.NodeSubstitute substitute, Class type) {
226
        return VAL_COOKIE;
227
    }
228
229
    public Node.Handle getHandle( Look.NodeSubstitute substitute ) {
230
        return VAL_HANDLE;
231
    }
232
    
233
    // Methods for STYLE -------------------------------------------------------
234
    
235
    public String getDisplayName( Look.NodeSubstitute substitute ) {
236
        return VAL_DISPLAY_NAME;
237
    }
238
    
239
    public String getName( Look.NodeSubstitute substitute ) {
240
        return VAL_NAME;
241
    }
242
    
243
    public void setName(Look.NodeSubstitute substitute, String newName ) {
244
        setNameCalled = true;
245
    }
246
    
247
    public String getShortDescription ( Look.NodeSubstitute substitute ) {
248
        return VAL_SHORT_DESCRIPTION;
249
    }
250
    
251
    public Image getIcon( Look.NodeSubstitute substitute, int type ) {
252
        return VAL_ICON;
253
    }
254
    
255
    public Image getOpenedIcon( Look.NodeSubstitute substitute, int type ) {
256
        return VAL_OPENED_ICON;
257
    }
258
    
259
    public HelpCtx getHelpCtx( Look.NodeSubstitute substitute ) {
260
        return VAL_HELP_CTX;
261
    }
262
    
263
    // Methods for CHILDREN ----------------------------------------------------
264
    
265
    public Object[] getChildObjects(Look.NodeSubstitute substitute) {
266
        return keys;
267
    }
268
        
269
    // Methods for ACTIONS & NEW TYPES -----------------------------------------
270
    
271
    public NewType[] getNewTypes( Look.NodeSubstitute substitute ) {
272
        return VAL_NEW_TYPES;
273
    }
274
    
275
    public SystemAction[] getActions( Look.NodeSubstitute substitute ) {
276
        return VAL_ACTIONS;
277
    }
278
    
279
    public SystemAction[] getContextActions( Look.NodeSubstitute substitute ) {
280
        return VAL_CONTEXT_ACTIONS;
281
    }
282
    
283
    public SystemAction getDefaultAction( Look.NodeSubstitute substitute ) {
284
        return VAL_DEFAULT_ACTION;
285
    }
286
    
287
    // Methods for PROPERTIES AND CUSTOMIZER -----------------------------------
288
    
289
    public Node.PropertySet[] getPropertySets( Look.NodeSubstitute substitute ) {
290
        return VAL_PROPERTY_SETS;
291
    }
292
    
293
    public java.awt.Component getCustomizer( Look.NodeSubstitute substitute ) {
294
        return VAL_CUSTOMIZER;
295
    }
296
    
297
    // Methods for CLIPBOARD OPERATIONS ----------------------------------------
298
     
299
    public boolean canRename( Look.NodeSubstitute substitute ) {
300
        return true;
301
    }
302
    
303
    public boolean canDestroy( Look.NodeSubstitute substitute ) {
304
        return true;
305
    }
306
    
307
    public boolean canCopy( Look.NodeSubstitute substitute ) {
308
        return true;
309
    }
310
    
311
    public boolean canCut( Look.NodeSubstitute substitute ) {
312
        return true;
313
    }
314
    
315
    public PasteType[] getPasteTypes( Look.NodeSubstitute substitute, Transferable t) {
316
        return VAL_PASTE_TYPES;
317
    }
318
    
319
    public PasteType getDropType( Look.NodeSubstitute substitute, Transferable t, int action, int index) {
320
        return VAL_DROP_TYPE;
321
    }
322
    
323
    public Transferable clipboardCopy( Look.NodeSubstitute substitute ) throws IOException {
324
        return VAL_CLIPBOARD_COPY;
325
    }
326
    
327
    public Transferable clipboardCut( Look.NodeSubstitute substitute ) throws IOException {
328
        return VAL_CLIPBOARD_CUT;
329
    }
330
    
331
    public Transferable drag( Look.NodeSubstitute substitute ) throws IOException {
332
        return VAL_DRAG;
333
    }
334
          
335
    public void destroy(Look.NodeSubstitute substitute) throws IOException {
336
        destroyCalled = true;
337
    }
338
    
339
    public static class NodeSubstitute extends Look.NodeSubstitute {
340
           
341
        public Object getRepresentedObject() { return null; }
342
        
343
        public void firePropertyChange( String name, Object o, Object n ) {}
344
345
        public void fireNameChange( String o, String n ) {}
346
        
347
        public void fireDisplayNameChange( String o, String n ) {}
348
        
349
        public void fireShortDescriptionChange(String o, String n) {}
350
351
        public void fireIconChange() {}
352
353
        public void fireOpenedIconChange() {}
354
355
        public void firePropertySetsChange( Node.PropertySet[] o, Node.PropertySet[] n ) {}
356
       
357
        public void fireCookieChange() {}
358
359
        public void fireNodeDestroyed() {}
360
361
        public void refreshChildren() {}
362
        
363
        public CookieSet getCookieSet() {
364
            return null;
365
        }
366
        
367
    }
368
    
369
    
370
    private static class TestingAction extends CallableSystemAction {
371
372
        private String name;
373
        
374
        TestingAction( String name ) {
375
            super();
376
            this.name = name;
377
        }
378
        
379
        public HelpCtx getHelpCtx() {
380
            return null;
381
        }
382
        
383
        public String getName() {
384
            return name;
385
        }
386
        
387
        public void performAction() {
388
        }
389
        
390
    }
391
    
392
    private static class TestingAction1 extends TestingAction {
393
        TestingAction1( String name ) {
394
            super( name );
395
        }
396
    }
397
    
398
    private static class TestingAction2 extends TestingAction {
399
        TestingAction2( String name ) {
400
            super( name );
401
        }
402
    }
403
    
404
    private static class TestingAction3 extends TestingAction {
405
        TestingAction3( String name ) {
406
            super( name );
407
        }
408
    }
409
    
410
    private static class TestingAction4 extends TestingAction {
411
        TestingAction4( String name ) {
412
            super( name );
413
        }
414
    }
415
    
416
    private static class TestingAction5 extends TestingAction {
417
        TestingAction5( String name ) {
418
            super( name );
419
        }
420
    }
421
}
(-)utilities/manifest.mf (-1 / +1 lines)
Lines 7-13 Link Here
7
OpenIDE-Module-Layer: org/netbeans/modules/utilities/Layer.xml
7
OpenIDE-Module-Layer: org/netbeans/modules/utilities/Layer.xml
8
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.20
8
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.20
9
OpenIDE-Module-Module-Dependencies: 
9
OpenIDE-Module-Module-Dependencies: 
10
 org.openidex.util/2,
10
 org.openidex.util/2-3,
11
 org.netbeans.modules.javahelp/1 > 1.2,
11
 org.netbeans.modules.javahelp/1 > 1.2,
12
 org.netbeans.modules.settings/1 > 1.0,
12
 org.netbeans.modules.settings/1 > 1.0,
13
 org.openide.io > 1.0,
13
 org.openide.io > 1.0,
(-)vcscore/manifest.mf (-1 / +1 lines)
Lines 5-10 Link Here
5
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
5
OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@
6
OpenIDE-Module-Layer: org/netbeans/modules/vcscore/resources/mf-layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/vcscore/resources/mf-layer.xml
7
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.20
7
OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.20
8
OpenIDE-Module-Module-Dependencies: org.openidex.util/2, org.openide.io > 1.0, org.openide.execution > 1.2, org.openide.loaders > 4.11
8
OpenIDE-Module-Module-Dependencies: org.openidex.util/2-3, org.openide.io > 1.0, org.openide.execution > 1.2, org.openide.loaders > 4.11
9
OpenIDE-Module-Requires: org.openide.windows.IOProvider
9
OpenIDE-Module-Requires: org.openide.windows.IOProvider
10
10
(-)web/advanced/manifest.mf (-1 / +1 lines)
Lines 11-17 Link Here
11
   org.netbeans.modules.j2eeserver/3,
11
   org.netbeans.modules.j2eeserver/3,
12
   org.netbeans.modules.schema2beans/1,
12
   org.netbeans.modules.schema2beans/1,
13
   org.netbeans.modules.html/1,
13
   org.netbeans.modules.html/1,
14
   org.openidex.util/2,
14
   org.openidex.util/2-3,
15
   org.netbeans.core/1 > 1.0,
15
   org.netbeans.core/1 > 1.0,
16
   org.openide.src > 1.0, org.openide.execution > 1.0,
16
   org.openide.src > 1.0, org.openide.execution > 1.0,
17
   org.netbeans.api.web.dd/1
17
   org.netbeans.api.web.dd/1

Return to bug 40150