New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip constructor cannot be resolved #210

Closed
kindlychung opened this Issue Sep 16, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@kindlychung

kindlychung commented Sep 16, 2015

Here is the code:

/*
 * Copyright 2013 ScalaFX Project
 * All right reserved.
 */
package scalafx.ensemble.example.charts

import scalafx.application.JFXApp
import scalafx.scene.Scene
import scalafx.scene.chart.PieChart
import scalafx.scene.control.Tooltip
import scala.collection.JavaConversions._


object BasicPie extends JFXApp {

  stage = new JFXApp.PrimaryStage {
    title = "Pie Chart Example"
    scene = new Scene {
      val pie: PieChart = new PieChart {
        data = Seq(
          PieChart.Data("Sun", 20),
          PieChart.Data("IBM", 12),
          PieChart.Data("HP", 25),
          PieChart.Data("Dell", 22),
          PieChart.Data("Apple", 30)
        )
        clockwise = false
      }
      root = pie
      val total = pie.getData.foldLeft(0.0) {
        (x, y) => x + y.getPieValue
      }
      pie.getData.foreach(
        d => {
          val sliceNode = d.getNode
          val pieValue: Double = d.getPieValue
          val percent = (pieValue / total) * 100
          val msg = "%s: %.2f (%.2f%%)".format(d.getName, pieValue, percent)
          val tt = new Tooltip()
          tt.setText(msg)
          tt.setStyle("-fx-background-color: yellow; " +
            "-fx-text-fill: black; ")
          Tooltip.install(sliceNode, tt)
        }
      )
    }
  }
}

Note that I have used Tooltip() instead of Tooltip(msg) because the latter would cause an type-mismatch error in intellij. Is this a bug?

@jpsacha

This comment has been minimized.

Member

jpsacha commented Oct 10, 2015

I would consider it a usability bug since looking at JavaFX documentation you can see there Tooltip constructor that takes String as an argument. The problem is that user would expect to have the same constructor in ScalaFX.

I think that person writing that Tooltip wrapper for ScaleFX assumed that it will be used in to forms. One if you just want a tooltip quickly:

val tt = Tooltip("some message")

Notice that there is no new, so it is the shortest way to write it. It is using apply factory method.
Second form for when you want to customize it (like changing style):

val tt = new Tooltip {
  text = "some message"
  style = "-fx-background-color: yellow; -fx-text-fill: black;"
}

I think that not having a Tooltip with String constructor was a deliberate choice at the time to avoid duplication (since there is already apply factory method that creates Tooltip from String). This applies also to may other wrappers.

For usability sake and to reduce confusion of users converting code directly from Java, this constructor should be added.

jpsacha added a commit that referenced this issue Oct 10, 2015

@jpsacha

This comment has been minimized.

Member

jpsacha commented Oct 10, 2015

The constructor was added to Tooltip. Please report if you see the same problem in other places.

@jpsacha jpsacha closed this Oct 10, 2015

@jpsacha jpsacha added this to the 8.0.*-R10 milestone Oct 10, 2015

@jpsacha jpsacha added the enhancement label Oct 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment