KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > api > RecentProjects


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.ui.api;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.PropertyChangeSupport JavaDoc;
25
26 import java.util.List JavaDoc;
27
28 import org.netbeans.modules.project.ui.OpenProjectList;
29
30 /**
31  * Provides simple information about recent projects and fires PropertyChangeEvent
32  * in case of change in the list of recent projects
33  * @author Milan Kubec
34  * @since 1.9.0
35  */

36 public final class RecentProjects {
37
38     /**
39      * Property representing recent project information
40      */

41     public static final String JavaDoc PROP_RECENT_PROJECT_INFO = "RecentProjectInformation"; // NOI18N
42

43     private static RecentProjects INSTANCE;
44     
45     private PropertyChangeSupport JavaDoc pch;
46     
47     public static RecentProjects getDefault() {
48         if (INSTANCE == null) {
49             return new RecentProjects();
50         } else {
51             return INSTANCE;
52         }
53     }
54     
55     /**
56      * Creates a new instance of RecentProjects
57      */

58     private RecentProjects() {
59         pch = new PropertyChangeSupport JavaDoc(this);
60         OpenProjectList.getDefault().addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
61             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
62                 if (evt.getPropertyName().equals(OpenProjectList.PROPERTY_RECENT_PROJECTS)) {
63                     pch.firePropertyChange(new PropertyChangeEvent JavaDoc(RecentProjects.class,
64                             PROP_RECENT_PROJECT_INFO, null, null));
65                 }
66             }
67         });
68     }
69     
70     /**
71      * Gets simple info (@link UnloadedProjectInformation) about recent projects in IDE.
72      * Project in the list might not exist or might not be valid e.g. in case when
73      * project was deleted or changed. It's responsibility of the user of the API
74      * to make sure the project exists and is valid.
75      * @return list of project information about recently opened projects
76      */

77     public List JavaDoc/*<UnloadedProjectInformation>*/ getRecentProjectInformation() {
78         return OpenProjectList.getDefault().getRecentProjectsInformation();
79     }
80     
81     /**
82      * Adds a listener, use WeakListener or properly remove listeners
83      * @param listener listener to be added
84      */

85     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
86         pch.addPropertyChangeListener(listener);
87     }
88     
89     /**
90      * Removes a listener
91      * @param listener listener to be removed
92      */

93     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
94         pch.removePropertyChangeListener(listener);
95     }
96     
97 }
98
Popular Tags