diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a1027d..4db6263 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,61 @@ { - "cSpell.words": ["Cascadia", "Lucida"] + "cSpell.words": ["Cascadia", "Lucida"], + "js/ts.suggest.completeFunctionCalls": false, + "autoalign.moveableItems": ["=", ":", "+=", "-=", "//"], + "autoalign.moveableItemsAdditional": [ + + ], + "autoalign.nonMoveableItems": [ + + "==", + "!=", + "/", + "*", + "#", + "<=", + ">=", + "=>", + "=<", + "for(", + "for (", + "if(", + "if (", + "-(", + "- (", + "(\"", + "('", + "(`", + "=~", + "&:", + ">:", + "*:", + "::", + ":active", + ":checked", + ":disabled", + ":empty", + ":enabled", + ":first-", + ":focus", + ":hover", + ":in-range", + ":invalid", + ":lang", + ":last-", + ":link", + ":not", + ":nth-", + ":only-", + ":optional", + ":out-of-range", + ":read-", + ":required", + ":root", + ":target", + ":valid", + ":visited", + "`", + "http:", + "https:" + ] } diff --git a/mainCode/.prettierrc b/mainCode/.prettierrc new file mode 100644 index 0000000..d2702b8 --- /dev/null +++ b/mainCode/.prettierrc @@ -0,0 +1,4 @@ +{ + "tabWidth": 2, + "useTabs": true +} diff --git a/mainCode/code/jfoenix-9.0.10.jar b/mainCode/code/jfoenix-9.0.10.jar new file mode 100644 index 0000000..2254e9f Binary files /dev/null and b/mainCode/code/jfoenix-9.0.10.jar differ diff --git a/mainCode/lib.pde b/mainCode/lib.pde new file mode 100644 index 0000000..caa897e --- /dev/null +++ b/mainCode/lib.pde @@ -0,0 +1,32 @@ +/*======IMPORT WINDOW LIBRARIES======*/ +import javafx.stage.Stage; //import JavaFX Stage library +import javafx.scene.canvas.Canvas; //import Canvas library +import javafx.scene.layout.Pane; //import Pane layout library +import javafx.scene.layout.StackPane; //import StackPane layout library + +//END + +/*======IMPORT UI CONTROLS LIBRARIES======*/ +import javafx.scene.control.Button; //import Button control library +import javafx.scene.control.TextField; //import TextField control library + +// TODO: Replace with FX textArea JFeonix textArea +import javafx.scene.control.TextArea; //import TextArea control library +import javafx.scene.control.Label; //import Label control library +import javafx.scene.control.ComboBox; //import ComboBox control library +import javafx.scene.control.CheckBox; //import CheckBox control library +import javafx.scene.paint.Color; //import Color library +import javafx.scene.text.Text; //import JavaFX text library +import javafx.scene.text.TextFlow; //import JavaFX text flow library +import javafx.scene.text.Font; //import JavaFX font library +import javafx.scene.layout.VBox; //import VBox layout library +import javafx.scene.layout.HBox; //import HBox layout library +import javafx.geometry.Insets; //import Dimension library +/*======IMPORT UTILITY LIBRARIES======*/ +import java.io.File; //import File library +import java.io.FileInputStream; //import FileInputStream library +import java.io.IOException; //import IOException library +import java.awt.image.BufferedImage; //import awt buffered image library +import java.util.Collection; +import java.util.Collections; +//END \ No newline at end of file diff --git a/mainCode/logData.pde b/mainCode/logData.pde index 252aaf7..8e6560e 100644 --- a/mainCode/logData.pde +++ b/mainCode/logData.pde @@ -1,53 +1,52 @@ -// initialize data logging file -public void initLogFile() { - fileNameInput = textFieldFileName.getText(); - textFieldFileDirInput = textFieldFileDir.getText() + OsDirChar; - fileDirectory = textFieldFileDirInput + fileNameInput + ".log"; - fileDirectoryReplaced = fileDirectory.replace("\\", "/"); +// // initialize data logging file +// public void initLogFile() { +// fileNameInput = textFieldFileName.getText(); +// textFieldFileDirInput = textFieldFileDir.getText() + OsDirChar; +// fileDirectory = textFieldFileDirInput + fileNameInput + ".log"; +// fileDirectoryReplaced = fileDirectory.replace("\\", "/"); - try { - File logFile = new File(fileDirectoryReplaced); - // Creating File - if (logFile.createNewFile()) { - logFileExists = false; - textAreaMainMsg("\n", "File created: " + textFieldFileDirInput + logFile.getName(), ""); - systemPrintln("File created: " + textFieldFileDirInput + logFile.getName()); - } else if (logFile.exists()) { - logFileExists = true; - textAreaMainMsg("\n", "File already exists: " + textFieldFileDirInput + logFile.getName(), ""); - systemPrintln("File already exists: " + textFieldFileDirInput + logFile.getName()); - } - } - catch (IOException e) { - textAreaMainMsg("\n", "Failed to create log file. " + e, ""); - systemPrintln("Failed to create log file. " + e); - initLogFileOk = false; - } +// try { +// File logFile = new File(fileDirectoryReplaced); +// // Creating File +// if (logFile.createNewFile()) { +// logFileExists = false; +// textAreaMainMsg("\n", "File created: " + textFieldFileDirInput + logFile.getName(), ""); +// systemPrintln("File created: " + textFieldFileDirInput + logFile.getName()); +// } else if (logFile.exists()) { +// logFileExists = true; +// textAreaMainMsg("\n", "File already exists: " + textFieldFileDirInput + logFile.getName(), ""); +// systemPrintln("File already exists: " + textFieldFileDirInput + logFile.getName()); +// } +// } +// catch (IOException e) { +// textAreaMainMsg("\n", "Failed to create log file. " + e, ""); +// systemPrintln("Failed to create log file. " + e); +// initLogFileOk = false; +// } - try { - Writer = new FileWriter(fileDirectoryReplaced, true); - initLogFileOk = true; - logData = true; - textAreaMainMsg("\n", "Logging data to. " + fileDirectory, ""); - } - catch(Exception e) { - textAreaMainMsg("\n", "Failed to init writer." + e, ""); - initLogFileOk = false; - } -} - -// write data to log file -public void writeToFile(String data) { - if (logData == true && dataLogPause == false) { - try { - Writer.append(data); - //Writer.write(data); - Writer.flush(); - loggingData = true; - } - catch(Exception e) { - textAreaMainMsg("\n", "Failed to log data." + e, ""); - } - } -} +// try { +// Writer = new FileWriter(fileDirectoryReplaced, true); +// initLogFileOk = true; +// logData = true; +// textAreaMainMsg("\n", "Logging data to. " + fileDirectory, ""); +// } +// catch(Exception e) { +// textAreaMainMsg("\n", "Failed to init writer." + e, ""); +// initLogFileOk = false; +// } +// } +// // write data to log file +// public void writeToFile(String data) { +// if (logData == true && dataLogPause == false) { +// try { +// Writer.append(data); +// //Writer.write(data); +// Writer.flush(); +// loggingData = true; +// } +// catch(Exception e) { +// textAreaMainMsg("\n", "Failed to log data." + e, ""); +// } +// } +// } diff --git a/mainCode/mainCode.pde b/mainCode/mainCode.pde index 5e1fa1f..5f82d72 100644 --- a/mainCode/mainCode.pde +++ b/mainCode/mainCode.pde @@ -1,50 +1,56 @@ + 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 +// 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 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 +// 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) { +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()); + //TextAreaMain.appendText(A + hour() + ":" + minute() + ":" + second() + " " + MSG + B); + //textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); logOutputData = A + hour() + ":" + minute() + ":" + second() + " " + MSG + B; if (initLogFileOk) { - writeToFile(logOutputData); + //writeToFile(logOutputData); } } else if (showTimeStamp == true && MSG.startsWith("\n")) { - textAreaMain.append(A + MSG + hour() + ":" + minute() + ":" + second() + " " + B); - textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); + // TextAreaMain.appendText(A + MSG + hour() + ":" + minute() + ":" + second() + " " + B); + //textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); logOutputData = A + MSG + hour() + ":" + minute() + ":" + second() + " " + B; if (initLogFileOk) { - writeToFile(logOutputData); + //writeToFile(logOutputData); } } else { - textAreaMain.append(A + MSG + B); - textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); + //TextAreaMain.appendText(A + MSG + B); + //textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); logOutputData = A + MSG + B; //print(logOutputData); if (initLogFileOk) { - writeToFile(logOutputData); + //writeToFile(logOutputData); } } } +//Function finds substring in a string and returns the position +public int findTextInString(String inputString, String txtToFind, int fromIndex) { + int position = inputString.indexOf(txtToFind, fromIndex); //get position of txtToFind in inputString + return position; //return position of txtToFind in inputString +} + //generate default random file name public String genFileName(String randomFileName) { if (lettersIndex == 26) { @@ -55,7 +61,7 @@ public String genFileName(String randomFileName) { return randomFileName; } -// get current operating system +// // get current operating system public void getOS() { if (platform == MACOS) { OS = "mac"; @@ -77,42 +83,44 @@ public void getOS() { } //initialize controls for search function -public void initSearch() { - try { - hilit = new DefaultHighlighter(); - painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); - systemPrintln("initSearch complete @ " + millis()); - } - catch (Exception e) { - systemPrintln("initSearch failed @ " + millis()); - } -} - -//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); - } - } else { //remove all highlights - hilit.removeAllHighlights(); - } - } - systemPrintln("getSearch complete @ " + millis()); - } - catch (Exception e) { //catch search exception - systemPrintln("getSearch failed @ " + millis()); - } -} - +// public void initSearch() { +// try { +// hilit = new DefaultHighlighter(); +// painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); +// systemPrintln("initSearch complete @ " + millis()); +// } +// catch (Exception e) { +// systemPrintln("initSearch failed @ " + millis()); +// } +// } +// 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); +// // } +// // } else { //remove all highlights +// // hilit.removeAllHighlights(); +// // } +// // } +// // systemPrintln("getSearch complete @ " + millis()); +// // } +// // catch (Exception e) { //catch search exception +// // systemPrintln("getSearch failed @ " + millis()); +// // } +// // VBox parent = new VBox(TextAreaMain, ButtonSettings); +// // ButtonSettings.setOnAction(event -> { +// // highlighter.highlight(parent, searchText); +// // event.consume(); +// // }); +// } //convert PImage to BufferedImage BufferedImage convertToBufferedImage(PImage imgToConvert) { imgToConvert.loadPixels(); //load pixel data @@ -146,17 +154,13 @@ public void setFont(String fontName, float fontSize) { } // Load the font - Font customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile) - .deriveFont(Font.PLAIN, fontSize); // Set style and size + Font systemFont = Font.loadFont(new FileInputStream(fontFile), fontSize); // Set style and size // Apply font to textAreaMain and textFieldMain - textAreaMain.setFont(customFont); - textFieldMain.setFont(customFont); + TextAreaMain.setFont(systemFont); + TextFieldMain.setFont(systemFont); systemPrintln("setFont complete @ " + millis()); } - catch (FontFormatException e) { - System.err.println("Invalid font format: " + e.getMessage()); - } catch (IOException e) { System.err.println("Error loading font: " + e.getMessage()); } @@ -164,99 +168,111 @@ public void setFont(String fontName, float fontSize) { // Processing setup function public void setup() { + size(700, 500, FX2D); //set initial window size + background(#FFFFFF); //set background color + surface.setTitle(versionInfo); //set surface title 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 + surface.setIcon(icon); //set software icon + canvas = (Canvas)surface.getNative(); //get native canvas + root = (StackPane)canvas.getParent(); //get parent of canvas + pane = addControls(); //add controls to pane - //add component listener for main frame - frame.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); - panelMain.repaint(); - panelMain.updateUI(); - textAreaMain.repaint(); - textAreaMain.updateUI(); - textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); - textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75)); - textAreaMainScrollPane.repaint(); - textFieldMain.setPreferredSize(new Dimension(width - 215, 30)); - textFieldMain.repaint(); - textFieldMain.updateUI(); - buttonConnect.setPreferredSize(new Dimension(width - 251, 25)); - buttonConnect.repaint(); - buttonConnect.updateUI(); + // 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 - buttonLogPauseResume.setPreferredSize(new Dimension(75, 25)); - buttonLogPauseResume.updateUI(); - buttonLogPauseResume.repaint(); + // //add component listener for main frame + // frame.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); + // panelMain.repaint(); + // panelMain.updateUI(); - buttonClear.setPreferredSize(new Dimension(75, 25)); - buttonClear.repaint(); - buttonClear.updateUI(); + // textAreaMain.repaint(); + // textAreaMain.updateUI(); + // textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); + // textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75)); + // textAreaMainScrollPane.repaint(); - buttonSettings.setPreferredSize(new Dimension(75, 25)); - buttonSettings.repaint(); - buttonSettings.updateUI(); + // textFieldMain.setPreferredSize(new Dimension(width - 215, 30)); + // textFieldMain.repaint(); + // textFieldMain.updateUI(); - textFieldSearch.setPreferredSize(new Dimension(200, 30)); - textFieldSearch.repaint(); - textFieldSearch.updateUI(); - } - } - } - ); + // buttonConnect.setPreferredSize(new Dimension(width - 251, 25)); + // buttonConnect.repaint(); + // buttonConnect.updateUI(); + // buttonLogPauseResume.setPreferredSize(new Dimension(75, 25)); + // buttonLogPauseResume.updateUI(); + // buttonLogPauseResume.repaint(); - //build main UI on event dispatch thread - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - buildMainUI(); - } - } - ); + // buttonClear.setPreferredSize(new Dimension(75, 25)); + // buttonClear.repaint(); + // buttonClear.updateUI(); + + // buttonSettings.setPreferredSize(new Dimension(75, 25)); + // buttonSettings.repaint(); + // buttonSettings.updateUI(); + + // textFieldSearch.setPreferredSize(new Dimension(200, 30)); + // textFieldSearch.repaint(); + // textFieldSearch.updateUI(); + // } + // } + // } + // ); + + + // //build main UI on event dispatch thread + // javax.swing.SwingUtilities.invokeLater(new Runnable() { + // public void run() { + // buildMainUI(); + // } + // } + // ); + + // //wait for main UI to initialize before continuing + // while (mainUiInit == false) { + // delay(1); + // } - //wait for main UI to initialize before continuing - 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 + // searchForPorts(); //search for available serial ports //set startup message length based on selected font size if (selectedFontSize == 12) { - textAreaMainMsg("", " -------------------------------------" + versionInfo + "-------------------------------------", ""); + TextAreaMainMsg("", " ------------------------------------" + versionInfo + "------------------------------------", ""); } else if (selectedFontSize == 14) { - textAreaMainMsg("", " -------------------------------" + versionInfo + "-------------------------------", ""); + TextAreaMainMsg("", " -----------------------------" + versionInfo + "-----------------------------", ""); } else if (selectedFontSize == 16) { - textAreaMainMsg("", " -----------------------" + versionInfo + "----------------------", ""); + TextAreaMainMsg("", " ------------------------" + versionInfo + "------------------------", ""); } else if (selectedFontSize == 18) { - textAreaMainMsg("", " -------------------" + versionInfo + "--------------------", ""); + TextAreaMainMsg("", " --------------------" + versionInfo + "--------------------", ""); } - textAreaMainMsg("\n", "Enter -h for help", ""); //print help message + TextAreaMainMsg("\n", "Enter -h for help", ""); //print help message systemPrintln("Startup complete" + " @ " + millis()); } // END setup -// Processing loop function -public void draw() { -} +// // Processing loop function +// public void draw() { +// } + +// //Processing settings function +// public void settings() { +// size(wndMinW, wndMinH); +// } -//Processing settings function -public void settings() { - size(wndMinW, wndMinH); -} diff --git a/mainCode/mainPaneControls.pde b/mainCode/mainPaneControls.pde new file mode 100644 index 0000000..d2793d0 --- /dev/null +++ b/mainCode/mainPaneControls.pde @@ -0,0 +1,440 @@ +// //build main window controls +// void buildMainUI() { +// drawPanelMain(); +// drawButtonConnect(); +// drawButtonClear(); +// drawButtonLogPauseResume(); +// drawButtonSettings(); +// drawTextAreaMain(); +// drawTextFieldMain(); +// 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()); +// } else { +// mainUiInit = false; +// } +// } + +// 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()); +// panelMain.repaint(); +// } +// //draw main window textarea +// void drawTextAreaMain() { +// textAreaMain = new JTextArea(); +// textAreaMainScrollPane = new JScrollPane(textAreaMain); +// textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75)); +// textAreaMain.setEditable(false); +// textAreaMain.setLineWrap(true); +// panelMain.add(textAreaMainScrollPane); +// systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// textAreaMain.repaint(); +// } + +// //draw main window textfield +// void drawTextFieldMain() { +// textFieldMain = new JTextField(); +// textFieldMain.setPreferredSize(new Dimension(width - 215, 30)); +// textFieldMain.setText("Press return key to send text..."); +// textFieldMain.setForeground(Color.GRAY); +// panelMain.add(textFieldMain); +// textFieldMain.setEditable(true); +// textFieldMain.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); +// //add focus listener for textFieldMain +// textFieldMain.addFocusListener(new FocusListener() { + +// //focus gained event handler +// @Override +// public void focusGained(FocusEvent fe) { +// if (textFieldMain.getText().equals("Press return key to send text...")) { +// textFieldMain.setText(""); +// textFieldMain.setForeground(Color.BLACK); +// systemPrintln("textFieldMain focus gained" + " @ " + millis()); +// } +// } + +// //focus lost event handler +// @Override +// public void focusLost(FocusEvent fe) { +// if (textFieldMain.getText().isEmpty()) { +// textFieldMain.setText("Press return key to send text..."); +// textFieldMain.setForeground(Color.GRAY); +// systemPrintln("textFieldMain focus lost" + " @ " + millis()); +// } +// } +// } +// ); + +// //add action listener for textFieldMain +// textFieldMain.addActionListener(new ActionListener() { +// @Override + +// public void actionPerformed(ActionEvent e) { +// 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 +// } +// } +// // 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 +// } + +// previousEnteredCommands.append(textFieldMain.getText()); //store entered command + +// //limit previous commands to a set amount of entries +// 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()); +// } +// } +// ); + +// textFieldMain.addKeyListener(new KeyAdapter() { +// @Override +// public void keyPressed(KeyEvent evt) { +// //handle up arrow keyPress +// if (evt.getKeyCode() == KeyEvent.VK_UP) { + +// if (prevCommandsIndex < previousEnteredCommands.size()) { +// prevCommandsIndex++; // decrement previous commands index +// } +// // if up key press count is less than or equal to previous commands size, get previous command +// if (previousEnteredCommands.size() > 0) { +// 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"); +// } + +// // //handle down arrow keyPress +// if (evt.getKeyCode() == KeyEvent.VK_DOWN) { +// if (prevCommandsIndex > 1) { +// prevCommandsIndex--; // decrement previous commands index +// } else { +// prevCommandsIndex = 0; // set previous commands index to zero which clears textFieldMain's text +// } +// // if previous commands length an previous commands index is greater than zero, get next command +// if (previousEnteredCommands.size() > 0 && prevCommandsIndex > 0) { +// String nextCommand = previousEnteredCommands.get(previousEnteredCommands.size() - prevCommandsIndex); // get next entered command +// textFieldMain.setText(nextCommand); // print next entered command to textFieldMain +// } else { +// textFieldMain.setText(""); // clear textFieldMain if at the most recent command +// } +// systemPrintln("Down arrow key pressed"); // debug print +// } +// systemPrintln("Key pressed: " + evt.getKeyCode() + " " + prevCommandsIndex); // debug print +// } +// } +// ); +// systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); // debug print +// textFieldMain.repaint(); // repaint textFieldMain +// } + +// // draw main window textFieldSearch textfield +// void drawTextFieldSearch() { +// textFieldSearch = new JTextField(); +// textFieldSearch.setPreferredSize(new Dimension(200, 30)); +// textFieldSearch.setFont(new Font("Monospaced", Font.PLAIN, 14)); +// textFieldSearch.setText("Enter search text."); +// textFieldSearch.setForeground(Color.GRAY); +// panelMain.add(textFieldSearch); +// textFieldSearch.setEditable(true); + +// //add focus listener for textFieldSearch +// textFieldSearch.addFocusListener(new FocusListener() { + +// //focus gained event handler +// @Override +// public void focusGained(FocusEvent fe) { +// if (textFieldSearch.getText().equals("Enter search text.")) { +// textFieldSearch.setText(""); +// textFieldSearch.setForeground(Color.BLACK); +// textFieldSearchHasText = false; +// systemPrintln("textFieldSearch focus gained" + " @ " + millis()); +// } +// textFieldSearchHasText = true; +// } + +// //focus lost event handler +// @Override +// public void focusLost(FocusEvent fe) { +// if (textFieldSearch.getText().isEmpty()) { +// textFieldSearch.setText("Enter search text."); +// textFieldSearch.setForeground(Color.GRAY); +// textFieldSearchHasText = false; +// systemPrintln("textFieldSearch focus lost" + " @ " + millis()); +// } +// textFieldSearchHasText = true; +// } +// } +// ); + +// //add action listener for textFieldSearch +// textFieldSearch.addActionListener(new ActionListener() { +// //action performed event handler +// @Override +// public void actionPerformed(ActionEvent e) { +// textFieldSearchHasText = true; +// getSearch(textFieldSearch.getText()); +// systemPrintln("textFieldSearch keyPressed Enter" + " @ " + millis()); +// } +// } +// ); + +// //add document listener for textFieldSearch +// textFieldSearch.getDocument().addDocumentListener(new DocumentListener() { +// //insert text update event handler +// @Override +// public void insertUpdate(DocumentEvent e) { +// getSearch(textFieldSearch.getText()); +// } + +// //remove text update handler +// @Override +// public void removeUpdate(DocumentEvent e) { +// getSearch(textFieldSearch.getText()); +// } + +// //text changed event handler +// @Override +// public void changedUpdate(DocumentEvent e) { +// } +// } +// ); + +// systemPrintln("EDT textFieldSearch = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// textFieldSearch.repaint(); +// } + +// //draw main window connect button +// void drawButtonConnect() { +// buttonConnect = new JButton(); +// buttonConnect.setPreferredSize(new Dimension(width - 251, 25)); +// buttonConnect.setBackground(buttonConnectRed); +// buttonConnect.setFocusPainted(false); +// panelMain.add(buttonConnect); + +// //add action listener for buttonConnect +// buttonConnect.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent actionEvent) { +// if (connectedToCOM == false) { +// //connectToCOM = true; +// connectPort(); +// } else if (connectedToCOM == true) { +// //connectToCOM = false; +// disconnectPort(); +// } +// systemPrintln("buttonConnect clicked" + " @ " + millis()); +// } +// } + +// ); +// systemPrintln("EDT buttonConnect = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// buttonConnect.repaint(); +// } + +// //draw main window clear button +// void drawButtonClear() { +// buttonClear = new JButton(); +// buttonClear.setPreferredSize(new Dimension(75, 25)); +// buttonClear.setMargin(new Insets(5, 5, 5, 5)); +// buttonClear.setText("Clear"); +// buttonClear.setFocusPainted(false); +// panelMain.add(buttonClear); + +// //add action listener for buttonClear +// buttonClear.addActionListener(new ActionListener() { +// public void actionPerformed(ActionEvent actionEvent) { +// textAreaMain.setText(""); + +// systemPrintln("buttonClear clicked" + " @ " + millis()); +// } +// } +// ); +// systemPrintln("EDT buttonClear = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// buttonClear.repaint(); +// } + +// //draw main window settings button +// void drawButtonSettings() { +// buttonSettings = new JButton(); +// buttonSettings.setPreferredSize(new Dimension(75, 25)); +// buttonSettings.setMargin(new Insets(5, 5, 5, 5)); +// buttonSettings.setText("Settings"); +// buttonSettings.setFocusPainted(false); +// panelMain.add(buttonSettings); + +// buttonSettings.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent actionEvent) { +// if (frameSettings == 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)); +// } +// systemPrintln("buttonSettings clicked" + " @ " + millis()); +// } +// } +// ); +// systemPrintln("EDT buttonSettings = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// buttonSettings.repaint(); +// } + +// //draw main window data logging pause/resume button +// void drawButtonLogPauseResume() { +// buttonLogPauseResume = new JButton(); +// buttonLogPauseResume.setPreferredSize(new Dimension(75, 25)); +// buttonLogPauseResume.setMargin(new Insets(0, 0, 0, 0)); +// buttonLogPauseResume.setText("Log On/Off"); +// buttonLogPauseResume.setFocusPainted(false); +// panelMain.add(buttonLogPauseResume); + +// //add action listener for buttonLogPauseResume +// buttonLogPauseResume.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent actionEvent) { +// if (loggingData == true) { +// if (dataLogPause == false) { +// textAreaMainMsg("\n", "Paused data logging", ""); +// dataLogPause = true; +// } else { +// dataLogPause = false; +// textAreaMainMsg("\n", "Resumed data logging", ""); +// } +// } +// systemPrintln("buttonLogPauseResume clicked" + " @ " + millis()); +// } +// } +// ); +// systemPrintln("EDT buttonLogPauseResume = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// buttonLogPauseResume.repaint(); +// } + +Pane addControls() { + pane = new Pane(); //create pane for main window controls + root.getChildren().add(pane); + addMainUI(); //add main window UI controls to pane + + return pane; +} + +//UI controls in main window top row HBox +private void initTopHBoxUi() { + /*====== Connect Button ======*/ + ButtonConnect = new Button("Connect"); + ButtonConnect.setPrefSize(width - 251, 25); + ButtonConnect.setPadding(new Insets(0, 0, 0, 0)); + ButtonConnect.setFont(Font.font("Oxygen", 14)); + //END Connect Button + + /*====== Clear Button ======*/ + ButtonClear = new Button("Clear"); + ButtonClear.setPrefSize(75, 25); + //add action listener for ButtonClear clears TextAreaMain + ButtonClear.setOnAction(event -> { + try { + TextAreaMain.clear(); + } + catch (Exception err) { + systemPrintln("Error clearing text area: " + err.getMessage()); + } + } + ); + //END Clear Button + + /*====== Log Pause/Resume Button ======*/ + ButtonLogPauseResume = new Button("Log On/Off"); + ButtonLogPauseResume.setPrefSize(75, 25); + ButtonLogPauseResume.setPadding(new Insets(0, 0, 0, 0)); + //END Log Pause/Resume Button + + /*====== Settings Button ======*/ + ButtonSettings = new Button("Settings"); + ButtonSettings.setPrefSize(75, 25); + ButtonSettings.setOnAction(event -> { + String txtToFind = TextFieldMain.getText(); + int position = findTextInString(TextAreaMain.getText(), txtToFind, indexFrom); + TextAreaMain.selectRange(position, position + txtToFind.length()); + indexFrom = position+txtToFind.length(); + } + ); + //END Settings Button + + //create HBox for top buttons and add buttons to HBox + topUiHBox = new HBox(ButtonConnect, ButtonClear, ButtonLogPauseResume, ButtonSettings); + topUiHBox.setSpacing(wndPD); + //END top buttons +} + +private void initTextAreaMain() { + /*====== Main Window Terminal Text Area ======*/ + TextAreaMain = new TextArea("qwreqtextryhojhdvohggfnbirehapttextju40836y584ythkldfbntextniey5t0q3tex49t8iregkjvmsdfvbotextp90q473qt94upojgrbfn8etext0rq5y9u3jotextrghnpbf09uetnektbsf"); + TextAreaMain.setLayoutX(wndPD); + TextAreaMain.setLayoutY(wndPD*2 + ButtonConnect.getPrefHeight()); + TextAreaMain.setPrefSize(width - wndPD*2, height - 75); + TextAreaMain.setEditable(false); + TextAreaMain.setStyle("-fx-highlight-fill: yellow; -fx-highlight-text-fill: black;"); //set highlight color for search function + //END Main Window Terminal Text Area +} + +//UI controls in main window bottom row HBox +private void initBottomHBoxUi() { + /*====== Main Window Text input Field ======*/ + TextFieldMain = new TextField(); + TextFieldMain.setLayoutX(wndPD); + TextFieldMain.setLayoutY(wndPD + TextAreaMain.getLayoutY() + TextAreaMain.getPrefHeight()); + TextFieldMain.setPrefSize(width - wndPD*2, 30); + pane.getChildren().add(TextFieldMain); + //END Main Window Text input Field + + /*====== Main Window Search Text Field ======*/ + TextFieldSearch = new TextField("Enter search text."); + TextFieldSearch.setLayoutX(wndPD*2 + TextFieldMain.getPrefWidth()); + TextFieldSearch.setLayoutY(wndPD + TextAreaMain.getLayoutY() + TextAreaMain.getPrefHeight()); + TextFieldSearch.setPrefSize(200, 30); + pane.getChildren().add(TextFieldSearch); + //END Main Window Search Text Field + + //create HBox for bottom text fields and add text fields to HBox + bottomUiHBox = new HBox(TextFieldMain); + bottomUiHBox.setSpacing(wndPD); +} + +//add main window UI controls to pane +private void addMainUI() { + initTopHBoxUi(); + initTextAreaMain(); + initBottomHBoxUi(); + mainUiVBox = new VBox(); + mainUiVBox.setLayoutX(wndPD); + mainUiVBox.setLayoutY(wndPD); + mainUiVBox.setSpacing(wndPD); + mainUiVBox.getChildren().addAll(topUiHBox, TextAreaMain, bottomUiHBox); + pane.getChildren().add(mainUiVBox); +} + diff --git a/mainCode/mainWindowUI.pde b/mainCode/mainWindowUI.pde deleted file mode 100644 index 5098f5e..0000000 --- a/mainCode/mainWindowUI.pde +++ /dev/null @@ -1,336 +0,0 @@ -//build main window controls -void buildMainUI() { - drawPanelMain(); - drawButtonConnect(); - drawButtonClear(); - drawButtonLogPauseResume(); - drawButtonSettings(); - drawTextAreaMain(); - drawTextFieldMain(); - 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()); - } else { - mainUiInit = false; - } -} - -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()); - panelMain.repaint(); -} -//draw main window textarea -void drawTextAreaMain() { - textAreaMain = new JTextArea(); - textAreaMainScrollPane = new JScrollPane(textAreaMain); - textAreaMainScrollPane.setPreferredSize(new Dimension(width - 10, height - 75)); - textAreaMain.setEditable(false); - textAreaMain.setLineWrap(true); - panelMain.add(textAreaMainScrollPane); - systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - textAreaMain.repaint(); -} - -//draw main window textfield -void drawTextFieldMain() { - textFieldMain = new JTextField(); - textFieldMain.setPreferredSize(new Dimension(width - 215, 30)); - textFieldMain.setText("Press return key to send text..."); - textFieldMain.setForeground(Color.GRAY); - panelMain.add(textFieldMain); - textFieldMain.setEditable(true); - textFieldMain.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); - //add focus listener for textFieldMain - textFieldMain.addFocusListener(new FocusListener() { - - //focus gained event handler - @Override - public void focusGained(FocusEvent fe) { - if (textFieldMain.getText().equals("Press return key to send text...")) { - textFieldMain.setText(""); - textFieldMain.setForeground(Color.BLACK); - systemPrintln("textFieldMain focus gained" + " @ " + millis()); - } - } - - //focus lost event handler - @Override - public void focusLost(FocusEvent fe) { - if (textFieldMain.getText().isEmpty()) { - textFieldMain.setText("Press return key to send text..."); - textFieldMain.setForeground(Color.GRAY); - systemPrintln("textFieldMain focus lost" + " @ " + millis()); - } - } - } - ); - - //add action listener for textFieldMain - textFieldMain.addActionListener(new ActionListener() { - @Override - - public void actionPerformed(ActionEvent e) { - 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 - } - } - // 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 - } - - previousEnteredCommands.append(textFieldMain.getText()); //store entered command - - //limit previous commands to a set amount of entries - 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()); - } - } - ); - - textFieldMain.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent evt) { - //handle up arrow keyPress - if (evt.getKeyCode() == KeyEvent.VK_UP) { - - if (prevCommandsIndex < previousEnteredCommands.size()) { - prevCommandsIndex++; // decrement previous commands index - } - // if up key press count is less than or equal to previous commands size, get previous command - if (previousEnteredCommands.size() > 0) { - 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"); - } - - // //handle down arrow keyPress - if (evt.getKeyCode() == KeyEvent.VK_DOWN) { - if (prevCommandsIndex > 1) { - prevCommandsIndex--; // decrement previous commands index - } else { - prevCommandsIndex = 0; // set previous commands index to zero which clears textFieldMain's text - } - // if previous commands length an previous commands index is greater than zero, get next command - if (previousEnteredCommands.size() > 0 && prevCommandsIndex > 0) { - String nextCommand = previousEnteredCommands.get(previousEnteredCommands.size() - prevCommandsIndex); // get next entered command - textFieldMain.setText(nextCommand); // print next entered command to textFieldMain - } else { - textFieldMain.setText(""); // clear textFieldMain if at the most recent command - } - systemPrintln("Down arrow key pressed"); // debug print - } - systemPrintln("Key pressed: " + evt.getKeyCode() + " " + prevCommandsIndex); // debug print - } - } - ); - systemPrintln("EDT txtAreaMain = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); // debug print - textFieldMain.repaint(); // repaint textFieldMain -} - -// draw main window textFieldSearch textfield -void drawTextFieldSearch() { - textFieldSearch = new JTextField(); - textFieldSearch.setPreferredSize(new Dimension(200, 30)); - textFieldSearch.setFont(new Font("Monospaced", Font.PLAIN, 14)); - textFieldSearch.setText("Enter search text."); - textFieldSearch.setForeground(Color.GRAY); - panelMain.add(textFieldSearch); - textFieldSearch.setEditable(true); - - //add focus listener for textFieldSearch - textFieldSearch.addFocusListener(new FocusListener() { - - //focus gained event handler - @Override - public void focusGained(FocusEvent fe) { - if (textFieldSearch.getText().equals("Enter search text.")) { - textFieldSearch.setText(""); - textFieldSearch.setForeground(Color.BLACK); - textFieldSearchHasText = false; - systemPrintln("textFieldSearch focus gained" + " @ " + millis()); - } - textFieldSearchHasText = true; - } - - //focus lost event handler - @Override - public void focusLost(FocusEvent fe) { - if (textFieldSearch.getText().isEmpty()) { - textFieldSearch.setText("Enter search text."); - textFieldSearch.setForeground(Color.GRAY); - textFieldSearchHasText = false; - systemPrintln("textFieldSearch focus lost" + " @ " + millis()); - } - textFieldSearchHasText = true; - } - } - ); - - //add action listener for textFieldSearch - textFieldSearch.addActionListener(new ActionListener() { - //action performed event handler - @Override - public void actionPerformed(ActionEvent e) { - textFieldSearchHasText = true; - getSearch(textFieldSearch.getText()); - systemPrintln("textFieldSearch keyPressed Enter" + " @ " + millis()); - } - } - ); - - //add document listener for textFieldSearch - textFieldSearch.getDocument().addDocumentListener(new DocumentListener() { - //insert text update event handler - @Override - public void insertUpdate(DocumentEvent e) { - getSearch(textFieldSearch.getText()); - } - - //remove text update handler - @Override - public void removeUpdate(DocumentEvent e) { - getSearch(textFieldSearch.getText()); - } - - //text changed event handler - @Override - public void changedUpdate(DocumentEvent e) { - } - } - ); - - systemPrintln("EDT textFieldSearch = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - textFieldSearch.repaint(); -} - -//draw main window connect button -void drawButtonConnect() { - buttonConnect = new JButton(); - buttonConnect.setPreferredSize(new Dimension(width - 251, 25)); - buttonConnect.setBackground(buttonConnectRed); - buttonConnect.setFocusPainted(false); - panelMain.add(buttonConnect); - - //add action listener for buttonConnect - buttonConnect.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - if (connectedToCOM == false) { - //connectToCOM = true; - connectPort(); - } else if (connectedToCOM == true) { - //connectToCOM = false; - disconnectPort(); - } - systemPrintln("buttonConnect clicked" + " @ " + millis()); - } - } - - ); - systemPrintln("EDT buttonConnect = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - buttonConnect.repaint(); -} - -//draw main window clear button -void drawButtonClear() { - buttonClear = new JButton(); - buttonClear.setPreferredSize(new Dimension(75, 25)); - buttonClear.setMargin(new Insets(5, 5, 5, 5)); - buttonClear.setText("Clear"); - buttonClear.setFocusPainted(false); - panelMain.add(buttonClear); - - //add action listener for buttonClear - buttonClear.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - textAreaMain.setText(""); - - systemPrintln("buttonClear clicked" + " @ " + millis()); - } - } - ); - systemPrintln("EDT buttonClear = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - buttonClear.repaint(); -} - -//draw main window settings button -void drawButtonSettings() { - buttonSettings = new JButton(); - buttonSettings.setPreferredSize(new Dimension(75, 25)); - buttonSettings.setMargin(new Insets(5, 5, 5, 5)); - buttonSettings.setText("Settings"); - buttonSettings.setFocusPainted(false); - panelMain.add(buttonSettings); - - buttonSettings.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - if (frameSettings == 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)); - } - systemPrintln("buttonSettings clicked" + " @ " + millis()); - } - } - ); - systemPrintln("EDT buttonSettings = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - buttonSettings.repaint(); -} - -//draw main window data logging pause/resume button -void drawButtonLogPauseResume() { - buttonLogPauseResume = new JButton(); - buttonLogPauseResume.setPreferredSize(new Dimension(75, 25)); - buttonLogPauseResume.setMargin(new Insets(0, 0, 0, 0)); - buttonLogPauseResume.setText("Log On/Off"); - buttonLogPauseResume.setFocusPainted(false); - panelMain.add(buttonLogPauseResume); - - //add action listener for buttonLogPauseResume - buttonLogPauseResume.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent actionEvent) { - if (loggingData == true) { - if (dataLogPause == false) { - textAreaMainMsg("\n", "Paused data logging", ""); - dataLogPause = true; - } else { - dataLogPause = false; - textAreaMainMsg("\n", "Resumed data logging", ""); - } - } - systemPrintln("buttonLogPauseResume clicked" + " @ " + millis()); - } - } - ); - systemPrintln("EDT buttonLogPauseResume = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - buttonLogPauseResume.repaint(); -} diff --git a/mainCode/processCommands.pde b/mainCode/processCommands.pde index aef2dd8..7f0fd0a 100644 --- a/mainCode/processCommands.pde +++ b/mainCode/processCommands.pde @@ -1,114 +1,114 @@ -public void processCommands() { - if (enteredCommand.equals("-h")) { - textAreaMainMsg("\n", "Available Commands:", "\n"); //display help message - textAreaMainMsg("", "-h : Show this help message", "\n"); //list available commands - textAreaMainMsg("", "-v : Show version information", "\n"); //shows version info - textAreaMainMsg("", "-s : Show connection status", "\n"); //shows connection status - textAreaMainMsg("", "-a= : Enable advanced serial port options in settings window", "\n"); //toggle advanced options - textAreaMainMsg("", "-connect : Connect to selected serial port", "\n"); //connect to serial port - textAreaMainMsg("", "-disconnect : Disconnect from connected serial port", "\n"); //disconnect from serial port - textAreaMainMsg("", "-clear : Clear the main text area", "\n"); //clears text area - textAreaMainMsg("", "-lpause : Pause data logging", "\n"); //pause data logging - textAreaMainMsg("", "-lresume : Resume data logging", "\n"); //resume data logging - textAreaMainMsg("", "-settings : Open settings window", "\n"); //open settings window - 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 - } else if (enteredCommand.equals("-clear")) { //clear main text area - textAreaMain.setText(""); //clear main text area - } else if (enteredCommand.equals("-v")) { //display version info - textAreaMainMsg("\n", versionInfo, ""); //display version info - } else if (enteredCommand.startsWith("-a")) { //toggle advanced options - if (enteredCommand.contains("=")) { - String enteredCommandSplit = enteredCommand.split("=")[1]; - if (enteredCommandSplit.equals("true")) { - frameSettings = null; //reset settings frame to force rebuild with new advanced options - advancedOptions = true; //enable advanced options - setTableData(); //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 - advancedOptions = false;//disable advanced options - setTableData(); //save advanced options to preferences table - textAreaMainMsg("\n", "Advanced serial port options disabled.", ""); - } - } else { - textAreaMainMsg("\n", "Invalid command parameter. Use -a=", ""); //invalid format message - } - } else if (enteredCommand.startsWith("-tstamp")) { //toggle time stamp - if (enteredCommand.contains("=")) { - String enteredCommandSplit = enteredCommand.split("=")[1]; - if (enteredCommandSplit.equals("true")) { - showTimeStamp = true; //enable time stamp - checkBoxTimeStamp.setSelected(true); //update settings window checkbox - textAreaMainMsg("\n", "Enabled time stamp.", ""); - } else if (enteredCommandSplit.equals("false")) { - textAreaMainMsg("\n", "Disabled time stamp.", ""); - showTimeStamp = false; //disable time stamp - checkBoxTimeStamp.setSelected(false); //update settings window checkbox - } - } else { - 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 - 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)); - } - } else if (enteredCommand.equals("-connect")) { //connect to serial port - connectPort(); //connect to serial port - } else if (enteredCommand.equals("-disconnect")) { //disconnect from serial port - disconnectPort(); //disconnect from serial port - } else if (enteredCommand.equals("-lpause") && loggingData == true) { //pause data logging - textAreaMainMsg("\n", "Paused data logging", ""); - dataLogPause = true; //pause data logging - } else if (enteredCommand.equals("-lresume") && loggingData == true) { //resume data logging - dataLogPause = false; //resume data logging - textAreaMainMsg("\n", "Resumed data logging", ""); - } else if (enteredCommand.equals("-s")) { // print connection status - if (connectedToCOM) { - if (advancedOptions == true) { - textAreaMainMsg("\n", "Connection Status: Connected to " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, ""); - } else { - textAreaMainMsg("\n", "Connection Status: Connected to " + selectedPort + "@" + selectedBaudRate, ""); - } - } else { - textAreaMainMsg("\n", "Connection Status: Not connected to any serial port.", ""); - } - } else if (enteredCommand.startsWith("-font") && !enteredCommand.startsWith("-fontsize")) { //set font - if (enteredCommand.contains("=")) { - String enteredCommandSplit = enteredCommand.split("=")[1]; - int fontIndex = int(enteredCommandSplit) - 1; - if (fontIndex >= 0 && fontIndex < fontList.length) { - selectedFont = fontList[fontIndex]; //set selected font - setTableData(); //save selected font to preferences table - setFont(selectedFont, selectedFontSize); //apply selected font - textAreaMainMsg("\n", "Set font to " + selectedFont + ".", ""); - } else { - textAreaMainMsg("\n", "Invalid font number. Use -font= where fontNumber is between 1 and " + fontList.length + ".", ""); //invalid font number message - } - } else { - textAreaMainMsg("\n", "Invalid command parameter. Use -font= e.g. -font=1", ""); //invalid format message - } - } else if (enteredCommand.startsWith("-fontsize")) { //set font size - if (enteredCommand.contains("=")) { - String enteredCommandSplit = enteredCommand.split("=")[1]; - 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 - setFont(selectedFont, selectedFontSize); //apply selected font size - textAreaMainMsg("\n", "Set font size to " + selectedFontSize + ".", ""); - } else { - textAreaMainMsg("\n", "Invalid font size. Use -fontsize= where size is 12, 14, 16, or 18.", ""); //invalid font size message - } - } else { - textAreaMainMsg("\n", "Invalid command parameter. Use -fontsize=", ""); //invalid format message - } - } -} // END processCommands +// public void processCommands() { +// if (enteredCommand.equals("-h")) { +// textAreaMainMsg("\n", "Available Commands:", "\n"); //display help message +// textAreaMainMsg("", "-h : Show this help message", "\n"); //list available commands +// textAreaMainMsg("", "-v : Show version information", "\n"); //shows version info +// textAreaMainMsg("", "-s : Show connection status", "\n"); //shows connection status +// textAreaMainMsg("", "-a= : Enable advanced serial port options in settings window", "\n"); //toggle advanced options +// textAreaMainMsg("", "-connect : Connect to selected serial port", "\n"); //connect to serial port +// textAreaMainMsg("", "-disconnect : Disconnect from connected serial port", "\n"); //disconnect from serial port +// textAreaMainMsg("", "-clear : Clear the main text area", "\n"); //clears text area +// textAreaMainMsg("", "-lpause : Pause data logging", "\n"); //pause data logging +// textAreaMainMsg("", "-lresume : Resume data logging", "\n"); //resume data logging +// textAreaMainMsg("", "-settings : Open settings window", "\n"); //open settings window +// 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 +// } else if (enteredCommand.equals("-clear")) { //clear main text area +// textAreaMain.setText(""); //clear main text area +// } else if (enteredCommand.equals("-v")) { //display version info +// textAreaMainMsg("\n", versionInfo, ""); //display version info +// } else if (enteredCommand.startsWith("-a")) { //toggle advanced options +// if (enteredCommand.contains("=")) { +// String enteredCommandSplit = enteredCommand.split("=")[1]; +// if (enteredCommandSplit.equals("true")) { +// frameSettings = null; //reset settings frame to force rebuild with new advanced options +// advancedOptions = true; //enable advanced options +// setTableData(); //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 +// advancedOptions = false;//disable advanced options +// setTableData(); //save advanced options to preferences table +// textAreaMainMsg("\n", "Advanced serial port options disabled.", ""); +// } +// } else { +// textAreaMainMsg("\n", "Invalid command parameter. Use -a=", ""); //invalid format message +// } +// } else if (enteredCommand.startsWith("-tstamp")) { //toggle time stamp +// if (enteredCommand.contains("=")) { +// String enteredCommandSplit = enteredCommand.split("=")[1]; +// if (enteredCommandSplit.equals("true")) { +// showTimeStamp = true; //enable time stamp +// checkBoxTimeStamp.setSelected(true); //update settings window checkbox +// textAreaMainMsg("\n", "Enabled time stamp.", ""); +// } else if (enteredCommandSplit.equals("false")) { +// textAreaMainMsg("\n", "Disabled time stamp.", ""); +// showTimeStamp = false; //disable time stamp +// checkBoxTimeStamp.setSelected(false); //update settings window checkbox +// } +// } else { +// 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 +// 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)); +// } +// } else if (enteredCommand.equals("-connect")) { //connect to serial port +// connectPort(); //connect to serial port +// } else if (enteredCommand.equals("-disconnect")) { //disconnect from serial port +// disconnectPort(); //disconnect from serial port +// } else if (enteredCommand.equals("-lpause") && loggingData == true) { //pause data logging +// textAreaMainMsg("\n", "Paused data logging", ""); +// dataLogPause = true; //pause data logging +// } else if (enteredCommand.equals("-lresume") && loggingData == true) { //resume data logging +// dataLogPause = false; //resume data logging +// textAreaMainMsg("\n", "Resumed data logging", ""); +// } else if (enteredCommand.equals("-s")) { // print connection status +// if (connectedToCOM) { +// if (advancedOptions == true) { +// textAreaMainMsg("\n", "Connection Status: Connected to " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, ""); +// } else { +// textAreaMainMsg("\n", "Connection Status: Connected to " + selectedPort + "@" + selectedBaudRate, ""); +// } +// } else { +// textAreaMainMsg("\n", "Connection Status: Not connected to any serial port.", ""); +// } +// } else if (enteredCommand.startsWith("-font") && !enteredCommand.startsWith("-fontsize")) { //set font +// if (enteredCommand.contains("=")) { +// String enteredCommandSplit = enteredCommand.split("=")[1]; +// int fontIndex = int(enteredCommandSplit) - 1; +// if (fontIndex >= 0 && fontIndex < fontList.length) { +// selectedFont = fontList[fontIndex]; //set selected font +// setTableData(); //save selected font to preferences table +// setFont(selectedFont, selectedFontSize); //apply selected font +// textAreaMainMsg("\n", "Set font to " + selectedFont + ".", ""); +// } else { +// textAreaMainMsg("\n", "Invalid font number. Use -font= where fontNumber is between 1 and " + fontList.length + ".", ""); //invalid font number message +// } +// } else { +// textAreaMainMsg("\n", "Invalid command parameter. Use -font= e.g. -font=1", ""); //invalid format message +// } +// } else if (enteredCommand.startsWith("-fontsize")) { //set font size +// if (enteredCommand.contains("=")) { +// String enteredCommandSplit = enteredCommand.split("=")[1]; +// 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 +// setFont(selectedFont, selectedFontSize); //apply selected font size +// textAreaMainMsg("\n", "Set font size to " + selectedFontSize + ".", ""); +// } else { +// textAreaMainMsg("\n", "Invalid font size. Use -fontsize= where size is 12, 14, 16, or 18.", ""); //invalid font size message +// } +// } else { +// textAreaMainMsg("\n", "Invalid command parameter. Use -fontsize=", ""); //invalid format message +// } +// } +// } // END processCommands diff --git a/mainCode/processPreferences.pde b/mainCode/processPreferences.pde index 55ec2b4..ebd7986 100644 --- a/mainCode/processPreferences.pde +++ b/mainCode/processPreferences.pde @@ -1,22 +1,23 @@ // function to load the preferences table public void loadTable () { - preferenceTable = loadTable("data/preferences.csv", "header"); - systemPrintln("loadTable complete @ " + millis()); + preferenceTable = loadTable("data/preferences.csv", "header"); + systemPrintln("loadTable complete @ " + millis()); } // function to get data from preferences table 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()); + advancedOptions = boolean(preferenceTable.getInt(0, "mode")); + selectedFont = preferenceTable.getString(0, "font"); + selectedFontSize = preferenceTable.getInt(0, "fontSize"); + setFont(selectedFont,selectedFontSize); + systemPrintln("getTableData complete @ " + millis()); } +// function to write data to preferences table and save 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 - saveTable(preferenceTable, "data/preferences.csv"); - systemPrintln("setTableData complete @ " + millis()); + 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 + saveTable(preferenceTable, "data/preferences.csv"); + systemPrintln("setTableData complete @ " + millis()); } diff --git a/mainCode/processSerial.pde b/mainCode/processSerial.pde index baa6081..5b041ab 100644 --- a/mainCode/processSerial.pde +++ b/mainCode/processSerial.pde @@ -1,125 +1,124 @@ -//search for available serial ports -public void searchForPorts() { +////search for available serial ports +//public void searchForPorts() { - if (connectedToCOM == false) { - availableCOMs = Serial.list(); - if (availableCOMs.length > 0) { - portsFound = true; - selectedPort = availableCOMs[0]; - if (advancedOptions == true) { - buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); - } else { - buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); - } - } else { - portsFound = false; - buttonConnect.setText("No serial ports found"); - } - } else if (connectedToCOM) { - availableCOMs = Serial.list(); - if (availableCOMs[0].equals(selectedPort) == true || availableCOMs[comboBoxPortSelectedIndex].equals(selectedPort) == true) { - systemPrintln("connected port found" + availableCOMs[0]); - } else { - } - } -} +// if (connectedToCOM == false) { +// availableCOMs = Serial.list(); +// if (availableCOMs.length > 0) { +// portsFound = true; +// selectedPort = availableCOMs[0]; +// if (advancedOptions == true) { +// buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); +// } else { +// buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); +// } +// } else { +// portsFound = false; +// buttonConnect.setText("No serial ports found"); +// } +// } else if (connectedToCOM) { +// availableCOMs = Serial.list(); +// if (availableCOMs[0].equals(selectedPort) == true || availableCOMs[comboBoxPortSelectedIndex].equals(selectedPort) == true) { +// systemPrintln("connected port found" + availableCOMs[0]); +// } else { +// } +// } +//} -// connect to serial port -public void connectPort() { - if (COMPort == null) { - try { - if (advancedOptions == true) { - // print connecting statements - textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, ""); - systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); +//// connect to serial port +//public void connectPort() { +// if (COMPort == null) { +// try { +// if (advancedOptions == true) { +// // print connecting statements +// textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, ""); +// systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); - // initialize processing serial port - COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate, selectedParity, selectedDataBits, selectedStopBits); - systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); - textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "\n"); - buttonConnect.setText("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); - buttonConnect.setBackground(buttonConnectGreen); - connectedToCOM = true; - } else { - // print connecting statements - textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate, ""); - systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate); +// // initialize processing serial port +// COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate, selectedParity, selectedDataBits, selectedStopBits); +// systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); +// textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits, "\n"); +// buttonConnect.setText("Connected to: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); +// buttonConnect.setBackground(buttonConnectGreen); +// connectedToCOM = true; +// } else { +// // print connecting statements +// textAreaMainMsg("\n", "Connecting to.. " + selectedPort + "@" + selectedBaudRate, ""); +// systemPrintln("Connecting to.. " + selectedPort + "@" + selectedBaudRate); - // initialize processing serial port - COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate); - systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate); - textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate, "\n"); - buttonConnect.setText("Connected-click to disconnect " + selectedPort + "@" + selectedBaudRate); - buttonConnect.setBackground(buttonConnectGreen); - connectedToCOM = true; - } - } - catch (Exception error) { - connectToCOM = false; - connectedToCOM = false; - COMPort = null; - textAreaMainMsg("\n", error.toString(), ""); - systemPrintln(error.toString()); - } - } -} +// // initialize processing serial port +// COMPort = new processing.serial. Serial(this, selectedPort, intBaudRate); +// systemPrintln("Connected to: " + selectedPort + "@" + selectedBaudRate); +// textAreaMainMsg("\n", "Connected to: " + selectedPort + "@" + selectedBaudRate, "\n"); +// buttonConnect.setText("Connected-click to disconnect " + selectedPort + "@" + selectedBaudRate); +// buttonConnect.setBackground(buttonConnectGreen); +// connectedToCOM = true; +// } +// } +// catch (Exception error) { +// connectToCOM = false; +// connectedToCOM = false; +// COMPort = null; +// textAreaMainMsg("\n", error.toString(), ""); +// systemPrintln(error.toString()); +// } +// } +//} -//disconnect serial port -public void disconnectPort() { - if (COMPort != null) { - try { - COMPort.clear(); - COMPort.stop(); - COMPort.dispose(); - COMPort = null; - connectedToCOM = false; - if (advancedOptions == true) { - systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); - 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); - textAreaMainMsg("\n", "Disconnected from: " + selectedPort + "@" + selectedBaudRate, ""); - buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); - buttonConnect.setBackground(buttonConnectRed); - } - } - catch (Exception error) { - textAreaMainMsg("\n", error.toString(), ""); - systemPrintln(error.toString()); - } - } -} +////disconnect serial port +//public void disconnectPort() { +// if (COMPort != null) { +// try { +// COMPort.clear(); +// COMPort.stop(); +// COMPort.dispose(); +// COMPort = null; +// connectedToCOM = false; +// if (advancedOptions == true) { +// systemPrintln("Disconnected from: " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); +// 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); +// textAreaMainMsg("\n", "Disconnected from: " + selectedPort + "@" + selectedBaudRate, ""); +// buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); +// buttonConnect.setBackground(buttonConnectRed); +// } +// } +// catch (Exception error) { +// textAreaMainMsg("\n", error.toString(), ""); +// systemPrintln(error.toString()); +// } +// } +//} -//write data to serial port -public void writeToPort(String i) { - try { - if (i.length() > 0) { - COMPort.write(i); - textAreaMainMsg("\n", i, "\n"); - } else { - COMPort.write('\n'); - textAreaMainMsg("", "\n", ""); - } - } - catch (Exception error) { +////write data to serial port +//public void writeToPort(String i) { +// try { +// if (i.length() > 0) { +// COMPort.write(i); +// textAreaMainMsg("\n", i, "\n"); +// } 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."); - } else { - textAreaMainMsg("\n", "ERROR--Failed to send data..." + '\n' + error, ""); - systemPrintln("ERROR--Failed to send data..." + '\n' + error); - } - } -} - -//read data from serial port -public void serialEvent(Serial p) { - serialInputData = p.readString(); - textAreaMainMsg("", serialInputData, ""); - textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); //set textAreaMain to autoscroll -} +// 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."); +// } else { +// textAreaMainMsg("\n", "ERROR--Failed to send data..." + '\n' + error, ""); +// systemPrintln("ERROR--Failed to send data..." + '\n' + error); +// } +// } +//} +////read data from serial port +//public void serialEvent(Serial p) { +// serialInputData = p.readString(); +// textAreaMainMsg("", serialInputData, ""); +// textAreaMain.setCaretPosition(textAreaMain.getDocument().getLength()); //set textAreaMain to autoscroll +//} diff --git a/mainCode/settingsWindowUI.pde b/mainCode/settingsWindowUI.pde index 22f521e..a13527b 100644 --- a/mainCode/settingsWindowUI.pde +++ b/mainCode/settingsWindowUI.pde @@ -1,491 +1,491 @@ -//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); - //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); - - //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()); - settingsUiInit = true; - frameSettings.setVisible(true); //make settings window visible - } else { - settingsUiInit = false; - } - - // end of settingsUI -} - -//draw port config section ui -void drawPortConfig() { - //draw (Port Config) label - 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); - - //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.NORTH, labelPort, 30, SpringLayout.NORTH, labelPortConfig); - panelMainSettings.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.NORTH, labelBaudRate, 40, SpringLayout.NORTH, labelPort); - panelMainSettings.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.NORTH, labelPortParity, 40, SpringLayout.NORTH, labelBaudRate); - if (advancedOptions == true) { - panelMainSettings.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.NORTH, labelPortDataBits, 40, SpringLayout.NORTH, labelPortParity); - if (advancedOptions == true) { - panelMainSettings.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.NORTH, labelPortStopBits, 40, SpringLayout.NORTH, labelPortDataBits); - if (advancedOptions == true) { - panelMainSettings.add(labelPortStopBits); - } - - //draw COM port combo box - comboBoxPort = new JComboBox(availableCOMs); - comboBoxPort.setPreferredSize(new Dimension(110, 20)); - //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); - comboBoxPort.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - systemPrintln("User selected " + comboBoxPort.getSelectedItem().toString()); - } - } - ); - - //draw Baud Rate combo box - comboBoxBaudRate = new JComboBox(baudRateList); - comboBoxBaudRate.setPreferredSize(new Dimension(110, 20)); - comboBoxBaudRate.setSelectedIndex(2); - comboBoxBaudRate.setEditable(true); - layoutSettings.putConstraint(SpringLayout.WEST, comboBoxBaudRate, 80, SpringLayout.WEST, labelBaudRate); - layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxBaudRate, 0, SpringLayout.NORTH, labelBaudRate); - panelMainSettings.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()); - } - } - ); - - //draw Parity combo box - comboBoxPortParity = new JComboBox(parityList); - comboBoxPortParity.setPreferredSize(new Dimension(110, 20)); - comboBoxPortParity.setSelectedIndex(0); - layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortParity, 80, SpringLayout.WEST, labelPortParity); - layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortParity, 0, SpringLayout.NORTH, labelPortParity); - if (advancedOptions == true) { - panelMainSettings.add(comboBoxPortParity); - } - - //add action listener to comboBoxPortParity - comboBoxPortParity.addActionListener(new ActionListener() { - - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - - systemPrintln("User selected " + comboBoxPortParity.getSelectedItem().toString() + " @ " + millis()); - } - } - ); - - //draw Data Bits combo box - comboBoxPortDataBits = new JComboBox(dataBitList); - comboBoxPortDataBits.setPreferredSize(new Dimension(110, 20)); - comboBoxPortDataBits.setSelectedIndex(3); - layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortDataBits, 80, SpringLayout.WEST, labelPortDataBits); - layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortDataBits, 0, SpringLayout.NORTH, labelPortDataBits); - if (advancedOptions == true) { - panelMainSettings.add(comboBoxPortDataBits); - } - - //add action listener to comboBoxPortDataBits - comboBoxPortDataBits.addActionListener(new ActionListener() { - - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - systemPrintln("User selected " + comboBoxPortDataBits.getSelectedItem().toString() + " @ " + millis()); - } - } - ); - - //draw Stop Bits combo box - comboBoxPortStopBits = new JComboBox(stopBitList); - comboBoxPortStopBits.setPreferredSize(new Dimension(110, 20)); - comboBoxPortStopBits.setSelectedIndex(0); - layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortStopBits, 80, SpringLayout.WEST, labelPortStopBits); - layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortStopBits, 0, SpringLayout.NORTH, labelPortStopBits); - if (advancedOptions == true) { - panelMainSettings.add(comboBoxPortStopBits); - } - - //add action listener to comboBoxPortStopBits - comboBoxPortStopBits.addActionListener(new ActionListener() { - - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - - systemPrintln("User selected " + comboBoxPortStopBits.getSelectedItem().toString() + " @ " + millis()); - } - } - ); - - //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) { - drawPortConfigInit = true; - systemPrintln("EDT drawPortConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - } else { - drawPortConfigInit = false; - } - - // end of drawPortConfig -} - -//draw data config ui -void drawDataConfig() { - //draw (Data Configuration) label - 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); - - //draw TimeStamp checkbox - checkBoxTimeStamp = new JCheckBox("Time Stamp"); - checkBoxTimeStamp.setPreferredSize(new Dimension(120, 20)); - 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); - - //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()); - } - } - ); - - //check if all components initialized successfully - if (labelDataConfig != null && checkBoxTimeStamp != null) { - drawDataConfigInit = true; - systemPrintln("EDT drawDataConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); - } else { - drawDataConfigInit = false; - } - // end of drawDataConfig -} - -//draw data logging ui -void drawLogConfig() { - //draw (Log Configuration) label - 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); - - // 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.NORTH, textFieldFileDir, 30, SpringLayout.NORTH, labelLogConfig); - panelMainSettings.add(textFieldFileDir); - - //add focus listener to textFieldFileDir - textFieldFileDir.addFocusListener(new FocusListener() { - - // add focusGained event listener to textFieldFileDir - @Override - public void focusGained(FocusEvent fe) { - //if (textFieldFileDir.getText().equals("file directory")) { - // textFieldFileDir.setText(""); - textFieldFileDir.setForeground(Color.BLACK); - //} - systemPrintln("textFieldFileDir focus gained" + " @ " + millis()); - } - - //add focusLost event listener to textFieldFileDir - @Override - public void focusLost(FocusEvent fe) { - //if (textFieldFileDir.getText().isEmpty()) { - //textFieldFileDir.setText("file directory"); - textFieldFileDir.setForeground(Color.GRAY); - //} - systemPrintln("textFieldFileDir focus lost" + " @ " + millis()); - } - } - ); - - //draw textFieldFileName TextField - textFieldFileName = new JTextField(genFileName(randomFileName)); - 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.NORTH, textFieldFileName, 30, SpringLayout.NORTH, textFieldFileDir); - panelMainSettings.add(textFieldFileName); - - //add focus listener to textFieldFileName - textFieldFileName.addFocusListener(new FocusListener() { - - //focus gained event handler - @Override - public void focusGained(FocusEvent fe) { - //if (textFieldFileName.getText().equals("file name")) { - //textFieldFileName.setText(""); - textFieldFileName.setForeground(Color.BLACK); - //} - systemPrintln("textFieldFileName focus gained" + " @ " + millis()); - } - - //focus lost event handler - @Override - public void focusLost(FocusEvent fe) { - //if (textFieldFileName.getText().isEmpty()) { - //textFieldFileName.setText("file name"); - textFieldFileName.setForeground(Color.GRAY); - //} - systemPrintln("textFieldFileName focus lost" + " @ " + millis()); - } - } - ); - - - //draw buttonBrowse Button - buttonBrowse = new JButton("Browse"); - buttonBrowse.setPreferredSize(new Dimension(60, 20)); - buttonBrowse.setMargin(new Insets(0, 0, 0, 0)); - buttonBrowse.setFocusPainted(false); - layoutSettings.putConstraint(SpringLayout.WEST, buttonBrowse, 160, SpringLayout.WEST, textFieldFileName); - layoutSettings.putConstraint(SpringLayout.NORTH, buttonBrowse, 0, SpringLayout.NORTH, textFieldFileDir); - panelMainSettings.add(buttonBrowse); - - //add action listener to buttonBrowse - buttonBrowse.addActionListener(new ActionListener() { - - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - - JFileChooser fileChooser = new JFileChooser(); //initialize new JFileChooser - fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY); //set JFileChooser to only select directories - int i = fileChooser.showOpenDialog(fileChooser); //show JFileChooser - - //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()); - 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()); - } - } - ); - - //draw buttonStartLog Button - buttonStartLog = new JButton("Start"); - buttonStartLog.setPreferredSize(new Dimension(60, 20)); - buttonStartLog.setMargin(new Insets(0, 0, 0, 0)); - buttonStartLog.setFocusPainted(false); - layoutSettings.putConstraint(SpringLayout.WEST, buttonStartLog, 0, SpringLayout.WEST, buttonBrowse); - layoutSettings.putConstraint(SpringLayout.NORTH, buttonStartLog, 30, SpringLayout.NORTH, buttonBrowse); - panelMainSettings.add(buttonStartLog); - //add action listener to buttonStartLog - buttonStartLog.addActionListener(new ActionListener() { - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - if (loggingData == false) { - dataLogPause = false; - initLogFile(); - } - systemPrintln("buttonStartLog clicked" + " @ " + millis()); - } - } - ); - - //draw buttonStopLog Button - buttonStopLog = new JButton("Stop"); - buttonStopLog.setPreferredSize(new Dimension(60, 20)); - buttonStopLog.setMargin(new Insets(0, 0, 0, 0)); - buttonStopLog.setFocusPainted(false); - layoutSettings.putConstraint(SpringLayout.WEST, buttonStopLog, 0, SpringLayout.WEST, buttonStartLog); - layoutSettings.putConstraint(SpringLayout.NORTH, buttonStopLog, 30, SpringLayout.NORTH, buttonStartLog); - panelMainSettings.add(buttonStopLog); - - //add action listener to buttonStopLog - buttonStopLog.addActionListener(new ActionListener() { - - //action performed event handler - public void actionPerformed(ActionEvent actionEvent) { - try { - if (loggingData || dataLogPause) { - Writer.flush(); - Writer.close(); - Writer = null; - logData = false; - textAreaMainMsg("\n", "Stopped logging data to: " + fileDirectory, ""); - loggingData = false; - } - } - catch (Exception e) { - textAreaMainMsg("\n", "Failed to stop logging data. " + e, ""); - } - systemPrintln("buttonStopLog clicked" + " @ " + millis()); - } - } - ); - - //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()); - } else { - drawLogConfigInit = false; - } - - // end of drawLogConfig -} +// //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); +// //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); + +// //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()); +// settingsUiInit = true; +// frameSettings.setVisible(true); //make settings window visible +// } else { +// settingsUiInit = false; +// } + +// // end of settingsUI +// } + +// //draw port config section ui +// void drawPortConfig() { +// //draw (Port Config) label +// 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); + +// //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.NORTH, labelPort, 30, SpringLayout.NORTH, labelPortConfig); +// panelMainSettings.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.NORTH, labelBaudRate, 40, SpringLayout.NORTH, labelPort); +// panelMainSettings.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.NORTH, labelPortParity, 40, SpringLayout.NORTH, labelBaudRate); +// if (advancedOptions == true) { +// panelMainSettings.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.NORTH, labelPortDataBits, 40, SpringLayout.NORTH, labelPortParity); +// if (advancedOptions == true) { +// panelMainSettings.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.NORTH, labelPortStopBits, 40, SpringLayout.NORTH, labelPortDataBits); +// if (advancedOptions == true) { +// panelMainSettings.add(labelPortStopBits); +// } + +// //draw COM port combo box +// comboBoxPort = new JComboBox(availableCOMs); +// comboBoxPort.setPreferredSize(new Dimension(110, 20)); +// //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); +// comboBoxPort.addActionListener(new ActionListener() { +// public void actionPerformed(ActionEvent actionEvent) { +// systemPrintln("User selected " + comboBoxPort.getSelectedItem().toString()); +// } +// } +// ); + +// //draw Baud Rate combo box +// comboBoxBaudRate = new JComboBox(baudRateList); +// comboBoxBaudRate.setPreferredSize(new Dimension(110, 20)); +// comboBoxBaudRate.setSelectedIndex(2); +// comboBoxBaudRate.setEditable(true); +// layoutSettings.putConstraint(SpringLayout.WEST, comboBoxBaudRate, 80, SpringLayout.WEST, labelBaudRate); +// layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxBaudRate, 0, SpringLayout.NORTH, labelBaudRate); +// panelMainSettings.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()); +// } +// } +// ); + +// //draw Parity combo box +// comboBoxPortParity = new JComboBox(parityList); +// comboBoxPortParity.setPreferredSize(new Dimension(110, 20)); +// comboBoxPortParity.setSelectedIndex(0); +// layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortParity, 80, SpringLayout.WEST, labelPortParity); +// layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortParity, 0, SpringLayout.NORTH, labelPortParity); +// if (advancedOptions == true) { +// panelMainSettings.add(comboBoxPortParity); +// } + +// //add action listener to comboBoxPortParity +// comboBoxPortParity.addActionListener(new ActionListener() { + +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { + +// systemPrintln("User selected " + comboBoxPortParity.getSelectedItem().toString() + " @ " + millis()); +// } +// } +// ); + +// //draw Data Bits combo box +// comboBoxPortDataBits = new JComboBox(dataBitList); +// comboBoxPortDataBits.setPreferredSize(new Dimension(110, 20)); +// comboBoxPortDataBits.setSelectedIndex(3); +// layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortDataBits, 80, SpringLayout.WEST, labelPortDataBits); +// layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortDataBits, 0, SpringLayout.NORTH, labelPortDataBits); +// if (advancedOptions == true) { +// panelMainSettings.add(comboBoxPortDataBits); +// } + +// //add action listener to comboBoxPortDataBits +// comboBoxPortDataBits.addActionListener(new ActionListener() { + +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { +// systemPrintln("User selected " + comboBoxPortDataBits.getSelectedItem().toString() + " @ " + millis()); +// } +// } +// ); + +// //draw Stop Bits combo box +// comboBoxPortStopBits = new JComboBox(stopBitList); +// comboBoxPortStopBits.setPreferredSize(new Dimension(110, 20)); +// comboBoxPortStopBits.setSelectedIndex(0); +// layoutSettings.putConstraint(SpringLayout.WEST, comboBoxPortStopBits, 80, SpringLayout.WEST, labelPortStopBits); +// layoutSettings.putConstraint(SpringLayout.NORTH, comboBoxPortStopBits, 0, SpringLayout.NORTH, labelPortStopBits); +// if (advancedOptions == true) { +// panelMainSettings.add(comboBoxPortStopBits); +// } + +// //add action listener to comboBoxPortStopBits +// comboBoxPortStopBits.addActionListener(new ActionListener() { + +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { + +// systemPrintln("User selected " + comboBoxPortStopBits.getSelectedItem().toString() + " @ " + millis()); +// } +// } +// ); + +// //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) { +// drawPortConfigInit = true; +// systemPrintln("EDT drawPortConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// } else { +// drawPortConfigInit = false; +// } + +// // end of drawPortConfig +// } + +// //draw data config ui +// void drawDataConfig() { +// //draw (Data Configuration) label +// 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); + +// //draw TimeStamp checkbox +// checkBoxTimeStamp = new JCheckBox("Time Stamp"); +// checkBoxTimeStamp.setPreferredSize(new Dimension(120, 20)); +// 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); + +// //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()); +// } +// } +// ); + +// //check if all components initialized successfully +// if (labelDataConfig != null && checkBoxTimeStamp != null) { +// drawDataConfigInit = true; +// systemPrintln("EDT drawDataConfig = " + javax.swing.SwingUtilities.isEventDispatchThread() + " @ " + millis()); +// } else { +// drawDataConfigInit = false; +// } +// // end of drawDataConfig +// } + +// //draw data logging ui +// void drawLogConfig() { +// //draw (Log Configuration) label +// 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); + +// // 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.NORTH, textFieldFileDir, 30, SpringLayout.NORTH, labelLogConfig); +// panelMainSettings.add(textFieldFileDir); + +// //add focus listener to textFieldFileDir +// textFieldFileDir.addFocusListener(new FocusListener() { + +// // add focusGained event listener to textFieldFileDir +// @Override +// public void focusGained(FocusEvent fe) { +// //if (textFieldFileDir.getText().equals("file directory")) { +// // textFieldFileDir.setText(""); +// textFieldFileDir.setForeground(Color.BLACK); +// //} +// systemPrintln("textFieldFileDir focus gained" + " @ " + millis()); +// } + +// //add focusLost event listener to textFieldFileDir +// @Override +// public void focusLost(FocusEvent fe) { +// //if (textFieldFileDir.getText().isEmpty()) { +// //textFieldFileDir.setText("file directory"); +// textFieldFileDir.setForeground(Color.GRAY); +// //} +// systemPrintln("textFieldFileDir focus lost" + " @ " + millis()); +// } +// } +// ); + +// //draw textFieldFileName TextField +// textFieldFileName = new JTextField(genFileName(randomFileName)); +// 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.NORTH, textFieldFileName, 30, SpringLayout.NORTH, textFieldFileDir); +// panelMainSettings.add(textFieldFileName); + +// //add focus listener to textFieldFileName +// textFieldFileName.addFocusListener(new FocusListener() { + +// //focus gained event handler +// @Override +// public void focusGained(FocusEvent fe) { +// //if (textFieldFileName.getText().equals("file name")) { +// //textFieldFileName.setText(""); +// textFieldFileName.setForeground(Color.BLACK); +// //} +// systemPrintln("textFieldFileName focus gained" + " @ " + millis()); +// } + +// //focus lost event handler +// @Override +// public void focusLost(FocusEvent fe) { +// //if (textFieldFileName.getText().isEmpty()) { +// //textFieldFileName.setText("file name"); +// textFieldFileName.setForeground(Color.GRAY); +// //} +// systemPrintln("textFieldFileName focus lost" + " @ " + millis()); +// } +// } +// ); + + +// //draw buttonBrowse Button +// buttonBrowse = new JButton("Browse"); +// buttonBrowse.setPreferredSize(new Dimension(60, 20)); +// buttonBrowse.setMargin(new Insets(0, 0, 0, 0)); +// buttonBrowse.setFocusPainted(false); +// layoutSettings.putConstraint(SpringLayout.WEST, buttonBrowse, 160, SpringLayout.WEST, textFieldFileName); +// layoutSettings.putConstraint(SpringLayout.NORTH, buttonBrowse, 0, SpringLayout.NORTH, textFieldFileDir); +// panelMainSettings.add(buttonBrowse); + +// //add action listener to buttonBrowse +// buttonBrowse.addActionListener(new ActionListener() { + +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { + +// JFileChooser fileChooser = new JFileChooser(); //initialize new JFileChooser +// fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY); //set JFileChooser to only select directories +// int i = fileChooser.showOpenDialog(fileChooser); //show JFileChooser + +// //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()); +// 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()); +// } +// } +// ); + +// //draw buttonStartLog Button +// buttonStartLog = new JButton("Start"); +// buttonStartLog.setPreferredSize(new Dimension(60, 20)); +// buttonStartLog.setMargin(new Insets(0, 0, 0, 0)); +// buttonStartLog.setFocusPainted(false); +// layoutSettings.putConstraint(SpringLayout.WEST, buttonStartLog, 0, SpringLayout.WEST, buttonBrowse); +// layoutSettings.putConstraint(SpringLayout.NORTH, buttonStartLog, 30, SpringLayout.NORTH, buttonBrowse); +// panelMainSettings.add(buttonStartLog); +// //add action listener to buttonStartLog +// buttonStartLog.addActionListener(new ActionListener() { +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { +// if (loggingData == false) { +// dataLogPause = false; +// initLogFile(); +// } +// systemPrintln("buttonStartLog clicked" + " @ " + millis()); +// } +// } +// ); + +// //draw buttonStopLog Button +// buttonStopLog = new JButton("Stop"); +// buttonStopLog.setPreferredSize(new Dimension(60, 20)); +// buttonStopLog.setMargin(new Insets(0, 0, 0, 0)); +// buttonStopLog.setFocusPainted(false); +// layoutSettings.putConstraint(SpringLayout.WEST, buttonStopLog, 0, SpringLayout.WEST, buttonStartLog); +// layoutSettings.putConstraint(SpringLayout.NORTH, buttonStopLog, 30, SpringLayout.NORTH, buttonStartLog); +// panelMainSettings.add(buttonStopLog); + +// //add action listener to buttonStopLog +// buttonStopLog.addActionListener(new ActionListener() { + +// //action performed event handler +// public void actionPerformed(ActionEvent actionEvent) { +// try { +// if (loggingData || dataLogPause) { +// Writer.flush(); +// Writer.close(); +// Writer = null; +// logData = false; +// textAreaMainMsg("\n", "Stopped logging data to: " + fileDirectory, ""); +// loggingData = false; +// } +// } +// catch (Exception e) { +// textAreaMainMsg("\n", "Failed to stop logging data. " + e, ""); +// } +// systemPrintln("buttonStopLog clicked" + " @ " + millis()); +// } +// } +// ); + +// //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()); +// } else { +// drawLogConfigInit = false; +// } + +// // end of drawLogConfig +// } diff --git a/mainCode/variables.pde b/mainCode/variables.pde index 55bdf0d..809e3df 100644 --- a/mainCode/variables.pde +++ b/mainCode/variables.pde @@ -6,12 +6,15 @@ 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 wndPD = 5; //padding for main window controls 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 indexFrom = 0; + 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) @@ -94,56 +97,88 @@ String selectedFont = fontList[0]; //selected font for textAreaMain and textFiel StringList previousEnteredCommands = new StringList(); //previous command entered in textFieldMain -Color buttonConnectRed = new Color(#EC4242); //red color for disconnected button -Color buttonConnectGreen = new Color(#3DC73D); //green color for connected 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 labelFont = new Font("Arial", Font.PLAIN, 12); //font for labels Font terminalFont; -FileWriter Writer; //create object of FileWriter for data logging +//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 //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 - -//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 +Pane pane; +Canvas canvas; +StackPane root; +Button ButtonConnect; //main window connect button +Button ButtonClear; //main window clear button +Button ButtonLogPauseResume; //main window log pause/resume button +Button ButtonSettings; //main window settings button +TextArea TextAreaMain; //main window text area +TextField TextFieldMain; //main window text field +TextField TextFieldSearch; //main window search text field +HBox topUiHBox; //HBox for top row of UI controls +HBox bottomUiHBox; //HBox for bottom row of UI controls +VBox mainUiVBox; //VBox for all main UI controls +//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 +//JFXHighlighter highlighter; //highlighter for textAreaMain search function + +/*======Settings Window Controls======*/ +Pane PaneSettings; //settings window pane +Stage StageSettings; //settings window stage +/*======Settings Window "Port Configuration" Controls======*/ +Label LabelPortConfig; // settings window "Port Configuration" label +Label LabelPort; // settings window "Port" comboBox label +Label LabelBaudRate; // settings window "Baud Rate" comboBox label +Label LabelPortParity; // settings window "Parity" comboBox label +Label LabelPortDataBits; // settings window "Data Bits" comboBox label +Label LabelPortStopBits; // settings window "Stop Bits" comboBox label + +/*======Settings Window "Data Configuration" Controls======*/ +Label LabelDataConfig; //settings window "Data Configuration" label +/*======Settings Window "Log Configuration" Controls======*/ +Label LabelLogConfig; //settings window "Log Configuration" label + +//END Settings Window Controls + +//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 BufferedImage bufferedIcon; //buffered image for icon +