[ Bugs-1717931 ] Shortcut not working for combobox and button
This commit is contained in:
parent
8db37af95e
commit
a9b3f4929b
|
@ -1,219 +1,239 @@
|
||||||
/******************************************************************************
|
/*********************************************************************
|
||||||
* 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.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.InputMap;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.plaf.ComponentInputMapUIResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adempiere CheckBox
|
* Adempiere CheckBox
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
|
* @version $Id: CCheckBox.java,v 1.2 2006/07/30 00:52:24 jjanke Exp $
|
||||||
*/
|
*/
|
||||||
public class CCheckBox extends JCheckBox implements CEditor
|
public class CCheckBox extends JCheckBox implements CEditor {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Creates an initially unselected check box button with no text, no icon.
|
* Creates an initially unselected check box button with no text, no icon.
|
||||||
*/
|
*/
|
||||||
public CCheckBox ()
|
public CCheckBox() {
|
||||||
{
|
super();
|
||||||
super ();
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an initially unselected check box with an icon.
|
* Creates an initially unselected check box with an icon.
|
||||||
*
|
*
|
||||||
* @param icon the Icon image to display
|
* @param icon
|
||||||
|
* the Icon image to display
|
||||||
*/
|
*/
|
||||||
public CCheckBox(Icon icon)
|
public CCheckBox(Icon icon) {
|
||||||
{
|
super(icon);
|
||||||
super (icon);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check box with an icon and specifies whether
|
* Creates a check box with an icon and specifies whether or not it is
|
||||||
* or not it is initially selected.
|
* initially selected.
|
||||||
*
|
*
|
||||||
* @param icon the Icon image to display
|
* @param icon
|
||||||
* @param selected a boolean value indicating the initial selection
|
* the Icon image to display
|
||||||
* state. If <code>true</code> the check box is selected
|
* @param selected
|
||||||
|
* a boolean value indicating the initial selection state. If
|
||||||
|
* <code>true</code> the check box is selected
|
||||||
*/
|
*/
|
||||||
public CCheckBox(Icon icon, boolean selected)
|
public CCheckBox(Icon icon, boolean selected) {
|
||||||
{
|
super(icon, selected);
|
||||||
super (icon, selected);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an initially unselected check box with text.
|
* Creates an initially unselected check box with text.
|
||||||
*
|
*
|
||||||
* @param text the text of the check box.
|
* @param text
|
||||||
|
* the text of the check box.
|
||||||
*/
|
*/
|
||||||
public CCheckBox (String text)
|
public CCheckBox(String text) {
|
||||||
{
|
super(text);
|
||||||
super (text);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check box where properties are taken from the
|
* Creates a check box where properties are taken from the Action supplied.
|
||||||
* Action supplied.
|
*
|
||||||
* @param a
|
* @param a
|
||||||
*/
|
*/
|
||||||
public CCheckBox(Action a)
|
public CCheckBox(Action a) {
|
||||||
{
|
super(a);
|
||||||
super (a);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check box with text and specifies whether
|
* Creates a check box with text and specifies whether or not it is
|
||||||
* or not it is initially selected.
|
* initially selected.
|
||||||
*
|
*
|
||||||
* @param text the text of the check box.
|
* @param text
|
||||||
* @param selected a boolean value indicating the initial selection
|
* the text of the check box.
|
||||||
* state. If <code>true</code> the check box is selected
|
* @param selected
|
||||||
|
* a boolean value indicating the initial selection state. If
|
||||||
|
* <code>true</code> the check box is selected
|
||||||
*/
|
*/
|
||||||
public CCheckBox (String text, boolean selected)
|
public CCheckBox(String text, boolean selected) {
|
||||||
{
|
super(text, selected);
|
||||||
super (text, selected);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an initially unselected check box with
|
* Creates an initially unselected check box with the specified text and
|
||||||
* the specified text and icon.
|
* icon.
|
||||||
*
|
*
|
||||||
* @param text the text of the check box.
|
* @param text
|
||||||
* @param icon the Icon image to display
|
* the text of the check box.
|
||||||
|
* @param icon
|
||||||
|
* the Icon image to display
|
||||||
*/
|
*/
|
||||||
public CCheckBox(String text, Icon icon)
|
public CCheckBox(String text, Icon icon) {
|
||||||
{
|
super(text, icon, false);
|
||||||
super (text, icon, false);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check box with text and icon,
|
* Creates a check box with text and icon, and specifies whether or not it
|
||||||
* and specifies whether or not it is initially selected.
|
* is initially selected.
|
||||||
*
|
*
|
||||||
* @param text the text of the check box.
|
* @param text
|
||||||
* @param icon the Icon image to display
|
* the text of the check box.
|
||||||
* @param selected a boolean value indicating the initial selection
|
* @param icon
|
||||||
* state. If <code>true</code> the check box is selected
|
* the Icon image to display
|
||||||
|
* @param selected
|
||||||
|
* a boolean value indicating the initial selection state. If
|
||||||
|
* <code>true</code> the check box is selected
|
||||||
*/
|
*/
|
||||||
public CCheckBox (String text, Icon icon, boolean selected)
|
public CCheckBox(String text, Icon icon, boolean selected) {
|
||||||
{
|
super(text, icon, selected);
|
||||||
super (text, icon, selected);
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common Init
|
* Common Init
|
||||||
*/
|
*/
|
||||||
private void init()
|
private void init() {
|
||||||
{
|
// Default to transparent, works better under windows look and feel
|
||||||
//Default to transparent, works better under windows look and feel
|
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
/*************************************************************************/
|
/** ********************************************************************** */
|
||||||
|
|
||||||
/** Mandatory (default false) */
|
/** Mandatory (default false) */
|
||||||
private boolean m_mandatory = false;
|
private boolean m_mandatory = false;
|
||||||
/** Read-Write */
|
|
||||||
|
/** Read-Write */
|
||||||
private boolean m_readWrite = true;
|
private boolean m_readWrite = true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Editor Mandatory
|
* Set Editor Mandatory
|
||||||
* @param mandatory true, if you have to enter data
|
*
|
||||||
|
* @param mandatory
|
||||||
|
* true, if you have to enter data
|
||||||
*/
|
*/
|
||||||
public void setMandatory (boolean mandatory)
|
public void setMandatory(boolean mandatory) {
|
||||||
{
|
|
||||||
m_mandatory = mandatory;
|
m_mandatory = mandatory;
|
||||||
setBackground(false);
|
setBackground(false);
|
||||||
} // setMandatory
|
} // setMandatory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is Field mandatory
|
* Is Field mandatory
|
||||||
* @return true, if mandatory
|
*
|
||||||
|
* @return true, if mandatory
|
||||||
*/
|
*/
|
||||||
public boolean isMandatory()
|
public boolean isMandatory() {
|
||||||
{
|
|
||||||
return m_mandatory;
|
return m_mandatory;
|
||||||
} // isMandatory
|
} // isMandatory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Editor
|
* Enable Editor
|
||||||
* @param rw true, if you can enter/select data
|
*
|
||||||
|
* @param rw
|
||||||
|
* true, if you can enter/select data
|
||||||
*/
|
*/
|
||||||
public void setReadWrite (boolean rw)
|
public void setReadWrite(boolean rw) {
|
||||||
{
|
|
||||||
if (super.isEnabled() != rw)
|
if (super.isEnabled() != rw)
|
||||||
super.setEnabled (rw);
|
super.setEnabled(rw);
|
||||||
setBackground(false);
|
setBackground(false);
|
||||||
m_readWrite = rw;
|
m_readWrite = rw;
|
||||||
} // setEditable
|
} // setEditable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is it possible to edit
|
* Is it possible to edit
|
||||||
* @return true, if editable
|
*
|
||||||
|
* @return true, if editable
|
||||||
*/
|
*/
|
||||||
public boolean isReadWrite()
|
public boolean isReadWrite() {
|
||||||
{
|
|
||||||
return m_readWrite;
|
return m_readWrite;
|
||||||
} // isEditable
|
} // isEditable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Background based on editable/mandatory/error - ignored -
|
* Set Background based on editable/mandatory/error - ignored -
|
||||||
* @param error if true, set background to error color, otherwise mandatory/editable
|
*
|
||||||
|
* @param error
|
||||||
|
* if true, set background to error color, otherwise
|
||||||
|
* mandatory/editable
|
||||||
*/
|
*/
|
||||||
public void setBackground (boolean error)
|
public void setBackground(boolean error) {
|
||||||
{
|
} // setBackground
|
||||||
} // setBackground
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Background
|
* Set Background
|
||||||
* @param bg
|
*
|
||||||
|
* @param bg
|
||||||
*/
|
*/
|
||||||
public void setBackground (Color bg)
|
public void setBackground(Color bg) {
|
||||||
{
|
|
||||||
if (bg.equals(getBackground()))
|
if (bg.equals(getBackground()))
|
||||||
return;
|
return;
|
||||||
super.setBackground(bg);
|
super.setBackground(bg);
|
||||||
} // setBackground
|
} // setBackground
|
||||||
|
|
||||||
|
/** Retain value */
|
||||||
/** Retain value */
|
|
||||||
private Object m_value = null;
|
private Object m_value = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Editor to value. Interpret Y/N and Boolean
|
* Set Editor to value. Interpret Y/N and Boolean
|
||||||
* @param value value of the editor
|
*
|
||||||
|
* @param value
|
||||||
|
* value of the editor
|
||||||
*/
|
*/
|
||||||
public void setValue (Object value)
|
public void setValue(Object value) {
|
||||||
{
|
|
||||||
m_value = value;
|
m_value = value;
|
||||||
boolean sel = false;
|
boolean sel = false;
|
||||||
if (value == null)
|
if (value == null)
|
||||||
|
@ -223,74 +243,100 @@ public class CCheckBox extends JCheckBox implements CEditor
|
||||||
else if (value.toString().equals("N"))
|
else if (value.toString().equals("N"))
|
||||||
sel = false;
|
sel = false;
|
||||||
else if (value instanceof Boolean)
|
else if (value instanceof Boolean)
|
||||||
sel = ((Boolean)value).booleanValue();
|
sel = ((Boolean) value).booleanValue();
|
||||||
else
|
else {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
sel = Boolean.getBoolean(value.toString());
|
sel = Boolean.getBoolean(value.toString());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.setSelected(sel);
|
this.setSelected(sel);
|
||||||
} // setValue
|
} // setValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Editor value
|
* Return Editor value
|
||||||
* @return current value as String or Boolean
|
*
|
||||||
|
* @return current value as String or Boolean
|
||||||
*/
|
*/
|
||||||
public Object getValue()
|
public Object getValue() {
|
||||||
{
|
|
||||||
if (m_value instanceof String)
|
if (m_value instanceof String)
|
||||||
return super.isSelected() ? "Y" : "N";
|
return super.isSelected() ? "Y" : "N";
|
||||||
return new Boolean (isSelected());
|
return new Boolean(isSelected());
|
||||||
} // getValue
|
} // getValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Display Value
|
* Return Display Value
|
||||||
* @return displayed String value
|
*
|
||||||
|
* @return displayed String value
|
||||||
*/
|
*/
|
||||||
public String getDisplay()
|
public String getDisplay() {
|
||||||
{
|
|
||||||
if (m_value instanceof String)
|
if (m_value instanceof String)
|
||||||
return super.isSelected() ? "Y" : "N";
|
return super.isSelected() ? "Y" : "N";
|
||||||
return Boolean.toString(super.isSelected());
|
return Boolean.toString(super.isSelected());
|
||||||
} // getDisplay
|
} // getDisplay
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Text
|
* Set Text
|
||||||
* @param mnemonicLabel text
|
*
|
||||||
|
* @param mnemonicLabel
|
||||||
|
* text
|
||||||
*/
|
*/
|
||||||
public void setText (String mnemonicLabel)
|
public void setText(String mnemonicLabel) {
|
||||||
{
|
super.setText(createMnemonic(mnemonicLabel));
|
||||||
super.setText (createMnemonic(mnemonicLabel));
|
} // setText
|
||||||
} // setText
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Mnemonics of text containing "&".
|
* Create Mnemonics of text containing "&". Based on MS notation of &Help =>
|
||||||
* Based on MS notation of &Help => H is Mnemonics
|
* H is Mnemonics Creates ALT_
|
||||||
* Creates ALT_
|
*
|
||||||
* @param text test with Mnemonics
|
* @param text
|
||||||
* @return text w/o &
|
* test with Mnemonics
|
||||||
|
* @return text w/o &
|
||||||
*/
|
*/
|
||||||
private String createMnemonic(String text)
|
private String createMnemonic(String text) {
|
||||||
{
|
|
||||||
if (text == null)
|
if (text == null)
|
||||||
return text;
|
return text;
|
||||||
int pos = text.indexOf('&');
|
int pos = text.indexOf('&');
|
||||||
if (pos != -1) // We have a nemonic
|
if (pos != -1) // We have a nemonic
|
||||||
{
|
{
|
||||||
char ch = text.charAt(pos+1);
|
char ch = text.charAt(pos + 1);
|
||||||
if (ch != ' ') // &_ - is the & character
|
if (ch != ' ') // &_ - is the & character
|
||||||
{
|
{
|
||||||
setMnemonic(ch);
|
setMnemonic(ch);
|
||||||
return text.substring(0, pos) + text.substring(pos+1);
|
return text.substring(0, pos) + text.substring(pos + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
} // createMnemonic
|
} // createMnemonic
|
||||||
|
|
||||||
|
/**
|
||||||
} // CCheckBox
|
* Overrides the JCheckBox.setMnemonic() method, setting modifier keys to
|
||||||
|
* CTRL+SHIFT.
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
String className = this.getClass().getName();
|
||||||
|
int mask = InputEvent.ALT_MASK; // Default Buttons
|
||||||
|
if (this instanceof JCheckBox // In Tab
|
||||||
|
|| className.indexOf("VButton") != -1)
|
||||||
|
mask = InputEvent.SHIFT_MASK + InputEvent.CTRL_MASK;
|
||||||
|
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
|
||||||
|
|
||||||
|
} // CCheckBox
|
||||||
|
|
Loading…
Reference in New Issue