package jas2.jds.module;
import jas2.util.*;
import java.util.*;
import hepjas.analysis.*;
import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
/**
* An abstract implementation of LocalDIM2 suitable for DIM's which
* simply want to open a single file of a particular type
* @see MultiFileLocalDIM
*/
public abstract class BasicLocalDIM implements LocalDIM2
{
/**
* Create a BasicLocalDIM.
*
* Specify a FileFilter that describes the type of files you want
* to open.
*/
public BasicLocalDIM(FileFilter f)
{
this.fileFilter = f;
}
/**
* Create a BasicLocalDIM.
*
* Specify a description of the files, and a filetype (e.g. .hbook)
* @param description Description of the files
* @param filetype The file type
*/
public BasicLocalDIM(String description, String filetype)
{
this(new BasicFileFilter(description,filetype));
}
public JASWizardPage getSetupPage()
{
return new BasicWizardPage();
}
public void setLocalJobBuilder(LocalJobBuilder ljb)
{
m_ljb = ljb;
}
public FileFilter getFileFilter()
{
return fileFilter;
}
/**
* Override to provide your own description of the filetype in the
* LocalJobWizard page. By default uses the description from the file
* filter.
*/
public String toString()
{
return fileFilter.getDescription();
}
/**
* Override to provide your own help topic
*/
public String getHelpTopic()
{
return "builtInModules.BasicLocalDIM";
}
class BasicWizardPage extends JASWizardPage implements Finishable, HasHelpPage
{
BasicWizardPage()
{
super(new BorderLayout());
m_filePanel = new OpenLocalFilePanel(false,false,BasicLocalDIM.this.getClass().getName(),fileFilter);
add(BorderLayout.NORTH, m_filePanel);
}
public void onFinish()
{
String fileName = m_filePanel.getText();
if (fileName.length() == 0)
{
JOptionPane.showMessageDialog(this, "You must enter a file name.",
"Error...", JOptionPane.ERROR_MESSAGE);
return; // dispose not called, so wizard stays open
}
m_ljb.createJob(fileName);
m_filePanel.saveState(); // only if successfully opened file
dispose();
}
public String getHelpTopic()
{
return BasicLocalDIM.this.getHelpTopic();
}
OpenLocalFilePanel m_filePanel;
}
private static class BasicFileFilter extends FileFilter
{
BasicFileFilter(String description, String filetype)
{
this.description = description;
this.filetype = filetype;
}
public boolean accept(java.io.File f)
{
return f.isDirectory() || f.getName().endsWith(filetype);
}
public String getDescription()
{
return description;
}
private String description;
private String filetype;
}
private FileFilter fileFilter;
transient LocalJobBuilder m_ljb;
}
Ads help maintain this website.