001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.print;
017:
018: public abstract class cUnit implements Cloneable {
019:
020: private double units = 0.0;
021:
022: public cUnit() {
023: }
024:
025: public double getUnits() {
026: return units;
027: }
028:
029: public void setUnits(double units) {
030: this .units = units;
031: }
032:
033: public abstract void setPoints(double p);
034:
035: public abstract double getPoints();
036:
037: public cUnit add(double units) {
038: cUnit temp = (cUnit) clone();
039: temp.setUnits(this .getUnits() + units);
040:
041: return temp;
042: }
043:
044: public cUnit add(cUnit units) {
045: cUnit temp = (cUnit) clone();
046: temp.setPoints(this .getPoints() + units.getPoints());
047:
048: return temp;
049: }
050:
051: public void addI(cUnit units) {
052: setPoints(getPoints() + units.getPoints());
053: }
054:
055: public cUnit sub(double units) {
056: cUnit temp = (cUnit) clone();
057: temp.setUnits(this .getUnits() - units);
058:
059: return temp;
060: }
061:
062: public cUnit sub(cUnit units) {
063: cUnit temp = (cUnit) clone();
064: temp.setPoints(this .getPoints() - units.getPoints());
065:
066: return temp;
067: }
068:
069: public void subI(cUnit units) {
070: setPoints(getPoints() - units.getPoints());
071: }
072:
073: public cUnit mul(double units) {
074: cUnit temp = (cUnit) clone();
075: temp.setUnits(this .getUnits() * units);
076:
077: return temp;
078: }
079:
080: public cUnit mul(cUnit units) {
081: cUnit temp = (cUnit) clone();
082: temp.setPoints(this .getPoints() * units.getPoints());
083:
084: return temp;
085: }
086:
087: public void mulI(cUnit units) {
088: setPoints(getPoints() * units.getPoints());
089: }
090:
091: public cUnit div(double units) {
092: cUnit temp = (cUnit) clone();
093: temp.setUnits(this .getUnits() / units);
094:
095: return temp;
096: }
097:
098: public cUnit div(cUnit units) {
099: cUnit temp = (cUnit) clone();
100: temp.setPoints(this .getPoints() / units.getPoints());
101:
102: return temp;
103: }
104:
105: public void divI(cUnit units) {
106: setPoints(getPoints() / units.getPoints());
107: }
108:
109: public boolean equals(Object unit) {
110: if (unit instanceof cUnit) {
111: return (getPoints() == ((cUnit) unit).getPoints());
112: }
113:
114: return false;
115: }
116:
117: public Object clone() {
118: cUnit clone;
119:
120: try {
121: clone = (cUnit) super .clone();
122: } catch (Exception e) {
123: System.err.println(e);
124:
125: return null;
126: }
127:
128: clone.setUnits(getPoints());
129:
130: return clone;
131: }
132: }
|