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;
}
}
- 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;
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);
}
}
- void computeTableSize() {
+ private void computeTableSize() {
int width = 0;
for (TableColumn column : columns) {
width += column.getWidth();
}
}
- 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);
}
}
- if (rect.width == tableWidth && rect.height == tableHeight) {
+ if (rect.width == width && rect.height == height) {
redraw();
}
tableColumn.redraw();
tableItem.redraw();
}
+
+ this.layout();
}
public int getColumnHeightSize() {
// for table item
int getTableWidth() {
- return tableWidth;
+ return table.getSize().x;
}
public void showColumn(TableColumn column) {}
FlatScrollBar hBar;
private int scrollBarWidth = 6;
+ private int tableColumnHeight = 30;
public TableScrolledComposite(Composite parent, int style) {
super(parent, checkStyle(style));
};
}
+ 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;
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) {
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);
}
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;
}
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) {
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;
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;
}
public void setScrollBarWidth(int scrollBarWidth) {
this.scrollBarWidth = scrollBarWidth;
}
+
+ public int getTableColumnHeight() {
+ return tableColumnHeight;
+ }
+
+ public void setTableColumnHeight(int tableColumnHeight) {
+ this.tableColumnHeight = tableColumnHeight;
+ }
}
return;
}
- Rectangle hostRect = sc.getClientArea();
+ Rectangle hostRect = sc.getBounds();
hBar = sc.hBar;
vBar = sc.vBar;
if (hBar != null) {
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);
}
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 ();
// 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) {
vSelection = 0;
vBar.setSelection(0);
}
- //tableRect.y = -vSelection;
- tableItemRect.y = -vSelection;
+ tableItemRect.y = -vSelection + sc.getTableColumnHeight();
}
}
sc.tableContent.setBounds(tableRect);
sc.tableItemContent.setBounds(tableItemRect);
+
inLayout = false;
}