public View breakView(int axis, int p0, float pos, float len) { if (axis == View.X_AXIS) { checkPainter(); int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len); try { // if the view contains line break char break the view int index = getDocument().getText(p0, p1 - p0) .indexOf(WrapHTMLFactory.SEPARATOR); if (index >= 0) { GlyphView v = (GlyphView) createFragment(p0, p0 + index + 1); return v; } } catch (BadLocationException ex) { // should never happen } } return super.breakView(axis, p0, pos, len); }
bug6857057() { Element elem = new StubBranchElement(" G L Y P H V"); GlyphView view = new GlyphView(elem); float pos = elem.getStartOffset(); float len = elem.getEndOffset() - pos; int res = view.getBreakWeight(View.X_AXIS, pos, len); if (res != View.ExcellentBreakWeight) { throw new RuntimeException("breakWeight != ExcellentBreakWeight"); } }
private static void retrieveGlyphViews(View root) { for (int i=0; i<= root.getViewCount()-1; i++) { View view = root.getView(i); if (view instanceof GlyphView && view.isVisible()) { if (!glyphViews.contains(view)) { glyphViews.add((GlyphView)view); } } else { retrieveGlyphViews(view); } } }
public View breakView(int axis, int p0, float pos, float len) { if(axis == View.X_AXIS) { checkPainter(); int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len); int breakSpot = getBreakSpot(p0, p1); if(breakSpot != -1) { p1 = breakSpot; } // else, no break in the region, return a fragment of the // bounded region. if(p0 == getStartOffset() && p1 == getEndOffset()) { return this; } GlyphView v = (GlyphView)createFragment(p0, p1); // FIX no setter //v.x = (int)pos; return v; } return this; }
public static void main(String[] args) throws Exception { toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); robot = new Robot(); robot.setAutoDelay(50); glyphViews = new ArrayList<GlyphView>(); createAndShowGUI(text1); toolkit.realSync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); } }); GlyphView [] arr1 = glyphViews.toArray(new GlyphView[glyphViews.size()]); frame.dispose(); glyphViews.clear(); createAndShowGUI(text2); toolkit.realSync(); Util.hitKeys(robot, KeyEvent.VK_HOME); toolkit.realSync(); Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_N); Util.hitKeys(robot, KeyEvent.VK_E); Util.hitKeys(robot, KeyEvent.VK_SPACE); Util.hitKeys(robot, KeyEvent.VK_T); Util.hitKeys(robot, KeyEvent.VK_W); Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_SPACE); toolkit.realSync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); } }); GlyphView [] arr2 = glyphViews.toArray(new GlyphView[glyphViews.size()]); if (arr1.length != arr2.length) { throw new RuntimeException("Test Failed!"); } for (int i=0; i<arr1.length; i++) { GlyphView v1 = arr1[i]; GlyphView v2 = arr2[i]; Field field = GlyphView.class.getDeclaredField("breakSpots"); field.setAccessible(true); int[] breakSpots1 = (int[])field.get(v1); int[] breakSpots2 = (int[])field.get(v2); if (!Arrays.equals(breakSpots1,breakSpots2)) { throw new RuntimeException("Test Failed!"); } } frame.dispose(); }
public static void main(String[] args) throws Exception { robot = new Robot(); robot.setAutoDelay(50); glyphViews = new ArrayList<GlyphView>(); createAndShowGUI(text1); robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); } }); GlyphView [] arr1 = glyphViews.toArray(new GlyphView[glyphViews.size()]); frame.dispose(); glyphViews.clear(); createAndShowGUI(text2); robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_HOME); robot.waitForIdle(); Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_N); Util.hitKeys(robot, KeyEvent.VK_E); Util.hitKeys(robot, KeyEvent.VK_SPACE); Util.hitKeys(robot, KeyEvent.VK_T); Util.hitKeys(robot, KeyEvent.VK_W); Util.hitKeys(robot, KeyEvent.VK_O); Util.hitKeys(robot, KeyEvent.VK_SPACE); robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { retrieveGlyphViews(editorPane.getUI().getRootView(editorPane)); } }); GlyphView [] arr2 = glyphViews.toArray(new GlyphView[glyphViews.size()]); if (arr1.length != arr2.length) { throw new RuntimeException("Test Failed!"); } for (int i=0; i<arr1.length; i++) { GlyphView v1 = arr1[i]; GlyphView v2 = arr2[i]; Field field = GlyphView.class.getDeclaredField("breakSpots"); field.setAccessible(true); int[] breakSpots1 = (int[])field.get(v1); int[] breakSpots2 = (int[])field.get(v2); if (!Arrays.equals(breakSpots1,breakSpots2)) { throw new RuntimeException("Test Failed!"); } } frame.dispose(); }
public float getSpan(GlyphView v, int startOffset, int endOffset, TabExpander tabExpander, float x) { return CHAR_WIDTH * (endOffset - startOffset); }
public int getBoundedPosition(GlyphView v, int startOffset, float x, float len) { int result = (int)len / CHAR_WIDTH + startOffset; return result <= v.getEndOffset() ? result : v.getEndOffset(); }
public float getHeight(GlyphView v) { return 0; }
public float getAscent(GlyphView v) { return 0; }
public float getDescent(GlyphView v) { return 0; }
public void paint(GlyphView v, Graphics g, Shape alloc, int startOffset, int endOffset) { }
public Shape modelToView(GlyphView v, int offset, Bias bias, Shape alloc) throws BadLocationException { return null; }
public int viewToModel(GlyphView v, float x, float y, Shape alloc, Bias[] biasReturn) { return -1; }