Skip to content
Snippets Groups Projects
Commit 41feebc5 authored by Abhay Menon's avatar Abhay Menon
Browse files

Added documentation and cleaned up code

parent c533063c
No related branches found
No related tags found
1 merge request!13Added documentation and cleaned up code
Pipeline #84600 passed with stages
in 6 minutes and 15 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
......@@ -2,7 +2,6 @@
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package notes.multi.console
import notes.multi.app.MessageUtils
import java.lang.IllegalArgumentException
......@@ -30,11 +29,11 @@ fun main(args: Array<String>) {
4. Close GUI Window
1. Create Notes
- To create notes, users must type "notes <filename>"
- To create notes, users must type "./console <filename>"
- To save changes, use the Ctrl + S keybinding
2. Edit Notes
- To edit notes, users must type "notes <filename>"
- To edit notes, users must type "./console <filename>"
- If the file doesn't exist, a new note will be created
- To save changes, use the Ctrl + S keybinding
......@@ -50,18 +49,27 @@ fun main(args: Array<String>) {
} else {
if (args.size < 2) {
/**
* File Path (can be relative or absolute)
*/
val filePathArg = args[0]
val fileTitle = Path(filePathArg).getFileName()
val fileText = Path(filePathArg).getParent() ?: System.getProperty("user.dir")
if (!File(fileText.toString()).isDirectory) throw IllegalArgumentException("[ERROR]: Directory does not exist!")
/**
* Title of the file
*/
val fileTitle = Path(filePathArg).fileName
/**
* Location of the file as text
*/
val fileLocation = Path(filePathArg).parent ?: System.getProperty("user.dir")
if (!File(fileLocation.toString()).isDirectory) throw IllegalArgumentException("[ERROR]: Directory does not exist!")
// Regex Check for a specific argument format:
MessageUtils.verifyFilename(fileTitle.toString(), Regex("^.*[.]([Mm][Dd]|[Tt][Xx][Tt])$"))
ConsoleUtils.verifyFilename(fileTitle.toString(), Regex("^.*[.]([Mm][Dd]|[Tt][Xx][Tt])$"))
val path = System.getProperty("user.dir")
Application.launch(TextWindow()::class.java, "--title=${fileTitle}", "--text=${fileText}")
// Passing the location and title as params to TextWindow
Application.launch(TextWindow()::class.java, "--title=${fileTitle}", "--location=${fileLocation}")
} else {
throw IllegalArgumentException("[ERROR]: Wrong number of arguments provided!")
......
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package notes.multi.app
package notes.multi.console
import java.lang.IllegalArgumentException
class MessageUtils {
class ConsoleUtils {
companion object {
fun getMessage(): String = "Hello World!"
/**
* Checks the `filename` inputted and throws an exception
* if the `filename` does not follow the regular expression `pattern`
* @param filename Name of the file
* @param pattern Regular expression pattern
* @throws IllegalArgumentException
*/
fun verifyFilename(filename: String, pattern: Regex) {
if (!(pattern matches filename)) {
......
......@@ -12,10 +12,7 @@ import notes.multi.utilities.Folder
import java.time.LocalDate
import java.time.LocalDateTime
class MessageUtilsTest {
@Test fun testGetMessage() {
assertEquals("Hello World!", MessageUtils.getMessage())
}
class ConsoleUtilsTest {
@Test fun checkModelClasses() {
var n = Note(
title = "NeverGonnaGiveYouUp",
......@@ -36,6 +33,6 @@ class MessageUtilsTest {
notes = mutableListOf<Note>(n)
)
assertEquals(fldr.notes?.get(0) ?: null, n)
assertEquals(fldr.notes?.get(0), n)
}
}
......@@ -3,35 +3,46 @@ package notes.multi.utilities
import java.io.File
import java.io.InputStream
class Filemanager(private val dir: String, val name: String) {
/**
* Used for managing files within the notes application and performs create, delete, and edit operations on files
* @param dir Directory of the file
* @param name Name of the file
*/
class FileManager(private val dir: String, val name: String) {
private val directory = File(dir)
private val filepath = File("$dir/$name")
private val listfiles = mutableListOf<File>()
private val listFiles = mutableListOf<File>()
init {
for (f in directory.listFiles()!!) {
if (f.extension.lowercase() == "txt" || f.extension.lowercase() == "md") {
listfiles.add(f)
listFiles.add(f)
}
}
}
//returns list of files
/**
* Returns a list of mutable files
*/
fun files() : MutableList<File> {
return listfiles
return listFiles
}
// create and write to that file
fun writefile(line:String) {
/**
* Create file and write to it
*/
fun writeFile (line : String) {
filepath.writeText(line)
if (!listfiles.contains(filepath)) {
listfiles.add(filepath)
if (!listFiles.contains(filepath)) {
listFiles.add(filepath)
}
}
// opens and read the existing file
fun openfile(): String {
if (!listfiles.contains(filepath)) {
/**
* Open and read existing file
*/
fun openFile(): String {
if (!listFiles.contains(filepath)) {
return ""
}
val inputStream: InputStream = filepath.inputStream()
......@@ -39,8 +50,11 @@ class Filemanager(private val dir: String, val name: String) {
return inputStream.bufferedReader().use { it.readText() }
}
fun deletefile():Boolean {
listfiles.remove(filepath)
/**
* Delete file
*/
fun deleteFile(): Boolean {
listFiles.remove(filepath)
return filepath.delete()
}
......
......@@ -3,13 +3,19 @@ package notes.multi.utilities
import java.time.LocalDate
import java.time.LocalDateTime
/**
* An abstract class denoting a Folder and all the relevant information about it
* @param title Title of the folder
* @param description Description of the folder
* @param author Author of the folder
* @param dateCreated Creation date of the folder
* @param lastModified Last modification date of the folder
* @param notes List of notes belonging to the folder
*/
class Folder(var title: String = "Untitled",
var description: String = "Empty",
val author: String = "?", // User class?
val dateCreated: LocalDate? = LocalDate.now(),
var lastModified: LocalDateTime? = LocalDateTime.now(),
var notes: MutableList<Note>? = null) {
// add/remove notes
// update last modified
}
\ No newline at end of file
......@@ -3,7 +3,16 @@ package notes.multi.utilities
import java.time.LocalDate
import java.time.LocalDateTime
/**
* An abstract class denoting a Note and all the relevant information about it
* @param title Title of the note
* @param text Text/Content of the note
* @param author Author of the note
* @param extension File extension of the note
* @param dateCreated Creation date of the note
* @param lastModified Last modification date of the note
* @param location Location of the note
*/
class Note(var title: String = "Untitled",
var text: StringBuffer = StringBuffer(""),
val author: String = "?", // User class?
......
package notes.multi.utilities
import notes.multi.utilities.Filemanager
import javafx.application.Application
import javafx.stage.Stage
......@@ -8,32 +7,47 @@ import javafx.scene.control.ScrollPane
import javafx.scene.control.TextArea
import javafx.scene.layout.VBox
import javafx.scene.layout.AnchorPane
import javafx.application.Application.Parameters
import javafx.application.Platform
import javafx.scene.control.Alert
import javafx.scene.control.ButtonType
import javafx.scene.input.KeyCode
import javafx.scene.layout.Priority
/**
* - Displays a responsive `TextArea` in a window with the text of the file passed to the `Application.launch` function
* - Parameters are passed through the second parameter of the `Application.launch` in this format:
* ```kotlin
* Application.launch(TextWindow()::class.java, "--title=${fileTitle}", "--location=${fileLocation}")
* ```
* @param title Name of the file to be accessed
* @param location Location of the file to be accessed
*/
class TextWindow(): Application() {
var paramsMap = mutableMapOf<String, String>()
/**
* Map of params received by the `Application.Launch` function
* @see /console/src/main/kotlin/notes/multi/console/Console.kt
*/
private var paramsMap = mutableMapOf<String, String>()
/**
* Boolean value denoting whether console has been pressed
*/
private var controlPressed = false
var controlpressed = false
override fun init() {
super.init()
val params = getParameters()
paramsMap = params.getNamed()
val params = parameters
paramsMap = params.named
}
override fun start(stage: Stage) {
val path = paramsMap["text"]!!
val filecontroller = Filemanager(path, paramsMap["title"]!!)
stage.setTitle(paramsMap["title"])
val path = paramsMap["location"]!!
val fileController = FileManager(path, paramsMap["title"]!!)
stage.title = paramsMap["title"]
val textarea = TextArea()
//textarea.setText(paramsMap["text"])
textarea.setText(filecontroller.openfile())
textarea.setWrapText(true)
textarea.text = fileController.openFile()
textarea.isWrapText = true
val scroll = ScrollPane()
val anchor = AnchorPane(textarea)
......@@ -42,47 +56,50 @@ class TextWindow(): Application() {
AnchorPane.setLeftAnchor(textarea, 0.0)
AnchorPane.setRightAnchor(textarea, 0.0)
scroll.setFitToHeight(true)
scroll.setHmin(300.0)
scroll.setFitToWidth(true)
// REMOVE THESE COMMENTS
// println("===========")
// println(scroll.isFitToHeight)
// println(scroll.isFitToWidth)
scroll.isFitToHeight = true
scroll.hmin = 300.0
scroll.isFitToWidth = true
/**
* Responsive Design and scroll properties
*/
scroll.content = textarea
val box = VBox(anchor)
VBox.setVgrow(anchor, Priority.ALWAYS)
stage.scene = Scene(box, 300.0, 300.0)
/**
* Logic for key presses:
* - Save: Ctrl + S
* - Delete: Ctrl + D
* - Close Window: Ctrl + W
*/
stage.scene.setOnKeyPressed { event->
if (event.code == KeyCode.CONTROL) {
controlpressed = true
} else if (event.code == KeyCode.S && controlpressed) {
controlPressed = true
} else if (event.code == KeyCode.S && controlPressed) {
val warning = Alert(Alert.AlertType.CONFIRMATION)
warning.title = "SAVE"
warning.contentText = "Do you want to save this file?"
val result = warning.showAndWait()
if (result.isPresent) {
when (result.get()) {
ButtonType.OK -> filecontroller.writefile(textarea.getText())
ButtonType.OK -> fileController.writeFile(textarea.text)
}
}
} else if (event.code == KeyCode.D && controlpressed) {
} else if (event.code == KeyCode.D && controlPressed) {
val warning = Alert(Alert.AlertType.CONFIRMATION)
warning.title = "DELETE"
warning.contentText = "Do you delete this file?"
val result = warning.showAndWait()
if (result.isPresent) {
when (result.get()) {
ButtonType.OK -> {filecontroller.deletefile()
ButtonType.OK -> {fileController.deleteFile()
Platform.exit()}
}
}
} else if (event.code == KeyCode.W && controlpressed) {
} else if (event.code == KeyCode.W && controlPressed) {
val warning = Alert(Alert.AlertType.CONFIRMATION)
warning.title = "WARNING"
warning.contentText = "The current work will not be saved. Are you sure you want to quit?"
......@@ -97,8 +114,11 @@ class TextWindow(): Application() {
}
}
stage.scene.setOnKeyReleased { event->
if (controlpressed) {controlpressed = false}
/**
* Control press logic
*/
stage.scene.setOnKeyReleased {
if (controlPressed) {controlPressed = false}
}
stage.show()
......
import notes.multi.utilities.Filemanager
import notes.multi.utilities.FileManager
import kotlin.test.Test
import kotlin.test.assertEquals
internal class FilemanagerTest {
private val testmanager: Filemanager = Filemanager("${System.getProperty("user.dir")}/testfolder/", "hello.txt")
internal class FileManagerTest {
private val testmanager: FileManager = FileManager("${System.getProperty("user.dir")}/testfolder/", "hello.txt")
@Test
fun createreadfile() {
val expected = "hello from the moon"
testmanager.writefile(expected)
assertEquals(expected, testmanager.openfile())
testmanager.writeFile(expected)
assertEquals(expected, testmanager.openFile())
}
@Test
fun ReadNoneExistingFile() {
val expected = ""
testmanager.writefile("walking to the mooon")
testmanager.deletefile()
assertEquals(expected, testmanager.openfile())
testmanager.writeFile("walking to the mooon")
testmanager.deleteFile()
assertEquals(expected, testmanager.openFile())
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment