You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/08/05 21:28:11 UTC

svn commit: r801373 - in /incubator/pivot/trunk: tutorials/src/org/apache/pivot/tutorials/tables.wtkx wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java

Author: gbrown
Date: Wed Aug  5 19:28:11 2009
New Revision: 801373

URL: http://svn.apache.org/viewvc?rev=801373&view=rev
Log:
Resolve PIVOT-209.

Modified:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tables.wtkx
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tables.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tables.wtkx?rev=801373&r1=801372&r2=801373&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tables.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/tables.wtkx Wed Aug  5 19:28:11 2009
@@ -30,7 +30,8 @@
                         <ScrollPane wtkx:id="sortableScrollPane" horizontalScrollBarPolicy="fill_to_capacity"
                             preferredWidth="276" preferredHeight="160">
                             <view>
-                                <TableView wtkx:id="sortableTableView" selectMode="multi">
+                                <TableView wtkx:id="sortableTableView" selectMode="multi"
+                                    styles="{alternateRowColor:null, columnSelectionColor:11, showVerticalGridLines:false}">
                                     <columns>
                                         <TableView.Column name="i" width="48"/>
                                         <TableView.Column name="a" width="48"/>

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=801373&r1=801372&r2=801373&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java Wed Aug  5 19:28:11 2009
@@ -66,6 +66,7 @@
     private Color inactiveSelectionBackgroundColor;
     private Color highlightBackgroundColor;
     private Color alternateRowColor;
+    private Color columnSelectionColor;
     private Color gridColor;
     private boolean showHorizontalGridLines;
     private boolean showVerticalGridLines;
@@ -87,6 +88,7 @@
         inactiveSelectionBackgroundColor = theme.getColor(9);
         highlightBackgroundColor = theme.getColor(10);
         alternateRowColor = theme.getColor(11);
+        columnSelectionColor = null;
         gridColor = theme.getColor(11);
         showHorizontalGridLines = true;
         showVerticalGridLines = true;
@@ -175,11 +177,10 @@
         graphics.setPaint(backgroundColor);
         graphics.fillRect(0, 0, width, height);
 
-        // Paint the list contents
+        // Ensure that we only paint items that are visible
         int rowStart = 0;
         int rowEnd = tableData.getLength() - 1;
 
-        // Ensure that we only paint items that are visible
         Rectangle clipBounds = graphics.getClipBounds();
         if (clipBounds != null) {
             rowStart = Math.max(rowStart, (int)Math.floor(clipBounds.y
@@ -188,8 +189,43 @@
                 + clipBounds.height) / (double)rowHeight) - 1);
         }
 
+        // Paint the row backgrounds
         int rowY = rowStart * rowHeight;
 
+        if (alternateRowColor != null) {
+            for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
+                if (rowIndex % 2 > 0) {
+                    graphics.setPaint(alternateRowColor);
+                    graphics.fillRect(0, rowY, width, rowHeight);
+                }
+
+                rowY += rowHeight;
+            }
+        }
+
+        // Paint the column backgrounds
+        int columnX = 0;
+        if (columnSelectionColor != null) {
+            graphics.setColor(columnSelectionColor);
+
+            columnX = 0;
+
+            for (int columnIndex = 0, columnCount = columns.getLength();
+                columnIndex < columnCount; columnIndex++) {
+                TableView.Column column = columns.get(columnIndex);
+                int columnWidth = columnWidths.get(columnIndex);
+
+                if (column.getSortDirection() != null) {
+                    graphics.fillRect(columnX, 0, columnWidth, height);
+                }
+
+                columnX += columnWidth + 1;
+            }
+        }
+
+        // Paint the list contents
+        rowY = rowStart * rowHeight;
+
         for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
             Object rowData = tableData.get(rowIndex);
             boolean rowHighlighted = (rowIndex == highlightedIndex
@@ -197,19 +233,14 @@
             boolean rowSelected = tableView.isRowSelected(rowIndex);
             boolean rowDisabled = tableView.isRowDisabled(rowIndex);
 
+            // Paint selection state
             Color rowBackgroundColor = null;
-
             if (rowSelected) {
                 rowBackgroundColor = (tableView.isFocused())
                     ? this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
             } else {
                 if (rowHighlighted && showHighlight && !rowDisabled) {
                     rowBackgroundColor = highlightBackgroundColor;
-                } else {
-                    if (alternateRowColor != null
-                        && rowIndex % 2 > 0) {
-                        rowBackgroundColor = alternateRowColor;
-                    }
                 }
             }
 
@@ -219,7 +250,7 @@
             }
 
             // Paint the cells
-            int cellX = 0;
+            columnX = 0;
 
             for (int columnIndex = 0, columnCount = columns.getLength();
                 columnIndex < columnCount; columnIndex++) {
@@ -229,7 +260,7 @@
 
                 int columnWidth = columnWidths.get(columnIndex);
 
-                Graphics2D rendererGraphics = (Graphics2D)graphics.create(cellX, rowY,
+                Graphics2D rendererGraphics = (Graphics2D)graphics.create(columnX, rowY,
                     columnWidth, rowHeight);
 
                 cellRenderer.render(rowData, tableView, column, rowSelected,
@@ -239,7 +270,7 @@
 
                 rendererGraphics.dispose();
 
-                cellX += columnWidth + 1;
+                columnX += columnWidth + 1;
             }
 
             rowY += rowHeight;
@@ -250,14 +281,14 @@
 
         // Paint the vertical grid lines
         if (showVerticalGridLines) {
-            int gridX = 0;
+            columnX = 0;
 
             for (int columnIndex = 0, columnCount = columns.getLength();
                 columnIndex < columnCount; columnIndex++) {
-                gridX += columnWidths.get(columnIndex);
+                columnX += columnWidths.get(columnIndex);
 
-                GraphicsUtilities.drawLine(graphics, gridX, 0, height, Orientation.VERTICAL);
-                gridX++;
+                GraphicsUtilities.drawLine(graphics, columnX, 0, height, Orientation.VERTICAL);
+                columnX++;
             }
         }
 
@@ -713,6 +744,28 @@
         setAlternateRowColor(theme.getColor(alternateRowColor));
     }
 
+    public Color getColumnSelectionColor() {
+        return columnSelectionColor;
+    }
+
+    public void setColumnSelectionColor(Color columnSelectionColor) {
+        this.columnSelectionColor = columnSelectionColor;
+        repaintComponent();
+    }
+
+    public final void setColumnSelectionColor(String columnSelectionColor) {
+        if (columnSelectionColor == null) {
+            throw new IllegalArgumentException("columnSelectionColor is null.");
+        }
+
+        setColumnSelectionColor(GraphicsUtilities.decodeColor(columnSelectionColor));
+    }
+
+    public final void setColumnSelectionColor(int columnSelectionColor) {
+        TerraTheme theme = (TerraTheme)Theme.getTheme();
+        setColumnSelectionColor(theme.getColor(columnSelectionColor));
+    }
+
     public Color getGridColor() {
         return gridColor;
     }