All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bibliothek.gui.dock.common.intern.DefaultCDockable Maven / Gradle / Ivy

Go to download

DockingFrames is an open source Java Swing docking framework, licenced under LGPL 2.1. This is the same distribution as the original distribution (http://www.docking-frames.org/), only reinstalled in maven

There is a newer version: 1.1.2p20b.fix-1
Show newest version
/*
 * Bibliothek - DockingFrames
 * Library built on Java/Swing, allows the user to "drag and drop"
 * panels containing any Swing-Component the developer likes to add.
 * 
 * Copyright (C) 2007 Benjamin Sigg
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Benjamin Sigg
 * [email protected]
 * CH - Switzerland
 */
package bibliothek.gui.dock.common.intern;

import java.awt.Component;
import java.awt.Container;
import java.awt.LayoutManager;

import javax.swing.Icon;

import bibliothek.gui.dock.common.CStation;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.action.CSeparator;
import bibliothek.gui.dock.dockable.IconHandling;
import bibliothek.util.FrameworkOnly;

/**
 * An {@link CDockable} that uses a {@link DefaultCommonDockable} to show
 * its content.
* Subclasses may override {@link #createCommonDockable()} to provide a custom subclass * of {@link DefaultCommonDockable}, note that {@link #createCommonDockable()} is called * as soon as the internal representation is required, e.g. for setting a property like * the title or the icon. * @author Benjamin Sigg */ @FrameworkOnly public class DefaultCDockable extends AbstractCDockable{ /** * Describes what the user can do with the enclosing {@link DefaultCDockable}.
* A name like X_Y tells, that feature X and * feature Y are available. The features are: *
    *
  • MIN: whether the dockable can be minimized
  • *
  • MAX: whether the dockable can be maximized
  • *
  • EXT: whether the dockable can be externalized
  • *
  • STACK: whether the dockable can be combined with other dockables, this * feature normally should be allowed.
  • *
  • CLOSE: whether the dockable can be closed by the user through an action * (normally a "x" in the right corner of the title)
  • *
* @author Benjamin Sigg */ public static enum Permissions{ /** no permissions at all */ NONE ( false, false, false, false, false ), /** all permissions */ ALL ( true, true, true, true, true ), /** all permissions except close */ DEFAULT ( true, true, true, true, false ), MIN ( true, false, false, false, false ), MAX ( false, true, false, false, false ), EXT ( false, false, true, false, false ), STACK ( false, false, false, true, false ), CLOSE ( false, false, false, false, true ), MIN_MAX ( true, true, false, false, false ), MIN_EXT ( true, false, true, false, false ), MIN_STACK ( true, false, false, true, false ), MIN_CLOSE ( true, false, false, false, true ), MAX_EXT ( false, true, true, false, false ), MAX_STACK ( false, true, false, true, false ), MAX_CLOSE ( false, true, false, false, true ), EXT_STACK ( false, false, true, true, false ), EXT_CLOSE ( false, false, true, false, true ), STACK_CLOSE ( false, false, false, true, true ), MIN_MAX_EXT ( true, true, true, false, false ), MIN_MAX_STACK ( true, true, false, true, true ), MIN_MAX_CLOSE ( true, true, false, false, true ), MIN_EXT_STACK ( true, false, true, true, false ), MIN_EXT_CLOSE ( true, false, true, false, true ), MIN_STACK_CLOSE ( true, false, false, true, true ), MAX_EXT_STACK ( false, true, true, true, false ), MAX_EXT_CLOSE ( false, true, true, false, true ), MAX_STACK_CLOSE ( false, true, false, true, true ), MIN_MAX_EXT_STACK ( true, true, true, true, false ), MIN_MAX_EXT_CLOSE ( true, true, true, false, true ), MIN_MAX_STACK_CLOSE ( true, true, false, true, true ), MIN_EXT_STACK_CLOSE ( true, false, true, true, true ), MAX_EXT_STACK_CLOSE ( false, true, true, true, true ), MIN_MAX_EXT_STACK_CLOSE ( true, true, true, true, true ); /** the user can minimize the dockable */ private boolean minimizable; /** the user can maximize the dockable */ private boolean maximizable; /** the user can externalize the dockable */ private boolean externalizable; /** the user can stack the dockable */ private boolean stackable; /** the user can close the dockable */ private boolean closeable; /** * Creates a new Permissions. * @param min {@link #minimizable} * @param max {@link #maximizable} * @param ext {@link #externalizable} * @param stack {@link #stackable} * @param close {@link #closeable} */ private Permissions( boolean min, boolean max, boolean ext, boolean stack, boolean close ){ this.minimizable = min; this.maximizable = max; this.externalizable = ext; this.stackable = stack; this.closeable = close; } /** * Represents the property {@link DefaultCDockable#isCloseable()}. * @return true if the user can close the dockable */ public boolean isCloseable() { return closeable; } /** * Represents the property {@link DefaultCDockable#isExternalizable()}. * @return true if the user can externalize the dockable */ public boolean isExternalizable() { return externalizable; } /** * Represents the property {@link DefaultCDockable#isMaximizable()}. * @return true if the user can maximize the dockable */ public boolean isMaximizable() { return maximizable; } /** * Represents the property {@link DefaultCDockable#isMinimizable()}. * @return true if the user can minimize the dockable */ public boolean isMinimizable() { return minimizable; } /** * Represents the property {@link DefaultCDockable#isStackable()}. * @return true if the user can combine the dockable with * other dockables */ public boolean isStackable() { return stackable; } } /** whether this dockable can be minimized */ private boolean minimizable; /** whether this dockable can be maximized */ private boolean maximizable; /** whether this dockable can be put into a dialog */ private boolean externalizable; /** whether this dockable can be closed by the user */ private boolean closeable; /** whether this dockable can be combined with other dockables */ private boolean stackable; /** * Creates a new dockable */ public DefaultCDockable( ){ this( Permissions.DEFAULT ); } /** * Creates a new dockable. * @param permission the permissions of this dockable */ public DefaultCDockable( Permissions permission ){ setMinimizable( permission.isMinimizable() ); setMaximizable( permission.isMaximizable() ); setExternalizable( permission.isExternalizable() ); setStackable( permission.isStackable() ); setCloseable( permission.isCloseable() ); } @Override protected DefaultCommonDockable createCommonDockable(){ return new DefaultCommonDockable( this, getClose() ); } /** * Gets the container on which the client can pack its components. * @return the panel showing the content */ public Container getContentPane(){ return intern().getContentPane(); } /** * Sets the {@link LayoutManager} of the {@link #getContentPane() content pane}. * @param layout the new layout manager */ public void setLayout( LayoutManager layout ){ getContentPane().setLayout( layout ); } /** * Adds component to the content pane. * @param component the new component */ public void add( Component component ){ getContentPane().add( component ); } /** * Adds component to the content pane. * @param component the new component * @param constraints constraints for the {@link #setLayout(LayoutManager) layout manager} */ public void add( Component component, Object constraints ){ getContentPane().add( component, constraints ); } /** * Removes component from the content pane. * @param component the component to remove */ public void remove( Component component ){ getContentPane().remove( component ); } /** * Sets the text that is shown as title. * @param text the title */ public void setTitleText( String text ){ intern().setTitleText( text ); } /** * Gets the text that is shown as title. * @return the title */ public String getTitleText(){ return intern().getTitleText(); } /** * Sets the tooltip that should be shown on the title of this dockable. * @param text the new tooltip, can be null */ public void setTitleToolTip( String text ){ intern().setTitleToolTip( text ); } /** * Gets the tooltip that is shown on the title of this dockable. * @return the tooltip or null */ public String getTitleToolTip(){ return intern().getTitleToolTip(); } /** * Sets the behavior of {@link #setTitleIcon(Icon)} in case of a null argument. Either * the icon is replaced by the default icon, or just not shown. * @param handling the new behavior, not null */ public void setTitleIconHandling( IconHandling handling ){ intern().setTitleIconHandling( handling ); } /** * Gets the behavior of {@link #setTitleIcon(Icon)}. * @return the behavior, not null */ public IconHandling getTitleIconHandling(){ return intern().getTitleIconHandling(); } /** * Sets the icon that is shown in the title of this CDockable. The exact behavior * of this method depends on the {@link IconHandling} that was set by {@link #setTitleIconHandling(IconHandling)}. * @param icon the title-icon */ public void setTitleIcon( Icon icon ){ intern().setTitleIcon( icon ); } /** * Gets the icon that is shown in the title. * @return the title-icon, might be null */ public Icon getTitleIcon(){ return intern().getTitleIcon(); } public boolean isMinimizable(){ return minimizable; } /** * Sets whether the user can minimize this dockable. * @param minimizable true if the user can minimize this element */ public void setMinimizable( boolean minimizable ){ if( this.minimizable != minimizable ){ this.minimizable = minimizable; listenerCollection.getCDockablePropertyListener().minimizableChanged( this ); CControlAccess control = control(); if( control != null ){ control.getLocationManager().ensureValidLocation( this ); } } } public boolean isMaximizable(){ return maximizable; } /** * Sets whether the user can maximize this dockable. * @param maximizable true if the user can maximize this element */ public void setMaximizable( boolean maximizable ){ if( this.maximizable != maximizable ){ this.maximizable = maximizable; listenerCollection.getCDockablePropertyListener().maximizableChanged( this ); CControlAccess control = control(); if( control != null ){ control.getLocationManager().ensureValidLocation( this ); } } } public boolean isExternalizable(){ return externalizable; } /** * Sets whether the user can externalize this dockable. * @param externalizable true if the user can externalize this element */ public void setExternalizable( boolean externalizable ){ if( this.externalizable != externalizable ){ this.externalizable = externalizable; listenerCollection.getCDockablePropertyListener().externalizableChanged( this ); CControlAccess control = control(); if( control != null ){ control.getLocationManager().ensureValidLocation( this ); } } } public boolean isCloseable(){ return closeable; } /** * Sets whether this element can be combined with other dockable to create * a stack. Note that this property is ignored if this element is already * in a stack. * @param stackable true if this element can be combined. */ public void setStackable( boolean stackable ) { this.stackable = stackable; } public boolean isStackable() { return stackable; } /** * Sets whether the user can close this dockable. * @param closeable true if the user can close this element */ public void setCloseable( boolean closeable ){ if( this.closeable != closeable ){ this.closeable = closeable; listenerCollection.getCDockablePropertyListener().closeableChanged( this ); } } /** * Adds an action to this dockable. The action will be shown in the * popup-menu which belongs to this dockable, and also as button in some titles * of this dockable. * @param action the new action */ public void addAction( CAction action ){ intern().getActions().add( action ); } /** * Adds a new action to this dockable. * @param index the location of the action * @param action the action * @see #addAction(CAction) */ public void insertAction( int index, CAction action ){ intern().getActions().insert( index, action ); } /** * Adds a separator to the list of {@link CAction}s of this dockable. */ public void addSeparator(){ addAction( CSeparator.SEPARATOR ); } /** * Adds a separator to the list of {@link CAction}s of this dockable. * @param index the location of the action */ public void insertSeparator( int index ){ insertAction( index, CSeparator.SEPARATOR ); } /** * Removes an action from this dockable * @param index the location of the action */ public void removeAction( int index ){ intern().getActions().remove( index ); } /** * Removes an action from this dockable. * @param action the action to remove */ public void removeAction( CAction action ){ intern().getActions().remove( action ); } /** * Gets the number of {@link CAction}s that were added to this dockable. * @return the number of actions */ public int getActionCount(){ return intern().getActions().getDockActionCount(); } /** * Gets the index'th action of this dockable. Be aware that * the result might be {@link CSeparator#SEPARATOR}. * @param index the location of an action * @return the action */ public CAction getAction( int index ){ return intern().getActions().getAction( index ); } @Override public DefaultCommonDockable intern() { return (DefaultCommonDockable)super.intern(); } public CStation asStation(){ return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy