diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..838458f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ \ No newline at end of file diff --git a/build/built-jar.properties b/build/built-jar.properties new file mode 100644 index 0000000..ebd1c18 --- /dev/null +++ b/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2016 13:30:07 +0530 + + +D\:\\OSS\\Hacktoberfest\\Random-Text-Generator= diff --git a/build/classes/random/text/generator/Gui$1.class b/build/classes/random/text/generator/Gui$1.class new file mode 100644 index 0000000..e0d4e22 Binary files /dev/null and b/build/classes/random/text/generator/Gui$1.class differ diff --git a/build/classes/random/text/generator/Gui$2.class b/build/classes/random/text/generator/Gui$2.class new file mode 100644 index 0000000..70fefa5 Binary files /dev/null and b/build/classes/random/text/generator/Gui$2.class differ diff --git a/build/classes/random/text/generator/Gui.class b/build/classes/random/text/generator/Gui.class new file mode 100644 index 0000000..670237d Binary files /dev/null and b/build/classes/random/text/generator/Gui.class differ diff --git a/build/classes/random/text/generator/RandomTextGenerator.class b/build/classes/random/text/generator/RandomTextGenerator.class index 63b7168..0fd006a 100644 Binary files a/build/classes/random/text/generator/RandomTextGenerator.class and b/build/classes/random/text/generator/RandomTextGenerator.class differ diff --git a/build/classes/random/text/generator/SpaceEfficientGenerator.class b/build/classes/random/text/generator/SpaceEfficientGenerator.class index 41775ae..e158e81 100644 Binary files a/build/classes/random/text/generator/SpaceEfficientGenerator.class and b/build/classes/random/text/generator/SpaceEfficientGenerator.class differ diff --git a/build/classes/random/text/generator/SpeedEfficientGenerator.class b/build/classes/random/text/generator/SpeedEfficientGenerator.class index 58b6dfb..8a9b6a1 100644 Binary files a/build/classes/random/text/generator/SpeedEfficientGenerator.class and b/build/classes/random/text/generator/SpeedEfficientGenerator.class differ diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 08bbc8d..50acb60 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,2 +1,2 @@ compile.on.save=true -user.properties.file=C:\\Users\\Ma Jing\\AppData\\Roaming\\NetBeans\\8.1\\build.properties +user.properties.file=C:\\Users\\Work\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 5403ce2..7a83fe9 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -3,7 +3,11 @@ - file:/C:/Users/Ma%20Jing/Documents/NetBeansProjects/Random%20Text%20Generator/src/random/text/generator/SpaceEfficientGenerator.java + file:/D:/OSS/Hacktoberfest/Random-Text-Generator/src/random/text/generator/SpaceEfficientGenerator.java + file:/D:/OSS/Hacktoberfest/Random-Text-Generator/src/random/text/generator/SpeedEfficientGenerator.java + file:/D:/OSS/Hacktoberfest/Random-Text-Generator/src/random/text/generator/RandomTextGenerator.java + file:/D:/OSS/Hacktoberfest/Random-Text-Generator/src/random/text/generator/WordSet.java + file:/D:/OSS/Hacktoberfest/Random-Text-Generator/src/random/text/generator/Gui.java diff --git a/src/random/text/generator/Gui.java b/src/random/text/generator/Gui.java index 719b426..f9e5a08 100644 --- a/src/random/text/generator/Gui.java +++ b/src/random/text/generator/Gui.java @@ -2,10 +2,13 @@ import java.awt.Component; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @@ -13,6 +16,9 @@ public class Gui { + private RandomTextGenerator generator; + //private static final int DEFAULT_WORD_AMOUNT; + public Gui() { init(); } @@ -28,18 +34,57 @@ public void init() { panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); frame.add(panel); - JLabel label = new JLabel("Click the button on the bottom!"); - label.setAlignmentX(Component.CENTER_ALIGNMENT); - panel.add(label); - - JTextArea textField = new JTextArea(5, 5); - textField.setText("Not randomly generated text."); - textField.setAlignmentX(Component.CENTER_ALIGNMENT); - panel.add(textField); + JLabel headerLabel = new JLabel("Click the button on the bottom!"); + headerLabel.setAlignmentX(Component.CENTER_ALIGNMENT); + panel.add(headerLabel); + + JComboBox generatorSelectBox = new JComboBox<>(); + generatorSelectBox.addItem("SpaceEfficientGenerator"); + generatorSelectBox.addItem("SpeedEfficientGenerator"); + generatorSelectBox.setAlignmentX(Component.RIGHT_ALIGNMENT); + panel.add(generatorSelectBox); + + JTextArea inputTextArea = new JTextArea(5, 5); + inputTextArea.setText(RandomTextGenerator.getDefaultText()); + inputTextArea.setAlignmentX(Component.CENTER_ALIGNMENT); + inputTextArea.setLineWrap(true); + inputTextArea.setWrapStyleWord(true); + panel.add(inputTextArea); + + JTextArea outputTextArea = new JTextArea(5, 5); + outputTextArea.setText("Result"); + outputTextArea.setEditable(false); + outputTextArea.setAlignmentX(Component.CENTER_ALIGNMENT); + outputTextArea.setLineWrap(true); + outputTextArea.setWrapStyleWord(true); + panel.add(outputTextArea); JButton generateTextButton = new JButton("Generate text"); generateTextButton.setAlignmentX(Component.CENTER_ALIGNMENT); panel.add(generateTextButton); + + JLabel executionTimeLabel = new JLabel(); + panel.add(executionTimeLabel); + + generateTextButton.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + String generatorType = (String)generatorSelectBox.getSelectedItem(); + String inputText = inputTextArea.getText(); + switch(generatorType){ + case "SpeedEfficientGenerator": + generator = new SpeedEfficientGenerator(inputText); + break; + default: + generator = new SpaceEfficientGenerator(inputText); + } + long startTime = System.currentTimeMillis(); + outputTextArea.setText(generator.generateText(200)); + long stopTime = System.currentTimeMillis(); + long elapsedTime = stopTime - startTime; + executionTimeLabel.setText("Time taken: " + elapsedTime + "ms"); + } + }); frame.pack(); frame.setLocationRelativeTo(null); diff --git a/src/random/text/generator/RandomTextGenerator.java b/src/random/text/generator/RandomTextGenerator.java index 7088860..acff3b5 100644 --- a/src/random/text/generator/RandomTextGenerator.java +++ b/src/random/text/generator/RandomTextGenerator.java @@ -10,7 +10,21 @@ * to form a new text. This technique is called the Markov chain. */ public abstract class RandomTextGenerator { - + protected static final String defaultText = "She is into superstitions, black cats and voodoo dolls. " + + "I feel a premonition that girl is gonna make me fall. " + + "She is into new sensations, new kicks in the candle light. " + + "She has got a new addiction for every day and night. " + + "She will make you take your clothes off and go dancing in the rain. " + + "She will make you live her crazy life but she will take away your pain like a bullet to your brain. " + + "Come On! Upside, inside out she is livin la vida loca. " + + "She will push and pull you down, livin la vida loca. " + + "Her lips are devil red and her skin is the color mocha. " + + "She will wear you out livin la vida loca. Come On! Livin la vida loca, Come on! " + + "She is livin la vida loca. Woke up in New York City in a funky cheap hotel. " + + "She took my heart and she took my money. She must have slipped me a sleeping pill. " + + "She never drinks the water and makes you order French Champagne. " + + "Once you have had a taste of her you will never be the same. " + + "Yeah, she will make you go insane."; public final String[] text; public final int SETSIZE = 3; @@ -18,6 +32,10 @@ public RandomTextGenerator(String text) { this.text = text.split("\\s+"); } + public static String getDefaultText(){ + return defaultText; + } + public String generateText(int wordAmount) { if (wordAmount <= SETSIZE) return null; diff --git a/src/random/text/generator/SpaceEfficientGenerator.java b/src/random/text/generator/SpaceEfficientGenerator.java index 6a41e3f..3ae39f8 100644 --- a/src/random/text/generator/SpaceEfficientGenerator.java +++ b/src/random/text/generator/SpaceEfficientGenerator.java @@ -34,21 +34,6 @@ public ArrayList getFollowingWords(WordSet set) { * @param args the command line arguments */ public static void main(String[] args) { - final String defaultText = "She is into superstitions, black cats and voodoo dolls. " - + "I feel a premonition that girl is gonna make me fall. " - + "She is into new sensations, new kicks in the candle light. " - + "She has got a new addiction for every day and night. " - + "She will make you take your clothes off and go dancing in the rain. " - + "She will make you live her crazy life but she will take away your pain like a bullet to your brain. " - + "Come On! Upside, inside out she is livin la vida loca. " - + "She will push and pull you down, livin la vida loca. " - + "Her lips are devil red and her skin is the color mocha. " - + "She will wear you out livin la vida loca. Come On! Livin la vida loca, Come on! " - + "She is livin la vida loca. Woke up in New York City in a funky cheap hotel. " - + "She took my heart and she took my money. She must have slipped me a sleeping pill. " - + "She never drinks the water and makes you order French Champagne. " - + "Once you have had a taste of her you will never be the same. " - + "Yeah, she will make you go insane."; SpaceEfficientGenerator gen = new SpaceEfficientGenerator(defaultText); System.out.println(gen.generateText(100)); } diff --git a/src/random/text/generator/SpeedEfficientGenerator.java b/src/random/text/generator/SpeedEfficientGenerator.java index 66e973c..bbf1076 100644 --- a/src/random/text/generator/SpeedEfficientGenerator.java +++ b/src/random/text/generator/SpeedEfficientGenerator.java @@ -52,21 +52,6 @@ public ArrayList getFollowingWords(WordSet set) { * @param args the command line arguments */ public static void main(String[] args) { - final String defaultText = "She is into superstitions, black cats and voodoo dolls. " - + "I feel a premonition that girl is gonna make me fall. " - + "She is into new sensations, new kicks in the candle light. " - + "She has got a new addiction for every day and night. " - + "She will make you take your clothes off and go dancing in the rain. " - + "She will make you live her crazy life but she will take away your pain like a bullet to your brain. " - + "Come On! Upside, inside out she is livin la vida loca. " - + "She will push and pull you down, livin la vida loca. " - + "Her lips are devil red and her skin is the color mocha. " - + "She will wear you out livin la vida loca. Come On! Livin la vida loca, Come on! " - + "She is livin la vida loca. Woke up in New York City in a funky cheap hotel. " - + "She took my heart and she took my money. She must have slipped me a sleeping pill. " - + "She never drinks the water and makes you order French Champagne. " - + "Once you have had a taste of her you will never be the same. " - + "Yeah, she will make you go insane."; SpeedEfficientGenerator gen = new SpeedEfficientGenerator(defaultText); // Uncomment the line below to print all the WordSets and their following words // gen.printWordMap();