/**********************************************************************
Virtual Cache is a program which helps to manage personal finances
Copyright (C) 2013 by Rovinskiy Nikolay
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
package Messages;
import Utils.HyperLinkListenerImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JFrame;
import javax.swing.text.BadLocationException;
/**
*
* @author User
*/
public class Legend extends javax.swing.JDialog {
/** Creates new form Legend */
public Legend(java.awt.Frame parent) {
super(parent, false);
this.setLocation(parent.getLocation().x+50, parent.getLocation().y+100);
initComponents();
blnFileNotFound=false;
jepInfo.addHyperlinkListener(new HyperLinkListenerImpl((jepInfo)));
this.setSize(650, 700);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jepInfo = new javax.swing.JEditorPane();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(650, 700));
jepInfo.setContentType("text/html");
jepInfo.setEditable(false);
jScrollPane1.setViewportView(jepInfo);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
public void setContentType(String type){jepInfo.setContentType(type);}
public String getContentType(){return jepInfo.getContentType();}
public void setData(File file)
{
FileInputStream fisReader;
InputStreamReader isrReader;
BufferedReader brReader;
try
{
fisReader=new FileInputStream(file);
isrReader=new InputStreamReader(fisReader);
brReader=new BufferedReader(isrReader);
String s=brReader.readLine();
// StringBuffer sbCollector=new StringBuffer("");
if(!jepInfo.getContentType().equals(CONTENT_TYPE_HTML))
while(s!=null)
{
//sbCollector.append(s);
//strCollector=new String(strCollector+s);
jepInfo.getDocument().insertString(jepInfo.getDocument().getLength(), s+"\n", null);
// else
//sbCollector.append(s);
//jepInfo.getDocument().insertString(jepInfo.getDocument().getLength(), s, null);
s=brReader.readLine();
}
if(jepInfo.getContentType().equals(CONTENT_TYPE_HTML))
{
if(System.getProperty("os.name").toLowerCase().startsWith("windows"))
jepInfo.setPage("file:"+File.separator+file.getAbsolutePath());
else
jepInfo.setPage("file://"+file.getAbsolutePath());
}
if(jepInfo.getDocument().getLength()>0)
jepInfo.setCaretPosition(0);
//jepInfo.getDocument().setText(strCollector);
// jepInfo.setText(sbCollector.toString());
}
catch(IOException ex)
{
OKMessage okm=new OKMessage((JFrame)this.getOwner(), "<html>Unable to open file<br>"+file.getAbsolutePath()+"!</html>");
okm.setVisible(true);
okm=null;
blnFileNotFound=true;
}
catch(BadLocationException ex1){}
}
@Override
public void setVisible(boolean visible)
{
if(blnFileNotFound)
this.dispose();
else
super.setVisible(visible);
}
public static final String CONTENT_TYPE_TEXT="text/plain; charset=UTF-8";
public static final String CONTENT_TYPE_HTML="text/html";
private boolean blnFileNotFound;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JEditorPane jepInfo;
// End of variables declaration//GEN-END:variables
}