Skip to content

Commit

Permalink
Added basic accessibility (#1240)
Browse files Browse the repository at this point in the history
Adds basic accessibility support

Co-authored-by: Tres Finocchiaro <[email protected]>
  • Loading branch information
Vzor- and tresf authored Feb 28, 2024
1 parent f2761f8 commit 6e1a503
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 71 deletions.
30 changes: 20 additions & 10 deletions src/qz/build/JLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.*;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.*;

public class JLink {
private static final Logger log = LogManager.getLogger(JLink.class);
Expand Down Expand Up @@ -233,10 +231,16 @@ private JLink calculateDepList() throws IOException {
depList.add(item);
}
}
// "jar:" URLs create transient zipfs dependency, see https://stackoverflow.com/a/57846672/3196753
depList.add("jdk.zipfs");
// fix for https://github.com/qzind/tray/issues/894 solution from https://github.com/adoptium/adoptium-support/issues/397
depList.add("jdk.crypto.ec");
switch(targetPlatform) {
case WINDOWS:
// Java accessibility bridge dependency, see https://github.com/qzind/tray/issues/1234
depList.add("jdk.accessibility");
default:
// "jar:" URLs create transient zipfs dependency, see https://stackoverflow.com/a/57846672/3196753
depList.add("jdk.zipfs");
// fix for https://github.com/qzind/tray/issues/894 solution from https://github.com/adoptium/adoptium-support/issues/397
depList.add("jdk.crypto.ec");
}
return this;
}

Expand Down Expand Up @@ -279,16 +283,22 @@ private JLink deployJre() throws IOException {
log.info("Successfully deployed a jre to {}", outPath);

// Remove all but java/javaw
String[] keepFiles;
List<String> keepFiles = new ArrayList<>();
//String[] keepFiles;
String keepExt;
switch(targetPlatform) {
case WINDOWS:
keepFiles = new String[]{ "java.exe", "javaw.exe" };
keepFiles.add("java.exe");
keepFiles.add("javaw.exe");
if(depList.contains("jdk.accessibility")) {
// Java accessibility bridge switching tool
keepFiles.add("jabswitch.exe");
}
// Windows stores ".dll" files in bin
keepExt = ".dll";
break;
default:
keepFiles = new String[]{ "java" };
keepFiles.add("java");
keepExt = null;
}

Expand Down
6 changes: 6 additions & 0 deletions src/qz/ui/DetailsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ private void initComponents(IconCache iconCache) {

requestTable = new RequestTable(iconCache);
reqScrollPane = new JScrollPane(requestTable);
requestTable.getAccessibleContext().setAccessibleName(requestLabel.getText() + " Details");
requestTable.getAccessibleContext().setAccessibleDescription("Signing details about this request.");
requestLabel.setLabelFor(requestTable);

certLabel = new JLabel("Certificate");
certLabel.setAlignmentX(CENTER_ALIGNMENT);

certTable = new CertificateTable(iconCache);
certScrollPane = new JScrollPane(certTable);
certTable.getAccessibleContext().setAccessibleName(certLabel.getText() + " Details");
certTable.getAccessibleContext().setAccessibleDescription("Certificate details about this request.");
certLabel.setLabelFor(certTable);

add(requestLabel);
add(reqScrollPane);
Expand Down
16 changes: 8 additions & 8 deletions src/qz/ui/component/EmLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
import java.util.Map;

/**
* Create a label at the multiplier of it's normal size, similar to CSS's "em" tag
* Create a label at the multiplier of its normal size, similar to CSS's "em" tag
*/
public class EmLabel extends JLabel {
public EmLabel() {}
public EmLabel(String text) {
super(text);
}
public EmLabel(String text, float multiplier) {
this(text, multiplier, true);
}
public EmLabel(String text, float multiplier, boolean underline) {
super(text);
Font template = getFont().deriveFont(multiplier * getFont().getSize());
stylizeComponent(this, multiplier, underline);
}

public static void stylizeComponent(Component j, float multiplier, boolean underline) {
Font template = j.getFont().deriveFont(multiplier * j.getFont().getSize());
if (!underline) {
Map<TextAttribute,Object> attributes = new HashMap<>(template.getAttributes());
attributes.remove(TextAttribute.UNDERLINE);
setFont(template.deriveFont(attributes));
j.setFont(template.deriveFont(attributes));
} else {
setFont(template);
j.setFont(template);
}
}
}
81 changes: 28 additions & 53 deletions src/qz/ui/component/LinkLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
import qz.ui.Themeable;
import qz.utils.ShellUtilities;

import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.TextAttribute;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
* Creates a JButton which visually appears as a clickable link
*
* TODO: Rename this class. Since switching from JLabel to a JButton, this class now has a misleading name.
*
* Created by Tres on 2/19/2015.
*/
public class LinkLabel extends EmLabel implements Themeable {
public class LinkLabel extends JButton implements Themeable {

private static final Logger log = LogManager.getLogger(LinkLabel.class);

private ArrayList<ActionListener> actionListeners;

public LinkLabel() {
super();
initialize();
Expand All @@ -39,7 +39,8 @@ public LinkLabel(String text) {
}

public LinkLabel(String text, float multiplier, boolean underline) {
super(text, multiplier, underline);
super(text);
EmLabel.stylizeComponent(this, multiplier, underline);
initialize();
}

Expand All @@ -53,15 +54,12 @@ public void setLinkLocation(final String url) {
}

public void setLinkLocation(final URL location) {
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
Desktop.getDesktop().browse(location.toURI());
}
catch(Exception e) {
log.error("", e);
}
addActionListener(ae -> {
try {
Desktop.getDesktop().browse(location.toURI());
}
catch(Exception e) {
log.error("", e);
}
});
}
Expand All @@ -70,55 +68,32 @@ public void setLinkLocation(final File filePath) {
addActionListener(ae -> ShellUtilities.browseDirectory(filePath.isDirectory()? filePath.getPath():filePath.getParent()));
}


private void initialize() {
Map<TextAttribute,Object> attributes = new HashMap<>(getFont().getAttributes());
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
setFont(getFont().deriveFont(attributes));

actionListeners = new ArrayList<>();

addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
for(ActionListener actionListener : actionListeners) {
actionListener.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "mouseClicked"));
}
}

@Override
public void mousePressed(MouseEvent e) {}

@Override
public void mouseReleased(MouseEvent e) {}

@Override
public void mouseEntered(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
public void mouseExited(MouseEvent e) {
setCursor(Cursor.getDefaultCursor());
}
});

refresh();
}

@Override
public void refresh() {
setForeground(Constants.TRUSTED_COLOR);
setBorderPainted(false);
setBorder(null);
setOpaque(false);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

public void addActionListener(ActionListener action) {
if (!actionListeners.contains(action)) {
actionListeners.add(action);
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleLinkLabel();
}
return accessibleContext;
}

public void removeActionListener(ActionListener action) {
actionListeners.remove(action);
protected class AccessibleLinkLabel extends AccessibleJButton {
public AccessibleRole getAccessibleRole() {
return AccessibleRole.HYPERLINK;
}
}

}

0 comments on commit 6e1a503

Please sign in to comment.