Java 类org.eclipse.swt.custom.CaretEvent 实例源码

项目:visuflow-plugin    文件:UnitBreakpointPropertiesDialog.java   
@Override
public void caretMoved(CaretEvent event) {
    int offset = event.caretOffset;
    int line = unitSelectionArea.getLineAtOffset(offset);
    if (line % 2 == 0) {
        String lineContent = unitSelectionArea.getLine(line);
        if (!lineContent.trim().isEmpty()) {
            // remove previous selection
            int lineCount = unitSelectionArea.getLineCount();
            unitSelectionArea.setLineBackground(0, lineCount, null);

            // set the new selection
            unitSelectionArea.setLineBackground(line, 1, lineHighlight);

            int unitIndex = line / 2;
            selectedUnit = selectedMethod.getUnits().get(unitIndex);
        }
    }
}
项目:egradle    文件:AbstractGroovyBasedEditor.java   
@Override
public void caretMoved(CaretEvent event) {
    if (event == null) {
        return;
    }
    lastCaretPosition = event.caretOffset;
    if (EclipseDevelopmentSettings.DEBUG_ADD_SPECIAL_TEXTS) {
        setStatusLineMessage("caret moved:" + event.caretOffset);
    }
    if (ignoreNextCaretMove) {
        ignoreNextCaretMove = false;
        return;
    }
    if (outlinePage == null) {
        return;
    }
    outlinePage.onEditorCaretMoved(event.caretOffset);
}
项目:bts    文件:BTSTextSelectionEvent.java   
public BTSTextSelectionEvent(TypedEvent event, BTSObject parentObject) {
    this.setOriginalEvent(event);
    this.display = event.display;
    this.widget = event.widget;
    this.time = event.time;
    if (event instanceof CaretEvent)
    {
        this.x = ((CaretEvent)event).caretOffset;
        this.y = ((CaretEvent)event).caretOffset;
    }
    else if (event instanceof SelectionEvent)
    {
        this.x = ((SelectionEvent)event).x;
        this.y = ((SelectionEvent)event).y;
        this.text = ((SelectionEvent)event).text;

    }
    this.setParentObject(parentObject);
}
项目:eclipse-batch-editor    文件:BatchEditor.java   
@Override
public void caretMoved(CaretEvent event) {
    if (event == null) {
        return;
    }
    lastCaretPosition = event.caretOffset;
    if (ignoreNextCaretMove) {
        ignoreNextCaretMove = false;
        return;
    }
    if (outlinePage == null) {
        return;
    }
    outlinePage.onEditorCaretMoved(event.caretOffset);
}
项目:eclipse-bash-editor    文件:BashEditor.java   
@Override
public void caretMoved(CaretEvent event) {
    if (event == null) {
        return;
    }
    lastCaretPosition = event.caretOffset;
    if (ignoreNextCaretMove) {
        ignoreNextCaretMove = false;
        return;
    }
    if (outlinePage == null) {
        return;
    }
    outlinePage.onEditorCaretMoved(event.caretOffset);
}
项目:ftc    文件:FtcEditor.java   
private void internalSetCaretListener(OnValueChanged<Integer> l) {
    getStyledText().addCaretListener(new CaretListener() {

        @Override
        public void caretMoved(CaretEvent event) {
            l.notify(event.caretOffset);
        }
    });
}
项目:TranskribusSwtGui    文件:ATranscriptionWidget.java   
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);
    }
项目:tlaplus    文件:GotoMatchingParenHandler.java   
public void caretMoved(CaretEvent event) {
    // TODO Auto-generated method stub
    editor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(
            null);
    editor.getViewer().getTextWidget().removeCaretListener(this);
    try {
     resource.deleteMarkers(PAREN_ERROR_MARKER_TYPE, false, 99);
 } catch (CoreException e) {
     // TODO Auto-generated catch block
     System.out.println("caretMoved threw exception");
 }

}
项目:eclipse-wakatime    文件:CustomCaretListener.java   
@Override
public void caretMoved(CaretEvent event) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) return;
    if (window.getPartService() == null) return;
    if (window.getPartService().getActivePart() == null) return;
    if (window.getPartService().getActivePart().getSite() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

    // log file if one is opened by default
    IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
    if (input instanceof IURIEditorInput) {
        URI uri = ((IURIEditorInput)input).getURI();
        if (uri != null && uri.getPath() != null) {
            String currentFile = uri.getPath();
            long currentTime = System.currentTimeMillis() / 1000;
            if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
项目:tlaplus    文件:ProofFoldAction.java   
public void caretMoved(CaretEvent event)
{
    update();
}
项目:bts    文件:EgyTextEditorPart.java   
/**
 * Process text selection.
 *
 * @param event the event
 */
protected void processTextSelection(TypedEvent event) {
    BTSTextSelectionEvent btsEvent = new BTSTextSelectionEvent(event, text);
    btsEvent.data = text;
    if (this.delaySelectionJob == null) {
        this.btsTextEvent = btsEvent;
        Job.getJobManager().cancel(BTSTextSelectionEvent.class);
        delaySelectionJob = new Job("delay_selection_processing"){
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                while (System.nanoTime() < lastSelectionTimeStamp + 350000000)
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        return Status.CANCEL_STATUS;
                    }
                final BTSTextSelectionEvent btsEvent = btsTextEvent;
                sync.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        List<BTSModelAnnotation> annotations = getModelAnnotationAtSelection(
                                btsEvent.x, btsEvent.y, btsEvent);                          
                        btsEvent.getTextAnnotations().addAll(annotations);
                        processSelection(annotations, false, btsEvent);
                        selectionService.setSelection(btsEvent);

                    }
                });
                delaySelectionJob = null;
                return Status.OK_STATUS;
            }
            @Override
            public boolean belongsTo(Object family) {
                return family.equals(BTSTextSelectionEvent.class);
            }
        };
        this.delaySelectionJob.schedule(400);
    } else if (!(event instanceof CaretEvent) || (this.btsTextEvent == null)
        || (this.btsTextEvent.getOriginalEvent() instanceof CaretEvent))
        this.btsTextEvent = btsEvent;
    this.lastSelectionTimeStamp = System.nanoTime();
}
项目:BrailleZephyr    文件:BZStyledText.java   
@Override
public void caretMoved(CaretEvent ignored)
{
    int caretOffset = source.getCaretOffset();
    int lineIndex = source.getLineAtOffset(caretOffset);
    int lineOffset = source.getOffsetAtLine(lineIndex);

    //   play line margin bell
    if(lineMarginClip != null && lineMarginBell > 0 && caretOffset == prevCaretOffset + 1)
    {
        if(caretOffset - lineOffset == lineMarginBell)
        if(!lineMarginClip.isActive())
        {
            lineMarginClip.setFramePosition(0);
            lineMarginClip.start();
        }
    }

    //   play line end bell
    if(lineEndClip != null && charsPerLine > 0 && caretOffset == prevCaretOffset + 1)
    {
        if(caretOffset - lineOffset == charsPerLine)
            if(!lineEndClip.isActive())
            {
                lineEndClip.setFramePosition(0);
                lineEndClip.start();
            }
    }

    prevCaretOffset = caretOffset;

    //   scroll other text to match current
    if(lineIndex == prevLineIndex)
        return;
    prevLineIndex = lineIndex;
    if(source != currentText)
        return;

    int sourceLinePixel = source.getLinePixel(lineIndex);
    int sourceHeight = source.getClientArea().height;
    int sourceLineHeight = source.getLineHeight();

    //   check if have to wait until after paint event
    if(sourceLinePixel < 0 || sourceLinePixel + sourceLineHeight > sourceHeight)
        adjustOtherThread.waitPainted(source, other);
    else
        adjustOtherThread.adjustOther(source, other);
}
项目:Progamer    文件:ProgamerMainView.java   
@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();
}
项目:q7.quality.mockups    文件:Styled_Text.java   
@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;

}