org.flexdock.docking.props.PropertyManager Maven / Gradle / Ivy
The newest version!
/*
* 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.props;
import java.awt.Component;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
import org.flexdock.docking.Dockable;
import org.flexdock.docking.DockingPort;
import org.flexdock.util.ClassMapping;
import org.flexdock.util.SwingUtility;
/**
* @author Christopher Butler
*/
public class PropertyManager {
public static final String DOCKABLE_PROPERTIES_KEY = DockablePropertySet.class.getName();
public static final String DOCKINGPORT_PROPERTIES_KEY = DockingPortPropertySet.class.getName();
private static final ClassMapping DOCKABLE_PROPS_MAPPING = new ClassMapping(ScopedDockablePropertySet.class, null);
private static final HashMap DOCKABLE_CLIENT_PROPERTIES = new HashMap();
public static DockingPortPropertySet getDockingPortRoot() {
return ScopedDockingPortPropertySet.ROOT_PROPS;
}
public static DockablePropertySet getDockableRoot() {
return ScopedDockablePropertySet.ROOT_PROPS;
}
public static void setDockablePropertyType(Class dockable, Class propType) {
if(dockable==null || propType==null) {
return;
}
if(!Dockable.class.isAssignableFrom(dockable) || !DockablePropertySet.class.isAssignableFrom(propType)) {
return;
}
DOCKABLE_PROPS_MAPPING.addClassMapping(dockable, propType);
}
public static DockablePropertySet getDockablePropertySet(Dockable dockable) {
if(dockable==null) {
return null;
}
Object obj = dockable.getClientProperty(DOCKABLE_PROPERTIES_KEY);
if(!(obj instanceof DockablePropertySet)) {
obj = createDockablePropertySet(dockable);
linkPropertySet(dockable, (DockablePropertySet)obj);
}
return (DockablePropertySet)obj;
}
private static void linkPropertySet(Dockable dockable, DockablePropertySet propertySet) {
dockable.putClientProperty(DOCKABLE_PROPERTIES_KEY, propertySet);
PropertyChangeListener[] listeners = PropertyChangeListenerFactory.getListeners();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy