defenderH2O
Grünschnabel
Ich habe schon in gui 6 toolbars buttons hinzugefügt
aber habs nicht hinbekommen das diese 6 toolbar buttons
die gewünschte dialog anzeigen!nicht via tabs. nur via toolbar!
ich habe in meinem 2 source rausgefunden wie ich per toolbar buttons click
die beispiel dialoge anzeigen lassen kann.
ich habe gedacht es müsste viell einfacher gehen wenn ich die idee in den vorhanden source noch integriere.
Wäre es möglich ohne großen aufwand das ich doch noch hinbekomme?!
also die toolbar buttons gingen ohne probleme
hier mein vorhandener code:
aber habs nicht hinbekommen das diese 6 toolbar buttons
die gewünschte dialog anzeigen!nicht via tabs. nur via toolbar!
ich habe in meinem 2 source rausgefunden wie ich per toolbar buttons click
die beispiel dialoge anzeigen lassen kann.
ich habe gedacht es müsste viell einfacher gehen wenn ich die idee in den vorhanden source noch integriere.
Wäre es möglich ohne großen aufwand das ich doch noch hinbekomme?!
also die toolbar buttons gingen ohne probleme
hier mein vorhandener code:
Code:
/*
package de.todesbaum.freemule.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.ByteArrayOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import de.todesbaum.freemule.application.AnnouncementListener;
import de.todesbaum.freemule.application.AnnouncementService;
import de.todesbaum.freemule.application.Client;
import de.todesbaum.freemule.application.ClientListener;
import de.todesbaum.freemule.application.ClientService;
import de.todesbaum.freemule.application.ClipboardListener;
import de.todesbaum.freemule.application.ClipboardService;
import de.todesbaum.freemule.application.DiscoveryListener;
import de.todesbaum.freemule.application.DiscoveryService;
import de.todesbaum.freemule.application.DownloadListener;
import de.todesbaum.freemule.application.DownloadService;
import de.todesbaum.freemule.application.FilelistCollectorListener;
import de.todesbaum.freemule.application.FilelistCollectorService;
import de.todesbaum.freemule.application.FilelistInsertListener;
import de.todesbaum.freemule.application.FilelistInsertService;
import de.todesbaum.freemule.application.FilelistListener;
import de.todesbaum.freemule.application.FilelistService;
import de.todesbaum.freemule.application.FreeMule;
import de.todesbaum.freemule.application.FreenetFile;
import de.todesbaum.freemule.application.Service;
import de.todesbaum.freemule.application.ServiceListener;
import de.todesbaum.freemule.application.ServiceThread;
import de.todesbaum.freemule.application.SharedFile;
import de.todesbaum.freemule.application.SharedFileListener;
import de.todesbaum.freemule.application.SharedFileService;
import de.todesbaum.freemule.application.UploadFile;
import de.todesbaum.freemule.application.UploadListener;
import de.todesbaum.freemule.application.UploadRequest;
import de.todesbaum.freemule.application.UploadRequestDiscoveryListener;
import de.todesbaum.freemule.application.UploadRequestDiscoveryService;
import de.todesbaum.freemule.application.UploadRequestInsertListener;
import de.todesbaum.freemule.application.UploadRequestInsertService;
import de.todesbaum.freemule.application.UploadRequestListener;
import de.todesbaum.freemule.application.UploadRequestService;
import de.todesbaum.freemule.application.UploadService;
import de.todesbaum.freemule.main.Configuration;
import de.todesbaum.freemule.main.LoggingPreferences;
import de.todesbaum.freemule.main.Version;
/**
*/
public class MainFrame extends JFrame implements ServiceListener, SharedFileListener, FilelistInsertListener, FilelistCollectorListener, DownloadListener, UploadRequestInsertListener, UploadRequestDiscoveryListener, DiscoveryListener, AnnouncementListener, ClientListener, ClipboardListener, FilelistListener, UploadListener, UploadRequestListener {
private Configuration configuration;
private FreeMule freeMule;
private JTabbedPane topTabbed;
private Action connectAction;
private Action disconnectAction;
private Action nodeAction;
private Action quitAction;
private Action preferencesAction;
private Action sharedDirectoriesAction;
private Action aboutAction;
private Action clearMessagesAction;
private Action downloadFilesAction;
private Action uploadFilesAction;
private Action KnownClientsAction;
private Action SearchAction;
private Action SharedFilesAction;
private Action loggingAction;
private LoggingPreferences loggingPreferences = new LoggingPreferences();
protected JList messageList;
protected DefaultListModel messageListModel = new DefaultListModel();
private StatusPanel statusPanel;
private DownloadFilesPanel downloadFilesPanel;
private UploadFilesPanel uploadFilesPanel;
private KnownClientsPanel knownClientsPanel;
private SharedFilesPanel sharedFilesPanel;
private LoggingPreferencesPanel loggingPreferencesPanel;
private SearchPanel searchPanel;
@SuppressWarnings("unused")
private ServicesPanel servicesPanel;
public MainFrame(FreeMule freeMule) {
super("freeMule " + Version.getVersion());
// try {
// // UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// // UIManager.setLookAndFeel("javax.swing.plaf.multi.MultiLookAndFeel");
// // UIManager.setLookAndFeel("javax.swing.plaf.synth.SynthLookAndFeel");
// SynthLookAndFeel synthLookAndFeel = new SynthLookAndFeel();
// synthLookAndFeel.load(getClass().getResourceAsStream("/synth-default.xml"), getClass());
// UIManager.setLookAndFeel(synthLookAndFeel);
// // } catch (ClassNotFoundException e) {
// // } catch (InstantiationException e) {
// // } catch (IllegalAccessException e) {
// } catch (UnsupportedLookAndFeelException e) {
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// } catch (ParseException e) {
// e.printStackTrace();
// }
createComponents();
setFreeMule(freeMule);
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
actionQuit();
}
});
createActions();
createToolbar();
createContent();
setJMenuBar(createMenuBar());
pack();
setSize(750, 550);
}
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("Freenet");
menuBar.add(fileMenu);
fileMenu.add(connectAction);
fileMenu.add(disconnectAction);
fileMenu.addSeparator();
fileMenu.add(nodeAction);
fileMenu.add(preferencesAction);
fileMenu.add(sharedDirectoriesAction);
fileMenu.addSeparator();
fileMenu.add(quitAction);
JMenu helpMenu = new JMenu("Help");
menuBar.add(helpMenu);
helpMenu.add(aboutAction);
return menuBar;
}
private void createActions() {
connectAction = new AbstractAction("Connect") {
public void actionPerformed(ActionEvent actionEvent) {
actionConnect();
}
};
connectAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/connect_established.png"));
connectAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK));
connectAction.putValue(Action.SHORT_DESCRIPTION, "Start all services and connect to Freenet");
disconnectAction = new AbstractAction("Disconnect") {
public void actionPerformed(ActionEvent actionEvent) {
actionDisconnect();
}
};
disconnectAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/connect_no.png"));
disconnectAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK));
disconnectAction.putValue(Action.SHORT_DESCRIPTION, "Stop all services and disconnect from Freenet");
disconnectAction.setEnabled(false);
preferencesAction = new AbstractAction("Preferences") {
public void actionPerformed(ActionEvent actionEvent) {
actionPreferences();
}
};
preferencesAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/kservices.png"));
preferencesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK));
preferencesAction.putValue(Action.SHORT_DESCRIPTION, "Change settings");
sharedDirectoriesAction = new AbstractAction("Shared Directories") {
public void actionPerformed(ActionEvent actionEvent) {
actionSharedDirectories();
}
};
sharedDirectoriesAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/preferences3.png"));
sharedDirectoriesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
sharedDirectoriesAction.putValue(Action.SHORT_DESCRIPTION, "Configure shared directories");
nodeAction = new AbstractAction("Node") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
nodeAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/node3.png"));
nodeAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
nodeAction.putValue(Action.SHORT_DESCRIPTION, "Configure Freenet node settings");
quitAction = new AbstractAction("Quit") {
public void actionPerformed(ActionEvent actionEvent) {
actionQuit();
}
};
quitAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/exit.png"));
quitAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
quitAction.putValue(Action.SHORT_DESCRIPTION, "Quit freeMule");
aboutAction = new AbstractAction("About") {
public void actionPerformed(ActionEvent actionEvent) {
actionAbout();
}
};
aboutAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/about.png"));
aboutAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
aboutAction.putValue(Action.SHORT_DESCRIPTION, "Shows freeMule version information");
clearMessagesAction = new AbstractAction("Clear Messages") {
public void actionPerformed(ActionEvent actionEvent) {
actionClearMessages();
}
};
clearMessagesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK));
clearMessagesAction.putValue(Action.SHORT_DESCRIPTION, "Clear the message window");
downloadFilesAction = new AbstractAction("Downloads") {
public void actionPerformed(ActionEvent actionEvent) {
actionDownloadFiles(actionEvent);
// actionNode();
}
};
downloadFilesAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/downloads.png"));
//downloadFilesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
downloadFilesAction.putValue(Action.SHORT_DESCRIPTION, "Downloads");
uploadFilesAction = new AbstractAction("Uploads") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
uploadFilesAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/uploads.png"));
uploadFilesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK));
uploadFilesAction.putValue(Action.SHORT_DESCRIPTION, "Uploads");
KnownClientsAction = new AbstractAction("Known Clients") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
KnownClientsAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/clients.png"));
KnownClientsAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK));
KnownClientsAction.putValue(Action.SHORT_DESCRIPTION, "Known Clients");
SearchAction = new AbstractAction("Search") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
SearchAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/kview.png"));
SearchAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
SearchAction.putValue(Action.SHORT_DESCRIPTION, "Search");
SharedFilesAction = new AbstractAction("Shared Files") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
SharedFilesAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/sharedfiles32.png"));
SharedFilesAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
SharedFilesAction.putValue(Action.SHORT_DESCRIPTION, "Shared Files");
loggingAction = new AbstractAction("Logging") {
public void actionPerformed(ActionEvent actionEvent) {
actionNode();
}
};
loggingAction.putValue(Action.SMALL_ICON, IconLoader.loadIcon("/img/toggle_log32.png"));
loggingAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
loggingAction.putValue(Action.SHORT_DESCRIPTION, "Logging");
}
private void createToolbar() {
JToolBar toolbar = new JToolBar();
toolbar.add(connectAction);
toolbar.add(disconnectAction);
toolbar.addSeparator();
toolbar.add(KnownClientsAction);
toolbar.add(downloadFilesPanel);
toolbar.add(uploadFilesAction);
toolbar.add(SearchAction);
toolbar.add(SharedFilesAction);
toolbar.add(loggingAction);
toolbar.add(preferencesAction);
toolbar.add(sharedDirectoriesAction);
toolbar.add(nodeAction);
toolbar.addSeparator();
toolbar.add(quitAction);
getContentPane().add(toolbar, BorderLayout.NORTH);
}
private void createComponents() {
statusPanel = new StatusPanel(this);
downloadFilesPanel = new DownloadFilesPanel(this);
uploadFilesPanel = new UploadFilesPanel(this);
searchPanel = new SearchPanel(this);
knownClientsPanel = new KnownClientsPanel(this);
sharedFilesPanel = new SharedFilesPanel(this);
loggingPreferencesPanel = new LoggingPreferencesPanel(this);
// servicesPanel = new ServicesPanel(this);
messageList = new JList(messageListModel);
}
private void createContent() {
JPanel contentPanel = new JPanel(new BorderLayout(12, 12));
contentPanel.setBorder(new EmptyBorder(12, 12, 12, 12));
// split pane
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
splitPane.setDividerLocation(0.5);
contentPanel.add(splitPane, BorderLayout.CENTER);
// top frame: tabbed pane
//JTabbedPane topTabbed = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
topTabbed = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); //richti
splitPane.setTopComponent(topTabbed);
ImageIcon down = createImageIcon("/img/down2.png");
ImageIcon up = createImageIcon("/img/up.png");
ImageIcon search = createImageIcon("/img/xmag.png");
ImageIcon clients = createImageIcon("/img/www.png");
ImageIcon sharedfiles = createImageIcon("/img/folder_html.png");
ImageIcon logg = createImageIcon("/img/toggle_log.png");
// topTabbed.add("Status", statusPanel);
topTabbed.addTab("Downloads", down, downloadFilesPanel);
topTabbed.addTab("Uploads", up, uploadFilesPanel);
topTabbed.addTab("Search", search, searchPanel);
topTabbed.addTab("Known Clients", clients, knownClientsPanel);
topTabbed.addTab("Shared Files", sharedfiles, sharedFilesPanel);
topTabbed.addTab("Logging", logg, loggingPreferencesPanel);
// topTabbed.add("Service Threads", servicesPanel);
// bottom frame: messages
splitPane.setBottomComponent(new JScrollPane(messageList));
splitPane.setResizeWeight(0.9);
// input line
JPanel keyInputPanel = new JPanel(new BorderLayout(5, 5));
contentPanel.add(keyInputPanel, BorderLayout.PAGE_END);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
buttonPanel.setBorder(new EmptyBorder(-12, -12, -12, -12));
buttonPanel.add(new JButton(clearMessagesAction));
keyInputPanel.add(buttonPanel, BorderLayout.LINE_END);
getContentPane().add(contentPanel, BorderLayout.CENTER);
}
/**
* @param configuration
* The configuration to set.
*/
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
loggingPreferences = configuration.getLoggingPreferences();
loggingPreferencesPanel.setLoggingPreferences(loggingPreferences);
}
/**
* @param freeMule
* The freeMule to set.
*/
public void setFreeMule(FreeMule freeMule) {
this.freeMule = freeMule;
freeMule.addServiceListener(this);
freeMule.getAnnouncementService().addServiceListener(this);
freeMule.getClientService().addServiceListener(this);
freeMule.getClipboardService().addServiceListener(this);
freeMule.getDiscoveryService().addServiceListener(this);
freeMule.getDownloadService().addServiceListener(this);
freeMule.getEngineService().addServiceListener(this);
freeMule.getFilelistCollectorService().addServiceListener(this);
freeMule.getFilelistInsertService().addServiceListener(this);
freeMule.getFilelistService().addServiceListener(this);
freeMule.getSharedFileService().addServiceListener(this);
freeMule.getUploadRequestDiscoveryService().addServiceListener(this);
freeMule.getUploadRequestInsertService().addServiceListener(this);
freeMule.getUploadService().addServiceListener(this);
freeMule.getAnnouncementService().addAnnouncementListener(this);
freeMule.getClientService().addClientListener(this);
freeMule.getClipboardService().addClipboardListener(this);
freeMule.getDiscoveryService().addDiscoveryListener(this);
freeMule.getDownloadService().addDownloadListener(this);
freeMule.getFilelistCollectorService().addFilelistCollectorListener(this);
freeMule.getFilelistInsertService().addFilelistInsertListener(this);
freeMule.getFilelistService().addFilelistListener(this);
freeMule.getSharedFileService().addSharedFileListener(this);
freeMule.getUploadRequestDiscoveryService().addUploadRequestDiscoveryListener(this);
freeMule.getUploadRequestInsertService().addUploadRequestInsertListener(this);
freeMule.getUploadService().addUploadListener(this);
downloadFilesPanel.setDownloadService(freeMule.getDownloadService());
uploadFilesPanel.setUploadService(freeMule.getUploadService());
searchPanel.setDownloadService(freeMule.getDownloadService());
searchPanel.setFilelistService(freeMule.getFilelistService());
knownClientsPanel.setClientService(freeMule.getClientService());
knownClientsPanel.setFilelistService(freeMule.getFilelistService());
sharedFilesPanel.setSharedFileService(freeMule.getSharedFileService());
// servicesPanel.setServices(freeMule.getServices());
}
public void actionConnect() {
connectAction.setEnabled(false);
//KnownClientsAction.setEnabled(false);
//downloadFilesAction.setEnabled(false);
//uploadFilesAction.setEnabled(false);
//SearchAction.setEnabled(false);
//SharedFilesAction.setEnabled(false);
preferencesAction.setEnabled(false);
sharedDirectoriesAction.setEnabled(false);
nodeAction.setEnabled(false);
freeMule.start();
statusPanel.setFreeMuleStatus("Starting", "#808080");
}
public void actionDisconnect() {
final FreeMule freeMuleCopy = freeMule;
new Thread(new Runnable() {
public void run() {
freeMuleCopy.stop();
}
}).start();
disconnectAction.setEnabled(false);
statusPanel.setFreeMuleStatus("Stopping", "#800000");
}
public void actionPreferences() {
PreferencesDialog dialog = new PreferencesDialog(this);
dialog.setUsername(configuration.getUsername());
dialog.setClientID(configuration.getPublicKey());
dialog.setIncomingDirectory(configuration.getIncomingDirectory());
dialog.setTempDirectory(configuration.getTempDirectory());
dialog.setNetworkName(configuration.getNetworkName());
dialog.setHopsToLive(configuration.getHopsToLive());
dialog.setVisible(true);
configuration.setUsername(dialog.getUsername());
configuration.setIncomingDirectory(dialog.getIncomingDirectory());
configuration.setTempDirectory(dialog.getTempDirectory());
configuration.setNetworkName(dialog.getNetworkName());
configuration.setHopsToLive(dialog.getHopsToLive());
freeMule.setUsername(dialog.getUsername());
freeMule.setIncomingDirectory(dialog.getIncomingDirectory());
freeMule.setTempDirectory(dialog.getTempDirectory());
freeMule.setNetworkName(dialog.getNetworkName());
freeMule.setHopsToLive(dialog.getHopsToLive());
}
protected void actionSharedDirectories() {
SharedDirectoriesDialog dialog = new SharedDirectoriesDialog(this);
dialog.setSharedDirectories(configuration.getSharedDirectories());
dialog.setVisible(true);
configuration.setSharedDirectories(dialog.getSharedDirectories());
freeMule.setSharedDirectories(dialog.getSharedDirectories());
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = MainFrame.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public void actionNode() {
NodeDialog nodeDialog = new NodeDialog(this);
nodeDialog.setNodeAddress(configuration.getNodeAddress());
nodeDialog.setNodePort(configuration.getNodePort());
nodeDialog.setVisible(true);
configuration.setNodeAddress(nodeDialog.getNodeAddress());
configuration.setNodePort(nodeDialog.getNodePort());
freeMule.setNodeAddress(nodeDialog.getNodeAddress());
freeMule.setNodePort(nodeDialog.getNodePort());
}
private void actionDownloadFiles(ActionEvent actionEvent){
if(actionEvent.getActionCommand().equals("Downloads")){
topTabbed.setSelectedComponent(downloadFilesPanel);
}
}
public void actionQuit() {
if (!connectAction.isEnabled()) {
if (JOptionPane.showConfirmDialog(this, "The freeMule service has not yet stopped.\nDo you really want to exit?", "Exit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
return;
}
}
configuration.save();
System.exit(0);
}
public void actionAbout() {
JOptionPane.showMessageDialog(this, "<html><big>freeMule " + Version.getVersion() + "</big><br>by <a href=\"mailto:droden@gmail.com\">droden@gmail.com</a></html>", "About freeMule", JOptionPane.INFORMATION_MESSAGE);
}
protected void actionClearMessages() {
synchronized (messageListModel) {
messageListModel.clear();
}
}
protected String getCurrentTimestamp() {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int millis = calendar.get(Calendar.MILLISECOND);
StringBuffer result = new StringBuffer(12);
if (hour < 10) {
result.append('0');
}
result.append(hour).append(':');
if (minute < 10) {
result.append('0');
}
result.append(minute).append(':');
if (second < 10) {
result.append('0');
}
result.append(second).append('.');
if (millis < 100) {
result.append('0');
if (millis < 10) {
result.append('0');
}
}
result.append(millis);
return result.toString();
}
private void addMessageToGUI(final String message) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized (messageListModel) {
messageListModel.addElement("[" + getCurrentTimestamp() + "] " + message);
messageList.ensureIndexIsVisible(messageListModel.getSize() - 1);
}
}
});
}
private void addMessageToFile(String message) {
String filename = loggingPreferences.getLogfile();
if (filename.equals("stdout")) {
System.out.println(message);
} else if (filename.equals("stderr")) {
System.err.println(message);
} else {
Writer writer = null;
try {
writer = new FileWriter(filename, true);
writer.write(message + "\n");
} catch (IOException e) {
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException ioe1) {
}
}
}
}
@SuppressWarnings("unused")
private String[] parseThrowable(Throwable throwable) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
PrintStream bytePrinter = new PrintStream(byteOutput);
throwable.printStackTrace(bytePrinter);
bytePrinter.close();
try {
byteOutput.close();
} catch (IOException e) {
}
byte[] throwableBytes = byteOutput.toByteArray();
String throwableText = new String(throwableBytes);
StringTokenizer throwableTokens = new StringTokenizer(throwableText, "\n");
List<String> throwableLines = new ArrayList<String>();
while (throwableTokens.hasMoreTokens()) {
String throwableLine = throwableTokens.nextToken();
throwableLines.add(throwableLine);
}
return throwableLines.toArray(new String[throwableLines.size()]);
}
private void logMessage(String serviceName, String eventName) {
logMessage(serviceName, eventName, null);
}
private void logMessage(String serviceName, String eventName, String message) {
logMessage(serviceName, eventName, message, null);
}
private void logMessage(String serviceName, String eventName, String message, Throwable throwable) {
String eventMessage = serviceName + ": " + eventName;
if (message != null) {
eventMessage += ": " + message;
}
if (throwable != null) {
eventMessage += ": " + throwable.getClass().getName() + ": " + throwable.getMessage();
}
eventMessage += ".";
if (loggingPreferences.getGUILogging(serviceName, eventName)) {
addMessageToGUI(eventMessage);
if (throwable != null) {
throwable.printStackTrace(System.err);
}
}
if (loggingPreferences.getFileLogging(serviceName, eventName)) {
addMessageToFile(eventMessage);
}
}
//
// INTERFACE ServiceListener
//
/**
* {@inheritDoc}
*/
public void serviceStarted(Service service) {
logMessage(service.getName(), "Service Started");
if (service == freeMule) {
statusPanel.setFreeMuleStatus("Running", "#00C000");
disconnectAction.setEnabled(true);
} else if (service == freeMule.getAnnouncementService()) {
statusPanel.setAnnouncementStatus("Idle", "#00C000");
} else if (service == freeMule.getFilelistInsertService()) {
statusPanel.setFilelistInsertStatus("Idle", "#00C000");
} else if (service == freeMule.getUploadRequestInsertService()) {
statusPanel.setUploadRequestInsertStatus("Idle", "#00C000");
}
}
/**
* {@inheritDoc}
*/
public void serviceAborted(Service service, Throwable throwable) {
logMessage(service.getName(), "Service Aborted", "ABNORMAL TERMINATION", throwable);
if (service.equals(freeMule)) {
statusPanel.setFreeMuleStatus("ABORTED", "#FF0000");
disconnectAction.setEnabled(false);
connectAction.setEnabled(true);
//KnownClientsAction.setEnabled(false);
//downloadFilesAction.setEnabled(false);
//uploadFilesAction.setEnabled(false);
//SearchAction.setEnabled(false);
//SharedFilesAction.setEnabled(false);
nodeAction.setEnabled(true);
preferencesAction.setEnabled(true);
sharedDirectoriesAction.setEnabled(true);
} else if (service == freeMule.getAnnouncementService()) {
statusPanel.setAnnouncementStatus("ABORTED", "#FF0000");
} else if (service == freeMule.getFilelistInsertService()) {
statusPanel.setFilelistInsertStatus("ABORTED", "#FF0000");
} else if (service == freeMule.getUploadRequestInsertService()) {
statusPanel.setUploadRequestInsertStatus("ABORTED", "#FF0000");
}
}
/**
* {@inheritDoc}
*/
public void serviceStopped(Service service) {
logMessage(service.getName(), "Service Stopped");
if (service == freeMule) {
statusPanel.setFreeMuleStatus("Stopped", "#000000");
disconnectAction.setEnabled(false);
connectAction.setEnabled(true);
//KnownClientsAction.setEnabled(true);
//downloadFilesAction.setEnabled(true);
//uploadFilesAction.setEnabled(true);
nodeAction.setEnabled(true);
preferencesAction.setEnabled(true);
sharedDirectoriesAction.setEnabled(true);
} else if (service == freeMule.getAnnouncementService()) {
statusPanel.setAnnouncementStatus("Stopped", "#000000");
} else if (service == freeMule.getFilelistInsertService()) {
statusPanel.setFilelistInsertStatus("Stopped", "#000000");
} else if (service == freeMule.getUploadRequestInsertService()) {
statusPanel.setUploadRequestInsertStatus("Stopped", "#000000");
}
}