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 */
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 *******************************************************/

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. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
/**
* Compiere Look & Feel.
* We wanted a nice UI not the battleship gray based stuff.
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
/**
* Compiere Look & Feel.
* We wanted a nice UI not the battleship gray based stuff.
* I guess a matter of taste.
* <code>
* :
@ -36,10 +36,10 @@ import javax.swing.plaf.metal.*;
*/
public class CompiereLookAndFeel extends MetalLookAndFeel
{
/**
* Constructor
*/
public CompiereLookAndFeel()
/**
* Constructor
*/
public CompiereLookAndFeel()
{
super();
// System.setProperty("awt.visualbell", "true");
@ -47,198 +47,195 @@ public class CompiereLookAndFeel extends MetalLookAndFeel
/** The name */
public static final String NAME = "Compiere";
/** The Theme */
private static CompiereTheme s_compiereTheme = new CompiereThemeBlueMetal();
private static MetalTheme s_theme = s_compiereTheme;
/** The Theme */
private static CompiereTheme s_compiereTheme = new CompiereThemeBlueMetal();
private static MetalTheme s_theme = s_compiereTheme;
/** Paint Round Corners */
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
* @return Name
*/
public String getName()
{
return NAME;
} // getName
/**
* The ID
* @return Name
*/
public String getID()
{
return NAME;
} // getID
/**
* The Description
* @return description
*/
public String getDescription()
{
return "Compiere Look & Feel - (c) 2001-2005 Jorg Janke";
} // getDescription
/**************************************************************************
* Get/Create Defaults
* @return UI Defaults
*/
public String getName()
{
return NAME;
} // getName
/**
* The ID
* @return Name
*/
public String getID()
{
return NAME;
} // getID
/**
* The Description
* @return description
*/
public String getDescription()
{
return "Compiere Look & Feel - (c) 2001-2005 Jorg Janke";
} // getDescription
/**************************************************************************
* Get/Create Defaults
* @return UI Defaults
*/
public UIDefaults getDefaults()
{
// System.out.println("CompiereLookAndFeel.getDefaults");
// Theme already created/set
MetalLookAndFeel.setCurrentTheme(s_theme);
UIDefaults defaults = super.getDefaults(); // calls init..Defaults
return defaults;
} // getDefaults
/**
* 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.
* Each <code>JComponent</code> class specifies its own UI class ID string.
*
* @param table UI Defaults
return defaults;
} // getDefaults
/**
* 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.
* Each <code>JComponent</code> class specifies its own UI class ID string.
*
* @param table UI Defaults
*/
protected void initClassDefaults(UIDefaults table)
{
// System.out.println("CompiereLookAndFeel.initClassDefaults");
super.initClassDefaults( table);
// Overwrite
putDefault (table, "PanelUI");
putDefault (table, "ButtonUI");
putDefault (table, "ToggleButtonUI");
putDefault (table, "TabbedPaneUI");
putDefault (table, "TableHeaderUI");
putDefault (table, "RadioButtonUI");
putDefault (table, "CheckBoxUI");
putDefault (table, "ComboBoxUI");
putDefault (table, "MenuUI");
putDefault (table, "MenuBarUI");
putDefault (table, "MenuItemUI");
putDefault (table, "CheckBoxMenuItemUI");
putDefault (table, "ToolBarUI");
putDefault (table, "RootPaneUI");
putDefault (table, "ViewportUI");
putDefault (table, "SplitPaneUI");
putDefault (table, "ScrollPaneUI");
putDefault (table, "LabelUI");
putDefault (table, "ToolTipUI");
putDefault (table, "TextAreaUI");
} // initClassDefaults
/**
* Put "uiKey - ClassName" pair in UIDefaults
* @param table
* @param uiKey
*/
private void putDefault (UIDefaults table, String uiKey)
{
try
{
String className = "org.compiere.plaf.Compiere" + uiKey;
table.put(uiKey, className);
}
catch (Exception ex)
{
ex.printStackTrace();
}
} // putDefault
/**
* For overwriting Component defaults
* @param table
putDefault (table, "ButtonUI");
putDefault (table, "ToggleButtonUI");
putDefault (table, "TabbedPaneUI");
putDefault (table, "TableHeaderUI");
putDefault (table, "RadioButtonUI");
putDefault (table, "CheckBoxUI");
putDefault (table, "ComboBoxUI");
putDefault (table, "MenuUI");
putDefault (table, "MenuBarUI");
putDefault (table, "MenuItemUI");
putDefault (table, "CheckBoxMenuItemUI");
putDefault (table, "ToolBarUI");
putDefault (table, "RootPaneUI");
putDefault (table, "ViewportUI");
putDefault (table, "SplitPaneUI");
putDefault (table, "ScrollPaneUI");
putDefault (table, "LabelUI");
putDefault (table, "ToolTipUI");
putDefault (table, "TextAreaUI");
} // initClassDefaults
/**
* Put "uiKey - ClassName" pair in UIDefaults
* @param table
* @param uiKey
*/
private void putDefault (UIDefaults table, String uiKey)
{
try
{
String className = "org.compiere.plaf.Compiere" + uiKey;
table.put(uiKey, className);
}
catch (Exception ex)
{
ex.printStackTrace();
}
} // putDefault
/**
* For overwriting Component defaults
* @param table
*/
protected void initSystemColorDefaults (UIDefaults table)
{
// System.out.println("CompiereLookAndFeel.initSystemColorDefaults");
super.initSystemColorDefaults( table);
// we made the color a bit darker
// table.put("textHighlight", CompiereUtils.getTranslucentColor(getTextHighlightColor(), 128));
} // initSystemColorDefaults
/**
* For overwriting Component defaults
* @param table
* For overwriting Component defaults
* @param table
*/
protected void initComponentDefaults (UIDefaults table)
{
// System.out.println("CompiereLookAndFeel.initComponentDefaults");
super.initComponentDefaults( table);
// ComboBox defaults
Color c = table.getColor("TextField.background");
table.put("ComboBox.background", c);
table.put("ComboBox.listBackground", c);
} // initComponentDefaults
/**************************************************************************
* Create Default Thems
*/
protected void createDefaultTheme()
{
setCurrentTheme(s_theme);
} // createDefaultTheme
/**
* Set Current Theme
* @param theme metal theme
*/
public static void setCurrentTheme (MetalTheme theme)
{
if (theme != null)
s_theme = theme;
MetalLookAndFeel.setCurrentTheme(s_theme);
} // setCurrentTheme
/**
* Get Current Theme
* @return Metal Theme
*/
public static MetalTheme getCurrentTheme()
{
return s_theme;
} // getCurrentTheme
/**
* Get Compiere Theme
* @return Metal Theme
*/
public static CompiereTheme getCompiereTheme()
{
return s_compiereTheme;
} // getCurrentTheme
/**
* Error Feedback.
* <p>
* Invoked when the user attempts an invalid operation,
* such as pasting into an uneditable <code>JTextField</code>
* that has focus.
* </p>
* <p>
* If the user has enabled visual error indication on
* the desktop, this method will flash the caption bar
* of the active window. The user can also set the
* property awt.visualbell=true to achieve the same
* results.
* </p>
* @param component Component the error occured in, may be
* null indicating the error condition is
* not directly associated with a
* <code>Component</code>.
*/
public void provideErrorFeedback (Component component)
{
Color c = table.getColor("TextField.background");
table.put("ComboBox.background", c);
table.put("ComboBox.listBackground", c);
} // initComponentDefaults
/**************************************************************************
* Create Default Thems
*/
protected void createDefaultTheme()
{
setCurrentTheme(s_theme);
} // createDefaultTheme
/**
* Set Current Theme
* @param theme metal theme
*/
public static void setCurrentTheme (MetalTheme theme)
{
if (theme != null)
s_theme = theme;
MetalLookAndFeel.setCurrentTheme(s_theme);
} // setCurrentTheme
/**
* Get Current Theme
* @return Metal Theme
*/
public static MetalTheme getCurrentTheme()
{
return s_theme;
} // getCurrentTheme
/**
* Get Compiere Theme
* @return Metal Theme
*/
public static CompiereTheme getCompiereTheme()
{
return s_compiereTheme;
} // getCurrentTheme
/**
* Error Feedback.
* <p>
* Invoked when the user attempts an invalid operation,
* such as pasting into an uneditable <code>JTextField</code>
* that has focus.
* </p>
* <p>
* If the user has enabled visual error indication on
* the desktop, this method will flash the caption bar
* of the active window. The user can also set the
* property awt.visualbell=true to achieve the same
* results.
* </p>
* @param component Component the error occured in, may be
* null indicating the error condition is
* not directly associated with a
* <code>Component</code>.
*/
public void provideErrorFeedback (Component component)
{
super.provideErrorFeedback (component);
} // provideErrorFeedback

View File

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

View File

@ -1,95 +1,96 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableHeaderUI;
/**
* Table Header UI
* 3D effect
*
* @author Jorg Janke
* @version $Id: AdempiereTableHeaderUI.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CompiereTableHeaderUI extends BasicTableHeaderUI
{
/**
* Static Create UI
* @param c Component
* @return Adempiere TableHeader UI
*/
public static ComponentUI createUI(JComponent c)
{
return new CompiereTableHeaderUI();
} // createUI
/**
* Install UI - set not Opaque
* @param c
*/
public void installUI(JComponent c)
{
super.installUI(c);
// TableHeader is in JViewpoiunt, which is Opaque
// When UI created, TableHeader not added to viewpoint
//c.setOpaque(true);
//c.putClientProperty(AdempierePLAF.BACKGROUND_FILL, "Y");
} // installUI
/**************************************************************************
* Update -
* 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
* <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
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c)
{
// AdempiereUtils.printParents (c); // Parent is JViewpoint
if (c.isOpaque()) // flat
CompiereUtils.fillRectange((Graphics2D)g, c, CompiereLookAndFeel.ROUND);
//
paint (g, c);
} // update
/**
* Paint 3D box
* @param g
* @param c
*/
public void paint(Graphics g, JComponent c)
{
super.paint( g, c);
CompiereUtils.paint3Deffect((Graphics2D)g, c, CompiereLookAndFeel.ROUND, true);
} // paint
} // AdempiereTableHeader
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTableHeaderUI;
import org.adempiere.plaf.*;
/**
* Table Header UI
* 3D effect
*
* @author Jorg Janke
* @version $Id: AdempiereTableHeaderUI.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CompiereTableHeaderUI extends BasicTableHeaderUI
{
/**
* Static Create UI
* @param c Component
* @return Adempiere TableHeader UI
*/
public static ComponentUI createUI(JComponent c)
{
return new CompiereTableHeaderUI();
} // createUI
/**
* Install UI - set not Opaque
* @param c
*/
public void installUI(JComponent c)
{
super.installUI(c);
// TableHeader is in JViewpoiunt, which is Opaque
// When UI created, TableHeader not added to viewpoint
c.setOpaque(true);
c.putClientProperty(AdempierePLAF.BACKGROUND_FILL, "Y");
} // installUI
/**************************************************************************
* Update -
* 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
* <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
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c)
{
// AdempiereUtils.printParents (c); // Parent is JViewpoint
if (c.isOpaque()) // flat
CompiereUtils.fillRectange((Graphics2D)g, c, CompiereLookAndFeel.ROUND);
//
paint (g, c);
} // update
/**
* Paint 3D box
* @param g
* @param c
*/
public void paint(Graphics g, JComponent c)
{
super.paint( g, c);
CompiereUtils.paint3Deffect((Graphics2D)g, c, CompiereLookAndFeel.ROUND, true);
} // paint
} // AdempiereTableHeader

View File

@ -3,18 +3,18 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.plaf;
import java.awt.*;
import java.util.logging.*;
@ -30,7 +30,7 @@ import org.compiere.util.*;
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)
*
* @author Jorg Janke
@ -38,8 +38,8 @@ import sun.awt.*;
*/
public class CompiereTheme extends MetalTheme
{
/**
* Constructor - nop
/**
* Constructor - nop
*/
public CompiereTheme()
{
@ -47,299 +47,561 @@ public class CompiereTheme extends MetalTheme
/**
* Return Theme Name
* @return Theme Name
*/
public String getName()
{
return s_name;
} // getName
/**
* String Representation
* @return info
*/
public String toString ()
{
return s_name;
} // toString
/**
* Set Default Colors
*/
protected void setDefault()
{
} // setDefault
/** Static Initializer */
static
{
s_theme = new CompiereThemeBlueMetal();
}
/** Theme Name */
protected static String s_name = "Compiere Theme";
/** Logger */
protected static Logger log = Logger.getLogger(CompiereTheme.class.getName());
/** Active Theme */
protected static CompiereTheme s_theme = null;
/** Blue 51,51,102 */
protected static ColorUIResource primary0 = new ColorUIResource(51, 51, 102);
/** Blue 102, 102, 153 */
protected static ColorUIResource primary1;
/** Blue 153, 153, 204 */
protected static ColorUIResource primary2;
/** Blue 204, 204, 255 */
protected static ColorUIResource primary3;
/** Black */
protected final ColorUIResource secondary0 = new ColorUIResource(0, 0, 0);
/** Gray 102, 102, 102 */
protected static ColorUIResource secondary1;
/** Gray 153, 153, 153 */
protected static ColorUIResource secondary2;
/** BlueGray 214, 224, 234 - background */
protected static ColorUIResource secondary3;
/** White */
protected final ColorUIResource secondary4 = new ColorUIResource(255, 255, 255);
/** Black */
protected static ColorUIResource black;
/** White */
protected static ColorUIResource white;
/** Background for mandatory fields */
protected static ColorUIResource mandatory;
/** Background for fields in error */
protected static ColorUIResource error;
/** Background for inactive fields */
protected static ColorUIResource inactive;
/** Background for info fields */
protected static ColorUIResource info;
/** Foreground Text OK */
protected static ColorUIResource txt_ok;
/** Foreground Text Error */
protected static ColorUIResource txt_error;
/** Control font */
protected static FontUIResource controlFont;
/** System font */
protected static FontUIResource systemFont;
/** User font */
protected static FontUIResource userFont;
/** Small font */
protected static FontUIResource smallFont;
/** Window Title font */
protected static FontUIResource windowFont;
/** Menu font */
protected static FontUIResource menuFont;
/** Default Font */
public static final String FONT_DEFAULT = "Dialog";
/** Default Font Size */
* @return Theme Name
*/
public String getName()
{
return s_name;
} // getName
/**
* String Representation
* @return info
*/
public String toString ()
{
return s_name;
} // toString
/**
* Set Default Colors
*/
protected void setDefault()
{
} // setDefault
/** Static Initializer */
static
{
s_theme = new CompiereThemeBlueMetal();
}
/** Theme Name */
protected static String s_name = "Compiere Theme";
/** Logger */
protected static Logger log = Logger.getLogger(CompiereTheme.class.getName());
/** Active Theme */
protected static CompiereTheme s_theme = null;
/** Blue 51,51,102 */
protected static ColorUIResource primary0 = new ColorUIResource(51, 51, 102);
/** Blue 102, 102, 153 */
protected static ColorUIResource primary1;
/** Blue 153, 153, 204 */
protected static ColorUIResource primary2;
/** Blue 204, 204, 255 */
protected static ColorUIResource primary3;
/** Black */
protected final ColorUIResource secondary0 = new ColorUIResource(0, 0, 0);
/** Gray 102, 102, 102 */
protected static ColorUIResource secondary1;
/** Gray 153, 153, 153 */
protected static ColorUIResource secondary2;
/** BlueGray 214, 224, 234 - background */
protected static ColorUIResource secondary3;
/** White */
protected final ColorUIResource secondary4 = new ColorUIResource(255, 255, 255);
/** Black */
protected static ColorUIResource black;
/** White */
protected static ColorUIResource white;
/** Background for mandatory fields */
protected static ColorUIResource mandatory;
/** Background for fields in error */
protected static ColorUIResource error;
/** Background for inactive fields */
protected static ColorUIResource inactive;
/** Background for info fields */
protected static ColorUIResource info;
/** Foreground Text OK */
protected static ColorUIResource txt_ok;
/** Foreground Text Error */
protected static ColorUIResource txt_error;
/** Control font */
protected static FontUIResource controlFont;
/** System font */
protected static FontUIResource systemFont;
/** User font */
protected static FontUIResource userFont;
/** Small font */
protected static FontUIResource smallFont;
/** Window Title font */
protected static FontUIResource windowFont;
/** Menu font */
protected static FontUIResource menuFont;
/** Default Font */
public static final String FONT_DEFAULT = "Dialog";
/** Default Font Size */
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)
* @return color
*/
public ColorUIResource getPrimary1()
{
return ColorBlind.getDichromatColorUIResource(primary1);
}
public ColorUIResource getPrimary2()
{
return ColorBlind.getDichromatColorUIResource(primary2);
}
public ColorUIResource getPrimary3()
{
return ColorBlind.getDichromatColorUIResource(primary3);
}
/**
* Get Seconary 1 (gray in default Metal Theme)
* @return color
*/
public ColorUIResource getSecondary0()
{
return ColorBlind.getDichromatColorUIResource(secondary0);
}
public ColorUIResource getSecondary1()
{
return ColorBlind.getDichromatColorUIResource(secondary1);
}
public ColorUIResource getSecondary2()
{
return ColorBlind.getDichromatColorUIResource(secondary2);
}
public ColorUIResource getSecondary3()
{
return ColorBlind.getDichromatColorUIResource(secondary3);
}
public ColorUIResource getSecondary4()
{
return ColorBlind.getDichromatColorUIResource(secondary4);
}
public ColorUIResource getBlack()
{
return ColorBlind.getDichromatColorUIResource(black);
}
public ColorUIResource getWhite()
{
return ColorBlind.getDichromatColorUIResource(white);
}
/**
* Control Font (plain)
* @return font
*/
protected static FontUIResource _getControlTextFont()
{
if (controlFont == null)
{
try
{
controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
controlFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return controlFont;
}
public FontUIResource getControlTextFont() {return _getControlTextFont();}
/**
* System Font
* @return font
*/
protected static FontUIResource _getSystemTextFont()
{
if (systemFont == null)
{
try
{
systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
systemFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return systemFont;
}
public FontUIResource getSystemTextFont() {return _getSystemTextFont();}
/**
* User Font
* @return font
*/
protected static FontUIResource _getUserTextFont()
{
if (userFont == null)
{
try
{
userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
userFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return userFont;
}
public FontUIResource getUserTextFont() {return _getUserTextFont();}
/**
* Menu
* @return font
*/
protected static FontUIResource _getMenuTextFont()
{
if (menuFont == null)
{
try
{
menuFont = new FontUIResource(Font.getFont("swing.plaf.metal.menuFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
menuFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return menuFont;
}
public FontUIResource getMenuTextFont() {return _getMenuTextFont();}
/**
* Window Title
* @return font
*/
protected static FontUIResource _getWindowTitleFont()
{
if (windowFont == null)
{
try
{
windowFont = new FontUIResource(Font.getFont("swing.plaf.metal.windowFont",
new Font(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2)));
}
catch (Exception e)
{
windowFont = new FontUIResource(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2);
}
}
return windowFont;
}
public FontUIResource getWindowTitleFont() {return _getWindowTitleFont();}
/**
* Sub Text
* @return font
*/
protected static FontUIResource _getSubTextFont()
{
if (smallFont == null)
{
try
{
smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2)));
}
catch (Exception e)
{
smallFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2);
}
}
return smallFont;
*/
public ColorUIResource getPrimary1()
{
return ColorBlind.getDichromatColorUIResource(primary1);
}
public ColorUIResource getPrimary2()
{
return ColorBlind.getDichromatColorUIResource(primary2);
}
public ColorUIResource getPrimary3()
{
return ColorBlind.getDichromatColorUIResource(primary3);
}
/**
* Get Seconary 1 (gray in default Metal Theme)
* @return color
*/
public ColorUIResource getSecondary0()
{
return ColorBlind.getDichromatColorUIResource(secondary0);
}
public ColorUIResource getSecondary1()
{
return ColorBlind.getDichromatColorUIResource(secondary1);
}
public ColorUIResource getSecondary2()
{
return ColorBlind.getDichromatColorUIResource(secondary2);
}
public ColorUIResource getSecondary3()
{
return ColorBlind.getDichromatColorUIResource(secondary3);
}
public ColorUIResource getSecondary4()
{
return ColorBlind.getDichromatColorUIResource(secondary4);
}
public ColorUIResource getBlack()
{
return ColorBlind.getDichromatColorUIResource(black);
}
public ColorUIResource getWhite()
{
return ColorBlind.getDichromatColorUIResource(white);
}
/**
* Control Font (plain)
* @return font
*/
protected static FontUIResource _getControlTextFont()
{
if (controlFont == null)
{
try
{
controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
controlFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return controlFont;
}
public FontUIResource getControlTextFont() {return _getControlTextFont();}
/**
* System Font
* @return font
*/
protected static FontUIResource _getSystemTextFont()
{
if (systemFont == null)
{
try
{
systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
systemFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return systemFont;
}
public FontUIResource getSystemTextFont() {return _getSystemTextFont();}
/**
* User Font
* @return font
*/
protected static FontUIResource _getUserTextFont()
{
if (userFont == null)
{
try
{
userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
userFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return userFont;
}
public FontUIResource getUserTextFont() {return _getUserTextFont();}
/**
* Menu
* @return font
*/
protected static FontUIResource _getMenuTextFont()
{
if (menuFont == null)
{
try
{
menuFont = new FontUIResource(Font.getFont("swing.plaf.metal.menuFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
menuFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return menuFont;
}
public FontUIResource getMenuTextFont() {return _getMenuTextFont();}
/**
* Window Title
* @return font
*/
protected static FontUIResource _getWindowTitleFont()
{
if (windowFont == null)
{
try
{
windowFont = new FontUIResource(Font.getFont("swing.plaf.metal.windowFont",
new Font(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2)));
}
catch (Exception e)
{
windowFont = new FontUIResource(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2);
}
}
return windowFont;
}
public FontUIResource getWindowTitleFont() {return _getWindowTitleFont();}
/**
* Sub Text
* @return font
*/
protected static FontUIResource _getSubTextFont()
{
if (smallFont == null)
{
try
{
smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2)));
}
catch (Exception e)
{
smallFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2);
}
}
return smallFont;
}
public FontUIResource getSubTextFont() {return _getSubTextFont();}
@Override
public void addCustomEntriesToTable(UIDefaults table) {
super.addCustomEntriesToTable(table);
Object[] defaults =
// Static property info
private static final String P_Primary1 = "#ColorPrimary1";
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,
error,
ExtendedTheme.ERROR_FG_KEY,
txt_error,
ExtendedTheme.INACTIVE_BG_KEY,
inactive,
ExtendedTheme.INFO_BG_KEY,
info,
ExtendedTheme.MANDATORY_BG_KEY,
mandatory
};
table.putDefaults(defaults);
}
} // AdempiereTheme
int r = Integer.parseInt(information.substring(information.indexOf("r=")+2, information.indexOf(",g=")));
int g = Integer.parseInt(information.substring(information.indexOf("g=")+2, information.indexOf(",b=")));
int b = 0;
int a = 255;
if (information.indexOf("a=") == -1)
b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf("]")));
else
{
b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf(",a=")));
a = Integer.parseInt(information.substring(information.indexOf("a=")+2, information.indexOf("]")));
}
ColorUIResource retValue = new ColorUIResource(new Color(r, g, b, a));
// System.out.println(" - " + retValue.toString());
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?
CompiereColor cc = null;
boolean stdCC = c.getClientProperty(CompiereLookAndFeel.BACKGROUND_FILL) != null;
boolean stdCC = c.getClientProperty(AdempierePLAF.BACKGROUND_FILL) != null;
try
{
cc = (CompiereColor)c.getClientProperty(CompiereLookAndFeel.BACKGROUND);
cc = (CompiereColor)c.getClientProperty(AdempierePLAF.BACKGROUND);
}
catch (Exception e)
{
@ -458,7 +458,7 @@ public class CompiereUtils
c.setName("C" + String.valueOf(s_no++));
System.out.print(c.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();
while (container != null)
@ -466,7 +466,7 @@ public class CompiereUtils
System.out.print (" - " + container.getName() + " " + container.getClass().getName()
+ " ** " + container.isOpaque());
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 ();
container = container.getParent();
}

View File

@ -1,284 +1,297 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
import org.compiere.util.*;
/**
* Adempiere Button supporting colored Background
*
* @author Jorg Janke
* @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CButton extends JButton implements CEditor
{
/**
* Creates a button with no set text or icon.
*/
public CButton()
{
this (null, null);
} // CButton
/**
* Creates a button with an icon.
*
* @param icon the Icon image to display on the button
*/
public CButton(Icon icon)
{
this (null, icon);
} // CButton
/**
* Creates a button with text.
*
* @param text the text of the button
*/
public CButton(String text)
{
this (text, null);
} // CButton
/**
* Creates a button where properties are taken from the
* <code>Action</code> supplied.
*
* @param a the <code>Action</code> used to specify the new button
*
* @since 1.3
*/
public CButton (Action a)
{
super (a);
} // CButton
/**
* Creates a button with initial text and an icon.
*
* @param text the text of the button
* @param icon the Icon image to display on the button
*/
public CButton(String text, Icon icon)
{
super (text, icon);
} // CButton
/**************************************************************************
* Set Background - Differentiates between system & user call.
* If User Call, sets Opaque & ContextAreaFilled to true
* @param bg background color
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground (bg);
setBackgroundColor(new CompiereColor(bg));
this.repaint();
} // setBackground
/**
* Set Background - NOP
* @param error error
*/
public void setBackground (boolean error)
{
} // setBackground
/**
* Set Standard Background
*/
public void setBackgroundColor ()
{
setBackgroundColor (null);
} // setBackground
/**
* Set Background
* @param bg AdempiereColor for Background, if null set standard background
*/
public void setBackgroundColor (CompiereColor bg)
{
if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground());
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg);
super.setBackground (bg.getFlatColor());
this.repaint();
} // setBackground
/**
* Get Background
* @return Color for Background
*/
public CompiereColor getBackgroundColor ()
{
try
{
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND);
}
catch (Exception e)
{
System.err.println("CButton - ClientProperty: " + e.getMessage());
}
return null;
} // getBackgroundColor
/** Mandatory (default false) */
private boolean m_mandatory = false;
/** Read-Write */
private boolean m_readWrite = true;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (isEnabled() != rw)
setEnabled(rw);
m_readWrite = rw;
} // setReadWrite
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return m_readWrite;
} // isReadWrite
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return getText();
} // getDisplay
/**
* Set Text & Mnemonic
* @param text text
*/
public void setText (String text)
{
if (text == null)
{
super.setText(text);
return;
}
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
int mnemonic = text.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
{
setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1);
}
}
super.setText (text);
if (getName() == null)
setName (text);
} // setText
/**
* Set Tool Tip Text & Mnemonic
* @param text text
*/
public void setToolTipText (String text)
{
if (text == null)
{
super.setText(text);
return;
}
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
int mnemonic = text.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
{
setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1);
}
}
super.setToolTipText (text);
if (getName() == null)
setName (text);
} // 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
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
import org.compiere.util.*;
/**
* Adempiere Button supporting colored Background
*
* @author Jorg Janke
* @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CButton extends JButton implements CEditor
{
/**
* Creates a button with no set text or icon.
*/
public CButton()
{
this (null, null);
} // CButton
/**
* Creates a button with an icon.
*
* @param icon the Icon image to display on the button
*/
public CButton(Icon icon)
{
this (null, icon);
} // CButton
/**
* Creates a button with text.
*
* @param text the text of the button
*/
public CButton(String text)
{
this (text, null);
} // CButton
/**
* Creates a button where properties are taken from the
* <code>Action</code> supplied.
*
* @param a the <code>Action</code> used to specify the new button
*
* @since 1.3
*/
public CButton (Action a)
{
super (a);
setContentAreaFilled(false);
setOpaque(false);
} // CButton
/**
* Creates a button with initial text and an icon.
*
* @param text the text of the button
* @param icon the Icon image to display on the button
*/
public CButton(String text, Icon icon)
{
super (text, icon);
setContentAreaFilled(false);
setOpaque(false);
//
setFont(AdempierePLAF.getFont_Label());
setForeground(AdempierePLAF.getTextColor_Label());
} // CButton
/**************************************************************************
* Set Background - Differentiates between system & user call.
* If User Call, sets Opaque & ContextAreaFilled to true
* @param bg background color
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground (bg);
// ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
if (!Trace.getCallerClass(1).startsWith("javax"))
{
setOpaque(true);
setContentAreaFilled(true);
}
this.repaint();
} // setBackground
/**
* Set Background - NOP
* @param error error
*/
public void setBackground (boolean error)
{
} // setBackground
/**
* Set Standard Background
*/
public void setBackgroundColor ()
{
setBackgroundColor (null);
} // setBackground
/**
* Set Background
* @param bg AdempiereColor for Background, if null set standard background
*/
public void setBackgroundColor (CompiereColor bg)
{
if (bg == null)
bg = CompiereColor.getDefaultBackground();
setOpaque(true);
putClientProperty(AdempierePLAF.BACKGROUND, bg);
super.setBackground (bg.getFlatColor());
this.repaint();
} // setBackground
/**
* Get Background
* @return Color for Background
*/
public CompiereColor getBackgroundColor ()
{
try
{
return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
}
catch (Exception e)
{
System.err.println("CButton - ClientProperty: " + e.getMessage());
}
return null;
} // getBackgroundColor
/** Mandatory (default false) */
private boolean m_mandatory = false;
/** Read-Write */
private boolean m_readWrite = true;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (isEnabled() != rw)
setEnabled(rw);
m_readWrite = rw;
} // setReadWrite
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return m_readWrite;
} // isReadWrite
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return getText();
} // getDisplay
/**
* Set Text & Mnemonic
* @param text text
*/
public void setText (String text)
{
if (text == null)
{
super.setText(text);
return;
}
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
int mnemonic = text.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
{
setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1);
}
}
super.setText (text);
if (getName() == null)
setName (text);
} // setText
/**
* Set Tool Tip Text & Mnemonic
* @param text text
*/
public void setToolTipText (String text)
{
if (text == null)
{
super.setText(text);
return;
}
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
int mnemonic = text.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
{
setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1);
}
}
super.setToolTipText (text);
if (getName() == null)
setName (text);
} // 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 *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.Color;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import org.adempiere.plaf.AdempierePLAF;
/**
* Adempiere CheckBox
*
* @author Jorg Janke
* @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CCheckBox extends JCheckBox implements CEditor
{
/**
* Creates an initially unselected check box button with no text, no icon.
*/
public CCheckBox ()
{
super ();
init();
}
/**
* Creates an initially unselected check box with an icon.
*
* @param icon the Icon image to display
*/
public CCheckBox(Icon icon)
{
super (icon);
init();
}
/**
* Creates a check box with an icon and specifies whether
* or not it is initially selected.
*
* @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox(Icon icon, boolean selected)
{
super (icon, selected);
init();
}
/**
* Creates an initially unselected check box with text.
*
* @param text the text of the check box.
*/
public CCheckBox (String text)
{
super (text);
init();
}
/**
* Creates a check box where properties are taken from the
* Action supplied.
* @param a
*/
public CCheckBox(Action a)
{
super (a);
init();
}
/**
* Creates a check box with text and specifies whether
* or not it is initially selected.
*
* @param text the text of the check box.
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox (String text, boolean selected)
{
super (text, selected);
init();
}
/**
* Creates an initially unselected check box with
* the specified text and icon.
*
* @param text the text of the check box.
* @param icon the Icon image to display
*/
public CCheckBox(String text, Icon icon)
{
super (text, icon, false);
init();
}
/**
* Creates a check box with text and icon,
* and specifies whether or not it is initially selected.
*
* @param text the text of the check box.
* @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox (String text, Icon icon, boolean selected)
{
super (text, icon, selected);
init();
}
/**
* Common Init
*/
private void init()
{
//Default to transparent, works better under windows look and feel
setOpaque(false);
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/** Read-Write */
private boolean m_readWrite = true;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEnabled() != rw)
super.setEnabled (rw);
setBackground(false);
m_readWrite = rw;
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return m_readWrite;
} // isEditable
/**
* Set Background based on editable/mandatory/error - ignored -
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
} // setBackground
/**
* Set Background
* @param bg
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/** Retain value */
private Object m_value = null;
/**
* Set Editor to value. Interpret Y/N and Boolean
* @param value value of the editor
*/
public void setValue (Object value)
{
m_value = value;
boolean sel = false;
if (value == null)
sel = false;
else if (value.toString().equals("Y"))
sel = true;
else if (value.toString().equals("N"))
sel = false;
else if (value instanceof Boolean)
sel = ((Boolean)value).booleanValue();
else
{
try
{
sel = Boolean.getBoolean(value.toString());
}
catch (Exception e)
{
}
}
this.setSelected(sel);
} // setValue
/**
* Return Editor value
* @return current value as String or Boolean
*/
public Object getValue()
{
if (m_value instanceof String)
return super.isSelected() ? "Y" : "N";
return new Boolean (isSelected());
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
if (m_value instanceof String)
return super.isSelected() ? "Y" : "N";
return Boolean.toString(super.isSelected());
} // getDisplay
/**
* Set Text
* @param mnemonicLabel text
*/
public void setText (String mnemonicLabel)
{
super.setText (createMnemonic(mnemonicLabel));
} // setText
/**
* Create Mnemonics of text containing "&".
* Based on MS notation of &Help => H is Mnemonics
* Creates ALT_
* @param text test with Mnemonics
* @return text w/o &
*/
private String createMnemonic(String text)
{
if (text == null)
return text;
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic
{
char ch = text.charAt(pos+1);
if (ch != ' ') // &_ - is the & character
{
setMnemonic(ch);
return text.substring(0, pos) + text.substring(pos+1);
}
}
return text;
} // createMnemonic
} // CCheckBox
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.Color;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import org.adempiere.plaf.AdempierePLAF;
/**
* Adempiere CheckBox
*
* @author Jorg Janke
* @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CCheckBox extends JCheckBox implements CEditor
{
/**
* Creates an initially unselected check box button with no text, no icon.
*/
public CCheckBox ()
{
super ();
init();
}
/**
* Creates an initially unselected check box with an icon.
*
* @param icon the Icon image to display
*/
public CCheckBox(Icon icon)
{
super (icon);
init();
}
/**
* Creates a check box with an icon and specifies whether
* or not it is initially selected.
*
* @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox(Icon icon, boolean selected)
{
super (icon, selected);
init();
}
/**
* Creates an initially unselected check box with text.
*
* @param text the text of the check box.
*/
public CCheckBox (String text)
{
super (text);
init();
}
/**
* Creates a check box where properties are taken from the
* Action supplied.
* @param a
*/
public CCheckBox(Action a)
{
super (a);
init();
}
/**
* Creates a check box with text and specifies whether
* or not it is initially selected.
*
* @param text the text of the check box.
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox (String text, boolean selected)
{
super (text, selected);
init();
}
/**
* Creates an initially unselected check box with
* the specified text and icon.
*
* @param text the text of the check box.
* @param icon the Icon image to display
*/
public CCheckBox(String text, Icon icon)
{
super (text, icon, false);
init();
}
/**
* Creates a check box with text and icon,
* and specifies whether or not it is initially selected.
*
* @param text the text of the check box.
* @param icon the Icon image to display
* @param selected a boolean value indicating the initial selection
* state. If <code>true</code> the check box is selected
*/
public CCheckBox (String text, Icon icon, boolean selected)
{
super (text, icon, selected);
init();
}
/**
* Common Init
*/
private void init()
{
setFont(AdempierePLAF.getFont_Label());
setForeground(AdempierePLAF.getTextColor_Label());
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/** Read-Write */
private boolean m_readWrite = true;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEnabled() != rw)
super.setEnabled (rw);
setBackground(false);
m_readWrite = rw;
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return m_readWrite;
} // isEditable
/**
* Set Background based on editable/mandatory/error - ignored -
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
} // setBackground
/**
* Set Background
* @param bg
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/** Retain value */
private Object m_value = null;
/**
* Set Editor to value. Interpret Y/N and Boolean
* @param value value of the editor
*/
public void setValue (Object value)
{
m_value = value;
boolean sel = false;
if (value == null)
sel = false;
else if (value.toString().equals("Y"))
sel = true;
else if (value.toString().equals("N"))
sel = false;
else if (value instanceof Boolean)
sel = ((Boolean)value).booleanValue();
else
{
try
{
sel = Boolean.getBoolean(value.toString());
}
catch (Exception e)
{
}
}
this.setSelected(sel);
} // setValue
/**
* Return Editor value
* @return current value as String or Boolean
*/
public Object getValue()
{
if (m_value instanceof String)
return super.isSelected() ? "Y" : "N";
return new Boolean (isSelected());
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
if (m_value instanceof String)
return super.isSelected() ? "Y" : "N";
return Boolean.toString(super.isSelected());
} // getDisplay
/**
* Set Text
* @param mnemonicLabel text
*/
public void setText (String mnemonicLabel)
{
super.setText (createMnemonic(mnemonicLabel));
} // setText
/**
* Create Mnemonics of text containing "&".
* Based on MS notation of &Help => H is Mnemonics
* Creates ALT_
* @param text test with Mnemonics
* @return text w/o &
*/
private String createMnemonic(String text)
{
if (text == null)
return text;
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic
{
char ch = text.charAt(pos+1);
if (ch != ' ') // &_ - is the & character
{
setMnemonic(ch);
return text.substring(0, pos) + text.substring(pos+1);
}
}
return text;
} // createMnemonic
} // CCheckBox

View File

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

View File

@ -3,24 +3,24 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.compiere.plaf.*;
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.compiere.plaf.*;
/**
* Conveniance Dialog Class.
@ -28,216 +28,217 @@ import org.compiere.plaf.*;
* Implementing empty Action and Mouse Listener
*
* @author Jorg Janke
* @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/
public class CDialog extends JDialog
implements ActionListener, MouseListener
{
/**
* CDialog
* @throws HeadlessException
*/
public CDialog() throws HeadlessException
{
this((Frame)null, false);
}
/**
* CDialog
* @param owner
* @throws HeadlessException
*/
public CDialog(Frame owner) throws HeadlessException
{
this (owner, false);
}
/**
* CDialog
* @param owner
* @param modal
* @throws HeadlessException
*/
public CDialog(Frame owner, boolean modal) throws HeadlessException
{
this (owner, null, modal);
}
/**
* CDialog
* @param owner
* @param title
* @throws HeadlessException
*/
public CDialog(Frame owner, String title) throws HeadlessException
{
this (owner, title, false);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @throws HeadlessException
*/
public CDialog(Frame owner, String title, boolean modal) throws HeadlessException
{
super(owner, title, modal);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @param gc
*/
public CDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
{
super(owner, title, modal, gc);
}
/**
* CDialog
* @param owner
* @throws HeadlessException
*/
public CDialog(Dialog owner) throws HeadlessException
{
this (owner, false);
}
/**
* CDialog
* @param owner
* @param modal
* @throws HeadlessException
*/
public CDialog(Dialog owner, boolean modal) throws HeadlessException
{
this(owner, null, modal);
}
/**
* CDialog
* @param owner
* @param title
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title) throws HeadlessException
{
this(owner, title, false);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title, boolean modal) throws HeadlessException
{
super(owner, title, modal);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @param gc
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException
{
super(owner, title, modal, gc);
}
/**
* Initialize.
* Install ALT-Pause
*/
* @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/
public class CDialog extends JDialog
implements ActionListener, MouseListener
{
/**
* CDialog
* @throws HeadlessException
*/
public CDialog() throws HeadlessException
{
this((Frame)null, false);
}
/**
* CDialog
* @param owner
* @throws HeadlessException
*/
public CDialog(Frame owner) throws HeadlessException
{
this (owner, false);
}
/**
* CDialog
* @param owner
* @param modal
* @throws HeadlessException
*/
public CDialog(Frame owner, boolean modal) throws HeadlessException
{
this (owner, null, modal);
}
/**
* CDialog
* @param owner
* @param title
* @throws HeadlessException
*/
public CDialog(Frame owner, String title) throws HeadlessException
{
this (owner, title, false);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @throws HeadlessException
*/
public CDialog(Frame owner, String title, boolean modal) throws HeadlessException
{
super(owner, title, modal);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @param gc
*/
public CDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
{
super(owner, title, modal, gc);
}
/**
* CDialog
* @param owner
* @throws HeadlessException
*/
public CDialog(Dialog owner) throws HeadlessException
{
this (owner, false);
}
/**
* CDialog
* @param owner
* @param modal
* @throws HeadlessException
*/
public CDialog(Dialog owner, boolean modal) throws HeadlessException
{
this(owner, null, modal);
}
/**
* CDialog
* @param owner
* @param title
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title) throws HeadlessException
{
this(owner, title, false);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title, boolean modal) throws HeadlessException
{
super(owner, title, modal);
}
/**
* CDialog
* @param owner
* @param title
* @param modal
* @param gc
* @throws HeadlessException
*/
public CDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException
{
super(owner, title, modal, gc);
}
/**
* Initialize.
* Install ALT-Pause
*/
protected void dialogInit()
{
super.dialogInit();
CompiereColor.setBackground(this);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setTitle(getTitle()); // remove Mn
//
Container c = getContentPane();
if (c instanceof JPanel)
{
JPanel panel = (JPanel)c;
panel.getActionMap().put(ACTION_DISPOSE, s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(s_disposeKeyStroke, ACTION_DISPOSE);
}
} // init
/**************************************************************************
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @param e
*/
public void actionPerformed(ActionEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
* @param e
*/
public void mouseClicked(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* @param e
*/
public void mouseEntered(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
* @param e
*/
public void mouseExited(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
* @param e
*/
public void mousePressed(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
* @param e
*/
public void mouseReleased(MouseEvent e)
{
}
/**
* Set Title
* @param title title
*/
public void setTitle(String title)
{
if (title != null)
{
int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic
{
int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1);
}
}
super.setTitle(title);
} // setTitle
/** Dispose Action Name */
protected static String ACTION_DISPOSE = "CDialogDispose";
/** Action */
protected static DialogAction s_dialogAction = new DialogAction(ACTION_DISPOSE);
/** ALT-EXCAPE */
protected static KeyStroke s_disposeKeyStroke =
Container c = getContentPane();
if (c instanceof JPanel)
{
JPanel panel = (JPanel)c;
panel.getActionMap().put(ACTION_DISPOSE, s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(s_disposeKeyStroke, ACTION_DISPOSE);
}
} // init
/**************************************************************************
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @param e
*/
public void actionPerformed(ActionEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
* @param e
*/
public void mouseClicked(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* @param e
*/
public void mouseEntered(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
* @param e
*/
public void mouseExited(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
* @param e
*/
public void mousePressed(MouseEvent e)
{
}
/**
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
* @param e
*/
public void mouseReleased(MouseEvent e)
{
}
/**
* Set Title
* @param title title
*/
public void setTitle(String title)
{
if (title != null)
{
int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic
{
int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1);
}
}
super.setTitle(title);
} // setTitle
/** Dispose Action Name */
protected static String ACTION_DISPOSE = "CDialogDispose";
/** Action */
protected static DialogAction s_dialogAction = new DialogAction(ACTION_DISPOSE);
/** ALT-EXCAPE */
protected static KeyStroke s_disposeKeyStroke =
KeyStroke.getKeyStroke(KeyEvent.VK_PAUSE, InputEvent.ALT_MASK);
/**
@ -245,40 +246,40 @@ public class CDialog extends JDialog
*
* @author Jorg Janke
* @version $Id: CDialog.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/
static class DialogAction extends AbstractAction
{
DialogAction (String actionName)
{
super(actionName);
putValue(AbstractAction.ACTION_COMMAND_KEY, actionName);
} // DialogAction
/**
* Action Listener
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
if (ACTION_DISPOSE.equals(e.getActionCommand()))
{
Object source = e.getSource();
while (source != null)
{
if (source instanceof Window)
{
((Window)source).dispose();
return;
}
if (source instanceof Container)
source = ((Container)source).getParent();
else
source = null;
}
}
else
System.out.println("Action: " + e);
} // actionPerformed
} // DialogAction
} // CDialog
*/
static class DialogAction extends AbstractAction
{
DialogAction (String actionName)
{
super(actionName);
putValue(AbstractAction.ACTION_COMMAND_KEY, actionName);
} // DialogAction
/**
* Action Listener
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
if (ACTION_DISPOSE.equals(e.getActionCommand()))
{
Object source = e.getSource();
while (source != null)
{
if (source instanceof Window)
{
((Window)source).dispose();
return;
}
if (source instanceof Container)
source = ((Container)source).getParent();
else
source = null;
}
}
else
System.out.println("Action: " + e);
} // actionPerformed
} // DialogAction
} // CDialog

View File

@ -3,21 +3,21 @@
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import javax.swing.*;
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import javax.swing.*;
import org.compiere.plaf.*;
/**
@ -25,111 +25,112 @@ import org.compiere.plaf.*;
*
* @author Jorg Janke
* @version $Id: CFrame.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CFrame extends JFrame
{
/**
* CFrame
* @throws HeadlessException
*/
public CFrame () throws HeadlessException
{
super ();
} // CFrame
/**
* CFrame
* @param gc
*/
public CFrame (GraphicsConfiguration gc)
{
super (gc);
} // CFrame
/**
* CFrame
* @param title
* @throws HeadlessException
*/
public CFrame (String title) throws HeadlessException
{
super (cleanup(title));
} // CFrame
/**
* CFrame
* @param title
* @param gc
*/
public CFrame (String title, GraphicsConfiguration gc)
{
super (cleanup(title), gc);
} // CFrame
/** Window ID */
private int p_AD_Window_ID = 0;
/**
* Frame Init.
* Install ALT-Pause
*/
*/
public class CFrame extends JFrame
{
/**
* CFrame
* @throws HeadlessException
*/
public CFrame () throws HeadlessException
{
super ();
} // CFrame
/**
* CFrame
* @param gc
*/
public CFrame (GraphicsConfiguration gc)
{
super (gc);
} // CFrame
/**
* CFrame
* @param title
* @throws HeadlessException
*/
public CFrame (String title) throws HeadlessException
{
super (cleanup(title));
} // CFrame
/**
* CFrame
* @param title
* @param gc
*/
public CFrame (String title, GraphicsConfiguration gc)
{
super (cleanup(title), gc);
} // CFrame
/** Window ID */
private int p_AD_Window_ID = 0;
/**
* Frame Init.
* Install ALT-Pause
*/
protected void frameInit ()
{
super.frameInit ();
CompiereColor.setBackground(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//
Container c = getContentPane();
if (c instanceof JPanel)
{
JPanel panel = (JPanel)c;
panel.getActionMap().put(CDialog.ACTION_DISPOSE, CDialog.s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(CDialog.s_disposeKeyStroke, CDialog.ACTION_DISPOSE);
}
} // frameInit
/**
* Cleanedup Title
* @param title title
* @return title w/o mn
*/
private static String cleanup (String title)
{
if (title != null)
{
int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic
{
int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1);
}
}
return title;
} // getTitle
/**
* Set Title
* @param title title
*/
public void setTitle(String title)
{
super.setTitle(cleanup(title));
} // setTitle
/**
* @return Returns the AD_Window_ID.
*/
public int getAD_Window_ID ()
{
return p_AD_Window_ID;
} // getAD_Window_ID
/**
* @param window_ID The AD_Window_ID to set.
*/
public void setAD_Window_ID (int window_ID)
{
p_AD_Window_ID = window_ID;
} // getAD_Window_ID
} // CFrame
if (c instanceof JPanel)
{
JPanel panel = (JPanel)c;
panel.getActionMap().put(CDialog.ACTION_DISPOSE, CDialog.s_dialogAction);
panel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(CDialog.s_disposeKeyStroke, CDialog.ACTION_DISPOSE);
}
} // frameInit
/**
* Cleanedup Title
* @param title title
* @return title w/o mn
*/
private static String cleanup (String title)
{
if (title != null)
{
int pos = title.indexOf("&");
if (pos != -1 && title.length() > pos) // We have a nemonic
{
int mnemonic = title.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
title = title.substring(0, pos) + title.substring(pos+1);
}
}
return title;
} // getTitle
/**
* Set Title
* @param title title
*/
public void setTitle(String title)
{
super.setTitle(cleanup(title));
} // setTitle
/**
* @return Returns the AD_Window_ID.
*/
public int getAD_Window_ID ()
{
return p_AD_Window_ID;
} // getAD_Window_ID
/**
* @param window_ID The AD_Window_ID to set.
*/
public void setAD_Window_ID (int window_ID)
{
p_AD_Window_ID = window_ID;
} // getAD_Window_ID
} // CFrame

View File

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

View File

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

View File

@ -1,214 +1,216 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.text.Document;
import org.adempiere.plaf.AdempierePLAF;
/**
* Password Field
*
* @author Jorg Janke
* @version $Id: CPassword.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CPassword extends JPasswordField implements CEditor
{
/**
* Constructs a new <code>JPasswordField</code>,
* with a default document, <code>null</code> starting
* text string, and 0 column width.
*/
public CPassword()
{
super();
init();
}
/**
* Constructs a new <code>JPasswordField</code> initialized
* with the specified text. The document model is set to the
* default, and the number of columns to 0.
*
* @param text the text to be displayed, <code>null</code> if none
*/
public CPassword (String text)
{
super (text);
init();
}
/**
* Constructs a new empty <code>JPasswordField</code> with the specified
* number of columns. A default model is created, and the initial string
* is set to <code>null</code>.
*
* @param columns the number of columns >= 0
*/
public CPassword (int columns)
{
super (columns);
init();
}
/**
* Constructs a new <code>JPasswordField</code> initialized with
* the specified text and columns. The document model is set to
* the default.
*
* @param text the text to be displayed, <code>null</code> if none
* @param columns the number of columns >= 0
*/
public CPassword (String text, int columns)
{
super (text,columns);
init();
}
/**
* Constructs a new <code>JPasswordField</code> that uses the
* given text storage model and the given number of columns.
* This is the constructor through which the other constructors feed.
* The echo character is set to '*'. If the document model is
* <code>null</code>, a default one will be created.
*
* @param doc the text storage to use
* @param txt the text to be displayed, <code>null</code> if none
* @param columns the number of columns to use to calculate
* the preferred width >= 0; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CPassword (Document doc, String txt, int columns)
{
super (doc, txt, columns);
init();
}
/**
* Common Init
*/
private void init()
{
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEditable() != rw)
super.setEditable (rw);
setBackground(false);
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return super.isEditable();
} // isReadWrite
/**
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param bg
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return new String(super.getPassword());
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return new String(super.getPassword());
} // getDisplay
}
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.text.Document;
import org.adempiere.plaf.AdempierePLAF;
/**
* Password Field
*
* @author Jorg Janke
* @version $Id: CPassword.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CPassword extends JPasswordField implements CEditor
{
/**
* Constructs a new <code>JPasswordField</code>,
* with a default document, <code>null</code> starting
* text string, and 0 column width.
*/
public CPassword()
{
super();
init();
}
/**
* Constructs a new <code>JPasswordField</code> initialized
* with the specified text. The document model is set to the
* default, and the number of columns to 0.
*
* @param text the text to be displayed, <code>null</code> if none
*/
public CPassword (String text)
{
super (text);
init();
}
/**
* Constructs a new empty <code>JPasswordField</code> with the specified
* number of columns. A default model is created, and the initial string
* is set to <code>null</code>.
*
* @param columns the number of columns >= 0
*/
public CPassword (int columns)
{
super (columns);
init();
}
/**
* Constructs a new <code>JPasswordField</code> initialized with
* the specified text and columns. The document model is set to
* the default.
*
* @param text the text to be displayed, <code>null</code> if none
* @param columns the number of columns >= 0
*/
public CPassword (String text, int columns)
{
super (text,columns);
init();
}
/**
* Constructs a new <code>JPasswordField</code> that uses the
* given text storage model and the given number of columns.
* This is the constructor through which the other constructors feed.
* The echo character is set to '*'. If the document model is
* <code>null</code>, a default one will be created.
*
* @param doc the text storage to use
* @param txt the text to be displayed, <code>null</code> if none
* @param columns the number of columns to use to calculate
* the preferred width >= 0; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CPassword (Document doc, String txt, int columns)
{
super (doc, txt, columns);
init();
}
/**
* Common Init
*/
private void init()
{
setFont(AdempierePLAF.getFont_Field());
setForeground(AdempierePLAF.getTextColor_Normal());
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEditable() != rw)
super.setEditable (rw);
setBackground(false);
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return super.isEditable();
} // isReadWrite
/**
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param bg
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return new String(super.getPassword());
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String 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)
{
super (view, vsbPolicy, hsbPolicy);
setBackgroundColor(null);
setOpaque(false);
getViewport().setOpaque(false);
} // CScollPane
@ -80,8 +81,12 @@ public class CScrollPane extends JScrollPane
public void setBackgroundColor (CompiereColor bg)
{
if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground());
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg);
bg = CompierePanelUI.getDefaultBackground();
putClientProperty(AdempierePLAF.BACKGROUND, bg);
// super.setBackground(bg.getFlatColor());
// getViewport().putClientProperty(CompierePLAF.BACKGROUND, bg);
// getViewport().setBackground(bg.getFlatColor());
// getViewport().setOpaque(true);
} // setBackground
} // CScollPane

View File

@ -1,373 +1,379 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.CompiereColor;
import org.compiere.plaf.CompiereLookAndFeel;
import org.compiere.plaf.CompierePanelUI;
import org.compiere.util.Trace;
import sun.swing.*;
/**
* Adempiere Color Tabbed Pane
*
* @author Jorg Janke
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTabbedPane extends JTabbedPane
{
/**
* Creates an empty <code>TabbedPane</code> with a default
* tab placement of <code>JTabbedPane.TOP</code> and default
* tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
*/
public CTabbedPane()
{
super();
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with the specified tab placement
* of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>, and a
* default tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
*
* @param tabPlacement the placement for the tabs relative to the content
*/
public CTabbedPane(int tabPlacement)
{
super(tabPlacement);
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with the specified tab placement
* and tab layout policy. Tab placement may be either:
* <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
* Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code>
* or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>.
*
* @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
* @exception IllegalArgumentException if tab placement or tab layout policy are not
* one of the above supported values
*/
public CTabbedPane(int tabPlacement, int tabLayoutPolicy)
{
super (tabPlacement, tabLayoutPolicy);
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with a defaults and Color
* @param bg Color
*/
public CTabbedPane (CompiereColor bg)
{
super();
init();
setBackgroundColor (bg);
} // CTabbedPane
/**
* Common Init
*/
private void init()
{
} // init
/**************************************************************************
* Set Background - ignored by UI -
* @param bg ignored
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground (bg);
setBackgroundColor (new CompiereColor(bg));
} // setBackground
/**
* Set Standard Background
*/
public void setBackgroundColor ()
{
setBackgroundColor (null);
} // setBackground
/**
* Set Background
* @param bg AdempiereColor for Background, if null set standard background
*/
public void setBackgroundColor (CompiereColor bg)
{
if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground());
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg);
super.setBackground (bg.getFlatColor());
//
repaint();
} // setBackground
/**
* Get Background
* @return Color for Background
*/
public CompiereColor getBackgroundColor ()
{
try
{
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND);
}
catch (Exception e)
{
System.err.println("ClientProperty: " + e.getMessage());
}
return null;
} // getBackgroundColor
/**************************************************************************
* Insert tab.
* If the component is a JPanel, the backround is set to the default
* AdempiereColor (and Opaque) if nothing was defined.
* 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>,
* either of which may be <code>null</code>. If <code>icon</code>
* is non-<code>null</code> and it implements
* <code>ImageIcon</code> a corresponding disabled icon will automatically
* be created and set on the tabbedpane.
* Uses java.util.Vector internally, see <code>insertElementAt</code>
* for details of insertion conventions.
*
* @param text the title with Mnemonic to be displayed in this tab
* @param icon the icon to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
* @param tip the tooltip to be displayed for this tab
* @param index the position to insert this new tab
*/
public void insertTab (String text, Icon icon, Component component, String tip, int index)
{
String title = text;
if (!title.startsWith("<html>"))
{
int pos = title.indexOf("&");
if (pos != -1)
title = title.substring(0, pos) + title.substring(pos+1);
}
// Enforce Tool Tip
if (tip == null || tip.length() == 0)
tip = title;
super.insertTab (title, icon, component, tip, index);
// Set component background
if (component instanceof JPanel)
{
JPanel p = (JPanel)component;
if (p.getClientProperty(CompiereLookAndFeel.BACKGROUND) == null)
{
//AdempiereColor.setBackground(p);
//p.setOpaque(true);
}
}
// Set first
if (index == 0)
getActionMap().put(ACTION_SELECT, s_action);
//
if (!setMnemonicAt(index, text))
{ // Only one - set direct
if (index < 9)
setMnemonicAt(index, '1'+index);
else if (index == 9)
setMnemonicAt(index, '0');
}
else // additional ALT-1..0
{
if (index < 9)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_1+index, Event.ALT_MASK), ACTION_SELECT);
else if (index == 9)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_0, Event.ALT_MASK), ACTION_SELECT);
}
//
} // insertTab
/**
* Set Title At
* @param index index
* @param text title with opt Mnemonic
*/
public void setTitleAt (int index, String text)
{
String title = text;
if (!title.startsWith("<html>"))
{
int pos = title.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
title = title.substring(0, pos) + title.substring(pos+1);
}
super.setTitleAt (index, title);
// setMnemonicAt(index, text);
} // setTitleAt
/**
* Set Mnemonic for Index based on text
* @param index for index
* @param text text
*/
public boolean setMnemonicAt (int index, String text)
{
// logistics - remove old
while (m_mnemonic.size() < index+1)
m_mnemonic.add((char)0);
char keyCode = m_mnemonic.get(index);
if (keyCode != 0)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.remove(KeyStroke.getKeyStroke(keyCode, Event.ALT_MASK));
m_mnemonic.set(index, (char)0);
//
if (!text.startsWith("<html>"))
{
int pos = text.indexOf("&");
if (pos != -1 && text.length() > pos) // We have a nemonic - creates ALT-_
{
keyCode = text.toUpperCase().charAt(pos+1);
if (keyCode != ' ')
{
setMnemonicAt(index, keyCode);
m_mnemonic.set(index, keyCode);
return true;
}
}
}
/**
keyCode = text.toUpperCase().charAt(0);
if (m_mnemonic.contains(keyCode))
{
keyCode = 0;
// Beginning new word
int pos = text.indexOf(' ');
while (pos != -1 && text.length() > pos)
{
char c = text.toUpperCase().charAt(pos+1);
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
{
keyCode = c;
break;
}
pos = text.indexOf(' ', pos+1);
}
// Any character
if (keyCode == 0)
{
for (int i = 1; i < text.length(); i++)
{
char c = text.toUpperCase().charAt(i);
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
{
keyCode = c;
break;
}
}
}
// First character fallback
// if (mnemonic == 0)
// mnemonic = text.toUpperCase().charAt(0);
}
if (keyCode != 0)
{
setMnemonicAt(index, keyCode);
m_mnemonic.set(index, keyCode);
}
**/
return false;
} // setMnemonicAt
/** Used Mnemonics */
private ArrayList<Character> m_mnemonic = new ArrayList<Character>(10);
/**
* String representation
* @return String representation
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("CTabbedPane [");
sb.append(super.toString());
CompiereColor bg = getBackgroundColor();
if (bg != null)
sb.append(bg.toString());
sb.append("]");
return sb.toString();
} // toString
/** Select Action Text */
private static final String ACTION_SELECT = "CAS";
/** Select Action */
private static CTAction s_action = new CTAction(ACTION_SELECT);
/**
* Select Action
*
* @author Jorg Janke
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
private static class CTAction extends UIAction
{
/**
* Constructor
*/
public CTAction (String actionName)
{
super (actionName);
} // Action
public void actionPerformed (ActionEvent e)
{
String key = getName();
if (!key.equals(ACTION_SELECT)
|| !(e.getSource() instanceof CTabbedPane))
return;
CTabbedPane pane = (CTabbedPane)e.getSource();
String command = e.getActionCommand();
if (command == null || command.length() != 1)
return;
int index = command.charAt(0)-'1';
if (index > -1 && index < pane.getTabCount())
pane.setSelectedIndex(index);
else
System.out.println("Action: " + e);
} // actionPerformed
} // Action
} // CTabbedPane
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.CompiereColor;
import org.compiere.plaf.CompiereLookAndFeel;
import org.compiere.plaf.CompierePanelUI;
import org.compiere.util.Trace;
import sun.swing.*;
/**
* Adempiere Color Tabbed Pane
*
* @author Jorg Janke
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTabbedPane extends JTabbedPane
{
/**
* Creates an empty <code>TabbedPane</code> with a default
* tab placement of <code>JTabbedPane.TOP</code> and default
* tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
*/
public CTabbedPane()
{
super();
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with the specified tab placement
* of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>, and a
* default tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
*
* @param tabPlacement the placement for the tabs relative to the content
*/
public CTabbedPane(int tabPlacement)
{
super(tabPlacement);
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with the specified tab placement
* and tab layout policy. Tab placement may be either:
* <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
* Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code>
* or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>.
*
* @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
* @exception IllegalArgumentException if tab placement or tab layout policy are not
* one of the above supported values
*/
public CTabbedPane(int tabPlacement, int tabLayoutPolicy)
{
super (tabPlacement, tabLayoutPolicy);
init();
} // CTabbedPane
/**
* Creates an empty <code>TabbedPane</code> with a defaults and Color
* @param bg Color
*/
public CTabbedPane (CompiereColor bg)
{
super();
init();
setBackgroundColor (bg);
} // CTabbedPane
/**
* Common Init
*/
private void 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)
{
if (bg.equals(getBackground()))
return;
super.setBackground (bg);
// ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
if (!Trace.getCallerClass(1).startsWith("javax"))
setBackgroundColor (new CompiereColor(bg));
} // setBackground
/**
* Set Standard Background
*/
public void setBackgroundColor ()
{
setBackgroundColor (null);
} // setBackground
/**
* Set Background
* @param bg AdempiereColor for Background, if null set standard background
*/
public void setBackgroundColor (CompiereColor bg)
{
if (bg == null)
bg = CompierePanelUI.getDefaultBackground();
setOpaque(true);
putClientProperty(AdempierePLAF.BACKGROUND, bg);
super.setBackground (bg.getFlatColor());
//
repaint();
} // setBackground
/**
* Get Background
* @return Color for Background
*/
public CompiereColor getBackgroundColor ()
{
try
{
return (CompiereColor)getClientProperty(AdempierePLAF.BACKGROUND);
}
catch (Exception e)
{
System.err.println("ClientProperty: " + e.getMessage());
}
return null;
} // getBackgroundColor
/**************************************************************************
* Insert tab.
* If the component is a JPanel, the backround is set to the default
* AdempiereColor (and Opaque) if nothing was defined.
* 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>,
* either of which may be <code>null</code>. If <code>icon</code>
* is non-<code>null</code> and it implements
* <code>ImageIcon</code> a corresponding disabled icon will automatically
* be created and set on the tabbedpane.
* Uses java.util.Vector internally, see <code>insertElementAt</code>
* for details of insertion conventions.
*
* @param text the title with Mnemonic to be displayed in this tab
* @param icon the icon to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
* @param tip the tooltip to be displayed for this tab
* @param index the position to insert this new tab
*/
public void insertTab (String text, Icon icon, Component component, String tip, int index)
{
String title = text;
if (!title.startsWith("<html>"))
{
int pos = title.indexOf("&");
if (pos != -1)
title = title.substring(0, pos) + title.substring(pos+1);
}
// Enforce Tool Tip
if (tip == null || tip.length() == 0)
tip = title;
super.insertTab (title, icon, component, tip, index);
// Set component background
if (component instanceof JPanel)
{
JPanel p = (JPanel)component;
if (p.getClientProperty(AdempierePLAF.BACKGROUND) == null)
{
CompiereColor.setBackground(p);
p.setOpaque(true);
}
}
// Set first
if (index == 0)
getActionMap().put(ACTION_SELECT, s_action);
//
if (!setMnemonicAt(index, text))
{ // Only one - set direct
if (index < 9)
setMnemonicAt(index, '1'+index);
else if (index == 9)
setMnemonicAt(index, '0');
}
else // additional ALT-1..0
{
if (index < 9)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_1+index, Event.ALT_MASK), ACTION_SELECT);
else if (index == 9)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_0, Event.ALT_MASK), ACTION_SELECT);
}
//
} // insertTab
/**
* Set Title At
* @param index index
* @param text title with opt Mnemonic
*/
public void setTitleAt (int index, String text)
{
String title = text;
if (!title.startsWith("<html>"))
{
int pos = title.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
title = title.substring(0, pos) + title.substring(pos+1);
}
super.setTitleAt (index, title);
// setMnemonicAt(index, text);
} // setTitleAt
/**
* Set Mnemonic for Index based on text
* @param index for index
* @param text text
*/
public boolean setMnemonicAt (int index, String text)
{
// logistics - remove old
while (m_mnemonic.size() < index+1)
m_mnemonic.add((char)0);
char keyCode = m_mnemonic.get(index);
if (keyCode != 0)
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.remove(KeyStroke.getKeyStroke(keyCode, Event.ALT_MASK));
m_mnemonic.set(index, (char)0);
//
if (!text.startsWith("<html>"))
{
int pos = text.indexOf("&");
if (pos != -1 && text.length() > pos) // We have a nemonic - creates ALT-_
{
keyCode = text.toUpperCase().charAt(pos+1);
if (keyCode != ' ')
{
setMnemonicAt(index, keyCode);
m_mnemonic.set(index, keyCode);
return true;
}
}
}
/**
keyCode = text.toUpperCase().charAt(0);
if (m_mnemonic.contains(keyCode))
{
keyCode = 0;
// Beginning new word
int pos = text.indexOf(' ');
while (pos != -1 && text.length() > pos)
{
char c = text.toUpperCase().charAt(pos+1);
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
{
keyCode = c;
break;
}
pos = text.indexOf(' ', pos+1);
}
// Any character
if (keyCode == 0)
{
for (int i = 1; i < text.length(); i++)
{
char c = text.toUpperCase().charAt(i);
if (Character.isLetterOrDigit(c) && !m_mnemonic.contains(c))
{
keyCode = c;
break;
}
}
}
// First character fallback
// if (mnemonic == 0)
// mnemonic = text.toUpperCase().charAt(0);
}
if (keyCode != 0)
{
setMnemonicAt(index, keyCode);
m_mnemonic.set(index, keyCode);
}
**/
return false;
} // setMnemonicAt
/** Used Mnemonics */
private ArrayList<Character> m_mnemonic = new ArrayList<Character>(10);
/**
* String representation
* @return String representation
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("CTabbedPane [");
sb.append(super.toString());
CompiereColor bg = getBackgroundColor();
if (bg != null)
sb.append(bg.toString());
sb.append("]");
return sb.toString();
} // toString
/** Select Action Text */
private static final String ACTION_SELECT = "CAS";
/** Select Action */
private static CTAction s_action = new CTAction(ACTION_SELECT);
/**
* Select Action
*
* @author Jorg Janke
* @version $Id: CTabbedPane.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
private static class CTAction extends UIAction
{
/**
* Constructor
*/
public CTAction (String actionName)
{
super (actionName);
} // Action
public void actionPerformed (ActionEvent e)
{
String key = getName();
if (!key.equals(ACTION_SELECT)
|| !(e.getSource() instanceof CTabbedPane))
return;
CTabbedPane pane = (CTabbedPane)e.getSource();
String command = e.getActionCommand();
if (command == null || command.length() != 1)
return;
int index = command.charAt(0)-'1';
if (index > -1 && index < pane.getTabCount())
pane.setSelectedIndex(index);
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. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.compiere.util.*;
/**
* Model Independent enhanced JTable.
* Provides sizing and sorting
*
* @author Jorg Janke
* @version $Id: CTable.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTable extends JTable
{
/**
* Default Constructor
*/
public CTable()
{
super(new DefaultTableModel());
setColumnSelectionAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.compiere.util.*;
/**
* Model Independent enhanced JTable.
* Provides sizing and sorting
*
* @author Jorg Janke
* @version $Id: CTable.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTable extends JTable
{
/**
* Default Constructor
*/
public CTable()
{
super(new DefaultTableModel());
setColumnSelectionAllowed(false);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getTableHeader().addMouseListener(new CTableMouseListener());
setSurrendersFocusOnKeystroke(true);
//Default row height too narrow
setRowHeight(getFont().getSize() + 8);
} // CTable
/** Last model index sorted */
protected int p_lastSortIndex = -1;
/** Sort direction */
protected boolean p_asc = true;
/** Sizing: making sure it fits in a column */
private final int SLACK = 15;
/** Sizing: max size in pt */
private final int MAXSIZE = 250;
/** Model Index of Key Column */
protected int p_keyColumnIndex = -1;
/** Logger */
private static Logger log = Logger.getLogger(CTable.class.getName());
/**
* Set Model index of Key Column.
* Used for identifying previous selected row after fort complete to set as selected row.
* If not set, column 0 is used.
* @param keyColumnIndex model index
*/
public void setKeyColumnIndex (int keyColumnIndex)
{
p_keyColumnIndex = keyColumnIndex;
} // setKeyColumnIndex
/**
* Get Model index of Key Column
* @return model index
*/
public int getKeyColumnIndex()
{
return p_keyColumnIndex;
} // getKeyColumnIndex
/**
* Get Current Row Key Column Value
* @return value or null
*/
public Object getSelectedKeyColumnValue()
{
int row = getSelectedRow();
if (row != -1 && p_keyColumnIndex != -1)
return getModel().getValueAt(row, p_keyColumnIndex);
return null;
} // getKeyColumnValue
/**
* Get Selected Value or null
* @return value
*/
public Object getSelectedValue()
{
int row = getSelectedRow();
int col = getSelectedColumn();
if (row == -1 || col == -1)
return null;
return getValueAt(row, col);
} // getSelectedValue
/**
* Stop Table Editors and remove focus
* @param saveValue save value
*/
public void stopEditor (boolean saveValue)
{
// MultiRow - remove editors
ChangeEvent ce = new ChangeEvent(this);
if (saveValue)
editingStopped(ce);
else
editingCanceled(ce);
//
if (getInputContext() != null)
getInputContext().endComposition();
// change focus to next
transferFocus();
} // stopEditor
/**************************************************************************
* Size Columns.
* @param useColumnIdentifier if false uses plain content -
* otherwise uses Column Identifier to indicate displayed columns
*/
public void autoSize (boolean useColumnIdentifier)
{
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int c = 0; c < size; c++)
{
TableColumn column = getColumnModel().getColumn(c);
// Not displayed columns
if (useColumnIdentifier
&& (column.getIdentifier() == null
|| column.getMaxWidth() == 0
|| column.getIdentifier().toString().length() == 0))
continue;
int width = 0;
// Header
TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = null;
if (renderer != null)
comp = renderer.getTableCellRendererComponent
(this, column.getHeaderValue(), false, false, 0, 0);
//
if (comp != null)
{
width = comp.getPreferredSize().width;
width = Math.max(width, comp.getWidth());
// Cells
int col = column.getModelIndex();
int maxRow = Math.min(20, getRowCount());
try
{
for (int row = 0; row < maxRow; row++)
{
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent
(this, getValueAt(row, col), false, false, row, col);
int rowWidth = comp.getPreferredSize().width;
width = Math.max(width, rowWidth);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, column.getIdentifier().toString(), e);
}
// Width not greater than 250
width = Math.min(MAXSIZE, width + SLACK);
}
//
column.setPreferredWidth(width);
} // for all columns
} // autoSize
/**
* Sort Table
* @param modelColumnIndex model column sort index
*/
@SuppressWarnings("unchecked")
protected void sort (int modelColumnIndex)
{
int rows = getRowCount();
if (rows == 0)
return;
// other column
if (modelColumnIndex != p_lastSortIndex)
p_asc = true;
else
p_asc = !p_asc;
p_lastSortIndex = modelColumnIndex;
//
log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc);
// Selection
Object selected = null;
int selRow = getSelectedRow();
int selCol = p_keyColumnIndex == -1 ? 0 : p_keyColumnIndex; // used to identify current row
if (getSelectedRow() >= 0)
selected = getValueAt(selRow, selCol);
// Prepare sorting
DefaultTableModel model = (DefaultTableModel)getModel();
MSort sort = new MSort(0, null);
sort.setSortAsc(p_asc);
// while something to sort
sorting:
while (true)
{
// Create sortList
ArrayList<MSort> sortList = new ArrayList<MSort>(rows);
// fill with data entity
for (int i = 0; i < rows; i++)
{
Object value = model.getValueAt(i, modelColumnIndex);
sortList.add(new MSort(i, value));
}
// sort list it
Collections.sort(sortList, sort);
// move out of sequence row
for (int i = 0; i < rows; i++)
{
int index = ((MSort)sortList.get(i)).index;
if (i != index)
{
// log.config( "move " + i + " to " + index);
model.moveRow(i,i, index);
continue sorting;
}
}
// we are done
// log.config("done");
break;
} // while something to sort
// selection
clearSelection();
if (selected != null)
{
for (int r = 0; r < rows; r++)
{
if (selected.equals(getValueAt(r, selCol)))
{
setRowSelectionInterval(r,r);
break;
}
}
} // selected != null
} // sort
/**
* String Representation
* @return info
*/
public String toString()
{
return new StringBuffer("CTable[").append(getModel()).append("]").toString();
} // toString
/**************************************************************************
* MouseListener
*/
class CTableMouseListener extends MouseAdapter
{
/**
* Constructor
*/
public CTableMouseListener()
{
super();
} // CTableMouseListener
/**
* Mouse clicked
* @param e event
*/
public void mouseClicked (MouseEvent e)
{
int vc = getColumnModel().getColumnIndexAtX(e.getX());
// log.info( "Sort " + vc + "=" + getColumnModel().getColumn(vc).getHeaderValue());
int mc = convertColumnIndexToModel(vc);
sort(mc);
protected int p_lastSortIndex = -1;
/** Sort direction */
protected boolean p_asc = true;
/** Sizing: making sure it fits in a column */
private final int SLACK = 15;
/** Sizing: max size in pt */
private final int MAXSIZE = 250;
/** Model Index of Key Column */
protected int p_keyColumnIndex = -1;
/** Logger */
private static Logger log = Logger.getLogger(CTable.class.getName());
/**
* Set Model index of Key Column.
* Used for identifying previous selected row after fort complete to set as selected row.
* If not set, column 0 is used.
* @param keyColumnIndex model index
*/
public void setKeyColumnIndex (int keyColumnIndex)
{
p_keyColumnIndex = keyColumnIndex;
} // setKeyColumnIndex
/**
* Get Model index of Key Column
* @return model index
*/
public int getKeyColumnIndex()
{
return p_keyColumnIndex;
} // getKeyColumnIndex
/**
* Get Current Row Key Column Value
* @return value or null
*/
public Object getSelectedKeyColumnValue()
{
int row = getSelectedRow();
if (row != -1 && p_keyColumnIndex != -1)
return getModel().getValueAt(row, p_keyColumnIndex);
return null;
} // getKeyColumnValue
/**
* Get Selected Value or null
* @return value
*/
public Object getSelectedValue()
{
int row = getSelectedRow();
int col = getSelectedColumn();
if (row == -1 || col == -1)
return null;
return getValueAt(row, col);
} // getSelectedValue
/**
* Stop Table Editors and remove focus
* @param saveValue save value
*/
public void stopEditor (boolean saveValue)
{
// MultiRow - remove editors
ChangeEvent ce = new ChangeEvent(this);
if (saveValue)
editingStopped(ce);
else
editingCanceled(ce);
//
if (getInputContext() != null)
getInputContext().endComposition();
// change focus to next
transferFocus();
} // stopEditor
/**************************************************************************
* Size Columns.
* @param useColumnIdentifier if false uses plain content -
* otherwise uses Column Identifier to indicate displayed columns
*/
public void autoSize (boolean useColumnIdentifier)
{
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int c = 0; c < size; c++)
{
TableColumn column = getColumnModel().getColumn(c);
// Not displayed columns
if (useColumnIdentifier
&& (column.getIdentifier() == null
|| column.getMaxWidth() == 0
|| column.getIdentifier().toString().length() == 0))
continue;
int width = 0;
// Header
TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = null;
if (renderer != null)
comp = renderer.getTableCellRendererComponent
(this, column.getHeaderValue(), false, false, 0, 0);
//
if (comp != null)
{
width = comp.getPreferredSize().width;
width = Math.max(width, comp.getWidth());
// Cells
int col = column.getModelIndex();
int maxRow = Math.min(20, getRowCount());
try
{
for (int row = 0; row < maxRow; row++)
{
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent
(this, getValueAt(row, col), false, false, row, col);
int rowWidth = comp.getPreferredSize().width;
width = Math.max(width, rowWidth);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, column.getIdentifier().toString(), e);
}
// Width not greater than 250
width = Math.min(MAXSIZE, width + SLACK);
}
//
column.setPreferredWidth(width);
} // for all columns
} // autoSize
/**
* Sort Table
* @param modelColumnIndex model column sort index
*/
@SuppressWarnings("unchecked")
protected void sort (int modelColumnIndex)
{
int rows = getRowCount();
if (rows == 0)
return;
// other column
if (modelColumnIndex != p_lastSortIndex)
p_asc = true;
else
p_asc = !p_asc;
p_lastSortIndex = modelColumnIndex;
//
log.config("#" + modelColumnIndex + " - rows=" + rows + ", asc=" + p_asc);
// Selection
Object selected = null;
int selRow = getSelectedRow();
int selCol = p_keyColumnIndex == -1 ? 0 : p_keyColumnIndex; // used to identify current row
if (getSelectedRow() >= 0)
selected = getValueAt(selRow, selCol);
// Prepare sorting
DefaultTableModel model = (DefaultTableModel)getModel();
MSort sort = new MSort(0, null);
sort.setSortAsc(p_asc);
// while something to sort
sorting:
while (true)
{
// Create sortList
ArrayList<MSort> sortList = new ArrayList<MSort>(rows);
// fill with data entity
for (int i = 0; i < rows; i++)
{
Object value = model.getValueAt(i, modelColumnIndex);
sortList.add(new MSort(i, value));
}
// sort list it
Collections.sort(sortList, sort);
// move out of sequence row
for (int i = 0; i < rows; i++)
{
int index = ((MSort)sortList.get(i)).index;
if (i != index)
{
// log.config( "move " + i + " to " + index);
model.moveRow(i,i, index);
continue sorting;
}
}
// we are done
// log.config("done");
break;
} // while something to sort
// selection
clearSelection();
if (selected != null)
{
for (int r = 0; r < rows; r++)
{
if (selected.equals(getValueAt(r, selCol)))
{
setRowSelectionInterval(r,r);
break;
}
}
} // selected != null
} // sort
/**
* String Representation
* @return info
*/
public String toString()
{
return new StringBuffer("CTable[").append(getModel()).append("]").toString();
} // toString
/**************************************************************************
* MouseListener
*/
class CTableMouseListener extends MouseAdapter
{
/**
* Constructor
*/
public CTableMouseListener()
{
super();
} // CTableMouseListener
/**
* Mouse clicked
* @param e event
*/
public void mouseClicked (MouseEvent e)
{
int vc = getColumnModel().getColumnIndexAtX(e.getX());
// log.info( "Sort " + vc + "=" + getColumnModel().getColumn(vc).getHeaderValue());
int mc = convertColumnIndexToModel(vc);
sort(mc);
}
} // CTableMouseListener
@Override
public void setFont(Font font) {
super.setFont(font);
//Update row height
setRowHeight(getFont().getSize() + 8);
}
} // CTable

View File

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

View File

@ -1,254 +1,262 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
/**
* Adempiere Text Field
*
* @author Jorg Janke
* @version $Id: CTextField.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTextField extends JTextField
implements CEditor, KeyListener
{
/**
* Constructs a new <code>TextField</code>. A default model is created,
* the initial string is <code>null</code>,
* and the number of columns is set to 0.
*/
public CTextField()
{
super();
init();
} // CTextField
/**
* Constructs a new <code>TextField</code> initialized with the
* specified text. A default model is created and the number of
* columns is 0.
*
* @param text the text to be displayed, or <code>null</code>
*/
public CTextField (String text)
{
super (text);
init();
} // CTextField
/**
* Constructs a new empty <code>TextField</code> with the specified
* number of columns.
* A default model is created and the initial string is set to
* <code>null</code>.
*
* @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CTextField (int columns)
{
super (columns);
init();
} // CTextField
/**
* Constructs a new <code>TextField</code> initialized with the
* specified text and columns. A default model is created.
*
* @param text the text to be displayed, or <code>null</code>
* @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CTextField (String text, int columns)
{
super (text, columns);
init();
} // CTextField
/**
* Constructs a new <code>JTextField</code> that uses the given text
* storage model and the given number of columns.
* This is the constructor through which the other constructors feed.
* 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>,
* a default will be provided by calling the
* <code>createDefaultModel</code> method
* @param text the initial string to display, or <code>null</code>
* @param columns the number of columns to use to calculate
* the preferred width >= 0; if <code>columns</code>
* is set to zero, the preferred width will be whatever
* naturally results from the component implementation
* @exception IllegalArgumentException if <code>columns</code> < 0
*/
public CTextField (Document doc, String text, int columns)
{
super (doc, text, columns);
init();
} // CTextField
/**
* Initialization
*/
private void init()
{
setBackground (false);
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEditable() != rw)
super.setEditable (rw);
setBackground(false);
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return super.isEditable();
} // isReadWrite
/**
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param bg background
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return getText();
} // getDisplay
/**
* key Pressed
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
* @param e
*/
public void keyPressed(KeyEvent e)
{
} // keyPressed
/**
* key Released
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
* @param e
*/
public void keyReleased(KeyEvent e)
{
} // keyReleased
/**
* key Typed
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
* @param e
*/
public void keyTyped(KeyEvent e)
{
} // keyTyped
} // CTextField
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
/**
* Adempiere Text Field
*
* @author Jorg Janke
* @version $Id: CTextField.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTextField extends JTextField
implements CEditor, KeyListener
{
/**
* Constructs a new <code>TextField</code>. A default model is created,
* the initial string is <code>null</code>,
* and the number of columns is set to 0.
*/
public CTextField()
{
super();
init();
} // CTextField
/**
* Constructs a new <code>TextField</code> initialized with the
* specified text. A default model is created and the number of
* columns is 0.
*
* @param text the text to be displayed, or <code>null</code>
*/
public CTextField (String text)
{
super (text);
init();
} // CTextField
/**
* Constructs a new empty <code>TextField</code> with the specified
* number of columns.
* A default model is created and the initial string is set to
* <code>null</code>.
*
* @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CTextField (int columns)
{
super (columns);
init();
} // CTextField
/**
* Constructs a new <code>TextField</code> initialized with the
* specified text and columns. A default model is created.
*
* @param text the text to be displayed, or <code>null</code>
* @param columns the number of columns to use to calculate
* the preferred width; if columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation
*/
public CTextField (String text, int columns)
{
super (text, columns);
init();
} // CTextField
/**
* Constructs a new <code>JTextField</code> that uses the given text
* storage model and the given number of columns.
* This is the constructor through which the other constructors feed.
* 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>,
* a default will be provided by calling the
* <code>createDefaultModel</code> method
* @param text the initial string to display, or <code>null</code>
* @param columns the number of columns to use to calculate
* the preferred width >= 0; if <code>columns</code>
* is set to zero, the preferred width will be whatever
* naturally results from the component implementation
* @exception IllegalArgumentException if <code>columns</code> < 0
*/
public CTextField (Document doc, String text, int columns)
{
super (doc, text, columns);
init();
} // CTextField
/**
* Initialization
*/
private void init()
{
setFont(AdempierePLAF.getFont_Field());
setForeground(AdempierePLAF.getTextColor_Normal());
setBackground (false);
// Minimum Size
Dimension size = getPreferredSize();
if (size != null)
size = new Dimension (20,10);
size.width = 30;
setMinimumSize(size);
} // init
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (super.isEditable() != rw)
super.setEditable (rw);
setBackground(false);
} // setEditable
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean isReadWrite()
{
return super.isEditable();
} // isReadWrite
/**
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param bg background
*/
public void setBackground (Color bg)
{
if (bg.equals(getBackground()))
return;
super.setBackground(bg);
} // setBackground
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
setText("");
else
setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return getText();
} // getDisplay
/**
* key Pressed
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
* @param e
*/
public void keyPressed(KeyEvent e)
{
} // keyPressed
/**
* key Released
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
* @param e
*/
public void keyReleased(KeyEvent e)
{
} // keyReleased
/**
* 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 *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.awt.im.*;
import javax.swing.*;
import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
/**
* Adempiere TextPane - A ScrollPane with a JTextPane.
* Manages visibility, opaque and color consistently *
* @author Jorg Janke
* @version $Id: CTextPane.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTextPane extends JScrollPane
implements CEditor
{
/**
* Constructs a new TextPane (HTML)
*/
public CTextPane()
{
this (new JTextPane());
} // CTextPane
/**
* Constructs a new JTextPane with the given document
* @param doc the model to use
*/
public CTextPane (StyledDocument doc)
{
this (new JTextPane (doc));
} // CTextPane
/**
* Create a JScrollArea with a JTextEditor
* @param textPane
*/
public CTextPane (JTextPane textPane)
{
super (textPane);
m_textPane = textPane;
super.setOpaque(false);
super.getViewport().setOpaque(false);
m_textPane.setContentType("text/html");
} // CTextPane
private JTextPane m_textPane = null;
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (m_textPane.isEditable() != rw)
m_textPane.setEditable (rw);
setBackground(false);
} // setReadWrite
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean 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
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param color color
*/
public void setBackground (Color color)
{
if (color.equals(getBackground()))
return;
if (m_textPane == null) // during init
super.setBackground(color);
else
m_textPane.setBackground(color);
} // setBackground
/**
* Get Background
* @return color
*/
public Color getBackground ()
{
if (m_textPane == null) // during init
return super.getBackground();
else
return m_textPane.getBackground();
} // getBackground
/**
* Set Foreground
* @param color color
*/
public void setForeground (Color color)
{
if (m_textPane == null) // during init
super.setForeground(color);
else
m_textPane.setForeground(color);
} // setForeground
/**
* Get Foreground
* @return color
*/
public Color getForeground ()
{
if (m_textPane == null) // during init
return super.getForeground();
else
return m_textPane.getForeground();
} // getForeground
/**
* Set Content Type
* @param type e.g. text/html
*/
public void setContentType (String type)
{
if (m_textPane != null) // during init
m_textPane.setContentType(type);
} // setContentType
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
m_textPane.setText("");
else
m_textPane.setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return m_textPane.getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return m_textPane.getText();
} // getDisplay
/**************************************************************************
* Set Text and position top
* @param text
*/
public void setText (String text)
{
m_textPane.setText(text);
m_textPane.setCaretPosition(0);
}
/**
* Get Text
* @return text
*/
public String getText()
{
return m_textPane.getText();
}
/**
* Set Caret Position
* @param pos pos
*/
public void setCaretPosition (int pos)
{
m_textPane.setCaretPosition (pos);
}
/**
* Get Caret Position
* @return position
*/
public int getCaretPosition()
{
return m_textPane.getCaretPosition();
}
/**
* Set Editable
* @param edit editable
*/
public void setEditable (boolean edit)
{
m_textPane.setEditable(edit);
}
/**
* Editable
* @return true if editable
*/
public boolean isEditable()
{
return m_textPane.isEditable();
}
/**
* Set Text Margin
* @param m insets
*/
public void setMargin (Insets m)
{
if (m_textPane != null)
m_textPane.setMargin(m);
} // setMargin
/**
* Set Opaque
* @param isOpaque opaque
*/
public void setOpaque (boolean isOpaque)
{
// JScrollPane & Viewport is always not Opaque
if (m_textPane == null) // during init of JScrollPane
super.setOpaque(isOpaque);
else
m_textPane.setOpaque(isOpaque);
} // setOpaque
/**
* Add Focus Listener
* @param l listener
*/
public void addFocusListener (FocusListener l)
{
if (m_textPane == null) // during init
super.addFocusListener(l);
else
m_textPane.addFocusListener(l);
}
/**
* Add Mouse Listener
* @param l listner
*/
public void addMouseListener (MouseListener l)
{
m_textPane.addMouseListener(l);
}
/**
* Add Key Listener
* @param l listner
*/
public void addKeyListener (KeyListener l)
{
m_textPane.addKeyListener(l);
}
/**
* Add Input Method Listener
* @param l listener
*/
public void addInputMethodListener (InputMethodListener l)
{
m_textPane.addInputMethodListener(l);
}
/**
* Get Input Method Requests
* @return requests
*/
public InputMethodRequests getInputMethodRequests()
{
return m_textPane.getInputMethodRequests();
}
/**
* Set Input Verifier
* @param l verifyer
*/
public void setInputVerifier (InputVerifier l)
{
m_textPane.setInputVerifier(l);
}
} // CTextPane
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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 *
* 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 *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* 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 *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.swing;
import java.awt.*;
import java.awt.event.*;
import java.awt.im.*;
import javax.swing.*;
import javax.swing.text.*;
import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*;
/**
* Adempiere TextPane - A ScrollPane with a JTextPane.
* Manages visibility, opaque and color consistently *
* @author Jorg Janke
* @version $Id: CTextPane.java,v 1.3 2006/07/30 00:52:24 jjanke Exp $
*/
public class CTextPane extends JScrollPane
implements CEditor
{
/**
* Constructs a new TextPane (HTML)
*/
public CTextPane()
{
this (new JTextPane());
} // CTextPane
/**
* Constructs a new JTextPane with the given document
* @param doc the model to use
*/
public CTextPane (StyledDocument doc)
{
this (new JTextPane (doc));
} // CTextPane
/**
* Create a JScrollArea with a JTextEditor
* @param textPane
*/
public CTextPane (JTextPane textPane)
{
super (textPane);
m_textPane = textPane;
super.setOpaque(false);
super.getViewport().setOpaque(false);
m_textPane.setContentType("text/html");
m_textPane.setFont(AdempierePLAF.getFont_Field());
m_textPane.setForeground(AdempierePLAF.getTextColor_Normal());
} // CTextPane
private JTextPane m_textPane = null;
/*************************************************************************/
/** Mandatory (default false) */
private boolean m_mandatory = false;
/**
* Set Editor Mandatory
* @param mandatory true, if you have to enter data
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
setBackground(false);
} // setMandatory
/**
* Is Field mandatory
* @return true, if mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Enable Editor
* @param rw true, if you can enter/select data
*/
public void setReadWrite (boolean rw)
{
if (m_textPane.isEditable() != rw)
m_textPane.setEditable (rw);
setBackground(false);
} // setReadWrite
/**
* Is it possible to edit
* @return true, if editable
*/
public boolean 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
*/
public void setBackground (boolean error)
{
if (error)
setBackground(AdempierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(AdempierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(AdempierePLAF.getFieldBackground_Mandatory());
else
setBackground(AdempierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Background
* @param color color
*/
public void setBackground (Color color)
{
if (color.equals(getBackground()))
return;
if (m_textPane == null) // during init
super.setBackground(color);
else
m_textPane.setBackground(color);
} // setBackground
/**
* Get Background
* @return color
*/
public Color getBackground ()
{
if (m_textPane == null) // during init
return super.getBackground();
else
return m_textPane.getBackground();
} // getBackground
/**
* Set Foreground
* @param color color
*/
public void setForeground (Color color)
{
if (m_textPane == null) // during init
super.setForeground(color);
else
m_textPane.setForeground(color);
} // setForeground
/**
* Get Foreground
* @return color
*/
public Color getForeground ()
{
if (m_textPane == null) // during init
return super.getForeground();
else
return m_textPane.getForeground();
} // getForeground
/**
* Set Content Type
* @param type e.g. text/html
*/
public void setContentType (String type)
{
if (m_textPane != null) // during init
m_textPane.setContentType(type);
} // setContentType
/**
* Set Editor to value
* @param value value of the editor
*/
public void setValue (Object value)
{
if (value == null)
m_textPane.setText("");
else
m_textPane.setText(value.toString());
} // setValue
/**
* Return Editor value
* @return current value
*/
public Object getValue()
{
return m_textPane.getText();
} // getValue
/**
* Return Display Value
* @return displayed String value
*/
public String getDisplay()
{
return m_textPane.getText();
} // getDisplay
/**************************************************************************
* Set Text and position top
* @param text
*/
public void setText (String text)
{
m_textPane.setText(text);
m_textPane.setCaretPosition(0);
}
/**
* Get Text
* @return text
*/
public String getText()
{
return m_textPane.getText();
}
/**
* Set Caret Position
* @param pos pos
*/
public void setCaretPosition (int pos)
{
m_textPane.setCaretPosition (pos);
}
/**
* Get Caret Position
* @return position
*/
public int getCaretPosition()
{
return m_textPane.getCaretPosition();
}
/**
* Set Editable
* @param edit editable
*/
public void setEditable (boolean edit)
{
m_textPane.setEditable(edit);
}
/**
* Editable
* @return true if editable
*/
public boolean isEditable()
{
return m_textPane.isEditable();
}
/**
* Set Text Margin
* @param m insets
*/
public void setMargin (Insets m)
{
if (m_textPane != null)
m_textPane.setMargin(m);
} // setMargin
/**
* Set Opaque
* @param isOpaque opaque
*/
public void setOpaque (boolean isOpaque)
{
// JScrollPane & Viewport is always not Opaque
if (m_textPane == null) // during init of JScrollPane
super.setOpaque(isOpaque);
else
m_textPane.setOpaque(isOpaque);
} // setOpaque
/**
* Add Focus Listener
* @param l listener
*/
public void addFocusListener (FocusListener l)
{
if (m_textPane == null) // during init
super.addFocusListener(l);
else
m_textPane.addFocusListener(l);
}
/**
* Add Mouse Listener
* @param l listner
*/
public void addMouseListener (MouseListener l)
{
m_textPane.addMouseListener(l);
}
/**
* Add Key Listener
* @param l listner
*/
public void addKeyListener (KeyListener l)
{
m_textPane.addKeyListener(l);
}
/**
* Add Input Method Listener
* @param l listener
*/
public void addInputMethodListener (InputMethodListener l)
{
m_textPane.addInputMethodListener(l);
}
/**
* Get Input Method Requests
* @return requests
*/
public InputMethodRequests getInputMethodRequests()
{
return m_textPane.getInputMethodRequests();
}
/**
* Set Input Verifier
* @param l verifyer
*/
public void setInputVerifier (InputVerifier l)
{
m_textPane.setInputVerifier(l);
}
} // CTextPane

View File

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