001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 005 package graphlab.samples.ui.texteditor.myplugin.actions; 006 007 import graphlab.platform.core.BlackBoard; 008 import graphlab.ui.extension.UIActionExtension; 009 010 import javax.swing.*; 011 import java.io.File; 012 013 public class OpenAction implements UIActionExtension { 014 015 public void actionPerformed(BlackBoard blackBoard) { 016 //Show the file editor 017 JFileChooser jfc = new JFileChooser(); 018 jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); 019 jfc.setMultiSelectionEnabled(false); 020 021 int ret = jfc.showOpenDialog(null); 022 if (ret == JFileChooser.APPROVE_OPTION) { 023 File selectedFile = jfc.getSelectedFile(); 024 025 //fetch the text area (body of application) from blackboard 026 JTextArea editor = Utils.getMainEditor(blackBoard); 027 028 //read the file and put it in editor 029 editor.setText(ReadWriteTextFile.getContents(selectedFile)); 030 031 //put the file address in blackboard to use later in save 032 blackBoard.setData("last file", selectedFile.getAbsolutePath()); 033 } 034 } 035 036 }