/* * @see org.eclipse.jface.text.IPainter#paint(int) */ public void paint(int reason) { IDocument document = fTextViewer.getDocument(); if (document == null) { deactivate(false); return; } if (!fIsActive) { fIsActive = true; fTextWidget.addPaintListener(this); redrawAll(); } else if (reason == CONFIGURATION || reason == INTERNAL) { redrawAll(); } else if (reason == TEXT_CHANGE) { // redraw current line only try { IRegion lineRegion = document.getLineInformationOfOffset(getDocumentOffset(fTextWidget.getCaretOffset())); int widgetOffset = getWidgetOffset(lineRegion.getOffset()); int charCount = fTextWidget.getCharCount(); int redrawLength = Math.min(lineRegion.getLength(), charCount - widgetOffset); if (widgetOffset >= 0 && redrawLength > 0) { fTextWidget.redrawRange(widgetOffset, redrawLength, true); } } catch (BadLocationException e) { // ignore } } }
/* * @see IPainter#paint(int) */ public void paint(int reason) { if (fViewer == null) { return; } if (fViewer.getDocument() == null) { deactivate(false); return; } // initialization if (!fIsActive) { StyledText textWidget = fViewer.getTextWidget(); textWidget.addLineBackgroundListener(this); textWidget.addPaintListener(this); fPositionManager.managePosition(fCurrentLine); fIsActive = true; } // This forces redraw of the line highlight if (updateHighlightLine()) { // clear last line // Fix the background colors for tokens that didn't have the same as line! if (isOpaque() && !fLastLine.isDeleted() && fViewer instanceof ITextViewerExtension2) { ITextViewerExtension2 ext = (ITextViewerExtension2) fViewer; try { ext.invalidateTextPresentation(fLastLine.getOffset(), fLastLine.getLength()); } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } } drawHighlightLine(fLastLine); // draw new line drawHighlightLine(fCurrentLine); } }
/** * Controls whether the status line will be painted into the parent component. * * @param enabled whether the status line will be painted. */ public void setEnabled(boolean enabled) { if (enabled) { parent.addPaintListener(this); } else { parent.removePaintListener(this); setContent(""); currentRect = null; } }
/** * 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(); }
public CommandLineUIFactory(StyledText parentText) { parent = parentText; StyledText widget = new StyledText(parent, SWT.ON_TOP); widget.setFont(parent.getFont()); widget.setMargins(COMMAND_CHAR_INDENT, 3, 3, 3); widget.setSize(5, 5); widget.setBackground(parent.getBackground()); widget.setForeground(parent.getForeground()); widget.setWordWrap(true); widget.setEnabled(true); // widget.setCaretOffset(2); widget.moveAbove(parent); widget.setVisible(false); widget.addPaintListener(new BorderPaintListener()); commandLineText = widget; parent.addPaintListener(new TextEditorPaintListener()); parent.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (commandLineUI != null && commandLineUI.isOpen()) { commandLineText.forceFocus(); } } }); parent.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { commandLineText.dispose(); if (commandLineUI != null) { commandLineUI.dispose(); } } }); }
/** @see IPainter#paint(int) */ public final void paint(final int reason) { Point selection = mSourceViewer.getSelectedRange(); if (selection.y > 0) { deactivate(true); return; } SexpNavigator explorer = mEditor.getExplorer(); boolean backward = true; boolean closeToParen = false; int offset = selection.x; IDocument document = mEditor.getDocument(); try { char previousChar = '\0'; char nextChar = '\0'; if (selection.x > 0) previousChar = document.getChar(selection.x - 1); if (selection.x > 0 && SchemeScannerUtilities.isClosingParenthesis(previousChar) && SchemeTextUtilities.getPartition(document, selection.x - 1).getType() == IDocument.DEFAULT_CONTENT_TYPE) { closeToParen = true; } else { nextChar = document.getChar(selection.x); if (selection.x < document.getLength() - 1 && SchemeScannerUtilities.isOpeningParenthesis(nextChar) && SchemeTextUtilities.getPartition(document, selection.x).getType() == IDocument.DEFAULT_CONTENT_TYPE) { closeToParen = true; backward = false; } } if (closeToParen && backward && explorer.backwardSexpression(selection.x)) { offset = explorer.getListStart(); char matchingChar = document.getChar(offset); mMismatch = SchemeScannerUtilities.getParenthesisType(previousChar) != SchemeScannerUtilities.getParenthesisType(matchingChar); } else { if (closeToParen && !backward && explorer.forwardSexpression(selection.x)) { offset = explorer.getSexpEnd() - 1; char matchingChar = document.getChar(offset); mMismatch = SchemeScannerUtilities.getParenthesisType(nextChar) != SchemeScannerUtilities.getParenthesisType(matchingChar); } else { deactivate(true); return; } } } catch (BadLocationException exception) { deactivate(true); return; } if (mIsActive) { // only if different if (offset != mBracketPosition.getOffset()) { // remove old highlighting handleDrawRequest(null); // update position mBracketPosition.isDeleted = false; mBracketPosition.offset = offset; mBracketPosition.length = 1; // apply new highlighting handleDrawRequest(null); } } else { mIsActive = true; mBracketPosition.isDeleted = false; mBracketPosition.offset = offset; mBracketPosition.length = 1; mTextWidget.addPaintListener(this); mPositionManager.managePosition(mBracketPosition); handleDrawRequest(null); } }
/** * Adds the listener to the collection of listeners who will be notified when the receiver needs * to be painted, by sending it one of the messages defined in the <code>PaintListener</code> * interface. * * @param inListener the listener which should be notified */ public void addPaintListener(final PaintListener inListener) { textWidget.addPaintListener(inListener); }
/** * Creates a new <code>BZStyledText</code> for parentShell <code>parentShell</code>. * * @param parentShell parentShell of the new instance (cannot be null) */ public BZStyledText(Shell parentShell) { this.parentShell = parentShell; // version from jar manifest String version = getClass().getPackage().getImplementationVersion(); // version from build file if (version == null) version = System.getProperty("braillezephyr.version"); // no version if (version == null) { logWriter.println("WARNING: unable to determine version, using 0.0"); version = "0.0"; } versionString = version; String[] versionStrings = versionString.split("\\."); versionMajor = Integer.parseInt(versionStrings[0]); if (versionStrings.length > 1) versionMinor = Integer.parseInt(versionStrings[1]); else versionMinor = 0; if (versionStrings.length > 2) versionPatch = Integer.parseInt(versionStrings[2]); else versionPatch = 0; color = parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK); composite = new Composite(parentShell, 0); composite.setLayout(new GridLayout(2, true)); // load fonts loadFont("BrailleZephyr_6.otf"); loadFont("BrailleZephyr_6b.otf"); loadFont("BrailleZephyr_6s.otf"); loadFont("BrailleZephyr_6sb.otf"); loadFont("BrailleZephyr_8.otf"); loadFont("BrailleZephyr_8b.otf"); loadFont("BrailleZephyr_8s.otf"); loadFont("BrailleZephyr_8sb.otf"); loadFont("BrailleZephyr_8w.otf"); loadFont("BrailleZephyr_8wb.otf"); loadFont("BrailleZephyr_8ws.otf"); loadFont("BrailleZephyr_8wsb.otf"); // load line margin bell try { InputStream inputStreamBellMargin = new BufferedInputStream(getClass().getResourceAsStream("/sounds/line_margin_bell.wav")); AudioInputStream audioInputStreamMargin = AudioSystem.getAudioInputStream(inputStreamBellMargin); DataLine.Info dataLineInfoMargin = new DataLine.Info(Clip.class, audioInputStreamMargin.getFormat()); lineMarginClip = (Clip) AudioSystem.getLine(dataLineInfoMargin); lineMarginClip.open(audioInputStreamMargin); } catch (IOException exception) { logWriter.println( "ERROR: Unable to read default line margin bell file: " + exception.getMessage()); lineMarginClip = null; } catch (UnsupportedAudioFileException exception) { logWriter.println( "ERROR: Sound file unsupported for default line margin bell: " + exception.getMessage()); lineMarginClip = null; } catch (LineUnavailableException exception) { logWriter.println( "ERROR: Line unavailable for default line margin bell: " + exception.getMessage()); lineMarginClip = null; } // load page margin bell try { InputStream inputStreamBellPage = new BufferedInputStream(getClass().getResourceAsStream("/sounds/page_margin_bell.wav")); AudioInputStream audioInputStreamPage = AudioSystem.getAudioInputStream(inputStreamBellPage); DataLine.Info dataLineInfoPage = new DataLine.Info(Clip.class, audioInputStreamPage.getFormat()); pageMarginClip = (Clip) AudioSystem.getLine(dataLineInfoPage); pageMarginClip.open(audioInputStreamPage); } catch (IOException exception) { logWriter.println( "ERROR: Unable to read default page margin bell file: " + exception.getMessage()); pageMarginClip = null; } catch (UnsupportedAudioFileException exception) { logWriter.println( "ERROR: Sound file unsupported for default page margin bell: " + exception.getMessage()); pageMarginClip = null; } catch (LineUnavailableException exception) { logWriter.println( "ERROR: Line unavailable for default page margin bell: " + exception.getMessage()); pageMarginClip = null; } // load line end bell try { InputStream inputStreamBellPage = new BufferedInputStream(getClass().getResourceAsStream("/sounds/line_end_bell.wav")); AudioInputStream audioInputStreamPage = AudioSystem.getAudioInputStream(inputStreamBellPage); DataLine.Info dataLineInfoPage = new DataLine.Info(Clip.class, audioInputStreamPage.getFormat()); lineEndClip = (Clip) AudioSystem.getLine(dataLineInfoPage); lineEndClip.open(audioInputStreamPage); } catch (IOException exception) { logWriter.println( "ERROR: Unable to read default line end bell file: " + exception.getMessage()); lineEndClip = null; } catch (UnsupportedAudioFileException exception) { logWriter.println( "ERROR: Sound file unsupported for default line end bell: " + exception.getMessage()); lineEndClip = null; } catch (LineUnavailableException exception) { logWriter.println( "ERROR: Line unavailable for default line end bell: " + exception.getMessage()); lineEndClip = null; } brailleText = new StyledText(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); brailleText.setLayoutData(new GridData(GridData.FILL_BOTH)); brailleText.setFont(new Font(parentShell.getDisplay(), "BrailleZephyr_6s", 18, SWT.NORMAL)); brailleText.addFocusListener(new FocusHandler(brailleText)); brailleText.addPaintListener(new PaintHandler(brailleText)); BrailleKeyHandler brailleKeyHandler = new BrailleKeyHandler(true); brailleText.addKeyListener(brailleKeyHandler); brailleText.addVerifyKeyListener(brailleKeyHandler); brailleText.addExtendedModifyListener(new ExtendedModifyHandler(brailleText)); content = brailleText.getContent(); asciiText = new StyledText(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); asciiText.setContent(content); asciiText.setLayoutData(new GridData(GridData.FILL_BOTH)); asciiText.setFont(new Font(parentShell.getDisplay(), "Monospace", 18, SWT.NORMAL)); asciiText.addFocusListener(new FocusHandler(asciiText)); asciiText.addPaintListener(new PaintHandler(asciiText)); asciiText.addVerifyKeyListener(new BrailleKeyHandler(false)); asciiText.addExtendedModifyListener(new ExtendedModifyHandler(asciiText)); brailleText.addCaretListener(new CaretHandler(brailleText, asciiText)); asciiText.addCaretListener(new CaretHandler(asciiText, brailleText)); currentText = brailleText; }
public StatusLine(StyledText textWidget) { this.parent = textWidget; parent.addPaintListener(this); }