Advertisement
Guest User

CPanel

a guest
Oct 16th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.03 KB | None | 0 0
  1. /******************************************************************************
  2.  * Product: Adempiere ERP & CRM Smart Business Solution                       *
  3.  * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
  4.  * This program is free software; you can redistribute it and/or modify it    *
  5.  * under the terms version 2 of the GNU General Public License as published   *
  6.  * by the Free Software Foundation. This program is distributed in the hope   *
  7.  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
  8.  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
  9.  * See the GNU General Public License for more details.                       *
  10.  * You should have received a copy of the GNU General Public License along    *
  11.  * with this program; if not, write to the Free Software Foundation, Inc.,    *
  12.  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
  13.  * For the text or an alternative of this public license, you may reach us    *
  14.  * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
  15.  * or via info@compiere.org or http://www.compiere.org/license.html           *
  16.  *****************************************************************************/
  17. package org.compiere.swing;
  18.  
  19. import java.awt.Color;
  20. import java.awt.LayoutManager;
  21.  
  22. import javax.swing.JPanel;
  23.  
  24. import org.adempiere.plaf.AdempiereLookAndFeel;
  25. import org.adempiere.plaf.AdempierePLAF;
  26. import org.compiere.plaf.CompiereColor;
  27. import org.compiere.plaf.CompiereLookAndFeel;
  28.  
  29. /**
  30.  *  Adempiere Panel supporting colored Backgrounds
  31.  *
  32.  *  @author     Jorg Janke
  33.  *  @version    $Id: CPanel.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
  34.  */
  35. public class CPanel extends JPanel
  36. {
  37.     /**
  38.      *
  39.      */
  40.     private static final long serialVersionUID = 4153588317643163582L;
  41.  
  42.  
  43.     /**
  44.      * Creates a new AdempierePanel with the specified layout manager
  45.      * and buffering strategy.
  46.      * @param layout  the LayoutManager to use
  47.      * @param isDoubleBuffered  a boolean, true for double-buffering, which
  48.      *        uses additional memory space to achieve fast, flicker-free updates
  49.      */
  50.     public CPanel (LayoutManager layout, boolean isDoubleBuffered)
  51.     {
  52.         super (layout, isDoubleBuffered);
  53.         init();
  54.     }   //  CPanel
  55.  
  56.     /**
  57.      * Create a new buffered CPanel with the specified layout manager
  58.      * @param layout  the LayoutManager to use
  59.      */
  60.     public CPanel (LayoutManager layout)
  61.     {
  62.         super (layout);
  63.         init();
  64.     }   //  CPanel
  65.  
  66.     /**
  67.      * Creates a new <code>CPanel</code> with <code>FlowLayout</code>
  68.      * and the specified buffering strategy.
  69.      * If <code>isDoubleBuffered</code> is true, the <code>CPanel</code>
  70.      * will use a double buffer.
  71.      * @param isDoubleBuffered  a boolean, true for double-buffering, which
  72.      *        uses additional memory space to achieve fast, flicker-free updates
  73.      */
  74.     public CPanel (boolean isDoubleBuffered)
  75.     {
  76.         super (isDoubleBuffered);
  77.         init();
  78.     }   //  CPanel
  79.  
  80.     /**
  81.      * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
  82.      */
  83.     public CPanel()
  84.     {
  85.         super ();
  86.         init();
  87.     }   //  CPanel
  88.  
  89.     /**
  90.      * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
  91.      * @param bc Initial Background Color
  92.      */
  93.     public CPanel(CompiereColor bc)
  94.     {
  95.         this ();
  96.         init();
  97.         setBackgroundColor (bc);
  98.     }   //  CPanel
  99.  
  100.     /**
  101.      *  Common init.
  102.      *  Adempiere backround requires that for the base, background is set explictily.
  103.      *  The additional panels should be transparent.
  104.      */
  105.     private void init()
  106.     {
  107.         setOpaque(false);   //  transparent
  108.     }   //  init
  109.  
  110.    
  111.     /**************************************************************************
  112.      *  Set Background - ignored by UI -
  113.      *  @param bg ignored
  114.      */
  115.     public void setBackground (Color bg)
  116.     {
  117.         if (bg.equals(getBackground()))
  118.             return;
  119.         super.setBackground (bg);
  120.         //  ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
  121.         //if (!Trace.getCallerClass(1).startsWith("javax"))
  122.         setBackgroundColor (new CompiereColor(bg));
  123.     }   //  setBackground
  124.  
  125.     /**
  126.      *  Set Background
  127.      *  @param bg AdempiereColor for Background, if null set standard background
  128.      */
  129.     public void setBackgroundColor (CompiereColor bg)
  130.     {
  131.         if (bg == null)
  132.             bg = new CompiereColor(AdempierePLAF.getFormBackground());
  133.         setOpaque(true);    //  not transparent
  134.         putClientProperty(CompiereLookAndFeel.BACKGROUND, bg);
  135.         super.setBackground (bg.getFlatColor());
  136.     }   //  setBackground
  137.  
  138.     /**
  139.      *  Get Background
  140.      *  @return Color for Background
  141.      */
  142.     public CompiereColor getBackgroundColor ()
  143.     {
  144.         try
  145.         {
  146.             return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND);
  147.         }
  148.         catch (Exception e)
  149.         {
  150.             System.err.println("CPanel - ClientProperty: " + e.getMessage());
  151.         }
  152.         return null;
  153.     }   //  getBackgroundColor
  154.  
  155.     /*************************************************************************/
  156.  
  157.     /**
  158.      *  Set Tab Hierarchy Level.
  159.      *  Has only effect, if tabs are on left or right side
  160.      *
  161.      *  @param level
  162.      */
  163.     public void setTabLevel (int level)
  164.     {
  165.         if (level == 0)
  166.             putClientProperty(AdempiereLookAndFeel.TABLEVEL, null);
  167.         else
  168.             putClientProperty(AdempiereLookAndFeel.TABLEVEL, new Integer(level));
  169.     }   //  setTabLevel
  170.  
  171.     /**
  172.      *  Get Tab Hierarchy Level
  173.      *  @return Tab Level
  174.      */
  175.     public int getTabLevel()
  176.     {
  177.         try
  178.         {
  179.             Integer ll = (Integer)getClientProperty(CompiereLookAndFeel.TABLEVEL);
  180.             if (ll != null)
  181.                 return ll.intValue();
  182.         }
  183.         catch (Exception e)
  184.         {
  185.             System.err.println("ClientProperty: " + e.getMessage());
  186.         }
  187.         return 0;
  188.     }   //  getTabLevel
  189.  
  190.    
  191.     /**************************************************************************
  192.      *  String representation
  193.      *  @return String representation
  194.      */
  195.     public String toString()
  196.     {
  197.         StringBuffer sb = new StringBuffer ("CPanel [");
  198.         sb.append(super.toString());
  199.         CompiereColor bg = getBackgroundColor();
  200.         if (bg != null)
  201.             sb.append(bg.toString());
  202.         sb.append("]");
  203.         return sb.toString();
  204.     }   //  toString
  205.  
  206. }   //  CPanel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement