locationload.java

来自「这是一个手机上的J2ME程序」· Java 代码 · 共 69 行

JAVA
69
字号
// J2ME Compass
// Copyright (C) 2007 Dana Peters
// http://www.qcontinuum.org/compass

package org.qcontinuum.compass;

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

public class LocationLoad extends List implements CommandListener {
    
    private boolean mDestination;
    private Displayable mParent, mGrandParent;
    private Command mLoadCommand, mDeleteCommand, mCancelCommand;
    
    public LocationLoad(boolean destination, Displayable parent, Displayable grandParent) {
        super("Load", List.IMPLICIT);
        mDestination = destination;
        mParent = parent;
        mGrandParent = grandParent;
        String recordStores[] = RecordStore.listRecordStores();
        if (recordStores != null) {
            for (int i = 0; i < recordStores.length; i++) {
                if (recordStores[i].compareTo("preferences") != 0) {
                    int j;
                    for (j = 0; j < size(); j++)
                        if (recordStores[i].compareTo(getString(j)) < 0)
                            break;
                    insert(j, recordStores[i], null);
                }
            }
        }
        if (size() == 0) {
            append("[none]", null);
            mLoadCommand = null;
            mDeleteCommand = null;
        } else {
            addCommand(mLoadCommand = new Command("Load", Command.OK, 0));
            addCommand(mDeleteCommand = new Command("Delete", Command.SCREEN, 1));
        }
        addCommand(mCancelCommand = new Command("Cancel", Command.CANCEL, 0));
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)  {
        String locationName = getString(getSelectedIndex());
        if (mLoadCommand != null && (c == List.SELECT_COMMAND || c == mLoadCommand)) {
            Location location = new Location(locationName);
            Preferences preferences = Compass.getPreferences();
            if (mDestination)
                preferences.setDestination(location);
            else
                preferences.setLocation(location);
            preferences.save();
            Compass.setRefresh(true);
            Compass.display(mGrandParent);
        } else if (mDeleteCommand != null && c == mDeleteCommand) {
            try {
                RecordStore.deleteRecordStore(locationName);
                Compass.display("Deleted \"" + locationName + "\".", 3, mParent);
            } catch (RecordStoreException e) {
                Compass.display(e);
            }
        } else if (c == mCancelCommand) {
            Compass.display(mParent);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?