view src/samer/core_/viewers/FileViewer.java @ 5:b67a33c44de7

Remove some crap, etc
author samer
date Fri, 05 Apr 2019 21:34:25 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	FileViewer.java	
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.core.viewers;
import  samer.core.types.*;
import  samer.core.util.*;
import  samer.core.*;
import  samer.core.Agent.*;
import  java.io.*;
import  java.awt.*;

public class FileViewer extends StringViewer
{
	VFile	vfile;

	public FileViewer(Viewable v) { this((VFile)v); }
	public FileViewer(VFile vfile) 
	{ 
		super(vfile); this.vfile=vfile; 
		Button b=new Button("...");
		b.addActionListener(new AgentAdapter(this));

		panel().add(b,"East");
	}

	public void getCommands(Registry r) { r.add("select"); super.getCommands(r); }
	public void	execute(String cmd, Environment env) throws Exception
	{
		if (cmd.equals("select") || cmd.equals("...")) {

			Container cont=panel().getParent();
			while (cont!=null && !(cont instanceof Frame)) { cont=cont.getParent(); }
			
			FileDialog dlg = new FileDialog((Frame)cont, "Select file", FileDialog.LOAD);
			dlg.setDirectory(vfile.getFile().getParent());
			dlg.setFile(vfile.getFile().getName());
			dlg.setVisible(true);
			dlg.dispose();
			// what if cancelled?

			vfile.setFile(new File(dlg.getDirectory(),dlg.getFile()));
			vfile.changed();
		} else super.execute(cmd,env);
	}
}