cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [8/8] cayenne git commit: revert SortButtonRenderer
Date Mon, 07 Dec 2015 15:31:47 GMT
revert SortButtonRenderer


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/9baef19b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/9baef19b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/9baef19b

Branch: refs/heads/master
Commit: 9baef19b7b460aecf669a689552d15fc62eb5560
Parents: b444b1d
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Mon Dec 7 18:20:50 2015 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Mon Dec 7 18:27:13 2015 +0300

----------------------------------------------------------------------
 .../modeler/util/SortButtonRenderer.java        | 81 +++++++++++---------
 1 file changed, 46 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/9baef19b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SortButtonRenderer.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SortButtonRenderer.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SortButtonRenderer.java
index 595ba4d..beae1e7 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SortButtonRenderer.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SortButtonRenderer.java
@@ -19,32 +19,49 @@
 package org.apache.cayenne.modeler.util;
 
 import javax.swing.BorderFactory;
-import javax.swing.JLabel;
+import javax.swing.JButton;
 import javax.swing.JTable;
-import javax.swing.border.Border;
+import javax.swing.border.MatteBorder;
 import javax.swing.table.TableCellRenderer;
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.Font;
+import java.awt.Insets;
 import java.util.Hashtable;
 
-public class SortButtonRenderer extends JLabel implements TableCellRenderer {
+public class SortButtonRenderer extends JButton implements TableCellRenderer {
 
     public static final int NONE = 0;
     public static final int DOWN = 1;
     public static final int UP = 2;
 
+    private int pushedColumn;
     private Hashtable state;
-    private JLabel downLabel , upLabel;
+    private JButton downButton, upButton;
 
     public SortButtonRenderer() {
+        MatteBorder matteBorder = BorderFactory.createMatteBorder(0, 0, 1, 1, Color.gray);
+        setBorder(matteBorder);
+
+        pushedColumn = -1;
         state = new Hashtable();
 
-        downLabel = new JLabel();
-        downLabel.setIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, false));
+        setMargin(new Insets(0, 0, 0, 0));
+        setHorizontalTextPosition(CENTER);
+        setIcon(new BlankIcon());
+
+        downButton = new JButton();
+
+        downButton.setBorder(matteBorder);
+        downButton.setMargin(new Insets(0, 0, 0, 0));
+        downButton.setHorizontalTextPosition(LEFT);
+        downButton.setIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, false));
+        downButton.setPressedIcon(new BevelArrowIcon(BevelArrowIcon.DOWN, false, true));
 
-        upLabel = new JLabel();
-        upLabel.setIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, false));
+        upButton = new JButton();
+        upButton.setBorder(matteBorder);
+        upButton.setMargin(new Insets(0, 0, 0, 0));
+        upButton.setHorizontalTextPosition(LEFT);
+        upButton.setIcon(new BevelArrowIcon(BevelArrowIcon.UP, false, false));
     }
 
     public Component getTableCellRendererComponent(
@@ -54,54 +71,48 @@ public class SortButtonRenderer extends JLabel implements TableCellRenderer
{
             boolean hasFocus,
             int row,
             int column) {
-        JLabel  label = this;
-        Object obj = state.get(column);
+        JButton button = this;
+        Object obj = state.get(new Integer(column));
 
         if (obj != null) {
-            if ((Integer) obj == DOWN) {
-                label = downLabel;
-            }
-            else {
-                label = upLabel;
+            if (((Integer) obj).intValue() == DOWN) {
+                button = downButton;
+            } else {
+                button = upButton;
             }
         }
-        Border border = BorderFactory.createLineBorder(Color.GRAY, 1);
-        label.setText(' ' + ((value == null) ? "" : value.toString()));
-        label.setFont(new Font("Verdana", Font.BOLD , 13));
-        label.setHorizontalTextPosition(JLabel.LEFT);
-        label.setBorder(border);
-        label.setOpaque(true);
-        label.setBackground(new Color(204, 238, 255));
-        return label;
+        button.setText((value == null) ? "" : value.toString());
+        return button;
+    }
+
+    public void setPressedColumn(int col) {
+        pushedColumn = col;
     }
 
     public void setSelectedColumn(int col, boolean isAscOrder) {
-        if (col < 0) {
+        if (col < 0)
             return;
-        }
         Integer value = null;
         //shows the direction of ordering
         if (isAscOrder) {
-            value = DOWN;
+            value = new Integer(DOWN);
         } else {
-            value = UP;
+            value = new Integer(UP);
         }
 
         state.clear();
-        state.put(col, value);
+        state.put(new Integer(col), value);
     }
 
     public int getState(int col) {
         int retValue;
-        Object obj = state.get(col);
+        Object obj = state.get(new Integer(col));
         if (obj == null) {
             retValue = NONE;
-        }
-        else {
-            if ((Integer) obj == DOWN) {
+        } else {
+            if (((Integer) obj).intValue() == DOWN) {
                 retValue = DOWN;
-            }
-            else {
+            } else {
                 retValue = UP;
             }
         }


Mime
View raw message