Package com.mapmidlet.gps

Source Code of com.mapmidlet.gps.LoadGpsLogForm

/*
* 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; version 3 of the License.
*
* 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.
*
* Author: Damian Waradzyn
*/
package com.mapmidlet.gps;

import java.io.IOException;

import javax.microedition.lcdui.*;

import com.mapmidlet.CloudGps;
import com.mapmidlet.misc.IOTool;
import com.mapmidlet.options.Options;
import com.mapmidlet.tile.ui.TileCanvas;

/**
* User interface responsible for choosing a NMEA file - just a simple file
* browser.
*
* @author Damian Waradzyn
*/
public class LoadGpsLogForm extends List implements CommandListener {

    public LoadGpsLogForm(TileCanvas tileCanvas) {
        super("Choose NMEA log file", IMPLICIT);
        addCommand(new Command("Open", Command.ITEM, 1));
        addCommand(new Command("Cancel", Command.CANCEL, 2));
        setCommandListener(this);
    }

    public void populateList() {
        String[] files = null;
        Options options = Options.getInstance();
        boolean retry = false;

        try {
            files = IOTool.listDir(options.replayDir);
        } catch (IOException io) {
            // io.printStackTrace();
            retry = true;
        } catch (IllegalArgumentException iae) {
            // iae.printStackTrace();
            retry = true;
        }

        if (retry) {
            options.replayDir = "file:///" + options.rootName;
            try {
                files = IOTool.listDir(options.replayDir);
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
        }
        deleteAll();

        int shlashPos = options.replayDir.indexOf('/', 8);
        if (shlashPos >= 0 && shlashPos < options.replayDir.length() - 1) {
            append("..", options.skin.getImage("up_dir.png"));
        }
        for (int i = 0; i < files.length; i++) {
            append(files[i], options.skin.getImage(files[i].endsWith("/") ? "dir.png" : "file.png"));
        }

    }

    public void commandAction(Command c, Displayable d) {
        String label = c.getLabel();
        if ("Open".equals(label) && getSelectedIndex() >= 0) {
            Options options = Options.getInstance();
            String selectedFile = getString(getSelectedIndex());
            if (getSelectedIndex() == 0 && "..".equals(getString(getSelectedIndex()))) {
                if (options.replayDir.endsWith("/")) {
                    options.replayDir = options.replayDir.substring(0, options.replayDir.length() - 2);
                }
                options.replayDir = options.replayDir.substring(0, options.replayDir.lastIndexOf('/') + 1);
                populateList();
                // TODO zaznaczenie katalogu, z kt�rego nast�pi�o wyj�cie w
                // g�r�.
            } else {
                if (selectedFile.endsWith("/")) {
                    if (options.replayDir.endsWith("/")) {
                        options.replayDir += selectedFile;
                    } else {
                        options.replayDir += "/" + selectedFile;
                    }
                    populateList();
                } else {
                    options.replayMode = true;
                    options.replayFileName = options.replayDir + (options.replayDir.endsWith("/") ? "" : "/")
                            + selectedFile;

                    CloudGps.getGpsConnection().close();
                    try {
                        CloudGps.getGpsConnection().open();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    CloudGps.showTileCanvas();
                }
            }
        } else if ("Cancel".equals(label)) {
            CloudGps.showTileCanvas();
        }
    }
}
TOP

Related Classes of com.mapmidlet.gps.LoadGpsLogForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.