home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / TextViewHTMLMarkerImp.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  3.8 KB  |  117 lines

  1. package netscape.application;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import netscape.util.Enumeration;
  6. import netscape.util.Hashtable;
  7.  
  8. public class TextViewHTMLMarkerImp extends TextViewHTMLMarker {
  9.    TextAttachment textAttachmentCache;
  10.  
  11.    public Hashtable attributesForMarker(Hashtable var1, Hashtable var2, TextView var3) {
  12.       if (!super.marker.equals("HR") && !super.marker.equals("IMG")) {
  13.          return var2;
  14.       } else {
  15.          Hashtable var4;
  16.          if (var2 != null && var2.count() > 0) {
  17.             var4 = (Hashtable)TextView.hashtablePool.allocateObject();
  18.             Enumeration var7 = var2.keys();
  19.  
  20.             while(var7.hasMoreElements()) {
  21.                Object var8 = var7.nextElement();
  22.                var4.put(var8, var2.get(var8));
  23.             }
  24.          } else {
  25.             var4 = (Hashtable)TextView.hashtablePool.allocateObject();
  26.          }
  27.  
  28.          TextAttachment var6 = this.textAttachment(var3.baseURL(), var3);
  29.          var4.put("TextAttachmentKey", var6);
  30.          if (super.marker.equals("IMG")) {
  31.             Hashtable var12 = ((TextViewHTMLElement)this).hashtableForHTMLAttributes(super.attributes);
  32.             String var5;
  33.             if (var12 != null && (var5 = (String)var12.get("ALIGN")) != null) {
  34.                int var13 = 0;
  35.                if (var5.equals("TOP")) {
  36.                   int var9 = 0;
  37.                   Font var11 = (Font)var4.get("FontKey");
  38.                   if (var11 == null) {
  39.                      var11 = (Font)var3.defaultAttributes().get("FontKey");
  40.                   }
  41.  
  42.                   if (var11 != null) {
  43.                      FontMetrics var10 = new FontMetrics(var11);
  44.                      var9 = var10.ascent();
  45.                   }
  46.  
  47.                   var13 = var6.height() - var9;
  48.                } else if (var5.equals("MIDDLE")) {
  49.                   var13 = var6.height() / 2;
  50.                }
  51.  
  52.                var4.put("TextAttachmentBaselineOffsetKey", new Integer(var13));
  53.             }
  54.          }
  55.  
  56.          return var4;
  57.       }
  58.    }
  59.  
  60.    public String prefix(Hashtable var1, char var2) {
  61.       return super.marker.equals("HR") ? "\n\n" : "";
  62.    }
  63.  
  64.    public String string(Hashtable var1) {
  65.       return super.marker.equals("BR") ? "\n" : "@";
  66.    }
  67.  
  68.    private TextAttachment textAttachment(URL var1, TextView var2) {
  69.       if (this.textAttachmentCache == null) {
  70.          if (super.marker.equals("HR")) {
  71.             this.textAttachmentCache = new HRTextAttachment();
  72.          } else if (super.marker.equals("IMG")) {
  73.             int var7 = -1;
  74.             int var8 = -1;
  75.             Hashtable var3 = ((TextViewHTMLElement)this).hashtableForHTMLAttributes(super.attributes);
  76.             String var4;
  77.             if (var3 != null && (var4 = (String)var3.get("SRC")) != null) {
  78.                try {
  79.                   String var9 = (String)var3.get("WIDTH");
  80.                   if (var9 != null) {
  81.                      var7 = Integer.parseInt(var9);
  82.                   }
  83.  
  84.                   var9 = (String)var3.get("HEIGHT");
  85.                   if (var9 != null) {
  86.                      var8 = Integer.parseInt(var9);
  87.                   }
  88.                } catch (NumberFormatException var11) {
  89.                   var8 = -1;
  90.                   var7 = -1;
  91.                }
  92.  
  93.                try {
  94.                   URL var5 = new URL(var1, var4);
  95.                   Bitmap var6;
  96.                   if ((var6 = Bitmap.bitmapFromURL(var5)) != null) {
  97.                      var6.loadData();
  98.                   }
  99.  
  100.                   if (var6 != null && var6.isValid()) {
  101.                      this.textAttachmentCache = new ImageAttachment(var6);
  102.                   }
  103.                } catch (MalformedURLException var10) {
  104.                   System.err.println("Malformed URL " + var4);
  105.                }
  106.             }
  107.  
  108.             if (this.textAttachmentCache == null) {
  109.                this.textAttachmentCache = new BrokenImageAttachment();
  110.             }
  111.          }
  112.       }
  113.  
  114.       return this.textAttachmentCache;
  115.    }
  116. }
  117.