source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rtextarea/BufferedImageBackgroundPainterStrategy.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 2.8 KB
Line 
1/*
2 * 01/22/2005
3 *
4 * BufferedImageBackgroundPainterStrategy.java - Renders an RTextAreaBase's
5 * background as an image using a BufferedImage.
6 *
7 * This library is distributed under a modified BSD license. See the included
8 * RSyntaxTextArea.License.txt file for details.
9 */
10package org.fife.ui.rtextarea;
11
12import java.awt.Graphics;
13import java.awt.Image;
14
15
16/**
17 * A strategy for painting the background of an <code>RTextAreaBase</code>
18 * as an image. The image is always stretched to completely fill the
19 * <code>RTextAreaBase</code>.<p>
20 *
21 * A <code>java.awt.image.BufferedImage</code> is used for rendering;
22 * theoretically, for performance you should use
23 * <code>java.awt.image.VolatileImage</code>; see
24 * <code>org.fife.ui.RTextArea.VolatileImageBackgroundPainterStrategy</code>
25 * for this.<p>
26 *
27 * You can set the scaling hint used when stretching/skewing the image
28 * to fit in the <code>RTextAreaBase</code>'s background via the
29 * <code>setScalingHint</code> method, but keep in mind the more
30 * accurate the scaling hint, the less responsive your application will
31 * be when stretching the window (as that's the only time the image's
32 * size is recalculated).
33 *
34 * @author Robert Futrell
35 * @version 0.1
36 * @see org.fife.ui.rtextarea.ImageBackgroundPainterStrategy
37 * @see org.fife.ui.rtextarea.VolatileImageBackgroundPainterStrategy
38 */
39public class BufferedImageBackgroundPainterStrategy
40 extends ImageBackgroundPainterStrategy {
41
42 private Image bgImage;
43
44
45 /**
46 * Constructor.
47 *
48 * @param ta The text area whose background we'll be painting.
49 */
50 public BufferedImageBackgroundPainterStrategy(RTextAreaBase ta) {
51 super(ta);
52 }
53
54
55 /**
56 * Paints the image at the specified location. This method assumes
57 * scaling has already been done, and simply paints the background
58 * image "as-is."
59 *
60 * @param g The graphics context.
61 * @param x The x-coordinate at which to paint.
62 * @param y The y-coordinate at which to paint.
63 */
64 protected void paintImage(Graphics g, int x, int y) {
65 if (bgImage != null)
66 g.drawImage(bgImage, x,y, null);
67 }
68
69
70 /**
71 * Rescales the displayed image to be the specified size.
72 *
73 * @param width The new width of the image.
74 * @param height The new height of the image.
75 * @param hint The scaling hint to use.
76 */
77 protected void rescaleImage(int width, int height, int hint) {
78 Image master = getMasterImage();
79 if (master!=null) {
80 bgImage = master.getScaledInstance(width,height, hint);
81 tracker.addImage(bgImage, 1);
82 try {
83 tracker.waitForID(1);
84 } catch (InterruptedException e) {
85 e.printStackTrace();
86 bgImage = null;
87 return;
88 } finally {
89 tracker.removeImage(bgImage, 1);
90 }
91 }
92 else {
93 bgImage = null;
94 }
95 }
96
97
98}
Note: See TracBrowser for help on using the repository browser.