home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Graphics;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JTree;
- import javax.swing.tree.TreeCellRenderer;
- import org.w3c.dom.Attr;
- import org.w3c.dom.Element;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
-
- public class XMLTreeCellRenderer extends JLabel implements TreeCellRenderer {
- public static boolean selected;
- public static ImageIcon elemIcon;
- public static ImageIcon entityIcon;
- public static ImageIcon cdataIcon;
- public static ImageIcon commentIcon;
- public static ImageIcon pcdataIcon;
- public static Color textSelectionColor;
- public static Color textNonSelectionColor;
- public static Color backgroundSelectionColor;
- public static Color backgroundNonSelectionColor;
- public static Color borderSelectionColor;
- ElemPanel elemPanel;
- XMLPro theApp;
- static int lineBreak = 36;
-
- public XMLTreeCellRenderer(ElemPanel var1, XMLPro var2) {
- this.theApp = var2;
- this.elemPanel = var1;
- textSelectionColor = Color.white;
- backgroundSelectionColor = Color.blue;
- textNonSelectionColor = Color.black;
- backgroundNonSelectionColor = Color.white;
- }
-
- String breakUp(String var1, int var2) {
- int var3 = 0;
- int var5 = var1.length();
- StringBuffer var7 = new StringBuffer(var5);
-
- while(var3 < var5) {
- if (var5 - var3 > var2) {
- int var4 = var3 + var2;
-
- while(var1.charAt(var4) != ' ') {
- --var4;
- if (var4 == var3) {
- return var1;
- }
- }
-
- var7.append(var1.substring(var3, var4));
- var7.append("\n");
- var3 = var4 + 1;
- } else {
- var7.append(var1.substring(var3));
- var3 = var5;
- }
- }
-
- return var7.toString();
- }
-
- public Component getTreeCellRendererComponent(JTree var1, Object var2, boolean var3, boolean var4, boolean var5, int var6, boolean var7) {
- Node var8 = ((ElemNode)var2).e;
- if (var8.getNodeType() == 3 && this.theApp.viewText) {
- String var12 = var8.getNodeValue();
- if (var12.length() > 0) {
- var12 = StringUtils.replaceStr(var12, "<", '<');
- var12 = this.breakUp(var12, lineBreak);
- } else {
- var12 = "<New PCDATA>";
- }
-
- KTextArea var15 = new KTextArea(var12);
- selected = var3;
- if (var3) {
- var15.text.setForeground(textSelectionColor);
- var15.text.setBackground(backgroundSelectionColor);
- } else {
- var15.text.setForeground(textNonSelectionColor);
- var15.text.setBackground(backgroundNonSelectionColor);
- }
-
- return var15;
- } else {
- if (var8.getNodeType() == 1) {
- String var9 = ((Element)var8).getTagName().toString();
- ((JLabel)this).setIcon(elemIcon);
- if (this.theApp.viewAttributes) {
- NamedNodeMap var10 = var8.getAttributes();
- int var11 = var10.getLength();
- if (var11 == 0) {
- ((JLabel)this).setText(var9);
- } else {
- ((JLabel)this).setText(var9 + " " + this.listAttributes(var10));
- }
- } else {
- ((JLabel)this).setText(var9);
- }
- } else if (var8.getNodeType() == 5) {
- ((JLabel)this).setIcon(entityIcon);
- ((JLabel)this).setText(var8.getNodeName());
- } else if (var8.getNodeType() == 3) {
- ((JLabel)this).setIcon(pcdataIcon);
- ((JLabel)this).setText("PCDATA");
- } else if (var8.getNodeType() == 4) {
- ((JLabel)this).setIcon(cdataIcon);
- ((JLabel)this).setText("CDATA");
- } else if (var8.getNodeType() == 8) {
- ((JLabel)this).setIcon(commentIcon);
- ((JLabel)this).setText("COMMENT");
- }
-
- selected = var3;
- if (var3) {
- ((JComponent)this).setForeground(textSelectionColor);
- ((JComponent)this).setBackground(backgroundSelectionColor);
- } else {
- ((JComponent)this).setForeground(textNonSelectionColor);
- ((JComponent)this).setBackground(backgroundNonSelectionColor);
- }
-
- return this;
- }
- }
-
- String listAttributes(NamedNodeMap var1) {
- String var2 = "[";
- int var3 = var1.getLength();
-
- for(int var4 = 0; var4 < var3; ++var4) {
- Attr var5 = (Attr)var1.item(var4);
- var2 = var2 + var5.getName() + "=" + var5.getValue();
- if (var4 != var3 - 1) {
- var2 = var2 + ", ";
- }
- }
-
- var2 = var2 + "]";
- return var2;
- }
-
- public void paint(Graphics var1) {
- Icon var3 = ((JLabel)this).getIcon();
- Color var2;
- if (selected) {
- var2 = backgroundSelectionColor;
- } else {
- var2 = backgroundNonSelectionColor;
- }
-
- var1.setColor(var2);
- if (var3 != null && ((JLabel)this).getText() != null) {
- int var4 = var3.getIconWidth() + ((JLabel)this).getIconTextGap();
- var1.fillRect(var4, 0, ((JComponent)this).getWidth() - 1 - var4, ((JComponent)this).getHeight() - 1);
- } else {
- var1.fillRect(0, 0, ((JComponent)this).getWidth() - 1, ((JComponent)this).getHeight() - 1);
- }
-
- super.paint(var1);
- }
- }
-