KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > pdf > Settings


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 package org.netbeans.modules.pdf;
20
21 import java.io.File JavaDoc;
22 import java.util.Properties JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import org.openide.ErrorManager;
26
27 import org.openide.util.Lookup;
28
29
30 /**
31  * New PDF settings.
32  *
33  * @author Libor Kramolis
34  * @author Marian Petras
35  */

36 public class Settings {
37     public static final String JavaDoc PROP_PDF_VIEWER = "PDFViewer"; //NOI18N
38
private File JavaDoc viewer;
39     private PropertyChangeSupport JavaDoc supp = new PropertyChangeSupport JavaDoc(this);
40
41
42     public static Settings getDefault() {
43         return (Settings) Lookup.getDefault().lookup(Settings.class);
44     }
45
46     public File JavaDoc getPDFViewer() {
47         return viewer;
48     }
49
50     public void setPDFViewer(File JavaDoc viewer) {
51         ErrorManager.getDefault()
52                 .getInstance("org.netbeans.modules.pdf") //NOI18N
53
.log("Settings [" + this + "].setPDFViewer: " + viewer);//NOI18N
54

55         File JavaDoc old = this.viewer;
56         this.viewer = viewer;
57         supp.firePropertyChange(PROP_PDF_VIEWER, old, viewer);
58     }
59
60     /**
61      * @see http://www.netbeans.org/download/dev/javadoc/SettingsAPIs/org/netbeans/spi/settings/doc-files/api.html#xmlprops
62      */

63     private void readProperties(Properties JavaDoc p) {
64         String JavaDoc fileName = p.getProperty(PROP_PDF_VIEWER);
65         if (fileName != null && fileName.length() != 0) {
66             viewer = new File JavaDoc(fileName);
67         } else {
68             viewer = null;
69         }
70     }
71
72     /**
73      * @see http://www.netbeans.org/download/dev/javadoc/SettingsAPIs/org/netbeans/spi/settings/doc-files/api.html#xmlprops
74      */

75     private void writeProperties(Properties JavaDoc p) {
76         p.setProperty(PROP_PDF_VIEWER,
77                       viewer != null ? viewer.toString() : null);
78     }
79
80
81     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
82         ErrorManager.getDefault()
83               .getInstance("org.netbeans.modules.pdf") //NOI18N
84
.log("Settings [" + this + "].addPropertyChangeListener: "//NOI18N
85
+ l);
86
87         supp.addPropertyChangeListener(l);
88     }
89
90     public void removePropertyChangeListener (PropertyChangeListener JavaDoc l) {
91         ErrorManager.getDefault()
92            .getInstance("org.netbeans.modules.pdf") //NOI18N
93
.log("Settings [" + this + "].removePropertyChangeListener: "//NOI18N
94
+ l);
95
96         supp.removePropertyChangeListener(l);
97     }
98
99 }
100
Popular Tags