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

bibliothek.gui.dock.common.action.panel.AbstractPanelPopupWindow 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) 2009 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.action.panel;

import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;

/**
 * Abstract implementation of {@link PanelPopupWindow}, handles
 * the {@link PanelPopupWindowListener}s.
* Subclasses should call {@link #validateBounds(Rectangle, GraphicsConfiguration)} before they get visible * @author Benjamin Sigg */ public abstract class AbstractPanelPopupWindow implements PanelPopupWindow{ private List listeners = new ArrayList(); public void addListener( PanelPopupWindowListener listener ){ if( listener == null ) throw new IllegalArgumentException( "listener must not be null" ); listeners.add( listener ); } public void removeListener( PanelPopupWindowListener listener ){ listeners.remove( listener ); } /** * Returns an array containing all the listeners of this {@link AbstractPanelPopupWindow}. * @return all the listeners */ protected PanelPopupWindowListener[] listeners(){ return listeners.toArray( new PanelPopupWindowListener[ listeners.size() ] ); } /** * Informs all listeners that this window has been closed */ protected void fireClosed(){ for( PanelPopupWindowListener listener : listeners() ){ listener.closed( this ); } } /** * Should be called before this window is made visible, ensure that the boundaries are valid. * @param bounds the proposed boundaries * @param configuration the screen on which this window is going to be visible, might be null * @return the actual boundaries, can be null to indicate that bounds is valid */ protected Rectangle validateBounds( Rectangle bounds, GraphicsConfiguration configuration ){ if( configuration == null ){ return null; } Rectangle screen = configuration.getBounds(); bounds = new Rectangle( bounds ); bounds.width = Math.min( bounds.width, screen.width ); bounds.height = Math.min( bounds.height, screen.height ); bounds.x = Math.min( Math.max( bounds.x, screen.x ), screen.x + screen.width - bounds.width ); bounds.y = Math.min( Math.max( bounds.y, screen.y ), screen.y + screen.height - bounds.height ); return bounds; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy