com.sun.swingset3.demos.JHyperlink Java Examples

The following examples show how to use com.sun.swingset3.demos.JHyperlink. 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: ButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();

    JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
    mainFrame.setComparator(EXACT_STRING_COMPARATOR);

    // Check all the buttons
    for (int i = 0; i < BUTTON_TOOLTIP.length; i++) {
        String tooltip = BUTTON_TOOLTIP[i];

        JButtonOperator button = new JButtonOperator(mainFrame, new ByToolTipChooser(tooltip));

        assertEquals(BUTTON_TEXT_BEFORE[i], button.getText());

        // Two buttons are hyperlinks, we don't want to click them
        if (!button.getSource().getClass().equals(JHyperlink.class)) {
            checkButton(button);
        }

        if (BUTTON_TEXT_AFTER.length > i) {
            assertEquals(BUTTON_TEXT_AFTER[i], button.getText());
        } else {
            assertEquals(BUTTON_TEXT_BEFORE[i], button.getText());
        }
    }
}
 
Example #2
Source File: HyperlinkCellRenderer.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public HyperlinkCellRenderer(Action action, boolean underlineOnRollover) {
    setAction(action);
    setHorizontalAlignment(JHyperlink.LEFT);
    rowColors = new Color[1];
    rowColors[0] = UIManager.getColor("Table.background");
    this.underlineOnRollover = underlineOnRollover;
    applyDefaults();
}
 
Example #3
Source File: HyperlinkCellRenderer.java    From littleluck with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfPointInsideHyperlink(Point p) {
    hitColumnIndex = table.columnAtPoint(p);
    hitRowIndex = table.rowAtPoint(p);

    if (hitColumnIndex != -1 && hitRowIndex != -1 &&
            columnModelIndeces.contains(table.getColumnModel().
                    getColumn(hitColumnIndex).getModelIndex())) {
        // We know point is within a hyperlink column, however we do further hit testing
        // to see if point is within the text bounds on the hyperlink
        TableCellRenderer renderer = table.getCellRenderer(hitRowIndex, hitColumnIndex);
        JHyperlink hyperlink = (JHyperlink) table.prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

        // Convert the event to the renderer's coordinate system
        cellRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
        hyperlink.setSize(cellRect.width, cellRect.height);
        p.translate(-cellRect.x, -cellRect.y);
        cellRect.x = cellRect.y = 0;
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        SwingUtilities.layoutCompoundLabel(
                hyperlink.getFontMetrics(hyperlink.getFont()),
                hyperlink.getText(), hyperlink.getIcon(),
                hyperlink.getVerticalAlignment(),
                hyperlink.getHorizontalAlignment(),
                hyperlink.getVerticalTextPosition(),
                hyperlink.getHorizontalTextPosition(),
                cellRect, iconRect, textRect, hyperlink.getIconTextGap());

        if (textRect.contains(p)) {
            // point is within hyperlink text bounds
            return true;
        }
    }
    // point is not within a hyperlink's text bounds
    hitRowIndex = -1;
    hitColumnIndex = -1;
    return false;
}
 
Example #4
Source File: HyperlinkCellRenderer.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public HyperlinkCellRenderer(Action action, boolean underlineOnRollover) {
    setAction(action);
    setHorizontalAlignment(JHyperlink.LEFT);
    rowColors = new Color[1];
    rowColors[0] = UIManager.getColor("Table.background");
    this.underlineOnRollover = underlineOnRollover;
    applyDefaults();
}
 
Example #5
Source File: HyperlinkCellRenderer.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfPointInsideHyperlink(Point p) {
    hitColumnIndex = table.columnAtPoint(p);
    hitRowIndex = table.rowAtPoint(p);

    if (hitColumnIndex != -1 && hitRowIndex != -1 &&
            columnModelIndeces.contains(table.getColumnModel().
                    getColumn(hitColumnIndex).getModelIndex())) {
        // We know point is within a hyperlink column, however we do further hit testing
        // to see if point is within the text bounds on the hyperlink
        TableCellRenderer renderer = table.getCellRenderer(hitRowIndex, hitColumnIndex);
        JHyperlink hyperlink = (JHyperlink) table.prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

        // Convert the event to the renderer's coordinate system
        cellRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
        hyperlink.setSize(cellRect.width, cellRect.height);
        p.translate(-cellRect.x, -cellRect.y);
        cellRect.x = cellRect.y = 0;
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        SwingUtilities.layoutCompoundLabel(
                hyperlink.getFontMetrics(hyperlink.getFont()),
                hyperlink.getText(), hyperlink.getIcon(),
                hyperlink.getVerticalAlignment(),
                hyperlink.getHorizontalAlignment(),
                hyperlink.getVerticalTextPosition(),
                hyperlink.getHorizontalTextPosition(),
                cellRect, iconRect, textRect, hyperlink.getIconTextGap());

        if (textRect.contains(p)) {
            // point is within hyperlink text bounds
            return true;
        }
    }
    // point is not within a hyperlink's text bounds
    hitRowIndex = -1;
    hitColumnIndex = -1;
    return false;
}
 
Example #6
Source File: HyperlinkCellRenderer.java    From Darcula with Apache License 2.0 5 votes vote down vote up
public HyperlinkCellRenderer(Action action, boolean underlineOnRollover) {
    setAction(action);
    setHorizontalAlignment(JHyperlink.LEFT);
    rowColors = new Color[1];
    rowColors[0] = UIManager.getColor("Table.background");
    this.underlineOnRollover = underlineOnRollover;
    applyDefaults();
}
 
Example #7
Source File: HyperlinkCellRenderer.java    From Darcula with Apache License 2.0 5 votes vote down vote up
protected boolean checkIfPointInsideHyperlink(Point p) {
    hitColumnIndex = table.columnAtPoint(p);
    hitRowIndex = table.rowAtPoint(p);

    if (hitColumnIndex != -1 && hitRowIndex != -1 &&
            columnModelIndeces.contains(table.getColumnModel().
                    getColumn(hitColumnIndex).getModelIndex())) {
        // We know point is within a hyperlink column, however we do further hit testing
        // to see if point is within the text bounds on the hyperlink
        TableCellRenderer renderer = table.getCellRenderer(hitRowIndex, hitColumnIndex);
        JHyperlink hyperlink = (JHyperlink) table.prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

        // Convert the event to the renderer's coordinate system
        cellRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
        hyperlink.setSize(cellRect.width, cellRect.height);
        p.translate(-cellRect.x, -cellRect.y);
        cellRect.x = cellRect.y = 0;
        iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
        textRect.x = textRect.y = textRect.width = textRect.height = 0;
        SwingUtilities.layoutCompoundLabel(
                hyperlink.getFontMetrics(hyperlink.getFont()),
                hyperlink.getText(), hyperlink.getIcon(),
                hyperlink.getVerticalAlignment(),
                hyperlink.getHorizontalAlignment(),
                hyperlink.getVerticalTextPosition(),
                hyperlink.getHorizontalTextPosition(),
                cellRect, iconRect, textRect, hyperlink.getIconTextGap());

        if (textRect.contains(p)) {
            // point is within hyperlink text bounds
            return true;
        }
    }
    // point is not within a hyperlink's text bounds
    hitRowIndex = -1;
    hitColumnIndex = -1;
    return false;
}