Skip to content

Commit

Permalink
UI redesigns - delete title labels and add collapsible variable tuner
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Aug 20, 2023
1 parent 143e97a commit 235a2ce
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import com.formdev.flatlaf.FlatLaf;
import com.github.serivesmejia.eocvsim.Build;
import com.github.serivesmejia.eocvsim.EOCVSim;
import com.github.serivesmejia.eocvsim.gui.component.CollapsiblePanelX;
import com.github.serivesmejia.eocvsim.gui.component.visualizer.*;
import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeSelectorPanel;
import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel;
import io.github.deltacv.vision.external.gui.SwingOpenCvViewport;
import com.github.serivesmejia.eocvsim.gui.component.tuner.ColorPicker;
import com.github.serivesmejia.eocvsim.gui.component.tuner.TunableFieldPanel;
Expand Down Expand Up @@ -64,7 +66,7 @@ public class Visualizer {
public SwingOpenCvViewport viewport = null;

public TopMenuBar menuBar = null;
public JPanel tunerMenuPanel = new JPanel();
public JPanel tunerMenuPanel;

public JPanel rightContainer = null;

Expand All @@ -77,6 +79,8 @@ public class Visualizer {

public TelemetryPanel telemetryPanel;

public JPanel tunerCollapsible;

private String title = "EasyOpenCV Simulator v" + Build.standardVersionString;
private String titleMsg = "No pipeline";
private String beforeTitle = "";
Expand Down Expand Up @@ -171,7 +175,14 @@ public void init(Theme theme) {
//global
frame.getContentPane().setDropTarget(new InputSourceDropTarget(eocvSim));

//frame.add(tunerMenuPanel, BorderLayout.SOUTH);
tunerCollapsible = new CollapsiblePanelX("Tuner", null);
tunerCollapsible.setLayout(new BoxLayout(tunerCollapsible, BoxLayout.LINE_AXIS));
tunerCollapsible.setVisible(false);

JScrollPane tunerScrollPane = new JScrollPane(tunerMenuPanel);
tunerCollapsible.add(tunerScrollPane);

frame.add(tunerCollapsible, BorderLayout.SOUTH);
frame.add(rightContainer, BorderLayout.EAST);

//initialize other various stuff of the frame
Expand Down Expand Up @@ -329,6 +340,8 @@ public void updateTunerFields(List<TunableFieldPanel> fields) {
tunerMenuPanel.add(fieldPanel);
fieldPanel.showFieldPanel();
}

tunerCollapsible.setVisible(!fields.isEmpty());
}

public void asyncCompilePipelines() {
Expand All @@ -349,7 +362,7 @@ public void asyncCompilePipelines() {

public void compilingUnsupported() {
asyncPleaseWaitDialog(
"Runtime compiling is not supported on this JVM",
"Runtime pipeline builds are not supported on this JVM",
"For further info, check the EOCV-Sim GitHub repo",
"Close",
new Dimension(320, 160),
Expand Down Expand Up @@ -397,7 +410,7 @@ public void createVSCodeWorkspace() {
}

public void askOpenVSCode() {
DialogFactory.createYesOrNo(frame, "A new workspace was created. Do you wanna open VS Code?", "",
DialogFactory.createYesOrNo(frame, "A new workspace was created. Do you want to open VS Code?", "",
(result) -> {
if(result == 0) {
VSCodeLauncher.INSTANCE.asyncLaunch(eocvSim.workspaceManager.getWorkspaceFile());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.github.serivesmejia.eocvsim.gui.component

import java.awt.Color
import java.awt.Dimension
import java.awt.event.MouseAdapter
Expand All @@ -7,13 +9,17 @@ import javax.swing.JPanel
import javax.swing.border.LineBorder
import javax.swing.border.TitledBorder

class JCollapsiblePanel(title: String?, titleCol: Color?) : JPanel() {
class CollapsiblePanelX(title: String?, titleCol: Color?) : JPanel() {
private val border: TitledBorder
private var visibleSize: Dimension? = null
private var collapsible = true

var isHidden = false
private set

init {
border = TitledBorder(title)

border.titleColor = titleCol
border.border = LineBorder(Color.white)
setBorder(border)
Expand All @@ -27,17 +33,22 @@ class JCollapsiblePanel(title: String?, titleCol: Color?) : JPanel() {
if (!collapsible) {
return
}
val i = getBorder().getBorderInsets(this@JCollapsiblePanel)

val i = getBorder().getBorderInsets(this@CollapsiblePanelX)
if (e.x < i.left + size.width && e.y < i.bottom + size.height) {
if (visibleSize == null || height > size.height) {
visibleSize = getSize()
}
if (getSize().height < visibleSize!!.height) {
maximumSize = Dimension(visibleSize!!.width, 20000)
minimumSize = visibleSize
} else {
maximumSize = Dimension(visibleSize!!.width, size.height)

for(e in components) {
e.isVisible = !isHidden

border.title = if(isHidden) {
"$title (hidden)"
} else {
title
}

isHidden = !isHidden
}

revalidate()
e.consume()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.serivesmejia.eocvsim.EOCVSim
import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeControlsPanel
import com.github.serivesmejia.eocvsim.gui.component.visualizer.opmode.OpModeSelectorPanel
import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.PipelineSelectorPanel
import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -31,7 +32,7 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() {
init {
pipelinePanel.layout = GridBagLayout()

pipelineSelectorPanel.border = EmptyBorder(0, 20, 0, 20)
pipelineSelectorPanel.border = EmptyBorder(20, 20, 0, 20)
pipelinePanel.add(pipelineSelectorPanel, GridBagConstraints().apply {
gridx = 0
gridy = 0
Expand All @@ -41,7 +42,7 @@ class PipelineOpModeSwitchablePanel(val eocvSim: EOCVSim) : JTabbedPane() {
fill = GridBagConstraints.BOTH
})

sourceSelectorPanel.border = EmptyBorder(0, 20, 0, 20)
sourceSelectorPanel.border = EmptyBorder(0, 20, -10, 20)

pipelinePanel.add(sourceSelectorPanel, GridBagConstraints().apply {
gridx = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver {
telemetryLabel.font = telemetryLabel.font.deriveFont(20.0f)
telemetryLabel.horizontalAlignment = JLabel.CENTER

add(telemetryLabel, GridBagConstraints().apply {
gridy = 0
ipady = 20
})
// add(telemetryLabel, GridBagConstraints().apply {
// gridy = 0
// ipady = 20
//})

telemetryScroll.setViewportView(telemetryList)
telemetryScroll.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
Expand All @@ -52,7 +52,7 @@ class TelemetryPanel : JPanel(), TelemetryTransmissionReceiver {
telemetryList.selectionMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION

add(telemetryScroll, GridBagConstraints().apply {
gridy = 1
gridy = 0

weightx = 0.5
weighty = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() {

@JvmField val mFileMenu = JMenu("File")
@JvmField val mWorkspMenu = JMenu("Workspace")
@JvmField val mEditMenu = JMenu("Edit")
@JvmField val mHelpMenu = JMenu("Help")

@JvmField val workspCompile = JMenuItem("Build java files")
Expand Down Expand Up @@ -90,6 +89,11 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() {

mFileMenu.addSeparator()

val editSettings = JMenuItem("Settings")
editSettings.addActionListener { DialogFactory.createConfigDialog(eocvSim) }

mFileMenu.add(editSettings)

val fileRestart = JMenuItem("Restart")

fileRestart.addActionListener { eocvSim.onMainUpdate.doOnce { eocvSim.restart() } }
Expand Down Expand Up @@ -137,14 +141,6 @@ class TopMenuBar(visualizer: Visualizer, eocvSim: EOCVSim) : JMenuBar() {

add(mWorkspMenu)

// EDIT

val editSettings = JMenuItem("Settings")
editSettings.addActionListener { DialogFactory.createConfigDialog(eocvSim) }

mEditMenu.add(editSettings)
add(mEditMenu)

// HELP

val helpUsage = JMenuItem("Documentation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {

pipelineSelectorLabel.horizontalAlignment = JLabel.CENTER

add(pipelineSelectorLabel, GridBagConstraints().apply {
gridy = 0
ipady = 20
})
//add(pipelineSelectorLabel, GridBagConstraints().apply {
// gridy = 0
// ipady = 20
//})

pipelineSelector.cellRenderer = PipelineListIconRenderer(eocvSim.pipelineManager)
pipelineSelector.selectionMode = ListSelectionModel.SINGLE_SELECTION
Expand All @@ -92,7 +92,7 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {
pipelineSelectorScroll.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED

add(pipelineSelectorScroll, GridBagConstraints().apply {
gridy = 1
gridy = 0

weightx = 0.5
weighty = 1.0
Expand All @@ -103,7 +103,7 @@ class PipelineSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {
})

add(buttonsPanel, GridBagConstraints().apply {
gridy = 2
gridy = 1
ipady = 20
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.serivesmejia.eocvsim.gui.component.visualizer
package com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline

import com.github.serivesmejia.eocvsim.EOCVSim
import com.github.serivesmejia.eocvsim.gui.component.PopupX
import com.github.serivesmejia.eocvsim.gui.component.visualizer.CreateSourcePanel
import com.github.serivesmejia.eocvsim.gui.util.icon.SourcesListIconRenderer
import com.github.serivesmejia.eocvsim.pipeline.PipelineManager
import com.github.serivesmejia.eocvsim.util.extension.clipUpperZero
Expand Down Expand Up @@ -37,10 +38,10 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {
sourceSelectorLabel.font = sourceSelectorLabel.font.deriveFont(20.0f)
sourceSelectorLabel.horizontalAlignment = JLabel.CENTER

add(sourceSelectorLabel, GridBagConstraints().apply {
gridy = 0
ipady = 20
})
// add(sourceSelectorLabel, GridBagConstraints().apply {
// gridy = 0
// ipady = 20
//})

sourceSelector.selectionMode = ListSelectionModel.SINGLE_SELECTION

Expand All @@ -49,7 +50,7 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {
sourceSelectorScroll.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED

add(sourceSelectorScroll, GridBagConstraints().apply {
gridy = 1
gridy = 0

weightx = 0.5
weighty = 1.0
Expand Down Expand Up @@ -82,7 +83,7 @@ class SourceSelectorPanel(private val eocvSim: EOCVSim) : JPanel() {
sourceSelectorButtonsContainer.add(sourceSelectorDeleteBtt)

add(sourceSelectorButtonsContainer, GridBagConstraints().apply {
gridy = 2
gridy = 1
ipady = 20
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

import com.github.serivesmejia.eocvsim.EOCVSim;
import com.github.serivesmejia.eocvsim.gui.Visualizer;
import com.github.serivesmejia.eocvsim.gui.component.visualizer.SourceSelectorPanel;
import com.github.serivesmejia.eocvsim.gui.component.visualizer.pipeline.SourceSelectorPanel;
import com.github.serivesmejia.eocvsim.input.source.ImageSource;
import com.github.serivesmejia.eocvsim.input.source.VideoSource;
import com.github.serivesmejia.eocvsim.pipeline.PipelineManager;
import com.github.serivesmejia.eocvsim.util.SysUtil;
import org.opencv.core.Mat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

package com.github.serivesmejia.eocvsim.pipeline;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import org.opencv.core.*;
import org.opencv.imgproc.Imgproc;
Expand All @@ -34,8 +38,20 @@ public class DefaultPipeline extends OpenCvPipeline {

private Telemetry telemetry;

private Paint boxPaint;
private Paint textPaint;

public DefaultPipeline(Telemetry telemetry) {
this.telemetry = telemetry;

textPaint = new Paint();
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(30);
textPaint.setAntiAlias(true);

boxPaint = new Paint();
boxPaint.setColor(Color.BLACK);
boxPaint.setStyle(Paint.Style.FILL);
}

@Override
Expand All @@ -51,32 +67,18 @@ public Mat processFrame(Mat input) {

if (blur > 0 && blur % 2 == 1) {
Imgproc.GaussianBlur(input, input, new Size(blur, blur), 0);
} else if (blur > 0) {
Imgproc.GaussianBlur(input, input, new Size(blur + 1, blur + 1), 0);
}

// Outline
Imgproc.putText(
input,
"Default pipeline selected",
new Point(0, 22 * aspectRatioPercentage),
Imgproc.FONT_HERSHEY_PLAIN,
2 * aspectRatioPercentage,
new Scalar(255, 255, 255),
(int) Math.round(5 * aspectRatioPercentage)
);

//Text
Imgproc.putText(
input,
"Default pipeline selected",
new Point(0, 22 * aspectRatioPercentage),
Imgproc.FONT_HERSHEY_PLAIN,
2 * aspectRatioPercentage,
new Scalar(0, 0, 0),
(int) Math.round(2 * aspectRatioPercentage)
);

return input;
}

@Override
public void onDrawFrame(Canvas canvas, int onscreenWidth, int onscreenHeight, float scaleBmpPxToCanvasPx, float scaleCanvasDensity, Object userContext) {
canvas.drawRect(new Rect(0, 0, 385, 45), boxPaint);

canvas.drawText("Default pipeline selected", 5, 33, textPaint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public OpenCvViewRenderer(boolean renderingOffsceen, String fpsMeterDescriptor)

metricsScale = 1.0f;

fpsMeterTextSize = 30 * metricsScale;
fpsMeterTextSize = 26 * metricsScale;
statBoxW = (int) (450 * metricsScale);
statBoxH = (int) (120 * metricsScale);
statBoxTextLineSpacing = (int) (35 * metricsScale);
Expand Down

0 comments on commit 235a2ce

Please sign in to comment.