use of gate.util.ExtensionFileFilter in project gate-core by GateNLP.
the class LogArea method getComponentToDisplay.
// LogArea
public JComponent getComponentToDisplay() {
// don't build the display more than once
if (logTab != null)
return logTab;
// create the main panel we will return so we can add things to it
logTab = new JPanel(new BorderLayout());
JToolBar toolbar = new JToolBar(JToolBar.HORIZONTAL);
toolbar.setFloatable(false);
JButton btnClear = new JButton(MainFrame.getIcon("ClearLog"));
btnClear.setToolTipText("Clear Log");
btnClear.addActionListener(clearAllAction);
btnScrollLock = new JToggleButton(MainFrame.getIcon("ScrollLock"), userConfig.getBoolean("ScrollLock", Boolean.FALSE));
btnScrollLock.setToolTipText("Scroll Lock");
btnScrollLock.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
userConfig.put("ScrollLock", btnScrollLock.isSelected());
}
});
logSizeModel = new SpinnerNumberModel(userConfig.getInt("LogSize", 80000).intValue(), 0, Integer.MAX_VALUE, 1);
logSizeModel.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
userConfig.put("LogSize", logSizeModel.getValue());
}
});
final JSpinner spinLogSize = new JSpinner(logSizeModel);
if (spinLogSize.getEditor() instanceof JSpinner.DefaultEditor) {
JTextField textField = ((JSpinner.DefaultEditor) spinLogSize.getEditor()).getTextField();
textField.setColumns(5);
}
cboLogSize = new JCheckBox("Max Log Size (chars)", userConfig.getBoolean("LimitLogSize", Boolean.TRUE));
cboLogSize.setOpaque(false);
spinLogSize.setEnabled(cboLogSize.isSelected());
cboLogSize.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
spinLogSize.setEnabled(cboLogSize.isSelected());
userConfig.put("LimitLogSize", cboLogSize.isSelected());
}
});
toolbar.add(cboLogSize);
toolbar.add(spinLogSize);
toolbar.addSeparator();
Icon fileIcon = MainFrame.getIcon("OpenFile");
final JButton btnLogFile = new JButton(fileIcon);
BufferedImage disabledIcon = new BufferedImage(fileIcon.getIconWidth(), fileIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = disabledIcon.createGraphics();
g2d.setComposite(AlphaComposite.SrcOver.derive(0.1f));
fileIcon.paintIcon(null, g2d, 0, 0);
btnLogFile.setDisabledIcon(new ImageIcon(disabledIcon));
btnLogFile.setToolTipText("Select Log File");
btnLogFile.setEnabled(userConfig.getBoolean("LogToFile", Boolean.FALSE));
final JTextField txtLogFile = new JTextField(20);
logFile = userConfig.getFile("LogFile");
if (logFile != null) {
try {
if (btnLogFile.isEnabled())
logFileWriter = new PrintWriter(new FileWriter(logFile, true));
txtLogFile.setText(logFile.getAbsolutePath());
} catch (IOException ioe) {
logFile = null;
}
}
btnLogFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
XJFileChooser fileChooser = MainFrame.getFileChooser();
ExtensionFileFilter filter = new ExtensionFileFilter("Log Files (*.txt)", "txt");
fileChooser.addChoosableFileFilter(filter);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setDialogTitle("Log File");
if (fileChooser.showSaveDialog(MainFrame.getInstance()) != JFileChooser.APPROVE_OPTION)
return;
File logFile = fileChooser.getSelectedFile();
if (logFile == null)
return;
try {
logFileWriter = new PrintWriter(new FileWriter(logFile, true));
userConfig.put("LogFile", logFile);
txtLogFile.setText(logFile.getAbsolutePath());
} catch (IOException ioe) {
logFile = null;
logFileWriter = null;
txtLogFile.setText("");
userConfig.remove("LogFile");
ioe.printStackTrace();
}
}
});
txtLogFile.setEditable(false);
txtLogFile.setEnabled(btnLogFile.isEnabled());
cboAppend = new JCheckBox("Append To", btnLogFile.isEnabled());
cboAppend.setOpaque(false);
cboAppend.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try {
logFileWriter = cboAppend.isSelected() && logFile != null ? new PrintWriter(new FileWriter(logFile, true)) : null;
btnLogFile.setEnabled(cboAppend.isSelected());
txtLogFile.setEnabled(cboAppend.isSelected());
userConfig.put("LogToFile", cboAppend.isSelected());
} catch (IOException e) {
logFile = null;
logFileWriter = null;
txtLogFile.setText("");
userConfig.remove("LogFile");
e.printStackTrace();
}
}
});
toolbar.add(cboAppend);
toolbar.add(txtLogFile);
toolbar.add(btnLogFile);
toolbar.addSeparator();
toolbar.add(Box.createHorizontalGlue());
toolbar.add(btnClear);
toolbar.add(btnScrollLock);
// add the text area as the main component, inside a scroller
logTab.add(new JScrollPane(this), BorderLayout.CENTER);
logTab.add(toolbar, BorderLayout.SOUTH);
// return the display
return logTab;
}
Aggregations