| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.menu.items; |
| 5 | |
|
| 6 | |
import java.awt.Toolkit; |
| 7 | |
import java.awt.event.ActionEvent; |
| 8 | |
import java.awt.event.KeyEvent; |
| 9 | |
import java.io.File; |
| 10 | |
import java.util.logging.Level; |
| 11 | |
import java.util.logging.Logger; |
| 12 | |
|
| 13 | |
import javax.swing.KeyStroke; |
| 14 | |
|
| 15 | |
import org.homeunix.thecave.buddi.Const; |
| 16 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 17 | |
import org.homeunix.thecave.buddi.i18n.keys.ButtonKeys; |
| 18 | |
import org.homeunix.thecave.buddi.i18n.keys.MenuKeys; |
| 19 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
| 20 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 21 | |
import org.homeunix.thecave.buddi.util.OperationCancelledException; |
| 22 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 23 | |
|
| 24 | |
import ca.digitalcave.moss.application.document.exception.DocumentLoadException; |
| 25 | |
import ca.digitalcave.moss.swing.MossFrame; |
| 26 | |
import ca.digitalcave.moss.swing.MossMenuItem; |
| 27 | |
import ca.digitalcave.moss.swing.MossSmartFileChooser; |
| 28 | |
import ca.digitalcave.moss.swing.exception.WindowOpenException; |
| 29 | |
|
| 30 | |
public class FileOpen extends MossMenuItem { |
| 31 | |
public static final long serialVersionUID = 0; |
| 32 | |
|
| 33 | |
public FileOpen(MossFrame frame) { |
| 34 | 5975 | super(frame, PrefsModel.getInstance().getTranslator().get(MenuKeys.MENU_FILE_OPEN), |
| 35 | |
KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); |
| 36 | 5975 | } |
| 37 | |
|
| 38 | |
@Override |
| 39 | |
public void actionPerformed(ActionEvent e) { |
| 40 | 138 | File f = MossSmartFileChooser.showOpenDialog( |
| 41 | |
getFrame(), |
| 42 | |
Const.FILE_FILTER_DATA, |
| 43 | |
PrefsModel.getInstance().getTranslator().get(BuddiKeys.FILECHOOSER_OPEN_DATA_FILE_TITLE), |
| 44 | |
PrefsModel.getInstance().getTranslator().get(ButtonKeys.BUTTON_OK), |
| 45 | |
PrefsModel.getInstance().getTranslator().get(BuddiKeys.MESSAGE_ERROR_CANNOT_WRITE_DATA_FILE), |
| 46 | |
PrefsModel.getInstance().getTranslator().get(BuddiKeys.MESSAGE_ERROR_CANNOT_READ_DATA_FILE), |
| 47 | |
PrefsModel.getInstance().getTranslator().get(BuddiKeys.ERROR)); |
| 48 | |
|
| 49 | 18 | if (f == null) |
| 50 | 18 | return; |
| 51 | |
|
| 52 | |
try { |
| 53 | 0 | MainFrame mainFrame = new MainFrame(ModelFactory.createDocument(f)); |
| 54 | 0 | mainFrame.openWindow( |
| 55 | |
PrefsModel.getInstance().getWindowSize(f + ""), |
| 56 | |
PrefsModel.getInstance().getWindowLocation(f + "")); |
| 57 | |
} |
| 58 | 0 | catch (OperationCancelledException oce){ |
| 59 | 0 | Logger.getLogger(this.getClass().getName()).finest("User cancelled open operation"); |
| 60 | |
} |
| 61 | 0 | catch (DocumentLoadException dle){ |
| 62 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading file", dle); |
| 63 | |
} |
| 64 | 0 | catch (WindowOpenException woe){} |
| 65 | 0 | } |
| 66 | |
} |