/** Creates the "Example" widgets. */ void createExampleWidgets() { /* Compute the widget style */ int style = getDefaultStyle(); if (horizontalButton.getSelection()) style |= SWT.H_SCROLL; if (verticalButton.getSelection()) style |= SWT.V_SCROLL; if (borderButton.getSelection()) style |= SWT.BORDER; if (noBackgroundButton.getSelection()) style |= SWT.NO_BACKGROUND; if (noFocusButton.getSelection()) style |= SWT.NO_FOCUS; if (noMergePaintsButton.getSelection()) style |= SWT.NO_MERGE_PAINTS; if (noRedrawResizeButton.getSelection()) style |= SWT.NO_REDRAW_RESIZE; /* Create the example widgets */ paintCount = 0; cx = 0; cy = 0; canvas = new Canvas(canvasGroup, style); canvas.addPaintListener( new PaintListener() { public void paintControl(PaintEvent e) { paintCount++; GC gc = e.gc; if (fillDamageButton.getSelection()) { Color color = e.display.getSystemColor(colors[paintCount % colors.length]); gc.setBackground(color); gc.fillRectangle(e.x, e.y, e.width, e.height); } Point size = canvas.getSize(); gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360); gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10); } }); canvas.addControlListener( new ControlAdapter() { public void controlResized(ControlEvent event) { Point size = canvas.getSize(); maxX = size.x * 3 / 2; maxY = size.y * 3 / 2; resizeScrollBars(); } }); ScrollBar bar = canvas.getHorizontalBar(); if (bar != null) { bar.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scrollHorizontal((ScrollBar) event.widget); } }); } bar = canvas.getVerticalBar(); if (bar != null) { bar.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scrollVertical((ScrollBar) event.widget); } }); } }
void propagateWidget(boolean enabled) { super.propagateWidget(enabled); if (formHandle != 0) propagateHandle(enabled, formHandle, OS.None); if (scrolledHandle != 0) { propagateHandle(enabled, scrolledHandle, OS.None); if (horizontalBar != null) horizontalBar.propagateWidget(enabled); if (verticalBar != null) verticalBar.propagateWidget(enabled); } }
void releaseChildren(boolean destroy) { if (horizontalBar != null) { horizontalBar.release(false); horizontalBar = null; } if (verticalBar != null) { verticalBar.release(false); verticalBar = null; } super.releaseChildren(destroy); }
/** * Installs this highlighter into the specified StyledText object. Client can manually call * detach() method, then wants to destroy this object. */ public void attach(StyledText parent) { detach(); text = parent; text.addDisposeListener(ml); text.addLineStyleListener(ml); text.addLineBackgroundListener(ml); text.addPaintListener(ml); text.addVerifyListener(ml); text.addExtendedModifyListener(ml); text.addControlListener(ml); text.addKeyListener(ml); text.addTraverseListener(ml); text.addMouseListener(ml); text.addSelectionListener(ml); text.getContent().addTextChangeListener(ml); ScrollBar sb = text.getVerticalBar(); if (sb != null) sb.addSelectionListener(ml); updateViewport(); new Thread() { public void run() { // setPriority(Thread.NORM_PRIORITY-1); while (true) { try { sleep(300); } catch (InterruptedException e) { } if (baseEditor == null || text == null) break; if (backParserDelay) { backParserDelay = false; try { sleep(1500); } catch (InterruptedException e) { } continue; } ; Display.getDefault() .syncExec( new Runnable() { public void run() { if (baseEditor == null || text == null) return; if (text.isDisposed()) return; // System.out.println(System.currentTimeMillis()); baseEditor.idleJob(80); // redrawFrom(text.getLineAtOffset(text.getCaretOffset())); } }); } ; }; }.start(); }
void redrawWidget( int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { super.redrawWidget(x, y, width, height, redrawAll, allChildren, trim); if (!trim) return; if (formHandle == 0 && scrolledHandle == 0) return; short[] root_x = new short[1], root_y = new short[1]; OS.XtTranslateCoords(handle, (short) x, (short) y, root_x, root_y); if (formHandle != 0) { short[] form_x = new short[1], form_y = new short[1]; OS.XtTranslateCoords(formHandle, (short) 0, (short) 0, form_x, form_y); redrawHandle( root_x[0] - form_x[0], root_y[0] - form_y[0], width, height, redrawAll, formHandle); } if (scrolledHandle != 0) { short[] scrolled_x = new short[1], scrolled_y = new short[1]; OS.XtTranslateCoords(scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y); redrawHandle( root_x[0] - scrolled_x[0], root_y[0] - scrolled_y[0], width, height, redrawAll, scrolledHandle); if (horizontalBar != null && horizontalBar.getVisible()) { int horizontalHandle = horizontalBar.handle; short[] hscroll_x = new short[1], hscroll_y = new short[1]; OS.XtTranslateCoords(horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y); redrawHandle( root_x[0] - hscroll_x[0], root_y[0] - hscroll_y[0], width, height, redrawAll, horizontalHandle); } if (verticalBar != null && verticalBar.getVisible()) { int verticalHandle = verticalBar.handle; short[] vscroll_x = new short[1], vscroll_y = new short[1]; OS.XtTranslateCoords(verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y); redrawHandle( root_x[0] - vscroll_x[0], root_y[0] - vscroll_y[0], width, height, redrawAll, verticalHandle); } } }
/** @see Component#processMouseEvent(MouseEvent) */ @Override protected void processMouseEvent(MouseEvent e) { // if(e.getID() == MouseEvent.MOUSE_PRESSED) // { // if(getViewport().getView() instanceof CellEditorListener) // { // ((CellEditorListener)getViewport().getView()).editingStopped(null); // requestFocus(); // } // } if (iValue != -1 && e.getID() == MouseEvent.MOUSE_RELEASED) { super.setValue(iValue); iValue = -1; } super.processMouseEvent(e); }
/** @see Component#processMouseMotionEvent(MouseEvent) */ @Override protected void processMouseMotionEvent(MouseEvent e) { if (iValue == -1 && e.getID() == MouseEvent.MOUSE_DRAGGED) { iValue = getValue(); } super.processMouseMotionEvent(e); }
void updateScrollBars() { hasVScrollBar = false; hasHScrollBar = needsHScrollBar(); if (needsVScrollBar()) { hasVScrollBar = true; hasHScrollBar = needsHScrollBar(); } ScrollBar hScroll = getHorizontalBar(); if (hScroll != null) { hScroll.setVisible(hasHScrollBar); } ScrollBar vScroll = getVerticalBar(); if (vScroll != null) { vScroll.setVisible(hasVScrollBar); } }
/** @see Adjustable#setValue(int) */ @Override public void setValue(int v) { if (iValue == -1) { super.setValue(v); } else { iValue = v; } }
/** * Removes this object from the corresponding StyledText widget. Object can't be used after this * call, until another attach. This method is called automatically, when StyledText widget is * disposed */ public void detach() { if (text == null) return; text.removeDisposeListener(ml); text.removeLineStyleListener(ml); text.removeLineBackgroundListener(ml); text.removePaintListener(ml); text.removeVerifyListener(ml); text.removeExtendedModifyListener(ml); text.removeControlListener(ml); text.removeKeyListener(ml); text.removeTraverseListener(ml); text.removeMouseListener(ml); text.removeSelectionListener(ml); ScrollBar sb = text.getVerticalBar(); if (sb != null) sb.removeSelectionListener(ml); baseEditor = null; }
void onDispose(Event event) { removeListener(SWT.Dispose, listener); notifyListeners(SWT.Dispose, event); event.type = SWT.None; table.removeListener(SWT.FocusIn, tableListener); table.removeListener(SWT.MouseDown, tableListener); unhookRowColumnListeners(); ScrollBar hBar = table.getHorizontalBar(); if (hBar != null) { hBar.removeListener(SWT.Selection, resizeListener); } ScrollBar vBar = table.getVerticalBar(); if (vBar != null) { vBar.removeListener(SWT.Selection, resizeListener); } }
private static String getOverflow(final ScrolledComposite composite) { String result; ScrollBar horizontalBar = composite.getHorizontalBar(); boolean scrollX = horizontalBar != null && horizontalBar.getVisible(); ScrollBar verticalBar = composite.getVerticalBar(); boolean scrollY = verticalBar != null && verticalBar.getVisible(); if (scrollX && scrollY) { result = "scroll"; } else if (scrollX) { result = "scrollX"; } else if (scrollY) { result = "scrollY"; } else { result = "hidden"; } return result; }
/** * Scrolls the canvas vertically. * * @param scrollBar */ void scrollVertical(ScrollBar scrollBar) { Rectangle bounds = canvas.getClientArea(); int y = -scrollBar.getSelection(); if (y + maxY < bounds.height) { y = bounds.height - maxY; } canvas.scroll(cx, y, cx, cy, maxX, maxY, false); cy = y; }
/** * Scrolls the canvas horizontally. * * @param scrollBar */ void scrollHorizontal(ScrollBar scrollBar) { Rectangle bounds = canvas.getClientArea(); int x = -scrollBar.getSelection(); if (x + maxX < bounds.width) { x = bounds.width - maxX; } canvas.scroll(x, cy, cx, cy, maxX, maxY, false); cx = x; }
private static Integer getBarSelection(final ScrollBar scrollBar) { Integer result; if (scrollBar != null) { result = new Integer(scrollBar.getSelection()); } else { result = null; } return result; }
private int GetItemIdOfFrame(Frame frame) { PixelOffset = (int) LibScroll.GetValue(); ViewIndex = (int) Math.floor((double) PixelOffset / (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING)); int id = ViewIndex + ScrollList.indexOf(frame); if (CurrentList == 0) { return (int) ActiveList.get(id); } else if (CurrentList >= 1 && CurrentList <= 4) { return (int) ((Item) ActiveList.get(id)).getId(); } return 0; }
boolean setScrollBarVisible(ScrollBar bar, boolean visible) { if (scrolledHandle == 0) return false; int barHandle = bar.handle; boolean managed = OS.XtIsManaged(barHandle); if (managed == visible) return false; /* * Feature in Motif. Hiding or showing a scroll bar * can cause the widget to automatically resize in * the OS. This behavior is unwanted. The fix is * to force the widget to resize to original size. */ int[] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; OS.XtGetValues(scrolledHandle, argList, argList.length / 2); int[] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0}; OS.XtGetValues(handle, argList1, argList1.length / 2); /* Hide or show the scroll bar */ if (visible) { OS.XtManageChild(barHandle); } else { OS.XtUnmanageChild(barHandle); } if ((state & CANVAS) != 0) { if (formHandle != 0) { boolean showBorder = (style & SWT.BORDER) != 0; int margin = showBorder || visible ? 3 : 0; if ((bar.style & SWT.V_SCROLL) != 0) { int[] argList2 = new int[] {OS.XmNmarginWidth, margin}; OS.XtSetValues(formHandle, argList2, argList2.length / 2); } if ((bar.style & SWT.H_SCROLL) != 0) { int[] argList2 = new int[] {OS.XmNmarginHeight, margin}; OS.XtSetValues(formHandle, argList2, argList2.length / 2); } } } /* * Feature in Motif. When XtSetValues() is used to restore the width and * height of the widget, the new width and height are sometimes ignored. * The fix is to use XtResizeWidget(). */ OS.XtResizeWidget(scrolledHandle, argList[1], argList[3], argList[5]); bar.sendEvent(visible ? SWT.Show : SWT.Hide); int[] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0}; OS.XtGetValues(handle, argList3, argList3.length / 2); return argList1[1] != argList3[1] || argList1[3] != argList3[3]; }
ScrollBar createStandardBar(int style) { if (scrolledHandle == 0) return null; ScrollBar bar = new ScrollBar(); bar.parent = this; bar.style = style; bar.display = display; int[] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0}; OS.XtGetValues(scrolledHandle, argList, argList.length / 2); if (style == SWT.H_SCROLL) bar.handle = argList[1]; if (style == SWT.V_SCROLL) bar.handle = argList[3]; bar.hookEvents(); bar.register(); return bar; }
/** Resizes the maximum and thumb of both scrollbars. */ void resizeScrollBars() { Rectangle clientArea = canvas.getClientArea(); ScrollBar bar = canvas.getHorizontalBar(); if (bar != null) { bar.setMaximum(maxX); bar.setThumb(clientArea.width); bar.setPageIncrement(clientArea.width); } bar = canvas.getVerticalBar(); if (bar != null) { bar.setMaximum(maxY); bar.setThumb(clientArea.height); bar.setPageIncrement(clientArea.height); } }
void reskinChildren(int flags) { if (horizontalBar != null) horizontalBar.reskin(flags); if (verticalBar != null) verticalBar.reskin(flags); super.reskinChildren(flags); }
/** * Constructs a new instance of this class given its parent table and a style value describing its * behavior and appearance. * * <p>The style value is either one of the style constants defined in class <code>SWT</code> which * is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together * (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style * constants. The class description lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * * @param parent a Table control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass * </ul> * * @see SWT#BORDER * @see Widget#checkSubclass() * @see Widget#getStyle() */ public TableCursor(Table parent, int style) { super(parent, style); table = parent; setBackground(null); setForeground(null); listener = event -> { switch (event.type) { case SWT.Dispose: onDispose(event); break; case SWT.FocusIn: case SWT.FocusOut: redraw(); break; case SWT.KeyDown: keyDown(event); break; case SWT.Paint: paint(event); break; case SWT.Traverse: { event.doit = true; switch (event.detail) { case SWT.TRAVERSE_ARROW_NEXT: case SWT.TRAVERSE_ARROW_PREVIOUS: case SWT.TRAVERSE_RETURN: event.doit = false; break; } break; } } }; int[] events = new int[] {SWT.Dispose, SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.Paint, SWT.Traverse}; for (int i = 0; i < events.length; i++) { addListener(events[i], listener); } tableListener = event -> { switch (event.type) { case SWT.MouseDown: tableMouseDown(event); break; case SWT.FocusIn: tableFocusIn(event); break; } }; table.addListener(SWT.FocusIn, tableListener); table.addListener(SWT.MouseDown, tableListener); disposeItemListener = event -> { unhookRowColumnListeners(); row = null; column = null; _resize(); }; disposeColumnListener = event -> { unhookRowColumnListeners(); row = null; column = null; _resize(); }; resizeListener = event -> _resize(); ScrollBar hBar = table.getHorizontalBar(); if (hBar != null) { hBar.addListener(SWT.Selection, resizeListener); } ScrollBar vBar = table.getVerticalBar(); if (vBar != null) { vBar.addListener(SWT.Selection, resizeListener); } getAccessible() .addAccessibleControlListener( new AccessibleControlAdapter() { @Override public void getRole(AccessibleControlEvent e) { e.detail = ACC.ROLE_TABLECELL; } }); getAccessible() .addAccessibleListener( new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { if (row == null) return; int columnIndex = column == null ? 0 : table.indexOf(column); e.result = row.getText(columnIndex); } }); }
private void SetFrames() { AccountCredit.SetText(String.format("Credit: $%.2f", Driver.CurrentUser.getCredit())); Frame current; TextLabel rowOne; TextLabel rowTwo; TextButton commandButton; if (LastCurrentListValue != CurrentList) { ArrayList temporaryList = null; ActiveList.clear(); if (CurrentList == 0) { temporaryList = Driver.CurrentUser.getPurchaseHistory(); } else if (CurrentList == 1) { temporaryList = DataLoader.getAlbums(); } else if (CurrentList == 2) { temporaryList = DataLoader.getAudiobooks(); } else if (CurrentList == 3) { temporaryList = DataLoader.getFilm(); } if (CurrentList >= 1 && CurrentList <= 3) { // if the use is looking at a store page, weed out all invisible songs/albums *unless* it is // a administrator. for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } } else if (CurrentList == 0) { for (int i = 0; i < temporaryList.size(); i++) { ActiveList.add(temporaryList.get(i)); } } else if (CurrentList == 4) { temporaryList = DataLoader.getAlbums(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } temporaryList = DataLoader.getAudiobooks(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } temporaryList = DataLoader.getFilm(); for (int i = 0; i < temporaryList.size(); i++) { if (temporaryList.get(i) instanceof Item && (!((Item) temporaryList.get(i)).isVisible() || Driver.CurrentUser.getAdministrator())) { ActiveList.add(temporaryList.get(i)); } } } LastCurrentListValue = CurrentList; } // this should never happen, but just in case it does, break the function before an error is // thrown. if (ActiveList == null) { return; } int MaximumIndex = ActiveList.size(); LibScroll.SetMax( Math.max( 0, MaximumIndex * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING) - Driver.GetGuiMain().GetWindow().getHeight() + 50)); PixelOffset = (int) LibScroll.GetValue(); ViewIndex = (int) Math.floor((double) PixelOffset / (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING)); for (int i = 0; i < ScrollList.size(); i++) { // Position the frame appropriately. current = ScrollList.get(i); current.GetPosition().yOffset = i * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING) - PixelOffset % (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING); rowOne = (TextLabel) current.GetChild("TopText"); rowTwo = (TextLabel) current.GetChild("BottomText"); commandButton = (TextButton) current.GetChild("Action"); // If the index we're looking for is out of bounds, don't display the frame. if (i + ViewIndex >= MaximumIndex) { CenterScrollFrame.RemoveChild(current); } else { CenterScrollFrame.AddChild(current); // Fill the text labels with content based on what view option is selected. if (CurrentList == 0) { if (!current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) { current.GetChild("Divider").GetPosition().xOffset = -99; current.GetChild("TopText").GetSize().xOffset = -105; current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize()); current.GetChild("Action2").SetVisible(true); ((TextButton) current.GetChild("Action2")).SetText("Rate"); Driver.GetGuiMain().GetTextBoxes(); } Item currentItem = DataLoader.getItemById(((Integer) ActiveList.get(i + ViewIndex)).intValue()); SetListText(rowOne, rowTwo, currentItem); if (CurrentPlayingItem == currentItem) { commandButton.SetText("Stop"); } else { commandButton.SetText("Play"); } } else if (CurrentList >= 1 && CurrentList <= 4) { if (current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) { current.GetChild("Divider").GetPosition().xOffset = -52; current.GetChild("TopText").GetSize().xOffset = -58; current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize()); current.GetChild("Action2").SetVisible(false); } Item currentItem = (Item) ActiveList.get(i + ViewIndex); SetListText(rowOne, rowTwo, currentItem); if (currentItem.isVisible()) { rowTwo.SetText(rowTwo.GetText() + "; HIDDEN"); } if (Driver.CurrentUser.getPurchaseHistory().contains(currentItem.getId())) { if (CurrentPlayingItem == currentItem) { commandButton.SetText("Stop"); } else { commandButton.SetText("Play"); } } else { commandButton.SetText("Buy"); } } } } }
void destroyScrollBar(ScrollBar bar) { setScrollBarVisible(bar, false); if ((state & CANVAS) != 0) bar.destroyHandle(); }