From ad7118c0fecdfc1ad4527c4a98e0505ec0fab083 Mon Sep 17 00:00:00 2001 From: Sarah Gerweck Date: Wed, 15 Jun 2016 17:35:55 -0700 Subject: [PATCH] Add a new DebugTools object for debugging methods --- .../scalafx/util/ScalaFXDebugTools.scala | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/scala/org/gerweck/scalafx/util/ScalaFXDebugTools.scala diff --git a/src/main/scala/org/gerweck/scalafx/util/ScalaFXDebugTools.scala b/src/main/scala/org/gerweck/scalafx/util/ScalaFXDebugTools.scala new file mode 100644 index 0000000..c438cc6 --- /dev/null +++ b/src/main/scala/org/gerweck/scalafx/util/ScalaFXDebugTools.scala @@ -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")) + } +}