< prev index next >

src/java.desktop/share/classes/javax/swing/text/PlainView.java

Print this page




  45      * @param elem the element
  46      */
  47     public PlainView(Element elem) {
  48         super(elem);
  49     }
  50 
  51     /**
  52      * Returns the tab size set for the document, defaulting to 8.
  53      *
  54      * @return the tab size
  55      */
  56     protected int getTabSize() {
  57         Integer i = (Integer) getDocument().getProperty(PlainDocument.tabSizeAttribute);
  58         int size = (i != null) ? i.intValue() : 8;
  59         return size;
  60     }
  61 
  62     /**
  63      * Renders a line of text, suppressing whitespace at the end
  64      * and expanding any tabs.  This is implemented to make calls
  65      * to the methods <code>drawUnselectedText</code> and
  66      * <code>drawSelectedText</code> so that the way selected and
  67      * unselected text are rendered can be customized.
  68      *
  69      * @param lineIndex the line to draw &gt;= 0
  70      * @param g the <code>Graphics</code> context
  71      * @param x the starting X position &gt;= 0
  72      * @param y the starting Y position &gt;= 0
  73      * @see #drawUnselectedText
  74      * @see #drawSelectedText
  75      */
  76     protected void drawLine(int lineIndex, Graphics g, int x, int y) {
  77         Element line = getElement().getElement(lineIndex);
  78         Element elem;
  79 
  80         try {
  81             if (line.isLeaf()) {
  82                 drawElement(lineIndex, line, g, x, y);
  83             } else {
  84                 // this line contains the composed text.
  85                 int count = line.getElementCount();
  86                 for(int i = 0; i < count; i++) {
  87                     elem = line.getElement(i);
  88                     x = drawElement(lineIndex, elem, g, x, y);
  89                 }
  90             }


 304                 }
 305                 else {
 306                     dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
 307                                               lineElement.getEndOffset() - 1,
 308                                               originalA, host, this);
 309                 }
 310             }
 311             drawLine(line, g, x, y);
 312             y += fontHeight;
 313             if (line == 0) {
 314                 // This should never really happen, in so far as if
 315                 // firstLineOffset is non 0, there should only be one
 316                 // line of text.
 317                 x -= firstLineOffset;
 318             }
 319         }
 320     }
 321 
 322     /**
 323      * Should return a shape ideal for painting based on the passed in
 324      * Shape <code>a</code>. This is useful if painting in a different
 325      * region. The default implementation returns <code>a</code>.
 326      */
 327     Shape adjustPaintRegion(Shape a) {
 328         return a;
 329     }
 330 
 331     /**
 332      * Provides a mapping from the document model coordinate space
 333      * to the coordinate space of the view mapped to it.
 334      *
 335      * @param pos the position to convert &gt;= 0
 336      * @param a the allocated region to render into
 337      * @return the bounding box of the given position
 338      * @exception BadLocationException  if the given position does not
 339      *   represent a valid location in the associated document
 340      * @see View#modelToView
 341      */
 342     public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
 343         // line coordinates
 344         Document doc = getDocument();
 345         Element map = getElement();




  45      * @param elem the element
  46      */
  47     public PlainView(Element elem) {
  48         super(elem);
  49     }
  50 
  51     /**
  52      * Returns the tab size set for the document, defaulting to 8.
  53      *
  54      * @return the tab size
  55      */
  56     protected int getTabSize() {
  57         Integer i = (Integer) getDocument().getProperty(PlainDocument.tabSizeAttribute);
  58         int size = (i != null) ? i.intValue() : 8;
  59         return size;
  60     }
  61 
  62     /**
  63      * Renders a line of text, suppressing whitespace at the end
  64      * and expanding any tabs.  This is implemented to make calls
  65      * to the methods {@code drawUnselectedText} and
  66      * {@code drawSelectedText} so that the way selected and
  67      * unselected text are rendered can be customized.
  68      *
  69      * @param lineIndex the line to draw &gt;= 0
  70      * @param g the {@code Graphics} context
  71      * @param x the starting X position &gt;= 0
  72      * @param y the starting Y position &gt;= 0
  73      * @see #drawUnselectedText
  74      * @see #drawSelectedText
  75      */
  76     protected void drawLine(int lineIndex, Graphics g, int x, int y) {
  77         Element line = getElement().getElement(lineIndex);
  78         Element elem;
  79 
  80         try {
  81             if (line.isLeaf()) {
  82                 drawElement(lineIndex, line, g, x, y);
  83             } else {
  84                 // this line contains the composed text.
  85                 int count = line.getElementCount();
  86                 for(int i = 0; i < count; i++) {
  87                     elem = line.getElement(i);
  88                     x = drawElement(lineIndex, elem, g, x, y);
  89                 }
  90             }


 304                 }
 305                 else {
 306                     dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
 307                                               lineElement.getEndOffset() - 1,
 308                                               originalA, host, this);
 309                 }
 310             }
 311             drawLine(line, g, x, y);
 312             y += fontHeight;
 313             if (line == 0) {
 314                 // This should never really happen, in so far as if
 315                 // firstLineOffset is non 0, there should only be one
 316                 // line of text.
 317                 x -= firstLineOffset;
 318             }
 319         }
 320     }
 321 
 322     /**
 323      * Should return a shape ideal for painting based on the passed in
 324      * Shape {@code a}. This is useful if painting in a different
 325      * region. The default implementation returns {@code a}.
 326      */
 327     Shape adjustPaintRegion(Shape a) {
 328         return a;
 329     }
 330 
 331     /**
 332      * Provides a mapping from the document model coordinate space
 333      * to the coordinate space of the view mapped to it.
 334      *
 335      * @param pos the position to convert &gt;= 0
 336      * @param a the allocated region to render into
 337      * @return the bounding box of the given position
 338      * @exception BadLocationException  if the given position does not
 339      *   represent a valid location in the associated document
 340      * @see View#modelToView
 341      */
 342     public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
 343         // line coordinates
 344         Document doc = getDocument();
 345         Element map = getElement();


< prev index next >