KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > MailWrappedView


1 package net.suberic.pooka.gui;
2 import javax.swing.text.WrappedPlainView JavaDoc;
3 import javax.swing.text.Segment JavaDoc;
4 import javax.swing.text.Element JavaDoc;
5 import net.suberic.pooka.MailUtilities;
6 import net.suberic.pooka.Pooka;
7
8 /**
9  * This class extends javax.swing.text.WrappedPlainView. Its primary
10  * purpose is to change the word wrapping methodology so that the text
11  * of new messages is wrapped on the screen at a character boundary, just
12  * as it will be when it's actually sent. So in other words, this
13  * class makes it so, if you have your mail client set to line wrap at 72
14  * characters, your mail entry window will also wrap at 72 characters, no
15  * matter what the size of your font or your window is.
16  */

17 public class MailWrappedView extends WrappedPlainView JavaDoc {
18
19   public MailWrappedView(Element JavaDoc elem) {
20     super(elem);
21   }
22   
23   public MailWrappedView(Element JavaDoc elem, boolean wordWrap) {
24     super(elem, wordWrap);
25   }
26   
27   private int characterLength = 72;
28
29   /**
30    * This implementation will break the line at the character length
31    * returned by getCharacterLength().
32    *
33    * Overrides <code>WrappedPlainView.calculateBreakPosition</code>
34    */

35   protected int calculateBreakPosition(int p0, int p1) {
36     super.calculateBreakPosition(p0, p1);
37     try {
38       String JavaDoc text = getDocument().getText(p0, p1 - p0);
39       int offset = MailUtilities.getBreakOffset(text, getCharacterLength(), getTabSize());
40       return p0 + offset;
41     } catch (javax.swing.text.BadLocationException JavaDoc ble) {
42       return p1;
43     }
44   }
45   
46   public int getCharacterLength() {
47     try {
48       String JavaDoc wrapLengthString = Pooka.getProperty("Pooka.lineLength");
49       characterLength = Integer.parseInt(wrapLengthString);
50     } catch (Exception JavaDoc e) {
51       characterLength = 72;
52     }
53     return characterLength;
54   }
55   
56   public void setCharacterLength(int newCharacterLength) {
57     characterLength = newCharacterLength;
58   }
59 }
60
61
Popular Tags