List of usage examples for javax.swing.text JTextComponent isEnabled
public boolean isEnabled()
From source file:FormattedTextFieldExample.java
protected void drawLine(int line, Graphics g, int x, int y) { // Set the colors JTextComponent host = (JTextComponent) getContainer(); unselected = (host.isEnabled()) ? host.getForeground() : host.getDisabledTextColor(); Caret c = host.getCaret();//ww w.j a v a 2 s . com selected = c.isSelectionVisible() ? host.getSelectedTextColor() : unselected; int p0 = element.getStartOffset(); int p1 = element.getEndOffset() - 1; int sel0 = ((JTextComponent) getContainer()).getSelectionStart(); int sel1 = ((JTextComponent) getContainer()).getSelectionEnd(); try { // If the element is empty or there is no selection // in this view, just draw the whole thing in one go. if (p0 == p1 || sel0 == sel1 || inView(p0, p1, sel0, sel1) == false) { drawUnselectedText(g, x, y, 0, contentBuff.count); return; } // There is a selection in this view. Draw up to three regions: // (a) The unselected region before the selection. // (b) The selected region. // (c) The unselected region after the selection. // First, map the selected region offsets to be relative // to the start of the region and then map them to view // offsets so that they take into account characters not // present in the model. int mappedSel0 = mapOffset(Math.max(sel0 - p0, 0)); int mappedSel1 = mapOffset(Math.min(sel1 - p0, p1 - p0)); if (mappedSel0 > 0) { // Draw an initial unselected region x = drawUnselectedText(g, x, y, 0, mappedSel0); } x = drawSelectedText(g, x, y, mappedSel0, mappedSel1); if (mappedSel1 < contentBuff.count) { drawUnselectedText(g, x, y, mappedSel1, contentBuff.count); } } catch (BadLocationException e) { // Should not happen! } }
From source file:org.fife.ui.rtextarea.RTATextTransferHandler.java
/** * 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.// w ww. j ava2 s . c o m * @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); }