java.awt.font.TextHitInfo#trailing ( )源码实例Demo

下面列出了java.awt.font.TextHitInfo#trailing ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码2 项目: TencentKona-8   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码3 项目: jdk8u-dev-jdk   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码4 项目: openjdk-jdk8u   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码6 项目: jdk8u_jdk   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码7 项目: openjdk-jdk9   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码8 项目: jdk8u-jdk   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码9 项目: jdk8u-jdk   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码10 项目: openjdk-8   文件: TextMeasureTests.java
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
源代码11 项目: dragonwell8_jdk   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码12 项目: TencentKona-8   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码13 项目: jdk8u_jdk   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码14 项目: openjdk-jdk8u   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码15 项目: jdk8u-jdk   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码16 项目: Bytecoder   文件: SwingUtilities2.java
/**
 * Draws the string at the specified location underlining the specified
 * character.
 *
 * @param c JComponent that will display the string, may be null
 * @param g Graphics to draw the text to
 * @param text String to display
 * @param underlinedIndex Index of a character in the string to underline
 * @param x X coordinate to draw the text at
 * @param y Y coordinate to draw the text at
 * @param useFPAPI use floating point API
 */
public static void drawStringUnderlineCharAt(JComponent c, Graphics g,
                                             String text, int underlinedIndex,
                                             float x, float y,
                                             boolean useFPAPI) {
    if (text == null || text.length() <= 0) {
        return;
    }
    SwingUtilities2.drawString(c, g, text, x, y, useFPAPI);
    int textLength = text.length();
    if (underlinedIndex >= 0 && underlinedIndex < textLength ) {
        float underlineRectY = y;
        int underlineRectHeight = 1;
        float underlineRectX = 0;
        int underlineRectWidth = 0;
        boolean isPrinting = isPrinting(g);
        boolean needsTextLayout = isPrinting;
        if (!needsTextLayout) {
            synchronized (charsBufferLock) {
                syncCharsBuffer(text);
                needsTextLayout =
                    isComplexLayout(charsBuffer, 0, textLength);
            }
        }
        if (!needsTextLayout) {
            FontMetrics fm = g.getFontMetrics();
            underlineRectX = x +
                SwingUtilities2.stringWidth(c,fm,
                                    text.substring(0,underlinedIndex));
            underlineRectWidth = fm.charWidth(text.
                                              charAt(underlinedIndex));
        } else {
            Graphics2D g2d = getGraphics2D(g);
            if (g2d != null) {
                TextLayout layout =
                    createTextLayout(c, text, g2d.getFont(),
                                   g2d.getFontRenderContext());
                if (isPrinting) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(text, getFontRenderContext(c)).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                                    text) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }
                }
                TextHitInfo leading =
                    TextHitInfo.leading(underlinedIndex);
                TextHitInfo trailing =
                    TextHitInfo.trailing(underlinedIndex);
                Shape shape =
                    layout.getVisualHighlightShape(leading, trailing);
                Rectangle rect = shape.getBounds();
                underlineRectX = x + rect.x;
                underlineRectWidth = rect.width;
            }
        }
        g.fillRect((int) underlineRectX, (int) underlineRectY + 1,
                   underlineRectWidth, underlineRectHeight);
    }
}
 
源代码17 项目: openjdk-jdk9   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码18 项目: jdk8u-jdk   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码19 项目: hottub   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}
 
源代码20 项目: jdk8u-dev-jdk   文件: bug8041990.java
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            SunToolkit.createNewAppContext();
            SwingUtilities.invokeLater(() -> {
                frame = new JFrame();
                component = new JLabel("Test Text");
                frame.add(component);
                frame.setBounds(100, 100, 100, 100);
                frame.setVisible(true);
                startSwingLatch.countDown();
            });
        }).start();
        startSwingLatch.await();

        AtomicReference<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(0));
            } catch (Exception e) {
                caughtException.set(e);
            }
        });
        checkThread.start();
        checkThread.join();

        if (caughtException.get() != null) {
            throw new RuntimeException("Failed. Caught exception!", caughtException.get());
        }
    } finally {
        new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> {
            if (frame != null) {
                frame.dispose();
            }
        })).start();
    }
}