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

org.noos.xing.mydoggy.plaf.ui.cmp.UIFSplitPane Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2000-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  o Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  o Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 *  o Neither the name of JGoodies Karsten Lentzsch nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.noos.xing.mydoggy.plaf.ui.cmp;

import javax.swing.*;
import javax.swing.plaf.SplitPaneUI;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;

/**
 * A JSplitPane subclass that can try to remove the divider border.
 * Useful if the splitted components render their own borders.
 * Note that this feature is not supported by all look&feels.
 * Some look&feel implementation will always show a divider border,
 * and conversely, others will never show a divider border.
 *
 * @author Karsten Lentzsch
 * @version $Revision: 1.2 $
 *
 * @see javax.swing.plaf.basic.BasicSplitPaneUI
 */
public class UIFSplitPane extends JSplitPane {

   /**
    * Holds the name of the bound property that tries to show or hide
    * the split pane's divider border.
    *
    * @see #isDividerBorderVisible()
    * @see #setDividerBorderVisible(boolean)
    */
   public static final String PROPERTYNAME_DIVIDER_BORDER_VISIBLE =
       "dividerBorderVisible";

   /**
    * Determines whether the divider border shall be removed when
    * the UI is updated.
    *
    * @see #isDividerBorderVisible()
    * @see #setDividerBorderVisible(boolean)
    */
   private boolean dividerBorderVisible;


   // Instance Creation *****************************************************

   /**
    * Constructs a UIFSplitPane configured to arrange the child
    * components side-by-side horizontally with no continuous
    * layout, using two buttons for the components.
    */
   public UIFSplitPane() {
       this(JSplitPane.HORIZONTAL_SPLIT, false,
               new JButton(UIManager.getString("SplitPane.leftButtonText")),
               new JButton(UIManager.getString("SplitPane.rightButtonText")));
   }


   /**
    * Constructs a UIFSplitPane configured with the
    * specified orientation and no continuous layout.
    *
    * @param newOrientation  JSplitPane.HORIZONTAL_SPLIT or
    *                        JSplitPane.VERTICAL_SPLIT
    * @throws IllegalArgumentException if orientation
    *          is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
    */
   public UIFSplitPane(int newOrientation) {
       this(newOrientation, false);
   }


   /**
    * Constructs a UIFSplitPane with the specified
    * orientation and redrawing style.
    *
    * @param newOrientation  JSplitPane.HORIZONTAL_SPLIT or
    *                        JSplitPane.VERTICAL_SPLIT
    * @param newContinuousLayout  a boolean, true for the components to
    *        redraw continuously as the divider changes position, false
    *        to wait until the divider position stops changing to redraw
    * @throws IllegalArgumentException if orientation
    *          is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
    */
   public UIFSplitPane(int newOrientation,
                     boolean newContinuousLayout) {
       this(newOrientation, newContinuousLayout, null, null);
   }


   /**
    * Constructs a UIFSplitPane with the specified orientation
    * and the given componenents.
    *
    * @param orientation  JSplitPane.HORIZONTAL_SPLIT or
    *                        JSplitPane.VERTICAL_SPLIT
    * @param leftComponent the Component that will
    *    appear on the left of a horizontally-split pane,
    *    or at the top of a vertically-split pane
    * @param rightComponent the Component that will
    *    appear on the right of a horizontally-split pane,
    *    or at the bottom of a vertically-split pane
    * @throws IllegalArgumentException if orientation
    *    is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
    */
   public UIFSplitPane(int orientation,
                        Component leftComponent,
                        Component rightComponent) {
       this(orientation, false, leftComponent, rightComponent);
   }


   /**
    * Constructs a UIFSplitPane with the specified orientation,
    * redrawing style, and given components.
    *
    * @param orientation  JSplitPane.HORIZONTAL_SPLIT or
    *                        JSplitPane.VERTICAL_SPLIT
    * @param continuousLayout  a boolean, true for the components to
    *        redraw continuously as the divider changes position, false
    *        to wait until the divider position stops changing to redraw
    * @param leftComponent the Component that will
    *          appear on the left
    *          of a horizontally-split pane, or at the top of a
    *          vertically-split pane
    * @param rightComponent the Component that will
    *          appear on the right
    *          of a horizontally-split pane, or at the bottom of a
    *          vertically-split pane
    * @throws IllegalArgumentException if orientation
    *          is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
    */
   public UIFSplitPane(int orientation,
                     boolean continuousLayout,
                     Component leftComponent,
                     Component rightComponent){
       super(orientation, continuousLayout, leftComponent, rightComponent);
       dividerBorderVisible = false;
   }


   /**
    * Constructs a UIFSplitPane,
    * i.e. a JSplitPane that has no borders.
    * Also disabled the one touch exandable property.
    *
    * @param orientation  JSplitPane.HORIZONTAL_SPLIT or
    *                        JSplitPane.VERTICAL_SPLIT
    * @param leftComponent the Component that will
    *    appear on the left of a horizontally-split pane,
    *    or at the top of a vertically-split pane
    * @param rightComponent the Component that will
    *    appear on the right of a horizontally-split pane,
    *    or at the bottom of a vertically-split pane
    * @throws IllegalArgumentException if orientation
    *    is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
    */
   public static UIFSplitPane createStrippedSplitPane(
            int orientation,
            Component leftComponent,
            Component rightComponent) {
       UIFSplitPane split = new UIFSplitPane(orientation, leftComponent,
rightComponent);
       split.setBorder(BorderFactory.createEmptyBorder());
       split.setOneTouchExpandable(false);
       return split;
   }


   // Accessing Properties **************************************************

   /**
    * Checks and answers whether the divider border shall be visible
    * or invisible.
    * Note that this feature is not supported by all look&feels.
    * Some look&feel implementation will always show a divider border,
    * and conversely, others will never show a divider border.
    *
    * @return the desired (but potentially inaccurate) divider border
visiblity
    */
   public boolean isDividerBorderVisible() {
       return dividerBorderVisible;
   }


   /**
    * Makes the divider border visible or invisible.
    * Note that this feature is not supported by all look&feels.
    * Some look&feel implementation will always show a divider border,
    * and conversely, others will never show a divider border.
    *
    * @param newVisibility   true for visible, false for invisible
    */
   public void setDividerBorderVisible(boolean newVisibility) {
       boolean oldVisibility = isDividerBorderVisible();
       if (oldVisibility == newVisibility)
           return;
       dividerBorderVisible = newVisibility;
       updateUI();
       firePropertyChange(PROPERTYNAME_DIVIDER_BORDER_VISIBLE,
                          oldVisibility,
                          newVisibility);
   }


   // Changing the Divider Border Visibility *********************************

   /**
    * Updates the UI and sets an empty divider border. The divider border
    * may be restored by a L&F at UI installation time. And so, we
    * try to reset it each time the UI is changed.
    */
   public void updateUI() {
       super.updateUI();
       if (!isDividerBorderVisible())
           setEmptyDividerBorder();
   }


   /**
    * Sets an empty divider border if and only if the UI is
    * an instance of BasicSplitPaneUI.
    */
   private void setEmptyDividerBorder() {
       SplitPaneUI splitPaneUI = getUI();
       if (splitPaneUI instanceof BasicSplitPaneUI) {
           BasicSplitPaneUI basicUI = (BasicSplitPaneUI) splitPaneUI;
           basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder());
       }
   }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy