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


Java JTextComponent.isEnabled方法代码示例

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


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

示例1: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        final BaseDocument doc = (BaseDocument)target.getDocument();
        doc.runAtomicAsUser (new Runnable () {
            public void run () {
                DocumentUtilities.setTypingModification(doc, true);
                try {
                    target.replaceSelection(null);
                } finally {
                    DocumentUtilities.setTypingModification(doc, false);
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ActionFactory.java

示例2: paint

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, Shape a) {
    ((Graphics2D) g).addRenderingHints(getHints());

    Container container = getContainer();
    if (container instanceof JTextComponent) {
        final JTextComponent textComp = (JTextComponent) container;
        selStart = textComp.getSelectionStart();
        selEnd = textComp.getSelectionEnd();
        unselectedFg = textComp.isEnabled()
                ? textComp.getForeground()
                : textComp.getDisabledTextColor();
        selectedFg = textComp.getCaret().isSelectionVisible()
                ? textComp.getSelectedTextColor()
                : unselectedFg;
    }
    super.paint(g, a);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:OutputView.java

示例3: show

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void show(Component invoker, int x, int y) {
	JTextComponent tc = (JTextComponent) invoker;
	String sel = tc.getSelectedText();

	boolean selected = sel != null && !sel.equals("");
	boolean enableAndEditable = tc.isEnabled() && tc.isEditable();

	cutItem.setEnabled(selected && enableAndEditable);
	copyItem.setEnabled(selected && tc.isEnabled());
	deleteItem.setEnabled(selected && enableAndEditable);
	pasteItem.setEnabled(enableAndEditable);
	selectAllItem.setEnabled(tc.isEnabled());

	super.show(invoker, x, y);
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:16,代码来源:TextComponentPopupMenu.java

示例4: getStateFor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
protected static State getStateFor(final JTextComponent jc) {
    if (!AquaFocusHandler.isActive(jc)) {
        return State.INACTIVE;
    }

    if (!jc.isEnabled()) {
        return State.DISABLED;
    }

    if (!jc.isEditable()) {
        return State.DISABLED;
    }

    return State.ACTIVE;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:AquaTextFieldBorder.java

示例5: mousePressed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Overridden to also focus the text component on right mouse clicks.
 *
 * @param e The mouse event.
 */
@Override
public void mousePressed(MouseEvent e) {
	super.mousePressed(e);
	if (!e.isConsumed() && SwingUtilities.isRightMouseButton(e)) {
		JTextComponent c = getComponent();
		if (c!=null && c.isEnabled() && c.isRequestFocusEnabled()) {
			c.requestFocusInWindow();
		}
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:16,代码来源:ConfigurableCaret.java

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (!target.isEditable() || !target.isEnabled()) {
        target.getToolkit().beep();
        return;
    }
    final BaseDocument doc = (BaseDocument) target.getDocument();
    final Indent indenter = Indent.get(doc);
    final class R implements Runnable {
        public @Override void run() {
            try {
                Caret caret = target.getCaret();
                int dotpos = caret.getDot();
                int eoloffset = Utilities.getRowEnd(target, dotpos);
                doc.insertString(eoloffset, "" + what, null); //NOI18N
                if (withNewline) {
                    //This is code from the editor module, but it is
                    //a pretty strange way to do this:
                    doc.insertString(dotpos, "-", null); //NOI18N
                    doc.remove(dotpos, 1);
                    int eolDot = Utilities.getRowEnd(target, caret.getDot());
                    int newDotPos = indenter.indentNewLine(eolDot);
                    caret.setDot(newDotPos);
                }
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    indenter.lock();
    try {
        doc.runAtomicAsUser(new R());
    } finally {
        indenter.unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:InsertSemicolonAction.java

示例7: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }
        BaseDocument doc = (BaseDocument)target.getDocument();
        StringBuffer sb = new StringBuffer("System.err.println(\""); // NOI18N
        File file = (File)doc.getProperty( "file" );
        if (file != null) {
            sb.append( file.getAbsolutePath() );
            sb.append(':');
        }
        try {
            sb.append(Utilities.getLineOffset(doc, target.getCaret().getDot()) + 1);
        } catch (BadLocationException e) {
        }
        sb.append(' ');

        BaseKit kit = Utilities.getKit(target);
        Action a = kit.getActionByName(BaseKit.insertContentAction);
        if (a != null) {
            Utilities.performAction(
                a,
                new ActionEvent(target, ActionEvent.ACTION_PERFORMED, sb.toString()),
                target
            );
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:JavaKit.java

示例8: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(final ActionEvent evt, final JTextComponent component) {
    if (component == null || !component.isEditable() || !component.isEnabled()) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    final BaseDocument doc = (BaseDocument) component.getDocument();
    final Source source = Source.create(doc);
    if (source != null) {
        final AtomicBoolean cancel = new AtomicBoolean();
        ProgressUtils.runOffEventDispatchThread(new Runnable() {
            @Override
            public void run() {
                try {
                    ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() {
                        @Override
                        public void run(ResultIterator resultIterator) throws Exception {
                            WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
                            copy.toPhase(Phase.RESOLVED);
                            doOrganizeImports(copy, false);
                        }
                    }).commit();
                } catch (Exception ex) {
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }, NbBundle.getMessage(OrganizeImports.class, "MSG_OragnizeImports"), cancel, false); //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:OrganizeImports.java

示例9: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(final ActionEvent evt, final JTextComponent target) {
    BaseKit.InsertTabAction insertTabAction = new BaseKit.InsertTabAction();
    insertTabAction.actionPerformed(evt, target);
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }
        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument) target.getDocument();
        doc.runAtomic(new TabReplacer(doc, caret.getDot()));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:InsertTabAction.java

示例10: setEditedComponent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
void setEditedComponent(Component comp, String text) {
    if (!comp.isShowing() || comp.getParent() == null)
        throw new IllegalArgumentException();

    editedComp = comp;
    editedText = text;
    if (inPlaceField != null) {
        remove(inPlaceField);
        inPlaceField = null;
    }

    if (comp instanceof JLabel || comp instanceof AbstractButton || comp instanceof JTabbedPane) {
        layerEditing = true;
        superContainer = null;
        createInPlaceField();
    }
    else if (comp instanceof JTextField || comp instanceof JTextArea) {
        layerEditing = false;
        superContainer = comp.getParent();

        Container cont = superContainer;
        do {
            if (cont.getParent() instanceof JLayeredPane) {
                superContainer = cont;
                break;
            }
            else cont = cont.getParent();
        }
        while (cont != null);

        editingTextComp = (JTextComponent)editedComp;
        oldText = editingTextComp.getText();
        editingTextComp.setText(editedText);

        // enable focus on component in component layer
        editingTextComp.setFocusable(true);
        if (!editingTextComp.isEnabled()) {
            editingTextComp.setEnabled(true);
            enabled = true;
        }
        if (!editingTextComp.isEditable()) {
            editingTextComp.setEditable(true);
            madeEditable = true;
        }
    }
    else throw new IllegalArgumentException();

    if (editingTextComp != null) {
        FormUtils.setupTextUndoRedo(editingTextComp);
    }

    attachListeners();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:InPlaceEditLayer.java

示例11: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(final ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        final BaseDocument doc = (BaseDocument)target.getDocument();
        final Caret caret = target.getCaret();

        final Indent formatter = Indent.get(doc);
        formatter.lock();
        try {
            doc.runAtomicAsUser (new Runnable () {
                public void run () {
                    DocumentUtilities.setTypingModification(doc, true);
                    try{
                        target.replaceSelection(""); //NOI18N

                        // insert new line, caret stays where it is
                        int dotPos = caret.getDot();
                        doc.insertString(dotPos, "\n", null); //NOI18N

                        // reindent the new line
                        formatter.reindent(dotPos + 1);   // newline

                        // make sure the caret stays on its original position
                        caret.setDot(dotPos);
                    } catch (GuardedException e) {
                        target.getToolkit().beep();
                    } catch (BadLocationException ble) {
                        LOG.log(Level.WARNING, null, ble);
                    } finally {
                        DocumentUtilities.setTypingModification(doc, false);
                    }
                }
            });
        } finally {
            formatter.unlock();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:BaseKit.java

示例12: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target == null) return;
    if (!target.isEditable() || !target.isEnabled()) {
        problem(null);
        return;
    }
    Caret caret = target.getCaret();
    BaseDocument doc = (BaseDocument)target.getDocument();
    try {
        if (caret.isSelectionVisible()) {
            int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
            int endPos = target.getSelectionEnd();
            doc.atomicLock();
            try {

                if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
                    endPos--;
                }

                int pos = startPos;
                int lineCnt = Utilities.getRowCount(doc, startPos, endPos);                            

                for (;lineCnt > 0; lineCnt--) {
                    doc.insertString(pos, commentStartString, null); 
                    doc.insertString(Utilities.getRowEnd(doc,pos), commentEndString, null);
                    pos = Utilities.getRowStart(doc, pos, +1);
                }

            } finally {
                doc.atomicUnlock();
            }
        } else { // selection not visible
            doc.insertString(Utilities.getRowStart(doc, target.getSelectionStart()),
                commentStartString, null);
            doc.insertString(Utilities.getRowEnd(doc, target.getSelectionStart()),
                commentEndString, null);
        }
    } catch (BadLocationException e) {
        problem(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:XMLKit.java

示例13: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(final ActionEvent evt, final JTextComponent component) {
    if (component == null || !component.isEditable() || !component.isEnabled()) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    final BaseDocument doc = (BaseDocument) component.getDocument();
    final Source source = Source.create(doc);
    if (source != null) {
        final AtomicBoolean cancel = new AtomicBoolean();
        ProgressUtils.runOffEventDispatchThread(new Runnable() {
            @Override
            public void run() {
                try {
                    ModificationResult result = ModificationResult.runModificationTask(Collections.singleton(source), new UserTask() {
                        @Override
                        public void run(ResultIterator resultIterator) throws Exception {
                            WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult());
                            copy.toPhase(Phase.RESOLVED);
                            TreeUtilities tu = copy.getTreeUtilities();
                            TreePath path = tu.pathFor(component.getCaretPosition());
                            path = tu.getPathElementOfKind(EnumSet.of(Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.ANNOTATION_TYPE), path);
                            if (path != null) {
                                doOrganizeMembers(copy, path);
                            } else {
                                CompilationUnitTree cut = copy.getCompilationUnit();
                                List<? extends Tree> typeDecls = cut.getTypeDecls();
                                if (typeDecls.isEmpty()) {
                                    Toolkit.getDefaultToolkit().beep();
                                } else {
                                    doOrganizeMembers(copy, copy.getTrees().getPath(cut, typeDecls.get(0)));
                                }
                            }
                        }
                    });
                    List<? extends Difference> diffs = result.getDifferences(source.getFileObject());
                    if (diffs != null && !diffs.isEmpty() && !checkGuarded(doc, diffs)) {
                        result.commit();
                    } else {
                        Toolkit.getDefaultToolkit().beep();
                    }
                } catch (Exception ex) {
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }, NbBundle.getMessage(OrganizeMembers.class, "MSG_OragnizeMembers"), cancel, false); //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:OrganizeMembers.java

示例14: canImport

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * This method indicates if a component would accept an import of the
 * given set of data flavors prior to actually attempting to import it.
 *
 * @param comp The component to receive the transfer.  This argument is
 *        provided to enable sharing of TransferHandlers by multiple
 *        components.
 * @param flavors The data formats available.
 * @return <code>true</code> iff the data can be inserted.
 */
@Override
public boolean canImport(JComponent comp, DataFlavor[] flavors) {
	JTextComponent c = (JTextComponent)comp;
	if (!(c.isEditable() && c.isEnabled())) {
		return false;
	}
	return (getImportFlavor(flavors, c) != null);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:19,代码来源:RTATextTransferHandler.java


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