FileDocCategorySizeDatePackage
LogBrokerMonitor.javaAPI DocApache log4j 1.2.1547396Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5.viewer

LogBrokerMonitor

public class LogBrokerMonitor extends Object
LogBrokerMonitor .
author
Michael J. Sikorsky
author
Robert Shaw
author
Brad Marlborough
author
Richard Wan
author
Brent Sprecher
author
Richard Hurst

Fields Summary
public static final String
DETAILED_VIEW
protected JFrame
_logMonitorFrame
protected int
_logMonitorFrameWidth
protected int
_logMonitorFrameHeight
protected LogTable
_table
protected CategoryExplorerTree
_categoryExplorerTree
protected String
_searchText
protected String
_NDCTextFilter
protected LogLevel
_leastSevereDisplayedLogLevel
protected JScrollPane
_logTableScrollPane
protected JLabel
_statusLabel
protected Object
_lock
protected JComboBox
_fontSizeCombo
protected int
_fontSize
protected String
_fontName
protected String
_currentView
protected boolean
_loadSystemFonts
protected boolean
_trackTableScrollPane
protected Dimension
_lastTableViewportSize
protected boolean
_callSystemExitOnClose
protected List
_displayedLogBrokerProperties
protected Map
_logLevelMenuItems
protected Map
_logTableColumnMenuItems
protected List
_levels
protected List
_columns
protected boolean
_isDisposed
protected ConfigurationManager
_configurationManager
protected MRUFileManager
_mruFileManager
protected File
_fileLocation
Constructors Summary
public LogBrokerMonitor(List logLevels)
Construct a LogBrokerMonitor.


  //--------------------------------------------------------------------------
  //   Private Variables:
  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------

        
     

    _levels = logLevels;
    _columns = LogTableColumn.getLogTableColumns();
    // This allows us to use the LogBroker in command line tools and
    // have the option for it to shutdown.

    String callSystemExitOnClose =
        System.getProperty("monitor.exit");
    if (callSystemExitOnClose == null) {
      callSystemExitOnClose = "false";
    }
    callSystemExitOnClose = callSystemExitOnClose.trim().toLowerCase();

    if (callSystemExitOnClose.equals("true")) {
      _callSystemExitOnClose = true;
    }

    initComponents();


    _logMonitorFrame.addWindowListener(
        new LogBrokerMonitorWindowAdaptor(this));

  
Methods Summary
public voidaddDisplayedProperty(java.lang.Object messageLine)

    _displayedLogBrokerProperties.add(messageLine);
  
public voidaddMessage(org.apache.log4j.lf5.LogRecord lr)
Add a log record message to be displayed in the LogTable. This method is thread-safe as it posts requests to the SwingThread rather than processing directly.

    if (_isDisposed == true) {
      // If the frame has been disposed of, do not log any more
      // messages.
      return;
    }

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        _categoryExplorerTree.getExplorerModel().addLogRecord(lr);
        _table.getFilteredLogTableModel().addLogRecord(lr); // update table
        updateStatusLabel(); // show updated counts
      }
    });
  
protected voidaddTableModelProperties()

    final FilteredLogTableModel model = _table.getFilteredLogTableModel();

    addDisplayedProperty(new Object() {
      public String toString() {
        return getRecordsDisplayedMessage();
      }
    });
    addDisplayedProperty(new Object() {
      public String toString() {
        return "Maximum number of displayed LogRecords: "
            + model._maxNumberOfLogRecords;
      }
    });
  
protected voidcenterFrame(javax.swing.JFrame frame)

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension comp = frame.getSize();

    frame.setLocation(((screen.width - comp.width) / 2),
        ((screen.height - comp.height) / 2));

  
protected intchangeFontSizeCombo(javax.swing.JComboBox box, int requestedSize)
Changes the font selection in the combo box and returns the size actually selected.

return
-1 if unable to select an appropriate font

    int len = box.getItemCount();
    int currentValue;
    Object currentObject;
    Object selectedObject = box.getItemAt(0);
    int selectedValue = Integer.parseInt(String.valueOf(selectedObject));
    for (int i = 0; i < len; i++) {
      currentObject = box.getItemAt(i);
      currentValue = Integer.parseInt(String.valueOf(currentObject));
      if (selectedValue < currentValue && currentValue <= requestedSize) {
        selectedValue = currentValue;
        selectedObject = currentObject;
      }
    }
    box.setSelectedItem(selectedObject);
    return selectedValue;
  
protected voidclearDetailTextArea()

    _table._detailTextArea.setText("");
  
protected voidcloseAfterConfirm()

    StringBuffer message = new StringBuffer();

    if (_callSystemExitOnClose == false) {
      message.append("Are you sure you want to close the logging ");
      message.append("console?\n");
      message.append("(Note: This will not shut down the Virtual Machine,\n");
      message.append("or the Swing event thread.)");
    } else {
      message.append("Are you sure you want to exit?\n");
      message.append("This will shut down the Virtual Machine.\n");
    }

    String title =
        "Are you sure you want to dispose of the Logging Console?";

    if (_callSystemExitOnClose == true) {
      title = "Are you sure you want to exit?";
    }
    int value = JOptionPane.showConfirmDialog(
        _logMonitorFrame,
        message.toString(),
        title,
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        null
    );

    if (value == JOptionPane.OK_OPTION) {
      dispose();
    }
  
protected javax.swing.JMenuItemcreateAllLogLevelsMenuItem()

    JMenuItem result = new JMenuItem("Show all LogLevels");
    result.setMnemonic('s");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        selectAllLogLevels(true);
        _table.getFilteredLogTableModel().refresh();
        updateStatusLabel();
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateAllLogTableColumnsMenuItem()

    JMenuItem result = new JMenuItem("Show all Columns");
    result.setMnemonic('s");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        selectAllLogTableColumns(true);
        // update list of columns and reset the view
        List selectedColumns = updateView();
        _table.setView(selectedColumns);
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateCloseMI()

    JMenuItem result = new JMenuItem("Close");
    result.setMnemonic('c");
    result.setAccelerator(KeyStroke.getKeyStroke("control Q"));
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        requestClose();
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateConfigureMaxRecords()

    JMenuItem result = new JMenuItem("Set Max Number of Records");
    result.setMnemonic('m");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        setMaxRecordConfiguration();
      }
    });

    return result;
  
protected javax.swing.JMenucreateConfigureMenu()

    JMenu configureMenu = new JMenu("Configure");
    configureMenu.setMnemonic('c");
    configureMenu.add(createConfigureSave());
    configureMenu.add(createConfigureReset());
    configureMenu.add(createConfigureMaxRecords());

    return configureMenu;
  
protected javax.swing.JMenuItemcreateConfigureReset()

    JMenuItem result = new JMenuItem("Reset");
    result.setMnemonic('r");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        resetConfiguration();
      }
    });

    return result;
  
protected javax.swing.JMenuItemcreateConfigureSave()

    JMenuItem result = new JMenuItem("Save");
    result.setMnemonic('s");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        saveConfiguration();
      }
    });

    return result;
  
protected javax.swing.JTextAreacreateDetailTextArea()

    JTextArea detailTA = new JTextArea();
    detailTA.setFont(new Font("Monospaced", Font.PLAIN, 14));
    detailTA.setTabSize(3);
    detailTA.setLineWrap(true);
    detailTA.setWrapStyleWord(false);
    return (detailTA);
  
protected javax.swing.JMenuItemcreateEditFindMI()

    JMenuItem editFindMI = new JMenuItem("Find");
    editFindMI.setMnemonic('f");
    editFindMI.setAccelerator(KeyStroke.getKeyStroke("control F"));

    editFindMI.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String inputValue =
                JOptionPane.showInputDialog(
                    _logMonitorFrame,
                    "Find text: ",
                    "Search Record Messages",
                    JOptionPane.QUESTION_MESSAGE
                );
            setSearchText(inputValue);
            findSearchText();
          }
        }

    );
    return editFindMI;
  
protected javax.swing.JMenuItemcreateEditFindNextMI()

    JMenuItem editFindNextMI = new JMenuItem("Find Next");
    editFindNextMI.setMnemonic('n");
    editFindNextMI.setAccelerator(KeyStroke.getKeyStroke("F3"));
    editFindNextMI.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        findSearchText();
      }
    });
    return editFindNextMI;
  
protected javax.swing.JMenucreateEditMenu()

    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic('e");
    editMenu.add(createEditFindMI());
    editMenu.add(createEditFindNextMI());
    editMenu.addSeparator();
    editMenu.add(createEditSortNDCMI());
    editMenu.add(createEditRestoreAllNDCMI());
    return editMenu;
  
protected javax.swing.JMenuItemcreateEditRestoreAllNDCMI()

    JMenuItem editRestoreAllNDCMI = new JMenuItem("Restore all NDCs");
    editRestoreAllNDCMI.setMnemonic('r");
    editRestoreAllNDCMI.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _table.getFilteredLogTableModel().setLogRecordFilter(createLogRecordFilter());
            // reset the text filter
            setNDCTextFilter("");
            _table.getFilteredLogTableModel().refresh();
            updateStatusLabel();
          }
        }
    );
    return editRestoreAllNDCMI;
  
protected javax.swing.JMenuItemcreateEditSortNDCMI()

    JMenuItem editSortNDCMI = new JMenuItem("Sort by NDC");
    editSortNDCMI.setMnemonic('s");
    editSortNDCMI.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String inputValue =
                JOptionPane.showInputDialog(
                    _logMonitorFrame,
                    "Sort by this NDC: ",
                    "Sort Log Records by NDC",
                    JOptionPane.QUESTION_MESSAGE
                );
            setNDCTextFilter(inputValue);
            sortByNDC();
            _table.getFilteredLogTableModel().refresh();
            updateStatusLabel();
          }
        }

    );
    return editSortNDCMI;
  
protected javax.swing.JMenuItemcreateExitMI()

    JMenuItem result = new JMenuItem("Exit");
    result.setMnemonic('x");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        requestExit();
      }
    });
    return result;
  
protected javax.swing.JMenucreateFileMenu()

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('f");
    JMenuItem exitMI;
    fileMenu.add(createOpenMI());
    fileMenu.add(createOpenURLMI());
    fileMenu.addSeparator();
    fileMenu.add(createCloseMI());
    createMRUFileListMI(fileMenu);
    fileMenu.addSeparator();
    fileMenu.add(createExitMI());
    return fileMenu;
  
protected javax.swing.JMenucreateHelpMenu()

    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic('h");
    helpMenu.add(createHelpProperties());
    return helpMenu;
  
protected javax.swing.JMenuItemcreateHelpProperties()

    final String title = "LogFactor5 Properties";
    final JMenuItem result = new JMenuItem(title);
    result.setMnemonic('l");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        showPropertiesDialog(title);
      }
    });
    return result;
  
protected javax.swing.JMenucreateLogLevelColorMenu()

    JMenu colorMenu = new JMenu("Configure LogLevel Colors");
    colorMenu.setMnemonic('c");
    Iterator levels = getLogLevels();
    while (levels.hasNext()) {
      colorMenu.add(createSubMenuItem((LogLevel) levels.next()));
    }

    return colorMenu;
  
protected javax.swing.JComboBoxcreateLogLevelCombo()

    JComboBox result = new JComboBox();
    Iterator levels = getLogLevels();
    while (levels.hasNext()) {
      result.addItem(levels.next());
    }
    result.setSelectedItem(_leastSevereDisplayedLogLevel);

    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JComboBox box = (JComboBox) e.getSource();
        LogLevel level = (LogLevel) box.getSelectedItem();
        setLeastSevereDisplayedLogLevel(level);
      }
    });
    result.setMaximumSize(result.getPreferredSize());
    return result;
  
protected javax.swing.JMenucreateLogLevelMenu()

    JMenu result = new JMenu("Log Level");
    result.setMnemonic('l");
    Iterator levels = getLogLevels();
    while (levels.hasNext()) {
      result.add(getMenuItem((LogLevel) levels.next()));
    }

    result.addSeparator();
    result.add(createAllLogLevelsMenuItem());
    result.add(createNoLogLevelsMenuItem());
    result.addSeparator();
    result.add(createLogLevelColorMenu());
    result.add(createResetLogLevelColorMenuItem());

    return result;
  
protected org.apache.log4j.lf5.LogRecordFiltercreateLogRecordFilter()

    LogRecordFilter result = new LogRecordFilter() {
      public boolean passes(LogRecord record) {
        CategoryPath path = new CategoryPath(record.getCategory());
        return
            getMenuItem(record.getLevel()).isSelected() &&
            _categoryExplorerTree.getExplorerModel().isCategoryPathActive(path);
      }
    };
    return result;
  
protected javax.swing.JCheckBoxMenuItemcreateLogTableColumnMenuItem(org.apache.log4j.lf5.viewer.LogTableColumn column)

    JCheckBoxMenuItem result = new JCheckBoxMenuItem(column.toString());

    result.setSelected(true);
    result.setMnemonic(column.toString().charAt(0));
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        // update list of columns and reset the view
        List selectedColumns = updateView();
        _table.setView(selectedColumns);
      }
    });
    return result;
  
protected voidcreateMRUFileListMI(javax.swing.JMenu menu)
Creates a Most Recently Used file list to be displayed in the File menu


    String[] files = _mruFileManager.getMRUFileList();

    if (files != null) {
      menu.addSeparator();
      for (int i = 0; i < files.length; i++) {
        JMenuItem result = new JMenuItem((i + 1) + " " + files[i]);
        result.setMnemonic(i + 1);
        result.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            requestOpenMRU(e);
          }
        });
        menu.add(result);
      }
    }
  
protected javax.swing.JMenuBarcreateMenuBar()

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createFileMenu());
    menuBar.add(createEditMenu());
    menuBar.add(createLogLevelMenu());
    menuBar.add(createViewMenu());
    menuBar.add(createConfigureMenu());
    menuBar.add(createHelpMenu());

    return (menuBar);
  
protected javax.swing.JCheckBoxMenuItemcreateMenuItem(org.apache.log4j.lf5.LogLevel level)

    JCheckBoxMenuItem result = new JCheckBoxMenuItem(level.toString());
    result.setSelected(true);
    result.setMnemonic(level.toString().charAt(0));
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        _table.getFilteredLogTableModel().refresh();
        updateStatusLabel();
      }
    });
    return result;
  
protected org.apache.log4j.lf5.LogRecordFiltercreateNDCLogRecordFilter(java.lang.String text)

    _NDCTextFilter = text;
    LogRecordFilter result = new LogRecordFilter() {
      public boolean passes(LogRecord record) {
        String NDC = record.getNDC();
        CategoryPath path = new CategoryPath(record.getCategory());
        if (NDC == null || _NDCTextFilter == null) {
          return false;
        } else if (NDC.toLowerCase().indexOf(_NDCTextFilter.toLowerCase()) == -1) {
          return false;
        } else {
          return getMenuItem(record.getLevel()).isSelected() &&
              _categoryExplorerTree.getExplorerModel().isCategoryPathActive(path);
        }
      }
    };

    return result;
  
protected javax.swing.JMenuItemcreateNoLogLevelsMenuItem()

    JMenuItem result = new JMenuItem("Hide all LogLevels");
    result.setMnemonic('h");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        selectAllLogLevels(false);
        _table.getFilteredLogTableModel().refresh();
        updateStatusLabel();
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateNoLogTableColumnsMenuItem()

    JMenuItem result = new JMenuItem("Hide all Columns");
    result.setMnemonic('h");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        selectAllLogTableColumns(false);
        // update list of columns and reset the view
        List selectedColumns = updateView();
        _table.setView(selectedColumns);
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateOpenMI()
Menu item added to allow log files to be opened with the LF5 GUI.

    JMenuItem result = new JMenuItem("Open...");
    result.setMnemonic('o");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        requestOpen();
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateOpenURLMI()
Menu item added to allow log files loaded from a URL to be opened by the LF5 GUI.

    JMenuItem result = new JMenuItem("Open URL...");
    result.setMnemonic('u");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        requestOpenURL();
      }
    });
    return result;
  
protected javax.swing.JMenuItemcreateResetLogLevelColorMenuItem()

    JMenuItem result = new JMenuItem("Reset LogLevel Colors");
    result.setMnemonic('r");
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        // reset the level colors in the map
        LogLevel.resetLogLevelColorMap();

        // refresh the table
        _table.getFilteredLogTableModel().refresh();
      }
    });
    return result;
  
protected javax.swing.JPanelcreateStatusArea()

    JPanel statusArea = new JPanel();
    JLabel status =
        new JLabel("No log records to display.");
    _statusLabel = status;
    status.setHorizontalAlignment(JLabel.LEFT);

    statusArea.setBorder(BorderFactory.createEtchedBorder());
    statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    statusArea.add(status);

    return (statusArea);
  
protected javax.swing.JMenuItemcreateSubMenuItem(org.apache.log4j.lf5.LogLevel level)

    final JMenuItem result = new JMenuItem(level.toString());
    final LogLevel logLevel = level;
    result.setMnemonic(level.toString().charAt(0));
    result.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        showLogLevelColorChangeDialog(result, logLevel);
      }
    });

    return result;

  
protected javax.swing.JToolBarcreateToolBar()

    JToolBar tb = new JToolBar();
    tb.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
    JComboBox fontCombo = new JComboBox();
    JComboBox fontSizeCombo = new JComboBox();
    _fontSizeCombo = fontSizeCombo;

    ClassLoader cl = this.getClass().getClassLoader();
    if(cl == null) {
        cl = ClassLoader.getSystemClassLoader();
    }
    URL newIconURL = cl.getResource("org/apache/log4j/lf5/viewer/" +
        "images/channelexplorer_new.gif");

    ImageIcon newIcon = null;

    if (newIconURL != null) {
      newIcon = new ImageIcon(newIconURL);
    }

    JButton newButton = new JButton("Clear Log Table");

    if (newIcon != null) {
      newButton.setIcon(newIcon);
    }

    newButton.setToolTipText("Clear Log Table.");
    //newButton.setBorder(BorderFactory.createEtchedBorder());

    newButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _table.clearLogRecords();
            _categoryExplorerTree.getExplorerModel().resetAllNodeCounts();
            updateStatusLabel();
            clearDetailTextArea();
            LogRecord.resetSequenceNumber();
          }
        }
    );

    Toolkit tk = Toolkit.getDefaultToolkit();
    // This will actually grab all the fonts

    String[] fonts;

    if (_loadSystemFonts) {
      fonts = GraphicsEnvironment.
          getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    } else {
      fonts = tk.getFontList();
    }

    for (int j = 0; j < fonts.length; j++) {
      fontCombo.addItem(fonts[j]);
    }

    fontCombo.setSelectedItem(_fontName);

    fontCombo.addActionListener(

        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JComboBox box = (JComboBox) e.getSource();
            String font = (String) box.getSelectedItem();
            _table.setFont(new Font(font, Font.PLAIN, _fontSize));
            _fontName = font;
          }
        }
    );

    fontSizeCombo.addItem("8");
    fontSizeCombo.addItem("9");
    fontSizeCombo.addItem("10");
    fontSizeCombo.addItem("12");
    fontSizeCombo.addItem("14");
    fontSizeCombo.addItem("16");
    fontSizeCombo.addItem("18");
    fontSizeCombo.addItem("24");

    fontSizeCombo.setSelectedItem(String.valueOf(_fontSize));
    fontSizeCombo.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JComboBox box = (JComboBox) e.getSource();
            String size = (String) box.getSelectedItem();
            int s = Integer.valueOf(size).intValue();

            setFontSizeSilently(s);
            refreshDetailTextArea();
            _fontSize = s;
          }
        }
    );

    tb.add(new JLabel(" Font: "));
    tb.add(fontCombo);
    tb.add(fontSizeCombo);
    tb.addSeparator();
    tb.addSeparator();
    tb.add(newButton);

    newButton.setAlignmentY(0.5f);
    newButton.setAlignmentX(0.5f);

    fontCombo.setMaximumSize(fontCombo.getPreferredSize());
    fontSizeCombo.setMaximumSize(
        fontSizeCombo.getPreferredSize());

    return (tb);
  
protected javax.swing.JMenucreateViewMenu()

    JMenu result = new JMenu("View");
    result.setMnemonic('v");
    Iterator columns = getLogTableColumns();
    while (columns.hasNext()) {
      result.add(getLogTableColumnMenuItem((LogTableColumn) columns.next()));
    }

    result.addSeparator();
    result.add(createAllLogTableColumnsMenuItem());
    result.add(createNoLogTableColumnsMenuItem());
    return result;
  
public voiddispose()
Dispose of the frame for the LogBrokerMonitor.

    _logMonitorFrame.dispose();
    _isDisposed = true;

    if (_callSystemExitOnClose == true) {
      System.exit(0);
    }
  
protected intfindRecord(int startRow, java.lang.String searchText, java.util.List records)

    if (startRow < 0) {
      startRow = 0; // start at first element if no rows are selected
    } else {
      startRow++; // start after the first selected row
    }
    int len = records.size();

    for (int i = startRow; i < len; i++) {
      if (matches((LogRecord) records.get(i), searchText)) {
        return i; // found a record
      }
    }
    // wrap around to beginning if when we reach the end with no match
    len = startRow;
    for (int i = 0; i < len; i++) {
      if (matches((LogRecord) records.get(i), searchText)) {
        return i; // found a record
      }
    }
    // nothing found
    return -1;
  
protected voidfindSearchText()

    String text = _searchText;
    if (text == null || text.length() == 0) {
      return;
    }
    int startRow = getFirstSelectedRow();
    int foundRow = findRecord(
        startRow,
        text,
        _table.getFilteredLogTableModel().getFilteredRecords()
    );
    selectRow(foundRow);
  
public javax.swing.JFramegetBaseFrame()

    return _logMonitorFrame;
  
public booleangetCallSystemExitOnClose()
Get the value of whether or not System.exit() will be called when the LogBrokerMonitor is closed.

    return _callSystemExitOnClose;
  
public org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerTreegetCategoryExplorerTree()

    return _categoryExplorerTree;
  
public org.apache.log4j.lf5.util.DateFormatManagergetDateFormatManager()
Get the DateFormatManager for formatting dates.

    return _table.getDateFormatManager();
  
protected intgetFirstSelectedRow()

    return _table.getSelectionModel().getMinSelectionIndex();
  
public java.util.MapgetLogLevelMenuItems()

    return _logLevelMenuItems;
  
protected java.util.IteratorgetLogLevels()

    return _levels.iterator();
  
protected javax.swing.JCheckBoxMenuItemgetLogTableColumnMenuItem(org.apache.log4j.lf5.viewer.LogTableColumn column)

    JCheckBoxMenuItem result = (JCheckBoxMenuItem) (_logTableColumnMenuItems.get(column));
    if (result == null) {
      result = createLogTableColumnMenuItem(column);
      _logTableColumnMenuItems.put(column, result);
    }
    return result;
  
public java.util.MapgetLogTableColumnMenuItems()

    return _logTableColumnMenuItems;
  
protected java.util.IteratorgetLogTableColumns()

    return _columns.iterator();
  
protected javax.swing.JCheckBoxMenuItemgetMenuItem(org.apache.log4j.lf5.LogLevel level)

    JCheckBoxMenuItem result = (JCheckBoxMenuItem) (_logLevelMenuItems.get(level));
    if (result == null) {
      result = createMenuItem(level);
      _logLevelMenuItems.put(level, result);
    }
    return result;
  
public java.lang.StringgetNDCTextFilter()

    return _NDCTextFilter;
  
protected java.lang.StringgetRecordsDisplayedMessage()

    FilteredLogTableModel model = _table.getFilteredLogTableModel();
    return getStatusText(model.getRowCount(), model.getTotalRowCount());
  
protected java.lang.StringgetStatusText(int displayedRows, int totalRows)

    StringBuffer result = new StringBuffer();
    result.append("Displaying: ");
    result.append(displayedRows);
    result.append(" records out of a total of: ");
    result.append(totalRows);
    result.append(" records.");
    return result.toString();
  
public javax.swing.JCheckBoxMenuItemgetTableColumnMenuItem(org.apache.log4j.lf5.viewer.LogTableColumn column)

    return getLogTableColumnMenuItem(column);
  
public voidhide()
Hide the frame for the LogBrokerMonitor.

    _logMonitorFrame.setVisible(false);
  
protected voidinitComponents()

    //
    // Configure the Frame.
    //
    _logMonitorFrame = new JFrame("LogFactor5");

    _logMonitorFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    String resource =
        "/org/apache/log4j/lf5/viewer/images/lf5_small_icon.gif";
    URL lf5IconURL = getClass().getResource(resource);

    if (lf5IconURL != null) {
      _logMonitorFrame.setIconImage(new ImageIcon(lf5IconURL).getImage());
    }
    updateFrameSize();

    //
    // Configure the LogTable.
    //
    JTextArea detailTA = createDetailTextArea();
    JScrollPane detailTAScrollPane = new JScrollPane(detailTA);
    _table = new LogTable(detailTA);
    setView(_currentView, _table);
    _table.setFont(new Font(_fontName, Font.PLAIN, _fontSize));
    _logTableScrollPane = new JScrollPane(_table);

    if (_trackTableScrollPane) {
      _logTableScrollPane.getVerticalScrollBar().addAdjustmentListener(
          new TrackingAdjustmentListener()
      );
    }


    // Configure the SplitPane between the LogTable & DetailTextArea
    //

    JSplitPane tableViewerSplitPane = new JSplitPane();
    tableViewerSplitPane.setOneTouchExpandable(true);
    tableViewerSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    tableViewerSplitPane.setLeftComponent(_logTableScrollPane);
    tableViewerSplitPane.setRightComponent(detailTAScrollPane);
    // Make sure to do this last..
    //tableViewerSplitPane.setDividerLocation(1.0); Doesn't work
    //the same under 1.2.x & 1.3
    // "350" is a magic number that provides the correct default
    // behaviour under 1.2.x & 1.3.  For example, bumping this
    // number to 400, causes the pane to be completely open in 1.2.x
    // and closed in 1.3
    tableViewerSplitPane.setDividerLocation(350);

    //
    // Configure the CategoryExplorer
    //

    _categoryExplorerTree = new CategoryExplorerTree();

    _table.getFilteredLogTableModel().setLogRecordFilter(createLogRecordFilter());

    JScrollPane categoryExplorerTreeScrollPane =
        new JScrollPane(_categoryExplorerTree);
    categoryExplorerTreeScrollPane.setPreferredSize(new Dimension(130, 400));

    // Load most recently used file list
    _mruFileManager = new MRUFileManager();

    //
    // Configure the SplitPane between the CategoryExplorer & (LogTable/Detail)
    //

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOneTouchExpandable(true);
    splitPane.setRightComponent(tableViewerSplitPane);
    splitPane.setLeftComponent(categoryExplorerTreeScrollPane);
    // Do this last.
    splitPane.setDividerLocation(130);
    //
    // Add the MenuBar, StatusArea, CategoryExplorer|LogTable to the
    // LogMonitorFrame.
    //
    _logMonitorFrame.getRootPane().setJMenuBar(createMenuBar());
    _logMonitorFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    _logMonitorFrame.getContentPane().add(createToolBar(),
        BorderLayout.NORTH);
    _logMonitorFrame.getContentPane().add(createStatusArea(),
        BorderLayout.SOUTH);

    makeLogTableListenToCategoryExplorer();
    addTableModelProperties();

    //
    // Configure ConfigurationManager
    //
    _configurationManager = new ConfigurationManager(this, _table);

  
protected booleanloadLogFile(java.io.File file)
Loads and parses a log file.

    boolean ok = false;
    try {
      LogFileParser lfp = new LogFileParser(file);
      lfp.parse(this);
      ok = true;
    } catch (IOException e) {
      LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
          getBaseFrame(), "Error reading " + file.getName());
    }

    return ok;
  
protected booleanloadLogFile(java.net.URL url)
Loads a parses a log file running on a server.

    boolean ok = false;
    try {
      LogFileParser lfp = new LogFileParser(url.openStream());
      lfp.parse(this);
      ok = true;
    } catch (IOException e) {
      LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
          getBaseFrame(), "Error reading URL:" + url.getFile());
    }
    return ok;
  
protected voidmakeLogTableListenToCategoryExplorer()

    ActionListener listener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        _table.getFilteredLogTableModel().refresh();
        updateStatusLabel();
      }
    };
    _categoryExplorerTree.getExplorerModel().addActionListener(listener);
  
protected booleanmatches(org.apache.log4j.lf5.LogRecord record, java.lang.String text)
Check to see if the any records contain the search string. Searching now supports NDC messages and date.

    String message = record.getMessage();
    String NDC = record.getNDC();

    if (message == null && NDC == null || text == null) {
      return false;
    }
    if (message.toLowerCase().indexOf(text.toLowerCase()) == -1 &&
        NDC.toLowerCase().indexOf(text.toLowerCase()) == -1) {
      return false;
    }

    return true;
  
protected voidpause(int millis)

    try {
      Thread.sleep(millis);
    } catch (InterruptedException e) {

    }
  
protected voidrefresh(javax.swing.JTextArea textArea)
When the fontsize of a JTextArea is changed, the word-wrapped lines may become garbled. This method clears and resets the text of the text area.

    String text = textArea.getText();
    textArea.setText("");
    textArea.setText(text);
  
protected voidrefreshDetailTextArea()

    refresh(_table._detailTextArea);
  
protected voidrequestClose()

    setCallSystemExitOnClose(false);
    closeAfterConfirm();
  
protected voidrequestExit()

    _mruFileManager.save();
    setCallSystemExitOnClose(true);
    closeAfterConfirm();
  
protected voidrequestOpen()
Uses a JFileChooser to select a file to opened with the LF5 GUI.

    JFileChooser chooser;

    if (_fileLocation == null) {
      chooser = new JFileChooser();
    } else {
      chooser = new JFileChooser(_fileLocation);
    }

    int returnVal = chooser.showOpenDialog(_logMonitorFrame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File f = chooser.getSelectedFile();
      if (loadLogFile(f)) {
        _fileLocation = chooser.getSelectedFile();
        _mruFileManager.set(f);
        updateMRUList();
      }
    }
  
protected voidrequestOpenMRU(java.awt.event.ActionEvent e)
Opens a file in the MRU list.

    String file = e.getActionCommand();
    StringTokenizer st = new StringTokenizer(file);
    String num = st.nextToken().trim();
    file = st.nextToken("\n");

    try {
      int index = Integer.parseInt(num) - 1;

      InputStream in = _mruFileManager.getInputStream(index);
      LogFileParser lfp = new LogFileParser(in);
      lfp.parse(this);

      _mruFileManager.moveToTop(index);
      updateMRUList();

    } catch (Exception me) {
      LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
          getBaseFrame(), "Unable to load file " + file);
    }

  
protected voidrequestOpenURL()
Uses a Dialog box to accept a URL to a file to be opened with the LF5 GUI.

    LogFactor5InputDialog inputDialog = new LogFactor5InputDialog(
        getBaseFrame(), "Open URL", "URL:");
    String temp = inputDialog.getText();

    if (temp != null) {
      if (temp.indexOf("://") == -1) {
        temp = "http://" + temp;
      }

      try {
        URL url = new URL(temp);
        if (loadLogFile(url)) {
          _mruFileManager.set(url);
          updateMRUList();
        }
      } catch (MalformedURLException e) {
        LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
            getBaseFrame(), "Error reading URL.");
      }
    }
  
protected voidresetConfiguration()

    _configurationManager.reset();
  
protected voidsaveConfiguration()

    _configurationManager.save();
  
protected voidselectAllLogLevels(boolean selected)

    Iterator levels = getLogLevels();
    while (levels.hasNext()) {
      getMenuItem((LogLevel) levels.next()).setSelected(selected);
    }
  
protected voidselectAllLogTableColumns(boolean selected)

    Iterator columns = getLogTableColumns();
    while (columns.hasNext()) {
      getLogTableColumnMenuItem((LogTableColumn) columns.next()).setSelected(selected);
    }
  
protected voidselectRow(int foundRow)

    if (foundRow == -1) {
      String message = _searchText + " not found.";
      JOptionPane.showMessageDialog(
          _logMonitorFrame,
          message,
          "Text not found",
          JOptionPane.INFORMATION_MESSAGE
      );
      return;
    }
    LF5SwingUtils.selectRow(foundRow, _table, _logTableScrollPane);
  
public voidsetCallSystemExitOnClose(boolean callSystemExitOnClose)
Set the value of whether or not System.exit() will be called when the LogBrokerMonitor is closed.

    _callSystemExitOnClose = callSystemExitOnClose;
  
public voidsetDateFormatManager(org.apache.log4j.lf5.util.DateFormatManager dfm)
Set the date format manager for formatting dates.

    _table.setDateFormatManager(dfm);
  
public voidsetFontSize(int fontSize)

    changeFontSizeCombo(_fontSizeCombo, fontSize);
    // setFontSizeSilently(actualFontSize); - changeFontSizeCombo fires event
    // refreshDetailTextArea();
  
protected voidsetFontSize(java.awt.Component component, int fontSize)

    Font oldFont = component.getFont();
    Font newFont =
        new Font(oldFont.getFontName(), oldFont.getStyle(), fontSize);
    component.setFont(newFont);
  
protected voidsetFontSizeSilently(int fontSize)
Does not update gui or cause any events to be fired.

    _fontSize = fontSize;
    setFontSize(_table._detailTextArea, fontSize);
    selectRow(0);
    setFontSize(_table, fontSize);
  
public voidsetFrameSize(int width, int height)

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    if (0 < width && width < screen.width) {
      _logMonitorFrameWidth = width;
    }
    if (0 < height && height < screen.height) {
      _logMonitorFrameHeight = height;
    }
    updateFrameSize();
  
protected voidsetLeastSevereDisplayedLogLevel(org.apache.log4j.lf5.LogLevel level)

    if (level == null || _leastSevereDisplayedLogLevel == level) {
      return; // nothing to do
    }
    _leastSevereDisplayedLogLevel = level;
    _table.getFilteredLogTableModel().refresh();
    updateStatusLabel();
  
public voidsetMaxNumberOfLogRecords(int maxNumberOfLogRecords)

    _table.getFilteredLogTableModel().setMaxNumberOfLogRecords(maxNumberOfLogRecords);
  
protected voidsetMaxRecordConfiguration()

    LogFactor5InputDialog inputDialog = new LogFactor5InputDialog(
        getBaseFrame(), "Set Max Number of Records", "", 10);

    String temp = inputDialog.getText();

    if (temp != null) {
      try {
        setMaxNumberOfLogRecords(Integer.parseInt(temp));
      } catch (NumberFormatException e) {
        LogFactor5ErrorDialog error = new LogFactor5ErrorDialog(
            getBaseFrame(),
            "'" + temp + "' is an invalid parameter.\nPlease try again.");
        setMaxRecordConfiguration();
      }
    }
  
public voidsetNDCLogRecordFilter(java.lang.String textFilter)

    _table.getFilteredLogTableModel().
        setLogRecordFilter(createNDCLogRecordFilter(textFilter));
  
protected voidsetNDCTextFilter(java.lang.String text)

    // if no value is set, set it to a blank string
    // otherwise use the value provided
    if (text == null) {
      _NDCTextFilter = "";
    } else {
      _NDCTextFilter = text;
    }
  
protected voidsetSearchText(java.lang.String text)

    _searchText = text;
  
public voidsetTitle(java.lang.String title)

    _logMonitorFrame.setTitle(title + " - LogFactor5");
  
protected voidsetView(java.lang.String viewString, org.apache.log4j.lf5.viewer.LogTable table)

    if (DETAILED_VIEW.equals(viewString)) {
      table.setDetailedView();
    } else {
      String message = viewString + "does not match a supported view.";
      throw new IllegalArgumentException(message);
    }
    _currentView = viewString;
  
public voidshow(int delay)
Show the frame for the LogBrokerMonitor. Dispatched to the swing thread.

    if (_logMonitorFrame.isVisible()) {
      return;
    }
    // This request is very low priority, let other threads execute first.
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        Thread.yield();
        pause(delay);
        _logMonitorFrame.setVisible(true);
      }
    });
  
public voidshow()

    show(0);
  
protected voidshowLogLevelColorChangeDialog(javax.swing.JMenuItem result, org.apache.log4j.lf5.LogLevel level)

    JMenuItem menuItem = result;
    Color newColor = JColorChooser.showDialog(
        _logMonitorFrame,
        "Choose LogLevel Color",
        result.getForeground());

    if (newColor != null) {
      // set the color for the record
      level.setLogLevelColorMap(level, newColor);
      _table.getFilteredLogTableModel().refresh();
    }

  
protected voidshowPropertiesDialog(java.lang.String title)

    JOptionPane.showMessageDialog(
        _logMonitorFrame,
        _displayedLogBrokerProperties.toArray(),
        title,
        JOptionPane.PLAIN_MESSAGE
    );
  
protected voidsortByNDC()

    String text = _NDCTextFilter;
    if (text == null || text.length() == 0) {
      return;
    }

    // Use new NDC filter
    _table.getFilteredLogTableModel().
        setLogRecordFilter(createNDCLogRecordFilter(text));
  
protected voidtrackTableScrollPane()
Ensures that the Table's ScrollPane Viewport will "track" with updates to the Table. When the vertical scroll bar is at its bottom anchor and tracking is enabled then viewport will stay at the bottom most point of the component. The purpose of this feature is to allow a developer to watch the table as messages arrive and not have to scroll after each new message arrives. When the vertical scroll bar is at any other location, then no tracking will happen.

deprecated
tracking is now done automatically.

    // do nothing
  
protected voidupdateFrameSize()

    _logMonitorFrame.setSize(_logMonitorFrameWidth, _logMonitorFrameHeight);
    centerFrame(_logMonitorFrame);
  
protected voidupdateMRUList()
Removes old file list and creates a new file list with the updated MRU list.

    JMenu menu = _logMonitorFrame.getJMenuBar().getMenu(0);
    menu.removeAll();
    menu.add(createOpenMI());
    menu.add(createOpenURLMI());
    menu.addSeparator();
    menu.add(createCloseMI());
    createMRUFileListMI(menu);
    menu.addSeparator();
    menu.add(createExitMI());
  
protected voidupdateStatusLabel()

    _statusLabel.setText(getRecordsDisplayedMessage());
  
protected java.util.ListupdateView()

    ArrayList updatedList = new ArrayList();
    Iterator columnIterator = _columns.iterator();
    while (columnIterator.hasNext()) {
      LogTableColumn column = (LogTableColumn) columnIterator.next();
      JCheckBoxMenuItem result = getLogTableColumnMenuItem(column);
      // check and see if the checkbox is checked
      if (result.isSelected()) {
        updatedList.add(column);
      }
    }

    return updatedList;