Ejemplo n.º 1
0
func trViewInitTree(m, tv sparta.Widget) {
	d := m.Property(sparta.Data).(*trList)
	if d.pos >= len(d.phyLs) {
		return
	}
	title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, d.phyLs[d.pos].Name, d.phyLs[d.pos].Id)
	m.SetProperty(sparta.Caption, title)
	rect := tv.Property(sparta.Geometry).(image.Rectangle)
	curTree := setTree(d.phyLs[d.pos], rect)
	curTree.putOnScreen()
	tv.SetProperty(sparta.Data, curTree)
	tv.Update()
}
Ejemplo n.º 2
0
// TxKey gets keyboard events.
func txKey(tx sparta.Widget, e interface{}) bool {
	data := tx.Property(sparta.Data).(*pageData)
	ev := e.(sparta.KeyEvent)
	switch ev.Key {
	case sparta.KeyDown:
		if (data.pos + 1) < (len(poem) - data.page + 1) {
			data.pos++
		}
		tx.Update()
	case sparta.KeyUp:
		if (data.pos - 1) >= 0 {
			data.pos--
		}
		tx.Update()
	case sparta.KeyPageUp:
		if data.pos == 0 {
			break
		}
		data.pos -= data.page
		if data.pos < 0 {
			data.pos = 0
		}
		tx.Update()
	case sparta.KeyPageDown:
		if data.pos == (len(poem) - data.page) {
			break
		}
		data.pos += data.page
		if data.pos > (len(poem) - data.page + 1) {
			data.pos = len(poem) - data.page
		}
		tx.Update()
	}
	return true
}
Ejemplo n.º 3
0
func txNavInfo(tx sparta.Widget, data *txList) {
	if len(data.sels) == 0 {
		tx.SetProperty(sparta.Data, nil)
	} else {
		pair := &txTaxAnc{
			tax: data.desc[data.sels[0]],
			anc: data.tax,
		}
		if data.tax.Id == "0" {
			pair.anc = nil
		}
		tx.SetProperty(sparta.Data, pair)
	}
	tx.Update()
}
Ejemplo n.º 4
0
func trViewMouse(tv sparta.Widget, e interface{}) bool {
	dt := tv.Property(sparta.Data)
	if dt == nil {
		return true
	}
	data := dt.(*trData)
	ev := e.(sparta.MouseEvent)
	switch ev.Button {
	case sparta.MouseRight:
		if !setFlag {
			return true
		}
		if data.sel == nil {
			return true
		}
		sel := trViewNearestNode(ev.Loc, data.node)
		if sel == nil {
			return true
		}
		x, y, pos := data.x, data.y, data.pos
		p := tv.Property(sparta.Parent).(sparta.Widget)
		d := p.Property(sparta.Data).(*trList)
		if sel == data.sel {
			vals := new(jdh.Values)
			vals.Add(jdh.NodCollapse, sel.id)
			localDB.Exec(jdh.Delete, jdh.Nodes, vals)
			localDB.Exec(jdh.Commit, "", nil)
		} else if !sel.isValidSis(data.sel) {
			return true
		} else {
			vals := new(jdh.Values)
			vals.Add(jdh.KeyId, data.sel.id)
			vals.Add(jdh.NodSister, sel.id)
			localDB.Exec(jdh.Set, jdh.Nodes, vals)
			localDB.Exec(jdh.Commit, "", nil)
		}
		rect := tv.Property(sparta.Geometry).(image.Rectangle)
		data = setTree(d.phyLs[d.pos], rect)
		data.x, data.y, data.pos = x, y, pos
		tv.SetProperty(sparta.Data, data)
		data.putOnScreen()
		tv.Update()
	case sparta.MouseLeft:
		data.sel = trViewNearestNode(ev.Loc, data.node)
		tv.Update()
	case -sparta.MouseWheel:
		data.pos.Y -= 5
		data.putOnScreen()
		tv.Update()
	case sparta.MouseWheel:
		data.pos.Y += 5
		data.putOnScreen()
		tv.Update()
	}
	return true
}
Ejemplo n.º 5
0
// TxMouse gets mouse events.
func txMouse(tx sparta.Widget, e interface{}) bool {
	data := tx.Property(sparta.Data).(*pageData)
	ev := e.(sparta.MouseEvent)
	switch ev.Button {
	case sparta.MouseLeft, -sparta.MouseWheel:
		if (data.pos + 1) < (len(poem) - data.page + 1) {
			data.pos++
		}
		tx.Update()
	case sparta.MouseRight, sparta.MouseWheel:
		if (data.pos - 1) >= 0 {
			data.pos--
		}
		tx.Update()
	}
	return true
}
Ejemplo n.º 6
0
func spNavInfo(tx sparta.Widget, db jdh.DB, spe *jdh.Specimen, tax *jdh.Taxon) {
	if spe == nil {
		tx.SetProperty(sparta.Data, nil)
		tx.Update()
		return
	}
	if spe.Taxon != tax.Id {
		tx.SetProperty(sparta.Data, nil)
		tx.Update()
		return
	}
	info := &spInfo{
		tax: tax,
		spe: spe,
	}
	if len(spe.Dataset) > 0 {
		info.set = dataset(cmd, db, spe.Dataset)
	}
	tx.SetProperty(sparta.Data, info)
	tx.Update()
}
Ejemplo n.º 7
0
func trViewKey(tv sparta.Widget, e interface{}) bool {
	dt := tv.Property(sparta.Data)
	if dt == nil {
		return true
	}
	data := dt.(*trData)
	rect := tv.Property(sparta.Geometry).(image.Rectangle)
	ev := e.(sparta.KeyEvent)
	switch ev.Key {
	case sparta.KeyDown:
		data.pos.Y -= 5
	case sparta.KeyUp:
		data.pos.Y += 5
	case sparta.KeyLeft:
		data.pos.X -= 5
	case sparta.KeyRight:
		data.pos.X += 5
	case sparta.KeyHome:
		data.pos = image.Pt(0, 0)
	case sparta.KeyPageUp:
		data.pos.Y += rect.Dy() - sparta.HeightUnit
	case sparta.KeyPageDown:
		data.pos.Y -= rect.Dy() - sparta.HeightUnit
	case ' ', sparta.KeyReturn:
		p := tv.Property(sparta.Parent).(sparta.Widget)
		d := p.Property(sparta.Data).(*trList)
		if (d.pos + 1) >= len(d.phyLs) {
			return false
		}
		d.pos++
		title := fmt.Sprintf("%s: please wait", cmd.Name)
		p.SetProperty(sparta.Caption, title)
		tv.SetProperty(sparta.Data, nil)
		go trViewInitTree(p, tv)
	case sparta.KeyBackSpace:
		p := tv.Property(sparta.Parent).(sparta.Widget)
		d := p.Property(sparta.Data).(*trList)
		if (d.pos - 1) < 0 {
			return false
		}
		d.pos--
		tv.SetProperty(sparta.Data, nil)
		title := fmt.Sprintf("%s: please wait", cmd.Name)
		p.SetProperty(sparta.Caption, title)
		go trViewInitTree(p, tv)
	case '+':
		data.y = data.y * 5 / 4
	case '-':
		data.y = data.y * 4 / 5
	case '*':
		data.x = data.x * 5 / 4
	case '/':
		data.x = data.x * 4 / 5
	case '#':
		root := data.node[0]
		data.y = float32(rect.Dy()-10) / float32(root.terms+2)
		data.x = float32(rect.Dx()-10-(sparta.WidthUnit*32)) / float32(root.level)
	case '=':
		data.y = float32(sparta.HeightUnit)
		data.x = float32(sparta.WidthUnit * 2)
	case '>':
		if !data.aln {
			return false
		}
		data.aln = false
	case '<':
		if data.aln {
			return false
		}
		data.aln = true
	default:
		return true
	}
	data.putOnScreen()
	tv.Update()
	return false
}