public void focusGained(FocusEvent event) { QuaquaUtilities.repaintBorder((JComponent) event.getComponent()); final JTextComponent tc = (JTextComponent) event.getSource(); if (tc.isEditable() && tc.isEnabled()) { String uiProperty; if (tc instanceof JPasswordField) { uiProperty = "PasswordField.autoSelect"; } else if (tc instanceof JFormattedTextField) { uiProperty = "FormattedTextField.autoSelect"; } else { uiProperty = "TextField.autoSelect"; } if (tc.getClientProperty("Quaqua.TextComponent.autoSelect") == Boolean.TRUE || tc.getClientProperty("Quaqua.TextComponent.autoSelect") == null && UIManager.getBoolean(uiProperty)) { if (event instanceof CausedFocusEvent) { CausedFocusEvent cfEvent = (CausedFocusEvent) event; if (cfEvent.getCause() == Cause.TRAVERSAL_FORWARD || cfEvent.getCause() == Cause.TRAVERSAL_BACKWARD) { tc.selectAll(); } } } } if (KeyboardFocusManager.getCurrentKeyboardFocusManager() instanceof QuaquaKeyboardFocusManager) { QuaquaKeyboardFocusManager kfm = (QuaquaKeyboardFocusManager) KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.setLastKeyboardTraversingComponent(null); } }
@Override public void focusGained(final FocusEvent e) { final JTextComponent component = getComponent(); if (!component.isEnabled() || !component.isEditable()) { super.focusGained(e); return; } mFocused = true; if (!shouldSelectAllOnFocus) { shouldSelectAllOnFocus = true; super.focusGained(e); return; } if (isMultiLineEditor) { super.focusGained(e); return; } final int end = component.getDocument().getLength(); final int dot = getDot(); final int mark = getMark(); if (dot == mark) { if (dot == 0) { component.setCaretPosition(end); component.moveCaretPosition(0); } else if (dot == end) { component.setCaretPosition(0); component.moveCaretPosition(end); } } super.focusGained(e); }
/** �����Ҽ�˵�����Ч�� */ public void checkMenuEnable() { if (!textComponent.isEnabled()) { if (copy.isEnabled()) copy.setEnabled(false); if (cut.isEnabled()) cut.setEnabled(false); if (paste.isEnabled()) paste.setEnabled(false); if (selectAll.isEnabled()) selectAll.setEnabled(false); return; } if (textComponent.getSelectedText() == null || textComponent.getSelectedText().equals("")) { if (copy.isEnabled()) copy.setEnabled(false); if (cut.isEnabled()) cut.setEnabled(false); } else { if (!copy.isEnabled()) copy.setEnabled(true); if (!cut.isEnabled()) cut.setEnabled(true); } if (!textComponent.isEditable()) { if (paste.isEnabled()) paste.setEnabled(false); if (cut.isEnabled()) cut.setEnabled(false); } else { if (!paste.isEnabled()) paste.setEnabled(true); // if (!cut.isEnabled()) // cut.setEnabled(true); } if (!selectAll.isEnabled()) selectAll.setEnabled(true); }
public void actionPerformed(ActionEvent e) { JTextComponent textComponent = getTextComponent(e); if (!textComponent.isEditable() || !textComponent.isEnabled()) { return; } try { outdentText(textComponent); } catch (BadLocationException e1) { e1.printStackTrace(); } }
public void actionPerformed(ActionEvent e) { JTextComponent textComponent = getTextComponent(e); if (!textComponent.isEditable() || !textComponent.isEnabled()) { return; } try { final int position = getCaretPosition(); final Document document = getDocument(); int docLen = document.getLength(); if (docLen == 0) { return; } int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n')); int toIndex = getText(fromIndex + 1, docLen - fromIndex - 1).indexOf('\n'); toIndex = toIndex < 0 ? docLen : fromIndex + toIndex + 1; String text = getText(fromIndex, toIndex - fromIndex); if (text.startsWith("\n") || toIndex >= docLen) { document.remove(fromIndex, toIndex - fromIndex); } else { document.remove(fromIndex, toIndex - fromIndex + 1); } int newPosition = 0; if (fromIndex > 0) { newPosition = fromIndex + 1; } docLen = document.getLength(); if (newPosition > docLen) { newPosition = getText().lastIndexOf('\n') + 1; } setCaretPosition(newPosition); } catch (BadLocationException e1) { e1.printStackTrace(); } }
public boolean verify(JComponent input) { JTextComponent jtc = (JTextComponent) input; if (!jtc.isEnabled()) return true; if (!jtc.isEditable()) return true; Number num = self.value; if (num != null) { try { checkRange(num); } catch (Exception ex) { input.putClientProperty("Verification-Error", ex.getMessage()); // tooltip.setText(ex.getMessage()); // tooltip.show(input); return false; } } else if (jtc.getText() != null && jtc.getText().length() > 0) { jtc.setText(""); } input.putClientProperty("Verification-Error", null); // tooltip.hide(); self.finalizeValue(); return true; }
private static void moveCaretToEndOfDocument(JTextComponent jTextComponent) { if (jTextComponent.isEditable()) { Document document = jTextComponent.getDocument(); jTextComponent.setCaretPosition(document.getEndPosition().getOffset() - 1); } }
/** * 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. */ public boolean canImport(JComponent comp, DataFlavor[] flavors) { JTextComponent c = (JTextComponent) comp; if (!(c.isEditable() && c.isEnabled())) return false; return (getImportFlavor(flavors, c) != null); }
protected void updateActions() { final boolean isEditable = _comp != null && _comp.isEditable(); _cut.setEnabled(isEditable); _paste.setEnabled(isEditable); }