psmith 2003/12/23 13:46:06
Modified: src/java/org/apache/log4j/chainsaw/receivers
NewReceiverDialogPanel.java
Log:
Jalopied, and added a JavaDoc viewer inside a JSplitPane for the Plugin
that is being edited.
Revision Changes Path
1.2 +170 -74
jakarta-log4j/src/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java
Index: NewReceiverDialogPanel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NewReceiverDialogPanel.java 22 Dec 2003 11:01:45 -0000 1.1
+++ NewReceiverDialogPanel.java 23 Dec 2003 21:46:06 -0000 1.2
@@ -49,94 +49,190 @@
package org.apache.log4j.chainsaw.receivers;
+import org.apache.log4j.chainsaw.help.HelpManager;
+import org.apache.log4j.chainsaw.helper.OkCancelPanel;
+import org.apache.log4j.chainsaw.messages.MessageCenter;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.net.SocketHubReceiver;
+import org.apache.log4j.plugins.Plugin;
+import org.apache.log4j.plugins.Receiver;
+
import java.awt.BorderLayout;
+import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import java.io.IOException;
+
+import java.net.URL;
+
import javax.swing.JDialog;
+import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
import javax.swing.UIManager;
-import org.apache.log4j.chainsaw.helper.OkCancelPanel;
-import org.apache.log4j.net.SocketHubReceiver;
-import org.apache.log4j.plugins.Plugin;
-import org.apache.log4j.plugins.Receiver;
-
+/**
+ * A panel that allows a user to configure a new Plugin, and
+ * view that plugins javadoc at the same time
+ *
+ * @author Paul Smith <[EMAIL PROTECTED]>
+ *
+ */
public class NewReceiverDialogPanel extends JPanel {
- private PluginPropertyEditorPanel pluginEditorPanel =
- new PluginPropertyEditorPanel();
- private OkCancelPanel okPanel = new OkCancelPanel();
-
- private NewReceiverDialogPanel() {
- setupComponents();
- setupListeners();
- }
-
- /**
- *
- */
- private void setupListeners() {
- }
-
- /**
- *
- */
- private void setupComponents() {
- setLayout(new BorderLayout());
-
- add(pluginEditorPanel, BorderLayout.CENTER);
- add(okPanel, BorderLayout.SOUTH);
- }
-
- public static NewReceiverDialogPanel create(Class receiverClass)
- throws Exception {
- Receiver receiverInstance = (Receiver) receiverClass.newInstance();
-
- NewReceiverDialogPanel panel = new NewReceiverDialogPanel();
-
- panel.pluginEditorPanel.setPlugin(receiverInstance);
-
- return panel;
- }
-
- public static void main(String[] args) throws Exception {
-
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-
- NewReceiverDialogPanel panel =
- NewReceiverDialogPanel.create(SocketHubReceiver.class);
-
- JDialog dialog = new JDialog((JFrame) null, true);
- dialog.getContentPane().add(panel);
-
- ActionListener al =
- new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(1);
+
+ private PluginPropertyEditorPanel pluginEditorPanel =
+ new PluginPropertyEditorPanel();
+ private final OkCancelPanel okPanel = new OkCancelPanel();
+ private final JEditorPane javaDocPane = new JEditorPane();
+ private final JScrollPane javaDocScroller = new JScrollPane(javaDocPane);
+ private final JSplitPane splitter = new JSplitPane();
+
+ private NewReceiverDialogPanel() {
+ setupComponents();
+ setupListeners();
+ }
+
+ /**
+ *
+ */
+ private void setupListeners() {
+
+ /**
+ * We listen for the plugin change, and modify the editor panes
+ * url to be the Help resource for that class
+ */
+ pluginEditorPanel.addPropertyChangeListener("plugin",
+ new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ Plugin plugin = (Plugin) evt.getNewValue();
+ URL url = HelpManager.getInstance().getHelpForClass(
+ plugin.getClass());
+
+ try {
+ javaDocPane.setPage(url);
+ } catch (IOException e) {
+ MessageCenter.getInstance().getLogger().error(
+ "Failed to load the Help resource for " +
+ plugin.getClass(), e);
+ }
+ }
+ });
+ }
+
+ /**
+ *
+ */
+ private void setupComponents() {
+ setLayout(new BorderLayout());
+
+ setupJavadoc();
+
+ setupPluginPropertyPanel();
+
+ setupSplitter();
+
+ add(splitter, BorderLayout.CENTER);
+ add(okPanel, BorderLayout.SOUTH);
+ setMinimumSize(new Dimension(600, 600));
+ setPreferredSize(getMinimumSize());
+ }
+
+ private void setupPluginPropertyPanel() {
+ pluginEditorPanel.setMinimumSize(new Dimension(320, 160));
+ pluginEditorPanel.setPreferredSize(pluginEditorPanel.getMinimumSize());
+ }
+
+ private void setupSplitter() {
+ splitter.setTopComponent(javaDocScroller);
+ splitter.setBottomComponent(pluginEditorPanel);
+ splitter.setResizeWeight(0.8);
+ splitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
+ }
+
+ private void setupJavadoc() {
+ javaDocPane.setEditable(false);
+ }
+
+ /**
+ * Creates a new panel, with the contents configured to allow the editing
+ * of a NEW instance of the specified class (which must implement the Receiver
+ * interface)
+ * @param receiverClass
+ * @return
+ * @throws IllegalArgumentException if the specified class is not a Receiver
+ */
+ public static NewReceiverDialogPanel create(Class receiverClass) {
+
+ if (!Receiver.class.isAssignableFrom(receiverClass)) {
+ throw new IllegalArgumentException(receiverClass.getName() +
+ " is not a Receiver");
+ }
+
+ Receiver receiverInstance = null;
+
+ try {
+ receiverInstance = (Receiver) receiverClass.newInstance();
+
+ } catch (Exception e) {
+ LogLog.error(
+ "Failed to create a new Receiver instance, this exception is
unexpected",
+ e);
}
- };
- panel.okPanel.getOkButton().addActionListener(al);
- panel.okPanel.getCancelButton().addActionListener(al);
+ NewReceiverDialogPanel panel = new NewReceiverDialogPanel();
+
+ panel.pluginEditorPanel.setPlugin(receiverInstance);
+
+ return panel;
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+
+ NewReceiverDialogPanel panel = NewReceiverDialogPanel.create(
+ SocketHubReceiver.class);
+
+ JDialog dialog = new JDialog((JFrame) null, true);
+ dialog.getContentPane().add(panel);
+
+ ActionListener al = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.exit(1);
+ }
+ };
+
+ panel.okPanel.getOkButton().addActionListener(al);
+ panel.okPanel.getCancelButton().addActionListener(al);
+
+ dialog.pack();
+
+ dialog.show();
+ }
+
+ /**
+ * @return Returns the okPanel.
+ */
+ public final OkCancelPanel getOkPanel() {
+
+ return okPanel;
+ }
- dialog.pack();
+ /**
+ *
+ */
+ public Plugin getPlugin() {
- dialog.show();
- }
- /**
- * @return Returns the okPanel.
- */
- public final OkCancelPanel getOkPanel() {
- return okPanel;
- }
-
- /**
- *
- */
- public Plugin getPlugin() {
- return this.pluginEditorPanel.getPlugin();
- }
+ return this.pluginEditorPanel.getPlugin();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]