📄 abstractdockable.java
字号:
/*
* Copyright (c) 2004 Christopher M Butler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.flexdock.docking.defaults;
import java.awt.Component;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import javax.swing.JComponent;
import org.flexdock.docking.Dockable;
import org.flexdock.docking.DockingManager;
import org.flexdock.docking.DockingPort;
import org.flexdock.docking.event.DockingEvent;
import org.flexdock.docking.event.DockingListener;
import org.flexdock.docking.props.DockablePropertySet;
import org.flexdock.docking.props.PropertyManager;
import org.flexdock.util.SwingUtility;
import org.flexdock.util.Utilities;
/**
* Provides a default implementation of the {@code Dockable} interface. This
* class should be extended by any application that wishes to make use of the
* {@code Dockable} interface without the need for writing out an implementation
* for every method that isn't explicitly used.
*
* @author Christopher Butler
*/
public abstract class AbstractDockable implements Dockable {
private String persistentId;
private ArrayList dockingListeners;
private ArrayList dragListeners;
private Hashtable clientProperties;
private HashSet frameDragSources;
/**
* Creates a new {@code AbstractDockable} instance. This constructor is
* meant to be invoked by subclasses as it initializes the
* {@code Dockable's} persistent ID and drag sources.
*
* @param id
* the persistent ID of the resulting {@code Dockable}
* @see Dockable#getPersistentId()
*/
public AbstractDockable(String id) {
persistentId = id;
dockingListeners = new ArrayList(2);
dragListeners = new ArrayList();
clientProperties = new Hashtable(2);
dragListeners.add(getComponent());
}
/**
* Returns the {@code Component} used to back this {@code Dockable}
* instance.
*
* @return the {@code Component} used to back this {@code Dockable}
* instance.
* @see Dockable#getComponent()
*/
public abstract Component getComponent();
/**
* Returns a {@code List} of {@code Components} used to initiate
* drag-to-dock operation. By default, the returned {@code List} contains
* the {@code Component} returned by {@code getComponent()}.
*
* @return a {@code List} of {@code Components} used to initiate
* drag-to-dock operation.
* @see Dockable#getDragSources()
* @see #getComponent()
*/
public List getDragSources() {
return dragListeners;
}
/**
* Returns the persistent ID of this {@code Dockable} instance provided when
* this object was instantiated.
*
* @return the persistent ID of this {@code Dockable}
* @see Dockable#getPersistentId()
* @see #AbstractDockable(String)
*/
public String getPersistentId() {
return persistentId;
}
/**
* Returns a {@code HashSet} of {@code Components} used as frame drag
* sources when this {@code Dockable} is floating in a non-decorated
* external dialog. The {@code HashSet} returned by this method is initially
* empty. Because it is mutable, however, new {@code Components} may be
* added to it.
*
* @return a {@code HashSet} of {@code Components} used as frame drag
* sources when this {@code Dockable} is floating in a non-decorated
* external dialog.
* @see Dockable#getFrameDragSources()
*/
public Set getFrameDragSources() {
if (frameDragSources == null)
frameDragSources = new HashSet();
return frameDragSources;
}
/**
* Sets the {@code String} to be used for tab labels when this
* {@code Dockable} is embedded within a tabbed layout. {@code null} values
* are discouraged, but not illegal.
*
* @param tabText
* the {@code String} to be used for tab labels when this
* {@code Dockable} is embedded within a tabbed layout.
*/
public void setTabText(String tabText) {
getDockingProperties().setDockableDesc(tabText);
}
/**
* Returns the {@code String} used for tab labels when this {@code Dockable}
* is embedded within a tabbed layout. It is possible for this method to
* return a {@code null} reference.
*
* @return tabText the {@code String} used for tab labels when this
* {@code Dockable} is embedded within a tabbed layout.
*/
public String getTabText() {
return getDockingProperties().getDockableDesc();
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
* @see DockingListener#dockingCanceled(DockingEvent)
*/
public void dockingCanceled(DockingEvent evt) {
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
* @see DockingListener#dockingComplete(DockingEvent)
*/
public void dockingComplete(DockingEvent evt) {
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
* @see DockingListener#dragStarted(DockingEvent)
*/
public void dragStarted(DockingEvent evt) {
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
* @see DockingListener#dropStarted(DockingEvent)
*/
public void dropStarted(DockingEvent evt) {
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
* @see DockingListener#undockingComplete(DockingEvent)
*/
public void undockingComplete(DockingEvent evt) {
}
/**
* No operation. Provided as a method stub to fulfull the
* {@code DockingListener} interface contract.
*
* @param evt
* the {@code DockingEvent} to respond to.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -