private void init() { this.composite = new Composite(this, SWT.BORDER | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED); this.composite.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE)); this.composite.addPaintListener( new PaintListener() { public void paintControl(PaintEvent e) { TGPainter painter = new TGPainter(e.gc); paintChords(painter); } }); this.composite.addMouseListener( new MouseAdapter() { public void mouseUp(MouseEvent e) { getComposite().setFocus(); getDialog().getEditor().setChord(getChord(e.x, e.y, true)); redraw(); } }); final Point origin = new Point(0, 0); final ScrollBar vBar = this.composite.getVerticalBar(); vBar.setIncrement(SCROLL_INCREMENT); vBar.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; Rectangle rect = getComposite().getBounds(); getShell().scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; redraw(); } }); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.minimumHeight = MIN_HEIGHT; this.composite.setLayoutData(data); this.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent arg0) { disposeChords(); disposeFont(); } }); }
// Install the listeners for events that need to be monitored for // popup closure. void installListeners() { // Listeners on this popup's table and scroll bar proposalTable.addListener(SWT.FocusOut, this); ScrollBar scrollbar = proposalTable.getVerticalBar(); if (scrollbar != null) { scrollbar.addListener(SWT.Selection, this); } // Listeners on this popup's shell getShell().addListener(SWT.Deactivate, this); getShell().addListener(SWT.Close, this); // Listeners on the target control control.addListener(SWT.MouseDoubleClick, this); control.addListener(SWT.MouseDown, this); control.addListener(SWT.Dispose, this); control.addListener(SWT.FocusOut, this); // Listeners on the target control's shell Shell controlShell = control.getShell(); controlShell.addListener(SWT.Move, this); controlShell.addListener(SWT.Resize, this); }
public GrapheChargesIHM(final ViewForm parent) { super(parent, SWT.H_SCROLL | SWT.V_SCROLL); this.parent = parent; // this.setLayout(new FillLayout(SWT.VERTICAL)); this.setSize(parent.getSize()); canvas = new Canvas(this, SWT.NONE); reglerTaille(); Menu menu = new Menu(parent.getShell(), SWT.POP_UP); MenuItem vueNormale = new MenuItem(menu, SWT.NONE); vueNormale.setText(message.getString("vueNormale")); vueNormale.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { vueSuperposee = false; canvas.redraw(); } }); new MenuItem(menu, SWT.SEPARATOR); MenuItem vueSuper = new MenuItem(menu, SWT.NONE); vueSuper.setText(message.getString("vueSuperposee")); vueSuper.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { vueSuperposee = true; canvas.redraw(); } }); canvas.setMenu(menu); final ScrollBar hBar = this.getHorizontalBar(); hBar.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = canvas.getLocation(); location.x = -hBar.getSelection(); canvas.setLocation(location); canvas.redraw(); } }); final ScrollBar vBar = this.getVerticalBar(); vBar.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = canvas.getLocation(); location.y = -vBar.getSelection(); canvas.setLocation(location); canvas.redraw(); } }); addListener( SWT.Resize, new Listener() { public void handleEvent(Event event) { reglerTaille(); Point size = canvas.getSize(); Rectangle rect = getClientArea(); hBar.setMaximum(size.x); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setMaximum(size.y); vBar.setThumb(Math.min(size.y, rect.height)); int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); Point location = canvas.getLocation(); if (hSelection >= vPage) { if (vPage <= 0) hSelection = 0; location.x = -hSelection; } int vSelection = vBar.getSelection(); if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } canvas.setLocation(location); } }); canvas.addMouseMoveListener( new MouseMoveListener() { public void mouseMove(MouseEvent e) { ActiviteGraphique actGraph = getAct(e.x, e.y); if (actGraph != null) { // EugesActRealise act = actGraph.getActiviteRealise(); } } }); canvas.addPaintListener( new PaintListener() { public void paintControl(PaintEvent e) { reglerTaille(); GC gc = e.gc; Point p = canvas.getSize(); // axe vertical gc.drawLine(20, 30, 20, p.y - 10); // fleche gc.drawLine(15, 35, 20, 30); gc.drawLine(20, 30, 25, 35); // graduations for (int i = 0; i < p.y - 60; i += 20) { gc.drawLine(15, p.y - 20 - i, 25, p.y - 20 - i); gc.drawString(Integer.toString(i / 10), 5, p.y - 20 - i - 5); } // axe horizontal gc.drawLine(10, p.y - 20, p.x - 10, p.y - 20); // fleche gc.drawLine(p.x - 10, p.y - 20, p.x - 15, p.y - 25); gc.drawLine(p.x - 10, p.y - 20, p.x - 15, p.y - 15); // legende Color blue = e.widget.getDisplay().getSystemColor(SWT.COLOR_BLUE); Color red = e.widget.getDisplay().getSystemColor(SWT.COLOR_RED); Color black = e.widget.getDisplay().getSystemColor(SWT.COLOR_BLACK); Color green = e.widget.getDisplay().getSystemColor(SWT.COLOR_GREEN); gc.setForeground(blue); gc.drawString(message.getString("chargesEstimees"), 0, 0); gc.setForeground(red); gc.drawString(message.getString("chargesReelles"), 0, 15); gc.setForeground(black); gc.drawString(message.getString("activites"), p.x - 50, p.y - 15); if (EugesElements._projet != null) { // si la vue superposee n'est pas choisie if (!vueSuperposee) { rectActivites.clear(); // graduations axe horizontal for (int i = 0; i < p.x - 40; i += 100) gc.drawLine(20 + i, p.y - 15, 20 + i, p.y - 25); // affichage des charges int nbact = 0; for (Iterator it = EugesElements._projet.get_listeIteration().iterator(); it.hasNext(); ) { Iteration itTemp = (Iteration) it.next(); for (int i = 0; i < itTemp.getActiviteCount(); i++) { EugesActRealise actTemp = itTemp.getActivite(i); nbact++; int chargeEstimee = actTemp.get_chargeEstimee(); int chargeReelle = actTemp.get_chargeReelle(); int[] dessus1 = { ((nbact) * 100) - 30, p.y - 20 - (chargeEstimee * 10), ((nbact) * 100) - 15, p.y - 35 - (chargeEstimee * 10), ((nbact) * 100) + 35, p.y - 35 - (chargeEstimee * 10), ((nbact) * 100) + 20, p.y - 20 - (chargeEstimee * 10) }; int[] cote1 = { ((nbact) * 100) + 20, p.y - 20, ((nbact) * 100) + 20, p.y - 20 - (chargeEstimee * 10), ((nbact) * 100) + 35, p.y - 35 - (chargeEstimee * 10), ((nbact) * 100) + 35, p.y - 35 }; int[] dessus2 = { ((nbact) * 100) + 20, p.y - 20 - (chargeReelle * 10), ((nbact) * 100) + 35, p.y - 35 - (chargeReelle * 10), ((nbact) * 100) + 85, p.y - 35 - (chargeReelle * 10), ((nbact) * 100) + 70, p.y - 20 - (chargeReelle * 10) }; int[] cote2 = { ((nbact) * 100) + 70, p.y - 20, ((nbact) * 100) + 70, p.y - 20 - (chargeReelle * 10), ((nbact) * 100) + 85, p.y - 35 - (chargeReelle * 10), ((nbact) * 100) + 85, p.y - 35 }; ActiviteGraphique estimee = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 100) - 30, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10), dessus1, cote1); ActiviteGraphique reelle = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 100) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10), dessus2, cote2); rectActivites.add(estimee); rectActivites.add(reelle); // rectangle charge estimée gc.setBackground(blue); gc.fillRectangle( ((nbact) * 100) - 30, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); gc.fillPolygon(dessus1); gc.fillPolygon(cote1); gc.setForeground(black); gc.drawRectangle( ((nbact) * 100) - 30, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); gc.drawPolygon(dessus1); gc.drawPolygon(cote1); gc.drawString( Integer.toString(chargeEstimee), ((nbact) * 100) - 25, p.y - 15 - (chargeEstimee * 10)); // rectangle charge réelle gc.setBackground(red); gc.fillRectangle( ((nbact) * 100) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10); gc.fillPolygon(dessus2); gc.fillPolygon(cote2); gc.setForeground(black); gc.drawRectangle( ((nbact) * 100) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10); gc.drawPolygon(dessus2); gc.drawPolygon(cote2); gc.drawString( Integer.toString(chargeReelle), ((nbact) * 100) + 25, p.y - 15 - (chargeReelle * 10)); } nbact++; } } else { rectActivites.clear(); // graduations axe horizontal for (int i = 0; i < p.x - 40; i += 50) gc.drawLine(20 + i, p.y - 15, 20 + i, p.y - 25); // affichage des charges int nbact = 0; for (Iterator it = EugesElements._projet.get_listeIteration().iterator(); it.hasNext(); ) { Iteration itTemp = (Iteration) it.next(); for (int i = 0; i < itTemp.getActiviteCount(); i++) { EugesActRealise actTemp = itTemp.getActivite(i); nbact++; int chargeEstimee = actTemp.get_chargeEstimee(); int chargeReelle = actTemp.get_chargeReelle(); int[] dessus1 = { ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), ((nbact) * 50) + 35, p.y - 35 - (chargeEstimee * 10), ((nbact) * 50) + 85, p.y - 35 - (chargeEstimee * 10), ((nbact) * 50) + 70, p.y - 20 - (chargeEstimee * 10) }; int[] cote1 = { ((nbact) * 50) + 70, p.y - 20, ((nbact) * 50) + 70, p.y - 20 - (chargeEstimee * 10), ((nbact) * 50) + 85, p.y - 35 - (chargeEstimee * 10), ((nbact) * 50) + 85, p.y - 35 }; if (chargeReelle > chargeEstimee) { int[] dessus2 = { ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), ((nbact) * 50) + 35, p.y - 35 - (chargeReelle * 10), ((nbact) * 50) + 85, p.y - 35 - (chargeReelle * 10), ((nbact) * 50) + 70, p.y - 20 - (chargeReelle * 10) }; int[] cote2 = { ((nbact) * 50) + 70, p.y - 20, ((nbact) * 50) + 70, p.y - 20 - (chargeReelle * 10), ((nbact) * 50) + 85, p.y - 35 - (chargeReelle * 10), ((nbact) * 50) + 85, p.y - 35 }; ActiviteGraphique estimee = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10), dessus1, cote1); ActiviteGraphique reelle = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10), dessus2, cote2); rectActivites.add(estimee); rectActivites.add(reelle); // rectangle charge réelle gc.setBackground(red); gc.fillRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10); gc.fillPolygon(dessus2); gc.fillPolygon(dessus1); gc.fillPolygon(cote2); gc.setForeground(black); gc.drawRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10); gc.drawPolygon(dessus2); gc.drawPolygon(cote2); // rectangle charge estimée gc.setBackground(blue); gc.fillRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); gc.fillPolygon(cote1); gc.setForeground(black); gc.drawRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); // gc.drawPolygon(dessus1); gc.drawPolygon(cote1); } else { int[] dessus2 = { ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), ((nbact) * 50) + 35, p.y - 35 - (chargeReelle * 10), ((nbact) * 50) + 85, p.y - 35 - (chargeReelle * 10), ((nbact) * 50) + 70, p.y - 20 - (chargeReelle * 10) }; ActiviteGraphique estimee = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10), dessus1, cote1); ActiviteGraphique reelle = new ActiviteGraphique( actTemp, new Rectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeReelle * 10), 50, chargeReelle * 10), dessus2, cote1); rectActivites.add(estimee); rectActivites.add(reelle); // rectangle charge estimée gc.setBackground(blue); gc.fillRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); gc.fillPolygon(cote1); gc.fillPolygon(dessus1); gc.setBackground(green); gc.fillPolygon(dessus2); gc.setForeground(black); gc.drawPolygon(dessus2); gc.setForeground(black); gc.drawRectangle( ((nbact) * 50) + 20, p.y - 20 - (chargeEstimee * 10), 50, chargeEstimee * 10); gc.drawPolygon(dessus1); gc.drawPolygon(cote1); } } nbact++; } } } } }); canvas.redraw(); }
/** * 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 addListeners() { origin = new Point(0, 0); hBar = canvas.getHorizontalBar(); vBar = canvas.getVerticalBar(); hBar.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { int hSelection = hBar.getSelection(); int destX = -hSelection - origin.x; Rectangle rect = canvas.getBounds(); canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); vBar.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { int vSelection = vBar.getSelection(); int destY = -vSelection - origin.y; Rectangle rect = canvas.getBounds(); canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); origin.y = -vSelection; } }); canvas.addListener( SWT.Resize, new Listener() { @Override public void handleEvent(Event e) { resizeScrollBar(); canvas.redraw(); } }); canvas.addListener( SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { GC gc = event.gc; gc.drawImage(backgroundImage, origin.x, origin.y); Point widthImagePoint = computeCenterPosition(canvas.getBounds(), patchedWidthImage); Point heightImagePoint = computeCenterPosition(canvas.getBounds(), patchedHeightImage); int hImage = widthImagePoint.y + origin.y - patchedHeightImage.getImageData().height - 10; int y = hImage; int x = heightImagePoint.x; if (y < 20) { y = 20; } if (x < 20) { x = 20; } gc.drawImage(patchedHeightImage, x + origin.x, y + origin.y); x = widthImagePoint.x; if (x < 20) { x = 20; } y = y + patchedHeightImage.getImageData().height + 10; gc.drawImage(patchedWidthImage, x + origin.x, y + origin.y); y = y + patchedWidthImage.getImageData().height + 10; gc.drawImage(patchedBothImage, x + origin.x, y + origin.y); if (attribute.isShowContent()) { disposeContentImage(); contentHeightImage = createContentImage(patchedHeightImage, contentHeightData); contentWidthImage = createContentImage(patchedWidthImage, contentWidthData); contentBothImage = createContentImage(patchedBothImage, contentBothData); hImage = widthImagePoint.y + origin.y - patchedHeightImage.getImageData().height - 10; y = hImage; x = heightImagePoint.x; if (y < 20) { y = 20; } if (x < 20) { x = 20; } gc.drawImage(contentHeightImage, x + origin.x, y + origin.y); x = widthImagePoint.x; if (x < 20) { x = 20; } y = y + patchedHeightImage.getImageData().height + 10; gc.drawImage(contentWidthImage, x + origin.x, y + origin.y); y = y + patchedWidthImage.getImageData().height + 10; gc.drawImage(contentBothImage, x + origin.x, y + origin.y); } } private void disposeContentImage() { if (contentBothImage != null && !contentBothImage.isDisposed()) { contentBothImage.dispose(); } if (contentHeightImage != null && contentHeightImage.isDisposed()) { contentHeightImage.dispose(); } if (contentWidthImage != null && !contentWidthImage.isDisposed()) { contentWidthImage.dispose(); } } }); }
/** * Creates rulers for the given graphical viewer. * * <p>The primaryViewer or its Control cannot be <code>null</code>. The primaryViewer's Control * should be a FigureCanvas and a child of this Composite. This method should only be invoked * once. * * <p>To create ruler(s), simply add the RulerProvider(s) (with the right key: * RulerProvider.PROPERTY_HORIZONTAL_RULER or RulerProvider.PROPERTY_VERTICAL_RULER) as a property * on the given viewer. It can be done after this method is invoked. * RulerProvider.PROPERTY_RULER_VISIBILITY can be used to show/hide the rulers. * * @param primaryViewer The graphical viewer for which the rulers have to be created */ public void setGraphicalViewer(ScrollingGraphicalViewer primaryViewer) { // pre-conditions Assert.isNotNull(primaryViewer); Assert.isNotNull(primaryViewer.getControl()); Assert.isTrue(diagramViewer == null); diagramViewer = primaryViewer; editor = (FigureCanvas) diagramViewer.getControl(); // layout whenever the scrollbars are shown or hidden, and whenever the // RulerComposite // is resized layoutListener = new Listener() { public void handleEvent(Event event) { // @TODO:Pratik If you use Display.asyncExec(runnable) here, // some flashing // occurs. You can see it when the palette is in the editor, and // you hit // the button to show/hide it. layout(true); } }; addListener(SWT.Resize, layoutListener); ScrollBar horizontalBar = editor.getHorizontalBar(); if (horizontalBar != null) { horizontalBar.addListener(SWT.Show, layoutListener); horizontalBar.addListener(SWT.Hide, layoutListener); } ScrollBar verticalBar = editor.getVerticalBar(); if (verticalBar != null) { verticalBar.addListener(SWT.Show, layoutListener); verticalBar.addListener(SWT.Hide, layoutListener); } propertyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String property = evt.getPropertyName(); if (RulerProvider.PROPERTY_HORIZONTAL_RULER.equals(property)) { setRuler( (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), PositionConstants.NORTH); } else if (RulerProvider.PROPERTY_VERTICAL_RULER.equals(property)) { setRuler( (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), PositionConstants.WEST); } else if (RulerProvider.PROPERTY_RULER_VISIBILITY.equals(property)) setRulerVisibility( ((Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY)) .booleanValue()); } }; diagramViewer.addPropertyChangeListener(propertyListener); Boolean rulerVisibility = (Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY); if (rulerVisibility != null) setRulerVisibility(rulerVisibility.booleanValue()); setRuler( (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), PositionConstants.NORTH); setRuler( (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), PositionConstants.WEST); }