in src/main/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java [88:360]
public ReceiversPanel(LogUI parentUi, ChainsawStatusBar sb) {
super(new BorderLayout());
m_statusBar = sb;
m_parent = parentUi;
final ReceiversTreeModel model = new ReceiversTreeModel();
m_parent.addReceiverEventListener(model);
receiversTree.setModel(model);
receiversTree.setExpandsSelectedPaths(true);
model.addTreeModelListener(
new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
expandRoot();
}
public void treeNodesInserted(TreeModelEvent e) {
expandRoot();
}
public void treeNodesRemoved(TreeModelEvent e) {
expandRoot();
}
public void treeStructureChanged(TreeModelEvent e) {
expandRoot();
}
private void expandRoot() {
receiversTree.expandPath(
new TreePath(model.getPathToRoot(model.RootNode)));
}
});
receiversTree.expandPath(
new TreePath(model.getPathToRoot(model.RootNode)));
receiversTree.addTreeWillExpandListener(
new TreeWillExpandListener() {
public void treeWillCollapse(TreeExpansionEvent event)
throws ExpandVetoException {
if (event.getPath().getLastPathComponent() == model.RootNode) {
throw new ExpandVetoException(event);
}
}
public void treeWillExpand(TreeExpansionEvent event) {
}
});
receiversTree.addTreeSelectionListener(
e -> {
TreePath path = e.getNewLeadSelectionPath();
if (path != null) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) path.getLastPathComponent();
if (
(node != null) && (node.getUserObject() != null)
&& (node.getUserObject() instanceof ChainsawReceiver)) {
ChainsawReceiver p = (ChainsawReceiver) node.getUserObject();
logger.debug("plugin=" + p);
pluginEditorPanel.setReceiverAndProperties(p,
m_classToProperties.get(p.getClass()));
} else {
pluginEditorPanel.setReceiverAndProperties(null, null);
}
}
});
receiversTree.setToolTipText("Allows you to manage Log4j Receivers");
newReceiverButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
newReceiverPopup.show(
buttonPanel.newReceiverButton, 0,
buttonPanel.newReceiverButton.getHeight());
}
};
newReceiverButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.ICON_NEW_RECEIVER));
newReceiverButtonAction.putValue(
Action.SHORT_DESCRIPTION, "Creates and configures a new Receiver");
newReceiverButtonAction.putValue(Action.NAME, "New Receiver");
newReceiverButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_N);
newReceiverButtonAction.setEnabled(true);
playReceiverButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
playCurrentlySelectedReceiver();
}
};
playReceiverButtonAction.putValue(
Action.SHORT_DESCRIPTION, "Resumes the selected Node");
playReceiverButtonAction.putValue(Action.NAME, "Resume");
playReceiverButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER));
playReceiverButtonAction.setEnabled(false);
playReceiverButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_R);
pauseReceiverButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
pauseCurrentlySelectedReceiver();
}
};
pauseReceiverButtonAction.putValue(
Action.SHORT_DESCRIPTION,
"Pause the selected Receiver. All events received will be discarded.");
pauseReceiverButtonAction.putValue(Action.NAME, "Pause");
pauseReceiverButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_P);
pauseReceiverButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.PAUSE));
pauseReceiverButtonAction.setEnabled(false);
shutdownReceiverButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
shutdownCurrentlySelectedReceiver();
}
};
shutdownReceiverButtonAction.putValue(
Action.SHORT_DESCRIPTION,
"Shuts down the selected Receiver, and removes it from the Plugin registry");
shutdownReceiverButtonAction.putValue(Action.NAME, "Shutdown");
shutdownReceiverButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER));
shutdownReceiverButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_S);
shutdownReceiverButtonAction.setEnabled(false);
saveReceiversButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
saveReceivers();
}
};
saveReceiversButtonAction.putValue(
Action.SHORT_DESCRIPTION,
"Save the current receiver configuration");
saveReceiversButtonAction.putValue(Action.NAME, "Save receivers");
saveReceiversButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.FILE_SAVE_AS));
saveReceiversButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_V);
restartReceiverButtonAction =
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
ChainsawReceiver selectedReceiver = getCurrentlySelectedReceiver();
if (selectedReceiver == null) {
return;
}
selectedReceiver.shutdown();
selectedReceiver.start();
//allow the visual receiver to get a container on restart
if (selectedReceiver instanceof VisualReceiver) {
((VisualReceiver) selectedReceiver).setContainer(ReceiversPanel.this);
}
}
};
restartReceiverButtonAction.putValue(
Action.SHORT_DESCRIPTION,
"Restarts the selected Receiver");
restartReceiverButtonAction.putValue(Action.NAME, "Restart");
restartReceiverButtonAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.ICON_RESTART));
restartReceiverButtonAction.putValue(
Action.MNEMONIC_KEY, KeyEvent.VK_R);
restartReceiverButtonAction.setEnabled(false);
showReceiverHelpAction =
new AbstractAction("Help") {
public void actionPerformed(ActionEvent e) {
ChainsawReceiver receiver = getCurrentlySelectedReceiver();
if (receiver != null) {
HelpManager.getInstance().showHelpForClass(receiver.getClass());
}
}
};
showReceiverHelpAction.putValue(
Action.SMALL_ICON, new ImageIcon(ChainsawIcons.HELP));
showReceiverHelpAction.putValue(
Action.SHORT_DESCRIPTION, "Displays the JavaDoc page for this Plugin");
startAllAction =
new AbstractAction(
"(Re)start All Receivers", new ImageIcon(ChainsawIcons.ICON_RESTART_ALL)) {
public void actionPerformed(ActionEvent e) {
if (
JOptionPane.showConfirmDialog(
null,
"This will cause any active Receiver to stop, and disconnect. Is this ok?",
"Confirm", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
new Thread(
() -> {
List<ChainsawReceiver> allReceivers = m_parent.getAllReceivers();
for (ChainsawReceiver rx : allReceivers) {
rx.shutdown();
rx.start();
}
updateReceiverTreeInDispatchThread();
m_statusBar.setMessage(
"All Receivers have been (re)started");
}).start();
}
}
};
startAllAction.putValue(
Action.SHORT_DESCRIPTION,
"Ensures that any Receiver that isn't active, is started, and any started action is stopped, and then restarted");
receiversTree.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
receiversTree.setCellRenderer(new ReceiverTreeCellRenderer());
receiversTree.setRowHeight(19);
buttonPanel = new ReceiverToolbar();
receiversTree.addTreeSelectionListener(buttonPanel);
PopupListener popupListener = new PopupListener(popupMenu);
receiversTree.addMouseListener(popupListener);
this.addMouseListener(popupListener);
JComponent component = receiversTree;
JScrollPane pane = new JScrollPane(component);
splitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitter.setTopComponent(pane);
splitter.setBottomComponent(pluginEditorPanel);
splitter.setResizeWeight(0.7);
add(buttonPanel, BorderLayout.NORTH);
add(splitter, BorderLayout.CENTER);
/**
* This Tree likes to be notified when Socket's are accepted so
* we listen for them and update the Tree.
*/
SocketNodeEventListener listener =
new SocketNodeEventListener() {
public void socketOpened(String remoteInfo) {
updateReceiverTreeInDispatchThread();
}
public void socketClosedEvent(Exception e) {
updateReceiverTreeInDispatchThread();
}
};
}