【问题标题】:Swing wrapper seems to lack certain peer functions?Swing 包装器似乎缺少某些对等功能?
【发布时间】:2012-11-18 06:44:34
【问题描述】:

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

【问题讨论】:

    标签: swing scala


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!确实问题似乎是覆盖某些方法..虽然我可以简单地向对等方发送调用调用,但覆盖方法已被证明是一个问题(因为对等方已经实例化)。也许有一种方法可以覆盖整个对等对象?
    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 2021-09-25
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 1970-01-01
    相关资源
    最近更新 更多