blob: 58bc1d763e7dfc35c4c6b07a5efb278e61410746 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
object Serialize {
@throws(classOf[java.io.IOException])
def write[A](o: A): Array[Byte] = {
val ba = new java.io.ByteArrayOutputStream(512)
val out = new java.io.ObjectOutputStream(ba)
out.writeObject(o)
out.close()
ba.toByteArray()
}
@throws(classOf[java.io.IOException])
@throws(classOf[ClassNotFoundException])
def read[A](buffer: Array[Byte]): A = {
val in =
new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
in.readObject().asInstanceOf[A]
}
}
@serializable
@SerialVersionUID(1L)
class VarModel[T]( getter: => T, setter: T => Unit )
{
Serialize.write(getter)
Serialize.write(setter)
def this( getter: => T ) = this( getter, null )
def getObject: AnyRef = getter.asInstanceOf[AnyRef]
def setObject( v: AnyRef ) = {
if( setter==null )
throw new RuntimeException( "Tried to set readonly model!")
setter( v.asInstanceOf[T] )
}
def detach = ()
}
@serializable
@SerialVersionUID(1L)
class Printer( p: VarModel[String] ) {
def print = println( p.getObject );
}
class Component extends Marker { }
class Form extends Component { }
@serializable
@SerialVersionUID(1L)
class Main {
var pass = "pass"
def main(args : Array[String]) : Unit = {
val f = new Form {
val p = new Printer( new VarModel( pass, pass=_ ) );
p.print
}
()
}
}
object Test {
def main(args: Array[String]) {
(new Main).main(Array[String]())
}
}
|