Package cookxml.cookswing.adder

Source Code of cookxml.cookswing.adder.TabAdder

/*
* (c) Copyright 2004 by Heng Yuan
*
* 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,
* ITNESS 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 cookxml.cookswing.adder;

import java.awt.*;
import javax.swing.*;

import cookxml.cookswing.helper.TabHelper;
import cookxml.core.DecodeEngine;
import cookxml.core.interfaces.Adder;

/**
* This adder is used to add a TabHelper to the JTabbedPane.
*
* @see javax.swing.JTabbedPane
* @see cookxml.cookswing.helper.TabHelper
* @author Heng Yuan
* @version $Id: TabAdder.java 233 2007-06-06 08:08:49Z coconut $
* @since CookSwing 1.0
*/
public class TabAdder implements Adder
{
  public boolean add (String ns, String parentTag, Object parent, Object child, DecodeEngine decodeEngine)
  {
    if (parent == null || child == null ||
      !(parent instanceof TabHelper) ||
      !(child instanceof Component))
      return false;

    Object grandParent = decodeEngine.getParent (parent);
    if (grandParent == null || !(grandParent instanceof JTabbedPane))
      return false;

    JTabbedPane tabbedpane = (JTabbedPane)grandParent;

    Component c = tabbedpane.add ((Component)child);
    int i = tabbedpane.indexOfComponent (c);

    TabHelper tab = (TabHelper)parent;
    String title = tab.title;
    if (title != null)
      tabbedpane.setTitleAt (i, title);
    String toolTipText = tab.toolTipText;
    if (toolTipText != null)
      tabbedpane.setToolTipTextAt (i, toolTipText);
    Icon icon = tab.icon;
    if (icon != null)
      tabbedpane.setIconAt (i, icon);
    Icon disabledIcon = tab.disabledIcon;
    if (disabledIcon != null)
      tabbedpane.setDisabledIconAt (i, icon);
    Color foreground = tab.foreground;
    if (foreground != null)
      tabbedpane.setForegroundAt (i, foreground);
    Color background = tab.background;
    if (background != null)
      tabbedpane.setBackgroundAt (i, background);
    Integer mnemonic = tab.mnemonic;
    if (mnemonic != null)
      tabbedpane.setMnemonicAt (i, mnemonic.intValue ());
    Integer displayedMnemonicIndex = tab.displayedMnemonicIndex;
    if (displayedMnemonicIndex != null)
      tabbedpane.setDisplayedMnemonicIndexAt (i, displayedMnemonicIndex.intValue ());
    Boolean enabled = tab.enabled;
    if (enabled != null)
      tabbedpane.setEnabledAt (i, enabled.booleanValue ());

    return true;
  }
}
TOP

Related Classes of cookxml.cookswing.adder.TabAdder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.