📄 gridcelldecimal.java
字号:
/*
* WExtLib - A class library for the Superwaba Virtual Machine
* Copyright (C) 2005, Virgilio Alexandre Fornazin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package wextlib.ui.grid;
import wextlib.ui.editors.*;
import wextlib.util.*;
import waba.fx.*;
/**
* This class implements a default Grid Cell with decimal editing support
*
* @author Virgilio Alexandre Fornazin (mailto:virgiliofornazin@gmail.com)
*/
public final class GridCellDecimal extends GridCell
{
/** Defines numeric precision */
private int m_iPrecision;
/** Defines numeric scale */
private int m_iDecimals;
/** Prefix for formatting number */
private String m_strPrefix;
/** In-place editor */
private DecimalEdit m_Editor;
/**
* Default constructor
*/
public GridCellDecimal()
{
m_iPrecision = 12;
m_iDecimals = 2;
m_strPrefix = "";
setDouble(0);
m_Editor = null;
}
/**
* Update display of the number
*/
public void updateDisplay()
{
setDouble(getDouble());
}
/**
* Get the number format prefix
*/
public String getPrefix()
{
return m_strPrefix;
}
/**
* Set the number format prefix
*/
public void setPrefix(String strPrefix)
{
m_strPrefix = strPrefix;
updateDisplay();
}
/**
* Get current precision (not currently used)
*/
public int getPrecision()
{
return m_iPrecision;
}
/**
* Set current precision (not currently used)
*/
public void setPrecision(int iPrecision)
{
m_iPrecision = iPrecision;
updateDisplay();
}
/**
* Get current decimal places
*/
public int getDecimals()
{
return m_iDecimals;
}
/**
* Set current decimal places
*/
public void setDecimals(int iDecimals)
{
m_iDecimals = iDecimals;
updateDisplay();
}
/**
* Get current value as double
*/
public double getDouble()
{
return NumberFormat.parseNumber(m_strCellText);
}
/**
* Set current value as double and update precision and decimal places
*/
public void setDouble(double dblDouble, int iPrecision, int iDecimals)
{
if (iPrecision != -1)
{
m_iPrecision = iPrecision;
}
if (iDecimals != -1)
{
m_iDecimals = iDecimals;
}
m_strCellText = NumberFormat.formatNumber(m_strPrefix, dblDouble, m_iDecimals);
}
/**
* Set current value as a double
*/
public void setDouble(double dblDouble)
{
setDouble(dblDouble, -1, -1);
}
/**
* Get the cell text
*/
public String getCellText()
{
return m_strCellText;
}
/**
* Set the cell text
*/
public void setCellText(String strText)
{
setDouble(NumberFormat.parseNumber(strText));
}
public boolean supportEditing()
{
return true;
}
public boolean onStartEdit(Grid grid, GridCellID cellID, Rect cellRect, Color clrForeColor, Color clrBackColor, Font cellFont, int chrCode)
{
super.onStartEdit(grid, cellID, cellRect, clrForeColor, clrBackColor, cellFont, chrCode);
m_Editor = new GridCellDecimalEditor();
m_EditGrid.add(m_Editor);
m_EditControl = m_Editor;
m_Editor.setVisible(false);
m_Editor.setRect(m_EditRect);
if (m_EditBackColor != null)
{
m_Editor.setBackColor(m_EditBackColor);
}
if (m_EditForeColor != null)
{
m_Editor.setForeColor(m_EditForeColor);
}
if (m_EditFont != null)
{
m_Editor.setFont(m_EditFont);
}
m_Editor.setPrecision(m_iPrecision);
m_Editor.setDecimals(m_iDecimals);
m_Editor.setDouble(getDouble(), m_iPrecision, m_iDecimals);
m_Editor.setVisible(true);
m_Editor.setCursorPos(0, m_Editor.getText().length());
m_Editor.requestFocus();
return true;
}
public boolean onEndEdit()
{
if (m_Editor == null)
{
return false;
}
setDouble(m_Editor.getDouble());
m_Editor = null;
m_EditGrid.remove(m_EditControl);
m_EditControl = null;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -