aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java
diff options
context:
space:
mode:
Diffstat (limited to 'netx/net/sourceforge/jnlp/util/logging/JavaConsole.java')
-rw-r--r--netx/net/sourceforge/jnlp/util/logging/JavaConsole.java200
1 files changed, 133 insertions, 67 deletions
diff --git a/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java
index 3b7d438..8671732 100644
--- a/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java
+++ b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java
@@ -38,10 +38,11 @@ package net.sourceforge.jnlp.util.logging;
import static net.sourceforge.jnlp.runtime.Translator.R;
+import java.awt.BorderLayout;
import java.awt.Dimension;
-import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
+import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
@@ -51,37 +52,104 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import java.util.Observable;
import java.util.Properties;
import java.util.Set;
import javax.swing.JButton;
+import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
+import javax.swing.JLabel;
import javax.swing.JPanel;
-import javax.swing.JScrollPane;
+import javax.swing.JSpinner;
import javax.swing.JSplitPane;
-import javax.swing.JTextArea;
+import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
-import javax.swing.border.EmptyBorder;
-import javax.swing.border.TitledBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.DefaultFormatter;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.ImageResources;
import net.sourceforge.jnlp.util.logging.headers.Header;
+import net.sourceforge.jnlp.util.logging.headers.JavaMessage;
+import net.sourceforge.jnlp.util.logging.headers.MessageWithHeader;
+import net.sourceforge.jnlp.util.logging.headers.ObservableMessagesProvider;
import net.sourceforge.jnlp.util.logging.headers.PluginMessage;
/**
* A simple Java console for IcedTeaPlugin and JavaWS
*
*/
-public class JavaConsole {
+public class JavaConsole implements ObservableMessagesProvider {
+
+ private List<MessageWithHeader> rawData = Collections.synchronizedList(new ArrayList<MessageWithHeader>());
+ private List<ConsoleOutputPane> outputs = new ArrayList<ConsoleOutputPane>();
+
+ private void refreshOutputs() {
+ refreshOutputs(outputsPanel, (Integer)numberOfOutputs.getValue());
+ }
+
+ private void refreshOutputs(JPanel pane, int count) {
+ pane.removeAll();
+ while(outputs.size()>count){
+ getObservable().deleteObserver(outputs.get(outputs.size()-1));
+ outputs.remove(outputs.size()-1);
+ }
+ while(outputs.size()<count){
+ ConsoleOutputPane c1 = new ConsoleOutputPane(this);
+ observable.addObserver(c1);
+ outputs.add(c1);
+ }
+ if (count == 0){
+ pane.add(new JPanel());
+ } else if (outputs.size() == 1){
+ pane.add(outputs.get(0));
+ } else {
+ JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,outputs.get(outputs.size()-2), outputs.get(outputs.size()-1));
+ splitPane.setDividerLocation(0.5);
+ splitPane.setResizeWeight(0.5);
+
+ for (int i = outputs.size()-3; i>=0; i--){
+ JSplitPane outerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, outputs.get(i), splitPane);
+ outerPane.setDividerLocation(0.5);
+ outerPane.setResizeWeight(0.5);
+ splitPane = outerPane;
+ }
+ pane.add(splitPane);
+
+ }
+ pane.validate();
+ }
+
+ private static class PublicObservable extends Observable {
+
+ @Override
+ public synchronized void setChanged() {
+ super.setChanged();
+ }
+ }
public static interface ClassLoaderInfoProvider {
public Map<String, String> getLoaderInfo();
}
+
private static JavaConsole console;
- private static Dimension lastSize;
+
+ private Dimension lastSize;
+ private JDialog consoleWindow;
+ private JPanel contentPanel;
+ private JPanel outputsPanel;
+ private ClassLoaderInfoProvider classLoaderInfoProvider;
+ private JSpinner numberOfOutputs;
+ private PublicObservable observable = new PublicObservable();
+ private boolean initialized = false;
private static class JavaConsoleHolder {
@@ -116,21 +184,7 @@ public class JavaConsole {
|| (DeploymentConfiguration.CONSOLE_SHOW_JAVAWS.equals(config.getProperty(DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE))
&& isApplication);
}
- private JDialog consoleWindow;
- private JTextArea stdErrText;
- private JTextArea stdOutText;
- private JPanel contentPanel;
- private ClassLoaderInfoProvider classLoaderInfoProvider;
- private boolean initialized = false;
-
- private String stdErrTextSrc = "";
- private String stdOutTextSrc = "";
-
- public JavaConsole() {
-
- }
-
-
+
private void initializeWindow() {
if (!initialized){
initialize();
@@ -149,7 +203,8 @@ public class JavaConsole {
});
consoleWindow.setIconImages(ImageResources.INSTANCE.getApplicationImages());
-
+ //view is added after console is made visible so no performance impact when hidden/
+ refreshOutputs();
consoleWindow.add(content);
consoleWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //HIDE_ON_CLOSE can cause shut down deadlock
consoleWindow.pack();
@@ -158,7 +213,7 @@ public class JavaConsole {
} else {
consoleWindow.setSize(new Dimension(900, 600));
}
- consoleWindow.setMinimumSize(new Dimension(900, 300));
+ consoleWindow.setMinimumSize(new Dimension(300, 300));
}
@@ -168,36 +223,18 @@ public class JavaConsole {
private void initialize() {
contentPanel = new JPanel();
+ outputsPanel = new JPanel();
+
+ outputsPanel.setLayout(new BorderLayout());
contentPanel.setLayout(new GridBagLayout());
GridBagConstraints c;
-
- Font monoSpace = new Font("Monospaced", Font.PLAIN, 12);
-
-
- stdOutText = new JTextArea();
- JScrollPane stdOutScrollPane = new JScrollPane(stdOutText);
- stdOutScrollPane.setBorder(new TitledBorder(
- new EmptyBorder(5, 5, 5, 5), "System.out"));
- stdOutText.setEditable(false);
- stdOutText.setFont(monoSpace);
-
- stdErrText = new JTextArea();
- JScrollPane stdErrScrollPane = new JScrollPane(stdErrText);
- stdErrScrollPane.setBorder(new TitledBorder(
- new EmptyBorder(5, 5, 5, 5), "System.err"));
- stdErrText.setEditable(false);
- stdErrText.setFont(monoSpace);
-
- JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
- stdOutScrollPane, stdErrScrollPane);
-
c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridheight = 10;
c.weighty = 1;
- contentPanel.add(splitPane, c);
+ contentPanel.add(outputsPanel, c);
/* buttons */
@@ -208,6 +245,7 @@ public class JavaConsole {
c.weighty = 0;
JPanel buttonPanel = new JPanel();
+ buttonPanel.setLayout(new GridLayout(2, 0, 0, 0));
contentPanel.add(buttonPanel, c);
JButton gcButton = new JButton(R("CONSOLErungc"));
@@ -221,6 +259,7 @@ public class JavaConsole {
System.gc();
OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("ButDone"));
printMemoryInfo();
+ updateModel();
}
});
@@ -235,6 +274,7 @@ public class JavaConsole {
Runtime.getRuntime().runFinalization();
OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, R("ButDone"));
printMemoryInfo();
+ updateModel();
}
});
@@ -245,6 +285,7 @@ public class JavaConsole {
@Override
public void actionPerformed(ActionEvent e) {
printMemoryInfo();
+ updateModel();
}
});
@@ -255,6 +296,7 @@ public class JavaConsole {
@Override
public void actionPerformed(ActionEvent e) {
printSystemProperties();
+ updateModel();
}
});
@@ -265,6 +307,7 @@ public class JavaConsole {
@Override
public void actionPerformed(ActionEvent e) {
printClassLoaders();
+ updateModel();
}
});
@@ -275,9 +318,26 @@ public class JavaConsole {
@Override
public void actionPerformed(ActionEvent e) {
printThreadInfo();
+ updateModel();
}
});
+ JLabel numberOfOutputsL = new JLabel(" Number of outputs: ");
+ buttonPanel.add(numberOfOutputsL);
+ numberOfOutputs = new JSpinner(new SpinnerNumberModel(1, 0, 10, 1));
+ JComponent comp = numberOfOutputs.getEditor();
+ JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
+ DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
+ formatter.setCommitsOnValidEdit(true);
+ numberOfOutputs.addChangeListener(new ChangeListener() {
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ refreshOutputs();
+ }
+ });
+ buttonPanel.add(numberOfOutputs);
+
JButton closeButton = new JButton(R("ButClose"));
buttonPanel.add(closeButton);
closeButton.addActionListener(new ActionListener() {
@@ -294,8 +354,6 @@ public class JavaConsole {
}
});
- splitPane.setDividerLocation(0.5);
- splitPane.setResizeWeight(0.5);
initialized = true;
}
@@ -304,12 +362,17 @@ public class JavaConsole {
}
public void showConsole(boolean modal) {
- initializeWindow();
- consoleWindow.setModal(modal);
- consoleWindow.setVisible(true);
+ if (consoleWindow == null || !consoleWindow.isVisible()){
+ initializeWindow();
+ consoleWindow.setModal(modal);
+ consoleWindow.setVisible(true);
+ }
}
public void hideConsole() {
+ //no need to update when hidden
+ outputsPanel.removeAll();//??
+ getObservable().deleteObservers();
consoleWindow.setModal(false);
consoleWindow.setVisible(false);
consoleWindow.dispose();
@@ -417,23 +480,17 @@ public class JavaConsole {
}
- synchronized void addMessage(Header header, String message) {
- String headerString = "";
- if (LogConfig.getLogConfig().isEnableHeaders()){
- headerString = header.toString();
- }
- if (header.level.isError()){
- stdErrTextSrc += headerString + message +"\n";
- }
- if (header.level.isOutput()){
- stdOutTextSrc += headerString + message + "\n";
- }
- if (initialized){
- stdErrText.setText(stdErrTextSrc);
- stdOutText.setText(stdOutTextSrc);
- }
+ synchronized void addMessage(MessageWithHeader m) {
+ rawData.add(m);
+ updateModel();
+ }
+
+ private synchronized void updateModel() {
+ observable.setChanged();
+ observable.notifyObservers();
}
+
/**
* parse plugin message and add it as header+message to data
* @param s string to be parsed
@@ -443,7 +500,16 @@ public class JavaConsole {
OutputController.getLogger().log(pm);
}
-
+ @Override
+ public List<MessageWithHeader> getData() {
+ return rawData;
+ }
+
+ @Override
+ public Observable getObservable() {
+ return observable;
+ }
+
public void createPluginReader(final File file) {
OutputController.getLogger().log("Starting processing of plugin-debug-to-console " + file.getAbsolutePath());
Thread t = new Thread(new Runnable() {