0
votes

any thoughts why the swing components in scala do not seem to be fully wrapped? For example, the "paintImmediately" function. Or "Update" (which I can't seem to override due to this).

An examination of the Scala source code compared to the scala API seems a little confusing.. (scala 2.9 source exert below). The API seems to suggest these other functions exist:

http://www.scala-lang.org/api/current/scala/swing/Component$SuperMixin.html

From what I can tell the SuperMixin trait is what opens up override calls to the peer component. Just a few seems defined. How might I override Update(Graphics g)? Is there a more fluent way of calling Panel.peer.paintImmediately(rect)?

I'm considering modding the Scala source to build a new Panel class to correct these issues for drawing.

abstract class Component extends 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)
    }
  }
1

1 Answers

0
votes

Most scala swing wrappers delegate to the corresponding wrapped peer component in the java library, and the operations are made available through implicit conversions.

I'll add some detail when I have some minutes to spare.