• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Platform类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Gui

//设置package包名称以及导入依赖的类
package strnet

import java.io.{ File, FileInputStream }
import java.util.Properties

import scalafx.Includes._
import scalafx.application.JFXApp.PrimaryStage
import scalafx.application.{ JFXApp, Platform }
import scalafx.scene.Scene
import scalafx.scene.image.Image
import scalafx.scene.control._
import scalafx.scene.layout._
import scalafx.stage.WindowEvent

object Gui extends JFXApp {
  val commonProp = new Properties
  commonProp.load(new FileInputStream(new File("conf" + File.separator + "common.conf")))

  val dir = new File(commonProp.getProperty("directories.path"))
  val command = commonProp.getProperty("exec.path")

  val defaultImg = new Image(new File("conf" + File.separator + "no.jpg").toURI().toString)

  val rootPane = new BorderPane()
  val listPane = new FlowPane(10, 10)
  val scrollPane = new ScrollPane()
  scrollPane.setContent(listPane)
  listPane.prefWidth.bind(scrollPane.width)
  listPane.prefHeight.bind(scrollPane.height)
  scrollPane.styleClass.append("base")


  rootPane.setCenter(scrollPane)

  def scanFiles(dir: File): Unit = {
    val thumbnails = dir.listFiles.filter(f => f.isFile && !f.getName.matches(".*\\.jpg"))
    thumbnails.foreach { f => listPane.children.add(new FileInfo(f, command, ".jpg", defaultImg)) }
  }

  stage = new PrimaryStage {
    title = "Bestiary"
    scene = new Scene(rootPane, 1280, 768) {
      stylesheets.add("/strnet/main.css")
    }
    onCloseRequest = (we: WindowEvent) => Platform.exit()
  }

  println(dir + ":" + dir.exists())
  if ( dir.exists() && dir.isDirectory() ) {
    scanFiles(dir)
  }
} 
开发者ID:hossshy,项目名称:bestiary,代码行数:53,代码来源:Gui.scala


示例2: LifeAppSpec

//设置package包名称以及导入依赖的类
package com.coding42.gol

import org.scalatest.{FlatSpec, Matchers}
import org.scalatest.concurrent.{Eventually, IntegrationPatience}

import scalafx.application.Platform

class LifeAppSpec extends FlatSpec with Eventually with IntegrationPatience with Matchers {

  it should "open the app and create a default canvas of 300x200" in {
    runApp()
    eventually {
      LifeApp.canvas.width.value shouldBe 300
      LifeApp.canvas.height.value shouldBe 200
    }
  }

  it should "check app updates steps" in {
    eventually {
      step shouldBe "Step: 1"
    }

    eventually {
      step shouldBe "Step: 2"
    }
  }

  it should "restart button does start steps again an can change size" in {
    eventually {
      step shouldBe "Step: 3"
    }

    Platform.runLater(LifeApp.restartBtn.fire())
    Platform.runLater(LifeApp.widthField.text = "100")
    Platform.runLater(LifeApp.heightField.text = "50")
    Platform.runLater(LifeApp.okBtn.fire())

    eventually {
      step shouldBe "Step: 1"
      LifeApp.canvas.width.value shouldBe 100
      LifeApp.canvas.height.value shouldBe 50
    }
  }

  private def step = LifeApp.stepText.text.value

  private def runApp(): Unit = {
    val thread = new Thread {
      override def run(): Unit = {
        LifeApp.main(Array.empty)
      }
    }
    thread.start()
  }

} 
开发者ID:adrijardi,项目名称:life,代码行数:57,代码来源:LifeAppSpec.scala


示例3: Ui

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

import org.rustkeylock.fragments.Empty
import org.rustkeylock.init.NativeInitializer
import org.slf4j.LoggerFactory

import com.typesafe.scalalogging.Logger

import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.image.Image
import scalafx.event.EventType
import scalafx.event.EventHandler
import scalafx.stage.WindowEvent
import scalafx.event.ActionEvent
import org.rustkeylock.utils.Defs
import org.rustkeylock.api.InterfaceWithRust
import scalafx.application.Platform

object Ui extends JFXApp {
  val Banner = """
                _        _              _            _    
 _ __ _   _ ___| |_     | | _____ _   _| | ___   ___| | __
| '__| | | / __| __|____| |/ / _ \ | | | |/ _ \ / __| |/ /
| |  | |_| \__ \ ||_____|   <  __/ |_| | | (_) | (__|   < 
|_|   \__,_|___/\__|    |_|\_\___|\__, |_|\___/ \___|_|\_\
                                  |___/                   

"""
  val logger = Logger(LoggerFactory.getLogger(this.getClass))
  logger.info(Banner)

  stage = new PrimaryStage {
    title = "rust-keylock"
    scene = new Empty()
    onCloseRequest = {
      new javafx.event.EventHandler[javafx.stage.WindowEvent] {
        def handle(ev: javafx.stage.WindowEvent): Unit = {
          InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_EXIT)
          ev.consume()
        }
      }
    }
  }

  stage.getIcons.add(new Image("images/rkl-small.png"))
  Platform.implicitExit_=(false)
  
  NativeInitializer.init(stage)
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:51,代码来源:Ui.scala


示例4: NativeInitializer

//设置package包名称以及导入依赖的类
package org.rustkeylock.init

import scala.util.Failure
import scala.util.Success
import scala.util.Try

import org.rustkeylock.api.InterfaceWithRust
import org.rustkeylock.callbacks.LogCb
import org.rustkeylock.callbacks.ShowEntriesSetCb
import org.rustkeylock.callbacks.ShowEntryCb
import org.rustkeylock.callbacks.ShowMenuCb
import org.rustkeylock.callbacks.ShowMessageCb
import org.slf4j.LoggerFactory

import com.typesafe.scalalogging.Logger
import scalafx.stage.Stage
import scalafx.application.Platform

object NativeInitializer {
  def init(stage: Stage): Unit = {
    new Thread(new NativeInitializer(stage)).start
  }
}

class NativeInitializer(stage: Stage) extends Runnable {
  val logger = Logger(LoggerFactory.getLogger(this.getClass))

  def run(): Unit = {
    logger.debug("Initializing rust-keylock native")
    Try {
      InterfaceWithRust.INSTANCE.execute(
        new ShowMenuCb(stage),
        new ShowEntryCb(stage),
        new ShowEntriesSetCb(stage),
        new ShowMessageCb(stage),
        new LogCb())
    } match {
      case Failure(error) => {
        logger.error("Native rust-keylock error detected", error)
      }
      case Success(_) => {
        logger.debug("Native rust-keylock exiting without errors")
      }
    }

    Platform.exit()
  }
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:49,代码来源:NativeInitializer.scala


示例5: ShowMessageCb

//设置package包名称以及导入依赖的类
package org.rustkeylock.callbacks

import org.rustkeylock.api.RustCallback
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import scalafx.application.Platform
import scalafx.scene.control.Alert.AlertType
import scalafx.scene.control.Alert
import org.rustkeylock.utils.Defs
import org.rustkeylock.api.InterfaceWithRust
import scalafx.stage.Stage

class ShowMessageCb(stage: Stage) extends RustCallback {
  val logger = Logger(LoggerFactory.getLogger(this.getClass))

  def apply(message: String): Unit = {
    logger.debug(s"Callback for showing message $message")
    Platform.runLater(new UiThreadRunnable(message))
  }

  class UiThreadRunnable(message: String) extends Runnable {
    override def run(): Unit = {
      new Alert(AlertType.Information) {
        initOwner(stage)
        title = "rust-keylock"
        contentText = message
      }.showAndWait()
      // It doesn't matter which menu we return from the show message screen. The logic of the rust-keylock library only needs something to proceed. 
			InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_ENTRIES_LIST)
    }
  }
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:33,代码来源:ShowMessageCb.scala


示例6: ShowMenuCb

//设置package包名称以及导入依赖的类
package org.rustkeylock.callbacks

import org.rustkeylock.api.RustCallback
import org.rustkeylock.fragments.EnterPassword
import org.rustkeylock.utils.Defs
import org.slf4j.LoggerFactory

import com.typesafe.scalalogging.Logger

import scalafx.application.Platform
import scalafx.stage.Stage
import org.rustkeylock.fragments.Empty
import org.rustkeylock.fragments.MainMenu
import org.rustkeylock.fragments.ImportExport
import org.rustkeylock.fragments.ExitMenu
import org.rustkeylock.fragments.ChangePassword

class ShowMenuCb(stage: Stage) extends RustCallback {
  val logger = Logger(LoggerFactory.getLogger(this.getClass))

  def apply(menu: String): Unit = {
    logger.debug("Callback for showing menu " + menu)
    Platform.runLater(new UiThreadRunnable(stage, menu))
  }

  class UiThreadRunnable(stage: Stage, menu: String) extends Runnable {
    override def run(): Unit = {
      val newScene = menu match {
        case Defs.MENU_TRY_PASS => {
          new EnterPassword(stage)
        }
        case Defs.MENU_CHANGE_PASS => {
          new ChangePassword(stage)
        }
        case Defs.MENU_MAIN => {
          new MainMenu(stage)
        }
        case Defs.MENU_EXIT => {
          new ExitMenu(stage)
        }
        case Defs.MENU_EXPORT_ENTRIES => {
          new ImportExport(true, stage)
        }
        case Defs.MENU_IMPORT_ENTRIES => {
          new ImportExport(false, stage)
        }
        case other => throw new RuntimeException(s"Cannot Show Menu with name '$menu' and no arguments")
      }

      stage.setScene(newScene)

    }
  }
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:55,代码来源:ShowMenuCb.scala


示例7: ShowEntryCb

//设置package包名称以及导入依赖的类
package org.rustkeylock.callbacks

import org.rustkeylock.api.EntryCallback
import org.rustkeylock.fragments.ShowEntry
import org.rustkeylock.japi.ScalaEntry
import org.slf4j.LoggerFactory

import com.typesafe.scalalogging.Logger

import scalafx.application.Platform
import scalafx.stage.Stage

class ShowEntryCb(stage: Stage) extends EntryCallback {
  private val logger = Logger(LoggerFactory.getLogger(this.getClass))

  def apply(anEntry: ScalaEntry.ByReference, entryIndex: Int, edit: Boolean, delete: Boolean): Unit = {
    logger.debug(s"Callback for showing Entry with index $entryIndex")
    Platform.runLater(new UiThreadRunnable(stage, anEntry, entryIndex, edit, delete))
  }

  class UiThreadRunnable(stage: Stage, anEntry: ScalaEntry.ByReference, entryIndex: Int, edit: Boolean, delete: Boolean) extends Runnable {
    override def run(): Unit = {
      stage.setScene(new ShowEntry(anEntry, entryIndex, edit, delete, stage))
    }
  }
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:27,代码来源:ShowEntryCb.scala


示例8: ShowEntriesSetCb

//设置package包名称以及导入依赖的类
package org.rustkeylock.callbacks

import org.rustkeylock.api.EntriesSetCallback
import org.rustkeylock.japi.ScalaEntriesSet
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import scalafx.stage.Stage
import scalafx.application.Platform
import org.rustkeylock.japi.ScalaEntry
import scala.collection.JavaConverters.asScalaIterator
import org.rustkeylock.fragments.ListEntries

class ShowEntriesSetCb(stage: Stage) extends EntriesSetCallback {
  private val logger = Logger(LoggerFactory.getLogger(this.getClass))

  def apply(entriesSet: ScalaEntriesSet.ByReference): Unit = {
    logger.debug("Callback for showing Entries")
    val entries = if (entriesSet.numberOfEntries == 1 && entriesSet.getEntries().get(0).name.equals("null")
				&& entriesSet.getEntries().get(0).user.equals("null")
				&& entriesSet.getEntries().get(0).pass.equals("null")
				&& entriesSet.getEntries().get(0).desc.equals("null")) {
			Nil
		} else {
			asScalaIterator(entriesSet.getEntries().iterator()).toList
		}

    Platform.runLater(new UiThreadRunnable(stage, entries))
  }

  class UiThreadRunnable(stage: Stage, entries: List[ScalaEntry]) extends Runnable {
    override def run(): Unit = {
      stage.setScene(new ListEntries(entries.map(_.name), stage))
    }
  }
} 
开发者ID:rust-keylock,项目名称:rust-keylock-ui,代码行数:36,代码来源:ShowEntriesSetCb.scala


示例9: 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


示例10: onEvent

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

import trove.core.event.{Event, EventListener}

import scalafx.application.Platform

// Wrapper to ensure we update UI on event dispatch thread.
trait UIEventListener extends EventListener {

    final override def onEvent: PartialFunction[Event,Unit] = {
      case e: Event =>
        if(onReceive.isDefinedAt(e)) {
          Platform.runLater {
            onReceive(e)
        }
      }
    }

    def onReceive: PartialFunction[Event,Unit]
    
    subscribeEvents()
} 
开发者ID:emanchgo,项目名称:trove,代码行数:23,代码来源:UIEventListener.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala MultipartFormData类代码示例发布时间:2022-05-23
下一篇:
Scala Metrics类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap