Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JEditorPane and HTML pages

 
cnu bonala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we restore history and next objects ( html pages )
when we implement javax.swing.text.html.*;
i am using vectors to store the visited links ( html pages)
but the problem is

i have a JEditorPane toolbar which consists of contents , >> ,<< <br /> buttons on it , here after viewing some pages if i click on contents and again i visit any page , then if i click on back , i could not restore the values correctly , <br /> this is the code<br /> private Vector getHelpFiles()<br /> {<br /> Vector temp = new Vector();<br /> try<br /> {<br /> File f = new File("D:/BSrinivas/cnucash/HelpFiles/help_Main.htm");<br /> System.out.println("File Opened="+f.getName());<br /> temp.add(f.toString());<br /> }<br /> catch (Exception e)<br /> {<br /> System.out.println("Invalid help file!");<br /> e.printStackTrace();<br /> return null;<br /> }<br /> return temp;<br /> }<br /> <br /> public HyperlinkListener createHyperLinkListener()<br /> {<br /> return new HyperlinkListener()<br /> {<br /> public void hyperlinkUpdate(HyperlinkEvent e)<br /> {<br /> if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)<br /> {<br /> if (e instanceof HTMLFrameHyperlinkEvent)<br /> {<br /> ((HTMLDocument)htmlEditor.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)e);<br /> }<br /> else<br /> {<br /> try <br /> {<br /> htmlEditor.setPage(e.getURL());<br /> System.out.println("LINK: " + e.getURL());<br /> <br /> String url = e.getURL().toString();<br /> url = url.substring(6, url.length());<br /> //System.out.println("LINK: " + url);<br /> <br /> vectorHelpFiles.addElement(url);<br /> iCurrentHelpFile = vectorHelpFiles.indexOf(url);<br /> File currentPage = new File(htmlEditor.getPage().getPath());<br /> int iFileIndex = vectorHelpFiles.indexOf(url);<br /> backButton.setEnabled(true);<br /> if (iCurrentHelpFile == vectorHelpFiles.size()-1)<br /> forwardButton.setEnabled(false);<br /> else<br /> forwardButton.setEnabled(true);<br /> } <br /> catch (IOException ioe) <br /> {<br /> System.out.println("IOE: " + ioe);<br /> }<br /> }<br /> }<br /> }<br /> };<br /> }<br /> public static void main(String[] args) <br /> {<br /> new HelpFrame();<br /> //System.out.println("Hello World!");<br /> }<br /> }<br /> class ActionClass implements ActionListener<br /> {<br /> HelpFrame parent;<br /> ActionClass(HelpFrame parent)<br /> {<br /> this.parent = parent;<br /> }<br /> public void actionPerformed(ActionEvent ae)<br /> {<br /> File currentPage = new File(parent.htmlEditor.getPage().getPath());<br /> //int iFileIndex = parent.vectorHelpFiles.indexOf(currentPage);<br /> int iFileIndex = parent.iCurrentHelpFile;<br /> <br /> //System.out.println("Vector: " + "\t Index:" + iFileIndex);<br /> <br /> if (ae.getSource() == parent.forwardButton)<br /> {<br /> iFileIndex++;<br /> if (iFileIndex >= parent.vectorHelpFiles.size()-1)<br /> parent.forwardButton.setEnabled(false);<br /> if (iFileIndex > 0)
parent.backButton.setEnabled(true);
parent.showURL((String)parent.vectorHelpFiles.elementAt(iFileIndex));
parent.iCurrentHelpFile = iFileIndex;
}
else if (ae.getSource() == parent.backButton)
{
iFileIndex--;
if (iFileIndex == 0)
parent.backButton.setEnabled(false);
if (iFileIndex < parent.vectorHelpFiles.size()-1)
parent.forwardButton.setEnabled(true);
//parent.showURL((String)parent.vectorHelpFiles.elementAt(parent.iCurrentHelpFile));
parent.showURL((String)parent.vectorHelpFiles.elementAt(iFileIndex));
parent.iCurrentHelpFile = iFileIndex;
}
else if (ae.getSource() == parent.homeButton)
{
iFileIndex = 0;
int index = parent.iCurrentHelpFile;
//parent.backButton.setEnabled(false);
//parent.forwardButton.setEnabled(false);
parent.showURL((String)parent.vectorHelpFiles.elementAt(iFileIndex));
parent.iCurrentHelpFile = iFileIndex;
//parent.iCurrentHelpFile = iFileIndex;
}

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!