~motu-torrent/azureus/upstream-stable

« back to all changes in this revision

Viewing changes to org/gudy/azureus2/ui/swt/components/BufferedTableItemImpl.java

  • Committer: John Dong
  • Date: 2007-10-22 04:54:13 UTC
  • Revision ID: john.dong@gmail.com-20071022045413-3ovb11u82rrcokxx
Commit 3.0.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * File    : BufferedTableItem.java
3
 
 * Created : 24 nov. 2003
4
 
 * By      : Olivier
5
 
 *
6
 
 * Azureus - a Java Bittorrent client
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 2 of the License.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details ( see the LICENSE file ).
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 
 */
21
 
 
22
 
package org.gudy.azureus2.ui.swt.components;
23
 
 
24
 
import org.eclipse.swt.graphics.*;
25
 
import org.eclipse.swt.widgets.Table;
26
 
 
27
 
import org.gudy.azureus2.ui.swt.Utils;
28
 
 
29
 
/**
30
 
 * @author Olivier
31
 
 *
32
 
 */
33
 
public abstract class BufferedTableItemImpl implements BufferedTableItem
34
 
{
35
 
        protected BufferedTableRow row;
36
 
 
37
 
        private int position;
38
 
 
39
 
        private Color ourFGColor = null;
40
 
        
41
 
        private String text = "";
42
 
        
43
 
        private Image icon = null;
44
 
 
45
 
        public BufferedTableItemImpl(BufferedTableRow row, int position) {
46
 
                this.row = row;
47
 
                this.position = position;
48
 
        }
49
 
 
50
 
        public String getText() {
51
 
                if (Utils.SWT32_TABLEPAINT) {
52
 
                        return text;
53
 
                }
54
 
 
55
 
                if (position != -1)
56
 
                        return row.getText(position);
57
 
                return "";
58
 
        }
59
 
 
60
 
        public boolean setText(String text) {
61
 
                if (Utils.SWT32_TABLEPAINT) {
62
 
                        if (this.text.equals(text)) {
63
 
                                return false;
64
 
                        }
65
 
        
66
 
                        this.text = (text == null) ? "" : text;
67
 
                        
68
 
                        Rectangle bounds = getBounds();
69
 
                        if (bounds != null) {
70
 
                                Table table = row.getTable();
71
 
                                Rectangle dirty = table.getClientArea().intersection(bounds);
72
 
                                table.redraw(dirty.x, dirty.y, dirty.width, dirty.height, false);
73
 
                        }
74
 
                        
75
 
                        return true;
76
 
                }
77
 
 
78
 
                if (position != -1)
79
 
                        return row.setText(position, text);
80
 
                return false;
81
 
        }
82
 
 
83
 
        public void setIcon(Image img) {
84
 
                if (position != -1) {
85
 
                        row.setImage(position, img);
86
 
                        icon = img;
87
 
                }
88
 
        }
89
 
 
90
 
        public Image getIcon() {
91
 
                if (position != -1) {
92
 
                        Image image = row.getImage(position);
93
 
                        return (image != null) ? image : icon;
94
 
                }
95
 
 
96
 
                return null;
97
 
        }
98
 
 
99
 
        public void setRowForeground(Color color) {
100
 
                row.setForeground(color);
101
 
        }
102
 
 
103
 
        public boolean setForeground(Color color) {
104
 
                if (position == -1)
105
 
                        return false;
106
 
 
107
 
                boolean ok;
108
 
                if (ourFGColor != null) {
109
 
                        ok = row.setForeground(position, color);
110
 
                        if (ok) {
111
 
                                if (!color.isDisposed())
112
 
                                        color.dispose();
113
 
                                ourFGColor = null;
114
 
                        }
115
 
                } else {
116
 
                        ok = row.setForeground(position, color);
117
 
                }
118
 
                return ok;
119
 
        }
120
 
        
121
 
        public Color getForeground() {
122
 
                if (position == -1)
123
 
                        return null;
124
 
 
125
 
                return row.getForeground(position);
126
 
        }
127
 
 
128
 
        public boolean setForeground(int red, int green, int blue) {
129
 
                if (position == -1)
130
 
                        return false;
131
 
 
132
 
                Color oldColor = row.getForeground(position);
133
 
 
134
 
                RGB newRGB = new RGB(red, green, blue);
135
 
 
136
 
                if (oldColor != null && oldColor.getRGB().equals(newRGB)) {
137
 
                        return false;
138
 
                }
139
 
 
140
 
                Color newColor = new Color(row.getTable().getDisplay(), newRGB);
141
 
                boolean ok = row.setForeground(position, newColor);
142
 
                if (ok) {
143
 
                        if (ourFGColor != null && !ourFGColor.isDisposed())
144
 
                                ourFGColor.dispose();
145
 
                        ourFGColor = newColor;
146
 
                } else {
147
 
                        if (!newColor.isDisposed())
148
 
                                newColor.dispose();
149
 
                }
150
 
 
151
 
                return ok;
152
 
        }
153
 
 
154
 
        public Color getBackground() {
155
 
                return row.getBackground();
156
 
        }
157
 
 
158
 
        public Rectangle getBounds() {
159
 
                if (position != -1)
160
 
                        return row.getBounds(position);
161
 
                return null;
162
 
        }
163
 
 
164
 
        public Table getTable() {
165
 
                return row.getTable();
166
 
        }
167
 
 
168
 
        public void dispose() {
169
 
                if (ourFGColor != null && !ourFGColor.isDisposed())
170
 
                        ourFGColor.dispose();
171
 
        }
172
 
 
173
 
        public boolean isShown() {
174
 
                return true;
175
 
// XXX Bounds check is almost always slower than any changes we
176
 
//     are going to do to the column
177
 
//              if (position < 0) {
178
 
//                      return false;
179
 
//              }
180
 
//              
181
 
//              Rectangle bounds = row.getBounds(position);
182
 
//              if (bounds == null) {
183
 
//                      return false;
184
 
//              }
185
 
//
186
 
//              return row.getTable().getClientArea().intersects(bounds);
187
 
        }
188
 
 
189
 
        public boolean needsPainting() {
190
 
                return false;
191
 
        }
192
 
 
193
 
        public void doPaint(GC gc) {
194
 
        }
195
 
 
196
 
        public void locationChanged() {
197
 
        }
198
 
 
199
 
        public int getPosition() {
200
 
                return position;
201
 
        }
202
 
 
203
 
        public Image getBackgroundImage() {
204
 
                Table table = row.getTable();
205
 
                
206
 
                Rectangle bounds = getBounds();
207
 
                
208
 
                if (bounds.isEmpty()) {
209
 
                        return null;
210
 
                }
211
 
                
212
 
                Image image = new Image(table.getDisplay(), bounds.width, bounds.height);
213
 
                
214
 
                GC gc = new GC(table);
215
 
                gc.copyArea(image, bounds.x, bounds.y);
216
 
                gc.dispose();
217
 
                
218
 
                return image;
219
 
        }
220
 
}
 
1
/*
 
2
 * File    : BufferedTableItem.java
 
3
 * Created : 24 nov. 2003
 
4
 * By      : Olivier
 
5
 *
 
6
 * Azureus - a Java Bittorrent client
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details ( see the LICENSE file ).
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 */
 
21
 
 
22
package org.gudy.azureus2.ui.swt.components;
 
23
 
 
24
import org.eclipse.swt.graphics.*;
 
25
import org.eclipse.swt.widgets.Table;
 
26
 
 
27
import org.gudy.azureus2.ui.swt.Utils;
 
28
 
 
29
/**
 
30
 * @author Olivier
 
31
 *
 
32
 */
 
33
public abstract class BufferedTableItemImpl implements BufferedTableItem
 
34
{
 
35
        protected BufferedTableRow row;
 
36
 
 
37
        private int position;
 
38
 
 
39
        private Color ourFGColor = null;
 
40
        
 
41
        private String text = "";
 
42
        
 
43
        private Image icon = null;
 
44
 
 
45
        public BufferedTableItemImpl(BufferedTableRow row, int position) {
 
46
                this.row = row;
 
47
                this.position = position;
 
48
        }
 
49
 
 
50
        public String getText() {
 
51
                if (Utils.SWT32_TABLEPAINT) {
 
52
                        return text;
 
53
                }
 
54
 
 
55
                if (position != -1)
 
56
                        return row.getText(position);
 
57
                return "";
 
58
        }
 
59
 
 
60
        public boolean setText(String text) {
 
61
                if (Utils.SWT32_TABLEPAINT) {
 
62
                        if (this.text.equals(text)) {
 
63
                                return false;
 
64
                        }
 
65
        
 
66
                        this.text = (text == null) ? "" : text;
 
67
                        
 
68
                        Rectangle bounds = getBounds();
 
69
                        if (bounds != null) {
 
70
                                Table table = row.getTable();
 
71
                                Rectangle dirty = table.getClientArea().intersection(bounds);
 
72
                                table.redraw(dirty.x, dirty.y, dirty.width, dirty.height, false);
 
73
                        }
 
74
                        
 
75
                        return true;
 
76
                }
 
77
 
 
78
                if (position != -1)
 
79
                        return row.setText(position, text);
 
80
                return false;
 
81
        }
 
82
 
 
83
        public void setIcon(Image img) {
 
84
                if (position != -1) {
 
85
                        row.setImage(position, img);
 
86
                        icon = img;
 
87
                }
 
88
        }
 
89
 
 
90
        public Image getIcon() {
 
91
                if (position != -1) {
 
92
                        Image image = row.getImage(position);
 
93
                        return (image != null) ? image : icon;
 
94
                }
 
95
 
 
96
                return null;
 
97
        }
 
98
 
 
99
        public void setRowForeground(Color color) {
 
100
                row.setForeground(color);
 
101
        }
 
102
 
 
103
        public boolean setForeground(Color color) {
 
104
                if (position == -1)
 
105
                        return false;
 
106
 
 
107
                boolean ok;
 
108
                if (ourFGColor != null) {
 
109
                        ok = row.setForeground(position, color);
 
110
                        if (ok) {
 
111
                                if (!color.isDisposed())
 
112
                                        color.dispose();
 
113
                                ourFGColor = null;
 
114
                        }
 
115
                } else {
 
116
                        ok = row.setForeground(position, color);
 
117
                }
 
118
                return ok;
 
119
        }
 
120
        
 
121
        public Color getForeground() {
 
122
                if (position == -1)
 
123
                        return null;
 
124
 
 
125
                return row.getForeground(position);
 
126
        }
 
127
 
 
128
        public boolean setForeground(int red, int green, int blue) {
 
129
                if (position == -1)
 
130
                        return false;
 
131
 
 
132
                Color oldColor = row.getForeground(position);
 
133
 
 
134
                RGB newRGB = new RGB(red, green, blue);
 
135
 
 
136
                if (oldColor != null && oldColor.getRGB().equals(newRGB)) {
 
137
                        return false;
 
138
                }
 
139
 
 
140
                Color newColor = new Color(row.getTable().getDisplay(), newRGB);
 
141
                boolean ok = row.setForeground(position, newColor);
 
142
                if (ok) {
 
143
                        if (ourFGColor != null && !ourFGColor.isDisposed())
 
144
                                ourFGColor.dispose();
 
145
                        ourFGColor = newColor;
 
146
                } else {
 
147
                        if (!newColor.isDisposed())
 
148
                                newColor.dispose();
 
149
                }
 
150
 
 
151
                return ok;
 
152
        }
 
153
 
 
154
        public Color getBackground() {
 
155
                return row.getBackground();
 
156
        }
 
157
 
 
158
        public Rectangle getBounds() {
 
159
                if (position != -1)
 
160
                        return row.getBounds(position);
 
161
                return null;
 
162
        }
 
163
 
 
164
        public Table getTable() {
 
165
                return row.getTable();
 
166
        }
 
167
 
 
168
        public void dispose() {
 
169
                if (ourFGColor != null && !ourFGColor.isDisposed())
 
170
                        ourFGColor.dispose();
 
171
        }
 
172
 
 
173
        public boolean isShown() {
 
174
                return true;
 
175
// XXX Bounds check is almost always slower than any changes we
 
176
//     are going to do to the column
 
177
//              if (position < 0) {
 
178
//                      return false;
 
179
//              }
 
180
//              
 
181
//              Rectangle bounds = row.getBounds(position);
 
182
//              if (bounds == null) {
 
183
//                      return false;
 
184
//              }
 
185
//
 
186
//              return row.getTable().getClientArea().intersects(bounds);
 
187
        }
 
188
 
 
189
        public boolean needsPainting() {
 
190
                return false;
 
191
        }
 
192
 
 
193
        public void doPaint(GC gc) {
 
194
        }
 
195
 
 
196
        public void locationChanged() {
 
197
        }
 
198
 
 
199
        public int getPosition() {
 
200
                return position;
 
201
        }
 
202
 
 
203
        public Image getBackgroundImage() {
 
204
                Table table = row.getTable();
 
205
                
 
206
                Rectangle bounds = getBounds();
 
207
                
 
208
                if (bounds.isEmpty()) {
 
209
                        return null;
 
210
                }
 
211
                
 
212
                Image image = new Image(table.getDisplay(), bounds.width, bounds.height);
 
213
                
 
214
                GC gc = new GC(table);
 
215
                gc.copyArea(image, bounds.x, bounds.y);
 
216
                gc.dispose();
 
217
                
 
218
                return image;
 
219
        }
 
220
 
 
221
  // @see org.gudy.azureus2.ui.swt.components.BufferedTableItem#redraw()
 
222
  public void redraw() {
 
223
  }
 
224
  
 
225
  // @see org.gudy.azureus2.ui.swt.components.BufferedTableItem#getMaxLines()
 
226
  public int getMaxLines() {
 
227
        return 1;
 
228
  }
 
229
}