0

任何想法为什么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 { 覆盖惰性 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)
    }
  }
4

1 回答 1

0

大多数 scala swing 包装器委托给 java 库中相应的包装peer组件,并且通过隐式转换使操作可用。

当我有空的时候,我会添加一些细节。

于 2012-11-18T08:31:19.317 回答