01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.properties.editors;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.jetbrains.annotations.Nullable;
18: import org.pentaho.reportdesigner.crm.report.model.ElementPadding;
19:
20: import java.text.DecimalFormat;
21: import java.text.ParseException;
22: import java.util.NoSuchElementException;
23: import java.util.StringTokenizer;
24:
25: /**
26: * User: Martin
27: * Date: 21.10.2005
28: * Time: 13:15:53
29: */
30: public class CellEditorJTextFieldWithEllipsisPadding extends
31: CellEditorJTextFieldWithEllipsis<ElementPadding> {
32: @NotNull
33: private static final DecimalFormat decimalFormat = new DecimalFormat(
34: "0.##");
35:
36: public CellEditorJTextFieldWithEllipsisPadding() {
37: }
38:
39: @NotNull
40: public String convertToText(@Nullable
41: ElementPadding obj) {
42: if (obj != null) {
43: return decimalFormat.format(obj.getTop()) + "; "
44: + decimalFormat.format(obj.getBottom()) + "; "
45: + decimalFormat.format(obj.getLeft()) + "; "
46: + decimalFormat.format(obj.getRight());
47: }
48:
49: return "";
50: }
51:
52: @NotNull
53: public ElementPadding convertFromText(@NotNull
54: String text) throws IllegalArgumentException {
55: try {
56: StringTokenizer strTok = new StringTokenizer(text, ";");
57: Number n1 = decimalFormat.parse(strTok.nextToken().trim());
58: Number n2 = decimalFormat.parse(strTok.nextToken().trim());
59: Number n3 = decimalFormat.parse(strTok.nextToken().trim());
60: Number n4 = decimalFormat.parse(strTok.nextToken().trim());
61:
62: return new ElementPadding(n1.doubleValue(), n2
63: .doubleValue(), n3.doubleValue(), n4.doubleValue());
64: } catch (NoSuchElementException e) {
65: throw new IllegalArgumentException(e);
66: } catch (ParseException e) {
67: throw new IllegalArgumentException(e);
68: }
69: }
70:
71: }
|