diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractBrailleTableParser.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractBrailleTableParser.java deleted file mode 100644 index e3dfb08728c75c343aa1ad7cb5667f47eaf9e759..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractBrailleTableParser.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -public interface AbstractBrailleTableParser { - - int getValue(String key); - -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractDocumentBuilder.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractDocumentBuilder.java deleted file mode 100644 index 7f977defeaaa00a00f5953a9dad157f2fca373fd..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractDocumentBuilder.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; -import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; - -/** - * This Class provides an Extension Point for further implementation - * and Protocol Building for Documents that need to be send to the printer. - * The common Interface is the getDocument() and assemble method. - * Its usable for all Braille printers. - * @author Andrey Ruzhanskiy - * @version 28.05.2019 - */ - -public abstract class AbstractDocumentBuilder { - /** - * MemberVariable for the final Document. Readable via getDocument - */ - - protected byte[] mDocument; - - AbstractBrailleTableParser mParser; - - /** - * Complex method for complex construction of an Document for the printer. - * @param data Raw Data to be printed without any escapesequences - * @return Fully build Document as byte[] - */ - public byte[] assemble(final MatrixData data) { - return null; - } - - /** - * Interface for getting the final Document. - * @return Document to be printed - */ - public byte[] getDocument() { - return mDocument; - } - - - /** - * The BrailleTableAlphabet to be used. For example German etc. - */ - protected BrailleAlphabet mAlphabet; - -} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractIndexV4Builder.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractIndexV4Builder.java deleted file mode 100644 index b30da67dea7995788dc133dc851ada5755bcd557..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/AbstractIndexV4Builder.java +++ /dev/null @@ -1,262 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -/** - * Abstract Class for Documents, that need special Escape Sequences for the Index Everest-V4. - * All special Documents (i.e. Floating Dot Area) should implement this class. All information taken - * from the Index PrinterConfiguration Interface Protocol V5_V4 2ß16-05-13. All the Variables with the respective Values have no - * particular order (except mStartTemporaryDoc, which must be at the beginning). All the Variable Names are set to - * final, these are PrinterConfiguration specific Values that should not be changed. - * @author Andrey Ruzhanskiy - * @version 31.05.2019 - */ - -@SuppressWarnings("checkstyle:MagicNumber") -public class AbstractIndexV4Builder extends AbstractDocumentBuilder { - - - - /** - * Standard Byte Sequence to announce StartTemporary Document ([ESC]D). - * Must be always at the beginning. - */ - - protected final byte[] mStartTemporaryDoc = new byte[] {0x1B, 0x44}; - - /** - * Standard Variable Name for Binding Margin (BI). - */ - - protected final byte[] mBindingMarginName = new byte[] {0x42, 0x49}; - - /** - * Standard Value for Everest-V4 A4 Paper Size(4). Possible Values: - * 0 - * to - * 10, - * whereas the number encodes the #charracters to leave empty on the line to the - * left and right. - */ - - protected byte[] mBindingMarginValue = new byte[] {0x34}; - - /** - * Standard Variable Name for Characters per Line (CH). - */ - - protected final byte[] mCharsPerLineName = new byte[] {0x43, 0x48}; - - /** - * Standard Value for Everest-V4 A4 Paper Size(30).If used, there must be also - * a corresponding Binding Margin. Possible Values are: - * 0: may not be usefull - * to - * 48:Absolute maximum due to printer heads total movement and only applicable to the printers - * that can use papers that big. - */ - - protected byte[] mCharsPerLineValue = new byte[] {0x33, 0x30}; - - /** - * Standard Variable Name for PageMode (Duplex) (DP). - */ - - protected final byte[] mPageModeName = new byte[] {0x44, 0x50}; - - /** - * Standard Value for Page Mode (2, Double sided). - * Possible Values are: - * 1 Single sided (normal horizontal printing) - * 2 Double sided (normal horizontal printing) - * 3 Double sided z-folding (normal horizontal printing) - * 5 Single sided z-folding (normal horizontal printing) - * 6 Double sided sideways z-folding (vertical printing) - * 7 Single sided sideways z-folding (vertical printing) - */ - - protected byte[] mPageModeValue = new byte[] {0x32}; - - /** - * Standard Variable Name for Braille Table (BT). - */ - - protected final byte[] mBrailleTableName = new byte[] {0x42, 0x54}; - - /** - * Currently, there is no standard for a Braille Table. - */ - protected byte[] mBrailleTableValue = null; - - /** - * Standard Variable Name for Driver Version (DV). - */ - - protected final byte[] mDriverVersionName = new byte[] {0x44, 0x56}; - - /** - * Standard Value for Driver Version (not used currently TODO). - */ - - protected byte[] mDriverVersion = null; - - /** - * Standard Variable Name for First Line Offset (FO). - */ - - protected final byte[] mFirstLineOffsetName = new byte[] {0x46, 0x4F}; - - /** - * Standard Value for First Line Offset.. - * Possible Values: equal or greater then 0. - * The value is specified in tenths of mm. - * TODO find standard value! - */ - - protected byte[] mFirstLineOffsetValue = null; - - /** - * Standard VariableName for Graphic Dot Distance (GD). - */ - - protected final byte[] mGraphicDotDistanceName = new byte[] {0x47, 0x44}; - - /** - * Standard Value for Graphic Dot Distance. Possible Values are 0, 1, 2. - * 0 = 2.0 mm - * 1 = 2.5 mm - * 2 = 1.6 mm - * Standard is 1 (2.5 mm). - */ - - protected byte[] mGraphicDotDistanceValue = new byte[] {0x31}; - - /** - * Standard VariableName for Lines per Page (LP). - */ - - protected final byte[] mLinesPerPageName = new byte[] {0x4C, 0x50}; - - /** - * Standard Value for Lines per Page (28). If this parameter is set, one must include - * the TM parameter as well. - */ - - protected byte[] mLinesPerPageValue = new byte[] {0x32, 0x38}; - - /** - * Standard VariableName for Line Spacing (LS). - */ - - protected final byte[] mLineSpacingName = new byte[] {0x4C, 0x53}; - - /** - * Standard Value for Line Spacing (GD). This parameter can only be specified in the beginning of a document - * and is ignored if a row has been added to the first page. Line spacing is ignored if DP is set to DP4 and DP8. - * Possible Values are: - * 50: 5.0 mm (single -normal) - * to - * 100: 10.0 mm (double) - */ - - protected byte[] mLineSpacingValue = new byte[] {0x35, 0x30}; - - /** - * Standard VariableName for Multiple Copies (MC). - */ - - protected final byte[] mMultipleCopiesName = new byte[] {0x4D, 0x43}; - - /** - * Standard Value for Multiple Copies (1). Possible Values are: - * 1 - * to - * 10000 - */ - - protected byte[] mMultipleCopiesValue = new byte[] {0x31}; - - /** - * Standard VariableName for Multiple Impact (MI). - */ - - protected final byte[] mMultipleImpactName = new byte[] {0x4D, 0x49}; - - /** - * Standard Value for Multiple Impact (1).To impact the hammers multiple times - * for a Braille row this parameter can be specified Possible Values are: - * 1 - * to - * 3. - */ - - protected byte[] mMultipleImpactValue = new byte[] {0x31}; - - /** - * Standard VariableName for Page Number (PN). - */ - - protected final byte[] mPageNumberName = new byte[] {0x50, 0x4E}; - - /** - * Standard Value for Page Number (0). This parameter needs to be specified before the first row is added - * to the first page. Possible Values are: - * 0: None - * 1: Top (require top margin > 0) - * 2: Top-left (require top margin > 0) - * 3: Top-right (require top margin > 0) - * 4: Bottom (require bottom margin > 0) - * 5: Bottom left (require bottom margin > 0) - * 6: Bottom right (require bottom margin > 0) - */ - - protected byte[] mPageNumberValue = new byte[] {0x30}; - - /** - * Standard VariableName for Braille Cell Size (TD). - */ - - protected final byte[] mBrailleCellSizeName = new byte[] {0x54, 0x44}; - - /** - * Standard Value for Braille Cell Size (0). Possible Values are: - * 0: 2.5 mm - * 1: 2.2 mm - * 2: 3.2 mm - */ - - protected byte[] mBrailleCellSizeValue = new byte[] {0x30}; - - /** - * Standard VariableName for Top Margin (TM). - */ - - protected final byte[] mTopMarginName = new byte[] {0x54, 0x4D}; - - /** - * Standard Value for Top Margin(not researched). The top margin is - * always specified in lines. Possible Values are: - * 0 - * to - * 10 - */ - - protected byte[] mTopMarginValue = null; - - /** - * Separator for values (,). - */ - protected final byte[] mComma = new byte[] {0x2C}; - - - /** - * Colon Character. - */ - protected final byte[] mColon = new byte[] {0x3A}; - - - - /** - * End of Escape Sequence (;). Must be always at the end. - */ - - protected final byte[] mSemicolon = new byte[] {0x3B}; -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/BrailleAlphabet.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/BrailleAlphabet.java deleted file mode 100644 index 9e691ba585664eb94f19c5b42b0bce32c309979e..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/BrailleAlphabet.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -import de.tudresden.inf.mci.brailleplot.printabledata.BrailleCell6; - -import java.util.HashMap; -import java.util.Map; - -/** - * Common Interface for all Braillealphabets. - * @author Andrey Ruzhanskiy - * @version 28.06.2019 - */ - -public abstract class BrailleAlphabet { - public abstract <T> byte[] getValue(BrailleCell6 cell); - public AbstractBrailleTableParser mParser; - public Map<BrailleCell6, byte[]> mAlphabet = new HashMap<>(); -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/DirectPrint.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/DirectPrint.java deleted file mode 100644 index 8a9912d42f920c3e785aa54d31fc69c6989f37fa..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/DirectPrint.java +++ /dev/null @@ -1,110 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -import javax.print.*; -import javax.print.attribute.HashPrintRequestAttributeSet; -import javax.print.attribute.PrintRequestAttributeSet; -import java.io.ByteArrayOutputStream; - - -/** - * This Class provides means to print. But poorly currently. Big TODO. - * Deprecated, currently the PrintDirector should be used. - * @author Andrey Ruzhanskiy, Leonard Kupper - * @version 28.05.2019 - */ - -public class DirectPrint { - - private byte[] mData; - - public DirectPrint() { - - } - - /** - * Method for printing the Document, represented as byte[]. - * @param input The Document, represented as byte[], that will be printed - * - */ - - public void printString(final byte[] input) { - this.mData = input; - DocFlavor flavor = new DocFlavor("application/octet-stream", "[B"); - Doc braille = new SimpleDoc(this.mData, flavor, null); - PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); - /*aset.add(new PageRanges(1, 1)); - aset.add(new Copies(1)); - */ - //new copy paste - PrintService services = - PrintServiceLookup.lookupDefaultPrintService(); - //System.out.println(services.toString()); - DocFlavor[] array = services.getSupportedDocFlavors(); - - - DocPrintJob job = services.createPrintJob(); - try { - job.print(braille, aset); - } catch (PrintException pe) { - System.out.println(pe.getMessage()); - } - - - } - - /** - * Method for printing the byte[] as a byte seperated String. - * @param data Data to be printed on the Command Line - */ - - public void prettyPrintCLI(final byte[] data) { - StringBuilder sb = new StringBuilder(); - for (byte b : data) { - sb.append(String.format("%02X ", b)); - } - System.out.println(sb.toString()); - - } - - /** - * Method for debug and printing purposes. - * Prints and returns a String containing the supported Document Flavors of the default PrinterConfiguration - * @return String with supported Document Flavor - */ - public static String lookUpAcceptedTypes() { - PrintService services = - PrintServiceLookup.lookupDefaultPrintService(); - StringBuilder result = new StringBuilder(); - DocFlavor[] doc = services.getSupportedDocFlavors(); - for (int i = 0; i < services.getSupportedDocFlavors().length; i++) { - result.append(doc[i]); - System.out.println(doc[i]); - } - - return result.toString(); - } - - /** - * For Demo Purposes. - * @param d Values from 1 to 3 whereas: - * 1.. Diagram - * 2.. Circle - * 3.. BetterData - * @return byte[] containing the bytes to be sent to the printer. - */ - @SuppressWarnings("checkstyle:MagicNumber") - public byte[] buildDemo(final int d) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - - byte[] diagramData = ("' l\n' l .i\n' :r *a\n' l .i\n' ::r:: *a\n' l\n' :r\n' l\n' ::r: +::;\n' l l l\n' :r r::l\n' l l l\n' ::r: r::l +:::::;\n' l l l loooool g\n' :r r::l r:::::l\n' l l l loooool\n' ::r: r::l r:::::l g\n' l l l r:::::l\n' :r r::l r:::::l\n' l l l l l .iccce'\n' ::r: r::l r:::::l .i\n' l l l l l .i ; l\n' :r::r::r::r::r::r::r::r::r::r::r\n' b b b b b l\n' ' ' ' ' ' '").getBytes(); - byte[] circleData = ("30.00:60.00\n31.90:59.90\n33.80:59.80\n35.60:59.50\n37.50:59.10\n39.30:58.50\n41.00:57.90\n42.80:57.10\n44.50:56.30\n46.10:55.30\n47.60:54.30\n49.10:53.10\n50.50:51.90\n51.90:50.50\n53.10:49.10\n54.30:47.60\n55.30:46.10\n56.30:44.50\n57.10:42.80\n57.90:41.00\n58.50:39.30\n59.10:37.50\n59.50:35.60\n59.80:33.80\n59.90:31.90\n60.00:30.00\n59.90:28.10\n59.80:26.20\n59.50:24.40\n59.10:22.50\n58.50:20.70\n57.90:19.00\n57.10:17.20\n56.30:15.50\n55.30:13.90\n54.30:12.40\n53.10:10.90\n51.90:9.50\n50.50:8.10\n49.10:6.90\n47.60:5.70\n46.10:4.70\n44.50:3.70\n42.80:2.90\n41.00:2.10\n39.30:1.50\n37.50:0.90\n35.60:0.50\n33.80:0.20\n31.90:0.10\n30.00:0.00\n28.10:0.10\n26.20:0.20\n24.40:0.50\n22.50:0.90\n20.70:1.50\n19.00:2.10\n17.20:2.90\n15.50:3.70\n13.90:4.70\n12.40:5.70\n10.90:6.90\n9.50:8.10\n8.10:9.50\n6.90:10.90\n5.70:12.40\n4.70:13.90\n3.70:15.50\n2.90:17.20\n2.10:19.00\n1.50:20.70\n0.90:22.50\n0.50:24.40\n0.20:26.20\n0.10:28.10\n0.00:30.00\n0.10:31.90\n0.20:33.80\n0.50:35.60\n0.90:37.50\n1.50:39.30\n2.10:41.00\n2.90:42.80\n3.70:44.50\n4.70:46.10\n5.70:47.60\n6.90:49.10\n8.10:50.50\n9.50:51.90\n10.90:53.10\n12.40:54.30\n13.90:55.30\n15.50:56.30\n17.20:57.10\n19.00:57.90\n20.70:58.50\n22.50:59.10\n24.40:59.50\n26.20:59.80\n28.10:59.90").getBytes(); - FloatingDotAreaBuilder fdaExample = new FloatingDotAreaBuilder(circleData, 5, 3, 6, -1); - byte[] betterData = fdaExample.getDocument(); - switch (d) { - case 1: return diagramData; - case 2: return circleData; - case 3: return betterData; - default: return null; - } - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/FloatingDotAreaBuilder.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/FloatingDotAreaBuilder.java deleted file mode 100644 index 3c5c4868a6b21149be8b00621b2662e4a8181763..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/FloatingDotAreaBuilder.java +++ /dev/null @@ -1,123 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - - -import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Class representing the FloatingDotAre-Protocol form the Braille Index Everest V4 for printing - * variable Areas on paper via Coordinates. - * @author Andrey Ruzhanskiy, Leonard Kupper - * @version 29.05.2019 - */ - -public class FloatingDotAreaBuilder extends AbstractIndexV4Builder { - private final byte[] mActivateDotArea = new byte[]{0x1B, 0x46}; - private final byte[] mParameterOrigo = new byte[]{0x4F, 0x52}; - private final byte[] mParameterWidth = new byte[]{0x57, 0x58}; - private final byte[] mParameterHeight = new byte[]{0x48, 0x59}; - private final byte[] mNewLine = new byte[] {0x0A}; - private int mOrigoX = -1; - private int mOrigoY = -1; - private int mWidthX = -1; - private int mHeightY = -1; - - - - - public FloatingDotAreaBuilder() { - - } - /** - * Construct a floating dot area with default origin and size. - * @param data - * A sequence of bytes containing a newline separated line of colon separated values: xxx.xx:yy.yyy - */ - public FloatingDotAreaBuilder(final byte[] data) { - // mDocument = this.assemble(data); - } - - /** - * Construct a floating dot area with specified origin and default size. - * @param data - * A sequence of bytes containing a newline separated line of colon separated values: xxx.xx:yy.yyy - * @param origoX - * Origin x value in centimetres - * @param origoY - * Origin y value in centimetres - */ - public FloatingDotAreaBuilder(final byte[] data, final int origoX, final int origoY) { - this.mOrigoX = origoX; - this.mOrigoY = origoY; - //mDocument = this.assemble(data); - } - - /** - * Construct a floating dot area with specified origin and size. - * @param data - * A sequence of bytes containing a newline separated line of colon separated values: xxx.xx:yy.yyy - * @param origoX - * Origin x value in centimeters - * @param origoY - * Origin y value in centimetres - * @param widthX - * Area width in millimeters - * @param heightY - * Area height in millimeters - */ - public FloatingDotAreaBuilder( - final byte[] data, - final int origoX, - final int origoY, - final int widthX, - final int heightY - ) { - this.mOrigoX = origoX; - this.mOrigoY = origoY; - this.mWidthX = widthX; - this.mHeightY = heightY; - //mDocument = this.assemble(data); - } - - @Override - public byte[] assemble(final MatrixData data) { - - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - try { - - stream.write(mActivateDotArea); - if ((mOrigoX >= 0) && (mOrigoY >= 0)) { - stream.write(mParameterOrigo); - //stream.write("(5.00, 3.00)".getBytes()); - stream.write("5.00:0.00".getBytes()); - } - if (mWidthX >= 0) { - stream.write(mComma); - stream.write(mParameterWidth); - stream.write(Integer.toString(mWidthX).getBytes()); - } - if (mHeightY >= 0) { - stream.write(mComma); - stream.write(mParameterHeight); - stream.write(Integer.toString(mHeightY).getBytes()); - } - stream.write(mSemicolon); - stream.write(mNewLine); - - //stream.write(data); - - //stream.write(parseData(data)); - - stream.write(mSemicolon); - - } catch (IOException e) { - e.getMessage(); - } - mDocument = stream.toByteArray(); - return mDocument; - } - - -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/GraphicPrintBuilder.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/GraphicPrintBuilder.java deleted file mode 100644 index 386b24e3ac3b9ff49b68915da7c3d386456c9b7e..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/GraphicPrintBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - - -/** - * Class representing the Graphic-Mode-Protocol from Braille Index Everest D4. - * @author Andrey Ruzhanskiy - */ -public class GraphicPrintBuilder extends AbstractIndexV4Builder { - - private final byte[] mEnterImageMode = new byte[] {0x1B, 0x09}; - private final byte[] mExitImageMode = new byte[] {0x1B, 0x0A}; - private final byte[] mSetImageType = new byte[] {0x1B, 0x0B}; - - protected GraphicPrintBuilder() { - - } - /** - * Assemble the Document. Hides the Protocol from the user. - * @return - * The ready to print Document, as byte[] - * @param data - */ - @Override - public byte[] assemble(final MatrixData data) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - try { - stream.write(mEnterImageMode); - stream.write(mSetImageType); - - // - - - stream.write(mExitImageMode); - } catch (IOException e) { - e.getMessage(); - } - mDocument = stream.toByteArray(); - return mDocument; - } - -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/JsonParser.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/JsonParser.java deleted file mode 100644 index 429708cbb9f495bd11eec59f7237068a717a9b80..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/JsonParser.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -public class JsonParser implements AbstractBrailleTableParser { - @Override - public int getValue(String key) { - return 0; - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NormalBuilder.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NormalBuilder.java deleted file mode 100644 index 02ac2b862024fde49888edf143432a62b536d26f..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NormalBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -import de.tudresden.inf.mci.brailleplot.configparser.Printer; -import de.tudresden.inf.mci.brailleplot.configparser.ValidProperty; -import de.tudresden.inf.mci.brailleplot.printabledata.BrailleCell6; -import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; - -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.util.Iterator; -import java.util.Properties; - - -/** - * Class representing a normal Document (for example a .txt) to print without - * any Escapesequences. - * @author Andrey Ruzhanskiy - * @version - */ -@SuppressWarnings("checkstyle:MagicNumber") -public class NormalBuilder extends AbstractDocumentBuilder { - - @Override - public byte[] assemble(final MatrixData data) { - if (data == null) { - throw new NullPointerException(); - } - - - Iterator<BrailleCell6<Boolean>> iter = data.getBrailleCell6Iterator(); - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - - mParser = new PropertiesParser(data.getPrinterConfig().getProperty("brailletable").toString()); - - // data.getFormatConfig().getProperty() - int width = data.getColumnCount() / 2; - int i = 0; - while (iter.hasNext()) { - stream.write(mParser.getValue(iter.next().toShortString())); - i++; - if (i == width) { - i = 0; - stream.write(0x0D); - stream.write(0x0A); - } - - - } - - - return stream.toByteArray(); - } - - protected NormalBuilder(){ - - } - -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NotSupportedFileExtension.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NotSupportedFileExtension.java deleted file mode 100644 index 407a4354022cbde654efa5004ac3e51f2ae0d226..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/NotSupportedFileExtension.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -/** - * Exception Class for not recogniced/not supported FIleExtension for brailletables. - * Used in NormalBuilder. - * @author Andrey Ruzhanskiy - * @version 11.07.2019 - */ - -public class NotSupportedFileExtension extends Exception { - - public NotSupportedFileExtension() { } - - public NotSupportedFileExtension(final String message) { - super(message); - } - - public NotSupportedFileExtension(final Throwable cause) { - super(cause); - } - - public NotSupportedFileExtension(final String message, final Throwable cause) { - super(message, cause); - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrintDirector.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrintDirector.java deleted file mode 100644 index e5302a0aa50164d021b598081253875e1794cbb0..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrintDirector.java +++ /dev/null @@ -1,121 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - - -import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; - -import javax.print.*; -import javax.print.attribute.HashPrintRequestAttributeSet; -import javax.print.attribute.PrintRequestAttributeSet; - -/** - * Implements a variation of the GoF Design pattern Builder. This class is used for setting the printerconfiguration and - * for printing. - * @author Andrey Ruzhanskiy - */ -public class PrintDirector { - private AbstractDocumentBuilder mBuilder; - private final PrinterConfiguration mPrinter; - private PrintService mService; - private String mPrinterName; - private DocFlavor mDocflavor; - private AbstractBrailleTableParser mParser; - - - /** - * Constructor for the PrintDirector. Main Class for printing. The class takes care of the complex Protocol to build - * the document for the given configuration. - * @param printer Which printerconfiguration should be used. Normalprinter assumes that no special Features like - * GraphicMode or FloatindDotArea will be used. - */ - - public PrintDirector(final PrinterConfiguration printer) { - this.mPrinter = printer; - - switch (mPrinter) { - case NORMALPRINTER: mBuilder = new NormalBuilder(); - case INDEX_EVEREST_D_V4_GRAPHIC_PRINTER: mBuilder = new GraphicPrintBuilder(); - case INDEX_EVEREST_D_V4_FLOATINGDOT_PRINTER: mBuilder = new FloatingDotAreaBuilder(); - //default: throw new IllegalArgumentException(); - default: mBuilder = new NormalBuilder(); - } - } - - /** - * Static method for checking if the printer, which was given, exists in the Printer System Dialog. - * @param printerName The name of the printer to check. - * @return - */ - - public static boolean printerExists(final String printerName) { - PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); - for (PrintService service: services) { - if (service.getName().equals(printerName)) { - return true; - } - } - return false; - } - - - /** - * Method for setting the Printer. - * @param printerName - * @throws IllegalArgumentException if the printer is not found. - */ - private void setPrinter(final String printerName) { - if (printerExists(printerName)) { - mPrinterName = printerName; - } else { - throw new IllegalArgumentException(); - } - } - - /** - * Stub. - * @param printerName - */ - - @SuppressWarnings("checkstyle:MagicNumber") - public <T> void print(final String printerName, final MatrixData<T> data) { - if (printerName == null || data == null) { - throw new NullPointerException(); - } - setUpDoc(); - setPrinter(printerName); - - byte[] result = mBuilder.assemble(data); - - // Printing the Document - - print(result); - } - - /** - * Method for setting up the DocFlavor fir printing. Currently, not parameterised because the printer can (hopefully - * understand raw bytes with an octet stream. - */ - private void setUpDoc() { - mDocflavor = new DocFlavor("application/octet-stream", "[B"); - } - - /** - * Private Method for sendind the data to the printer. - * @param data - */ - - private void print(final byte[] data) { - if (data == null) { - throw new NullPointerException(); - } - Doc doc = new SimpleDoc(data, mDocflavor, null); - PrintRequestAttributeSet asset = new HashPrintRequestAttributeSet(); - mService = PrintServiceLookup.lookupDefaultPrintService(); - DocPrintJob job = mService.createPrintJob(); - try { - job.print(doc, asset); - } catch (PrintException pe) { - System.out.println(pe.getMessage()); - } - - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrinterConfiguration.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrinterConfiguration.java deleted file mode 100644 index 71fbf453331495ae1f7cd38129f7a9e821ab2c1c..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PrinterConfiguration.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -/** - * This enum provides means to differentiate between printers. - * This should be extended if new printers are supported. If its unknown, the standard should be NormalPrinter. This - * assumes that no special features are supported and hence, normal braille should be printed. - * Currently used in PrintDirector - * @author Andrey Ruzhanskiy - */ - -public enum PrinterConfiguration { - NORMALPRINTER, INDEX_EVEREST_D_V4_FLOATINGDOT_PRINTER, INDEX_EVEREST_D_V4_GRAPHIC_PRINTER -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PropertiesParser.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PropertiesParser.java deleted file mode 100644 index 9989bd95ef4db8a9dfd30e63f686362fc7625f00..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/PropertiesParser.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.Objects; -import java.util.Properties; - - -public class PropertiesParser implements AbstractBrailleTableParser { - private Properties mProperties = new Properties(); - - PropertiesParser(final String path){ - FileInputStream stream; - try { - stream = new FileInputStream(path); - mProperties.load(stream); - } catch (java.io.IOException e) { - throw new RuntimeException(e); - } - } - - public Properties getProperties(){ - if (Objects.isNull(mProperties)){ - throw new NullPointerException(); - } - if (mProperties.isEmpty()) { - throw new IllegalArgumentException(); - } - return mProperties; - } - - //BIG TODO explain or as leo. My fucking head hurts.... - //BIG TODO add null check(contains) - - @Override - public int getValue(String bitString) { - return Integer.parseInt(mProperties.getProperty(bitString)); - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/XmlParser.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/XmlParser.java deleted file mode 100644 index eda622c74d235f65d23282dbb76c4ce6f5fe5bc1..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/XmlParser.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.exporter; - -public class XmlParser implements AbstractBrailleTableParser { - @Override - public int getValue(String key) { - return 0; - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/package-info.java b/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/package-info.java deleted file mode 100644 index 6715b66f76a5aaae7c206c544097b0cf21648ad2..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/exporter/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Brailleplot Exporter package. - * Contains printer classes. - */ -package de.tudresden.inf.mci.brailleplot.exporter; diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/AbstractPrintableData.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/AbstractPrintableData.java deleted file mode 100644 index 1c068702de5f4688189d14e762d495d33ac5fbd0..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/AbstractPrintableData.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import de.tudresden.inf.mci.brailleplot.configparser.Printer; -import de.tudresden.inf.mci.brailleplot.configparser.Format; - -/** - * Abstract parent class for all {@link PrintableData} implementations. - * @author Georg Graßnick - * @version 2019.06.26 - */ -abstract class AbstractPrintableData implements PrintableData { - - private final Printer mPrinter; - private final Format mFormat; - - AbstractPrintableData(final Printer printer, final Format format) { - if (printer == null || format == null) { - throw new NullPointerException(); - } - mPrinter = printer; - mFormat = format; - } - - @Override - public Printer getPrinterConfig() { - return mPrinter; - } - - @Override - public Format getFormatConfig() { - return mFormat; - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/BrailleCell6.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/BrailleCell6.java deleted file mode 100644 index 585252f10dfa5421a4f8f9bb340becd62449f401..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/BrailleCell6.java +++ /dev/null @@ -1,117 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -/** - * Simple container class encapsulating 6 dots to form a representation of a Braille cell. - * The ordering of the positions follows the following convention: - * Top to bottom, then left to right; indices start at 0: - * - * 0 3 - * 1 4 - * 2 5 - * - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.28 - */ -public final class BrailleCell6<T> { - - static final int DOT_COUNT = 6; - static final int ROW_COUNT = 3; - static final int COLUMN_COUNT = 2; - - private T[] mDots; - - /** - * Constructor. - * The values are not checked for null! - * @param first Value of the first dot. - * @param second Value of the second dot. - * @param third Value of the third dot. - * @param fourth Value of the fourth dot. - * @param fifth Value of the fifth dot. - * @param sixth Value of the sixth dot. - */ - @SuppressWarnings({"unchecked", "checkstyle:MagicNumber"}) - public BrailleCell6(final T first, final T second, final T third, final T fourth, final T fifth, final T sixth) { - mDots = (T[]) new Object[DOT_COUNT]; - mDots[0] = first; - mDots[1] = second; - mDots[2] = third; - mDots[3] = fourth; - mDots[4] = fifth; - mDots[5] = sixth; - } - - /** - * Constructor. - * The values are not checked for null! - * @param vals An array of values to obtain the values from. - * @throws IllegalArgumentException If the length is not equal to 6. - */ - public BrailleCell6(final T[] vals) { - if (vals.length != DOT_COUNT) { - throw new IllegalArgumentException("Input Array must be of length " + DOT_COUNT); - } - mDots = vals.clone(); - } - - /** - * Get the value at the specified position. - * @param index The index of the position, - * @return The according value. - * @throws ArrayIndexOutOfBoundsException If the index is out of bounds (not in 0-5). - */ - public T get(final int index) { - if (index < 0 || index >= DOT_COUNT) { - throw new ArrayIndexOutOfBoundsException("Index not valid"); - } - return mDots[index]; - } - - /** - * Set the value at the specified position. - * @param index The index of the position. - * @param value The value to set. - * @throws ArrayIndexOutOfBoundsException If the index is out of bounds (not in 0-5). - */ - public void set(final int index, final T value) { - if (index < 0 || index >= DOT_COUNT) { - throw new ArrayIndexOutOfBoundsException("Index not valid"); - } - mDots[index] = value; - } - - /** - * Get the internal data array. - * @return The internal data array of length 6. - */ - public T[] data() { - return mDots; - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ROW_COUNT; i++) { - for (int j = 0; j < COLUMN_COUNT; j++) { - sb.append(mDots[i * COLUMN_COUNT + j]); - sb.append(" "); - } - sb.append("\n"); - } - return sb.toString(); - } - - public String toShortString(){ - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < mDots.length; i++) { - if(Boolean.parseBoolean(mDots[i].toString())) { - sb.append("1"); - } else { - sb.append("0"); - } - - } - return sb.toString(); - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/FloatingPointData.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/FloatingPointData.java deleted file mode 100644 index 67a34488e35a42ed95c58ce66038c044b52841a7..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/FloatingPointData.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import java.util.Iterator; - -/** - * This data is used to describe the data for the "Floating Dot Area" print mode. - * For each dot to emboss, there is one {@link Point2D} object which encapsulates both the position in width and height, - * as well as the intensity of the point. - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public interface FloatingPointData<T> extends PrintableData { - - /** - * Returns an iterator over all {@link Point2DValued}. - * @return An iterator over all points. - */ - Iterator<Point2DValued<T>> getIterator(); - - /** - * Add a point to the data structure. - * @param point The point to be inserted. - */ - void addPoint(Point2DValued<T> point); -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/MatrixData.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/MatrixData.java deleted file mode 100644 index b01567c7860b90f8f365dce5f45fb8d4a9825ec0..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/MatrixData.java +++ /dev/null @@ -1,81 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import java.util.Iterator; - -/** - * This data is used to describe the data for the "Braille" and "Graphics" print modes. - * The data is organized in a matrix structure, which can be queried for its values on integer x (row) and y (column) indices. - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public interface MatrixData<T> extends PrintableData { - - /** - * Get the value for a specific position in the matrix. - * Indices start at 0. - * @param row The row index of the position. - * @param column The column index of the position. - * @return The value at the requested position. - */ - T getValue(int row, int column); - - /** - * Get an iterator which iterates all dots of the matrix. - * Depending on the width and height parameters, the iterator will iterate the dots of Braille cells of the - * specified size from top to bottom and then from left to right - * Example: width = 2, height = 3; matrix size is 4x6: - * - * 01 04 07 10 - * 02 05 08 11 - * 03 06 09 12 - * 13 16 19 22 - * 14 17 20 23 - * 15 18 21 24 - * - * @param width The width of a Braille cell - * @param height The height of a Braille cell - * @return The according iterator. - */ - Iterator<T> getDotIterator(int width, int height); - - - /** - * Get an iterator which iterates over Braille cells of the matrix. - * The cells have a width of 2 columns and a height of 3 rows to mach a standard 6 dot Braille cell. - * The matrix is traversed from left to right and then top to bottom. - * Example: matrix size is 4x6 - The ids specify the associated Braille cell. - * - * 01 01 02 02 - * 01 01 02 02 - * 01 01 02 02 - * 03 03 04 04 - * 03 03 04 04 - * 03 03 04 04 - * - * @return The according iterator. - */ - Iterator<BrailleCell6<T>> getBrailleCell6Iterator(); - - /** - * Set the value at a specific position. - * Indices start at 0. - * @param row The row index of the position. - * @param column The column index of the position. - * @param value The value to set. - */ - void setValue(int row, int column, T value); - - /** - * Getter. - * @return The number of rows. - */ - int getRowCount(); - - /** - * Getter. - * @return The number of columns. - */ - int getColumnCount(); -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2D.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2D.java deleted file mode 100644 index 6bcf6401ae76d18b5cf355702617700c92d2a016..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2D.java +++ /dev/null @@ -1,77 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import javax.measure.Quantity; -import javax.measure.quantity.Length; -import java.util.Objects; - -/** - * Representation of a 2 dimensional point. - * Encapsulates a position on x and y axis. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public class Point2D { - - private final Quantity<Length> mX; - private final Quantity<Length> mY; - - /** - * Constructor. - * @param x Position on the x axis. - * @param y Position on the y axis. - */ - public Point2D(final Quantity<Length> x, final Quantity<Length> y) { - if (x == null || y == null) { - throw new NullPointerException(); - } - mX = x; - mY = y; - } - - /** - * Getter. - * @return The position on the x axis. - */ - public final Quantity<Length> getX() { - return mX; - } - - /** - * Getter. - * @return The position on the y axis. - */ - public final Quantity<Length> getY() { - return mY; - } - - /** - * Check for Object equality. - * @param other The other to compare to. - * @return true, if X and Y positions of both points are equal; else false - */ - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Point2D)) { - return false; - } - Point2D point = (Point2D) other; - return mX.equals(point.mX) && mY.equals(point.mY); - } - - @Override - public int hashCode() { - return Objects.hash(mX, mY); - } - - /** - * Create a human readable String to represent the point. - * @return A human readable String. - */ - @Override - public String toString() { - return "(" + mX + ", " + mY + ")"; - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2DValued.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2DValued.java deleted file mode 100644 index 8b674c972cb3785bf681d03d02620089427ce2fc..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/Point2DValued.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import javax.measure.Quantity; -import javax.measure.quantity.Length; -import java.util.Objects; - -/** - * Representation of a 2 dimensional point with an associated value. - * Encapsulates both the position on x and y axis, as well as a value (think of embossing intensity). - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public class Point2DValued<T> extends Point2D { - - private final T mVal; - - /** - * Constructor. - * @param x Position on the x axis. - * @param y Position on the y axis. - * @param val The value of the dot - */ - public Point2DValued(final Quantity<Length> x, final Quantity<Length> y, final T val) { - super(x, y); - if (val == null) { - throw new NullPointerException(); - } - mVal = val; - } - - /** - * Getter. - * @return The value that is associated with this point. - */ - public final T getVal() { - return mVal; - } - - /** - * Check for Object equality. - * @param other The other to compare to. - * @return true, if X and Y positions and the values of both points are equal; else false - */ - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Point2DValued)) { - return false; - } - Point2D point = (Point2DValued) other; - return super.equals(other) && mVal.equals(((Point2DValued) other).mVal); - } - - @Override - public int hashCode() { - return Objects.hash(mVal, super.hashCode()); - } - - /** - * Create a human readable String to represent the point. - * @return A human readable String. - */ - @Override - public String toString() { - return "(" + super.getX() + ", " + super.getY() + ": " + mVal + ")"; - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/PrintableData.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/PrintableData.java deleted file mode 100644 index 0ba23f88dfe5d83e055887801a3c75879c81d917..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/PrintableData.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import de.tudresden.inf.mci.brailleplot.configparser.Printer; -import de.tudresden.inf.mci.brailleplot.configparser.Format; - -/** - * Top interface for all data types that describe data ready for printing. - * These data containers are generated by the rasterizer and later on processed by the printer backend. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public interface PrintableData { - - /** - * Getter for the Printer Configuration, that was used to generate this data representation in the rasterizer. - * @return The associated Printer Configuration - */ - Printer getPrinterConfig(); - - /** - * Getter for the Format Configuration, that was used to generate this data representation in the rasterizer. - * @return The associated Format Configuration - */ - Format getFormatConfig(); - -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleFloatingPointDataImpl.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleFloatingPointDataImpl.java deleted file mode 100644 index a8a61648047214203c61be32c81d7a033b4514b2..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleFloatingPointDataImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import java.util.Iterator; -import java.util.LinkedList; - -import de.tudresden.inf.mci.brailleplot.configparser.Printer; -import de.tudresden.inf.mci.brailleplot.configparser.Format; - -/** - * A low effort implementation of the {@link FloatingPointData} interface. - * The underlying data is organized in a {@link LinkedList}, which makes insertions fast, but slows down random access. - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public class SimpleFloatingPointDataImpl<T> extends AbstractPrintableData implements FloatingPointData<T> { - - private LinkedList<Point2DValued<T>> mPoints; - - public SimpleFloatingPointDataImpl(final Printer printer, final Format format) { - super(printer, format); - mPoints = new LinkedList<>(); - } - - @Override - public Iterator<Point2DValued<T>> getIterator() { - return mPoints.iterator(); - } - - @Override - public void addPoint(final Point2DValued<T> point) { - if (point == null) { - throw new NullPointerException(); - } - mPoints.addLast(point); - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleMatrixDataImpl.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleMatrixDataImpl.java deleted file mode 100644 index b4e1023fa115b67214a7e821743657575fa1e87c..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/SimpleMatrixDataImpl.java +++ /dev/null @@ -1,202 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.printabledata; - -import java.util.Iterator; -import java.util.Vector; - -import de.tudresden.inf.mci.brailleplot.configparser.Printer; -import de.tudresden.inf.mci.brailleplot.configparser.Format; - -/** - * A low effort implementation of the {@link MatrixData} interface. - * The underlying data is represented by a {@link Vector} which makes the lookup and insertion fast, but uses lots of memory. - * @param <T> The type used for representing the intensity. Could be set to {@link Boolean} for basic Braille support, - * * but could also by set to {@link Short} if different embossing strengths are required. - * @author Georg Graßnick - * @version 2019.06.26 - */ -public class SimpleMatrixDataImpl<T> extends AbstractPrintableData implements MatrixData<T> { - - private final int mRows; - private final int mColumns; - private final Vector<T> mData; - - /** - * Constructor. - * @param printer The according {@link Printer} object. - * @param format The according {@link Format} object. - * @param rowCount The height of the matrix. - * @param columnCount The width of the matrix. - * @param defaultValue The default value each element will be assigned. - * @throws IllegalArgumentException if rowCount {@literal <} 0 or columnCount {@literal <} 0 - */ - public SimpleMatrixDataImpl(final Printer printer, final Format format, final int rowCount, final int columnCount, final T defaultValue) { - super(printer, format); - if (rowCount <= 0 || columnCount <= 0) { - throw new IllegalArgumentException("rowCount and columnCount must be a non zero positive integer"); - } - mRows = rowCount; - mColumns = columnCount; - mData = new Vector<>(rowCount * columnCount); - mData.setSize(rowCount * columnCount); - for (int i = 0; i < mData.size(); i++) { - mData.setElementAt(defaultValue, i); - } - } - - /** - * Calculate the index for the underlying {@link java.util.ArrayList}. - * @param row The row index of the requested index. - * @param column The column index of the requested index. - * @return The according index in the underlying {@link java.util.ArrayList} - * @throws IndexOutOfBoundsException If row or column are negative or larger than the size of the matrix. - */ - private int calcIndex(final int row, final int column) { - if (row >= mRows || column > mColumns || row < 0 || column < 0) { - throw new IndexOutOfBoundsException("Index (" + row + "," + column + ") out of bounds"); - } - return row * mColumns + column; - } - - @Override - public T getValue(final int row, final int column) { - return mData.get(calcIndex(row, column)); - } - - @Override - public void setValue(final int row, final int column, final T value) { - if (value == null) { - throw new NullPointerException(); - } - mData.set(calcIndex(row, column), value); - } - - @Override - public Iterator<T> getDotIterator(final int width, final int height) { - return new ElementIter(width, height, this); - } - - @Override - public Iterator<BrailleCell6<T>> getBrailleCell6Iterator() { - return new BrailleCell6Iterator(this); - } - - @Override - public int getColumnCount() { - return mColumns; - } - - @Override - public int getRowCount() { - return mRows; - } - - public final String toString() { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < getRowCount(); i++) { - for (int j = 0; j < getColumnCount(); j++) { - /* - sb.append(getValue(i, j)); - */ - if (getValue(i, j).equals(true)) { - sb.append("o"); - } else { - sb.append(" "); - } - if (((j+1) % 2) == 0) { - sb.append(" "); - } - sb.append(" "); - } - sb.append("\n"); - } - return sb.toString(); - } - - /** - * Iterator that iterates all elements of the matrix in a pattern that iterates Braille cells of specified height - * and width from left to right and top to bottom. - * See {@link MatrixData#getDotIterator(int, int)} for details. - */ - class ElementIter implements Iterator<T> { - - private final SimpleMatrixDataImpl<T> mMatrix; - - private final int mCellWidth; - private final int mCellHeight; - - // We use indices starting at 1, so that we do not have to check for the x-index to be 0 in the next() method call - private int mCurrentX = 1; - private int mCurrentY = 1; - - private boolean mIsFirstElem = true; - - ElementIter(final int cellWidth, final int cellHeight, final SimpleMatrixDataImpl<T> matrix) { - if (matrix.getColumnCount() % cellWidth != 0) { - throw new IllegalArgumentException("Cannot create requested iterator: matrix column count (" + matrix.getColumnCount() + ") is not a multiple of cell height (" + cellHeight + ")"); - } - if (matrix.getRowCount() % cellHeight != 0) { - throw new IllegalArgumentException("Cannot create requested iterator: matrix row count (" + matrix.getRowCount() + ") is not a multiple of cell width (" + cellWidth + ")"); - } - mMatrix = matrix; - mCellWidth = cellWidth; - mCellHeight = cellHeight; - } - - @Override - public boolean hasNext() { - return !(mCurrentY == mMatrix.getRowCount() && mCurrentX == mMatrix.getColumnCount()); - } - - @Override - public T next() { - if (mIsFirstElem) { - mIsFirstElem = false; - } else if (mCurrentY % mCellHeight != 0) { - // Staying in the current cell, move down - mCurrentY++; - } else if (mCurrentX % mCellWidth != 0) { - // Staying in current cell, move right, set y to the top most index of the current cell - mCurrentX++; - mCurrentY = (((mCurrentY / mCellHeight) - 1) * mCellHeight) + 1; - } else if (mCurrentX < mMatrix.getColumnCount()) { // Moving on to the next cell - // Right is possible - mCurrentX += 1; - mCurrentY = (((mCurrentY / mCellHeight) - 1) * mCellHeight) + 1; - } else { - // We need to go downwards - mCurrentY += 1; - mCurrentX = 1; - } - // Correct index to match the specifications of the MatrixData interface - return mMatrix.getValue(mCurrentY - 1, mCurrentX - 1); - } - } - - /** - * Iterator that returns {@link BrailleCell6} objects rather than the dots themselves. - * See {@link MatrixData#getBrailleCell6Iterator()} for details. - */ - class BrailleCell6Iterator implements Iterator<BrailleCell6<T>> { - - private final Iterator<T> mElemIter; - - BrailleCell6Iterator(final SimpleMatrixDataImpl<T> matrix) { - mElemIter = matrix.getDotIterator(BrailleCell6.COLUMN_COUNT, BrailleCell6.ROW_COUNT); - } - - @Override - public boolean hasNext() { - return mElemIter.hasNext(); - } - - @Override - @SuppressWarnings("unchecked") - public BrailleCell6<T> next() { - T[] vals = (T[]) new Object[BrailleCell6.DOT_COUNT]; - for (int i = 0; i < BrailleCell6.DOT_COUNT; i++) { - vals[i] = mElemIter.next(); - } - return new BrailleCell6<>(vals); - } - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/package-info.java b/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/package-info.java deleted file mode 100644 index 807aba761ac1322d538c04c6479d5483e55fb3a5..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/printabledata/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * This package contains all the requiered classes and interfaces for data exchange between the rasterizer and - * the printer backend. - * @author Georg Graßnick - * @version 2019.06.26 - */ -package de.tudresden.inf.mci.brailleplot.printabledata; diff --git a/src/main/java/diagrams/BarChart.java b/src/main/java/diagrams/BarChart.java deleted file mode 100644 index d1d04427b61db9f9cd0f445850598a3e1e89c3cd..0000000000000000000000000000000000000000 --- a/src/main/java/diagrams/BarChart.java +++ /dev/null @@ -1,67 +0,0 @@ -package diagrams; - -import de.tudresden.inf.mci.brailleplot.rendering.Renderable; -import parser.CategorialPointListList; -import parser.PointListList; -import parser.XType; - -import java.util.List; - -public class BarChart implements Renderable { - private CategorialPointListList p; - - public BarChart(CategorialPointListList p) { - this.p = p; - p.updateMinMax(); - } - - public int getCategoryCount() { - return p.getCategoryCount(); - } - - public List<String> getCategoryNames() { - return p.getCategoryNames(); - } - - public void addCategory(String name) { - p.categoryNames.add(name); - } - - public String getCategoryName(int index) { - return p.getCategoryName(index); - } - - public double getCategorySum(int index) { - return p.getCategorySum(index); - } - - public XType getXType() { - return p.getXType(); - } - - public double getMaxYSum() { - return p.getMaxYSum(); - } - - public double getMinY() { - return p.getMinY(); - } - - public double getMaxY() { - return p.getMaxY(); - } - - /** returns a list with x-y-Pairs: x is the index (always just counts from 0 up), y is the value - * - * @param index - * @return - */ - public PointListList.PointList getDataSet(int index) { - return (PointListList.PointList) p.get(index); - } - - public String getDataSetName(int index) { - return p.get(index).getName(); - } - -} diff --git a/src/main/java/diagrams/Diagram.java b/src/main/java/diagrams/Diagram.java deleted file mode 100644 index 049c15a3c7bf6f07a13eada7e9a27c42bb6b50c7..0000000000000000000000000000000000000000 --- a/src/main/java/diagrams/Diagram.java +++ /dev/null @@ -1,36 +0,0 @@ -package diagrams; - -import parser.PointListList; -import parser.XType; - -public class Diagram { - public PointListList p; - - public double getMinX() { - return p.getMinX(); - } - - public double getMaxX() { - return p.getMaxX(); - } - - public double getMinY() { - return p.getMinY(); - } - - public double getMaxY() { - return p.getMaxY(); - } - - public XType getXType() { - return p.getXType(); - } - - public PointListList.PointList getDataSet(int index) { - return (PointListList.PointList) p.get(index); - } - - public String getDataSetName(int index) { - return p.get(index).getName(); - } -} diff --git a/src/main/java/diagrams/LinePlot.java b/src/main/java/diagrams/LinePlot.java deleted file mode 100644 index b312694f1e1863a408b52d172f12ccd24c05fc46..0000000000000000000000000000000000000000 --- a/src/main/java/diagrams/LinePlot.java +++ /dev/null @@ -1,11 +0,0 @@ -package diagrams; - -import parser.PointListList; - -public class LinePlot extends Diagram { - - public LinePlot(PointListList p) { - this.p = p; - p.updateMinMax(); - } -} diff --git a/src/main/java/diagrams/ScatterPlot.java b/src/main/java/diagrams/ScatterPlot.java deleted file mode 100644 index ddce1d1c340753dddf53d52c475bc62541658d6a..0000000000000000000000000000000000000000 --- a/src/main/java/diagrams/ScatterPlot.java +++ /dev/null @@ -1,11 +0,0 @@ -package diagrams; - -import parser.PointListList; - -public class ScatterPlot extends Diagram { - - public ScatterPlot(PointListList p) { - this.p = p; - p.updateMinMax(); - } -} diff --git a/src/main/java/parser/Axis.java b/src/main/java/parser/Axis.java deleted file mode 100644 index 969cd1d08a79b7479f04e3d5c13f67b1f6fc7a95..0000000000000000000000000000000000000000 --- a/src/main/java/parser/Axis.java +++ /dev/null @@ -1,151 +0,0 @@ -package parser; - -import java.text.DecimalFormat; -import java.util.NoSuchElementException; - -public abstract class Axis { - - // The following offsets can and shall be overwritten by child classes - /** X offset of horizontal axis labels */ - public final double labelOffsetHorizontalX; - /** Y offset of horizontal axis labels */ - public final double labelOffsetHorizontalY; - /** X offset of vertical axis labels */ - public final double labelOffsetVerticalX; - /** Y offset of vertical axis labels */ - public final double labelOffsetVerticalY; - - protected double ticInterval; - protected Range ticRange; - protected double gridInterval; - protected Range range; - protected double labelInterval; - protected Range labelRange; - protected final DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Constants.locale); - - protected String unit; - protected String title; - - /** How much the point position shall be shifted - used for nominal axes.*/ - protected final double pointOffset; - - /** - * Constructor setting the label and point offsets. - * @param labelOffsetHorizontalX - * @param labelOffsetHorizontalY - * @param labelOffsetVerticalX - * @param labelOffsetVerticalY - * @param pointOffset - */ - public Axis(double labelOffsetHorizontalX, double labelOffsetHorizontalY, double labelOffsetVerticalX, - double labelOffsetVerticalY, double pointOffset, String title, String unit) { - this.labelOffsetHorizontalX = labelOffsetHorizontalX; - this.labelOffsetHorizontalY = labelOffsetHorizontalY; - this.labelOffsetVerticalX = labelOffsetVerticalX; - this.labelOffsetVerticalY = labelOffsetVerticalY; - this.pointOffset = pointOffset; - this.title = title; - this.unit = unit; - } - - public AxisIterator ticLines() { - return new AxisIterator(ticRange, ticInterval); - } - - public AxisIterator gridLines() { - return new AxisIterator(range, gridInterval); - } - - public AxisIterator labelPositions() { - return new AxisIterator(labelRange, labelInterval); - } - - public abstract String formatForAxisLabel(double value); - - public abstract String formatForAxisAudioLabel(double value); - - public abstract String formatForSymbolAudioLabel(double value); - - public static class AxisIterator implements java.util.Iterator<Double>, Iterable<Double> { - - private Range range; - private double interval; - private double current; - - protected AxisIterator(Range range, double interval) { - this(range, interval, 0); - } - - protected AxisIterator(Range range, double interval, double offset) { - this.range = range; - this.interval = interval; - current = range.getFrom() + offset; - } - - /** - * Get the next axis value. There used to be a check for skipping the - * zero value, but now it is not skipped anymore, because there are axis - * configurations where the zero tics and gridlines are needed. - */ - @Override - public boolean hasNext() { - return current <= range.getTo(); - } - - @Override - public Double next() { - if (!hasNext()) - throw new NoSuchElementException(); - double nextCurrent = this.current; - this.current += interval; - return nextCurrent; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public AxisIterator iterator() { - return this; - } - - } - - public double getTicInterval() { - return ticInterval; - } - - public Range getTicRange() { - return ticRange; - } - - public double getGridInterval() { - return gridInterval; - } - - public Range getRange() { - return range; - } - - public double getLabelInterval() { - return labelInterval; - } - - public Range getLabelRange() { - return labelRange; - } - - public String getUnit() { - return unit; - } - - public String getTitle() { - return title; - } - - public double getPointOffset() { - return pointOffset; - } -} \ No newline at end of file diff --git a/src/main/java/parser/CategorialPointListList.java b/src/main/java/parser/CategorialPointListList.java deleted file mode 100644 index fe1ae0ed984d1509b8cc95dc37d639ad1b6d6fe3..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CategorialPointListList.java +++ /dev/null @@ -1,69 +0,0 @@ -package parser; - -import java.util.ArrayList; -import java.util.List; - -/** - * A {@link PointListList} storing a list of category names. The x values of the - * added points should correspond to the index of their category in the category - * list. - */ -public class CategorialPointListList extends PointListList { - - private static final long serialVersionUID = -1291194891140659342L; - - public List<String> categoryNames; - private double maxYSum = Double.NEGATIVE_INFINITY; - - public XType getXType() { - return XType.CATEGORIAL; - } - - public CategorialPointListList() { - categoryNames = new ArrayList<>(); - } - - public void addCategory(String name) { - categoryNames.add(name); - } - - public String getCategoryName(int index) { - try { - return categoryNames.get(index); - } catch (Exception e) { - return ""; - } - } - - public int getCategoryCount() { - return categoryNames.size(); - } - - public void setCategoryNames(List<String> categoryNames) { - this.categoryNames = categoryNames; - } - - public List<String> getCategoryNames() { - return categoryNames; - } - - public double getCategorySum(int index) { - double sum = 0; - for(PointList pointList : this) { - if(pointList.size() > index) - sum += pointList.get(index).getY(); - } - return sum; - } - - @Override - public void updateMinMax() { - super.updateMinMax(); - for(int i = 0; i < categoryNames.size(); i++) - maxYSum = Math.max(maxYSum, getCategorySum(i)); - } - - public double getMaxYSum() { - return maxYSum; - } -} diff --git a/src/main/java/parser/Constants.java b/src/main/java/parser/Constants.java deleted file mode 100644 index 2b1ab9889d9a9800769d4471771f73f894028e9d..0000000000000000000000000000000000000000 --- a/src/main/java/parser/Constants.java +++ /dev/null @@ -1,46 +0,0 @@ -package parser; - -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.util.*; - -public class Constants { - public static final String PROPERTIES_FILENAME = "svgplot.properties"; - public static final Locale locale = new Locale("de"); - public static final NumberFormat numberFormat = NumberFormat.getInstance(locale); - public static final ResourceBundle bundle = ResourceBundle.getBundle("Bundle"); - public static final double STROKE_WIDTH = 0.5; - public static final List<Integer> MARGIN = Collections.unmodifiableList(Arrays.asList(15, 10, 15, 10)); - /** List of letters for function naming */ - public static final List<String> FN_LIST = Collections - .unmodifiableList(Arrays.asList("f", "g", "h", "i", "j", "k", "l", "m", "o", "p", "q", "r")); - /** List of letters for point naming */ - public static final List<String> PN_LIST = Collections.unmodifiableList( - Arrays.asList("A", "B", "C", "D", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "T")); - public static final String SPACER_CSS_CLASS = "poi_symbol_bg"; - public static final DecimalFormat decimalFormat = getSvgDecimalFormat(); - /** The minimal distance of grid lines in mm */ - public static final int MIN_GRID_DISTANCE = 10; - public static final int MIN_LINE_LENGTH = 30; - public static final Point titlePosition = new Point(Constants.MARGIN.get(3), Constants.MARGIN.get(0) + 10); - public static final double CHAR_WIDTH = 6.5; - public static final double TEXTURE_BORDER_DISTANCE = 2; - public static final double TEXTURE_MIN_HEIGHT = 7; - public static final double TEXTURE_MIN_WIDTH = 20; - public static final double HALF_BAR_DISTANCE = 3; - - // Used for double comparisons - public static final double EPSILON = 1E-10; - - private Constants() { - } - - private static final DecimalFormat getSvgDecimalFormat() { - DecimalFormat decimalFormat = new DecimalFormat("0.###"); - DecimalFormatSymbols dfs = new DecimalFormatSymbols(); - dfs.setDecimalSeparator('.'); - decimalFormat.setDecimalFormatSymbols(dfs); - return decimalFormat; - } -} diff --git a/src/main/java/parser/CoordinateSystem.java b/src/main/java/parser/CoordinateSystem.java deleted file mode 100644 index ed98f37aac68da8d74d114fd52883cd378065e6c..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CoordinateSystem.java +++ /dev/null @@ -1,284 +0,0 @@ -package parser; - -import java.util.List; - - -/** - * - * @author Gregor Harlan, Jens Bornschein Idea and supervising by Jens - * Bornschein jens.bornschein@tu-dresden.de Copyright by Technische - * Universität Dresden / MCI 2014 - * - */ -public class CoordinateSystem { - - public final Axis xAxis; - public final Axis yAxis; - - public final boolean pi; - - /** Origin of the real coordinate system (left upper corner) */ - private final Point origin; - - /** Size of the drawing area excluding margins */ - private final Point size; - - /** - * Constructor for a coordinate system with a nominal x axis. TODO replace - * by a factory in order to avoid code duplication - * - * @param xCategories - * @param yRange - * @param size - * @param diagramContentMargin - */ - public CoordinateSystem(List<String> xCategories, Range yRange, Point size, List<Integer> diagramContentMargin, String xUnit, String yUnit) { - origin = new Point(diagramContentMargin.get(3), diagramContentMargin.get(0)); - - this.size = new Point(size); - this.size.setX(this.size.getX() - (diagramContentMargin.get(1) + diagramContentMargin.get(3))); - this.size.setY(this.size.getY() - (diagramContentMargin.get(0) + diagramContentMargin.get(2))); - // this.size.x = Math.min(this.size.x, this.size.y); - // this.size.y = this.size.x; - - xAxis = new NominalAxis(xCategories, this.size.getX(), xUnit); - yAxis = new MetricAxis(yRange, this.size.getY(), yRange.getName(), yUnit); - - this.pi = false; - } - - public CoordinateSystem(Range xRange, Range yRange, Point size, List<Integer> margin, String xUnit, String yUnit) { - this(xRange, yRange, size, margin, false, xUnit, yUnit); - } - - /** - * Constructor for a coordinate system with metric axes. TODO replace by a - * factory in order to avoid code duplication - * - * @param xRange - * @param yRange - * @param size - * @param diagramContentMargin - * @param pi - */ - public CoordinateSystem(Range xRange, Range yRange, Point size, List<Integer> diagramContentMargin, boolean pi, String xUnit, String yUnit) { - origin = new Point(diagramContentMargin.get(3), diagramContentMargin.get(0)); - - this.size = new Point(size); - this.size.setX(this.size.getX() - (diagramContentMargin.get(1) + diagramContentMargin.get(3))); - this.size.setY(this.size.getY() - (diagramContentMargin.get(0) + diagramContentMargin.get(2))); - // this.size.x = Math.min(this.size.x, this.size.y); - // this.size.y = this.size.x; - - xAxis = new MetricAxis(xRange, this.size.getX(), xRange.getName(), xUnit); - yAxis = new MetricAxis(yRange, this.size.getY(), yRange.getName(), yUnit); - - this.pi = pi; - } - - /** - * Converts a point from virtual to real coordinates. - * - * @param x - * | virtual x coordinate - * @param y - * | virtual y coordinate - * @return real point - */ - public Point convert(double x, double y) { - double newX = origin.getX() - + (x - xAxis.range.getFrom()) * size.getX() / (xAxis.range.getTo() - xAxis.range.getFrom()); - double newY = origin.getY() + size.getY() - - ((y - yAxis.range.getFrom()) * size.getY() / (yAxis.range.getTo() - yAxis.range.getFrom())); - return new Point(newX, newY); - } - - /** - * Converts a point from virtual to real coordinates using an offset from the axes. - * - * @param x - * | virtual x coordinate - * @param y - * | virtual y coordinate - * @return real point - */ - public Point convertWithOffset(double x, double y) { - return convert(x + xAxis.getPointOffset(), y + yAxis.getPointOffset()); - } - - /** - * Converts a point from virtual to real coordinates. - * - * @param point - * | virtual coordinates - * @return real point - */ - public Point convert(Point point) { - return convert(point.getX(), point.getY()); - } - - /** - * Converts a point from virtual to real coordinates using an offset from the axes. - * - * @param point - * | virtual coordinates - * @return real point - */ - public Point convertWithOffset(Point point) { - return convertWithOffset(point.getX(), point.getY()); - } - - /** - * Converts a point from virtual coordinates and translates it in real - * space. - * - * @param x - * | virtual x coordinate - * @param y - * | virtual y coordinate - * @param dx - * | real x transformation - * @param dy - * | real y transformation - * @return real point - */ - public Point convert(double x, double y, double dx, double dy) { - Point real = convert(x, y); - real.translate(dx, dy); - return real; - } - - /** - * Converts a point from virtual coordinates and translates it in real - * space. - * - * @param point - * | virtual coordinates - * @param dx - * | real x transformation - * @param dy - * | real y transformation - * @return real point - */ - public Point convert(Point point, double dx, double dy) { - return convert(point.getX(), point.getY(), dx, dy); - } - - /** - * Converts a distance on the x axis from virtual to real. - * - * @param distance - * | virtual distance - * @return real distance - */ - public double convertXDistance(double distance) { - return distance * size.getX() / (xAxis.range.getTo() - xAxis.range.getFrom()); - } - - /** - * Converts a distance on the y axis from virtual to real. - * - * @param distance - * | virtual distance - * @return real distance - */ - public double convertYDistance(double distance) { - return distance * size.getY() / (yAxis.range.getTo() - yAxis.range.getFrom()); - } - - /** - * Converts two virtual points and calculates their real distance - * - * @param point1 - * @param point2 - * @return real distance - */ - public double convertDistance(Point point1, Point point2) { - return convert(point1).distance(convert(point2)); - } - - /** - * Formats the x value of a point with respect to if Pi is set in the - * coordinate system. - * - * @param x - * x-value - * @return formated string for the point - */ - public String formatX(double x) { - String str = xAxis.formatForAxisLabel(x); - if (pi && !"0".equals(str)) { - str += " pi"; - } - return str; - } - - /** - * Formats the x value of a point with respect to if Pi is set in the - * coordinate system, for axis audio labels. - * - * @param x - * x-value - * @return formated string for the point - */ - public String formatXForAxisSpeech(double x) { - String str = xAxis.formatForAxisAudioLabel(x); - if (pi && !"0".equals(str)) { - str += " pi"; - } - return str; - } - - /** - * Formats the x value of a point with respect to if Pi is set in the - * coordinate system, for symbol audio labels. - * - * @param x - * x-value - * @return formated string for the point - */ - public String formatXForSymbolSpeech(double x) { - String str = xAxis.formatForSymbolAudioLabel(x); - if (pi && !"0".equals(str)) { - str += " pi"; - } - return str; - } - - /** - * Formats the y value of a point. - * - * @param y - * y-value - * @return formated string for the point - */ - public String formatY(double y) { - return yAxis.formatForAxisLabel(y); - } - - /** - * Formats a Point that it is optimized for speech output. E.g. (x / y) - * - * @param point - * The point that should be transformed into a textual - * representation - * @return formated string for the point with '/' as delimiter - */ - public String formatForSpeech(Point point) { - return ((point.getName() != null && !point.getName().isEmpty()) ? point.getName() + " " : "") - + formatXForSymbolSpeech(point.getX()) + " / " + formatY(point.getY()); - } - - /** - * Formats a Point that it is optimized for speech output for an axis audio label. - * - * @param point - * The point that should be transformed into a textual - * representation - * @return formated string for the point with '/' as delimiter - */ - public String formatForAxisSpeech(Point point) { - return ((point.getName() != null && !point.getName().isEmpty()) ? point.getName() + " " : "") - + formatXForAxisSpeech(point.getX()) + " / " + formatY(point.getY()); - } -} diff --git a/src/main/java/parser/CsvDotParser.java b/src/main/java/parser/CsvDotParser.java deleted file mode 100644 index 5294a3c80266e6bed0941e8a037cb658dcd9ba70..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvDotParser.java +++ /dev/null @@ -1,130 +0,0 @@ -package parser; - -import parser.PointListList.PointList; - -import java.text.ParseException; -import java.util.Iterator; -import java.util.List; - -public class CsvDotParser extends CsvParseAlgorithm { - - /** - * Parses scattered point data in horizontal data sets, alternating x and y. The - * first column contains the row name in the x row. - * - * @return the parsed data - */ - public PointListList parseAsHorizontalDataSets(List<? extends List<String>> csvData) { - int row = 0; - - PointListList pointListList = new PointListList(); - - // Continue as long as there are at least two further rows left - while (csvData.size() >= row + 2) { - PointList rowPoints = new PointList(); - - Iterator<String> xRowIterator = csvData.get(row).iterator(); - Iterator<String> yRowIterator = csvData.get(row + 1).iterator(); - - row += 2; - - // Get the row name - if (xRowIterator.hasNext() && yRowIterator.hasNext()) { - rowPoints.setName(xRowIterator.next()); - yRowIterator.next(); - } else { - continue; - } - - // Get the row values - while (xRowIterator.hasNext() && yRowIterator.hasNext()) { - Number xValue; - Number yValue; - try { - xValue = Constants.numberFormat.parse(xRowIterator.next()); - yValue = Constants.numberFormat.parse(yRowIterator.next()); - } catch (ParseException e) { - continue; - } - Point newPoint = new Point(xValue.doubleValue(), yValue.doubleValue()); - rowPoints.insertSorted(newPoint); - } - - // If there were no points found, do not add the row to the list - if (!rowPoints.isEmpty()) - pointListList.add(rowPoints); - } - - return pointListList; - } - - /** - * Parses scattered point data in vertical data sets, alternating x and y. The - * first row contains the column name in the x column. - * - * @return the parsed data - */ - @Override - public PointListList parseAsVerticalDataSets(List<? extends List<String>> csvData) { - int row = 0; - - PointListList pointListList = new PointListList(); - - if (csvData.isEmpty()) - return pointListList; - - // Iterate over the first row in order to get the headers - int col = 0; - for (String header : csvData.get(0)) { - if (col % 2 == 0) { - PointList pointList = new PointList(); - pointList.setName(header); - pointListList.add(pointList); - } - col++; - } - - row++; - - // Continue as long as there is at least one further rows left - while (csvData.size() >= row + 1) { - List<String> fields = csvData.get(row); - Iterator<String> fieldIterator = fields.iterator(); - - col = -1; - - while (fieldIterator.hasNext()) { - String xRaw = fieldIterator.next(); - String yRaw; - - col++; - - if (!fieldIterator.hasNext()) - break; - - yRaw = fieldIterator.next(); - - Number xValue; - Number yValue; - - try { - xValue = Constants.numberFormat.parse(xRaw); - yValue = Constants.numberFormat.parse(yRaw); - } catch (ParseException e) { - col++; - continue; - } - - Point point = new Point(xValue.doubleValue(), yValue.doubleValue()); - - addPointToPointListList(pointListList, col / 2, point); - - col++; - } - - row++; - } - - return pointListList; - } -} diff --git a/src/main/java/parser/CsvOrientation.java b/src/main/java/parser/CsvOrientation.java deleted file mode 100644 index 45bc2dcd44ffc7437f6fb945291ad1830838442c..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvOrientation.java +++ /dev/null @@ -1,34 +0,0 @@ -package parser; - -import com.beust.jcommander.IStringConverter; - -public enum CsvOrientation { - - HORIZONTAL, VERTICAL; - - public static CsvOrientation fromString(String code) { - if(code.equals("vertical") || code.equals("v")) - return CsvOrientation.VERTICAL; - else - return CsvOrientation.HORIZONTAL; - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } - - public static class CsvOrientationConverter implements IStringConverter<CsvOrientation> { - - public CsvOrientationConverter() { - super(); - } - - @Override - public CsvOrientation convert(String value) { - CsvOrientation convertedValue = CsvOrientation.fromString(value); - return convertedValue; - } - - } -} diff --git a/src/main/java/parser/CsvParseAlgorithm.java b/src/main/java/parser/CsvParseAlgorithm.java deleted file mode 100644 index 878738e7359361f7b0ac940e6653110d4ce5df8d..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvParseAlgorithm.java +++ /dev/null @@ -1,49 +0,0 @@ -package parser; - -import parser.PointListList.PointList; - -import java.util.List; - -/** - * An algorithm for parsing CSV data. Contains implementations for two - * orientations of the data in the file. - */ -public abstract class CsvParseAlgorithm { - /** - * If the data sets are oriented horizontally, i.e. in rows, parse the rows - * into {@link PointList PointLists}. - * - * @param csvData - * @return - */ - public abstract PointListList parseAsHorizontalDataSets(List<? extends List<String>> csvData); - - /** - * If the data sets are oriented vertically, i.e. in columns, parse the - * columns into {@link PointList PointLists}. - * - * @param csvData - * @return - */ - public abstract PointListList parseAsVerticalDataSets(List<? extends List<String>> csvData); - - /** - * Adds a {@code point} to a {@link PointList} in a {@link PointListList}, - * specified by {@code listIndex}. Adds more {@link PointList PointLists} if - * needed. - * - * @param pointListList - * the {@link PointListList} to which the point shall be added - * @param listIndex - * the index of the list to which the point shall be added - * @param point - * the point which shall be added - */ - protected void addPointToPointListList(PointListList pointListList, int listIndex, Point point) { - while (pointListList.size() < listIndex) { - pointListList.add(new PointList()); - } - - pointListList.get(listIndex).insertSorted(point); - } -} diff --git a/src/main/java/parser/CsvParser.java b/src/main/java/parser/CsvParser.java deleted file mode 100644 index 5c89fafa06dac4b05eae02ea9c2fbe59ccf6a72f..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvParser.java +++ /dev/null @@ -1,71 +0,0 @@ -package parser; - -import com.opencsv.CSVReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Arrays; - -public class CsvParser { - - static final Logger log = LoggerFactory.getLogger(CsvParser.class); - - public ArrayList<ArrayList<String>> csvData; - - /** - * Initiates the parser. The parser reads from the specified {@code reader} - * and populates {@link #csvData}. - * - * @param reader - * a reader, like {@link FileReader} - * @param separator - * @param quoteChar - * @throws IOException - * if the {@link CSVReader} has problems parsing - */ - public CsvParser(Reader reader, char separator, char quoteChar) throws IOException { - CSVReader csvReader = new CSVReader(reader, separator, quoteChar); - - csvData = new ArrayList<>(); - - String[] nextLine; - while ((nextLine = csvReader.readNext()) != null) { - csvData.add(new ArrayList<String>(Arrays.asList(nextLine))); - } - - csvReader.close(); - } - - public PointListList parse(CsvType csvType, CsvOrientation csvOrientation) { - CsvParseAlgorithm csvParseAlgorithm; - - log.info("Parse die Daten als \"{}\", Orientierung \"{}\"", csvType, csvOrientation); - - switch (csvType) { - case DOTS: - csvParseAlgorithm = new CsvDotParser(); - break; - case X_ALIGNED: - csvParseAlgorithm = new CsvXAlignedParser(); - break; - case X_ALIGNED_CATEGORIES: - csvParseAlgorithm = new CsvXAlignedCategoriesParser(); - break; - default: - return null; - } - - switch (csvOrientation) { - case HORIZONTAL: - return csvParseAlgorithm.parseAsHorizontalDataSets(csvData); - case VERTICAL: - return csvParseAlgorithm.parseAsVerticalDataSets(csvData); - default: - return null; - } - } -} diff --git a/src/main/java/parser/CsvType.java b/src/main/java/parser/CsvType.java deleted file mode 100644 index 6288a67f063cb5a439b599bc9b1e6d7f44fa97f2..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvType.java +++ /dev/null @@ -1,52 +0,0 @@ -package parser; - -import com.beust.jcommander.IStringConverter; - -/** - * Determines what data is represented how by the CSV file. The values are - * structural properties, whereas the {@link XType} held by every value - * determines whether the x values are metric or categorial. - */ -public enum CsvType { - DOTS(XType.METRIC), X_ALIGNED(XType.METRIC), X_ALIGNED_CATEGORIES(XType.CATEGORIAL); - - public final XType xType; - - private CsvType(XType xType) { - this.xType = xType; - } - - public static CsvType fromString(String value) { - switch (value.toLowerCase()) { - case "x_aligned": - case "xa": - return CsvType.X_ALIGNED; - case "x_aligned_categories": - case "xac": - return CsvType.X_ALIGNED_CATEGORIES; - case "dots": - case "d": - default: - return DOTS; - } - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } - - public static class CsvTypeConverter implements IStringConverter<CsvType> { - - public CsvTypeConverter() { - super(); - } - - @Override - public CsvType convert(String value) { - CsvType convertedValue = CsvType.fromString(value); - return convertedValue; - } - - } -} diff --git a/src/main/java/parser/CsvXAlignedCategoriesParser.java b/src/main/java/parser/CsvXAlignedCategoriesParser.java deleted file mode 100644 index 6009d6156c7678f7f49c9bec342701465370d7df..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvXAlignedCategoriesParser.java +++ /dev/null @@ -1,133 +0,0 @@ -package parser; - -import parser.PointListList.PointList; - -import java.text.ParseException; -import java.util.Iterator; -import java.util.List; - - -public class CsvXAlignedCategoriesParser extends CsvParseAlgorithm { - - @Override - public PointListList parseAsHorizontalDataSets(List<? extends List<String>> csvData) { - CategorialPointListList pointListList = new CategorialPointListList(); - - Iterator<? extends List<String>> rowIterator = csvData.iterator(); - - if(!rowIterator.hasNext()) - return pointListList; - - Iterator<String> lineIterator = rowIterator.next().iterator(); - - // Move the iterator to the first category name - if(!lineIterator.hasNext()) - return pointListList; - lineIterator.next(); - if(!lineIterator.hasNext()) - return pointListList; - - // Store all categories - while(lineIterator.hasNext()) { - pointListList.addCategory(lineIterator.next()); - } - - // Store each row's data set - while(rowIterator.hasNext()) { - lineIterator = rowIterator.next().iterator(); - - // Create a PointList with the title of the data set - if(!lineIterator.hasNext()) - continue; - PointList pointList = new PointList(); - pointList.setName(lineIterator.next()); - pointListList.add(pointList); - - // Add all the points - int colPosition = 0; - while (lineIterator.hasNext()) { - if(colPosition >= pointListList.getCategoryCount()) - break; - - // Find out the y value - Number yValue; - try { - yValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - colPosition++; - continue; - } - - // Add the new point - Point newPoint = new Point(colPosition, yValue.doubleValue()); - pointList.insertSorted(newPoint); - colPosition++; - } - } - - return pointListList; - } - - @Override - public PointListList parseAsVerticalDataSets(List<? extends List<String>> csvData) { - CategorialPointListList pointListList = new CategorialPointListList(); - Iterator<? extends List<String>> rowIterator = csvData.iterator(); - - - if(!rowIterator.hasNext()) - return pointListList; - - Iterator<String> lineIterator = rowIterator.next().iterator(); - - // Move the iterator to the first title - if(!lineIterator.hasNext()) - return pointListList; - - lineIterator.next(); - - if(!lineIterator.hasNext()) - return pointListList; - - // Add a PointList for each title - while(lineIterator.hasNext()) { - PointList pointList = new PointList(); - pointList.setName(lineIterator.next()); - pointListList.add(pointList); - } - - // Add the data - int categoryCounter = 0; - while(rowIterator.hasNext()) { - lineIterator = rowIterator.next().iterator(); - if(!lineIterator.hasNext()) { - categoryCounter++; - continue; - } - - // Find out the category title - String currentCategory = lineIterator.next(); - pointListList.addCategory(currentCategory); - - // Find out the y values and add the points to the respective lists - int currentDataSet = 0; - while(lineIterator.hasNext()) { - Number yValue; - try { - yValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - currentDataSet++; - continue; - } - - Point newPoint = new Point(categoryCounter, yValue.doubleValue()); - addPointToPointListList(pointListList, currentDataSet, newPoint); - currentDataSet++; - } - - categoryCounter++; - } - - return pointListList; - } - -} diff --git a/src/main/java/parser/CsvXAlignedParser.java b/src/main/java/parser/CsvXAlignedParser.java deleted file mode 100644 index 185d9753a1b4520878b63a7ba3d0eaec20f918e7..0000000000000000000000000000000000000000 --- a/src/main/java/parser/CsvXAlignedParser.java +++ /dev/null @@ -1,143 +0,0 @@ -package parser; - -import parser.PointListList.PointList; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - - -public class CsvXAlignedParser extends CsvParseAlgorithm { - - @Override - public PointListList parseAsHorizontalDataSets(List<? extends List<String>> csvData) { - PointListList pointListList = new PointListList(); - List<Number> xValues = new ArrayList<>(); - Iterator<? extends List<String>> rowIterator = csvData.iterator(); - - if(!rowIterator.hasNext()) - return pointListList; - - Iterator<String> lineIterator = rowIterator.next().iterator(); - - // Move the iterator to the x value - if(!lineIterator.hasNext()) - return pointListList; - lineIterator.next(); - if(!lineIterator.hasNext()) - return pointListList; - - // Store all x values, if one is not specified store NaN - while(lineIterator.hasNext()) { - Number xValue; - try { - xValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - xValue = Double.NaN; - } - xValues.add(xValue); - } - - // Store each row's data set - while(rowIterator.hasNext()) { - lineIterator = rowIterator.next().iterator(); - - // Create a PointList with the title of the data set - if(!lineIterator.hasNext()) - continue; - PointList pointList = new PointList(); - pointList.setName(lineIterator.next()); - pointListList.add(pointList); - - // Add all the points - int colPosition = 0; - while (lineIterator.hasNext()) { - if(colPosition >= xValues.size()) - break; - Number xValue = xValues.get(colPosition); - if(xValue.equals(Double.NaN)) { - lineIterator.next(); - colPosition++; - continue; - } - - // Find out the y value - Number yValue; - try { - yValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - colPosition++; - continue; - } - - // Add the new point - Point newPoint = new Point(xValue.doubleValue(), yValue.doubleValue()); - pointList.insertSorted(newPoint); - colPosition++; - } - } - - return pointListList; - } - - @Override - public PointListList parseAsVerticalDataSets(List<? extends List<String>> csvData) { - PointListList pointListList = new PointListList(); - Iterator<? extends List<String>> rowIterator = csvData.iterator(); - - if(!rowIterator.hasNext()) - return pointListList; - - Iterator<String> lineIterator = rowIterator.next().iterator(); - - // Move the iterator to the first title - if(!lineIterator.hasNext()) - return pointListList; - lineIterator.next(); - if(!lineIterator.hasNext()) - return pointListList; - - // Add a PointList for each title - while(lineIterator.hasNext()) { - PointList pointList = new PointList(); - pointList.setName(lineIterator.next()); - pointListList.add(pointList); - } - - // Add the data - while(rowIterator.hasNext()) { - lineIterator = rowIterator.next().iterator(); - if(!lineIterator.hasNext()) - continue; - - // Find out the x value - Number xValue; - try { - xValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - continue; - } - - // Find out the y values and add the points to the respective lists - int currentDataSet = 0; - while(lineIterator.hasNext()) { - Number yValue; - try { - yValue = Constants.numberFormat.parse(lineIterator.next()); - } catch (ParseException e) { - currentDataSet++; - continue; - } - - Point newPoint = new Point(xValue.doubleValue(), yValue.doubleValue()); - addPointToPointListList(pointListList, currentDataSet, newPoint); - currentDataSet++; - } - - } - - return pointListList; - } - -} diff --git a/src/main/java/parser/MetricAxis.java b/src/main/java/parser/MetricAxis.java deleted file mode 100644 index f806a3d111fa8393886efb3fbb85df05b913d2fe..0000000000000000000000000000000000000000 --- a/src/main/java/parser/MetricAxis.java +++ /dev/null @@ -1,132 +0,0 @@ -package parser; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author Gregor Harlan, Jens Bornschein Idea and supervising by Jens - * Bornschein jens.bornschein@tu-dresden.de Copyright by Technische - * Universität Dresden / MCI 2014 - * - */ -public class MetricAxis extends Axis { - public final double atom; - public final int atomCount; - public final List<Double> intervalSteps; - - public MetricAxis(Range axisRange, double size, String title, String unit) { - - // Set the label offsets - super(-5, 20, -10, 5, 0, title, unit); - - boolean finished = false; - double interval = 0; - range = new Range(0, 0); - range.setName(axisRange.getName()); - int dimensionExp; - double dimension; - double factor; - do { - /* - * Calculate how many tics there can maximally be without violating - * the minimal distance of grid lines constraint. - */ - int maxTics = (int) (size / Constants.MIN_GRID_DISTANCE); - // Calculate which interval (virtual) the tics must minimally have. - interval = axisRange.distance() / maxTics; - dimensionExp = 0; - int direction = interval < 1 ? -1 : 1; - while (direction * 0.5 * Math.pow(10, dimensionExp) < direction * interval) { - dimensionExp += direction; - } - if (direction == 1) { - dimensionExp--; - } - dimension = Math.pow(10, dimensionExp); - factor = getFactorForIntervalAndDimension(interval, dimension); - finished = true; - interval = factor * dimension * 2; - range.setFrom(((int) (axisRange.getFrom() / interval)) * interval); - range.setTo(((int) (axisRange.getTo() / interval)) * interval); - if (range.getFrom() > axisRange.getFrom()) { - axisRange.setFrom(range.getFrom() - interval); - finished = false; - } - if (range.getTo() < axisRange.getTo()) { - axisRange.setTo(range.getTo() + interval); - finished = false; - } - } while (!finished); - - gridInterval = interval; - - ticInterval = interval; // TODO set this to 2 * interval if needed, maybe create an option - ticRange = new Range(Math.ceil(range.getFrom() / ticInterval) * ticInterval, - Math.floor(range.getTo() / ticInterval) * ticInterval); - - labelRange = ticRange; - labelInterval = ticInterval * 2; - - decimalFormat.setMaximumFractionDigits(Math.max(0, -dimensionExp + 2)); - - atom = dimension / 100; - atomCount = (int) (range.distance() / atom + 1); - - intervalSteps = new ArrayList<>(); - calculateIntervalSteps(dimension, factor); - } - - @Override - public String formatForAxisLabel(double value) { - String str = decimalFormat.format(value); - return "-0".equals(str) ? "0" : str; - } - - @Override - public String formatForAxisAudioLabel(double value) { - return formatForAxisLabel(value); - } - - @Override - public String formatForSymbolAudioLabel(double value) { - return formatForAxisLabel(value); - } - - /** - * @param dimension - * @param factor - */ - private void calculateIntervalSteps(double dimension, double factor) { - int i = 0; - if (Math.abs(factor - 2.5) < Constants.EPSILON) { - intervalSteps.add(i++, 2.5 * dimension); - intervalSteps.add(i++, dimension); - } else if (Math.abs(factor - 1) < Constants.EPSILON) { - intervalSteps.add(i++, dimension); - } - - intervalSteps.add(i++, 0.5 * dimension); - intervalSteps.add(i++, 0.1 * dimension); - intervalSteps.add(i++, 0.05 * dimension); - intervalSteps.add(i, 0.01 * dimension); - } - - /** - * @param interval - * @param dimension - * @return the calculated factor - */ - private double getFactorForIntervalAndDimension(double interval, double dimension) { - double factor; - if (interval > dimension) { - factor = 2.5; - } else if (interval > 0.5 * dimension) { - factor = 1; - } else { - factor = 0.5; - } - return factor; - } - -} diff --git a/src/main/java/parser/NominalAxis.java b/src/main/java/parser/NominalAxis.java deleted file mode 100644 index 2762d5f3cb0f88ba817ad50a62e4bf098089f85c..0000000000000000000000000000000000000000 --- a/src/main/java/parser/NominalAxis.java +++ /dev/null @@ -1,88 +0,0 @@ -package parser; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * Axis for displaying nominals. - */ -public class NominalAxis extends Axis { - - static final Logger log = LoggerFactory.getLogger(NominalAxis.class); - - /** - * The categories displayed on the Axis in order. - */ - protected List<String> categories; - - /** - * The nominal axis gets constructed so that each tic corresponds to one - * category. The tics are however shown - * - * @param categories - * @param size - * @param unit - */ - public NominalAxis(List<String> categories, double size, String unit) { - // TODO: upon implementation of vertical nominal axes set the values - // correctly - super(Constants.CHAR_WIDTH, 15, -10, -Constants.CHAR_WIDTH, 0.5, null, unit); - - this.categories = categories; - - double categorySize = size / categories.size(); - int maxLabelLength = 0; - for (String label : categories) - if (label.length() > maxLabelLength) - maxLabelLength = label.length(); - if (categorySize < Constants.CHAR_WIDTH * (maxLabelLength + 1)) { - log.warn( - "Der Platz reicht nicht aus, um Achsenbeschriftungen darzustellen. Die längste Beschriftung hat eine Länge von " - + maxLabelLength + " Zeichen."); - } - - // Subdivide the axis into sections for each category - ticInterval = 1; - gridInterval = 1; - labelInterval = 1; - - ticRange = new Range(0, categories.size()); - range = ticRange; - labelRange = new Range(0, categories.size() - 1); - - } - - @Override - public String formatForAxisLabel(double value) { - int categoryNumber = (int) Math.round(value); - if (categories.size() <= categoryNumber || categoryNumber < 0) - return null; - // throw new IllegalArgumentException("The selected category does not - // exist"); - return categories.get(categoryNumber); - } - - @Override - public String formatForAxisAudioLabel(double value) { - int categoryNumber = (int) Math.round(value); - - if (categoryNumber == 0) { - return "|" + categories.get(categoryNumber); - } else if (categoryNumber == categories.size()) { - return categories.get(categoryNumber - 1) + "|"; - } else if (categoryNumber > 0 && categoryNumber < categories.size()) { - return categories.get(categoryNumber - 1) + "|" + categories.get(categoryNumber); - } else { - return null; - } - } - - @Override - public String formatForSymbolAudioLabel(double value) { - return formatForAxisLabel(value); - } - -} diff --git a/src/main/java/parser/Point.java b/src/main/java/parser/Point.java deleted file mode 100644 index 8add0af1c1295ad58f103ca05958ef0eed5e1f0f..0000000000000000000000000000000000000000 --- a/src/main/java/parser/Point.java +++ /dev/null @@ -1,242 +0,0 @@ -package parser; - -import org.w3c.dom.Element; - -import com.beust.jcommander.IStringConverter; - - -/** - * A point in a coordinate system specified by an x and y coordinate. Can also - * have a name and an SVG symbol. Provides helper methods, e.g. for calculating - * the distance between two points. - * - * @author Gregor Harlan Idea and supervising by Jens Bornschein - * jens.bornschein@tu-dresden.de Copyright by Technische Universität - * Dresden / MCI 2014 - * - */ -public class Point implements Comparable<Point> { - - protected double x; - protected double y; - protected String name; - protected Element symbol; - - /** - * Copy constructor - * - * @param otherPoint - * the point to copy - */ - public Point(Point otherPoint) { - this(otherPoint.getX(), otherPoint.getY(), otherPoint.getName(), - otherPoint.getSymbol() != null ? (Element) otherPoint.getSymbol().cloneNode(true) : null); - } - - /** - * Represents a two dimensional Point in the plot - * - * @param x - * | x (horizontal) position of the point - * @param y - * | y (vertical) position of the point - */ - public Point(double x, double y) { - this(x, y, "", null); - } - - /** - * Represents a two dimensional Point in the plot - * - * @param x - * | x (horizontal) position of the point - * @param y - * | y (vertical) position of the point - * @param name - * | the name of the point - */ - public Point(double x, double y, String name) { - this(x, y, name, null); - } - - /** - * Represents a two dimensional Point in the plot - * - * @param x - * | x (horizontal) position of the point - * @param y - * | y (vertical) position of the point - * @param symbol - * | the symbol to use for the point - */ - public Point(double x, double y, Element symbol) { - this(x, y, "", symbol); - } - - /** - * Represents a two dimensional Point in the plot - * - * @param x - * | x (horizontal) position of the point - * @param y - * | y (vertical) position of the point - * @param name - * | the name of the point - * @param symbol - * | the symbol to use for the point - */ - public Point(double x, double y, String name, Element symbol) { - this.setX(x); - this.setY(y); - this.setName(name); - this.setSymbol(symbol); - } - - /** - * Move the point - * - * @param dx - * | movement in x (horizontal) direction - * @param dy - * | movement in y (vertical) direction - */ - public void translate(double dx, double dy) { - setX(getX() + dx); - setY(getY() + dy); - } - - /** - * formats the x value as an svg compatible decimal value. - * - * @return - */ - public String x() { - return SvgTools.format2svg(getX()); - } - - /** - * formats the y value as an svg compatible decimal value. - * - * @return - */ - public String y() { - return SvgTools.format2svg(getY()); - } - - @Override - /** - * formats the x and y values as svg compatible decimal values and combine - * them by a comma. - * - * @return x,y - */ - public String toString() { - return x() + "," + y(); - } - - /** - * computes the two dimensional euclidean distance of two points. - * - * @param other - * | second point - * @return the two dimensional euclidean distance between this and the other - * point. - */ - public double distance(Point other) { - return Math.sqrt(Math.pow(other.getX() - getX(), 2) + Math.pow(other.getY() - getY(), 2)); - } - - public static class Converter implements IStringConverter<Point> { - /** - * Convert a formatted string to a point. The format is: - * {@code [<x>][,<y>]} Omitted values will default to 0. - * - * @param value - * | formatted string - */ - @Override - public Point convert(String value) { - String[] s = value.split(","); - return new Point(s.length > 0 ? Double.parseDouble(s[0]) : 0, s.length > 1 ? Double.parseDouble(s[1]) : 0); - } - } - - /** - * Compares with x priority. Returns -1 if p2 is null. - * - * @param p2 - * | other point - * @return - */ - @Override - public int compareTo(Point p2) { - if (p2 != null) { - if (Math.abs(p2.getX() - getX()) < Constants.EPSILON) { - return getY() < p2.getY() ? -1 : 1; - } else - return getX() < p2.getX() ? -1 : 1; - } - return -1; - } - - /** - * Compare the y values of two points. Returns -1 if p2 is null. - * - * @param p2 - * | other point - * @return - */ - public int compareToY(Point p2) { - if (p2 != null) { - return getY() < p2.getY() ? -1 : 1; - } - return -1; - } - - /** - * Compare the x values of two points. Returns -1 if p2 is null. - * - * @param p2 - * | other point - * @return - */ - public int compareToX(Point p2) { - if (p2 != null) { - return getX() < p2.getX() ? -1 : 1; - } - return -1; - } - - public double getX() { - return x; - } - - public void setX(double x) { - this.x = x; - } - - public double getY() { - return y; - } - - public void setY(double y) { - this.y = y; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Element getSymbol() { - return symbol; - } - - public void setSymbol(Element symbol) { - this.symbol = symbol; - } - -} diff --git a/src/main/java/parser/PointListList.java b/src/main/java/parser/PointListList.java deleted file mode 100644 index aed9db9fdcc6019b941c0c87594ad445c9621f6f..0000000000000000000000000000000000000000 --- a/src/main/java/parser/PointListList.java +++ /dev/null @@ -1,245 +0,0 @@ -package parser; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.beust.jcommander.IStringConverter; - -/** - * - * @author Gregor Harlan, Jens Bornschein Idea and supervising by Jens - * Bornschein jens.bornschein@tu-dresden.de Copyright by Technische - * Universität Dresden / MCI 2014 - * - */ -public class PointListList extends ArrayList<PointListList.PointList> { - - private static final long serialVersionUID = 6902232865786868851L; - protected Double maxX = Double.NEGATIVE_INFINITY; - protected Double maxY = Double.NEGATIVE_INFINITY; - protected Double minX = Double.POSITIVE_INFINITY; - protected Double minY = Double.POSITIVE_INFINITY; - - public XType getXType() { - return XType.METRIC; - } - - public PointListList() { - this(""); - } - - public PointListList(String pointLists) { - - if (pointLists == null || pointLists.isEmpty()) - return; - - // TODO: load from file - - // pointLists = pointLists.replaceAll("[^\\d.,^\\s+,^\\{^\\}^-]", ""); - String[] lists = pointLists.split("\\}"); - for (String l : lists) { - PointList pl = new PointList(l); - if (!pl.isEmpty()) { - this.add(pl); - } - } - } - - @Override - public boolean add(PointList pl) { - boolean success = super.add(pl); - updateMinMax(); - return success; - } - - public boolean add(List<Point> points) { - PointList pl = new PointList(points); - return add(pl); - } - - public void updateMinMax() { - for(PointList checkPl : this) { - maxX = Math.max(getMaxX(), checkPl.getMaxX()); - maxY = Math.max(getMaxY(), checkPl.getMaxY()); - minX = Math.min(getMinX(), checkPl.getMinX()); - minY = Math.min(getMinY(), checkPl.getMinY()); - } - } - - public double getMaxX() { - return maxX; - } - - public double getMaxY() { - return maxY; - } - - public double getMinX() { - return minX; - } - - public double getMinY() { - return minY; - } - - public boolean hasValidMinMaxValues() { - return maxX > minX && maxY > minY; - } - - public static class Converter implements IStringConverter<PointListList> { - @Override - public PointListList convert(String value) { - return new PointListList(value); - } - } - - /** - * List of Points including max values - * - * @author Jens Bornschein - * - */ - public static class PointList extends ArrayList<Point> { - - private static final long serialVersionUID = -2318768874799315111L; - private Double maxX = Double.NEGATIVE_INFINITY; - private Double maxY = Double.NEGATIVE_INFINITY; - private Double minX = Double.POSITIVE_INFINITY; - private Double minY = Double.POSITIVE_INFINITY; - private String name = ""; - - public PointList(List<Point> points) { - if (points != null && !points.isEmpty()) { - for (Point p : points) { - this.insertSorted(p); - } - } - } - - public PointList(String points) { - if (points == null || points.isEmpty()) - return; - - String[] pl = points.split("::"); - - if (pl != null && pl.length > 0) { - - String pts; - if (pl.length > 1) { - setName(pl[0].trim()); - pts = pl[1].replaceAll("[^\\d.,^\\s+,^-]", ""); - } else { - pts = pl[0].replaceAll("[^\\d.,^\\s+,^-]", ""); - } - String[] s = pts.split("\\s+"); - - for (String string : s) { - if (string != null && !string.isEmpty()) { - Point p = (new Point.Converter()).convert(string); - this.insertSorted(p); - } - } - } - } - - public PointList() { - this(""); - } - - public boolean insertSorted(Point p) { - maxX = Math.max(getMaxX(), p.getX()); - maxY = Math.max(getMaxY(), p.getY()); - minX = Math.min(getMinX(), p.getX()); - minY = Math.min(getMinY(), p.getY()); - boolean returnVal = super.add(p); - - Comparable<Point> cmp = (Comparable<Point>) p; - for (int i = size()-1; i > 0 && cmp.compareTo(get(i-1)) < 0; i--) - Collections.swap(this, i, i-1); - return returnVal; - } - - - @Deprecated - public void add(int index, Point element) { -// throw new UnsupportedOperationException("Only insertions via insertSorted are allowed"); - this.insertSorted(element); - } - - @Deprecated - public boolean add(Point e) { -// throw new UnsupportedOperationException("Only insertions via insertSorted are allowed"); - return this.insertSorted(e); - } - - public double getMaxX() { - return maxX; - } - - public double getMaxY() { - return maxY; - } - - public double getMinX() { - return minX; - } - - public double getMinY() { - return minY; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - /** - * Gets the first maximum of the data set. - * TODO implement multiple maxima with a proper string representation - * @return first maximum point - */ - public Point getFirstMaximum() { - if(this.isEmpty()) - return null; - - Point maxPoint = get(0); - - for(Point p : this) { - if(maxPoint.getY() < p.getY()) - maxPoint = p; - } - - return maxPoint; - } - - /** - * Gets the first minimum of the data set. - * TODO implement multiple minimum with a proper string representation - * @return first minimum point - */ - public Point getFirstMinimum() { - if(this.isEmpty()) - return null; - - Point minPoint = get(0); - - for(Point p : this) { - if(minPoint.getY() > p.getY()) - minPoint = p; - } - - return minPoint; - } - - public class Converter implements IStringConverter<PointList> { - @Override - public PointList convert(String value) { - return new PointList(value.trim()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/parser/Range.java b/src/main/java/parser/Range.java deleted file mode 100644 index ddd99be38c84303ffed73b2ac56deff5999e8be0..0000000000000000000000000000000000000000 --- a/src/main/java/parser/Range.java +++ /dev/null @@ -1,117 +0,0 @@ -package parser; - -import com.beust.jcommander.IStringConverter; -/** - * - * @author Gregor Harlan, Jens Bornschein - * Idea and supervising by Jens Bornschein jens.bornschein@tu-dresden.de - * Copyright by Technische Universität Dresden / MCI 2014 - * - */ -public class Range { - /** Start of the range */ - private double from; - /** End of the range */ - private double to; - - private String name; - - /** - * Constructor with name. - * @param from | start of the range - * @param to | end of the range - * @param name - */ - public Range(double from, double to, String name) { - this.from = from; - this.to = to; - this.name = name; - } - - /** - * Constructor without name. - * @param from | start of the range - * @param to | end of the range - */ - public Range(double from, double to) { - this(from, to, ""); - } - - /** - * Calculates the distance covered by the range. - * @return distance - */ - public double distance() { - return to - from; - } - - @Override - public String toString() { - return name + " " + from + ":" + to; - } - - /** - * Converter class for parsing ranges from strings. - */ - public static class Converter implements IStringConverter<Range> { - /** - * Converts a range specified by a string to a {@link Range} instance. - * The syntax is: {@code [["]<name>["]::]<from>:<to>[:<name>]}. - * The second name parameter is preferred. - * The from and to parameters should be parsable as Double. - * - * @param value | correctly formatted range string - */ - @Override - public Range convert(String value) { - String[] parts = value.split("::"); - String[] s; - String name = ""; - - // Extract the name if specified and remove quotations - if(parts.length > 1){ - name = parts[0].replace("\"", "").trim(); - s = parts[1].split(":"); - }else{ - s = parts[0].split(":"); - } - - // There were not enough parameters specified. - if (s.length < 2) - return new Range(-8, 8); - - /* - * If there are two parameters, use the first name string, - * if there are more, use the second one. - */ - return s.length > 2 ? new Range(Double.parseDouble(s[0]), - Double.parseDouble(s[1]), s[2]) : new Range( - Double.parseDouble(s[0]), Double.parseDouble(s[1]), name); - } - - } - - public double getFrom() { - return from; - } - - public void setFrom(double from) { - this.from = from; - } - - public double getTo() { - return to; - } - - public void setTo(double to) { - this.to = to; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/src/main/java/parser/SvgTools.java b/src/main/java/parser/SvgTools.java deleted file mode 100644 index 881ef6b322fa51534c4c2b3949d33d0458760a8f..0000000000000000000000000000000000000000 --- a/src/main/java/parser/SvgTools.java +++ /dev/null @@ -1,111 +0,0 @@ -package parser; - -import java.text.MessageFormat; - -public class SvgTools { - private SvgTools() { - } - - /** - * Format a number for svg usage according to the constant decimalFormat - * - * @param value - * @return - */ - public static String format2svg(double value) { - return Constants.decimalFormat.format(value); - } - - /** - * Formats an additional Name of an object. Checks if the name is set. If - * name is set, the name is packed into brackets and prepend with an - * whitespace - * - * @param name - * | optional name of an object or NULL - * @return empty string or the name of the object packed into brackets and - * prepend with a whitespace e.g. ' (optional name)' - */ - public static String formatName(String name) { - return (name == null || name.isEmpty()) ? "" : " (" + name + ")"; - } - - /** - * Try to translate a key in the localized version defined in the - * PropertyResourceBundle file. - * - * @param key - * | PropertyResourceBundle key - * @param arguments - * | arguments that should fill the placeholder in the returned - * PropertyResourceBundle value - * @return a localized string for the given PropertyResourceBundle key, - * filled with the set arguments - */ - public static String translate(String key, Object... arguments) { - return MessageFormat.format(Constants.bundle.getString(key), arguments); - } - - /** - * Try to translate a key in the localized version defined in the - * PropertyResourceBundle file. This function is optimized for differing - * sentences depending on the amount of results. - * - * @param key - * | PropertyResourceBundle key - * @param arguments - * | arguments that should fill the placeholder in the returned - * PropertyResourceBundle value. The last argument gives the - * count and decide which value will be returned. - * @return a localized string for the given amount depending - * PropertyResourceBundle key, filled with the set arguments - */ - public static String translateN(String key, Object... arguments) { - int last = (int) arguments[arguments.length - 1]; - String suffix = last == 0 ? "_0" : last == 1 ? "_1" : "_n"; - return translate(key + suffix, arguments); - } - - /** - * Formats a Point that it is optimized for textual output and packed into - * the caption with brackets. E.g. E(x | y) - * - * @param cs - * the coordinate system - * @param point - * The point that should be transformed into a textual - * representation - * @param cap - * The caption string without brackets - * @return formated string for the point with '/' as delimiter if now - * caption is set, otherwise packed in the caption with brackets and - * the '|' as delimiter - */ - public static String formatForText(CoordinateSystem cs, Point point, String cap) { - String p = cs.formatX(point.getX()) + " | " + cs.formatY(point.getY()); - String capTrimmed = cap.trim(); - return (capTrimmed != null && !capTrimmed.isEmpty()) ? capTrimmed + "(" + p + ")" : p; - } - - /** - * Try to translate the function index into a continuous literal starting - * with the char 'f'. If the given index is not valid it returns the name as - * a combination of 'f' + the given number. - * - * @param f - * | the index if the function - * @return a literal representation to the given function index e.g. 'f', - * 'g', 'h' or 'f1000'. - */ - public static String getFunctionName(int f) { - if (f < 0 || f > (Constants.FN_LIST.size() - 1)) - return "f" + f; - return Constants.FN_LIST.get(f); - } - - public static String getPointName(int p) { - if (p < 0 || p > (Constants.PN_LIST.size() - 1)) - return "P" + p; - return Constants.PN_LIST.get(p); - } -} diff --git a/src/main/java/parser/XType.java b/src/main/java/parser/XType.java deleted file mode 100644 index a162d519fd7365ec95f2efaf5025a5451d33343c..0000000000000000000000000000000000000000 --- a/src/main/java/parser/XType.java +++ /dev/null @@ -1,8 +0,0 @@ -package parser; - -/** - * Determines whether the x values are metric or categorial. - */ -public enum XType { - METRIC, CATEGORIAL -} \ No newline at end of file diff --git a/src/main/java/parser/package-info.java b/src/main/java/parser/package-info.java deleted file mode 100644 index c0234d3ba7e185f5c06bc21388a4c6296f1586f3..0000000000000000000000000000000000000000 --- a/src/main/java/parser/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * CSV parsing - */ -package parser; \ No newline at end of file