Added a lot of stuff.

This commit is contained in:
Andrew Lalis 2020-03-10 17:40:47 +01:00
parent 54033fc05f
commit ff4ed594b2
7 changed files with 483 additions and 0 deletions

31
pom.xml
View File

@ -8,5 +8,36 @@
<artifactId>SQL-Assesser-2</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- SQLite3 Driver -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.30.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package com.gyrobian;
import com.gyrobian.view.Window;
/**
* The main class of the application.
*/
public class SQLAssesser2 {
public static void main(String[] args) {
Window window = new Window();
window.init();
}
}

View File

@ -0,0 +1,26 @@
package com.gyrobian.listener;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Listener for when a user clicks a button to clear a text component.
*/
public class ClearTextComponentListener implements ActionListener {
private final JTextComponent textComponent;
public ClearTextComponentListener(JTextComponent textComponent) {
this.textComponent = textComponent;
}
/**
* Invoked when an action occurs.
*
* @param e the event to be processed
*/
@Override
public void actionPerformed(ActionEvent e) {
this.textComponent.setText(null);
}
}

View File

@ -0,0 +1,38 @@
package com.gyrobian.listener;
import com.gyrobian.util.FileLoader;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Listener for when a user clicks to load the contents of a file into a text component.
*/
public class LoadTextComponentFromFileListener implements ActionListener {
private final JTextComponent textComponent;
public LoadTextComponentFromFileListener(JTextComponent textComponent) {
this.textComponent = textComponent;
}
/**
* Invoked when an action occurs.
*
* @param e the event to be processed
*/
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("SQL, Text", "sql", "txt"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
int result = fileChooser.showOpenDialog(textComponent);
if (result == JFileChooser.APPROVE_OPTION) {
this.textComponent.setText(FileLoader.readFile(fileChooser.getSelectedFile()));
}
}
}

View File

@ -0,0 +1,51 @@
package com.gyrobian.util;
import java.io.*;
/**
* Helps with loading files.
*/
public class FileLoader {
/**
* Reads a resource file from the classpath, and returns its contents as a string.
* @param classPath The class path of the resource.
* @return The string containing the contents of the file.
* @throws IOException If an error occurred or the file could not be read.
*/
public static String readResource(String classPath) throws IOException {
String newLine = System.getProperty("line.separator");
InputStream is = FileLoader.class.getClassLoader().getResourceAsStream(classPath);
if (is == null) {
throw new IOException("Could not open input stream to resource.");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder result = new StringBuilder();
boolean flag = false;
for (String line; (line = reader.readLine()) != null; ) {
result.append(flag? newLine: "").append(line);
flag = true;
}
return result.toString();
}
/**
* Reads a file into a string.
* @param selectedFile The file object, as it is often selected by a JFileChooser.
* @return The string containing the file, or an empty string.
*/
public static String readFile(File selectedFile) {
try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append('\n');
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
}

View File

@ -0,0 +1,257 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.gyrobian.view.Window">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="40455" binding="inputPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="b073a" binding="templateInputPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered"/>
<children>
<component id="7793b" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="11"/>
<text value="Template - The code to check against."/>
</properties>
</component>
<grid id="6eada" binding="templateTextEditorPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="d18b7" binding="templateTextEditorButtonPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5133a" class="javax.swing.JButton" binding="loadTemplateFromFileButton">
<constraints/>
<properties>
<text value="Load From File"/>
</properties>
</component>
<component id="68617" class="javax.swing.JButton" binding="clearTemplateButton">
<constraints/>
<properties>
<text value="Clear"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="9d68">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="22"/>
</properties>
<border type="none"/>
<children>
<component id="9ef0c" class="javax.swing.JTextArea" binding="templateTextArea">
<constraints/>
<properties>
<font swing-font="TextArea.font"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
<grid id="6359f" binding="testingInputPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered"/>
<children>
<component id="dc74d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Testing - The code to test correctness of."/>
</properties>
</component>
<grid id="d5268" binding="testingTextEditorPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="c0bda" binding="testingTextEditorButtonPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="60c89" class="javax.swing.JButton" binding="loadTestingFromFileButton">
<constraints/>
<properties>
<text value="Load From File"/>
</properties>
</component>
<component id="6b2ef" class="javax.swing.JButton" binding="clearTestingButton">
<constraints/>
<properties>
<text value="Clear"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="85f79">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="22"/>
</properties>
<border type="none"/>
<children>
<component id="fc72f" class="javax.swing.JTextArea" binding="testingTextArea">
<constraints/>
<properties>
<font swing-font="TextArea.font"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
</children>
</grid>
<grid id="b1a5d" binding="assessmentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8cfc7" class="javax.swing.JLabel" binding="assessmentPanelTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Assessment - Compare the template's output to the testing output."/>
</properties>
</component>
<scrollpane id="1c0c9">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="22"/>
</properties>
<border type="none"/>
<children>
<component id="c7cae" class="javax.swing.JTextPane" binding="assessmentTextPane">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="3d6d6" binding="outputPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="bevel-lowered"/>
<children>
<component id="e23f2" class="javax.swing.JLabel" binding="outputPanelTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Execution Output - Log of actions performed by each script."/>
</properties>
</component>
<grid id="8f7c4" binding="templateOutputPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="aa5b5">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="22"/>
</properties>
<border type="none"/>
<children>
<component id="1932b" class="javax.swing.JTextPane" binding="templateOutputTextPane">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="eb06c" binding="testingOutputPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="4bbad">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="22"/>
</properties>
<border type="none"/>
<children>
<component id="99b7f" class="javax.swing.JTextPane" binding="testingOutputTextPane">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,66 @@
package com.gyrobian.view;
import com.gyrobian.listener.ClearTextComponentListener;
import com.gyrobian.listener.LoadTextComponentFromFileListener;
import javax.swing.*;
import java.awt.*;
/**
* The window that's used for displaying the application.
*/
public class Window extends JFrame {
private JPanel mainPanel;
private JPanel assessmentPanel;
private JPanel inputPanel;
private JPanel templateInputPanel;
private JPanel testingInputPanel;
private JPanel outputPanel;
private JTextArea templateTextArea;
private JPanel templateTextEditorPanel;
private JPanel testingTextEditorPanel;
private JTextArea testingTextArea;
private JButton loadTemplateFromFileButton;
private JButton clearTemplateButton;
private JButton loadTestingFromFileButton;
private JButton clearTestingButton;
private JPanel templateTextEditorButtonPanel;
private JPanel testingTextEditorButtonPanel;
private JLabel outputPanelTitle;
private JPanel templateOutputPanel;
private JPanel testingOutputPanel;
private JTextPane templateOutputTextPane;
private JTextPane testingOutputTextPane;
private JLabel assessmentPanelTitle;
private JTextPane assessmentTextPane;
public Window() {
super("SQL-Assesser-2");
}
/**
* Initializes the window and makes it visible.
*/
public void init() {
this.initializeEventListeners();
this.setContentPane(mainPanel);
this.pack();
this.setExtendedState(this.getExtendedState() | Frame.MAXIMIZED_BOTH);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
/**
* Initializes all event listening for any components that need it.
*/
private void initializeEventListeners() {
this.clearTemplateButton.addActionListener(new ClearTextComponentListener(this.templateTextArea));
this.clearTestingButton.addActionListener(new ClearTextComponentListener(this.testingTextArea));
this.loadTemplateFromFileButton.addActionListener(new LoadTextComponentFromFileListener(this.templateTextArea));
this.loadTestingFromFileButton.addActionListener(new LoadTextComponentFromFileListener(this.testingTextArea));
}
}