001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: InternalDockingUtil.java,v 1.27 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking.internalutil;
024:
025: import net.infonode.docking.DockingWindow;
026: import net.infonode.docking.RootWindow;
027: import net.infonode.docking.TabWindow;
028: import net.infonode.docking.View;
029: import net.infonode.docking.action.DockingWindowAction;
030: import net.infonode.docking.properties.WindowTabButtonProperties;
031: import net.infonode.docking.util.DockingUtil;
032: import net.infonode.docking.util.ViewMap;
033: import net.infonode.properties.propertymap.PropertyMap;
034: import net.infonode.util.IntList;
035: import net.infonode.util.Printer;
036:
037: import javax.swing.*;
038: import java.awt.*;
039: import java.awt.event.ActionEvent;
040: import java.awt.event.ActionListener;
041: import java.util.ArrayList;
042: import java.util.Map;
043:
044: /**
045: * @author $Author: jesper $
046: * @version $Revision: 1.27 $
047: */
048: public class InternalDockingUtil {
049: private InternalDockingUtil() {
050: }
051:
052: public static final int DEFAULT_BUTTON_ICON_SIZE = 10;
053:
054: public static void getViews(DockingWindow window, ArrayList views) {
055: if (window == null)
056: return;
057: else if (window instanceof View)
058: views.add(window);
059: else {
060: for (int i = 0; i < window.getChildWindowCount(); i++)
061: getViews(window.getChildWindow(i), views);
062: }
063: }
064:
065: public static IntList getWindowPath(DockingWindow window) {
066: return getWindowPath(window, IntList.EMPTY_LIST);
067: }
068:
069: /**
070: * Returns the window located at <tt>windowPath</tt>.
071: *
072: * @param relativeToWindow the window the path is relative to
073: * @param windowPath the window path
074: * @return the window located at <tt>windowPath</tt>
075: */
076: public static DockingWindow getWindow(
077: DockingWindow relativeToWindow, IntList windowPath) {
078: return windowPath.isEmpty() ? relativeToWindow
079: : windowPath.getValue() >= relativeToWindow
080: .getChildWindowCount() ? null : getWindow(
081: relativeToWindow.getChildWindow(windowPath
082: .getValue()), windowPath.getNext());
083: }
084:
085: private static IntList getWindowPath(DockingWindow window,
086: IntList tail) {
087: DockingWindow parent = window.getWindowParent();
088: return parent == null ? tail : getWindowPath(parent,
089: new IntList(parent.getChildWindowIndex(window), tail));
090: }
091:
092: public static void addDebugMenuItems(JPopupMenu menu,
093: final DockingWindow window) {
094: menu.add("Dump Tree").addActionListener(new ActionListener() {
095: public void actionPerformed(ActionEvent e) {
096: dump(window, new Printer());
097: }
098: });
099: }
100:
101: public static void dump(DockingWindow window, Printer printer) {
102: DockingWindow parent = window.getWindowParent();
103:
104: String clName = window.getClass().getName();
105:
106: printer
107: .println(clName.substring(clName.lastIndexOf('.') + 1)
108: + ", "
109: + System.identityHashCode(window)
110: + " ("
111: + (parent == null ? "null" : String
112: .valueOf(System
113: .identityHashCode(parent)))
114: + "), '"
115: + window.getTitle()
116: + "', "
117: + (window.isVisible() ? "visible"
118: : "not visible")
119: + ", "
120: + (window.isMaximized() ? "maximized"
121: : "not maximized") + ", "
122: + (window.getChildWindowCount() > 0 ? ":" : ""));
123:
124: if (window.getChildWindowCount() > 0) {
125: printer.beginSection();
126:
127: for (int i = 0; i < window.getChildWindowCount(); i++) {
128: if (window.getChildWindow(i) == null)
129: printer.println("null");
130: else
131: dump(window.getChildWindow(i), printer);
132: }
133:
134: printer.endSection();
135: }
136: }
137:
138: public static RootWindow createInnerRootWindow(View[] views) {
139: RootWindow rootWindow = DockingUtil.createRootWindow(
140: new ViewMap(views), true);
141: rootWindow.getRootWindowProperties().getWindowAreaProperties()
142: .setBackgroundColor(null);
143: rootWindow.getRootWindowProperties()
144: .getWindowAreaShapedPanelProperties()
145: .setComponentPainter(null);
146: rootWindow.getRootWindowProperties().getComponentProperties()
147: .setBackgroundColor(null);
148: rootWindow.getRootWindowProperties().getComponentProperties()
149: .setBorder(null);
150: //rootWindow.getRootWindowProperties().getWindowAreaProperties().setBorder(new LineBorder(Color.GRAY));
151: return rootWindow;
152: }
153:
154: public static boolean updateButtons(ButtonInfo[] buttonInfos,
155: AbstractButton[] buttons, Container container,
156: DockingWindow window, PropertyMap map, Map changes) {
157: // DockingWindow window = w.getOptimizedWindow();
158: boolean updateContainer = false;
159:
160: for (int i = 0; i < buttonInfos.length; i++) {
161: WindowTabButtonProperties p = new WindowTabButtonProperties(
162: buttonInfos[i].getProperty().get(map));
163: DockingWindowAction action = p.getAction();
164: Map propertyChanges = changes == null ? null
165: : (Map) changes.get(p.getMap());
166: boolean v = p.isVisible();
167: boolean b = action != null && action.isPerformable(window);
168: boolean visible = p.isVisible() && action != null
169: && action.getAction(window).isEnabled();
170:
171: if ((buttons[i] == null || (propertyChanges != null && propertyChanges
172: .containsKey(WindowTabButtonProperties.FACTORY)))
173: && p.getFactory() != null && action != null) {
174: buttons[i] = p.getFactory().createButton(window);
175: buttons[i].setFocusable(false);
176: buttons[i].addActionListener(action.getAction(window)
177: .toSwingAction());
178: updateContainer = true;
179: }
180:
181: if (buttons[i] != null) {
182: buttons[i].setToolTipText(p.getToolTipText());
183: buttons[i].setIcon(p.getIcon());
184: buttons[i].setVisible(visible);
185: }
186: }
187:
188: if (updateContainer && container != null) {
189: container.removeAll();
190:
191: for (int j = 0; j < buttonInfos.length; j++) {
192: if (buttons[j] != null)
193: container.add(buttons[j]);
194: }
195: }
196:
197: return updateContainer;
198: }
199:
200: public static void addToRootWindow(DockingWindow window,
201: RootWindow rootWindow) {
202: if (rootWindow == null)
203: return;
204:
205: DockingWindow w = rootWindow.getWindow();
206:
207: if (w == null)
208: rootWindow.setWindow(window);
209: else if (w instanceof TabWindow)
210: ((TabWindow) w).addTab(window);
211: else
212: rootWindow.setWindow(new TabWindow(new DockingWindow[] { w,
213: window }));
214: }
215: }
|