it.unibo.scafi.simulation.frontend.view.SimulationPanel.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2016-2019, Roberto Casadei, Mirko Viroli, and contributors.
* See the LICENSE file distributed with this work for additional information regarding copyright ownership.
*/
package it.unibo.scafi.simulation.frontend.view
import java.awt._
import java.awt.event.MouseEvent
import javax.swing._
import javax.swing.border.LineBorder
import it.unibo.scafi.simulation.frontend.Settings
import it.unibo.scafi.simulation.frontend.controller.GeneralController
/**
* This is the most important panel in which the simulation will be executed.
*/
class SimulationPanel(controller: GeneralController) extends JDesktopPane {
final private val neighborsPanel: NeighborsPanel = new NeighborsPanel
final private val valuesPanel: ValuesPanel = new ValuesPanel
private var bkgImage: Image = null
final private val captureRect: Rectangle = new Rectangle
final private val popup: MyPopupMenu = new MyPopupMenu(controller)
this.setBackground(Settings.Color_background)
setBorder(new LineBorder(Color.black))
this.add(valuesPanel, 1)
this.add(neighborsPanel, 2)
val motion: SimulationPanelMouseListener = new SimulationPanelMouseListener(this)
this.addMouseListener(motion)
this.addMouseMotionListener(motion)
override def paintComponent(g: Graphics): Unit = {
if (bkgImage != null) {
// Shows background image
g.drawImage(bkgImage, 0, 0, this.getWidth, this.getHeight, this)
}
if (captureRect != null) {
// Shows selection area
g.setColor(Settings.Color_selection)
g.drawRect(captureRect.getX.toInt, captureRect.getY.toInt, captureRect.getWidth.toInt, captureRect.getHeight.toInt)
g.setColor(Settings.Color_selection)
g.fillRect(captureRect.getX.toInt, captureRect.getY.toInt, captureRect.getWidth.toInt, captureRect.getHeight.toInt)
}
}
/**
* Set the background image
*
* @param bkgImage
*/
def setBackgroundImage(bkgImage: Image): Unit = {
this.bkgImage = bkgImage
}
/**
* Shows the panel representing the neighbourhood
*
* @param show
*/
def showNeighbours(show: Boolean): Unit = {
neighborsPanel.setVisible(show)
this.revalidate()
this.repaint()
}
def toggleNeighbours(): Unit = {
neighborsPanel.setVisible(!neighborsPanel.isVisible)
}
def setRectSelection(r: Rectangle): Unit = {
this.captureRect.setRect(r)
}
def getCaptureRect: Rectangle = {
return captureRect
}
def maybeShowPopup(e: MouseEvent): Unit = {
if (e.isPopupTrigger) {
popup.show(e.getComponent, e.getX, e.getY)
}
}
def getPopUpMenu: MyPopupMenu = {
return this.popup
}
def increaseFontSize(): Unit = { this.valuesPanel.increaseFontSize() }
def decreaseFontSize(): Unit = { this.valuesPanel.decreaseFontSize() }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy