From 4669951c2ac0d185cff83065ef03870cb5a9df9b Mon Sep 17 00:00:00 2001 From: phib Date: Wed, 10 Mar 2010 04:15:58 +0000 Subject: [PATCH] Use numberpad keys to invoke calculator Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2967153 --- .../src/org/compiere/grid/ed/Calculator.java | 2 +- .../src/org/compiere/grid/ed/MDocNumber.java | 55 ++++++++----------- client/src/org/compiere/grid/ed/VNumber.java | 26 ++++++++- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/client/src/org/compiere/grid/ed/Calculator.java b/client/src/org/compiere/grid/ed/Calculator.java index ac809b62e6..4b880bdee3 100644 --- a/client/src/org/compiere/grid/ed/Calculator.java +++ b/client/src/org/compiere/grid/ed/Calculator.java @@ -301,7 +301,7 @@ public final class Calculator extends CDialog m_decimal = m_format.getDecimalFormatSymbols().getDecimalSeparator(); // display start number - if (m_number.doubleValue() > 0.00 ) + if (m_number.doubleValue() != 0.00 ) { m_display = m_format.format(m_number); display.setText(m_display); diff --git a/client/src/org/compiere/grid/ed/MDocNumber.java b/client/src/org/compiere/grid/ed/MDocNumber.java index c418ff87c8..3129f92b82 100644 --- a/client/src/org/compiere/grid/ed/MDocNumber.java +++ b/client/src/org/compiere/grid/ed/MDocNumber.java @@ -18,6 +18,7 @@ package org.compiere.grid.ed; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.text.ParseException; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; @@ -151,31 +152,6 @@ public final class MDocNumber extends PlainDocument 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 // Thousand - treat as Decimal else if (c == m_decimalSeparator || c == m_groupingSeparator || c == '.' || c == ',') @@ -215,13 +191,30 @@ public final class MDocNumber extends PlainDocument } // decimal or thousand // 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(), - m_format, m_displayType, m_title); - super.remove(0, content.length()); - super.insertString(0, result, attr); + + // Minus - put minus on start of string + if ( c == m_minusSign && offset == 0 ) + { + // 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 ADialog.beep(); diff --git a/client/src/org/compiere/grid/ed/VNumber.java b/client/src/org/compiere/grid/ed/VNumber.java index da95b45e3b..c166e4d279 100644 --- a/client/src/org/compiere/grid/ed/VNumber.java +++ b/client/src/org/compiere/grid/ed/VNumber.java @@ -558,10 +558,10 @@ public final class VNumber extends JComponent return; } - if (e.getSource() == m_button) + if (e.getSource() == m_button ) { 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_button.setEnabled(true); try @@ -594,6 +594,7 @@ public final class VNumber extends JComponent // ESC if (e.getKeyCode() == KeyEvent.VK_ESCAPE) m_text.setText(m_initialText); + m_modified = true; m_setting = true; try @@ -693,9 +694,26 @@ public final class VNumber extends JComponent * @param displayType display type * @param title title * @return value + * @deprecated Use {@link #startCalculator(Container,String,DecimalFormat,int,String,char)} instead */ public static String startCalculator(Container jc, String value, 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); BigDecimal startValue = new BigDecimal(0.0); @@ -711,12 +729,14 @@ public final class VNumber extends JComponent { log.info("InvalidEntry - " + pe.getMessage()); } - + // Find frame Frame frame = Env.getFrame(jc); // Actual Call Calculator calc = new Calculator(frame, title, displayType, format, startValue); + if ( "*+-/".indexOf(operator) > -1 ) + calc.handleInput(operator); AEnv.showCenterWindow(frame, calc); BigDecimal result = calc.getNumber(); log.config( "Result=" + result);