Draws the TextLine offset from the location. @param panel DrawingPanel @param g Graphics
(DrawingPanel panel, Graphics g)
| 95 | * @param g Graphics |
| 96 | */ |
| 97 | @Override |
| 98 | public void draw(DrawingPanel panel, Graphics g) { |
| 99 | if(dirty) { |
| 100 | parseText(g); |
| 101 | dirty = false; |
| 102 | } |
| 103 | int xpix = 0, ypix = 0; |
| 104 | switch(location) { |
| 105 | case CENTER : |
| 106 | xpix = panel.getLeftGutter()+(panel.lastWidth-panel.getLeftGutter()-panel.getRightGutter())/2; |
| 107 | ypix = panel.getTopGutter()+(panel.lastHeight-panel.getTopGutter()-panel.getBottomGutter())/2; |
| 108 | break; |
| 109 | case BOTTOM : |
| 110 | xpix = panel.getLeftGutter()+(panel.lastWidth-panel.leftGutter-panel.rightGutter)/2; |
| 111 | ypix = (panel.getBottomGutter()>height+yoff) ? // is gutter large enough? |
| 112 | panel.getHeight()-panel.bottomGutter+yoff+height : // draw in bottom gutter |
| 113 | panel.getHeight()-panel.bottomGutter-yoff; // draw in display area |
| 114 | break; |
| 115 | case LEFT : |
| 116 | xpix = (panel.leftGutter>height+xoff) ? // is left gutter large enought? |
| 117 | panel.leftGutter-xoff : // draw in left of gutter |
| 118 | panel.leftGutter+xoff+height; // draw in display area |
| 119 | ypix = panel.getTopGutter()+(panel.lastHeight-panel.getTopGutter()-panel.getBottomGutter())/2; |
| 120 | break; |
| 121 | default : |
| 122 | case TOP : |
| 123 | xpix = panel.getLeftGutter()+(panel.lastWidth-panel.leftGutter-panel.rightGutter)/2; |
| 124 | ypix = (panel.getTopGutter()>ascent+yoff) ? // is gutter large enough? |
| 125 | panel.getTopGutter()-yoff-descent-1 : // draw in gutter |
| 126 | panel.getTopGutter()+yoff+ascent+1; // draw in display area |
| 127 | break; |
| 128 | case RIGHT : |
| 129 | xpix = (panel.rightGutter>height+xoff) ? // is right gutter large enought? |
| 130 | panel.lastWidth-panel.leftGutter+xoff+height : // draw in left of gutter |
| 131 | panel.lastWidth-panel.leftGutter-xoff; // draw in display area |
| 132 | ypix = panel.getTopGutter()+(panel.lastHeight-panel.getTopGutter()-panel.getBottomGutter())/2; |
| 133 | break; |
| 134 | case CUSTOM : |
| 135 | xpix = xoff; |
| 136 | ypix = yoff; |
| 137 | break; |
| 138 | } |
| 139 | Graphics2D g2 = (Graphics2D) g.create(); |
| 140 | //Shape currentClip = g2.getClip(); |
| 141 | Rectangle viewRect = panel.getViewRect(); |
| 142 | if(viewRect==null) { |
| 143 | g2.setClip(0, 0, panel.getWidth(), panel.getHeight()); |
| 144 | } else { // set the clip to the entire viewport |
| 145 | g2.setClip(viewRect.x, viewRect.y, viewRect.x+viewRect.width, viewRect.y+viewRect.height); |
| 146 | } |
| 147 | drawText(g, xpix, ypix); |
| 148 | g2.dispose();// BH 2020.02.26//setClip(currentClip); // restore the original clipping |
| 149 | } |
| 150 | |
| 151 | } |
| 152 |
nothing calls this directly
no test coverage detected