Table widget: add function that getting table width
authorjihye424.kim <jihye424.kim@samsung.com>
Sun, 6 Sep 2015 01:33:00 +0000 (10:33 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Sun, 6 Sep 2015 01:33:00 +0000 (10:33 +0900)
- delete unnecessary redraw function
- change unnecessary setBounds function
  to setLocation or setSize function

Change-Id: I7e1f8db964a822c59b5a3536d3289c3c22f175c2
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/ui/table/Table.java
src/org/tizen/emulator/manager/ui/table/TableColumn.java
src/org/tizen/emulator/manager/ui/table/TableItem.java
src/org/tizen/emulator/manager/ui/table/TableItemCell.java

index dbead29..c7a0b5f 100644 (file)
@@ -83,7 +83,6 @@ public class Table extends TableScrolledComposite {
        Composite table = null;
        Composite tableItem = null;
        Composite tableColumn = null;
-       private int width = 0;
        private int tableWidth = 0;
        private int tableHeight = 0;
 
@@ -108,7 +107,6 @@ public class Table extends TableScrolledComposite {
 
                focusIndex = -1;
                sortDirection = SWT.None;
-               setTableEmpty();
 
                if ((style & SWT.CHECK) != 0) {
                        isCheck = true;
@@ -118,6 +116,8 @@ public class Table extends TableScrolledComposite {
 
                }
 
+               setTableEmpty();
+
                addListener();
        }
 
@@ -1069,10 +1069,11 @@ public class Table extends TableScrolledComposite {
                int width = Math.max(tableWidth, rect.width);
                int height = Math.max(tableHeight, rect.height);
 
-
-
                table.setSize(width, height);
-               tableColumn.setBounds(0, 0, width, 30);
+               if (rect.width == width && rect.height == height) {
+                       redraw();
+               }
+               tableColumn.setBounds(0, 0, width, columnHeight);
                tableItem.setBounds(0, columnHeight, width, height - columnHeight);
        }
 
@@ -1190,8 +1191,9 @@ public class Table extends TableScrolledComposite {
                return width;
        }
 
-       int getWidth() {
-               return width;
+       // for table item
+       int getTableWidth() {
+               return table.getSize().x;
        }
 
        public void showColumn(TableColumn column) {}
@@ -1212,12 +1214,6 @@ public class Table extends TableScrolledComposite {
                @Override
                public void controlResized(ControlEvent e) {
                        updateScrollBars(false);
-
-                       for (TableItem item : items) {
-                               if (item != null) {
-                                       item.updateSizeAndLocation(-1);
-                               }
-                       }
                }
        };
 
@@ -1226,7 +1222,6 @@ public class Table extends TableScrolledComposite {
                @Override
                public void paintControl(PaintEvent e) {
                        Rectangle rect= ((Composite)e.widget).getClientArea();
-                       width = rect.width;
 
                        GC gc = e.gc;
                        if (headerVisible) {
@@ -1247,7 +1242,6 @@ public class Table extends TableScrolledComposite {
                @Override
                public void paintControl(PaintEvent e) {
                        Rectangle rect= ((Composite)e.widget).getClientArea();
-                       width = rect.width;
 
                        GC gc = e.gc;
                        int top = 0;
index df5fbe2..d2d27d3 100644 (file)
@@ -212,7 +212,7 @@ public class TableColumn extends Canvas {
                }
 
                this.width = width;
-               setBounds(getLeft(), getBounds().y, width, parent.getColumnHeightSize());
+               setBounds(getLeft(), 0, width, parent.getColumnHeightSize());
                parent.updateScrollBars(true);
                processNextColumnsMoveEvent();
        }
@@ -440,7 +440,6 @@ public class TableColumn extends Canvas {
                                return;
                        }
 
-                       TableColumn column = (TableColumn) event.widget;
                        if (event.type == SWT.MouseEnter) {
                                isHoverState = true;
                                redraw();
@@ -450,12 +449,11 @@ public class TableColumn extends Canvas {
                                        isResizeableState = false;
                                        if (setCursor) {
                                                setCursor = false;
-                                               column.setCursor(backupCursor);
+                                               setCursor(backupCursor);
                                        }
                                }
-                               // TODO
-                               column.redraw();
-                               column.update();
+                               redraw();
+                               update();
                        } else if (event.type == SWT.MouseMove) {
                                if (!resizable) {
                                        return;
@@ -465,21 +463,20 @@ public class TableColumn extends Canvas {
                                        isResizeableState = true;
                                        if (!setCursor) {
                                                setCursor = true;
-                                               backupCursor = column.getCursor();
-                                               column.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_SIZEWE));
+                                               backupCursor = getCursor();
+                                               setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_SIZEWE));
                                        }
                                } else {
                                        isResizeableState = false;
                                        if (setCursor) {
                                                setCursor = false;
-                                               column.setCursor(backupCursor);
+                                               setCursor(backupCursor);
                                        }
                                }
 
                                if (isResizedState) {
                                        if (event.x > MIN_WIDTH) {
                                                setWidth(event.x);
-                                               redraw();
                                        }
                                }
                        }
@@ -497,13 +494,11 @@ public class TableColumn extends Canvas {
                @Override
                public void controlResized(ControlEvent e) {
                        needRedrawingText = true;
-                       parent.redraw();
                        for (TableItem item : parent.getItems()) {
                                if (item != null) {
                                        item.updateSizeAndLocation(getOrderIndex());
                                }
                        }
-                       redraw();
                }
        };
 
@@ -512,7 +507,6 @@ public class TableColumn extends Canvas {
                public void mouseDoubleClick(MouseEvent e) {
                        if (isResizeableState) {
                                setWidth(getPreferredWidth());
-                               redraw();
                        }
                }
 
index 76c292b..1c10e7b 100644 (file)
@@ -51,9 +51,10 @@ class TableItemData {
        Font font;
        Color backgroundColor;
        Color foregroundColor;
+       int textWidth = -1;
 
        // for drawing table item
-       int textWidth = -1;
+       int drawingTextWidth = 0;
        boolean needRedrawingText = true;
        String drawingText = "";
 
@@ -544,7 +545,7 @@ public class TableItem extends Canvas {
                        result = new Rectangle(0, 0, 0, 0);
                } else {
                        int left = getLeft(index);
-                       int top  = getTop(parent.indexOf(this));
+                       int top  = getTop(this.index);
                        int width = 0;
                        if (index == 0 && columnCount == 0) {
                                int spacing = getSpacing(index);
@@ -808,7 +809,7 @@ public class TableItem extends Canvas {
                if (rect.width == 0) {
                        updateSizeAndLocation(-1);
                } else {
-                       setBounds(new Rectangle(rect.x, getTop(index), rect.width, rect.height));
+                       setLocation(rect.x, getTop(index));
                }
        }
 
@@ -819,10 +820,10 @@ public class TableItem extends Canvas {
 
                int width = 0;
                for (int i = 0; i < parent.getColumnCount(); i++) {
-                       width += getBounds(i).width;
+                       width += parent.getColumn(i).getWidth();
                }
 
-               width = Math.max(width, parent.getWidth());
+               width = Math.max(width, parent.getTableWidth());
                int top = getTop(index);
                int height = getHeight();
 
index dc4d979..29f07e7 100644 (file)
@@ -80,7 +80,6 @@ class TableItemCell extends Composite {
 
                        GC gc = e.gc;
                        Rectangle rect = ((Composite)e.widget).getClientArea();
-
                        int imageX = rect.x;
                        int textX  = rect.x;
                        int imageY = rect.y;
@@ -123,7 +122,7 @@ class TableItemCell extends Composite {
                                }
                                data.needRedrawingText = false;
                                data.drawingText = drawingText;
-                               data.textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
+                               data.drawingTextWidth = TextSizeUtil.textExtent(getFont(), drawingText);
                        }
 
                        switch(item.getParent().getColumn(index).getAlignment()) {
@@ -133,14 +132,14 @@ class TableItemCell extends Composite {
                                break;
                        case SWT.RIGHT:
                                imageX += (image != null
-                                               ? rect.width - imageSize.x - data.textWidth - 10
-                                               : rect.width - data.textWidth - 10);
+                                               ? rect.width - imageSize.x - data.drawingTextWidth - 10
+                                               : rect.width - data.drawingTextWidth - 10);
                                textX += imageX + imageSize.x + 5;
                                break;
                        case SWT.CENTER:
                                imageX += (image != null
-                                               ? (rect.width - imageSize.x - data.textWidth) / 2 + 5
-                                               : (rect.width - data.textWidth) / 2) - 5;
+                                               ? (rect.width - imageSize.x - data.drawingTextWidth) / 2 + 5
+                                               : (rect.width - data.drawingTextWidth) / 2) - 5;
                                textX += imageX + imageSize.x + 5;
                                break;
                        default: