package jmri.util; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import javax.annotation.Nonnull; import java.awt.Container; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.*; import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Accessibility Tool for checking swing JFrames and JPanels. *
* Checks for JButton, JTextArea, JTextField components to * ensure they have accessible content for screen reading software. * * @author Steve Young Copyright (C) 2022 */ public class AccessibilityChecks { private static final boolean LOGSYSTEMOUT = Boolean.getBoolean("jmri.util.AccessibilityChecks.logToSystemOut"); // false unless set true private static final boolean WARNISSUES = Boolean.getBoolean("jmri.util.AccessibilityChecks.warnOnIssue"); // false unless set true private static final boolean ASSERTFAIL = Boolean.getBoolean("jmri.util.AccessibilityChecks.failOnIssue"); // false unless set true private static final boolean INCLUDELAF = Boolean.getBoolean("jmri.util.AccessibilityChecks.includeLaf"); // false unless set true /** * Check a JPanel or Container for Accessibility issues. *
* Typical usage would be to pass a JPanel. * * @param contentPane eg. JFrame.getContentPane() or a JPanel * @return Empty string if no errors, else String containing details. */ @Nonnull public static String check( @Nonnull final Container contentPane) { return check(contentPane, false); } /** * Check a JPanel or Container for Accessibility issues. *
* Typical usage would be to pass a JPanel. * * @param contentPane eg. JFrame.getContentPane() or a JPanel * @param failOnIssue set true to fail the unit test if any issue found. * @return Empty string if no errors, else String containing details. */ @Nonnull public static String check( @Nonnull final Container contentPane, final boolean failOnIssue) { return feedBack(getSingleContentPaneList(contentPane), failOnIssue); } /** * Check a Frame for Accessibility issues. *
* Typical usage would be to pass a JFrame. * Searches the frame via * getContentPane() , getLayeredPane(), getRootPane() * for issues. * * @param frame a JFrame for which to search through. * @return Empty string if no errors, else String containing details. */ @Nonnull public static String check(@Nonnull JFrame frame) { return check(frame, false); } /** * Check a Frame for Accessibility issues. *
* Typical usage would be to pass a JFrame.
* Searches the frame via
* getContentPane() , getLayeredPane(), getRootPane()
* for issues.
*
* @param frame a JFrame for which to search through.
* @param failOnIssue set true to fail the unit test if any issue found.
* @return Empty string if no errors, else String containing details.
*/
@Nonnull
public static String check(@Nonnull JFrame frame, final boolean failOnIssue) {
HashSet