List of usage examples for org.eclipse.swt.widgets Composite isDisposed
public boolean isDisposed()
true
if the widget has been disposed, and false
otherwise. From source file:org.mwc.debrief.track_shift.views.StackedDotHelper.java
/** * initialise the data, check we've got sensor data & the correct number of * visible tracks/*from w ww . j a va 2 s .c om*/ * * @param showError * @param onlyVis * @param holder */ void initialise(final TrackDataProvider tracks, final boolean showError, final boolean onlyVis, final Composite holder, final ErrorLogger logger, final String dataType, final boolean needBrg, final boolean needFreq) { // have we been created? if (holder == null) return; // are we visible? if (holder.isDisposed()) return; _secondaryTrack = null; _primaryTrack = null; // do we have some data? if (tracks == null) { // output error message logger.logError(IStatus.INFO, "Please open a Debrief plot", null); return; } // check we have a primary track final WatchableList priTrk = tracks.getPrimaryTrack(); if (priTrk == null) { logger.logError(IStatus.INFO, "A primary track must be placed on the Tote", null); return; } else { if (!(priTrk instanceof TrackWrapper)) { logger.logError(IStatus.INFO, "The primary track must be a vehicle track", null); return; } else _primaryTrack = (TrackWrapper) priTrk; } // now the sec track final WatchableList[] secs = tracks.getSecondaryTracks(); // any? if ((secs == null) || (secs.length == 0)) { } else { // too many? if (secs.length > 1) { logger.logError(IStatus.INFO, "Only 1 secondary track may be on the tote", null); return; } // correct sort? final WatchableList secTrk = secs[0]; if (!(secTrk instanceof ISecondaryTrack)) { logger.logError(IStatus.INFO, "The secondary track must be a vehicle track", null); return; } else { _secondaryTrack = (ISecondaryTrack) secTrk; } } // must have worked, hooray logger.logError(IStatus.OK, dataType + " error", null); // ok, get the positions updateDoublets(onlyVis, needBrg, needFreq); }
From source file:org.gumtree.vis.swt.PlotComposite.java
public void setPlot(final IPlot plot) { final IPlot oldPlot = this.plot; if (oldPlot != null) { oldPlot.cleanUp();/*from w w w . j a v a 2 s . co m*/ frame.remove((JPanel) oldPlot); } this.plot = plot; final Composite composite = this; Display display = Display.getCurrent(); if (display == null) { display = Display.getDefault(); } display.asyncExec(new Runnable() { @Override public void run() { if (!composite.isDisposed()) { embedPlot(plot); removeListeners(oldPlot); addListeners(); composite.pack(); composite.getParent().layout(true, true); } } }); }
From source file:org.gumtree.vis.swt.PlotComposite.java
private void addListeners() { if (plot != null) { // mouseWheelListener = new MouseWheelListener() { //// w w w . j a v a2s. com // @Override // public void mouseScrolled(MouseEvent event) { // JPanel panel = null; // if (plot instanceof JPanel) { // panel = (JPanel) plot; // } // MouseWheelEvent awtEvent = org.gumtree.vis.listener.SWT_AWT.toMouseWheelEvent( // event, panel); // plot.processMouseWheelEvent(awtEvent); // } // }; // addMouseWheelListener(mouseWheelListener); keyListener = new KeyListener() { boolean keyPressed = false; @Override public void keyReleased(KeyEvent event) { switch (event.keyCode) { case SWT.DEL: plot.removeSelectedMask(); plot.removeSelectedText(); break; default: break; } switch (event.character) { default: break; } keyPressed = false; } @Override public void keyPressed(KeyEvent event) { switch (event.stateMask) { case SWT.CTRL: if (event.keyCode == 'c' || event.keyCode == 'C') { if (!keyPressed) { plot.doCopy(); } } else if (event.keyCode == 'z' || event.keyCode == 'Z' || event.keyCode == 'r' || event.keyCode == 'R') { if (!keyPressed) { plot.restoreAutoBounds(); } } else if (event.keyCode == 'p' || event.keyCode == 'P') { if (!keyPressed) { Thread newThread = new Thread(new Runnable() { @Override public void run() { plot.createChartPrintJob(); } }); newThread.start(); } } else if (event.keyCode == 'e' || event.keyCode == 'E') { if (!keyPressed) { Thread newThread = new Thread(new Runnable() { @Override public void run() { try { plot.doSaveAs(); } catch (IOException e) { handleException(e); } } }); newThread.start(); } } keyPressed = true; break; case SWT.ALT: break; default: switch (event.keyCode) { case SWT.ARROW_UP: plot.moveSelectedMask(event.keyCode); if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() > 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int cursorX = 0; int charCount = 0; int newCursorIndex = cursorIndex; for (int i = 0; i < lines.length; i++) { if (cursorIndex > charCount && cursorIndex < charCount + lines[i].length() + 1) { cursorX = cursorIndex - charCount; if (i > 0) { if (cursorX <= lines[i - 1].length()) { newCursorIndex = charCount - lines[i - 1].length() - 1 + cursorX; } else { newCursorIndex = charCount - 1; } plot.setTextInputCursorIndex(newCursorIndex); } break; } else if (cursorIndex == charCount + lines[i].length() + 1) { newCursorIndex = charCount; plot.setTextInputCursorIndex(newCursorIndex); break; } charCount += lines[i].length() + 1; } } } } break; case SWT.ARROW_LEFT: plot.moveSelectedMask(event.keyCode); if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() > 0) { plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() - 1); } } } break; case SWT.ARROW_RIGHT: plot.moveSelectedMask(event.keyCode); if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() < plot.getTextInputContent().length()) { plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() + 1); } } } break; case SWT.ARROW_DOWN: plot.moveSelectedMask(event.keyCode); if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() >= 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int cursorX = 0; int charCount = 0; int newCursorIndex = cursorIndex; for (int i = 0; i < lines.length; i++) { if (cursorIndex >= charCount && cursorIndex < charCount + lines[i].length() + 1) { cursorX = cursorIndex - charCount; if (i < lines.length - 1) { if (cursorX <= lines[i + 1].length()) { newCursorIndex = charCount + lines[i].length() + 1 + cursorX; } else { newCursorIndex = charCount + lines[i].length() + 1 + lines[i + 1].length(); } plot.setTextInputCursorIndex(newCursorIndex); } break; } charCount += lines[i].length() + 1; } } } } break; case SWT.ESC: plot.cancelTextInput(); case SWT.SHIFT: break; case SWT.CTRL: break; case SWT.ALT: break; case SWT.F1: break; case SWT.F2: break; case SWT.F3: break; case SWT.F4: break; case SWT.F5: break; case SWT.F6: break; case SWT.F7: break; case SWT.F8: break; case SWT.F9: break; case SWT.F10: break; case SWT.F11: break; case SWT.F12: break; case SWT.PAGE_UP: if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() >= 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int cursorX = 0; int charCount = 0; int newLine = 0; for (int i = 0; i < lines.length; i++) { if (cursorIndex >= charCount && cursorIndex < charCount + lines[i].length() + 1) { cursorX = cursorIndex - charCount; if (i > 0) { newLine = i - 5; if (newLine < 0) { newLine = 0; } jumpToPosition(newLine, cursorX); } break; } charCount += lines[i].length() + 1; } } } } break; case SWT.PAGE_DOWN: if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() >= 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int cursorX = 0; int charCount = 0; int newLine = 0; for (int i = 0; i < lines.length; i++) { if (cursorIndex >= charCount && cursorIndex < charCount + lines[i].length() + 1) { cursorX = cursorIndex - charCount; if (i < lines.length - 1) { newLine = i + 5; if (newLine >= lines.length) { newLine = lines.length - 1; } jumpToPosition(newLine, cursorX); } break; } charCount += lines[i].length() + 1; } } } } break; case SWT.HOME: if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() >= 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int charCount = 0; for (int i = 0; i < lines.length; i++) { if (cursorIndex >= charCount && cursorIndex <= charCount + lines[i].length()) { plot.setTextInputCursorIndex(charCount); break; } charCount += lines[i].length() + 1; } } } } break; case SWT.END: if (plot.isCurrentlyInputtingText()) { if (plot.getTextInputContent() != null) { if (plot.getTextInputCursorIndex() >= 0) { String text = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); String[] lines = text.split("\n", 100); int charCount = 0; for (int i = 0; i < lines.length; i++) { if (cursorIndex >= charCount && cursorIndex <= charCount + lines[i].length()) { plot.setTextInputCursorIndex(charCount + lines[i].length()); break; } charCount += lines[i].length() + 1; } } } } break; case SWT.BS: if (plot.isCurrentlyInputtingText()) { String inputText; String textInputContent = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); int newIndex; if (textInputContent == null || cursorIndex <= 0 || textInputContent.length() == 0) { return; } else if (cursorIndex == 1) { inputText = textInputContent.substring(1); newIndex = 0; } else if (cursorIndex < textInputContent.length()) { newIndex = cursorIndex - 1; inputText = textInputContent.substring(0, newIndex) + textInputContent.substring(cursorIndex); } else { inputText = textInputContent.substring(0, textInputContent.length() - 1); newIndex = inputText.length(); } plot.setTextInputContent(inputText); plot.setTextInputCursorIndex(newIndex); } break; case SWT.DEL: if (plot.isCurrentlyInputtingText()) { String inputText; String textInputContent = plot.getTextInputContent(); int cursorIndex = plot.getTextInputCursorIndex(); int newIndex = cursorIndex; if (textInputContent == null || textInputContent.length() == 0 || cursorIndex >= textInputContent.length()) { return; } else if (cursorIndex == 0) { inputText = textInputContent.substring(1); } else { inputText = textInputContent.substring(0, cursorIndex) + textInputContent.substring(cursorIndex + 1); } plot.setTextInputContent(inputText); plot.setTextInputCursorIndex(newIndex); } break; case SWT.CAPS_LOCK: break; case SWT.INSERT: break; case SWT.NUM_LOCK: break; case SWT.PRINT_SCREEN: break; case SWT.SCROLL_LOCK: break; case SWT.PAUSE: break; default: if (plot.isCurrentlyInputtingText()) { if (Character.isWhitespace(event.character) && event.keyCode != SWT.SPACE) { if (event.keyCode == SWT.CR || event.keyCode == SWT.LF || event.keyCode == 16777296) { addStringToTextInput("\n", plot.getTextInputCursorIndex()); } } else { addStringToTextInput(String.valueOf(event.character), plot.getTextInputCursorIndex()); } } break; } plot.repaint(); } } }; addKeyListener(keyListener); final Composite composite = this; chartMouseListener = new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { } @Override public void chartMouseClicked(ChartMouseEvent event) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { if (!composite.isDisposed() && !composite.isFocusControl()) { composite.setFocus(); } } }); } }; plot.addChartMouseListener(chartMouseListener); } }