myGully.com Boerse.SH - BOERSE.AM - BOERSE.IO - BOERSE.IM Boerse.BZ .TO Nachfolger
Zurück   myGully.com > Computer & Technik > Programmierung
Seite neu laden

[Java Mobile] Tastenbelegung

Willkommen

myGully

Links

Forum

 
Antwort
Themen-Optionen Ansicht
Ungelesen 17.06.10, 15:15   #1
hupe12345
Anfänger
 
Registriert seit: Jul 2009
Beiträge: 15
Bedankt: 0
hupe12345 ist noch neu hier! | 0 Respekt Punkte
Standard [Java Mobile] Tastenbelegung

hallo,
ich habe da ein kleines Excel tool auf java basis fürs Handy.
mit den tasten 2,4,6,8 wechselt man die zeile bzw spalte.
Mit 1,3,7,9 hingegen gibt man sofort die gedrücke zahl in die Zelle ein.
Da ich aber zur navigation die Hoch,runter,links,rechts tasten nehme würd ich das gern ändern das 2,4,6,8 nicht die selbe funktion wie die navigationstasten haben sondern das gleiche wie 1,3,7,9 , also gleich den wert in die zelle schreiben.
In dem Code find ich aber die "Tastenbelegung" nicht
Kann mir jemand helfen die zu finden?
danke schön

Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SheetShow.java

package sheet;

import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;

// Referenced classes of package sheet:
//            Table, CellResize, Backable, Cell, 
//            Quitable

final class SheetShow extends Canvas
    implements CommandListener, Backable
{

    public SheetShow()
    {
        for(int i = 0; i < COMMANDS.length; i++)
            addCommand(COMMANDS[i]);

        appWidth = getWidth();
        appHeight = getHeight();
        data = newSheet();
        moved = true;
        try
        {
            Class.forName("sheet.Cell");
            Class.forName("sheet.Operation");
            Class.forName("sheet.CellCalc");
            Class.forName("sheet.CellCalc$IntegerStack");
        }
        catch(ClassNotFoundException classnotfoundexception) { }
    }

    public void show(Display disp, Quitable toQuit)
    {
        winQuit = toQuit;
        display = disp;
        show();
    }

    public void show()
    {
        display.setCurrent(this);
        setCommandListener(this);
    }

    protected void paint(Graphics g)
    {
        g.setColor(0xffffff);
        g.fillRect(0, 0, appWidth, appHeight);
        data.paint(g, appWidth, appHeight, 0);
    }

    private void actualSave(String fname)
    {
        try
        {
            data.save(fname);
            show();
        }
        catch(IllegalArgumentException e)
        {
            Alert err = new Alert("File error", e.getMessage(), null, AlertType.ERROR);
            display.setCurrent(err, this);
        }
    }

    private void actualLoad(String fname)
    {
        try
        {
            Table tmpdata = Table.load(fname);
            data = tmpdata;
            if(data != null)
                data.calculate();
            show();
        }
        catch(IllegalArgumentException e)
        {
            Alert err = new Alert("File error", e.getMessage(), null, AlertType.ERROR);
            display.setCurrent(err, this);
        }
    }

    private void showWait(final String message, final Runnable action)
    {
        Canvas wait = new Canvas() {

            protected void paint(Graphics g)
            {
                g.drawString(message, getWidth() / 2, getHeight() / 2, 17);
                SheetShow.display.callSerially(action);
            }

        }
;
        display.setCurrent(wait);
    }

    private void save(final Runnable action)
    {
        TextBox fnameEdit = new TextBox("Enter sheet name", data.getName(), 32, 4);
        fnameEdit.setCommandListener(new CommandListener() {

            public void commandAction(Command cmd, Displayable obj)
            {
                if(cmd == SheetShow.okCommand)
                {
                    final String fname = ((TextBox)obj).getString();
                    showWait("Saving...", new Runnable() {

                        public void run()
                        {
                            actualSave(fname);
                            if(action != null)
                                action.run();
                        }

                    }
);
                } else
                {
                    show();
                }
            }



        }
);
        fnameEdit.addCommand(okCommand);
        fnameEdit.addCommand(cancelCommand);
        display.setCurrent(fnameEdit);
    }

    private void load()
    {
        final Displayable back = this;
        showWait("Reading...", new Runnable() {

            public void run()
            {
                try
                {
                    String nameList[] = RecordStore.listRecordStores();
                    final Alert errAlert = new Alert("Info", "No files to open", null, AlertType.ERROR);
                    if(nameList != null)
                    {
                        List list = new List("Open a sheet", 3, nameList, null);
                        final Command deleteCommand = new Command("Delete", 1, 1);
                        list.setCommandListener(new CommandListener() {

                            public void commandAction(Command cmd, Displayable obj)
                            {
                                final List flist = (List)obj;
                                final int idx = flist.getSelectedIndex();
                                if(cmd == SheetShow.okCommand || cmd == List.SELECT_COMMAND)
                                    showWait("Loading...", new Runnable() {

                                        public void run()
                                        {
                                            actualLoad(flist.getString(idx));
                                        }

                                    }
);
                                else
                                if(cmd == deleteCommand)
                                    showWait("Deleting...", new Runnable() {

                                        public void run()
                                        {
                                            try
                                            {
                                                RecordStore.deleteRecordStore(flist.getString(idx));
                                                flist.delete(idx);
                                                if(flist.size() > 0)
                                                    SheetShow.display.setCurrent(flist);
                                                else
                                                    SheetShow.display.setCurrent(errAlert, back);
                                            }
                                            catch(Exception e)
                                            {
                                                Alert err = new Alert("File error", e.getMessage(), null, AlertType.ERROR);
                                                SheetShow.display.setCurrent(err, flist);
                                            }
                                        }

                                    }
);
                                else
                                    show();
                            }



                        }
);
                        list.addCommand(SheetShow.okCommand);
                        list.addCommand(SheetShow.cancelCommand);
                        list.addCommand(deleteCommand);
                        SheetShow.display.setCurrent(list);
                    } else
                    {
                        SheetShow.display.setCurrent(errAlert, back);
                    }
                }
                catch(Exception e)
                {
                    Alert err = new Alert("File error", e.getMessage(), null, AlertType.ERROR);
                    SheetShow.display.setCurrent(err, back);
                }
            }



        }
);
    }

    private void checkModified(final Runnable action)
    {
        if(data.isChanged())
        {
            final Command yesCommand = new Command("Yes", 1, 1);
            final Command noCommand = new Command("No", 1, 1);
            Form wantsave = new Form("Warning");
            wantsave.append(new StringItem(null, "The data was modified. Save?"));
            wantsave.setCommandListener(new CommandListener() {

                public void commandAction(Command cmd, Displayable obj)
                {
                    if(cmd == yesCommand)
                        save(action);
                    else
                    if(cmd == noCommand)
                        action.run();
                    else
                        show();
                }

            }
);
            wantsave.addCommand(yesCommand);
            wantsave.addCommand(noCommand);
            wantsave.addCommand(cancelCommand);
            display.setCurrent(wantsave);
        } else
        {
            action.run();
        }
    }

    public void keyPressed(int code)
    {
        int key = getGameAction(code);
        switch(key)
        {
        case 1: // '\001'
            data.moveCursor(1);
            moved = true;
            break;

        case 6: // '\006'
            data.moveCursor(2);
            moved = true;
            break;

        case 2: // '\002'
            data.moveCursor(3);
            moved = true;
            break;

        case 5: // '\005'
            data.moveCursor(4);
            moved = true;
            break;

        case 8: // '\b'
            Cell cur = data.getCurrentCell(false);
            Alert details;
            if(cur != null)
                details = new Alert(cur.getName() + " details", cur.getDetails(), null, null);
            else
                details = new Alert("Details", "This cell is empty", null, null);
            moved = true;
            details.setTimeout(-2);
            display.setCurrent(details, this);
            break;

        case 3: // '\003'
        case 4: // '\004'
        case 7: // '\007'
        default:
            if(code == -12)
            {
                menuAction((short)3, (short)3);
                moved = true;
                break;
            }
            if(code == 35)
            {
                data.getCurrentCell(true).edit(null, this, display);
                break;
            }
            if(code == 42 && moved)
            {
                code = 61;
                data.getCurrentCell(true).edit(String.valueOf((char)code), this, display);
                data.moveCursor(2);
                break;
            }
            if(code == 42)
                code = 8;
            moved = !data.getCurrentCell(true).appendChar((char)code, moved);
            break;
        }
        repaint();
    }

    private void setSubmenu(Displayable parent, final short menuIdx)
    {
        final SheetShow sheet = this;
        parent.setCommandListener(new CommandListener() {

            public void commandAction(Command cmd, Displayable obj)
            {
                short opt = (short)((List)obj).getSelectedIndex();
                sheet.menuAction(menuIdx, opt);
            }

        }
);
    }

    public void commandAction(Command cmd, Displayable obj)
    {
        short menuIdx = (short)cmd.getPriority();
        moved = true;
        if(MENUS[menuIdx] != null)
        {
            setSubmenu(MENUS[menuIdx], menuIdx);
            display.setCurrent(MENUS[menuIdx]);
        } else
        {
            menuAction(menuIdx, (short)0);
        }
    }

    private Table newSheet()
    {
        Font fnt = Font.getFont(64, 0, 8);
        short defw = (short)fnt.stringWidth("0000");
        short defh = (short)(fnt.getHeight() + 1);
        clipBoard = null;
        return new Table((short)10, (short)9, defw, defh);
    }

    public void menuAction(short menu, short opt)
    {
label0:
        switch(menu)
        {
        default:
            break;

        case 2: // '\002'
            showWait("Calculating...", new Runnable() {

                public void run()
                {
                    data.calculate();
                    show();
                }

            }
);
            break;

        case 4: // '\004'
            show();
            break;

        case 0: // '\0'
            switch(opt)
            {
            default:
                break;

            case 0: // '\0'
                data.getCurrentCell(true).edit(null, this, display);
                break label0;

            case 1: // '\001'
                data.clearCurrentCell();
                show();
                break label0;

            case 2: // '\002'
                clipBoard = data.getCurrentCell(false);
                show();
                break label0;

            case 3: // '\003'
                if(clipBoard != null)
                    data.getCurrentCell(true).paste(clipBoard);
                // fall through

            case 4: // '\004'
                show();
                break;
            }
            break;

        case 1: // '\001'
            switch(opt)
            {
            case 0: // '\0'
            {
                CellResize resz = new CellResize(data, this);
                display.setCurrent(resz);
                break;
            }

            case 1: // '\001'
            {
                List list = new List("Cell Colour", 3, Cell.colors, null);
                setSubmenu(list, (short)6);
                display.setCurrent(list);
                break;
            }

            case 2: // '\002'
            {
                List list = new List("Cell Alignment", 3, Cell.aligns, null);
                setSubmenu(list, (short)7);
                display.setCurrent(list);
                break;
            }

            case 3: // '\003'
            {
                show();
                break;
            }
            }
            break;

        case 5: // '\005'
            Alert scr = new Alert("Sheet help", "This is a small spreadsheet application capable of simple integer and string operations. You can find some hints in the Formula help (accessible from the formula editor).\n- To enter a numeric value, simply type the number ('*' serves as a backspace).\n- To enter a formula, press '*' key, then the formula editor will be opened with '=' pre-entered.\n- To simply edit a cell formula, press '#'.\n- Left softkey shows the full cell data.\n---\nMC, 2001", null, null);
            scr.setTimeout(-2);
            display.setCurrent(scr, this);
            break;

        case 3: // '\003'
            switch(opt)
            {
            case 0: // '\0'
                checkModified(new Runnable() {

                    public void run()
                    {
                        data = newSheet();
                        System.gc();
                        show();
                    }

                }
);
                break;

            case 1: // '\001'
                checkModified(new Runnable() {

                    public void run()
                    {
                        load();
                    }

                }
);
                break;

            case 2: // '\002'
                save(null);
                break;

            case 3: // '\003'
                checkModified(new Runnable() {

                    public void run()
                    {
                        SheetShow.winQuit.quit();
                    }

                }
);
                break;

            case 4: // '\004'
                show();
                break;
            }
            break;

        case 6: // '\006'
            data.getCurrentCell(true).setColor(opt);
            show();
            break;

        case 7: // '\007'
            data.getCurrentCell(true).setAlign(opt);
            show();
            break;
        }
    }
    private static final short TBL_WIDTH = 10;
    private static final short TBL_HEIGHT = 9;
    private static final short M_CELL_DATA = 0;
    private static final short M_CELL_FORMAT = 1;
    private static final short M_RECALC = 2;
    private static final short M_FILE = 3;
    private static final short M_CANCEL = 4;
    private static final short M_HELP = 5;
    private static final short M_E_COLOUR = 6;
    private static final short M_E_ALIGN = 7;
    private static final short MCD_EDIT = 0;
    private static final short MCD_CLEAR = 1;
    private static final short MCD_COPY = 2;
    private static final short MCD_PASTE = 3;
    private static final short MCD_BACK = 4;
    private static final short MCF_SIZE = 0;
    private static final short MCF_COLOUR = 1;
    private static final short MCF_ALIGN = 2;
    private static final short MCF_BACK = 3;
    private static final short MFM_NEW = 0;
    private static final short MFM_LOAD = 1;
    private static final short MFM_SAVE = 2;
    private static final short MFM_EXIT = 3;
    private static final short MFM_BACK = 4;
    private static final Command COMMANDS[] = {
        new Command("Cell Data", 1, 0), new Command("Cell Format", 1, 1), new Command("Recalculate", 1, 2), new Command("File", 1, 3), new Command("Cancel", 3, 4), new Command("Help", 5, 5)
    };
    private static final List MENUS[] = {
        new List("Cell Data", 3, new String[] {
            "Edit Cell", "Clear Cell", "Copy", "Paste", "Back to sheet"
        }, null), new List("Cell Format", 3, new String[] {
            "Cell Size", "Cell Colour", "Cell Alignment", "Back to sheet"
        }, null), null, new List("File", 3, new String[] {
            "New sheet", "Open", "Save", "Exit", "Back to sheet"
        }, null), null, null
    };
    private static final Command okCommand = new Command("Ok", 4, 1);
    private static final Command cancelCommand = new Command("Cancel", 3, 1);
    private static int appWidth;
    private static int appHeight;
    private static Display display;
    private static Quitable winQuit;
    private Table data;
    private Cell clipBoard;
    private boolean moved;
}
Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Cell.java

package sheet;

import javax.microedition.lcdui.*;

// Referenced classes of package sheet:
//            CellCalc, Operand, CellContainer, Backable, 
//            Calculator

final class Cell
{
    private static class Calculate
        implements Calculator
    {

        public void showHelp(Displayable back, Display disp)
        {
            Alert scr = new Alert("Formula help", "To enter a formula, start with '=' sign.\nCell reference: A1/a1..Z99/z99\nMath operators: +, -, *, /, ()\nForce textual value: ', or embrace with \"\"\nBuilt-in functions (case-insensitive):\n  abs(x)\n  sum(a, b, ...)\n  str(n)->string\n  num(s)->number", null, null);
            scr.setTimeout(-2);
            disp.setCurrent(scr, back);
        }

        private Operand checkOperand(Operand arg)
            throws IllegalArgumentException
        {
            if(Operand.isName(arg))
            {
                Cell c = Cell.parent.getByName(Operand.getName(arg));
                if(c != null)
                {
                    if(c.errMsg != null)
                        throw new IllegalArgumentException("'" + Operand.getName(arg) + "' doesn't have a value");
                    if(!c.calculated)
                        throw new IllegalArgumentException();
                    arg = c.result;
                } else
                {
                    arg = null;
                }
            }
            return arg;
        }

        public Operand oper(short operation, Operand op1, Operand op2)
            throws IllegalArgumentException
        {
            Operand a = checkOperand(op1);
            Operand b = checkOperand(op2);
            Operand res;
            switch(operation)
            {
            case 1: // '\001'
                res = new Operand(-Operand.getNumber(a));
                break;

            case 2: // '\002'
                if(Operand.isNumber(a) && Operand.isNumber(b))
                    res = new Operand(Operand.getNumber(a) + Operand.getNumber(b));
                else
                    res = new Operand(Operand.getText(a) + Operand.getText(b), false);
                break;

            case 3: // '\003'
                res = new Operand(Operand.getNumber(a) - Operand.getNumber(b));
                break;

            case 4: // '\004'
                res = new Operand(Operand.getNumber(a) * Operand.getNumber(b));
                break;

            case 5: // '\005'
                res = new Operand(Operand.getNumber(a) / Operand.getNumber(b));
                break;

            default:
                res = a;
                break;
            }
            return res;
        }

        public Operand call(String fname, Operand args[])
            throws IllegalArgumentException
        {
            String fnocase = fname.toLowerCase();
            StringBuffer addon = new StringBuffer("()");
            if(fnocase.equals("abs"))
            {
                if(args.length == 1)
                    return new Operand(Math.abs(Operand.getNumber(checkOperand(args[0]))));
                addon.append(" has 1 argument");
            } else
            if(fnocase.equals("str"))
            {
                if(args.length == 1)
                    return new Operand(Operand.getText(checkOperand(args[0])), false);
                addon.append(" has 1 argument");
            } else
            if(fnocase.equals("num"))
            {
                if(args.length == 1)
                {
                    Operand trial = new Operand(Operand.getText(checkOperand(args[0])), true);
                    if(Operand.isNumber(trial))
                        return trial;
                    addon.append(": '");
                    addon.append(trial);
                    addon.append("' is not a number");
                } else
                {
                    addon.append(" has 1 argument");
                }
            } else
            {
                if(fnocase.equals("sum"))
                {
                    int sum = 0;
                    for(int i = 0; i < args.length; i++)
                        sum += Operand.getNumber(checkOperand(args[i]));

                    return new Operand(sum);
                }
                addon.append(" doesn't exist");
            }
            throw new IllegalArgumentException(fname + addon.toString());
        }

        private Calculate()
        {
        }

    }


    public Cell(CellContainer cont, byte ccol, byte crow)
    {
        colorIdx = 0;
        alignIdx = 0;
        parent = cont;
        column = ccol;
        row = crow;
        calculated = true;
        render();
    }

    public boolean isData()
    {
        return colorIdx != 0 || formula != null;
    }

    public byte getRow()
    {
        return row;
    }

    public byte getColumn()
    {
        return column;
    }

    public void setColor(short color)
    {
        if(colorIdx != color)
        {
            colorIdx = color;
            parent.notifyChanged();
            render();
        }
    }

    public void setAlign(short align)
    {
        if(alignIdx != align)
        {
            alignIdx = align;
            parent.notifyChanged();
            render();
        }
    }

    public void render()
    {
        if(isData())
        {
            int cellWidth = parent.getColumnWidth(column);
            int cellHeight = parent.getRowHeight(row);
            Font font = Font.getFont(64, 0, 8);
            int h = cellHeight - font.getHeight();
            int dx = 1;
            String text = errMsg != null ? errMsg : result != null ? Operand.getText(result) : "";
            int slen = font.stringWidth(text);
            if(slen > 0)
            {
                int wid = cellWidth - 3;
                int ci = alignIdx;
                if(slen > wid)
                    slen = wid;
                if(ci == 0)
                    ci = result == null || !Operand.isNumber(result) ? 3 : 1;
                switch(ci)
                {
                case 1: // '\001'
                    dx = wid - slen;
                    break;

                case 2: // '\002'
                    dx = (wid - slen) / 2;
                    break;

                case 3: // '\003'
                    dx = 1;
                    break;
                }
            }
            image = Image.createImage(cellWidth, cellHeight);
            Graphics g = image.getGraphics();
            g.setColor(0);
            g.setFont(font);
            switch(colorIdx)
            {
            case 1: // '\001'
                int even = 1 - cellWidth % 2;
                for(int y = 1; y < cellHeight; y += 2)
                {
                    g.drawLine(0, y, cellHeight - 1 - y, cellHeight - 1);
                    g.drawLine(cellWidth - 1, y - even, (cellWidth - 1 - y) + even, 0);
                }

                for(int x = 1; x <= cellWidth - cellHeight; x += 2)
                    g.drawLine(x, 0, (x + cellHeight) - 1, cellHeight - 1);

                g.setColor(0xffffff);
                g.drawString(text, dx + 1, h + 1, 20);
                g.setColor(0);
                break;

            case 2: // '\002'
                g.fillRect(0, 0, cellWidth, cellHeight);
                g.setColor(0xffffff);
                break;
            }
            g.drawString(text, dx, h, 20);
        } else
        {
            image = null;
        }
    }

    public int paint(Graphics g, int left, int top)
    {
        if(image != null)
            g.drawImage(image, left, top, 20);
        return colorIdx != 2 ? 0 : 0xffffff;
    }

    public String getName()
    {
        char col = (char)(65 + column);
        return String.valueOf(col) + String.valueOf(row + 1);
    }

    public String getDetails()
    {
        StringBuffer str = new StringBuffer();
        if(formula != null)
        {
            str.append("Formula: ");
            str.append(formula);
            str.append("\n");
            if(errMsg != null)
            {
                str.append("Error: ");
                str.append(errMsg);
            } else
            if(result != null)
            {
                str.append("Result: ");
                str.append(Operand.getText(result));
            } else
            {
                str.append("No result");
            }
        }
        return str.toString();
    }

    public void notCalculated()
    {
        result = null;
        calculated = false;
    }

    public boolean isCalculated()
    {
        return calculated;
    }

    public void paste(Cell cell)
    {
        if(cell != null)
        {
            formula = cell.formula;
            colorIdx = cell.colorIdx;
            alignIdx = cell.alignIdx;
            parent.notifyChanged();
            parent.calculate();
        }
    }

    public boolean calculate()
    {
        calculated = true;
        errMsg = null;
        if(formula != null)
        {
            CellCalc parser = new CellCalc(calc);
            char fchar = formula.charAt(0);
            if(fchar == '=' && formula.length() > 1)
                try
                {
                    result = parser.calculate(formula, (short)1, (short)formula.length());
                }
                catch(IllegalArgumentException e)
                {
                    calculated = false;
                    result = null;
                    errMsg = e.getMessage();
                }
            else
            if(fchar == '\'')
                result = new Operand(formula.substring(1), false);
            else
                result = new Operand(formula, true);
        }
        render();
        return calculated;
    }

    public void edit(String def_str, final Backable back, final Display disp)
    {
        int mode = 0;
        if(def_str == null)
            def_str = formula;
        else
        if(def_str.length() > 0 && Character.isDigit(def_str.charAt(0)))
            mode = 2;
        String name = getName();
        final Command okCommand = new Command("Ok", 4, 0);
        Command cancelCommand = new Command("Cancel", 3, 0);
        final Command helpCommand = new Command("Help", 5, 0);
        TextBox editor = new TextBox(name, def_str, 50, mode);
        editor.setCommandListener(new CommandListener() {

            public void commandAction(Command cmd, Displayable obj)
            {
                TextBox me = (TextBox)obj;
                if(cmd == helpCommand)
                {
                    Cell.calc.showHelp(me, disp);
                } else
                {
                    if(cmd == okCommand)
                    {
                        if(formula != me.getString())
                        {
                            formula = me.getString();
                            if(formula.length() == 0)
                                formula = null;
                            Cell.parent.notifyChanged();
                        }
                        errMsg = null;
                        Cell.parent.calculate();
                    }
                    back.show();
                }
            }

        }
);
        editor.addCommand(okCommand);
        editor.addCommand(cancelCommand);
        editor.addCommand(helpCommand);
        disp.setCurrent(editor);
    }

    public boolean appendChar(char ch, boolean fromStart)
    {
        if(ch == '\b' && formula != null)
        {
            int len = formula.length();
            if(len > 1)
                formula = formula.substring(0, len - 1);
            else
                formula = null;
        } else
        if(fromStart || formula == null)
            formula = String.valueOf(ch);
        else
            formula += ch;
        parent.notifyChanged();
        parent.calculate();
        return formula != null && formula.length() != 0;
    }

    public byte[] serialize(int version)
    {
        byte data[];
        if(isData() && version == 1)
        {
            byte formb[] = formula != null ? formula.getBytes() : new byte[0];
            data = new byte[formb.length + 4];
            data[0] = column;
            data[1] = row;
            data[2] = (byte)colorIdx;
            data[3] = (byte)alignIdx;
            System.arraycopy(formb, 0, data, 4, formb.length);
        } else
        {
            data = null;
        }
        return data;
    }

    public static Cell deserialize(byte data[], CellContainer cont, int version)
    {
        Cell cell;
        if(version == 1 && data != null)
        {
            cell = new Cell(cont, data[0], data[1]);
            cell.colorIdx = data[2];
            cell.alignIdx = data[3];
            cell.formula = new String(data, 4, data.length - 4);
            if(cell.formula.length() == 0)
                cell.formula = null;
            cell.calculated = false;
        } else
        {
            cell = null;
        }
        return cell;
    }

    static final String colors[] = {
        "White", "Light Gray", "Black"
    };
    static final int BG_WHITE = 0;
    static final int BG_LGRAY = 1;
    static final int BG_BLACK = 2;
    static final String aligns[] = {
        "Default", "Right", "Center", "Left"
    };
    static final int AL_DEFAULT = 0;
    static final int AL_RIGHT = 1;
    static final int AL_CENTER = 2;
    static final int AL_LEFT = 3;
    private static CellContainer parent;
    private static Calculate calc = new Calculate();
    private byte column;
    private byte row;
    private short colorIdx;
    private short alignIdx;
    private String formula;
    private Operand result;
    private boolean calculated;
    private String errMsg;
    private Image image;

}
Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Table.java

package sheet;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.rms.RecordStore;

// Referenced classes of package sheet:
//            Cell, CellContainer, Sheet, Portable

final class Table
    implements CellContainer
{

    public Table(short nofHor, short nofVer, short defWidth, short defHeight)
    {
        cells = new Cell[nofHor][nofVer];
        rows = new short[nofVer];
        cols = new short[nofHor];
        szX = nofHor;
        szY = nofVer;
        for(int i = 0; i < nofHor; i++)
            cols[i] = defWidth;

        for(int i = 0; i < nofVer; i++)
            rows[i] = defHeight;

        name = "noname";
    }

    public void moveCursor(int dir)
    {
        switch(dir)
        {
        default:
            break;

        case 3: // '\003'
            if(cursorX > 0)
            {
                cursorX--;
                if(cursorX < tblLeft)
                    tblLeft--;
            } else
            {
                Sheet.ported.CannotMoveSignal();
            }
            break;

        case 4: // '\004'
            if(cursorX < szX - 1)
            {
                cursorX++;
                if(cursorX >= tblRight)
                    tblLeft++;
            } else
            {
                Sheet.ported.CannotMoveSignal();
            }
            break;

        case 1: // '\001'
            if(cursorY > 0)
            {
                cursorY--;
                if(cursorY < tblTop)
                    tblTop--;
            } else
            {
                Sheet.ported.CannotMoveSignal();
            }
            break;

        case 2: // '\002'
            if(cursorY < szY - 1)
            {
                cursorY++;
                if(cursorY >= tblBottom)
                    tblTop++;
            } else
            {
                Sheet.ported.CannotMoveSignal();
            }
            break;
        }
    }

    public short getColumnWidth(int col)
    {
        return cols[col];
    }

    public short getRowHeight(int row)
    {
        return rows[row];
    }

    public void setRowHeight(int row, short height)
    {
        rows[row] = height;
        for(int i = 0; i < szX; i++)
        {
            Cell cell = cells[i][row];
            if(cell != null)
                cell.render();
        }

        notifyChanged();
    }

    public void setColumnWidth(int col, short width)
    {
        cols[col] = width;
        for(int i = 0; i < szY; i++)
        {
            Cell cell = cells[col][i];
            if(cell != null)
                cell.render();
        }

        notifyChanged();
    }

    public void paint(Graphics g, int width, int height, int mode)
    {
        Font hdrFont = Font.getFont(64, 0, 8);
        int hdrH = hdrFont.getHeight() + 1;
        int hdrW = hdrFont.stringWidth("10") + 2;
        g.setColor(0);
        g.setFont(hdrFont);
        short i = tblLeft;
        int maxX;
        for(maxX = hdrW; maxX < width && i < szX; i++)
        {
            int w = getColumnWidth(i);
            char rn = (char)(65 + i);
            g.drawString(String.valueOf(rn), maxX + 1 + w / 2, 1, 17);
            maxX += w + 1;
        }

        tblRight = (short)(i - 1);
        g.drawLine(0, hdrH, maxX, hdrH);
        i = tblTop;
        int maxY;
        for(maxY = hdrH; maxY < height && i < szY; i++)
        {
            int h = getRowHeight(i);
            int x = hdrW;
            boolean isCurRow = i == cursorY;
            g.drawString(String.valueOf(i + 1), hdrW - 1, ((maxY + h) - hdrH) + 2, 24);
            for(int j = tblLeft; j <= tblRight; j++)
            {
                Cell c = cells[j][i];
                int w = getColumnWidth(j);
                int cursorColor = 0;
                if(c != null)
                    cursorColor = c.paint(g, x + 1, maxY + 1);
                if(j == cursorX && isCurRow)
                {
                    g.setColor(cursorColor);
                    g.drawRect(x + 1, maxY + 1, w - 1, h - 1);
                    g.setColor(0);
                }
                if(c != null && !c.isCalculated())
                {
                    int xe = x + w;
                    int ye = maxY + h;
                    g.drawLine(x + 1, maxY + 1, xe, ye);
                    g.drawLine(x + 1, ye, xe, maxY + 1);
                }
                x += w + 1;
            }

            maxY += h + 1;
            if(mode == 1 && isCurRow)
            {
                g.setStrokeStyle(1);
                g.drawLine(0, maxY, maxX, maxY);
                g.setStrokeStyle(0);
            } else
            {
                g.drawLine(0, maxY, maxX, maxY);
            }
        }

        tblBottom = (short)(i - 1);
        g.drawLine(hdrW, 0, hdrW, maxY);
        int ix = tblLeft;
        int cx = hdrW;
        for(; ix <= tblRight; ix++)
        {
            int w = getColumnWidth(ix);
            cx += w + 1;
            if(mode == 1 && ix == cursorX)
            {
                g.setStrokeStyle(1);
                g.drawLine(cx, 0, cx, maxY);
                g.setStrokeStyle(0);
            } else
            {
                g.drawLine(cx, 0, cx, maxY);
            }
        }

        if(dataChanged)
        {
            int crossX = hdrW / 2;
            int crossY = hdrH / 2;
            g.drawLine(crossX - 1, crossY - 1, crossX + 1, crossY + 1);
            g.drawLine(crossX + 1, crossY - 1, crossX - 1, crossY + 1);
        }
    }

    public Cell getByName(String name)
        throws IllegalArgumentException
    {
        try
        {
            int col = name.charAt(0) - 65;
            if(col >= szX)
                col = name.charAt(0) - 97;
            int row = Integer.parseInt(name.substring(1, name.length())) - 1;
            return cells[col][row];
        }
        catch(Exception exception)
        {
            throw new IllegalArgumentException("Wrong cell name '" + name + "'");
        }
    }

    public void notifyChanged()
    {
        dataChanged = true;
    }

    public boolean isChanged()
    {
        return dataChanged;
    }

    public void calculate()
    {
        int prevNotCalc = 0;
        int notCalc = -1;
        for(int ix = 0; ix < szX; ix++)
        {
            for(int iy = 0; iy < szY; iy++)
                if(cells[ix][iy] != null)
                    cells[ix][iy].notCalculated();

        }

        while(notCalc != 0 && prevNotCalc != notCalc) 
        {
            prevNotCalc = notCalc;
            notCalc = 0;
            for(int ix = 0; ix < szX; ix++)
            {
                for(int iy = 0; iy < szY; iy++)
                {
                    Cell cell = cells[ix][iy];
                    if(cell != null && !cell.isCalculated() && !cell.calculate())
                        notCalc++;
                }

            }

        }
    }

    public Cell getCurrentCell(boolean fCreate)
    {
        Cell curCell = cells[cursorX][cursorY];
        if(curCell == null && fCreate)
        {
            curCell = new Cell(this, cursorX, cursorY);
            cells[cursorX][cursorY] = curCell;
        }
        return curCell;
    }

    public void clearCurrentCell()
    {
        if(cells[cursorX][cursorY] != null)
        {
            cells[cursorX][cursorY] = null;
            notifyChanged();
        }
    }

    public int getCurrentColumn()
    {
        return cursorX;
    }

    public int getCurrentRow()
    {
        return cursorY;
    }

    public String getName()
    {
        return name;
    }

    public void save(String fname)
        throws IllegalArgumentException
    {
        name = fname;
        try
        {
            RecordStore.deleteRecordStore(fname);
        }
        catch(Exception exception) { }
        try
        {
            RecordStore rs = RecordStore.openRecordStore(fname, true);
            byte header[] = new byte[(szX + 1) * 2 + (szY + 1) * 2 + 3];
            header[0] = 1;
            header[1] = (byte)szX;
            header[2] = (byte)szY;
            int iwr = 3;
            for(int ic = 0; ic < szX; ic++)
            {
                short w = getColumnWidth(ic);
                header[iwr] = (byte)w;
                header[iwr + 1] = (byte)(w >>> 8);
                iwr += 2;
            }

            for(int ir = 0; ir < szY; ir++)
            {
                short h = getRowHeight(ir);
                header[iwr] = (byte)h;
                header[iwr + 1] = (byte)(h >>> 8);
                iwr += 2;
            }

            rs.addRecord(header, 0, header.length);
            for(int ix = 0; ix < szX; ix++)
            {
                for(int iy = 0; iy < szY; iy++)
                {
                    Cell cell = cells[ix][iy];
                    if(cell != null)
                    {
                        byte data[] = cell.serialize(1);
                        if(data != null)
                            rs.addRecord(data, 0, data.length);
                    }
                }

            }

            rs.closeRecordStore();
            dataChanged = false;
        }
        catch(Exception exception1)
        {
            throw new IllegalArgumentException("'" + fname + "' can't be saved");
        }
    }

    public static Table load(String fname)
        throws IllegalArgumentException
    {
        Table table;
        try
        {
            RecordStore rs = RecordStore.openRecordStore(fname, true);
            int nofrecs = rs.getNumRecords();
            byte header[] = rs.getRecord(1);
            int version = header[0];
            if(version != 1)
                throw new IllegalArgumentException();
            short szx = header[1];
            short szy = header[2];
            int ird = 3;
            table = new Table(szx, szy, (short)0, (short)0);
            table.name = fname;
            for(int ic = 0; ic < szx; ic++)
            {
                short w = (short)(header[ird] + (header[ird + 1] << 8));
                ird += 2;
                table.setColumnWidth(ic, w);
            }

            for(int ir = 0; ir < szy; ir++)
            {
                short h = (short)(header[ird] + (header[ird + 1] << 8));
                ird += 2;
                table.setRowHeight(ir, h);
            }

            for(int i = 2; i <= nofrecs; i++)
            {
                byte data[] = rs.getRecord(i);
                Cell cell = Cell.deserialize(data, table, version);
                if(cell != null)
                    table.cells[cell.getColumn()][cell.getRow()] = cell;
            }

            rs.closeRecordStore();
            table.dataChanged = false;
        }
        catch(Exception exception)
        {
            throw new IllegalArgumentException("'" + fname + "' can't be read");
        }
        return table;
    }

    public static final int UP = 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;
}
hupe12345 ist offline   Mit Zitat antworten
Antwort


Forumregeln
Du kannst keine neue Themen eröffnen
Du kannst keine Antworten verfassen
Du kannst keine Anhänge posten
Du kannst nicht deine Beiträge editieren

BB code is An
Smileys sind An.
[IMG] Code ist An.
HTML-Code ist Aus.

Gehe zu


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:52 Uhr.


Sitemap

().