Line 22... |
Line 22... |
22 |
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ByteArrayProducer;
|
22 |
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ByteArrayProducer;
|
23 |
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ImageProducer;
|
23 |
import org.openconcerto.openoffice.spreadsheet.BytesProducer.ImageProducer;
|
24 |
import org.openconcerto.openoffice.spreadsheet.CellStyle.StyleTableCellProperties;
|
24 |
import org.openconcerto.openoffice.spreadsheet.CellStyle.StyleTableCellProperties;
|
25 |
import org.openconcerto.openoffice.style.data.BooleanStyle;
|
25 |
import org.openconcerto.openoffice.style.data.BooleanStyle;
|
26 |
import org.openconcerto.openoffice.style.data.DataStyle;
|
26 |
import org.openconcerto.openoffice.style.data.DataStyle;
|
27 |
import org.openconcerto.openoffice.style.data.DateStyle;
|
- |
|
28 |
import org.openconcerto.utils.FileUtils;
|
27 |
import org.openconcerto.utils.FileUtils;
|
29 |
import org.openconcerto.utils.TimeUtils;
|
28 |
import org.openconcerto.utils.TimeUtils;
|
30 |
import org.openconcerto.utils.TimeUtils.DurationNullsChanger;
|
29 |
import org.openconcerto.utils.TimeUtils.DurationNullsChanger;
|
31 |
import org.openconcerto.utils.Tuple2;
|
30 |
import org.openconcerto.utils.Tuple2;
|
32 |
import org.openconcerto.utils.Tuple3;
|
31 |
import org.openconcerto.utils.Tuple3;
|
Line 61... |
Line 60... |
61 |
public class MutableCell<D extends ODDocument> extends Cell<D> {
|
60 |
public class MutableCell<D extends ODDocument> extends Cell<D> {
|
62 |
|
61 |
|
63 |
static private final DateFormat TextPDateFormat = DateFormat.getDateInstance();
|
62 |
static private final DateFormat TextPDateFormat = DateFormat.getDateInstance();
|
64 |
static private final DateFormat TextPTimeFormat = DateFormat.getTimeInstance();
|
63 |
static private final DateFormat TextPTimeFormat = DateFormat.getTimeInstance();
|
65 |
static private final NumberFormat TextPMinuteSecondFormat = new DecimalFormat("00.###");
|
64 |
static private final NumberFormat TextPMinuteSecondFormat = new DecimalFormat("00.###");
|
66 |
static private final NumberFormat TextPFloatFormat = DecimalFormat.getNumberInstance();
|
- |
|
67 |
static private final NumberFormat TextPPercentFormat = DecimalFormat.getPercentInstance();
|
- |
|
68 |
static private final NumberFormat TextPCurrencyFormat = DecimalFormat.getCurrencyInstance();
|
- |
|
69 |
|
- |
|
70 |
static public String formatNumber(Number n, final CellStyle defaultStyle) {
|
- |
|
71 |
return formatNumber(TextPFloatFormat, n, defaultStyle);
|
- |
|
72 |
}
|
- |
|
73 |
|
- |
|
74 |
static public String formatPercent(Number n, final CellStyle defaultStyle) {
|
- |
|
75 |
return formatNumber(TextPPercentFormat, n, defaultStyle);
|
- |
|
76 |
}
|
- |
|
77 |
|
- |
|
78 |
static public String formatCurrency(Number n, final CellStyle defaultStyle) {
|
- |
|
79 |
return formatNumber(TextPCurrencyFormat, n, defaultStyle);
|
- |
|
80 |
}
|
- |
|
81 |
|
- |
|
82 |
static private String formatNumber(NumberFormat format, Number n, final CellStyle defaultStyle) {
|
- |
|
83 |
synchronized (format) {
|
- |
|
84 |
final int decPlaces = DataStyle.getDecimalPlaces(defaultStyle);
|
- |
|
85 |
format.setMinimumFractionDigits(0);
|
- |
|
86 |
format.setMaximumFractionDigits(decPlaces);
|
- |
|
87 |
return format.format(n);
|
- |
|
88 |
}
|
- |
|
89 |
}
|
- |
|
90 |
|
65 |
|
91 |
static private boolean LO_MODE = true;
|
66 |
static private boolean LO_MODE = true;
|
92 |
// no date part, all time part to zero
|
67 |
// no date part, all time part to zero
|
93 |
static private final DurationNullsChanger TIME_NULLS = new TimeUtils.DurationNullsBuilder(TimeUtils.EmptyFieldPolicy.SET_TO_ZERO).setToNull(TimeUtils.getDateFields()).build();
|
68 |
static private final DurationNullsChanger TIME_NULLS = new TimeUtils.DurationNullsBuilder(TimeUtils.EmptyFieldPolicy.SET_TO_ZERO).setToNull(TimeUtils.getDateFields()).build();
|
94 |
|
69 |
|
Line 239... |
Line 214... |
239 |
if (formatted.get0() != null) {
|
214 |
if (formatted.get0() != null) {
|
240 |
text = formatted.get0();
|
215 |
text = formatted.get0();
|
241 |
} else {
|
216 |
} else {
|
242 |
// either there were no format or formatting failed
|
217 |
// either there were no format or formatting failed
|
243 |
if (vt == ODValueType.FLOAT) {
|
218 |
if (vt == ODValueType.FLOAT) {
|
244 |
text = formatNumber((Number) obj, getDefaultStyle());
|
219 |
text = getODDocument().getPackage().formatNumber((Number) obj, getDefaultStyle());
|
245 |
} else if (vt == ODValueType.PERCENTAGE) {
|
220 |
} else if (vt == ODValueType.PERCENTAGE) {
|
246 |
text = formatPercent((Number) obj, getDefaultStyle());
|
221 |
text = getODDocument().getPackage().formatPercent((Number) obj, getDefaultStyle());
|
247 |
} else if (vt == ODValueType.CURRENCY) {
|
222 |
} else if (vt == ODValueType.CURRENCY) {
|
248 |
text = formatCurrency((Number) obj, getDefaultStyle());
|
223 |
text = getODDocument().getPackage().formatCurrency((Number) obj, getDefaultStyle());
|
249 |
} else if (vt == ODValueType.DATE) {
|
224 |
} else if (vt == ODValueType.DATE) {
|
250 |
final Date d;
|
225 |
final Date d;
|
251 |
if (obj instanceof Calendar) {
|
226 |
if (obj instanceof Calendar) {
|
252 |
d = ((Calendar) obj).getTime();
|
227 |
d = ((Calendar) obj).getTime();
|
253 |
} else {
|
228 |
} else {
|
Line 260... |
Line 235... |
260 |
text = "" + normalized.getHours() + ':' + TextPMinuteSecondFormat.format(normalized.getMinutes()) + ':' + TextPMinuteSecondFormat.format(TimeUtils.getSeconds(normalized));
|
235 |
text = "" + normalized.getHours() + ':' + TextPMinuteSecondFormat.format(normalized.getMinutes()) + ':' + TextPMinuteSecondFormat.format(TimeUtils.getSeconds(normalized));
|
261 |
} else {
|
236 |
} else {
|
262 |
text = TextPTimeFormat.format(((Calendar) obj).getTime());
|
237 |
text = TextPTimeFormat.format(((Calendar) obj).getTime());
|
263 |
}
|
238 |
}
|
264 |
} else if (vt == ODValueType.BOOLEAN) {
|
239 |
} else if (vt == ODValueType.BOOLEAN) {
|
265 |
// LO do not use the the document language but the system language
|
- |
|
266 |
// http://help.libreoffice.org/Common/Selecting_the_Document_Language
|
- |
|
267 |
Locale l = Locale.getDefault();
|
240 |
Locale l = null;
|
268 |
// except of course if there's a data style
|
- |
|
269 |
final CellStyle s = getStyle();
|
241 |
final CellStyle s = getStyle();
|
270 |
if (s != null) {
|
242 |
if (s != null) {
|
271 |
final DataStyle ds = s.getDataStyle();
|
243 |
final DataStyle ds = s.getDataStyle();
|
272 |
if (ds != null)
|
244 |
if (ds != null)
|
273 |
l = DateStyle.getLocale(ds.getElement());
|
245 |
l = ds.getLocale();
|
274 |
}
|
246 |
}
|
- |
|
247 |
if (l == null)
|
- |
|
248 |
l = getODDocument().getPackage().getLocale();
|
275 |
text = BooleanStyle.toString((Boolean) obj, l, lenient);
|
249 |
text = BooleanStyle.toString((Boolean) obj, l, lenient);
|
276 |
} else if (vt == ODValueType.STRING) {
|
250 |
} else if (vt == ODValueType.STRING) {
|
277 |
text = obj.toString();
|
251 |
text = obj.toString();
|
278 |
} else {
|
252 |
} else {
|
279 |
throw new IllegalStateException(vt + " unknown");
|
253 |
throw new IllegalStateException(vt + " unknown");
|