The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
LogTextPanel.java
package org.apache.log4j.gui;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.text.StyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.StyleConstants;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.util.ArrayList;
import org.apache.log4j.*;
public class LogTextPanel extends JPanel {
private JScrollBar scrollBar;
private JTextPane textPane;
private JCheckBox cbxTail;
private StyledDocument doc;
private Hashtable fontAttributes;
private int eventBufferMaxSize = 10000;
private ArrayList eventBuffer = new ArrayList(eventBufferMaxSize);
private int eventViewIndex = 0;
public LogTextPanel() {
constructComponents();
createDefaultFontAttributes();
}
private void constructComponents() {
// setup the panel's additional components...
this.setLayout(new BorderLayout());
cbxTail = new JCheckBox();
cbxTail.setSelected(true);
cbxTail.setText("Tail log events");
JPanel bottomPanel = new JPanel();
bottomPanel.add(cbxTail, null);
textPane = new JTextPane();
textPane.setEditable(false);
textPane.setText("");
doc = textPane.getStyledDocument();
scrollBar = new JScrollBar(JScrollBar.VERTICAL);
this.add(bottomPanel, BorderLayout.SOUTH);
this.add(scrollBar, BorderLayout.EAST);
this.add(textPane, BorderLayout.CENTER);
}
public
void setTextBackground(Color color) {
textPane.setBackground(color);
}
public
void setTextBackground(String v) {
textPane.setBackground(parseColor(v));
}
private void createDefaultFontAttributes() {
Priority[] prio = Priority.getAllPossiblePriorities();
fontAttributes = new Hashtable();
for (int i=0; i<prio.length;i++) {
MutableAttributeSet att = new SimpleAttributeSet();
fontAttributes.put(prio[i], att);
//StyleConstants.setFontSize(att,11);
}
setTextColor(Priority.FATAL, Color.red);
setTextColor(Priority.ERROR, Color.magenta);
setTextColor(Priority.WARN, Color.orange);
setTextColor(Priority.INFO, Color.blue);
setTextColor(Priority.DEBUG, Color.black);
}
private
Color parseColor (String v) {
StringTokenizer st = new StringTokenizer(v,",");
int val[] = {255,255,255,255};
int i=0;
while (st.hasMoreTokens()) {
val[i]=Integer.parseInt(st.nextToken());
i++;
}
return new Color(val[0],val[1],val[2],val[3]);
}
void setTextColor(Priority p, String v) {
StyleConstants.setForeground(
(MutableAttributeSet)fontAttributes.get(p),parseColor(v));
}
void setTextColor(Priority p, Color c) {
StyleConstants.setForeground(
(MutableAttributeSet)fontAttributes.get(p),c);
}
void setTextFontSize(int size) {
Enumeration e = fontAttributes.elements();
while (e.hasMoreElements()) {
StyleConstants.setFontSize((MutableAttributeSet)e.nextElement(),size);
}
return;
}
void setTextFontName(String name) {
Enumeration e = fontAttributes.elements();
while (e.hasMoreElements()) {
StyleConstants.setFontFamily((MutableAttributeSet)e.nextElement(),name);
}
return;
}
void setEventBufferSize(int bufferSize) {
eventBufferMaxSize = bufferSize;
}
void newEvents(EventBufferElement[] evts) {
if((eventBuffer.size() + evts.length) >= eventBufferMaxSize) {
for(int i=0; i < evts.length; i++) {
eventBuffer.remove(0);
}
eventViewIndex -= evts.length;
if(eventViewIndex < 0)
eventViewIndex = 0;
}
for(int i=0; i < evts.length; i++)
eventBuffer.add(evts[i]);
if((eventBuffer.size() > maxR) && cbxTail.isSelected()) {
eventViewIndex = (eventBuffer.size() - maxR);
}
// only redraw if new line is visible...
if((maxR < 0) || (eventBuffer.size() >= eventViewIndex && eventBuffer.size() <= (eventViewIndex + maxR)))
drawText();
}
int maxR = -1;
void drawText() {
if(maxR < 0)
maxR = textPane.getHeight() / textPane.getFontMetrics(textPane.getFont()).getHeight();
try {
doc.remove(0, doc.getLength());
} catch(Exception e) { e.printStackTrace(); }
for(int i=eventViewIndex; (i < eventBuffer.size()) && (i < (eventViewIndex + maxR)); i++) {
EventBufferElement evt = (EventBufferElement)eventBuffer.get(i);
try {
doc.insertString(doc.getLength(), evt.text, (MutableAttributeSet)fontAttributes.get(evt.prio));
} catch(Exception e) { e.printStackTrace(); }
}
}
}