OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 83 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.openoffice.spreadsheet;
15
 
20 ilm 16
import org.openconcerto.openoffice.Log;
17 ilm 17
import org.openconcerto.openoffice.ODDocument;
18
import org.openconcerto.openoffice.ODFrame;
19
import org.openconcerto.openoffice.ODValueType;
20 ilm 20
import org.openconcerto.openoffice.OOXML;
25 ilm 21
import org.openconcerto.openoffice.StyleDesc;
73 ilm 22
import org.openconcerto.openoffice.XMLVersion;
17 ilm 23
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ByteArrayProducer;
24
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ImageProducer;
73 ilm 25
import org.openconcerto.openoffice.spreadsheet.CellStyle.StyleTableCellProperties;
61 ilm 26
import org.openconcerto.openoffice.style.data.BooleanStyle;
20 ilm 27
import org.openconcerto.openoffice.style.data.DataStyle;
61 ilm 28
import org.openconcerto.openoffice.style.data.DateStyle;
17 ilm 29
import org.openconcerto.utils.FileUtils;
73 ilm 30
import org.openconcerto.utils.TimeUtils;
80 ilm 31
import org.openconcerto.utils.TimeUtils.DurationNullsChanger;
73 ilm 32
import org.openconcerto.utils.Tuple2;
25 ilm 33
import org.openconcerto.utils.Tuple3;
17 ilm 34
 
35
import java.awt.Color;
36
import java.awt.Image;
21 ilm 37
import java.awt.Point;
17 ilm 38
import java.io.File;
39
import java.io.IOException;
40
import java.text.DateFormat;
41
import java.text.DecimalFormat;
42
import java.text.NumberFormat;
20 ilm 43
import java.util.Calendar;
17 ilm 44
import java.util.Date;
45
import java.util.List;
61 ilm 46
import java.util.Locale;
65 ilm 47
import java.util.logging.Level;
17 ilm 48
 
25 ilm 49
import javax.xml.datatype.Duration;
50
 
17 ilm 51
import org.jdom.Attribute;
52
import org.jdom.Element;
53
import org.jdom.Namespace;
54
import org.jdom.Text;
55
 
56
/**
57
 * A cell whose value can be changed.
58
 *
59
 * @author Sylvain
60
 * @param <D> type of document
61
 */
62
public class MutableCell<D extends ODDocument> extends Cell<D> {
63
 
20 ilm 64
    static private final DateFormat TextPDateFormat = DateFormat.getDateInstance();
65
    static private final DateFormat TextPTimeFormat = DateFormat.getTimeInstance();
25 ilm 66
    static private final NumberFormat TextPMinuteSecondFormat = new DecimalFormat("00.###");
20 ilm 67
    static private final NumberFormat TextPFloatFormat = DecimalFormat.getNumberInstance();
68
    static private final NumberFormat TextPPercentFormat = DecimalFormat.getPercentInstance();
69
    static private final NumberFormat TextPCurrencyFormat = DecimalFormat.getCurrencyInstance();
17 ilm 70
 
20 ilm 71
    static public String formatNumber(Number n, final CellStyle defaultStyle) {
73 ilm 72
        return formatNumber(TextPFloatFormat, n, defaultStyle);
20 ilm 73
    }
74
 
75
    static public String formatPercent(Number n, final CellStyle defaultStyle) {
73 ilm 76
        return formatNumber(TextPPercentFormat, n, defaultStyle);
20 ilm 77
    }
78
 
79
    static public String formatCurrency(Number n, final CellStyle defaultStyle) {
73 ilm 80
        return formatNumber(TextPCurrencyFormat, n, defaultStyle);
20 ilm 81
    }
82
 
73 ilm 83
    static private String formatNumber(NumberFormat format, Number n, final CellStyle defaultStyle) {
20 ilm 84
        synchronized (format) {
85
            final int decPlaces = DataStyle.getDecimalPlaces(defaultStyle);
73 ilm 86
            format.setMinimumFractionDigits(0);
20 ilm 87
            format.setMaximumFractionDigits(decPlaces);
88
            return format.format(n);
89
        }
90
    }
91
 
80 ilm 92
    static private boolean LO_MODE = true;
93
    // no date part, all time part to zero
94
    static private final DurationNullsChanger TIME_NULLS = new TimeUtils.DurationNullsBuilder(TimeUtils.EmptyFieldPolicy.SET_TO_ZERO).setToNull(TimeUtils.getDateFields()).build();
95
 
96
    public static void setTimeValueMode(boolean loMode) {
97
        LO_MODE = loMode;
98
    }
99
 
100
    /**
101
     * Whether {@link #setValue(Object)} formats {@link Duration} using the standard way or using
102
     * the LibreOffice way. LibreOffice does not support years, months and days in cells ; even set
103
     * to 0 (it does in user meta fields). The initial value is <code>true</code>.
104
     *
105
     * @return <code>true</code> if durations should be formatted the LibO way.
106
     */
107
    public static boolean getTimeValueMode() {
108
        return LO_MODE;
109
    }
110
 
25 ilm 111
    MutableCell(Row<D> parent, Element elem, StyleDesc<CellStyle> styleDesc) {
112
        super(parent, elem, styleDesc);
17 ilm 113
    }
114
 
115
    // ask our column to our row so we don't have to update anything when columns are removed/added
116
    public final int getX() {
117
        return this.getRow().getX(this);
118
    }
119
 
120
    public final int getY() {
121
        return this.getRow().getY();
122
    }
123
 
21 ilm 124
    public final Point getPoint() {
125
        return new Point(getX(), getY());
126
    }
127
 
128
    final void setRowsSpanned(final int rowsSpanned) {
129
        if (rowsSpanned <= 1)
130
            this.getElement().removeAttribute("number-rows-spanned", getNS().getTABLE());
131
        else
132
            this.getElement().setAttribute("number-rows-spanned", String.valueOf(rowsSpanned), getNS().getTABLE());
133
    }
134
 
17 ilm 135
    // *** setValue
136
 
137
    private void setValueAttributes(ODValueType type, Object val) {
73 ilm 138
        final Namespace valueNS = getValueNS();
139
        final Attribute valueTypeAttr = this.getElement().getAttribute("value-type", valueNS);
67 ilm 140
        // e.g. DATE
141
        final ODValueType currentType = valueTypeAttr == null ? null : ODValueType.get(valueTypeAttr.getValue());
142
 
17 ilm 143
        if (type == null) {
144
            if (valueTypeAttr != null) {
145
                valueTypeAttr.detach();
146
            }
147
        } else {
73 ilm 148
            if (!type.equals(currentType)) {
149
                if (valueTypeAttr != null) {
150
                    valueTypeAttr.setValue(type.getName());
151
                } else {
152
                    // create an instance of Attribute to avoid a getAttribute() in the simpler
153
                    // setAttribute()
154
                    this.getElement().setAttribute(new Attribute("value-type", type.getName(), valueNS));
155
                }
156
            }
17 ilm 157
        }
73 ilm 158
 
159
        // remove old value attribute (assume Element is valid, otherwise we would need to remove
160
        // all possible value attributes)
161
        if (currentType != null && (!currentType.equals(type) || type == ODValueType.STRING)) {
162
            // e.g. @date-value
163
            this.getElement().removeAttribute(currentType.getValueAttribute(), valueNS);
164
        }
165
        // Like LO, do not generate string-value
166
        if (type != null && type != ODValueType.STRING) {
80 ilm 167
            // LO cells don't support the full syntax of a duration (user meta fields do)
168
            // instead it support only values without nYnMnD
169
            if (type == ODValueType.TIME && getTimeValueMode()) {
170
                final Duration d = val instanceof Duration ? (Duration) val : TimeUtils.timePartToDuration((Calendar) val);
171
                val = TIME_NULLS.apply(getODDocument().getEpoch().normalizeToHours(d));
172
            }
73 ilm 173
            this.getElement().setAttribute(type.getValueAttribute(), type.format(val), valueNS);
174
        }
17 ilm 175
    }
176
 
177
    // ATTN this removes any content associated with this cell be it notes, cell anchored objects,
178
    // etc. This is because it's difficult to tell apart the text content and the rest (e.g. notes),
179
    // for example in Calc office:annotation is a child of table:cell whereas in Writer it's a child
180
    // of text:p.
181
    private void setTextP(String value) {
182
        if (value == null)
183
            this.getElement().removeContent();
184
        else {
185
            // try to reuse the first text:p to keep style
186
            final Element child = this.getElement().getChild("p", getNS().getTEXT());
187
            final Element t = child != null ? child : new Element("p", getNS().getTEXT());
73 ilm 188
            t.setContent(OOXML.get(this.getODDocument().getFormatVersion(), false).encodeWSasList(value));
17 ilm 189
 
190
            this.getElement().setContent(t);
191
        }
192
    }
193
 
194
    private void setValue(ODValueType type, Object value, String textP) {
195
        this.setValueAttributes(type, value);
196
        this.setTextP(textP);
197
    }
198
 
199
    public void clearValue() {
200
        this.setValue(null, null, null);
201
    }
202
 
203
    public void setValue(Object obj) {
25 ilm 204
        this.setValue(obj, true);
205
    }
206
 
207
    public void setValue(Object obj, final boolean allowTypeChange) throws UnsupportedOperationException {
20 ilm 208
        final ODValueType type;
209
        final ODValueType currentType = getValueType();
210
        // try to keep current type, since for example a Number can work with FLOAT, PERCENTAGE
211
        // and CURRENCY
212
        if (currentType != null && currentType.canFormat(obj.getClass())) {
213
            type = currentType;
214
        } else {
57 ilm 215
            final ODValueType tmp = ODValueType.forObject(obj);
216
            // allow any Object
217
            if (allowTypeChange && tmp == null) {
218
                type = ODValueType.STRING;
219
                obj = String.valueOf(obj);
220
            } else {
221
                type = tmp;
222
            }
25 ilm 223
        }
224
        if (type == null) {
20 ilm 225
            throw new IllegalArgumentException("Couldn't infer type of " + obj);
226
        }
25 ilm 227
        this.setValue(obj, type, allowTypeChange, true);
20 ilm 228
    }
229
 
230
    /**
231
     * Change the value of this cell.
232
     *
233
     * @param obj the new cell value.
234
     * @param vt the value type.
25 ilm 235
     * @param allowTypeChange if <code>true</code> <code>obj</code> and <code>vt</code> might be
236
     *        changed to allow the data style to format, e.g. from Boolean.FALSE to 0.
20 ilm 237
     * @param lenient <code>false</code> to throw an exception if we can't format according to the
238
     *        ODF, <code>true</code> to try best-effort.
239
     * @throws UnsupportedOperationException if <code>obj</code> couldn't be formatted.
240
     */
25 ilm 241
    public void setValue(Object obj, ODValueType vt, final boolean allowTypeChange, final boolean lenient) throws UnsupportedOperationException {
20 ilm 242
        final String text;
25 ilm 243
        final Tuple3<String, ODValueType, Object> formatted = format(obj, vt, !allowTypeChange, lenient);
244
        vt = formatted.get1();
245
        obj = formatted.get2();
20 ilm 246
 
25 ilm 247
        if (formatted.get0() != null) {
248
            text = formatted.get0();
20 ilm 249
        } else {
250
            // either there were no format or formatting failed
251
            if (vt == ODValueType.FLOAT) {
252
                text = formatNumber((Number) obj, getDefaultStyle());
253
            } else if (vt == ODValueType.PERCENTAGE) {
254
                text = formatPercent((Number) obj, getDefaultStyle());
255
            } else if (vt == ODValueType.CURRENCY) {
256
                text = formatCurrency((Number) obj, getDefaultStyle());
257
            } else if (vt == ODValueType.DATE) {
25 ilm 258
                final Date d;
259
                if (obj instanceof Calendar) {
260
                    d = ((Calendar) obj).getTime();
261
                } else {
262
                    d = (Date) obj;
263
                }
264
                text = TextPDateFormat.format(d);
20 ilm 265
            } else if (vt == ODValueType.TIME) {
25 ilm 266
                if (obj instanceof Duration) {
267
                    final Duration normalized = getODDocument().getEpoch().normalizeToHours((Duration) obj);
73 ilm 268
                    text = "" + normalized.getHours() + ':' + TextPMinuteSecondFormat.format(normalized.getMinutes()) + ':' + TextPMinuteSecondFormat.format(TimeUtils.getSeconds(normalized));
25 ilm 269
                } else {
270
                    text = TextPTimeFormat.format(((Calendar) obj).getTime());
271
                }
20 ilm 272
            } else if (vt == ODValueType.BOOLEAN) {
61 ilm 273
                // LO do not use the the document language but the system language
274
                // http://help.libreoffice.org/Common/Selecting_the_Document_Language
275
                Locale l = Locale.getDefault();
276
                // except of course if there's a data style
277
                final CellStyle s = getStyle();
278
                if (s != null) {
279
                    final DataStyle ds = s.getDataStyle();
280
                    if (ds != null)
281
                        l = DateStyle.getLocale(ds.getElement());
282
                }
283
                text = BooleanStyle.toString((Boolean) obj, l, lenient);
20 ilm 284
            } else if (vt == ODValueType.STRING) {
285
                text = obj.toString();
19 ilm 286
            } else {
20 ilm 287
                throw new IllegalStateException(vt + " unknown");
19 ilm 288
            }
20 ilm 289
        }
290
        this.setValue(vt, obj, text);
17 ilm 291
    }
292
 
25 ilm 293
    // return null String if no data style exists, or if one exists but we couldn't use it
294
    private Tuple3<String, ODValueType, Object> format(Object obj, ODValueType valueType, boolean onlyCast, boolean lenient) {
295
        String res = null;
20 ilm 296
        try {
25 ilm 297
            final Tuple3<DataStyle, ODValueType, Object> ds = getDataStyleAndValue(obj, valueType, onlyCast);
298
            if (ds != null) {
299
                obj = ds.get2();
300
                valueType = ds.get1();
301
                // act like OO, that is if we set a String to a Date cell, change the value and
302
                // value-type but leave the data-style untouched
303
                if (ds.get0().canFormat(obj.getClass()))
304
                    res = ds.get0().format(obj, getDefaultStyle(), lenient);
305
            }
20 ilm 306
        } catch (UnsupportedOperationException e) {
307
            if (lenient)
65 ilm 308
                Log.get().log(Level.WARNING, "Couldn't format", e);
20 ilm 309
            else
310
                throw e;
311
        }
25 ilm 312
        return Tuple3.create(res, valueType, obj);
20 ilm 313
    }
314
 
315
    public final DataStyle getDataStyle() {
25 ilm 316
        final Tuple3<DataStyle, ODValueType, Object> s = this.getDataStyleAndValue(this.getValue(), this.getValueType(), true);
317
        return s != null ? s.get0() : null;
318
    }
319
 
320
    private final Tuple3<DataStyle, ODValueType, Object> getDataStyleAndValue(Object obj, ODValueType valueType, boolean onlyCast) {
20 ilm 321
        final CellStyle s = this.getStyle();
73 ilm 322
        return s != null ? s.getDataStyle(obj, valueType, onlyCast) : null;
20 ilm 323
    }
324
 
325
    protected final CellStyle getDefaultStyle() {
326
        return this.getRow().getSheet().getDefaultCellStyle();
327
    }
328
 
17 ilm 329
    public void replaceBy(String oldValue, String newValue) {
330
        replaceContentBy(this.getElement(), oldValue, newValue);
331
    }
332
 
333
    private void replaceContentBy(Element l, String oldValue, String newValue) {
20 ilm 334
        final List<?> content = l.getContent();
17 ilm 335
        for (int i = 0; i < content.size(); i++) {
336
            final Object obj = content.get(i);
337
            if (obj instanceof Text) {
338
                // System.err.println(" Text --> " + obj.toString());
339
                final Text t = (Text) obj;
340
                t.setText(t.getText().replaceAll(oldValue, newValue));
341
            } else if (obj instanceof Element) {
342
                replaceContentBy((Element) obj, oldValue, newValue);
343
            }
344
        }
345
    }
346
 
73 ilm 347
    /**
348
     * Set the raw value of the formula attribute.
349
     *
350
     * @param formula the raw value, e.g. "of:sum(A1:A2)".
351
     */
352
    public final void setRawFormula(final String formula) {
353
        // from 19.642 table:formula of OpenDocument-v1.2 : Whenever the initial text of a formula
354
        // has the appearance of an NCName followed by ":", an OpenDocument producer shall provide a
355
        // valid namespace prefix in order to eliminate any ambiguity.
356
        final String nsPrefix = getFormulaNSPrefix(formula).get0();
357
        if (nsPrefix != null && this.getElement().getNamespace(nsPrefix) == null) {
358
            throw new IllegalArgumentException("Unknown namespace prefix : " + nsPrefix);
359
        }
360
        this.setFormulaNoCheck(formula);
361
    }
362
 
363
    private final void setFormulaNoCheck(final String formula) {
364
        this.getElement().setAttribute("formula", formula, getTABLE());
365
    }
366
 
367
    public final void setFormulaAndNamespace(final Tuple2<Namespace, String> formula) {
368
        this.setFormulaAndNamespace(formula.get0(), formula.get1());
369
    }
370
 
371
    public final void setFormula(final String formula) {
372
        this.setFormulaAndNamespace(null, formula);
373
    }
374
 
375
    public final void setFormulaAndNamespace(final Namespace ns, final String formula) {
376
        if (getODDocument().getVersion() == XMLVersion.OOo) {
377
            if (ns != null)
378
                throw new IllegalArgumentException("Namespaces not supported by this version : " + ns);
379
            this.setFormulaNoCheck(formula);
380
        } else if (ns == null) {
381
            final String nsPrefix = getFormulaNSPrefix(formula).get0();
382
            if (nsPrefix != null) {
383
                // eliminate ambiguity
384
                final Namespace defaultNS = getDefaultFormulaNS();
385
                // prevent infinite recursion
386
                if (defaultNS == null)
387
                    throw new IllegalStateException("Cannot resolve ambiguity, formula appears to begin with " + nsPrefix + " and no default namespace found");
388
                this.setFormulaAndNamespace(defaultNS, formula);
389
            } else {
390
                this.setFormulaNoCheck(formula);
391
            }
392
        } else {
393
            final Namespace existingNS = this.getElement().getNamespace(ns.getPrefix());
394
            if (existingNS == null)
395
                this.getElement().getDocument().getRootElement().addNamespaceDeclaration(ns);
396
            else if (!existingNS.equals(ns))
397
                throw new IllegalStateException("Namespace conflict : " + existingNS + " != " + ns);
398
            this.setFormulaNoCheck(ns.getPrefix() + ':' + formula);
399
        }
400
    }
401
 
17 ilm 402
    public final void unmerge() {
403
        // from 8.1.3 Table Cell : table-cell are like covered-table-cell with some extra
404
        // optional attributes so it's safe to rename covered cells into normal ones
405
        final int x = this.getX();
406
        final int y = this.getY();
407
        final int columnsSpanned = getColumnsSpanned();
408
        final int rowsSpanned = getRowsSpanned();
409
        for (int i = 0; i < columnsSpanned; i++) {
410
            for (int j = 0; j < rowsSpanned; j++) {
411
                // don't mind if we change us at 0,0 we're already a table-cell
412
                this.getRow().getSheet().getImmutableCellAt(x + i, y + j).getElement().setName("table-cell");
413
            }
414
        }
415
        this.getElement().removeAttribute("number-columns-spanned", getNS().getTABLE());
416
        this.getElement().removeAttribute("number-rows-spanned", getNS().getTABLE());
417
    }
418
 
419
    /**
420
     * Merge this cell and the following ones. If this cell already spanned multiple columns/rows
421
     * this method un-merge any additional cells.
422
     *
423
     * @param columnsSpanned number of columns to merge.
424
     * @param rowsSpanned number of rows to merge.
425
     */
426
    public final void merge(final int columnsSpanned, final int rowsSpanned) {
427
        final int currentCols = this.getColumnsSpanned();
428
        final int currentRows = this.getRowsSpanned();
429
 
430
        // nothing to do
431
        if (columnsSpanned == currentCols && rowsSpanned == currentRows)
432
            return;
433
 
434
        final int x = this.getX();
435
        final int y = this.getY();
436
 
437
        // check for problems before any modifications
438
        for (int i = 0; i < columnsSpanned; i++) {
439
            for (int j = 0; j < rowsSpanned; j++) {
440
                final boolean coveredByThis = i < currentCols && j < currentRows;
441
                if (!coveredByThis) {
442
                    final int x2 = x + i;
443
                    final int y2 = y + j;
444
                    final Cell<D> immutableCell = this.getRow().getSheet().getImmutableCellAt(x2, y2);
445
                    // check for overlapping range from inside
446
                    if (immutableCell.coversOtherCells())
447
                        throw new IllegalArgumentException("Cell at " + x2 + "," + y2 + " is a merged cell.");
448
                    // and outside
449
                    if (immutableCell.getElement().getName().equals("covered-table-cell"))
450
                        throw new IllegalArgumentException("Cell at " + x2 + "," + y2 + " is already covered.");
451
                }
452
            }
453
        }
454
 
455
        final boolean shrinks = columnsSpanned < currentCols || rowsSpanned < currentRows;
456
        if (shrinks)
457
            this.unmerge();
458
 
459
        // from 8.1.3 Table Cell : table-cell are like covered-table-cell with some extra
460
        // optional attributes so it's safe to rename
461
        for (int i = 0; i < columnsSpanned; i++) {
462
            for (int j = 0; j < rowsSpanned; j++) {
463
                final boolean coveredByThis = i < currentCols && j < currentRows;
464
                // don't cover this,
465
                // if we grow the current covered cells are invalid so don't try to access them
466
                if ((i != 0 || j != 0) && (shrinks || !coveredByThis))
467
                    // MutableCell is needed to break repeated
468
                    this.getRow().getSheet().getCellAt(x + i, y + j).getElement().setName("covered-table-cell");
469
            }
470
        }
471
        this.getElement().setAttribute("number-columns-spanned", columnsSpanned + "", getNS().getTABLE());
472
        this.getElement().setAttribute("number-rows-spanned", rowsSpanned + "", getNS().getTABLE());
473
    }
474
 
475
    @Override
476
    public final String getStyleName() {
477
        return this.getRow().getSheet().getStyleNameAt(this.getX(), this.getY());
478
    }
479
 
73 ilm 480
    public final StyleTableCellProperties getTableCellProperties() {
481
        return this.getRow().getSheet().getTableCellPropertiesAt(this.getX(), this.getY());
482
    }
483
 
17 ilm 484
    public void setImage(final File pic) throws IOException {
485
        this.setImage(pic, false);
486
    }
487
 
488
    public void setImage(final File pic, boolean keepRatio) throws IOException {
489
        this.setImage(pic.getName(), new ByteArrayProducer(FileUtils.readBytes(pic), keepRatio));
490
    }
491
 
492
    public void setImage(final String name, final Image img) throws IOException {
493
        this.setImage(name, img == null ? null : new ImageProducer(img, true));
494
    }
495
 
496
    private void setImage(final String name, final BytesProducer data) {
497
        final Namespace draw = this.getNS().getNS("draw");
498
        final Element frame = this.getElement().getChild("frame", draw);
499
        final Element imageElem = frame == null ? null : frame.getChild("image", draw);
500
 
501
        if (imageElem != null) {
502
            final Attribute refAttr = imageElem.getAttribute("href", this.getNS().getNS("xlink"));
503
            this.getODDocument().getPackage().putFile(refAttr.getValue(), null);
504
 
505
            if (data == null)
506
                frame.detach();
507
            else {
508
                refAttr.setValue("Pictures/" + name + (data.getFormat() != null ? "." + data.getFormat() : ""));
509
                this.getODDocument().getPackage().putFile(refAttr.getValue(), data.getBytes(new ODFrame<D>(getODDocument(), frame)));
510
            }
511
        } else if (data != null)
512
            throw new IllegalStateException("this cell doesn't contain an image: " + this);
513
    }
514
 
515
    public final void setBackgroundColor(final Color color) {
73 ilm 516
        this.getPrivateStyle().getTableCellProperties(this).setBackgroundColor(color);
17 ilm 517
    }
518
}