package misc; import java.awt.Color; import java.awt.Component; import java.awt.Frame; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLFrameHyperlinkEvent; @SuppressWarnings ("serial") public class Guide extends HtmlDialog { // ======================================== static public final int H_SPACE = 5; static public final int V_SPACE = 2; // ======================================== Color standardBackground = Color.gray; Color highlightColor = Color.orange; Component [] component; Color [] componentBackgroundColor; int next = -1; boolean [] done; // ======================================== public Guide (Frame frame, String titleName, String fileName, Component [] component, Color standardBackground, Color highlightColor) { super (frame, titleName, fileName); this.component = component; this.standardBackground = standardBackground; this.highlightColor = highlightColor; done = new boolean [component.length]; componentBackgroundColor = new Color [component.length]; for (int i = 0; i < component.length; i++) if (component [i] != null) componentBackgroundColor [i] = component [i].getBackground (); reset (); editorPane.addHyperlinkListener (new Hyperactive ()); } // ======================================== class Hyperactive implements HyperlinkListener { public void hyperlinkUpdate (HyperlinkEvent e) { if (e.getEventType () == HyperlinkEvent.EventType.ACTIVATED) { String file = e.getURL ().getPath (); String command = file.substring (file.lastIndexOf ("/")+1); int idx = command.indexOf ("?"); if (idx >= 0) command = command.substring (0, idx); if ("Reset".equals (command)) { reset (); setNext (); } else if (command.startsWith ("ActionG")) { String [] bound = command.substring ("ActionG".length ()).split ("\\-"); flipGroup (Integer.parseInt (bound[0]), Integer.parseInt (bound[1])); } else if (command.startsWith ("Action")) flipStep (Integer.parseInt (command.substring ("Action".length ()))); else if (e instanceof HTMLFrameHyperlinkEvent) { HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e; HTMLDocument doc = (HTMLDocument) editorPane.getDocument (); doc.processHTMLFrameHyperlinkEvent (evt); } else { try { editorPane.setPage (e.getURL ()); } catch (Throwable t) { Log.keepLastException ("Guide::hyperlinkUpdate", t); } } } } } // ======================================== public void setVisible (boolean visible) { reset (); super.setVisible (visible); if (visible) { setNext (); editorPane.scrollToReference ("Top"); } } // ======================================== public void changeHtmlClassAction (String actionName, String className) { String newPage = editorPane.getText (). replaceAll ("