Java 类javax.swing.event.CaretListener 实例源码
项目:incubator-netbeans
文件:WikiEditPanel.java
/**
* Creates new form WikiEditPanel
*/
public WikiEditPanel(String wikiLanguage, boolean editing, boolean switchable) {
this.wikiLanguage = wikiLanguage;
this.switchable = switchable;
this.wikiFormatText = "";
this.htmlFormatText = "";
initComponents();
pnlButtons.setVisible(switchable);
textCode.getDocument().addDocumentListener(new RevalidatingListener());
textPreview.getDocument().addDocumentListener(new RevalidatingListener());
textCode.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
makeCaretVisible(textCode);
}
});
textCode.getDocument().addDocumentListener(new EnablingListener());
// A11Y - Issues 163597 and 163598
UIUtils.fixFocusTraversalKeys(textCode);
UIUtils.issue163946Hack(scrollCode);
Spellchecker.register(textCode);
textPreview.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
setEditing(editing);
}
项目:incubator-netbeans
文件:NavigatorContent.java
private void updateActiveEditor() {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(this);
return;
}
JTextComponent c = findActivePane();
if (c == null) {
editorReleased();
return;
}
if (activeEditor != null && activeEditor.get() == c) {
return;
}
editorReleased();
activeEditor = new WeakReference<>(c);
wCaretL = WeakListeners.create(CaretListener.class, this, c);
c.addCaretListener(this);
selectCurrentNode();
}
项目:openjdk-jdk10
文件:TableViewLayoutTest.java
public TableViewLayoutTest() {
super("Code example for a TableView bug");
setUndecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
edit.setEditorKit(new CodeBugEditorKit());
initCodeBug();
this.getContentPane().add(new JScrollPane(edit));
this.pack();
this.setLocationRelativeTo(null);
edit.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
JTextComponent textComp = (JTextComponent) e.getSource();
try {
Rectangle rect = textComp.getUI().modelToView(textComp, e.getDot());
yCaret = rect.getY();
xCaret = rect.getX();
} catch (BadLocationException ex) {
throw new RuntimeException("Failed to get pixel position of caret", ex);
}
}
});
}
项目:bigtable-sql
文件:RowColumnLabel.java
RowColumnLabel(ISQLEntryPanel sqlEntryPanel)
{
super(" ", JLabel.CENTER);
_sqlEntryPanel = sqlEntryPanel;
sqlEntryPanel.addCaretListener(new CaretListener()
{
public void caretUpdate(CaretEvent e)
{
onCaretUpdate(e);
}
});
writePosition(0,0, 0);
setToolTipText(s_stringMgr.getString("RowColumnLabel.tooltip"));
}
项目:metasfresh
文件:VString.java
/**
* Feature Request [1707462]
* Set VFormat
* @param strMask mask
* @author fer_luck
*/
public void setVFormat (String strMask)
{
m_VFormat = strMask;
//Get the actual caret from the field, if there's no
//caret then just catch the exception and continue
//creating the new caret.
try{
CaretListener [] cl = this.getCaretListeners();
this.removeCaretListener(cl[0]);
} catch(ClassCastException ex ){
log.debug("VString.setVFormat - No caret Listeners");
}
//hengsin: [ adempiere-Bugs-1891037 ], preserve current data before change of format
String s = getText();
setDocument(new MDocString(m_VFormat, m_fieldLength, this));
setText(s);
}
项目:jpexs-decompiler
文件:SlotConstTraitDetailPanel.java
public SlotConstTraitDetailPanel(final DecompiledEditorPane editor) {
slotConstEditor = new LineMarkedEditorPane();
setLayout(new BorderLayout());
add(new JScrollPane(slotConstEditor), BorderLayout.CENTER);
slotConstEditor.setFont(Configuration.getSourceFont());
slotConstEditor.changeContentType("text/flasm3");
slotConstEditor.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if (ignoreCaret) {
return;
}
Highlighting spec = Highlighting.searchPos(specialHilights, slotConstEditor.getCaretPosition());
if (spec != null) {
editor.hilightSpecial(spec.getProperties().subtype, (int) spec.getProperties().index);
slotConstEditor.getCaret().setVisible(true);
}
}
});
}
项目:cagrid-core
文件:PropertyConfigurationStep.java
protected void addTextOption(TextPropertyConfigurationOption option, Component control) {
String defaultValue = this.model.getProperty(option.getName());
if (defaultValue == null) {
defaultValue = option.getDefaultValue();
}
final String requiredField = option.getName();
final JTextField valueField = new JTextField(defaultValue);
if (option.isRequired()) {
boolean isSet = defaultValue != null && defaultValue.trim().length() > 0;
this.requiredFields.put(option.getName(), isSet);
valueField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent evt) {
if (PropertyConfigurationStep.this.requiredFields.containsKey(requiredField)) {
boolean selected = valueField.getText() != null && valueField.getText().trim().length() > 0;
PropertyConfigurationStep.this.requiredFields.put(requiredField, selected);
PropertyConfigurationStep.this.checkComplete();
}
}
});
}
addOption(option.getName(), option.getDescription(), valueField, control);
}
项目:cagrid-core
文件:PropertyConfigurationStep.java
protected void addPasswordOption(PasswordPropertyConfigurationOption option) {
String defaultValue = this.model.getProperty(option.getName());
if (defaultValue == null) {
defaultValue = option.getDefaultValue();
}
final String requiredField = option.getName();
final JPasswordField valueField = new JPasswordField(defaultValue);
if (option.isRequired()) {
boolean isSet = defaultValue != null && defaultValue.trim().length() > 0;
this.requiredFields.put(option.getName(), isSet);
valueField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent evt) {
if (PropertyConfigurationStep.this.requiredFields.containsKey(requiredField)) {
boolean selected = valueField.getPassword() != null
&& String.valueOf(valueField.getPassword()).trim().length() > 0;
PropertyConfigurationStep.this.requiredFields.put(requiredField, selected);
PropertyConfigurationStep.this.checkComplete();
}
}
});
}
addOption(option.getName(), option.getDescription(), valueField);
}
项目:BBCodeEditor
文件:SourceMenuPanel.java
/**
* constructor
*
* @param textArea the textArea-instance
*/
public SourceMenuPanel(JTextArea textArea) {
super(new FlowLayout(FlowLayout.LEFT,5,2));
_textArea = textArea;
Document doc = _textArea.getDocument();
doc.addUndoableEditListener(new MyUndoableEditListener());
createActionTable();
_textArea.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
boolean select = e.getDot() != e.getMark();
_btnCut.setEnabled(select);
_btnCopy.setEnabled(select);
}
});
initLayout();
}
项目:BibTeX-Converter
文件:GUI.java
/**
* updates the inputPane-area, if references were imported from a file
*
* @param bibTexStrng
* a string containing the raw bibtext references
*/
public static void setInput(String bibTexString) {
if (clearInput) {
final CaretListener[] clis = inputPane.getCaretListeners();
final CaretListener cli = clis[0];
inputPane = new JTextArea();
inputPane.setText(bibTexString);
inputPane.addCaretListener(cli);
} else
{
inputPane.setText(bibTexString);
}
inputPane.validate();
}
项目:incubator-netbeans
文件:SearchBar.java
private CaretListener createCaretListenerForComponent() {
return new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if (SearchBar.getInstance().isVisible()) {
int num = SearchBar.getInstance().getNumOfMatches();
SearchBar.getInstance().showNumberOfMatches(null, num);
}
}
};
}
项目:incubator-netbeans
文件:TaskPanel.java
/**
* Creates new form TaskPanel
*/
public TaskPanel (LocalTask task) {
this.task = task;
initComponents();
updateReadOnlyField(headerField);
Font font = new JLabel().getFont();
headerField.setFont(font.deriveFont((float) (font.getSize() * 1.7)));
mainScrollPane.getVerticalScrollBar().setUnitIncrement(10);
privateNotesField.addCaretListener(new CaretListener() {
@Override
public void caretUpdate (CaretEvent e) {
makeCaretVisible(privateNotesField);
}
});
// A11Y - Issues 163597 and 163598
UIUtils.fixFocusTraversalKeys(privateNotesField);
initSpellChecker();
attachmentsPanel = new AttachmentsPanel(this);
attachmentsSection.setContent(attachmentsPanel);
GroupLayout layout = (GroupLayout) attributesPanel.getLayout();
dueDatePicker = UIUtils.createDatePickerComponent();
scheduleDatePicker = new SchedulePicker();
layout.replace(dummyDueDateField, dueDatePicker.getComponent());
dueDateLabel.setLabelFor(dueDatePicker.getComponent());
layout.replace(dummyScheduleDateField, scheduleDatePicker.getComponent());
scheduleDateLabel.setLabelFor(scheduleDatePicker.getComponent());
attachListeners();
}
项目:rapidminer
文件:JEditTextArea.java
protected void fireCaretEvent() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i--) {
if (listeners[i] == CaretListener.class) {
((CaretListener) listeners[i + 1]).caretUpdate(caretEvent);
}
}
}
项目:enigma-vk
文件:CodeReader.java
public CodeReader() {
setEditable(false);
setContentType("text/java");
// turn off token highlighting (it's wrong most of the time anyway...)
DefaultSyntaxKit kit = (DefaultSyntaxKit)getEditorKit();
kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker");
// hook events
addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent event) {
if (m_selectionListener != null && m_sourceIndex != null) {
Token token = m_sourceIndex.getReferenceToken(event.getDot());
if (token != null) {
m_selectionListener.onSelect(m_sourceIndex.getDeobfReference(token));
} else {
m_selectionListener.onSelect(null);
}
}
}
});
m_selectionHighlightPainter = new SelectionHighlightPainter();
m_sourceIndex = null;
m_selectionListener = null;
}
项目:openjdk-jdk10
文件:JTextComponentOperator.java
/**
* Maps {@code JTextComponent.addCaretListener(CaretListener)} through queue
*/
public void addCaretListener(final CaretListener caretListener) {
runMapping(new MapVoidAction("addCaretListener") {
@Override
public void map() {
((JTextComponent) getSource()).addCaretListener(caretListener);
}
});
}
项目:openjdk-jdk10
文件:JTextComponentOperator.java
/**
* Maps {@code JTextComponent.removeCaretListener(CaretListener)}
* through queue
*/
public void removeCaretListener(final CaretListener caretListener) {
runMapping(new MapVoidAction("removeCaretListener") {
@Override
public void map() {
((JTextComponent) getSource()).removeCaretListener(caretListener);
}
});
}
项目:openjdk9
文件:JTextComponentOperator.java
/**
* Maps {@code JTextComponent.addCaretListener(CaretListener)} through queue
*/
public void addCaretListener(final CaretListener caretListener) {
runMapping(new MapVoidAction("addCaretListener") {
@Override
public void map() {
((JTextComponent) getSource()).addCaretListener(caretListener);
}
});
}
项目:openjdk9
文件:JTextComponentOperator.java
/**
* Maps {@code JTextComponent.removeCaretListener(CaretListener)}
* through queue
*/
public void removeCaretListener(final CaretListener caretListener) {
runMapping(new MapVoidAction("removeCaretListener") {
@Override
public void map() {
((JTextComponent) getSource()).removeCaretListener(caretListener);
}
});
}
项目:lippen-network-tool
文件:IPV4Field.java
@Override
public void addCaretListener(CaretListener listener) {
if (this.ipFields != null) {
for (JIPV4Field field : this.ipFields) {
field.addCaretListener(listener);
}
}
}
项目:lippen-network-tool
文件:IPV4Field.java
@Override
public void removeCaretListener(CaretListener listener) {
if (this.ipFields != null) {
for (JIPV4Field field : this.ipFields) {
field.removeCaretListener(listener);
}
}
}
项目:gogui2
文件:Comment.java
public Comment(Listener listener)
{
m_listener = listener;
m_textPane = new JTextPane();
setFocusTraversalKeys(m_textPane);
GuiUtil.addStyle(m_textPane, "marked", Color.white,
Color.decode("#38d878"), false);
setPreferredSize();
m_textPane.getDocument().addDocumentListener(this);
CaretListener caretListener = new CaretListener()
{
public void caretUpdate(CaretEvent event)
{
if (m_listener == null)
return;
m_listener.textSelected(m_textPane.getSelectedText());
}
};
m_textPane.addCaretListener(caretListener);
setViewportView(m_textPane);
setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
if (Platform.isMac())
m_normalFont = new Font("Lucida Grande", Font.PLAIN, 11);
else
m_normalFont = UIManager.getFont("TextPane.font");
setMonoFont(false);
}
项目:balloonist
文件:CaretListenerSupport.java
/**
* @param ce if the source inside the event is not null, that component will be excluded from
* the list of components to be notified about the caret event.
*/
public void fireValueChanged(CaretEvent ce)
{
for (int loop=size()-1; loop>=0; loop--)
{
CaretListener cl = (CaretListener) get(loop);
if (ce==null || cl!=ce.getSource())
{
// System.out.println("fireValueChanged: tsl: "+tsl);
// System.out.println("fireValueChanged: tse.getSource(): "+tse.getSource());
cl.caretUpdate(ce);
}
}
}
项目:djigger
文件:HostConnectionParameter.java
public HostConnectionParameter() {
super();
defaultName = true;
JPanel namePane = new JPanel(new GridLayout(0, 2));
namePane.add(new JLabel("Name"));
name = new JTextField(20);
name.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
defaultName = false;
}
});
namePane.add(name);
hostParametersPane = new JPanel(new GridLayout(0, 2));
hostParametersPane.add(new JLabel("Host"));
host = new JTextField(20);
host.addCaretListener(this);
hostParametersPane.add(host);
hostParametersPane.add(new JLabel("Port"));
port = new JTextField(5);
port.addCaretListener(this);
hostParametersPane.add(port);
hostParametersPane.add(new JLabel("Username"));
username = new JTextField(20);
hostParametersPane.add(username);
hostParametersPane.add(new JLabel("Password"));
password = new JTextField(20);
hostParametersPane.add(password);
host.requestFocusInWindow();
}
项目:netbeansplugins
文件:ChangeObserverOfWizardPanel.java
/**
* Bind a CaretListener.
* <p>
* This method propagates caret events to wizard panel change events.
*
* @param source an object implementing addCaretListener.
*/
public boolean bindCaretListener( Object source ) {
boolean bound = false;
try {
final CaretListener caretListener = getCaretListener();
final CaretListener weakCaretListener = (CaretListener) WeakListeners.create( CaretListener.class, caretListener, source );
final Method m = source.getClass().getMethod( "addCaretListener", CaretListener.class );
m.invoke( source, weakCaretListener );
bound = true;
} catch (Exception ex) {
ErrorManager.getDefault().notify( ex );
}
return bound;
}
项目:Prism-gsoc16
文件:GUIWindowLog.java
public void open(JTextArea ta, GUILog logPlugin)
{
this.logPlugin = logPlugin;
textArea = ta;
textArea.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
if (GUIWindowLog.this.logPlugin != null)
GUIWindowLog.this.logPlugin.getSelectionChangeHandler().notifyListeners(new GUIEvent(1));
}
});
updater = new GUIWindowLogUpdater(this, textArea);
updater.start();
}
项目:j2se_for_android
文件:JTextComponent.java
protected void fireCaretUpdate(CaretEvent e) {
CaretListener[] carets = JTextComponent.this.getCaretListeners();
if(carets != null){
for (int i = 0; i < carets.length; i++) {
carets[i].caretUpdate(e);
}
}
}
项目:javify
文件:JTextComponent.java
/**
* Notifies all registered <code>CaretListener</code> objects that the caret
* was updated.
*
* @param event the event to send
*/
protected void fireCaretUpdate(CaretEvent event)
{
CaretListener[] listeners = getCaretListeners();
for (int index = 0; index < listeners.length; ++index)
listeners[index].caretUpdate(event);
}
项目:rapidminer-studio
文件:JEditTextArea.java
protected void fireCaretEvent() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i--) {
if (listeners[i] == CaretListener.class) {
((CaretListener) listeners[i + 1]).caretUpdate(caretEvent);
}
}
}
项目:jvm-stm
文件:JTextComponent.java
/**
* Notifies all registered <code>CaretListener</code> objects that the caret
* was updated.
*
* @param event the event to send
*/
protected void fireCaretUpdate(CaretEvent event)
{
CaretListener[] listeners = getCaretListeners();
for (int index = 0; index < listeners.length; ++index)
listeners[index].caretUpdate(event);
}
项目:Wurst-Enigma
文件:CodeReader.java
public CodeReader()
{
setEditable(false);
setContentType("text/java");
// turn off token highlighting (it's wrong most of the time anyway...)
DefaultSyntaxKit kit = (DefaultSyntaxKit)getEditorKit();
kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker");
// hook events
addCaretListener(new CaretListener()
{
@Override
public void caretUpdate(CaretEvent event)
{
if(m_selectionListener != null && m_sourceIndex != null)
{
Token token =
m_sourceIndex.getReferenceToken(event.getDot());
if(token != null)
m_selectionListener.onSelect(m_sourceIndex
.getDeobfReference(token));
else
m_selectionListener.onSelect(null);
}
}
});
m_selectionHighlightPainter = new SelectionHighlightPainter();
m_sourceIndex = null;
m_selectionListener = null;
}
项目:openwonderland
文件:ErrorReportFrame.java
/**
* Creates new form ErrorReportFrame
*/
public ErrorReportFrame() {
initComponents();
errorText.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent ce) {
String sel = errorText.getSelectedText();
copyButton.setEnabled(sel != null);
}
});
}
项目:JNAerator
文件:JEditTextArea.java
protected void fireCaretEvent()
{
Object[] listeners = listenerList.getListenerList();
for(int i = listeners.length - 2; i >= 0; i--)
{
if(listeners[i] == CaretListener.class)
{
((CaretListener)listeners[i+1]).caretUpdate(caretEvent);
}
}
}
项目:incubator-taverna-workbench
文件:LineEnabledTextPanel.java
public LineEnabledTextPanel(final JTextComponent component) {
this.setLayout(new BorderLayout());
textComponent = component;
updateDocument();
JScrollPane scrollPane = new JScrollPane(textComponent );
scrollPane.setPreferredSize(textComponent.getPreferredSize() );
this.add(scrollPane, BorderLayout.CENTER);;
final JLabel caretLabel = new JLabel("Line: 1 Column: 0");
setCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
int caretPosition = getCaretPosition();
Element root = document.getRootElements()[0];
int elementIndex = root.getElementIndex(caretPosition);
int relativeOffset = caretPosition - root.getElement(elementIndex).getStartOffset();
caretLabel.setText("Line: " + (elementIndex + 1) + " Column: " + relativeOffset);
}});
this.add(caretLabel, BorderLayout.SOUTH);
KeyStroke gotoLineKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.META_MASK);
gotoLineAction = new GotoLineAction();
textComponent.getInputMap().put(gotoLineKeystroke, "gotoLineKeystroke");
textComponent.getActionMap().put("gotoLineKeystroke", gotoLineAction);
}
项目:WollMux
文件:TextComponentTags.java
/**
* Immer wenn der Cursor mit der Maus in einen Bereich innerhalb eines Tags gesetzt
* wird, sorgt der hier registrierte caret Listener dafür, dass der Bereich auf das
* gesamte Tag ausgedehnt wird.
*
* @author Christoph Lutz (D-III-ITD-5.1)
*/
private void changeCaretHandling()
{
compo.addCaretListener(new CaretListener()
{
public void caretUpdate(CaretEvent e)
{
extraHighlightOff();
int dot = compo.getCaret().getDot();
int mark = compo.getCaret().getMark();
for (Iterator<TagPos> iter = getTagPosIterator(); iter.hasNext();)
{
TextComponentTags.TagPos fp = iter.next();
if (dot > fp.start && dot < fp.end)
{
if (dot < mark)
{
caretMoveDot(fp.start);
}
else if (dot > mark)
{
caretMoveDot(fp.end);
}
else
{
caretSetDot(fp.end);
extraHighlight(fp.start, fp.end);
}
}
}
}
});
}
项目:jpexs-decompiler
文件:Amf3ValueEditor.java
@Override
public void validateValue() {
Amf3Importer importer = new Amf3Importer();
String textVal = editor.getText();
try {
if (!textVal.trim().isEmpty()) {
importer.stringToAmf(textVal);
}
} catch (IOException | Amf3ParseException ex) {
if (ex instanceof Amf3ParseException) {
Amf3ParseException ape = (Amf3ParseException) ex;
if (ape.line > 0) {
editor.gotoLine((int) ape.line);
}
}
final CaretListener cl = new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
errorLabel.setVisible(false);
editor.removeCaretListener(this);
}
};
editor.addCaretListener(cl);
errorLabel.setText("<html>" + AppStrings.translate("error") + ":" + ex.getMessage() + "</html>");
errorLabel.setVisible(true);
throw new IllegalArgumentException("Invalid AMF value", ex);
}
}
项目:cn1
文件:JTextComponent.java
protected void fireCaretUpdate(final CaretEvent ce) {
CaretListener[] listeners = getCaretListeners();
for (int i = 0; i < listeners.length; i++) {
listeners[i].caretUpdate(ce);
}
if (ce != null) {
handleComposedText(ce.getDot());
}
}
项目:cn1
文件:StyleContext_NamedStyleTest.java
public void testGetListeners() {
ns.addChangeListener(this);
EventListener[] listeners = ns.getListeners(ChangeListener.class);
assertEquals(1, listeners.length);
assertSame(this, listeners[0]);
listeners = ns.getListeners(CaretListener.class);
assertEquals(0, listeners.length);
ns.removeChangeListener(this);
listeners = ns.getListeners(ChangeListener.class);
assertEquals(0, listeners.length);
}
项目:cn1
文件:JTextComponentTest.java
public void assertEquals(final Vector<SimpleCaretListener> listeners1, final CaretListener[] listeners2) {
assertNotNull(listeners1);
assertNotNull(listeners2);
assertEquals(listeners1.size(), listeners2.length);
for (int i = 0; i < listeners1.size(); i++) {
assertEquals(listeners1.get(i), listeners2[i]);
}
}
项目:JamVM-PH
文件:JTextComponent.java
/**
* Notifies all registered <code>CaretListener</code> objects that the caret
* was updated.
*
* @param event the event to send
*/
protected void fireCaretUpdate(CaretEvent event)
{
CaretListener[] listeners = getCaretListeners();
for (int index = 0; index < listeners.length; ++index)
listeners[index].caretUpdate(event);
}
项目:K-scope
文件:CodePane.java
/**
* コンストラクタ
*/
public LineHighlightTextPaneUI() {
CodePane.this.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
CodePane.this.repaint();
}
});
}