home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 1999 May / may1999.iso / May / JBUILDER / JSAMPLES.Z / Wonderland.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-30  |  7.7 KB  |  109 lines

  1. import com.sun.java.swing.ImageIcon;
  2. import com.sun.java.swing.text.AttributeSet;
  3. import com.sun.java.swing.text.BadLocationException;
  4. import com.sun.java.swing.text.DefaultStyledDocument;
  5. import com.sun.java.swing.text.Style;
  6. import com.sun.java.swing.text.StyleConstants;
  7. import com.sun.java.swing.text.StyleContext;
  8. import java.awt.Color;
  9. import java.util.Hashtable;
  10. import java.util.Locale;
  11. import java.util.MissingResourceException;
  12. import java.util.ResourceBundle;
  13.  
  14. public class Wonderland {
  15.    DefaultStyledDocument doc;
  16.    StyleContext styles;
  17.    Hashtable runAttr;
  18.    Wonderland$Paragraph[] data = new Wonderland$Paragraph[]{new Wonderland$Paragraph("title", new Wonderland$Run[]{new Wonderland$Run("none", "ALICE'S ADVENTURES IN WONDERLAND")}), new Wonderland$Paragraph("author", new Wonderland$Run[]{new Wonderland$Run("none", "Lewis Carroll")}), new Wonderland$Paragraph("heading", new Wonderland$Run[]{new Wonderland$Run("alice", " ")}), new Wonderland$Paragraph("edition", new Wonderland$Run[]{new Wonderland$Run("none", "THE MILLENNIUM FULCRUM EDITION 3.0")}), new Wonderland$Paragraph("heading", new Wonderland$Run[]{new Wonderland$Run("none", "CHAPTER V")}), new Wonderland$Paragraph("subtitle", new Wonderland$Run[]{new Wonderland$Run("none", "Advice from a Caterpillar")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", " ")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", "The Caterpillar and Alice looked at each other for some time in silence:  at last the Caterpillar took the hookah out of its mouth, and addressed her in a languid, sleepy voice.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "Who are YOU?  "), new Wonderland$Run("none", "said the Caterpillar.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", "This was not an encouraging opening for a conversation.  Alice replied, rather shyly, "), new Wonderland$Run("aquote", "I--I hardly know, sir, just at present--at least I know who I WAS when I got up this morning, but I think I must have been changed several times since then. ")}), new Wonderland$Paragraph("heading", new Wonderland$Run[]{new Wonderland$Run("caterpillar", " ")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "What do you mean by that? "), new Wonderland$Run("none", " said the Caterpillar sternly.  "), new Wonderland$Run("cquote", "Explain yourself!")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("aquote", "I can't explain MYSELF, I'm afraid, sir"), new Wonderland$Run("none", " said Alice, "), new Wonderland$Run("aquote", "because I'm not myself, you see.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "I don't see,"), new Wonderland$Run("none", " said the Caterpillar.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("aquote", "I'm afraid I can't put it more clearly,  "), new Wonderland$Run("none", "Alice replied very politely, "), new Wonderland$Run("aquote", "for I can't understand it myself to begin with; and being so many different sizes in a day is very confusing.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "It isn't,  "), new Wonderland$Run("none", "said the Caterpillar.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("aquote", "Well, perhaps you haven't found it so yet,"), new Wonderland$Run("none", " said Alice; "), new Wonderland$Run("aquote", "but when you have to turn into a chrysalis--you will some day, you know--and then after that into a butterfly, I should think you'll feel it a little queer, won't you?")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "Not a bit, "), new Wonderland$Run("none", "said the Caterpillar.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("aquote", "Well, perhaps your feelings may be different,"), new Wonderland$Run("none", " said Alice; "), new Wonderland$Run("aquote", "all I know is, it would feel very queer to ME.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "You!"), new Wonderland$Run("none", " said the Caterpillar contemptuously.  "), new Wonderland$Run("cquote", "Who are YOU?")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("normal", "Which brought them back again to the beginning of the conversation.  Alice felt a little irritated at the Caterpillar's making such VERY short remarks, and she drew herself up and said, very gravely, "), new Wonderland$Run("aquote", "I think, you ought to tell me who YOU are, first.")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("cquote", "Why?  "), new Wonderland$Run("none", "said the Caterpillar.")}), new Wonderland$Paragraph("heading", new Wonderland$Run[]{new Wonderland$Run("hatter", " ")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", " ")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", " ")}), new Wonderland$Paragraph("normal", new Wonderland$Run[]{new Wonderland$Run("none", " ")})};
  19.  
  20.    Wonderland(DefaultStyledDocument var1, StyleContext var2) {
  21.       this.doc = var1;
  22.       this.styles = var2;
  23.       this.runAttr = new Hashtable();
  24.    }
  25.  
  26.    void loadDocument() {
  27.       this.createStyles();
  28.  
  29.       for(int var1 = 0; var1 < this.data.length; ++var1) {
  30.          Wonderland$Paragraph var2 = this.data[var1];
  31.          this.addParagraph(var2);
  32.       }
  33.  
  34.    }
  35.  
  36.    void addParagraph(Wonderland$Paragraph var1) {
  37.       try {
  38.          Object var2 = null;
  39.  
  40.          for(int var3 = 0; var3 < var1.data.length; ++var3) {
  41.             Wonderland$Run var4 = var1.data[var3];
  42.             Style var6 = (Style)this.runAttr.get(var4.attr);
  43.             this.doc.insertString(this.doc.getLength(), var4.content, var6);
  44.          }
  45.  
  46.          Style var7 = this.styles.getStyle(var1.logical);
  47.          this.doc.setLogicalStyle(this.doc.getLength() - 1, var7);
  48.          this.doc.insertString(this.doc.getLength(), "\n", (AttributeSet)null);
  49.       } catch (BadLocationException var5) {
  50.          System.err.println("Internal error: " + var5);
  51.       }
  52.    }
  53.  
  54.    void createStyles() {
  55.       Style var1 = this.styles.addStyle((String)null, (Style)null);
  56.       this.runAttr.put("none", var1);
  57.       var1 = this.styles.addStyle((String)null, (Style)null);
  58.       StyleConstants.setItalic(var1, true);
  59.       StyleConstants.setForeground(var1, new Color(153, 153, 102));
  60.       this.runAttr.put("cquote", var1);
  61.       var1 = this.styles.addStyle((String)null, (Style)null);
  62.       StyleConstants.setItalic(var1, true);
  63.       StyleConstants.setForeground(var1, new Color(51, 102, 153));
  64.       this.runAttr.put("aquote", var1);
  65.  
  66.       try {
  67.          ResourceBundle var2 = ResourceBundle.getBundle("Stylepad", Locale.getDefault());
  68.          var1 = this.styles.addStyle((String)null, (Style)null);
  69.          ImageIcon var3 = new ImageIcon(var2.getString("aliceGif"));
  70.          StyleConstants.setIcon(var1, var3);
  71.          this.runAttr.put("alice", var1);
  72.          var1 = this.styles.addStyle((String)null, (Style)null);
  73.          ImageIcon var4 = new ImageIcon(var2.getString("caterpillarGif"));
  74.          StyleConstants.setIcon(var1, var4);
  75.          this.runAttr.put("caterpillar", var1);
  76.          var1 = this.styles.addStyle((String)null, (Style)null);
  77.          ImageIcon var5 = new ImageIcon(var2.getString("hatterGif"));
  78.          StyleConstants.setIcon(var1, var5);
  79.          this.runAttr.put("hatter", var1);
  80.       } catch (MissingResourceException var6) {
  81.       }
  82.  
  83.       Style var12 = this.styles.getStyle("default");
  84.       Style var13 = this.styles.addStyle("heading", var12);
  85.       StyleConstants.setFontFamily(var13, "Helvetica");
  86.       StyleConstants.setBold(var13, true);
  87.       StyleConstants.setAlignment(var13, 1);
  88.       StyleConstants.setSpaceAbove(var13, 10.0F);
  89.       StyleConstants.setSpaceBelow(var13, 10.0F);
  90.       StyleConstants.setFontSize(var13, 18);
  91.       Style var14 = this.styles.addStyle("title", var13);
  92.       StyleConstants.setFontSize(var14, 32);
  93.       var14 = this.styles.addStyle("edition", var13);
  94.       StyleConstants.setFontSize(var14, 16);
  95.       var14 = this.styles.addStyle("author", var13);
  96.       StyleConstants.setItalic(var14, true);
  97.       StyleConstants.setSpaceBelow(var14, 25.0F);
  98.       var14 = this.styles.addStyle("subtitle", var13);
  99.       StyleConstants.setSpaceBelow(var14, 35.0F);
  100.       var14 = this.styles.addStyle("normal", var12);
  101.       StyleConstants.setLeftIndent(var14, 10.0F);
  102.       StyleConstants.setRightIndent(var14, 10.0F);
  103.       StyleConstants.setFontFamily(var14, "Helvetica");
  104.       StyleConstants.setFontSize(var14, 14);
  105.       StyleConstants.setSpaceAbove(var14, 4.0F);
  106.       StyleConstants.setSpaceBelow(var14, 4.0F);
  107.    }
  108. }
  109.