📄 cell.java
字号:
/*
* MC2 -- j2me spreadsheet
*
* Copyright (c) 2004-2006 Michael Zemljanukha (mixaz@mail.ru)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program 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 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.wapindustrial.calc;
/*
* Cell.java
*
* Created on October 1, 2003, 2:29 PM
*/
public class Cell extends LispObject {
// static final LispObject ERROR = new LispObject(); // error value
// static final Cell EMPTY_CELL = new Cell(0,0,NIL,NIL); // a pseudo cell used instead of empty cells on the sheet
short i,j;
// String text;
LispObject value;
LispObject formula;
/** parent sheet */
// Sheet sheet;
static final int FORMAT_SHOWVALUE = 0x0;
static final int FORMAT_SHOWLISP = 0x1;
static final int FORMAT_SHOWFORMULA = 0x2;
static final int MASK_FORMULA = 0x0003;
static final int FORMAT_SHOWDATE = 0x0<<2;
static final int FORMAT_SHOWTIME = 0x1<<2;
static final int FORMAT_SHOWDATETIME = 0x2<<2;
static final int MASK_DATE = 0x000C;
short format;
public Cell(int _i, int _j, LispObject _formula, int _format) {
i = (short)_i; j = (short)_j;
formula = _formula;
value = NIL;
format = (short)_format;
// setValue( _value );
}
// public Cell(int _i, int _j, LispObject _formula, LispObject _value, int _format) {
// i = (short)_i; j = (short)_j;
// formula = _formula;
// value = _value;
// format = (short)_format;
// }
// public void setValue( LispObject _value ) {
// value = _value;
//// text = value.toValueString();
// }
public String getText() {
int mask = format & MASK_FORMULA;
if( mask == FORMAT_SHOWLISP )
return formula.toString();
if( mask == FORMAT_SHOWFORMULA )
return getFormula();
return value.toValueString( format );
}
public final boolean isEmpty() {
return value == NIL;
}
/**
* Checks if '=' must be added in formula bar.
* @return
* true for list and complex atoms
* false for simple atoms (WS parser literals, not functions)
*/
public final boolean isFormula() {
switch(formula.typeNumber()) {
case TYPE_REFERENCE:
case TYPE_NAME:
case TYPE_FUNCTORLIST:
case TYPE_QUOTEDLIST:
case TYPE_ERROR:
case TYPE_DATE:
case TYPE_ROWCOLUMN:
case TYPE_CELL:
case TYPE_SHEET:
case TYPE_FUNCTION:
return true;
// case TYPE_BOOLEAN = 6;
// case TYPE_SHORT = 7;
// case TYPE_LONG = 8;
// case TYPE_FLOAT = 9;
// case TYPE_STRING = 10;
// return false;
}
return false;
//return value != formula; // they are the same for atoms (constants)
}
public String getFormula() {
// if( isEmpty() )
// return "";
StringBuffer sb = new StringBuffer(40);
if( isFormula() ) {
sb.append( '=' );
formula.toFormulaBuffer( sb );
}
else {
formula.toValueBuffer( sb, format );
}
return sb.toString();
}
/* =========================
* complex Atom interface
*/
public int typeNumber() {
return TYPE_CELL;
}
/* (non-Javadoc)
* @see com.wapindustrial.calc.LispObject#listSize()
*/
public int listSize() {
return 5;
}
// public FunctorList toList() {
// return new FunctorListN(
// Bfunc.BFUNC.table[Bfunc.INDEX_CELL_CREATE],
// new LispObject[] {
// new ShortAtom( i ),
// new ShortAtom( j ),
// formula,
// new ShortAtom( format )
// }
// );
// }
/* (non-Javadoc)
* @see com.wapindustrial.calc.LispObject#getPart(int)
*/
LispObject getPart(int part) {
switch(part) {
case 0:
return Bfunc.BFUNC.table[Bfunc.INDEX_CELL_CREATE];
case 1:
return new ShortAtom( i );
case 2:
return new ShortAtom( j );
case 3:
return formula;
case 4:
return new ShortAtom( format );
// fields above listSize() are optional (temporary) - aren't saved to list but can be requested via getPart()
case 5:
return value;
}
return super.getPart(part);
}
public static LispObject fromList( FunctorList fl ) throws EvaluateException {
int size = fl.listSize();
int i = ((ShortAtom)fl.evaluateArg1()).value;
int j = ((ShortAtom)fl.evaluateArg2()).value;
LispObject formula = fl.getArgument3();
formula = Sheet.evaluateRef( formula, i, j );
// LispObject value = FormulaError.ERROR;
// try {
// value = formula.evaluateSExp();
// }
// catch( EvaluateException ee ) {
// }
int format = ((ShortAtom)fl.evaluateArgN(4)).value;
return new Cell(
i,
j,
formula, // formula
// value, // value
format
);
}
// for cells in worksheet hashtable
public int hashCode() {
return (i << 16) | j;
}
public boolean equals(Object obj) {
return hashCode() == obj.hashCode();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -