KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > model > TopComponentContextSubModel


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
21 package org.netbeans.core.windows.model;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.netbeans.core.windows.ModeImpl;
26 import org.netbeans.core.windows.SplitConstraint;
27 import org.openide.windows.TopComponent;
28
29 /**
30  * Model which stores context of TopComponents in one mode. Context consists
31  * of mode and constraints info of previous container TopComponent was part of.
32  *
33  * This sub model is not thread safe. It is supposed to be just part of DefaultModeModel
34  * which is responsible for the synch.
35  *
36  * @author Dafe Simonek
37  */

38 final class TopComponentContextSubModel {
39     
40     private static final class Context {
41         // XXX we should use weak reference for holding mode, to let it vanish
42
ModeImpl mode;
43         //tab index
44
int index = -1;
45         SplitConstraint[] constraints;
46     } // end of Context
47

48     /** Mapping <TopComponentID, Context> between top component and context holding
49      its previous location */

50     private final Map JavaDoc<String JavaDoc, Context> tcID2Contexts = new HashMap JavaDoc<String JavaDoc, Context> (10);
51     
52     public TopComponentContextSubModel() {
53     }
54
55     public void setTopComponentPreviousConstraints(String JavaDoc tcID, SplitConstraint[] constraints) {
56         Context context = tcID2Contexts.get(tcID);
57         if (context == null) {
58             context = new Context();
59             tcID2Contexts.put(tcID, context);
60         }
61         context.constraints = constraints;
62     }
63     
64     public void setTopComponentPreviousMode(String JavaDoc tcID, ModeImpl mode, int index) {
65         Context context = tcID2Contexts.get(tcID);
66         if (context == null) {
67             context = new Context();
68             tcID2Contexts.put(tcID, context);
69         }
70         context.mode = mode;
71         context.index = index;
72     }
73     
74     public SplitConstraint[] getTopComponentPreviousConstraints(String JavaDoc tcID) {
75         Context context = tcID2Contexts.get(tcID);
76         return context == null ? null : context.constraints;
77     }
78     
79     public ModeImpl getTopComponentPreviousMode(String JavaDoc tcID) {
80         Context context = tcID2Contexts.get(tcID);
81         return context == null ? null : context.mode;
82     }
83     
84     public int getTopComponentPreviousIndex(String JavaDoc tcID) {
85         Context context = tcID2Contexts.get(tcID);
86         return context == null ? -1 : context.index;
87     }
88 }
89
Popular Tags