Skip to content

Commit

Permalink
Add welcome dialogs to EOCV-Sim
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Nov 21, 2024
1 parent de7d7a9 commit 2e2ad47
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ class EOCVSim(val params: Parameters = Parameters()) {

logger.info("-- Begin EOCVSim loop ($hexCode) --")

if(!config.flags.contains("showIAmA") || config.flags["showIAmA"] == true) {
DialogFactory.createIAmA(visualizer)
}

while (!eocvSimThread.isInterrupted && !destroying) {
//run all pending requested runnables
onMainUpdate.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.List;

public class Config {
public volatile Theme simTheme = Theme.Light;
public volatile Theme simTheme = Theme.Dark;

@Deprecated
public volatile double zoom = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
package com.github.serivesmejia.eocvsim.gui;

import com.github.serivesmejia.eocvsim.EOCVSim;
import com.github.serivesmejia.eocvsim.config.Config;
import com.github.serivesmejia.eocvsim.gui.dialog.*;
import com.github.serivesmejia.eocvsim.gui.dialog.SplashScreen;
import com.github.serivesmejia.eocvsim.gui.dialog.iama.IAmA;
import com.github.serivesmejia.eocvsim.gui.dialog.source.CreateCameraSource;
import com.github.serivesmejia.eocvsim.gui.dialog.source.CreateImageSource;
import com.github.serivesmejia.eocvsim.gui.dialog.source.CreateSource;
Expand Down Expand Up @@ -160,6 +162,10 @@ public static void createSplashScreen(EventHandler closeHandler) {
invokeLater(() -> new SplashScreen(closeHandler));
}

public static void createIAmA(Visualizer visualizer) {
invokeLater(() -> new IAmA(visualizer.frame, visualizer));
}

public static FileAlreadyExists.UserChoice createFileAlreadyExistsDialog(EOCVSim eocvSim) {
return new FileAlreadyExists(eocvSim.visualizer.frame, eocvSim).run();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.github.serivesmejia.eocvsim.gui

object EOCVSimIconLibrary {

val icoEOCVSim by icon("ico_eocvsim", "/images/icon/ico_eocvsim.png", false)

val icoImg by icon("ico_img", "/images/icon/ico_img.png")
val icoCam by icon("ico_cam", "/images/icon/ico_cam.png")
val icoVid by icon("ico_vid", "/images/icon/ico_vid.png")

val icoConfig by icon("ico_config", "/images/icon/ico_config.png")
val icoSlider by icon("ico_slider", "/images/icon/ico_slider.png")
val icoTextbox by icon("ico_textbox", "/images/icon/ico_textbox.png")
val icoColorPick by icon("ico_colorpick", "/images/icon/ico_colorpick.png")

val icoArrowDropdown by icon("ico_arrow_dropdown", "/images/icon/ico_arrow_dropdown.png")

val icoFlag by icon("ico_flag", "/images/icon/ico_flag.png")
val icoNotStarted by icon("ico_not_started", "/images/icon/ico_not_started.png")
val icoPlay by icon("ico_play", "/images/icon/ico_play.png")
val icoStop by icon("ico_stop", "/images/icon/ico_stop.png")

val icoGears by icon("ico_gears", "/images/icon/ico_gears.png")
val icoHammer by icon("ico_hammer", "/images/icon/ico_hammer.png")

val icoColorPickPointer by icon("ico_colorpick_pointer", "/images/icon/ico_colorpick_pointer.png")

package com.github.serivesmejia.eocvsim.gui

object EOCVSimIconLibrary {

val icoEOCVSim by icon("ico_eocvsim", "/images/icon/ico_eocvsim.png", false)

val icoImg by icon("ico_img", "/images/icon/ico_img.png")
val icoCam by icon("ico_cam", "/images/icon/ico_cam.png")
val icoVid by icon("ico_vid", "/images/icon/ico_vid.png")

val icoConfig by icon("ico_config", "/images/icon/ico_config.png")
val icoSlider by icon("ico_slider", "/images/icon/ico_slider.png")
val icoTextbox by icon("ico_textbox", "/images/icon/ico_textbox.png")
val icoColorPick by icon("ico_colorpick", "/images/icon/ico_colorpick.png")

val icoArrowDropdown by icon("ico_arrow_dropdown", "/images/icon/ico_arrow_dropdown.png")

val icoFlag by icon("ico_flag", "/images/icon/ico_flag.png")
val icoNotStarted by icon("ico_not_started", "/images/icon/ico_not_started.png")
val icoPlay by icon("ico_play", "/images/icon/ico_play.png")
val icoStop by icon("ico_stop", "/images/icon/ico_stop.png")

val icoGears by icon("ico_gears", "/images/icon/ico_gears.png")
val icoHammer by icon("ico_hammer", "/images/icon/ico_hammer.png")

val icoColorPickPointer by icon("ico_colorpick_pointer", "/images/icon/ico_colorpick_pointer.png")

val icoFirstRobotics by icon("ico_first_robotics", "/images/icon/ico_firstrobotics.png", false)
val icoPaperVision by icon("ico_paper_vision", "/images/icon/ico_ezv.png", false)
val icoUser by icon("ico_user", "/images/icon/ico_user.png")

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Visualizer {
public final ArrayList<JFrame> childFrames = new ArrayList<>();
public final ArrayList<JDialog> childDialogs = new ArrayList<>();

private final EOCVSim eocvSim;
public final EOCVSim eocvSim;
public JFrame frame;

public SwingOpenCvViewport viewport = null;
Expand Down Expand Up @@ -156,7 +156,7 @@ public void init(Theme theme) {
/*
* TOP MENU BAR
*/

frame.setJMenuBar(menuBar);

/*
Expand Down Expand Up @@ -471,7 +471,7 @@ public boolean pleaseWaitDialog(JDialog diag, String message, String subMessage,
apwd.subMsg = subMsg;
apwd.cancelBtt = cancelBtt;
}

if(size == null) size = new Dimension(400, 200);
dialog.setSize(size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() {

mHelpMenu.add(helpExportLogs)

mHelpMenu.addSeparator()

val helpIAmA = JMenuItem("I am a...")
helpIAmA.addActionListener { DialogFactory.createIAmA(eocvSim.visualizer) }

mHelpMenu.add(helpIAmA)

val helpAbout = JMenuItem("About")
helpAbout.addActionListener { DialogFactory.createAboutDialog(eocvSim) }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.github.serivesmejia.eocvsim.gui.dialog.iama

import com.github.serivesmejia.eocvsim.gui.EOCVSimIconLibrary
import com.github.serivesmejia.eocvsim.gui.Visualizer
import java.awt.Dimension
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import java.awt.GridLayout
import javax.swing.JButton
import javax.swing.JDialog
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel

class IAmA(
val parent: JFrame,
val visualizer: Visualizer
) {

val dialog = JDialog(parent)

init {
dialog.isModal = true
dialog.title = "Welcome !"

dialog.contentPane.layout = GridBagLayout()

val text = """
<b>Welcome to EOCV-Sim! We'll start with a walkthrough.</b><br>
Please select the option that best describes you.<br><br>
<b>I am..</b>
""".trimIndent()

dialog.contentPane.add(JLabel("<html><div style='text-align: center;'>$text</div></html>").apply {
font = font.deriveFont(14f)
}, GridBagConstraints().apply {
gridx = 0
gridy = 0
weightx = 1.0
weighty = 1.0
})

val buttonsPanel = JPanel().apply {
layout = GridLayout(1, 3, 10, 10)
}

buttonsPanel.add(JButton(
"<html><div style='text-align: center;'>A FIRST Robotics Team</div></html>",
EOCVSimIconLibrary.icoFirstRobotics.scaleToFit(60, 60)
).apply {
font = font.deriveFont(14f)
horizontalTextPosition = JButton.CENTER
verticalTextPosition = JButton.BOTTOM

addActionListener {
dialog.dispose()
IAmAFirstRobotics(this@IAmA.parent, visualizer)
}
})

buttonsPanel.add(JButton(
"<html><div style='text-align: center;'>A General Public User</div></html>",
EOCVSimIconLibrary.icoUser.scaleToFit(60, 60)
).apply {
font = font.deriveFont(14f)
horizontalTextPosition = JButton.CENTER
verticalTextPosition = JButton.BOTTOM

addActionListener {
dialog.dispose()
IAmAGeneralPublic(this@IAmA.parent, visualizer)
}
})

buttonsPanel.add(JButton(
"<html><div style='text-align: center;'>Specifically Interested<br>in PaperVision</div></html>",
EOCVSimIconLibrary.icoPaperVision.scaleToFit(60, 60)
).apply {
font = font.deriveFont(14f)
horizontalTextPosition = JButton.CENTER
verticalTextPosition = JButton.BOTTOM

addActionListener {
dialog.dispose()
IAmAPaperVision(this@IAmA.parent, visualizer)
}
})

dialog.contentPane.add(buttonsPanel, GridBagConstraints().apply {
gridx = 0
gridy = 1
weightx = 1.0
weighty = 1.0
})

dialog.size = Dimension(600, 250)
dialog.isResizable = false

dialog.defaultCloseOperation = JDialog.DISPOSE_ON_CLOSE
dialog.setLocationRelativeTo(null)
dialog.isVisible = true
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.github.serivesmejia.eocvsim.gui.dialog.iama

import com.github.serivesmejia.eocvsim.gui.Visualizer
import java.awt.Desktop
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import java.net.URI
import javax.swing.BorderFactory
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JButton
import javax.swing.JDialog
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel

class IAmAFirstRobotics(
parent: JFrame,
visualizer: Visualizer
) {

private val dialog = JDialog(parent).apply {
isModal = true
title = "Welcome !"
contentPane.layout = GridBagLayout()

isResizable = false
setSize(520, 230)
setLocationRelativeTo(null)
}

init {
// Create the contents panel
val contentsPanel = JPanel(GridBagLayout())

contentsPanel.border = BorderFactory.createEmptyBorder(10, 0, 0, 0)

val contentText = """
<b>Hey FTC teams! EOCV-Sim helps you develop EasyOpenCV pipelines<br>
without needing to always have the robot hardware at hand.</b><br><br>
Work with code identical to the FtcRobotController, iterate with tools like the<br>
variable tuner, and quickly visualize your code changes using workspaces.<br><br>
<b>Click on "Open Docs"</b> to learn more about EOCV-Sim and workspaces.<br>
""".trimIndent()

// Add a descriptive JLabel to the contents panel
contentsPanel.add(
JLabel("<html><div style='text-align: center;'>$contentText</div></html>").apply {
font = font.deriveFont(14f)
horizontalAlignment = JLabel.CENTER
},
GridBagConstraints().apply {
gridx = 0
gridy = 0
weightx = 1.0
weighty = 1.0
fill = GridBagConstraints.BOTH
}
)

// Create the buttons panel
val buttonsPanel = JPanel().apply {
layout = BoxLayout(this, BoxLayout.X_AXIS)

add(Box.createHorizontalGlue()) // Align the button to the right

add(JButton("Open Docs").apply {
addActionListener {
// open webpage
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(URI("https://docs.deltacv.org/eocv-sim"));
}
}
})

add(Box.createHorizontalStrut(10)) // Add some space between the buttons

add(JButton("Next").apply {
addActionListener {
dialog.dispose() // Close the dialog on click
IAmAPaperVision(parent, visualizer)
}
})

border = BorderFactory.createEmptyBorder(0, 10, 10, 10)
}

// Add the contents panel to the dialog
dialog.contentPane.add(
contentsPanel,
GridBagConstraints().apply {
gridx = 0
gridy = 0
weightx = 1.0
weighty = 1.0
fill = GridBagConstraints.BOTH
}
)

// Add the buttons panel to the dialog
dialog.contentPane.add(
buttonsPanel,
GridBagConstraints().apply {
gridx = 0
gridy = 1
weightx = 1.0
weighty = 0.0
fill = GridBagConstraints.HORIZONTAL
}
)

// Make the dialog visible
dialog.isVisible = true
}
}
Loading

0 comments on commit 2e2ad47

Please sign in to comment.