Skip to content

Commit c79b0c6

Browse files
committed
6666
1 parent 25701d6 commit c79b0c6

File tree

4 files changed

+48
-62
lines changed

4 files changed

+48
-62
lines changed

App/src/view/Factory.kt

-59
This file was deleted.

App/src/view/FinderGUI.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package view
22

33
import finder.Finder666
44
import view.components.FinderImagePanel
5+
import view.components.Frame666
56
import java.awt.BorderLayout
67

78
/**
@@ -10,7 +11,7 @@ import java.awt.BorderLayout
1011
*/
1112
open class FinderGUI(title: String, var graph: Finder666) {
1213
val panel = FinderImagePanel(graph)
13-
val frame = Factory.create(title, { setupFrame() }, { file -> graph = graph.createFromFile(file) })
14+
val frame = Frame666(title, { setupFrame() }, { file -> graph = graph.createFromFile(file) })
1415

1516
init {
1617
frame.add(panel, BorderLayout.CENTER)

App/src/view/SearcherGUI.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package view
22

33
import searcher.Searcher666
4+
import view.components.Frame666
45

56
/**
67
* @author ice1000
78
* Created by ice1000 on 2016/8/11.
89
*/
910
class SearcherGUI(title: String, var graph: Searcher666) {
10-
val frame = Factory.create(title, { setupFrame() }, { file -> graph = graph.createFromFile(file) })
11+
val frame = Frame666(title, { setupFrame() }, { file -> graph = graph.createFromFile(file) })
1112

1213
private fun setupFrame() {
1314
frame.setupSize(graph.image.width, graph.image.height)

App/src/view/components/Frame666.kt

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,62 @@
11
package view.components
22

3+
import ice1000.average
34
import java.awt.BorderLayout
45
import java.awt.Component
6+
import java.io.File
7+
import javax.swing.JButton
8+
import javax.swing.JFileChooser
59
import javax.swing.JFrame
10+
import javax.swing.filechooser.FileNameExtensionFilter
611

712
/**
813
* @author ice1000
914
* Created by ice1000 on 2016/8/8.
1015
*/
1116

12-
class Frame666(title: String) : JFrame(title) {
17+
class Frame666(title: String, setupFrame: () -> Unit, changeGraph: (File) -> Unit) : JFrame(title) {
1318

1419
var spaceHeight = 0
1520
var spaceWidth = 0
1621

22+
init {
23+
layout = BorderLayout()
24+
25+
val chooserButton = JButton("Open File")
26+
27+
chooserButton.addActionListener { action ->
28+
29+
val chooser = JFileChooser()
30+
chooser.fileSelectionMode = JFileChooser.FILES_ONLY
31+
chooser.fileFilter = FileNameExtensionFilter("Supported Image Format", "png", "jpg")
32+
33+
if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) {
34+
changeGraph(chooser.selectedFile)
35+
setupFrame()
36+
}
37+
}
38+
add(chooserButton, BorderLayout.SOUTH)
39+
40+
fun manageAverage(number: Int) {
41+
average += number
42+
if (average > 0b11111111) average = 0b11111111
43+
if (average < 0b0) average = 0b0
44+
println(average)
45+
setupFrame()
46+
}
47+
48+
val plusButton = JButton("+\n+\n+")
49+
plusButton.addActionListener { action -> manageAverage(5) }
50+
add(plusButton, BorderLayout.WEST)
51+
52+
val minusButton = JButton("-\n-\n-")
53+
minusButton.addActionListener { action -> manageAverage(-5) }
54+
add(minusButton, BorderLayout.EAST)
55+
56+
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
57+
isResizable = false
58+
}
59+
1760
override fun add(comp: Component, constraints: Any?) {
1861
super.add(comp, constraints)
1962
when (constraints) {

0 commit comments

Comments
 (0)