📄 perspectivemanager.java
字号:
for (int i = 0; i < perspectives.length; i++)
{
String id = perspectives[i].getPersistentId();
if (!id.equals(EMPTY_PERSPECTIVE))
{
//TODO reset layout, maybe there is a better way
if (reset)
perspectives[i].getLayout().setRestorationLayout(null);
//p.unload();
//p.reset(port);
}
}
loadPerspectiveImpl(key, port, reset);
// if perspective load fails, then rollback the perspective name
// to its previous value (instead of null)
if(!Utilities.isEqual(getCurrentPerspectiveName(), key))
setCurrentPerspectiveName(current);
}
public void restore(Window w) throws IOException, PersistenceException {
reload(w, true);
load();
reload(w, false);
/*DockingPort port = DockingManager.getRootDockingPort(w);
String current = getCurrentPerspectiveName();
String key = current == null ? m_defaultPerspective : current;
setCurrentPerspectiveName(null);
loadPerspectiveImpl(key, port, false);
if(!Utilities.isEqual(getCurrentPerspectiveName(), key))
setCurrentPerspectiveName(current);*/
}
public void reload() {
String current = getCurrentPerspectiveName();
// if the current perspective is null, the use the default value
String key = current==null? m_defaultPerspective: current;
// null-out the current perspective name to force a reload.
// otherwise, the loadPerspective() call will short-circuit since
// it'll detect that the requested perspective is already loaded.
setCurrentPerspectiveName(null);
// load the perspective
loadPerspective(key);
// if the perspective load failed, then rollback the perspective name
// to its previous value (instead of null)
if(!Utilities.isEqual(getCurrentPerspectiveName(), key))
setCurrentPerspectiveName(current);
}
public void loadPerspective() {
loadPerspective(m_defaultPerspective);
}
public void loadPerspectiveAsDefault(String perspectiveId) {
loadPerspectiveAsDefault(perspectiveId, false);
}
public void loadPerspectiveAsDefault(String perspectiveId, boolean reset) {
if(perspectiveId!=null)
setDefaultPerspective(perspectiveId);
loadPerspective(perspectiveId, reset);
}
public void loadPerspective(String perspectiveId) {
loadPerspective(perspectiveId, false);
}
public void loadPerspective(String perspectiveId, boolean reset) {
RootWindow window = getMainApplicationWindow();
if(window!=null) {
loadPerspective(perspectiveId, window.getRootContainer(), reset);
return;
}
DockingPort rootPort = findMainDockingPort();
if(rootPort!=null)
loadPerspective(perspectiveId, rootPort, reset);
}
public void loadPerspective(String perspectiveId, Component window) {
loadPerspective(perspectiveId, window, false);
}
public void loadPerspective(String perspectiveId, Component window, boolean reset) {
if(window==null) {
loadPerspective(perspectiveId, reset);
return;
}
DockingPort port = DockingManager.getRootDockingPort(window);
loadPerspective(perspectiveId, port, reset);
}
public void loadPerspective(String perspectiveId, DockingPort rootPort) {
loadPerspective(perspectiveId, rootPort, false);
}
public void loadPerspective(String perspectiveId, DockingPort rootPort, boolean reset) {
if(perspectiveId==null || perspectiveId.equals(getCurrentPerspectiveName()))
return;
loadPerspectiveImpl(perspectiveId, rootPort, reset);
}
private void loadPerspectiveImpl(String perspectiveId, final DockingPort rootPort, boolean reset) {
if(perspectiveId==null)
return;
Perspective current = getCurrentPerspective();
final Perspective perspective = getPerspective(perspectiveId);
// remember the current layout state so we'll be able to
// restore when we switch back
if(current!=null) {
cacheLayoutState(current, rootPort);
current.unload();
}
// if the new perspective isn't available, then we're done
if(perspective==null)
return;
synchronized(this) {
setCurrentPerspectiveName(perspectiveId);
if(reset) {
perspective.reset(rootPort);
EventManager.dispatch(new PerspectiveEvent(perspective, current,
PerspectiveEvent.RESET));
} else {
perspective.load(rootPort);
EventManager.dispatch(new PerspectiveEvent(perspective, current,
PerspectiveEvent.CHANGED));
}
}
EventQueue.invokeLater(new Runnable() {
public void run() {
cacheLayoutState(perspective, rootPort);
}
});
}
private void cacheLayoutState(Perspective p, DockingPort port) {
if(p!=null)
p.cacheLayoutState(port);
}
public LayoutNode createLayout(DockingPort port) {
return LayoutBuilder.getInstance().createLayout(port);
}
public boolean display(Dockable dockable) {
return RestorationManager.getInstance().restore(dockable);
}
static void setDockingStateListening(boolean enabled) {
UPDATE_LISTENER.setEnabled(enabled);
}
static boolean isDockingStateListening() {
return UPDATE_LISTENER.isEnabled();
}
static void clear(DockingPort port) {
if(port!=null) {
boolean currState = isDockingStateListening();
setDockingStateListening(false);
port.clear();
setDockingStateListening(currState);
}
}
static void updateDockingStates(final Dockable[] dockables) {
if(dockables==null)
return;
EventQueue.invokeLater(new Runnable() {
public void run() {
for(int i=0; i<dockables.length; i++) {
UPDATE_LISTENER.updateState(dockables[i]);
}
}
});
}
public synchronized boolean store() throws IOException, PersistenceException {
return store(null);
}
public synchronized boolean store(String persistenceKey) throws IOException, PersistenceException {
if(m_persistHandler==null)
return false;
DockingPort rootPort = findMainDockingPort();
cacheLayoutState(getCurrentPerspective(), rootPort);
Perspective[] items = getPerspectives();
for(int i=0; i<items.length; i++) {
items[i] = (Perspective)items[i].clone();
}
PerspectiveModel info = new PerspectiveModel(m_defaultPerspective, getCurrentPerspectiveName(), items);
String pKey = persistenceKey==null? m_defaultPersistenceKey: persistenceKey;
return m_persistHandler.store(pKey, info);
}
public synchronized boolean load() throws IOException, PersistenceException {
return load(null);
}
public synchronized boolean load(String persistenceKey) throws IOException, PersistenceException {
if(m_persistHandler==null)
return false;
String pKey = persistenceKey==null? m_defaultPersistenceKey: persistenceKey;
PerspectiveModel info = m_persistHandler.load(pKey);
if(info==null)
return false;
Perspective[] perspectives = info.getPerspectives();
m_perspectives.clear();
for(int i=0; i<perspectives.length; i++) {
add(perspectives[i]);
}
setDefaultPerspective(info.getDefaultPerspective());
setCurrentPerspectiveName(info.getCurrentPerspective());
return true;
}
public static boolean isRestoreFloatingOnLoad() {
return getInstance().restoreFloatingOnLoad;
}
public static void setRestoreFloatingOnLoad(boolean restoreFloatingOnLoad) {
getInstance().restoreFloatingOnLoad = restoreFloatingOnLoad;
}
//FIXME returns wrong window (first found) for multiple frames
public static RootWindow getMainApplicationWindow() {
RootWindow[] windows = DockingManager.getDockingWindows();
// if the DockingManager couldn't resolve any windows using the
// standard mechanism, we can try our own custom search
if(windows.length==0)
windows = resolveDockingWindows();
// TODO: fix this code to keep track of the proper dialog owner
RootWindow window = null;
for(int i=0; i<windows.length; i++) {
window = windows[i];
if(window.getOwner()==null)
break;
}
return window;
}
private static RootWindow[] resolveDockingWindows() {
// locate all the root dockingports
Set rootPorts = DockingPortTracker.getRootDockingPorts();
ArrayList windows = new ArrayList(rootPorts.size());
// for each dockingPort, resolve its root window
for(Iterator it=rootPorts.iterator(); it.hasNext();) {
DockingPort port = (DockingPort)it.next();
RootWindow window = RootWindow.getRootContainer((Component)port);
if(window!=null)
windows.add(window);
}
return (RootWindow[])windows.toArray(new RootWindow[0]);
}
public static DockingPort getMainDockingPort() {
RootWindow window = getMainApplicationWindow();
return window==null? null: DockingManager.getRootDockingPort(window.getRootContainer());
}
public boolean restore(boolean loadFromStorage) throws IOException, PersistenceException {
boolean loaded = loadFromStorage? load(): true;
reload();
return loaded;
}
public String getDefaultPersistenceKey() {
return m_defaultPersistenceKey;
}
public void setDefaultPersistenceKey(String key) {
m_defaultPersistenceKey = key;
}
private DockingPort findMainDockingPort() {
Set rootPorts = DockingPortTracker.getRootDockingPorts();
DockingPort rootPort = null;
for(Iterator it=rootPorts.iterator(); it.hasNext();) {
DockingPort port = (DockingPort)it.next();
Window win = SwingUtilities.getWindowAncestor((Component)port);
if(win instanceof Dialog)
continue;
rootPort = port;
break;
}
return rootPort;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -