Newer
Older
MagnetRON / src / org / ntlab / actions / OpenAction.java
package org.ntlab.actions;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

import org.ntlab.deltaViewer.IMagnetRON;

public class OpenAction extends AbstractMagnetRONAction {
	
	private String lastDir = null;

	public OpenAction(IMagnetRON magnetRON) {
		super("開く...", magnetRON);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String wd = (lastDir  != null) ? lastDir : System.getProperty("user.dir");
		JFileChooser fc = new JFileChooser(wd);
		// Adds file filter for supported file format
		FileFilter defaultFilter = new FileFilter() {
			public boolean accept(File file) {
				String lcase = file.getName().toLowerCase();
				return lcase.endsWith(".magnet");
			}
			@Override
			public String getDescription() {
				return "MagnetRONファイル";
			}
		};
		fc.addChoosableFileFilter(defaultFilter);
		int rc = fc.showOpenDialog(null);
		if (rc == JFileChooser.APPROVE_OPTION) {
			lastDir = fc.getSelectedFile().getParent();
			magnetRON.open(fc.getSelectedFile());
		}
	}

}