summaryrefslogtreecommitdiff
path: root/java/src/org/singinst/uf/view/SwingHelp.java
blob: 9d22307ccc60f73845db1a9499b2cdfadc2d909f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.singinst.uf.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.RootPaneContainer;

public class SwingHelp {
	private static final SwingHelp instance = new SwingHelp();
	private final JPanel helpPanel = new JPanel(new BorderLayout());
	private final JEditorPane helpText = new JEditorPane();
	private RootPaneContainer root;
	private Component oldGlassPane;

	public void init(final RootPaneContainer root, String mainHelpString) {
		this.root = root;
		helpText.setEditable(false);
		helpText.setContentType("text/html");
		helpPanel.add(new JScrollPane(helpText));
		helpPanel.addMouseListener(new MouseAdapter() {});
		Box southBox = Box.createHorizontalBox();

		JButton helpButton = new JButton("OK");
		helpButton.setAlignmentX(Component.CENTER_ALIGNMENT);
		helpButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				root.setGlassPane(oldGlassPane);
				oldGlassPane.setVisible(false);
			}
			
		});

		southBox.add(Box.createHorizontalGlue());
		southBox.add(helpButton);
		southBox.add(Box.createHorizontalGlue());
		helpPanel.add(southBox, BorderLayout.SOUTH);
		helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

		if (mainHelpString != null) {
			help(mainHelpString);
		}
	}

	public void help(String helpString) {
		helpText.setText(helpString);
		oldGlassPane = root.getGlassPane();
		root.setGlassPane(helpPanel);
		helpPanel.setVisible(true);
	}

	public static SwingHelp getInstance() {
		return instance;
	}

}