Skip to content

Commit

Permalink
Don't show the topControls in cases when not used.
Browse files Browse the repository at this point in the history
  • Loading branch information
barrybecker4 committed Nov 26, 2021
1 parent cd94c91 commit f35a843
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class CaveExplorer() extends Simulator("Cave Explorer") {
this.addMouseMotionListener(handler)
}

override def createTopControls: JPanel = {
val controls = new JPanel
controls.add(createResetButton)
controls.add(createOptionsButton)
controls
}

override protected def reset(): Unit = {
setNumStepsPerFrame(CaveExplorer.DEFAULT_STEPS_PER_FRAME)
// remove handlers to void memory leak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ abstract class SimulatorOptionsDialog(parent: Component,
}
tabbedPanel.add("Custom", customParamPanel)
tabbedPanel.setToolTipTextAt(tabbedPanel.getTabCount - 1, "Change the custom options for the simulation")
tabbedPanel.setSelectedComponent(customParamPanel)

if (showCustomTabByDefault)
tabbedPanel.setSelectedComponent(customParamPanel)
else
tabbedPanel.setSelectedComponent(renderingParamPanel)

mainPanel.add(tabbedPanel, BorderLayout.CENTER)
mainPanel.add(buttonsPanel, BorderLayout.SOUTH)
mainPanel
}

protected def showCustomTabByDefault: Boolean = false

protected def createCheckBox(label: String, ttip: String, initialValue: Boolean): JCheckBox = {
val cb = new JCheckBox(label, initialValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class ComplexMappingExplorer extends Simulator("Complex Mapping Explorer") {
redraw()
}

override def createTopControls: JPanel = {
val controls = new JPanel
controls.add(createResetButton)
controls
}

def setFunction(func: ComplexFunction): Unit = {
function = func
redraw()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright by Barry G. Becker, 2014-2017. Licensed under MIT License: http://www.opensource.org/licenses/MIT

// Copyright by Barry G. Becker, 2014-2017. Licensed under MIT License: http://www.opensource.org/licenses/MIT
package com.barrybecker4.simulation.conway

import com.barrybecker4.simulation.conway.model.ConwayModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DiceOptionsDialog private[dice](parent: Component, simulator: Simulator)

override def getTitle = "Dice Simulation Configuration"

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val paramPanel = new JPanel
paramPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FractalOptionsDialog(val parent1: Component, val simulator: Simulator)

override protected def createRenderingParamPanel = new JPanel

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
setResizable(true)
val mainPanel = new JPanel(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class FunctionOptionsDialog(parent: Component, simulator: Simulator)

override def getTitle = "Function Inverse Configuration"

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val funcPanel = new JPanel(new BorderLayout)
val innerPanel = new JPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class GraphOptionsDialog(parent: Component, simulator: Simulator)

override def getTitle = "Graph Simulation Configuration"

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val paramPanel = new JPanel
paramPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ import com.barrybecker4.simulation.common.ui.Simulator
import com.barrybecker4.ui.animation.AnimationFrame
import com.barrybecker4.ui.renderers.{AbstractFunctionRenderer, SingleFunctionRenderer}
import FunctionType.DIAGONAL
import java.awt._

import java.awt.*
import javax.swing.JPanel

/**
* Simulates graphing a function
* @author Barry Becker
*/
object GraphSimulator extends App {
val sim = new GraphSimulator
sim.setPaused(true)
new AnimationFrame(sim)
}

class GraphSimulator private() extends Simulator("Graph") {
class GraphSimulator extends Simulator("Graph") {

private var graph: AbstractFunctionRenderer = _
private var function: Function = _
Expand All @@ -41,6 +33,12 @@ class GraphSimulator private() extends Simulator("Graph") {
graph = new SingleFunctionRenderer(function)
}

override def createTopControls: JPanel = {
val controls = new JPanel
controls.add(createOptionsButton)
controls
}

override def paint(g: Graphics): Unit = {
graph.setSize(getWidth, getHeight)
graph.paint(g)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright by Barry G. Becker, 2021. Licensed under MIT License: http://www.opensource.org/licenses/MIT
package com.barrybecker4.simulation.graphing

import com.barrybecker4.ui.animation.AnimationFrame


/**
* Simulates graphing a function
*/
object GraphSimulatorApp {

def main(args: Array[String]): Unit = {
val sim = new GraphSimulator()
sim.setPaused(true)
new AnimationFrame(sim)
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright by Barry G. Becker, 2016-2017. Licensed under MIT License: http://www.opensource.org/licenses/MIT
// Copyright by Barry G. Becker, 2016-2021. Licensed under MIT License: http://www.opensource.org/licenses/MIT
package com.barrybecker4.simulation.parameter

import com.barrybecker4.optimization.parameter.redistribution._
import com.barrybecker4.optimization.parameter.types.{BooleanParameter, DoubleParameter, IntegerParameter, Parameter}
import ParameterDistributionType._
import Consts._


object ParameterDistributionType {
private object Consts {
val DEFAULT_NAME = "Param"
val NUM_DISCRETES = 10
val NUM_DISCRETESM1: Int = NUM_DISCRETES - 1
Expand All @@ -21,77 +21,77 @@ object ParameterDistributionType {
enum ParameterDistributionType(val name: String, val param: Parameter):

case GAUSSIAN8 extends ParameterDistributionType("Gaussian 0-8",
new DoubleParameter(0, 0, 8.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 8.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.3))))
case GAUSSIAN_NARROW1 extends ParameterDistributionType("Gaussian (narrow 0-1)",
new DoubleParameter(0, 0, 1.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 1.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.15))))
case GAUSSIAN_NARROW8 extends ParameterDistributionType("Gaussian (narrow 0-8)",
new DoubleParameter(0, 0, 8.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 8.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.15))))
case GAUSSIAN_NARROWER extends ParameterDistributionType("Gaussian (narrower)",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.1))))
case GAUSSIAN_NARROWEST extends ParameterDistributionType("Gaussian (narrowest)",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.01)))) // still has a problem
case GAUSSIAN_WIDE extends ParameterDistributionType("Gaussian (wide)",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.5, 0.8))))
case UNIFORM extends ParameterDistributionType("Uniform",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME))
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME))
case RIGHT_SKEWED_GAUSSIAN extends ParameterDistributionType("Right skewed gaussian",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.7, 0.3))))
case RIGHT_SKEWED_GAUSSIAN1 extends ParameterDistributionType("Right skewed gaussian1",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.8, 0.1))))
case RIGHT_SKEWED_GAUSSIAN2 extends ParameterDistributionType("Right skewed gaussian2",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.9, 0.05))))
case RIGHT_SKEWED_GAUSSIAN3 extends ParameterDistributionType("Right skewed gaussian3",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.9, 0.5))))
case LEFT_SKEWED_GAUSSIAN extends ParameterDistributionType("Left skewed gaussian",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.3, 0.3))))
case LEFT_SKEWED_GAUSSIAN1 extends ParameterDistributionType("Left skewed gaussian1",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.2, 0.1))))
case LEFT_SKEWED_GAUSSIAN2 extends ParameterDistributionType("Left skewed gaussian2",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.1, 0.05))))
case LEFT_SKEWED_GAUSSIAN3 extends ParameterDistributionType("Left skewed gaussian3",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.1, 0.7))))
case MIN_SKEWED_GAUSSIAN extends ParameterDistributionType("Minimum skewed gaussian",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(0.0, 0.1))))
case MAX_SKEWED_GAUSSIAN extends ParameterDistributionType("Maximum skewed gaussian",
new DoubleParameter(0, 0, 10.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 10.0, Consts.DEFAULT_NAME,
Some(new GaussianRedistribution(1.0, 0.1))))
case SPECIAL_UNIFORM2 extends ParameterDistributionType("Special Uniform 0.2",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new UniformRedistribution(Array(0.2), Array(0.01)))))
case SPECIAL_UNIFORM_LEFT extends ParameterDistributionType("Special Uniform Left only",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new UniformRedistribution(Array(0.0), Array(0.01)))))
case SPECIAL_UNIFORM_RIGHT extends ParameterDistributionType("Special Uniform Right only",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new UniformRedistribution(Array(1.0), Array(0.02)))))
case SPECIAL_UNIFORM_LEFTRIGHT extends ParameterDistributionType("Special Uniform Left and Right only",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new UniformRedistribution(Array(0.0, 1.0), Array(0.005, 0.005)))))
case SPECIAL_UNIFORM_SEVERAL extends ParameterDistributionType("Special Uniform Several",
new DoubleParameter(0, 0, 5.0, ParameterDistributionType.DEFAULT_NAME,
new DoubleParameter(0, 0, 5.0, Consts.DEFAULT_NAME,
Some(new UniformRedistribution(Array(0.1, 0.3, 0.8, 0.832), Array(0.01, 0.02, 0.01, 0.01)))))
case DISCRETE_UNIFORM extends ParameterDistributionType("Uniform discrete",
new IntegerParameter(0, 0, ParameterDistributionType.NUM_DISCRETESM1, ParameterDistributionType.DEFAULT_NAME))
new IntegerParameter(0, 0, Consts.NUM_DISCRETESM1, Consts.DEFAULT_NAME))
case SPECIFIC_DISCRETE_1 extends ParameterDistributionType("Uniform discrete1",
new IntegerParameter(0, 0, ParameterDistributionType.NUM_DISCRETESM1, ParameterDistributionType.DEFAULT_NAME,
Some(DiscreteRedistribution(ParameterDistributionType.NUM_DISCRETES, Array(3), Array(0.8)))))
new IntegerParameter(0, 0, Consts.NUM_DISCRETESM1, Consts.DEFAULT_NAME,
Some(DiscreteRedistribution(Consts.NUM_DISCRETES, Array(3), Array(0.8)))))
case SPECIFIC_DISCRETE_2 extends ParameterDistributionType("Uniform discrete (0, 4)",
new IntegerParameter(0, 0, ParameterDistributionType.NUM_DISCRETESM1, ParameterDistributionType.DEFAULT_NAME,
new IntegerParameter(0, 0, Consts.NUM_DISCRETESM1, Consts.DEFAULT_NAME,
Some(DiscreteRedistribution(NUM_DISCRETES, Array(0, 4), Array(0.3, 0.3)))))
case SPECIFIC_DISCRETE_ALL extends ParameterDistributionType("Uniform discrete (all)",
new IntegerParameter(0, 0, 3, DEFAULT_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ParameterOptionsDialog private[parameter](parent: Component, simulator: Si

override def getTitle = "Parameter Simulation Configuration"

override def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val paramPanel = new JPanel
paramPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,21 @@ package com.barrybecker4.simulation.predprey
import com.barrybecker4.math.function.CountFunction
import com.barrybecker4.math.function.Function
import com.barrybecker4.simulation.common.ui.Simulator
import com.barrybecker4.simulation.common.ui.SimulatorApplet
import com.barrybecker4.simulation.graphing.GraphOptionsDialog
import com.barrybecker4.simulation.predprey.creatures.Foxes
import com.barrybecker4.simulation.predprey.creatures.Population
import com.barrybecker4.simulation.predprey.creatures.Rabbits
import com.barrybecker4.simulation.predprey.options.DynamicOptions
import com.barrybecker4.ui.renderers.MultipleFunctionRenderer
import com.barrybecker4.simulation.predprey.options.PredPreyOptionsDialog
import com.barrybecker4.ui.util.GUIUtil

import javax.swing.JPanel
import java.awt.Color
import java.awt.Graphics
import java.util


/**
* Simulates foxes (predators) and rabbits (prey) in the wild.
*
* @author Barry Becker
*/
object PredPreySimulator {
def main(args: Array[String]): Unit = {
val sim = new PredPreySimulator
sim.setPaused(true)
GUIUtil.showApplet(new SimulatorApplet(sim))
}
}

class PredPreySimulator() extends Simulator("Predator Prey Simulation") {

private var foxes = new Foxes
Expand Down Expand Up @@ -89,7 +77,7 @@ class PredPreySimulator() extends Simulator("Predator Prey Simulation") {
options
}

override protected def createOptionsDialog = new GraphOptionsDialog(frame, this)
override protected def createOptionsDialog = new PredPreyOptionsDialog(frame, this)

override def paint(g: Graphics): Unit = {
graph.setSize(getWidth, getHeight)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright by Barry G. Becker, 2021. Licensed under MIT License: http://www.opensource.org/licenses/MIT
package com.barrybecker4.simulation.predprey

import com.barrybecker4.ui.util.GUIUtil
import com.barrybecker4.simulation.common.ui.SimulatorApplet

/**
* Simulates foxes (predators) and rabbits (prey) in the wild.
*
* @author Barry Becker
*/
object PredPreySimulatorApp {
def main(args: Array[String]): Unit = {
val sim = new PredPreySimulator
sim.setPaused(true)
GUIUtil.showApplet(new SimulatorApplet(sim))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class RDOptionsDialog private[reactiondiffusion](parent: Component, simulator: S
private var showProfilingCheckbox: JCheckBox = _
private var useParallelRenderingCheckbox: JCheckBox = _

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val panel = new JPanel
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class SnakeOptionsDialog private[snake](parent: Component, simulator: SnakeSimul
private var springKField: NumberInput = _
private var springDampingField: NumberInput = _

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val customParamPanel = new JPanel
customParamPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class StockOptionsDialog private[stock](parent: Component, simulator: Simulator)

override def getTitle = "Stock Simulation Configuration"

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val paramPanel = new JPanel
paramPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class OptionsDialog(parent: Component, simulator: Simulator) extends SimulatorOp

override def getTitle = "Stock Simulation Configuration"

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val paramPanel = new JPanel
paramPanel.setLayout(new BorderLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TrebuchetOptionsDialog private[trebuchet](parent: Component, simulator: Tr
private var counterWeightMassField: NumberInput = _
private var slingReleaseAngleField: NumberInput = _

override protected def showCustomTabByDefault: Boolean = true

override protected def createCustomParamPanel: JPanel = {
val customParamPanel = new JPanel
customParamPanel.setLayout(new BorderLayout)
Expand Down
Loading

0 comments on commit f35a843

Please sign in to comment.