From 110f14a7f5f79d11ec6988cf804bdd6fbf3eda51 Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Thu, 7 Dec 2006 03:24:12 +0000 Subject: [PATCH] Adempiere 3.1.2 --- .../src/org/adempiere/plaf/AdempierePLAF.java | 9 + .../src/org/compiere/plaf/CompiereColor.java | 2506 +++++++++-------- .../compiere/plaf/CompiereLookAndFeel.java | 369 ++- .../org/compiere/plaf/CompierePanelUI.java | 47 +- .../compiere/plaf/CompiereTabbedPaneUI.java | 8 +- .../compiere/plaf/CompiereTableHeaderUI.java | 191 +- .../src/org/compiere/plaf/CompiereTheme.java | 864 ++++-- .../src/org/compiere/plaf/CompiereUtils.java | 8 +- looks/src/org/compiere/swing/CButton.java | 581 ++-- looks/src/org/compiere/swing/CCheckBox.java | 596 ++-- looks/src/org/compiere/swing/CComboBox.java | 670 ++--- looks/src/org/compiere/swing/CDialog.java | 519 ++-- looks/src/org/compiere/swing/CFrame.java | 235 +- looks/src/org/compiere/swing/CLabel.java | 566 ++-- looks/src/org/compiere/swing/CPanel.java | 394 +-- looks/src/org/compiere/swing/CPassword.java | 430 +-- looks/src/org/compiere/swing/CScrollPane.java | 9 +- looks/src/org/compiere/swing/CTabbedPane.java | 752 ++--- looks/src/org/compiere/swing/CTable.java | 590 ++-- looks/src/org/compiere/swing/CTextArea.java | 926 +++--- looks/src/org/compiere/swing/CTextField.java | 516 ++-- looks/src/org/compiere/swing/CTextPane.java | 702 ++--- .../src/org/compiere/swing/CToggleButton.java | 535 ++-- looks/src/org/compiere/util/Ini.java | 4 +- 24 files changed, 6209 insertions(+), 5818 deletions(-) diff --git a/looks/src/org/adempiere/plaf/AdempierePLAF.java b/looks/src/org/adempiere/plaf/AdempierePLAF.java index 483bfc6162..4a4d4bc5b1 100644 --- a/looks/src/org/adempiere/plaf/AdempierePLAF.java +++ b/looks/src/org/adempiere/plaf/AdempierePLAF.java @@ -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 *******************************************************/ diff --git a/looks/src/org/compiere/plaf/CompiereColor.java b/looks/src/org/compiere/plaf/CompiereColor.java index ff35fe6117..1d26ea91e9 100644 --- a/looks/src/org/compiere/plaf/CompiereColor.java +++ b/looks/src/org/compiere/plaf/CompiereColor.java @@ -1,1238 +1,1268 @@ -/****************************************************************************** - * 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.*; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.logging.*; -import javax.swing.*; -import javax.swing.plaf.*; - -import org.adempiere.plaf.AdempierePLAF; -import org.compiere.swing.ColorBlind; -import org.compiere.swing.ThemeUtils; -import org.compiere.util.*; - -/** - * Adempiere Background Color - * - * @author Jorg Janke - * @version $Id: AdempiereColor.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ - */ -public class CompiereColor implements Serializable -{ - /** Background type Flat */ - public static final String TYPE_FLAT = "F"; - /** Background type Gradient */ - public static final String TYPE_GRADIENT = "G"; - /** Background type Lines */ - public static final String TYPE_LINES = "L"; - /** Background type Texture */ - public static final String TYPE_TEXTURE = "T"; - - /** Names */ - private static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes"); - - /** Type Values */ - public static final String[] TYPE_VALUES = new String[] { - TYPE_FLAT, TYPE_GRADIENT, TYPE_LINES, TYPE_TEXTURE - }; - /** Type Names */ - public static final String[] TYPE_NAMES = new String[] { - s_res.getString("BackColType_Flat"), - s_res.getString("BackColType_Gradient"), - s_res.getString("BackColType_Lines"), - s_res.getString("BackColType_Texture") - }; - /** Types */ - public static final ValueNamePair[] TYPES = new ValueNamePair[] { - new ValueNamePair(TYPE_VALUES[0], TYPE_NAMES[0]), - new ValueNamePair(TYPE_VALUES[1], TYPE_NAMES[1]), - new ValueNamePair(TYPE_VALUES[2], TYPE_NAMES[2]), - new ValueNamePair(TYPE_VALUES[3], TYPE_NAMES[3]) - }; - - /** Gradient Starting Values */ - public static final int[] GRADIENT_SP_VALUES = new int[] { - SwingConstants.NORTH, SwingConstants.NORTH_EAST, - SwingConstants.EAST, SwingConstants.SOUTH_EAST, - SwingConstants.SOUTH, SwingConstants.SOUTH_WEST, - SwingConstants.WEST, SwingConstants.NORTH_WEST - }; - /** Gradient Starting Names */ - public static final String[] GRADIENT_SP_NAMES = new String[] { - "North", "North-East", - "East", "South-East", - "South", "South-West", - "West", "North-West" - }; - /** Gradient Starting Point */ - public static final KeyNamePair[] GRADIENT_SP = new KeyNamePair[] { - new KeyNamePair(GRADIENT_SP_VALUES[0], GRADIENT_SP_NAMES[0]), - new KeyNamePair(GRADIENT_SP_VALUES[1], GRADIENT_SP_NAMES[1]), - new KeyNamePair(GRADIENT_SP_VALUES[2], GRADIENT_SP_NAMES[2]), - new KeyNamePair(GRADIENT_SP_VALUES[3], GRADIENT_SP_NAMES[3]), - new KeyNamePair(GRADIENT_SP_VALUES[4], GRADIENT_SP_NAMES[4]), - new KeyNamePair(GRADIENT_SP_VALUES[5], GRADIENT_SP_NAMES[5]), - new KeyNamePair(GRADIENT_SP_VALUES[6], GRADIENT_SP_NAMES[6]), - new KeyNamePair(GRADIENT_SP_VALUES[7], GRADIENT_SP_NAMES[7]) - }; - /** Exception text */ - private static final String EXCEPTION_TEXT = "Arguments cannot be NULL"; - - - /************************************************************************** - * Set Background of Component to default color - * @param c component - */ - public static void setBackground (JComponent c) - { - setBackground (c, new CompiereColor(AdempierePLAF.getFormBackground())); - } // setBackground - - /** - * Set Background of Component - * @param c Component - * @param cc Color - */ - public static void setBackground (JComponent c, CompiereColor cc) - { - c.putClientProperty(CompiereLookAndFeel.BACKGROUND, cc); - } // setBackground - - /** - * Get Background Color of component - * @param c JComponent - * @return Color - */ - public static CompiereColor getBackground (JComponent c) - { - CompiereColor bg = null; - try - { - bg = (CompiereColor)c.getClientProperty(CompiereLookAndFeel.BACKGROUND); - } - catch (Exception e) - { - log.severe("ClientProperty: " + e.getMessage()); - } - return bg; - } // getBackground - - /** - * Set Background of Window Content Pane to default color - * @param win window - */ - public static void setBackground (Window win) - { - setBackground (win, new CompiereColor(AdempierePLAF.getFormBackground())); - } // setBackground - - /** - * Set Background of Window Content Pane - * @param win window - * @param cc adempiere color - */ - public static void setBackground (Window win, CompiereColor cc) - { - if (win instanceof JDialog) - { - ((JPanel)((JDialog)win).getContentPane()).putClientProperty(CompiereLookAndFeel.BACKGROUND, cc); - // ((JPanel)((JDialog)win).getContentPane()).setName("contentPane"); - } - else if (win instanceof JFrame) - { - ((JPanel)((JFrame)win).getContentPane()).putClientProperty(CompiereLookAndFeel.BACKGROUND, cc); - // ((JPanel)((JFrame)win).getContentPane()).setName("contentPane"); - } - else if (win instanceof JWindow) - { - ((JPanel)((JWindow)win).getContentPane()).putClientProperty(CompiereLookAndFeel.BACKGROUND, cc); - // ((JPanel)((JWindow)win).getContentPane()).setName("contentPane"); - } - } // setBackground - - /** - * Get Default Background - * @return Background - * @see CompierePanelUI#getDefaultBackground - */ - public static CompiereColor getDefaultBackground() - { - return new CompiereColor(AdempierePLAF.getFormBackground()); - } // getDefaultBackground - - /** - * Parse attributes and return AdempiereColor - * @param attributes attributes - * @return AdempiereColor - */ - public static CompiereColor parse (String attributes) - { - CompiereColor cc = new CompiereColor (); - try - { - if (attributes != null && attributes.length() > 0) - cc.parseAttributres (attributes); - } - catch (Exception e) - { - log.severe("(" + attributes + ") - " + e.toString()); - } - return cc; - } // parse - - - /************************************************************************* - * Create Gradient Background Color (Window System Color - White) - */ - public CompiereColor() - { - this (TYPE_GRADIENT); - } // AdempiereColor - - /** - * Create Default Background Colors of Type - * @param type Background type (see constants TYPE_*) - */ - public CompiereColor (String type) - { - if (type == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - if (type.equals(TYPE_FLAT) || type.equals(TYPE_GRADIENT) - || type.equals(TYPE_TEXTURE) || type.equals(TYPE_LINES)) - { - m_type = type; - } - else - new java.lang.IllegalArgumentException ("Invalid Type"); - } // AdempiereColor - - /** - * Create Flat Background Color - * @param bg background - */ - public CompiereColor (Color bg) - { - this (bg, true); - } // AdempiereColor - - /** - * Create Background Color - * @param bg Color - * @param flat if true create Flat color otherwise Gradient color with white lower color - */ - public CompiereColor (Color bg, boolean flat) - { - if (bg == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - m_type = flat ? TYPE_FLAT : TYPE_GRADIENT; - m_primaryColor = bg; - } // AdempiereColor - - /** - * Set Background to Gradient colors - * @param upperColor upper Color - * @param lowerColor lower Color - * @param startPoint Starting point - e.g. SOUTH_WEST see SwingConstants, default NORTH_WEST - * @param repeatDistance X/Y Distance to repeat gradient in points - 0 no repeats - */ - public CompiereColor (Color upperColor, Color lowerColor, int startPoint, int repeatDistance) - { - if (upperColor == null || lowerColor == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - m_type = TYPE_GRADIENT; - m_primaryColor = upperColor; - m_secondaryColor = lowerColor; - m_startPoint = startPoint; - m_repeatDistance = repeatDistance; - } // AdempiereColor - - /** - * Set Background to Gradient colors. - * Starting in the north, repeat after 100 pt - * @param upperColor upper color - * @param lowerColor lower color - */ - public CompiereColor (Color upperColor, Color lowerColor) - { - this (upperColor, lowerColor, SwingConstants.NORTH_WEST, 100); - } // AdempiereColor - - /** - * Set Background to Texture - * - * @param textureURL URL to a *.gif or *.jpg graphic file - * @param taint Color to taint the texture (use white for not tainting it) - * @param compositeAlpha Value from 0(no) to 1(full) taining - */ - public CompiereColor (URL textureURL, Color taint, float compositeAlpha) - { - if (textureURL == null || taint == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - m_type = TYPE_TEXTURE; - m_textureURL = textureURL; - m_primaryColor = taint; - m_compositeAlpha = compositeAlpha; - } // AdempiereColor - - /** - * Set Background to Texture - * - * @param textureURL URL to a *.gif or *.jpg graphic file - * @param taint Color to taint the texture (use white for not tainting it) - * @param compositeAlpha Tainting value from 0 (no - FullGraph) to 1 (full - NoGraph) - */ - public CompiereColor (String textureURL, Color taint, float compositeAlpha) - { - if (textureURL == null || taint == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - m_type = TYPE_TEXTURE; - setTextureURL(textureURL); - m_primaryColor = taint; - m_compositeAlpha = compositeAlpha; - } // AdempiereColor - - /** - * Set Background to Lines - * - * @param lineColor line color - * @param backColor background color - * @param lineWidth Stroke width in point - * @param lineDistance Distance between lines in points - */ - public CompiereColor (Color lineColor, Color backColor, float lineWidth, int lineDistance) - { - if (lineColor == null || backColor == null) - new java.lang.IllegalArgumentException (EXCEPTION_TEXT); - m_type = TYPE_LINES; - m_primaryColor = backColor; - m_secondaryColor = lineColor; - m_lineWidth = lineWidth; - m_lineDistance = lineDistance; - } // AdempiereColor - - /** - * Copy Color - * @param cc color - */ - public CompiereColor (CompiereColor cc) - { - if (cc == null) - return; - setColor(cc); - } // AdempiereColor - - /*************************************************************************/ - - /** Type - Default: Gradient */ - private String m_type = TYPE_GRADIENT; - - /** Primary Color - Default Panel back */ - private Color m_primaryColor = UIManager.getColor("Panel.background"); - /** Secondary Color - Default: gray-white */ - private Color m_secondaryColor = new Color (245, 245, 245); - - /** Texture Graph URL */ - private URL m_textureURL = null; - /** Texture Graph */ - private BufferedImage m_image = null; - /** Texture Alpha - Default: 0.7 */ - private float m_compositeAlpha = 0.7f; - - /** Line Width - Default: 1 */ - private float m_lineWidth = 1.0f; - /** Line Distance - Default: 5 */ - private int m_lineDistance = 5; - - /** Gradient Starting point - Default: NORTH_WEST */ - private int m_startPoint = SwingConstants.NORTH_WEST; - /** Gradient repeat distance in points - Default: 100 */ - private int m_repeatDistance = 100; - - /** Background */ - private ColorBackground m_back = null; - /** 3D Look */ - private boolean m_3d = true; - - /** Diry marker for repaining Background */ - private boolean m_dirty = true; - /** Logger */ - private static Logger log = Logger.getLogger(CompiereColor.class.getName()); - - /************************************************************************** - * Get BackgroundType (Flat, Gradient, Lines, Texture) - * @return Background Type (see TYPE_* constants) - */ - public String getType() - { - return m_type; - } // getType - - /** - * Flat Background Type (default) - * @return true if Flat background - */ - public boolean isFlat() - { - return TYPE_FLAT.equals(getType()); - } // isFlat - - /** - * Gradient Background Type - * @return true if Gradient background - */ - public boolean isGradient() - { - return TYPE_GRADIENT.equals(getType()); - } // isGradient - - /** - * Line Background Type - * @return true if Line background - */ - public boolean isLine() - { - return TYPE_LINES.equals(getType()); - } // isLine - - /** - * Texture Background Type - * @return true if Texture background - */ - public boolean isTexture() - { - return TYPE_TEXTURE.equals(getType()); - } // isTexture - - - /************************ - * Get Flat Color - * @return Primary Color - */ - public Color getFlatColor() - { - return m_primaryColor; - } // getFlatColor - - /** - * Set Flat Color - * @param color flat color - */ - public void setFlatColor(Color color) - { - if (!isFlat() || color == null) - return; - m_primaryColor = color; - m_dirty = true; - } // getFlatColor - - - /************************ - * Gradient Upper Color - * @return Color or null - */ - public Color getGradientUpperColor() - { - if (!isGradient()) - return null; - return m_primaryColor; - } // getGradientUpperColor - - /** - * Gradient Upper Color - * @param color upper color - */ - public void setGradientUpperColor(Color color) - { - if (!isGradient() || color == null) - return; - m_primaryColor = color; - m_dirty = true; - } // getGradientUpperColor - - /** - * Gradient Lower Color - * @return Color or null - */ - public Color getGradientLowerColor() - { - if (!isGradient()) - return null; - return m_secondaryColor; - } // getGradientLowerColor - - /** - * Gradient Lower Color - * @param color lower color - */ - public void setGradientLowerColor(Color color) - { - if (!isGradient() || color == null) - return; - m_secondaryColor = color; - m_dirty = true; - } // setGradientLowerColor - - /** - * Gradient Starting Point - * @return starting point - e.g. NORTH - or 0 - * @see SwingConstants - */ - public int getGradientStartPoint () - { - if (!isGradient()) - return 0; - return m_startPoint; - } // getGradientStartPoint - - /** - * Gradient Starting Point - * @param startPoint starting point - e.g. NORTH - * @see SwingConstants - */ - public void setGradientStartPoint (int startPoint) - { - if (!isGradient()) - return; - m_startPoint = startPoint; - m_dirty = true; - } // setGradientStartPoint - - /** - * Gradient Repeat Distance in point - * @return Repeat Distance - or 0 - */ - public int getGradientRepeatDistance () - { - if (!isGradient()) - return 0; - return m_repeatDistance; - } // getGradientRepeatDistance - - /** - * Gradient Repeat Distance. - * Zero stands for no repeats - * @param repeatDistance repeat gradient after point x+repeat / y+repeat (depending on direction) - */ - public void setGradientRepeatDistance (int repeatDistance) - { - if (!isGradient()) - return; - m_repeatDistance = repeatDistance; - m_dirty = true; - } // setGradientRepeatDistance - - /** - * Gradient Repeat Distance. - * Zero stands for no repeats - * @param repeatDistanceString repeat gradient after point x+repeat / y+repeat (depending on direction) - */ - public void setGradientRepeatDistance (String repeatDistanceString) - { - if (!isGradient()) - return; - try - { - setGradientRepeatDistance(Integer.parseInt(repeatDistanceString)); - } - catch (Exception e) - { - log.severe("Parsing=" - + repeatDistanceString + " - " + e.getMessage()); - } - } // setGradientRepeatDistance - - - /************************ - * Texture Url - * @return URL (if not found, org.compiere.plaf.background.jpg is used) - */ - public URL getTextureURL() - { - if (!isTexture()) - return null; - if (m_textureURL == null) - m_textureURL = CompiereColor.class.getResource("Adempiere00x100.gif"); - return m_textureURL; - } // getTextureURL - - /** - * Get Texture Image based on Texture URL - * @return Image - */ - public BufferedImage getTextureImage() - { - if (m_image == null) - { - URL url = getTextureURL(); - m_image = CompiereUtils.loadBufferedImage(url, BufferedImage.TYPE_INT_ARGB_PRE); - } - return m_image; - } // getTextureImage - - /** - * Texture Url - * @param url URL to graphic file (jpg) - */ - public void setTextureURL(URL url) - { - if (!isTexture() || url == null) - return; - m_textureURL = url; - m_image = null; - m_dirty = true; - } // setTextureURL - - /** - * Texture Url - * @param urlString URL to graphic file (jpg) - */ - public void setTextureURL(String urlString) - { - if (!isTexture() || urlString == null) - return; - try - { - setTextureURL (new URL(urlString)); - } - catch (Exception e) - { - log.severe("Parsing URL=" - + urlString + " - " + e.getMessage()); - } - } // setTextureURL - - /** - * Texture Taint Color - * @return Color or null - */ - public Color getTextureTaintColor() - { - if (!isTexture()) - return null; - return m_primaryColor; - } // getTextureTaintColor - - /** - * Texture Taint Color - * @param color taint color - */ - public void setTextureTaintColor(Color color) - { - if (!isTexture() || color == null) - return; - m_primaryColor = color; - m_dirty = true; - } // setTextureTaintColor - - /** - * Texture Composite Alpha - * @return Composite Ampha or 0f - */ - public float getTextureCompositeAlpha() - { - if (!isTexture()) - return 0f; - return m_compositeAlpha; - } // getTextureCompositeAlpha - - /** - * Texture Composite Alpha - * @param alpha alpha value - */ - public void setTextureCompositeAlpha(float alpha) - { - if (!isTexture()) - return; - m_compositeAlpha = alpha; - m_dirty = true; - } // setTextureCompositeAlpha - - /** - * Texture Composite Alpha - * @param alphaString String to be parsed - */ - public void setTextureCompositeAlpha(String alphaString) - { - if (!isTexture() || alphaString == null) - return; - try - { - setTextureCompositeAlpha(Float.parseFloat(alphaString)); - } - catch (Exception e) - { - log.severe("Parsing=" - + alphaString + " - " + e.getMessage()); - } - } // setTextureCompositeAlpha - - - /************************ - * Line Color - * @return Color or null - */ - public Color getLineColor() - { - if (!isLine()) - return null; - return m_secondaryColor; - } // getLineColor - - /** - * Line Color - * @param color line color - */ - public void setLineColor(Color color) - { - if (!isLine() || color == null) - return; - m_secondaryColor = color; - m_dirty = true; - } // setLineColor - - /** - * Line Background Color - * @return Color or null - */ - public Color getLineBackColor() - { - if (!isLine()) - return null; - return m_primaryColor; - } // getLineBackColor - - /** - * Line Background Color - * @param color background color - */ - public void setLineBackColor(Color color) - { - if (!isLine() || color == null) - return; - m_primaryColor = color; - m_dirty = true; - } // setLineBackColor - - /** - * Background Line Width - * @return width or 0f - */ - public float getLineWidth() - { - if (!isLine()) - return 0f; - return m_lineWidth; - } // getLineWidth - - /** - * Background Line Width - * @param width line width - */ - public void setLineWidth(float width) - { - if (!isLine()) - return; - m_lineWidth = width; - m_dirty = true; - } // setLineWidth - - /** - * Background Line Width - * @param widthString line width - */ - public void setLineWidth(String widthString) - { - if (!isLine() || widthString == null) - return; - try - { - setLineWidth(Float.parseFloat(widthString)); - } - catch (Exception e) - { - log.severe("Parsing=" - + widthString + " - " + e.getMessage()); - } - } // setLineWidth - - /** - * Background Line distance in pt - * @return distance or 0 - */ - public int getLineDistance() - { - if (!isLine()) - return 0; - return m_lineDistance; - } // getLineDistance - - /** - * Background Line distance in pt - * @param distance line distance - */ - public void setLineDistance(int distance) - { - if (!isLine()) - return; - m_lineDistance = distance; - m_dirty = true; - } // setLineDistance - - /** - * Background Line distance in pt - * @param distanceString line distance - */ - public void setLineDistance(String distanceString) - { - if (!isLine()) - return; - try - { - setLineDistance(Integer.parseInt(distanceString)); - } - catch (Exception e) - { - log.severe("Parsing=" - + distanceString + " - " + e.getMessage()); - } - } // setLineDistance - - /** - * Set Prinary Color - * @param color primary color - */ - protected void setPrimaryColor (Color color) - { - if (color != null) - m_primaryColor = color; - } // setPrimaryColor - - /** - * Set AdempiereColor from AdempiereColor - * @param cc AdempiereColor - */ - public void setColor (CompiereColor cc) - { - if (cc == null) - return; - m_type = cc.getType(); - // - if (cc.isFlat()) - m_primaryColor = cc.getFlatColor(); - else if (cc.isGradient()) - { - m_primaryColor = cc.getGradientUpperColor(); - m_secondaryColor = cc.getGradientLowerColor(); - m_startPoint = cc.getGradientStartPoint(); - m_repeatDistance = cc.getGradientRepeatDistance(); - } - else if (cc.isTexture()) - { - setTextureURL(cc.getTextureURL()); - m_primaryColor = cc.getTextureTaintColor(); - m_compositeAlpha = cc.getTextureCompositeAlpha(); - } - else if (cc.isLine()) - { - m_primaryColor = cc.getLineBackColor(); - m_secondaryColor = cc.getLineColor(); - m_lineWidth = cc.getLineWidth(); - m_lineDistance = cc.getLineDistance(); - } - else - log.severe("Invalid Color"); - // - m_dirty = true; - } // setColor - - - /************************************************************************** - * Fill with AdempiereColor Background - * @param g the Graphics context in which to paint - * @param c the component being painted - */ - public void paint (Graphics g, JComponent c) - { - getColorBackground(c).paint (g, c); - } // paint - - /** - * Fill with Adempiere Background - * @param g graphics - * @param c component - * @param x x pos - * @param y y pos - * @param w with - * @param h height - */ - public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) - { - getColorBackground(c).paintRect (g,c, x,y, w,h); - } // paintRect - - /** - * Get Background - * @param c Componenr - * @return Background - */ - private ColorBackground getColorBackground (JComponent c) - { - if (m_back == null) - { - Rectangle bounds = c.getBounds(); - Container container = c.getParent(); - while (container != null) - { - bounds = container.getBounds(bounds); - container = container.getParent(); - } - m_back = new ColorBackground (bounds); - } - return m_back; - } // getBackground - - - /************************************************************************** - * String representation - * @return string representation - */ - public String toString() - { - StringBuffer sb = new StringBuffer ("AdempiereColor["); - if (isFlat()) - sb.append("Flat") - .append(" ").append(ThemeUtils.getColorAsString(getFlatColor())); - else if (isGradient()) - sb.append("Gradient") - .append(" Upper=").append(ThemeUtils.getColorAsString(getGradientUpperColor())) - .append(",Lower=").append(ThemeUtils.getColorAsString(getGradientLowerColor())) - .append(",Start=").append(getGradientStartPoint()) - .append(",RDistance=").append(getGradientRepeatDistance()); - else if (isLine()) - sb.append("Line") - .append(" Color=").append(ThemeUtils.getColorAsString(getLineColor())) - .append(",BackColor=").append(ThemeUtils.getColorAsString(getLineBackColor())) - .append(",Width=").append(getLineWidth()) - .append(",Distance=").append(getLineDistance()); - else if (isTexture()) - sb.append("Texture") - .append(" GraphURL=").append(getTextureURL()) - .append(",Taint=").append(ThemeUtils.getColorAsString(getTextureTaintColor())) - .append(",Alpha=").append(getTextureCompositeAlpha()); - sb.append("]"); - return sb.toString(); - } // toString - - /** - * Parse String Representation and set Attributes - * @param str parse string - */ - private void parseAttributres (String str) - { - if (str.indexOf("[Flat ") != -1) - { - m_type = TYPE_FLAT; - m_primaryColor = ThemeUtils.parseColor(str, - new ColorUIResource(m_primaryColor)); - } - else if (str.indexOf("[Gradient ") != -1) - { - m_type = TYPE_GRADIENT; - m_primaryColor = ThemeUtils.parseColor(str.substring(str.indexOf(" Upper=")+7, str.indexOf(",Lower=")), - new ColorUIResource(m_primaryColor)); - m_secondaryColor = ThemeUtils.parseColor(str.substring(str.indexOf(",Lower=")+7, str.indexOf(",Start=")), - new ColorUIResource(m_secondaryColor)); - m_startPoint = Integer.parseInt(str.substring(str.indexOf(",Start=")+7, str.indexOf(",RDistance="))); - setGradientRepeatDistance(str.substring(str.indexOf(",RDistance=")+11, str.lastIndexOf("]"))); - } - else if (str.indexOf("[Line ") != -1) - { - m_type = TYPE_LINES; - m_primaryColor = ThemeUtils.parseColor(str.substring(str.indexOf(" Color=")+7, str.indexOf(",BackColor=")), - new ColorUIResource(m_primaryColor)); - m_secondaryColor = ThemeUtils.parseColor(str.substring(str.indexOf(",BackColor=")+11, str.indexOf(",Width=")), - new ColorUIResource(m_secondaryColor)); - setLineWidth(str.substring(str.indexOf(",Width=")+7, str.indexOf(",Distance="))); - setLineDistance(str.substring(str.indexOf(",Distance=")+10, str.lastIndexOf("]"))); - } - else if (str.indexOf("[Texture ") != -1) - { - m_type = TYPE_TEXTURE; - setTextureURL (str.substring(str.indexOf(" GraphURL=")+10, str.indexOf(",Taint="))); - m_primaryColor = ThemeUtils.parseColor(str.substring(str.indexOf(",Taint=")+7, str.indexOf(",Alpha=")), - new ColorUIResource(m_primaryColor)); - setTextureCompositeAlpha (str.substring(str.indexOf(",Alpha=")+7, str.lastIndexOf("]"))); - } - } // parseString - - /** - * Does the background needs to be redone - * @return true if there were changes - */ - boolean isDirty() - { - return m_dirty; - } // isDirty - - /** - * Set Dirty - * @param dirty if true, the background will be re-painted - */ - void setDirty (boolean dirty) - { - m_dirty = dirty; - } // setDirty - - -/****************************************************************************** - * Background contains a Buffered Image with the background. - * The initial size is determined by the constructor. - * It is resized if required when painting. - *
- * The Buffered image is a 8-bit RGBA color components packed into integer pixels. - * The image has a DirectColorModel with alpha. The color data in this image - * is considered to be premultiplied with alpha - */ -public class ColorBackground -{ - /** - * Create Color Background - * @param bounds Rectangle to fit in - */ - public ColorBackground (Rectangle bounds) - { - createColorBackground (bounds); - fillColorBackground (); - } // Background - - private int m_height = 200; - private int m_width = 200; - private BufferedImage m_backImage; - private int m_colorBlind = ColorBlind.getColorType(); - - /** - * Create Color Background - * @param bounds Rectangle to fit in - */ - private void createColorBackground (Rectangle bounds) - { - m_height = Math.max(bounds.y + bounds.height, m_height); - m_width = Math.max(bounds.x + bounds.width, m_width); - m_backImage = new BufferedImage (m_width, m_height, BufferedImage.TYPE_INT_ARGB_PRE); - } // create Background - - - /** - * Fill Background with Color - */ - public void fillColorBackground () - { - Graphics2D g2D = m_backImage.createGraphics(); - - if (isGradient()) - { - Point start = null; - Point end = null; - int r = 1; // repeats - switch (m_startPoint) - { - case SwingConstants.NORTH_WEST: - start = new Point (0, 0); - if (m_repeatDistance > 0) - end = new Point (m_repeatDistance, m_repeatDistance); - // end = new Point (Math.min(m_repeatDistance, m_width), Math.min(m_repeatDistance, height)); - else - end = new Point (m_width/r, m_height/r); - break; - case SwingConstants.WEST: - start = new Point (0, m_height/2); - if (m_repeatDistance > 0) - end = new Point (m_repeatDistance, m_height/2); - // end = new Point (Math.min(m_repeatDistance, m_width), m_height/2); - else - end = new Point (m_width/r, m_height/2); - break; - case SwingConstants.SOUTH_WEST: - start = new Point (0, m_height); - if (m_repeatDistance > 0) - end = new Point (m_repeatDistance, m_height-m_repeatDistance); - // end = new Point (Math.min(m_width, m_repeatDistance), Math.max(0, m_height-m_repeatDistance)); - else - end = new Point (m_width/r, m_height-(m_height/r)); - break; - case SwingConstants.SOUTH: - start = new Point (0, m_height); - if (m_repeatDistance > 0) - end = new Point (0, m_height-m_repeatDistance); - // end = new Point (0, Math.max(0, m_height-m_repeatDistance)); - else - end = new Point (0, m_height-(m_height/r)); - break; - case SwingConstants.SOUTH_EAST: - start = new Point (m_width, m_height); - if (m_repeatDistance > 0) - end = new Point (m_width-m_repeatDistance, m_height-m_repeatDistance); - // end = new Point (Math.min(0, m_width-m_repeatDistance), Math.max(0, m_height-m_repeatDistance)); - else - end = new Point (m_width-(m_width/r), m_height-(m_height/r)); - break; - case SwingConstants.EAST: - start = new Point (m_width, m_height/2); - if (m_repeatDistance > 0) - end = new Point (m_width-m_repeatDistance, m_height/2); - // end = new Point (Math.min(0, m_width-m_repeatDistance), m_height/2); - else - end = new Point (m_width-(m_width/r), m_height/2); - break; - case SwingConstants.NORTH_EAST: - start = new Point (m_width, 0); - if (m_repeatDistance > 0) - end = new Point (m_width-m_repeatDistance, m_repeatDistance); - // end = new Point (Math.min(0, m_width-m_repeatDistance), Math.min(m_height, m_repeatDistance)); - else - end = new Point (m_width-(m_width/r), m_height/r); - break; - default: - case SwingConstants.NORTH: - start = new Point (0, 0); - if (m_repeatDistance > 0) - end = new Point (0, m_repeatDistance); - // end = new Point (0, Math.min(m_height, m_repeatDistance)); - else - end = new Point (0, m_height/r); - } - GradientPaint paint = new GradientPaint( - start, - ColorBlind.getDichromatColor(getGradientUpperColor()), - end, - ColorBlind.getDichromatColor(getGradientLowerColor()), - true); // cyclic - g2D.setPaint(paint); - g2D.fillRect(0, 0, m_width, m_height); - } - else if (isTexture()) - { - BufferedImage image = getTextureImage(); - if (image == null) - { - g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); - g2D.fillRect(0, 0, m_width, m_height); - } - else - { - Rectangle anchor = new Rectangle (0,0, image.getWidth(), image.getHeight()); - TexturePaint texture = new TexturePaint (image, anchor); - g2D.setPaint(texture); - g2D.fillRect(0, 0, m_width, m_height); - g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTextureCompositeAlpha())); - g2D.setPaint(ColorBlind.getDichromatColor(getTextureTaintColor())); - g2D.fillRect(0, 0, m_width, m_height); - } - } - else if (isLine()) - { - // Background - g2D.setPaint(ColorBlind.getDichromatColor(getLineBackColor())); - g2D.fillRect(0, 0, m_width, m_height); - // Lines - g2D.setPaint(ColorBlind.getDichromatColor(getLineColor())); - g2D.setStroke(new BasicStroke(getLineWidth())); - for (int y = 0; y < m_height; y += getLineDistance()) - g2D.drawLine(0, y, m_width, y); - } - else // flat - { - g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); - g2D.fillRect(0, 0, m_width, m_height); - } - setDirty (false); - } // fillBackground - - /** - * Paint/copy background to component - * @param g graphics - * @param c component - */ - public void paint (Graphics g, JComponent c) - { - Rectangle bounds = c.getBounds(); - check (bounds); - // - int h = c.getHeight(); - int w = c.getWidth(); - // Copy Background - g.drawImage (m_backImage, - 0, 0, // destination start point - w, h, // destination end point - bounds.x, bounds.y, // source start - bounds.x+w, bounds.y+h, // source end - c); - } // paint - - /** - * Paint/copy background to component rectangle - * @param g graphics - * @param c compnent - * @param x x pos - * @param y y pos - * @param w width - * @param h height - */ - public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) - { - Rectangle bounds = c.getBounds(); - check (bounds); - // Copy Background - g.drawImage (m_backImage, - x, y, // destination start point - x+w, h+y, // destination end point - x, y, // source start - x+w, y+h, // source end - c); - } // paint - - /** - * Check size of background and repaint if required - * @param bounds Bounds of component - */ - private void check (Rectangle bounds) - { - // Re-Create, if Color Type changed - if (ColorBlind.getColorType() != m_colorBlind) - { - m_colorBlind = ColorBlind.getColorType(); - setDirty(true); - } - // we need to create new background - if ((m_height < (bounds.y + bounds.height)) - || (m_width < (bounds.x + bounds.width))) - { - createColorBackground (bounds); - fillColorBackground(); - } - else if (isDirty()) - fillColorBackground(); - } // check - -} // ColorBackground - -} // AdempiereColor +/****************************************************************************** + * 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.*; +import java.awt.image.*; +import java.io.*; +import java.net.*; +import java.util.*; +import java.util.logging.*; +import javax.swing.*; +import javax.swing.plaf.*; + +import org.adempiere.plaf.AdempierePLAF; +import org.compiere.swing.ColorBlind; +import org.compiere.swing.ThemeUtils; +import org.compiere.util.*; + +/** + * Adempiere Background Color + * + * @author Jorg Janke + * @version $Id: AdempiereColor.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ + */ +public class CompiereColor implements Serializable +{ + /** Background type Flat */ + public static final String TYPE_FLAT = "F"; + /** Background type Gradient */ + public static final String TYPE_GRADIENT = "G"; + /** Background type Lines */ + public static final String TYPE_LINES = "L"; + /** Background type Texture */ + public static final String TYPE_TEXTURE = "T"; + + /** Names */ + private static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes"); + + /** Type Values */ + public static final String[] TYPE_VALUES = new String[] { + TYPE_FLAT, TYPE_GRADIENT, TYPE_LINES, TYPE_TEXTURE + }; + /** Type Names */ + public static final String[] TYPE_NAMES = new String[] { + s_res.getString("BackColType_Flat"), + s_res.getString("BackColType_Gradient"), + s_res.getString("BackColType_Lines"), + s_res.getString("BackColType_Texture") + }; + /** Types */ + public static final ValueNamePair[] TYPES = new ValueNamePair[] { + new ValueNamePair(TYPE_VALUES[0], TYPE_NAMES[0]), + new ValueNamePair(TYPE_VALUES[1], TYPE_NAMES[1]), + new ValueNamePair(TYPE_VALUES[2], TYPE_NAMES[2]), + new ValueNamePair(TYPE_VALUES[3], TYPE_NAMES[3]) + }; + + /** Gradient Starting Values */ + public static final int[] GRADIENT_SP_VALUES = new int[] { + SwingConstants.NORTH, SwingConstants.NORTH_EAST, + SwingConstants.EAST, SwingConstants.SOUTH_EAST, + SwingConstants.SOUTH, SwingConstants.SOUTH_WEST, + SwingConstants.WEST, SwingConstants.NORTH_WEST + }; + /** Gradient Starting Names */ + public static final String[] GRADIENT_SP_NAMES = new String[] { + "North", "North-East", + "East", "South-East", + "South", "South-West", + "West", "North-West" + }; + /** Gradient Starting Point */ + public static final KeyNamePair[] GRADIENT_SP = new KeyNamePair[] { + new KeyNamePair(GRADIENT_SP_VALUES[0], GRADIENT_SP_NAMES[0]), + new KeyNamePair(GRADIENT_SP_VALUES[1], GRADIENT_SP_NAMES[1]), + new KeyNamePair(GRADIENT_SP_VALUES[2], GRADIENT_SP_NAMES[2]), + new KeyNamePair(GRADIENT_SP_VALUES[3], GRADIENT_SP_NAMES[3]), + new KeyNamePair(GRADIENT_SP_VALUES[4], GRADIENT_SP_NAMES[4]), + new KeyNamePair(GRADIENT_SP_VALUES[5], GRADIENT_SP_NAMES[5]), + new KeyNamePair(GRADIENT_SP_VALUES[6], GRADIENT_SP_NAMES[6]), + new KeyNamePair(GRADIENT_SP_VALUES[7], GRADIENT_SP_NAMES[7]) + }; + /** Exception text */ + private static final String EXCEPTION_TEXT = "Arguments cannot be NULL"; + + + /************************************************************************** + * Set Background of Component to default color + * @param c component + */ + public static void setBackground (JComponent c) + { + setBackground (c, CompierePanelUI.getDefaultBackground()); + } // setBackground + + /** + * Set Background of Component + * @param c Component + * @param cc Color + */ + public static void setBackground (JComponent c, CompiereColor cc) + { + c.putClientProperty(AdempierePLAF.BACKGROUND, cc); + } // setBackground + + /** + * Get Background Color of component + * @param c JComponent + * @return Color + */ + public static CompiereColor getBackground (JComponent c) + { + CompiereColor bg = null; + try + { + bg = (CompiereColor)c.getClientProperty(AdempierePLAF.BACKGROUND); + } + catch (Exception e) + { + log.severe("ClientProperty: " + e.getMessage()); + } + return bg; + } // getBackground + + /** + * Set Background of Window Content Pane to default color + * @param win window + */ + public static void setBackground (Window win) + { + setBackground (win, CompierePanelUI.getDefaultBackground()); + } // setBackground + + /** + * Set Background of Window Content Pane + * @param win window + * @param cc adempiere color + */ + public static void setBackground (Window win, CompiereColor cc) + { + if (win instanceof JDialog) + { + ((JPanel)((JDialog)win).getContentPane()).putClientProperty(AdempierePLAF.BACKGROUND, cc); + // ((JPanel)((JDialog)win).getContentPane()).setName("contentPane"); + } + else if (win instanceof JFrame) + { + ((JPanel)((JFrame)win).getContentPane()).putClientProperty(AdempierePLAF.BACKGROUND, cc); + // ((JPanel)((JFrame)win).getContentPane()).setName("contentPane"); + } + else if (win instanceof JWindow) + { + ((JPanel)((JWindow)win).getContentPane()).putClientProperty(AdempierePLAF.BACKGROUND, cc); + // ((JPanel)((JWindow)win).getContentPane()).setName("contentPane"); + } + } // setBackground + + /** + * Set Default Background + * @param bg Background Color + * @see CompierePanelUI#setDefaultBackground + */ + public static void setDefaultBackground (CompiereColor bg) + { + CompierePanelUI.setDefaultBackground(bg); + } // setDefaultBackground + + /** + * Get Default Background + * @return Background + * @see CompierePanelUI#getDefaultBackground + */ + public static CompiereColor getDefaultBackground() + { + return CompierePanelUI.getDefaultBackground(); + } // getDefaultBackground + + /** + * Set Default Background + * @param setDefault if true, the background will be set to the default color + * @see CompierePanelUI#setSetDefault + */ + public static void setSetDefault (boolean setDefault) + { + CompierePanelUI.setSetDefault(setDefault); + } // setSetDefault + + /** + * Is the Default Background set by default + * @return true if default background is set + * @see CompierePanelUI#isSetDefault + */ + public static boolean isSetDefault() + { + return CompierePanelUI.isSetDefault(); + } // isSetDefault + + /** + * Parse attributes and return CompiereColor + * @param attributes attributes + * @return AdempiereColor + */ + public static CompiereColor parse (String attributes) + { + CompiereColor cc = new CompiereColor (); + try + { + if (attributes != null && attributes.length() > 0) + cc.parseAttributres (attributes); + } + catch (Exception e) + { + log.severe("(" + attributes + ") - " + e.toString()); + } + return cc; + } // parse + + + /************************************************************************* + * Create Gradient Background Color (Window System Color - White) + */ + public CompiereColor() + { + this (TYPE_GRADIENT); + } // AdempiereColor + + /** + * Create Default Background Colors of Type + * @param type Background type (see constants TYPE_*) + */ + public CompiereColor (String type) + { + if (type == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + if (type.equals(TYPE_FLAT) || type.equals(TYPE_GRADIENT) + || type.equals(TYPE_TEXTURE) || type.equals(TYPE_LINES)) + { + m_type = type; + } + else + new java.lang.IllegalArgumentException ("Invalid Type"); + } // AdempiereColor + + /** + * Create Flat Background Color + * @param bg background + */ + public CompiereColor (Color bg) + { + this (bg, true); + } // AdempiereColor + + /** + * Create Background Color + * @param bg Color + * @param flat if true create Flat color otherwise Gradient color with white lower color + */ + public CompiereColor (Color bg, boolean flat) + { + if (bg == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + m_type = flat ? TYPE_FLAT : TYPE_GRADIENT; + m_primaryColor = bg; + } // AdempiereColor + + /** + * Set Background to Gradient colors + * @param upperColor upper Color + * @param lowerColor lower Color + * @param startPoint Starting point - e.g. SOUTH_WEST see SwingConstants, default NORTH_WEST + * @param repeatDistance X/Y Distance to repeat gradient in points - 0 no repeats + */ + public CompiereColor (Color upperColor, Color lowerColor, int startPoint, int repeatDistance) + { + if (upperColor == null || lowerColor == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + m_type = TYPE_GRADIENT; + m_primaryColor = upperColor; + m_secondaryColor = lowerColor; + m_startPoint = startPoint; + m_repeatDistance = repeatDistance; + } // AdempiereColor + + /** + * Set Background to Gradient colors. + * Starting in the north, repeat after 100 pt + * @param upperColor upper color + * @param lowerColor lower color + */ + public CompiereColor (Color upperColor, Color lowerColor) + { + this (upperColor, lowerColor, SwingConstants.NORTH_WEST, 100); + } // AdempiereColor + + /** + * Set Background to Texture + * + * @param textureURL URL to a *.gif or *.jpg graphic file + * @param taint Color to taint the texture (use white for not tainting it) + * @param compositeAlpha Value from 0(no) to 1(full) taining + */ + public CompiereColor (URL textureURL, Color taint, float compositeAlpha) + { + if (textureURL == null || taint == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + m_type = TYPE_TEXTURE; + m_textureURL = textureURL; + m_primaryColor = taint; + m_compositeAlpha = compositeAlpha; + } // AdempiereColor + + /** + * Set Background to Texture + * + * @param textureURL URL to a *.gif or *.jpg graphic file + * @param taint Color to taint the texture (use white for not tainting it) + * @param compositeAlpha Tainting value from 0 (no - FullGraph) to 1 (full - NoGraph) + */ + public CompiereColor (String textureURL, Color taint, float compositeAlpha) + { + if (textureURL == null || taint == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + m_type = TYPE_TEXTURE; + setTextureURL(textureURL); + m_primaryColor = taint; + m_compositeAlpha = compositeAlpha; + } // AdempiereColor + + /** + * Set Background to Lines + * + * @param lineColor line color + * @param backColor background color + * @param lineWidth Stroke width in point + * @param lineDistance Distance between lines in points + */ + public CompiereColor (Color lineColor, Color backColor, float lineWidth, int lineDistance) + { + if (lineColor == null || backColor == null) + new java.lang.IllegalArgumentException (EXCEPTION_TEXT); + m_type = TYPE_LINES; + m_primaryColor = backColor; + m_secondaryColor = lineColor; + m_lineWidth = lineWidth; + m_lineDistance = lineDistance; + } // AdempiereColor + + /** + * Copy Color + * @param cc color + */ + public CompiereColor (CompiereColor cc) + { + if (cc == null) + return; + setColor(cc); + } // AdempiereColor + + /*************************************************************************/ + + /** Type - Default: Gradient */ + private String m_type = TYPE_GRADIENT; + + /** Primary Color - Default Panel back */ + private Color m_primaryColor = UIManager.getColor("Panel.background"); + /** Secondary Color - Default: gray-white */ + private Color m_secondaryColor = new Color (245, 245, 245); + + /** Texture Graph URL */ + private URL m_textureURL = null; + /** Texture Graph */ + private BufferedImage m_image = null; + /** Texture Alpha - Default: 0.7 */ + private float m_compositeAlpha = 0.7f; + + /** Line Width - Default: 1 */ + private float m_lineWidth = 1.0f; + /** Line Distance - Default: 5 */ + private int m_lineDistance = 5; + + /** Gradient Starting point - Default: NORTH_WEST */ + private int m_startPoint = SwingConstants.NORTH_WEST; + /** Gradient repeat distance in points - Default: 100 */ + private int m_repeatDistance = 100; + + /** Background */ + private ColorBackground m_back = null; + /** 3D Look */ + private boolean m_3d = true; + + /** Diry marker for repaining Background */ + private boolean m_dirty = true; + /** Logger */ + private static Logger log = Logger.getLogger(CompiereColor.class.getName()); + + /************************************************************************** + * Get BackgroundType (Flat, Gradient, Lines, Texture) + * @return Background Type (see TYPE_* constants) + */ + public String getType() + { + return m_type; + } // getType + + /** + * Flat Background Type (default) + * @return true if Flat background + */ + public boolean isFlat() + { + return TYPE_FLAT.equals(getType()); + } // isFlat + + /** + * Gradient Background Type + * @return true if Gradient background + */ + public boolean isGradient() + { + return TYPE_GRADIENT.equals(getType()); + } // isGradient + + /** + * Line Background Type + * @return true if Line background + */ + public boolean isLine() + { + return TYPE_LINES.equals(getType()); + } // isLine + + /** + * Texture Background Type + * @return true if Texture background + */ + public boolean isTexture() + { + return TYPE_TEXTURE.equals(getType()); + } // isTexture + + + /************************ + * Get Flat Color + * @return Primary Color + */ + public Color getFlatColor() + { + return m_primaryColor; + } // getFlatColor + + /** + * Set Flat Color + * @param color flat color + */ + public void setFlatColor(Color color) + { + if (!isFlat() || color == null) + return; + m_primaryColor = color; + m_dirty = true; + } // getFlatColor + + + /************************ + * Gradient Upper Color + * @return Color or null + */ + public Color getGradientUpperColor() + { + if (!isGradient()) + return null; + return m_primaryColor; + } // getGradientUpperColor + + /** + * Gradient Upper Color + * @param color upper color + */ + public void setGradientUpperColor(Color color) + { + if (!isGradient() || color == null) + return; + m_primaryColor = color; + m_dirty = true; + } // getGradientUpperColor + + /** + * Gradient Lower Color + * @return Color or null + */ + public Color getGradientLowerColor() + { + if (!isGradient()) + return null; + return m_secondaryColor; + } // getGradientLowerColor + + /** + * Gradient Lower Color + * @param color lower color + */ + public void setGradientLowerColor(Color color) + { + if (!isGradient() || color == null) + return; + m_secondaryColor = color; + m_dirty = true; + } // setGradientLowerColor + + /** + * Gradient Starting Point + * @return starting point - e.g. NORTH - or 0 + * @see SwingConstants + */ + public int getGradientStartPoint () + { + if (!isGradient()) + return 0; + return m_startPoint; + } // getGradientStartPoint + + /** + * Gradient Starting Point + * @param startPoint starting point - e.g. NORTH + * @see SwingConstants + */ + public void setGradientStartPoint (int startPoint) + { + if (!isGradient()) + return; + m_startPoint = startPoint; + m_dirty = true; + } // setGradientStartPoint + + /** + * Gradient Repeat Distance in point + * @return Repeat Distance - or 0 + */ + public int getGradientRepeatDistance () + { + if (!isGradient()) + return 0; + return m_repeatDistance; + } // getGradientRepeatDistance + + /** + * Gradient Repeat Distance. + * Zero stands for no repeats + * @param repeatDistance repeat gradient after point x+repeat / y+repeat (depending on direction) + */ + public void setGradientRepeatDistance (int repeatDistance) + { + if (!isGradient()) + return; + m_repeatDistance = repeatDistance; + m_dirty = true; + } // setGradientRepeatDistance + + /** + * Gradient Repeat Distance. + * Zero stands for no repeats + * @param repeatDistanceString repeat gradient after point x+repeat / y+repeat (depending on direction) + */ + public void setGradientRepeatDistance (String repeatDistanceString) + { + if (!isGradient()) + return; + try + { + setGradientRepeatDistance(Integer.parseInt(repeatDistanceString)); + } + catch (Exception e) + { + log.severe("Parsing=" + + repeatDistanceString + " - " + e.getMessage()); + } + } // setGradientRepeatDistance + + + /************************ + * Texture Url + * @return URL (if not found, org.compiere.plaf.background.jpg is used) + */ + public URL getTextureURL() + { + if (!isTexture()) + return null; + if (m_textureURL == null) + m_textureURL = CompiereColor.class.getResource("Adempiere00x100.gif"); + return m_textureURL; + } // getTextureURL + + /** + * Get Texture Image based on Texture URL + * @return Image + */ + public BufferedImage getTextureImage() + { + if (m_image == null) + { + URL url = getTextureURL(); + m_image = CompiereUtils.loadBufferedImage(url, BufferedImage.TYPE_INT_ARGB_PRE); + } + return m_image; + } // getTextureImage + + /** + * Texture Url + * @param url URL to graphic file (jpg) + */ + public void setTextureURL(URL url) + { + if (!isTexture() || url == null) + return; + m_textureURL = url; + m_image = null; + m_dirty = true; + } // setTextureURL + + /** + * Texture Url + * @param urlString URL to graphic file (jpg) + */ + public void setTextureURL(String urlString) + { + if (!isTexture() || urlString == null) + return; + try + { + setTextureURL (new URL(urlString)); + } + catch (Exception e) + { + log.severe("Parsing URL=" + + urlString + " - " + e.getMessage()); + } + } // setTextureURL + + /** + * Texture Taint Color + * @return Color or null + */ + public Color getTextureTaintColor() + { + if (!isTexture()) + return null; + return m_primaryColor; + } // getTextureTaintColor + + /** + * Texture Taint Color + * @param color taint color + */ + public void setTextureTaintColor(Color color) + { + if (!isTexture() || color == null) + return; + m_primaryColor = color; + m_dirty = true; + } // setTextureTaintColor + + /** + * Texture Composite Alpha + * @return Composite Ampha or 0f + */ + public float getTextureCompositeAlpha() + { + if (!isTexture()) + return 0f; + return m_compositeAlpha; + } // getTextureCompositeAlpha + + /** + * Texture Composite Alpha + * @param alpha alpha value + */ + public void setTextureCompositeAlpha(float alpha) + { + if (!isTexture()) + return; + m_compositeAlpha = alpha; + m_dirty = true; + } // setTextureCompositeAlpha + + /** + * Texture Composite Alpha + * @param alphaString String to be parsed + */ + public void setTextureCompositeAlpha(String alphaString) + { + if (!isTexture() || alphaString == null) + return; + try + { + setTextureCompositeAlpha(Float.parseFloat(alphaString)); + } + catch (Exception e) + { + log.severe("Parsing=" + + alphaString + " - " + e.getMessage()); + } + } // setTextureCompositeAlpha + + + /************************ + * Line Color + * @return Color or null + */ + public Color getLineColor() + { + if (!isLine()) + return null; + return m_secondaryColor; + } // getLineColor + + /** + * Line Color + * @param color line color + */ + public void setLineColor(Color color) + { + if (!isLine() || color == null) + return; + m_secondaryColor = color; + m_dirty = true; + } // setLineColor + + /** + * Line Background Color + * @return Color or null + */ + public Color getLineBackColor() + { + if (!isLine()) + return null; + return m_primaryColor; + } // getLineBackColor + + /** + * Line Background Color + * @param color background color + */ + public void setLineBackColor(Color color) + { + if (!isLine() || color == null) + return; + m_primaryColor = color; + m_dirty = true; + } // setLineBackColor + + /** + * Background Line Width + * @return width or 0f + */ + public float getLineWidth() + { + if (!isLine()) + return 0f; + return m_lineWidth; + } // getLineWidth + + /** + * Background Line Width + * @param width line width + */ + public void setLineWidth(float width) + { + if (!isLine()) + return; + m_lineWidth = width; + m_dirty = true; + } // setLineWidth + + /** + * Background Line Width + * @param widthString line width + */ + public void setLineWidth(String widthString) + { + if (!isLine() || widthString == null) + return; + try + { + setLineWidth(Float.parseFloat(widthString)); + } + catch (Exception e) + { + log.severe("Parsing=" + + widthString + " - " + e.getMessage()); + } + } // setLineWidth + + /** + * Background Line distance in pt + * @return distance or 0 + */ + public int getLineDistance() + { + if (!isLine()) + return 0; + return m_lineDistance; + } // getLineDistance + + /** + * Background Line distance in pt + * @param distance line distance + */ + public void setLineDistance(int distance) + { + if (!isLine()) + return; + m_lineDistance = distance; + m_dirty = true; + } // setLineDistance + + /** + * Background Line distance in pt + * @param distanceString line distance + */ + public void setLineDistance(String distanceString) + { + if (!isLine()) + return; + try + { + setLineDistance(Integer.parseInt(distanceString)); + } + catch (Exception e) + { + log.severe("Parsing=" + + distanceString + " - " + e.getMessage()); + } + } // setLineDistance + + /** + * Set Prinary Color + * @param color primary color + */ + protected void setPrimaryColor (Color color) + { + if (color != null) + m_primaryColor = color; + } // setPrimaryColor + + /** + * Set AdempiereColor from AdempiereColor + * @param cc AdempiereColor + */ + public void setColor (CompiereColor cc) + { + if (cc == null) + return; + m_type = cc.getType(); + // + if (cc.isFlat()) + m_primaryColor = cc.getFlatColor(); + else if (cc.isGradient()) + { + m_primaryColor = cc.getGradientUpperColor(); + m_secondaryColor = cc.getGradientLowerColor(); + m_startPoint = cc.getGradientStartPoint(); + m_repeatDistance = cc.getGradientRepeatDistance(); + } + else if (cc.isTexture()) + { + setTextureURL(cc.getTextureURL()); + m_primaryColor = cc.getTextureTaintColor(); + m_compositeAlpha = cc.getTextureCompositeAlpha(); + } + else if (cc.isLine()) + { + m_primaryColor = cc.getLineBackColor(); + m_secondaryColor = cc.getLineColor(); + m_lineWidth = cc.getLineWidth(); + m_lineDistance = cc.getLineDistance(); + } + else + log.severe("Invalid Color"); + // + m_dirty = true; + } // setColor + + + /************************************************************************** + * Fill with AdempiereColor Background + * @param g the Graphics context in which to paint + * @param c the component being painted + */ + public void paint (Graphics g, JComponent c) + { + getColorBackground(c).paint (g, c); + } // paint + + /** + * Fill with Adempiere Background + * @param g graphics + * @param c component + * @param x x pos + * @param y y pos + * @param w with + * @param h height + */ + public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) + { + getColorBackground(c).paintRect (g,c, x,y, w,h); + } // paintRect + + /** + * Get Background + * @param c Componenr + * @return Background + */ + private ColorBackground getColorBackground (JComponent c) + { + if (m_back == null) + { + Rectangle bounds = c.getBounds(); + Container container = c.getParent(); + while (container != null) + { + bounds = container.getBounds(bounds); + container = container.getParent(); + } + m_back = new ColorBackground (bounds); + } + return m_back; + } // getBackground + + + /************************************************************************** + * String representation + * @return string representation + */ + public String toString() + { + StringBuffer sb = new StringBuffer ("AdempiereColor["); + if (isFlat()) + sb.append("Flat") + .append(" ").append(CompiereTheme.getColorAsString(getFlatColor())); + else if (isGradient()) + sb.append("Gradient") + .append(" Upper=").append(CompiereTheme.getColorAsString(getGradientUpperColor())) + .append(",Lower=").append(CompiereTheme.getColorAsString(getGradientLowerColor())) + .append(",Start=").append(getGradientStartPoint()) + .append(",RDistance=").append(getGradientRepeatDistance()); + else if (isLine()) + sb.append("Line") + .append(" Color=").append(CompiereTheme.getColorAsString(getLineColor())) + .append(",BackColor=").append(CompiereTheme.getColorAsString(getLineBackColor())) + .append(",Width=").append(getLineWidth()) + .append(",Distance=").append(getLineDistance()); + else if (isTexture()) + sb.append("Texture") + .append(" GraphURL=").append(getTextureURL()) + .append(",Taint=").append(CompiereTheme.getColorAsString(getTextureTaintColor())) + .append(",Alpha=").append(getTextureCompositeAlpha()); + sb.append("]"); + return sb.toString(); + } // toString + + /** + * Parse String Representation and set Attributes + * @param str parse string + */ + private void parseAttributres (String str) + { + if (str.indexOf("[Flat ") != -1) + { + m_type = TYPE_FLAT; + m_primaryColor = CompiereTheme.parseColor(str, + new ColorUIResource(m_primaryColor)); + } + else if (str.indexOf("[Gradient ") != -1) + { + m_type = TYPE_GRADIENT; + m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(" Upper=")+7, str.indexOf(",Lower=")), + new ColorUIResource(m_primaryColor)); + m_secondaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",Lower=")+7, str.indexOf(",Start=")), + new ColorUIResource(m_secondaryColor)); + m_startPoint = Integer.parseInt(str.substring(str.indexOf(",Start=")+7, str.indexOf(",RDistance="))); + setGradientRepeatDistance(str.substring(str.indexOf(",RDistance=")+11, str.lastIndexOf("]"))); + } + else if (str.indexOf("[Line ") != -1) + { + m_type = TYPE_LINES; + m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(" Color=")+7, str.indexOf(",BackColor=")), + new ColorUIResource(m_primaryColor)); + m_secondaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",BackColor=")+11, str.indexOf(",Width=")), + new ColorUIResource(m_secondaryColor)); + setLineWidth(str.substring(str.indexOf(",Width=")+7, str.indexOf(",Distance="))); + setLineDistance(str.substring(str.indexOf(",Distance=")+10, str.lastIndexOf("]"))); + } + else if (str.indexOf("[Texture ") != -1) + { + m_type = TYPE_TEXTURE; + setTextureURL (str.substring(str.indexOf(" GraphURL=")+10, str.indexOf(",Taint="))); + m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",Taint=")+7, str.indexOf(",Alpha=")), + new ColorUIResource(m_primaryColor)); + setTextureCompositeAlpha (str.substring(str.indexOf(",Alpha=")+7, str.lastIndexOf("]"))); + } + } // parseString + + /** + * Does the background needs to be redone + * @return true if there were changes + */ + boolean isDirty() + { + return m_dirty; + } // isDirty + + /** + * Set Dirty + * @param dirty if true, the background will be re-painted + */ + void setDirty (boolean dirty) + { + m_dirty = dirty; + } // setDirty + + +/****************************************************************************** + * Background contains a Buffered Image with the background. + * The initial size is determined by the constructor. + * It is resized if required when painting. + *
+ * The Buffered image is a 8-bit RGBA color components packed into integer pixels. + * The image has a DirectColorModel with alpha. The color data in this image + * is considered to be premultiplied with alpha + */ +public class ColorBackground +{ + /** + * Create Color Background + * @param bounds Rectangle to fit in + */ + public ColorBackground (Rectangle bounds) + { + createColorBackground (bounds); + fillColorBackground (); + } // Background + + private int m_height = 200; + private int m_width = 200; + private BufferedImage m_backImage; + private int m_colorBlind = ColorBlind.getColorType(); + + /** + * Create Color Background + * @param bounds Rectangle to fit in + */ + private void createColorBackground (Rectangle bounds) + { + m_height = Math.max(bounds.y + bounds.height, m_height); + m_width = Math.max(bounds.x + bounds.width, m_width); + m_backImage = new BufferedImage (m_width, m_height, BufferedImage.TYPE_INT_ARGB_PRE); + } // create Background + + + /** + * Fill Background with Color + */ + public void fillColorBackground () + { + Graphics2D g2D = m_backImage.createGraphics(); + + if (isGradient()) + { + Point start = null; + Point end = null; + int r = 1; // repeats + switch (m_startPoint) + { + case SwingConstants.NORTH_WEST: + start = new Point (0, 0); + if (m_repeatDistance > 0) + end = new Point (m_repeatDistance, m_repeatDistance); + // end = new Point (Math.min(m_repeatDistance, m_width), Math.min(m_repeatDistance, height)); + else + end = new Point (m_width/r, m_height/r); + break; + case SwingConstants.WEST: + start = new Point (0, m_height/2); + if (m_repeatDistance > 0) + end = new Point (m_repeatDistance, m_height/2); + // end = new Point (Math.min(m_repeatDistance, m_width), m_height/2); + else + end = new Point (m_width/r, m_height/2); + break; + case SwingConstants.SOUTH_WEST: + start = new Point (0, m_height); + if (m_repeatDistance > 0) + end = new Point (m_repeatDistance, m_height-m_repeatDistance); + // end = new Point (Math.min(m_width, m_repeatDistance), Math.max(0, m_height-m_repeatDistance)); + else + end = new Point (m_width/r, m_height-(m_height/r)); + break; + case SwingConstants.SOUTH: + start = new Point (0, m_height); + if (m_repeatDistance > 0) + end = new Point (0, m_height-m_repeatDistance); + // end = new Point (0, Math.max(0, m_height-m_repeatDistance)); + else + end = new Point (0, m_height-(m_height/r)); + break; + case SwingConstants.SOUTH_EAST: + start = new Point (m_width, m_height); + if (m_repeatDistance > 0) + end = new Point (m_width-m_repeatDistance, m_height-m_repeatDistance); + // end = new Point (Math.min(0, m_width-m_repeatDistance), Math.max(0, m_height-m_repeatDistance)); + else + end = new Point (m_width-(m_width/r), m_height-(m_height/r)); + break; + case SwingConstants.EAST: + start = new Point (m_width, m_height/2); + if (m_repeatDistance > 0) + end = new Point (m_width-m_repeatDistance, m_height/2); + // end = new Point (Math.min(0, m_width-m_repeatDistance), m_height/2); + else + end = new Point (m_width-(m_width/r), m_height/2); + break; + case SwingConstants.NORTH_EAST: + start = new Point (m_width, 0); + if (m_repeatDistance > 0) + end = new Point (m_width-m_repeatDistance, m_repeatDistance); + // end = new Point (Math.min(0, m_width-m_repeatDistance), Math.min(m_height, m_repeatDistance)); + else + end = new Point (m_width-(m_width/r), m_height/r); + break; + default: + case SwingConstants.NORTH: + start = new Point (0, 0); + if (m_repeatDistance > 0) + end = new Point (0, m_repeatDistance); + // end = new Point (0, Math.min(m_height, m_repeatDistance)); + else + end = new Point (0, m_height/r); + } + GradientPaint paint = new GradientPaint( + start, + ColorBlind.getDichromatColor(getGradientUpperColor()), + end, + ColorBlind.getDichromatColor(getGradientLowerColor()), + true); // cyclic + g2D.setPaint(paint); + g2D.fillRect(0, 0, m_width, m_height); + } + else if (isTexture()) + { + BufferedImage image = getTextureImage(); + if (image == null) + { + g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); + g2D.fillRect(0, 0, m_width, m_height); + } + else + { + Rectangle anchor = new Rectangle (0,0, image.getWidth(), image.getHeight()); + TexturePaint texture = new TexturePaint (image, anchor); + g2D.setPaint(texture); + g2D.fillRect(0, 0, m_width, m_height); + g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTextureCompositeAlpha())); + g2D.setPaint(ColorBlind.getDichromatColor(getTextureTaintColor())); + g2D.fillRect(0, 0, m_width, m_height); + } + } + else if (isLine()) + { + // Background + g2D.setPaint(ColorBlind.getDichromatColor(getLineBackColor())); + g2D.fillRect(0, 0, m_width, m_height); + // Lines + g2D.setPaint(ColorBlind.getDichromatColor(getLineColor())); + g2D.setStroke(new BasicStroke(getLineWidth())); + for (int y = 0; y < m_height; y += getLineDistance()) + g2D.drawLine(0, y, m_width, y); + } + else // flat + { + g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); + g2D.fillRect(0, 0, m_width, m_height); + } + setDirty (false); + } // fillBackground + + /** + * Paint/copy background to component + * @param g graphics + * @param c component + */ + public void paint (Graphics g, JComponent c) + { + Rectangle bounds = c.getBounds(); + check (bounds); + // + int h = c.getHeight(); + int w = c.getWidth(); + // Copy Background + g.drawImage (m_backImage, + 0, 0, // destination start point + w, h, // destination end point + bounds.x, bounds.y, // source start + bounds.x+w, bounds.y+h, // source end + c); + } // paint + + /** + * Paint/copy background to component rectangle + * @param g graphics + * @param c compnent + * @param x x pos + * @param y y pos + * @param w width + * @param h height + */ + public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) + { + Rectangle bounds = c.getBounds(); + check (bounds); + // Copy Background + g.drawImage (m_backImage, + x, y, // destination start point + x+w, h+y, // destination end point + x, y, // source start + x+w, y+h, // source end + c); + } // paint + + /** + * Check size of background and repaint if required + * @param bounds Bounds of component + */ + private void check (Rectangle bounds) + { + // Re-Create, if Color Type changed + if (ColorBlind.getColorType() != m_colorBlind) + { + m_colorBlind = ColorBlind.getColorType(); + setDirty(true); + } + // we need to create new background + if ((m_height < (bounds.y + bounds.height)) + || (m_width < (bounds.x + bounds.width))) + { + createColorBackground (bounds); + fillColorBackground(); + } + else if (isDirty()) + fillColorBackground(); + } // check + +} // ColorBackground + +} // AdempiereColor diff --git a/looks/src/org/compiere/plaf/CompiereLookAndFeel.java b/looks/src/org/compiere/plaf/CompiereLookAndFeel.java index c5ce52a437..24158145fe 100644 --- a/looks/src/org/compiere/plaf/CompiereLookAndFeel.java +++ b/looks/src/org/compiere/plaf/CompiereLookAndFeel.java @@ -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. * * : @@ -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 ComponentUI classes, - * putting the ID-ComponentUI pairs in the passed-in defaults table. - * Each JComponent class specifies its own UI class ID string. - * - * @param table UI Defaults + return defaults; + } // getDefaults + + /** + * Creates the mapping from UI class IDs to ComponentUI classes, + * putting the ID-ComponentUI pairs in the passed-in defaults table. + * Each JComponent 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. - *

- * Invoked when the user attempts an invalid operation, - * such as pasting into an uneditable JTextField - * that has focus. - *

- *

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

- * @param component Component the error occured in, may be - * null indicating the error condition is - * not directly associated with a - * Component. - */ - 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. + *

+ * Invoked when the user attempts an invalid operation, + * such as pasting into an uneditable JTextField + * that has focus. + *

+ *

+ * 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. + *

+ * @param component Component the error occured in, may be + * null indicating the error condition is + * not directly associated with a + * Component. + */ + public void provideErrorFeedback (Component component) + { super.provideErrorFeedback (component); } // provideErrorFeedback diff --git a/looks/src/org/compiere/plaf/CompierePanelUI.java b/looks/src/org/compiere/plaf/CompierePanelUI.java index 60b537de41..519be7030f 100644 --- a/looks/src/org/compiere/plaf/CompierePanelUI.java +++ b/looks/src/org/compiere/plaf/CompierePanelUI.java @@ -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 diff --git a/looks/src/org/compiere/plaf/CompiereTabbedPaneUI.java b/looks/src/org/compiere/plaf/CompiereTabbedPaneUI.java index 40540e8470..35d5d87312 100644 --- a/looks/src/org/compiere/plaf/CompiereTabbedPaneUI.java +++ b/looks/src/org/compiere/plaf/CompiereTabbedPaneUI.java @@ -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(); } diff --git a/looks/src/org/compiere/plaf/CompiereTableHeaderUI.java b/looks/src/org/compiere/plaf/CompiereTableHeaderUI.java index 1c65d1785c..aa5a526f4e 100644 --- a/looks/src/org/compiere/plaf/CompiereTableHeaderUI.java +++ b/looks/src/org/compiere/plaf/CompiereTableHeaderUI.java @@ -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 JComponent when the specified - * component is being painted. - * - * By default this method will fill the specified component with - * its background color (if its opaque property is - * true) and then immediately call paint. - * - * @param g the Graphics 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 JComponent when the specified + * component is being painted. + * + * By default this method will fill the specified component with + * its background color (if its opaque property is + * true) and then immediately call paint. + * + * @param g the Graphics 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 diff --git a/looks/src/org/compiere/plaf/CompiereTheme.java b/looks/src/org/compiere/plaf/CompiereTheme.java index 73eef28db1..400632cbb7 100644 --- a/looks/src/org/compiere/plaf/CompiereTheme.java +++ b/looks/src/org/compiere/plaf/CompiereTheme.java @@ -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. + *

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

+ * 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 diff --git a/looks/src/org/compiere/plaf/CompiereUtils.java b/looks/src/org/compiere/plaf/CompiereUtils.java index 2f1423893e..6eff702982 100644 --- a/looks/src/org/compiere/plaf/CompiereUtils.java +++ b/looks/src/org/compiere/plaf/CompiereUtils.java @@ -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(); } diff --git a/looks/src/org/compiere/swing/CButton.java b/looks/src/org/compiere/swing/CButton.java index 0145a2cc78..4fa6c1d4ca 100644 --- a/looks/src/org/compiere/swing/CButton.java +++ b/looks/src/org/compiere/swing/CButton.java @@ -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 - * Action supplied. - * - * @param a the Action 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 + * Action supplied. + * + * @param a the Action 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 diff --git a/looks/src/org/compiere/swing/CCheckBox.java b/looks/src/org/compiere/swing/CCheckBox.java index 24646bac32..004524d97c 100644 --- a/looks/src/org/compiere/swing/CCheckBox.java +++ b/looks/src/org/compiere/swing/CCheckBox.java @@ -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 true 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 true 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 true 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 true 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 true 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 true 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 diff --git a/looks/src/org/compiere/swing/CComboBox.java b/looks/src/org/compiere/swing/CComboBox.java index 4e5bb5cee1..eb3b7bbebc 100644 --- a/looks/src/org/compiere/swing/CComboBox.java +++ b/looks/src/org/compiere/swing/CComboBox.java @@ -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 JComboBox that takes it's items from an - * existing ComboBoxModel. Since the - * ComboBoxModel 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 ComboBoxModel that provides the - * displayed list of items - * @see DefaultComboBoxModel - */ - public CComboBox(ComboBoxModel aModel) - { - super(aModel); - init(); - } // CComboBox - - /** - * Creates a JComboBox 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 JComboBox 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 JComboBox 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 JComboBox with a default data model. - * The default data model is an empty list of objects. - * Use addItem 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 JComboBox that takes it's items from an + * existing ComboBoxModel. Since the + * ComboBoxModel 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 ComboBoxModel that provides the + * displayed list of items + * @see DefaultComboBoxModel + */ + public CComboBox(ComboBoxModel aModel) + { + super(aModel); + init(); + } // CComboBox + + /** + * Creates a JComboBox 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 JComboBox 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 JComboBox 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 JComboBox with a default data model. + * The default data model is an empty list of objects. + * Use addItem 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 diff --git a/looks/src/org/compiere/swing/CDialog.java b/looks/src/org/compiere/swing/CDialog.java index dd3a478f9e..7781598c82 100644 --- a/looks/src/org/compiere/swing/CDialog.java +++ b/looks/src/org/compiere/swing/CDialog.java @@ -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 diff --git a/looks/src/org/compiere/swing/CFrame.java b/looks/src/org/compiere/swing/CFrame.java index 1dff8a2c1a..f53c5f28a9 100644 --- a/looks/src/org/compiere/swing/CFrame.java +++ b/looks/src/org/compiere/swing/CFrame.java @@ -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 diff --git a/looks/src/org/compiere/swing/CLabel.java b/looks/src/org/compiere/swing/CLabel.java index acaa279f30..ac3a097ba0 100644 --- a/looks/src/org/compiere/swing/CLabel.java +++ b/looks/src/org/compiere/swing/CLabel.java @@ -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 Label 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 SwingConstants: - * LEFT, - * CENTER, - * RIGHT, - * LEADING or - * TRAILING. - */ - public CLabel (String text, Icon icon, int horizontalAlignment) - { - super (text, icon, horizontalAlignment); - init(); - } - - /** - * Creates a Label 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 SwingConstants: - * LEFT, - * CENTER, - * RIGHT, - * LEADING or - * TRAILING. - */ - public CLabel (String text, int horizontalAlignment) - { - super(text, horizontalAlignment); - init(); - } - - /** - * Creates a Label 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 Label 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 SwingConstants: - * LEFT, - * CENTER, - * RIGHT, - * LEADING or - * TRAILING. - */ - public CLabel (Icon image, int horizontalAlignment) - { - super (image, horizontalAlignment); - init(); - } - - /** - * Creates a Label 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 JLabel 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 Label 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 Label 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 SwingConstants: + * LEFT, + * CENTER, + * RIGHT, + * LEADING or + * TRAILING. + */ + public CLabel (String text, Icon icon, int horizontalAlignment) + { + super (text, icon, horizontalAlignment); + init(); + } + + /** + * Creates a Label 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 SwingConstants: + * LEFT, + * CENTER, + * RIGHT, + * LEADING or + * TRAILING. + */ + public CLabel (String text, int horizontalAlignment) + { + super(text, horizontalAlignment); + init(); + } + + /** + * Creates a Label 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 Label 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 SwingConstants: + * LEFT, + * CENTER, + * RIGHT, + * LEADING or + * TRAILING. + */ + public CLabel (Icon image, int horizontalAlignment) + { + super (image, horizontalAlignment); + init(); + } + + /** + * Creates a Label 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 JLabel 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 Label 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 diff --git a/looks/src/org/compiere/swing/CPanel.java b/looks/src/org/compiere/swing/CPanel.java index cac704ee6d..261d33c350 100644 --- a/looks/src/org/compiere/swing/CPanel.java +++ b/looks/src/org/compiere/swing/CPanel.java @@ -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 CPanel with FlowLayout - * and the specified buffering strategy. - * If isDoubleBuffered is true, the CPanel - * 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 CPanel with a double buffer and a flow layout. - */ - public CPanel() - { - super (); - init(); - } // CPanel - - /** - * Creates a new CPanel 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 CPanel with FlowLayout + * and the specified buffering strategy. + * If isDoubleBuffered is true, the CPanel + * 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 CPanel with a double buffer and a flow layout. + */ + public CPanel() + { + super (); + init(); + } // CPanel + + /** + * Creates a new CPanel 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 diff --git a/looks/src/org/compiere/swing/CPassword.java b/looks/src/org/compiere/swing/CPassword.java index 9ba5a487c1..275bb1c762 100644 --- a/looks/src/org/compiere/swing/CPassword.java +++ b/looks/src/org/compiere/swing/CPassword.java @@ -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 JPasswordField, - * with a default document, null starting - * text string, and 0 column width. - */ - public CPassword() - { - super(); - init(); - } - - /** - * Constructs a new JPasswordField 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, null if none - */ - public CPassword (String text) - { - super (text); - init(); - } - - /** - * Constructs a new empty JPasswordField with the specified - * number of columns. A default model is created, and the initial string - * is set to null. - * - * @param columns the number of columns >= 0 - */ - public CPassword (int columns) - { - super (columns); - init(); - } - - /** - * Constructs a new JPasswordField initialized with - * the specified text and columns. The document model is set to - * the default. - * - * @param text the text to be displayed, null if none - * @param columns the number of columns >= 0 - */ - public CPassword (String text, int columns) - { - super (text,columns); - init(); - } - - /** - * Constructs a new JPasswordField 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 - * null, a default one will be created. - * - * @param doc the text storage to use - * @param txt the text to be displayed, null 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 JPasswordField, + * with a default document, null starting + * text string, and 0 column width. + */ + public CPassword() + { + super(); + init(); + } + + /** + * Constructs a new JPasswordField 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, null if none + */ + public CPassword (String text) + { + super (text); + init(); + } + + /** + * Constructs a new empty JPasswordField with the specified + * number of columns. A default model is created, and the initial string + * is set to null. + * + * @param columns the number of columns >= 0 + */ + public CPassword (int columns) + { + super (columns); + init(); + } + + /** + * Constructs a new JPasswordField initialized with + * the specified text and columns. The document model is set to + * the default. + * + * @param text the text to be displayed, null if none + * @param columns the number of columns >= 0 + */ + public CPassword (String text, int columns) + { + super (text,columns); + init(); + } + + /** + * Constructs a new JPasswordField 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 + * null, a default one will be created. + * + * @param doc the text storage to use + * @param txt the text to be displayed, null 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 + + +} diff --git a/looks/src/org/compiere/swing/CScrollPane.java b/looks/src/org/compiere/swing/CScrollPane.java index 0f1f6df1c4..eb8810ab8d 100644 --- a/looks/src/org/compiere/swing/CScrollPane.java +++ b/looks/src/org/compiere/swing/CScrollPane.java @@ -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 diff --git a/looks/src/org/compiere/swing/CTabbedPane.java b/looks/src/org/compiere/swing/CTabbedPane.java index 8695404ac4..7822e88f77 100644 --- a/looks/src/org/compiere/swing/CTabbedPane.java +++ b/looks/src/org/compiere/swing/CTabbedPane.java @@ -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 TabbedPane with a default - * tab placement of JTabbedPane.TOP and default - * tab layout policy of JTabbedPane.WRAP_TAB_LAYOUT. - */ - public CTabbedPane() - { - super(); - init(); - } // CTabbedPane - - /** - * Creates an empty TabbedPane with the specified tab placement - * of either: JTabbedPane.TOP, JTabbedPane.BOTTOM, - * JTabbedPane.LEFT, or JTabbedPane.RIGHT, and a - * default tab layout policy of JTabbedPane.WRAP_TAB_LAYOUT. - * - * @param tabPlacement the placement for the tabs relative to the content - */ - public CTabbedPane(int tabPlacement) - { - super(tabPlacement); - init(); - } // CTabbedPane - - /** - * Creates an empty TabbedPane with the specified tab placement - * and tab layout policy. Tab placement may be either: - * JTabbedPane.TOP, JTabbedPane.BOTTOM, - * JTabbedPane.LEFT, or JTabbedPane.RIGHT. - * Tab layout policy may be either: JTabbedPane.WRAP_TAB_LAYOUT - * or JTabbedPane.SCROLL_TAB_LAYOUT. - * - * @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 TabbedPane 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. - *

- * Inserts a component, at index, - * represented by a title and/or icon, - * either of which may be null. If icon - * is non-null and it implements - * ImageIcon a corresponding disabled icon will automatically - * be created and set on the tabbedpane. - * Uses java.util.Vector internally, see insertElementAt - * 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("")) - { - 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("")) - { - 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("")) - { - 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 m_mnemonic = new ArrayList(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 TabbedPane with a default + * tab placement of JTabbedPane.TOP and default + * tab layout policy of JTabbedPane.WRAP_TAB_LAYOUT. + */ + public CTabbedPane() + { + super(); + init(); + } // CTabbedPane + + /** + * Creates an empty TabbedPane with the specified tab placement + * of either: JTabbedPane.TOP, JTabbedPane.BOTTOM, + * JTabbedPane.LEFT, or JTabbedPane.RIGHT, and a + * default tab layout policy of JTabbedPane.WRAP_TAB_LAYOUT. + * + * @param tabPlacement the placement for the tabs relative to the content + */ + public CTabbedPane(int tabPlacement) + { + super(tabPlacement); + init(); + } // CTabbedPane + + /** + * Creates an empty TabbedPane with the specified tab placement + * and tab layout policy. Tab placement may be either: + * JTabbedPane.TOP, JTabbedPane.BOTTOM, + * JTabbedPane.LEFT, or JTabbedPane.RIGHT. + * Tab layout policy may be either: JTabbedPane.WRAP_TAB_LAYOUT + * or JTabbedPane.SCROLL_TAB_LAYOUT. + * + * @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 TabbedPane 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. + *

+ * Inserts a component, at index, + * represented by a title and/or icon, + * either of which may be null. If icon + * is non-null and it implements + * ImageIcon a corresponding disabled icon will automatically + * be created and set on the tabbedpane. + * Uses java.util.Vector internally, see insertElementAt + * 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("")) + { + 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("")) + { + 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("")) + { + 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 m_mnemonic = new ArrayList(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 diff --git a/looks/src/org/compiere/swing/CTable.java b/looks/src/org/compiere/swing/CTable.java index ed628d76e8..7c0d1f6ccb 100644 --- a/looks/src/org/compiere/swing/CTable.java +++ b/looks/src/org/compiere/swing/CTable.java @@ -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 sortList = new ArrayList(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 sortList = new ArrayList(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 diff --git a/looks/src/org/compiere/swing/CTextArea.java b/looks/src/org/compiere/swing/CTextArea.java index f7d5f9df53..eb1cee59ca 100644 --- a/looks/src/org/compiere/swing/CTextArea.java +++ b/looks/src/org/compiere/swing/CTextArea.java @@ -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 diff --git a/looks/src/org/compiere/swing/CTextField.java b/looks/src/org/compiere/swing/CTextField.java index 54586011b5..3d8216c08a 100644 --- a/looks/src/org/compiere/swing/CTextField.java +++ b/looks/src/org/compiere/swing/CTextField.java @@ -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 TextField. A default model is created, - * the initial string is null, - * and the number of columns is set to 0. - */ - public CTextField() - { - super(); - init(); - } // CTextField - - /** - * Constructs a new TextField 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 null - */ - public CTextField (String text) - { - super (text); - init(); - } // CTextField - - /** - * Constructs a new empty TextField with the specified - * number of columns. - * A default model is created and the initial string is set to - * null. - * - * @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 TextField initialized with the - * specified text and columns. A default model is created. - * - * @param text the text to be displayed, or null - * @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 JTextField 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 null, a default model is created. - * - * @param doc the text storage to use; if this is null, - * a default will be provided by calling the - * createDefaultModel method - * @param text the initial string to display, or null - * @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 - * @exception IllegalArgumentException if columns < 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 TextField. A default model is created, + * the initial string is null, + * and the number of columns is set to 0. + */ + public CTextField() + { + super(); + init(); + } // CTextField + + /** + * Constructs a new TextField 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 null + */ + public CTextField (String text) + { + super (text); + init(); + } // CTextField + + /** + * Constructs a new empty TextField with the specified + * number of columns. + * A default model is created and the initial string is set to + * null. + * + * @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 TextField initialized with the + * specified text and columns. A default model is created. + * + * @param text the text to be displayed, or null + * @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 JTextField 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 null, a default model is created. + * + * @param doc the text storage to use; if this is null, + * a default will be provided by calling the + * createDefaultModel method + * @param text the initial string to display, or null + * @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 + * @exception IllegalArgumentException if columns < 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 diff --git a/looks/src/org/compiere/swing/CTextPane.java b/looks/src/org/compiere/swing/CTextPane.java index 99700a2893..8f4ec14e6c 100644 --- a/looks/src/org/compiere/swing/CTextPane.java +++ b/looks/src/org/compiere/swing/CTextPane.java @@ -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 diff --git a/looks/src/org/compiere/swing/CToggleButton.java b/looks/src/org/compiere/swing/CToggleButton.java index 2e596c1544..e8cde55835 100644 --- a/looks/src/org/compiere/swing/CToggleButton.java +++ b/looks/src/org/compiere/swing/CToggleButton.java @@ -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 diff --git a/looks/src/org/compiere/util/Ini.java b/looks/src/org/compiere/util/Ini.java index e003dfe458..79e9178c57 100644 --- a/looks/src/org/compiere/util/Ini.java +++ b/looks/src/org/compiere/util/Ini.java @@ -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 */