Exemplo n.º 1
0
 def __init__(self):
     nf = NumberFormat.getInstance()
     nf.setMinimumFractionDigits(2)
     nf.setMaximumFractionDigits(2)
     self.result = JFormattedTextField(nf,
                                       border=None,
                                       horizontalAlignment=JTextField.RIGHT)
     self.DTCR = DefaultTableCellRenderer()
Exemplo n.º 2
0
 def _prepare_cell_renderers(self):
     default_cell_renderer = DefaultTableCellRenderer()
     default_cell_renderer.setHorizontalAlignment(JLabel.LEFT)
     for column_name, column in self._get_columns():
         cell_renderer = self._create_cell_renderer(column_name)
         if cell_renderer is None:
             cell_renderer = default_cell_renderer
         column.setCellRenderer(cell_renderer)
 def __init__(self, *args, **kwargs):
     font, fontsize, style = "SansSerif", 12, Font.PLAIN
     if 'fontsize' in kwargs:
         fontsize = kwargs.pop('fontsize')
     if 'style' in kwargs:
         style = kwargs.pop('style')
     if 'font' in kwargs:
         font = kwargs.pop('font')
     DefaultTableCellRenderer.__init__(self, *args, **kwargs)
     self.font_ = Font(font, style, fontsize)
Exemplo n.º 4
0
class sRenderer( DefaultTableCellRenderer ) :

    #---------------------------------------------------------------------------
    # Name: __init__()
    # Role: Constructor
    #---------------------------------------------------------------------------
    def __init__( self ) :
        self.DTCR    = DefaultTableCellRenderer()
        self.spinner = JSpinner( SpinnerListModel( choices ) )

    #---------------------------------------------------------------------------
    # Name: getTableCellRendererComponent()
    # Role: Return the component containing the rendered value
    # Note: Called frequently, don't create a new component each time
    #---------------------------------------------------------------------------
    def getTableCellRendererComponent(
        self,
        table,               # table containing cell being rendered
        value,               # Object  - value being rendered
        isSelected,          # boolean - Is value selected?
        hasFocus,            # boolean - Does this cell have focus?
        row,                 # int     - Row # (0..N)
        col                  # int     - Col # (0..N)
    ) :
        comp = self.DTCR.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, col
        )
#       print '[ %d, %d ] : %s on %s' % ( row, col, comp.getForeground(), comp.getBackground() )
        tf = self.spinner.getEditor().getTextField()
        tf.setForeground( comp.getForeground() )
        tf.setBackground( comp.getBackground() )
        self.spinner.setValue( value )
        return self.spinner
Exemplo n.º 5
0
    def getTableCellRendererComponent(self, table, value, isSelected, hasFocus, rowIndex, columnIndex):
        """
        Gets the JComponent for each cell.

        Args:
            table: the table this rendering process corresponds to.
            value: the value of the cell
            isSelected: true if the cell is to be rendered with the selection highlighted; otherwise false
            hasFocus: if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
            rowIndex: the rowIndex for this cell
            columnIndex: the columnIndex for this cell.
        """
        comp = DefaultTableCellRenderer.getTableCellRendererComponent(self, table, value, isSelected, hasFocus, rowIndex, columnIndex)

        modelRow = table.convertRowIndexToModel(rowIndex)

        percentSameStatus = table.model.getValueAt(modelRow, 3)
        percentSameLength = table.model.getValueAt(modelRow, 4)
        hasId = table.model.getValueAt(modelRow, 5)

        idorModeActive = len(self.state.replacementRuleTableModel.rules) > 0

        if (percentSameStatus == 100.0 and percentSameLength == 100.0 and hasId) and idorModeActive:
            if not isSelected:
                comp.setBackground(Color.GREEN)
        else:
            if not isSelected:
                comp.setBackground(Color.WHITE)

        return comp
Exemplo n.º 6
0
 def getTableCellRendererComponent(self, table, value, isSelected, hasFocus,
                                   row, column):
     x = DefaultTableCellRenderer.getTableCellRendererComponent(
         self, table, value, isSelected, hasFocus, row, column)
     for availableValue in self.__availableValues:
         if value == availableValue.getValue():
             x.setText(availableValue.getLabel())
             break
     return x
Exemplo n.º 7
0
 def getTableCellRendererComponent(self, table, value, isSelected,
                                   hasFocus, row, col):
     c = DefaultTableCellRenderer.getTableCellRendererComponent(
         self, table, value, isSelected, hasFocus, row, col)
     if col == 1 and value.startswith("{{") and value.endswith("}}"):
         c.setForeground(Color.RED)
     elif col == 1 and value.startswith("** ") and value.endswith(
             " **"):
         c.setForeground(Color.ORANGE)
     else:
         c.setForeground(table.getForeground())
     return self
Exemplo n.º 8
0
        def getCellRenderer(self, row, column):
	    import javax.swing.table.DefaultTableCellRenderer as DefaultTableCellRenderer
	    import javax.swing.JLabel as JLabel
	    global AAA 
            renderer = None
            if AAA.columnTypes[column]=="Text":
                renderer = DefaultTableCellRenderer()
                renderer.setHorizontalAlignment(JLabel.LEFT)
            elif AAA.columnTypes[column]=="Currency2" or AAA.columnTypes[column]=="Currency0":
	        rowCurrencies = self.getDataModel().getRowCurrencies()
	        curr = None
                if 0 <= row and row < len(rowCurrencies):
                    curr = AAA.rowCurrencies.get(row)
                else:
                    curr = self.book.getCurrencies().getBaseType() # Footer reports base currency
                renderer = AAA.CurrencyRenderer(curr, AAA.columnTypes[column] == "Currency0")
                renderer.setHorizontalAlignment(JLabel.RIGHT)
            elif AAA.columnTypes[column]=="Percent":
                renderer = AAA.PercentRenderer()
                renderer.setHorizontalAlignment(JLabel.RIGHT)
            else:
                renderer = DefaultTableCellRenderer()
            return renderer
Exemplo n.º 9
0
    def getTableCellRendererComponent(
            self, table, value, isSelected, hasFocus, row, column):

        renderer = DefaultTableCellRenderer.getTableCellRendererComponent(
                self, table, value, isSelected, hasFocus, row, column)

        value = table.getValueAt(row, column)
        model = table.getModel()
        rowsCount = model.getRowCount()
        if rowsCount == 1:
            renderer.setBackground(table.getBackground())
            renderer.setForeground(table.getForeground())
        else:
            colValues = []
            for index in xrange(rowsCount):
                valueAtIndex = model.getValueAt(index, column)
                colValues.append(valueAtIndex)
            minBound = min(colValues)
            maxBound = max(colValues)
            if minBound != maxBound:
                valueAsFraction = (
                    float(value - minBound) / (maxBound - minBound))
                if valueAsFraction > 0.75:
                    renderer.setForeground(Color.WHITE)
                else:
                    renderer.setForeground(Color.BLACK)
                if valueAsFraction > 0.5:
                    red = 1.0
                else:
                    red = (valueAsFraction * 2.0)
                if valueAsFraction < 0.5:
                    green = 1.0
                else:
                    green = 2 - (valueAsFraction * 2.0)
                blue = 111/256.0

                if isSelected:
                    red = max(0.0, red-0.25)
                    green = max(0.0, green-0.25)
                    blue = max(0.0, blue-0.25)

                renderer.setBackground(Color(red, green, blue))
        return renderer
Exemplo n.º 10
0
class myRenderer(DefaultTableCellRenderer):

    #---------------------------------------------------------------------------
    # Name: __init__()
    # Role: Constructor - instantiate the JFormattedTextField to be used
    #---------------------------------------------------------------------------
    def __init__(self):
        nf = NumberFormat.getInstance()
        nf.setMinimumFractionDigits(2)
        nf.setMaximumFractionDigits(2)
        self.result = JFormattedTextField(nf,
                                          border=None,
                                          horizontalAlignment=JTextField.RIGHT)
        self.DTCR = DefaultTableCellRenderer()

    #---------------------------------------------------------------------------
    # Name: getTableCellRendererComponent()
    # Role: Return the component containing the rendered value
    # Note: Called frequently, don't create a new component each time
    #---------------------------------------------------------------------------
    def getTableCellRendererComponent(
            self,
            table,  # JTable  - table containing value
            value,  # Object  - value being rendered
            isSelected,  # boolean - Is value selected?
            hasFocus,  # boolean - Does this cell have focus?
            row,  # int     - Row # (0..N)
            col  # int     - Col # (0..N)
    ):
        comp = self.DTCR.getTableCellRendererComponent(table, value,
                                                       isSelected, hasFocus,
                                                       row, col)
        result = self.result
        result.setForeground(comp.getForeground())
        result.setBackground(comp.getBackground())
        result.setBorder(comp.getBorder())
        result.setValue(value)
        return result
Exemplo n.º 11
0
 def __init__(self):
     DefaultTableCellRenderer.__init__(self)
     self.spinner = JSpinner(SpinnerListModel(choices))
 def getTableCellRendererComponent(self, table, val, isSel, hasFoc, row,
                                   column):
     c = DefaultTableCellRenderer.getTableCellRendererComponent(
         self, table, val, isSel, hasFoc, row, column)
     c.setFont(self.font_)
     return c
Exemplo n.º 13
0
    def getTableCellRendererComponent(
            self,
            table,  # JTable  - table containing value
            value,  # Object  - value being rendered
            isSelected,  # boolean - Is value selected?
            hasFocus,  # boolean - Does this cell have focus?
            row,  # int     - Row # ( 0 .. N-1 )
            col  # int     - Col # ( 0 .. N-1 )
    ):
        #-----------------------------------------------------------------------
        # Start by retrieving the default renderer component (i.e., JLabel)
        #-----------------------------------------------------------------------
        comp = DefaultTableCellRenderer.getTableCellRendererComponent(
            self, table, value, isSelected, hasFocus, row, col)
        #-----------------------------------------------------------------------
        # The first time we encounter the foreground & background colors for the
        # JLabel being used to display table cells (based upon isSelected), we
        # we need to save these colors.
        # Note: This is not the only way that this could have been done.
        #-----------------------------------------------------------------------
        if not self.bg[isSelected]:
            self.bg[isSelected] = comp.getBackground()
            self.fg[isSelected] = comp.getForeground()

        #-----------------------------------------------------------------------
        # Set the section heading row colors differently
        #-----------------------------------------------------------------------
        if table.getValueAt(row, 0).startswith('_'):
            if isSelected:
                comp.setBackground(Color.yellow)
                comp.setForeground(Color.blue)
            else:
                comp.setBackground(Color.blue)
                comp.setForeground(Color.white)
            comp.setFont(boldFont)
            metrics = fmBold
        else:
            comp.setBackground(self.bg[isSelected])
            comp.setForeground(self.fg[isSelected])
            comp.setFont(plainFont)
            metrics = fmPlain

        if value:
            if col == 0 and value.startswith('_'):
                value = value[1:]
            tcm = table.getColumnModel()  # Table Column Model
            width = tcm.getColumn(col).getWidth()
            height = table.getRowHeight(row)  # Cell height

            result, here, nl = '', '', ''
            offset = done = 0

            while not done:
                if metrics.stringWidth(here + value[offset]) < width:
                    here += value[offset]
                    offset += 1
                else:
                    result += nl + here
                    here, nl = '', '\n'
                done = offset == len(value)

            result = (result + nl + here)
            lines = result.count('\n') + 1
            rHeight = lines * table.getRowHeight()
            if rHeight > height:
                table.setRowHeight(row, rHeight)
            result = result.replace('>', '&gt;').replace('\n', '<br>')
            findText = table.getModel().getFindText()
            if findText:
                if result.find(findText) > -1:
                    result = result.replace(
                        findText,
                        '<font bgcolor="green" color="yellow">%s</font>' %
                        findText)
            value = '<html>' + result.replace(' ', '&nbsp;')

        comp.setText(value)
        return comp
Exemplo n.º 14
0
 def __init__(self):
     DefaultTableCellRenderer.__init__(self)
     self.comboBox = JComboBox(choices)
Exemplo n.º 15
0
 def __init__(self, availableValues):
     DefaultTableCellRenderer.__init__(self)
     self.__availableValues = availableValues
Exemplo n.º 16
0
    def getTableCellRendererComponent(
            self,
            table,  # JTable  - table containing value
            value,  # Object  - value being rendered
            isSelected,  # boolean - Is value selected?
            hasFocus,  # boolean - Does this cell have focus?
            row,  # int     - Row # ( 0 .. N-1 )
            col  # int     - Col # ( 0 .. N-1 )
    ):
        #-----------------------------------------------------------------------
        # Name: camelWords()
        # Role: Return a list of words in the specified camelCase text
        #-----------------------------------------------------------------------
        def camelWords(name):
            prev, result = 0, []
            for i in range(len(name)):
                ch = name[i]
                if ch == ch.upper() or ch == '_':
                    result.append(name[prev:i])
                    prev = i
            result.append(name[prev:])
            return result

        #-----------------------------------------------------------------------
        # Start by retrieving the default renderer component (i.e., JLabel)
        #-----------------------------------------------------------------------
        comp = DefaultTableCellRenderer.getTableCellRendererComponent(
            self, table, value, isSelected, hasFocus, row, col)
        pWidth = self.widths[col]  # Preferred column width
        if pWidth:  # Has it been set?
            #-------------------------------------------------------------------
            # Adjust the preferred width to keep ellipses from being displayed
            #-------------------------------------------------------------------
            pWidth -= 3
            if self.fm.stringWidth(value) > pWidth:
                if col:
                    pad, words = ' ', value.split(' ')
                else:
                    pad, words = '', camelWords(value)
                result, curr = '<html>', ''
                for word in words:
                    if self.fm.stringWidth(curr + pad + word) > pWidth:
                        result += curr + '<br>'
                        curr = ''
                    if curr:
                        curr += pad + word
                    else:
                        curr = word
                result += curr
                if self.hiText:
                    if value.count(self.hiText) > 0:
                        result = result.replace(
                            self.hiText,
                            '<font bgcolor=yellow>%s</font>' % self.hiText)
                comp.setText(result)
            else:
                if self.hiText:
                    if value.count(self.hiText) > 0:
                        value = value.replace(
                            self.hiText,
                            '<font bgcolor=yellow>%s</font>' % self.hiText)
                    comp.setText('<html>' + value)
        return comp