当前位置: 首页>>代码示例>>Java>>正文


Java JTextComponent类代码示例

本文整理汇总了Java中javax.swing.text.JTextComponent的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent类的具体用法?Java JTextComponent怎么用?Java JTextComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JTextComponent类属于javax.swing.text包,在下文中一共展示了JTextComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public void actionPerformed(final ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument)target.getDocument();
        doc.render(new Runnable () {
            public void run () {
                DocumentUtilities.setTypingModification(doc, true);
                try {
                    int dotPos = caret.getDot();
                    int bolPos = Utilities.getRowStart(target, dotPos);
                    int eolPos = Utilities.getRowEnd(target, dotPos);
                    eolPos = Math.min(eolPos + 1, doc.getLength()); // include '\n'
                    caret.setDot(bolPos);
                    caret.moveDot(eolPos);
                } catch (BadLocationException e) {
                    target.getToolkit().beep();
                } finally {
                    DocumentUtilities.setTypingModification(doc, false);
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BaseKit.java

示例2: showPopupMenu

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public void showPopupMenu(int x, int y) {
    // First call the build-popup-menu action to possibly rebuild the popup menu
    JTextComponent c = getComponent();
    if (c != null) {
        BaseKit kit = Utilities.getKit(c);
        if (kit != null) {
            Action a = kit.getActionByName(ExtKit.buildPopupMenuAction);
            if (a != null) {
                a.actionPerformed(new ActionEvent(c, 0, "")); // NOI18N
            }
        }

        JPopupMenu pm = getPopupMenu();
        if (pm != null) {
            if (c.isShowing()) { // fix of #18808
                if (!c.isFocusOwner()) {
                    c.requestFocus();
                }
                pm.show(c, x, y);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EditorUI.java

示例3: saveAs

import javax.swing.text.JTextComponent; //导入依赖的package包/类
private boolean saveAs( Component comp ) {
    if( comp == null ) return false;
    JTextComponent edit = (JTextComponent)com2text.get( comp );
    File file = (File)edit.getDocument().getProperty( FILE );
    
    fileChooser.setCurrentDirectory( file.getParentFile() );
    fileChooser.setSelectedFile( file );
    KitInfo fileInfo = KitInfo.getKitInfoOrDefault( file );
    
    if( fileInfo != null ) fileChooser.setFileFilter( fileInfo );
    
    // show the dialog, test the result
    if( fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
        return saveFile( comp, fileChooser.getSelectedFile(), true );
    else
        return false; // Cancel was pressed - not saved
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Editor.java

示例4: setStatusText

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public static void setStatusText(JTextComponent c, String text) {
        // TODO: fix this, do not use reflection
        try {
            Object editorUI = getEditorUI(c);
            if (editorUI == null) {
                c.putClientProperty(STATUS_BAR_TEXT_PROPERTY, text);
                return;
            }
            Method getSbMethod = editorUI.getClass().getMethod("getStatusBar");
            Object statusBar = getSbMethod.invoke(editorUI);
            Method setTextMethod = statusBar.getClass().getMethod("setText", String.class, String.class);
            setTextMethod.invoke(statusBar, "main", text);
        } catch (Exception e) {
            LOG.log(Level.WARNING, e.getMessage(), e);
        }
//        StatusBar sb = getEditorUI(c).getStatusBar();
//        if (sb != null) {
//            sb.setText(StatusBar.CELL_MAIN, text);
//        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ComponentUtils.java

示例5: defaultAction

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public void defaultAction(JTextComponent component) {
    if (component != null) {
        Completion.get().hideDocumentation();
        Completion.get().hideCompletion();
        
        StringBuilder sb = new StringBuilder();
        sb.append(this.name);
        if (this.paramTypes.length == 0) {
            sb.append("() "); // NOI18N
        } else {
            sb.append('(');
            for (String pt : paramTypes) {
                sb.append(pt).append(", "); // NOI18N
            }
            sb.setCharAt(sb.length() - 2, ')');
        }
        
        complete(component, sb.toString(), substitutionOffset);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavadocCompletionItem.java

示例6: getLineFromMouseEvent

import javax.swing.text.JTextComponent; //导入依赖的package包/类
private int getLineFromMouseEvent(MouseEvent e){
    int line = -1;
    EditorUI eui = editorUI;
    if (eui != null) {
        try{
            JTextComponent component = eui.getComponent();
            BaseDocument document = eui.getDocument();
            BaseTextUI textUI = (BaseTextUI)component.getUI();
            int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
            line = Utilities.getLineOffset(document, clickOffset);
        }catch (BadLocationException ble) {
            LOG.log(Level.WARNING, null, ble);
        }
    }
    return line;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:GlyphGutter.java

示例7: MasterMatcher

import javax.swing.text.JTextComponent; //导入依赖的package包/类
private MasterMatcher(JTextComponent component) {
    this.component = component;
    if (component != null) {
        component.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if ("document".equals(evt.getPropertyName())) {
                    synchronized (LOCK) {
                        // Cancel any pending task and clear the lastResult
                        if (task != null) {
                            task.cancel();
                            task = null;
                        }
                        if (lastResult != null) {
                            lastResult.cancel();
                            lastResult = null; // Prevent memory leak upon document change
                        }
                    }
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:MasterMatcher.java

示例8: instantSubstitution

import javax.swing.text.JTextComponent; //导入依赖的package包/类
@Override
public boolean instantSubstitution(JTextComponent component) {
    ElementKind kind = item.getKind();
    if (kind == ElementKind.PARAMETER || kind == ElementKind.CLASS || kind == ElementKind.MODULE) {
        // These types of elements aren't ever instant substituted in Java - use same behavior here
        return false;
    }

    if (component != null) {
        try {
            int caretOffset = component.getSelectionEnd();
            if (caretOffset > substitutionOffset) {
                String text = component.getDocument().getText(substitutionOffset, caretOffset - substitutionOffset);
                if (!getInsertPrefix().toString().startsWith(text)) {
                    return false;
                }
            }
        }
        catch (BadLocationException ble) {}
    }
    defaultAction(component);
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:GsfCompletionItem.java

示例9: getVisibleCharacterRange

import javax.swing.text.JTextComponent; //导入依赖的package包/类
static int[] getVisibleCharacterRange(final Accessible a) {
    final Accessible sa = CAccessible.getSwingAccessible(a);
    if (!(sa instanceof JTextComponent)) return null;

    final JTextComponent jc = (JTextComponent) sa;
    final Rectangle rect = jc.getVisibleRect();
    final Point topLeft = new Point(rect.x, rect.y);
    final Point topRight = new Point(rect.x + rect.width, rect.y);
    final Point bottomLeft = new Point(rect.x, rect.y + rect.height);
    final Point bottomRight = new Point(rect.x + rect.width, rect.y + rect.height);

    int start = Math.min(jc.viewToModel(topLeft), jc.viewToModel(topRight));
    int end = Math.max(jc.viewToModel(bottomLeft), jc.viewToModel(bottomRight));
    if (start < 0) start = 0;
    if (end < 0) end = 0;
    return new int[] { start, end };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:CAccessibleText.java

示例10: register

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public void register(BaseDocument document) {
    this.document = document;
    
    JTextComponent pane = paneRef.get();
    if (pane != null) {
        gatherProviders(pane);
    }
    
    if (document != null) {
        if (weakL == null) {
            weakL = WeakListeners.create(Annotations.AnnotationsListener.class, this, document.getAnnotations());
            document.getAnnotations().addAnnotationsListener(weakL);
        }
    }
    
    clear();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AnnotationViewDataImpl.java

示例11: TextComponentPrintable

import javax.swing.text.JTextComponent; //导入依赖的package包/类
/**
 * Constructs  {@code TextComponentPrintable} to print {@code JTextComponent}
 * {@code textComponent} with {@code headerFormat} and {@code footerFormat}.
 *
 * @param textComponent {@code JTextComponent} to print
 * @param headerFormat the page header or {@code null} for none
 * @param footerFormat the page footer or {@code null} for none
 */
private TextComponentPrintable(JTextComponent textComponent,
        MessageFormat headerFormat,
        MessageFormat footerFormat) {
    this.textComponentToPrint = textComponent;
    this.headerFormat = headerFormat;
    this.footerFormat = footerFormat;
    headerFont = textComponent.getFont().deriveFont(Font.BOLD,
        HEADER_FONT_SIZE);
    footerFont = textComponent.getFont().deriveFont(Font.PLAIN,
        FOOTER_FONT_SIZE);
    this.pagesMetrics =
        Collections.synchronizedList(new ArrayList<IntegerSegment>());
    this.rowsMetrics = new ArrayList<IntegerSegment>(LIST_SIZE);
    this.printShell = createPrintShell(textComponent);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TextComponentPrintable.java

示例12: initInputVerifiers

import javax.swing.text.JTextComponent; //导入依赖的package包/类
private void initInputVerifiers () {
    InputVerifier iv = new InputVerifier() {
        @Override
        public boolean verify (JComponent input) {
            if (input == panel.startRevisionTextField || input == panel.endRevisionTextField || input == panel.oneRevisionTextField) {
                JTextComponent comp = (JTextComponent) input;
                if (comp.getText().trim().isEmpty()) {
                    comp.setText(SVNRevision.HEAD.toString());
                }
            }
            return true;
        }
    };
    panel.startRevisionTextField.setInputVerifier(iv);
    panel.endRevisionTextField.setInputVerifier(iv);
    panel.oneRevisionTextField.setInputVerifier(iv);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:RevertModifications.java

示例13: delegates

import javax.swing.text.JTextComponent; //导入依赖的package包/类
protected boolean delegates(JTextComponent target) {
    ConsoleModel model = ConsoleModel.get(target.getDocument());
    if (model == null) {
        return true;
    }
    ConsoleSection input = model.getInputSection();
    if (input == null) {
        return true;
    }
    int offset = target.getCaretPosition();
    if (offset < input.getPartBegin() || offset > input.getEnd()) {
        return true;
    }
    Document doc = target.getDocument();
    
    LineDocument ld = LineDocumentUtils.as(doc, LineDocument.class);
    if (ld == null) {
        return true;
    }
    try {
        int end = LineDocumentUtils.getLineEnd(ld, input.getPartBegin());
        return offset > end;
    } catch (BadLocationException ex) {
        return true;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:OverrideEditorActions.java

示例14: FoldHierarchyTransactionImpl

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public FoldHierarchyTransactionImpl(FoldHierarchyExecution execution, boolean suppressEvents) {
    this.execution = execution;
    this.affectedStartOffset = -1;
    this.affectedEndOffset = -1;
    this.suppressEvents = suppressEvents;
    
    this.transaction = SpiPackageAccessor.get().createFoldHierarchyTransaction(this);
    this.dmgCounter = execution.getDamagedCount();
    if (dmgCounter > 0) {
        String t = null;
        JTextComponent comp = execution.getComponent();
        if (comp != null) {
            Document doc = comp.getDocument();
            try {
                t = doc.getText(0, doc.getLength());
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        if (debugFoldHierarchy) {
            initialSnapshot = execution.toString() + 
                              "\nContent at previous commit:\n====\n" + execution.getCommittedContent() + "\n====\n" +
                              "\nText content:\n====\n" + t + "\n====\n";
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:FoldHierarchyTransactionImpl.java

示例15: actionPerformed

import javax.swing.text.JTextComponent; //导入依赖的package包/类
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    final JavaSource js = JavaSource.forDocument(target.getDocument());
    
    if (js == null) {
        StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToSupport.class, "WARN_CannotGoToGeneric",1));
        return;
    }
    
    final int caretPos = target.getCaretPosition();
    final AtomicBoolean cancel = new AtomicBoolean();
    
    ProgressUtils.runOffEventDispatchThread(new Runnable() {
        @Override
        public void run() {
            goToImpl(target, js, caretPos, cancel);
        }
    }, NbBundle.getMessage(JavaKit.class, "goto-super-implementation"), cancel, false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:GoToSuperTypeAction.java


注:本文中的javax.swing.text.JTextComponent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。