Skip to content

Commit

Permalink
差不多了,把CUI的信息移植到GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Aug 9, 2016
1 parent f9f33a4 commit fa1f526
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/core/models/Graph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ class Graph(file: File) {
}
}

operator fun plusAssign(point: Point) {
if (pointCache connect point) LogConsole.log("Yes!! Connected!!")
else LogConsole.log("Not connected!!")
/**
* @param point send a clicked point
* @return connected
*/
fun send(point: Point): Boolean {
val ret = pointCache connect point
// LogConsole.log("Yes!! Connected!!")
// else
// LogConsole.log("Not connected!!")
val line = Line(pointCache, point)
line.getAllPoints().forEach { p -> image.setRGB(p.x, p.y, Color.BLUE.rgb) }
pointCache = point
pointCache.getColor = getColor
return ret
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/core/models/Point.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class Point(val x: Int, val y: Int, internal var getColor: (Int, Int) -> Boolean
/** 判断两点是否连通 (。ŏ﹏ŏ) */
infix fun connect(point: Point): Boolean {
val line = Line(this, point)
(Math.min(this.x, point.x)..Math.max(this.x, point.x)).forEach { x ->
if (!getColor(x, line.f(x).toInt())) return false
}
(Math.min(this.y, point.y)..Math.max(this.y, point.y)).forEach { y ->
if (!getColor(line.fa(y).toInt(), y)) return false
}
line.getAllPoints().forEach { p -> if (!getColor(p.x, p.y)) return false }
return true
}

Expand Down
8 changes: 5 additions & 3 deletions src/view/components/ImagePanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package view.components

import core.models.Graph
import core.models.Point
import utils.debug.LogConsole
import java.awt.Graphics
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
import javax.swing.JOptionPane
import javax.swing.JPanel

/**
Expand All @@ -22,9 +22,11 @@ class ImagePanel(var graph: Graph) : JPanel() {
override fun mousePressed(e: MouseEvent) = Unit
override fun mouseClicked(e: MouseEvent) {
graph.init()
graph += Point(e.x, e.y)
val connected = graph.send(Point(e.x, e.y))
repaint()
LogConsole.log("e.x = ${e.x}, e.y = ${e.y}")
JOptionPane.showMessageDialog(null, if (connected) "Connected" else "Not Connected",
"Information", JOptionPane.INFORMATION_MESSAGE)
// LogConsole.log("e.x = ${e.x}, e.y = ${e.y}")
}
})
}
Expand Down

0 comments on commit fa1f526

Please sign in to comment.