/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/
/** * Abbreviation support allowing to expand defined character sequences * into the expanded strings or call the arbitrary action. * * @author Miloslav Metelka * @version 1.00 * @deprecated Use Editor Code Templates API instead. This class is no longer * functional.
*/
@Deprecated publicclass Abbrev implements/* SettingsChangeListener,*/ PropertyChangeListener {
/** * Test whether the abbreviation expansion is disabled * at the caret position in the given component's document. * * @param component non-null text component. * @return true if the abbreviation can be expanded or false if not.
*/ publicstaticboolean isAbbrevDisabled(JTextComponent component) {
Document doc = component.getDocument(); if (doc instanceof BaseDocument) {
BaseDocument bdoc = (BaseDocument)doc;
SyntaxSupport sup = bdoc.getSyntaxSupport(); if (sup != null) {
Caret caret = component.getCaret(); return sup.isAbbrevDisabled(caret != null ? caret.getDot() : 0);
}
} returnfalse; // abbrev not disabled
}
/** Abbreviation accounting string. Here the characters forming * abbreviation are stored.
*/ private StringBuffer abbrevSB = new StringBuffer();
/** Check whether the document text matches the abbreviation accounting * string.
*/ privateboolean checkDocText;
/** Additional check whether the character right before the abbreviation * string in the text is not accepted by the <tt>addTypedAcceptor</tt>. * This test is only performed if <tt>checkDocText</tt> is true.
*/ privateboolean checkTextDelimiter;
/** Extended UI to which this abbreviation is associated to */ protected EditorUI editorUI;
/** Chars on which to expand acceptor */ private Acceptor doExpandAcceptor;
/** Whether add the typed char */ private Acceptor addTypedAcceptor;
/** Which chars reset abbreviation accounting */ private Acceptor resetAcceptor;
if (EditorUI.COMPONENT_PROPERTY.equals(propName)) {
JTextComponent component = (JTextComponent)evt.getNewValue(); if (component != null) { // just installed
// settingsChange(null);
} else { // just deinstalled // component = (JTextComponent)evt.getOldValue();
/** Add typed character to abbreviation accounting string. */ publicvoid addChar(char ch) {
abbrevSB.append(ch);
}
/** Get current abbreviation string */ public String getAbbrevString() { return abbrevSB.toString();
}
/** Get mapping table [abbrev, expanded-abbrev] */ public Map getAbbrevMap() { return abbrevMap;
}
/** Translate string using abbreviation table * @param abbrev string to translate. Pass null to translate current abbreviation * string * @return expanded abbreviation
*/ public Object translateAbbrev(String abbrev) {
String abbStr = (abbrev != null) ? abbrev : abbrevSB.toString(); return getAbbrevMap().get(abbStr);
}
/** Checks whether there's valid string to expand and if so it returns it.
*/ public String getExpandString(char typedChar) { return (doExpandAcceptor.accept(typedChar)) ? getExpandString() : null;
}
publicboolean expandString(char typedChar, String expandStr, ActionEvent evt) throws BadLocationException { if (expandString(expandStr, evt)) { if (addTypedAcceptor.accept(typedChar)) { int dotPos = editorUI.getComponent().getCaret().getDot();
editorUI.getDocument().insertString(dotPos, String.valueOf(typedChar), null);
} returntrue;
} returnfalse;
}
/** Expand abbreviation on current caret position. * Remove characters back to the word start and insert expanded abbreviation. * @return whether the typed character should be added to the abbreviation or not
*/ publicboolean expandString(final String expandStr, final ActionEvent evt) throws BadLocationException { // Disabled due to code templates if (true) {
reset(); returntrue;
}
final BaseDocument doc = editorUI.getDocument(); final Object[] result = new Object [1];
doc.runAtomicAsUser (new Runnable () { publicvoid run () { try {
Caret caret = editorUI.getComponent().getCaret(); int pos = caret.getDot() - expandStr.length(); try {
doc.remove(pos, expandStr.length());
result [0] = doExpansion(pos, expandStr, evt);
} catch (BadLocationException ex) {
result [0] = ex;
}
} finally { if (result [0] instanceofBoolean && (Boolean) result [0]) {
reset();
} else {
doc.breakAtomicLock();
}
}
}
}); if (result [0] instanceof BadLocationException) throw (BadLocationException) result [0]; return (Boolean) result [0];
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.