From 94ae08701bbd7585a0b7e5a92d1975965a503c03 Mon Sep 17 00:00:00 2001 From: Dennis Kao <ulysseskao@gmail.com> Date: Wed, 15 Jan 2014 11:28:52 +0800 Subject: [PATCH] Merge branch 'origin/2.1.x' --- xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java | 197 ++++++++++++++++-------------------------------- 1 files changed, 67 insertions(+), 130 deletions(-) diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java index f82e526..bfcb788 100644 --- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java +++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextNodeElement.java @@ -11,9 +11,9 @@ import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.CoordinateList; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.CoordinateList; import com.ximple.util.DgnUtility; @@ -22,149 +22,120 @@ * * @author Ulysses * @version 0.1 - * @since 2006/5/18 �U�� 04:02:58 + * @since 2006/5/18 �U�� 04:02:58 */ -public class TextNodeElement extends Element implements ComplexElement, GeometryConverter -{ +public class TextNodeElement extends Element implements ComplexElement, GeometryConverter { private static final Logger logger = Logger.getLogger(TextElement.class); private ArrayList<Element> list = new ArrayList<Element>(); - public TextNodeElement(byte[] raw) - { + TextNodeElement(byte[] raw) { super(raw); } - public int size() - { + public int size() { return list.size(); } - public boolean isEmpty() - { + public boolean isEmpty() { return list.isEmpty(); } - public boolean contains(Object o) - { + public boolean contains(Object o) { return list.contains(o); } - public Iterator<Element> iterator() - { + public Iterator<Element> iterator() { return list.iterator(); } - public Object[] toArray() - { + public Object[] toArray() { return list.toArray(); } - public <T> T[] toArray(T[] ts) - { + public <T> T[] toArray(T[] ts) { return list.toArray(ts); } - public boolean add(Element element) - { + public boolean add(Element element) { return list.add(element); } - public boolean remove(Object o) - { + public boolean remove(Object o) { return list.remove(o); } - public boolean containsAll(Collection<?> objects) - { + public boolean containsAll(Collection<?> objects) { return list.containsAll(objects); } - public boolean addAll(Collection<? extends Element> elements) - { + public boolean addAll(Collection<? extends Element> elements) { return list.addAll(elements); } - public boolean addAll(int i, Collection<? extends Element> elements) - { + public boolean addAll(int i, Collection<? extends Element> elements) { return list.addAll(i, elements); } - public boolean removeAll(Collection<?> objects) - { + public boolean removeAll(Collection<?> objects) { return list.removeAll(objects); } - public boolean retainAll(Collection<?> objects) - { + public boolean retainAll(Collection<?> objects) { return list.retainAll(objects); } - public void clear() - { + public void clear() { list.clear(); } - public Element get(int index) - { + public Element get(int index) { return list.get(index); } - public Element set(int index, Element element) - { + public Element set(int index, Element element) { return list.set(index, element); } - public void add(int index, Element element) - { + public void add(int index, Element element) { list.add(index, element); } - public Element remove(int index) - { + public Element remove(int index) { return list.remove(index); } - public int indexOf(Object o) - { + public int indexOf(Object o) { return list.indexOf(o); } - public int lastIndexOf(Object o) - { + public int lastIndexOf(Object o) { return list.lastIndexOf(o); } - public ListIterator<Element> listIterator() - { + public ListIterator<Element> listIterator() { return list.listIterator(); } - public ListIterator<Element> listIterator(int index) - { + public ListIterator<Element> listIterator(int index) { return list.listIterator(index); } - public List<Element> subList(int fromIndex, int toIndex) - { + public List<Element> subList(int fromIndex, int toIndex) { return list.subList(fromIndex, toIndex); } - public Element[] toArray(Element[] a) - { + public Element[] toArray(Element[] a) { return list.toArray(a); } - public String[] getTextArray() - { + public String[] getTextArray() { ArrayList<String> list = new ArrayList<String>(); - for (ListIterator it = listIterator(); it.hasNext();) - { + for (ListIterator it = listIterator(); it.hasNext();) { Element element = (Element) it.next(); - if (element instanceof TextElement) - { + if (element instanceof TextElement) { list.add(((TextElement) element).getText()); } } @@ -172,8 +143,7 @@ return list.toArray(new String[list.size()]); } - public Geometry toGeometry(GeometryFactory factory) - { + public Geometry toGeometry(GeometryFactory factory) { /* * CoordinateList coords = new CoordinateList(); * for (ListIterator it = listIterator(); it.hasNext(); ) @@ -190,104 +160,85 @@ // return factory.createMultiPoint(coords.toCoordinateArray()); } - public Geometry toAnchorGeometry(GeometryFactory factory) - { + public Geometry toAnchorGeometry(GeometryFactory factory) { CoordinateList coords = new CoordinateList(); - for (int i = 0; i < size(); i++) - { + for (int i = 0; i < size(); i++) { TextElement txtElm = (TextElement) get(i); coords.add(txtElm.toAnchorCoordinates(), false); } return factory.createMultiPoint(coords.toCoordinateArray()); } - public int getTotalWords() - { + public int getTotalWords() { return (raw[18] & 0x0000ffff); } - public void setTotalWords(int value) - { + public void setTotalWords(int value) { raw[18] = (short) (value & 0x0000ffff); } - public int getNumString() - { + public int getNumString() { return (raw[19] & 0x0000ffff); } - public void setNumString(int value) - { + public void setNumString(int value) { raw[19] = (short) (value & 0x0000ffff); } - public int getNodeNumber() - { + public int getNodeNumber() { return (raw[20] & 0x0000ffff); } - public void setNodeNumber(int value) - { + public void setNodeNumber(int value) { raw[20] = (short) (value & 0x0000ffff); } - public int getMaxLength() - { + public int getMaxLength() { return (raw[21] & 0x00ff); } - public void setMaxLength(int value) - { + public void setMaxLength(int value) { raw[21] = (short) ((value & 0x00ff) | (raw[21] & 0xff00)); } - public int getMaxUsed() - { + public int getMaxUsed() { return ((raw[21] >> 8) & 0x00ff); } - public void setMaxUsed(int value) - { + public void setMaxUsed(int value) { raw[21] = (short) (((value << 8) & 0xff00) | (raw[21] & 0x00ff)); } - public int getJustification() - { + public int getJustification() { return ((raw[22] >> 8) & 0x00ff); } - public void setJustification(int value) - { + public void setJustification(int value) { raw[22] = (short) (((value << 8) & 0xff00) | (raw[22] & 0x00ff)); } - - public int getFontIndex() - { + + public int getFontIndex() { return (raw[22] & 0x00ff); } - public void setFontIndex(int value) - { + public void setFontIndex(int value) { raw[22] = (short) ((value & 0x00ff) | (raw[22] & 0xff00)); } - public double getLineSpacing() - { + public double getLineSpacing() { int lineSpace; lineSpace = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff); return lineSpace; } - public void setLineSpacing(double value) - { - int temp = (int) (value*1000.0); + public void setLineSpacing(double value) { + int temp = (int) (value * 1000.0); raw[23] = (short) ((temp >> 16) & 0x0000ffff); raw[24] = (short) (temp & 0x0000ffff); } - public double getTextNodeLength() - { + public double getTextNodeLength() { int lengthMult; lengthMult = ((raw[25] << 16) & 0xffff0000); @@ -296,15 +247,13 @@ return DgnUtility.converIntToDouble(lengthMult); } - public void setTextNodeLength(double value) - { + public void setTextNodeLength(double value) { int temp = DgnUtility.converDoubleToInt(value); raw[25] = (short) ((temp >> 16) & 0x0000ffff); raw[26] = (short) (temp & 0x0000ffff); } - public double getTextNodeHeight() - { + public double getTextNodeHeight() { int heightMult; heightMult = ((raw[27] << 16) & 0xffff0000); @@ -313,30 +262,26 @@ return DgnUtility.converIntToDouble(heightMult); } - public void setTextNodeHeight(double value) - { + public void setTextNodeHeight(double value) { int temp = DgnUtility.converDoubleToInt(value); raw[27] = (short) ((temp >> 16) & 0x0000ffff); raw[28] = (short) (temp & 0x0000ffff); } - public double getRotationAngle() - { + public double getRotationAngle() { int rotation = (raw[29] << 16 & 0xffff0000); rotation += raw[30]; return DgnUtility.converIntToRotation(rotation); } - public void setRotationAngle(double value) - { + public void setRotationAngle(double value) { int temp = DgnUtility.converRotatioToInt(value); raw[29] = (short) (temp >> 16 & 0x0000ffff); raw[30] = (short) (temp & 0x0000ffff); } - public Coordinate getOrigin() - { + public Coordinate getOrigin() { int x = ((raw[31] << 16) & 0xffff0000) | (raw[32] & 0x0000ffff); double dx = DgnUtility.converUnitToCoord(x); // return DgnUtility.convertFromDGN(x); @@ -347,8 +292,7 @@ return new Coordinate(dx, dy); } - public void setOrigin(Coordinate value) - { + public void setOrigin(Coordinate value) { int x = DgnUtility.converCoordToUnit(value.x); raw[31] = (short) (x >> 16 & 0x0000ffff); raw[32] = (short) (x & 0x0000ffff); @@ -358,8 +302,7 @@ raw[34] = (short) (y & 0x0000ffff); } - public Object clone() throws CloneNotSupportedException - { + public Object clone() throws CloneNotSupportedException { int pos = this.rawBuffer.position(); this.rawBuffer.position(0); byte[] rawBytes = this.rawBuffer.array(); @@ -368,8 +311,7 @@ this.rawBuffer.position(pos); TextNodeElement other = new TextNodeElement(otherRaw); - for (Object o : this) - { + for (Object o : this) { TextElement textElm = (TextElement) o; other.add((Element) textElm.clone()); } @@ -377,27 +319,22 @@ return other; } - public static class ElementHandler extends Element.ElementHandler - { + public static class ElementHandler extends Element.ElementHandler { private static ElementHandler instance = null; - public ElementHandler() - { + public ElementHandler() { super(ElementType.TEXTNODE); } - public static IElementHandler getInstance() - { - if (instance == null) - { + public static IElementHandler getInstance() { + if (instance == null) { instance = new ElementHandler(); } return instance; } - protected Element createElement(byte[] raw) - { + protected Element createElement(byte[] raw) { return new TextNodeElement(raw); } } -- Gitblit v0.0.0-SNAPSHOT