--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.table;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import com.codeaffine.eclipse.swt.widget.scrollbar.FlatScrollBar;
+
+public class CustomScrolledComposite extends Composite {
+ Control content;
+ Listener contentListener;
+ Listener filter;
+
+ int minHeight = 0;
+ int minWidth = 0;
+ boolean expandHorizontal = false;
+ boolean expandVertical = false;
+ boolean showFocusedControl = false;
+ boolean showNextFocusedControl = true;
+
+ FlatScrollBar vBar;
+ FlatScrollBar hBar;
+
+ int scrollBarWidth = 6;
+
+ public CustomScrolledComposite(Composite parent, int style) {
+ super(parent, checkStyle(style));
+ super.setLayout(new CustomScrolledCompositeLayout());
+
+ if ((style & SWT.VERTICAL) != 0) {
+ vBar = new FlatScrollBar(this, SWT.VERTICAL);
+ if (vBar != null) {
+ vBar.setVisible(false);
+ vBar.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ vScroll();
+ }
+ });
+ }
+ }
+
+ if ((style & SWT.HORIZONTAL) != 0) {
+ hBar = new FlatScrollBar(this, SWT.HORIZONTAL);
+ if (hBar != null) {
+ hBar.setVisible(false);
+ hBar.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ hScroll();
+ }
+ });
+ }
+ }
+
+ contentListener = new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Resize) {
+ layout(false);
+ }
+ }
+ };
+
+ filter = new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.FocusIn) {
+ if (!showNextFocusedControl) {
+ showNextFocusedControl = true;
+ } else if (event.widget instanceof Control) {
+ Control control = (Control) event.widget;
+ if (contains(control)) {
+ showControl(control);
+ }
+ }
+ } else {
+ if (event.widget instanceof Control) {
+ Control control = (Control) event.widget;
+ showNextFocusedControl = control.getDisplay().getActiveShell()
+ == control.getShell();
+ }
+ }
+ }
+ };
+
+ addDisposeListener(new DisposeListener(){
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ getDisplay().removeFilter(SWT.FocusIn, filter);
+ getDisplay().removeFilter(SWT.FocusOut, filter);
+ }
+
+ });
+ }
+
+ static int checkStyle (int style) {
+ int mask = SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
+ return style & mask;
+ }
+
+ boolean contains(Control control) {
+ if (control == null || control.isDisposed()) {
+ return false;
+ }
+
+ Composite parent = control.getParent();
+ while (parent != null && !(parent instanceof Shell)) {
+ if (this == parent) return true;
+ parent = parent.getParent();
+ }
+
+ return false;
+ }
+
+ public Control getContent() {
+ return content;
+ }
+
+ public Point getOrigin() {
+ checkWidget();
+ if (content == null) {
+ return new Point(0, 0);
+ }
+ Point location = content.getLocation();
+ return new Point(-location.x, -location.y);
+ }
+
+ public void setOrigin(Point origin) {
+ setOrigin(origin.x, origin.y);
+ }
+
+ public void setOrigin(int x, int y) {
+ checkWidget();
+ if (content == null) return;
+ if (hBar != null) {
+ hBar.setSelection(x);
+ hBar.notifyListeners(SWT.None);
+ x = -hBar.getSelection();
+ } else {
+ x = 0;
+ }
+
+ if (vBar != null) {
+ vBar.setSelection(y);
+ hBar.notifyListeners(SWT.None);
+ y = -vBar.getSelection();
+ } else {
+ y = 0;
+ }
+ content.setLocation(x, y);
+ }
+
+ public void setContent(Control content) {
+ checkWidget();
+ if (this.content != null && !this.content.isDisposed()) {
+ this.content.removeListener(SWT.Resize, contentListener);
+ this.content.setBounds(new Rectangle(-200, -200, 0, 0));
+ }
+
+ this.content = content;
+
+ if (this.content != null) {
+
+ if (vBar != null) {
+ vBar.setMaximum (0);
+ vBar.setThumb (0);
+ vBar.setSelection(0);
+ vBar.notifyListeners(SWT.None);
+ }
+ if (hBar != null) {
+ hBar.setMaximum (0);
+ hBar.setThumb (0);
+ hBar.setSelection(0);
+ hBar.notifyListeners(SWT.None);
+ }
+ //content.setLocation(0, 0);
+ layout(false);
+ this.content.addListener(SWT.Resize, contentListener);
+ } else {
+ if (hBar != null) {
+ hBar.setVisible(false);
+ }
+ if (vBar != null) {
+ vBar.setVisible(false);
+ }
+ }
+ }
+
+ boolean needVScroll(Rectangle contentRect, boolean hVisible) {
+ if (vBar == null) {
+ return false;
+ }
+ boolean result = false;
+ Rectangle hostRect = getBounds();
+ int border = getBorderWidth();
+ hostRect.height -= 2*border;
+
+ if (contentRect.height != hostRect.height) {
+ if (hVisible && hBar != null) {
+ hostRect.height -= hBar.getSize().y;
+ }
+ }
+
+ if (!expandVertical && contentRect.height > hostRect.height) {
+ result = true;
+ }
+ if (expandVertical && minHeight > hostRect.height) {
+ result = true;
+ }
+
+ if (result) {
+ vBar.setBounds(hostRect.width - 6, 0, 6, hostRect.height);
+ } else {
+ vBar.setBounds(0, 0, 0, 0);
+ }
+
+ return result;
+ }
+
+ void vScroll() {
+ if (content == null) return;
+ Point location = content.getLocation ();
+ int vSelection = vBar.getSelection();
+ content.setLocation (location.x, -vSelection);
+ }
+
+ boolean needHScroll(Rectangle contentRect, boolean vVisible) {
+ if (hBar == null) {
+ return false;
+ }
+
+ boolean result = false;
+ Rectangle hostRect = getBounds();
+ int border = getBorderWidth();
+ hostRect.width -= 2*border;
+
+ if (contentRect.width != hostRect.width) {
+ if (vVisible && vBar != null) {
+ hostRect.width -= vBar.getSize().x;
+ }
+ }
+
+ if (!expandHorizontal && contentRect.width > hostRect.width) {
+ result = true;
+ }
+ if (expandHorizontal && minWidth > hostRect.width) {
+ result = true;
+ }
+
+ if (result) {
+ hBar.setBounds(0, hostRect.height-6, hostRect.width, 6);
+ } else {
+ hBar.setBounds(0, 0, 0, 0);
+ }
+ return result;
+ }
+
+ void hScroll() {
+ if (content == null) return;
+ Point location = content.getLocation ();
+ int hSelection = hBar.getSelection();
+ content.setLocation (-hSelection, location.y);
+ }
+
+ public void setMinSize(Point size) {
+ if (size == null) {
+ setMinSize(0, 0);
+ } else {
+ setMinSize(size.x, size.y);
+ }
+ }
+
+ public void setMinSize(int width, int height) {
+ checkWidget();
+ if (width == minWidth && height == minHeight) {
+ return;
+ }
+
+ minWidth = Math.max(0, width);
+ minHeight = Math.max(0, height);
+ layout(false);
+ }
+
+ public void setShowFocusedControl(boolean show) {
+ checkWidget();
+ if (showFocusedControl == show) {
+ return;
+ }
+
+ Display display = getDisplay();
+ display.removeFilter(SWT.FocusIn, filter);
+ display.removeFilter(SWT.FocusOut, filter);
+
+ showFocusedControl = show;
+ if (showFocusedControl) {
+ display.addFilter(SWT.FocusIn, filter);
+ display.addFilter(SWT.FocusOut, filter);
+ }
+
+ Control control = display.getFocusControl();
+ if (contains(control)) {
+ showControl(control);
+ }
+ }
+
+ 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 boolean getExpandHorizontal() {
+ checkWidget();
+ return expandHorizontal;
+ }
+
+ public boolean getExpandVertical() {
+ checkWidget();
+ return expandVertical;
+ }
+
+ public void setExpandHorizontal(boolean expand) {
+ checkWidget();
+ if (expand == expandHorizontal) return;
+ expandHorizontal = expand;
+ layout(false);
+ }
+
+ public void setExpandVertical(boolean expand) {
+ checkWidget();
+ if (expand == expandVertical) return;
+ expandVertical = expand;
+ layout(false);
+ }
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.table;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Layout;
+
+public class CustomScrolledCompositeLayout extends Layout {
+ boolean inLayout = false;
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+
+ @Override
+ protected Point computeSize(Composite composite, int wHint, int hHint,
+ boolean flushCache) {
+ CustomScrolledComposite sc = (CustomScrolledComposite)composite;
+ Point size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ if (sc.content != null) {
+ Point preferredSize = sc.content.computeSize(wHint, hHint, flushCache);
+ Point currentSize = sc.content.getSize();
+ size.x = sc.getExpandHorizontal() ? preferredSize.x : currentSize.x;
+ size.y = sc.getExpandVertical() ? preferredSize.y : currentSize.y;
+ }
+ size.x = Math.max(size.x, sc.minWidth);
+ size.y = Math.max(size.y, sc.minHeight);
+ if (wHint != SWT.DEFAULT) size.x = wHint;
+ if (hHint != SWT.DEFAULT) size.y = hHint;
+ return size;
+ }
+
+ @Override
+ protected void layout(Composite composite, boolean flushCache) {
+ if (inLayout) {
+ return;
+ }
+ CustomScrolledComposite sc = (CustomScrolledComposite)composite;
+ if (sc.content == null) {
+ return;
+ }
+ Rectangle hostRect = sc.getClientArea();
+ if (sc.hBar != null) {
+ if (sc.hBar.getSize().y >= hostRect.height) {
+ return;
+ }
+ }
+ if (sc.vBar != null) {
+
+ if (sc.vBar.getSize().x >= hostRect.width) {
+ System.out.println(sc.vBar.getSize().x + " " + sc.getSize().x);
+ return;
+ }
+ }
+
+ inLayout = true;
+ Rectangle contentRect = sc.content.getBounds();
+
+ boolean hVisible = sc.needHScroll(contentRect, false);
+ boolean vVisible = sc.needVScroll(contentRect, hVisible);
+ if (!hVisible && vVisible) {
+ hVisible = sc.needHScroll(contentRect, vVisible);
+ }
+ if (sc.hBar != null) {
+ sc.hBar.setVisible(hVisible);
+ }
+ if (sc.vBar != null) {
+ sc.vBar.setVisible(vVisible);
+ }
+
+ if (sc.expandHorizontal) {
+ contentRect.width = Math.max(sc.minWidth, hostRect.width);
+ }
+ if (sc.expandVertical) {
+ contentRect.height = Math.max(sc.minHeight, hostRect.height);
+ }
+
+ GC gc = new GC (sc);
+ if (sc.hBar != null && sc.hBar.isVisible()) {
+ int hPage = contentRect.width - hostRect.width;
+ int hSelection = sc.hBar.getSelection ();
+ if (hSelection >= hPage) {
+ if (hPage <= 0) {
+ hSelection = 0;
+ sc.hBar.setSelection(0);
+ }
+ contentRect.x = -hSelection;
+ }
+ }
+
+ if (sc.vBar != null && sc.vBar.isVisible()) {
+ sc.vBar.setMaximum(contentRect.height - hostRect.height);
+ int vPage = contentRect.height - hostRect.height;
+ int vSelection = sc.vBar.getSelection ();
+ if (vSelection >= vPage) {
+ if (vPage <= 0) {
+ vSelection = 0;
+ sc.vBar.setSelection(0);
+ }
+ contentRect.y = -vSelection;
+ }
+ }
+ gc.dispose ();
+
+ sc.content.setBounds (contentRect);
+ inLayout = false;
+ }
+
+}