Skip to content

Commit

Permalink
Major UI upgrades, implement Paint Style & make VisionProcessors work…
Browse files Browse the repository at this point in the history
… with the variable tuner
  • Loading branch information
serivesmejia committed Aug 20, 2023
1 parent 235a2ce commit 05e462a
Show file tree
Hide file tree
Showing 54 changed files with 796 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,25 @@ public void init(Theme theme) {
* TELEMETRY
*/

telemetryPanel.setBorder(new EmptyBorder(0, 20, 20, 20));
rightContainer.add(telemetryPanel);
JPanel telemetryWithInsets = new JPanel();
telemetryWithInsets.setLayout(new BoxLayout(telemetryWithInsets, BoxLayout.LINE_AXIS));
telemetryWithInsets.setBorder(new EmptyBorder(0, 20, 20, 20));

telemetryWithInsets.add(telemetryPanel);

rightContainer.add(telemetryWithInsets);

//global
frame.getContentPane().setDropTarget(new InputSourceDropTarget(eocvSim));

tunerCollapsible = new CollapsiblePanelX("Tuner", null);
tunerCollapsible = new CollapsiblePanelX("Tuner", null, null);
tunerCollapsible.setLayout(new BoxLayout(tunerCollapsible, BoxLayout.LINE_AXIS));
tunerCollapsible.setVisible(false);

JScrollPane tunerScrollPane = new JScrollPane(tunerMenuPanel);
tunerScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tunerScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

tunerCollapsible.add(tunerScrollPane);

frame.add(tunerCollapsible, BorderLayout.SOUTH);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* Copyright (c) 2023 Sebastian Erives
* Credit where it's due - based off of https://stackoverflow.com/a/52956783
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.github.serivesmejia.eocvsim.gui.component

import java.awt.Color
Expand All @@ -9,23 +33,33 @@ import javax.swing.JPanel
import javax.swing.border.LineBorder
import javax.swing.border.TitledBorder

class CollapsiblePanelX(title: String?, titleCol: Color?) : JPanel() {
class CollapsiblePanelX @JvmOverloads constructor(
title: String?,
titleCol: Color?,
borderCol: Color? = Color.white
) : JPanel() {
private val border: TitledBorder
private var visibleSize: Dimension? = null
private var collapsible = true

var isHidden = false
private set

init {
border = TitledBorder(title)
val titleAndDescriptor = if(isHidden) {
"$title (click here to expand)"
} else {
"$title (click here to hide)"
}

border = TitledBorder(titleAndDescriptor)

border.titleColor = titleCol
border.border = LineBorder(Color.white)
border.border = LineBorder(borderCol)

setBorder(border)

// as Titleborder has no access to the Label we fake the size data ;)
val l = JLabel(title)
val l = JLabel(titleAndDescriptor)
val size = l.getPreferredSize()

addMouseListener(object : MouseAdapter() {
Expand All @@ -41,9 +75,9 @@ class CollapsiblePanelX(title: String?, titleCol: Color?) : JPanel() {
e.isVisible = !isHidden

border.title = if(isHidden) {
"$title (hidden)"
"$title (click here to expand)"
} else {
title
"$title (click here to hide)"
}

isHidden = !isHidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

package com.github.serivesmejia.eocvsim.gui.component

import com.github.serivesmejia.eocvsim.gui.util.Location
import com.github.serivesmejia.eocvsim.gui.util.Corner
import com.github.serivesmejia.eocvsim.util.event.EventHandler
import java.awt.Point
import java.awt.Window
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
Expand Down Expand Up @@ -97,32 +98,46 @@ class PopupX @JvmOverloads constructor(windowAncestor: Window,

companion object {

fun JComponent.popUpXOnThis(panel: JPanel,
popupLocation: Location = Location.TOP,
closeOnFocusLost: Boolean = true,
fixX: Boolean = false,
fixY: Boolean = true): PopupX {
fun JComponent.popUpXOnThis(
panel: JPanel,
buttonCorner: Corner = Corner.TOP_LEFT,
popupCorner: Corner = Corner.BOTTOM_LEFT,
closeOnFocusLost: Boolean = true
): PopupX {

val frame = SwingUtilities.getWindowAncestor(this)
val location = locationOnScreen

val popup = PopupX(frame, panel, location.x,
if(popupLocation == Location.TOP) location.y else location.y + height,
closeOnFocusLost, fixX, fixY
val cornerLocation: Point = when(buttonCorner) {
Corner.TOP_LEFT -> Point(location.x, location.y)
Corner.TOP_RIGHT -> Point(location.x + width, location.y)
Corner.BOTTOM_LEFT -> Point(location.x, location.y + height)
Corner.BOTTOM_RIGHT -> Point(location.x + width, location.y + height)
}

val popup = PopupX(frame, panel,
cornerLocation.x,
cornerLocation.y,
closeOnFocusLost
)

popup.onShow {
popup.setLocation(
popup.window.location.x - width / 3,
if(popupLocation == Location.TOP) popup.window.location.y else popup.window.location.y + popup.window.height
)

val topRightPointX = popup.window.location.x + popup.window.width

if(topRightPointX > frame.width) {
popup.setLocation(
popup.window.location.x - ((topRightPointX - frame.width) / 2),
popup.window.location.y
when(popupCorner) {
Corner.TOP_LEFT -> popup.setLocation(
popup.window.location.x,
popup.window.location.y + popup.window.height
)
Corner.TOP_RIGHT -> popup.setLocation(
popup.window.location.x - popup.window.width,
popup.window.location.y + popup.window.height
)
Corner.BOTTOM_LEFT -> popup.setLocation(
popup.window.location.x + width,
popup.window.location.y + popup.window.height
)
Corner.BOTTOM_RIGHT -> popup.setLocation(
popup.window.location.x - popup.window.width,
popup.window.location.y + popup.window.height
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import kotlinx.coroutines.swing.Swing
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import java.awt.GridLayout
import java.awt.Insets
import javax.swing.BoxLayout
import javax.swing.JPanel
import javax.swing.JTabbedPane
import javax.swing.border.EmptyBorder
import javax.swing.border.TitledBorder

class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() {

Expand All @@ -32,17 +34,24 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() {
init {
pipelinePanel.layout = GridBagLayout()

pipelineSelectorPanel.border = EmptyBorder(20, 20, 0, 20)
pipelineSelectorPanel.border = TitledBorder("Pipelines").apply {
border = EmptyBorder(0, 0, 0, 0)
}

pipelinePanel.add(pipelineSelectorPanel, GridBagConstraints().apply {
gridx = 0
gridy = 0

weightx = 1.0
weighty = 1.0
fill = GridBagConstraints.BOTH

insets = Insets(10, 20, 5, 20)
})

sourceSelectorPanel.border = EmptyBorder(0, 20, -10, 20)
sourceSelectorPanel.border = TitledBorder("Sources").apply {
border = EmptyBorder(0, 0, 0, 0)
}

pipelinePanel.add(sourceSelectorPanel, GridBagConstraints().apply {
gridx = 0
Expand All @@ -51,6 +60,8 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() {
weightx = 1.0
weighty = 1.0
fill = GridBagConstraints.BOTH

insets = Insets(-5, 20, -10, 20)
})

opModePanel.layout = GridLayout(2, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import java.awt.GridLayout
import java.awt.event.MouseEvent
import java.awt.event.MouseMotionListener
import javax.swing.*
import javax.swing.border.EmptyBorder
import javax.swing.border.TitledBorder

class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver {

Expand All @@ -18,6 +20,10 @@ class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver {
val telemetryLabel = JLabel("Telemetry")

init {
border = TitledBorder("Telemetry").apply {
border = EmptyBorder(0, 0, 0, 0)
}

layout = GridBagLayout()

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* Copyright (c) 2023 Sebastian Erives
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode

import com.github.serivesmejia.eocvsim.EOCVSim
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/*
* Copyright (c) 2023 Sebastian Erives
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode

import javax.swing.JButton
import javax.swing.JList
import javax.swing.JPanel
import javax.swing.JScrollPane
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
/*
* Copyright (c) 2023 Sebastian Erives
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode

import com.github.serivesmejia.eocvsim.EOCVSim
import com.github.serivesmejia.eocvsim.gui.EOCVSimIconLibrary
import com.github.serivesmejia.eocvsim.gui.component.PopupX.Companion.popUpXOnThis
import com.github.serivesmejia.eocvsim.gui.util.Location
import com.github.serivesmejia.eocvsim.gui.util.Corner
import com.github.serivesmejia.eocvsim.pipeline.PipelineData
import com.github.serivesmejia.eocvsim.util.ReflectUtil
import com.github.serivesmejia.eocvsim.util.loggerForThis
Expand All @@ -16,7 +39,6 @@ import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.*


class OpModeSelectorPanel(val eocvSim: EOCVSim, val opModeControlsPanel: OpModeControlsPanel) : JPanel() {

private var _selectedIndex = -1
Expand Down Expand Up @@ -126,7 +148,7 @@ class OpModeSelectorPanel(val eocvSim: EOCVSim, val opModeControlsPanel: OpModeC

private fun registerListeners() {
autonomousButton.addActionListener {
val popup = autonomousButton.popUpXOnThis(OpModePopupPanel(autonomousSelector), Location.BOTTOM)
val popup = autonomousButton.popUpXOnThis(OpModePopupPanel(autonomousSelector), Corner.BOTTOM_LEFT, Corner.TOP_LEFT)

opModeControlsPanel.stopCurrentOpMode()

Expand All @@ -145,7 +167,7 @@ class OpModeSelectorPanel(val eocvSim: EOCVSim, val opModeControlsPanel: OpModeC
}

teleopButton.addActionListener {
val popup = teleopButton.popUpXOnThis(OpModePopupPanel(teleopSelector), Location.BOTTOM)
val popup = teleopButton.popUpXOnThis(OpModePopupPanel(teleopSelector), Corner.BOTTOM_RIGHT, Corner.TOP_RIGHT)

opModeControlsPanel.stopCurrentOpMode()

Expand Down
Loading

0 comments on commit 05e462a

Please sign in to comment.