KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > NbIOProvider


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.core.output2;
21
22 import java.io.IOException JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.openide.util.Exceptions;
25 import org.openide.util.NbBundle;
26 import org.openide.windows.IOProvider;
27 import org.openide.windows.InputOutput;
28 import org.openide.windows.OutputWriter;
29
30 /**
31  * Supplies Output Window implementation through Lookup.
32  * @author Jesse Glick, Tim Boudreau
33  */

34 public final class NbIOProvider extends IOProvider {
35     private static final PairMap namesToIos = new PairMap();
36
37     private static final String JavaDoc STDOUT = NbBundle.getMessage(NbIOProvider.class,
38         "LBL_STDOUT"); //NOI18N
39

40     public OutputWriter getStdOut() {
41         if (Controller.LOG) {
42             Controller.log("NbIOProvider.getStdOut");
43         }
44         InputOutput stdout = getIO (STDOUT, false, null);
45         NbWriter out = ((NbIO)stdout).writer();
46         
47         Controller.ensureViewInDefault ((NbIO) stdout, true);
48         //ensure it is not closed
49
if (out != null && out.isClosed()) {
50             try {
51                 out.reset();
52                 out = (NbWriter) stdout.getOut();
53             } catch (IOException JavaDoc e) {
54                 Exceptions.printStackTrace(e);
55                 stdout = getIO (STDOUT, true, null);
56                 out = (NbWriter) stdout.getOut();
57             }
58         } else {
59             out = (NbWriter) stdout.getOut();
60         }
61         return out;
62     }
63     
64     
65     public InputOutput getIO(String JavaDoc name, boolean newIO) {
66         return getIO (name, newIO, new Action JavaDoc[0]);
67     }
68     
69     public InputOutput getIO(String JavaDoc name, Action JavaDoc[] toolbarActions) {
70         return getIO (name, true, toolbarActions);
71     }
72     
73     private InputOutput getIO(String JavaDoc name, boolean newIO, Action JavaDoc[] toolbarActions) {
74         if (Controller.LOG) {
75             Controller.log("GETIO: " + name + " new:" + newIO);
76         }
77         NbIO result = namesToIos.get(name);
78
79         if (result == null || newIO) {
80             result = new NbIO(name, toolbarActions);
81             namesToIos.add (name, result);
82             Controller.ensureViewInDefault (result, newIO);
83         } else {
84             // mkleint ignore actions if reuse of tabs.
85
// result.setToolbarActions(toolbarActions);
86
}
87         return result;
88     }
89     
90     
91     static void dispose (NbIO io) {
92         namesToIos.remove (io);
93     }
94     
95     /**
96      * Called when the output window is hidden. Switches the caching of IOs
97      * to weak references, so that only those still alive will be shown the
98      * next time the output window is opened.
99      */

100     static void setWeak(boolean value) {
101         namesToIos.setWeak(value);
102     }
103 }
104
105
Popular Tags