1 /***
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id$
29 */
30
31 package palmed.edit;
32
33 import javax.microedition.lcdui.Graphics;
34 import javax.microedition.lcdui.Item;
35 import palmed.edit.text.ITextView;
36 import palmed.ui.IComponent;
37
38 /***
39 * This class implements a modification indicator watching a given text.
40 *
41 * @author Mathieu Champlon
42 * @version $Revision$ $Date$
43 */
44 public final class ModificationIndicator implements ITextView, IComponent
45 {
46 /***
47 * The size of the indicator.
48 */
49 private static final int SIZE = 17;
50 /***
51 * The background color.
52 */
53 private static final int BACKGROUND_COLOR = 0xADAAAD;
54 /***
55 * The foreground color.
56 */
57 private static final int FOREGROUND_COLOR = 0x000000;
58 /***
59 * The current modification status.
60 */
61 private boolean hasBeenModified_;
62
63 /***
64 * Create a modification indicator.
65 */
66 public ModificationIndicator()
67 {
68 }
69
70 /***
71 * {@inheritDoc}
72 */
73 public void resize( final int width, final int height )
74 {
75 }
76
77 /***
78 * {@inheritDoc}
79 */
80 public void paint( final Graphics g )
81 {
82 g.setColor( BACKGROUND_COLOR );
83 g.fillRect( 0, 0, SIZE, SIZE );
84 if( hasBeenModified_ )
85 {
86 g.setColor( FOREGROUND_COLOR );
87 final int y = (SIZE + g.getFont().getHeight()) / 2;
88 g.drawChar( '*', SIZE / 2, y, Graphics.BASELINE | Graphics.HCENTER );
89 }
90 }
91
92 /***
93 * {@inheritDoc}
94 */
95 public void update( final int columns, final int lines )
96 {
97 }
98
99 /***
100 * {@inheritDoc}
101 */
102 public void modified( final boolean status )
103 {
104 hasBeenModified_ = status;
105 }
106
107 /***
108 * {@inheritDoc}
109 */
110 public int getLayout()
111 {
112 return Item.LAYOUT_DEFAULT;
113 }
114
115 /***
116 * {@inheritDoc}
117 */
118 public int getWidth()
119 {
120 return SIZE;
121 }
122
123 /***
124 * {@inheritDoc}
125 */
126 public int getHeight()
127 {
128 return SIZE;
129 }
130
131 /***
132 * {@inheritDoc}
133 */
134 public boolean click( final int x, final int y )
135 {
136 return false;
137 }
138
139 /***
140 * {@inheritDoc}
141 */
142 public void drag( final int x, final int y )
143 {
144 }
145
146 /***
147 * {@inheritDoc}
148 */
149 public void unclick( final int x, final int y )
150 {
151 }
152 }