FileSaveDialogS60.java
/*
* Copyright © 2012 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example.paint.views.components;
import com.nokia.example.paint.Main;
import com.nokia.example.paint.helpers.FileHandler;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
public class FileSaveDialogS60
extends TextBox
implements CommandListener {
private Command saveCmd;
private Command cancelCmd;
private Command backCmd;
public FileSaveDialogS60() {
super("Give filename", "", 50, TextField.ANY);
setCommandListener(this);
saveCmd = new Command("OK", Command.OK, 1);
addCommand(saveCmd);
cancelCmd = new Command("Cancel", Command.CANCEL, 1);
addCommand(cancelCmd);
/*
* Java Runtime 2.0 for Series 40 adds an extra back command,
* but it does not do anything by default
*/
try {
Class.forName("com.nokia.mid.ui.VirtualKeyboard");
backCmd = new Command("Back", Command.BACK, 1);
addCommand(backCmd);
}
catch (Exception e) {
}
}
public void commandAction(Command cmd, Displayable dsplbl) {
if (cmd == saveCmd) {
final Image saveable = Main.getInstance().getDrawArea().getDrawing();
FileHandler.saveImageToFile(this.getString(), saveable);
}
else if (cmd == cancelCmd || cmd == backCmd) {
Main.getInstance().showDrawing();
}
Main.getInstance().getDrawArea().allowDrawing(true);
}
}