home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2001 October / PCpro_2001_10.ISO / xml / xmlpro / data1.cab / Program_Executable_FILES / xmlpro.jar / AttribEditor.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-09-15  |  3.7 KB  |  134 lines

  1. import java.awt.event.FocusEvent;
  2. import java.awt.event.FocusListener;
  3. import java.awt.event.ItemEvent;
  4. import java.awt.event.ItemListener;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7. import javax.swing.JComboBox;
  8. import javax.swing.JComponent;
  9. import javax.swing.border.BevelBorder;
  10. import javax.swing.text.JTextComponent;
  11. import org.w3c.dom.Element;
  12.  
  13. public class AttribEditor implements FocusListener, ItemListener {
  14.    // $FF: renamed from: el org.w3c.dom.Element
  15.    Element field_0;
  16.    JComponent control;
  17.    String name;
  18.    boolean textfield = false;
  19.    String oldText = null;
  20.    XMLPro theApp;
  21.  
  22.    AttribEditor(String var1, String var2, Element var3, boolean var4, XMLPro var5) {
  23.       this.theApp = var5;
  24.       int var6 = 5;
  25.       if (var1 != null) {
  26.          var6 = (int)((double)var1.length() / 1.3);
  27.       }
  28.  
  29.       if (var6 < 5) {
  30.          var6 = 5;
  31.       }
  32.  
  33.       this.control = new KTextAtt(var6, this);
  34.       this.oldText = var3.getAttribute(var2);
  35.       if (var1 != null) {
  36.          ((KTextAtt)this.control).setText(StringUtils.replaceStr(var1, "<", '<'));
  37.       }
  38.  
  39.       ((KTextAtt)this.control).setBorder(new BevelBorder(1));
  40.       this.textfield = true;
  41.       this.field_0 = var3;
  42.       this.name = var2;
  43.       if (var4 && !this.theApp.editFixedAttributes) {
  44.          this.control.setEnabled(false);
  45.       }
  46.  
  47.       this.control.addFocusListener(this);
  48.    }
  49.  
  50.    AttribEditor(String var1, Vector var2, String var3, Element var4, boolean var5, XMLPro var6) {
  51.       this.theApp = var6;
  52.       boolean var7 = false;
  53.       boolean var8 = false;
  54.       boolean var9 = false;
  55.       this.control = new JComboBox();
  56.       ((JComboBox)this.control).setBorder(new BevelBorder(1));
  57.       this.oldText = var4.getAttribute(var3);
  58.       Enumeration var10 = var2.elements();
  59.  
  60.       while(var10.hasMoreElements()) {
  61.          String var11 = (String)var10.nextElement();
  62.          ((JComboBox)this.control).addItem(var11);
  63.          if (var11.equals(var1)) {
  64.             var9 = true;
  65.             ((JComboBox)this.control).setSelectedItem(var11);
  66.          }
  67.       }
  68.  
  69.       if (!var9) {
  70.          ((JComboBox)this.control).addItem(var1);
  71.          ((JComboBox)this.control).setSelectedItem(var1);
  72.       }
  73.  
  74.       this.field_0 = var4;
  75.       this.name = var3;
  76.       ((JComboBox)this.control).addItemListener(this);
  77.       if (var5 && !this.theApp.editFixedAttributes) {
  78.          this.control.setEnabled(false);
  79.       }
  80.  
  81.    }
  82.  
  83.    public void focusGained(FocusEvent var1) {
  84.       this.theApp.treeSelected = false;
  85.       if (this.theApp.lastText != null && this.theApp.lastText != this.control) {
  86.          this.theApp.lastText.setSelectionStart(0);
  87.          this.theApp.lastText.setSelectionEnd(0);
  88.       }
  89.  
  90.    }
  91.  
  92.    public void focusLost(FocusEvent var1) {
  93.       ElemNode var3 = this.theApp.elems.selectedElem;
  94.       this.oldText = this.field_0.getAttribute(this.name);
  95.       String var2 = ((JTextComponent)this.control).getText();
  96.       var2 = StringUtils.replaceStr(var2, '<', "<");
  97.       if (this.oldText == null || !this.oldText.equals(var2)) {
  98.          if (var2.length() > 0) {
  99.             this.field_0.setAttribute(this.name, var2);
  100.          } else {
  101.             this.field_0.removeAttribute(this.name);
  102.          }
  103.  
  104.          this.theApp.xmlDocument.validated = false;
  105.          this.theApp.xmlDocument.modified = true;
  106.          this.theApp.undoManager.attributeTextMod(var3, this.name, this.oldText);
  107.       }
  108.  
  109.       this.oldText = var2;
  110.       if (this.control instanceof JTextComponent) {
  111.          this.theApp.lastText = (JTextComponent)this.control;
  112.       }
  113.  
  114.    }
  115.  
  116.    public void itemStateChanged(ItemEvent var1) {
  117.       if (this.theApp.lastText != null) {
  118.          this.theApp.lastText.setSelectionStart(0);
  119.          this.theApp.lastText.setSelectionEnd(0);
  120.       }
  121.  
  122.       if (var1.getStateChange() == 1) {
  123.          ElemNode var2 = this.theApp.elems.selectedElem;
  124.          String var3 = (String)((JComboBox)this.control).getSelectedItem();
  125.          this.oldText = this.field_0.getAttribute(this.name);
  126.          this.field_0.setAttribute(this.name, var3);
  127.          this.theApp.xmlDocument.validated = false;
  128.          this.theApp.xmlDocument.modified = true;
  129.          this.theApp.undoManager.attributeTextMod(var2, this.name, this.oldText);
  130.       }
  131.  
  132.    }
  133. }
  134.