- Card card = action.getCard();
- Contact contact = action.getContact();
- Data data = action.getData();
-
- switch (action.getMode()) {
- case MOVE:
- int x = 0;
- int y = 0;
-
- if (action.getKey().getKeyType() == KeyType.ArrowUp)
- x = -1;
- if (action.getKey().getKeyType() == KeyType.ArrowDown)
- x = 1;
- if (action.getKey().getKeyType() == KeyType.ArrowLeft)
- y = -1;
- if (action.getKey().getKeyType() == KeyType.ArrowRight)
- y = 1;
-
- if (content != null) {
- String err = content.move(x, y);
- if (err != null)
- setMessage(err, true);
- }
-
- break;
- // mode with windows:
- case CONTACT_LIST:
- if (card != null) {
- pushContent(new ContactList(card));
- }
- break;
- case CONTACT_DETAILS:
- if (contact != null) {
- pushContent(new ContactDetails(contact));
- }
- break;
- // mode interpreted by MainWindow:
- case HELP:
- // TODO
- // setMessage("Help! I need somebody! Help!", false);
- if (answer == null) {
- setQuestion(key, "Test question?", "[initial]");
- } else {
- setMessage("You answered: " + answer, false);
- }
-
- break;
- case BACK:
- String warning = content.getExitWarning();
- if (warning != null) {
- if (answer == null) {
- setQuestion(key, warning);
- } else {
- setMessage(null, false);
- if (answer.equalsIgnoreCase("y")) {
- popContent();
- }
- }
- } else {
- popContent();
- }
-
- if (contentStack.size() == 0) {
- close();
- }
-
- break;
- // action modes:
- case EDIT_DETAIL:
- if (answer == null) {
- if (data != null) {
- String name = data.getName();
- String value = data.getValue();
- setQuestion(key, name, value);
- }
- } else {
- setMessage(null, false);
- data.setValue(answer);
- }
- break;
- case DELETE_CONTACT:
- if (answer == null) {
- if (contact != null) {
- setQuestion(key, "Delete contact? [Y/N]");
- }
- } else {
- setMessage(null, false);
- if (answer.equalsIgnoreCase("y")) {
- if (contact.delete()) {
- content.refreshData();
- invalidate();
- setTitle();
- } else {
- setMessage("Cannot delete this contact", true);
- }
- }
- }
- break;
- case SAVE_CARD:
- if (answer == null) {
- if (card != null) {
- setQuestion(key, "Save changes? [Y/N]");
- }
- } else {
- setMessage(null, false);
- if (answer.equalsIgnoreCase("y")) {
- boolean ok = false;
- try {
- if (card.save()) {
- ok = true;
- invalidate();
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
-
- if (!ok) {
- setMessage("Cannot save to file", true);
- }
- }
- }
- break;
- default:
- case NONE:
- break;
- }