Use numberpad keys to invoke calculator

Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2967153
This commit is contained in:
phib 2010-03-10 04:15:58 +00:00
parent 08aa2b0875
commit 4669951c2a
3 changed files with 48 additions and 35 deletions

View File

@ -301,7 +301,7 @@ public final class Calculator extends CDialog
m_decimal = m_format.getDecimalFormatSymbols().getDecimalSeparator(); m_decimal = m_format.getDecimalFormatSymbols().getDecimalSeparator();
// display start number // display start number
if (m_number.doubleValue() > 0.00 ) if (m_number.doubleValue() != 0.00 )
{ {
m_display = m_format.format(m_number); m_display = m_format.format(m_number);
display.setText(m_display); display.setText(m_display);

View File

@ -18,6 +18,7 @@ package org.compiere.grid.ed;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.ParseException;
import javax.swing.text.AttributeSet; import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
@ -151,31 +152,6 @@ public final class MDocNumber extends PlainDocument
return; return;
} }
// Plus - remove minus sign
if (c == '+')
{
// ADebug.trace(ADebug.l6_Database, "Plus=" + c);
// only positive numbers
if (m_displayType == DisplayType.Integer)
return;
if (content.length() > 0 && content.charAt(0) == '-')
super.remove(0, 1);
}
// Toggle Minus - put minus on start of string
else if (c == '-' || c == m_minusSign)
{
// ADebug.trace(ADebug.l6_Database, "Minus=" + c);
// no minus possible
if (m_displayType == DisplayType.Integer)
return;
// remove or add
if (content.length() > 0 && content.charAt(0) == '-')
super.remove(0, 1);
else
super.insertString(0, "-", attr);
}
// Decimal - remove other decimals // Decimal - remove other decimals
// Thousand - treat as Decimal // Thousand - treat as Decimal
else if (c == m_decimalSeparator || c == m_groupingSeparator || c == '.' || c == ',') else if (c == m_decimalSeparator || c == m_groupingSeparator || c == '.' || c == ',')
@ -215,13 +191,30 @@ public final class MDocNumber extends PlainDocument
} // decimal or thousand } // decimal or thousand
// something else // something else
else if (VNumber.AUTO_POPUP) else if (VNumber.AUTO_POPUP || "=+-/*".indexOf(c) > -1)
{ {
log.fine("Input=" + c + " (" + (int)c + ")");
String result = VNumber.startCalculator(m_tc, getText(), // Minus - put minus on start of string
m_format, m_displayType, m_title); if ( c == m_minusSign && offset == 0 )
super.remove(0, content.length()); {
super.insertString(0, result, attr); // no minus possible
if (m_displayType == DisplayType.Integer)
return;
// add at start of string
else
super.insertString(0, "-", attr);
}
else
{
log.fine("Input=" + c + " (" + (int)c + ")");
String result = VNumber.startCalculator(m_tc, getText(),
m_format, m_displayType, m_title, c);
super.remove(0, content.length());
// insertString(0, result, attr);
m_tc.setText(result);
}
} }
else else
ADialog.beep(); ADialog.beep();

View File

@ -558,10 +558,10 @@ public final class VNumber extends JComponent
return; return;
} }
if (e.getSource() == m_button) if (e.getSource() == m_button )
{ {
m_button.setEnabled(false); m_button.setEnabled(false);
String str = startCalculator(this, m_text.getText(), m_format, m_displayType, m_title); String str = startCalculator(this, m_text.getText(), m_format, m_displayType, m_title, ' ');
m_text.setText(str); m_text.setText(str);
m_button.setEnabled(true); m_button.setEnabled(true);
try try
@ -594,6 +594,7 @@ public final class VNumber extends JComponent
// ESC // ESC
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
m_text.setText(m_initialText); m_text.setText(m_initialText);
m_modified = true; m_modified = true;
m_setting = true; m_setting = true;
try try
@ -693,9 +694,26 @@ public final class VNumber extends JComponent
* @param displayType display type * @param displayType display type
* @param title title * @param title title
* @return value * @return value
* @deprecated Use {@link #startCalculator(Container,String,DecimalFormat,int,String,char)} instead
*/ */
public static String startCalculator(Container jc, String value, public static String startCalculator(Container jc, String value,
DecimalFormat format, int displayType, String title) DecimalFormat format, int displayType, String title)
{
return startCalculator(jc, value, format, displayType, title, ' ');
} // startCalculator
/**
* Invalid Entry - Start Calculator
* @param jc parent
* @param value value
* @param format format
* @param displayType display type
* @param title title
* @param operator optional math operator +-/*
* @return value
*/
public static String startCalculator(Container jc, String value,
DecimalFormat format, int displayType, String title, char operator)
{ {
log.config("Value=" + value); log.config("Value=" + value);
BigDecimal startValue = new BigDecimal(0.0); BigDecimal startValue = new BigDecimal(0.0);
@ -711,12 +729,14 @@ public final class VNumber extends JComponent
{ {
log.info("InvalidEntry - " + pe.getMessage()); log.info("InvalidEntry - " + pe.getMessage());
} }
// Find frame // Find frame
Frame frame = Env.getFrame(jc); Frame frame = Env.getFrame(jc);
// Actual Call // Actual Call
Calculator calc = new Calculator(frame, title, Calculator calc = new Calculator(frame, title,
displayType, format, startValue); displayType, format, startValue);
if ( "*+-/".indexOf(operator) > -1 )
calc.handleInput(operator);
AEnv.showCenterWindow(frame, calc); AEnv.showCenterWindow(frame, calc);
BigDecimal result = calc.getNumber(); BigDecimal result = calc.getNumber();
log.config( "Result=" + result); log.config( "Result=" + result);