Use numberpad keys to invoke calculator
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2967153
This commit is contained in:
parent
08aa2b0875
commit
4669951c2a
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
@ -717,6 +735,8 @@ public final class VNumber extends JComponent
|
|||
// 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);
|
||||
|
|
Loading…
Reference in New Issue