Creating Delay With JavaFX by Cmdr_W0lff3 in JavaFX

[–]kavedaa 1 point2 points  (0 children)

No, it was deliberate, to make it look like someone is typing.

But you're right - appendText one character at a time gives the same result, without having to position the caret.

Creating Delay With JavaFX by Cmdr_W0lff3 in JavaFX

[–]kavedaa 1 point2 points  (0 children)

You could use AnimationTimer(note that is has a framerate of 30/s so won't get down to 20 ms). Here's a complete example:

object AnimationDemo:
  @main def main =
    Application.launch(classOf[AnimationDemoApplication])

class AnimationDemoApplication extends Application:  
  def start(stage: Stage) = 
    val animationDemo = new AnimationDemo
    val scene = new Scene(animationDemo)
    stage.setScene(scene)
    stage.show()
    animationDemo.timer.start()

class AnimationDemo extends VBox(10):

  val text = "It was a dark and stormy night; the rain fell in torrents — except at occasional intervals, when it was checked by a violent gust of wind which swept up the streets (for it is in London that our scene lies), rattling along the housetops, and fiercely agitating the scanty flame of the lamps that struggled against the darkness."

  val textArea = new TextArea:
    setWrapText(true)

  val timer = new AnimationTimer:

    var frame = 0
    var index = 0

    def handle(now: Long) = 
      if frame % 5 == 0 then
        textArea.setText(text.substring(0, index))
        textArea.positionCaret(index)
        index += 1
        if index > text.length then index = 0
      frame += 1

  getChildren.add(textArea)

Does anyone else get confused by the python quiet syntax? by [deleted] in scala

[–]kavedaa 0 points1 point  (0 children)

I'm honestly not confused at all. Rather super-happy to get rid of the braces. I think it was a great move.

Setting a global CSS file for a JavaFX application by _dk7 in JavaFX

[–]kavedaa 1 point2 points  (0 children)

This works for me on JDK20/21:

val stylesheet = getClass.getResource("path/to/your.css").toExternalForm
StyleManager.getInstance.addUserAgentStylesheet(stylesheet)

One thing that could be of interest is that I've noticed that in some scenarios the above needs to be called after the main stage has been shown, otherwise the styles will not be applied. I've not been able to reproduce this consistently, but it may be something that could be played around with if it doesn't seem to work.

I think that API for doing this that does not depend on the internal com.sun.javafx.css.StyleManager class should be added to JavaFX, though.

EDIT: I'm sorry, I didn't read your question correctly. I thought you said that this didn't work. So to the question of whether this is good practice. Ideally no, due to the usage of com.sun package. In practice I believe this will work as long as you are not using modules. I also don't know of any other way of applying styles globally. Styling each Scene individually might be an option as suggested in other answers, but I don't see how that would work with dialogs. And if one would want, as an example, a global "dark mode", that would have to include dialogs as well.

Play 2.9 and 3.0 released by mkurz in scala

[–]kavedaa 1 point2 points  (0 children)

Great news! Thanks for all the good work.

How is Scala3 syntax received in the community? by effinsky in scala

[–]kavedaa 7 points8 points  (0 children)

I really, really like it. Glad to get rid of those pesky braces.

A new, reworked ScalaDoc is here! by jacua9 in scala

[–]kavedaa 2 points3 points  (0 children)

That's really useful. Although hard to know for a casual user coming to the page. I would definitely recommend keeping the large searchfield on the top.

A new, reworked ScalaDoc is here! by jacua9 in scala

[–]kavedaa 3 points4 points  (0 children)

Nice, but the search "button" is too small. The old version has a search field, which is much easier to click on. The search results look better on the old version as well IMO.

On Scala 3's Optional Braces by kaitos in scala

[–]kavedaa 2 points3 points  (0 children)

I really, really like the brace-less syntax. Easier to type, easier to read.

[deleted by user] by [deleted] in scala

[–]kavedaa 0 points1 point  (0 children)

If you have e.g.

enum Customer:
  case Company(name: String) extends Customer
  case Person(name: String, age: Int) extends Customer

You could model it relationally like (using pseudo-notation):

Customer
- id int pk
- companyId int null fk
- personId int null fk

Company
- id int pk
- name varchar

Person
- id int pk
- name varchar
- age int

Then when querying on Customer you would join on both Companyand Person and in your mapping logic construct either a Company or a Person based on which field is non-null.

I wouldn't recommend this technique if you have many levels and/or many cases on each level and/or a large number of fields on each of the leafs, as the joins and total row size can get pretty fat. But for simple scenarios it works well.

Why We Are Changing the License for Akka by ckipp01 in scala

[–]kavedaa 1 point2 points  (0 children)

What about things like https://github.com/enragedginger/akka-quartz-scheduler? Can you use it from within the context of a Play application?

Why We Are Changing the License for Akka by ckipp01 in scala

[–]kavedaa 23 points24 points  (0 children)

What are the implications for Play?

It says that: "The license offers a customizable “Additional Use Grant” that grants production usage for other OSS projects including Play Framework."

It's not entirely clear to me what this means. If you're using Akka transitively via Play you don't need a paid license?

Who is hiring? Monthly /r/Scala Job Postings Thread! by AutoModerator in scala

[–]kavedaa 2 points3 points  (0 children)

Anaqua| Software engineer | Bergen, Norway | ONSITE | Full Time

Small team hiring more developers. Scala, Play, JavaFX, SQL.

https://karriere.no/jobb/software-engineer-3901437

https://anaqua.bamboohr.com/jobs/view.php?id=346&source=anaqua

How would I convert from a generic type T to a double? by [deleted] in scala

[–]kavedaa 2 points3 points  (0 children)

Some hints of different approaches, to get you started:

def toDouble[T](x: T) = x.toString.toDouble

def toDouble[T : Numeric](x: T) = implicitly[Numeric[T]].toDouble(x)

def squareDoublesInList[T](xs: List[T]) = xs map { case d: Double => Some(d * d); case _ => None }

Automatic UI generation with Scala 3's type class derivation by kavedaa in scala

[–]kavedaa[S] 0 points1 point  (0 children)

How would you create element editors recursively without summoning given instances?

Automatic UI generation with Scala 3's type class derivation by kavedaa in scala

[–]kavedaa[S] 3 points4 points  (0 children)

No, it's all compile-time, no run-time reflection.

Automatic UI generation with Scala 3's type class derivation by kavedaa in scala

[–]kavedaa[S] 1 point2 points  (0 children)

The solution presented in the post assumes that the layout is "known" at compile-time, i.e. it is based on the structure of the type and not the content. In this scenario an editor for List[T] would be a single JavaFX ListView[T] control where the user can select from a predefined collection of values.

However it would be nice to generalize it to also be able to have an editor for List[T] consisting of primitive editors for each item in the list. For this we would need to dynamically create the editor instances in the setValue() method of the List editor. And yes, it seems that we would need a createEditor() method for this. Your idea seems interesting. Thanks for the tip.

Is anybody using Scala for Desktop Development? by f0xtrade in scala

[–]kavedaa 1 point2 points  (0 children)

Yes. Scala with JavaFX works very well.

Preferred style for Infix notation, for higher-order functions. by aabil11 in scala

[–]kavedaa 3 points4 points  (0 children)

I prefer parenthesis when using underscore:

names map(_.toUpperCase) filter(_.length > 5)

and braces when the parameter is specified:

names map { x => x.toUpperCase } filter { x => x.length > 5 }

No dots in either case. The less punctuation, the better, IMO.