001: /*
002: Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.objects;
028:
029: import it.stefanochizzolini.clown.files.File;
030: import java.text.DecimalFormat;
031: import java.text.DecimalFormatSymbols;
032:
033: /**
034: PDF real number object.
035: */
036: public class PdfReal extends PdfAtomicObject<Double> implements
037: IPdfNumber {
038: // <class>
039: // <static>
040: // <fields>
041: protected static final DecimalFormat formatter;
042: // </fields>
043:
044: // <constructors>
045: static {
046: DecimalFormatSymbols symbols = new DecimalFormatSymbols();
047: symbols.setDecimalSeparator('.');
048: formatter = new DecimalFormat("0.#####", symbols);
049: }
050:
051: // </constructors>
052:
053: // <interface>
054: // <public>
055: public static String toPdf(double value) {
056: return formatter.format(value);
057: }
058:
059: // </public>
060: // </interface>
061: // </static>
062:
063: // <dynamic>
064: // <constructors>
065: public PdfReal(double value) {
066: setValue(value);
067: }
068:
069: // </constructors>
070:
071: // <iterface>
072: // <public>
073: @Override
074: public Object clone(File context) {
075: // Shallow copy.
076: PdfReal clone = (PdfReal) super .clone();
077:
078: // Deep copy.
079: /* NOTE: No mutable object to be cloned. */
080:
081: return clone;
082: }
083:
084: @Override
085: public String toPdf() {
086: return PdfReal.toPdf(getValue());
087: }
088:
089: // <IPdfNumber>
090: public double getNumberValue() {
091: return getValue();
092: }
093:
094: public void setNumberValue(double value) {
095: setValue(value);
096: }
097:
098: public void translateNumberValue(double value) {
099: setValue(getValue() + value);
100: }
101: // </IPdfNumber>
102: // </public>
103: // </interface>
104: // </class>
105: }
|