diff --git a/src/main/scala/com/devdaily/sarah/Sarah.scala b/src/main/scala/com/devdaily/sarah/Sarah.scala index 8e51f8e..58fd735 100644 --- a/src/main/scala/com/devdaily/sarah/Sarah.scala +++ b/src/main/scala/com/devdaily/sarah/Sarah.scala @@ -180,13 +180,19 @@ class Sarah { def updateUISarahIsNotListening { mainFrameController.updateUISarahIsNotListening } - def destroySplashScreen { screen.setVisible(false) screen = null } + def displayAvailableVoiceCommands(voiceCommands: scala.collection.immutable.List[String]) { + mainFrameController.displayAvailableVoiceCommands(voiceCommands) + } + + + + def loadPlugins { // get a list of subdirs in the plugins dir, assume each is a plugin log.info("Getting list of PLUGIN subdirectories, looking in '" + CANON_PLUGINS_DIR + "'") diff --git a/src/main/scala/com/devdaily/sarah/actors/Brain.scala b/src/main/scala/com/devdaily/sarah/actors/Brain.scala index 5eebcdd..70690e4 100644 --- a/src/main/scala/com/devdaily/sarah/actors/Brain.scala +++ b/src/main/scala/com/devdaily/sarah/actors/Brain.scala @@ -17,6 +17,7 @@ import _root_.com.weiglewilczek.slf4s.Logger import _root_.com.devdaily.sarah._ import _root_.com.devdaily.sarah.plugins._ import scala.io.Source +import scala.collection.mutable.ArrayBuffer object Brain { @@ -322,16 +323,19 @@ with Logging * List all the voice command the user can say. */ def listAvailableVoiceCommands() { - log.info("(Brain) Entered Brain::listAvailableVoiceCommands") + // get all voice commands from the config files (populates allVoiceCommands) loadAllUserConfigurationFilesOrDie - allVoiceCommands.foreach{ voiceCommand => - val voiceCommandKey = voiceCommand.getCommand() - printf("COMMAND: %s\n", voiceCommandKey) - } - printf("COMMAND: %s\n", "go to sleep") - printf("COMMAND: %s\n", "wake up") - printf("COMMAND: %s\n", "what can i say") - printf("COMMAND: %s\n", "soylent green is people") + + val voiceCommandsAsStrings = allVoiceCommands.map(_.getCommand) + val voiceCommandListForSarah = ArrayBuffer[String]() + voiceCommandListForSarah.addAll(voiceCommandsAsStrings) + voiceCommandListForSarah += "go to sleep" + voiceCommandListForSarah += "wake up" + voiceCommandListForSarah += "what can i say?" + voiceCommandListForSarah += "soylent green is people" + + sarah.displayAvailableVoiceCommands(voiceCommandListForSarah.toList) + } def handleUserDefinedVoiceCommand(textTheUserSaid: String) { diff --git a/src/main/scala/com/devdaily/sarah/gui/DisplayTextWindow.scala b/src/main/scala/com/devdaily/sarah/gui/DisplayTextWindow.scala new file mode 100644 index 0000000..7b88a5b --- /dev/null +++ b/src/main/scala/com/devdaily/sarah/gui/DisplayTextWindow.scala @@ -0,0 +1,92 @@ +package com.devdaily.sarah.gui + +import javax.swing.JPanel +import javax.swing.JButton +import javax.swing.JFrame +import java.awt.GridBagLayout +import javax.swing.JTextArea +import java.awt.Dimension +import java.awt.Insets +import javax.swing.JScrollPane +import java.awt.BorderLayout +import javax.swing.JLayeredPane +import javax.swing.BorderFactory +import java.awt.Graphics +import java.awt.AlphaComposite +import java.awt.Graphics2D + +/** + * TODO - fix layout stuff here. i'm going through great lengths b/c i can't remember + * swing layouts, and i'm in a rush tonight. + */ +class DisplayTextWindow(frame: BaseMainFrame, textToShow: String) { + + def getEmptyPanel: ClearPanel = { + val p = new ClearPanel + p.setSize(new Dimension(300,300)) + p.setPreferredSize(new Dimension(300,300)) + p.setMinimumSize(new Dimension(300,300)) + p.setMaximumSize(new Dimension(300,300)) + return p + } + + // use this as filler/padding + val headerPanel = getEmptyPanel + val footerPanel = getEmptyPanel + val westPanel = getEmptyPanel + val eastPanel = getEmptyPanel + + // create the text area and scroll pane + val size = new Dimension(400,300) + val editor = new JTextArea + editor.setEditable(false) + editor.setSize(size) + editor.setPreferredSize(size) + editor.setMaximumSize(size) + editor.setMinimumSize(size) + editor.setMargin(new Insets(5,15,25,15)) + editor.setText(textToShow) + + val scrollPane = new JScrollPane(editor) + scrollPane.setPreferredSize(size) + scrollPane.setMaximumSize(size) + + // add the scroll panel to a new panel + val panel = new ClearPanel + panel.setLayout(new BorderLayout) + panel.add(scrollPane, BorderLayout.CENTER) + panel.add(headerPanel, BorderLayout.NORTH) + panel.add(footerPanel, BorderLayout.SOUTH) + panel.add(westPanel, BorderLayout.WEST) + panel.add(eastPanel, BorderLayout.EAST) + + // add the panel to the glass pane, but don't show it + frame.setGlassPane(panel) + + def setVisible(b: Boolean) { + println("SET VISIBLE WAS CALLED") + frame.getGlassPane.setVisible(b) + } + +} + +/** + * A slightly clear (translucent) panel. Source code from p. 228 of Filthy Rich Clients. + */ +class ClearPanel extends JPanel { + override def paintComponent(g: Graphics) { + val clip = g.getClipBounds + val alpha = AlphaComposite.SrcOver.derive(0.65f) + val g2 = g.asInstanceOf[Graphics2D] + g2.setComposite(alpha) + g2.setColor(getBackground) + g2.fillRect(clip.x, clip.y, clip.width, clip.height) + } +} + + + + + + + diff --git a/src/main/scala/com/devdaily/sarah/gui/MicrophoneMainFrameController.scala b/src/main/scala/com/devdaily/sarah/gui/MicrophoneMainFrameController.scala index 84b52ab..7fbf3e5 100644 --- a/src/main/scala/com/devdaily/sarah/gui/MicrophoneMainFrameController.scala +++ b/src/main/scala/com/devdaily/sarah/gui/MicrophoneMainFrameController.scala @@ -10,6 +10,12 @@ import javax.swing.JLabel import java.awt.FlowLayout import com.devdaily.sarah.plugins.Utils import com.devdaily.sarah.actors.Brain +import javax.swing.JEditorPane +import java.awt.Dimension +import javax.swing.UIManager +import java.awt.Insets +import javax.swing.JScrollPane +import javax.swing.JOptionPane class MicrophoneMainFrameController(sarah: Sarah) extends BaseMainFrameController { @@ -46,6 +52,19 @@ class MicrophoneMainFrameController(sarah: Sarah) extends BaseMainFrameControlle invokeLater(headerPanel.setSarahIsSpeaking) } + def displayAvailableVoiceCommands(voiceCommands: List[String]) { + val sb = new StringBuilder + for (s <- voiceCommands) { + sb.append(s) + sb.append("\n") + } + val textToShow = sb.toString + val window = new DisplayTextWindow(getMainFrame, textToShow) + invokeLater(window.setVisible(true)) + Utils.sleep(5000) + invokeLater(window.setVisible(false)) + } + } /**