summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/Paintable.java
blob: d5528495c2972269a3271252a71ba29e83c80144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.vaadin.terminal;

import java.io.Serializable;
import java.util.EventObject;

/**
 * Interface implemented by all classes that can be painted. Classes
 * implementing this interface know how to output themselves to a UIDL stream
 * and that way describing to the terminal how it should be displayed in the UI.
 * 
 * @author IT Mill Ltd.
 * @version
 * @VERSION@
 * @since 3.0
 */
public interface Paintable extends java.util.EventListener, Serializable {

    /**
     * <p>
     * Paints the Paintable into a UIDL stream. This method creates the UIDL
     * sequence describing it and outputs it to the given UIDL stream.
     * </p>
     * 
     * <p>
     * It is called when the contents of the component should be painted in
     * response to the component first being shown or having been altered so
     * that its visual representation is changed.
     * </p>
     * 
     * @param target
     *            the target UIDL stream where the component should paint itself
     *            to.
     * @throws PaintException
     *             if the paint operation failed.
     */
    public void paint(PaintTarget target) throws PaintException;

    /**
     * Requests that the paintable should be repainted as soon as possible.
     */
    public void requestRepaint();

    /**
     * Adds an unique id for component that get's transferred to terminal for
     * testing purposes. Keeping identifiers unique throughout the Application
     * instance is on programmers responsibility.
     * <p>
     * Note, that with the current terminal implementation the identifier cannot
     * be changed while the component is visible. This means that the identifier
     * should be set before the component is painted for the first time and kept
     * the same while visible in the client.
     * 
     * @param id
     *            A short (< 20 chars) alphanumeric id
     */
    public void setDebugId(String id);

    /**
     * Get's currently set debug identifier
     * 
     * @return current debug id, null if not set
     */
    public String getDebugId();

    /**
     * Repaint request event is thrown when the paintable needs to be repainted.
     * This is typically done when the <code>paint</code> method would return
     * dissimilar UIDL from the previous call of the method.
     */
    @SuppressWarnings("serial")
    public class RepaintRequestEvent extends EventObject {

        /**
         * Constructs a new event.
         * 
         * @param source
         *            the paintable needing repaint.
         */
        public RepaintRequestEvent(Paintable source) {
            super(source);
        }

        /**
         * Gets the paintable needing repainting.
         * 
         * @return Paintable for which the <code>paint</code> method will return
         *         dissimilar UIDL from the previous call of the method.
         */
        public Paintable getPaintable() {
            return (Paintable) getSource();
        }
    }

    /**
     * Listens repaint requests. The <code>repaintRequested</code> method is
     * called when the paintable needs to be repainted. This is typically done
     * when the <code>paint</code> method would return dissimilar UIDL from the
     * previous call of the method.
     */
    public interface RepaintRequestListener extends Serializable {

        /**
         * Receives repaint request events.
         * 
         * @param event
         *            the repaint request event specifying the paintable source.
         */
        public void repaintRequested(RepaintRequestEvent event);
    }

    /**
     * Adds repaint request listener. In order to assure that no repaint
     * requests are missed, the new repaint listener should paint the paintable
     * right after adding itself as listener.
     * 
     * @param listener
     *            the listener to be added.
     */
    public void addListener(RepaintRequestListener listener);

    /**
     * Removes repaint request listener.
     * 
     * @param listener
     *            the listener to be removed.
     */
    public void removeListener(RepaintRequestListener listener);

    /**
     * Request sending of repaint events on any further visible changes.
     * Normally the paintable only send up to one repaint request for listeners
     * after paint as the paintable as the paintable assumes that the listeners
     * already know about the repaint need. This method resets the assumtion.
     * Paint implicitly does the assumtion reset functionality implemented by
     * this method.
     * <p>
     * This method is normally used only by the terminals to note paintables
     * about implicit repaints (painting the component without actually invoking
     * paint method).
     * </p>
     */
    public void requestRepaintRequests();
}