From: jihye424.kim Date: Thu, 12 Nov 2015 10:37:44 +0000 (+0900) Subject: table: fix scroll bar of table error X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a20ff0e6fc6e79de3cf399c2dce44e05aad76336;p=sdk%2Femulator%2Femulator-manager.git table: fix scroll bar of table error - scroll bar error -- not show scroll bar when chaged table size -- not scroll to last item -- not change scroll bar location when reduced table size Change-Id: I985a1a0c5143e0b94bb4d08b7341a091d3e973c2 Signed-off-by: jihye424.kim --- diff --git a/src/org/tizen/emulator/manager/ui/table/Table.java b/src/org/tizen/emulator/manager/ui/table/Table.java index b4c86fa..1b0426e 100644 --- a/src/org/tizen/emulator/manager/ui/table/Table.java +++ b/src/org/tizen/emulator/manager/ui/table/Table.java @@ -44,7 +44,6 @@ import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; @@ -955,48 +954,6 @@ public class Table extends TableScrolledComposite { } } - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - @Override - public Point computeSize( int wHint, int hHint, boolean changed ) { - checkWidget(); - if (wHint != SWT.DEFAULT && wHint < 0) { - wHint = 0; - } - if (hHint != SWT.DEFAULT && hHint < 0) { - hHint = 0; - } - - computeTableSize(); - int width = this.tableWidth; - int height = this.tableHeight; - - if( width == 0) { - width = DEFAULT_WIDTH; - } - if(height == 0) { - height = DEFAULT_HEIGHT; - } - if(wHint > 0 && wHint > width) { - width = wHint; - } - if(hHint > 0 && hHint > height) { - height = hHint; - } - int border = getBorderWidth(); - width += border * 2; - height += border * 2; - /* - if( ( style & SWT.V_SCROLL ) != 0 ) { - width += getVerticalBar().getSize().x; - } - if( ( style & SWT.H_SCROLL ) != 0 ) { - height += getHorizontalBar().getSize().y; - } - */ - return new Point( width, height ); - } - public boolean getHeaderVisible() { checkWidget(); return headerVisible; @@ -1065,20 +1022,36 @@ public class Table extends TableScrolledComposite { computeTableSize(); } + Rectangle compRect = this.getBounds(); Rectangle tableRect = new Rectangle(0, 0, tableWidth, tableHeight); - Rectangle tableItemRect = new Rectangle(0, 0, tableWidth, tableHeight - columnHeight); - boolean vBackup = vVisible; - boolean hBackup = hVisible; + boolean vBackup = isVerticalBarVisible(); + boolean hBackup = isHorizontalBarVisible(); + hVisible = this.needHScroll(tableRect, false); - vVisible = this.needVScroll(tableItemRect, hVisible); + if (compRect.width == 0) { + hVisible = false; + } + + vVisible = this.needVScroll(tableRect, hVisible); + if (compRect.height == 0) { + vVisible = false; + } + if (vVisible) { hVisible = this.needHScroll(tableRect, vVisible); } - if (hBackup && !hVisible) { + if (!hBackup && hVisible) { + tableHeight += this.getScrollBarWidth(); + } else if (hBackup && !hVisible) { + tableHeight -= this.getScrollBarWidth(); setOrigin(0, getOrigin().y); } - if (vBackup && !vVisible) { + + if (!vBackup && vVisible) { + tableWidth += this.getScrollBarWidth(); + } else if (vBackup && !vVisible) { + tableWidth -= this.getScrollBarWidth();; setOrigin(getOrigin().x, 0); } @@ -1086,7 +1059,7 @@ public class Table extends TableScrolledComposite { } - void computeTableSize() { + private void computeTableSize() { int width = 0; for (TableColumn column : columns) { width += column.getWidth(); @@ -1105,25 +1078,19 @@ public class Table extends TableScrolledComposite { } } - void setTableSize() { + private void setTableSize() { Rectangle rect = this.getBounds(); - if (vVisible) { - tableWidth += this.getScrollBarWidth(); - } - if (hVisible) { - tableHeight += this.getScrollBarWidth(); - } - tableWidth = Math.max(tableWidth, rect.width); - tableHeight = Math.max(tableHeight, rect.height); - table.setSize(tableWidth, tableHeight); + int width = Math.max(tableWidth, rect.width); + int height = Math.max(tableHeight, rect.height); - if (tableColumn.getBounds().width != tableWidth) { - tableColumn.setBounds(0, 0, tableWidth, columnHeight); - } + table.setSize(width, height); - if (tableItem.getBounds().width != tableWidth) { - tableItem.setBounds(0, columnHeight, tableWidth, tableHeight - columnHeight); + if (tableColumn.getBounds().width != width) { + tableColumn.setBounds(0, 0, width, columnHeight); + tableItem.setBounds(0, columnHeight, width, height - columnHeight); + } else if (tableItem.getBounds().height != height) { + tableItem.setBounds(0, columnHeight, width, height - columnHeight); for (TableItem item : items) { if (item != null) { item.updateSizeAndLocation(-1); @@ -1131,7 +1098,7 @@ public class Table extends TableScrolledComposite { } } - if (rect.width == tableWidth && rect.height == tableHeight) { + if (rect.width == width && rect.height == height) { redraw(); } @@ -1139,6 +1106,8 @@ public class Table extends TableScrolledComposite { tableColumn.redraw(); tableItem.redraw(); } + + this.layout(); } public int getColumnHeightSize() { @@ -1257,7 +1226,7 @@ public class Table extends TableScrolledComposite { // for table item int getTableWidth() { - return tableWidth; + return table.getSize().x; } public void showColumn(TableColumn column) {} diff --git a/src/org/tizen/emulator/manager/ui/table/TableScrolledComposite.java b/src/org/tizen/emulator/manager/ui/table/TableScrolledComposite.java index 9fb1040..ef4c25b 100644 --- a/src/org/tizen/emulator/manager/ui/table/TableScrolledComposite.java +++ b/src/org/tizen/emulator/manager/ui/table/TableScrolledComposite.java @@ -54,6 +54,7 @@ public class TableScrolledComposite extends Composite { FlatScrollBar hBar; private int scrollBarWidth = 6; + private int tableColumnHeight = 30; public TableScrolledComposite(Composite parent, int style) { super(parent, checkStyle(style)); @@ -95,6 +96,20 @@ public class TableScrolledComposite extends Composite { }; } + public boolean isVerticalBarVisible() { + if (vBar != null) { + return vBar.isVisible(); + } + return false; + } + + public boolean isHorizontalBarVisible() { + if (hBar != null) { + return hBar.isVisible(); + } + return false; + } + private static int checkStyle (int style) { int mask = SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; return style & mask; @@ -145,11 +160,12 @@ public class TableScrolledComposite extends Composite { if (vBar != null) { vBar.setSelection(y); hBar.notifyListeners(SWT.None); - y = -vBar.getSelection(); + y = -vBar.getSelection() + tableColumnHeight; } else { y = 0; } tableContent.setLocation(x, 0); + tableItemContent.setLocation(x, y); } public void setTableItemContent(Control content) { @@ -162,11 +178,11 @@ public class TableScrolledComposite extends Composite { this.tableContent.removeListener(SWT.Resize, contentListener); this.tableContent.setBounds(new Rectangle(-200, -200, 0, 0)); } - + this.tableContent = content; if (this.tableContent != null) { - + if (vBar != null) { vBar.setMaximum (0); vBar.setThumb (0); @@ -199,14 +215,14 @@ public class TableScrolledComposite extends Composite { } boolean result = false; Rectangle hostRect = getBounds(); - //int border = getBorderWidth(); - //hostRect.height -= 2 * border; - - if(hostRect.height != contentRect.height) { - if (hVisible && hBar != null) { - hostRect.height -= hBar.getSize().y; - } - } +// int border = getBorderWidth(); +// hostRect.height -= 2 * border; +// +// if(hostRect.height != contentRect.height) { +// if (hVisible && hBar != null) { +// hostRect.height -= hBar.getSize().y; +// } +// } if (contentRect.height > hostRect.height) { result = true; @@ -216,10 +232,11 @@ public class TableScrolledComposite extends Composite { } void vScroll() { + if (tableItemContent == null) return; Point location = tableItemContent.getLocation (); int vSelection = vBar.getSelection(); - tableItemContent.setLocation (location.x, -vSelection); + tableItemContent.setLocation (location.x, -vSelection + tableColumnHeight); } boolean needHScroll(Rectangle contentRect, boolean vVisible) { @@ -229,14 +246,14 @@ public class TableScrolledComposite extends Composite { boolean result = false; Rectangle hostRect = getBounds(); - //int border = getBorderWidth(); - //hostRect.width -= 2 * border; - - if (hostRect.width != contentRect.width) { - if (vVisible && vBar != null) { - hostRect.width -= vBar.getSize().x; - } - } +// int border = getBorderWidth(); +// hostRect.width -= 2 * border; +// +// if (hostRect.width != contentRect.width) { +// if (vVisible && vBar != null) { +// hostRect.width -= vBar.getSize().x; +// } +// } if (contentRect.width > hostRect.width) { result = true; @@ -271,47 +288,6 @@ public class TableScrolledComposite extends Composite { layout(false); } - public void showControl(Control control) { - checkWidget(); - if (control == null) { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - if (control.isDisposed()) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - if (!contains(control)) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds()); - Rectangle area = getClientArea(); - Point origin = getOrigin(); - - if (itemRect.x < 0) { - origin.x = Math.max(0, origin.x + itemRect.x); - } else { - if (area.width < itemRect.x + itemRect.width) { - origin.x = Math.max(0, - origin.x + itemRect.x - + Math.min(itemRect.width, area.width) - - area.width); - } - } - - if (itemRect.y < 0) { - origin.y = Math.max(0, origin.y + itemRect.y); - } else { - if (area.height < itemRect.y + itemRect.height) { - origin.y = Math.max(0, - origin.y + itemRect.y - + Math.min(itemRect.height, area.height) - - area.height); - } - } - - setOrigin(origin); - } - public int getScrollBarWidth() { return scrollBarWidth; } @@ -319,4 +295,12 @@ public class TableScrolledComposite extends Composite { public void setScrollBarWidth(int scrollBarWidth) { this.scrollBarWidth = scrollBarWidth; } + + public int getTableColumnHeight() { + return tableColumnHeight; + } + + public void setTableColumnHeight(int tableColumnHeight) { + this.tableColumnHeight = tableColumnHeight; + } } diff --git a/src/org/tizen/emulator/manager/ui/table/TableScrolledCompositeLayout.java b/src/org/tizen/emulator/manager/ui/table/TableScrolledCompositeLayout.java index b4a01e0..810079f 100644 --- a/src/org/tizen/emulator/manager/ui/table/TableScrolledCompositeLayout.java +++ b/src/org/tizen/emulator/manager/ui/table/TableScrolledCompositeLayout.java @@ -74,7 +74,7 @@ public class TableScrolledCompositeLayout extends Layout { return; } - Rectangle hostRect = sc.getClientArea(); + Rectangle hostRect = sc.getBounds(); hBar = sc.hBar; vBar = sc.vBar; if (hBar != null) { @@ -92,18 +92,19 @@ public class TableScrolledCompositeLayout extends Layout { Rectangle tableRect = sc.tableContent.getBounds(); Rectangle tableItemRect = sc.tableItemContent.getBounds(); +// System.out.println("Layout Table Rect: " + tableRect.width + " , " + tableRect.height); +// System.out.println("Layout Table Item Rect: " + tableItemRect.width + " , " + tableItemRect.height); + boolean hVisible = sc.needHScroll(tableRect, false); - boolean vVisible = sc.needVScroll(tableItemRect, hVisible); + boolean vVisible = sc.needVScroll(tableRect, hVisible); + int scrollBarWidth = sc.getScrollBarWidth(); - if (!hVisible && vVisible) { - hVisible = sc.needHScroll(tableRect, vVisible); - } if (hBar != null) { hBar.setVisible(hVisible); if (hVisible) { hBar.setBounds(0, hostRect.height-scrollBarWidth, - hostRect.width, scrollBarWidth); + (vVisible ? hostRect.width -2 - 6 : hostRect.width - 2) , scrollBarWidth); } else { hBar.setBounds(0, 0, 0, 0); } @@ -113,20 +114,16 @@ public class TableScrolledCompositeLayout extends Layout { if (vVisible) { // 30 is table column height vBar.setBounds(hostRect.width - scrollBarWidth, 30, scrollBarWidth, - (hVisible ? hostRect.height - 30 - scrollBarWidth - : hostRect.height - 30)); + hostRect.height - 30 - 2); } else { vBar.setBounds(0, 0, 0, 0); } } -// boolean isChangeTableRect = false; -// boolean isChangeTableItemRect = false; GC gc = new GC (sc); if (hBar != null && hBar.isVisible()) { int hPage = tableRect.width - hostRect.width; - hBar.setMaximum(hPage); - hBar.setIncrementButtonLength(6); + hBar.setMaximum(hPage + 12); hBar.setIncrement(gc.getFontMetrics().getAverageCharWidth()); hBar.setPageIncrement(hostRect.width / 2); int hSelection = hBar.getSelection (); @@ -141,10 +138,8 @@ public class TableScrolledCompositeLayout extends Layout { // using tableItemRect if (vBar != null && vBar.isVisible()) { - int vPage = tableItemRect.height - hostRect.height; - vBar.setMaximum(vPage); - //vBar.setIncrement(30); - vBar.setIncrementButtonLength(6); + int vPage = tableRect.height - hostRect.height; + vBar.setMaximum(vPage + 12); vBar.setPageIncrement(hostRect.height / 2); int vSelection = vBar.getSelection (); if (vSelection >= vPage) { @@ -152,8 +147,7 @@ public class TableScrolledCompositeLayout extends Layout { vSelection = 0; vBar.setSelection(0); } - //tableRect.y = -vSelection; - tableItemRect.y = -vSelection; + tableItemRect.y = -vSelection + sc.getTableColumnHeight(); } } @@ -161,6 +155,7 @@ public class TableScrolledCompositeLayout extends Layout { sc.tableContent.setBounds(tableRect); sc.tableItemContent.setBounds(tableItemRect); + inLayout = false; }