javax.swing.text.JTextComponent Java Examples

The following examples show how to use javax.swing.text.JTextComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompletionLayoutPopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void show(JTextComponent editorComponent, int anchorOffset) {
    if (editorComponent == null || ClipboardHistory.getInstance().getData().isEmpty()) {
        return;
    }

    if (!isVisible()) { // documentation already visible
        ScrollCompletionPane scrollCompletionPane = new ScrollCompletionPane(editorComponent, ClipboardHistory.getInstance(), null, chSelectionListener, mouseListener);
        scrollCompletionPane.setName(POPUP_NAME);
        setContentComponent(scrollCompletionPane);
        setLayout(scrollCompletionPane);   
        setEditorComponent(editorComponent);
    }

    if (!isVisible()) { // do not check for size as it should remain the same
        // Set anchoring only if not displayed yet because completion
        // may have overriden the anchoring
        setAnchorOffset(anchorOffset);
        updateLayout(this);
        chSelectionListener.valueChanged(null);
        
    } // otherwise leave present doc displayed
}
 
Example #2
Source File: ActionUtils.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the line of text at the given position.  The returned value may
 * be null.  It will not contain the trailing new-line character.
 * @param target the text component
 * @param pos char position
 * @return
 */
public static String getLineAt(JTextComponent target, int pos) {
    String line = null;
    Document doc = target.getDocument();
    if (doc instanceof PlainDocument) {
        PlainDocument pDoc = (PlainDocument) doc;
        int start = pDoc.getParagraphElement(pos).getStartOffset();
        int end = pDoc.getParagraphElement(pos).getEndOffset();
        try {
            line = doc.getText(start, end - start);
            if (line != null && line.endsWith("\n")) {
                line = line.substring(0, line.length() - 1);
            }
        } catch (BadLocationException ex) {
            Logger.getLogger(ActionUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return line;
}
 
Example #3
Source File: AbbrevDetection.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean expand(CodeTemplateManagerOperation op, JTextComponent component, int abbrevStartOffset, CharSequence abbrev) {
    op.waitLoaded();
    CodeTemplate ct = op.findByAbbreviation(abbrev.toString());
    if (ct != null) {
        if (accept(ct, CodeTemplateManagerOperation.getTemplateFilters(component, abbrevStartOffset))) {
            Document doc = component.getDocument();
            sendUndoableEdit(doc, CloneableEditorSupport.BEGIN_COMMIT_GROUP);
            try {
                // Remove the abbrev text
                doc.remove(abbrevStartOffset, abbrev.length());
                ct.insert(component);
            } catch (BadLocationException ble) {
            } finally {
                sendUndoableEdit(doc, CloneableEditorSupport.END_COMMIT_GROUP);
            }
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: IMGCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public IMGCustomizer(IMG img, JTextComponent target) {
    this.img = img;
    this.target = target;
    
    initComponents();

    jFileChooser1.setAcceptAllFileFilterUsed(false);
    jFileChooser1.addChoosableFileFilter(
        new FileFilter() {
            public boolean accept(File pathname) {
                FileObject fo = FileUtil.toFileObject(pathname);
                return pathname.isDirectory() || (fo != null && fo.getMIMEType().startsWith("image/")); // NOI18N
            }
            public String getDescription() {
                String desc = NbBundle.getMessage(IMGCustomizer.class, "LBL_IMG_FileChooserDesc");
                return desc;
            }
        }
    );
            
}
 
Example #5
Source File: SwingUtilities2.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines whether the SelectedTextColor should be used for painting text
 * foreground for the specified highlight.
 *
 * Returns true only if the highlight painter for the specified highlight
 * is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
 * or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
 * is null or equals to the selection color of the text component.
 *
 * This is a hack for fixing both bugs 4761990 and 5003294
 */
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
    Highlighter.HighlightPainter painter = h.getPainter();
    String painterClass = painter.getClass().getName();
    if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
            painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
        return false;
    }
    try {
        DefaultHighlighter.DefaultHighlightPainter defPainter =
                (DefaultHighlighter.DefaultHighlightPainter) painter;
        if (defPainter.getColor() != null &&
                !defPainter.getColor().equals(c.getSelectionColor())) {
            return false;
        }
    } catch (ClassCastException e) {
        return false;
    }
    return true;
}
 
Example #6
Source File: TextContextualMenuHelper.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Install some basic contextual menu items for a JTextComponent. Note Swing
 * already implements most basic commands, so the implementation is not
 * written here. This only applies a simple UI to existing functionality,
 * because some users won't know to try ctrl-C to copy.
 * 
 * @param jtc
 *            the text component to install contextual menu items on.
 * @param copy
 *            whether "Copy" should be included.
 * @param cut
 *            whether "Cut" should be included.
 * @param paste
 *            whether "Paste" should be included.
 * @param clear
 *            whether "Clear" should be included.
 */
public static void install(final JTextComponent jtc, boolean copy,
		boolean cut, boolean paste, boolean clear) {
	if (cut) {
		install(jtc, "cut", "cut");
	}
	if (copy) {
		install(jtc, "copy", "copy");
	}
	if (paste) {
		install(jtc, "paste", "paste");
	}
	if (clear) {
		ContextualMenuHelper.add(jtc, strings.getString("clear"),
				new Runnable() {
					public void run() {
						jtc.setText("");
					}
				});
	}
}
 
Example #7
Source File: SetProperty.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleTransfer(JTextComponent targetComponent) {
    allBeans = initAllBeans(targetComponent);
    SetPropertyCustomizer c = new SetPropertyCustomizer(this, targetComponent);
    boolean accept = c.showDialog();
    if (accept) {
        String body = createBody();
        try {
            JspPaletteUtilities.insert(body, targetComponent);
        } catch (BadLocationException ble) {
            accept = false;
        }
    }

    return accept;
}
 
Example #8
Source File: ProjectEditorSupportImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public int getCurrentOffset() {
    try {
        return performOnAWT(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                JTextComponent mostActiveEditor = EditorRegistry.lastFocusedComponent();

                if ((mostActiveEditor != null) && (mostActiveEditor.getCaret() != null)) {
                    return mostActiveEditor.getCaretPosition();
                }

                return -1;
            }
        });
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
    }
    return -1;
}
 
Example #9
Source File: EditorRegistry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized static void _focusGained(JTextComponent c, Component origFocused, List<PropertyChangeEvent> events) {
    Item item = item(c);
    assert (item != null) : "Not registered!"; // NOI18N

    // Move the item to head of the list
    removeFromItemList(item);
    addToItemListAsFirst(item);
    item.focused = true;

    c.addPropertyChangeListener(PropertyDocL.INSTANCE);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, FOCUS_GAINED_PROPERTY + ": " + dumpComponent(c) + '\n'); //NOI18N
        logItemListFinest();
    }
    if (c == origFocused) {
        origFocused = null;
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("has equal components, using origFocused = "+origFocused);
        }
    }
    events.add(new PropertyChangeEvent(EditorRegistry.class, FOCUS_GAINED_PROPERTY, origFocused, c));
}
 
Example #10
Source File: NbToolTip.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Request(
    AnnotationDesc annoDesc, Annotation[] annos, Line.Part lp,
    int offset, Object tooltipAttributeValue,
    ToolTipSupport tts, JTextComponent component, AbstractDocument doc, NbEditorKit kit, int requestId
) {
    this.annoDesc = annoDesc;
    this.annos = annos;
    this.linePart = lp;
    this.tts = tts;
    this.component = component;
    this.doc = doc;
    this.kit = kit;
    this.offset = offset;
    this.tooltipAttributeValue = tooltipAttributeValue;
    this.requestId = requestId;
}
 
Example #11
Source File: CodeTemplateCompletionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected @Override boolean canFilter(JTextComponent component) {
    if (component.getCaret() == null) {
        return false;
    }
    int caretOffset = component.getSelectionStart();
    Document doc = component.getDocument();
    filterPrefix = null;
    if (caretOffset >= queryCaretOffset) {
        if (queryAnchorOffset < queryCaretOffset) {
            try {
                filterPrefix = doc.getText(queryAnchorOffset, caretOffset - queryAnchorOffset);
                if (!isJavaIdentifierPart(filterPrefix)) {
                    filterPrefix = null;
                }
            } catch (BadLocationException e) {
                // filterPrefix stays null -> no filtering
            }
        }
    }
    return (filterPrefix != null);
}
 
Example #12
Source File: FadingDemo.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void setTextAndAnimate(final JTextComponent textComponent,
        final String text) {
   Color c = textComponent.getForeground();

   KeyFrames keyFrames = new KeyFrames(KeyValues.create(
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 255),
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 0),
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 255)
           ));
   PropertySetter setter = new PropertySetter(textComponent, "foreground",
           keyFrames);

   Animator animator = new Animator(200, setter);
   animator.addTarget(new TimingTargetAdapter() {
       private boolean textSet = false;

       public void timingEvent(float fraction) {
           if (fraction >= 0.5f && !textSet) {
               textComponent.setText(text);
               textSet = true;
           }
       } 
   });
   animator.start();
}
 
Example #13
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerAccessorFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ConfigurableControlAccessorFactory.class);
	
	Map<Class<?>, Class<?extends ControlAccessor>> accessors = 
			new ManagedMap<Class<?>,Class<?extends ControlAccessor>>();
	accessors.put(JTextComponent.class, TextComponentAccessor.class);
	accessors.put(JList.class, ListAccessor.class);
	accessors.put(Selector.class, SelectorAccessor.class);
	accessors.put(JToggleButton.class, ToggleButtonAccessor.class);
	accessors.put(JComboBox.class, ComboAccessor.class);
	accessors.put(View.class, ViewAccessor.class);
	accessors.put(JLabel.class, LabelAccessor.class);
	accessors.put(TablePanel.class, TablePanelAccessor.class);
	bdb.addPropertyValue("accessors", accessors);
	
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), ACCESSOR_FACTORY_BEAN_NAME);
	
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #14
Source File: SwingElementState.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the element is editable or not
 *
 * @return if the element is editable or not
 */
@PublicAtsApi
public boolean isElementEditable() {

    try {

        Component component = SwingElementLocator.findFixture(element).component();
        if (component instanceof JTextComponent) {
            return ((JTextComponent) component).isEditable();
        } else if (component instanceof JComboBox) {
            return ((JComboBox) component).isEditable();
        } else if (component instanceof JTree) {
            return ((JTree) component).isEditable();
        }
        throw new NotSupportedOperationException("Component of type \"" + component.getClass().getName()
                                                 + "\" doesn't have 'editable' state!");
    } catch (ElementNotFoundException nsee) {
        lastNotFoundException = nsee;
        return false;
    }
}
 
Example #15
Source File: DesktopPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void updateMissingValueState() {
    if (!(impl.getEditor() instanceof JTextComponent)) {
        return;
    }
    JTextComponent editor = (JTextComponent) impl.getEditor();
    boolean value = required && isEditableWithParent() && StringUtils.isBlank(editor.getText());

    decorateMissingValue(impl.getEditor(), value);
}
 
Example #16
Source File: SynthScrollPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void componentAdded(ContainerEvent e) {
    if (e.getChild() instanceof JTextComponent) {
        e.getChild().addFocusListener(this);
        viewportViewHasFocus = e.getChild().isFocusOwner();
        scrollpane.repaint();
    }
}
 
Example #17
Source File: SeaGlassTextFieldUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicTextUI#getPreferredSize(javax.swing.JComponent)
 */
public Dimension getPreferredSize(JComponent c) {
    // The following code has been derived from BasicTextUI.
    Document  doc      = ((JTextComponent) c).getDocument();
    Insets    i        = c.getInsets();
    Dimension d        = c.getSize();
    View      rootView = getRootView((JTextComponent) c);

    if (doc instanceof AbstractDocument) {
        ((AbstractDocument) doc).readLock();
    }

    try {
        if ((d.width > (i.left + i.right)) && (d.height > (i.top + i.bottom))) {
            rootView.setSize(d.width - i.left - i.right, d.height - i.top - i.bottom);
        } else if (d.width == 0 && d.height == 0) {
            // Probably haven't been layed out yet, force some sort of
            // initial sizing.
            rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
        }

        d.width  = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) + (long) i.left + (long) i.right, Integer.MAX_VALUE);
        d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS) + (long) i.top + (long) i.bottom, Integer.MAX_VALUE);
    } finally {
        if (doc instanceof AbstractDocument) {
            ((AbstractDocument) doc).readUnlock();
        }
    }

    // Fix: The preferred width is always two pixels too small on a Mac.
    d.width += 2;

    // We'd like our heights to be odd by default.
    if ((d.height & 1) == 0) {
        d.height--;
    }

    return d;
}
 
Example #18
Source File: Install.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public synchronized void propertyChange(PropertyChangeEvent evt) {
    JTextComponent jtc = EditorRegistry.focusedComponent();
    if (jtc == null) return;
    
    Document active = jtc.getDocument();
    Object sourceProperty = active.getProperty(Document.StreamDescriptionProperty);
    if (!(sourceProperty instanceof DataObject)) return;

    FileObject activeFile = ((DataObject)sourceProperty).getPrimaryFile();
    TimesCollectorPeer.getDefault().select(activeFile);
}
 
Example #19
Source File: XPStyle.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Insets getBorderInsets(Component c, Insets insets)       {
    insets = super.getBorderInsets(c, insets);

    Insets margin = null;
    if (c instanceof AbstractButton) {
        Insets m = ((AbstractButton)c).getMargin();
        // if this is a toolbar button then ignore getMargin()
        // and subtract the padding added by the constructor
        if(c.getParent() instanceof JToolBar
           && ! (c instanceof JRadioButton)
           && ! (c instanceof JCheckBox)
           && m instanceof InsetsUIResource) {
            insets.top -= 2;
            insets.left -= 2;
            insets.bottom -= 2;
            insets.right -= 2;
        } else {
            margin = m;
        }
    } else if (c instanceof JToolBar) {
        margin = ((JToolBar)c).getMargin();
    } else if (c instanceof JTextComponent) {
        margin = ((JTextComponent)c).getMargin();
    }
    if (margin != null) {
        insets.top    = margin.top + 2;
        insets.left   = margin.left + 2;
        insets.bottom = margin.bottom + 2;
        insets.right  = margin.right + 2;
    }
    return insets;
}
 
Example #20
Source File: CAccessible.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListeners(Component c) {
    if (c instanceof JTextComponent) {
        JTextComponent tc = (JTextComponent) c;
        AXTextChangeNotifier listener = new AXTextChangeNotifier();
        tc.getDocument().addDocumentListener(listener);
        tc.addCaretListener(listener);
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
Example #21
Source File: AquaTextFieldSearch.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected static void installSearchField(final JTextComponent c) {
    final SearchFieldBorder border = getSearchTextFieldBorder();
    c.setBorder(border);
    c.setLayout(border.getCustomLayout());
    c.add(getFindButton(c), BorderLayout.WEST);
    c.add(getCancelButton(c), BorderLayout.EAST);
    c.add(getPromptLabel(c), BorderLayout.CENTER);

    final TextUI ui = c.getUI();
    if (ui instanceof AquaTextFieldUI) {
        ((AquaTextFieldUI)ui).setPaintingDelegate(border);
    }
}
 
Example #22
Source File: FlatTextFieldUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
static void propertyChange( JTextComponent c, PropertyChangeEvent e ) {
	switch( e.getPropertyName() ) {
		case FlatClientProperties.PLACEHOLDER_TEXT:
		case FlatClientProperties.COMPONENT_ROUND_RECT:
			c.repaint();
			break;

		case FlatClientProperties.MINIMUM_WIDTH:
			c.revalidate();
			break;
	}
}
 
Example #23
Source File: AquaTextFieldFormattedUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void mouseClicked(final MouseEvent e) {
    if (e.getClickCount() != 1) return;

    final JTextComponent c = getComponent();
    // apparently, focus has already been granted by the time this mouse listener fires
//    if (c.hasFocus()) return;

    c.setCaretPosition(viewToModel(c, e.getPoint()));
}
 
Example #24
Source File: CustomCellEditor.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
    final JTextComponent target = getTextComponent(e);
    if (target != null) {
        target.paste();
    }
}
 
Example #25
Source File: CAccessibleText.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static int[] getRangeForLine(final Accessible a, final int lineIndex) {
    Accessible sa = CAccessible.getSwingAccessible(a);
    if (!(sa instanceof JTextComponent)) return null;

    final JTextComponent jc = (JTextComponent) sa;
    final Element root = jc.getDocument().getDefaultRootElement();
    final Element line = root.getElement(lineIndex);
    if (line == null) return null;

    return new int[] { line.getStartOffset(), line.getEndOffset() };
}
 
Example #26
Source File: Merge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MergeTwoFoldersType(RepositoryFile repositoryRoot, File root) {
    super(repositoryRoot);

    panel = new MergeTwoFoldersPanel();
    previewPanel = new TwoFoldersPreviewPanel();

    RepositoryPaths mergeStartRepositoryPaths =
        new RepositoryPaths(
            repositoryRoot,
            (JTextComponent) panel.mergeStartUrlComboBox.getEditor().getEditorComponent(),
            panel.mergeStartBrowseButton,
            panel.mergeStartRevisionTextField,
            panel.mergeStartSearchButton,
            panel.mergeStartBrowseRevisionButton
        );

    RepositoryPaths mergeEndRepositoryPaths =
        new RepositoryPaths(
            repositoryRoot,
            (JTextComponent) panel.mergeEndUrlComboBox.getEditor().getEditorComponent(),
            panel.mergeEndBrowseButton,
            panel.mergeEndRevisionTextField,
            panel.mergeEndSearchButton,
            panel.mergeEndBrowseRevisionButton
        );

    init(mergeStartRepositoryPaths,
         panel.mergeStartRepositoryFolderLabel,
         mergeEndRepositoryPaths,
         panel.mergeEndRepositoryFolderLabel,
         root);

    previewPanel.localFolderTextField.setText(root.getAbsolutePath());
    ((JTextComponent) panel.mergeStartUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
    ((JTextComponent) panel.mergeEndUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
}
 
Example #27
Source File: AttributeResultItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected int removeTextLength(JTextComponent component, int offset, int removeLength) {
    if (removeLength <= 0) {
        return super.removeTextLength(component, offset, removeLength);
    }
    TokenSequence s = createTokenSequence(component);
    s.move(offset);
    if (!s.moveNext()) {
        return super.removeTextLength(component, offset, removeLength);
    }
    TokenId id = s.token().id();
    if (id != XMLTokenId.ARGUMENT) {
        return s.token().length() - (offset - s.offset());
    }
    int l = s.offset() + s.token().length();
    while (s.moveNext()) {
        id = s.token().id();
        if (id== XMLTokenId.VALUE) {
            // remove up to and including the quote
            return s.offset() - offset + 1;
        } else if (!(id == XMLTokenId.WS || id == XMLTokenId.OPERATOR)) {
            break;
        }
        l = s.offset() + s.token().length();
    }
    return l - offset;
}
 
Example #28
Source File: MultiTextUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int viewToModel2D(JTextComponent a, Point2D b, Position.Bias[] c) {
    int returnValue =
        ((TextUI) (uis.elementAt(0))).viewToModel2D(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).viewToModel2D(a,b,c);
    }
    return returnValue;
}
 
Example #29
Source File: AquaTextFieldBorder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static int getShrinkageFor(final JTextComponent jc, final int height) {
    if (jc == null) return 0;
    final TextUI ui = jc.getUI();
    if (ui == null) return 0;
    final Dimension size = ui.getPreferredSize(jc);
    if (size == null) return 0;
    final int shrinkage = size.height - height;
    return (shrinkage < 0) ? 0 : (shrinkage > 3) ? 3 : shrinkage;
}
 
Example #30
Source File: LineHighlighter.java    From darklaf with MIT License 5 votes vote down vote up
public void paint(final Graphics g, final int p0, final int p1, final Shape bounds,
                  final JTextComponent c) {
    try {
        Rectangle r = c.modelToView(c.getCaretPosition());
        g.setColor(color);
        g.fillRect(0, r.y, c.getWidth(), r.height);

        if (lastView == null) {
            lastView = r;
        }
    } catch (BadLocationException ble) {
        ble.printStackTrace();
    }
}