[ Bugs-1717931 ] Shortcut not working for combobox and button

This commit is contained in:
bmovaqar 2007-05-22 08:03:51 +00:00
parent c774a9be12
commit 8db37af95e
1 changed files with 215 additions and 169 deletions

View File

@ -1,26 +1,45 @@
/****************************************************************************** /*********************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * This file is part of Adempiere ERP Bazaar *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * http://www.adempiere.org *
* 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 * * Copyright (C) 1999 - 2006 Compiere Inc. *
* by the Free Software Foundation. This program is distributed in the hope * * Copyright (C) Contributors *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This program is free software; you can redistribute it and/or *
* See the GNU General Public License for more details. * * modify it under the terms of the GNU General Public License *
* You should have received a copy of the GNU General Public License along * * as published by the Free Software Foundation; either version 2 *
* with this program; if not, write to the Free Software Foundation, Inc., * * of the License, or (at your option) any later version. *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * *
* For the text or an alternative of this public license, you may reach us * * This program is distributed in the hope that it will be useful, *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* or via info@compiere.org or http://www.compiere.org/license.html * * 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Bahman Movaqar (bmovaqar@users.sf.net) *
**********************************************************************/
package org.compiere.swing; package org.compiere.swing;
import java.awt.*; import java.awt.Color;
import javax.swing.*; import java.awt.event.InputEvent;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.plaf.ComponentInputMapUIResource;
import org.adempiere.plaf.AdempierePLAF; import org.adempiere.plaf.AdempierePLAF;
import org.compiere.plaf.*; import org.compiere.plaf.CompiereColor;
import org.compiere.plaf.CompiereLookAndFeel;
/** /**
* Adempiere Button supporting colored Background * Adempiere Button supporting colored Background
@ -28,116 +47,113 @@ import org.compiere.plaf.*;
* @author Jorg Janke * @author Jorg Janke
* @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $ * @version $Id: CButton.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
*/ */
public class CButton extends JButton implements CEditor public class CButton extends JButton implements CEditor {
{
/** /**
* Creates a button with no set text or icon. * Creates a button with no set text or icon.
*/ */
public CButton() public CButton() {
{ this(null, null);
this (null, null);
} // CButton } // CButton
/** /**
* Creates a button with an icon. * Creates a button with an icon.
* *
* @param icon the Icon image to display on the button * @param icon
* the Icon image to display on the button
*/ */
public CButton(Icon icon) public CButton(Icon icon) {
{ this(null, icon);
this (null, icon);
} // CButton } // CButton
/** /**
* Creates a button with text. * Creates a button with text.
* *
* @param text the text of the button * @param text
* the text of the button
*/ */
public CButton(String text) public CButton(String text) {
{ this(text, null);
this (text, null);
} // CButton } // CButton
/** /**
* Creates a button where properties are taken from the * Creates a button where properties are taken from the <code>Action</code>
* <code>Action</code> supplied. * supplied.
* *
* @param a the <code>Action</code> used to specify the new button * @param a
* the <code>Action</code> used to specify the new button
* *
* @since 1.3 * @since 1.3
*/ */
public CButton (Action a) public CButton(Action a) {
{ super(a);
super (a);
} // CButton } // CButton
/** /**
* Creates a button with initial text and an icon. * Creates a button with initial text and an icon.
* *
* @param text the text of the button * @param text
* @param icon the Icon image to display on the button * the text of the button
* @param icon
* the Icon image to display on the button
*/ */
public CButton(String text, Icon icon) public CButton(String text, Icon icon) {
{ super(text, icon);
super (text, icon);
} // CButton } // CButton
/***************************************************************************
/************************************************************************** * Set Background - Differentiates between system & user call. If User Call,
* Set Background - Differentiates between system & user call. * sets Opaque & ContextAreaFilled to true
* If User Call, sets Opaque & ContextAreaFilled to true *
* @param bg background color * @param bg
* background color
*/ */
public void setBackground (Color bg) public void setBackground(Color bg) {
{
if (bg.equals(getBackground())) if (bg.equals(getBackground()))
return; return;
super.setBackground (bg); super.setBackground(bg);
setBackgroundColor(new CompiereColor(bg)); setBackgroundColor(new CompiereColor(bg));
this.repaint(); this.repaint();
} // setBackground } // setBackground
/** /**
* Set Background - NOP * Set Background - NOP
* @param error error *
* @param error
* error
*/ */
public void setBackground (boolean error) public void setBackground(boolean error) {
{
} // setBackground } // setBackground
/** /**
* Set Standard Background * Set Standard Background
*/ */
public void setBackgroundColor () public void setBackgroundColor() {
{ setBackgroundColor(null);
setBackgroundColor (null);
} // setBackground } // setBackground
/** /**
* Set Background * Set Background
* @param bg AdempiereColor for Background, if null set standard background *
* @param bg
* AdempiereColor for Background, if null set standard background
*/ */
public void setBackgroundColor (CompiereColor bg) public void setBackgroundColor(CompiereColor bg) {
{
if (bg == null) if (bg == null)
bg = new CompiereColor(AdempierePLAF.getFormBackground()); bg = new CompiereColor(AdempierePLAF.getFormBackground());
putClientProperty(CompiereLookAndFeel.BACKGROUND, bg); putClientProperty(CompiereLookAndFeel.BACKGROUND, bg);
super.setBackground (bg.getFlatColor()); super.setBackground(bg.getFlatColor());
this.repaint(); this.repaint();
} // setBackground } // setBackground
/** /**
* Get Background * Get Background
*
* @return Color for Background * @return Color for Background
*/ */
public CompiereColor getBackgroundColor () public CompiereColor getBackgroundColor() {
{ try {
try return (CompiereColor) getClientProperty(CompiereLookAndFeel.BACKGROUND);
{ } catch (Exception e) {
return (CompiereColor)getClientProperty(CompiereLookAndFeel.BACKGROUND);
}
catch (Exception e)
{
System.err.println("CButton - ClientProperty: " + e.getMessage()); System.err.println("CButton - ClientProperty: " + e.getMessage());
} }
return null; return null;
@ -145,34 +161,37 @@ public class CButton extends JButton implements CEditor
/** Mandatory (default false) */ /** Mandatory (default false) */
private boolean m_mandatory = false; private boolean m_mandatory = false;
/** Read-Write */ /** Read-Write */
private boolean m_readWrite = true; private boolean m_readWrite = true;
/** /**
* Set Editor Mandatory * Set Editor Mandatory
* @param mandatory true, if you have to enter data *
* @param mandatory
* true, if you have to enter data
*/ */
public void setMandatory (boolean mandatory) public void setMandatory(boolean mandatory) {
{
m_mandatory = mandatory; m_mandatory = mandatory;
setBackground(false); setBackground(false);
} // setMandatory } // setMandatory
/** /**
* Is Field mandatory * Is Field mandatory
*
* @return true, if mandatory * @return true, if mandatory
*/ */
public boolean isMandatory() public boolean isMandatory() {
{
return m_mandatory; return m_mandatory;
} // isMandatory } // isMandatory
/** /**
* Enable Editor * Enable Editor
* @param rw true, if you can enter/select data *
* @param rw
* true, if you can enter/select data
*/ */
public void setReadWrite (boolean rw) public void setReadWrite(boolean rw) {
{
if (isEnabled() != rw) if (isEnabled() != rw)
setEnabled(rw); setEnabled(rw);
m_readWrite = rw; m_readWrite = rw;
@ -180,19 +199,20 @@ public class CButton extends JButton implements CEditor
/** /**
* Is it possible to edit * Is it possible to edit
*
* @return true, if editable * @return true, if editable
*/ */
public boolean isReadWrite() public boolean isReadWrite() {
{
return m_readWrite; return m_readWrite;
} // isReadWrite } // isReadWrite
/** /**
* Set Editor to value * Set Editor to value
* @param value value of the editor *
* @param value
* value of the editor
*/ */
public void setValue (Object value) public void setValue(Object value) {
{
if (value == null) if (value == null)
setText(""); setText("");
else else
@ -201,83 +221,109 @@ public class CButton extends JButton implements CEditor
/** /**
* Return Editor value * Return Editor value
*
* @return current value * @return current value
*/ */
public Object getValue() public Object getValue() {
{
return getText(); return getText();
} // getValue } // getValue
/** /**
* Return Display Value * Return Display Value
*
* @return displayed String value * @return displayed String value
*/ */
public String getDisplay() public String getDisplay() {
{
return getText(); return getText();
} // getDisplay } // getDisplay
/** /**
* Set Text & Mnemonic * Set Text & Mnemonic
* @param text text *
* @param text
* text
*/ */
public void setText (String text) public void setText(String text) {
{ if (text == null) {
if (text == null)
{
super.setText(text); super.setText(text);
return; return;
} }
int pos = text.indexOf('&'); int pos = text.indexOf('&');
if (pos != -1) // We have a nemonic - creates ALT-_ if (pos != -1) // We have a nemonic - creates ALT-_
{ {
int mnemonic = text.toUpperCase().charAt(pos+1); int mnemonic = text.toUpperCase().charAt(pos + 1);
if (mnemonic != ' ') if (mnemonic != ' ') {
{
setMnemonic(mnemonic); setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1); text = text.substring(0, pos) + text.substring(pos + 1);
} }
} }
super.setText (text); super.setText(text);
if (getName() == null) if (getName() == null)
setName (text); setName(text);
} // setText } // setText
/** /**
* Set Tool Tip Text & Mnemonic * Set Tool Tip Text & Mnemonic
* @param text text *
* @param text
* text
*/ */
public void setToolTipText (String text) public void setToolTipText(String text) {
{ if (text == null) {
if (text == null)
{
super.setText(text); super.setText(text);
return; return;
} }
int pos = text.indexOf('&'); int pos = text.indexOf('&');
if (pos != -1) // We have a nemonic - creates ALT-_ if (pos != -1) // We have a nemonic - creates ALT-_
{ {
int mnemonic = text.toUpperCase().charAt(pos+1); int mnemonic = text.toUpperCase().charAt(pos + 1);
if (mnemonic != ' ') if (mnemonic != ' ') {
{
setMnemonic(mnemonic); setMnemonic(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1); text = text.substring(0, pos) + text.substring(pos + 1);
} }
} }
super.setToolTipText (text); super.setToolTipText(text);
if (getName() == null) if (getName() == null)
setName (text); setName(text);
} // setToolTipText } // setToolTipText
/** /**
* Set Action Command * Set Action Command
* @param actionCommand command *
* @param actionCommand
* command
*/ */
public void setActionCommand (String actionCommand) public void setActionCommand(String actionCommand) {
{ super.setActionCommand(actionCommand);
super.setActionCommand (actionCommand); if (getName() == null && actionCommand != null
if (getName() == null && actionCommand != null && actionCommand.length() > 0) && actionCommand.length() > 0)
setName(actionCommand); setName(actionCommand);
} // setActionCommand } // setActionCommand
/**
* Overrides the JButton.setMnemonic() method, setting modifier keys to
* CTRL+ALT.
*
* @param mnemonic
* The mnemonic character code.
*/
public void setMnemonic(int mnemonic) {
super.setMnemonic(mnemonic);
InputMap map = SwingUtilities.getUIInputMap(this,
JComponent.WHEN_IN_FOCUSED_WINDOW);
if (map == null) {
map = new ComponentInputMapUIResource(this);
SwingUtilities.replaceUIInputMap(this,
JComponent.WHEN_IN_FOCUSED_WINDOW, map);
}
map.clear();
int mask = InputEvent.ALT_MASK + InputEvent.CTRL_MASK; // Default
// Buttons
map.put(KeyStroke.getKeyStroke(mnemonic, mask, false), "pressed");
map.put(KeyStroke.getKeyStroke(mnemonic, mask, true), "released");
map.put(KeyStroke.getKeyStroke(mnemonic, 0, true), "released");
setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map);
} // setMnemonic
} // CButton } // CButton