Browse Source

Minor tweaks

- Display file name in window title
- More keyboard shortcuts
- NewAccountDialog cancel button
Tankernn 8 years ago
parent
commit
8653348136

+ 1 - 0
src/main/java/eu/tankernn/accounts/AccountManager.java

@@ -111,6 +111,7 @@ public class AccountManager {
 			FileManager.saveFile(CachedFileChooser.selectFile(saveAs), data);
 		}
 		lastJSONString = data;
+		refresh.run();
 	}
 
 	/**

+ 1 - 1
src/main/java/eu/tankernn/accounts/CachedFileChooser.java

@@ -20,7 +20,7 @@ public class CachedFileChooser {
 		return f;
 	}
 
-	private static File getLastFileFromCache() {
+	public static File getLastFileFromCache() {
 		// Open last file
 		try {
 			// Create file to cache last filename

+ 15 - 3
src/main/java/eu/tankernn/accounts/frame/MainFrame.java

@@ -6,6 +6,7 @@ import java.awt.EventQueue;
 import java.awt.LayoutManager;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.io.File;
 
 import javax.swing.JFrame;
 import javax.swing.JList;
@@ -19,6 +20,7 @@ import javax.swing.event.ListSelectionListener;
 
 import eu.tankernn.accounts.Account;
 import eu.tankernn.accounts.AccountManager;
+import eu.tankernn.accounts.CachedFileChooser;
 import eu.tankernn.accounts.frame.menu.MainMenuBar;
 import eu.tankernn.accounts.util.GUIUtils;
 
@@ -95,9 +97,7 @@ public class MainFrame implements ListSelectionListener, DocumentListener {
 		// Ask the user to save changes before quitting
 		frame.addWindowListener(new WindowAdapter() {
 			public void windowClosing(WindowEvent ev) {
-				if (AccountManager.closeFile()) {
-					frame.dispose();
-				}
+				exit();
 			}
 		});
 	}
@@ -107,16 +107,28 @@ public class MainFrame implements ListSelectionListener, DocumentListener {
 		if (accounts.getSelectedValue() != null)
 			accountPanel.updatePanel(accounts.getSelectedValue());
 	}
+	
+	public void exit() {
+		if (AccountManager.closeFile()) {
+			frame.dispose();
+		}
+	}
 
 	public void refresh() {
 		accounts.setModel(GUIUtils.listModelFromList(AccountManager.getAccounts()));
 		accountPanel.updatePanel(null);
+		File f = CachedFileChooser.getLastFileFromCache();
+		this.setTitleFilename(f == null ? "New file" : f.getName());
 	}
 
 	private void search() {
 		String s = search.getText().trim();
 		accounts.setModel(GUIUtils.listModelFromList(AccountManager.search(s)));
 	}
+	
+	private void setTitleFilename(String name) {
+		frame.setTitle("Account Management System - " + name);
+	}
 
 	// Update list on search field change
 

+ 1 - 1
src/main/java/eu/tankernn/accounts/frame/NewAccountDialog.java

@@ -20,7 +20,7 @@ public class NewAccountDialog {
 	 * Create the dialog.
 	 */
 	public NewAccountDialog() {
-		result = JOptionPane.showConfirmDialog(null, components, "New Account", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE);
+		result = JOptionPane.showConfirmDialog(null, components, "New Account", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
 	}
 
 	public String getFirstName() {

+ 6 - 4
src/main/java/eu/tankernn/accounts/frame/menu/MainMenuBar.java

@@ -48,16 +48,18 @@ public class MainMenuBar extends JMenuBar implements ActionListener {
 		// File menu
 		addMenuWithItems(fileMenu, newFile, openFile, saveFile, saveFileAs);
 
-		newFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
-		openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
-		saveFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
-		saveFileAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK | Event.SHIFT_MASK));
+		newFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.META_MASK));
+		openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.META_MASK));
+		saveFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.META_MASK));
+		saveFileAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.META_MASK | Event.SHIFT_MASK));
 
 		// Database menu
 		addMenuWithItems(database, importDatabase, exportDatabase);
 
 		// Accounts menu
 		addMenuWithItems(accountMenu, newAccount, refresh);
+		newAccount.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.META_MASK | Event.SHIFT_MASK));
+		refresh.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
 
 		// Options menu
 		addMenuWithItems(optionsMenu, useEncryption);