private void internalSetCaretListener(OnValueChanged<Integer> l) { getStyledText().addCaretListener(new CaretListener() { @Override public void caretMoved(CaretEvent event) { l.notify(event.caretOffset); } }); }
protected void initCaretListener() { CaretListener caretListener = new CaretListener() { @Override public void caretMoved(CaretEvent event) { logger.trace("caret moved = "+event.caretOffset+" selection (old) = "+text.getSelection()); // updateLineAndWordObjects(); } }; addUserCaretListener(caretListener); }
public void addUserCaretListener(CaretListener l) { caretListener.add(l); text.addCaretListener(l); }
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (part != null) { Class c = part.getClass(); if (c.getName().equals("org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor")) { IEditorPart editor = (IEditorPart) part; final StyledText st = (StyledText) editor.getAdapter(Control.class); Listener[] ls = st.getListeners(SWT.None); if (st.getListeners(SWT.None).length==0){ st.addCaretListener(new CaretListener() { @Override public void caretMoved(CaretEvent event) { // TODO Auto-generated method stub System.out.println("SOY EL CARACTER DEL CODIGO: " + event.caretOffset); int nextCaretWithNode = event.caretOffset; ArrayList<JavaMarioNode> node = null; while (node == null && nextCaretWithNode<st.getCharCount()) node = visitor.hm.get(++nextCaretWithNode); if (node!=null) { System.out.println("SOY EL MARIONODE ASOCIADO: " + node.get(0) + ", x="+node.get(0).rectangle.x+" y="+node.get(0).rectangle.y); if (!node.get(0).rectangle.isEmpty()) { marioX = node.get(0).rectangle.x*16; marioY = drawingBox.height - node.get(0).rectangle.y*16-maryoImg.getBounds().height; myCanvas.redraw(); } } } }); } IEditorInput input = editor.getEditorInput(); System.out.println("Evento de selecci�n sobre un editor java"); System.out.println("IWortkbenchPart = "+c.getName()); System.out.println("IEditorInput = "+input.getName()); System.out.println("----------------CONTENT-----------------"); System.out.println("----------------------------------------"); } } System.out.println(getSite().getPage().getEditorReferences().length+" editores abiertos."); action1.run(); }
@Override public Control construct(Composite parent) { Composite composite = new Composite(parent, SWT.BORDER); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(composite); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL) .grab(true, true).applyTo(composite); Display display = composite.getDisplay(); Color green = new Color(composite.getDisplay(), new RGB(0, 255, 0)); Color red = new Color(composite.getDisplay(), new RGB(255, 0, 0)); StyledText t1 = new StyledText(composite, SWT.SINGLE | SWT.BORDER); t1.setLayoutData(new GridData(GridData.FILL_BOTH)); t1.setText("SINGLE, Green Background"); t1.setBackground(green); StyledText t2 = new StyledText(composite, SWT.FULL_SELECTION | SWT.BORDER); t2.setLayoutData(new GridData(GridData.FILL_BOTH)); t2.setText("Full_Selection, Red Foreground"); t2.setForeground(red); StyledText t3 = new StyledText(composite, SWT.MULTI | SWT.BORDER); t3.setLayoutData(new GridData(GridData.FILL_BOTH)); t3.setText("MULTI, Style Range is applied"); StyleRange styleRange = new StyleRange(); styleRange.start = 0; styleRange.length = t3.getText().length(); styleRange.fontStyle = SWT.BOLD; styleRange.foreground = display.getSystemColor(SWT.COLOR_BLUE); t3.setStyleRange(styleRange); StyledText t4 = new StyledText(composite, SWT.READ_ONLY | SWT.BORDER); t4.setLayoutData(new GridData(GridData.FILL_BOTH)); t4.setText("READ ONLY"); StyleRange styleRange2 = new StyleRange(); styleRange2.start = 5; styleRange2.length = t4.getText().length() - 5; styleRange2.fontStyle = SWT.ITALIC; styleRange2.foreground = display.getSystemColor(SWT.COLOR_MAGENTA); t4.setStyleRange(styleRange2); StyledText t5 = new StyledText(composite, SWT.WRAP | SWT.BORDER); t5.setLayoutData(new GridData(GridData.FILL_BOTH)); t5.setText("WRAP"); StyledText t6 = new StyledText(composite, SWT.MULTI | SWT.BORDER); t6.setLayoutData(new GridData(GridData.FILL_BOTH)); t6.setText("This is a text for testing Caret Offset"); CaretListener caretListener = new CaretListener() { @Override public void caretMoved(CaretEvent event) { Shell shell = event.widget.getDisplay().getActiveShell(); MessageDialog.openInformation(shell, "Info", "Info for you"); } }; t6.addCaretListener(caretListener); StyledText tMouseDown = new StyledText(composite, SWT.MULTI | SWT.BORDER); tMouseDown.setLayoutData(new GridData(GridData.FILL_BOTH)); tMouseDown.setText("Handler on mouse down Listener"); tMouseDown.addMouseListener(new StyledTextMouseDownHandler()); StyledText tArgument = new StyledText(composite, SWT.MULTI | SWT.BORDER); tArgument.setLayoutData(new GridData(GridData.FILL_BOTH)); tArgument.setText("Custom Argument Handler on mouse with case e.button=SWT.KeyDown"); @SuppressWarnings("unused") ArgumentHandler argumentHandler = new ArgumentHandler(tArgument); StyledText tMouseUp = new StyledText(composite, SWT.MULTI | SWT.BORDER); tMouseUp.setLayoutData(new GridData(GridData.FILL_BOTH)); tMouseUp.setText("Handler on mouse up Listener"); tMouseUp.addMouseListener(new StyledTextMouseUpHandler()); return null; }