为什么scala中的swing组件似乎没有被完全包裹?例如,“paintImmediately”函数。或者“更新”(由于这个原因我似乎无法覆盖)。
与scala API相比,对Scala源代码的检查似乎有点令人困惑。(scala 2.9源代码如下)。 API似乎表明存在这些其他功能:
http://www.scala-lang.org/api/current/scala/swing/Component $ SuperMixin.html
据我所知,SuperMixin的特性是打开对等组件的覆盖调用。只有少数似乎已定义。我如何覆盖更新(图形g)?是否有更流畅的方式调用Panel.peer.paintImmediately(rect)?
我正在考虑修改Scala源代码来构建一个新的Panel类来纠正这些绘图问题。
抽象类组件扩展UIElement { override lazy val peer:javax.swing.JComponent = new javax.swing.JComponent with SuperMixin {} var initP:JComponent = null
/**
* This trait is used to redirect certain calls from the peer to the wrapper
* and back. Useful to expose methods that can be customized by overriding.
*/
protected trait SuperMixin extends JComponent {
override def paintComponent(g: Graphics) {
Component.this.paintComponent(g.asInstanceOf[Graphics2D])
}
def __super__paintComponent(g: Graphics) {
super.paintComponent(g)
}
override def paintBorder(g: Graphics) {
Component.this.paintBorder(g.asInstanceOf[Graphics2D])
}
def __super__paintBorder(g: Graphics) {
super.paintBorder(g)
}
override def paintChildren(g: Graphics) {
Component.this.paintChildren(g.asInstanceOf[Graphics2D])
}
def __super__paintChildren(g: Graphics) {
super.paintChildren(g)
}
override def paint(g: Graphics) {
Component.this.paint(g.asInstanceOf[Graphics2D])
}
def __super__paint(g: Graphics) {
super.paint(g)
}
}
答案 0 :(得分:0)
大多数scala swing包装器委托给java库中相应的包装peer
组件,并通过隐式转换使操作可用。
如果我有一些时间,我会添加一些细节。