本文整理汇总了Java中javax.swing.text.Position类的典型用法代码示例。如果您正苦于以下问题:Java Position类的具体用法?Java Position怎么用?Java Position使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Position类属于javax.swing.text包,在下文中一共展示了Position类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPosition
import javax.swing.text.Position; //导入依赖的package包/类
@Override
public PositionBounds getPosition() {
try {
DataObject dobj = DataObject.find(getParentFile());
if (dobj != null) {
EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getLookup().lookup(EditorCookie.Observable.class);
if (obs != null && obs instanceof CloneableEditorSupport) {
CloneableEditorSupport supp = (CloneableEditorSupport)obs;
PositionBounds bounds = new PositionBounds(
supp.createPositionRef(loc[0], Position.Bias.Forward),
supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
);
return bounds;
}
}
} catch (DataObjectNotFoundException ex) {
LOG.log(Level.INFO, "Can't resolve", ex);//NOI18N
}
return null;
}
示例2: testAddCompleteMatchOverlap
import javax.swing.text.Position; //导入依赖的package包/类
public void testAddCompleteMatchOverlap() {
PositionsBag hs = new PositionsBag(doc, true);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
SimpleAttributeSet attribsB = new SimpleAttributeSet();
attribsA.addAttribute("set-A", "attribsA");
attribsB.addAttribute("set-B", "attribsB");
hs.addHighlight(pos(10), pos(20), attribsA);
hs.addHighlight(pos(10), pos(20), attribsB);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> attributes = hs.getAttributes();
assertEquals("Wrong number of highlights", 2, marks.size());
assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B");
assertNull("1. highlight - wrong end", attributes.get(1));
}
示例3: buildUpFixDataForLine
import javax.swing.text.Position; //导入依赖的package包/类
private Pair<FixData, String> buildUpFixDataForLine(Position line) {
List<ErrorDescription> errorDescriptions = getErrorsForLine(line, true);
if (errorDescriptions.isEmpty()) {
return null;
}
List<ErrorDescription> trueErrors = filter(errorDescriptions, true);
List<ErrorDescription> others = filter(errorDescriptions, false);
//build up the description of the annotation:
StringBuffer description = new StringBuffer();
concatDescription(trueErrors, description);
if (!trueErrors.isEmpty() && !others.isEmpty()) {
description.append("\n\n"); //NOI18N
}
concatDescription(others, description);
return Pair.of(new FixData(computeFixes(trueErrors), computeFixes(others)), description.toString());
}
示例4: testAddRightOverlap
import javax.swing.text.Position; //导入依赖的package包/类
public void testAddRightOverlap() {
PositionsBag hs = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
SimpleAttributeSet attribsB = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
attribsB.addAttribute("set-name", "attribsB");
hs.addHighlight(pos(10), pos(20), attribsA);
hs.addHighlight(pos(15), pos(25), attribsB);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> atttributes = hs.getAttributes();
assertEquals("Wrong number of highlights", 3, marks.size());
assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset());
assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset());
assertEquals("2. highlight - wrong end offset", 25, marks.get(2).getOffset());
assertEquals("2. highlight - wrong attribs", "attribsB", atttributes.get(1).getAttribute("set-name"));
assertNull( "2. highlight - wrong end", atttributes.get(2));
}
示例5: fireMatchesHighlighted
import javax.swing.text.Position; //导入依赖的package包/类
private void fireMatchesHighlighted(Position[] origin, Position[] matches, BracesMatcher.ContextLocator locator) {
MatchListener[] ll;
synchronized (LOCK) {
if (matchListeners.isEmpty()) {
return;
}
ll = (MatchListener[]) matchListeners.toArray(new MatchListener[matchListeners.size()]);
}
if (ll.length == 0) {
return;
}
MatchEvent evt = new MatchEvent(component, locator, this);
evt.setHighlights(origin, matches);
for (int i = 0; i < ll.length; i++) {
MatchListener matchListener = ll[i];
matchListener.matchHighlighted(evt);
}
}
示例6: testMarkSwapMultiBB
import javax.swing.text.Position; //导入依赖的package包/类
public void testMarkSwapMultiBB() throws Exception {
RandomTestContainer container = createContainer();
RandomTestContainer.Context context = container.context();
DocumentContentTesting.insert(context, 0, "abcdefghijkl");
Position pos2 = DocumentContentTesting.createPosition(context, 2, true);
Position pos3 = DocumentContentTesting.createPosition(context, 3, true);
Position pos5 = DocumentContentTesting.createPosition(context, 5, true);
container.runChecks(context);
DocumentContentTesting.remove(context, 2, 4);
DocumentContentTesting.insert(context, 2, "xyzw");
Position pos22 = DocumentContentTesting.createPosition(context, 2, true);
Position pos23 = DocumentContentTesting.createPosition(context, 3, true);
Position pos24 = DocumentContentTesting.createPosition(context, 4, true);
Position pos25 = DocumentContentTesting.createPosition(context, 5, true);
assertNotSame(pos3, pos2);
container.runChecks(context);
DocumentContentTesting.undo(context, 1); // Undo Ins(2, "x") tj. Rem(2,1) => becomes: pos3=2 2
DocumentContentTesting.undo(context, 1); // Undo Rem(2, 1) tj. Ins(2,"c") => becomes: pos3=3 2
container.runChecks(context);
}
示例7: getNextPosition
import javax.swing.text.Position; //导入依赖的package包/类
/** Get the next position of the position given by parameters.
* It can be either just offset increasing but it can be movement
* to the next token for the token boundary.
* @return next token-position or null for the EOT position
*/
public FormatTokenPosition getNextPosition(TokenItem token, int offset,
Position.Bias bias) {
if (token == null) { // end of chain
return null;
} else { // regular token
offset++;
if (offset >= token.getImage().length()) {
token = token.getNext();
offset = 0;
}
return getPosition(token, offset, bias);
}
}
示例8: insert
import javax.swing.text.Position; //导入依赖的package包/类
@Override
public void insert(MutableContext context) throws BadLocationException {
int offset = context.getBreakInsertOffset();
BaseDocument doc = (BaseDocument) context.getDocument();
if (offset > 0 && offset < doc.getLength()) { //check corners
String text = doc.getText(offset - 1, 2); //get char before and after
if (TWO_CURLY_BRACES_IMAGE.equals(text)) { //NOI18N
//context.setText("\n\n", 1, 1, 0, 2);
//reformat workaround -- the preferred
//won't work as the reformatter will not reformat the line with the closing tag
int from = Utilities.getRowStart(doc, offset);
int to = Utilities.getRowEnd(doc, offset);
reformat = new Position[]{doc.createPosition(from), doc.createPosition(to)};
context.setText("\n\n", 1, 1);
}
}
}
示例9: invalidateGrammar
import javax.swing.text.Position; //导入依赖的package包/类
/**
* Notification from invalidator thread, the grammar need to be reloaded.
*/
public synchronized void invalidateGrammar() {
// make current loader a zombie
if (state == VALID) {
String msg = NbBundle.getMessage(GrammarManager.class, "MSG_loading_cancel");
StatusDisplayer.getDefault().setStatusText(msg);
}
doc.removeDocumentListener(this);
//remove FileChangeListeners from the external DTD files
for(FileObject fo : externalDTDs) {
// System.out.println("[GrammarManager] removed FileObjectListener from " + fo.getPath());
fo.removeFileChangeListener(this);
}
externalDTDs.clear();
guarded = new Position[0];
state = INVALID;
}
示例10: modelToView
import javax.swing.text.Position; //导入依赖的package包/类
static Rectangle2D modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readLock();
}
try {
Rectangle alloc = getVisibleEditorRect(tc);
if (alloc != null) {
View rootView = tc.getUI().getRootView(tc);
rootView.setSize(alloc.width, alloc.height);
Shape s = rootView.modelToView(pos, alloc, bias);
if (s != null) {
return s.getBounds2D();
}
}
} finally {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
return null;
}
示例11: modelToViewChecked
import javax.swing.text.Position; //导入依赖的package包/类
@Override
public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
int startOffset = getStartOffset();
Rectangle2D.Double mutableBounds = ViewUtils.shape2Bounds(alloc);
int charIndex = offset - startOffset;
if (charIndex == 1) {
mutableBounds.x += firstTabWidth;
} else if (charIndex > 1) {
int extraTabCount = getLength() - 1;
if (extraTabCount > 0) {
mutableBounds.x += firstTabWidth + (charIndex - 1) * ((width - firstTabWidth) / extraTabCount);
}
}
mutableBounds.width = 1;
return mutableBounds;
}
示例12: testRemoveAligned2Clip
import javax.swing.text.Position; //导入依赖的package包/类
public void testRemoveAligned2Clip() {
PositionsBag hs = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(pos(10), pos(40), attribsA);
hs.removeHighlights(pos(10), pos(20), true);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> atttributes = hs.getAttributes();
assertEquals("Wrong number of highlights", 2, marks.size());
assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset", 40, marks.get(1).getOffset());
assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
assertNull(" 1. highlight - wrong end", atttributes.get(1));
hs.removeHighlights(pos(30), pos(40), true);
assertEquals("Wrong number of highlights", 2, marks.size());
assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset", 30, marks.get(1).getOffset());
assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
assertNull(" 1. highlight - wrong end", atttributes.get(1));
}
示例13: addBias
import javax.swing.text.Position; //导入依赖的package包/类
static List<Position.Bias> addBias(List<Position.Bias> biases, int offsetAndBias, int index) {
if ((offsetAndBias & BACKWARD_BIAS_BIT) != 0) {
if (biases == null) {
biases = new ArrayList<>(index + 1);
while (--index >= 0) {
biases.add(Position.Bias.Forward);
}
}
biases.add(Position.Bias.Backward);
} else { // Forward bias
if (biases != null) {
biases.add(Position.Bias.Forward);
}
}
return biases;
}
示例14: reformat
import javax.swing.text.Position; //导入依赖的package包/类
/**
* Reformat a block of code.
* <br/>
* The document should not be locked prior entering of this method.
* <br/>
* The method should be called from AWT thread so that the given offsets are more stable.
*
* @param doc document to work with
* @param startOffset offset at which the formatting starts
* @param endOffset offset at which the formatting ends
* @return length of the reformatted code
*/
public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset) throws BadLocationException {
final Reformat formatter = Reformat.get(doc);
formatter.lock();
try {
final Object[] result = new Object[1];
doc.runAtomicAsUser(new Runnable() {
public @Override void run() {
try {
Position endPos = doc.createPosition(endOffset);
formatter.reformat(startOffset, endOffset);
result[0] = Math.max(endPos.getOffset() - startOffset, 0);
} catch (BadLocationException ex) {
result[0] = ex;
}
}
});
if (result[0] instanceof BadLocationException) {
throw (BadLocationException) result[0];
} else {
return (Integer) result[0];
}
} finally {
formatter.unlock();
}
}
示例15: testRemoveLeftOverlapClip
import javax.swing.text.Position; //导入依赖的package包/类
public void testRemoveLeftOverlapClip() {
PositionsBag hs = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(pos(10), pos(20), attribsA);
hs.removeHighlights(pos(5), pos(15), true);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> atttributes = hs.getAttributes();
assertEquals("Wrong number of highlights", 2, marks.size());
assertEquals("1. highlight - wrong start offset", 15, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
assertNull(" 1. highlight - wrong end", atttributes.get(1));
}