@@ -31,6 +31,7 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
3131 private val primaryColour = UIManager .getDefaults().getColor(" Panel.foreground" )
3232 private val backgroundColour = UIManager .getDefaults().getColor(" CheckBox.icon.background" )
3333 private val secondaryColour = UIManager .getDefaults().getColor(" Button.default.background" ) // javax.swing.UIManager.getDefaults().getColor("Button.default.focusColor")
34+ val barHeight = UIManager .getInt(" ScrollBar.width" )
3435 private val green = if (! FlatLaf .isLafDark()) Color (89 , 158 , 94 ) else Color (136 , 207 , 131 )
3536 private val d = 20
3637 private val hSpace = 100
@@ -89,15 +90,10 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
8990 g.drawString(zoomStr, width - zoomStrWidth - 5 , 10 + 15 )
9091 }
9192
92- val barHeight = UIManager .getInt(" ScrollBar.width" )
93- val tOffset = ((xOffset.toDouble()/ renderedWidth) * width).toInt()
94- val w = (width/ scaleFactor)* width/ renderedWidth
95- g.color = Color (100 , 100 , 100 , 50 )
9693 g.color = UIManager .getColor(" ScrollBar.track" )
9794 g.fillRect(0 , 0 , width,barHeight)
98- g.color = Color (150 , 150 , 255 , 150 )
99- g.color = UIManager .getColor(" ScrollBar.thumb" )
100- g.fillRect(tOffset, 0 , max(w.toInt(), 5 ),barHeight)
95+ g.color = if (draggingScrollBar) UIManager .getColor(" ScrollBar.pressedThumbColor" ) else UIManager .getColor(" ScrollBar.thumb" )
96+ g.fillRect(scrollBarPosition(), 0 , scrollBarWidth(), barHeight)
10197
10298 selectedNode?.let { node ->
10399 val xPos = (node.x.toDouble()/ renderedWidth) * width
@@ -139,6 +135,14 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
139135 g.scale(1/scale, 1/scale)*/
140136 }
141137
138+ private fun scrollBarPosition (): Int {
139+ return ((xOffset.toDouble()/ renderedWidth) * width).toInt()
140+ }
141+
142+ private fun scrollBarWidth (): Int {
143+ return max(((width/ scaleFactor)* width/ renderedWidth).toInt(), 5 )
144+ }
145+
142146 fun saveImage (filename : String ) {
143147 println (" Full graph size $renderedWidth x $renderedHeight " )
144148 val imageSize = 30000
@@ -315,7 +319,7 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
315319 return
316320 }
317321
318- if (e.y < 10 ) {
322+ if (e.y < barHeight ) {
319323 xOffset = ((e.x.toDouble()/ width) * renderedWidth).roundToInt() - width/ 2
320324 repaint()
321325 return
@@ -348,7 +352,13 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
348352 startPos = p0.point
349353 }
350354
355+ private var draggingScrollBar = false
351356 override fun mouseReleased (e : MouseEvent ) {
357+ println (" Mouse released" )
358+ if (draggingScrollBar) {
359+ draggingScrollBar = false
360+ repaint()
361+ }
352362 if (e.button != MouseEvent .BUTTON1 ) {
353363 mouseClicked(e)
354364 e.consume()
@@ -361,19 +371,33 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
361371 override fun mouseExited (p0 : MouseEvent ) {}
362372
363373 override fun mouseDragged (e : MouseEvent ) {
374+ println (" Mouse dragged" )
364375 if (e.button != MouseEvent .BUTTON1 ) {
365376 e.consume()
366377 return
367378 }
368379
369380 val delta = Point (e.x - startPos.x, e.y - startPos.y)
381+ startPos = Point (e.x, e.y)
382+
383+ val pos = scrollBarPosition()
384+ val w = scrollBarWidth()
385+ if (e.y < barHeight || draggingScrollBar) {
386+ if ((e.x >= pos && e.x < pos + w) || draggingScrollBar) {
387+ xOffset + = ((delta.x.toDouble()/ width) * renderedWidth).roundToInt()
388+ draggingScrollBar = true
389+ repaint()
390+ }
391+ e.consume()
392+ return
393+ }
394+
370395 println (" " + e.x + " " + e.y)
371396 /* associatedScrollPane?.horizontalScrollBar?.value -= delta.x
372397 associatedScrollPane?.verticalScrollBar?.value -= delta.y*/
373398 xOffset - = (delta.x / scaleFactor).toInt()
374399 yOffset - = (delta.y / scaleFactor).toInt()
375400 repaint()
376- startPos = Point (e.x, e.y)
377401 }
378402
379403 override fun mouseMoved (e : MouseEvent ) {
0 commit comments