Example usage for javax.swing.text Document getStartPosition

List of usage examples for javax.swing.text Document getStartPosition

Introduction

In this page you can find the example usage for javax.swing.text Document getStartPosition.

Prototype

public Position getStartPosition();

Source Link

Document

Returns a position that represents the start of the document.

Usage

From source file:de.unentscheidbar.validation.swing.trigger.DocumentChangeTriggerTest.java

@Override
protected void provokeTrigger(Iterable<JTextComponent> components) {

    for (final JTextComponent c : components) {
        runInEdt(new Callable<Void>() {

            @Override/* w  w  w. ja  va  2 s  . c o  m*/
            public Void call() throws Exception {

                Document doc = c.getDocument();
                switch (rnd.nextInt(3)) {
                case 0:
                    doc.remove(doc.getStartPosition().getOffset(), doc.getLength() / 2);
                    break;
                case 1:
                    doc.insertString(rnd.nextInt(Math.max(1, doc.getStartPosition().getOffset())),
                            RandomStringUtils.randomAlphanumeric(1 + rnd.nextInt(10)), null);
                    break;
                case 2:
                    c.setText(UUID.randomUUID().toString());
                    break;
                default:
                    Assert.fail();
                }
                return null;
            }
        });

    }
    drainEventQueue();
}