diff --git a/.vscode/settings.json b/.vscode/settings.json
index 5a1027d..1928e45 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,3 +1,15 @@
{
- "cSpell.words": ["Cascadia", "Lucida"]
+ "cSpell.words": [
+ "Autoscrolls",
+ "Cascadia",
+ "darcula",
+ "Darcula",
+ "darkula",
+ "flatlaf",
+ "formdev",
+ "Intelli",
+ "Lucida",
+ "mbahler"
+ ],
+ "include": "**/*.{ts,js,php,css,scss,html,pde}"
}
diff --git a/Arduino-Test-Code/Arduino-Test-Code.ino b/Arduino-Test-Code/Arduino-Test-Code.ino
index 8d0be11..e4c9a03 100644
--- a/Arduino-Test-Code/Arduino-Test-Code.ino
+++ b/Arduino-Test-Code/Arduino-Test-Code.ino
@@ -1,17 +1,14 @@
-int l = 0;
-
void setup() {
- Serial.begin(9600); //initialize serial
+ Serial.begin(9600); //initialize serial at 9600 baud rate
}
void loop() {
- l++; //count program scans
+ if (Serial.available()) { // if serial port is connected and has data
+ if (Serial.availableForWrite()){ // if serial port can be written to
+ Serial.write(Serial.read()); // echo received data
+ }
+ }
- Serial.print("hello world ");
- //Serial.print(" @ ");
- // Serial.print(l); //print program scan count
- //Serial.print(" scans");
- //Serial.write(10);
}
diff --git a/README.md b/README.md
index b56cbdf..f77f6f0 100644
--- a/README.md
+++ b/README.md
@@ -11,19 +11,23 @@ Windows10, Kubuntu25.04, Ubuntu24.04.2, LinuxMint 22.1 Cinnamon
_Main window_
-
+
_Settings window_
-
+
-_Settings window advanced options enabled)_
+_Settings window (advanced options enabled)_
-
+
+
+_Custom Baud Rate editing_
+
+
_Text finder_
-
+
## Commands
@@ -66,3 +70,9 @@ _Text finder_
* -fontsize=16 *(set font size to 16)*
* -fontsize=18 *(set font size to 18)*
+-theme *(set software theme)*
+* -theme=light *(set software theme color to light)*
+* -theme=dark *(set software theme color to dark)*
+* -theme=intellij *(set software theme color to intellij)*
+* -theme=darkula *(set software theme color to darkula)*
+
diff --git a/mainCode/.vscode/settings.json b/mainCode/.vscode/settings.json
index e953a6b..f54cd95 100644
--- a/mainCode/.vscode/settings.json
+++ b/mainCode/.vscode/settings.json
@@ -1,3 +1,10 @@
{
- "cSpell.words": ["lstop", "tstamp"]
+ "cSpell.words": [
+ "Autoscrolls",
+ "baudedit",
+ "flatlaf",
+ "formdev",
+ "lstop",
+ "tstamp"
+ ]
}
diff --git a/mainCode/baudEditPopup.pde b/mainCode/baudEditPopup.pde
new file mode 100644
index 0000000..f9a3048
--- /dev/null
+++ b/mainCode/baudEditPopup.pde
@@ -0,0 +1,117 @@
+public void initDialogBaudEdit() {
+ dialogBaudEdit = new JDialog(dialogSettingsMain, "Baud Rate list");
+ dialogBaudEdit.setSize(new Dimension(300, 300));
+ dialogBaudEdit.setResizable(false);
+ dialogBaudEdit.setAlwaysOnTop(true);
+ dialogBaudEdit.setLocationRelativeTo(dialogSettingsMain);
+ dialogBaudEdit.setLayout(layoutBaudEdit);
+ dialogBaudEdit.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
+ dialogBaudEdit.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ buttonBaudEditCancel.doClick(); //simulate cancel button click
+ }
+ }
+ );
+
+ // initialize and add text area to dialogBaudEdit
+ textAreaBaudEdit = new JTextArea(java.util.Arrays.toString(baudRateList).replace(",", "\n").replace("[", "").replace("]", "").replace(" ", "").trim());
+ scrollPaneBaudEdit = new JScrollPane(textAreaBaudEdit);
+ scrollPaneBaudEdit.setPreferredSize(new Dimension(274, 226));
+ textAreaBaudEdit.setLineWrap(true);
+ textAreaBaudEdit.setAutoscrolls(true);
+
+ layoutBaudEdit.putConstraint(SpringLayout.WEST, scrollPaneBaudEdit, 5, SpringLayout.WEST, dialogBaudEdit);
+ layoutBaudEdit.putConstraint(SpringLayout.NORTH, scrollPaneBaudEdit, 5, SpringLayout.NORTH, dialogBaudEdit);
+ dialogBaudEdit.add(scrollPaneBaudEdit);
+
+
+ // initialize and add OK button to dialogBaudEdit
+ buttonBaudEditOk = new JButton("OK");
+ buttonBaudEditOk.setPreferredSize(new Dimension(60, 20));
+ buttonBaudEditOk.setFocusPainted(false);
+ layoutBaudEdit.putConstraint(SpringLayout.EAST, buttonBaudEditOk, 0, SpringLayout.EAST, scrollPaneBaudEdit);
+ layoutBaudEdit.putConstraint(SpringLayout.NORTH, buttonBaudEditOk, 5, SpringLayout.SOUTH, scrollPaneBaudEdit);
+ dialogBaudEdit.add(buttonBaudEditOk);
+ buttonBaudEditOk.addActionListener( new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ /*Process TextArea Get text from textArea and append it to string array*/
+ int textAreaBaudEditLineCount = textAreaBaudEdit.getLineCount();
+ String[] textAreaBaudEditArray = {};
+ try {// Traverse the text in the JTextArea line by line
+ for (int i = 0; i < textAreaBaudEditLineCount; i ++) {
+ int start = textAreaBaudEdit.getLineStartOffset(i);
+ int end = textAreaBaudEdit.getLineEndOffset(i);
+ //processLine(textArea.getText(start, end-start));
+ // Step 1: Create a new array with length = original length + 1
+ textAreaBaudEditArray = Arrays.copyOf(textAreaBaudEditArray, textAreaBaudEditArray.length + 1);
+
+ // Step 2: Add the new element to the last index of the new array
+ textAreaBaudEditArray[textAreaBaudEditArray.length - 1] = textAreaBaudEdit.getText(start, end-start).trim();
+ systemPrintln(textAreaBaudEdit.getText(start, end-start).trim(), "debug");
+ }
+ }
+ catch(BadLocationException e) {
+ // Handle exception as you see fit
+ }
+ //end Process TextArea
+ baudRateList = textAreaBaudEditArray;
+ newBaudRateModel = new DefaultComboBoxModel(baudRateList); // populate newBaudRateModel with textAreaBaudEdit's text
+ comboBoxBaudRate.setModel(newBaudRateModel); // set comboBoxBaudRate's model to currBaudRateModel
+ dialogSettingsMain.setEnabled(true); // enable settings window
+ dialogBaudEdit.setVisible(false); // hide baud edit window
+ systemPrintln("buttonBaudEditOk clicked @ " + millis(), "debug"); // print debug statement
+ }
+ }
+ );
+
+ // initialize and add CANCEL button to dialogBaudEdit
+ buttonBaudEditCancel = new JButton("CANCEL");
+ buttonBaudEditCancel.setPreferredSize(new Dimension(60, 20));
+ buttonBaudEditCancel.setMargin(new Insets(0, 0, 0, 0));
+ buttonBaudEditCancel.setFocusPainted(false);
+ layoutBaudEdit.putConstraint(SpringLayout.EAST, buttonBaudEditCancel, -5, SpringLayout.WEST, buttonBaudEditOk);
+ layoutBaudEdit.putConstraint(SpringLayout.NORTH, buttonBaudEditCancel, 5, SpringLayout.SOUTH, scrollPaneBaudEdit);
+ dialogBaudEdit.add(buttonBaudEditCancel);
+ buttonBaudEditCancel.addActionListener(new ActionListener() {
+ public void actionPerformed (ActionEvent actionEvent) {
+ /*Process TextArea Get text from textArea and append it to string array*/
+ int textAreaBaudEditLineCount = textAreaBaudEdit.getLineCount();
+ String[] textAreaBaudEditArray = {};
+ try {// Traverse the text in the JTextArea line by line
+ for (int i = 0; i < textAreaBaudEditLineCount; i ++) {
+ int start = textAreaBaudEdit.getLineStartOffset(i);
+ int end = textAreaBaudEdit.getLineEndOffset(i);
+ //processLine(textArea.getText(start, end-start));
+ // Step 1: Create a new array with length = original length + 1
+ textAreaBaudEditArray = Arrays.copyOf(textAreaBaudEditArray, textAreaBaudEditArray.length + 1);
+
+ // Step 2: Add the new element to the last index of the new array
+ textAreaBaudEditArray[textAreaBaudEditArray.length - 1] = textAreaBaudEdit.getText(start, end-start).trim();
+ systemPrintln(textAreaBaudEdit.getText(start, end-start).trim(), "debug");
+ }
+ }
+ catch(BadLocationException e) {
+ // Handle exception as you see fit
+ }
+ //end Process TextArea
+ if (!textAreaBaudEditArray.equals(baudRateList)) {
+ textAreaBaudEdit.setText(java.util.Arrays.toString(baudRateList).replace(",", "\n").replace("[", "\n").replace("]", "\n").replace(" ", "").trim());
+ }
+ dialogSettingsMain.setEnabled(true); //enable settings window
+ dialogBaudEdit.setVisible(false); //hide baud edit window
+ }
+ }
+ );
+
+ //dialogBaudEdit.pack();
+
+ if (dialogBaudEdit != null && textAreaBaudEdit != null && buttonBaudEditOk != null && buttonBaudEditCancel != null) {
+ dialogBaudEditIsInit = true;
+ dialogBaudEdit.setVisible(true); // show baud rate edit window
+ dialogSettingsMain.setEnabled(false); // disable setting window
+ } else {
+ dialogBaudEditIsInit = false;
+ }
+}
+
diff --git a/mainCode/code/flatlaf-3.7.1.jar b/mainCode/code/flatlaf-3.7.1.jar
new file mode 100644
index 0000000..017a2e8
Binary files /dev/null and b/mainCode/code/flatlaf-3.7.1.jar differ
diff --git a/mainCode/data/Serial_Terminal_Manual.odt b/mainCode/data/Serial_Terminal_Manual.odt
new file mode 100644
index 0000000..4af923a
Binary files /dev/null and b/mainCode/data/Serial_Terminal_Manual.odt differ
diff --git a/mainCode/data/editBaud.png b/mainCode/data/editBaud.png
new file mode 100644
index 0000000..17983cf
Binary files /dev/null and b/mainCode/data/editBaud.png differ
diff --git a/mainCode/data/preferences.csv b/mainCode/data/preferences.csv
index 74bcfa1..ec79c71 100644
--- a/mainCode/data/preferences.csv
+++ b/mainCode/data/preferences.csv
@@ -1,2 +1,2 @@
-mode,theme,font,fontSize
-0,1,jetbrains-mono.regular.ttf,14.0
+mode,theme,font,fontSize,baudRateList
+0,light,jetbrains-mono.regular.ttf,14.0,"[4800, 9600, 38400, 57600, 115200]"
diff --git a/mainCode/data/refresh.png b/mainCode/data/refresh.png
new file mode 100644
index 0000000..6ae48b5
Binary files /dev/null and b/mainCode/data/refresh.png differ
diff --git a/mainCode/libs.pde b/mainCode/libs.pde
new file mode 100644
index 0000000..b7b48d0
--- /dev/null
+++ b/mainCode/libs.pde
@@ -0,0 +1,50 @@
+import processing.serial.Serial; // import processing Serial
+import com.formdev.flatlaf.FlatLightLaf; // import flatlaf light theme
+import com.formdev.flatlaf.FlatDarkLaf; // import flatlaf dark theme
+import com.formdev.flatlaf.FlatIntelliJLaf; // import flatlaf IntelliL theme
+import com.formdev.flatlaf.FlatDarculaLaf; // import flatlaf Darcula theme
+import java.awt.Font; // import java Font
+import java.awt.FontFormatException; // import java FontFormatException
+import java.awt.event.WindowAdapter; // import java WindowAdapter
+import java.awt.event.WindowEvent; // import java WindowEvent
+import java.awt.event.ActionListener; // import java ActionListener
+import java.awt.event.ActionEvent; // import java ActionEvent
+import java.awt.event.KeyAdapter; // import java KeyAdapter
+import java.awt.event.KeyEvent; // import java KeyEvent
+import java.awt.event.ComponentEvent; // import java ComponentEvent
+import java.awt.event.FocusListener; // import java FocusListener
+import java.awt.event.FocusEvent; // import java FocusEvent
+import java.awt.KeyboardFocusManager; // import java KeyBoardFocusManger
+import java.awt.Dimension; // import java dimension library
+import java.awt.image.BufferedImage; // import java buffered image library
+import java.awt.FlowLayout; // import java FlowLayout
+import java.awt.Color; // import java Color
+import java.awt.Insets; // import java insets
+
+import javax.swing.JFrame; // import javax JFrame
+import javax.swing.JPanel; // import javax JPanel
+import javax.swing.JButton; // import javax JButton
+import javax.swing.JDialog; // import javax JDialog
+import javax.swing.JTextArea; // import javax JTextArea
+import javax.swing.JTextField; // import javax JTextField
+import javax.swing.JScrollPane; // import javax JScrollPane
+import javax.swing.JComboBox; // import javax JComboBox
+import javax.swing.JCheckBox; // import javax JCheckBox
+import javax.swing.JLabel; // import javax JLabel
+import javax.swing.SpringLayout; // import javax SpringLayout
+import javax.swing.DefaultComboBoxModel; // import javax DefaultComboBox
+import javax.swing.UIManager; // import javax UIManager
+import javax.swing.UnsupportedLookAndFeelException; // import javax UnsupportedLookAndFeelManager
+import javax.swing.event.DocumentListener; // import javax DocumentListener
+import javax.swing.event.DocumentEvent; // import javax DocumentEvent
+import javax.swing.text.Highlighter; // import javax Highlighter
+import javax.swing.text.DefaultHighlighter; // import javax DefaultHighlighter
+import javax.swing.text.BadLocationException; // import javax BadLocationException
+import javax.swing.ImageIcon; // import javax ImageIcon
+import javax.swing.JFileChooser; // import javax JFileChooser
+
+import java.io.File; //import file library
+import java.io.FileWriter; //import file writer library
+import java.util.Collections; //import collections library
+import java.util.Scanner; //import scanner library
+import java.util.Arrays; //import arrays library
\ No newline at end of file
diff --git a/mainCode/logData.pde b/mainCode/logData.pde
index 252aaf7..9e2d590 100644
--- a/mainCode/logData.pde
+++ b/mainCode/logData.pde
@@ -11,16 +11,16 @@ public void initLogFile() {
if (logFile.createNewFile()) {
logFileExists = false;
textAreaMainMsg("\n", "File created: " + textFieldFileDirInput + logFile.getName(), "");
- systemPrintln("File created: " + textFieldFileDirInput + logFile.getName());
+ systemPrintln("File created: " + textFieldFileDirInput + logFile.getName(), "debug");
} else if (logFile.exists()) {
logFileExists = true;
textAreaMainMsg("\n", "File already exists: " + textFieldFileDirInput + logFile.getName(), "");
- systemPrintln("File already exists: " + textFieldFileDirInput + logFile.getName());
+ systemPrintln("File already exists: " + textFieldFileDirInput + logFile.getName(), "debug");
}
}
- catch (IOException e) {
- textAreaMainMsg("\n", "Failed to create log file. " + e, "");
- systemPrintln("Failed to create log file. " + e);
+ catch (IOException error) {
+ textAreaMainMsg("\n", "Failed to create log file. " + error, "");
+ systemPrintln("Failed to create log file. " + error, "error");
initLogFileOk = false;
}
@@ -50,4 +50,3 @@ public void writeToFile(String data) {
}
}
}
-
diff --git a/mainCode/mainCode.pde b/mainCode/mainCode.pde
index 5e1fa1f..e6e156d 100644
--- a/mainCode/mainCode.pde
+++ b/mainCode/mainCode.pde
@@ -1,137 +1,145 @@
-import processing.serial.*; //import serial library
-import java.awt.*; //import awt library
-import java.awt.Font; //import awt font library
-import java.awt.event.*; //import awt event library
-import java.awt.event.KeyAdapter; //import awt key adapter library
-import java.awt.event.KeyEvent; //import awt key event library
-import java.awt.Dimension.*; //import awt dimension library
-import java.awt.image.BufferedImage; //import awt buffered image library
-import javax.swing.*; //import swing library
-import javax.swing.event.*; //import swing event library
-import javax.swing.text.*; //import swing text library
-import java.io.File; //import file library
-import java.io.FileWriter; //import file writer library
-import java.util.Collections; //import collections library
-import java.util.Scanner; //import scanner library
-
-javax.swing.JFrame frame; //create instance of JFrame
-java.awt.Canvas canvas; //create instance of Canvas
-
//append text to textAreaMain
public void textAreaMainMsg(String A, String MSG, String B) {
- textAreaMainMsgIsRunning = true;
- if (showTimeStamp == true && A == "\n") {
- textAreaMain.append(A + hour() + ":" + minute() + ":" + second() + " " + MSG + B);
- textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
- logOutputData = A + hour() + ":" + minute() + ":" + second() + " " + MSG + B;
- if (initLogFileOk) {
- writeToFile(logOutputData);
- }
- } else if (showTimeStamp == true && MSG.startsWith("\n")) {
- textAreaMain.append(A + MSG + hour() + ":" + minute() + ":" + second() + " " + B);
- textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
- logOutputData = A + MSG + hour() + ":" + minute() + ":" + second() + " " + B;
- if (initLogFileOk) {
- writeToFile(logOutputData);
- }
- } else {
- textAreaMain.append(A + MSG + B);
- textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
- logOutputData = A + MSG + B;
- //print(logOutputData);
- if (initLogFileOk) {
- writeToFile(logOutputData);
+ try {
+ textAreaMainMsgIsRunning = true;
+ if (showTimeStamp == true && A == "\n") {
+ textAreaMain.append(A + hour() + ":" + minute() + ":" + second() + " " + MSG + B);
+ textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
+ logOutputData = A + hour() + ":" + minute() + ":" + second() + " " + MSG + B;
+ if (initLogFileOk) {
+ writeToFile(logOutputData);
+ }
+ } else if (showTimeStamp == true && MSG.startsWith("\n")) {
+ textAreaMain.append(A + MSG + hour() + ":" + minute() + ":" + second() + " " + B);
+ textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
+ logOutputData = A + MSG + hour() + ":" + minute() + ":" + second() + " " + B;
+ if (initLogFileOk) {
+ writeToFile(logOutputData);
+ }
+ } else {
+ textAreaMain.append(A + MSG + B);
+ textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
+ logOutputData = A + MSG + B;
+ //print(logOutputData);
+ if (initLogFileOk) {
+ writeToFile(logOutputData);
+ }
}
}
+ catch (Exception error) {
+ systemPrintln("textAreaMainMsg failed @ " + millis() + "error = " + error, "error");
+ }
}
//generate default random file name
public String genFileName(String randomFileName) {
- if (lettersIndex == 26) {
- lettersIndex = 0;
+ try {
+ if (lettersIndex == 26) {
+ lettersIndex = 0;
+ }
+ randomFileName = "log_" + day() + "-" + month() + "-" + year() + letters[lettersIndex] + hour()+minute()+second();
+ lettersIndex++;
}
- randomFileName = "log_" + day() + "-" + month() + "-" + year() + letters[lettersIndex] + hour()+minute()+second();
- lettersIndex++;
+ catch (Exception error) {
+ systemPrintln("genFileName failed @ " + millis() + "error = " + error, "error");
+ }
+ systemPrintln("textAreaMainMsg complete @ " + millis(), "debug");
return randomFileName;
}
// get current operating system
-public void getOS() {
+public String getOS() {
if (platform == MACOS) {
OS = "mac";
- systemPrintln("OS = MACOS");
+ systemPrintln("OS = MACOS", "debug");
} else if (platform == WINDOWS) {
OS = "windows";
OsDirChar = "\\";
defaultLogDir = (System.getProperty("user.home") + OsDirChar + "Desktop"); //set default log directory to user's desktop
- systemPrintln("OS = WINDOWS" + " @ " + millis());
+ systemPrintln("OS = WINDOWS" + " @ " + millis(), "debug");
} else if (platform == LINUX) {
OS = "linux";
OsDirChar = "/";
defaultLogDir = (System.getProperty("user.home") + OsDirChar + "Desktop"); //set default log directory to user's desktop
- systemPrintln("OS = LINUX" + " @ " + millis());
+ systemPrintln("OS = LINUX" + " @ " + millis(), "debug");
} else if (platform == OTHER) {
OS = "other";
- systemPrintln("OS not recognized" + " @ " + millis());
+ systemPrintln("OS not recognized" + " @ " + millis(), "debug");
}
+ systemPrintln("getOS complete @ " + millis(), "debug");
+ return OS;
}
//initialize controls for search function
public void initSearch() {
try {
- hilit = new DefaultHighlighter();
- painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
- systemPrintln("initSearch complete @ " + millis());
+ highlighter = new DefaultHighlighter(); // create new DefaultHighlighter
+ painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); // create new DefaultHighlightPainter
+ systemPrintln("initSearch complete @ " + millis(), "debug"); // print debug statement
}
- catch (Exception e) {
- systemPrintln("initSearch failed @ " + millis());
+ catch (Exception error) {
+ systemPrintln("initSearch failed @ " + millis() + "error = " + error, "error"); //print debug statement
}
}
//search textAreaMain
public void getSearch(String searchText) {
- try { // try searching textAreaMain
- if (textFieldSearchHasText == true) { //textFieldSearch has text other than prompt text
- if (searchText.length() > 0) { //only run if search text is longer than zero
- String textAreaMainText = textAreaMain.getText();
- hilit = textAreaMain.getHighlighter();
- hilit.removeAllHighlights();
- int index = textAreaMainText.indexOf(searchText);
- while (index >= 0) { //search text
- int searchTextLength = searchText.length();
- hilit.addHighlight(index, index+searchTextLength, painter);
- index = textAreaMainText.indexOf(searchText, index + searchTextLength);
+ try { // try searching textAreaMain
+ if (textFieldSearchHasText == true) { // textFieldSearch has text other than prompt text
+ if (searchText.length() > 0) { // only run if search text is longer than zero
+ String textAreaMainText = textAreaMain.getText(); // get text from textAreaMain
+ highlighter = textAreaMain.getHighlighter(); // get textAreaMain's highlighter
+ highlighter.removeAllHighlights(); // remove old highlights
+ int index = textAreaMainText.indexOf(searchText); // position of first index of search text
+ while (index >= 0) { // search for text
+ int searchTextLength = searchText.length(); // get length of search text
+ highlighter.addHighlight(index, index+searchTextLength, painter); // add highlight to textAreaMain
+ index = textAreaMainText.indexOf(searchText, index + searchTextLength); // update index to next search text
}
- } else { //remove all highlights
- hilit.removeAllHighlights();
+ } else {
+ highlighter.removeAllHighlights(); // remove all highlights
}
}
- systemPrintln("getSearch complete @ " + millis());
+ systemPrintln("getSearch complete @ " + millis(), "debug"); // print debug statement
}
- catch (Exception e) { //catch search exception
- systemPrintln("getSearch failed @ " + millis());
+ catch (Exception error) { //catch search exception
+ systemPrintln("getSearch failed @ " + millis() + "error = " + error, "error"); // print debug statement
}
}
//convert PImage to BufferedImage
BufferedImage convertToBufferedImage(PImage imgToConvert) {
- imgToConvert.loadPixels(); //load pixel data
BufferedImage convertedImg = new BufferedImage(imgToConvert.width, imgToConvert.height, BufferedImage.TYPE_INT_ARGB);
+ try {
+ imgToConvert.loadPixels(); //load pixel data
- for (int y = 0; y < imgToConvert.height; y++) {
- for (int x = 0; x < imgToConvert.width; x++) {
- int loc = x + y * imgToConvert.width;
- convertedImg.setRGB(x, y, imgToConvert.pixels[loc]); // Copy pixel data
+ for (int y = 0; y < imgToConvert.height; y++) {
+ for (int x = 0; x < imgToConvert.width; x++) {
+ int loc = x + y * imgToConvert.width;
+ convertedImg.setRGB(x, y, imgToConvert.pixels[loc]); // Copy pixel data
+ }
}
}
+ catch (Exception error) {
+ systemPrintln("convertToBufferedImage failed @ " + millis() + "error = " + error, "error");
+ }
+ systemPrintln("convertToBufferedImage complete @ " + millis(), "debug");
return convertedImg;
}
// print to system console
-public void systemPrintln(String msg) {
- if (showDebugStatements == true) {
- System.out.println(msg);
- } else {
- //do nothing
+public void systemPrintln(String msg, String type) {
+ try {
+ if (showDebugStatements == true) {
+ if (type.equals("debug")) {
+ System.out.println(msg);
+ } else if (type.equals("error")) {
+ System.err.println(msg);
+ }
+ } else {
+ //do nothing
+ }
+ }
+ catch (Exception error) {
}
}
@@ -139,7 +147,7 @@ public void systemPrintln(String msg) {
public void setFont(String fontName, float fontSize) {
try {
// Path to your font file (TTF or OTF)
- File fontFile = new File(dataPath("") + OsDirChar + fontName);
+ File fontFile = new File(dataPath("") + OsDirChar + fontName); //get font file
//println(fontFile.getAbsolutePath());
if (!fontFile.exists()) {
throw new IOException("Font file not found: " + fontFile.getAbsolutePath());
@@ -149,10 +157,9 @@ public void setFont(String fontName, float fontSize) {
Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile)
.deriveFont(Font.PLAIN, fontSize); // Set style and size
- // Apply font to textAreaMain and textFieldMain
- textAreaMain.setFont(customFont);
- textFieldMain.setFont(customFont);
- systemPrintln("setFont complete @ " + millis());
+ textAreaMain.setFont(customFont); // set textAreaMain font
+ textFieldMain.setFont(customFont); // set textFieldMain font
+ systemPrintln("setFont complete @ " + millis(), "debug");
}
catch (FontFormatException e) {
System.err.println("Invalid font format: " + e.getMessage());
@@ -162,24 +169,67 @@ public void setFont(String fontName, float fontSize) {
}
}
-// Processing setup function
-public void setup() {
- icon = loadImage("icon.png"); //import software icon
- bufferedIcon = convertToBufferedImage(icon); //convert PImage to BufferedImage for use as JFrame icon
- frame = (javax.swing.JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
- canvas = (processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative();
- frame.setLocation(displayWidth/2 - wndMinW/2, displayHeight/2 - wndMinH/2);
- frame.setSize(wndMinW, wndMinH);
- frame.remove(canvas);
- frame.setMinimumSize(new Dimension(wndMinW, wndMinH));
- frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame.setIconImage(bufferedIcon); //set custom icon
- frame.setTitle(versionInfo); //set frame title
- frame.setResizable(true); //allow frame resizing
- frame.setVisible(true); //make frame visible
+// set software theme
+public void setTheme(String theme) {
+ try {
+ if (theme.equals("light")) {
+ UIManager.setLookAndFeel(new FlatLightLaf()); // set theme to light
+ FlatLightLaf.setup();
+ FlatLaf.updateUI();
+ systemPrintln("setTheme complete @ " + millis(), "debug"); // print debug statement
+ } else if (theme.equals("dark")) {
+ UIManager.setLookAndFeel(new FlatDarkLaf()); // set theme to dark
+ FlatDarkLaf.setup();
+ FlatLaf.updateUI();
+ systemPrintln("setTheme complete @ " + millis(), "debug"); // print debug statement
+ } else if (theme.equals("intellij")) {
+ UIManager.setLookAndFeel(new FlatIntelliJLaf()); // set theme to dark
+ FlatIntelliJLaf.setup();
+ FlatLaf.updateUI();
+ systemPrintln("setTheme complete @ " + millis(), "debug"); // print debug statement
+ } else if (theme.equals("darcula")) {
+ UIManager.setLookAndFeel(new FlatDarculaLaf()); // set theme to dark
+ FlatDarculaLaf.setup();
+ FlatLaf.updateUI();
+ systemPrintln("setTheme complete @ " + millis(), "debug"); // print debug statement
+ } else {
+ systemPrintln("Theme not recognized, defaulting to light theme @ " + millis(), "debug"); // print debug statement
+ UIManager.setLookAndFeel(new FlatLightLaf()); // default theme to light
+ FlatLightLaf.setup();
+ FlatLaf.updateUI();
+ }
+ }
+ catch (UnsupportedLookAndFeelException error) {
+ systemPrintln("Error setting theme: " + error.getMessage(), "error"); // print error statement
+ }
+}
+
+// software main setup function
+public void setupMain() {
+ OS = getOS(); // get operating system
+ loadTable(); // load preferences table
+ getTableData(); // get preferences table data
+ setTheme(theme); // set software theme
+ iconMain = loadImage("icon.png"); // import software icon
+ iconRefresh = loadImage("refresh.png"); // import refresh button icon
+ iconEditBaud = loadImage("editBaud.png"); // import edit baud rate button icon
+ bufferedIconMain = convertToBufferedImage(iconMain); // convert PImage to BufferedImage for use as JFrame icon
+ bufferedIconRefresh = convertToBufferedImage(iconRefresh); // convert PImage to BufferedImage for use as refresh button icon
+ bufferedIconEditBaud = convertToBufferedImage(iconEditBaud); // convert PImage to BufferedImage for use as edit baud rate button icon
+ frameMainWindow = (javax.swing.JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
+ canvasMainWindow = (processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative();
+ frameMainWindow.setLocation(displayWidth/2 - wndMinW/2, displayHeight/2 - wndMinH/2);
+ frameMainWindow.setSize(wndMinW, wndMinH);
+ frameMainWindow.remove(canvasMainWindow);
+ frameMainWindow.setMinimumSize(new Dimension(wndMinW, wndMinH));
+ frameMainWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frameMainWindow.setIconImage(bufferedIconMain); // set custom icon
+ frameMainWindow.setTitle(versionInfo); // set frame title
+ frameMainWindow.setResizable(true); // allow frame resizing
+ frameMainWindow.setVisible(true); // make frame visible
//add component listener for main frame
- frame.addComponentListener(new java.awt.event.ComponentAdapter() {
+ frameMainWindow.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if (mainUiInit == true) { //only run if main UI has been initialized
panelMain.setBounds(0, 0, width, height);
@@ -189,7 +239,11 @@ public void setup() {
textAreaMain.repaint();
textAreaMain.updateUI();
textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength());
- textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75));
+ if (OS.equals("linux")) { // linux misplaces the ui components. this adjusts according to the OS.
+ textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 110));
+ } else {
+ textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 105));
+ }
textAreaMainScrollPane.repaint();
textFieldMain.setPreferredSize(new Dimension(width - 215, 30));
@@ -233,11 +287,9 @@ public void setup() {
while (mainUiInit == false) {
delay(1);
}
- getOS(); //get operating system
- loadTable(); //load preferences table
- getTableData(); //get preferences table data
- searchForPorts(); //search for available serial ports
- initSearch(); //initialize textAreaMain searching
+ setFont(selectedFont, selectedFontSize);
+ searchForPorts(); // search for available serial ports
+ initSearch(); // initialize textAreaMain searching
//set startup message length based on selected font size
if (selectedFontSize == 12) {
textAreaMainMsg("", " -------------------------------------" + versionInfo + "-------------------------------------", "");
@@ -249,14 +301,24 @@ public void setup() {
textAreaMainMsg("", " -------------------" + versionInfo + "--------------------", "");
}
textAreaMainMsg("\n", "Enter -h for help", ""); //print help message
- systemPrintln("Startup complete" + " @ " + millis());
-} // END setup
+ systemPrintln("Startup complete" + " @ " + millis(), "debug");
+}
+
+// Processing setup function
+public void setup() {
+ setupMain(); // software setup function
+
+ // enter code here
+}
// Processing loop function
public void draw() {
+ // enter code here
}
//Processing settings function
public void settings() {
- size(wndMinW, wndMinH);
+ JFrame.setDefaultLookAndFeelDecorated(true); // set JFrame DefaultLookAndFeelDecorated to true for custom window decorations
+ JDialog.setDefaultLookAndFeelDecorated(true);// set JDialog DefaultLookAndFeelDecorated to true for custom window decorations
+ size(wndMinW, wndMinH); // set main window size
}
diff --git a/mainCode/mainWindowUI.pde b/mainCode/mainWindowUI.pde
index 5098f5e..f654d4f 100644
--- a/mainCode/mainWindowUI.pde
+++ b/mainCode/mainWindowUI.pde
@@ -10,7 +10,7 @@ void buildMainUI() {
drawTextFieldSearch();
if (panelMain != null && textAreaMain != null && textFieldMain != null && textFieldSearch != null && buttonConnect != null && buttonClear != null && buttonSettings != null && buttonLogPauseResume != null) {
mainUiInit = true;
- systemPrintln("Main UI initialized @ " + millis());
+ systemPrintln("Main UI initialized @ " + millis(), "debug");
} else {
mainUiInit = false;
}
@@ -20,21 +20,25 @@ void drawPanelMain() {
panelMain = new JPanel();
panelMain.setLocation(0, 0);
panelMain.setBounds(0, 0, width, height);
- panelMain.setBackground(Color.WHITE);
panelMain.setLayout(new FlowLayout());
- frame.add(panelMain); //add panel to main frame
- systemPrintln("EDT panelMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ frameMainWindow.add(panelMain); //add panel to main frame
+ systemPrintln("EDT panelMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
panelMain.repaint();
}
//draw main window textarea
void drawTextAreaMain() {
textAreaMain = new JTextArea();
textAreaMainScrollPane = new JScrollPane(textAreaMain);
- textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75));
+ println(OS);
+ if (OS.equals("linux")) { // linux misplaces the ui components. this adjusts according to the OS.
+ textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 110));
+ } else {
+ textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 105));
+ }
textAreaMain.setEditable(false);
- textAreaMain.setLineWrap(true);
+ //textAreaMain.setLineWrap(true);
panelMain.add(textAreaMainScrollPane);
- systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
textAreaMain.repaint();
}
@@ -56,7 +60,7 @@ void drawTextFieldMain() {
if (textFieldMain.getText().equals("Press return key to send text...")) {
textFieldMain.setText("");
textFieldMain.setForeground(Color.BLACK);
- systemPrintln("textFieldMain focus gained" + " @ " + millis());
+ systemPrintln("textFieldMain focus gained" + " @ " + millis(), "debug");
}
}
@@ -66,7 +70,7 @@ void drawTextFieldMain() {
if (textFieldMain.getText().isEmpty()) {
textFieldMain.setText("Press return key to send text...");
textFieldMain.setForeground(Color.GRAY);
- systemPrintln("textFieldMain focus lost" + " @ " + millis());
+ systemPrintln("textFieldMain focus lost" + " @ " + millis(), "debug");
}
}
}
@@ -80,19 +84,21 @@ void drawTextFieldMain() {
prevCommandsIndex = 0; //reset up key press count on enter keyPress
commandFound = false; //reset commandFound variable
- // check if entered data is a valid command
- for (int i = 0; i < validCommands.length; i ++) {
- if (textFieldMain.getText().equals(validCommands[i])) {
- commandFound = true;
- enteredCommand = textFieldMain.getText(); //update enteredCommand variable
- processCommands(); //process entered command
+ for (int i = 0; i < validCommands.length; i ++) { // check if entered data is a valid command
+ if (textFieldMain.getText().equals(validCommands[i]) && !connectedToCOM) { // if entered text is equal to a command and serialPort is not connected
+ commandFound = true; // set commandFound to to true
+ enteredCommand = textFieldMain.getText(); // update enteredCommand variable
}
}
- // if entered data is not a command, send to serial port
- if (!commandFound && !textFieldMain.getText().startsWith("-")) {
- writeToPort(textFieldMain.getText()); //send entered text to serial port write process
- } else if (!commandFound && textFieldMain.getText().startsWith("-")) {
- textAreaMainMsg("\n", "Invalid command entered. Type -h for help.", ""); //invalid command message
+
+ if (commandFound && !connectedToCOM) { // if entered data is a command and serialPort is not connected
+ processCommands(); // process entered command
+ } else if (!commandFound && !connectedToCOM) { // if entered data is not a command and serialPort is not connected
+ textAreaMainMsg("\n", "Invalid command entered. Type -h for help.", ""); // print invalid command message
+ }
+
+ if (connectedToCOM) { // if connected to com send to serial port
+ writeToPort(textFieldMain.getText()); // send entered text to serial port write process
}
previousEnteredCommands.append(textFieldMain.getText()); //store entered command
@@ -101,10 +107,8 @@ void drawTextFieldMain() {
if (previousEnteredCommands.size() > prevCommandsLimit) {
previousEnteredCommands.remove(0); //remove oldest entry
}
- systemPrintln(previousEnteredCommands.toString()); //print previous commands size and content to console
-
textFieldMain.setText(""); //clear text field after enter pressed
- systemPrintln("textFieldMain keyPressed Enter" + " @ " + millis());
+ systemPrintln("textFieldMain keyPressed Enter" + " @ " + millis(), "debug");
}
}
);
@@ -123,10 +127,10 @@ void drawTextFieldMain() {
String lastCommand = previousEnteredCommands.get(previousEnteredCommands.size() - prevCommandsIndex); // get last entered command
textFieldMain.setText(lastCommand); // print last entered command to textFieldMain
}
- systemPrintln("Up arrow key pressed");
+ systemPrintln("Up arrow key pressed @ " + millis(), "debug");
}
- // //handle down arrow keyPress
+ //handle down arrow keyPress
if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
if (prevCommandsIndex > 1) {
prevCommandsIndex--; // decrement previous commands index
@@ -140,13 +144,13 @@ void drawTextFieldMain() {
} else {
textFieldMain.setText(""); // clear textFieldMain if at the most recent command
}
- systemPrintln("Down arrow key pressed"); // debug print
+ systemPrintln("Down arrow key pressed @ " + millis(), "debug"); // debug print
}
- systemPrintln("Key pressed: " + evt.getKeyCode() + " " + prevCommandsIndex); // debug print
+ systemPrintln("Key pressed: " + evt.getKeyCode() + " " + prevCommandsIndex, "debug"); // debug print
}
}
);
- systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); // debug print
+ systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug"); // debug print
textFieldMain.repaint(); // repaint textFieldMain
}
@@ -170,7 +174,7 @@ void drawTextFieldSearch() {
textFieldSearch.setText("");
textFieldSearch.setForeground(Color.BLACK);
textFieldSearchHasText = false;
- systemPrintln("textFieldSearch focus gained" + " @ " + millis());
+ systemPrintln("textFieldSearch focus gained" + " @ " + millis(), "debug");
}
textFieldSearchHasText = true;
}
@@ -182,7 +186,7 @@ void drawTextFieldSearch() {
textFieldSearch.setText("Enter search text.");
textFieldSearch.setForeground(Color.GRAY);
textFieldSearchHasText = false;
- systemPrintln("textFieldSearch focus lost" + " @ " + millis());
+ systemPrintln("textFieldSearch focus lost" + " @ " + millis(), "debug");
}
textFieldSearchHasText = true;
}
@@ -196,7 +200,7 @@ void drawTextFieldSearch() {
public void actionPerformed(ActionEvent e) {
textFieldSearchHasText = true;
getSearch(textFieldSearch.getText());
- systemPrintln("textFieldSearch keyPressed Enter" + " @ " + millis());
+ systemPrintln("textFieldSearch keyPressed Enter" + " @ " + millis(), "debug");
}
}
);
@@ -222,7 +226,7 @@ void drawTextFieldSearch() {
}
);
- systemPrintln("EDT textFieldSearch = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT textFieldSearch = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
textFieldSearch.repaint();
}
@@ -245,12 +249,12 @@ void drawButtonConnect() {
//connectToCOM = false;
disconnectPort();
}
- systemPrintln("buttonConnect clicked" + " @ " + millis());
+ systemPrintln("buttonConnect clicked" + " @ " + millis(), "debug");
}
}
);
- systemPrintln("EDT buttonConnect = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT buttonConnect = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
buttonConnect.repaint();
}
@@ -268,11 +272,11 @@ void drawButtonClear() {
public void actionPerformed(ActionEvent actionEvent) {
textAreaMain.setText("");
- systemPrintln("buttonClear clicked" + " @ " + millis());
+ systemPrintln("buttonClear clicked" + " @ " + millis(), "debug");
}
}
);
- systemPrintln("EDT buttonClear = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT buttonClear = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
buttonClear.repaint();
}
@@ -288,20 +292,21 @@ void drawButtonSettings() {
buttonSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
- if (frameSettings == null) { //if settings window has not been drawn
+ if (dialogSettingsMain == null) { //if settings window has not been drawn
settingsUI(); //draw settings window
availableCOMs = processing.serial.Serial.list(); //get available serial ports
comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs));
} else { //otherwise if settings window has been drawn make it visible
- frameSettings.setVisible(true);
- availableCOMs = processing.serial.Serial.list();//get available serial ports
- comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs));
+ dialogSettingsMain.setLocationRelativeTo(frameMainWindow); // Center the settings window relative to the main frame
+ dialogSettingsMain.setVisible(true); // show settings window
+ frameMainWindow.setEnabled(false); // disable main window
+ availableCOMs = processing.serial.Serial.list(); // get available serial ports
}
- systemPrintln("buttonSettings clicked" + " @ " + millis());
+ systemPrintln("buttonSettings clicked" + " @ " + millis(), "debug");
}
}
);
- systemPrintln("EDT buttonSettings = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT buttonSettings = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
buttonSettings.repaint();
}
@@ -327,10 +332,10 @@ void drawButtonLogPauseResume() {
textAreaMainMsg("\n", "Resumed data logging", "");
}
}
- systemPrintln("buttonLogPauseResume clicked" + " @ " + millis());
+ systemPrintln("buttonLogPauseResume clicked" + " @ " + millis(), "debug");
}
}
);
- systemPrintln("EDT buttonLogPauseResume = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT buttonLogPauseResume = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
buttonLogPauseResume.repaint();
}
diff --git a/mainCode/processCommands.pde b/mainCode/processCommands.pde
index aef2dd8..07a0fba 100644
--- a/mainCode/processCommands.pde
+++ b/mainCode/processCommands.pde
@@ -14,6 +14,7 @@ public void processCommands() {
textAreaMainMsg("", "-tstamp= : Enable/disable time stamp", "\n"); //toggle time stamp
textAreaMainMsg("", "-font= : Set font for main text area and input field" + "\n" + "available font types:" + "\n \t" + "1. Courier" + "\n \t" + "2. Cascadia Code" + "\n \t" + "3. JetBrains Mono(default)" + "\n \t" + "4. Liberation Mono", "\n"); //set font
textAreaMainMsg("", "-fontsize= : Set font size for main text area and input field" + "\n" + "available font sizes:" + "\n \t" + "10" + "\n \t" + "12" + "\n \t" + "14(Default)" + "\n \t" + "16" + "\n \t" + "18", "\n"); //set font size
+ textAreaMainMsg("", "-theme= : Set software theme" + "\n" + "available themes:" + "\n \t" + "light(default)" + "\n \t" + "dark" + "\n \t" + "intelij" + "\n \t" + "darcula" ,"\n"); //print set theme command help
} else if (enteredCommand.equals("-clear")) { //clear main text area
textAreaMain.setText(""); //clear main text area
} else if (enteredCommand.equals("-v")) { //display version info
@@ -22,14 +23,14 @@ public void processCommands() {
if (enteredCommand.contains("=")) {
String enteredCommandSplit = enteredCommand.split("=")[1];
if (enteredCommandSplit.equals("true")) {
- frameSettings = null; //reset settings frame to force rebuild with new advanced options
+ dialogSettingsMain = null; //reset settings frame to force rebuild with new advanced options
advancedOptions = true; //enable advanced options
- setTableData(); //save advanced options to preferences table
+ setTableData("advanced"); //save advanced options to preferences table
textAreaMainMsg("\n", "Advanced serial port options enabled.", "");
} else if (enteredCommandSplit.equals("false")) {
- frameSettings = null; //reset settings frame to force rebuild with removed advanced options
+ dialogSettingsMain = null; //reset settings frame to force rebuild with removed advanced options
advancedOptions = false;//disable advanced options
- setTableData(); //save advanced options to preferences table
+ setTableData("advanced"); //save advanced options to preferences table
textAreaMainMsg("\n", "Advanced serial port options disabled.", "");
}
} else {
@@ -51,12 +52,12 @@ public void processCommands() {
textAreaMainMsg("\n", "Invalid command parameter. Use -tstamp=", ""); //invalid format message
}
} else if (enteredCommand.equals("-settings")) { //open settings window
- if (frameSettings == null) { //if settings window has not been drawn
+ if (dialogSettingsMain == null) { //if settings window has not been drawn
settingsUI(); //draw settings window
availableCOMs = processing.serial.Serial.list(); //get available serial ports
comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs));
} else { //otherwise if settings window has been drawn make it visible
- frameSettings.setVisible(true);
+ dialogSettingsMain.setVisible(true);
availableCOMs = processing.serial.Serial.list();//get available serial ports
comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs));
}
@@ -86,7 +87,7 @@ public void processCommands() {
int fontIndex = int(enteredCommandSplit) - 1;
if (fontIndex >= 0 && fontIndex < fontList.length) {
selectedFont = fontList[fontIndex]; //set selected font
- setTableData(); //save selected font to preferences table
+ setTableData("advanced"); //save selected font to preferences table
setFont(selectedFont, selectedFontSize); //apply selected font
textAreaMainMsg("\n", "Set font to " + selectedFont + ".", "");
} else {
@@ -101,7 +102,7 @@ public void processCommands() {
int fontSize = int(enteredCommandSplit);
if (fontSize == 10 || fontSize == 12 || fontSize == 14 || fontSize == 16 || fontSize == 18) {
selectedFontSize = fontSize; //set selected font size
- setTableData(); //save selected font size to preferences table
+ setTableData("advanced"); //save selected font size to preferences table
setFont(selectedFont, selectedFontSize); //apply selected font size
textAreaMainMsg("\n", "Set font size to " + selectedFontSize + ".", "");
} else {
@@ -110,5 +111,20 @@ public void processCommands() {
} else {
textAreaMainMsg("\n", "Invalid command parameter. Use -fontsize=", ""); //invalid format message
}
+ } else if (enteredCommand.startsWith("-theme")) { //set font size
+ if (enteredCommand.contains("=")) {
+ String enteredCommandSplit = enteredCommand.split("=")[1].trim();
+ String newTheme = enteredCommandSplit;
+ if (newTheme.equals("light") || newTheme.equals("dark") || newTheme.equals("intellij") || newTheme.equals("darcula")) {
+ theme = newTheme; //set selected theme
+ setTableData("advanced"); //save selected font size to preferences table
+ setTheme(theme);
+ textAreaMainMsg("\n", "Set theme to " + theme + ".", "");
+ } else {
+ textAreaMainMsg("\n", "Invalid theme. Use -theme= where type is light, dark, intellij, or darcula.", ""); //invalid theme message
+ }
+ } else {
+ textAreaMainMsg("\n", "Invalid command parameter. Use -theme= where type is light, dark, intellij, or darcula.", ""); //invalid format message
+ }
}
-} // END processCommands
+} // end of processCommands()
diff --git a/mainCode/processPreferences.pde b/mainCode/processPreferences.pde
index 55ec2b4..bad4e44 100644
--- a/mainCode/processPreferences.pde
+++ b/mainCode/processPreferences.pde
@@ -1,7 +1,7 @@
// function to load the preferences table
public void loadTable () {
preferenceTable = loadTable("data/preferences.csv", "header");
- systemPrintln("loadTable complete @ " + millis());
+ systemPrintln("loadTable complete @ " + millis(), "debug");
}
// function to get data from preferences table
@@ -9,14 +9,24 @@ public void getTableData() {
advancedOptions = boolean(preferenceTable.getInt(0, "mode"));
selectedFont = preferenceTable.getString(0, "font");
selectedFontSize = preferenceTable.getInt(0, "fontSize");
- setFont(selectedFont,selectedFontSize);
- systemPrintln("getTableData complete @ " + millis());
+ String tempBaudRates = preferenceTable.getString(0, "baudRateList").replace("]", "").replace("[", "").replace(" ", "").trim();
+ baudRateList = tempBaudRates.split(",");
+ theme = preferenceTable.getString(0, "theme");
+ currBaudRateModel = new DefaultComboBoxModel(baudRateList);
+ systemPrintln("getTableData complete @ " + millis(), "debug");
}
-public void setTableData() {
- preferenceTable.setInt(0, "mode", int(advancedOptions)); //save advanced options mode to preferences table
- preferenceTable.setString(0, "font", selectedFont); //save selected font to preferences table
- preferenceTable.setFloat(0, "fontSize", selectedFontSize); //save selected font size to preferences table
+public void setTableData(String mode) {
+ if (mode.equals("advanced")) {
+ preferenceTable.setInt(0, "mode", int(advancedOptions)); //save advanced options mode to preferences table
+ preferenceTable.setString(0, "font", selectedFont); //save selected font to preferences table
+ preferenceTable.setFloat(0, "fontSize", selectedFontSize); //save selected font size to preferences table
+ preferenceTable.setString(0, "baudRateList", java.util.Arrays.toString(baudRateList)); //save baud rate list to preferences table
+ } else if (mode.equals("basic")) {
+ preferenceTable.setString(0, "baudRateList", java.util.Arrays.toString(baudRateList)); //save baud rate list to preferences table
+ }
+ preferenceTable.setString(0, "theme", theme);
saveTable(preferenceTable, "data/preferences.csv");
- systemPrintln("setTableData complete @ " + millis());
+ systemPrintln("setTableData complete @ " + millis(), "debug");
}
+
diff --git a/mainCode/processSerial.pde b/mainCode/processSerial.pde
index baa6081..0b1813c 100644
--- a/mainCode/processSerial.pde
+++ b/mainCode/processSerial.pde
@@ -19,7 +19,7 @@ public void searchForPorts() {
} else if (connectedToCOM) {
availableCOMs = Serial.list();
if (availableCOMs[0].equals(selectedPort) == true || availableCOMs[comboBoxPortSelectedIndex].equals(selectedPort) == true) {
- systemPrintln("connected port found" + availableCOMs[0]);
+ systemPrintln("connected port found" + availableCOMs[0], "debug");
} else {
}
}
@@ -32,11 +32,11 @@ public void connectPort() {
if (advancedOptions == true) {
// print connecting statements
textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "");
- systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
+ systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "debug");
// initialize processing serial port
COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate, selectedParity, selectedDataBits, selectedStopBits);
- systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
+ systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "debug");
textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "\n");
buttonConnect.setText("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
buttonConnect.setBackground(buttonConnectGreen);
@@ -44,11 +44,11 @@ public void connectPort() {
} else {
// print connecting statements
textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate, "");
- systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate);
+ systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate, "debug");
// initialize processing serial port
COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate);
- systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate);
+ systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate, "debug");
textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate, "\n");
buttonConnect.setText("Connected-click to disconnect " + selectedPort + "@" + selectedBaudRate);
buttonConnect.setBackground(buttonConnectGreen);
@@ -60,7 +60,7 @@ public void connectPort() {
connectedToCOM = false;
COMPort = null;
textAreaMainMsg("\n", error.toString(), "");
- systemPrintln(error.toString());
+ systemPrintln(error.toString(), "error");
}
}
}
@@ -75,12 +75,12 @@ public void disconnectPort() {
COMPort = null;
connectedToCOM = false;
if (advancedOptions == true) {
- systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
+ systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "debug");
textAreaMainMsg("\n", "Disconnected from: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "");
buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
buttonConnect.setBackground(buttonConnectRed);
} else {
- systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate);
+ systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate, "debug");
textAreaMainMsg("\n", "Disconnected from: " + selectedPort + "@" + selectedBaudRate, "");
buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate);
buttonConnect.setBackground(buttonConnectRed);
@@ -88,7 +88,7 @@ public void disconnectPort() {
}
catch (Exception error) {
textAreaMainMsg("\n", error.toString(), "");
- systemPrintln(error.toString());
+ systemPrintln(error.toString(), "error");
}
}
}
@@ -98,20 +98,19 @@ public void writeToPort(String i) {
try {
if (i.length() > 0) {
COMPort.write(i);
- textAreaMainMsg("\n", i, "\n");
+ COMPort.clear();
} else {
COMPort.write('\n');
- textAreaMainMsg("", "\n", "");
}
}
catch (Exception error) {
if (!connectedToCOM) {
textAreaMainMsg("\n", "ERROR--Failed to send data... Not connected to serial port.", "");
- systemPrintln("ERROR--Failed to send data... Not connected to serial port.");
+ systemPrintln("ERROR--Failed to send data... Not connected to serial port.", "debug");
} else {
textAreaMainMsg("\n", "ERROR--Failed to send data..." + '\n' + error, "");
- systemPrintln("ERROR--Failed to send data..." + '\n' + error);
+ systemPrintln("ERROR--Failed to send data..." + '\n' + error, "error");
}
}
}
@@ -122,4 +121,3 @@ public void serialEvent(Serial p) {
textAreaMainMsg("", serialInputData, "");
textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); //set textAreaMain to autoscroll
}
-
diff --git a/mainCode/settingsWindowUI.pde b/mainCode/settingsWindowUI.pde
index 22f521e..e69df3b 100644
--- a/mainCode/settingsWindowUI.pde
+++ b/mainCode/settingsWindowUI.pde
@@ -1,25 +1,35 @@
//draw main ui for settings window
void settingsUI() {
- frameSettings = new JFrame("Settings");
- frameSettings.setSize(500, 300);
- frameSettings.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frameSettings.setResizable(false);
- frameSettings.setIconImage(bufferedIcon);
- panelMainSettings = new JPanel();
- panelMainSettings.setBackground(Color.white);
- panelMainSettings.setLayout(layoutSettings);
+ dialogSettingsMain = new JDialog(frameMainWindow, "Settings");
+ if (OS.equals("linux")) { // linux misplaces the ui components. this adjusts according to the OS.
+ dialogSettingsMain.setSize(486, 343);
+ } else {
+ dialogSettingsMain.setSize(500, 350);
+ }
+ dialogSettingsMain.setResizable(false);
+ dialogSettingsMain.setIconImage(bufferedIconMain);
+ dialogSettingsMain.setLocationRelativeTo(frameMainWindow);
+ dialogSettingsMain.setLayout(layoutSettings);
+ dialogSettingsMain.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); //simulate cancel button click on close to reset settings values
+ dialogSettingsMain.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ buttonCancel.doClick(); //simulate cancel button click to reset settings values and close window
+ }
+ }
+ );
//add components here
drawPortConfig(); //draw port config section ui
drawDataConfig(); //draw data config section ui
drawLogConfig(); //draw data logging section ui
- frameSettings.add(panelMainSettings);
- frameSettings.setLocationRelativeTo(null);
+ drawOkCancelButtons(); //draw ok and cancel buttons
//check if settings UI initialized successfully
- if (frameSettings != null && panelMainSettings != null && drawPortConfigInit == true && drawDataConfigInit == true && drawLogConfigInit == true) {
- systemPrintln("EDT settingsUI = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ if (dialogSettingsMain != null && drawPortConfigInit == true && drawDataConfigInit == true && drawLogConfigInit == true) {
+ systemPrintln("EDT settingsUI = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
settingsUiInit = true;
- frameSettings.setVisible(true); //make settings window visible
+ dialogSettingsMain.setVisible(true); // show settings window
+ frameMainWindow.setEnabled(false); // disable main window
} else {
settingsUiInit = false;
}
@@ -33,54 +43,54 @@ void drawPortConfig() {
labelPortConfig = new JLabel("Port Configuration");
labelPortConfig.setPreferredSize(new Dimension(120, 20));
labelPortConfig.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelPortConfig, 10, SpringLayout.WEST, panelMainSettings);
- layoutSettings.putConstraint(SpringLayout.NORTH, labelPortConfig, 10, SpringLayout.NORTH, panelMainSettings);
- panelMainSettings.add(labelPortConfig);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelPortConfig, 10, SpringLayout.WEST, dialogSettingsMain);
+ layoutSettings.putConstraint(SpringLayout.NORTH, labelPortConfig, 10, SpringLayout.NORTH, dialogSettingsMain);
+ dialogSettingsMain.add(labelPortConfig);
//draw (Port) label
labelPort = new JLabel("Port");
labelPort.setPreferredSize(new Dimension(80, 20));
labelPort.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelPort, 10, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelPort, 10, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, labelPort, 30, SpringLayout.NORTH, labelPortConfig);
- panelMainSettings.add(labelPort);
+ dialogSettingsMain.add(labelPort);
//draw (Baud Rate) label
labelBaudRate = new JLabel("Baud Rate");
labelBaudRate.setPreferredSize(new Dimension(80, 20));
labelBaudRate.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelBaudRate, 10, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelBaudRate, 10, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, labelBaudRate, 40, SpringLayout.NORTH, labelPort);
- panelMainSettings.add(labelBaudRate);
+ dialogSettingsMain.add(labelBaudRate);
//draw (Parity) label
labelPortParity = new JLabel("Parity");
labelPortParity.setPreferredSize(new Dimension(80, 20));
labelPortParity.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelPortParity, 10, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelPortParity, 10, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, labelPortParity, 40, SpringLayout.NORTH, labelBaudRate);
if (advancedOptions == true) {
- panelMainSettings.add(labelPortParity);
+ dialogSettingsMain.add(labelPortParity);
}
//draw (Data Bits) label
labelPortDataBits = new JLabel("Data Bits");
labelPortDataBits.setPreferredSize(new Dimension(80, 20));
labelPortDataBits.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelPortDataBits, 10, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelPortDataBits, 10, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, labelPortDataBits, 40, SpringLayout.NORTH, labelPortParity);
if (advancedOptions == true) {
- panelMainSettings.add(labelPortDataBits);
+ dialogSettingsMain.add(labelPortDataBits);
}
//draw (Stop Bits) label
labelPortStopBits = new JLabel("Stop Bits");
labelPortStopBits.setPreferredSize(new Dimension(80, 20));
labelPortStopBits.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelPortStopBits, 10, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelPortStopBits, 10, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, labelPortStopBits, 40, SpringLayout.NORTH, labelPortDataBits);
if (advancedOptions == true) {
- panelMainSettings.add(labelPortStopBits);
+ dialogSettingsMain.add(labelPortStopBits);
}
//draw COM port combo box
@@ -89,30 +99,73 @@ void drawPortConfig() {
//comboBoxPort.setSelectedIndex(0); //throws error on startup when there are no available COM ports
layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPort, 80, SpringLayout.WEST, labelPort);
layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPort, 0, SpringLayout.NORTH, labelPort);
- panelMainSettings.add(comboBoxPort);
+ dialogSettingsMain.add(comboBoxPort);
comboBoxPort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
- systemPrintln("User selected " + comboBoxPort.getSelectedItem().toString());
+ systemPrintln("User selected " + comboBoxPort.getSelectedItem().toString(), "debug");
+ }
+ }
+ );
+
+ //draw COM refresh button
+ buttonRefreshCOMs = new JButton();
+ buttonRefreshCOMs.setPreferredSize(new Dimension(20, 20));
+ buttonRefreshCOMs.setIcon(new ImageIcon(bufferedIconRefresh));
+ layoutSettings.putConstraint(SpringLayout.WEST, buttonRefreshCOMs, 5, SpringLayout.EAST, comboBoxPort);
+ layoutSettings.putConstraint(SpringLayout.NORTH, buttonRefreshCOMs, 0, SpringLayout.NORTH, comboBoxPort);
+ dialogSettingsMain.add(buttonRefreshCOMs);
+ buttonRefreshCOMs.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (connectedToCOM == false) {
+ availableCOMs = processing.serial.Serial.list(); //get available serial ports
+ comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs));
+ systemPrintln("Available COMs:" + java.util.Arrays.toString(availableCOMs), "debug");
+ systemPrintln("buttonRefreshCOMs clicked @ " + millis(), "debug");
+ } else {
+ textAreaMainMsg("\n", "Cannot refresh COM ports while connected to port.", "");
+ }
}
}
);
//draw Baud Rate combo box
- comboBoxBaudRate = new JComboBox(baudRateList);
+ comboBoxBaudRate = new JComboBox();
comboBoxBaudRate.setPreferredSize(new Dimension(110, 20));
- comboBoxBaudRate.setSelectedIndex(2);
- comboBoxBaudRate.setEditable(true);
+ comboBoxBaudRate.setEditable(false);
layoutSettings.putConstraint(SpringLayout.WEST, comboBoxBaudRate, 80, SpringLayout.WEST, labelBaudRate);
layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxBaudRate, 0, SpringLayout.NORTH, labelBaudRate);
- panelMainSettings.add(comboBoxBaudRate);
-
+ newBaudRateModel = currBaudRateModel; // set newBaudRateModel to currBaudRateModel values
+ comboBoxBaudRate.setModel(currBaudRateModel); // set comboBoxBaudRate's model to currBaudRateModel
+ comboBoxBaudRate.setSelectedIndex(1); // select baudRate no.1 with default baud list it equals 9600
+ dialogSettingsMain.add(comboBoxBaudRate);
//add action listener to comboBoxBaudRate
comboBoxBaudRate.addActionListener(new ActionListener() {
//action performed event handler
public void actionPerformed(ActionEvent actionEvent) {
- systemPrintln("User selected " + comboBoxBaudRate.getSelectedItem().toString() + " @ " + millis());
+ systemPrintln("User selected " + comboBoxBaudRate.getSelectedItem().toString() + " @ " + millis(), "debug");
+ }
+ }
+ );
+
+ //draw Baud Rate edit button
+ buttonEditBaud = new JButton();
+ buttonEditBaud.setPreferredSize(new Dimension(20, 20));
+ buttonEditBaud.setIcon(new ImageIcon(bufferedIconEditBaud));
+ layoutSettings.putConstraint(SpringLayout.WEST, buttonEditBaud, 5, SpringLayout.EAST, comboBoxBaudRate);
+ layoutSettings.putConstraint(SpringLayout.NORTH, buttonEditBaud, 0, SpringLayout.NORTH, comboBoxBaudRate);
+ dialogSettingsMain.add(buttonEditBaud);
+ buttonEditBaud.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (dialogBaudEditIsInit == false) {
+ initDialogBaudEdit();
+ } else {
+ dialogBaudEdit.setLocationRelativeTo(dialogSettingsMain); // Center the baud edit dialog relative to the settings dialog
+ dialogBaudEdit.setVisible(true); // show baud edit window
+ dialogSettingsMain.setEnabled(false); // disable settings window
+ }
+ systemPrintln("buttonEditBaud clicked @ " + millis(), "debug");
}
}
);
@@ -124,7 +177,7 @@ void drawPortConfig() {
layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortParity, 80, SpringLayout.WEST, labelPortParity);
layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortParity, 0, SpringLayout.NORTH, labelPortParity);
if (advancedOptions == true) {
- panelMainSettings.add(comboBoxPortParity);
+ dialogSettingsMain.add(comboBoxPortParity);
}
//add action listener to comboBoxPortParity
@@ -133,7 +186,7 @@ void drawPortConfig() {
//action performed event handler
public void actionPerformed(ActionEvent actionEvent) {
- systemPrintln("User selected " + comboBoxPortParity.getSelectedItem().toString() + " @ " + millis());
+ systemPrintln("User selected " + comboBoxPortParity.getSelectedItem().toString() + " @ " + millis(), "debug");
}
}
);
@@ -145,7 +198,7 @@ void drawPortConfig() {
layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortDataBits, 80, SpringLayout.WEST, labelPortDataBits);
layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortDataBits, 0, SpringLayout.NORTH, labelPortDataBits);
if (advancedOptions == true) {
- panelMainSettings.add(comboBoxPortDataBits);
+ dialogSettingsMain.add(comboBoxPortDataBits);
}
//add action listener to comboBoxPortDataBits
@@ -153,7 +206,7 @@ void drawPortConfig() {
//action performed event handler
public void actionPerformed(ActionEvent actionEvent) {
- systemPrintln("User selected " + comboBoxPortDataBits.getSelectedItem().toString() + " @ " + millis());
+ systemPrintln("User selected " + comboBoxPortDataBits.getSelectedItem().toString() + " @ " + millis(), "debug");
}
}
);
@@ -165,7 +218,7 @@ void drawPortConfig() {
layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortStopBits, 80, SpringLayout.WEST, labelPortStopBits);
layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortStopBits, 0, SpringLayout.NORTH, labelPortStopBits);
if (advancedOptions == true) {
- panelMainSettings.add(comboBoxPortStopBits);
+ dialogSettingsMain.add(comboBoxPortStopBits);
}
//add action listener to comboBoxPortStopBits
@@ -174,91 +227,17 @@ void drawPortConfig() {
//action performed event handler
public void actionPerformed(ActionEvent actionEvent) {
- systemPrintln("User selected " + comboBoxPortStopBits.getSelectedItem().toString() + " @ " + millis());
+ systemPrintln("User selected " + comboBoxPortStopBits.getSelectedItem().toString() + " @ " + millis(), "debug");
}
}
);
- //draw ok button
- buttonOk = new JButton("OK");
- buttonOk.setPreferredSize(new Dimension(60, 20));
- buttonOk.setMargin(new Insets(0, 0, 0, 0));
- buttonOk.setFocusPainted(false);
- layoutSettings.putConstraint(SpringLayout.EAST, buttonOk, -10, SpringLayout.EAST, panelMainSettings);
- layoutSettings.putConstraint(SpringLayout.SOUTH, buttonOk, -10, SpringLayout.SOUTH, panelMainSettings);
- panelMainSettings.add(buttonOk);
- //add action listener to buttonOk
- buttonOk.addActionListener(new ActionListener() {
-
- //action performed event handler
- public void actionPerformed(ActionEvent actionEvent) {
- if (connectedToCOM == false && portsFound == true) {
- selectedPort = comboBoxPort.getSelectedItem().toString();
- selectedBaudRate = comboBoxBaudRate.getSelectedItem().toString();
-
- switch (comboBoxPortParity.getSelectedItem().toString()) {
- case "None":
- selectedParity = 'N';
- break;
- case "Even":
- selectedParity = 'E';
- break;
- case "Odd":
- selectedParity = 'O';
- break;
- case "Mark":
- selectedParity = 'M';
- break;
- case "Space":
- selectedParity = 'S';
- break;
- default:
- selectedParity = 'N';
- break;
- }
-
- selectedDataBits = int(comboBoxPortDataBits.getSelectedItem().toString());
- selectedStopBits = float(comboBoxPortStopBits.getSelectedItem().toString());
- comboBoxPortSelectedIndex = comboBoxPort.getSelectedIndex();
- if (advancedOptions == true) {
- buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
- } else {
- buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate);
- }
- frameSettings.setVisible(false);
- } else {
- frameSettings.setVisible(false);
- }
- systemPrintln("buttonOk clicked" + " @ " + millis());
- }
- }
- );
-
- //draw ok button
- buttonCancel = new JButton("CANCEL");
- buttonCancel.setPreferredSize(new Dimension(60, 20));
- buttonCancel.setMargin(new Insets(0, 0, 0, 0));
- buttonCancel.setFocusPainted(false);
- layoutSettings.putConstraint(SpringLayout.EAST, buttonCancel, -65, SpringLayout.EAST, buttonOk);
- layoutSettings.putConstraint(SpringLayout.SOUTH, buttonCancel, -10, SpringLayout.SOUTH, panelMainSettings);
- panelMainSettings.add(buttonCancel);
-
- //add action listener to buttonCancel
- buttonCancel.addActionListener(new ActionListener() {
-
- //action performed event handler
- public void actionPerformed(ActionEvent actionEvent) {
- frameSettings.setVisible(false);
- systemPrintln("buttonCancel clicked" + " @ " + millis());
- }
- }
- );
//check if all components initialized successfully
- if (labelPortConfig != null && labelPort != null && labelBaudRate != null && labelPortParity != null && labelPortDataBits != null && labelPortStopBits != null && comboBoxPort != null && comboBoxBaudRate != null && comboBoxPortParity != null && comboBoxPortDataBits != null && comboBoxPortStopBits != null && buttonOk != null && buttonCancel != null) {
+ if (labelPortConfig != null && labelPort != null && labelBaudRate != null && labelPortParity != null && labelPortDataBits != null && labelPortStopBits != null && comboBoxPort != null && comboBoxBaudRate != null && comboBoxPortParity != null && comboBoxPortDataBits != null && comboBoxPortStopBits != null) {
drawPortConfigInit = true;
- systemPrintln("EDT drawPortConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT drawPortConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
} else {
drawPortConfigInit = false;
}
@@ -272,9 +251,9 @@ void drawDataConfig() {
labelDataConfig = new JLabel("Data Configuration");
labelDataConfig.setPreferredSize(new Dimension(150, 20));
labelDataConfig.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelDataConfig, 255, SpringLayout.WEST, panelMainSettings);
- layoutSettings.putConstraint(SpringLayout.NORTH, labelDataConfig, 10, SpringLayout.NORTH, panelMainSettings);
- panelMainSettings.add(labelDataConfig);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelDataConfig, 255, SpringLayout.WEST, dialogSettingsMain);
+ layoutSettings.putConstraint(SpringLayout.NORTH, labelDataConfig, 10, SpringLayout.NORTH, dialogSettingsMain);
+ dialogSettingsMain.add(labelDataConfig);
//draw TimeStamp checkbox
checkBoxTimeStamp = new JCheckBox("Time Stamp");
@@ -282,23 +261,17 @@ void drawDataConfig() {
checkBoxTimeStamp.setFont(labelFont);
checkBoxTimeStamp.setOpaque(false);
checkBoxTimeStamp.setFocusPainted(false);
- layoutSettings.putConstraint(SpringLayout.WEST, checkBoxTimeStamp, 255, SpringLayout.WEST, panelMainSettings);
- layoutSettings.putConstraint(SpringLayout.NORTH, checkBoxTimeStamp, 40, SpringLayout.NORTH, panelMainSettings);
- panelMainSettings.add(checkBoxTimeStamp);
+ checkBoxTimeStamp.setSelected(showTimeStamp); //set checkBoxTimeStamp to tStampIsChecked value
+ layoutSettings.putConstraint(SpringLayout.WEST, checkBoxTimeStamp, 255, SpringLayout.WEST, dialogSettingsMain);
+ layoutSettings.putConstraint(SpringLayout.NORTH, checkBoxTimeStamp, 40, SpringLayout.NORTH, dialogSettingsMain);
+ dialogSettingsMain.add(checkBoxTimeStamp);
//add action listener to checkBoxTimeStamp
checkBoxTimeStamp.addActionListener(new ActionListener() {
//action performed event handler
public void actionPerformed(ActionEvent actionEvent) {
- if (checkBoxTimeStamp.isSelected() == true) {
- showTimeStamp = true;
- textAreaMainMsg("\n", "Enabled time stamp.", "");
- } else {
- textAreaMainMsg("\n", "Disabled time stamp.", "");
- showTimeStamp = false;
- }
- systemPrintln("checkBoxTimeStamp clicked" + " @ " + millis());
+ systemPrintln("checkBoxTimeStamp clicked" + " @ " + millis(), "debug");
}
}
);
@@ -306,7 +279,7 @@ void drawDataConfig() {
//check if all components initialized successfully
if (labelDataConfig != null && checkBoxTimeStamp != null) {
drawDataConfigInit = true;
- systemPrintln("EDT drawDataConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT drawDataConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
} else {
drawDataConfigInit = false;
}
@@ -319,18 +292,18 @@ void drawLogConfig() {
labelLogConfig = new JLabel("Log Configuration");
labelLogConfig.setPreferredSize(new Dimension(120, 20));
labelLogConfig.setFont(labelFont);
- layoutSettings.putConstraint(SpringLayout.WEST, labelLogConfig, 255, SpringLayout.WEST, panelMainSettings);
- layoutSettings.putConstraint(SpringLayout.NORTH, labelLogConfig, 100, SpringLayout.NORTH, panelMainSettings);
- panelMainSettings.add(labelLogConfig);
+ layoutSettings.putConstraint(SpringLayout.WEST, labelLogConfig, 255, SpringLayout.WEST, dialogSettingsMain);
+ layoutSettings.putConstraint(SpringLayout.NORTH, labelLogConfig, 100, SpringLayout.NORTH, dialogSettingsMain);
+ dialogSettingsMain.add(labelLogConfig);
// draw textFieldFileDir TextField
textFieldFileDir = new JTextField(defaultLogDir);
textFieldFileDir.setPreferredSize(new Dimension(155, 20));
textFieldFileDir.setFont(new Font("Monospaced", Font.PLAIN, 12));
textFieldFileDir.setForeground(Color.GRAY);
- layoutSettings.putConstraint(SpringLayout.WEST, textFieldFileDir, 255, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, textFieldFileDir, 255, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, textFieldFileDir, 30, SpringLayout.NORTH, labelLogConfig);
- panelMainSettings.add(textFieldFileDir);
+ dialogSettingsMain.add(textFieldFileDir);
//add focus listener to textFieldFileDir
textFieldFileDir.addFocusListener(new FocusListener() {
@@ -342,7 +315,7 @@ void drawLogConfig() {
// textFieldFileDir.setText("");
textFieldFileDir.setForeground(Color.BLACK);
//}
- systemPrintln("textFieldFileDir focus gained" + " @ " + millis());
+ systemPrintln("textFieldFileDir focus gained" + " @ " + millis(), "debug");
}
//add focusLost event listener to textFieldFileDir
@@ -352,7 +325,7 @@ void drawLogConfig() {
//textFieldFileDir.setText("file directory");
textFieldFileDir.setForeground(Color.GRAY);
//}
- systemPrintln("textFieldFileDir focus lost" + " @ " + millis());
+ systemPrintln("textFieldFileDir focus lost" + " @ " + millis(), "debug");
}
}
);
@@ -362,9 +335,9 @@ void drawLogConfig() {
textFieldFileName.setPreferredSize(new Dimension(155, 20));
textFieldFileName.setFont(new Font("Monospaced", Font.PLAIN, 12));
textFieldFileName.setForeground(Color.GRAY);
- layoutSettings.putConstraint(SpringLayout.WEST, textFieldFileName, 255, SpringLayout.WEST, panelMainSettings);
+ layoutSettings.putConstraint(SpringLayout.WEST, textFieldFileName, 255, SpringLayout.WEST, dialogSettingsMain);
layoutSettings.putConstraint(SpringLayout.NORTH, textFieldFileName, 30, SpringLayout.NORTH, textFieldFileDir);
- panelMainSettings.add(textFieldFileName);
+ dialogSettingsMain.add(textFieldFileName);
//add focus listener to textFieldFileName
textFieldFileName.addFocusListener(new FocusListener() {
@@ -376,7 +349,7 @@ void drawLogConfig() {
//textFieldFileName.setText("");
textFieldFileName.setForeground(Color.BLACK);
//}
- systemPrintln("textFieldFileName focus gained" + " @ " + millis());
+ systemPrintln("textFieldFileName focus gained" + " @ " + millis(), "debug");
}
//focus lost event handler
@@ -386,7 +359,7 @@ void drawLogConfig() {
//textFieldFileName.setText("file name");
textFieldFileName.setForeground(Color.GRAY);
//}
- systemPrintln("textFieldFileName focus lost" + " @ " + millis());
+ systemPrintln("textFieldFileName focus lost" + " @ " + millis(), "debug");
}
}
);
@@ -399,7 +372,7 @@ void drawLogConfig() {
buttonBrowse.setFocusPainted(false);
layoutSettings.putConstraint(SpringLayout.WEST, buttonBrowse, 160, SpringLayout.WEST, textFieldFileName);
layoutSettings.putConstraint(SpringLayout.NORTH, buttonBrowse, 0, SpringLayout.NORTH, textFieldFileDir);
- panelMainSettings.add(buttonBrowse);
+ dialogSettingsMain.add(buttonBrowse);
//add action listener to buttonBrowse
buttonBrowse.addActionListener(new ActionListener() {
@@ -414,14 +387,14 @@ void drawLogConfig() {
//if user selected a valid directory and logData is false
if (i == JFileChooser.APPROVE_OPTION && logData == false) {
File file = fileChooser.getSelectedFile();
- systemPrintln("User selected " + file.toString());
+ systemPrintln("User selected " + file.toString(), "debug");
textFieldFileDir.setText(file.toString());
textAreaMainMsg("\n", "Log path set to: " + file.toString(), "");
} else if (i == JFileChooser.APPROVE_OPTION && logData == true) {
textAreaMainMsg("\n", "Data logging must be stopped to change log directory.", "");
}
- systemPrintln("buttonBrowse clicked" + " @ " + millis());
+ systemPrintln("buttonBrowse clicked" + " @ " + millis(), "debug");
}
}
);
@@ -433,7 +406,7 @@ void drawLogConfig() {
buttonStartLog.setFocusPainted(false);
layoutSettings.putConstraint(SpringLayout.WEST, buttonStartLog, 0, SpringLayout.WEST, buttonBrowse);
layoutSettings.putConstraint(SpringLayout.NORTH, buttonStartLog, 30, SpringLayout.NORTH, buttonBrowse);
- panelMainSettings.add(buttonStartLog);
+ dialogSettingsMain.add(buttonStartLog);
//add action listener to buttonStartLog
buttonStartLog.addActionListener(new ActionListener() {
//action performed event handler
@@ -442,7 +415,7 @@ void drawLogConfig() {
dataLogPause = false;
initLogFile();
}
- systemPrintln("buttonStartLog clicked" + " @ " + millis());
+ systemPrintln("buttonStartLog clicked" + " @ " + millis(), "debug");
}
}
);
@@ -454,7 +427,7 @@ void drawLogConfig() {
buttonStopLog.setFocusPainted(false);
layoutSettings.putConstraint(SpringLayout.WEST, buttonStopLog, 0, SpringLayout.WEST, buttonStartLog);
layoutSettings.putConstraint(SpringLayout.NORTH, buttonStopLog, 30, SpringLayout.NORTH, buttonStartLog);
- panelMainSettings.add(buttonStopLog);
+ dialogSettingsMain.add(buttonStopLog);
//add action listener to buttonStopLog
buttonStopLog.addActionListener(new ActionListener() {
@@ -474,7 +447,7 @@ void drawLogConfig() {
catch (Exception e) {
textAreaMainMsg("\n", "Failed to stop logging data. " + e, "");
}
- systemPrintln("buttonStopLog clicked" + " @ " + millis());
+ systemPrintln("buttonStopLog clicked" + " @ " + millis(), "debug");
}
}
);
@@ -482,10 +455,139 @@ void drawLogConfig() {
//check if all components initialized successfully
if (labelLogConfig != null && textFieldFileDir != null && textFieldFileName != null && buttonBrowse != null && buttonStartLog != null && buttonStopLog != null) {
drawLogConfigInit = true;
- systemPrintln("EDT drawLogConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis());
+ systemPrintln("EDT drawLogConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis(), "debug");
} else {
drawLogConfigInit = false;
}
// end of drawLogConfig
}
+
+//draw close open buttons
+public void drawOkCancelButtons() {
+ //draw ok button
+ buttonOk = new JButton("OK");
+ buttonOk.setPreferredSize(new Dimension(60, 20));
+ buttonOk.setMargin(new Insets(0, 0, 0, 0));
+ buttonOk.setFocusPainted(false);
+ if (OS.equals("linux")) { // linux misplaces the ui components. this adjusts according to the OS.
+ layoutSettings.putConstraint(SpringLayout.WEST, buttonOk, 413, SpringLayout.EAST, dialogSettingsMain);
+ } else {
+ layoutSettings.putConstraint(SpringLayout.WEST, buttonOk, 399, SpringLayout.EAST, dialogSettingsMain);
+ }
+ layoutSettings.putConstraint(SpringLayout.SOUTH, buttonOk, 262, SpringLayout.SOUTH, dialogSettingsMain);
+ dialogSettingsMain.add(buttonOk);
+
+ //add action listener to buttonOk
+ buttonOk.addActionListener(new ActionListener() {
+
+ //action performed event handler
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (connectedToCOM == false && portsFound == true) { //only allow to save settings if not currently connected to COM port and there are available COM ports
+ selectedPort = comboBoxPort.getSelectedItem().toString();
+ selectedBaudRate = comboBoxBaudRate.getSelectedItem().toString();
+ currBaudRateModel = newBaudRateModel; // set currBaudRateModel to newBaudRateModel
+ comboBoxBaudRate.setModel(currBaudRateModel); // set comboBoxBaudRate model to currBaudRateModel
+ if (advancedOptions == true) {
+ switch (comboBoxPortParity.getSelectedItem().toString()) {
+ case "None":
+ selectedParity = 'N';
+ break;
+ case "Even":
+ selectedParity = 'E';
+ break;
+ case "Odd":
+ selectedParity = 'O';
+ break;
+ case "Mark":
+ selectedParity = 'M';
+ break;
+ case "Space":
+ selectedParity = 'S';
+ break;
+ default:
+ selectedParity = 'N';
+ break;
+ }
+ selectedDataBits = int(comboBoxPortDataBits.getSelectedItem().toString());
+ selectedStopBits = float(comboBoxPortStopBits.getSelectedItem().toString());
+ comboBoxPortSelectedIndex = comboBoxPort.getSelectedIndex();
+ selectedDataBitsString = comboBoxPortDataBits.getSelectedItem().toString();
+ selectedStopBitsString = comboBoxPortStopBits.getSelectedItem().toString();
+ selectedParityString = comboBoxPortParity.getSelectedItem().toString();
+ buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits);
+ } else {
+ buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate);
+ }
+ setTableData("basic");
+ frameMainWindow.setEnabled(true); // disable main window when settings window is open
+ dialogSettingsMain.setVisible(false); // hide settings window
+ } else {
+ try {
+ comboBoxPort.setSelectedItem(selectedPort); // reset comboBoxPort to selectedPort
+ comboBoxBaudRate.setSelectedItem(selectedBaudRate); // reset comboBoxBaudRate to selectedBaudRate
+ comboBoxBaudRate.setModel(currBaudRateModel); // set comboBoxBaudRate model to currBaudRateModel
+ if (advancedOptions == true) {
+ comboBoxPortParity.setSelectedItem(selectedParityString); // reset comboBoxPortParity to selectedParityString
+ comboBoxPortDataBits.setSelectedItem(selectedDataBitsString); // reset comboBoxPortDataBits to selectedDataBitsString
+ comboBoxPortStopBits.setSelectedItem(selectedStopBitsString); // reset comboBoxPortStopBits to selectedStopBitsString
+ }
+ frameMainWindow.setEnabled(true); // disable main window when settings window is open
+ dialogSettingsMain.setVisible(false); // hide settings window
+ }
+ catch (Exception error) {
+ frameMainWindow.setEnabled(true); // disable main window when settings window is open
+ dialogSettingsMain.setVisible(false); // hide settings window
+ systemPrintln("Ok button error likely a comboBox has no data @ " + millis(), error.toString());
+ }
+ }
+
+ if (checkBoxTimeStamp.isSelected() == true) {
+ showTimeStamp = true;
+ } else {
+ showTimeStamp = false;
+ }
+ systemPrintln("buttonOk clicked" + " @ " + millis(), "debug");
+ }
+ }
+ );
+
+ //draw cancel button
+ buttonCancel = new JButton("CANCEL");
+ buttonCancel.setPreferredSize(new Dimension(60, 20));
+ buttonCancel.setMargin(new Insets(0, 0, 0, 0));
+ buttonCancel.setFocusPainted(false);
+ layoutSettings.putConstraint(SpringLayout.EAST, buttonCancel, -10, SpringLayout.WEST, buttonOk);
+ layoutSettings.putConstraint(SpringLayout.SOUTH, buttonCancel, 262, SpringLayout.SOUTH, dialogSettingsMain);
+ dialogSettingsMain.add(buttonCancel);
+
+ //add action listener to buttonCancel
+ buttonCancel.addActionListener(new ActionListener() {
+
+ //action performed event handler
+ public void actionPerformed(ActionEvent actionEvent) {
+ try {
+ newBaudRateModel = currBaudRateModel; // set newBaudRateModel to currBaudRateModel values
+ comboBoxPort.setSelectedItem(selectedPort); // reset comboBoxPort to selectedPort
+ comboBoxBaudRate.setModel(currBaudRateModel); // set comboBoxBaudRate model to currBaudRateModel
+ comboBoxBaudRate.setSelectedItem(selectedBaudRate); // reset comboBoxBaudRate to selectedBaudRate
+ checkBoxTimeStamp.setSelected(showTimeStamp); // reset checkBoxTimeStamp to tStampIsChecked
+
+ if (advancedOptions == true) {
+ comboBoxPortParity.setSelectedItem(selectedParityString); // reset comboBoxPortParity to selectedParityString
+ comboBoxPortDataBits.setSelectedItem(selectedDataBitsString); // reset comboBoxPortDataBits to selectedDataBitsString
+ comboBoxPortStopBits.setSelectedItem(selectedStopBitsString); // reset comboBoxPortStopBits to selectedStopBitsString
+ }
+ }
+ catch (Exception error) {
+ frameMainWindow.setEnabled(true); // disable main window when settings window is open
+ dialogSettingsMain.setVisible(false); // hide settings window
+ systemPrintln("CANCEL button error likely a comboBox has no data @ " + millis(), error.toString());
+ }
+ frameMainWindow.setEnabled(true); // disable main window when settings window is open
+ dialogSettingsMain.setVisible(false); // hide settings window
+ systemPrintln("buttonCancel clicked" + " @ " + millis(), "debug");
+ }
+ }
+ );
+}
diff --git a/mainCode/variables.pde b/mainCode/variables.pde
index 55bdf0d..82b28fa 100644
--- a/mainCode/variables.pde
+++ b/mainCode/variables.pde
@@ -1,149 +1,172 @@
-float selectedStopBits = 1.0; //serial port stop bits 1.0, 1.5, or 2.0 (1.0 is the default)
-float fontSizeFloat[] = {10f, 12f, 14f, 16f, 18f}; //font size as float for textAreaMain and textFieldMain
-float selectedFontSize = 14; //selected font size as float for textAreaMain and textFieldMain
+float selectedStopBits = 1.0; // serial port stop bits 1.0, 1.5, or 2.0 (1.0 is the default)
+float fontSizeFloat[] = {10f, 12f, 14f, 16f, 18f}; // font size as float for textAreaMain and textFieldMain
+float selectedFontSize = 14; // selected font size as float for textAreaMain and textFieldMain
-int lettersIndex = 0; //index for random file name letters
-
-int wndMinH = 500; //minimum height of main window
-int wndMinW = 700; //minimum width of main window
-int serialInputDataInt;
-int selectedDataBits = 8; //serial port data bits 5-6-7-8 (8 is default)
-int comboBoxPortSelectedIndex = 0;
-int tmr1_lastMillis = 0; //tmr1 last millis reading
-int prevCommandsLimit = 10; //limit of previous entered commands stored
-int prevCommandsIndex = 0; //count of up key presses for previous command retrieval
+int lettersIndex = 0; // index for random file name letters
+int wndMinH = 500; // minimum height of main window
+int wndMinW = 700; // minimum width of main window
+int serialInputDataInt; // serial input data as integer for data logging
+int selectedDataBits = 8; // serial port data bits 5-6-7-8 (8 is default)
+int comboBoxPortSelectedIndex = 0; // index of selected port in comboBoxPort, used to check if selected port was removed while connected
+int tmr1_lastMillis = 0; // tmr1 last millis reading
+int prevCommandsLimit = 10; // limit of previous entered commands stored
+int prevCommandsIndex = 0; // count of up key presses for previous command retrieval
char selectedParity = 'N'; //serial port parity 'N' for none, 'E' for even, 'O' for odd, 'M' for mark, 'S' for space ('N' is the default)
-boolean showDebugStatements = true; //if true show debug statements in console
-boolean connectToCOM = false; //if connecting to com port
-boolean connectedToCOM = false; //if connected to com port
-boolean loggingData = false ; //if logging succeeded
-boolean logDataButtonPressed = false;
-boolean stopLoggingDataButtonPressed = false;
-boolean dataLogPause = false; //toggles data logging pause/resume
-boolean logData = false;
-boolean initLogFileOk = false; //if log file successfully initialized
-boolean showTimeStamp = false;
-boolean portsFound = false;
-boolean textAreaMainMsgIsRunning = false;
-boolean textFieldSearchHasText = false; //if textFieldSearch has text other than prompt text
-boolean serialPortRemoved = false; //if serial port was removed while connected
-boolean logFileExists = false; //if log file already exists when creating log file
-
-boolean mainUiInit, settingsUiInit, drawPortConfigInit, drawDataConfigInit, drawLogConfigInit = false; //if UI has been initialized
-boolean commandFound = false; //true if entered command is a valid command
-boolean advancedOptions = false; //true if advanced serial port options are enabled
+boolean showDebugStatements = true; // if true show debug statements in console
+boolean connectToCOM = false; // if connecting to com port
+boolean connectedToCOM = false; // if connected to com port
+boolean loggingData = false ; // if logging succeeded
+boolean logDataButtonPressed = false;
+boolean stopLoggingDataButtonPressed = false;
+boolean dataLogPause = false; // toggles data logging pause/resume
+boolean logData = false;
+boolean initLogFileOk = false; // if log file successfully initialized
+boolean showTimeStamp = false;
+boolean portsFound = false;
+boolean textAreaMainMsgIsRunning = false;
+boolean textFieldSearchHasText = false; // if textFieldSearch has text other than prompt text
+boolean serialPortRemoved = false; // if serial port was removed while connected
+boolean logFileExists = false; // if log file already exists when creating log file
+boolean mainUiInit, settingsUiInit, dialogBaudEditIsInit, drawPortConfigInit, drawDataConfigInit, drawLogConfigInit = false; // if UI has been initialized
+boolean commandFound = false; // true if entered command is a valid command
+boolean advancedOptions = false; // true if advanced serial port options are enabled
-String versionInfo = "SerialTerminal 2.3.0";
-String selectedPort = null; // Name of selected COM port
-String[] baudRateList = {"2400", "4800", "9600", "38400", "57600", "115200", "250000", "500000", "1000000", "2000000"};
-String selectedBaudRate = baudRateList[2];
-String[] availableCOMs; // List of available COM ports
-String oldFirstPort;
+String versionInfo = "SerialTerminal 3.0.0";
+String selectedPort = null; // Name of selected COM port
+String[] baudRateList = {"4800", "9600", "38400", "57600", "115200"};
+String selectedBaudRate = baudRateList[1];
+String[] availableCOMs; // List of available COM ports
String serialInputData = "0";
-String textFieldFileDirInput; //Input from fileDirectoryTextField
-String fileNameInput; //Input from fileNameTextField
-String fileDirectory; //Directory for saving data table
-String fileDirectoryReplaced; //Directory \ set to /
+String textFieldFileDirInput; // Input from fileDirectoryTextField
+String fileNameInput; // Input from fileNameTextField
+String fileDirectory; // Directory for saving data table
+String fileDirectoryReplaced; // Directory \ set to /
String randomFileName;
String logOutputData;
String letters[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String months[] = {"", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
-String OS; //current operating system
-String OsDirChar; //os specific directory character e.g.(windows dir is \)(linux dir is /)
-String defaultLogDir; //os specific desktop directory
+String OS; // current operating system
+String OsDirChar; // os specific directory character e.g.(windows dir is \)(linux dir is /)
+String defaultLogDir; // os specific desktop directory
String parityList[] = {"None", "Even", "Odd", "Mark", "Space"};
String dataBitList[] = {"5", "6", "7", "8"};
String stopBitList[] = {"1.0", "1.5", "2.0"};
+String selectedParityString = parityList[0]; // String value of selected parity for display purposes
+String selectedDataBitsString = dataBitList[3]; // String value of selected data bits for display purposes
+String selectedStopBitsString = stopBitList[0]; // String value of selected stop bits for display purposes
String serialPortList[];
-String enteredCommand = ""; //command entered in textFieldMain updates on enter press
-String validCommands[] = {//list of valid commands
- "-h", //help
- "-v", //version
- "-s", //connection status
- "-a", //advanced options
- "-a=true", //enable advanced options
- "-a=false", //disable advanced options
- "-connect", //connect
- "-disconnect", //disconnect
- "-clear", //clear
- "-lpause", //log pause
- "-lresume", //log resume
- "-settings", //settings
- "-tstamp", //timestamp
- "-tstamp=true", //enable timestamp
- "-tstamp=false", //disable timestamp
- "-lstart", //log start
- "-lstop", //log stop
- "-font", //set font
- "-font=1", //set font to Courier
- "-font=2", //set font to Cascadia Code
- "-font=3", //set font to JetBrains Mono (default)
- "-font=4", //set font to Liberation Mono
- "-fontsize", //set font size
- "-fontsize=10", //set font size to 10
- "-fontsize=12", //set font size to 12
- "-fontsize=14", //set font size to 14
- "-fontsize=16", //set font size to 16
- "-fontsize=18" //set font size to 18
+String enteredCommand = ""; // command entered in textFieldMain updates on enter press
+String validCommands[] = { // list of valid commands
+ "-h", // help
+ "-v", // version
+ "-s", // connection status
+ "-a", // advanced options
+ "-a=true", // enable advanced options
+ "-a=false", // disable advanced options
+ "-connect", // connect
+ "-disconnect", // disconnect
+ "-clear", // clear
+ "-lpause", // log pause
+ "-lresume", // log resume
+ "-settings", // settings
+ "-tstamp", // timestamp
+ "-tstamp=true", // enable timestamp
+ "-tstamp=false", // disable timestamp
+ "-lstart", // log start
+ "-lstop", // log stop
+ "-font", // set font
+ "-font=1", // set font to Courier
+ "-font=2", // set font to Cascadia Code
+ "-font=3", // set font to JetBrains Mono (default)
+ "-font=4", // set font to Liberation Mono
+ "-fontsize", // set font size
+ "-fontsize=10", // set font size to 10
+ "-fontsize=12", // set font size to 12
+ "-fontsize=14", // set font size to 14
+ "-fontsize=16", // set font size to 16
+ "-fontsize=18", // set font size to 18
+ "-theme", // set theme
+ "-theme=light", // set theme to light
+ "-theme=dark", // set theme to dark
+ "-theme=intellij", // set theme to intellij
+ "-theme=darcula" // set theme to darcula
}; //list of valid commands END
-String fontList[] = {"courier-prime.regular.ttf", "cascadia.code.ttf", "jetbrains-mono.regular.ttf", "liberation-mono.regular.ttf"}; //list of available fonts for textAreaMain and textFieldMain
-String selectedFont = fontList[0]; //selected font for textAreaMain and textFieldMain
+String fontList[] = {"courier-prime.regular.ttf", "cascadia.code.ttf", "jetbrains-mono.regular.ttf", "liberation-mono.regular.ttf"}; // list of available fonts for textAreaMain and textFieldMain
+String selectedFont = fontList[0]; // selected font for textAreaMain and textFieldMain
+String theme = "light"; // software theme
+StringList previousEnteredCommands = new StringList(); // previous command entered in textFieldMain
-StringList previousEnteredCommands = new StringList(); //previous command entered in textFieldMain
-Color buttonConnectRed = new Color(#EC4242); //red color for disconnected button
+Color buttonConnectRed = new Color(#EC4242); //red color for disconnected button
Color buttonConnectGreen = new Color(#3DC73D); //green color for connected button
-PImage icon; //import software icon
-
-Font labelFont = new Font("Arial", Font.PLAIN, 12); //font for labels
-Font terminalFont;
-FileWriter Writer; //create object of FileWriter for data logging
-int intBaudRate = int(selectedBaudRate); //integer value of selectedBaudRate for Serial constructor
-processing.serial.Serial COMPort = null; //create object of Serial class
+Font labelFont = new Font("Arial", Font.PLAIN, 12); // font for labels
+Font terminalFont; // font for terminal
+FileWriter Writer; // create object of FileWriter for data logging
+int intBaudRate = int(selectedBaudRate); // integer value of selectedBaudRate for Serial constructor
+processing.serial.Serial COMPort = null; // create object of Serial class
+Table preferenceTable; // preferences table
-Table preferenceTable; //preferences table
//Controls for main window
-JPanel panelMain; //main window panel
-JTextArea textAreaMain; //main window text area
-JTextField textFieldMain; //main window text field
-JTextField textFieldSearch; //main window search text field
-JScrollPane textAreaMainScrollPane; //main window text area scroll pane
-JButton buttonConnect; //main window connect button
-JButton buttonClear; //main window clear button
-JButton buttonSettings; //main window settings button
-JButton buttonLogPauseResume; //main window log pause/resume button
-Highlighter hilit; //highlighter for textAreaMain search function
-Highlighter.HighlightPainter painter; //painter for textAreaMain search function
+javax.swing.JFrame frameMainWindow; //create instance of JFrame
+java.awt.Canvas canvasMainWindow; //create instance of Canvas
+JPanel panelMain; // main window panel
+JTextArea textAreaMain; // main window text area
+JTextField textFieldMain; // main window text field
+JTextField textFieldSearch; // main window search text field
+JScrollPane textAreaMainScrollPane; // main window text area scroll pane
+JButton buttonConnect; // main window connect button
+JButton buttonClear; // main window clear button
+JButton buttonSettings; // main window settings button
+JButton buttonLogPauseResume; // main window log pause/resume button
+Highlighter highlighter; // highlighter for textAreaMain search function
+Highlighter.HighlightPainter painter; // painter for textAreaMain search function
+BufferedImage bufferedIconMain; // buffered image for software icon
+PImage iconMain; //software icon
+
//Controls for settings window
-JFrame frameSettings; //settings window frame
-JLabel labelPortConfig; //settings window Port Configuration label
-JLabel labelPort; //settings window Port label
-JLabel labelBaudRate; //settings window Baud Rate label
-JLabel labelDataConfig; //settings window Data Configuration label
-JLabel labelLogConfig; //settings window Log Configuration label
-JLabel labelPortParity; //settings window Port Parity label
-JLabel labelPortDataBits; //settings window Port Data Bits label
-JLabel labelPortStopBits; //settings window Port Stop Bits label
-JPanel panelMainSettings; //settings window main panel
-JComboBox comboBoxPort; //settings window Port combo box
-JComboBox comboBoxBaudRate; //settings window Baud Rate combo box
-JComboBox comboBoxPortParity; //settings window Port Parity combo box
-JComboBox comboBoxPortDataBits; //settings window Port Data Bits combo box
-JComboBox comboBoxPortStopBits; //settings window Port Stop Bits combo box
-JCheckBox checkBoxTimeStamp = new JCheckBox(); //settings window Time Stamp check box Initialized here due to cli dependencies
-JButton buttonOk; //settings window OK button
-JButton buttonCancel; //settings window Cancel button
-JButton buttonStartLog; //settings window Start Log button
-JButton buttonStopLog; //settings window Stop Log button
-JButton buttonBrowse; //settings window Browse button
-JTextField textFieldFileName; //settings window File Name text field
-JTextField textFieldFileDir; //settings window File Directory text field
-SpringLayout layoutSettings = new SpringLayout(); //settings window layout manager
+JLabel labelPortConfig; // settings window Port Configuration label
+JLabel labelPort; // settings window Port label
+JLabel labelBaudRate; // settings window Baud Rate label
+JLabel labelDataConfig; // settings window Data Configuration label
+JLabel labelLogConfig; // settings window Log Configuration label
+JLabel labelPortParity; // settings window Port Parity label
+JLabel labelPortDataBits; // settings window Port Data Bits label
+JLabel labelPortStopBits; // settings window Port Stop Bits label
+JDialog dialogSettingsMain; // settings window main panel
+JComboBox comboBoxPort; // settings window Port combo box
+JComboBox comboBoxBaudRate; // settings window Baud Rate combo box
+JComboBox comboBoxPortParity; // settings window Port Parity combo box
+JComboBox comboBoxPortDataBits; // settings window Port Data Bits combo box
+JComboBox comboBoxPortStopBits; // settings window Port Stop Bits combo box
+JCheckBox checkBoxTimeStamp = new JCheckBox(); // settings window Time Stamp check box Initialized here due to cli dependencies
+JButton buttonOk; // settings window OK button
+JButton buttonCancel; // settings window Cancel button
+JButton buttonStartLog; // settings window Start Log button
+JButton buttonStopLog; // settings window Stop Log button
+JButton buttonBrowse; // settings window Browse button
+JButton buttonRefreshCOMs; // settings window refresh COMs button Icon should be a refresh symbol
+JButton buttonEditBaud; // settings window edit baud rate button Icon should be ... or a pencil
+JTextField textFieldFileName; // settings window File Name text field
+JTextField textFieldFileDir; // settings window File Directory text field
+SpringLayout layoutSettings = new SpringLayout(); // settings window layout manager
+BufferedImage bufferedIconRefresh; // buffered image for refresh button icon
+BufferedImage bufferedIconEditBaud; // buffered image for edit baud rate button icon
+DefaultComboBoxModel currBaudRateModel = new DefaultComboBoxModel(baudRateList); // current model for comboBoxBaudRate
+DefaultComboBoxModel newBaudRateModel = new DefaultComboBoxModel(); // new model for comboBoxBaudRate is defined on baudEdit OK, set on settings OK
+PImage iconRefresh; // serial port refresh button icon
+PImage iconEditBaud; // serial port custom baud rate icon
+
+//Controls for baud edit window
+JDialog dialogBaudEdit; // baud rate edit popup dialog
+JTextArea textAreaBaudEdit; // dialogBaudEdit dialog text area
+JScrollPane scrollPaneBaudEdit; // dialogBaudEdit textArea scroll pane
+JButton buttonBaudEditOk; // dialogBaudEdit dialog confirm button
+JButton buttonBaudEditCancel; // dialogBaudEdit dialog cancel button
+SpringLayout layoutBaudEdit = new SpringLayout(); // dialogBaudEdit dialog layout manager
-BufferedImage bufferedIcon; //buffered image for icon