Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8260690: JConsole User Guide Link from the Help menu is not accessibl…
…e by keyboard

Reviewed-by: aivanov, dmarkov
  • Loading branch information
skodanda authored and Dmitry Markov committed May 21, 2021
1 parent e48d7d6 commit b5d32bb
Showing 1 changed file with 122 additions and 14 deletions.
136 changes: 122 additions & 14 deletions src/jdk.jconsole/share/classes/sun/tools/jconsole/AboutDialog.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,17 +25,50 @@

package sun.tools.jconsole;

import java.awt.*;
import java.awt.event.*;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.FlowLayout;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.geom.Rectangle2D;
import java.beans.PropertyVetoException;
import java.net.URI;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

import static java.awt.BorderLayout.*;
import static sun.tools.jconsole.Utilities.*;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Document;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import javax.swing.text.View;

import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.NORTH;
import static java.awt.BorderLayout.SOUTH;

import static sun.tools.jconsole.Utilities.setAccessibleDescription;
import static sun.tools.jconsole.Utilities.setAccessibleName;

@SuppressWarnings("serial")
public class AboutDialog extends InternalDialog {
Expand All @@ -51,6 +84,8 @@ public class AboutDialog extends InternalDialog {

private JLabel statusBar;
private Action closeAction;
private JEditorPane helpLink;
private final String urlStr = getOnlineDocUrl();

public AboutDialog(JConsole jConsole) {
super(jConsole, Messages.HELP_ABOUT_DIALOG_TITLE, false);
Expand All @@ -72,25 +107,49 @@ public AboutDialog(JConsole jConsole) {
String jConsoleVersion = Version.getVersion();
String vmName = System.getProperty("java.vm.name");
String vmVersion = System.getProperty("java.vm.version");
String urlStr = getOnlineDocUrl();
String locUrlStr = urlStr;
if (isBrowseSupported()) {
urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
locUrlStr = "<a style='color:#35556b' href=\"" + locUrlStr + "\">" + locUrlStr + "</a>";
}

JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
infoAndLogoPanel.setBackground(bgColor);

String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
JEditorPane helpLink = new JEditorPane("text/html",
helpLink = new JEditorPane("text/html",
"<html><font color=#"+ colorStr + ">" +
Resources.format(Messages.HELP_ABOUT_DIALOG_JCONSOLE_VERSION, jConsoleVersion) +
"<p>" + Resources.format(Messages.HELP_ABOUT_DIALOG_JAVA_VERSION, (vmName +", "+ vmVersion)) +
"<p>" + urlStr + "</html>");
"<p>" + locUrlStr + "</html>");

helpLink.setOpaque(false);
helpLink.setEditable(false);
helpLink.setForeground(textColor);

mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

helpLink.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_ENTER) || (e.getKeyCode() == KeyEvent.VK_SPACE)) {
browse(urlStr);
e.consume();
}
}
});

helpLink.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
highlight();
}
@Override
public void focusLost(FocusEvent e) {
removeHighlights();
}
});

helpLink.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
Expand Down Expand Up @@ -128,6 +187,25 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
Utilities.updateTransparency(this);
}

public void highlight() {
try {
removeHighlights();

Highlighter hilite = helpLink.getHighlighter();
Document doc = helpLink.getDocument();
String text = doc.getText(0, doc.getLength());
int pos = text.indexOf(urlStr, 0);
hilite.addHighlight(pos, pos + urlStr.length(), new HighlightPainter());
} catch (BadLocationException e) {
// ignore
}
}

public void removeHighlights() {
Highlighter hilite = helpLink.getHighlighter();
hilite.removeAllHighlights();
}

public void showDialog() {
statusBar.setText(" ");
setVisible(true);
Expand Down Expand Up @@ -192,4 +270,34 @@ private static class TPanel extends JPanel {
setOpaque(false);
}
}

private static class HighlightPainter
extends DefaultHighlighter.DefaultHighlightPainter {

public HighlightPainter() {
super(null);
}
@Override
public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds,
JTextComponent c, View view) {
g.setColor(c.getSelectionColor());
Rectangle alloc;

if (bounds instanceof Rectangle) {
alloc = (Rectangle)bounds;
} else {
alloc = bounds.getBounds();
}

Graphics2D g2d = (Graphics2D)g;

float[] dash = { 2F, 2F };
Stroke dashedStroke = new BasicStroke(1F, BasicStroke.CAP_SQUARE,
BasicStroke.JOIN_MITER, 3F, dash, 0F);
g2d.fill(dashedStroke.createStrokedShape(
new Rectangle2D.Float(alloc.x, alloc.y,
alloc.width - 1, alloc.height - 1)));
return alloc;
}
}
}

3 comments on commit b5d32bb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on b5d32bb Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-b5d32bbf in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

this pull request contains a backport of commit b5d32bbf from the openjdk/jdk repository.

The commit being backported was authored by K Suman Rajkumaar on 21 May 2021 and was reviewed by Alexey Ivanov and Dmitry Markov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-b5d32bbf:TheRealMDoerr-backport-b5d32bbf
$ git checkout TheRealMDoerr-backport-b5d32bbf
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-b5d32bbf

Please sign in to comment.