1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.aikiit.fotorenamer.gui;
17
18 import de.aikiit.fotorenamer.util.ComponentGaugeUtil;
19 import org.apache.logging.log4j.LogManager;
20 import org.apache.logging.log4j.Logger;
21
22 import javax.swing.*;
23 import java.awt.*;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.io.File;
27
28 import static de.aikiit.fotorenamer.util.LocalizationHelper.getBundleString;
29 import static de.aikiit.fotorenamer.util.LocalizationHelper.getLanguage;
30 import static de.aikiit.fotorenamer.util.LocalizationHelper.getParameterizedBundleString;
31
32
33
34
35
36
37
38
39 class HelpWindow extends JFrame implements ActionListener {
40
41
42
43 private static final Logger LOG = LogManager.getLogger(HelpWindow.class);
44
45
46
47
48 private JButton endButton = null;
49
50
51
52
53 private static final String HTML_HELP_LOCATION = File.separator + "html"
54 + File.separator;
55
56
57
58
59
60 HelpWindow() {
61 SwingUtilities.invokeLater(this::init);
62 }
63
64
65
66
67 private void init() {
68 this.setTitle(getBundleString(
69 "fotorenamer.ui.help.title"));
70 this.setResizable(false);
71 JPanel top = new JPanel(new FlowLayout());
72 JPanel bottom = new JPanel(new FlowLayout());
73
74 JEditorPane textfield = new JEditorPane();
75 textfield.setContentType("text/html");
76 textfield.setEditable(false);
77 loadHelpContents(top, textfield);
78
79 JScrollPane rollpanel = new JScrollPane(top);
80 rollpanel.setPreferredSize(new Dimension(350, 300));
81 rollpanel.setVerticalScrollBarPolicy(
82 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
83
84 this.endButton = new JButton(getBundleString(
85 "fotorenamer.ui.help.close"));
86 this.endButton.addActionListener(this);
87 this.endButton.setMnemonic(getBundleString("fotorenamer.ui.help.close.mnemonic").charAt(0));
88 bottom.add(this.endButton);
89
90 this.getContentPane().setLayout(new BorderLayout());
91 this.getContentPane().add(rollpanel, BorderLayout.NORTH);
92 this.getContentPane().add(bottom, BorderLayout.CENTER);
93
94 this.pack();
95 ComponentGaugeUtil.makeCentered(this);
96
97
98 SwingUtilities.invokeLater(() -> {
99 getRootPane().setDefaultButton(endButton);
100 endButton.requestFocusInWindow();
101 });
102
103 LOG.debug("HelpWindow init done.");
104 }
105
106
107
108
109
110
111
112 private void loadHelpContents(final JPanel base, final JEditorPane textfield) {
113 try {
114 String helpPageLocation = HTML_HELP_LOCATION;
115
116 if (getLanguage().startsWith("de")) {
117 helpPageLocation += "hilfe.html";
118 } else {
119 helpPageLocation += "help.html";
120 }
121
122 textfield.setPage(HelpWindow.class.getResource(helpPageLocation));
123 base.add(textfield);
124 } catch (Exception e) {
125 base.setLayout(new GridLayout(1, 1));
126 base.add(new JLabel(getParameterizedBundleString("fotorenamer.ui.help.error", e.getMessage(), e.getClass().getSimpleName())));
127 }
128 }
129
130
131
132
133
134
135 public final void actionPerformed(final ActionEvent event) {
136 if (event.getSource() == this.endButton) {
137 LOG.debug("Disabling visibility of helpWindow.");
138 setVisible(false);
139 }
140 }
141 }