Source

miuler-blacknote / src / main / scala / com / miuler / blacknote / BlackNote.scala

package com.miuler.blacknote

import org.gnome.gdk.Event
import org.gnome.gtk.Window.DeleteEvent
import org.gnome.gtk.Button
import org.gnome.gtk.ComboBox
import org.gnome.gtk.Entry
import org.gnome.gtk.Gtk
import org.gnome.gtk.HBox
import org.gnome.gtk.Label
import org.gnome.gtk.ListStore
import org.gnome.gtk.VBox
import org.gnome.gtk.Widget
import org.gnome.gtk.Window
import Events.newMethodEventsToWindow
import org.gnome.gtk.DataColumnString
import org.gnome.gtk.DataColumn
import org.gnome.gtk.CellRendererText

class WindowConnect(window: Window) {

  def connect2 (eventType: AnyRef, function: (Widget, Event)=>Boolean) {
    
    val deleteEvent = classOf[Window.DeleteEvent]
    
    eventType match {
      case deleteEvent => {
        window.connect(new Window.DeleteEvent() {
          def onDeleteEvent(source: Widget, event: Event) = function(source, event)
        })
      }
    }

  }
}

object Events {
  implicit def newMethodEventsToWindow(window: Window) : WindowConnect = new WindowConnect(window)
}




class BlackNote() extends Window {
  
  println("BlackNote")
  val nombre = "Miuler"
  initWindow()
  
  
  def initWindow() {
    // ------------------------------------------------------------------------
    this.setDefaultSize(300, 200)
    val vBox = new VBox(false, 0)
    val hBox = new HBox(false, 20)
    hBox.setBorderWidth(5)
    vBox.add(hBox)
    add(vBox)
    
    // ------------------------------------------------------------------------
    hBox.add(new Label("Buscar :"))
    
    // ------------------------------------------------------------------------
    val firstColumnString = new DataColumnString()
    val columns = Array[DataColumn](firstColumnString)
    val model = new ListStore(columns)
    val entry = new Entry()
    val comboBox = new ComboBox(model, entry)
    val cellRendererText = new CellRendererText(comboBox)
    cellRendererText.setText(firstColumnString)
    hBox.add(comboBox)
    // ------------------------------------------------------------------------
    var row = model.appendRow()
    model.setValue(row, firstColumnString, "Miuler1")
    row = model.appendRow()
    model.setValue(row, firstColumnString, "Miuler2")
    
    // ------------------------------------------------------------------------
    val button = new Button("clickeame")
    vBox.add(new Button("clickeame1"))
    vBox.add(new Button("clickeame2"))
    this.connect2(classOf[Window.DeleteEvent], onDeleteEvent)

    showAll ()
  }
  
  def onDeleteEvent (source: Widget, event: Event) = {
    Gtk.mainQuit
    false
  }
}