Search in sources :

Example 1 with CustomHTMLEditorKit

use of net.pms.newgui.components.CustomHTMLEditorKit in project UniversalMediaServer by UniversalMediaServer.

the class LanguageSelection method buildComponent.

private JComponent buildComponent() {
    // UIManager manages to get the background color wrong for text
    // components on OS X, so we apply the color manually
    Color backgroundColor = UIManager.getColor("Panel.background");
    rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));
    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    selectionPanelBorder.setTitle(" ");
    selectionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(selectionPanelBorder, BorderFactory.createEmptyBorder(10, 5, 10, 5))));
    selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.PAGE_AXIS));
    descriptionText.setEditable(false);
    descriptionText.setBackground(backgroundColor);
    descriptionText.setFocusable(false);
    descriptionText.setLineWrap(true);
    descriptionText.setWrapStyleWord(true);
    descriptionText.setBorder(BorderFactory.createEmptyBorder(5, 15, 10, 15));
    selectionPanel.add(descriptionText);
    jLanguage = new JComboBox<>(keyedModel);
    jLanguage.setEditable(false);
    jLanguage.setPreferredSize(new Dimension(50, jLanguage.getPreferredSize().height));
    jLanguage.addActionListener(new LanguageComboBoxActionListener());
    languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.PAGE_AXIS));
    languagePanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    languagePanel.add(jLanguage);
    selectionPanel.add(languagePanel);
    warningText.setEditable(false);
    warningText.setFocusable(false);
    warningText.setBackground(backgroundColor);
    warningText.setFont(warningText.getFont().deriveFont(Font.BOLD));
    warningText.setLineWrap(true);
    warningText.setWrapStyleWord(true);
    warningText.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 15));
    selectionPanel.add(warningText);
    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    infoTextBorder.setTitle(" ");
    infoText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(infoTextBorder, BorderFactory.createEmptyBorder(15, 20, 20, 20))));
    infoText.setEditable(false);
    infoText.setFocusable(false);
    infoText.setBackground(backgroundColor);
    infoText.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    // This exercise is to avoid using the default shared StyleSheet with padding
    CustomHTMLEditorKit editorKit = new CustomHTMLEditorKit();
    StyleSheet styleSheet = new StyleSheet();
    styleSheet.addRule("a { color: #0000EE; text-decoration:underline; }");
    editorKit.setStyleSheet(styleSheet);
    infoText.setEditorKit(editorKit);
    infoText.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                boolean error = false;
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI(e.getDescription()));
                    } catch (IOException | URISyntaxException ex) {
                        LOGGER.error("Language selection failed to open translation page hyperlink: ", ex.getMessage());
                        LOGGER.trace("", ex);
                        error = true;
                    }
                } else {
                    LOGGER.warn("Desktop is not supported, the clicked translation page link can't be opened");
                    error = true;
                }
                if (error) {
                    JOptionPane.showOptionDialog(dialog, String.format(buildString("LanguageSelection.6", true), PMS.CROWDIN_LINK), buildString("Dialog.Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
                }
            }
        }
    });
    rootPanel.add(selectionPanel);
    rootPanel.add(infoText);
    applyButton.addActionListener(new ApplyButtonActionListener());
    applyButton.setActionCommand("apply");
    selectButton.addActionListener(new SelectButtonActionListener());
    selectButton.setActionCommand("select");
    return rootPanel;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Color(java.awt.Color) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) URI(java.net.URI) StyleSheet(javax.swing.text.html.StyleSheet) HyperlinkListener(javax.swing.event.HyperlinkListener) CustomHTMLEditorKit(net.pms.newgui.components.CustomHTMLEditorKit)

Aggregations

Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 URI (java.net.URI)1 BoxLayout (javax.swing.BoxLayout)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1 HyperlinkListener (javax.swing.event.HyperlinkListener)1 StyleSheet (javax.swing.text.html.StyleSheet)1 CustomHTMLEditorKit (net.pms.newgui.components.CustomHTMLEditorKit)1