Newer
Older
MagnetRON / src / org / ntlab / actions / OpenAction.java
  1. package org.ntlab.actions;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.io.File;
  5.  
  6. import javax.swing.JFileChooser;
  7. import javax.swing.UIManager;
  8. import javax.swing.filechooser.FileFilter;
  9.  
  10. import org.ntlab.deltaViewer.IMagnetRON;
  11.  
  12. /**
  13. *
  14. *
  15. * @author Nitta Lab.
  16. */
  17. public class OpenAction extends AbstractMagnetRONAction {
  18. private static final long serialVersionUID = -3935721814268952040L;
  19.  
  20. private String lastDir = null;
  21. private String fileDesc = "MagnetRON File";
  22. public OpenAction(IMagnetRON magnetRON) {
  23. super("Open File...", magnetRON);
  24. }
  25.  
  26. public OpenAction(String name, IMagnetRON magnetRON) {
  27. super(name, magnetRON);
  28. }
  29.  
  30. public OpenAction(String name, IMagnetRON magnetRON, String fileDesc) {
  31. super(name, magnetRON);
  32. this.fileDesc = fileDesc;
  33. }
  34.  
  35. @Override
  36. public void actionPerformed(ActionEvent e) {
  37. String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir");
  38. UIManager.put("FileChooser.acceptAllFileFilterText", "All files");
  39. UIManager.put("FileChooser.lookInLabelText", "Location");
  40. UIManager.put("FileChooser.cancelButtonText", "Cancel");
  41. UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel");
  42. UIManager.put("FileChooser.openButtonText", "Open");
  43. UIManager.put("FileChooser.openButtonToolTipText", "Open File");
  44. UIManager.put("FileChooser.filesOfTypeLabelText", "Type");
  45. UIManager.put("FileChooser.fileNameLabelText", "File");
  46. UIManager.put("FileChooser.listViewButtonToolTipText", "List");
  47. UIManager.put("FileChooser.listViewButtonAccessibleName", "List");
  48. UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
  49. UIManager.put("FileChooser.detailsViewButtonAccessibleName", "Details");
  50. UIManager.put("FileChooser.upFolderToolTipText", "Up one level");
  51. UIManager.put("FileChooser.upFolderAccessibleName", "Up one level");
  52. UIManager.put("FileChooser.homeFolderToolTipText", "Workplace");
  53. UIManager.put("FileChooser.homeFolderAccessibleName", "Workplace");
  54. UIManager.put("FileChooser.fileNameHeaderText", "Name");
  55. UIManager.put("FileChooser.fileSizeHeaderText", "Size");
  56. UIManager.put("FileChooser.fileTypeHeaderText", "Type");
  57. UIManager.put("FileChooser.fileDateHeaderText", "Date");
  58. UIManager.put("FileChooser.fileAttrHeaderText", "Attributes");
  59. UIManager.put("FileChooser.openDialogTitleText","Open file");
  60. UIManager.put("FileChooser.readOnly", Boolean.TRUE);
  61. JFileChooser fc = new JFileChooser(wd);
  62. FileFilter defaultFilter = new FileFilter() {
  63. public boolean accept(File file) {
  64. String lcase = file.getName().toLowerCase();
  65. return lcase.endsWith(".magnet");
  66. }
  67. @Override
  68. public String getDescription() {
  69. return fileDesc;
  70. }
  71. };
  72. fc.addChoosableFileFilter(defaultFilter);
  73. int rc = fc.showOpenDialog(null);
  74. if (rc == JFileChooser.APPROVE_OPTION) {
  75. lastDir = fc.getSelectedFile().getParent();
  76. magnetRON.open(fc.getSelectedFile());
  77. }
  78. }
  79.  
  80. }