当前位置: 首页>>代码示例>>Scala>>正文


Scala ActionEvent类代码示例

本文整理汇总了Scala中scalafx.event.ActionEvent的典型用法代码示例。如果您正苦于以下问题:Scala ActionEvent类的具体用法?Scala ActionEvent怎么用?Scala ActionEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActionEvent类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: UnitConverterPresenter

//设置package包名称以及导入依赖的类
package com.stulsoft.pscalafx.demo1

import scala.reflect.runtime.universe.typeOf
import scalafx.application.{Platform, JFXApp}
import scalafx.Includes._
import scalafx.scene.Scene
import scalafx.scene.control.{ComboBox, TextField}
import scalafx.event.ActionEvent
import scalafxml.core.{DependenciesByType, FXMLView}
import scalafxml.core.macros.sfxml
import javafx.beans.binding.StringBinding


@sfxml
class UnitConverterPresenter(from: TextField,
                             to: TextField,
                             types: ComboBox[UnitConverter],
                             converters: UnitConverters) {

  // Filling the combo box
  for (converter <- converters.available) {
    types += converter
  }
  types.getSelectionModel.selectFirst()

  // Data binding
  to.text <== new StringBinding {
    bind(from.text.delegate, types.getSelectionModel.selectedItemProperty)

    def computeValue(): String = types.getSelectionModel.getSelectedItem.run(from.text.value)
  }

  // Close button event handler
  def onClose(event: ActionEvent) {
    Platform.exit()
  }
}

object ScalaFXML extends JFXApp {

  val root = FXMLView(getClass.getResource("/fxml/unitconverter.fxml"),
    new DependenciesByType(Map(
      typeOf[UnitConverters] -> new UnitConverters(InchesToMM, MMtoInches))))

  stage = new JFXApp.PrimaryStage() {
    title = "Unit conversion"
    scene = new Scene(root)

  }
} 
开发者ID:ysden123,项目名称:poc,代码行数:51,代码来源:ScalaFXML.scala

示例2: inputError

//设置package包名称以及导入依赖的类
package ch.thomsch.pause.controller

import java.io.IOException
import java.util.concurrent.Executors
import javafx.fxml.FXML

import ch.thomsch.pause.{About, Actions, Pause}

import scalafx.event.ActionEvent
import scalafx.scene.control._
import scalafx.scene.input.{KeyCode, KeyEvent}
import scalafxml.core.macros.sfxml


  def inputError = {
    println("Cannot start timer, input error was made")
    onOffButton.delegate.setSelected(false)
    timeField.setDisable(false)

    Executors.newCachedThreadPool().submit(new Runnable {
      override def run(): Unit = {
        timeField.setStyle("-fx-control-inner-background: red")
        Thread.sleep(2000)
        timeField.setStyle("")
      }
    })
  }

  @FXML
  def onButtonAction(event: scalafx.event.ActionEvent) {
    timeField.setDisable(onOffButton.delegate.isSelected)
    if (onOffButton.delegate.isSelected) {
      if(time.isDefined) {
        Actions.startTimer(time.get, progress.progressProperty)
        onOffButton.setText("On")
      } else inputError
    } else {
      Actions.cancelTimer()
      onOffButton.setText("Activate")
    }
  }

  @FXML
  def onAboutActionClick(event: scalafx.event.ActionEvent) {
    try {
      About.createUI.show()
    } catch {
      case _ : IOException => Pause.showErrorMessage("We are sorry, this window is not available for now : The program cannot find the file about.fxml.")
    }
  }

  @FXML
  def onEnterPressed(event : KeyEvent) : Unit = {
    if(event.code == KeyCode.Enter) {
      onOffButton.delegate.setSelected(!onOffButton.delegate.isSelected)
      onButtonAction(new ActionEvent(event.source, event.target))
      event.consume()
    } else if(event.code == KeyCode.Escape) if(event.isShiftDown) Actions.closeApplication() else Pause.hide()
  }
} 
开发者ID:Thomsch,项目名称:pause,代码行数:61,代码来源:SettingsController.scala

示例3: EditMenuController

//设置package包名称以及导入依赖的类
package de.m7w3.signal.controller

import scalafx.event.ActionEvent
import scalafx.scene.control.MenuItem
import scalafxml.core.macros.sfxml


@sfxml
class EditMenuController(editMenuItemSettings: MenuItem) extends MenuController {

  def onEditSettings(event: ActionEvent): Unit = {
    println("edit->settings")
    println(s"${editMenuItemSettings.id}")
  }

  override def onMenu(): Unit = {
    println("menu")
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:20,代码来源:EditMenuController.scala

示例4: HelpMenuController

//设置package包名称以及导入依赖的类
package de.m7w3.signal.controller

import scalafx.event.ActionEvent
import scalafxml.core.macros.sfxml

@sfxml
class HelpMenuController extends MenuController {
  def onHelpOnline(event: ActionEvent): Unit = {
    println("go to https://github.com/abenali/signal-desktop-client/wiki")
  }

  def onHelpAbout(event: ActionEvent): Unit = {
    println("help->about")
  }

  override def onMenu(): Unit = println("helpmenu")
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:18,代码来源:HelpMenuController.scala

示例5: DictionaryListController

//设置package包名称以及导入依赖的类
package bozzy.controllers



import bozzy.I18n

import scalafx.event.ActionEvent
import scalafx.scene.control.ListView
import scalafx.stage.FileChooser
import scalafx.stage.FileChooser.ExtensionFilter
import scalafxml.core.macros.sfxml

import bozzy.steno.StenoDictionary

@sfxml
class DictionaryListController (private val dictionary_list: ListView[StenoDictionary]) {

    dictionary_list.items = MainDictionary.openDictionaries
  def handleAdd (event: ActionEvent) {
    val fileChooser = new FileChooser {
      title = I18n.i18n.getString("openResourceFileTitle")
      extensionFilters.add(
        new ExtensionFilter("Steno Dictionaries", Seq("*.json", "*.rtf"))
      )
    }
    val selectedFile = fileChooser.showOpenDialog(bozzy.Bozzy.stage)
    if (selectedFile != null) {
      MainDictionary.addDictionary(selectedFile.getAbsolutePath)
    }
  }
  def handleRemove (event: ActionEvent) = {
    val selectedDictionary = dictionary_list.selectionModel.value.getSelectedItem

    if (selectedDictionary != null) {
      MainDictionary.removeDictionary(selectedDictionary.filename)
    }
  }
  def handleMoveUp (event: ActionEvent) = {}
  def handleMoveDown (event: ActionEvent) = {}
} 
开发者ID:morinted,项目名称:Bozzy,代码行数:41,代码来源:DictionaryListController.scala

示例6: newName

//设置package包名称以及导入依赖的类
package net.mikolak.pomisos.crud

import java.util.function.Predicate

import org.controlsfx.validation.{Severity, ValidationResult, ValidationSupport, Validator}

import scalafx.beans.property.{ObjectProperty, ReadOnlyObjectProperty}
import scalafx.event.ActionEvent
import scalafx.scene.control.{Button, TextField}
import scalafxml.core.macros.sfxml
import scalafx.Includes._
import scalafx.beans.binding.Bindings
import net.mikolak.pomisos.utils.Implicits._

trait AddNew {
  def newName: ObjectProperty[Option[String]]
}

@sfxml
class AddNewController(
    val addNewArea: TextField,
    val addNewButton: Button
) extends AddNew {

  lazy val newName = ObjectProperty[Option[String]](None)
  setUpValidation()

  def addItem(event: ActionEvent): Unit = {
    newName.value = Some(addNewArea.text.value.toString).filter(_.nonEmpty)
    addNewArea.text.value = ""
  }

  private def setUpValidation() = {
    val textEmpty = addNewArea.text.mapToBoolean(_.trim().isEmpty)
    addNewButton.disable <== textEmpty

    val createItemHandle = addNewArea.onAction.value

    def textValidator =
      Validator.createPredicateValidator(new Predicate[String] {
        override def test(t: String) = !textEmpty.value
      }, "Name must not be empty", Severity.WARNING)

    val validationSupport = new ValidationSupport()
    validationSupport.registerValidator(addNewArea, textValidator)
    validationSupport.initInitialDecoration()

    val validationResult: ReadOnlyObjectProperty[ValidationResult] = validationSupport.validationResultProperty()

    addNewArea.onAction <== validationResult.mapNullable(vR => if (vR.exists(_.getWarnings.isEmpty)) createItemHandle else null)
  }

} 
开发者ID:mikolak-net,项目名称:pomisos,代码行数:54,代码来源:AddNewController.scala


注:本文中的scalafx.event.ActionEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。