package ch.rakudave.jnetmap.plugins;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import ch.rakudave.jnetmap.model.device.Device;
import ch.rakudave.jnetmap.util.Icons;
import ch.rakudave.jnetmap.util.Settings;
import ch.rakudave.jnetmap.util.logging.Appender;
import ch.rakudave.jnetmap.util.logging.ListenerAppender;
import ch.rakudave.jnetmap.util.logging.Logger;
import ch.rakudave.jnetmap.util.logging.Logger.Level;
import ch.rakudave.jnetmap.view.preferences.PreferencePanel;
/**
* @author rakudave
*/
@PluginImplementation
public class LogPanel implements ChangeListener, SidebarPlugin {
private JTextArea area;
private Appender appender;
@Override
public JPanel getPanel() {
JPanel p = new JPanel(new BorderLayout());
area = new JTextArea();
area.setEditable(false);
appender = new ListenerAppender(Level.valueOf(Settings.get("plugin.logpanel.loglevel", "INFO")), this);
Logger.addAppender(appender);
final JComboBox levelSelector = new JComboBox(Level.values());
levelSelector.setSelectedItem(appender.getLevel());
levelSelector.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Level logLevel = (Level) levelSelector.getSelectedItem();
appender.setLevel(logLevel);
Settings.put("plugin.logpanel.loglevel", logLevel.toString());
}
});
p.add(levelSelector, BorderLayout.NORTH);
p.add(new JScrollPane(area), BorderLayout.CENTER);
return p;
}
/* (non-Javadoc)
* @see ch.rakudave.jnetmap.plugins.ILogPanel#stateChanged(javax.swing.event.ChangeEvent)
*/
@Override
public void stateChanged(ChangeEvent e) {
area.append(e.getSource().toString());
}
@Override
public String getAuthor() {
return "rakudave";
}
@Override
public String getDescription() {
return "Provides convenient access to the system log";
}
@Override
public String getPluginName() {
return "Log Panel";
}
@Override
public Icon getIcon() {
return Icons.get("properties");
}
@Override
public PreferencePanel getSettingsPanel() {
return null;
}
@Override
public boolean hasSettings() {
return false;
}
@Override
public String getTabTitle() {
return "Log";
}
@Override
public String getToolTip() {
return getDescription();
}
@Override
public void graphClicked(Device v, MouseEvent me) {}
@Override
public void graphPressed(Device v, MouseEvent me) {}
@Override
public void graphReleased(Device v, MouseEvent me) {}
}