diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/SystemOut.java b/src/SystemOut.java deleted file mode 100644 index e07e546..0000000 --- a/src/SystemOut.java +++ /dev/null @@ -1,28 +0,0 @@ -import java.util.ArrayList; - -public class SystemOut { - private boolean formatRaw; - private int columnWidth; - - public void print(ArrayList text) { - if (formatRaw) { - for(int counter = 0; counter < text.size(); counter++) { - System.out.println("<" + counter + ">: <" + text.get(counter) + ">"); - } - - } - else { - - } - } - - - public void formatRaw() { - formatRaw = true; - } - - public void formatFix(int length) { - formatRaw = false; - columnWidth = length; - } -} diff --git a/src/TextOutput.java b/src/TextOutput.java new file mode 100644 index 0000000..e049478 --- /dev/null +++ b/src/TextOutput.java @@ -0,0 +1,67 @@ +import java.util.ArrayList; + +public class TextOutput { + private boolean formatRaw; + private int columnWidth; + + public void print(ArrayList text) { + if (formatRaw) { + for (int counter = 0; counter < text.size(); counter++) { + System.out.println("<" + (counter + 1) + ">: <" + text.get(counter) + ">"); + } + } + else { + for (String paragraph : text) { + String[] words = paragraph.split(" "); + int currentLength = 0; + for(String word: words) { + if(word.length() > columnWidth){ + String[] letters = word.split(""); + int letterLenght = letters.length; + int lettersPrinted = 0; + do{ + System.out.println(); + currentLength = 0; + for(int i=0; i< columnWidth; i++) { + if(letterLenght > 0) { + System.out.print(letters[lettersPrinted]); + letterLenght--; + lettersPrinted++; + currentLength++; + } + } + } + while (letterLenght>columnWidth); + + } + + else { + if(word.length() >= columnWidth - currentLength){ + System.out.println(); + currentLength = 0; + } + System.out.print(word + " "); + currentLength += word.length() + 1; + + + + } + } + + + + + + } + } + } + + public void formatRaw() { + formatRaw = true; + } + + public void formatFix(int length) { + formatRaw = false; + columnWidth = length; + } +} diff --git a/test/SystemOutTest.java b/test/SystemOutTest.java deleted file mode 100644 index cdcde17..0000000 --- a/test/SystemOutTest.java +++ /dev/null @@ -1,8 +0,0 @@ -import static org.junit.jupiter.api.Assertions.*; - -class SystemOutTest { - - public void print(){ - - } -} \ No newline at end of file diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java new file mode 100644 index 0000000..f7dd6b4 --- /dev/null +++ b/test/TextOutputTest.java @@ -0,0 +1,30 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.swing.*; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class TextOutputTest { + TextOutput textOutput; + ArrayList text; + + @BeforeEach + public void setup(){ + textOutput = new TextOutput(); + textOutput.formatFix(9); + //textOutput.formatRaw(); + text = new ArrayList<>(); + text.add("123 45678 "); + text.add("123456789"); + text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText"); + } + + @Test + public void print(){ + textOutput.print(text); + + } +} \ No newline at end of file