Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 140 lines (120 sloc) 4.995 kB
dbe0e2b fixed Scala comments, added svn:keywords
michelou authored
1 /* __ *\
2 ** ________ ___ / / ___ Scala API **
2d11a5b Updated copyright notices to 2011
Antonio Cunei authored
3 ** / __/ __// _ | / / / _ | (c) 2007-2011, LAMP/EPFL **
dbe0e2b fixed Scala comments, added svn:keywords
michelou authored
4 ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5 ** /____/\___/_/ |_/____/_/ | | **
6 ** |/ **
7 \* */
8
9
10
3061007 scala.swing update, reverted Martin's changes
NAME authored
11 package scala.swing
ef488e9 scala.swing update
NAME authored
12
852f027 Synchronize trunk with local changes:
Ingo Maier authored
13 import java.awt.Cursor
d4c63b2 @odersky Fixed #2494, plus some reorganization of swing ...
odersky authored
14 import event._
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
15 import scala.collection.mutable.HashMap
16 import scala.ref._
17 import java.util.WeakHashMap
18
19 object UIElement {
20 private val ClientKey = "scala.swingWrapper"
21 private[this] val wrapperCache = new WeakHashMap[java.awt.Component, WeakReference[UIElement]]
22
23 private def cache(e: UIElement) = e.peer match {
24 case p: javax.swing.JComponent => p.putClientProperty(ClientKey, e)
25 case _ => wrapperCache.put(e.peer, new WeakReference(e))
26 }
27
28 /**
d4c53a9 Better scaladocs
Ingo Maier authored
29 * Looks up the internal component cache for a wrapper of the given
30 * Java Swing peer. If this method finds one of the given type `C`,
31 * it will return that wrapper. Otherwise it returns `null`. This
32 * method never throws an exception.
25d87ef Fixed #2803.
Ingo Maier authored
33 *
34 * Clients should be extremely careful with type parameter `C` and
35 * its interaction with type inference. Better err on the side of caution
36 * and explicitly specify `C`.
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
37 */
7ddabed @odersky Closed #2801.
odersky authored
38 private[swing] def cachedWrapper[C>:Null<:UIElement](c: java.awt.Component): C = {
35c5908 Applied some of Kevin Wright's patches.
Ingo Maier authored
39 val w = c match {
40 case c: javax.swing.JComponent => c.getClientProperty(ClientKey)
41 case _ => wrapperCache.get(c)
42 }
43 try { w.asInstanceOf[C] } catch { case _ => null }
44 }
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
45
46 /**
d4c53a9 Better scaladocs
Ingo Maier authored
47 * Returns a wrapper for a given Java Swing peer. If there is a
48 * compatible wrapper in use, this method will return it.
49 *
50 * `wrap` methods in companion objects of subclasses of UIElement have the
51 * same behavior, except that they return more specific wrappers.
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
52 */
53 def wrap(c: java.awt.Component): UIElement = {
35c5908 Applied some of Kevin Wright's patches.
Ingo Maier authored
54 val w = cachedWrapper[UIElement](c)
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
55 if (w != null) w
56 else new UIElement { def peer = c }
57 }
58 }
bc99ad9 scala.swing update
NAME authored
59
d814e50 scala.swing update for rc2
NAME authored
60 /**
b219392 oops, worked on branch, merging back into trunk
Ingo Maier authored
61 * The base trait of all user interface elements. Subclasses belong to one
62 * of two groups: top-level elements such as windows and dialogs, or
b953900 added some swing scaladocs
Ingo Maier authored
63 * <code>Component</code>s.
64 *
c02c236 more scaladocs for swing
Ingo Maier authored
65 * @note [Java Swing] This trait does not have an exact counterpart in
66 * Java Swing. The peer is of type java.awt.Component since this is the
67 * least common upper bound of possible underlying peers.
68 *
35c5908 Applied some of Kevin Wright's patches.
Ingo Maier authored
69 * @note [Implementation] A UIElement automatically adds itself to the
70 * component cache on creation.
71 *
b953900 added some swing scaladocs
Ingo Maier authored
72 * @see java.awt.Component
d814e50 scala.swing update for rc2
NAME authored
73 */
b3924e6 ComponentResized et al moved to UIElementResized
Ingo Maier authored
74 trait UIElement extends Proxy with LazyPublisher {
c02c236 more scaladocs for swing
Ingo Maier authored
75 /**
76 * The underlying Swing peer.
77 */
bc99ad9 scala.swing update
NAME authored
78 def peer: java.awt.Component
aa3d38d Fixed and added things for Andrew, rearranged e...
Ingo Maier authored
79 def self = peer
3fbd4f0 Loading images through getResource for the jar,...
Ingo Maier authored
80
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
81 UIElement.cache(this)
82
bc99ad9 scala.swing update
NAME authored
83 def foreground: Color = peer.getForeground
84 def foreground_=(c: Color) = peer.setForeground(c)
85 def background: Color = peer.getBackground
86 def background_=(c: Color) = peer.setBackground(c)
ef488e9 scala.swing update
NAME authored
87
113c795 Fixed Table, wrapped more of button
NAME authored
88 def minimumSize = peer.getMinimumSize
89 def minimumSize_=(x: Dimension) = peer.setMinimumSize(x)
90 def maximumSize = peer.getMaximumSize
91 def maximumSize_=(x: Dimension) = peer.setMaximumSize(x)
92 def preferredSize = peer.getPreferredSize
93 def preferredSize_=(x: Dimension) = peer.setPreferredSize(x)
954377b Removed deprecation warnings.
Ingo Maier authored
94
bc99ad9 scala.swing update
NAME authored
95 def font: Font = peer.getFont
96 def font_=(f: Font) = peer.setFont(f)
d814e50 scala.swing update for rc2
NAME authored
97
98 def locationOnScreen = peer.getLocationOnScreen
99 def location = peer.getLocation
100 def bounds = peer.getBounds
101 def size = peer.getSize
cb6a345 Merged revisions 24830-24831,24834-24862 via sv...
Antonio Cunei authored
102 @deprecated("Explicit size assignment for UIElements is not supported anymore. " +
15d4776 Merged revisions 24803-24820 via svnmerge from
Antonio Cunei authored
103 "Use a layout manager or subclass Window.", "2.8.0")
f759e27 @odersky changes to swing library to make Button app work
odersky authored
104 def size_=(dim: Dimension) = peer.setSize(dim)
d83917a * dialogs use named arguments now, messages are...
Ingo Maier authored
105
d814e50 scala.swing update for rc2
NAME authored
106 def locale = peer.getLocale
107 def toolkit = peer.getToolkit
108
109 def cursor: Cursor = peer.getCursor
110 def cursor_=(c: Cursor) { peer.setCursor(c) }
111
112 def visible: Boolean = peer.isVisible
113 def visible_=(b: Boolean) { peer.setVisible(b) }
114 def showing: Boolean = peer.isShowing
5906c86 bigger commit for 2.8 preview
Ingo Maier authored
115 def displayable: Boolean = peer.isDisplayable
d814e50 scala.swing update for rc2
NAME authored
116
117 def repaint() { peer.repaint }
0d51322 Fixes for #1817, #1850
Ingo Maier authored
118 def repaint(rect: Rectangle) { peer.repaint(rect.x, rect.y, rect.width, rect.height) }
119 def ignoreRepaint: Boolean = peer.getIgnoreRepaint
120 def ignoreRepaint_=(b: Boolean) { peer.setIgnoreRepaint(b) }
b3924e6 ComponentResized et al moved to UIElementResized
Ingo Maier authored
121
cb6a345 Merged revisions 24830-24831,24834-24862 via sv...
Antonio Cunei authored
122 protected def onFirstSubscribe() {
b3924e6 ComponentResized et al moved to UIElementResized
Ingo Maier authored
123 peer.addComponentListener(new java.awt.event.ComponentListener {
124 def componentHidden(e: java.awt.event.ComponentEvent) {
125 publish(UIElementHidden(UIElement.this))
126 }
127 def componentShown(e: java.awt.event.ComponentEvent) {
128 publish(UIElementShown(UIElement.this))
129 }
130 def componentMoved(e: java.awt.event.ComponentEvent) {
131 publish(UIElementMoved(UIElement.this))
132 }
133 def componentResized(e: java.awt.event.ComponentEvent) {
134 publish(UIElementResized(UIElement.this))
135 }
136 })
137 }
cb6a345 Merged revisions 24830-24831,24834-24862 via sv...
Antonio Cunei authored
138 protected def onLastUnsubscribe() {}
dbe0e2b fixed Scala comments, added svn:keywords
michelou authored
139 }
Something went wrong with that request. Please try again.