2
* File : BufferedTableItem.java
3
* Created : 24 nov. 2003
6
* Azureus - a Java Bittorrent client
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.
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 ).
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
22
package org.gudy.azureus2.ui.swt.components;
24
import org.eclipse.swt.graphics.*;
25
import org.eclipse.swt.widgets.Table;
27
import org.gudy.azureus2.ui.swt.Utils;
33
public abstract class BufferedTableItemImpl implements BufferedTableItem
35
protected BufferedTableRow row;
39
private Color ourFGColor = null;
41
private String text = "";
43
private Image icon = null;
45
public BufferedTableItemImpl(BufferedTableRow row, int position) {
47
this.position = position;
50
public String getText() {
51
if (Utils.SWT32_TABLEPAINT) {
56
return row.getText(position);
60
public boolean setText(String text) {
61
if (Utils.SWT32_TABLEPAINT) {
62
if (this.text.equals(text)) {
66
this.text = (text == null) ? "" : text;
68
Rectangle bounds = getBounds();
70
Table table = row.getTable();
71
Rectangle dirty = table.getClientArea().intersection(bounds);
72
table.redraw(dirty.x, dirty.y, dirty.width, dirty.height, false);
79
return row.setText(position, text);
83
public void setIcon(Image img) {
85
row.setImage(position, img);
90
public Image getIcon() {
92
Image image = row.getImage(position);
93
return (image != null) ? image : icon;
99
public void setRowForeground(Color color) {
100
row.setForeground(color);
103
public boolean setForeground(Color color) {
108
if (ourFGColor != null) {
109
ok = row.setForeground(position, color);
111
if (!color.isDisposed())
116
ok = row.setForeground(position, color);
121
public Color getForeground() {
125
return row.getForeground(position);
128
public boolean setForeground(int red, int green, int blue) {
132
Color oldColor = row.getForeground(position);
134
RGB newRGB = new RGB(red, green, blue);
136
if (oldColor != null && oldColor.getRGB().equals(newRGB)) {
140
Color newColor = new Color(row.getTable().getDisplay(), newRGB);
141
boolean ok = row.setForeground(position, newColor);
143
if (ourFGColor != null && !ourFGColor.isDisposed())
144
ourFGColor.dispose();
145
ourFGColor = newColor;
147
if (!newColor.isDisposed())
154
public Color getBackground() {
155
return row.getBackground();
158
public Rectangle getBounds() {
160
return row.getBounds(position);
164
public Table getTable() {
165
return row.getTable();
168
public void dispose() {
169
if (ourFGColor != null && !ourFGColor.isDisposed())
170
ourFGColor.dispose();
173
public boolean isShown() {
175
// XXX Bounds check is almost always slower than any changes we
176
// are going to do to the column
177
// if (position < 0) {
181
// Rectangle bounds = row.getBounds(position);
182
// if (bounds == null) {
186
// return row.getTable().getClientArea().intersects(bounds);
189
public boolean needsPainting() {
193
public void doPaint(GC gc) {
196
public void locationChanged() {
199
public int getPosition() {
203
public Image getBackgroundImage() {
204
Table table = row.getTable();
206
Rectangle bounds = getBounds();
208
if (bounds.isEmpty()) {
212
Image image = new Image(table.getDisplay(), bounds.width, bounds.height);
214
GC gc = new GC(table);
215
gc.copyArea(image, bounds.x, bounds.y);
2
* File : BufferedTableItem.java
3
* Created : 24 nov. 2003
6
* Azureus - a Java Bittorrent client
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.
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 ).
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
22
package org.gudy.azureus2.ui.swt.components;
24
import org.eclipse.swt.graphics.*;
25
import org.eclipse.swt.widgets.Table;
27
import org.gudy.azureus2.ui.swt.Utils;
33
public abstract class BufferedTableItemImpl implements BufferedTableItem
35
protected BufferedTableRow row;
39
private Color ourFGColor = null;
41
private String text = "";
43
private Image icon = null;
45
public BufferedTableItemImpl(BufferedTableRow row, int position) {
47
this.position = position;
50
public String getText() {
51
if (Utils.SWT32_TABLEPAINT) {
56
return row.getText(position);
60
public boolean setText(String text) {
61
if (Utils.SWT32_TABLEPAINT) {
62
if (this.text.equals(text)) {
66
this.text = (text == null) ? "" : text;
68
Rectangle bounds = getBounds();
70
Table table = row.getTable();
71
Rectangle dirty = table.getClientArea().intersection(bounds);
72
table.redraw(dirty.x, dirty.y, dirty.width, dirty.height, false);
79
return row.setText(position, text);
83
public void setIcon(Image img) {
85
row.setImage(position, img);
90
public Image getIcon() {
92
Image image = row.getImage(position);
93
return (image != null) ? image : icon;
99
public void setRowForeground(Color color) {
100
row.setForeground(color);
103
public boolean setForeground(Color color) {
108
if (ourFGColor != null) {
109
ok = row.setForeground(position, color);
111
if (!color.isDisposed())
116
ok = row.setForeground(position, color);
121
public Color getForeground() {
125
return row.getForeground(position);
128
public boolean setForeground(int red, int green, int blue) {
132
Color oldColor = row.getForeground(position);
134
RGB newRGB = new RGB(red, green, blue);
136
if (oldColor != null && oldColor.getRGB().equals(newRGB)) {
140
Color newColor = new Color(row.getTable().getDisplay(), newRGB);
141
boolean ok = row.setForeground(position, newColor);
143
if (ourFGColor != null && !ourFGColor.isDisposed())
144
ourFGColor.dispose();
145
ourFGColor = newColor;
147
if (!newColor.isDisposed())
154
public Color getBackground() {
155
return row.getBackground();
158
public Rectangle getBounds() {
160
return row.getBounds(position);
164
public Table getTable() {
165
return row.getTable();
168
public void dispose() {
169
if (ourFGColor != null && !ourFGColor.isDisposed())
170
ourFGColor.dispose();
173
public boolean isShown() {
175
// XXX Bounds check is almost always slower than any changes we
176
// are going to do to the column
177
// if (position < 0) {
181
// Rectangle bounds = row.getBounds(position);
182
// if (bounds == null) {
186
// return row.getTable().getClientArea().intersects(bounds);
189
public boolean needsPainting() {
193
public void doPaint(GC gc) {
196
public void locationChanged() {
199
public int getPosition() {
203
public Image getBackgroundImage() {
204
Table table = row.getTable();
206
Rectangle bounds = getBounds();
208
if (bounds.isEmpty()) {
212
Image image = new Image(table.getDisplay(), bounds.width, bounds.height);
214
GC gc = new GC(table);
215
gc.copyArea(image, bounds.x, bounds.y);
221
// @see org.gudy.azureus2.ui.swt.components.BufferedTableItem#redraw()
222
public void redraw() {
225
// @see org.gudy.azureus2.ui.swt.components.BufferedTableItem#getMaxLines()
226
public int getMaxLines() {