Exemplo n.º 1
0
class SourceCellRenderer(TreeCellRenderer):
    def __init__(self,tree,mapContext):
        self.tree = tree
        self.mapContext = mapContext
        ## Group
        self.lblFolder = JLabel()
        self.lblFolder.setBackground(Color(222,227,233)) #.BLUE.brighter())
        self.lblFolder.setOpaque(True)
        self.lblFolder.setText("plddddddddddddddddddddddddddddddddddddddddddddddddddddddd")
        
        ### Folder
        self.pnlFolder = JPanel()
        self.pnlFolder.setOpaque(False)
        self.pnlFolder.setLayout(FlowLayout(FlowLayout.LEFT))
        self.lblGroup = JLabel()
        #self.lblGroup.setBackground(Color(222,227,233)) #.BLUE.brighter())
        #self.lblGroup.setOpaque(True)
        self.lblGroup.setText("plddddddddddddddddddddddddddddddddddddddddddddddddddddddd")
        self.lblGroupPreferredSize = self.lblGroup.getPreferredSize()
        self.lblGroupIcon = JLabel()
        self.pnlFolder.add(self.lblGroupIcon)
        self.pnlFolder.add(self.lblGroup)
        #self.lblGroup.setBorder(
        #  BorderFactory.createLineBorder(Color(222,227,233).darker(),1)
        #)
        #self.lblGroupPreferredSize.setSize(30,200)#self.lblGroupPreferredSize.getHeight()+4, self.lblGroupPreferredSize.getWidth())
        
        ### LAYER
        self.pnlLayer = JPanel()
        self.pnlLayer.setOpaque(False)
        #self.pnlLayer.setBorder(EmptyBorder(2,2,2,2))

        self.pnlLayer.setLayout(FlowLayout(FlowLayout.LEFT))
        self.chkLayerVisibility = JCheckBox()
        self.chkLayerVisibility.setOpaque(False)
        self.pnlLayer.add(self.chkLayerVisibility)
        self.lblLayerIcon = JLabel()
        self.lblLayerName = JLabel()
        self.pnlLayer.add(self.lblLayerIcon)
        self.pnlLayer.add(self.lblLayerName)
        #self.tree.setRowHeight(int(self.pnlLayer.getPreferredSize().getHeight())) #+2
        self.tree.setRowHeight(int(self.pnlFolder.getPreferredSize().getHeight()))
        
        self.lblUnknown = JLabel()
        
    def getTreeCellRendererComponent(self, tree, value, selected, expanded, leaf, row, hasFocus):
        uo = value.getUserObject()
        if isinstance(uo, DataFolder):
            #self.lblFolder.setText(uo.getName())
            text = "[" + str(value.getChildCount()) +"] " + uo.getName()
            self.lblFolder.setText(text)
            self.lblFolder.setPreferredSize(self.lblGroupPreferredSize)
            if uo.getIcon()!=None:
                self.lblGroupIcon.setIcon(uo.getIcon())
            else:
                self.lblGroupIcon.setIcon(getIconByName("librarybrowser-folder")) #icon-folder-open"))
            
            return self.lblFolder
        if isinstance(uo, DataGroup):
            self.lblGroup.setText(uo.getName())
            self.lblGroup.setPreferredSize(self.lblGroupPreferredSize)
            if uo.getIcon()!=None:
                self.lblGroupIcon.setIcon(uo.getIcon())
            else:
                #import pdb
                #pdb.set_trace()
                self.lblGroupIcon.setIcon(getIconByName("librarybrowser-folder")) #icon-folder-open"))
            
            return self.pnlFolder
        if isinstance(uo, DataLayer):
            layer = uo.getLayer()
            self.lblLayerName.setText(layer.getName())
            self.lblLayerIcon.setIcon(getIconFromLayer(layer))
            self.chkLayerVisibility.setSelected(layer.isVisible())
            if layer.isWithinScale(self.mapContext.getScaleView()): # and layer.isVisible():
                self.chkLayerVisibility.setEnabled(True)
            else:
                self.chkLayerVisibility.setEnabled(False)

                            
            self.lblLayerName.setForeground(Color.BLACK)
            
            font = self.lblLayerName.getFont()
            self.lblLayerName.setForeground(Color.BLACK)
            if layer.isEditing():
                self.lblLayerName.setForeground(Color.RED)
            if layer.isActive() and font.isBold():
                pass
            elif layer.isActive() and not font.isBold():
                newfont = font.deriveFont(Font.BOLD)
                self.lblLayerName.setFont(newfont)
            else:
                newfont = font.deriveFont(Font.PLAIN)
                self.lblLayerName.setFont(newfont)
            #self.pnlLayer.repaint()
            return self.pnlLayer
        self.lblUnknown.setText("")
        self.lblUnknown.setPreferredSize(Dimension(0,0))

        return self.lblUnknown
Exemplo n.º 2
0
class SelectionCellRenderer(TreeCellRenderer):
    def __init__(self, tree, mapContext):
        self.tree = tree
        self.mapContext = mapContext
        self.lblGroup = JLabel()
        self.lblGroup.setBackground(Color(222, 227, 233))  #.BLUE.brighter())
        self.lblGroup.setOpaque(True)
        self.lblGroup.setText(
            "plddddddddddddddddddddddddddddddddddddddddddddddddddddddd")

        self.lblGroupPreferredSize = self.lblGroup.getPreferredSize()
        #h = self.lblGroupPreferredSize.getHeight()
        #w = self.lblGroupPreferredSize.getWidth()
        #self.lblGroupPreferredSize.setSize(h, w)
        self.pnlLayer = JPanel()
        self.pnlLayer.setOpaque(False)

        self.pnlLayer.setLayout(FlowLayout(FlowLayout.LEFT))

        self.lblClean = JLabel()

        self.chkLayerVisibility = JCheckBox()
        self.chkLayerVisibility.setOpaque(False)
        self.lblLayerName = JLabel()
        self.lblLayerIcon = JLabel()
        self.lblFeatureSelecteds = JLabel()

        self.pnlLayer.add(self.chkLayerVisibility)
        self.pnlLayer.add(self.lblClean)
        self.pnlLayer.add(self.lblFeatureSelecteds)
        self.pnlLayer.add(self.lblLayerIcon)
        self.pnlLayer.add(self.lblLayerName)
        self.tree.setRowHeight(
            int(self.pnlLayer.getPreferredSize().getHeight()) - 3)
        self.lblUnknown = JLabel()

        ## Feature
        self.lblFeatureIcon = JLabel()
        self.lblFeatureName = JLabel()
        i18n = ToolsLocator.getI18nManager()
        self.lblFeatureName.setText(i18n.getTranslation("_Feature"))
        self.pnlFeature = JPanel()
        self.pnlFeature.setOpaque(False)
        self.pnlFeature.setLayout(FlowLayout(FlowLayout.LEFT))
        self.pnlFeature.add(self.lblFeatureIcon)
        self.pnlFeature.add(self.lblFeatureName)

    def getTreeCellRendererComponent(self, tree, value, selected, expanded,
                                     leaf, row, hasFocus):
        uo = value.getUserObject()
        if isinstance(uo, DataGroup):
            text = "[" + str(value.getChildCount()) + "] " + uo.getName()
            self.lblGroup.setText(text)
            self.lblGroup.setPreferredSize(self.lblGroupPreferredSize)
            return self.lblGroup
        if isinstance(uo, DataLayer):
            layer = uo.getLayer()

            self.lblLayerName.setText(uo.getName())
            self.lblLayerIcon.setIcon(getIconFromLayer(layer))
            if layer.isVisible():
                self.lblLayerName.setEnabled(True)
            else:
                self.lblLayerName.setEnabled(False)
            self.lblClean.setIcon(getIconByName("edit-clear"))
            self.chkLayerVisibility.setSelected(layer.isVisible())
            if layer.isWithinScale(
                    self.mapContext.getScaleView()):  # and layer.isVisible():
                self.chkLayerVisibility.setEnabled(True)
            else:
                self.chkLayerVisibility.setEnabled(False)
            if layer.getDataStore() != None and layer.getDataStore(
            ).getSelection() != None and layer.getDataStore().getSelection(
            ).getSize() != 0:  # and layer.isVisible():
                self.lblClean.setEnabled(True)
                self.lblFeatureSelecteds.setText(
                    str(layer.getDataStore().getSelection().getSize()))
                self.lblFeatureSelecteds.setEnabled(True)
            else:
                self.lblClean.setEnabled(False)
                self.lblFeatureSelecteds.setText("0")
                self.lblFeatureSelecteds.setEnabled(False)

            font = self.lblLayerName.getFont()
            self.lblLayerName.setForeground(Color.BLACK)
            if layer.isEditing():
                self.lblLayerName.setForeground(Color.RED)
            #if layer.isActive():
            if layer.isActive():  # and not font.isBold():
                newfont = font.deriveFont(Font.BOLD)
                self.lblLayerName.setFont(newfont)
            else:
                newfont = font.deriveFont(Font.PLAIN)
                self.lblLayerName.setFont(newfont)

            return self.pnlLayer
        if isinstance(uo, FeatureDataLayerNode):
            self.lblFeatureName.setText(uo.getFeature().toString())
            self.lblFeatureIcon.setIcon(getIconByName("edit-clear"))

            return self.pnlFeature
        self.lblUnknown.setText("")
        self.lblUnknown.setPreferredSize(Dimension(0, 0))
        return self.lblUnknown