kerry
5 years ago
13 changed files with 280 additions and 97 deletions
@ -0,0 +1,21 @@ |
|||||||
|
package com.fr.design.unit; |
||||||
|
|
||||||
|
import com.fr.stable.fun.mark.Mutable; |
||||||
|
import com.fr.stable.unit.UNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public interface ReportLengthUNIT extends Mutable { |
||||||
|
String MARK_STRING = "ReportLengthUNIT"; |
||||||
|
|
||||||
|
int CURRENT_LEVEL = 1; |
||||||
|
|
||||||
|
String unitText(); |
||||||
|
|
||||||
|
int unitType(); |
||||||
|
|
||||||
|
float unit2Value4Scale(UNIT value); |
||||||
|
|
||||||
|
UNIT float2UNIT(float value); |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.design.unit; |
||||||
|
|
||||||
|
import com.fr.stable.fun.mark.Immutable; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public interface ReportLengthUnitProcessor extends Immutable { |
||||||
|
String MARK_STRING = "ReportLengthUnitProcessor"; |
||||||
|
int CURRENT_LEVEL = 1; |
||||||
|
|
||||||
|
ReportLengthUNIT getReportLengthUNIT(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
package com.fr.design.unit; |
||||||
|
|
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.unit.impl.CMReportLengthUNIT; |
||||||
|
import com.fr.design.unit.impl.INCHReportLengthUNIT; |
||||||
|
import com.fr.design.unit.impl.MMReportLengthUNIT; |
||||||
|
import com.fr.design.unit.impl.PTReportLengthUNIT; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public class UnitConvertUtil { |
||||||
|
private static List<ReportLengthUNIT> lengthUNITList = new ArrayList<ReportLengthUNIT>(); |
||||||
|
|
||||||
|
static { |
||||||
|
lengthUNITList.add(new CMReportLengthUNIT()); |
||||||
|
lengthUNITList.add(new INCHReportLengthUNIT()); |
||||||
|
lengthUNITList.add(new PTReportLengthUNIT()); |
||||||
|
lengthUNITList.add(new MMReportLengthUNIT()); |
||||||
|
} |
||||||
|
|
||||||
|
private UnitConvertUtil() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static ReportLengthUNIT parseLengthUNIT(int unitType) { |
||||||
|
ReportLengthUnitProcessor lengthUnitProcessor = ExtraDesignClassManager.getInstance().getSingle(ReportLengthUnitProcessor.MARK_STRING); |
||||||
|
if (lengthUnitProcessor != null) { |
||||||
|
return lengthUnitProcessor.getReportLengthUNIT(); |
||||||
|
} |
||||||
|
for (ReportLengthUNIT lengthUNIT : lengthUNITList) { |
||||||
|
if (unitType == lengthUNIT.unitType()) { |
||||||
|
return lengthUNIT; |
||||||
|
} |
||||||
|
} |
||||||
|
return new MMReportLengthUNIT(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
import com.fr.design.unit.ReportLengthUnitProcessor; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public abstract class AbstracReportLengthUnitProcessor implements ReportLengthUnitProcessor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int layerIndex() { |
||||||
|
return DEFAULT_LAYER_INDEX; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.design.unit.ReportLengthUNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public abstract class AbstractReportLengthUNIT implements ReportLengthUNIT { |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String mark4Provider() { |
||||||
|
return getClass().getName(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
import com.fr.design.unit.impl.AbstractReportLengthUNIT; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.unit.CM; |
||||||
|
import com.fr.stable.unit.UNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public class CMReportLengthUNIT extends AbstractReportLengthUNIT { |
||||||
|
@Override |
||||||
|
public String unitText() { |
||||||
|
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Unit_CM"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int unitType() { |
||||||
|
return Constants.UNIT_CM; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public float unit2Value4Scale(UNIT value) { |
||||||
|
return value.toCMValue4Scale2(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UNIT float2UNIT(float value) { |
||||||
|
return new CM(value); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
import com.fr.design.unit.impl.AbstractReportLengthUNIT; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.unit.INCH; |
||||||
|
import com.fr.stable.unit.UNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public class INCHReportLengthUNIT extends AbstractReportLengthUNIT { |
||||||
|
@Override |
||||||
|
public String unitText() { |
||||||
|
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Unit_INCH"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int unitType() { |
||||||
|
return Constants.UNIT_INCH; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public float unit2Value4Scale(UNIT value) { |
||||||
|
return value.toINCHValue4Scale3(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UNIT float2UNIT(float value) { |
||||||
|
return new INCH(value); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
import com.fr.design.unit.impl.AbstractReportLengthUNIT; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.unit.MM; |
||||||
|
import com.fr.stable.unit.UNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public class MMReportLengthUNIT extends AbstractReportLengthUNIT { |
||||||
|
@Override |
||||||
|
public String unitText() { |
||||||
|
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Unit_MM"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int unitType() { |
||||||
|
return Constants.UNIT_MM; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public float unit2Value4Scale(UNIT value) { |
||||||
|
return value.toMMValue4Scale2(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UNIT float2UNIT(float value) { |
||||||
|
return new MM(value); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.unit.impl; |
||||||
|
|
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.unit.PT; |
||||||
|
import com.fr.stable.unit.UNIT; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-04-09 |
||||||
|
*/ |
||||||
|
public class PTReportLengthUNIT extends AbstractReportLengthUNIT { |
||||||
|
@Override |
||||||
|
public String unitText() { |
||||||
|
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Unit_PT_Duplicate"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int unitType() { |
||||||
|
return Constants.UNIT_PT; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public float unit2Value4Scale(UNIT value) { |
||||||
|
return value.toPTValue4Scale2(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UNIT float2UNIT(float value) { |
||||||
|
return new PT(value); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue