コード例 #1
0
ファイル: show.py プロジェクト: hangal/unifi
    def __init__(self):
        sourcePath = System.getProperty("unifi.sp")
        uc_file = System.getProperty("unifi.read") 
        sourcePath = sourcePath.split(":")

        print "srcpath:", sourcePath
        print "uc_file:", uc_file

        self.panel = GuiPanel(sourcePath, uc_file)
        self.miner = TermMiner(Unit._current_unit_collection)
        self.panel.guessCallback = GythonCallback(self, self.miner)
        self.guessCallback = self.panel.guessCallback
        self.currentGraphRep = None

        #graphevents.clickNode = self.mouseClickNode
        graphevents.clickEdge = self.mouseClickEdge
        graphevents.mouseEnterEdge = self.mouseEnterEdge
        graphevents.mouseLeaveEdge = self.mouseLeaveEdge
        graphevents.mouseEnterNode = self.mouseEnterNode
        graphevents.mouseLeaveNode = self.mouseLeaveNode
        self.prevClicked = None

        EdgeEditorPopup.addItem("** UniFi Options **")

        disconnectEdgeItem = EdgeEditorPopup.addItem("Disconnect")
        disconnectEdgeItem.menuEvent = self.disconnectEdge

        vf.defaultNodeZooming(false)
        vf.defaultEdgeZooming(false)

        self.source = "None"

        self.miner.run()

        showAllClusters = System.getProperty("showall")
        if showAllClusters is None:
            from java.util import ArrayList
            arrayList = ArrayList()
            for r in self.miner.sortedReps:
                arrayList.add(r)

            self.panel.filterAndSortClusters(arrayList)

        self.panel.display_all()
        self.add(self.panel)
        
        # add the toolbar to the main UI window
        ui.dock(self)
コード例 #2
0
ファイル: show.py プロジェクト: hangal/unifi
class SourceViewer(com.hp.hpl.guess.ui.DockableAdapter):

    def __init__(self):
        sourcePath = System.getProperty("unifi.sp")
        uc_file = System.getProperty("unifi.read") 
        sourcePath = sourcePath.split(":")

        print "srcpath:", sourcePath
        print "uc_file:", uc_file

        self.panel = GuiPanel(sourcePath, uc_file)
        self.miner = TermMiner(Unit._current_unit_collection)
        self.panel.guessCallback = GythonCallback(self, self.miner)
        self.guessCallback = self.panel.guessCallback
        self.currentGraphRep = None

        #graphevents.clickNode = self.mouseClickNode
        graphevents.clickEdge = self.mouseClickEdge
        graphevents.mouseEnterEdge = self.mouseEnterEdge
        graphevents.mouseLeaveEdge = self.mouseLeaveEdge
        graphevents.mouseEnterNode = self.mouseEnterNode
        graphevents.mouseLeaveNode = self.mouseLeaveNode
        self.prevClicked = None

        EdgeEditorPopup.addItem("** UniFi Options **")

        disconnectEdgeItem = EdgeEditorPopup.addItem("Disconnect")
        disconnectEdgeItem.menuEvent = self.disconnectEdge

        vf.defaultNodeZooming(false)
        vf.defaultEdgeZooming(false)

        self.source = "None"

        self.miner.run()

        showAllClusters = System.getProperty("showall")
        if showAllClusters is None:
            from java.util import ArrayList
            arrayList = ArrayList()
            for r in self.miner.sortedReps:
                arrayList.add(r)

            self.panel.filterAndSortClusters(arrayList)

        self.panel.display_all()
        self.add(self.panel)
        
        # add the toolbar to the main UI window
        ui.dock(self)

    def disconnectEdge(self, edge):
        print "removing edge:", edge

##    def mouseClickNode(self, node):
##        print "mouseClickNode clicked!!!"
##
##        containingHull = None
##        print "self.hulls.size:", len(self.hulls)
##        for hull in self.hulls:
##            print "iterating self.hulls, hull:", hull
##            nodes = hull.getNodes()
##            if node in nodes:
##                containingHull = hull
##                break
##
##        if containingHull == None: 
##            print "No containing hull for this node:", node
##            return
##
##        print "Found containing hull for this node:", node
##
##        from java.awt import Color
##
##        if self.prevHull != None:
##            colorStr = self.prevHull.getColor()
##            c = colorStr.split(',')
##
##            c = Color(int(c[0]), int(c[1]), int(c[2]), int(c[3]) - 70)
##            self.prevHull.setColor(c)
##
##
##
##        colorStr = containingHull.getColor()
##        c = colorStr.split(',')
##        c = Color(int(c[0]), int(c[1]), int(c[2]), int(c[3]) + 70)
##        containingHull.setColor(c)

##    def mouseClickNode(self, node):
##        if node == self.currSelectedNode:
##            return
##
##        self.panel.updateNodeSelection(unit(node));
##
##        if self.prevSelectedNode != None:
##            self.prevSelectedNode.size = self.prevSelectedNode.size - 10
##            self.prevSelectedNode.color = self.prevSelectedNodeOrigColor
##
##        if self.currSelectedNode != None:
##            self.prevSelectedNode = self.currSelectedNode
##            self.prevSelectedNodeOrigColor = self.currSelectedNodeOrigColor
##
##        self.currSelectedNode = node
##        self.currSelectedNodeOrigColor = node.color
##
##        node.size = node.size + 10
##        node.color = 'gray'

       
    def getFullVarRepr(self, node):
        fullLabel = node.classname
        idx = fullLabel.find(",")
        varName = fullLabel[:idx]
        return varName

    def mouseEnterEdge(self, edge):
        n1 = edge.getNode1()
        n2 = edge.getNode2()

        self.prevN1Label = n1.label
        self.prevN2Label = n2.label

        n1.label = self.getFullVarRepr(n1)
        n2.label = self.getFullVarRepr(n2)

    def mouseLeaveEdge(self, edge):
        n1 = edge.getNode1()
        n2 = edge.getNode2()

        n1.label = self.prevN1Label
        n2.label = self.prevN2Label

    def mouseEnterNode(self, node):
        self.prevNlabel = node.label
        node.label = self.getFullVarRepr(node)

    def mouseLeaveNode(self, node):
        node.label = self.prevNlabel

    def mouseClickEdge(self, edge):
        if self.prevClicked:
            self.prevClicked.color = 'gray'
            self.prevClicked.width -= 2

        edge.color = 'red'
        edge.width += 2
        self.prevClicked = edge

        eidlist = edge.eid.split(';')
        eids = []
        for eid in eidlist:
            try:
                eid = int(eid)
                eids.append(eid)
            except:
                pass
        if len(eids)==1:
            self.panel.display_source(eids[0])
        else:
            self.panel.display_source2(eids)

    def getTitle(self):
        return self.source