Mercurial > hg > jslab
view src/samer/core_/viewers/swing/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.swing; import samer.core.types.*; import samer.core.util.*; import samer.core.*; import java.io.*; import javax.swing.*; public class FileViewer extends StringViewer { VFile vfile; public FileViewer(Viewable v) { this((VFile)v); } public FileViewer(VFile vfile) { super(vfile); this.vfile=vfile; JButton b=new JButton("..."); b.addActionListener(new AgentAdapter(this)); add(Box.createHorizontalStrut(4)); add(b); } public void getCommands(Agent.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=getParent(); //while (cont!=null && !(cont instanceof Frame)) { cont=cont.getParent(); } JFileChooser fc = new JFileChooser(vfile.getFile()); fc.setCurrentDirectory(vfile.getFile().getAbsoluteFile()); fc.setDialogTitle(vfile.getNode().fullName()); try { if (vfile.getFile().isDirectory()) fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } catch (Exception ex) {} if (fc.showDialog(panel(),"Select")==fc.APPROVE_OPTION) { vfile.setFile(fc.getSelectedFile()); vfile.changed(); } } else super.execute(cmd,env); } }