protected void clicked(CharPos pos) { AttributedCharacterIterator inf = pos.part.ti(); inf.setIndex(pos.ch.getCharIndex()); FuckMeGentlyWithAChainsaw url = (FuckMeGentlyWithAChainsaw) inf.getAttribute(ChatAttribute.HYPERLINK); if ((url != null) && (WebBrowser.self != null)) WebBrowser.self.show(url.url); }
/** Returns a Set of the attribute identifiers at <code>index</code>. */ Map getAttributes(int index) { if (isValidMask()) { AttributedCharacterIterator iterator = getIterator(); if (index >= 0 && index <= iterator.getEndIndex()) { iterator.setIndex(index); return iterator.getAttributes(); } } return null; }
public void actionPerformed(ActionEvent ae) { if (getFormattedTextField().isEditable()) { if (getAllowsInvalid()) { // This will work if the currently edited value is valid. updateMask(); } boolean validEdit = false; if (isValidMask()) { int start = getFormattedTextField().getSelectionStart(); if (start != -1) { AttributedCharacterIterator iterator = getIterator(); iterator.setIndex(start); Map attributes = iterator.getAttributes(); Object field = getAdjustField(start, attributes); if (canIncrement(field, start)) { try { Object value = stringToValue(getFormattedTextField().getText()); int fieldTypeCount = getFieldTypeCountTo(field, start); value = adjustValue(value, attributes, field, direction); if (value != null && isValidValue(value, false)) { resetValue(value); updateMask(); if (isValidMask()) { selectField(field, fieldTypeCount); } validEdit = true; } } catch (ParseException pe) { } catch (BadLocationException ble) { } } } } if (!validEdit) { invalidEdit(); } } }
/** * Updates the interal bitset from <code>iterator</code>. This will set <code>validMask</code> to * true if <code>iterator</code> is non-null. */ private void updateMask(AttributedCharacterIterator iterator) { if (iterator != null) { validMask = true; this.iterator = iterator; // Update the literal mask if (literalMask == null) { literalMask = new BitSet(); } else { for (int counter = literalMask.length() - 1; counter >= 0; counter--) { literalMask.clear(counter); } } iterator.first(); while (iterator.current() != CharacterIterator.DONE) { Map attributes = iterator.getAttributes(); boolean set = isLiteral(attributes); int start = iterator.getIndex(); int end = iterator.getRunLimit(); while (start < end) { if (set) { literalMask.set(start); } else { literalMask.clear(start); } start++; } iterator.setIndex(start); } } }
/** Selects the fields identified by <code>attributes</code>. */ void selectField(Object f, int count) { AttributedCharacterIterator iterator = getIterator(); if (iterator != null && (f instanceof AttributedCharacterIterator.Attribute)) { AttributedCharacterIterator.Attribute field = (AttributedCharacterIterator.Attribute) f; iterator.first(); while (iterator.current() != CharacterIterator.DONE) { while (iterator.getAttribute(field) == null && iterator.next() != CharacterIterator.DONE) ; if (iterator.current() != CharacterIterator.DONE) { int limit = iterator.getRunLimit(field); if (--count <= 0) { getFormattedTextField().select(iterator.getIndex(), limit); break; } iterator.setIndex(limit); iterator.next(); } } } }
/** * Returns the number of occurences of <code>f</code> before the location <code>start</code> in * the current <code>AttributedCharacterIterator</code>. */ private int getFieldTypeCountTo(Object f, int start) { AttributedCharacterIterator iterator = getIterator(); int count = 0; if (iterator != null && (f instanceof AttributedCharacterIterator.Attribute)) { AttributedCharacterIterator.Attribute field = (AttributedCharacterIterator.Attribute) f; int index = 0; iterator.first(); while (iterator.getIndex() < start) { while (iterator.getAttribute(field) == null && iterator.next() != CharacterIterator.DONE) ; if (iterator.current() != CharacterIterator.DONE) { iterator.setIndex(iterator.getRunLimit(field)); iterator.next(); count++; } else { break; } } } return count; }
/** * Returns the start of the first run that contains the attribute <code>id</code>. This will * return <code>-1</code> if the attribute can not be found. */ int getAttributeStart(AttributedCharacterIterator.Attribute id) { if (isValidMask()) { AttributedCharacterIterator iterator = getIterator(); iterator.first(); while (iterator.current() != CharacterIterator.DONE) { if (iterator.getAttribute(id) != null) { return iterator.getIndex(); } iterator.next(); } } return -1; }
/** * Constructs an {@code AttributedString} from a range of the text contained in the specified * {@code AttributedCharacterIterator}, starting at {@code start} and ending at {@code end}. All * attributes will be copied to this attributed string. * * @param iterator the {@code AttributedCharacterIterator} that contains the text for this * attributed string. * @param start the start index of the range of the copied text. * @param end the end index of the range of the copied text. * @throws IllegalArgumentException if {@code start} is less than first index of {@code iterator}, * {@code end} is greater than the last index + 1 in {@code iterator} or if {@code start > * end}. */ public AttributedString(AttributedCharacterIterator iterator, int start, int end) { this(iterator, start, end, iterator.getAllAttributeKeys()); }
private AttributedString( AttributedCharacterIterator iterator, int start, int end, Set<Attribute> attributes) { if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() || start > end) { throw new IllegalArgumentException(); } if (attributes == null) { return; } StringBuilder buffer = new StringBuilder(); iterator.setIndex(start); while (iterator.getIndex() < end) { buffer.append(iterator.current()); iterator.next(); } text = buffer.toString(); attributeMap = new HashMap<Attribute, List<Range>>((attributes.size() * 4 / 3) + 1); Iterator<Attribute> it = attributes.iterator(); while (it.hasNext()) { AttributedCharacterIterator.Attribute attribute = it.next(); iterator.setIndex(start); while (iterator.getIndex() < end) { Object value = iterator.getAttribute(attribute); int runStart = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); if ((value instanceof Annotation && runStart >= start && limit <= end) || (value != null && !(value instanceof Annotation))) { addAttribute( attribute, value, (runStart < start ? start : runStart) - start, (limit > end ? end : limit) - start); } iterator.setIndex(limit); } } }
/** * Constructs an {@code AttributedString} from an {@code AttributedCharacterIterator}, which * represents attributed text. * * @param iterator the {@code AttributedCharacterIterator} that contains the text for this * attributed string. */ public AttributedString(AttributedCharacterIterator iterator) { if (iterator.getBeginIndex() > iterator.getEndIndex()) { // text.0A=Invalid substring range throw new IllegalArgumentException(Messages.getString("text.0A")); // $NON-NLS-1$ } StringBuilder buffer = new StringBuilder(); for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) { buffer.append(iterator.current()); iterator.next(); } text = buffer.toString(); Set<AttributedCharacterIterator.Attribute> attributes = iterator.getAllAttributeKeys(); if (attributes == null) { return; } attributeMap = new HashMap<Attribute, List<Range>>((attributes.size() * 4 / 3) + 1); Iterator<Attribute> it = attributes.iterator(); while (it.hasNext()) { AttributedCharacterIterator.Attribute attribute = it.next(); iterator.setIndex(0); while (iterator.current() != CharacterIterator.DONE) { int start = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); Object value = iterator.getAttribute(attribute); if (value != null) { addAttribute(attribute, value, start, limit); } iterator.setIndex(limit); } } }