Adempiere 3.1.2

This commit is contained in:
vpj-cd 2006-12-07 03:24:12 +00:00
parent b4c4d18be1
commit 110f14a7f5
24 changed files with 6209 additions and 5818 deletions

View File

@ -63,6 +63,15 @@ public final class AdempierePLAF
{ {
/** Logger */ /** Logger */
private static Logger log = Logger.getLogger(AdempierePLAF.class.getName()); private static Logger log = Logger.getLogger(AdempierePLAF.class.getName());
/** Version tag */
public static final String VERSION = "R1.4.0";
/** Key of Client Property to paint in CompiereColor */
public static final String BACKGROUND = "AdempiereBackground";
/** Key of Client Property for Rectangle Items - if exists, the standard background is used */
public static final String BACKGROUND_FILL = "AdempiereBackgroundFill";
/** Key of Client Property for CPanel */
public static final String TABLEVEL = "AdempiereTabLevel";
/****** Background *******************************************************/ /****** Background *******************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -3,27 +3,27 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.plaf; package org.compiere.plaf;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.metal.*; import javax.swing.plaf.metal.*;
/** /**
* Compiere Look & Feel. * Compiere Look & Feel.
* We wanted a nice UI not the battleship gray based stuff. * We wanted a nice UI not the battleship gray based stuff.
* I guess a matter of taste. * I guess a matter of taste.
* <code> * <code>
* : * :
@ -36,10 +36,10 @@ import javax.swing.plaf.metal.*;
*/ */
public class CompiereLookAndFeel extends MetalLookAndFeel public class CompiereLookAndFeel extends MetalLookAndFeel
{ {
/** /**
* Constructor * Constructor
*/ */
public CompiereLookAndFeel() public CompiereLookAndFeel()
{ {
super(); super();
// System.setProperty("awt.visualbell", "true"); // System.setProperty("awt.visualbell", "true");
@ -47,198 +47,195 @@ public class CompiereLookAndFeel extends MetalLookAndFeel
/** The name */ /** The name */
public static final String NAME = "Compiere"; public static final String NAME = "Compiere";
/** The Theme */ /** The Theme */
private static CompiereTheme s_compiereTheme = new CompiereThemeBlueMetal(); private static CompiereTheme s_compiereTheme = new CompiereThemeBlueMetal();
private static MetalTheme s_theme = s_compiereTheme; private static MetalTheme s_theme = s_compiereTheme;
/** Paint Round Corners */ /** Paint Round Corners */
protected static boolean ROUND = false; protected static boolean ROUND = false;
/** Key of Client Property to paint in CompiereColor */
public static final String BACKGROUND = "CompiereBackground";
/** Key of Client Property for Rectangle Items - if exists, the standard background is used */
public static final String BACKGROUND_FILL = "CompiereBackgroundFill";
/** Key of Client Property for CPanel */
public static final String TABLEVEL = "CompiereTabLevel";
/** Version tag */
public static final String VERSION = "R1.4.0";
/** /**
* The Name * The Name
* @return Name * @return Name
*/ */
public String getName() public String getName()
{ {
return NAME; return NAME;
} // getName } // getName
/** /**
* The ID * The ID
* @return Name * @return Name
*/ */
public String getID() public String getID()
{ {
return NAME; return NAME;
} // getID } // getID
/** /**
* The Description * The Description
* @return description * @return description
*/ */
public String getDescription() public String getDescription()
{ {
return "Compiere Look & Feel - (c) 2001-2005 Jorg Janke"; return "Compiere Look & Feel - (c) 2001-2005 Jorg Janke";
} // getDescription } // getDescription
/************************************************************************** /**************************************************************************
* Get/Create Defaults * Get/Create Defaults
* @return UI Defaults * @return UI Defaults
*/ */
public UIDefaults getDefaults() public UIDefaults getDefaults()
{ {
// System.out.println("CompiereLookAndFeel.getDefaults");
// Theme already created/set // Theme already created/set
MetalLookAndFeel.setCurrentTheme(s_theme); MetalLookAndFeel.setCurrentTheme(s_theme);
UIDefaults defaults = super.getDefaults(); // calls init..Defaults UIDefaults defaults = super.getDefaults(); // calls init..Defaults
return defaults; return defaults;
} // getDefaults } // getDefaults
/** /**
* Creates the mapping from UI class IDs to <code>ComponentUI</code> classes, * Creates the mapping from UI class IDs to <code>ComponentUI</code> classes,
* putting the ID-<code>ComponentUI</code> pairs in the passed-in defaults table. * putting the ID-<code>ComponentUI</code> pairs in the passed-in defaults table.
* Each <code>JComponent</code> class specifies its own UI class ID string. * Each <code>JComponent</code> class specifies its own UI class ID string.
* *
* @param table UI Defaults * @param table UI Defaults
*/ */
protected void initClassDefaults(UIDefaults table) protected void initClassDefaults(UIDefaults table)
{ {
// System.out.println("CompiereLookAndFeel.initClassDefaults");
super.initClassDefaults( table); super.initClassDefaults( table);
// Overwrite // Overwrite
putDefault (table, "PanelUI"); putDefault (table, "PanelUI");
putDefault (table, "ButtonUI"); putDefault (table, "ButtonUI");
putDefault (table, "ToggleButtonUI"); putDefault (table, "ToggleButtonUI");
putDefault (table, "TabbedPaneUI"); putDefault (table, "TabbedPaneUI");
putDefault (table, "TableHeaderUI"); putDefault (table, "TableHeaderUI");
putDefault (table, "RadioButtonUI"); putDefault (table, "RadioButtonUI");
putDefault (table, "CheckBoxUI"); putDefault (table, "CheckBoxUI");
putDefault (table, "ComboBoxUI"); putDefault (table, "ComboBoxUI");
putDefault (table, "MenuUI"); putDefault (table, "MenuUI");
putDefault (table, "MenuBarUI"); putDefault (table, "MenuBarUI");
putDefault (table, "MenuItemUI"); putDefault (table, "MenuItemUI");
putDefault (table, "CheckBoxMenuItemUI"); putDefault (table, "CheckBoxMenuItemUI");
putDefault (table, "ToolBarUI"); putDefault (table, "ToolBarUI");
putDefault (table, "RootPaneUI"); putDefault (table, "RootPaneUI");
putDefault (table, "ViewportUI"); putDefault (table, "ViewportUI");
putDefault (table, "SplitPaneUI"); putDefault (table, "SplitPaneUI");
putDefault (table, "ScrollPaneUI"); putDefault (table, "ScrollPaneUI");
putDefault (table, "LabelUI"); putDefault (table, "LabelUI");
putDefault (table, "ToolTipUI"); putDefault (table, "ToolTipUI");
putDefault (table, "TextAreaUI"); putDefault (table, "TextAreaUI");
} // initClassDefaults } // initClassDefaults
/** /**
* Put "uiKey - ClassName" pair in UIDefaults * Put "uiKey - ClassName" pair in UIDefaults
* @param table * @param table
* @param uiKey * @param uiKey
*/ */
private void putDefault (UIDefaults table, String uiKey) private void putDefault (UIDefaults table, String uiKey)
{ {
try try
{ {
String className = "org.compiere.plaf.Compiere" + uiKey; String className = "org.compiere.plaf.Compiere" + uiKey;
table.put(uiKey, className); table.put(uiKey, className);
} }
catch (Exception ex) catch (Exception ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
} // putDefault } // putDefault
/** /**
* For overwriting Component defaults * For overwriting Component defaults
* @param table * @param table
*/ */
protected void initSystemColorDefaults (UIDefaults table) protected void initSystemColorDefaults (UIDefaults table)
{ {
// System.out.println("CompiereLookAndFeel.initSystemColorDefaults");
super.initSystemColorDefaults( table); super.initSystemColorDefaults( table);
// we made the color a bit darker
// table.put("textHighlight", CompiereUtils.getTranslucentColor(getTextHighlightColor(), 128));
} // initSystemColorDefaults } // initSystemColorDefaults
/** /**
* For overwriting Component defaults * For overwriting Component defaults
* @param table * @param table
*/ */
protected void initComponentDefaults (UIDefaults table) protected void initComponentDefaults (UIDefaults table)
{ {
// System.out.println("CompiereLookAndFeel.initComponentDefaults");
super.initComponentDefaults( table); super.initComponentDefaults( table);
// ComboBox defaults // ComboBox defaults
Color c = table.getColor("TextField.background"); Color c = table.getColor("TextField.background");
table.put("ComboBox.background", c); table.put("ComboBox.background", c);
table.put("ComboBox.listBackground", c); table.put("ComboBox.listBackground", c);
} // initComponentDefaults } // initComponentDefaults
/************************************************************************** /**************************************************************************
* Create Default Thems * Create Default Thems
*/ */
protected void createDefaultTheme() protected void createDefaultTheme()
{ {
setCurrentTheme(s_theme); setCurrentTheme(s_theme);
} // createDefaultTheme } // createDefaultTheme
/** /**
* Set Current Theme * Set Current Theme
* @param theme metal theme * @param theme metal theme
*/ */
public static void setCurrentTheme (MetalTheme theme) public static void setCurrentTheme (MetalTheme theme)
{ {
if (theme != null) if (theme != null)
s_theme = theme; s_theme = theme;
MetalLookAndFeel.setCurrentTheme(s_theme); MetalLookAndFeel.setCurrentTheme(s_theme);
} // setCurrentTheme } // setCurrentTheme
/** /**
* Get Current Theme * Get Current Theme
* @return Metal Theme * @return Metal Theme
*/ */
public static MetalTheme getCurrentTheme() public static MetalTheme getCurrentTheme()
{ {
return s_theme; return s_theme;
} // getCurrentTheme } // getCurrentTheme
/** /**
* Get Compiere Theme * Get Compiere Theme
* @return Metal Theme * @return Metal Theme
*/ */
public static CompiereTheme getCompiereTheme() public static CompiereTheme getCompiereTheme()
{ {
return s_compiereTheme; return s_compiereTheme;
} // getCurrentTheme } // getCurrentTheme
/** /**
* Error Feedback. * Error Feedback.
* <p> * <p>
* Invoked when the user attempts an invalid operation, * Invoked when the user attempts an invalid operation,
* such as pasting into an uneditable <code>JTextField</code> * such as pasting into an uneditable <code>JTextField</code>
* that has focus. * that has focus.
* </p> * </p>
* <p> * <p>
* If the user has enabled visual error indication on * If the user has enabled visual error indication on
* the desktop, this method will flash the caption bar * the desktop, this method will flash the caption bar
* of the active window. The user can also set the * of the active window. The user can also set the
* property awt.visualbell=true to achieve the same * property awt.visualbell=true to achieve the same
* results. * results.
* </p> * </p>
* @param component Component the error occured in, may be * @param component Component the error occured in, may be
* null indicating the error condition is * null indicating the error condition is
* not directly associated with a * not directly associated with a
* <code>Component</code>. * <code>Component</code>.
*/ */
public void provideErrorFeedback (Component component) public void provideErrorFeedback (Component component)
{ {
super.provideErrorFeedback (component); super.provideErrorFeedback (component);
} // provideErrorFeedback } // provideErrorFeedback

View File

@ -109,7 +109,7 @@ public class CompierePanelUI extends BasicPanelUI
CompiereColor bg = null; CompiereColor bg = null;
try try
{ {
bg = (CompiereColor)c.getClientProperty(CompiereLookAndFeel.BACKGROUND); bg = (CompiereColor)c.getClientProperty(AdempierePLAF.BACKGROUND);
} }
catch (Exception e) catch (Exception e)
{ {
@ -132,5 +132,48 @@ public class CompierePanelUI extends BasicPanelUI
/*************************************************************************/ /*************************************************************************/
/** Default Background */
private static CompiereColor s_default = new CompiereColor();
/** Set Background to default setting */
private static boolean s_setDefault = false;
} // AdempierePanel
/**
* Set Default Background
* @param bg Background Color
*/
public static void setDefaultBackground (CompiereColor bg)
{
if (bg == null)
return;
s_default.setColor(bg);
} // setBackground
/**
* Get Default Background
* @return Background
*/
public static CompiereColor getDefaultBackground()
{
return s_default;
} // getBackground
/**
* Set Default Background
* @param setDefault if true, the background will be set to the default color
*/
public static void setSetDefault (boolean setDefault)
{
s_setDefault = setDefault;
} // setSetDefault
/**
* Is the Default Background set by default
* @return true if default background is set
*/
public static boolean isSetDefault()
{
return s_setDefault;
} // isSetDefault
} // CompierePanel

View File

@ -180,7 +180,7 @@ public class CompiereTabbedPaneUI extends MetalTabbedPaneUI
JPanel jp = (JPanel)comp; JPanel jp = (JPanel)comp;
try try
{ {
bg = (CompiereColor)jp.getClientProperty(CompiereLookAndFeel.BACKGROUND); bg = (CompiereColor)jp.getClientProperty(AdempierePLAF.BACKGROUND);
} }
catch (Exception e) catch (Exception e)
{ {
@ -373,7 +373,7 @@ public class CompiereTabbedPaneUI extends MetalTabbedPaneUI
try try
{ {
if (jc != null) if (jc != null)
bg = (CompiereColor)jc.getClientProperty(CompiereLookAndFeel.BACKGROUND); bg = (CompiereColor)jc.getClientProperty(AdempierePLAF.BACKGROUND);
} }
catch (Exception e) catch (Exception e)
{ {
@ -382,7 +382,7 @@ public class CompiereTabbedPaneUI extends MetalTabbedPaneUI
if (bg == null) if (bg == null)
{ {
bg = new CompiereColor(jc.getBackground()); bg = new CompiereColor(jc.getBackground());
jc.putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); jc.putClientProperty(AdempierePLAF.BACKGROUND, bg);
} }
bg.paintRect(g, jc, x,y, w,h); bg.paintRect(g, jc, x,y, w,h);
} }
@ -1023,7 +1023,7 @@ public class CompiereTabbedPaneUI extends MetalTabbedPaneUI
JComponent jc = (JComponent)comp; JComponent jc = (JComponent)comp;
try try
{ {
Integer ll = (Integer)jc.getClientProperty(CompiereLookAndFeel.TABLEVEL); Integer ll = (Integer)jc.getClientProperty(AdempierePLAF.TABLEVEL);
if (ll != null) if (ll != null)
level = ll.intValue(); level = ll.intValue();
} }

View File

@ -1,95 +1,96 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.plaf; package org.compiere.plaf;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableHeaderUI; import javax.swing.plaf.basic.BasicTableHeaderUI;
import org.adempiere.plaf.*;
/**
* Table Header UI /**
* 3D effect * Table Header UI
* * 3D effect
* @author Jorg Janke *
* @version $Id: AdempiereTableHeaderUI.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @author Jorg Janke
*/ * @version $Id: AdempiereTableHeaderUI.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
public class CompiereTableHeaderUI extends BasicTableHeaderUI */
{ public class CompiereTableHeaderUI extends BasicTableHeaderUI
/** {
* Static Create UI /**
* @param c Component * Static Create UI
* @return Adempiere TableHeader UI * @param c Component
*/ * @return Adempiere TableHeader UI
public static ComponentUI createUI(JComponent c) */
{ public static ComponentUI createUI(JComponent c)
return new CompiereTableHeaderUI(); {
} // createUI return new CompiereTableHeaderUI();
} // createUI
/**
* Install UI - set not Opaque /**
* @param c * Install UI - set not Opaque
*/ * @param c
public void installUI(JComponent c) */
{ public void installUI(JComponent c)
super.installUI(c); {
// TableHeader is in JViewpoiunt, which is Opaque super.installUI(c);
// When UI created, TableHeader not added to viewpoint // TableHeader is in JViewpoiunt, which is Opaque
//c.setOpaque(true); // When UI created, TableHeader not added to viewpoint
//c.putClientProperty(AdempierePLAF.BACKGROUND_FILL, "Y"); c.setOpaque(true);
} // installUI c.putClientProperty(AdempierePLAF.BACKGROUND_FILL, "Y");
} // installUI
/**************************************************************************
* Update - /**************************************************************************
* This method is invoked by <code>JComponent</code> when the specified * Update -
* component is being painted. * This method is invoked by <code>JComponent</code> when the specified
* * component is being painted.
* By default this method will fill the specified component with *
* its background color (if its <code>opaque</code> property is * By default this method will fill the specified component with
* <code>true</code>) and then immediately call <code>paint</code>. * its background color (if its <code>opaque</code> property is
* * <code>true</code>) and then immediately call <code>paint</code>.
* @param g the <code>Graphics</code> context in which to paint *
* @param c the component being painted * @param g the <code>Graphics</code> context in which to paint
* * @param c the component being painted
* @see #paint *
* @see javax.swing.JComponent#paintComponent * @see #paint
*/ * @see javax.swing.JComponent#paintComponent
public void update(Graphics g, JComponent c) */
{ public void update(Graphics g, JComponent c)
// AdempiereUtils.printParents (c); // Parent is JViewpoint {
if (c.isOpaque()) // flat // AdempiereUtils.printParents (c); // Parent is JViewpoint
CompiereUtils.fillRectange((Graphics2D)g, c, CompiereLookAndFeel.ROUND); if (c.isOpaque()) // flat
// CompiereUtils.fillRectange((Graphics2D)g, c, CompiereLookAndFeel.ROUND);
paint (g, c); //
} // update paint (g, c);
} // update
/**
* Paint 3D box /**
* @param g * Paint 3D box
* @param c * @param g
*/ * @param c
public void paint(Graphics g, JComponent c) */
{ public void paint(Graphics g, JComponent c)
super.paint( g, c); {
CompiereUtils.paint3Deffect((Graphics2D)g, c, CompiereLookAndFeel.ROUND, true); super.paint( g, c);
} // paint CompiereUtils.paint3Deffect((Graphics2D)g, c, CompiereLookAndFeel.ROUND, true);
} // paint
} // AdempiereTableHeader
} // AdempiereTableHeader

View File

@ -3,18 +3,18 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.plaf; package org.compiere.plaf;
import java.awt.*; import java.awt.*;
import java.util.logging.*; import java.util.logging.*;
@ -30,7 +30,7 @@ import org.compiere.util.*;
import sun.awt.*; import sun.awt.*;
/** /**
* Compiere User definable Theme (if used in Metal L&F). * Compiere User definable Theme (if used in Metal L&F).
* In other Environments, it provides UI extensions (e.g. Error Color) * In other Environments, it provides UI extensions (e.g. Error Color)
* *
* @author Jorg Janke * @author Jorg Janke
@ -38,8 +38,8 @@ import sun.awt.*;
*/ */
public class CompiereTheme extends MetalTheme public class CompiereTheme extends MetalTheme
{ {
/** /**
* Constructor - nop * Constructor - nop
*/ */
public CompiereTheme() public CompiereTheme()
{ {
@ -47,299 +47,561 @@ public class CompiereTheme extends MetalTheme
/** /**
* Return Theme Name * Return Theme Name
* @return Theme Name * @return Theme Name
*/ */
public String getName() public String getName()
{ {
return s_name; return s_name;
} // getName } // getName
/** /**
* String Representation * String Representation
* @return info * @return info
*/ */
public String toString () public String toString ()
{ {
return s_name; return s_name;
} // toString } // toString
/** /**
* Set Default Colors * Set Default Colors
*/ */
protected void setDefault() protected void setDefault()
{ {
} // setDefault } // setDefault
/** Static Initializer */ /** Static Initializer */
static static
{ {
s_theme = new CompiereThemeBlueMetal(); s_theme = new CompiereThemeBlueMetal();
} }
/** Theme Name */ /** Theme Name */
protected static String s_name = "Compiere Theme"; protected static String s_name = "Compiere Theme";
/** Logger */ /** Logger */
protected static Logger log = Logger.getLogger(CompiereTheme.class.getName()); protected static Logger log = Logger.getLogger(CompiereTheme.class.getName());
/** Active Theme */ /** Active Theme */
protected static CompiereTheme s_theme = null; protected static CompiereTheme s_theme = null;
/** Blue 51,51,102 */ /** Blue 51,51,102 */
protected static ColorUIResource primary0 = new ColorUIResource(51, 51, 102); protected static ColorUIResource primary0 = new ColorUIResource(51, 51, 102);
/** Blue 102, 102, 153 */ /** Blue 102, 102, 153 */
protected static ColorUIResource primary1; protected static ColorUIResource primary1;
/** Blue 153, 153, 204 */ /** Blue 153, 153, 204 */
protected static ColorUIResource primary2; protected static ColorUIResource primary2;
/** Blue 204, 204, 255 */ /** Blue 204, 204, 255 */
protected static ColorUIResource primary3; protected static ColorUIResource primary3;
/** Black */ /** Black */
protected final ColorUIResource secondary0 = new ColorUIResource(0, 0, 0); protected final ColorUIResource secondary0 = new ColorUIResource(0, 0, 0);
/** Gray 102, 102, 102 */ /** Gray 102, 102, 102 */
protected static ColorUIResource secondary1; protected static ColorUIResource secondary1;
/** Gray 153, 153, 153 */ /** Gray 153, 153, 153 */
protected static ColorUIResource secondary2; protected static ColorUIResource secondary2;
/** BlueGray 214, 224, 234 - background */ /** BlueGray 214, 224, 234 - background */
protected static ColorUIResource secondary3; protected static ColorUIResource secondary3;
/** White */ /** White */
protected final ColorUIResource secondary4 = new ColorUIResource(255, 255, 255); protected final ColorUIResource secondary4 = new ColorUIResource(255, 255, 255);
/** Black */ /** Black */
protected static ColorUIResource black; protected static ColorUIResource black;
/** White */ /** White */
protected static ColorUIResource white; protected static ColorUIResource white;
/** Background for mandatory fields */ /** Background for mandatory fields */
protected static ColorUIResource mandatory; protected static ColorUIResource mandatory;
/** Background for fields in error */ /** Background for fields in error */
protected static ColorUIResource error; protected static ColorUIResource error;
/** Background for inactive fields */ /** Background for inactive fields */
protected static ColorUIResource inactive; protected static ColorUIResource inactive;
/** Background for info fields */ /** Background for info fields */
protected static ColorUIResource info; protected static ColorUIResource info;
/** Foreground Text OK */ /** Foreground Text OK */
protected static ColorUIResource txt_ok; protected static ColorUIResource txt_ok;
/** Foreground Text Error */ /** Foreground Text Error */
protected static ColorUIResource txt_error; protected static ColorUIResource txt_error;
/** Control font */ /** Control font */
protected static FontUIResource controlFont; protected static FontUIResource controlFont;
/** System font */ /** System font */
protected static FontUIResource systemFont; protected static FontUIResource systemFont;
/** User font */ /** User font */
protected static FontUIResource userFont; protected static FontUIResource userFont;
/** Small font */ /** Small font */
protected static FontUIResource smallFont; protected static FontUIResource smallFont;
/** Window Title font */ /** Window Title font */
protected static FontUIResource windowFont; protected static FontUIResource windowFont;
/** Menu font */ /** Menu font */
protected static FontUIResource menuFont; protected static FontUIResource menuFont;
/** Default Font */ /** Default Font */
public static final String FONT_DEFAULT = "Dialog"; public static final String FONT_DEFAULT = "Dialog";
/** Default Font Size */ /** Default Font Size */
public static final int FONT_SIZE = 12; public static final int FONT_SIZE = 12;
/**
* Set Theme to current Metal Theme and copy it
*/
public static void setTheme ()
{
log.fine("");
AppContext context = AppContext.getAppContext();
MetalTheme copyFrom = (MetalTheme)context.get("currentMetalTheme");
boolean flat = Ini.isPropertyBool(Ini.P_UI_FLAT);
setTheme (copyFrom, flat);
} // setTheme
/**
* Set Theme to current Metal Theme and copy it
* @param copyFrom theme
* @param flat flat colors
*/
public static void setTheme (MetalTheme copyFrom, boolean flat)
{
if (copyFrom == null || copyFrom instanceof CompiereTheme)
return;
log.fine(copyFrom.getName() + " - Flat=" + flat);
// May not be correct, if Themes overwrites default methods
primary1 = copyFrom.getPrimaryControlDarkShadow();
primary2 = copyFrom.getPrimaryControlShadow();
primary3 = copyFrom.getPrimaryControl();
secondary1 = copyFrom.getControlDarkShadow();
secondary2 = copyFrom.getControlShadow();
secondary3 = copyFrom.getControl();
CompierePanelUI.setDefaultBackground(new CompiereColor(secondary3, flat));
white = copyFrom.getPrimaryControlHighlight();
black = copyFrom.getPrimaryControlInfo();
//
controlFont = copyFrom.getControlTextFont();
systemFont = copyFrom.getSystemTextFont();
userFont = copyFrom.getUserTextFont();
smallFont = copyFrom.getSubTextFont();
menuFont = copyFrom.getMenuTextFont();
windowFont = copyFrom.getWindowTitleFont();
} // setTheme
/************************************************************************** /**************************************************************************
* Get Primary 1 (blue in default Metal Theme) * Get Primary 1 (blue in default Metal Theme)
* @return color * @return color
*/ */
public ColorUIResource getPrimary1() public ColorUIResource getPrimary1()
{ {
return ColorBlind.getDichromatColorUIResource(primary1); return ColorBlind.getDichromatColorUIResource(primary1);
} }
public ColorUIResource getPrimary2() public ColorUIResource getPrimary2()
{ {
return ColorBlind.getDichromatColorUIResource(primary2); return ColorBlind.getDichromatColorUIResource(primary2);
} }
public ColorUIResource getPrimary3() public ColorUIResource getPrimary3()
{ {
return ColorBlind.getDichromatColorUIResource(primary3); return ColorBlind.getDichromatColorUIResource(primary3);
} }
/** /**
* Get Seconary 1 (gray in default Metal Theme) * Get Seconary 1 (gray in default Metal Theme)
* @return color * @return color
*/ */
public ColorUIResource getSecondary0() public ColorUIResource getSecondary0()
{ {
return ColorBlind.getDichromatColorUIResource(secondary0); return ColorBlind.getDichromatColorUIResource(secondary0);
} }
public ColorUIResource getSecondary1() public ColorUIResource getSecondary1()
{ {
return ColorBlind.getDichromatColorUIResource(secondary1); return ColorBlind.getDichromatColorUIResource(secondary1);
} }
public ColorUIResource getSecondary2() public ColorUIResource getSecondary2()
{ {
return ColorBlind.getDichromatColorUIResource(secondary2); return ColorBlind.getDichromatColorUIResource(secondary2);
} }
public ColorUIResource getSecondary3() public ColorUIResource getSecondary3()
{ {
return ColorBlind.getDichromatColorUIResource(secondary3); return ColorBlind.getDichromatColorUIResource(secondary3);
} }
public ColorUIResource getSecondary4() public ColorUIResource getSecondary4()
{ {
return ColorBlind.getDichromatColorUIResource(secondary4); return ColorBlind.getDichromatColorUIResource(secondary4);
} }
public ColorUIResource getBlack() public ColorUIResource getBlack()
{ {
return ColorBlind.getDichromatColorUIResource(black); return ColorBlind.getDichromatColorUIResource(black);
} }
public ColorUIResource getWhite() public ColorUIResource getWhite()
{ {
return ColorBlind.getDichromatColorUIResource(white); return ColorBlind.getDichromatColorUIResource(white);
} }
/** /**
* Control Font (plain) * Control Font (plain)
* @return font * @return font
*/ */
protected static FontUIResource _getControlTextFont() protected static FontUIResource _getControlTextFont()
{ {
if (controlFont == null) if (controlFont == null)
{ {
try try
{ {
controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont", controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE))); new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
} }
catch (Exception e) catch (Exception e)
{ {
controlFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE); controlFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
} }
} }
return controlFont; return controlFont;
} }
public FontUIResource getControlTextFont() {return _getControlTextFont();} public FontUIResource getControlTextFont() {return _getControlTextFont();}
/** /**
* System Font * System Font
* @return font * @return font
*/ */
protected static FontUIResource _getSystemTextFont() protected static FontUIResource _getSystemTextFont()
{ {
if (systemFont == null) if (systemFont == null)
{ {
try try
{ {
systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont", systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE))); new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
} }
catch (Exception e) catch (Exception e)
{ {
systemFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE); systemFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
} }
} }
return systemFont; return systemFont;
} }
public FontUIResource getSystemTextFont() {return _getSystemTextFont();} public FontUIResource getSystemTextFont() {return _getSystemTextFont();}
/** /**
* User Font * User Font
* @return font * @return font
*/ */
protected static FontUIResource _getUserTextFont() protected static FontUIResource _getUserTextFont()
{ {
if (userFont == null) if (userFont == null)
{ {
try try
{ {
userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont", userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE))); new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
} }
catch (Exception e) catch (Exception e)
{ {
userFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE); userFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
} }
} }
return userFont; return userFont;
} }
public FontUIResource getUserTextFont() {return _getUserTextFont();} public FontUIResource getUserTextFont() {return _getUserTextFont();}
/** /**
* Menu * Menu
* @return font * @return font
*/ */
protected static FontUIResource _getMenuTextFont() protected static FontUIResource _getMenuTextFont()
{ {
if (menuFont == null) if (menuFont == null)
{ {
try try
{ {
menuFont = new FontUIResource(Font.getFont("swing.plaf.metal.menuFont", menuFont = new FontUIResource(Font.getFont("swing.plaf.metal.menuFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE))); new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
} }
catch (Exception e) catch (Exception e)
{ {
menuFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE); menuFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
} }
} }
return menuFont; return menuFont;
} }
public FontUIResource getMenuTextFont() {return _getMenuTextFont();} public FontUIResource getMenuTextFont() {return _getMenuTextFont();}
/** /**
* Window Title * Window Title
* @return font * @return font
*/ */
protected static FontUIResource _getWindowTitleFont() protected static FontUIResource _getWindowTitleFont()
{ {
if (windowFont == null) if (windowFont == null)
{ {
try try
{ {
windowFont = new FontUIResource(Font.getFont("swing.plaf.metal.windowFont", windowFont = new FontUIResource(Font.getFont("swing.plaf.metal.windowFont",
new Font(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2))); new Font(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2)));
} }
catch (Exception e) catch (Exception e)
{ {
windowFont = new FontUIResource(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2); windowFont = new FontUIResource(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2);
} }
} }
return windowFont; return windowFont;
} }
public FontUIResource getWindowTitleFont() {return _getWindowTitleFont();} public FontUIResource getWindowTitleFont() {return _getWindowTitleFont();}
/** /**
* Sub Text * Sub Text
* @return font * @return font
*/ */
protected static FontUIResource _getSubTextFont() protected static FontUIResource _getSubTextFont()
{ {
if (smallFont == null) if (smallFont == null)
{ {
try try
{ {
smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont", smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2))); new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2)));
} }
catch (Exception e) catch (Exception e)
{ {
smallFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2); smallFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2);
} }
} }
return smallFont; return smallFont;
} }
public FontUIResource getSubTextFont() {return _getSubTextFont();} public FontUIResource getSubTextFont() {return _getSubTextFont();}
@Override // Static property info
public void addCustomEntriesToTable(UIDefaults table) {
super.addCustomEntriesToTable(table); private static final String P_Primary1 = "#ColorPrimary1";
Object[] defaults = private static final String P_Primary2 = "#ColorPrimary2";
private static final String P_Primary3 = "#ColorPrimary3";
private static final String P_Secondary1 = "#ColorSecondary1";
private static final String P_Secondary2 = "#ColorSecondary2";
private static final String P_Secondary3 = "#ColorSecondary3";
private static final String P_Black = "#ColorBlack";
private static final String P_White = "#ColorWhite";
private static final String P_Error = "#ColorError";
private static final String P_Info = "#ColorInfo";
private static final String P_Mandatory = "#ColorMandatory";
private static final String P_Inactive = "#ColorInactive";
private static final String P_Txt_OK = "#ColorTextOK";
private static final String P_Txt_Error = "#ColorTextError";
//
private static final String P_Control = "#FontControl";
private static final String P_System = "#FontSystem";
private static final String P_User = "#FontUser";
private static final String P_Small = "#FontSmall";
private static final String P_Window = "#FontWindow";
private static final String P_Menu = "#FontMenu";
/** Background Color */
protected static final String P_CompiereColor = "#CompiereColor";
/**
* Save information in Properties
*/
public static void save ()
{
log.config(CompiereColor.getDefaultBackground().toString());
//
Ini.setProperty(P_Primary1, getColorAsString(primary1));
Ini.setProperty(P_Primary2, getColorAsString(primary2));
Ini.setProperty(P_Primary3, getColorAsString(primary3));
Ini.setProperty(P_Secondary1, getColorAsString(secondary1));
Ini.setProperty(P_Secondary2, getColorAsString(secondary2));
Ini.setProperty(P_Secondary3, getColorAsString(secondary3));
Ini.setProperty(P_Error, getColorAsString(error));
Ini.setProperty(P_Info, getColorAsString(info));
Ini.setProperty(P_Mandatory, getColorAsString(mandatory));
Ini.setProperty(P_Inactive, getColorAsString(inactive));
Ini.setProperty(P_White, getColorAsString(white));
Ini.setProperty(P_Black, getColorAsString(black));
Ini.setProperty(P_Txt_OK, getColorAsString(txt_ok));
Ini.setProperty(P_Txt_Error, getColorAsString(txt_error));
//
Ini.setProperty(P_Control, ((Font)controlFont).toString());
Ini.setProperty(P_System, ((Font)systemFont).toString());
Ini.setProperty(P_User, ((Font)userFont).toString());
Ini.setProperty(P_Small, ((Font)smallFont).toString());
Ini.setProperty(P_Window, ((Font)windowFont).toString());
Ini.setProperty(P_Menu, ((Font)menuFont).toString());
//
CompiereColor cc = CompiereColor.getDefaultBackground();
Ini.setProperty(P_CompiereColor, cc.toString());
} // save
/**
* Parses Color into String representation.
* Required as SystemColors and Alpha Colors have different formats
* @param c Color
* @return [r=102,g=102,b=153,a=255]
* @see #parseColor
*/
public static String getColorAsString (Color c)
{
if (c == null)
c = SystemColor.control;
StringBuffer sb = new StringBuffer("[r=").append(c.getRed())
.append(",g=").append(c.getGreen())
.append(",b=").append(c.getBlue())
.append(",a=").append(c.getAlpha())
.append("]");
// System.out.println(sb.toString());
return sb.toString();
} // getColorAsString
/**
* Load Properties from Ini
*/
public static void load ()
{
primary1 = parseColor (Ini.getProperty(P_Primary1), primary1);
primary2 = parseColor (Ini.getProperty(P_Primary2), primary2);
primary3 = parseColor (Ini.getProperty(P_Primary3), primary3);
secondary1 = parseColor (Ini.getProperty(P_Secondary1), secondary1);
secondary2 = parseColor (Ini.getProperty(P_Secondary2), secondary2);
secondary3 = parseColor (Ini.getProperty(P_Secondary3), secondary3);
error = parseColor(Ini.getProperty(P_Error), error);
info = parseColor(Ini.getProperty(P_Info), info);
mandatory = parseColor(Ini.getProperty(P_Mandatory), mandatory);
inactive = parseColor(Ini.getProperty(P_Inactive), inactive);
white = parseColor(Ini.getProperty(P_White), white);
black = parseColor(Ini.getProperty(P_Black), black);
txt_ok = parseColor(Ini.getProperty(P_Txt_OK), txt_ok);
txt_error = parseColor(Ini.getProperty(P_Txt_Error), txt_error);
//
controlFont = parseFont(Ini.getProperty(P_Control), controlFont);
systemFont = parseFont(Ini.getProperty(P_System), systemFont);
userFont = parseFont(Ini.getProperty(P_User), userFont);
smallFont = parseFont(Ini.getProperty(P_Small), smallFont);
windowFont = parseFont(Ini.getProperty(P_Window), windowFont);
menuFont = parseFont(Ini.getProperty(P_Menu), menuFont);
//
CompiereColor cc = CompiereColor.parse(Ini.getProperty(P_CompiereColor));
CompiereColor.setDefaultBackground(cc);
} // load
/**
* Reset Info in Properties
*/
public static void reset ()
{
/**
Ini.remove (P_Primary1);
Ini.remove (P_Primary2);
Ini.remove (P_Primary3);
Ini.remove (P_Secondary1);
Ini.remove (P_Secondary2);
Ini.remove (P_Secondary3);
Ini.remove (P_Error);
Ini.remove (P_Info);
Ini.remove (P_Mandatory);
Ini.remove (P_Inactive);
Ini.remove (P_White);
Ini.remove (P_Black);
Ini.remove (P_Txt_OK);
Ini.remove (P_Txt_Error);
//
Ini.remove (P_Control);
Ini.remove (P_System);
Ini.remove (P_User);
Ini.remove (P_Small);
Ini.remove (P_Window);
Ini.remove (P_Menu);
// CompiereColor
Ini.remove(P_CompiereColor);
**/
// Initialize
Ini.setProperty(Ini.P_UI_LOOK, CompiereLookAndFeel.NAME);
Ini.setProperty(Ini.P_UI_THEME, s_name);
//
if (s_theme != null)
s_theme.setDefault();
// Background
// CompiereColor cc = new CompiereColor(SystemColor.control); // flat Windows 212-208-200
// CompiereColor cc = new CompiereColor(secondary3); // flat Metal 204-204-204
CompiereColor cc = new CompiereColor(secondary3, false);
CompiereColor.setDefaultBackground (cc);
//
save(); // save properties
} // reset
/**
* Parse Color.
* <p>
* Color - [r=102,g=102,b=153,a=0]
*
* @param information string information to be parsed
* @param stdColor color used if info cannot parsed
* @return color
* @see #getColorAsString
*/
protected static ColorUIResource parseColor (String information, ColorUIResource stdColor)
{
if (information == null
|| information.length() == 0
|| information.trim().length() == 0)
return stdColor;
// System.out.print("ParseColor=" + info);
try
{ {
ExtendedTheme.ERROR_BG_KEY, int r = Integer.parseInt(information.substring(information.indexOf("r=")+2, information.indexOf(",g=")));
error, int g = Integer.parseInt(information.substring(information.indexOf("g=")+2, information.indexOf(",b=")));
ExtendedTheme.ERROR_FG_KEY, int b = 0;
txt_error, int a = 255;
ExtendedTheme.INACTIVE_BG_KEY, if (information.indexOf("a=") == -1)
inactive, b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf("]")));
ExtendedTheme.INFO_BG_KEY, else
info, {
ExtendedTheme.MANDATORY_BG_KEY, b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf(",a=")));
mandatory a = Integer.parseInt(information.substring(information.indexOf("a=")+2, information.indexOf("]")));
}; }
table.putDefaults(defaults); ColorUIResource retValue = new ColorUIResource(new Color(r, g, b, a));
} // System.out.println(" - " + retValue.toString());
} // AdempiereTheme return retValue;
}
catch (Exception e)
{
log.config(information + " - cannot parse: " + e.toString());
}
return stdColor;
} // parseColor
/**
* Parse Font
* <p>
* javax.swing.plaf.FontUIResource[family=dialog.bold,name=Dialog,style=bold,size=12]
*
* @param information string information to be parsed
* @param stdFont font used if info cannot be parsed
* @return font
*/
private static FontUIResource parseFont(String information, FontUIResource stdFont)
{
if (information == null
|| information.length() == 0
|| information.trim().length() == 0)
return stdFont;
// System.out.print("ParseFont=" + info);
try
{
String name = information.substring(information.indexOf("name=")+5, information.indexOf(",style="));
String s = information.substring(information.indexOf("style=")+6, information.indexOf(",size="));
int style = Font.PLAIN;
if (s.equals("bold"))
style = Font.BOLD;
else if (s.equals("italic"))
style = Font.ITALIC;
else if (s.equals("bolditalic"))
style = Font.BOLD | Font.ITALIC;
int size = Integer.parseInt(information.substring(information.indexOf(",size=")+6, information.lastIndexOf("]")));
FontUIResource retValue = new FontUIResource(name,style,size);
// System.out.println(" - " + retValue.toString());
return retValue;
}
catch (Exception e)
{
log.config(information + " - cannot parse: " + e.toString());
}
return stdFont;
} // parseFont
} // CompiereTheme

View File

@ -52,10 +52,10 @@ public class CompiereUtils
{ {
// Paint in AdempiereColor? // Paint in AdempiereColor?
CompiereColor cc = null; CompiereColor cc = null;
boolean stdCC = c.getClientProperty(CompiereLookAndFeel.BACKGROUND_FILL) != null; boolean stdCC = c.getClientProperty(AdempierePLAF.BACKGROUND_FILL) != null;
try try
{ {
cc = (CompiereColor)c.getClientProperty(CompiereLookAndFeel.BACKGROUND); cc = (CompiereColor)c.getClientProperty(AdempierePLAF.BACKGROUND);
} }
catch (Exception e) catch (Exception e)
{ {
@ -458,7 +458,7 @@ public class CompiereUtils
c.setName("C" + String.valueOf(s_no++)); c.setName("C" + String.valueOf(s_no++));
System.out.print(c.getName()); System.out.print(c.getName());
System.out.print(" - " + c.getClass().getName()); System.out.print(" - " + c.getClass().getName());
System.out.println (" ** " + c.isOpaque() + " bg=" + (c.getClientProperty(CompiereLookAndFeel.BACKGROUND) != null)); System.out.println (" ** " + c.isOpaque() + " bg=" + (c.getClientProperty(AdempierePLAF.BACKGROUND) != null));
// //
Container container = c.getParent(); Container container = c.getParent();
while (container != null) while (container != null)
@ -466,7 +466,7 @@ public class CompiereUtils
System.out.print (" - " + container.getName() + " " + container.getClass().getName() System.out.print (" - " + container.getName() + " " + container.getClass().getName()
+ " ** " + container.isOpaque()); + " ** " + container.isOpaque());
if (container instanceof JComponent) if (container instanceof JComponent)
System.out.print (" bg=" + (((JComponent)container).getClientProperty(CompiereLookAndFeel.BACKGROUND) != null)); System.out.print (" bg=" + (((JComponent)container).getClientProperty(AdempierePLAF.BACKGROUND) != null));
System.out.println (); System.out.println ();
container = container.getParent(); container = container.getParent();
} }

View File

@ -1,284 +1,297 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
* Adempiere Button supporting colored Background * Adempiere Button supporting colored Background
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CButton extends JButton implements CEditor public class CButton extends JButton implements CEditor
{ {
/** /**
* Creates a button with no set text or icon. * Creates a button with no set text or icon.
*/ */
public CButton() public CButton()
{ {
this (null, null); this (null, null);
} // CButton } // CButton
/** /**
* Creates a button with an icon. * Creates a button with an icon.
* *
* @param icon the Icon image to display on the button * @param icon the Icon image to display on the button
*/ */
public CButton(Icon icon) public CButton(Icon icon)
{ {
this (null, icon); this (null, icon);
} // CButton } // CButton
/** /**
* Creates a button with text. * Creates a button with text.
* *
* @param text the text of the button * @param text the text of the button
*/ */
public CButton(String text) public CButton(String text)
{ {
this (text, null); this (text, null);
} // CButton } // CButton
/** /**
* Creates a button where properties are taken from the * Creates a button where properties are taken from the
* <code>Action</code> supplied. * <code>Action</code> supplied.
* *
* @param a the <code>Action</code> used to specify the new button * @param a the <code>Action</code> used to specify the new button
* *
* @since 1.3 * @since 1.3
*/ */
public CButton (Action a) public CButton (Action a)
{ {
super (a); super (a);
} // CButton setContentAreaFilled(false);
setOpaque(false);
/** } // CButton
* Creates a button with initial text and an icon.
* /**
* @param text the text of the button * Creates a button with initial text and an icon.
* @param icon the Icon image to display on the button *
*/ * @param text the text of the button
public CButton(String text, Icon icon) * @param icon the Icon image to display on the button
{ */
super (text, icon); public CButton(String text, Icon icon)
} // CButton {
super (text, icon);
setContentAreaFilled(false);
/************************************************************************** setOpaque(false);
* Set Background - Differentiates between system & user call. //
* If User Call, sets Opaque & ContextAreaFilled to true setFont(AdempierePLAF.getFont_Label());
* @param bg background color setForeground(AdempierePLAF.getTextColor_Label());
*/ } // CButton
public void setBackground (Color bg)
{
if (bg.equals(getBackground())) /**************************************************************************
return; * Set Background - Differentiates between system & user call.
super.setBackground (bg); * If User Call, sets Opaque & ContextAreaFilled to true
setBackgroundColor(new CompiereColor(bg)); * @param bg background color
this.repaint(); */
} // setBackground public void setBackground (Color bg)
{
/** if (bg.equals(getBackground()))
* Set Background - NOP return;
* @param error error super.setBackground (bg);
*/ // ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
public void setBackground (boolean error) if (!Trace.getCallerClass(1).startsWith("javax"))
{ {
} // setBackground setOpaque(true);
setContentAreaFilled(true);
/** }
* Set Standard Background this.repaint();
*/ } // setBackground
public void setBackgroundColor ()
{ /**
setBackgroundColor (null); * Set Background - NOP
} // setBackground * @param error error
*/
/** public void setBackground (boolean error)
* Set Background {
* @param bg AdempiereColor for Background, if null set standard background } // setBackground
*/
public void setBackgroundColor (CompiereColor bg) /**
{ * Set Standard Background
if (bg == null) */
bg = new CompiereColor(AdempierePLAF.getFormBackground()); public void setBackgroundColor ()
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); {
super.setBackground (bg.getFlatColor()); setBackgroundColor (null);
this.repaint(); } // setBackground
} // setBackground
/**
/** * Set Background
* Get Background * @param bg AdempiereColor for Background, if null set standard background
* @return Color for Background */
*/ public void setBackgroundColor (CompiereColor bg)
public CompiereColor getBackgroundColor () {
{ if (bg == null)
try bg = CompiereColor.getDefaultBackground();
{ setOpaque(true);
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND); putClientProperty(AdempierePLAF.BACKGROUND, bg);
} super.setBackground (bg.getFlatColor());
catch (Exception e) this.repaint();
{ } // setBackground
System.err.println("CButton - ClientProperty: " + e.getMessage());
} /**
return null; * Get Background
} // getBackgroundColor * @return Color for Background
*/
/** Mandatory (default false) */ public CompiereColor getBackgroundColor ()
private boolean m_mandatory = false; {
/** Read-Write */ try
private boolean m_readWrite = true; {
return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
/** }
* Set Editor Mandatory catch (Exception e)
* @param mandatory true, if you have to enter data {
*/ System.err.println("CButton - ClientProperty: " + e.getMessage());
public void setMandatory (boolean mandatory) }
{ return null;
m_mandatory = mandatory; } // getBackgroundColor
setBackground(false);
} // setMandatory /** Mandatory (default false) */
private boolean m_mandatory = false;
/** /** Read-Write */
* Is Field mandatory private boolean m_readWrite = true;
* @return true, if mandatory
*/ /**
public boolean isMandatory() * Set Editor Mandatory
{ * @param mandatory true, if you have to enter data
return m_mandatory; */
} // isMandatory public void setMandatory (boolean mandatory)
{
/** m_mandatory = mandatory;
* Enable Editor setBackground(false);
* @param rw true, if you can enter/select data } // setMandatory
*/
public void setReadWrite (boolean rw) /**
{ * Is Field mandatory
if (isEnabled() != rw) * @return true, if mandatory
setEnabled(rw); */
m_readWrite = rw; public boolean isMandatory()
} // setReadWrite {
return m_mandatory;
/** } // isMandatory
* Is it possible to edit
* @return true, if editable /**
*/ * Enable Editor
public boolean isReadWrite() * @param rw true, if you can enter/select data
{ */
return m_readWrite; public void setReadWrite (boolean rw)
} // isReadWrite {
if (isEnabled() != rw)
/** setEnabled(rw);
* Set Editor to value m_readWrite = rw;
* @param value value of the editor } // setReadWrite
*/
public void setValue (Object value) /**
{ * Is it possible to edit
if (value == null) * @return true, if editable
setText(""); */
else public boolean isReadWrite()
setText(value.toString()); {
} // setValue return m_readWrite;
} // isReadWrite
/**
* Return Editor value /**
* @return current value * Set Editor to value
*/ * @param value value of the editor
public Object getValue() */
{ public void setValue (Object value)
return getText(); {
} // getValue if (value == null)
setText("");
/** else
* Return Display Value setText(value.toString());
* @return displayed String value } // setValue
*/
public String getDisplay() /**
{ * Return Editor value
return getText(); * @return current value
} // getDisplay */
public Object getValue()
/** {
* Set Text & Mnemonic return getText();
* @param text text } // getValue
*/
public void setText (String text) /**
{ * Return Display Value
if (text == null) * @return displayed String value
{ */
super.setText(text); public String getDisplay()
return; {
} return getText();
int pos = text.indexOf("&"); } // getDisplay
if (pos != -1) // We have a nemonic - creates ALT-_
{ /**
int mnemonic = text.toUpperCase().charAt(pos+1); * Set Text & Mnemonic
if (mnemonic != ' ') * @param text text
{ */
setMnemonic(mnemonic); public void setText (String text)
text = text.substring(0, pos) + text.substring(pos+1); {
} if (text == null)
} {
super.setText (text); super.setText(text);
if (getName() == null) return;
setName (text); }
} // setText int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
/** {
* Set Tool Tip Text & Mnemonic int mnemonic = text.toUpperCase().charAt(pos+1);
* @param text text if (mnemonic != ' ')
*/ {
public void setToolTipText (String text) setMnemonic(mnemonic);
{ text = text.substring(0, pos) + text.substring(pos+1);
if (text == null) }
{ }
super.setText(text); super.setText (text);
return; if (getName() == null)
} setName (text);
int pos = text.indexOf("&"); } // setText
if (pos != -1) // We have a nemonic - creates ALT-_
{ /**
int mnemonic = text.toUpperCase().charAt(pos+1); * Set Tool Tip Text & Mnemonic
if (mnemonic != ' ') * @param text text
{ */
setMnemonic(mnemonic); public void setToolTipText (String text)
text = text.substring(0, pos) + text.substring(pos+1); {
} if (text == null)
} {
super.setToolTipText (text); super.setText(text);
if (getName() == null) return;
setName (text); }
} // setToolTipText int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
/** {
* Set Action Command int mnemonic = text.toUpperCase().charAt(pos+1);
* @param actionCommand command if (mnemonic != ' ')
*/ {
public void setActionCommand (String actionCommand) setMnemonic(mnemonic);
{ text = text.substring(0, pos) + text.substring(pos+1);
super.setActionCommand (actionCommand); }
if (getName() == null && actionCommand != null && actionCommand.length() > 0) }
setName(actionCommand); super.setToolTipText (text);
} // setActionCommand if (getName() == null)
setName (text);
} // CButton } // setToolTipText
/**
* Set Action Command
* @param actionCommand command
*/
public void setActionCommand (String actionCommand)
{
super.setActionCommand (actionCommand);
if (getName() == null && actionCommand != null && actionCommand.length() > 0)
setName(actionCommand);
} // setActionCommand
} // CButton

View File

@ -1,298 +1,298 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.Color; import java.awt.Color;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
/** /**
* Adempiere CheckBox * Adempiere CheckBox
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CCheckBox extends JCheckBox implements CEditor public class CCheckBox extends JCheckBox implements CEditor
{ {
/** /**
* Creates an initially unselected check box button with no text, no icon. * Creates an initially unselected check box button with no text, no icon.
*/ */
public CCheckBox () public CCheckBox ()
{ {
super (); super ();
init(); init();
} }
/** /**
* Creates an initially unselected check box with an icon. * Creates an initially unselected check box with an icon.
* *
* @param icon the Icon image to display * @param icon the Icon image to display
*/ */
public CCheckBox(Icon icon) public CCheckBox(Icon icon)
{ {
super (icon); super (icon);
init(); init();
} }
/** /**
* Creates a check box with an icon and specifies whether * Creates a check box with an icon and specifies whether
* or not it is initially selected. * or not it is initially selected.
* *
* @param icon the Icon image to display * @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection * @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected * state. If <code>true</code> the check box is selected
*/ */
public CCheckBox(Icon icon, boolean selected) public CCheckBox(Icon icon, boolean selected)
{ {
super (icon, selected); super (icon, selected);
init(); init();
} }
/** /**
* Creates an initially unselected check box with text. * Creates an initially unselected check box with text.
* *
* @param text the text of the check box. * @param text the text of the check box.
*/ */
public CCheckBox (String text) public CCheckBox (String text)
{ {
super (text); super (text);
init(); init();
} }
/** /**
* Creates a check box where properties are taken from the * Creates a check box where properties are taken from the
* Action supplied. * Action supplied.
* @param a * @param a
*/ */
public CCheckBox(Action a) public CCheckBox(Action a)
{ {
super (a); super (a);
init(); init();
} }
/** /**
* Creates a check box with text and specifies whether * Creates a check box with text and specifies whether
* or not it is initially selected. * or not it is initially selected.
* *
* @param text the text of the check box. * @param text the text of the check box.
* @param selected a boolean value indicating the initial selection * @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected * state. If <code>true</code> the check box is selected
*/ */
public CCheckBox (String text, boolean selected) public CCheckBox (String text, boolean selected)
{ {
super (text, selected); super (text, selected);
init(); init();
} }
/** /**
* Creates an initially unselected check box with * Creates an initially unselected check box with
* the specified text and icon. * the specified text and icon.
* *
* @param text the text of the check box. * @param text the text of the check box.
* @param icon the Icon image to display * @param icon the Icon image to display
*/ */
public CCheckBox(String text, Icon icon) public CCheckBox(String text, Icon icon)
{ {
super (text, icon, false); super (text, icon, false);
init(); init();
} }
/** /**
* Creates a check box with text and icon, * Creates a check box with text and icon,
* and specifies whether or not it is initially selected. * and specifies whether or not it is initially selected.
* *
* @param text the text of the check box. * @param text the text of the check box.
* @param icon the Icon image to display * @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection * @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected * state. If <code>true</code> the check box is selected
*/ */
public CCheckBox (String text, Icon icon, boolean selected) public CCheckBox (String text, Icon icon, boolean selected)
{ {
super (text, icon, selected); super (text, icon, selected);
init(); init();
} }
/** /**
* Common Init * Common Init
*/ */
private void init() private void init()
{ {
//Default to transparent, works better under windows look and feel setFont(AdempierePLAF.getFont_Label());
setOpaque(false); setForeground(AdempierePLAF.getTextColor_Label());
} // init } // init
/*************************************************************************/ /*************************************************************************/
/** Mandatory (default false) */ /** Mandatory (default false) */
private boolean m_mandatory = false; private boolean m_mandatory = false;
/** Read-Write */ /** Read-Write */
private boolean m_readWrite = true; private boolean m_readWrite = true;
/** /**
* Set Editor Mandatory * Set Editor Mandatory
* @param mandatory true, if you have to enter data * @param mandatory true, if you have to enter data
*/ */
public void setMandatory (boolean mandatory) public void setMandatory (boolean mandatory)
{ {
m_mandatory = mandatory; m_mandatory = mandatory;
setBackground(false); setBackground(false);
} // setMandatory } // setMandatory
/** /**
* Is Field mandatory * Is Field mandatory
* @return true, if mandatory * @return true, if mandatory
*/ */
public boolean isMandatory() public boolean isMandatory()
{ {
return m_mandatory; return m_mandatory;
} // isMandatory } // isMandatory
/** /**
* Enable Editor * Enable Editor
* @param rw true, if you can enter/select data * @param rw true, if you can enter/select data
*/ */
public void setReadWrite (boolean rw) public void setReadWrite (boolean rw)
{ {
if (super.isEnabled() != rw) if (super.isEnabled() != rw)
super.setEnabled (rw); super.setEnabled (rw);
setBackground(false); setBackground(false);
m_readWrite = rw; m_readWrite = rw;
} // setEditable } // setEditable
/** /**
* Is it possible to edit * Is it possible to edit
* @return true, if editable * @return true, if editable
*/ */
public boolean isReadWrite() public boolean isReadWrite()
{ {
return m_readWrite; return m_readWrite;
} // isEditable } // isEditable
/** /**
* Set Background based on editable/mandatory/error - ignored - * Set Background based on editable/mandatory/error - ignored -
* @param error if true, set background to error color, otherwise mandatory/editable * @param error if true, set background to error color, otherwise mandatory/editable
*/ */
public void setBackground (boolean error) public void setBackground (boolean error)
{ {
} // setBackground } // setBackground
/** /**
* Set Background * Set Background
* @param bg * @param bg
*/ */
public void setBackground (Color bg) public void setBackground (Color bg)
{ {
if (bg.equals(getBackground())) if (bg.equals(getBackground()))
return; return;
super.setBackground(bg); super.setBackground(bg);
} // setBackground } // setBackground
/** Retain value */ /** Retain value */
private Object m_value = null; private Object m_value = null;
/** /**
* Set Editor to value. Interpret Y/N and Boolean * Set Editor to value. Interpret Y/N and Boolean
* @param value value of the editor * @param value value of the editor
*/ */
public void setValue (Object value) public void setValue (Object value)
{ {
m_value = value; m_value = value;
boolean sel = false; boolean sel = false;
if (value == null) if (value == null)
sel = false; sel = false;
else if (value.toString().equals("Y")) else if (value.toString().equals("Y"))
sel = true; sel = true;
else if (value.toString().equals("N")) else if (value.toString().equals("N"))
sel = false; sel = false;
else if (value instanceof Boolean) else if (value instanceof Boolean)
sel = ((Boolean)value).booleanValue(); sel = ((Boolean)value).booleanValue();
else else
{ {
try try
{ {
sel = Boolean.getBoolean(value.toString()); sel = Boolean.getBoolean(value.toString());
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
this.setSelected(sel); this.setSelected(sel);
} // setValue } // setValue
/** /**
* Return Editor value * Return Editor value
* @return current value as String or Boolean * @return current value as String or Boolean
*/ */
public Object getValue() public Object getValue()
{ {
if (m_value instanceof String) if (m_value instanceof String)
return super.isSelected() ? "Y" : "N"; return super.isSelected() ? "Y" : "N";
return new Boolean (isSelected()); return new Boolean (isSelected());
} // getValue } // getValue
/** /**
* Return Display Value * Return Display Value
* @return displayed String value * @return displayed String value
*/ */
public String getDisplay() public String getDisplay()
{ {
if (m_value instanceof String) if (m_value instanceof String)
return super.isSelected() ? "Y" : "N"; return super.isSelected() ? "Y" : "N";
return Boolean.toString(super.isSelected()); return Boolean.toString(super.isSelected());
} // getDisplay } // getDisplay
/** /**
* Set Text * Set Text
* @param mnemonicLabel text * @param mnemonicLabel text
*/ */
public void setText (String mnemonicLabel) public void setText (String mnemonicLabel)
{ {
super.setText (createMnemonic(mnemonicLabel)); super.setText (createMnemonic(mnemonicLabel));
} // setText } // setText
/** /**
* Create Mnemonics of text containing "&". * Create Mnemonics of text containing "&".
* Based on MS notation of &Help => H is Mnemonics * Based on MS notation of &Help => H is Mnemonics
* Creates ALT_ * Creates ALT_
* @param text test with Mnemonics * @param text test with Mnemonics
* @return text w/o & * @return text w/o &
*/ */
private String createMnemonic(String text) private String createMnemonic(String text)
{ {
if (text == null) if (text == null)
return text; return text;
int pos = text.indexOf("&"); int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic if (pos != -1) // We have a nemonic
{ {
char ch = text.charAt(pos+1); char ch = text.charAt(pos+1);
if (ch != ' ') // &_ - is the & character if (ch != ' ') // &_ - is the & character
{ {
setMnemonic(ch); setMnemonic(ch);
return text.substring(0, pos) + text.substring(pos+1); return text.substring(0, pos) + text.substring(pos+1);
} }
} }
return text; return text;
} // createMnemonic } // createMnemonic
} // CCheckBox } // CCheckBox

View File

@ -1,333 +1,337 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
* Adempiere Colored Combo Box. * Adempiere Colored Combo Box.
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CComboBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CComboBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CComboBox extends JComboBox public class CComboBox extends JComboBox
implements CEditor implements CEditor
{ {
/** /**
* Creates a <code>JComboBox</code> that takes it's items from an * Creates a <code>JComboBox</code> that takes it's items from an
* existing <code>ComboBoxModel</code>. Since the * existing <code>ComboBoxModel</code>. Since the
* <code>ComboBoxModel</code> is provided, a combo box created using * <code>ComboBoxModel</code> is provided, a combo box created using
* this constructor does not create a default combo box model and * this constructor does not create a default combo box model and
* may impact how the insert, remove and add methods behave. * may impact how the insert, remove and add methods behave.
* *
* @param aModel the <code>ComboBoxModel</code> that provides the * @param aModel the <code>ComboBoxModel</code> that provides the
* displayed list of items * displayed list of items
* @see DefaultComboBoxModel * @see DefaultComboBoxModel
*/ */
public CComboBox(ComboBoxModel aModel) public CComboBox(ComboBoxModel aModel)
{ {
super(aModel); super(aModel);
init(); init();
} // CComboBox } // CComboBox
/** /**
* Creates a <code>JComboBox</code> that contains the elements * Creates a <code>JComboBox</code> that contains the elements
* in the specified array. By default the first item in the array * in the specified array. By default the first item in the array
* (and therefore the data model) becomes selected. * (and therefore the data model) becomes selected.
* *
* @param items an array of objects to insert into the combo box * @param items an array of objects to insert into the combo box
* @see DefaultComboBoxModel * @see DefaultComboBoxModel
*/ */
public CComboBox(final Object items[]) public CComboBox(final Object items[])
{ {
super(items); super(items);
init(); init();
} // CComboBox } // CComboBox
/** /**
* Creates a <code>JComboBox</code> that contains the elements * Creates a <code>JComboBox</code> that contains the elements
* in the specified array. By default the first item in the array * in the specified array. By default the first item in the array
* (and therefore the data model) becomes selected. * (and therefore the data model) becomes selected.
* *
* @param items an array of objects to insert into the combo box * @param items an array of objects to insert into the combo box
* @param key set selected if exists * @param key set selected if exists
* @see DefaultComboBoxModel * @see DefaultComboBoxModel
*/ */
public CComboBox(final Object items[], String key) public CComboBox(final Object items[], String key)
{ {
this(items); this(items);
if (key == null) if (key == null)
return; return;
for (int i = 0; i < 0; i++) for (int i = 0; i < 0; i++)
{ {
Object item = items[i]; Object item = items[i];
if (item == null) if (item == null)
continue; continue;
boolean found = false; boolean found = false;
if (item instanceof NamePair) if (item instanceof NamePair)
found = ((NamePair)item).getID().equals(key); found = ((NamePair)item).getID().equals(key);
else else
found = item.toString().equals(key); found = item.toString().equals(key);
if (found) if (found)
{ {
setSelectedIndex(i); setSelectedIndex(i);
break; break;
} }
} }
} // CComboBox } // CComboBox
/** /**
* Creates a <code>JComboBox</code> that contains the elements * Creates a <code>JComboBox</code> that contains the elements
* in the specified Vector. By default the first item in the vector * in the specified Vector. By default the first item in the vector
* and therefore the data model) becomes selected. * and therefore the data model) becomes selected.
* *
* @param items an array of vectors to insert into the combo box * @param items an array of vectors to insert into the combo box
* @see DefaultComboBoxModel * @see DefaultComboBoxModel
*/ */
public CComboBox(Vector items) public CComboBox(Vector items)
{ {
super(items); super(items);
init(); init();
} // CComboBox } // CComboBox
/** /**
* Creates a <code>JComboBox</code> with a default data model. * Creates a <code>JComboBox</code> with a default data model.
* The default data model is an empty list of objects. * The default data model is an empty list of objects.
* Use <code>addItem</code> to add items. By default the first item * Use <code>addItem</code> to add items. By default the first item
* in the data model becomes selected. * in the data model becomes selected.
* *
* @see DefaultComboBoxModel * @see DefaultComboBoxModel
*/ */
public CComboBox() public CComboBox()
{ {
super(); super();
init(); init();
} // CComboBox } // CComboBox
/** Field Height */ /** Field Height */
public static int FIELD_HIGHT = 0; public static int FIELD_HIGHT = 0;
/** /**
* Common Init * Common Init
*/ */
private void init() private void init()
{ {
FIELD_HIGHT = getPreferredSize().height; // overwrite - otherwise Label Font
} // init setFont(AdempierePLAF.getFont_Field());
setForeground(AdempierePLAF.getTextColor_Normal());
setBackground(false);
/*************************************************************************/ FIELD_HIGHT = getPreferredSize().height;
} // init
/** Icon */
private Icon m_icon = null;
/*************************************************************************/
/**
* Set Icon of arrow button to icon /** Icon */
* @param defaultIcon Icon to be displayed private Icon m_icon = null;
*/
public void setIcon (Icon defaultIcon) /**
{ * Set Icon of arrow button to icon
if (getUI() instanceof CompiereComboBoxUI) * @param defaultIcon Icon to be displayed
((CompiereComboBoxUI)getUI()).setIcon(defaultIcon); */
m_icon = defaultIcon; public void setIcon (Icon defaultIcon)
} // setIcon {
if (getUI() instanceof CompiereComboBoxUI)
/** ((CompiereComboBoxUI)getUI()).setIcon(defaultIcon);
* Set UI and re-set Icon for arrow button m_icon = defaultIcon;
* @param ui } // setIcon
*/
public void setUI (ComboBoxUI ui) /**
{ * Set UI and re-set Icon for arrow button
super.setUI(ui); * @param ui
if (m_icon != null && ui instanceof CompiereComboBoxUI) */
((CompiereComboBoxUI)getUI()).setIcon(m_icon); public void setUI (ComboBoxUI ui)
} // setUI {
super.setUI(ui);
/** if (m_icon != null && ui instanceof CompiereComboBoxUI)
* Display Popup. ((CompiereComboBoxUI)getUI()).setIcon(m_icon);
* Called from AdempiereComboPopup and allows to implement } // setUI
* alternative actions than showing the popup
* @return if true, the popup should be displayed /**
*/ * Display Popup.
public boolean displayPopup() * Called from AdempiereComboPopup and allows to implement
{ * alternative actions than showing the popup
return true; * @return if true, the popup should be displayed
} // displayPopup */
public boolean displayPopup()
/*************************************************************************/ {
return true;
/** Mandatory (default false) */ } // displayPopup
private boolean m_mandatory = false;
/*************************************************************************/
/**
* Set Editor Mandatory /** Mandatory (default false) */
* @param mandatory true, if you have to enter data private boolean m_mandatory = false;
*/
public void setMandatory (boolean mandatory) /**
{ * Set Editor Mandatory
m_mandatory = mandatory; * @param mandatory true, if you have to enter data
setBackground(false); */
} // setMandatory public void setMandatory (boolean mandatory)
{
/** m_mandatory = mandatory;
* Is Field mandatory setBackground(false);
* @return true, if mandatory } // setMandatory
*/
public boolean isMandatory() /**
{ * Is Field mandatory
return m_mandatory; * @return true, if mandatory
} // isMandatory */
public boolean isMandatory()
/** {
* Enable Editor return m_mandatory;
* @param rw true, if you can enter/select data } // isMandatory
*/
public void setReadWrite (boolean rw) /**
{ * Enable Editor
if (super.isEnabled() != rw) * @param rw true, if you can enter/select data
super.setEnabled (rw); */
setBackground(false); public void setReadWrite (boolean rw)
} // setReadWrite {
if (super.isEnabled() != rw)
/** super.setEnabled (rw);
* Is it possible to edit setBackground(false);
* @return true, if editable } // setReadWrite
*/
public boolean isReadWrite() /**
{ * Is it possible to edit
return super.isEnabled(); * @return true, if editable
} // isReadWrite */
public boolean isReadWrite()
/** {
* Set Background based on editable / mandatory / error return super.isEnabled();
* @param error if true, set background to error color, otherwise mandatory/editable } // isReadWrite
*/
public void setBackground (boolean error) /**
{ * Set Background based on editable / mandatory / error
if (error) * @param error if true, set background to error color, otherwise mandatory/editable
setBackground(AdempierePLAF.getFieldBackground_Error()); */
else if (!isReadWrite()) public void setBackground (boolean error)
setBackground(AdempierePLAF.getFieldBackground_Inactive()); {
else if (m_mandatory) if (error)
setBackground(AdempierePLAF.getFieldBackground_Mandatory()); setBackground(AdempierePLAF.getFieldBackground_Error());
else else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Normal()); setBackground(AdempierePLAF.getFieldBackground_Inactive());
} // setBackground else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
/** else
* Set Background setBackground(AdempierePLAF.getFieldBackground_Normal());
* @param bg } // setBackground
*/
public void setBackground (Color bg) /**
{ * Set Background
if (bg.equals(getBackground())) * @param bg
return; */
super.setBackground(bg); public void setBackground (Color bg)
} // setBackground {
if (bg.equals(getBackground()))
/** return;
* Set Editor to value super.setBackground(bg);
* @param value value of the editor } // setBackground
*/
public void setValue (Object value) /**
{ * Set Editor to value
super.setSelectedItem(value); * @param value value of the editor
} // setValue */
public void setValue (Object value)
/** {
* Return Editor value super.setSelectedItem(value);
* @return current value } // setValue
*/
public Object getValue() /**
{ * Return Editor value
return super.getSelectedItem(); * @return current value
} // getValue */
public Object getValue()
/** {
* Return Display Value return super.getSelectedItem();
* @return displayed String value } // getValue
*/
public String getDisplay() /**
{ * Return Display Value
Object o = super.getSelectedItem(); * @return displayed String value
if (o == null) */
return ""; public String getDisplay()
return o.toString(); {
} // getDisplay Object o = super.getSelectedItem();
if (o == null)
/** return "";
* Add Mouse Listener - 1-4-0 Bug. return o.toString();
* Bug in 1.4.0 Metal: arrowButton gets Mouse Events, so add the JComboBox } // getDisplay
* MouseListeners to the arrowButton - No context menu if right-click
* @see CompiereComboBoxUI#installUI(JComponent) /**
* @param ml * Add Mouse Listener - 1-4-0 Bug.
*/ * Bug in 1.4.0 Metal: arrowButton gets Mouse Events, so add the JComboBox
public void addMouseListener (MouseListener ml) * MouseListeners to the arrowButton - No context menu if right-click
{ * @see CompiereComboBoxUI#installUI(JComponent)
super.addMouseListener(ml); * @param ml
// ignore calls from javax.swing.plaf.basic.BasicComboBoxUI.installListeners(BasicComboBoxUI.java:271) */
if (getUI() instanceof CompiereComboBoxUI && !Trace.getCallerClass(1).startsWith("javax")) public void addMouseListener (MouseListener ml)
{ {
JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton(); super.addMouseListener(ml);
if (b != null) // ignore calls from javax.swing.plaf.basic.BasicComboBoxUI.installListeners(BasicComboBoxUI.java:271)
b.addMouseListener(ml); if (getUI() instanceof CompiereComboBoxUI && !Trace.getCallerClass(1).startsWith("javax"))
} {
//begin vpj-cd e-evolution JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton();
if (getUI() instanceof org.adempiere.plaf.AdempiereComboBoxUI && !Trace.getCallerClass(1).startsWith("javax")) if (b != null)
{ b.addMouseListener(ml);
JButton b = ((org.adempiere.plaf.AdempiereComboBoxUI)getUI()).getArrowButton(); }
if (b != null) //begin vpj-cd e-evolution
b.addMouseListener(ml); if (getUI() instanceof org.adempiere.plaf.AdempiereComboBoxUI && !Trace.getCallerClass(1).startsWith("javax"))
} {
//end vpj-cd e-evolution JButton b = ((org.adempiere.plaf.AdempiereComboBoxUI)getUI()).getArrowButton();
} // addMouseListener if (b != null)
b.addMouseListener(ml);
/** }
* Remove Mouse Listener. //end vpj-cd e-evolution
* @param ml } // addMouseListener
*/
public void removeMouseListener (MouseListener ml) /**
{ * Remove Mouse Listener.
super.removeMouseListener(ml); * @param ml
if (getUI() instanceof CompiereComboBoxUI) */
{ public void removeMouseListener (MouseListener ml)
JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton(); {
if (b != null) super.removeMouseListener(ml);
b.removeMouseListener(ml); if (getUI() instanceof CompiereComboBoxUI)
} {
} // removeMouseListener JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton();
if (b != null)
/** b.removeMouseListener(ml);
* Set Action Command }
* @param actionCommand command } // removeMouseListener
*/
public void setActionCommand (String actionCommand) /**
{ * Set Action Command
super.setActionCommand (actionCommand); * @param actionCommand command
if (getName() == null && actionCommand != null && actionCommand.length() > 0) */
setName(actionCommand); public void setActionCommand (String actionCommand)
} // setActionCommand {
super.setActionCommand (actionCommand);
} // CComboBox if (getName() == null && actionCommand != null && actionCommand.length() > 0)
setName(actionCommand);
} // setActionCommand
} // CComboBox

View File

@ -3,24 +3,24 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import org.compiere.plaf.*; import org.compiere.plaf.*;
/** /**
* Conveniance Dialog Class. * Conveniance Dialog Class.
@ -28,216 +28,217 @@ import org.compiere.plaf.*;
* Implementing empty Action and Mouse Listener * Implementing empty Action and Mouse Listener
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CDialog extends JDialog public class CDialog extends JDialog
implements ActionListener, MouseListener implements ActionListener, MouseListener
{ {
/** /**
* CDialog * CDialog
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog() throws HeadlessException public CDialog() throws HeadlessException
{ {
this((Frame)null, false); this((Frame)null, false);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Frame owner) throws HeadlessException public CDialog(Frame owner) throws HeadlessException
{ {
this (owner, false); this (owner, false);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param modal * @param modal
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Frame owner, boolean modal) throws HeadlessException public CDialog(Frame owner, boolean modal) throws HeadlessException
{ {
this (owner, null, modal); this (owner, null, modal);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Frame owner, String title) throws HeadlessException public CDialog(Frame owner, String title) throws HeadlessException
{ {
this (owner, title, false); this (owner, title, false);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @param modal * @param modal
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Frame owner, String title, boolean modal) throws HeadlessException public CDialog(Frame owner, String title, boolean modal) throws HeadlessException
{ {
super(owner, title, modal); super(owner, title, modal);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @param modal * @param modal
* @param gc * @param gc
*/ */
public CDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc) public CDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
{ {
super(owner, title, modal, gc); super(owner, title, modal, gc);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Dialog owner) throws HeadlessException public CDialog(Dialog owner) throws HeadlessException
{ {
this (owner, false); this (owner, false);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param modal * @param modal
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Dialog owner, boolean modal) throws HeadlessException public CDialog(Dialog owner, boolean modal) throws HeadlessException
{ {
this(owner, null, modal); this(owner, null, modal);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Dialog owner, String title) throws HeadlessException public CDialog(Dialog owner, String title) throws HeadlessException
{ {
this(owner, title, false); this(owner, title, false);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @param modal * @param modal
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Dialog owner, String title, boolean modal) throws HeadlessException public CDialog(Dialog owner, String title, boolean modal) throws HeadlessException
{ {
super(owner, title, modal); super(owner, title, modal);
} }
/** /**
* CDialog * CDialog
* @param owner * @param owner
* @param title * @param title
* @param modal * @param modal
* @param gc * @param gc
* @throws HeadlessException * @throws HeadlessException
*/ */
public CDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException public CDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException
{ {
super(owner, title, modal, gc); super(owner, title, modal, gc);
} }
/** /**
* Initialize. * Initialize.
* Install ALT-Pause * Install ALT-Pause
*/ */
protected void dialogInit() protected void dialogInit()
{ {
super.dialogInit(); super.dialogInit();
CompiereColor.setBackground(this);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setTitle(getTitle()); // remove Mn setTitle(getTitle()); // remove Mn
// //
Container c = getContentPane(); Container c = getContentPane();
if (c instanceof JPanel) if (c instanceof JPanel)
{ {
JPanel panel = (JPanel)c; JPanel panel = (JPanel)c;
panel.getActionMap().put(ACTION_DISPOSE, s_dialogAction); panel.getActionMap().put(ACTION_DISPOSE, s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(s_disposeKeyStroke, ACTION_DISPOSE); panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(s_disposeKeyStroke, ACTION_DISPOSE);
} }
} // init } // init
/************************************************************************** /**************************************************************************
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @param e * @param e
*/ */
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
} }
/** /**
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
* @param e * @param e
*/ */
public void mouseClicked(MouseEvent e) public void mouseClicked(MouseEvent e)
{ {
} }
/** /**
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* @param e * @param e
*/ */
public void mouseEntered(MouseEvent e) public void mouseEntered(MouseEvent e)
{ {
} }
/** /**
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
* @param e * @param e
*/ */
public void mouseExited(MouseEvent e) public void mouseExited(MouseEvent e)
{ {
} }
/** /**
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
* @param e * @param e
*/ */
public void mousePressed(MouseEvent e) public void mousePressed(MouseEvent e)
{ {
} }
/** /**
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
* @param e * @param e
*/ */
public void mouseReleased(MouseEvent e) public void mouseReleased(MouseEvent e)
{ {
} }
/** /**
* Set Title * Set Title
* @param title title * @param title title
*/ */
public void setTitle(String title) public void setTitle(String title)
{ {
if (title != null) if (title != null)
{ {
int pos = title.indexOf("&"); int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic if (pos != -1 && title.length() > pos) // We have a nemonic
{ {
int mnemonic = title.toUpperCase().charAt(pos+1); int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ') if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1); title = title.substring(0, pos) + title.substring(pos+1);
} }
} }
super.setTitle(title); super.setTitle(title);
} // setTitle } // setTitle
/** Dispose Action Name */ /** Dispose Action Name */
protected static String ACTION_DISPOSE = "CDialogDispose"; protected static String ACTION_DISPOSE = "CDialogDispose";
/** Action */ /** Action */
protected static DialogAction s_dialogAction = new DialogAction(ACTION_DISPOSE); protected static DialogAction s_dialogAction = new DialogAction(ACTION_DISPOSE);
/** ALT-EXCAPE */ /** ALT-EXCAPE */
protected static KeyStroke s_disposeKeyStroke = protected static KeyStroke s_disposeKeyStroke =
KeyStroke.getKeyStroke(KeyEvent.VK_PAUSE, InputEvent.ALT_MASK); KeyStroke.getKeyStroke(KeyEvent.VK_PAUSE, InputEvent.ALT_MASK);
/** /**
@ -245,40 +246,40 @@ public class CDialog extends JDialog
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/ */
static class DialogAction extends AbstractAction static class DialogAction extends AbstractAction
{ {
DialogAction (String actionName) DialogAction (String actionName)
{ {
super(actionName); super(actionName);
putValue(AbstractAction.ACTION_COMMAND_KEY, actionName); putValue(AbstractAction.ACTION_COMMAND_KEY, actionName);
} // DialogAction } // DialogAction
/** /**
* Action Listener * Action Listener
* @param e event * @param e event
*/ */
public void actionPerformed (ActionEvent e) public void actionPerformed (ActionEvent e)
{ {
if (ACTION_DISPOSE.equals(e.getActionCommand())) if (ACTION_DISPOSE.equals(e.getActionCommand()))
{ {
Object source = e.getSource(); Object source = e.getSource();
while (source != null) while (source != null)
{ {
if (source instanceof Window) if (source instanceof Window)
{ {
((Window)source).dispose(); ((Window)source).dispose();
return; return;
} }
if (source instanceof Container) if (source instanceof Container)
source = ((Container)source).getParent(); source = ((Container)source).getParent();
else else
source = null; source = null;
} }
} }
else else
System.out.println("Action: " + e); System.out.println("Action: " + e);
} // actionPerformed } // actionPerformed
} // DialogAction } // DialogAction
} // CDialog } // CDialog

View File

@ -3,21 +3,21 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import org.compiere.plaf.*; import org.compiere.plaf.*;
/** /**
@ -25,111 +25,112 @@ import org.compiere.plaf.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CFrame.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CFrame.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CFrame extends JFrame public class CFrame extends JFrame
{ {
/** /**
* CFrame * CFrame
* @throws HeadlessException * @throws HeadlessException
*/ */
public CFrame () throws HeadlessException public CFrame () throws HeadlessException
{ {
super (); super ();
} // CFrame } // CFrame
/** /**
* CFrame * CFrame
* @param gc * @param gc
*/ */
public CFrame (GraphicsConfiguration gc) public CFrame (GraphicsConfiguration gc)
{ {
super (gc); super (gc);
} // CFrame } // CFrame
/** /**
* CFrame * CFrame
* @param title * @param title
* @throws HeadlessException * @throws HeadlessException
*/ */
public CFrame (String title) throws HeadlessException public CFrame (String title) throws HeadlessException
{ {
super (cleanup(title)); super (cleanup(title));
} // CFrame } // CFrame
/** /**
* CFrame * CFrame
* @param title * @param title
* @param gc * @param gc
*/ */
public CFrame (String title, GraphicsConfiguration gc) public CFrame (String title, GraphicsConfiguration gc)
{ {
super (cleanup(title), gc); super (cleanup(title), gc);
} // CFrame } // CFrame
/** Window ID */ /** Window ID */
private int p_AD_Window_ID = 0; private int p_AD_Window_ID = 0;
/** /**
* Frame Init. * Frame Init.
* Install ALT-Pause * Install ALT-Pause
*/ */
protected void frameInit () protected void frameInit ()
{ {
super.frameInit (); super.frameInit ();
CompiereColor.setBackground(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// //
Container c = getContentPane(); Container c = getContentPane();
if (c instanceof JPanel) if (c instanceof JPanel)
{ {
JPanel panel = (JPanel)c; JPanel panel = (JPanel)c;
panel.getActionMap().put(CDialog.ACTION_DISPOSE, CDialog.s_dialogAction); panel.getActionMap().put(CDialog.ACTION_DISPOSE, CDialog.s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(CDialog.s_disposeKeyStroke, CDialog.ACTION_DISPOSE); panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(CDialog.s_disposeKeyStroke, CDialog.ACTION_DISPOSE);
} }
} // frameInit } // frameInit
/** /**
* Cleanedup Title * Cleanedup Title
* @param title title * @param title title
* @return title w/o mn * @return title w/o mn
*/ */
private static String cleanup (String title) private static String cleanup (String title)
{ {
if (title != null) if (title != null)
{ {
int pos = title.indexOf("&"); int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic if (pos != -1 && title.length() > pos) // We have a nemonic
{ {
int mnemonic = title.toUpperCase().charAt(pos+1); int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ') if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1); title = title.substring(0, pos) + title.substring(pos+1);
} }
} }
return title; return title;
} // getTitle } // getTitle
/** /**
* Set Title * Set Title
* @param title title * @param title title
*/ */
public void setTitle(String title) public void setTitle(String title)
{ {
super.setTitle(cleanup(title)); super.setTitle(cleanup(title));
} // setTitle } // setTitle
/** /**
* @return Returns the AD_Window_ID. * @return Returns the AD_Window_ID.
*/ */
public int getAD_Window_ID () public int getAD_Window_ID ()
{ {
return p_AD_Window_ID; return p_AD_Window_ID;
} // getAD_Window_ID } // getAD_Window_ID
/** /**
* @param window_ID The AD_Window_ID to set. * @param window_ID The AD_Window_ID to set.
*/ */
public void setAD_Window_ID (int window_ID) public void setAD_Window_ID (int window_ID)
{ {
p_AD_Window_ID = window_ID; p_AD_Window_ID = window_ID;
} // getAD_Window_ID } // getAD_Window_ID
} // CFrame } // CFrame

View File

@ -1,281 +1,285 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import org.compiere.plaf.*; import org.compiere.plaf.*;
import org.adempiere.plaf.*;
/**
* Label with Mnemonics interpretation /**
* * Label with Mnemonics interpretation
* @author Jorg Janke *
* @version $Id: CLabel.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @author Jorg Janke
*/ * @version $Id: CLabel.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
public class CLabel extends JLabel */
{ public class CLabel extends JLabel
public static int DEFAULT_ALIGNMENT = JLabel.TRAILING; {
public static int DEFAULT_ALIGNMENT = JLabel.TRAILING;
/**
* Creates a <code>Label</code> instance with the specified /**
* text, image, and horizontal alignment. * Creates a <code>Label</code> instance with the specified
* The label is centered vertically in its display area. * text, image, and horizontal alignment.
* The text is on the trailing edge of the image. * The label is centered vertically in its display area.
* * The text is on the trailing edge of the image.
* @param text The text to be displayed by the label. *
* @param icon The image to be displayed by the label. * @param text The text to be displayed by the label.
* @param horizontalAlignment One of the following constants * @param icon The image to be displayed by the label.
* defined in <code>SwingConstants</code>: * @param horizontalAlignment One of the following constants
* <code>LEFT</code>, * defined in <code>SwingConstants</code>:
* <code>CENTER</code>, * <code>LEFT</code>,
* <code>RIGHT</code>, * <code>CENTER</code>,
* <code>LEADING</code> or * <code>RIGHT</code>,
* <code>TRAILING</code>. * <code>LEADING</code> or
*/ * <code>TRAILING</code>.
public CLabel (String text, Icon icon, int horizontalAlignment) */
{ public CLabel (String text, Icon icon, int horizontalAlignment)
super (text, icon, horizontalAlignment); {
init(); super (text, icon, horizontalAlignment);
} init();
}
/**
* Creates a <code>Label</code> instance with the specified /**
* text and horizontal alignment. * Creates a <code>Label</code> instance with the specified
* The label is centered vertically in its display area. * text and horizontal alignment.
* * The label is centered vertically in its display area.
* @param text The text to be displayed by the label. *
* @param horizontalAlignment One of the following constants * @param text The text to be displayed by the label.
* defined in <code>SwingConstants</code>: * @param horizontalAlignment One of the following constants
* <code>LEFT</code>, * defined in <code>SwingConstants</code>:
* <code>CENTER</code>, * <code>LEFT</code>,
* <code>RIGHT</code>, * <code>CENTER</code>,
* <code>LEADING</code> or * <code>RIGHT</code>,
* <code>TRAILING</code>. * <code>LEADING</code> or
*/ * <code>TRAILING</code>.
public CLabel (String text, int horizontalAlignment) */
{ public CLabel (String text, int horizontalAlignment)
super(text, horizontalAlignment); {
init(); super(text, horizontalAlignment);
} init();
}
/**
* Creates a <code>Label</code> instance with the specified text. /**
* The label is aligned against the leading edge of its display area, * Creates a <code>Label</code> instance with the specified text.
* and centered vertically. * The label is aligned against the leading edge of its display area,
* * and centered vertically.
* @param text The text to be displayed by the label. *
*/ * @param text The text to be displayed by the label.
public CLabel (String text) */
{ public CLabel (String text)
super(text, DEFAULT_ALIGNMENT); {
init(); super(text, DEFAULT_ALIGNMENT);
} init();
}
/**
* Creates a <code>Label</code> instance with the specified /**
* image and horizontal alignment. * Creates a <code>Label</code> instance with the specified
* The label is centered vertically in its display area. * image and horizontal alignment.
* * The label is centered vertically in its display area.
* @param image The image to be displayed by the label. *
* @param horizontalAlignment One of the following constants * @param image The image to be displayed by the label.
* defined in <code>SwingConstants</code>: * @param horizontalAlignment One of the following constants
* <code>LEFT</code>, * defined in <code>SwingConstants</code>:
* <code>CENTER</code>, * <code>LEFT</code>,
* <code>RIGHT</code>, * <code>CENTER</code>,
* <code>LEADING</code> or * <code>RIGHT</code>,
* <code>TRAILING</code>. * <code>LEADING</code> or
*/ * <code>TRAILING</code>.
public CLabel (Icon image, int horizontalAlignment) */
{ public CLabel (Icon image, int horizontalAlignment)
super (image, horizontalAlignment); {
init(); super (image, horizontalAlignment);
} init();
}
/**
* Creates a <code>Label</code> instance with the specified image. /**
* The label is centered vertically and horizontally * Creates a <code>Label</code> instance with the specified image.
* in its display area. * The label is centered vertically and horizontally
* * in its display area.
* @param image The image to be displayed by the label. *
*/ * @param image The image to be displayed by the label.
public CLabel (Icon image) */
{ public CLabel (Icon image)
super (image, DEFAULT_ALIGNMENT); {
init(); super (image, DEFAULT_ALIGNMENT);
} init();
}
/**
* Creates a <code>JLabel</code> instance with /**
* no image and with an empty string for the title. * Creates a <code>JLabel</code> instance with
* The label is centered vertically * no image and with an empty string for the title.
* in its display area. * The label is centered vertically
* The label's contents, once set, will be displayed on the leading edge * in its display area.
* of the label's display area. * The label's contents, once set, will be displayed on the leading edge
*/ * of the label's display area.
public CLabel () */
{ public CLabel ()
super("", DEFAULT_ALIGNMENT); {
init(); super("", DEFAULT_ALIGNMENT);
} init();
}
/**
* Creates a <code>Label</code> instance with the specified text. /**
* The label is aligned against the leading edge of its display area, * Creates a <code>Label</code> instance with the specified text.
* and centered vertically. * The label is aligned against the leading edge of its display area,
* * and centered vertically.
* @param label The text to be displayed by the label. *
* @param toolTip The optional Tooltip text * @param label The text to be displayed by the label.
*/ * @param toolTip The optional Tooltip text
public CLabel (String label, String toolTip) */
{ public CLabel (String label, String toolTip)
super (label, DEFAULT_ALIGNMENT); {
if (toolTip != null && toolTip.length() > 0) super (label, DEFAULT_ALIGNMENT);
super.setToolTipText(toolTip); if (toolTip != null && toolTip.length() > 0)
init(); super.setToolTipText(toolTip);
} // CLabel init();
} // CLabel
/**
* Trailing Label for Field /**
* @param label label * Trailing Label for Field
* @param field field * @param label label
*/ * @param field field
public CLabel (String label, Component field) */
{ public CLabel (String label, Component field)
this (label, TRAILING); {
setLabelFor(field); this (label, TRAILING);
} // CLabel setLabelFor(field);
} // CLabel
/** Mnemonic saved */
private char m_savedMnemonic = 0; /** Mnemonic saved */
private char m_savedMnemonic = 0;
/**
* Common init /**
*/ * Common init
private void init() */
{ private void init()
setFocusable (false); {
setOpaque(false); setFocusable (false);
if (getToolTipText() == null) // force Tool Tip setOpaque(false);
setToolTipText(getText()); if (getToolTipText() == null) // force Tool Tip
} // init setToolTipText(getText());
//
setForeground(AdempierePLAF.getTextColor_Label());
/** setFont(AdempierePLAF.getFont_Label());
* Set Background } // init
* @param bg background
*/
public void setBackground (Color bg) /**
{ * Set Background
if (bg.equals(getBackground())) * @param bg background
return; */
super.setBackground(bg); public void setBackground (Color bg)
} // setBackground {
if (bg.equals(getBackground()))
/** return;
* Set Font to Bold super.setBackground(bg);
* @param bold true bold false normal } // setBackground
*/
public void setFontBold (boolean bold) /**
{ * Set Font to Bold
Font font = getFont(); * @param bold true bold false normal
if (bold != font.isBold()) */
{ public void setFontBold (boolean bold)
font = new Font (font.getName(), bold ? {
Font.BOLD : Font.PLAIN, Font font = getFont();
font.getSize()); if (bold != font.isBold())
setFont (font); {
} font = new Font (font.getName(), bold ?
} // setFontBold Font.BOLD : Font.PLAIN,
font.getSize());
/************************************************************************** setFont (font);
* Set label text - if it includes &, the next character is the Mnemonic }
* @param mnemonicLabel Label containing Mnemonic } // setFontBold
*/
public void setText (String mnemonicLabel) /**************************************************************************
{ * Set label text - if it includes &, the next character is the Mnemonic
String text = createMnemonic (mnemonicLabel); * @param mnemonicLabel Label containing Mnemonic
super.setText (text); */
if (text != null && getName() == null) public void setText (String mnemonicLabel)
setName(text); {
} // setText String text = createMnemonic (mnemonicLabel);
super.setText (text);
/** if (text != null && getName() == null)
* Create Mnemonics of text containing "&". setName(text);
* Based on MS notation of &Help => H is Mnemonics } // setText
* @param text test with Mnemonics
* @return text w/o & /**
* @see JLabel#setLabelFor(java.awt.Component) * Create Mnemonics of text containing "&".
*/ * Based on MS notation of &Help => H is Mnemonics
private String createMnemonic(String text) * @param text test with Mnemonics
{ * @return text w/o &
if (text == null) * @see JLabel#setLabelFor(java.awt.Component)
return text; */
int pos = text.indexOf("&"); private String createMnemonic(String text)
if (pos != -1) // We have a nemonic {
{ if (text == null)
char ch = text.charAt(pos+1); return text;
if (ch != ' ') // &_ - is the & character int pos = text.indexOf("&");
{ if (pos != -1) // We have a nemonic
setDisplayedMnemonic(ch); {
setSavedMnemonic(ch); char ch = text.charAt(pos+1);
return text.substring(0, pos) + text.substring(pos+1); if (ch != ' ') // &_ - is the & character
} {
} setDisplayedMnemonic(ch);
return text; setSavedMnemonic(ch);
} // createMnemonic return text.substring(0, pos) + text.substring(pos+1);
}
/** }
* Set ReadWrite return text;
* @param rw enabled } // createMnemonic
*/
public void setReadWrite (boolean rw) /**
{ * Set ReadWrite
this.setEnabled(rw); * @param rw enabled
} // setReadWrite */
public void setReadWrite (boolean rw)
/** {
* Set Label For this.setEnabled(rw);
* @param c component } // setReadWrite
*/
public void setLabelFor (Component c) /**
{ * Set Label For
super.setLabelFor (c); * @param c component
if (c.getName() == null) */
c.setName(getName()); public void setLabelFor (Component c)
} // setLabelFor {
super.setLabelFor (c);
if (c.getName() == null)
/** c.setName(getName());
* @return Returns the savedMnemonic. } // setLabelFor
*/
public char getSavedMnemonic ()
{ /**
return m_savedMnemonic; * @return Returns the savedMnemonic.
} // getSavedMnemonic */
public char getSavedMnemonic ()
/** {
* @param savedMnemonic The savedMnemonic to set. return m_savedMnemonic;
*/ } // getSavedMnemonic
public void setSavedMnemonic (char savedMnemonic)
{ /**
m_savedMnemonic = savedMnemonic; * @param savedMnemonic The savedMnemonic to set.
} // getSavedMnemonic */
public void setSavedMnemonic (char savedMnemonic)
} // CLabel {
m_savedMnemonic = savedMnemonic;
} // getSavedMnemonic
} // CLabel

View File

@ -1,197 +1,197 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
* Adempiere Panel supporting colored Backgrounds * Adempiere Panel supporting colored Backgrounds
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CPanel.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CPanel.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CPanel extends JPanel public class CPanel extends JPanel
{ {
/** /**
* Creates a new AdempierePanel with the specified layout manager * Creates a new AdempierePanel with the specified layout manager
* and buffering strategy. * and buffering strategy.
* @param layout the LayoutManager to use * @param layout the LayoutManager to use
* @param isDoubleBuffered a boolean, true for double-buffering, which * @param isDoubleBuffered a boolean, true for double-buffering, which
* uses additional memory space to achieve fast, flicker-free updates * uses additional memory space to achieve fast, flicker-free updates
*/ */
public CPanel (LayoutManager layout, boolean isDoubleBuffered) public CPanel (LayoutManager layout, boolean isDoubleBuffered)
{ {
super (layout, isDoubleBuffered); super (layout, isDoubleBuffered);
init(); init();
} // CPanel } // CPanel
/** /**
* Create a new buffered CPanel with the specified layout manager * Create a new buffered CPanel with the specified layout manager
* @param layout the LayoutManager to use * @param layout the LayoutManager to use
*/ */
public CPanel (LayoutManager layout) public CPanel (LayoutManager layout)
{ {
super (layout); super (layout);
init(); init();
} // CPanel } // CPanel
/** /**
* Creates a new <code>CPanel</code> with <code>FlowLayout</code> * Creates a new <code>CPanel</code> with <code>FlowLayout</code>
* and the specified buffering strategy. * and the specified buffering strategy.
* If <code>isDoubleBuffered</code> is true, the <code>CPanel</code> * If <code>isDoubleBuffered</code> is true, the <code>CPanel</code>
* will use a double buffer. * will use a double buffer.
* @param isDoubleBuffered a boolean, true for double-buffering, which * @param isDoubleBuffered a boolean, true for double-buffering, which
* uses additional memory space to achieve fast, flicker-free updates * uses additional memory space to achieve fast, flicker-free updates
*/ */
public CPanel (boolean isDoubleBuffered) public CPanel (boolean isDoubleBuffered)
{ {
super (isDoubleBuffered); super (isDoubleBuffered);
init(); init();
} // CPanel } // CPanel
/** /**
* Creates a new <code>CPanel</code> with a double buffer and a flow layout. * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
*/ */
public CPanel() public CPanel()
{ {
super (); super ();
init(); init();
} // CPanel } // CPanel
/** /**
* Creates a new <code>CPanel</code> with a double buffer and a flow layout. * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
* @param bc Initial Background Color * @param bc Initial Background Color
*/ */
public CPanel(CompiereColor bc) public CPanel(CompiereColor bc)
{ {
this (); this ();
init(); init();
setBackgroundColor (bc); setBackgroundColor (bc);
} // CPanel } // CPanel
/** /**
* Common init. * Common init.
* Adempiere backround requires that for the base, background is set explictily. * Adempiere backround requires that for the base, background is set explictily.
* The additional panels should be transparent. * The additional panels should be transparent.
*/ */
private void init() private void init()
{ {
setOpaque(false); // transparent setOpaque(false); // transparent
} // init } // init
/************************************************************************** /**************************************************************************
* Set Background - ignored by UI - * Set Background - ignored by UI -
* @param bg ignored * @param bg ignored
*/ */
public void setBackground (Color bg) public void setBackground (Color bg)
{ {
if (bg.equals(getBackground())) if (bg.equals(getBackground()))
return; return;
super.setBackground (bg); super.setBackground (bg);
// ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61) // ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
//if (!Trace.getCallerClass(1).startsWith("javax")) if (!Trace.getCallerClass(1).startsWith("javax"))
setBackgroundColor (new CompiereColor(bg)); setBackgroundColor (new CompiereColor(bg));
} // setBackground } // setBackground
/** /**
* Set Background * Set Background
* @param bg AdempiereColor for Background, if null set standard background * @param bg AdempiereColor for Background, if null set standard background
*/ */
public void setBackgroundColor (CompiereColor bg) public void setBackgroundColor (CompiereColor bg)
{ {
if (bg == null) if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground()); bg = CompierePanelUI.getDefaultBackground();
setOpaque(true); // not transparent setOpaque(true); // not transparent
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); putClientProperty(AdempierePLAF.BACKGROUND, bg);
super.setBackground (bg.getFlatColor()); super.setBackground (bg.getFlatColor());
} // setBackground } // setBackground
/** /**
* Get Background * Get Background
* @return Color for Background * @return Color for Background
*/ */
public CompiereColor getBackgroundColor () public CompiereColor getBackgroundColor ()
{ {
try try
{ {
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND); return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println("CPanel - ClientProperty: " + e.getMessage()); System.err.println("CPanel - ClientProperty: " + e.getMessage());
} }
return null; return null;
} // getBackgroundColor } // getBackgroundColor
/*************************************************************************/ /*************************************************************************/
/** /**
* Set Tab Hierarchy Level. * Set Tab Hierarchy Level.
* Has only effect, if tabs are on left or right side * Has only effect, if tabs are on left or right side
* *
* @param level * @param level
*/ */
public void setTabLevel (int level) public void setTabLevel (int level)
{ {
if (level == 0) if (level == 0)
putClientProperty(CompiereLookAndFeel.TABLEVEL, null); putClientProperty(AdempierePLAF.TABLEVEL, null);
else else
putClientProperty(CompiereLookAndFeel.TABLEVEL, new Integer(level)); putClientProperty(AdempierePLAF.TABLEVEL, new Integer(level));
} // setTabLevel } // setTabLevel
/** /**
* Get Tab Hierarchy Level * Get Tab Hierarchy Level
* @return Tab Level * @return Tab Level
*/ */
public int getTabLevel() public int getTabLevel()
{ {
try try
{ {
Integer ll = (Integer)getClientProperty(CompiereLookAndFeel.TABLEVEL); Integer ll = (Integer)getClientProperty(AdempierePLAF.TABLEVEL);
if (ll != null) if (ll != null)
return ll.intValue(); return ll.intValue();
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println("ClientProperty: " + e.getMessage()); System.err.println("ClientProperty: " + e.getMessage());
} }
return 0; return 0;
} // getTabLevel } // getTabLevel
/************************************************************************** /**************************************************************************
* String representation * String representation
* @return String representation * @return String representation
*/ */
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer ("CPanel ["); StringBuffer sb = new StringBuffer ("CPanel [");
sb.append(super.toString()); sb.append(super.toString());
CompiereColor bg = getBackgroundColor(); CompiereColor bg = getBackgroundColor();
if (bg != null) if (bg != null)
sb.append(bg.toString()); sb.append(bg.toString());
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} // toString } // toString
} // CPanel } // CPanel

View File

@ -1,214 +1,216 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.Color; import java.awt.Color;
import javax.swing.JPasswordField; import javax.swing.JPasswordField;
import javax.swing.text.Document; import javax.swing.text.Document;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
/** /**
* Password Field * Password Field
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CPassword.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CPassword.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CPassword extends JPasswordField implements CEditor public class CPassword extends JPasswordField implements CEditor
{ {
/** /**
* Constructs a new <code>JPasswordField</code>, * Constructs a new <code>JPasswordField</code>,
* with a default document, <code>null</code> starting * with a default document, <code>null</code> starting
* text string, and 0 column width. * text string, and 0 column width.
*/ */
public CPassword() public CPassword()
{ {
super(); super();
init(); init();
} }
/** /**
* Constructs a new <code>JPasswordField</code> initialized * Constructs a new <code>JPasswordField</code> initialized
* with the specified text. The document model is set to the * with the specified text. The document model is set to the
* default, and the number of columns to 0. * default, and the number of columns to 0.
* *
* @param text the text to be displayed, <code>null</code> if none * @param text the text to be displayed, <code>null</code> if none
*/ */
public CPassword (String text) public CPassword (String text)
{ {
super (text); super (text);
init(); init();
} }
/** /**
* Constructs a new empty <code>JPasswordField</code> with the specified * Constructs a new empty <code>JPasswordField</code> with the specified
* number of columns. A default model is created, and the initial string * number of columns. A default model is created, and the initial string
* is set to <code>null</code>. * is set to <code>null</code>.
* *
* @param columns the number of columns >= 0 * @param columns the number of columns >= 0
*/ */
public CPassword (int columns) public CPassword (int columns)
{ {
super (columns); super (columns);
init(); init();
} }
/** /**
* Constructs a new <code>JPasswordField</code> initialized with * Constructs a new <code>JPasswordField</code> initialized with
* the specified text and columns. The document model is set to * the specified text and columns. The document model is set to
* the default. * the default.
* *
* @param text the text to be displayed, <code>null</code> if none * @param text the text to be displayed, <code>null</code> if none
* @param columns the number of columns >= 0 * @param columns the number of columns >= 0
*/ */
public CPassword (String text, int columns) public CPassword (String text, int columns)
{ {
super (text,columns); super (text,columns);
init(); init();
} }
/** /**
* Constructs a new <code>JPasswordField</code> that uses the * Constructs a new <code>JPasswordField</code> that uses the
* given text storage model and the given number of columns. * given text storage model and the given number of columns.
* This is the constructor through which the other constructors feed. * This is the constructor through which the other constructors feed.
* The echo character is set to '*'. If the document model is * The echo character is set to '*'. If the document model is
* <code>null</code>, a default one will be created. * <code>null</code>, a default one will be created.
* *
* @param doc the text storage to use * @param doc the text storage to use
* @param txt the text to be displayed, <code>null</code> if none * @param txt the text to be displayed, <code>null</code> if none
* @param columns the number of columns to use to calculate * @param columns the number of columns to use to calculate
* the preferred width >= 0; if columns is set to zero, the * the preferred width >= 0; if columns is set to zero, the
* preferred width will be whatever naturally results from * preferred width will be whatever naturally results from
* the component implementation * the component implementation
*/ */
public CPassword (Document doc, String txt, int columns) public CPassword (Document doc, String txt, int columns)
{ {
super (doc, txt, columns); super (doc, txt, columns);
init(); init();
} }
/** /**
* Common Init * Common Init
*/ */
private void init() private void init()
{ {
} // init setFont(AdempierePLAF.getFont_Field());
setForeground(AdempierePLAF.getTextColor_Normal());
/*************************************************************************/ } // init
/** Mandatory (default false) */ /*************************************************************************/
private boolean m_mandatory = false;
/** Mandatory (default false) */
/** private boolean m_mandatory = false;
* Set Editor Mandatory
* @param mandatory true, if you have to enter data /**
*/ * Set Editor Mandatory
public void setMandatory (boolean mandatory) * @param mandatory true, if you have to enter data
{ */
m_mandatory = mandatory; public void setMandatory (boolean mandatory)
setBackground(false); {
} // setMandatory m_mandatory = mandatory;
setBackground(false);
/** } // setMandatory
* Is Field mandatory
* @return true, if mandatory /**
*/ * Is Field mandatory
public boolean isMandatory() * @return true, if mandatory
{ */
return m_mandatory; public boolean isMandatory()
} // isMandatory {
return m_mandatory;
/** } // isMandatory
* Enable Editor
* @param rw true, if you can enter/select data /**
*/ * Enable Editor
public void setReadWrite (boolean rw) * @param rw true, if you can enter/select data
{ */
if (super.isEditable() != rw) public void setReadWrite (boolean rw)
super.setEditable (rw); {
setBackground(false); if (super.isEditable() != rw)
} // setEditable super.setEditable (rw);
setBackground(false);
/** } // setEditable
* Is it possible to edit
* @return true, if editable /**
*/ * Is it possible to edit
public boolean isReadWrite() * @return true, if editable
{ */
return super.isEditable(); public boolean isReadWrite()
} // isReadWrite {
return super.isEditable();
/** } // isReadWrite
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable /**
*/ * Set Background based on editable / mandatory / error
public void setBackground (boolean error) * @param error if true, set background to error color, otherwise mandatory/editable
{ */
if (error) public void setBackground (boolean error)
setBackground(AdempierePLAF.getFieldBackground_Error()); {
else if (!isReadWrite()) if (error)
setBackground(AdempierePLAF.getFieldBackground_Inactive()); setBackground(AdempierePLAF.getFieldBackground_Error());
else if (m_mandatory) else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Mandatory()); setBackground(AdempierePLAF.getFieldBackground_Inactive());
else else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Normal()); setBackground(AdempierePLAF.getFieldBackground_Mandatory());
} // setBackground else
setBackground(AdempierePLAF.getFieldBackground_Normal());
/** } // setBackground
* Set Background
* @param bg /**
*/ * Set Background
public void setBackground (Color bg) * @param bg
{ */
if (bg.equals(getBackground())) public void setBackground (Color bg)
return; {
super.setBackground(bg); if (bg.equals(getBackground()))
} // setBackground return;
super.setBackground(bg);
/** } // setBackground
* Set Editor to value
* @param value value of the editor /**
*/ * Set Editor to value
public void setValue (Object value) * @param value value of the editor
{ */
if (value == null) public void setValue (Object value)
setText(""); {
else if (value == null)
setText(value.toString()); setText("");
} // setValue else
setText(value.toString());
/** } // setValue
* Return Editor value
* @return current value /**
*/ * Return Editor value
public Object getValue() * @return current value
{ */
return new String(super.getPassword()); public Object getValue()
} // getValue {
return new String(super.getPassword());
/** } // getValue
* Return Display Value
* @return displayed String value /**
*/ * Return Display Value
public String getDisplay() * @return displayed String value
{ */
return new String(super.getPassword()); public String getDisplay()
} // getDisplay {
return new String(super.getPassword());
} // getDisplay
}
}

View File

@ -68,6 +68,7 @@ public class CScrollPane extends JScrollPane
public CScrollPane (Component view, int vsbPolicy, int hsbPolicy) public CScrollPane (Component view, int vsbPolicy, int hsbPolicy)
{ {
super (view, vsbPolicy, hsbPolicy); super (view, vsbPolicy, hsbPolicy);
setBackgroundColor(null);
setOpaque(false); setOpaque(false);
getViewport().setOpaque(false); getViewport().setOpaque(false);
} // CScollPane } // CScollPane
@ -80,8 +81,12 @@ public class CScrollPane extends JScrollPane
public void setBackgroundColor (CompiereColor bg) public void setBackgroundColor (CompiereColor bg)
{ {
if (bg == null) if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground()); bg = CompierePanelUI.getDefaultBackground();
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); putClientProperty(AdempierePLAF.BACKGROUND, bg);
// super.setBackground(bg.getFlatColor());
// getViewport().putClientProperty(CompierePLAF.BACKGROUND, bg);
// getViewport().setBackground(bg.getFlatColor());
// getViewport().setOpaque(true);
} // setBackground } // setBackground
} // CScollPane } // CScollPane

View File

@ -1,373 +1,379 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.CompiereColor; import org.compiere.plaf.CompiereColor;
import org.compiere.plaf.CompiereLookAndFeel; import org.compiere.plaf.CompiereLookAndFeel;
import org.compiere.plaf.CompierePanelUI; import org.compiere.plaf.CompierePanelUI;
import org.compiere.util.Trace; import org.compiere.util.Trace;
import sun.swing.*; import sun.swing.*;
/** /**
* Adempiere Color Tabbed Pane * Adempiere Color Tabbed Pane
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CTabbedPane extends JTabbedPane public class CTabbedPane extends JTabbedPane
{ {
/** /**
* Creates an empty <code>TabbedPane</code> with a default * Creates an empty <code>TabbedPane</code> with a default
* tab placement of <code>JTabbedPane.TOP</code> and default * tab placement of <code>JTabbedPane.TOP</code> and default
* tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>. * tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
*/ */
public CTabbedPane() public CTabbedPane()
{ {
super(); super();
init(); init();
} // CTabbedPane } // CTabbedPane
/** /**
* Creates an empty <code>TabbedPane</code> with the specified tab placement * Creates an empty <code>TabbedPane</code> with the specified tab placement
* of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>, * of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>, and a * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>, and a
* default tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>. * default tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
* *
* @param tabPlacement the placement for the tabs relative to the content * @param tabPlacement the placement for the tabs relative to the content
*/ */
public CTabbedPane(int tabPlacement) public CTabbedPane(int tabPlacement)
{ {
super(tabPlacement); super(tabPlacement);
init(); init();
} // CTabbedPane } // CTabbedPane
/** /**
* Creates an empty <code>TabbedPane</code> with the specified tab placement * Creates an empty <code>TabbedPane</code> with the specified tab placement
* and tab layout policy. Tab placement may be either: * and tab layout policy. Tab placement may be either:
* <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>, * <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>. * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
* Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code> * Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code>
* or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>. * or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>.
* *
* @param tabPlacement the placement for the tabs relative to the content * @param tabPlacement the placement for the tabs relative to the content
* @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
* @exception IllegalArgumentException if tab placement or tab layout policy are not * @exception IllegalArgumentException if tab placement or tab layout policy are not
* one of the above supported values * one of the above supported values
*/ */
public CTabbedPane(int tabPlacement, int tabLayoutPolicy) public CTabbedPane(int tabPlacement, int tabLayoutPolicy)
{ {
super (tabPlacement, tabLayoutPolicy); super (tabPlacement, tabLayoutPolicy);
init(); init();
} // CTabbedPane } // CTabbedPane
/** /**
* Creates an empty <code>TabbedPane</code> with a defaults and Color * Creates an empty <code>TabbedPane</code> with a defaults and Color
* @param bg Color * @param bg Color
*/ */
public CTabbedPane (CompiereColor bg) public CTabbedPane (CompiereColor bg)
{ {
super(); super();
init(); init();
setBackgroundColor (bg); setBackgroundColor (bg);
} // CTabbedPane } // CTabbedPane
/** /**
* Common Init * Common Init
*/ */
private void init() private void init()
{ {
} // init setOpaque(false);
setFont(AdempierePLAF.getFont_Label());
setForeground(AdempierePLAF.getTextColor_Label());
/************************************************************************** } // init
* Set Background - ignored by UI -
* @param bg ignored
*/ /**************************************************************************
public void setBackground (Color bg) * Set Background - ignored by UI -
{ * @param bg ignored
if (bg.equals(getBackground())) */
return; public void setBackground (Color bg)
super.setBackground (bg); {
setBackgroundColor (new CompiereColor(bg)); if (bg.equals(getBackground()))
} // setBackground return;
super.setBackground (bg);
/** // ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
* Set Standard Background if (!Trace.getCallerClass(1).startsWith("javax"))
*/ setBackgroundColor (new CompiereColor(bg));
public void setBackgroundColor () } // setBackground
{
setBackgroundColor (null); /**
} // setBackground * Set Standard Background
*/
/** public void setBackgroundColor ()
* Set Background {
* @param bg AdempiereColor for Background, if null set standard background setBackgroundColor (null);
*/ } // setBackground
public void setBackgroundColor (CompiereColor bg)
{ /**
if (bg == null) * Set Background
bg = new CompiereColor(AdempierePLAF.getFormBackground()); * @param bg AdempiereColor for Background, if null set standard background
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); */
super.setBackground (bg.getFlatColor()); public void setBackgroundColor (CompiereColor bg)
// {
repaint(); if (bg == null)
} // setBackground bg = CompierePanelUI.getDefaultBackground();
setOpaque(true);
/** putClientProperty(AdempierePLAF.BACKGROUND, bg);
* Get Background super.setBackground (bg.getFlatColor());
* @return Color for Background //
*/ repaint();
public CompiereColor getBackgroundColor () } // setBackground
{
try /**
{ * Get Background
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND); * @return Color for Background
} */
catch (Exception e) public CompiereColor getBackgroundColor ()
{ {
System.err.println("ClientProperty: " + e.getMessage()); try
} {
return null; return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
} // getBackgroundColor }
catch (Exception e)
{
/************************************************************************** System.err.println("ClientProperty: " + e.getMessage());
* Insert tab. }
* If the component is a JPanel, the backround is set to the default return null;
* AdempiereColor (and Opaque) if nothing was defined. } // getBackgroundColor
* Redquired as otherwise a gray background would be pained.
* <p>
* Inserts a <code>component</code>, at <code>index</code>, /**************************************************************************
* represented by a <code>title</code> and/or <code>icon</code>, * Insert tab.
* either of which may be <code>null</code>. If <code>icon</code> * If the component is a JPanel, the backround is set to the default
* is non-<code>null</code> and it implements * AdempiereColor (and Opaque) if nothing was defined.
* <code>ImageIcon</code> a corresponding disabled icon will automatically * Redquired as otherwise a gray background would be pained.
* be created and set on the tabbedpane. * <p>
* Uses java.util.Vector internally, see <code>insertElementAt</code> * Inserts a <code>component</code>, at <code>index</code>,
* for details of insertion conventions. * represented by a <code>title</code> and/or <code>icon</code>,
* * either of which may be <code>null</code>. If <code>icon</code>
* @param text the title with Mnemonic to be displayed in this tab * is non-<code>null</code> and it implements
* @param icon the icon to be displayed in this tab * <code>ImageIcon</code> a corresponding disabled icon will automatically
* @param component The component to be displayed when this tab is clicked. * be created and set on the tabbedpane.
* @param tip the tooltip to be displayed for this tab * Uses java.util.Vector internally, see <code>insertElementAt</code>
* @param index the position to insert this new tab * for details of insertion conventions.
*/ *
public void insertTab (String text, Icon icon, Component component, String tip, int index) * @param text the title with Mnemonic to be displayed in this tab
{ * @param icon the icon to be displayed in this tab
String title = text; * @param component The component to be displayed when this tab is clicked.
if (!title.startsWith("<html>")) * @param tip the tooltip to be displayed for this tab
{ * @param index the position to insert this new tab
int pos = title.indexOf("&"); */
if (pos != -1) public void insertTab (String text, Icon icon, Component component, String tip, int index)
title = title.substring(0, pos) + title.substring(pos+1); {
} String title = text;
// Enforce Tool Tip if (!title.startsWith("<html>"))
if (tip == null || tip.length() == 0) {
tip = title; int pos = title.indexOf("&");
super.insertTab (title, icon, component, tip, index); if (pos != -1)
// Set component background title = title.substring(0, pos) + title.substring(pos+1);
if (component instanceof JPanel) }
{ // Enforce Tool Tip
JPanel p = (JPanel)component; if (tip == null || tip.length() == 0)
if (p.getClientProperty(CompiereLookAndFeel.BACKGROUND) == null) tip = title;
{ super.insertTab (title, icon, component, tip, index);
//AdempiereColor.setBackground(p); // Set component background
//p.setOpaque(true); if (component instanceof JPanel)
} {
} JPanel p = (JPanel)component;
// Set first if (p.getClientProperty(AdempierePLAF.BACKGROUND) == null)
if (index == 0) {
getActionMap().put(ACTION_SELECT, s_action); CompiereColor.setBackground(p);
// p.setOpaque(true);
if (!setMnemonicAt(index, text)) }
{ // Only one - set direct }
if (index < 9) // Set first
setMnemonicAt(index, '1'+index); if (index == 0)
else if (index == 9) getActionMap().put(ACTION_SELECT, s_action);
setMnemonicAt(index, '0'); //
} if (!setMnemonicAt(index, text))
else // additional ALT-1..0 { // Only one - set direct
{ if (index < 9)
if (index < 9) setMnemonicAt(index, '1'+index);
getInputMap(WHEN_IN_FOCUSED_WINDOW) else if (index == 9)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_1+index, Event.ALT_MASK), ACTION_SELECT); setMnemonicAt(index, '0');
else if (index == 9) }
getInputMap(WHEN_IN_FOCUSED_WINDOW) else // additional ALT-1..0
.put(KeyStroke.getKeyStroke(KeyEvent.VK_0, Event.ALT_MASK), ACTION_SELECT); {
} if (index < 9)
// getInputMap(WHEN_IN_FOCUSED_WINDOW)
} // insertTab .put(KeyStroke.getKeyStroke(KeyEvent.VK_1+index, Event.ALT_MASK), ACTION_SELECT);
else if (index == 9)
/** getInputMap(WHEN_IN_FOCUSED_WINDOW)
* Set Title At .put(KeyStroke.getKeyStroke(KeyEvent.VK_0, Event.ALT_MASK), ACTION_SELECT);
* @param index index }
* @param text title with opt Mnemonic //
*/ } // insertTab
public void setTitleAt (int index, String text)
{ /**
String title = text; * Set Title At
if (!title.startsWith("<html>")) * @param index index
{ * @param text title with opt Mnemonic
int pos = title.indexOf("&"); */
if (pos != -1) // We have a nemonic - creates ALT-_ public void setTitleAt (int index, String text)
title = title.substring(0, pos) + title.substring(pos+1); {
} String title = text;
super.setTitleAt (index, title); if (!title.startsWith("<html>"))
// setMnemonicAt(index, text); {
} // setTitleAt int pos = title.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
title = title.substring(0, pos) + title.substring(pos+1);
/** }
* Set Mnemonic for Index based on text super.setTitleAt (index, title);
* @param index for index // setMnemonicAt(index, text);
* @param text text } // setTitleAt
*/
public boolean setMnemonicAt (int index, String text)
{ /**
// logistics - remove old * Set Mnemonic for Index based on text
while (m_mnemonic.size() < index+1) * @param index for index
m_mnemonic.add((char)0); * @param text text
char keyCode = m_mnemonic.get(index); */
if (keyCode != 0) public boolean setMnemonicAt (int index, String text)
getInputMap(WHEN_IN_FOCUSED_WINDOW) {
.remove(KeyStroke.getKeyStroke(keyCode, Event.ALT_MASK)); // logistics - remove old
m_mnemonic.set(index, (char)0); while (m_mnemonic.size() < index+1)
// m_mnemonic.add((char)0);
if (!text.startsWith("<html>")) char keyCode = m_mnemonic.get(index);
{ if (keyCode != 0)
int pos = text.indexOf("&"); getInputMap(WHEN_IN_FOCUSED_WINDOW)
if (pos != -1 && text.length() > pos) // We have a nemonic - creates ALT-_ .remove(KeyStroke.getKeyStroke(keyCode, Event.ALT_MASK));
{ m_mnemonic.set(index, (char)0);
keyCode = text.toUpperCase().charAt(pos+1); //
if (keyCode != ' ') if (!text.startsWith("<html>"))
{ {
setMnemonicAt(index, keyCode); int pos = text.indexOf("&");
m_mnemonic.set(index, keyCode); if (pos != -1 && text.length() > pos) // We have a nemonic - creates ALT-_
return true; {
} keyCode = text.toUpperCase().charAt(pos+1);
} if (keyCode != ' ')
} {
/** setMnemonicAt(index, keyCode);
keyCode = text.toUpperCase().charAt(0); m_mnemonic.set(index, keyCode);
if (m_mnemonic.contains(keyCode)) return true;
{ }
keyCode = 0; }
// Beginning new word }
int pos = text.indexOf(' '); /**
while (pos != -1 && text.length() > pos) keyCode = text.toUpperCase().charAt(0);
{ if (m_mnemonic.contains(keyCode))
char c = text.toUpperCase().charAt(pos+1); {
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c)) keyCode = 0;
{ // Beginning new word
keyCode = c; int pos = text.indexOf(' ');
break; while (pos != -1 && text.length() > pos)
} {
pos = text.indexOf(' ', pos+1); char c = text.toUpperCase().charAt(pos+1);
} if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
// Any character {
if (keyCode == 0) keyCode = c;
{ break;
for (int i = 1; i < text.length(); i++) }
{ pos = text.indexOf(' ', pos+1);
char c = text.toUpperCase().charAt(i); }
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c)) // Any character
{ if (keyCode == 0)
keyCode = c; {
break; for (int i = 1; i < text.length(); i++)
} {
} char c = text.toUpperCase().charAt(i);
} if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
// First character fallback {
// if (mnemonic == 0) keyCode = c;
// mnemonic = text.toUpperCase().charAt(0); break;
} }
if (keyCode != 0) }
{ }
setMnemonicAt(index, keyCode); // First character fallback
m_mnemonic.set(index, keyCode); // if (mnemonic == 0)
} // mnemonic = text.toUpperCase().charAt(0);
**/ }
return false; if (keyCode != 0)
} // setMnemonicAt {
setMnemonicAt(index, keyCode);
/** Used Mnemonics */ m_mnemonic.set(index, keyCode);
private ArrayList<Character> m_mnemonic = new ArrayList<Character>(10); }
**/
return false;
/** } // setMnemonicAt
* String representation
* @return String representation /** Used Mnemonics */
*/ private ArrayList<Character> m_mnemonic = new ArrayList<Character>(10);
public String toString()
{
StringBuffer sb = new StringBuffer ("CTabbedPane ["); /**
sb.append(super.toString()); * String representation
CompiereColor bg = getBackgroundColor(); * @return String representation
if (bg != null) */
sb.append(bg.toString()); public String toString()
sb.append("]"); {
return sb.toString(); StringBuffer sb = new StringBuffer ("CTabbedPane [");
} // toString sb.append(super.toString());
CompiereColor bg = getBackgroundColor();
/** Select Action Text */ if (bg != null)
private static final String ACTION_SELECT = "CAS"; sb.append(bg.toString());
/** Select Action */ sb.append("]");
private static CTAction s_action = new CTAction(ACTION_SELECT); return sb.toString();
} // toString
/**
* Select Action /** Select Action Text */
* private static final String ACTION_SELECT = "CAS";
* @author Jorg Janke /** Select Action */
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ private static CTAction s_action = new CTAction(ACTION_SELECT);
*/
private static class CTAction extends UIAction /**
{ * Select Action
/** *
* Constructor * @author Jorg Janke
*/ * @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
public CTAction (String actionName) */
{ private static class CTAction extends UIAction
super (actionName); {
} // Action /**
* Constructor
public void actionPerformed (ActionEvent e) */
{ public CTAction (String actionName)
String key = getName(); {
if (!key.equals(ACTION_SELECT) super (actionName);
|| !(e.getSource() instanceof CTabbedPane)) } // Action
return;
CTabbedPane pane = (CTabbedPane)e.getSource(); public void actionPerformed (ActionEvent e)
String command = e.getActionCommand(); {
if (command == null || command.length() != 1) String key = getName();
return; if (!key.equals(ACTION_SELECT)
int index = command.charAt(0)-'1'; || !(e.getSource() instanceof CTabbedPane))
if (index > -1 && index < pane.getTabCount()) return;
pane.setSelectedIndex(index); CTabbedPane pane = (CTabbedPane)e.getSource();
else String command = e.getActionCommand();
System.out.println("Action: " + e); if (command == null || command.length() != 1)
} // actionPerformed return;
int index = command.charAt(0)-'1';
} // Action if (index > -1 && index < pane.getTabCount())
pane.setSelectedIndex(index);
} // CTabbedPane else
System.out.println("Action: " + e);
} // actionPerformed
} // Action
} // CTabbedPane

View File

@ -1,314 +1,304 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Compiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.table.*; import javax.swing.table.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
* Model Independent enhanced JTable. * Model Independent enhanced JTable.
* Provides sizing and sorting * Provides sizing and sorting
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CTable.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CTable.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CTable extends JTable public class CTable extends JTable
{ {
/** /**
* Default Constructor * Default Constructor
*/ */
public CTable() public CTable()
{ {
super(new DefaultTableModel()); super(new DefaultTableModel());
setColumnSelectionAllowed(false); setColumnSelectionAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF); setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getTableHeader().addMouseListener(new CTableMouseListener()); getTableHeader().addMouseListener(new CTableMouseListener());
setSurrendersFocusOnKeystroke(true); setSurrendersFocusOnKeystroke(true);
//Default row height too narrow
setRowHeight(getFont().getSize() + 8);
} // CTable } // CTable
/** Last model index sorted */ /** Last model index sorted */
protected int p_lastSortIndex = -1; protected int p_lastSortIndex = -1;
/** Sort direction */ /** Sort direction */
protected boolean p_asc = true; protected boolean p_asc = true;
/** Sizing: making sure it fits in a column */ /** Sizing: making sure it fits in a column */
private final int SLACK = 15; private final int SLACK = 15;
/** Sizing: max size in pt */ /** Sizing: max size in pt */
private final int MAXSIZE = 250; private final int MAXSIZE = 250;
/** Model Index of Key Column */ /** Model Index of Key Column */
protected int p_keyColumnIndex = -1; protected int p_keyColumnIndex = -1;
/** Logger */ /** Logger */
private static Logger log = Logger.getLogger(CTable.class.getName()); private static Logger log = Logger.getLogger(CTable.class.getName());
/** /**
* Set Model index of Key Column. * Set Model index of Key Column.
* Used for identifying previous selected row after fort complete to set as selected row. * Used for identifying previous selected row after fort complete to set as selected row.
* If not set, column 0 is used. * If not set, column 0 is used.
* @param keyColumnIndex model index * @param keyColumnIndex model index
*/ */
public void setKeyColumnIndex (int keyColumnIndex) public void setKeyColumnIndex (int keyColumnIndex)
{ {
p_keyColumnIndex = keyColumnIndex; p_keyColumnIndex = keyColumnIndex;
} // setKeyColumnIndex } // setKeyColumnIndex
/** /**
* Get Model index of Key Column * Get Model index of Key Column
* @return model index * @return model index
*/ */
public int getKeyColumnIndex() public int getKeyColumnIndex()
{ {
return p_keyColumnIndex; return p_keyColumnIndex;
} // getKeyColumnIndex } // getKeyColumnIndex
/** /**
* Get Current Row Key Column Value * Get Current Row Key Column Value
* @return value or null * @return value or null
*/ */
public Object getSelectedKeyColumnValue() public Object getSelectedKeyColumnValue()
{ {
int row = getSelectedRow(); int row = getSelectedRow();
if (row != -1 && p_keyColumnIndex != -1) if (row != -1 && p_keyColumnIndex != -1)
return getModel().getValueAt(row, p_keyColumnIndex); return getModel().getValueAt(row, p_keyColumnIndex);
return null; return null;
} // getKeyColumnValue } // getKeyColumnValue
/** /**
* Get Selected Value or null * Get Selected Value or null
* @return value * @return value
*/ */
public Object getSelectedValue() public Object getSelectedValue()
{ {
int row = getSelectedRow(); int row = getSelectedRow();
int col = getSelectedColumn(); int col = getSelectedColumn();
if (row == -1 || col == -1) if (row == -1 || col == -1)
return null; return null;
return getValueAt(row, col); return getValueAt(row, col);
} // getSelectedValue } // getSelectedValue
/** /**
* Stop Table Editors and remove focus * Stop Table Editors and remove focus
* @param saveValue save value * @param saveValue save value
*/ */
public void stopEditor (boolean saveValue) public void stopEditor (boolean saveValue)
{ {
// MultiRow - remove editors // MultiRow - remove editors
ChangeEvent ce = new ChangeEvent(this); ChangeEvent ce = new ChangeEvent(this);
if (saveValue) if (saveValue)
editingStopped(ce); editingStopped(ce);
else else
editingCanceled(ce); editingCanceled(ce);
// //
if (getInputContext() != null) if (getInputContext() != null)
getInputContext().endComposition(); getInputContext().endComposition();
// change focus to next // change focus to next
transferFocus(); transferFocus();
} // stopEditor } // stopEditor
/************************************************************************** /**************************************************************************
* Size Columns. * Size Columns.
* @param useColumnIdentifier if false uses plain content - * @param useColumnIdentifier if false uses plain content -
* otherwise uses Column Identifier to indicate displayed columns * otherwise uses Column Identifier to indicate displayed columns
*/ */
public void autoSize (boolean useColumnIdentifier) public void autoSize (boolean useColumnIdentifier)
{ {
TableModel model = this.getModel(); TableModel model = this.getModel();
int size = model.getColumnCount(); int size = model.getColumnCount();
// for all columns // for all columns
for (int c = 0; c < size; c++) for (int c = 0; c < size; c++)
{ {
TableColumn column = getColumnModel().getColumn(c); TableColumn column = getColumnModel().getColumn(c);
// Not displayed columns // Not displayed columns
if (useColumnIdentifier if (useColumnIdentifier
&& (column.getIdentifier() == null && (column.getIdentifier() == null
|| column.getMaxWidth() == 0 || column.getMaxWidth() == 0
|| column.getIdentifier().toString().length() == 0)) || column.getIdentifier().toString().length() == 0))
continue; continue;
int width = 0; int width = 0;
// Header // Header
TableCellRenderer renderer = column.getHeaderRenderer(); TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null) if (renderer == null)
renderer = new DefaultTableCellRenderer(); renderer = new DefaultTableCellRenderer();
Component comp = null; Component comp = null;
if (renderer != null) if (renderer != null)
comp = renderer.getTableCellRendererComponent comp = renderer.getTableCellRendererComponent
(this, column.getHeaderValue(), false, false, 0, 0); (this, column.getHeaderValue(), false, false, 0, 0);
// //
if (comp != null) if (comp != null)
{ {
width = comp.getPreferredSize().width; width = comp.getPreferredSize().width;
width = Math.max(width, comp.getWidth()); width = Math.max(width, comp.getWidth());
// Cells // Cells
int col = column.getModelIndex(); int col = column.getModelIndex();
int maxRow = Math.min(20, getRowCount()); int maxRow = Math.min(20, getRowCount());
try try
{ {
for (int row = 0; row < maxRow; row++) for (int row = 0; row < maxRow; row++)
{ {
renderer = getCellRenderer(row, col); renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent comp = renderer.getTableCellRendererComponent
(this, getValueAt(row, col), false, false, row, col); (this, getValueAt(row, col), false, false, row, col);
int rowWidth = comp.getPreferredSize().width; int rowWidth = comp.getPreferredSize().width;
width = Math.max(width, rowWidth); width = Math.max(width, rowWidth);
} }
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, column.getIdentifier().toString(), e); log.log(Level.SEVERE, column.getIdentifier().toString(), e);
} }
// Width not greater than 250 // Width not greater than 250
width = Math.min(MAXSIZE, width + SLACK); width = Math.min(MAXSIZE, width + SLACK);
} }
// //
column.setPreferredWidth(width); column.setPreferredWidth(width);
} // for all columns } // for all columns
} // autoSize } // autoSize
/** /**
* Sort Table * Sort Table
* @param modelColumnIndex model column sort index * @param modelColumnIndex model column sort index
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void sort (int modelColumnIndex) protected void sort (int modelColumnIndex)
{ {
int rows = getRowCount(); int rows = getRowCount();
if (rows == 0) if (rows == 0)
return; return;
// other column // other column
if (modelColumnIndex != p_lastSortIndex) if (modelColumnIndex != p_lastSortIndex)
p_asc = true; p_asc = true;
else else
p_asc = !p_asc; p_asc = !p_asc;
p_lastSortIndex = modelColumnIndex; p_lastSortIndex = modelColumnIndex;
// //
log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc); log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc);
// Selection // Selection
Object selected = null; Object selected = null;
int selRow = getSelectedRow(); int selRow = getSelectedRow();
int selCol = p_keyColumnIndex == -1 ? 0 : p_keyColumnIndex; // used to identify current row int selCol = p_keyColumnIndex == -1 ? 0 : p_keyColumnIndex; // used to identify current row
if (getSelectedRow() >= 0) if (getSelectedRow() >= 0)
selected = getValueAt(selRow, selCol); selected = getValueAt(selRow, selCol);
// Prepare sorting // Prepare sorting
DefaultTableModel model = (DefaultTableModel)getModel(); DefaultTableModel model = (DefaultTableModel)getModel();
MSort sort = new MSort(0, null); MSort sort = new MSort(0, null);
sort.setSortAsc(p_asc); sort.setSortAsc(p_asc);
// while something to sort // while something to sort
sorting: sorting:
while (true) while (true)
{ {
// Create sortList // Create sortList
ArrayList<MSort> sortList = new ArrayList<MSort>(rows); ArrayList<MSort> sortList = new ArrayList<MSort>(rows);
// fill with data entity // fill with data entity
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
Object value = model.getValueAt(i, modelColumnIndex); Object value = model.getValueAt(i, modelColumnIndex);
sortList.add(new MSort(i, value)); sortList.add(new MSort(i, value));
} }
// sort list it // sort list it
Collections.sort(sortList, sort); Collections.sort(sortList, sort);
// move out of sequence row // move out of sequence row
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
int index = ((MSort)sortList.get(i)).index; int index = ((MSort)sortList.get(i)).index;
if (i != index) if (i != index)
{ {
// log.config( "move " + i + " to " + index); // log.config( "move " + i + " to " + index);
model.moveRow(i,i, index); model.moveRow(i,i, index);
continue sorting; continue sorting;
} }
} }
// we are done // we are done
// log.config("done"); // log.config("done");
break; break;
} // while something to sort } // while something to sort
// selection // selection
clearSelection(); clearSelection();
if (selected != null) if (selected != null)
{ {
for (int r = 0; r < rows; r++) for (int r = 0; r < rows; r++)
{ {
if (selected.equals(getValueAt(r, selCol))) if (selected.equals(getValueAt(r, selCol)))
{ {
setRowSelectionInterval(r,r); setRowSelectionInterval(r,r);
break; break;
} }
} }
} // selected != null } // selected != null
} // sort } // sort
/** /**
* String Representation * String Representation
* @return info * @return info
*/ */
public String toString() public String toString()
{ {
return new StringBuffer("CTable[").append(getModel()).append("]").toString(); return new StringBuffer("CTable[").append(getModel()).append("]").toString();
} // toString } // toString
/************************************************************************** /**************************************************************************
* MouseListener * MouseListener
*/ */
class CTableMouseListener extends MouseAdapter class CTableMouseListener extends MouseAdapter
{ {
/** /**
* Constructor * Constructor
*/ */
public CTableMouseListener() public CTableMouseListener()
{ {
super(); super();
} // CTableMouseListener } // CTableMouseListener
/** /**
* Mouse clicked * Mouse clicked
* @param e event * @param e event
*/ */
public void mouseClicked (MouseEvent e) public void mouseClicked (MouseEvent e)
{ {
int vc = getColumnModel().getColumnIndexAtX(e.getX()); int vc = getColumnModel().getColumnIndexAtX(e.getX());
// log.info( "Sort " + vc + "=" + getColumnModel().getColumn(vc).getHeaderValue()); // log.info( "Sort " + vc + "=" + getColumnModel().getColumn(vc).getHeaderValue());
int mc = convertColumnIndexToModel(vc); int mc = convertColumnIndexToModel(vc);
sort(mc); sort(mc);
} }
} // CTableMouseListener } // CTableMouseListener
@Override
public void setFont(Font font) {
super.setFont(font);
//Update row height
setRowHeight(getFont().getSize() + 8);
}
} // CTable } // CTable

View File

@ -1,462 +1,464 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.im.*; import java.awt.im.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
/** /**
* Adempiere TextArea - A ScrollPane with a JTextArea. * Adempiere TextArea - A ScrollPane with a JTextArea.
* Manages visibility, opaque and color consistently * Manages visibility, opaque and color consistently
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CTextArea.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CTextArea.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CTextArea extends JScrollPane public class CTextArea extends JScrollPane
implements CEditor implements CEditor
{ {
/** /**
* Constructs a new TextArea. A default model is set, the initial string * Constructs a new TextArea. A default model is set, the initial string
* is null, and rows/columns are set to 0. * is null, and rows/columns are set to 0.
*/ */
public CTextArea() public CTextArea()
{ {
this (new JTextArea()); this (new JTextArea());
} // CText } // CText
/** /**
* Constructs a new TextArea with the specified text displayed. * Constructs a new TextArea with the specified text displayed.
* A default model is created and rows/columns are set to 0. * A default model is created and rows/columns are set to 0.
* *
* @param text the text to be displayed, or null * @param text the text to be displayed, or null
*/ */
public CTextArea (String text) public CTextArea (String text)
{ {
this (new JTextArea (text)); this (new JTextArea (text));
} // CText } // CText
/** /**
* Constructs a new empty TextArea with the specified number of * Constructs a new empty TextArea with the specified number of
* rows and columns. A default model is created, and the initial * rows and columns. A default model is created, and the initial
* string is null. * string is null.
* *
* @param rows the number of rows >= 0 * @param rows the number of rows >= 0
* @param columns the number of columns >= 0 * @param columns the number of columns >= 0
* @exception IllegalArgumentException if the rows or columns * @exception IllegalArgumentException if the rows or columns
* arguments are negative. * arguments are negative.
*/ */
public CTextArea (int rows, int columns) public CTextArea (int rows, int columns)
{ {
this (new JTextArea (rows, columns)); this (new JTextArea (rows, columns));
} // CText } // CText
/** /**
* Constructs a new TextArea with the specified text and number * Constructs a new TextArea with the specified text and number
* of rows and columns. A default model is created. * of rows and columns. A default model is created.
* *
* @param text the text to be displayed, or null * @param text the text to be displayed, or null
* @param rows the number of rows >= 0 * @param rows the number of rows >= 0
* @param columns the number of columns >= 0 * @param columns the number of columns >= 0
* @exception IllegalArgumentException if the rows or columns * @exception IllegalArgumentException if the rows or columns
* arguments are negative. * arguments are negative.
*/ */
public CTextArea (String text, int rows, int columns) public CTextArea (String text, int rows, int columns)
{ {
this (new JTextArea(text, rows, columns)); this (new JTextArea(text, rows, columns));
} // CText } // CText
/** /**
* Constructs a new JTextArea with the given document model, and defaults * Constructs a new JTextArea with the given document model, and defaults
* for all of the other arguments (null, 0, 0). * for all of the other arguments (null, 0, 0).
* *
* @param doc the model to use * @param doc the model to use
*/ */
public CTextArea (Document doc) public CTextArea (Document doc)
{ {
this (new JTextArea (doc)); this (new JTextArea (doc));
} // CText } // CText
/** /**
* Constructs a new JTextArea with the specified number of rows * Constructs a new JTextArea with the specified number of rows
* and columns, and the given model. All of the constructors * and columns, and the given model. All of the constructors
* feed through this constructor. * feed through this constructor.
* *
* @param doc the model to use, or create a default one if null * @param doc the model to use, or create a default one if null
* @param text the text to be displayed, null if none * @param text the text to be displayed, null if none
* @param rows the number of rows >= 0 * @param rows the number of rows >= 0
* @param columns the number of columns >= 0 * @param columns the number of columns >= 0
* @exception IllegalArgumentException if the rows or columns * @exception IllegalArgumentException if the rows or columns
* arguments are negative. * arguments are negative.
*/ */
public CTextArea (Document doc, String text, int rows, int columns) public CTextArea (Document doc, String text, int rows, int columns)
{ {
this (new JTextArea (doc, text, rows, columns)); this (new JTextArea (doc, text, rows, columns));
} // CTextArea } // CTextArea
/** /**
* Create a JScrollArea with a JTextArea. * Create a JScrollArea with a JTextArea.
* (use Cpmpiere Colors, Line wrap) * (use Cpmpiere Colors, Line wrap)
* @param textArea * @param textArea
*/ */
public CTextArea (JTextArea textArea) public CTextArea (JTextArea textArea)
{ {
super (textArea); super (textArea);
m_textArea = textArea; m_textArea = textArea;
super.setOpaque(false); super.setOpaque(false);
super.getViewport().setOpaque(false); super.getViewport().setOpaque(false);
m_textArea.setLineWrap(true); m_textArea.setFont(AdempierePLAF.getFont_Field());
m_textArea.setWrapStyleWord(true); m_textArea.setForeground(AdempierePLAF.getTextColor_Normal());
// Overwrite default Tab m_textArea.setLineWrap(true);
m_textArea.firePropertyChange("editable", !isEditable(), isEditable()); m_textArea.setWrapStyleWord(true);
} // CTextArea // Overwrite default Tab
m_textArea.firePropertyChange("editable", !isEditable(), isEditable());
/** Text Area */ } // CTextArea
private JTextArea m_textArea = null;
/** Text Area */
/*************************************************************************/ private JTextArea m_textArea = null;
/** Mandatory (default false) */ /*************************************************************************/
private boolean m_mandatory = false;
/** Mandatory (default false) */
/** private boolean m_mandatory = false;
* Set Editor Mandatory
* @param mandatory true, if you have to enter data /**
*/ * Set Editor Mandatory
public void setMandatory (boolean mandatory) * @param mandatory true, if you have to enter data
{ */
m_mandatory = mandatory; public void setMandatory (boolean mandatory)
setBackground(false); {
} // setMandatory m_mandatory = mandatory;
setBackground(false);
/** } // setMandatory
* Is Field mandatory
* @return true, if mandatory /**
*/ * Is Field mandatory
public boolean isMandatory() * @return true, if mandatory
{ */
return m_mandatory; public boolean isMandatory()
} // isMandatory {
return m_mandatory;
/** } // isMandatory
* Enable Editor
* @param rw true, if you can enter/select data /**
*/ * Enable Editor
public void setReadWrite (boolean rw) * @param rw true, if you can enter/select data
{ */
if (m_textArea.isEditable() != rw) public void setReadWrite (boolean rw)
m_textArea.setEditable (rw); {
setBackground(false); if (m_textArea.isEditable() != rw)
} // setReadWrite m_textArea.setEditable (rw);
setBackground(false);
/** } // setReadWrite
* Is it possible to edit
* @return true, if editable /**
*/ * Is it possible to edit
public boolean isReadWrite() * @return true, if editable
{ */
return m_textArea.isEditable(); public boolean isReadWrite()
} // isReadWrite {
return m_textArea.isEditable();
/** } // isReadWrite
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable /**
*/ * Set Background based on editable / mandatory / error
public void setBackground (boolean error) * @param error if true, set background to error color, otherwise mandatory/editable
{ */
if (error) public void setBackground (boolean error)
setBackground(AdempierePLAF.getFieldBackground_Error()); {
else if (!isReadWrite()) if (error)
setBackground(AdempierePLAF.getFieldBackground_Inactive()); setBackground(AdempierePLAF.getFieldBackground_Error());
else if (m_mandatory) else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Mandatory()); setBackground(AdempierePLAF.getFieldBackground_Inactive());
else else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Normal()); setBackground(AdempierePLAF.getFieldBackground_Mandatory());
} // setBackground else
setBackground(AdempierePLAF.getFieldBackground_Normal());
/** } // setBackground
* Set Background color
* @param color color /**
*/ * Set Background color
public void setBackground (Color color) * @param color color
{ */
if (color.equals(getBackground())) public void setBackground (Color color)
return; {
if (m_textArea == null) // during init if (color.equals(getBackground()))
super.setBackground(color); return;
else if (m_textArea == null) // during init
m_textArea.setBackground(color); super.setBackground(color);
} else
/** m_textArea.setBackground(color);
* Get Background color }
* @return background /**
*/ * Get Background color
public Color getBackground () * @return background
{ */
if (m_textArea == null) // during init public Color getBackground ()
return super.getBackground(); {
else if (m_textArea == null) // during init
return m_textArea.getBackground(); return super.getBackground();
} else
/** return m_textArea.getBackground();
* Set Foreground color }
* @param color /**
*/ * Set Foreground color
public void setForeground (Color color) * @param color
{ */
if (m_textArea == null) // during init public void setForeground (Color color)
super.setForeground(color); {
else if (m_textArea == null) // during init
m_textArea.setForeground(color); super.setForeground(color);
} else
/** m_textArea.setForeground(color);
* Get Foreground color }
* @return color /**
*/ * Get Foreground color
public Color getForeground () * @return color
{ */
if (m_textArea == null) // during init public Color getForeground ()
return super.getForeground(); {
else if (m_textArea == null) // during init
return m_textArea.getForeground(); return super.getForeground();
} else
return m_textArea.getForeground();
/** }
* Set Editor to value
* @param value value of the editor /**
*/ * Set Editor to value
public void setValue (Object value) * @param value value of the editor
{ */
if (value == null) public void setValue (Object value)
m_textArea.setText(""); {
else if (value == null)
m_textArea.setText(value.toString()); m_textArea.setText("");
} // setValue else
m_textArea.setText(value.toString());
/** } // setValue
* Return Editor value
* @return current value /**
*/ * Return Editor value
public Object getValue() * @return current value
{ */
return m_textArea.getText(); public Object getValue()
} // getValue {
return m_textArea.getText();
/** } // getValue
* Return Display Value
* @return displayed String value /**
*/ * Return Display Value
public String getDisplay() * @return displayed String value
{ */
return m_textArea.getText(); public String getDisplay()
} // getDisplay {
return m_textArea.getText();
/************************************************************************* } // getDisplay
* Set Text and position top
* @param text /*************************************************************************
*/ * Set Text and position top
public void setText (String text) * @param text
{ */
m_textArea.setText(text); public void setText (String text)
m_textArea.setCaretPosition(0); {
} m_textArea.setText(text);
/** m_textArea.setCaretPosition(0);
* Get Text }
* @return text /**
*/ * Get Text
public String getText() * @return text
{ */
return m_textArea.getText(); public String getText()
} {
/** return m_textArea.getText();
* Append text }
* @param text /**
*/ * Append text
public void append (String text) * @param text
{ */
m_textArea.append (text); public void append (String text)
} {
m_textArea.append (text);
/** }
* Set Columns
* @param cols /**
*/ * Set Columns
public void setColumns (int cols) * @param cols
{ */
m_textArea.setColumns (cols); public void setColumns (int cols)
} {
/** m_textArea.setColumns (cols);
* Get Columns }
* @return columns /**
*/ * Get Columns
public int getColumns() * @return columns
{ */
return m_textArea.getColumns(); public int getColumns()
} {
return m_textArea.getColumns();
/** }
* Set Rows
* @param rows /**
*/ * Set Rows
public void setRows (int rows) * @param rows
{ */
m_textArea.setRows(rows); public void setRows (int rows)
} {
/** m_textArea.setRows(rows);
* Get Rows }
* @return rows /**
*/ * Get Rows
public int getRows() * @return rows
{ */
return m_textArea.getRows(); public int getRows()
} {
return m_textArea.getRows();
/** }
* Set Text Caret Position
* @param pos /**
*/ * Set Text Caret Position
public void setCaretPosition (int pos) * @param pos
{ */
m_textArea.setCaretPosition (pos); public void setCaretPosition (int pos)
} {
/** m_textArea.setCaretPosition (pos);
* Get Text Caret Position }
* @return position /**
*/ * Get Text Caret Position
public int getCaretPosition() * @return position
{ */
return m_textArea.getCaretPosition(); public int getCaretPosition()
} {
return m_textArea.getCaretPosition();
/** }
* Set Text Editable
* @param edit /**
*/ * Set Text Editable
public void setEditable (boolean edit) * @param edit
{ */
m_textArea.setEditable(edit); public void setEditable (boolean edit)
} {
/** m_textArea.setEditable(edit);
* Is Text Editable }
* @return true if editable /**
*/ * Is Text Editable
public boolean isEditable() * @return true if editable
{ */
return m_textArea.isEditable(); public boolean isEditable()
} {
return m_textArea.isEditable();
/** }
* Set Text Line Wrap
* @param wrap /**
*/ * Set Text Line Wrap
public void setLineWrap (boolean wrap) * @param wrap
{ */
m_textArea.setLineWrap (wrap); public void setLineWrap (boolean wrap)
} {
/** m_textArea.setLineWrap (wrap);
* Set Text Wrap Style Word }
* @param word /**
*/ * Set Text Wrap Style Word
public void setWrapStyleWord (boolean word) * @param word
{ */
m_textArea.setWrapStyleWord (word); public void setWrapStyleWord (boolean word)
} {
m_textArea.setWrapStyleWord (word);
/** }
* Set Opaque
* @param isOpaque /**
*/ * Set Opaque
public void setOpaque (boolean isOpaque) * @param isOpaque
{ */
// JScrollPane & Viewport is always not Opaque public void setOpaque (boolean isOpaque)
if (m_textArea == null) // during init of JScrollPane {
super.setOpaque(isOpaque); // JScrollPane & Viewport is always not Opaque
else if (m_textArea == null) // during init of JScrollPane
m_textArea.setOpaque(isOpaque); super.setOpaque(isOpaque);
} // setOpaque else
m_textArea.setOpaque(isOpaque);
/** } // setOpaque
* Set Text Margin
* @param m insets /**
*/ * Set Text Margin
public void setMargin (Insets m) * @param m insets
{ */
if (m_textArea != null) public void setMargin (Insets m)
m_textArea.setMargin(m); {
} // setMargin if (m_textArea != null)
m_textArea.setMargin(m);
} // setMargin
/**
* AddFocusListener
* @param l /**
*/ * AddFocusListener
public void addFocusListener (FocusListener l) * @param l
{ */
if (m_textArea == null) // during init public void addFocusListener (FocusListener l)
super.addFocusListener(l); {
else if (m_textArea == null) // during init
m_textArea.addFocusListener(l); super.addFocusListener(l);
} else
/** m_textArea.addFocusListener(l);
* Add Text Mouse Listener }
* @param l /**
*/ * Add Text Mouse Listener
public void addMouseListener (MouseListener l) * @param l
{ */
m_textArea.addMouseListener(l); public void addMouseListener (MouseListener l)
} {
/** m_textArea.addMouseListener(l);
* Add Text Key Listener }
* @param l /**
*/ * Add Text Key Listener
public void addKeyListener (KeyListener l) * @param l
{ */
m_textArea.addKeyListener(l); public void addKeyListener (KeyListener l)
} {
/** m_textArea.addKeyListener(l);
* Add Text Input Method Listener }
* @param l /**
*/ * Add Text Input Method Listener
public void addInputMethodListener (InputMethodListener l) * @param l
{ */
m_textArea.addInputMethodListener(l); public void addInputMethodListener (InputMethodListener l)
} {
/** m_textArea.addInputMethodListener(l);
* Get text Input Method Requests }
* @return requests /**
*/ * Get text Input Method Requests
public InputMethodRequests getInputMethodRequests() * @return requests
{ */
return m_textArea.getInputMethodRequests(); public InputMethodRequests getInputMethodRequests()
} {
/** return m_textArea.getInputMethodRequests();
* Set Text Input Verifier }
* @param l /**
*/ * Set Text Input Verifier
public void setInputVerifier (InputVerifier l) * @param l
{ */
m_textArea.setInputVerifier(l); public void setInputVerifier (InputVerifier l)
} {
m_textArea.setInputVerifier(l);
} // CTextArea }
} // CTextArea

View File

@ -1,254 +1,262 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
/** /**
* Adempiere Text Field * Adempiere Text Field
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CTextField.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CTextField.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CTextField extends JTextField public class CTextField extends JTextField
implements CEditor, KeyListener implements CEditor, KeyListener
{ {
/** /**
* Constructs a new <code>TextField</code>. A default model is created, * Constructs a new <code>TextField</code>. A default model is created,
* the initial string is <code>null</code>, * the initial string is <code>null</code>,
* and the number of columns is set to 0. * and the number of columns is set to 0.
*/ */
public CTextField() public CTextField()
{ {
super(); super();
init(); init();
} // CTextField } // CTextField
/** /**
* Constructs a new <code>TextField</code> initialized with the * Constructs a new <code>TextField</code> initialized with the
* specified text. A default model is created and the number of * specified text. A default model is created and the number of
* columns is 0. * columns is 0.
* *
* @param text the text to be displayed, or <code>null</code> * @param text the text to be displayed, or <code>null</code>
*/ */
public CTextField (String text) public CTextField (String text)
{ {
super (text); super (text);
init(); init();
} // CTextField } // CTextField
/** /**
* Constructs a new empty <code>TextField</code> with the specified * Constructs a new empty <code>TextField</code> with the specified
* number of columns. * number of columns.
* A default model is created and the initial string is set to * A default model is created and the initial string is set to
* <code>null</code>. * <code>null</code>.
* *
* @param columns the number of columns to use to calculate * @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the * the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from * preferred width will be whatever naturally results from
* the component implementation * the component implementation
*/ */
public CTextField (int columns) public CTextField (int columns)
{ {
super (columns); super (columns);
init(); init();
} // CTextField } // CTextField
/** /**
* Constructs a new <code>TextField</code> initialized with the * Constructs a new <code>TextField</code> initialized with the
* specified text and columns. A default model is created. * specified text and columns. A default model is created.
* *
* @param text the text to be displayed, or <code>null</code> * @param text the text to be displayed, or <code>null</code>
* @param columns the number of columns to use to calculate * @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the * the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from * preferred width will be whatever naturally results from
* the component implementation * the component implementation
*/ */
public CTextField (String text, int columns) public CTextField (String text, int columns)
{ {
super (text, columns); super (text, columns);
init(); init();
} // CTextField } // CTextField
/** /**
* Constructs a new <code>JTextField</code> that uses the given text * Constructs a new <code>JTextField</code> that uses the given text
* storage model and the given number of columns. * storage model and the given number of columns.
* This is the constructor through which the other constructors feed. * This is the constructor through which the other constructors feed.
* If the document is <code>null</code>, a default model is created. * If the document is <code>null</code>, a default model is created.
* *
* @param doc the text storage to use; if this is <code>null</code>, * @param doc the text storage to use; if this is <code>null</code>,
* a default will be provided by calling the * a default will be provided by calling the
* <code>createDefaultModel</code> method * <code>createDefaultModel</code> method
* @param text the initial string to display, or <code>null</code> * @param text the initial string to display, or <code>null</code>
* @param columns the number of columns to use to calculate * @param columns the number of columns to use to calculate
* the preferred width >= 0; if <code>columns</code> * the preferred width >= 0; if <code>columns</code>
* is set to zero, the preferred width will be whatever * is set to zero, the preferred width will be whatever
* naturally results from the component implementation * naturally results from the component implementation
* @exception IllegalArgumentException if <code>columns</code> < 0 * @exception IllegalArgumentException if <code>columns</code> < 0
*/ */
public CTextField (Document doc, String text, int columns) public CTextField (Document doc, String text, int columns)
{ {
super (doc, text, columns); super (doc, text, columns);
init(); init();
} // CTextField } // CTextField
/** /**
* Initialization * Initialization
*/ */
private void init() private void init()
{ {
setBackground (false); setFont(AdempierePLAF.getFont_Field());
} // init setForeground(AdempierePLAF.getTextColor_Normal());
setBackground (false);
/*************************************************************************/ // Minimum Size
Dimension size = getPreferredSize();
/** Mandatory (default false) */ if (size != null)
private boolean m_mandatory = false; size = new Dimension (20,10);
size.width = 30;
/** setMinimumSize(size);
* Set Editor Mandatory } // init
* @param mandatory true, if you have to enter data
*/ /*************************************************************************/
public void setMandatory (boolean mandatory)
{ /** Mandatory (default false) */
m_mandatory = mandatory; private boolean m_mandatory = false;
setBackground(false);
} // setMandatory /**
* Set Editor Mandatory
/** * @param mandatory true, if you have to enter data
* Is Field mandatory */
* @return true, if mandatory public void setMandatory (boolean mandatory)
*/ {
public boolean isMandatory() m_mandatory = mandatory;
{ setBackground(false);
return m_mandatory; } // setMandatory
} // isMandatory
/**
/** * Is Field mandatory
* Enable Editor * @return true, if mandatory
* @param rw true, if you can enter/select data */
*/ public boolean isMandatory()
public void setReadWrite (boolean rw) {
{ return m_mandatory;
if (super.isEditable() != rw) } // isMandatory
super.setEditable (rw);
setBackground(false); /**
} // setEditable * Enable Editor
* @param rw true, if you can enter/select data
/** */
* Is it possible to edit public void setReadWrite (boolean rw)
* @return true, if editable {
*/ if (super.isEditable() != rw)
public boolean isReadWrite() super.setEditable (rw);
{ setBackground(false);
return super.isEditable(); } // setEditable
} // isReadWrite
/**
* Is it possible to edit
/** * @return true, if editable
* Set Background based on editable / mandatory / error */
* @param error if true, set background to error color, otherwise mandatory/editable public boolean isReadWrite()
*/ {
public void setBackground (boolean error) return super.isEditable();
{ } // isReadWrite
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite()) /**
setBackground(AdempierePLAF.getFieldBackground_Inactive()); * Set Background based on editable / mandatory / error
else if (m_mandatory) * @param error if true, set background to error color, otherwise mandatory/editable
setBackground(AdempierePLAF.getFieldBackground_Mandatory()); */
else public void setBackground (boolean error)
setBackground(AdempierePLAF.getFieldBackground_Normal()); {
} // setBackground if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
/** else if (!isReadWrite())
* Set Background setBackground(AdempierePLAF.getFieldBackground_Inactive());
* @param bg background else if (m_mandatory)
*/ setBackground(AdempierePLAF.getFieldBackground_Mandatory());
public void setBackground (Color bg) else
{ setBackground(AdempierePLAF.getFieldBackground_Normal());
if (bg.equals(getBackground())) } // setBackground
return;
super.setBackground(bg); /**
} // setBackground * Set Background
* @param bg background
/** */
* Set Editor to value public void setBackground (Color bg)
* @param value value of the editor {
*/ if (bg.equals(getBackground()))
public void setValue (Object value) return;
{ super.setBackground(bg);
if (value == null) } // setBackground
setText("");
else /**
setText(value.toString()); * Set Editor to value
} // setValue * @param value value of the editor
*/
/** public void setValue (Object value)
* Return Editor value {
* @return current value if (value == null)
*/ setText("");
public Object getValue() else
{ setText(value.toString());
return getText(); } // setValue
} // getValue
/**
/** * Return Editor value
* Return Display Value * @return current value
* @return displayed String value */
*/ public Object getValue()
public String getDisplay() {
{ return getText();
return getText(); } // getValue
} // getDisplay
/**
* Return Display Value
/** * @return displayed String value
* key Pressed */
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) public String getDisplay()
* @param e {
*/ return getText();
public void keyPressed(KeyEvent e) } // getDisplay
{
} // keyPressed
/**
/** * key Pressed
* key Released * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) * @param e
* @param e */
*/ public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e) {
{ } // keyPressed
} // keyReleased
/**
/** * key Released
* key Typed * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) * @param e
* @param e */
*/ public void keyReleased(KeyEvent e)
public void keyTyped(KeyEvent e) {
{ } // keyReleased
} // keyTyped
/**
} // CTextField * key Typed
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
* @param e
*/
public void keyTyped(KeyEvent e)
{
} // keyTyped
} // CTextField

View File

@ -1,350 +1,352 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.im.*; import java.awt.im.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.*;
/** /**
* Adempiere TextPane - A ScrollPane with a JTextPane. * Adempiere TextPane - A ScrollPane with a JTextPane.
* Manages visibility, opaque and color consistently * * Manages visibility, opaque and color consistently *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CTextPane.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CTextPane.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CTextPane extends JScrollPane public class CTextPane extends JScrollPane
implements CEditor implements CEditor
{ {
/** /**
* Constructs a new TextPane (HTML) * Constructs a new TextPane (HTML)
*/ */
public CTextPane() public CTextPane()
{ {
this (new JTextPane()); this (new JTextPane());
} // CTextPane } // CTextPane
/** /**
* Constructs a new JTextPane with the given document * Constructs a new JTextPane with the given document
* @param doc the model to use * @param doc the model to use
*/ */
public CTextPane (StyledDocument doc) public CTextPane (StyledDocument doc)
{ {
this (new JTextPane (doc)); this (new JTextPane (doc));
} // CTextPane } // CTextPane
/** /**
* Create a JScrollArea with a JTextEditor * Create a JScrollArea with a JTextEditor
* @param textPane * @param textPane
*/ */
public CTextPane (JTextPane textPane) public CTextPane (JTextPane textPane)
{ {
super (textPane); super (textPane);
m_textPane = textPane; m_textPane = textPane;
super.setOpaque(false); super.setOpaque(false);
super.getViewport().setOpaque(false); super.getViewport().setOpaque(false);
m_textPane.setContentType("text/html"); m_textPane.setContentType("text/html");
} // CTextPane m_textPane.setFont(AdempierePLAF.getFont_Field());
m_textPane.setForeground(AdempierePLAF.getTextColor_Normal());
private JTextPane m_textPane = null; } // CTextPane
/*************************************************************************/ private JTextPane m_textPane = null;
/** Mandatory (default false) */ /*************************************************************************/
private boolean m_mandatory = false;
/** Mandatory (default false) */
/** private boolean m_mandatory = false;
* Set Editor Mandatory
* @param mandatory true, if you have to enter data /**
*/ * Set Editor Mandatory
public void setMandatory (boolean mandatory) * @param mandatory true, if you have to enter data
{ */
m_mandatory = mandatory; public void setMandatory (boolean mandatory)
setBackground(false); {
} // setMandatory m_mandatory = mandatory;
setBackground(false);
/** } // setMandatory
* Is Field mandatory
* @return true, if mandatory /**
*/ * Is Field mandatory
public boolean isMandatory() * @return true, if mandatory
{ */
return m_mandatory; public boolean isMandatory()
} // isMandatory {
return m_mandatory;
/** } // isMandatory
* Enable Editor
* @param rw true, if you can enter/select data /**
*/ * Enable Editor
public void setReadWrite (boolean rw) * @param rw true, if you can enter/select data
{ */
if (m_textPane.isEditable() != rw) public void setReadWrite (boolean rw)
m_textPane.setEditable (rw); {
setBackground(false); if (m_textPane.isEditable() != rw)
} // setReadWrite m_textPane.setEditable (rw);
setBackground(false);
/** } // setReadWrite
* Is it possible to edit
* @return true, if editable /**
*/ * Is it possible to edit
public boolean isReadWrite() * @return true, if editable
{ */
return m_textPane.isEditable(); public boolean isReadWrite()
} // isReadWrite {
return m_textPane.isEditable();
/** } // isReadWrite
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable /**
*/ * Set Background based on editable / mandatory / error
public void setBackground (boolean error) * @param error if true, set background to error color, otherwise mandatory/editable
{ */
if (error) public void setBackground (boolean error)
setBackground(AdempierePLAF.getFieldBackground_Error()); {
else if (!isReadWrite()) if (error)
setBackground(AdempierePLAF.getFieldBackground_Inactive()); setBackground(AdempierePLAF.getFieldBackground_Error());
else if (m_mandatory) else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Mandatory()); setBackground(AdempierePLAF.getFieldBackground_Inactive());
else else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Normal()); setBackground(AdempierePLAF.getFieldBackground_Mandatory());
} // setBackground else
setBackground(AdempierePLAF.getFieldBackground_Normal());
/** } // setBackground
* Set Background
* @param color color /**
*/ * Set Background
public void setBackground (Color color) * @param color color
{ */
if (color.equals(getBackground())) public void setBackground (Color color)
return; {
if (m_textPane == null) // during init if (color.equals(getBackground()))
super.setBackground(color); return;
else if (m_textPane == null) // during init
m_textPane.setBackground(color); super.setBackground(color);
} // setBackground else
m_textPane.setBackground(color);
/** } // setBackground
* Get Background
* @return color /**
*/ * Get Background
public Color getBackground () * @return color
{ */
if (m_textPane == null) // during init public Color getBackground ()
return super.getBackground(); {
else if (m_textPane == null) // during init
return m_textPane.getBackground(); return super.getBackground();
} // getBackground else
return m_textPane.getBackground();
/** } // getBackground
* Set Foreground
* @param color color /**
*/ * Set Foreground
public void setForeground (Color color) * @param color color
{ */
if (m_textPane == null) // during init public void setForeground (Color color)
super.setForeground(color); {
else if (m_textPane == null) // during init
m_textPane.setForeground(color); super.setForeground(color);
} // setForeground else
m_textPane.setForeground(color);
/** } // setForeground
* Get Foreground
* @return color /**
*/ * Get Foreground
public Color getForeground () * @return color
{ */
if (m_textPane == null) // during init public Color getForeground ()
return super.getForeground(); {
else if (m_textPane == null) // during init
return m_textPane.getForeground(); return super.getForeground();
} // getForeground else
return m_textPane.getForeground();
/** } // getForeground
* Set Content Type
* @param type e.g. text/html /**
*/ * Set Content Type
public void setContentType (String type) * @param type e.g. text/html
{ */
if (m_textPane != null) // during init public void setContentType (String type)
m_textPane.setContentType(type); {
} // setContentType if (m_textPane != null) // during init
m_textPane.setContentType(type);
} // setContentType
/**
* Set Editor to value
* @param value value of the editor /**
*/ * Set Editor to value
public void setValue (Object value) * @param value value of the editor
{ */
if (value == null) public void setValue (Object value)
m_textPane.setText(""); {
else if (value == null)
m_textPane.setText(value.toString()); m_textPane.setText("");
} // setValue else
m_textPane.setText(value.toString());
/** } // setValue
* Return Editor value
* @return current value /**
*/ * Return Editor value
public Object getValue() * @return current value
{ */
return m_textPane.getText(); public Object getValue()
} // getValue {
return m_textPane.getText();
/** } // getValue
* Return Display Value
* @return displayed String value /**
*/ * Return Display Value
public String getDisplay() * @return displayed String value
{ */
return m_textPane.getText(); public String getDisplay()
} // getDisplay {
return m_textPane.getText();
} // getDisplay
/**************************************************************************
* Set Text and position top
* @param text /**************************************************************************
*/ * Set Text and position top
public void setText (String text) * @param text
{ */
m_textPane.setText(text); public void setText (String text)
m_textPane.setCaretPosition(0); {
} m_textPane.setText(text);
/** m_textPane.setCaretPosition(0);
* Get Text }
* @return text /**
*/ * Get Text
public String getText() * @return text
{ */
return m_textPane.getText(); public String getText()
} {
return m_textPane.getText();
/** }
* Set Caret Position
* @param pos pos /**
*/ * Set Caret Position
public void setCaretPosition (int pos) * @param pos pos
{ */
m_textPane.setCaretPosition (pos); public void setCaretPosition (int pos)
} {
/** m_textPane.setCaretPosition (pos);
* Get Caret Position }
* @return position /**
*/ * Get Caret Position
public int getCaretPosition() * @return position
{ */
return m_textPane.getCaretPosition(); public int getCaretPosition()
} {
return m_textPane.getCaretPosition();
/** }
* Set Editable
* @param edit editable /**
*/ * Set Editable
public void setEditable (boolean edit) * @param edit editable
{ */
m_textPane.setEditable(edit); public void setEditable (boolean edit)
} {
/** m_textPane.setEditable(edit);
* Editable }
* @return true if editable /**
*/ * Editable
public boolean isEditable() * @return true if editable
{ */
return m_textPane.isEditable(); public boolean isEditable()
} {
return m_textPane.isEditable();
/** }
* Set Text Margin
* @param m insets /**
*/ * Set Text Margin
public void setMargin (Insets m) * @param m insets
{ */
if (m_textPane != null) public void setMargin (Insets m)
m_textPane.setMargin(m); {
} // setMargin if (m_textPane != null)
m_textPane.setMargin(m);
/** } // setMargin
* Set Opaque
* @param isOpaque opaque /**
*/ * Set Opaque
public void setOpaque (boolean isOpaque) * @param isOpaque opaque
{ */
// JScrollPane & Viewport is always not Opaque public void setOpaque (boolean isOpaque)
if (m_textPane == null) // during init of JScrollPane {
super.setOpaque(isOpaque); // JScrollPane & Viewport is always not Opaque
else if (m_textPane == null) // during init of JScrollPane
m_textPane.setOpaque(isOpaque); super.setOpaque(isOpaque);
} // setOpaque else
m_textPane.setOpaque(isOpaque);
/** } // setOpaque
* Add Focus Listener
* @param l listener /**
*/ * Add Focus Listener
public void addFocusListener (FocusListener l) * @param l listener
{ */
if (m_textPane == null) // during init public void addFocusListener (FocusListener l)
super.addFocusListener(l); {
else if (m_textPane == null) // during init
m_textPane.addFocusListener(l); super.addFocusListener(l);
} else
/** m_textPane.addFocusListener(l);
* Add Mouse Listener }
* @param l listner /**
*/ * Add Mouse Listener
public void addMouseListener (MouseListener l) * @param l listner
{ */
m_textPane.addMouseListener(l); public void addMouseListener (MouseListener l)
} {
/** m_textPane.addMouseListener(l);
* Add Key Listener }
* @param l listner /**
*/ * Add Key Listener
public void addKeyListener (KeyListener l) * @param l listner
{ */
m_textPane.addKeyListener(l); public void addKeyListener (KeyListener l)
} {
/** m_textPane.addKeyListener(l);
* Add Input Method Listener }
* @param l listener /**
*/ * Add Input Method Listener
public void addInputMethodListener (InputMethodListener l) * @param l listener
{ */
m_textPane.addInputMethodListener(l); public void addInputMethodListener (InputMethodListener l)
} {
/** m_textPane.addInputMethodListener(l);
* Get Input Method Requests }
* @return requests /**
*/ * Get Input Method Requests
public InputMethodRequests getInputMethodRequests() * @return requests
{ */
return m_textPane.getInputMethodRequests(); public InputMethodRequests getInputMethodRequests()
} {
/** return m_textPane.getInputMethodRequests();
* Set Input Verifier }
* @param l verifyer /**
*/ * Set Input Verifier
public void setInputVerifier (InputVerifier l) * @param l verifyer
{ */
m_textPane.setInputVerifier(l); public void setInputVerifier (InputVerifier l)
} {
m_textPane.setInputVerifier(l);
} // CTextPane }
} // CTextPane

View File

@ -1,262 +1,273 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us * * For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html * * or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/ *****************************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.Color; import java.awt.Color;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.CompiereColor; import org.compiere.plaf.CompiereColor;
import org.compiere.plaf.CompiereLookAndFeel; import org.compiere.plaf.CompiereLookAndFeel;
import org.compiere.util.Trace; import org.compiere.util.Trace;
/** /**
* Adempiere Color Taggle Button * Adempiere Color Taggle Button
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CToggleButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CToggleButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CToggleButton extends JToggleButton implements CEditor public class CToggleButton extends JToggleButton implements CEditor
{ {
/** /**
* Creates an initially unselected toggle button * Creates an initially unselected toggle button
* without setting the text or image. * without setting the text or image.
*/ */
public CToggleButton () public CToggleButton ()
{ {
this(null, null, false); this(null, null, false);
} }
/** /**
* Creates an initially unselected toggle button * Creates an initially unselected toggle button
* with the specified image but no text. * with the specified image but no text.
* *
* @param icon the image that the button should display * @param icon the image that the button should display
*/ */
public CToggleButton(Icon icon) public CToggleButton(Icon icon)
{ {
this(null, icon, false); this(null, icon, false);
} }
/** /**
* Creates a toggle button with the specified image * Creates a toggle button with the specified image
* and selection state, but no text. * and selection state, but no text.
* *
* @param icon the image that the button should display * @param icon the image that the button should display
* @param selected if true, the button is initially selected; * @param selected if true, the button is initially selected;
* otherwise, the button is initially unselected * otherwise, the button is initially unselected
*/ */
public CToggleButton(Icon icon, boolean selected) public CToggleButton(Icon icon, boolean selected)
{ {
this(null, icon, selected); this(null, icon, selected);
} }
/** /**
* Creates an unselected toggle button with the specified text. * Creates an unselected toggle button with the specified text.
* *
* @param text the string displayed on the toggle button * @param text the string displayed on the toggle button
*/ */
public CToggleButton (String text) public CToggleButton (String text)
{ {
this(text, null, false); this(text, null, false);
} }
/** /**
* Creates a toggle button with the specified text * Creates a toggle button with the specified text
* and selection state. * and selection state.
* *
* @param text the string displayed on the toggle button * @param text the string displayed on the toggle button
* @param selected if true, the button is initially selected; * @param selected if true, the button is initially selected;
* otherwise, the button is initially unselected * otherwise, the button is initially unselected
*/ */
public CToggleButton (String text, boolean selected) public CToggleButton (String text, boolean selected)
{ {
this(text, null, selected); this(text, null, selected);
} }
/** /**
* Creates a toggle button where properties are taken from the * Creates a toggle button where properties are taken from the
* Action supplied. * Action supplied.
* @param a * @param a
*/ */
public CToggleButton(Action a) public CToggleButton(Action a)
{ {
this(null, null, false); this(null, null, false);
setAction(a); setAction(a);
} }
/** /**
* Creates a toggle button that has the specified text and image, * Creates a toggle button that has the specified text and image,
* and that is initially unselected. * and that is initially unselected.
* *
* @param text the string displayed on the button * @param text the string displayed on the button
* @param icon the image that the button should display * @param icon the image that the button should display
*/ */
public CToggleButton(String text, Icon icon) public CToggleButton(String text, Icon icon)
{ {
this(text, icon, false); this(text, icon, false);
} }
/** /**
* Creates a toggle button with the specified text, image, and * Creates a toggle button with the specified text, image, and
* selection state. * selection state.
* *
* @param text the text of the toggle button * @param text the text of the toggle button
* @param icon the image that the button should display * @param icon the image that the button should display
* @param selected if true, the button is initially selected; * @param selected if true, the button is initially selected;
* otherwise, the button is initially unselected * otherwise, the button is initially unselected
*/ */
public CToggleButton (String text, Icon icon, boolean selected) public CToggleButton (String text, Icon icon, boolean selected)
{ {
super(text, icon, selected); super(text, icon, selected);
} setContentAreaFilled(false);
setOpaque(false);
/*************************************************************************/ //
setFont(AdempierePLAF.getFont_Label());
/** setForeground(AdempierePLAF.getTextColor_Label());
* Set Background - Differentiates between system & user call. }
* If User Call, sets Opaque & ContextAreaFilled to true
* @param bg /*************************************************************************/
*/
public void setBackground(Color bg) /**
{ * Set Background - Differentiates between system & user call.
if (bg.equals(getBackground())) * If User Call, sets Opaque & ContextAreaFilled to true
return; * @param bg
super.setBackground( bg); */
} // setBackground public void setBackground(Color bg)
{
/** if (bg.equals(getBackground()))
* Set Background - NOP return;
* @param error super.setBackground( bg);
*/ // ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
public void setBackground (boolean error) if (!Trace.getCallerClass(1).startsWith("javax"))
{ {
} // setBackground setOpaque(true);
setContentAreaFilled(true);
/** }
* Set Standard Background } // setBackground
*/
public void setBackgroundColor () /**
{ * Set Background - NOP
setBackgroundColor (null); * @param error
} // setBackground */
public void setBackground (boolean error)
/** {
* Set Background } // setBackground
* @param bg AdempiereColor for Background, if null set standard background
*/ /**
public void setBackgroundColor (CompiereColor bg) * Set Standard Background
{ */
if (bg == null) public void setBackgroundColor ()
bg = new CompiereColor(AdempierePLAF.getFormBackground()); {
setOpaque(true); setBackgroundColor (null);
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); } // setBackground
super.setBackground (bg.getFlatColor());
} // setBackground /**
* Set Background
/** * @param bg AdempiereColor for Background, if null set standard background
* Get Background */
* @return Color for Background public void setBackgroundColor (CompiereColor bg)
*/ {
public CompiereColor getBackgroundColor () if (bg == null)
{ bg = CompiereColor.getDefaultBackground();
try setOpaque(true);
{ putClientProperty(AdempierePLAF.BACKGROUND, bg);
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND); super.setBackground (bg.getFlatColor());
} } // setBackground
catch (Exception e)
{ /**
System.err.println("CButton - ClientProperty: " + e.getMessage()); * Get Background
} * @return Color for Background
return null; */
} // getBackgroundColor public CompiereColor getBackgroundColor ()
{
/** Mandatory (default false) */ try
private boolean m_mandatory = false; {
return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
/** }
* Set Editor Mandatory catch (Exception e)
* @param mandatory true, if you have to enter data {
*/ System.err.println("CButton - ClientProperty: " + e.getMessage());
public void setMandatory (boolean mandatory) }
{ return null;
m_mandatory = mandatory; } // getBackgroundColor
setBackground(false);
} // setMandatory /** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Is Field mandatory /**
* @return true, if mandatory * Set Editor Mandatory
*/ * @param mandatory true, if you have to enter data
public boolean isMandatory() */
{ public void setMandatory (boolean mandatory)
return m_mandatory; {
} // isMandatory m_mandatory = mandatory;
setBackground(false);
/** } // setMandatory
* Enable Editor
* @param rw true, if you can enter/select data /**
*/ * Is Field mandatory
public void setReadWrite (boolean rw) * @return true, if mandatory
{ */
if (super.isEnabled() != rw) public boolean isMandatory()
super.setEnabled(rw); {
} // setReadWrite return m_mandatory;
} // isMandatory
/**
* Is it possible to edit /**
* @return true, if editable * Enable Editor
*/ * @param rw true, if you can enter/select data
public boolean isReadWrite() */
{ public void setReadWrite (boolean rw)
return super.isEnabled(); {
} // isReadWrite if (super.isEnabled() != rw)
super.setEnabled(rw);
/** } // setReadWrite
* Set Editor to value
* @param value value of the editor /**
*/ * Is it possible to edit
public void setValue (Object value) * @return true, if editable
{ */
if (value == null) public boolean isReadWrite()
setText(""); {
else return super.isEnabled();
setText(value.toString()); } // isReadWrite
} // setValue
/**
/** * Set Editor to value
* Return Editor value * @param value value of the editor
* @return current value */
*/ public void setValue (Object value)
public Object getValue() {
{ if (value == null)
return getText(); setText("");
} // getValue else
setText(value.toString());
/** } // setValue
* Return Display Value
* @return displayed String value /**
*/ * Return Editor value
public String getDisplay() * @return current value
{ */
return getText(); public Object getValue()
} // getDisplay {
return getText();
} // CToggleButton } // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return getText();
} // getDisplay
} // CToggleButton

View File

@ -76,9 +76,9 @@ public final class Ini implements Serializable
/** UI Theme */ /** UI Theme */
public static final String P_UI_THEME = "UITheme"; public static final String P_UI_THEME = "UITheme";
/** Flat Color UI /** Flat Color UI*/
public static final String P_UI_FLAT = "UIFlat"; public static final String P_UI_FLAT = "UIFlat";
private static final boolean DEFAULT_UI_FLAT = false; /*private static final boolean DEFAULT_UI_FLAT = false;
*/ */
/** Auto Save */ /** Auto Save */