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

bibliothek.gui.dock.common.layout.FullLockConflictResolver 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) 2008 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.layout;

import bibliothek.gui.dock.facile.station.split.*;

/**
 * This {@link ConflictResolver} has a alternative strategy how to handle cases
 * where two requests collide and a satisfying solution is not possible: the
 * two affected trees are checked for their "fully locked state" and if one
 * is fully locked but not the other, then the request of the fully locked one
 * is answered. Fully locked means that each child of some node has a request. 
 * @author Benjamin Sigg
 *
 */
public class FullLockConflictResolver extends DefaultConflictResolver{
    @Override
    public double resolveHorizontal( ResizeNode node,
            ResizeRequest left, double deltaLeft, ResizeRequest right,
            double deltaRight ) {

        if( left.getFractionWidth() == 1 && right.getFractionWidth() == 1 ){
            boolean leftLocked = checkHorizontalFullLock( node.getLeft() );
            boolean rightLocked = checkHorizontalFullLock( node.getRight() );

            if( !leftLocked && rightLocked ){
                return deltaRight;
            }
            else if( leftLocked && !rightLocked ){
                return deltaLeft;
            }
        }

        return super.resolveHorizontal( node, left, deltaLeft, right, deltaRight );
    }
    @Override
    public double resolveVertical( ResizeNode node,
            ResizeRequest top, double deltaTop, ResizeRequest bottom,
            double deltaBottom ) {
        
        if( top.getFractionWidth() == 1 && bottom.getFractionWidth() == 1 ){
            boolean topLocked = checkVerticalFullLock( node.getLeft() );
            boolean bottomLocked = checkVerticalFullLock( node.getRight() );
            
            if( !topLocked && bottomLocked ){
                return deltaBottom;
            }
            else if( topLocked && !bottomLocked ){
                return deltaTop;
            }
        }

        return super.resolveVertical( node, top, deltaTop, bottom, deltaBottom );
    }

    /**
     * Checks whether element is fully locked in its horizontal dimension.
     * Fully locked means that: 
*
    *
  • if element is a node: its children have both requests * for a change in width and its children are also * {@link #checkHorizontalFullLock(ResizeElement) fully locked}
  • *
  • if element is a leaf: it has a resize request for the width
  • *
  • in any other case: true
  • *
* @param element the element to check * @return true if the horizontal dimension has very high * priority for this node, false otherwise */ protected boolean checkHorizontalFullLock( ResizeElement element ){ if( element instanceof ResizeNode ){ ResizeNode node = (ResizeNode)element; ResizeRequest leftRequest = node.getLeft().getRequest(); ResizeRequest rightRequest = node.getRight().getRequest(); if( leftRequest == null || leftRequest.getFractionWidth() == -1 ) return false; if( rightRequest == null || rightRequest.getFractionWidth() == -1 ) return false; if( !checkHorizontalFullLock( node.getLeft())) return false; if( !checkHorizontalFullLock( node.getRight())) return false; } else if( element instanceof ResizeLeaf ){ ResizeLeaf leaf = (ResizeLeaf)element; ResizeRequest request = leaf.getRequest(); if( request == null || request.getFractionWidth() == -1 ) return false; } return true; } /** * Checks whether element is fully locked in its vertical dimension. * Fully locked means that:
*
    *
  • if element is a node: its children have both requests * for a change in height and its children are also * {@link #checkHorizontalFullLock(ResizeElement) fully locked}
  • *
  • if element is a leaf: it has a resize request for the height
  • *
  • in any other case: true
  • *
* @param element the element to check * @return true if the vertical dimension has very high * priority for this node, false otherwise */ protected boolean checkVerticalFullLock( ResizeElement element ){ if( element instanceof ResizeNode ){ ResizeNode node = (ResizeNode)element; ResizeRequest leftRequest = node.getLeft().getRequest(); ResizeRequest rightRequest = node.getRight().getRequest(); if( leftRequest == null || leftRequest.getFractionHeight() == -1 ) return false; if( rightRequest == null || rightRequest.getFractionHeight() == -1 ) return false; if( !checkVerticalFullLock( node.getLeft())) return false; if( !checkVerticalFullLock( node.getRight())) return false; } else if( element instanceof ResizeLeaf ){ ResizeLeaf leaf = (ResizeLeaf)element; ResizeRequest request = leaf.getRequest(); if( request == null || request.getFractionHeight() == -1 ) return false; } return true; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy