public void testCreateElement() throws Exception { Document doc = jta.getDocument(); Element elem = doc.getDefaultRootElement(); BasicTextUI ui = (BasicTextUI) jta.getUI(); assertTrue(ui.create(elem) instanceof PlainView); jta.setLineWrap(true); assertTrue(ui.create(elem) instanceof WrappedPlainView); jta.setLineWrap(false); elem = elem.getElement(0); assertTrue(ui.create(elem) instanceof PlainView); jta.setLineWrap(true); assertTrue(ui.create(elem) instanceof WrappedPlainView); try { new BasicTextAreaUI().create(null); fail("NPE should be thrown"); } catch (NullPointerException npe) { // PASSED } }
/** * Returns a ViewFactory that supplies WrappedPlainViews. */ public ViewFactory getViewFactory() { return new ViewFactory() { public View create(Element el) { return new WrappedPlainView(el); } }; }
/** * Create the view. Returns a WrappedPlainView if the text area * has lineWrap set to true, otherwise returns a PlainView. If * lineWrap is true has to check whether the wrap style is word * or character and return an appropriate WrappedPlainView. * * @param elem the element to create a View for * @return an appropriate View for the element */ public View create(Element elem) { JTextArea comp = (JTextArea) getComponent(); if (comp.getLineWrap()) { if (comp.getWrapStyleWord()) return new WrappedPlainView(elem, true); else return new WrappedPlainView(elem, false); } else return new PlainView(elem); }
@Override public View create(final Element element) { Document doc = element.getDocument(); Boolean i18n = (Boolean)doc.getProperty(StringConstants.BIDI_PROPERTY); if (i18n.booleanValue()) { return AccessController.doPrivileged(new PrivilegedAction<View>() { public View run() { try { Class cls = Class.forName(PLAIN_VIEW_I18N_CLASS); Constructor constructor = cls.getConstructor(new Class[] {Element.class}); constructor.setAccessible(true); return (View)constructor.newInstance(new Object[] {element}); } catch (Exception e) { return null; } } }); } JTextComponent comp = getComponent(); boolean lineWrap = false; boolean wordWrap = false; if (comp instanceof JTextArea) { JTextArea c = (JTextArea)getComponent(); lineWrap = c.getLineWrap(); wordWrap = c.getWrapStyleWord(); } if (lineWrap) { return new WrappedPlainView(element, wordWrap); } return new PlainView(element); }
/** * Return true when a Wrapped View is used. * * @see Scrollable#getScrollableTracksViewportWidth() */ public boolean getScrollableTracksViewportWidth() { View view = editor.getUI().getRootView(editor).getView(0); if (view instanceof WrappedPlainView) { return true; } else if (getParent() instanceof JViewport) { return (((JViewport) getParent()).getWidth() > getPreferredSize().width); } return false; }
/** Plain view for the element */ public @Override View create(Element elem) { return new WrappedPlainView(elem); }
public View create(Element elem) { return new WrappedPlainView(elem); }