Add a new DebugTools object for debugging methods

This commit is contained in:
Sarah Gerweck 2016-06-15 17:35:55 -07:00
parent b962c62209
commit ad7118c0fe

View File

@ -0,0 +1,43 @@
package org.gerweck.scalafx.util
import scalafx.scene.input.Dragboard
import org.log4s._
/** Miscellaneous utility methods for debugging activity. */
object ScalaFXDebugTools {
/** Print information about drag-and-drop content to the logs.
*
* This can get quite noisy if you do it on DragOver, so typically this
* would only be used during debugging and disabled altogether in the real
* product.
*/
def logDragboardInfo(logger: Logger, level: LogLevel, showData: Boolean = true)(drb: Dragboard): Unit = {
val summary = {
val m =
Map("html" -> drb.hasHtml,
"text" -> drb.hasString,
"url" -> drb.hasUrl,
"image" -> drb.hasImage,
"rtf" -> drb.hasRtf)
m.map{case (k, v) => s"has${k.capitalize}: $v"}.mkString("; ")
}
var pieces: Seq[String] = Vector(summary)
if (showData) {
if (drb.hasUrl) {
pieces :+= s"Dragboard URL: ${drb.url}"
}
if (drb.hasHtml) {
pieces :+= s"Dragboard HTML: ${drb.html}"
}
if (drb.hasString) {
pieces :+= s"Dragboard String: ${drb.string}"
}
if (drb.hasRtf) {
pieces :+= s"Dragboard RTF: ${drb.rtf}"
}
}
logger(level)(pieces.mkString("\n"))
}
}