*/
package jalview.gui;
-import jalview.util.MessageManager;
-
import java.awt.BorderLayout;
+import java.awt.Color;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.PrintStream;
import javax.swing.JButton;
+import javax.swing.JComboBox;
import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
+import org.apache.log4j.Level;
import org.apache.log4j.SimpleLayout;
+import jalview.bin.Cache;
+import jalview.util.MessageManager;
+
/**
* Simple Jalview Java Console. Version 1 - allows viewing of console output
* after desktop is created. Acquired with thanks from RJHM's site
private int MIN_HEIGHT = 250;
+ private JComboBox logLevelCombo = new JComboBox();
+
public Console()
{
// create all components and add them
// textArea = cpt.getTextArea();
textArea = new JTextArea();
textArea.setEditable(false);
- JButton button = new JButton(MessageManager.getString("action.clear"));
+ JButton clearButton = new JButton(
+ MessageManager.getString("action.clear"));
+ JButton copyToClipboardButton = new JButton(
+ MessageManager.getString("label.copy_to_clipboard"));
+ copyToClipboardButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ copyConsoleTextToClipboard();
+ }
+ });
+ copyToClipboardButton.addMouseListener(new MouseAdapter()
+ {
+ private Color bg = textArea.getBackground();
+
+ public void mousePressed(MouseEvent e)
+ {
+ textArea.setBackground(textArea.getSelectionColor());
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ textArea.setBackground(bg);
+ }
+
+ });
+ copyToClipboardButton.setToolTipText(
+ MessageManager.getString("label.copy_to_clipboard_tooltip"));
+
+ JLabel logLevelLabel = new JLabel(
+ MessageManager.getString("label.log_level") + ":");
+
+ // logLevelCombo.addItem(Level.ALL);
+ logLevelCombo.addItem(Level.DEBUG);
+ logLevelCombo.addItem(Level.INFO);
+ logLevelCombo.addItem(Level.WARN);
+ // logLevelCombo.addItem(Level.ERROR);
+ // logLevelCombo.addItem(Level.FATAL);
+ // logLevelCombo.addItem(Level.OFF);
+ // logLevelCombo.addItem(Level.TRACE);
+ setChosenLogLevelCombo();
+ logLevelCombo.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ if (Cache.log != null)
+ {
+ Cache.log.setLevel((Level) logLevelCombo.getSelectedItem());
+ }
+ }
+
+ });
// frame = cpt;
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new JScrollPane(textArea),
BorderLayout.CENTER);
- frame.getContentPane().add(button, BorderLayout.SOUTH);
+ JPanel southPanel = new JPanel();
+ southPanel.setLayout(new GridBagLayout());
+
+ JPanel logLevelPanel = new JPanel();
+ logLevelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
+ logLevelPanel.add(logLevelLabel);
+ logLevelPanel.add(logLevelCombo);
+ logLevelLabel.setToolTipText(
+ MessageManager.getString("label.log_level_tooltip"));
+ logLevelCombo.setToolTipText(
+ MessageManager.getString("label.log_level_tooltip"));
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.gridwidth = 1;
+ gbc.gridheight = 1;
+ gbc.weightx = 0.1;
+ southPanel.add(logLevelPanel, gbc);
+
+ gbc.gridx++;
+ gbc.weightx = 0.8;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ southPanel.add(clearButton, gbc);
+
+ gbc.gridx++;
+ gbc.weightx = 0.1;
+ gbc.fill = GridBagConstraints.NONE;
+ southPanel.add(copyToClipboardButton, gbc);
+
+ southPanel.setVisible(true);
+ frame.getContentPane().add(southPanel, BorderLayout.SOUTH);
frame.setVisible(visible);
updateConsole = visible;
frame.addWindowListener(this);
- button.addActionListener(this);
+ clearButton.addActionListener(this);
+
if (redirect)
{
redirectStreams();
textAppender.start();
}
+ private void setChosenLogLevelCombo()
+ {
+ Level currentLogLevel = Cache.log == null ? Level.INFO
+ : Cache.log.getLevel();
+ logLevelCombo.setSelectedItem(currentLogLevel);
+ if (!logLevelCombo.getSelectedItem().equals(currentLogLevel))
+ {
+ logLevelCombo.setSelectedItem(Level.INFO);
+ }
+ }
+
+ private void copyConsoleTextToClipboard()
+ {
+ String consoleText = textArea.getText();
+ StringSelection consoleTextSelection = new StringSelection(consoleText);
+ Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
+ cb.setContents(consoleTextSelection, null);
+ }
+
+ private void setLogLevel()
+ {
+
+ }
+
PipedOutputStream pout = null, perr = null;
public void redirectStreams()
frame.setVisible(selected);
if (selected == true)
{
+ setChosenLogLevelCombo();
redirectStreams();
updateConsole = true;
frame.toFront();
}
else
{
+ // reset log level to user preference
+ if (Cache.log != null)
+ {
+ String userLogLevel = Cache.getDefault("logs.Jalview.level",
+ Level.INFO.toString());
+ Cache.log.setLevel(Level.toLevel(userLogLevel));
+ }
+
unredirectStreams();
updateConsole = false;
}
import jalview.gui.Desktop;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
+import jalview.util.Platform;
/*
* BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
MessageManager.getString("label.delete"),
MessageManager.getString("label.rename") };
- confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
- messageSB.toString(),
- MessageManager.getString("label.backupfiles_confirm_delete"),
- // "Confirm delete"
- JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
- null, options, options[0]);
+ confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+ : JvOptionPane.showOptionDialog(Desktop.desktop,
+ messageSB.toString(),
+ MessageManager.getString(
+ "label.backupfiles_confirm_delete"),
+ // "Confirm delete"
+ JvOptionPane.YES_NO_OPTION,
+ JvOptionPane.WARNING_MESSAGE, null, options,
+ options[0]);
}
else
{
MessageManager.getString("label.delete"),
MessageManager.getString("label.keep") };
- confirmButton = JvOptionPane.showOptionDialog(Desktop.desktop,
- messageSB.toString(),
- MessageManager.getString("label.backupfiles_confirm_delete"),
- // "Confirm delete"
- JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
- null, options, options[0]);
+ confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+ : JvOptionPane.showOptionDialog(Desktop.desktop,
+ messageSB.toString(),
+ MessageManager.getString(
+ "label.backupfiles_confirm_delete"),
+ // "Confirm delete"
+ JvOptionPane.YES_NO_OPTION,
+ JvOptionPane.WARNING_MESSAGE, null, options,
+ options[0]);
}
// return should be TRUE if file is to be deleted
// "(modified {0}, size {1})"
}
- int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
- messageSB.toString(),
- MessageManager
- .getString("label.backupfiles_confirm_delete"),
- // "Confirm delete"
- JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
+ int confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
+ : JvOptionPane.showConfirmDialog(Desktop.desktop,
+ messageSB.toString(),
+ MessageManager.getString(
+ "label.backupfiles_confirm_delete"),
+ // "Confirm delete"
+ JvOptionPane.YES_NO_OPTION,
+ JvOptionPane.WARNING_MESSAGE);
doDelete = (confirmButton == JvOptionPane.YES_OPTION);
}
// "The new saved file might not be okay."
}
- int confirmButton = JvOptionPane.showConfirmDialog(Desktop.desktop,
- messageSB.toString(),
- MessageManager
- .getString("label.backupfiles_confirm_save_file"),
- // "Confirm save file"
- JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
+ int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION
+ : JvOptionPane.showConfirmDialog(Desktop.desktop,
+ messageSB.toString(),
+ MessageManager.getString(
+ "label.backupfiles_confirm_save_file"),
+ // "Confirm save file"
+ JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
okay = confirmButton == JvOptionPane.OK_OPTION;
}
if (okay)