X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fhelp%2Ftours%2FSlideSetManager.java;h=0d9e38155cc830dffdf2210b9d046d8827c77c71;hb=1c0d3174f8ad5964f59855d4fe6df7c6fb7326e5;hp=abf5e74b888dcdd24e70aeb57988a31cfaccfd22;hpb=cb3399a95fa26c1f6c1916b20325859fe3cfae00;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/gui/help/tours/SlideSetManager.java b/src/net/sf/openrocket/gui/help/tours/SlideSetManager.java index abf5e74b..0d9e3815 100644 --- a/src/net/sf/openrocket/gui/help/tours/SlideSetManager.java +++ b/src/net/sf/openrocket/gui/help/tours/SlideSetManager.java @@ -11,6 +11,8 @@ import java.util.Map; import javax.swing.text.html.StyleSheet; +import net.sf.openrocket.util.BugException; + /** * A manager that loads a number of slide sets from a defined base directory * and provides access to them. @@ -18,11 +20,14 @@ import javax.swing.text.html.StyleSheet; * @author Sampo Niskanen */ public class SlideSetManager { + private static final String TOURS_BASE_DIR = "datafiles/tours"; private static final String TOURS_FILE = "tours.txt"; private static final String STYLESHEET_FILE = "style.css"; - + private static SlideSetManager slideSetManager = null; + + private final String baseDir; private final Map slideSets = new LinkedHashMap(); @@ -49,20 +54,24 @@ public class SlideSetManager { List tours = loadTourList(); StyleSheet styleSheet = loadStyleSheet(); - for (String file : tours) { + for (String fileAndDir : tours) { + String base; + String file; - String base = baseDir + file; - int index = base.lastIndexOf('/'); + String fullFileAndDir = baseDir + fileAndDir; + int index = fullFileAndDir.lastIndexOf('/'); if (index >= 0) { - base = base.substring(0, index); + base = fullFileAndDir.substring(0, index); + file = fullFileAndDir.substring(index + 1); } else { base = ""; + file = ""; } SlideSetLoader loader = new SlideSetLoader(base); SlideSet set = loader.load(file); set.setStyleSheet(styleSheet); - slideSets.put(file, set); + slideSets.put(fileAndDir, set); } } @@ -131,4 +140,26 @@ public class SlideSetManager { } + + + /** + * Return a singleton implementation that has loaded the default tours. + */ + public static SlideSetManager getSlideSetManager() { + if (slideSetManager == null) { + try { + SlideSetManager ssm = new SlideSetManager(TOURS_BASE_DIR); + ssm.load(); + + if (ssm.getSlideSetNames().isEmpty()) { + throw new FileNotFoundException("No tours found."); + } + + slideSetManager = ssm; + } catch (IOException e) { + throw new BugException(e); + } + } + return slideSetManager; + } }