📄 stafjvmlogviewer.java
字号:
fSelectJVMLogNameDialog.setSize(panelWidth, 120); fSelectJVMLogNameDialog.getContentPane().add( selectJVMLogNamePanel); // Determine the number of JVM Logs that exist for the JVMName java.util.List jvmLogNameList = new ArrayList(); for (int i = 1; i <= fMaxJVMLogs; i++) { jvmLogNameList.add("JVMLog." + i); } // Convert the list of existing JVM Log names to an array Object[] possibleValues = jvmLogNameList.toArray(new Object[0]); fAvailableJVMLogNames = new JComboBox(possibleValues); fAvailableJVMLogNames.setBackground(Color.white); JPanel jvmLogNamesComboBoxPanel = new JPanel(); jvmLogNamesComboBoxPanel.add(fAvailableJVMLogNames); selectJVMLogNamePanel.add(BorderLayout.NORTH, jvmLogNamesComboBoxPanel); JPanel selectJVMLogNameButtonPanel = new JPanel(); selectJVMLogNameButtonPanel.setLayout( new FlowLayout(FlowLayout.CENTER, 0, 0)); fSelectJVMLogNameOkButton = new JButton("OK"); fSelectJVMLogNameOkButton.addActionListener(this); fSelectJVMLogNameCancelButton = new JButton("Cancel"); fSelectJVMLogNameCancelButton.addActionListener(this); selectJVMLogNameButtonPanel.add(fSelectJVMLogNameOkButton); selectJVMLogNameButtonPanel.add(Box.createHorizontalStrut(20)); selectJVMLogNameButtonPanel.add(fSelectJVMLogNameCancelButton); selectJVMLogNamePanel.add( BorderLayout.SOUTH, selectJVMLogNameButtonPanel); // Set up Change Font Dialog panels fChangeFontDialog = new JDialog(this, "Change Font", true); fChangeFontDialog.setSize(220, 120); JPanel changeFontPanel = new JPanel(); changeFontPanel.setLayout(new BorderLayout()); changeFontPanel.setBorder(new TitledBorder("Select Font")); fChangeFontDialog.getContentPane().add(changeFontPanel); GraphicsEnvironment env = GraphicsEnvironment. getLocalGraphicsEnvironment(); String[] fontNames = env.getAvailableFontFamilyNames(); fAvailableFonts = new JComboBox(fontNames); fAvailableFonts.setBackground(Color.white); changeFontPanel.add(BorderLayout.NORTH, fAvailableFonts); JPanel changeFontButtonPanel = new JPanel(); changeFontButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); fChangeFontOkButton = new JButton("OK"); fChangeFontOkButton.addActionListener(this); fChangeFontCancelButton = new JButton("Cancel"); fChangeFontCancelButton.addActionListener(this); changeFontButtonPanel.add(fChangeFontOkButton); changeFontButtonPanel.add(Box.createHorizontalStrut(20)); changeFontButtonPanel.add(fChangeFontCancelButton); changeFontPanel.add(BorderLayout.SOUTH, changeFontButtonPanel); columnNames = new Vector(); columnNames.add(""); fLogTable = new JTable(); fLogTable.setFont(new Font(fFontName, Font.PLAIN, 12)); fAvailableFonts.setSelectedItem(fFontName); fLogTable.setRowSelectionAllowed(true); fLogTable.setColumnSelectionAllowed(false); fLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updateRowHeights(fLogTable, 0, fFontName); sizeColumnsToFitText(fLogTable); JScrollPane logScroll = new JScrollPane(fLogTable); // Scroll to bottom fLogVerticalScrollBar = logScroll.getVerticalScrollBar(); fLogVerticalScrollBar.setValue(fLogVerticalScrollBar.getMaximum()); getContentPane().add(logScroll); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { if (! fSystemExit) dispose(); else System.exit(0); } }); } public void actionPerformed(ActionEvent e) { if (e.getSource() == fFileExit) { if (! fSystemExit) dispose(); else { System.exit(0); } } else if (e.getSource() == fViewRefresh) { refreshTable(); } else if (e.getSource() == fViewShowCurrent) { fDisplayAll = false; refreshTable(); } else if (e.getSource() == fViewShowAll) { fDisplayAll = true; refreshTable(); } else if (e.getSource() == fViewSelectJVMLogName) { fSelectJVMLogNameDialog.setLocationRelativeTo(fLogFrame); fSelectJVMLogNameDialog.show(); } else if (e.getSource() == fSelectJVMLogNameOkButton) { fJVMLogName = (String)fAvailableJVMLogNames.getSelectedItem(); fJVMLogFileName = fJVMLogDirName + fJVMLogName; String frameTitle = "JVM Log for Service " + fServiceName + " - STAF " + fMachine + " FS GET FILE " + fJVMLogFileName; fLogFrame.setTitle(frameTitle); refreshTable(); fSelectJVMLogNameDialog.hide(); } else if (e.getSource() == fSelectJVMLogNameCancelButton) { fSelectJVMLogNameDialog.hide(); } else if (e.getSource() == fViewChangeFont) { fChangeFontDialog.setLocationRelativeTo(fLogFrame); fChangeFontDialog.show(); } else if (e.getSource() == fChangeFontOkButton) { fFontName = (String)fAvailableFonts.getSelectedItem(); fLogTable.setFont(new Font(fFontName, Font.PLAIN, 12)); updateLogTableRenderers(); updateRowHeights(fLogTable, 0, fFontName); sizeColumnsToFitText(fLogTable); fChangeFontDialog.hide(); } else if (e.getSource() == fChangeFontCancelButton) { fChangeFontDialog.hide(); } } } public class STAFLogTableCellRenderer extends JTextArea implements TableCellRenderer { public Hashtable rowHeights = new Hashtable(); private boolean isHeader = true; public STAFLogTableCellRenderer() { this(false); } public STAFLogTableCellRenderer(boolean isHeader) { if (isHeader) { setFont(new Font(fFontName, Font.BOLD, 12)); setBackground(Color.lightGray); } else { setFont(new Font(fFontName, Font.PLAIN, 12)); setBackground(Color.white); } this.isHeader = isHeader; setOpaque(true); setForeground(Color.black); //setHorizontalAlignment(SwingConstants.LEFT); setBorder(BorderFactory.createRaisedBevelBorder()); } public void clearRowHeights() { rowHeights.clear(); } public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { if (isHeader) { setBackground(Color.lightGray); } else if (isSelected) { setBackground(UIManager.getColor("Table.selectionBackground")); } else { setBackground(Color.white); } setText((value == null) ? "" : String.valueOf(value)); return this; } }public class STAFTableModel extends javax.swing.table.DefaultTableModel{ public STAFTableModel() { super(); } public STAFTableModel(java.lang.Object[][] data, java.lang.Object[] columnNames) { super(data, columnNames); } public STAFTableModel(java.lang.Object[] columnNames, int numRows) { super(columnNames, numRows); } public STAFTableModel(int numRows, int numColumns) { super(numRows, numColumns); } public STAFTableModel(java.util.Vector columnNames, int numRows) { super(columnNames, numRows); } public STAFTableModel(java.util.Vector data, java.util.Vector columnNames) { super(data, columnNames); } public Class getColumnClass(int col) { if (dataVector.isEmpty()) { return (new Object()).getClass(); } else { Vector v = (Vector)dataVector.elementAt(0); return v.elementAt(col).getClass(); } } public boolean isCellEditable(int row, int column) { return false; }}public class STAFTableMap extends DefaultTableModel implements TableModelListener{ protected STAFTableModel model; public STAFTableModel getModel() { return model; } public void setModel(STAFTableModel model) { this.model = model; model.addTableModelListener(this); } public Object getValueAt(int aRow, int aColumn) { return model.getValueAt(aRow, aColumn); } public void setValueAt(Object aValue, int aRow, int aColumn) { model.setValueAt(aValue, aRow, aColumn); } public int getRowCount() { return (model == null) ? 0 : model.getRowCount(); } public int getColumnCount() { return (model == null) ? 0 : model.getColumnCount(); } public String getColumnName(int aColumn) { return model.getColumnName(aColumn); } public Class getColumnClass(int aColumn) { return model.getColumnClass(aColumn); } public boolean isCellEditable(int row, int column) { return false; } public void tableChanged(TableModelEvent e) { fireTableChanged(e); }} private STAFHandle fHandle; private String fMachine = "local"; private String fServiceName = ""; private String fJVMName = ""; private int fMaxJVMLogs = 1; private String fJVMLogDirName = ""; private String fJVMLogName = "JVMLog.1"; private String fJVMLogFileName = null; private String fLogName = null; private JTable fLogTable; private boolean fDisplayAll = false; private String fFontName = "Monospaced"; boolean fSystemExit = true; STAFTableModel fLogTableModel; String fStartDateTime = null; Vector columnNames; STAFLogFrame fLogFrame; JScrollBar fLogVerticalScrollBar; Component parent; JMenu fFileMenu; JMenu fViewMenu; JMenuItem fFileExit; JMenuItem fViewRefresh; JMenuItem fViewShowCurrent; JMenuItem fViewShowAll; JMenuItem fViewSelectJVMLogName; JMenuItem fViewChangeFont; JDialog fSelectJVMLogNameDialog; JComboBox fAvailableJVMLogNames; JButton fSelectJVMLogNameOkButton; JButton fSelectJVMLogNameCancelButton; JDialog fChangeFontDialog; JComboBox fAvailableFonts; JButton fChangeFontOkButton; JButton fChangeFontCancelButton;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -