home *** CD-ROM | disk | FTP | other *** search
- package sheet;
-
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.rms.RecordStore;
-
- final class Table implements CellContainer {
- // $FF: renamed from: UP int
- public static final int field_0 = 1;
- public static final int DOWN = 2;
- public static final int LEFT = 3;
- public static final int RIGHT = 4;
- public static final int DB_VERSION_1 = 1;
- public static final int DB_LAST_VERSION = 1;
- public static final int MD_NORMAL = 0;
- public static final int MD_CELLSIZE = 1;
- private String name;
- private Cell[][] cells;
- private short[] rows;
- private short[] cols;
- private boolean dataChanged;
- private short szX;
- private short szY;
- private byte cursorX;
- private byte cursorY;
- private short tblLeft;
- private short tblTop;
- private short tblRight;
- private short tblBottom;
-
- public Table(short var1, short var2, short var3, short var4) {
- this.cells = new Cell[var1][var2];
- this.rows = new short[var2];
- this.cols = new short[var1];
- this.szX = var1;
- this.szY = var2;
-
- for(int var5 = 0; var5 < var1; ++var5) {
- this.cols[var5] = var3;
- }
-
- for(int var6 = 0; var6 < var2; ++var6) {
- this.rows[var6] = var4;
- }
-
- this.name = "noname";
- }
-
- public void moveCursor(int var1) {
- switch (var1) {
- case 1:
- if (this.cursorY > 0) {
- --this.cursorY;
- if (this.cursorY < this.tblTop) {
- --this.tblTop;
- }
- } else {
- Sheet.ported.CannotMoveSignal();
- }
- break;
- case 2:
- if (this.cursorY < this.szY - 1) {
- ++this.cursorY;
- if (this.cursorY >= this.tblBottom) {
- ++this.tblTop;
- }
- } else {
- Sheet.ported.CannotMoveSignal();
- }
- break;
- case 3:
- if (this.cursorX > 0) {
- --this.cursorX;
- if (this.cursorX < this.tblLeft) {
- --this.tblLeft;
- }
- } else {
- Sheet.ported.CannotMoveSignal();
- }
- break;
- case 4:
- if (this.cursorX < this.szX - 1) {
- ++this.cursorX;
- if (this.cursorX >= this.tblRight) {
- ++this.tblLeft;
- }
- } else {
- Sheet.ported.CannotMoveSignal();
- }
- }
-
- }
-
- public short getColumnWidth(int var1) {
- return this.cols[var1];
- }
-
- public short getRowHeight(int var1) {
- return this.rows[var1];
- }
-
- public void setRowHeight(int var1, short var2) {
- this.rows[var1] = var2;
-
- for(int var3 = 0; var3 < this.szX; ++var3) {
- Cell var4 = this.cells[var3][var1];
- if (var4 != null) {
- var4.render();
- }
- }
-
- this.notifyChanged();
- }
-
- public void setColumnWidth(int var1, short var2) {
- this.cols[var1] = var2;
-
- for(int var3 = 0; var3 < this.szY; ++var3) {
- Cell var4 = this.cells[var1][var3];
- if (var4 != null) {
- var4.render();
- }
- }
-
- this.notifyChanged();
- }
-
- public void paint(Graphics var1, int var2, int var3, int var4) {
- Font var5 = Font.getFont(64, 0, 8);
- int var6 = var5.getHeight() + 1;
- int var7 = var5.stringWidth("10") + 2;
- var1.setColor(0);
- var1.setFont(var5);
- short var10 = this.tblLeft;
-
- int var8;
- for(var8 = var7; var8 < var2 && var10 < this.szX; ++var10) {
- short var11 = this.getColumnWidth(var10);
- char var12 = (char)(65 + var10);
- var1.drawString(String.valueOf(var12), var8 + 1 + var11 / 2, 1, 17);
- var8 += var11 + 1;
- }
-
- this.tblRight = (short)(var10 - 1);
- var1.drawLine(0, var6, var8, var6);
- var10 = this.tblTop;
-
- int var9;
- for(var9 = var6; var9 < var3 && var10 < this.szY; ++var10) {
- short var21 = this.getRowHeight(var10);
- int var23 = var7;
- boolean var13 = var10 == this.cursorY;
- var1.drawString(String.valueOf(var10 + 1), var7 - 1, var9 + var21 - var6 + 2, 24);
-
- for(int var14 = this.tblLeft; var14 <= this.tblRight; ++var14) {
- Cell var15 = this.cells[var14][var10];
- short var16 = this.getColumnWidth(var14);
- int var17 = 0;
- if (var15 != null) {
- var17 = var15.paint(var1, var23 + 1, var9 + 1);
- }
-
- if (var14 == this.cursorX && var13) {
- var1.setColor(var17);
- var1.drawRect(var23 + 1, var9 + 1, var16 - 1, var21 - 1);
- var1.setColor(0);
- }
-
- if (var15 != null && !var15.isCalculated()) {
- int var18 = var23 + var16;
- int var19 = var9 + var21;
- var1.drawLine(var23 + 1, var9 + 1, var18, var19);
- var1.drawLine(var23 + 1, var19, var18, var9 + 1);
- }
-
- var23 += var16 + 1;
- }
-
- var9 += var21 + 1;
- if (var4 == 1 && var13) {
- var1.setStrokeStyle(1);
- var1.drawLine(0, var9, var8, var9);
- var1.setStrokeStyle(0);
- } else {
- var1.drawLine(0, var9, var8, var9);
- }
- }
-
- this.tblBottom = (short)(var10 - 1);
- var1.drawLine(var7, 0, var7, var9);
- int var22 = this.tblLeft;
-
- for(int var24 = var7; var22 <= this.tblRight; ++var22) {
- short var25 = this.getColumnWidth(var22);
- var24 += var25 + 1;
- if (var4 == 1 && var22 == this.cursorX) {
- var1.setStrokeStyle(1);
- var1.drawLine(var24, 0, var24, var9);
- var1.setStrokeStyle(0);
- } else {
- var1.drawLine(var24, 0, var24, var9);
- }
- }
-
- if (this.dataChanged) {
- int var26 = var7 / 2;
- int var27 = var6 / 2;
- var1.drawLine(var26 - 1, var27 - 1, var26 + 1, var27 + 1);
- var1.drawLine(var26 + 1, var27 - 1, var26 - 1, var27 + 1);
- }
-
- }
-
- public Cell getByName(String var1) throws IllegalArgumentException {
- try {
- int var2 = var1.charAt(0) - 65;
- if (var2 >= this.szX) {
- var2 = var1.charAt(0) - 97;
- }
-
- int var3 = Integer.parseInt(var1.substring(1, var1.length())) - 1;
- return this.cells[var2][var3];
- } catch (Exception var5) {
- throw new IllegalArgumentException("Wrong cell name '" + var1 + "'");
- }
- }
-
- public void notifyChanged() {
- this.dataChanged = true;
- }
-
- public boolean isChanged() {
- return this.dataChanged;
- }
-
- public void calculate() {
- int var1 = 0;
- int var2 = -1;
-
- for(int var3 = 0; var3 < this.szX; ++var3) {
- for(int var4 = 0; var4 < this.szY; ++var4) {
- if (this.cells[var3][var4] != null) {
- this.cells[var3][var4].notCalculated();
- }
- }
- }
-
- while(var2 != 0 && var1 != var2) {
- var1 = var2;
- var2 = 0;
-
- for(int var5 = 0; var5 < this.szX; ++var5) {
- for(int var6 = 0; var6 < this.szY; ++var6) {
- Cell var7 = this.cells[var5][var6];
- if (var7 != null && !var7.isCalculated() && !var7.calculate()) {
- ++var2;
- }
- }
- }
- }
-
- }
-
- public Cell getCurrentCell(boolean var1) {
- Cell var2 = this.cells[this.cursorX][this.cursorY];
- if (var2 == null && var1) {
- var2 = new Cell(this, this.cursorX, this.cursorY);
- this.cells[this.cursorX][this.cursorY] = var2;
- }
-
- return var2;
- }
-
- public void clearCurrentCell() {
- if (this.cells[this.cursorX][this.cursorY] != null) {
- this.cells[this.cursorX][this.cursorY] = null;
- this.notifyChanged();
- }
-
- }
-
- public int getCurrentColumn() {
- return this.cursorX;
- }
-
- public int getCurrentRow() {
- return this.cursorY;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void save(String var1) throws IllegalArgumentException {
- this.name = var1;
-
- try {
- RecordStore.deleteRecordStore(var1);
- } catch (Exception var11) {
- }
-
- try {
- RecordStore var2 = RecordStore.openRecordStore(var1, true);
- byte[] var3 = new byte[(this.szX + 1) * 2 + (this.szY + 1) * 2 + 3];
- var3[0] = 1;
- var3[1] = (byte)this.szX;
- var3[2] = (byte)this.szY;
- int var4 = 3;
-
- for(int var5 = 0; var5 < this.szX; ++var5) {
- short var6 = this.getColumnWidth(var5);
- var3[var4] = (byte)var6;
- var3[var4 + 1] = (byte)(var6 >>> 8);
- var4 += 2;
- }
-
- for(int var13 = 0; var13 < this.szY; ++var13) {
- short var7 = this.getRowHeight(var13);
- var3[var4] = (byte)var7;
- var3[var4 + 1] = (byte)(var7 >>> 8);
- var4 += 2;
- }
-
- var2.addRecord(var3, 0, var3.length);
-
- for(int var14 = 0; var14 < this.szX; ++var14) {
- for(int var8 = 0; var8 < this.szY; ++var8) {
- Cell var9 = this.cells[var14][var8];
- if (var9 != null) {
- byte[] var10 = var9.serialize(1);
- if (var10 != null) {
- var2.addRecord(var10, 0, var10.length);
- }
- }
- }
- }
-
- var2.closeRecordStore();
- this.dataChanged = false;
- } catch (Exception var12) {
- throw new IllegalArgumentException("'" + var1 + "' can't be saved");
- }
- }
-
- public static Table load(String var0) throws IllegalArgumentException {
- try {
- RecordStore var2 = RecordStore.openRecordStore(var0, true);
- int var3 = var2.getNumRecords();
- byte[] var4 = var2.getRecord(1);
- byte var5 = var4[0];
- if (var5 != 1) {
- throw new IllegalArgumentException();
- } else {
- short var6 = (short)var4[1];
- short var7 = (short)var4[2];
- int var8 = 3;
- Table var1 = new Table(var6, var7, (short)0, (short)0);
- var1.name = var0;
-
- for(int var9 = 0; var9 < var6; ++var9) {
- short var10 = (short)(var4[var8] + (var4[var8 + 1] << 8));
- var8 += 2;
- var1.setColumnWidth(var9, var10);
- }
-
- for(int var15 = 0; var15 < var7; ++var15) {
- short var11 = (short)(var4[var8] + (var4[var8 + 1] << 8));
- var8 += 2;
- var1.setRowHeight(var15, var11);
- }
-
- for(int var16 = 2; var16 <= var3; ++var16) {
- byte[] var12 = var2.getRecord(var16);
- Cell var13 = Cell.deserialize(var12, var1, var5);
- if (var13 != null) {
- var1.cells[var13.getColumn()][var13.getRow()] = var13;
- }
- }
-
- var2.closeRecordStore();
- var1.dataChanged = false;
- return var1;
- }
- } catch (Exception var14) {
- throw new IllegalArgumentException("'" + var0 + "' can't be read");
- }
- }
- }
-