| 1 | |
package de.glossmaker.gui.gloss.help; |
| 2 | |
|
| 3 | |
import java.awt.Component; |
| 4 | |
import java.awt.MenuItem; |
| 5 | |
import java.io.File; |
| 6 | |
import java.net.URL; |
| 7 | |
import java.util.Locale; |
| 8 | |
|
| 9 | |
import javax.help.HelpBroker; |
| 10 | |
import javax.help.HelpSet; |
| 11 | |
import javax.help.JHelp; |
| 12 | |
import javax.swing.JRootPane; |
| 13 | |
|
| 14 | |
import org.apache.log4j.Logger; |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
public class HelpSystem { |
| 23 | 0 | private static final Logger mLogger = Logger.getLogger(HelpSystem.class); |
| 24 | |
|
| 25 | 0 | private static HelpSystem mHelpSystem = null; |
| 26 | 0 | private static JHelp mHelpViewer = null; |
| 27 | 0 | private static HelpBroker mHelpBroker = null; |
| 28 | 0 | private static JRootPane mRootPane = null; |
| 29 | 0 | private static String mLanguage = null; |
| 30 | |
|
| 31 | |
private HelpSet mHelpSet; |
| 32 | |
|
| 33 | 0 | private HelpSystem() { |
| 34 | |
try { |
| 35 | 0 | File f = new File(""); |
| 36 | |
|
| 37 | 0 | URL url = new URL("jar:file:" + f.getAbsolutePath() + |
| 38 | |
"/resources/help/translations/glossmaker_" + |
| 39 | |
Locale.getDefault().getLanguage().toUpperCase() + |
| 40 | |
".jar!/jhelpset.hs"); |
| 41 | 0 | mHelpSet = new HelpSet(null, url); |
| 42 | 0 | mHelpBroker = mHelpSet.createHelpBroker(); |
| 43 | 0 | mHelpViewer = new JHelp(mHelpSet); |
| 44 | 0 | } catch (Exception e) { |
| 45 | 0 | mLogger.error("Help system not found.", e); |
| 46 | 0 | } |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
private void changeLanguage() { |
| 50 | |
try { |
| 51 | 0 | File f = new File(""); |
| 52 | 0 | URL url = new URL("jar:file:" + f.getAbsolutePath() + |
| 53 | |
"/resources/help/translations/glossmaker_" + |
| 54 | |
Locale.getDefault().getLanguage().toUpperCase() + |
| 55 | |
".jar!/jhelpset.hs"); |
| 56 | 0 | mHelpSet = new HelpSet(null, url); |
| 57 | 0 | mHelpBroker.setHelpSet(mHelpSet); |
| 58 | 0 | mHelpViewer = new JHelp(mHelpSet); |
| 59 | 0 | } catch (Exception e) { |
| 60 | 0 | mLogger.error("Help system not found.", e); |
| 61 | 0 | } |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public void setRootPane(JRootPane rootPane) { |
| 65 | 0 | mRootPane = rootPane; |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
public static HelpSystem getInstance() { |
| 69 | 0 | if (mHelpSystem == null) { |
| 70 | 0 | mHelpSystem = new HelpSystem(); |
| 71 | 0 | mLanguage = Locale.getDefault().getLanguage(); |
| 72 | |
} |
| 73 | 0 | if (Locale.getDefault().getLanguage().equals(mLanguage) == false) { |
| 74 | 0 | mHelpSystem.changeLanguage(); |
| 75 | 0 | mLanguage = Locale.getDefault().getLanguage(); |
| 76 | |
} |
| 77 | 0 | return mHelpSystem; |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
public HelpSet getHelpSet() { |
| 82 | 0 | return mHelpSet; |
| 83 | |
} |
| 84 | |
|
| 85 | |
public HelpBroker getHelpBroker() { |
| 86 | 0 | return mHelpBroker; |
| 87 | |
} |
| 88 | |
|
| 89 | |
JHelp getHelpViewer() { |
| 90 | 0 | return mHelpViewer; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public void enableHelp(String str) { |
| 94 | 0 | mHelpBroker.enableHelp(mRootPane, str, mHelpSet); |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
public void enableHelp(MenuItem item, String str, HelpSet hs) { |
| 98 | 0 | mHelpBroker.enableHelp(item, str, hs); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public void enableHelp(Component component, String str, HelpSet hs) { |
| 102 | 0 | mHelpBroker.enableHelp(component, str, hs); |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
public void enableHelpOnButton(Component component, String str, HelpSet hs) { |
| 106 | 0 | mHelpBroker.enableHelpOnButton(component, str, hs); |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
public void enableHelpKey(Component component, String str, HelpSet hs) { |
| 110 | 0 | mHelpBroker.enableHelpKey(component, str, hs); |
| 111 | 0 | } |
| 112 | |
} |