⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logbrokermonitor.java

📁 apache的log4j源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    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;  }  /**   * 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.   */  protected void refresh(JTextArea textArea) {    String text = textArea.getText();    textArea.setText("");    textArea.setText(text);  }  protected void refreshDetailTextArea() {    refresh(_table._detailTextArea);  }  protected void clearDetailTextArea() {    _table._detailTextArea.setText("");  }  /**   * Changes the font selection in the combo box and returns the   * size actually selected.   * @return -1 if unable to select an appropriate font   */  protected int changeFontSizeCombo(JComboBox box, int requestedSize) {    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;  }  /**   * Does not update gui or cause any events to be fired.   */  protected void setFontSizeSilently(int fontSize) {    _fontSize = fontSize;    setFontSize(_table._detailTextArea, fontSize);    selectRow(0);    setFontSize(_table, fontSize);  }  protected void setFontSize(Component component, int fontSize) {    Font oldFont = component.getFont();    Font newFont =        new Font(oldFont.getFontName(), oldFont.getStyle(), fontSize);    component.setFont(newFont);  }  protected void updateFrameSize() {    _logMonitorFrame.setSize(_logMonitorFrameWidth, _logMonitorFrameHeight);    centerFrame(_logMonitorFrame);  }  protected void pause(int millis) {    try {      Thread.sleep(millis);    } catch (InterruptedException e) {    }  }  protected void initComponents() {    //    // 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 LogRecordFilter createLogRecordFilter() {    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;  }  // Added in version 1.2 - Creates a new filter that sorts records based on  // an NDC string passed in by the user.  protected LogRecordFilter createNDCLogRecordFilter(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 void updateStatusLabel() {    _statusLabel.setText(getRecordsDisplayedMessage());  }  protected String getRecordsDisplayedMessage() {    FilteredLogTableModel model = _table.getFilteredLogTableModel();    return getStatusText(model.getRowCount(), model.getTotalRowCount());  }  protected void addTableModelProperties() {    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 String getStatusText(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();  }  protected void makeLogTableListenToCategoryExplorer() {    ActionListener listener = new ActionListener() {      public void actionPerformed(ActionEvent e) {        _table.getFilteredLogTableModel().refresh();        updateStatusLabel();      }    };    _categoryExplorerTree.getExplorerModel().addActionListener(listener);  }  protected JPanel createStatusArea() {    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 JTextArea createDetailTextArea() {    JTextArea detailTA = new JTextArea();    detailTA.setFont(new Font("Monospaced", Font.PLAIN, 14));    detailTA.setTabSize(3);    detailTA.setLineWrap(true);    detailTA.setWrapStyleWord(false);    return (detailTA);  }  protected JMenuBar createMenuBar() {    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 JMenu createLogLevelMenu() {    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 JMenuItem createAllLogLevelsMenuItem() {    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 JMenuItem createNoLogLevelsMenuItem() {    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 JMenu createLogLevelColorMenu() {    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 JMenuItem createResetLogLevelColorMenuItem() {    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 void selectAllLogLevels(boolean selected) {    Iterator levels = getLogLevels();    while (levels.hasNext()) {      getMenuItem((LogLevel) levels.next()).setSelected(selected);    }  }  protected JCheckBoxMenuItem getMenuItem(LogLevel level) {    JCheckBoxMenuItem result = (JCheckBoxMenuItem) (_logLevelMenuItems.get(level));    if (result == null) {      result = createMenuItem(level);      _logLevelMenuItems.put(level, result);    }    return result;  }  protected JMenuItem createSubMenuItem(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;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -