All pastes #1626863 Raw Edit

Rajgopal

public text v1 · immutable
#1626863 ·published 2009-10-18 11:17 UTC
rendered paste body
/*************************************************************************** *   Copyright (C) 2009 by Rajgopal Vaithiyanathan			   * *   rajgopalv@yahoo.com						   * *                                                                         * *   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 2 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, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************//* * PosterView.java * * Created on Aug 23, 2009, 3:39:49 PM */package codeposter;import formatter.CodeFormatter;import formatter.PosterPreferences;import java.awt.datatransfer.Transferable;import java.awt.event.ActionEvent;import java.awt.event.MouseEvent;import java.awt.event.WindowEvent;import looknfeel.LnFListener;import indent.IndentManager;import java.awt.Color;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.ClipboardOwner;import java.awt.datatransfer.StringSelection;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.WindowListener;import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.OutputStreamWriter;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import pastebin.WebPoster;import pastebin.WebPosterPrefs;/* * @author Rajgopal */public class PosterView extends javax.swing.JFrame implements ActionListener,WindowListener{    private AboutDialog about;    private LnFListener lnf;    private CodeFormatter formatter;    private IndentManager indent;    private PosterPreferences posterPrefs;    private SignatureDialog signatureDialog;    private WebPoster webposter ;    private FormatterSettings formatterSettingsDialog;    private MouseAdapter madpt;    /** Creates new form PosterView */    public PosterView()    {	initComponents();	posterPrefs=new PosterPreferences();	formatter = new CodeFormatter(posterPrefs);	this.setDefaultCloseOperation(EXIT_ON_CLOSE);	setTitle("Orkut Code Poster - ııll raj llıı");	indent = new IndentManager(viewTextBox);	viewTextBox.addKeyListener(indent);	lnf = new LnFListener(this);	buttonGroup.add(standard_color);	buttonGroup.add(black_color);	buttonGroup.add(blue_color);	buttonGroup.add(red_color);	buttonGroup.add(green_color);	metal_menu.addActionListener(this);	motif_menu.addActionListener(this);	window_menu.addActionListener(this);	setPosterProperties();	about = new AboutDialog(this, true,lnf);	signatureDialog = new SignatureDialog(this, true, lnf, posterPrefs);	webposter = new WebPoster(this,true,lnf);	formatterSettingsDialog = new FormatterSettings(new javax.swing.JFrame(), true,lnf,posterPrefs);	Rectangle r = getGraphicsConfiguration().getBounds();	setLocation(r.width / 2 - getWidth() / 2, r.height / 2 - getHeight() / 2);	addWindowListener(this);	madpt = new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                publishCode(evt);            }	    private void publishCode(MouseEvent evt)	    {		publishActionPerformed(null);	    }        };	this.setVisible(true);    }    private void setPosterProperties()    {	switch(posterPrefs.getSyntaxColor())	{	    default:		formatter.setColorCode(0);		standard_color.setSelected(true);		break;	    case 1:		formatter.setColorCode(1);		red_color.setSelected(true);		break;	    case 2:		formatter.setColorCode(2);		green_color.setSelected(true);		break;	    case 3:		formatter.setColorCode(3);		blue_color.setSelected(true);		break;	    case 4:		formatter.setColorCode(4);		blue_color.setSelected(true);		break;	}	try{	    switch (posterPrefs.getTheme())	    {		default:		    lnf.setWindowsTheme();		    break;		case 1:		    lnf.setMotifTheme();		    break;		case 2:		    lnf.setMetalTheme();		    break;	    }	} catch(Exception ex)	{	  JOptionPane.showConfirmDialog(null, "Theme you seleceted was not found in this platform"+"\nSetting to theme to Metal.", "Theme not supported", JOptionPane.PLAIN_MESSAGE);	    posterPrefs.setTheme(2);	    try	    {		lnf.setMetalTheme();	    } catch (Exception ex1){}	}	line.setSelected(posterPrefs.isLineNum());	unicodeIndent.setSelected(posterPrefs.isUnicodeIndent());	setSize(posterPrefs.getWidth(), posterPrefs.getHeight());    }    /** 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">    private void initComponents() {        buttonGroup = new javax.swing.ButtonGroup();        PosterTabPane = new javax.swing.JTabbedPane();        viewTab = new javax.swing.JPanel();        jScrollPane1 = new javax.swing.JScrollPane();        viewTextBox = new javax.swing.JTextArea();        unicodeIndent = new javax.swing.JCheckBox();        line = new javax.swing.JCheckBox();        htmlTab = new javax.swing.JPanel();        jScrollPane2 = new javax.swing.JScrollPane();        formattedTextBox = new javax.swing.JTextArea();        error_status = new javax.swing.JLabel();        menuBar = new javax.swing.JMenuBar();        file = new javax.swing.JMenu();        open_menu = new javax.swing.JMenuItem();        publish = new javax.swing.JMenuItem();        exportToHTML = new javax.swing.JMenuItem();        exit_menu = new javax.swing.JMenuItem();        edit = new javax.swing.JMenu();        jMenu1 = new javax.swing.JMenu();        standard_color = new javax.swing.JRadioButtonMenuItem();        blue_color = new javax.swing.JRadioButtonMenuItem();        red_color = new javax.swing.JRadioButtonMenuItem();        green_color = new javax.swing.JRadioButtonMenuItem();        black_color = new javax.swing.JRadioButtonMenuItem();        formatCode_menu = new javax.swing.JMenuItem();        pastebinSettings = new javax.swing.JMenuItem();        signature = new javax.swing.JMenuItem();        formatterSettings = new javax.swing.JMenuItem();        theme = new javax.swing.JMenu();        window_menu = new javax.swing.JMenuItem();        motif_menu = new javax.swing.JMenuItem();        metal_menu = new javax.swing.JMenuItem();        help = new javax.swing.JMenu();        about_menu = new javax.swing.JMenuItem();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        viewTextBox.setColumns(20);        viewTextBox.setFont(new java.awt.Font("Courier New", 0, 12));        viewTextBox.setRows(5);        viewTextBox.setTabSize(4);        jScrollPane1.setViewportView(viewTextBox);        unicodeIndent.setText("Use unicode characters for indentation");        unicodeIndent.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                unicodeIndentActionPerformed(evt);            }        });        line.setText("Include Line numbers");        line.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                lineActionPerformed(evt);            }        });        org.jdesktop.layout.GroupLayout viewTabLayout = new org.jdesktop.layout.GroupLayout(viewTab);        viewTab.setLayout(viewTabLayout);        viewTabLayout.setHorizontalGroup(            viewTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(org.jdesktop.layout.GroupLayout.TRAILING, viewTabLayout.createSequentialGroup()                .addContainerGap()                .add(viewTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)                    .add(viewTabLayout.createSequentialGroup()                        .add(unicodeIndent)                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 47, Short.MAX_VALUE)                        .add(line)))                .addContainerGap())        );        viewTabLayout.setVerticalGroup(            viewTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(viewTabLayout.createSequentialGroup()                .addContainerGap()                .add(viewTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(unicodeIndent)                    .add(line, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)                .addContainerGap())        );        PosterTabPane.addTab("Type Here", viewTab);        formattedTextBox.setColumns(20);        formattedTextBox.setEditable(false);        formattedTextBox.setFont(new java.awt.Font("Courier New", 0, 12));        formattedTextBox.setRows(5);        formattedTextBox.setTabSize(4);        formattedTextBox.addFocusListener(new java.awt.event.FocusAdapter() {            public void focusGained(java.awt.event.FocusEvent evt) {                formattedTextBoxFocusGained(evt);            }        });        jScrollPane2.setViewportView(formattedTextBox);        error_status.setFont(new java.awt.Font("Courier New", 0, 12)); // NOI18N        error_status.setForeground(new java.awt.Color(158, 0, 0));        org.jdesktop.layout.GroupLayout htmlTabLayout = new org.jdesktop.layout.GroupLayout(htmlTab);        htmlTab.setLayout(htmlTabLayout);        htmlTabLayout.setHorizontalGroup(            htmlTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(org.jdesktop.layout.GroupLayout.TRAILING, htmlTabLayout.createSequentialGroup()                .addContainerGap()                .add(htmlTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)                    .add(org.jdesktop.layout.GroupLayout.LEADING, error_status, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE))                .addContainerGap())        );        htmlTabLayout.setVerticalGroup(            htmlTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(org.jdesktop.layout.GroupLayout.TRAILING, htmlTabLayout.createSequentialGroup()                .addContainerGap()                .add(error_status)                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)                .addContainerGap())        );        PosterTabPane.addTab("Post This", htmlTab);        file.setText("File");        open_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));        open_menu.setText("Open");        open_menu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                open_menuActionPerformed(evt);            }        });        file.add(open_menu);        publish.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));        publish.setText("Publish on pastebin.ca");        publish.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                publishActionPerformed(evt);            }        });        file.add(publish);        exportToHTML.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));        exportToHTML.setText("Export to HTML");        exportToHTML.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exportToHTMLActionPerformed(evt);            }        });        file.add(exportToHTML);        exit_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));        exit_menu.setText("Exit");        exit_menu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                exit_menuActionPerformed(evt);            }        });        file.add(exit_menu);        menuBar.add(file);        edit.setText("Edit");        jMenu1.setText("Syntax Coloring");        standard_color.setSelected(true);        standard_color.setText("Standard");        standard_color.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                standard_colorActionPerformed(evt);            }        });        jMenu1.add(standard_color);        blue_color.setSelected(true);        blue_color.setText("All Blue");        blue_color.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                blue_colorActionPerformed(evt);            }        });        jMenu1.add(blue_color);        red_color.setSelected(true);        red_color.setText("All Red");        red_color.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                red_colorActionPerformed(evt);            }        });        jMenu1.add(red_color);        green_color.setSelected(true);        green_color.setText("All Green");        green_color.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                green_colorActionPerformed(evt);            }        });        jMenu1.add(green_color);        black_color.setSelected(true);        black_color.setText("All Black");        black_color.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                black_colorActionPerformed(evt);            }        });        jMenu1.add(black_color);        edit.add(jMenu1);        formatCode_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.SHIFT_MASK));        formatCode_menu.setText("FormatCode");        formatCode_menu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                formatCode_menuActionPerformed(evt);            }        });        edit.add(formatCode_menu);        pastebinSettings.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK));        pastebinSettings.setText("Publisher settings");        pastebinSettings.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                pastebinSettingsActionPerformed(evt);            }        });        edit.add(pastebinSettings);        signature.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));        signature.setText("Signature Settings");        signature.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                signatureActionPerformed(evt);            }        });        edit.add(signature);        formatterSettings.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));        formatterSettings.setText("Formatter Settings");        formatterSettings.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                formatterSettingsActionPerformed(evt);            }        });        edit.add(formatterSettings);        menuBar.add(edit);        theme.setText("Theme");        window_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.ALT_MASK));        window_menu.setText("Windows");        theme.add(window_menu);        motif_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK));        motif_menu.setText("Motif");        theme.add(motif_menu);        metal_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.ALT_MASK));        metal_menu.setText("Metal");        theme.add(metal_menu);        menuBar.add(theme);        help.setText("Help");        about_menu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));        about_menu.setText("About");        about_menu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                about_menuActionPerformed(evt);            }        });        help.add(about_menu);        menuBar.add(help);        setJMenuBar(menuBar);        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(PosterTabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(PosterTabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)        );        pack();    }// </editor-fold>    private void convert()    {	String viewString = viewTextBox.getText();	String htmlString = viewString;	if(posterPrefs.isEnableSignature())	    if(posterPrefs.isAddSignAtBegining())		htmlString = posterPrefs.getSignature()+htmlString;	    else		htmlString+=posterPrefs.getSignature();	htmlString = formatter.format(htmlString, unicodeIndent.isSelected(),line.isSelected());	formattedTextBox.setText(htmlString);	if(viewString.length()>2048 || htmlString.length()>2048)	{	    error_status.setForeground(Color.red);	    error_status.setText("<html>WARNING : Your post's length exceeds 2048 characters.<br>Click this warning to publish your code");	    error_status.addMouseListener(madpt);	}	else if(posterPrefs.getAutoCopy())	{	    error_status.setForeground(Color.BLUE);	    error_status.setText("Contents copied to clipboard.!");	    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();	    error_status.removeMouseListener(madpt);	    StringSelection data = new StringSelection(htmlString);	    cb.setContents(data, null);	}	else	    error_status.setText("");    }    private void loadContent(String fname)    {	FileReader fr = null;	try	{	    fr = new FileReader(fname);	    viewTextBox.read(fr, null);	    indent.format();	}	catch (Exception e)	{	    JOptionPane.showMessageDialog(this, "Error in reading file.!", "Error!", JOptionPane.NO_OPTION);	    return;	} finally {	    try	    {		if(fr!=null)fr.close();	    } catch (IOException ex)	    {}	}    }    private void exit_menuActionPerformed(java.awt.event.ActionEvent evt)                                              {                                              	posterPrefs.setHeight(getHeight());	posterPrefs.setWidth(getWidth());	posterPrefs.writePreferences();	System.exit(0);    }                                             private void about_menuActionPerformed(java.awt.event.ActionEvent evt)                                               {                                               	about.setVisible(true);    }                                              private void open_menuActionPerformed(java.awt.event.ActionEvent evt)                                              {                                              	JFileChooser filechooser = new JFileChooser();	int option = filechooser.showOpenDialog(this);	if (option == JFileChooser.APPROVE_OPTION)	{	    File f = filechooser.getSelectedFile();	    loadContent(f.getAbsolutePath());	}    }                                             private void publishActionPerformed(java.awt.event.ActionEvent evt)                                            {                                            	webposter.setContent(viewTextBox.getText());	String reply = webposter.post();	if(reply.charAt(0) != '*' )	    JOptionPane.showMessageDialog(this,reply, "Failed to publish at http://pastebin.ca", JOptionPane.NO_OPTION);	else	{	    if(posterPrefs.getAutoCopy())	    {		Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();		StringSelection data = new StringSelection(reply.substring(49));		cb.setContents(data, null);	    }	    JOptionPane.showInputDialog(this, reply.substring(1, 49),"Publish to http://pastebin.ca",JOptionPane.NO_OPTION,null,null,reply.substring(49));	}    }                                           private void formattedTextBoxFocusGained(java.awt.event.FocusEvent evt)                                                 {                                                 	convert();}                                                private void lineActionPerformed(java.awt.event.ActionEvent evt)                                         {                                         	posterPrefs.setLineNum(line.isSelected());}                                        private void unicodeIndentActionPerformed(java.awt.event.ActionEvent evt)                                                  {                                                  	if(unicodeIndent.isSelected())	    if(JOptionPane.showConfirmDialog(null,	    "Using unicode characters in your program will reduce the characters used for indentation. But after posting\n" +	    "the formatted code in the forum, users cannot copy-paste from the forum and compile it directly .They will\n" +	    "have to remove the unicode characters manually before compilation.", "Not Reccomended!", JOptionPane.OK_CANCEL_OPTION)	    == JOptionPane.CANCEL_OPTION)		unicodeIndent.setSelected(false);	posterPrefs.setUnicodeIndent(unicodeIndent.isSelected());}                                                 private void formatterSettingsActionPerformed(java.awt.event.ActionEvent evt)                                                      {                                                      	formatterSettingsDialog.setVisible(true);}                                                     private void signatureActionPerformed(java.awt.event.ActionEvent evt)                                              {                                              	signatureDialog.setVisible(true);}                                             private void pastebinSettingsActionPerformed(java.awt.event.ActionEvent evt)                                                     {                                                     	webposter.setContent(viewTextBox.getText());	webposter.setVisible(true);}                                                    private void formatCode_menuActionPerformed(java.awt.event.ActionEvent evt)                                                    {                                                    	indent.format();}                                                   private void black_colorActionPerformed(java.awt.event.ActionEvent evt)                                                {                                                	formatter.setColorCode(4);	posterPrefs.setSyntaxColor(4);}                                               private void green_colorActionPerformed(java.awt.event.ActionEvent evt)                                                {                                                	formatter.setColorCode(2);	posterPrefs.setSyntaxColor(2);}                                               private void red_colorActionPerformed(java.awt.event.ActionEvent evt)                                              {                                              	formatter.setColorCode(1);	posterPrefs.setSyntaxColor(1);}                                             private void blue_colorActionPerformed(java.awt.event.ActionEvent evt)                                               {                                               	formatter.setColorCode(3);	posterPrefs.setSyntaxColor(3);}                                              private void standard_colorActionPerformed(java.awt.event.ActionEvent evt)                                                   {                                                   	formatter.setColorCode(0);	posterPrefs.setSyntaxColor(0);}                                                  private void exportToHTMLActionPerformed(java.awt.event.ActionEvent evt)                                                 {                                                 	String viewString = viewTextBox.getText();	String htmlString = viewString;	if(posterPrefs.isEnableSignature())	    if(posterPrefs.isAddSignAtBegining())		htmlString = posterPrefs.getSignature()+htmlString;	    else		htmlString+=posterPrefs.getSignature();	JFileChooser chooser = new JFileChooser();	chooser.setDialogTitle("Save As..");	int option = chooser.showSaveDialog(this);	if (option == JFileChooser.APPROVE_OPTION)	{	    File f = chooser.getSelectedFile();	    if (!f.exists())		try		{		    f.createNewFile();		} catch (IOException e)		{		   JOptionPane.showMessageDialog(this, "Error in creating file.!", "Error!", JOptionPane.NO_OPTION);		   return;		}	    else	    {		if(JOptionPane.showConfirmDialog(this, "Are you sure you want to replace this file?", "Replace ?", JOptionPane.OK_CANCEL_OPTION)==JOptionPane.CANCEL_OPTION)		    return;	    }	    String outfile = f.getAbsolutePath();	    htmlString = HTMLExporter.export(htmlString, unicodeIndent.isSelected(),		    line.isSelected(), formatter.getColorCode());	    FileOutputStream fos = null;	    OutputStreamWriter osw = null;	    BufferedWriter bw = null;	    try	    {		fos = new FileOutputStream(outfile);		osw = new OutputStreamWriter(fos);		bw = new BufferedWriter(osw);		bw.write(htmlString);	    } catch (Exception ex)	    {		JOptionPane.showMessageDialog(this, "Error in writing into the file.!", "Error!", JOptionPane.NO_OPTION);	    } finally	    {		try		{		    if(bw!=null)bw.close();		    if(osw!=null)osw.close();		    if(fos!=null)fos.close();		} catch (IOException ex)		{}	    }	}		formattedTextBox.setText(htmlString);    }                                                // Variables declaration - do not modify    private javax.swing.JTabbedPane PosterTabPane;    private javax.swing.JMenuItem about_menu;    private javax.swing.JRadioButtonMenuItem black_color;    private javax.swing.JRadioButtonMenuItem blue_color;    private javax.swing.ButtonGroup buttonGroup;    private javax.swing.JMenu edit;    private javax.swing.JLabel error_status;    private javax.swing.JMenuItem exit_menu;    private javax.swing.JMenuItem exportToHTML;    private javax.swing.JMenu file;    private javax.swing.JMenuItem formatCode_menu;    private javax.swing.JTextArea formattedTextBox;    private javax.swing.JMenuItem formatterSettings;    private javax.swing.JRadioButtonMenuItem green_color;    private javax.swing.JMenu help;    private javax.swing.JPanel htmlTab;    private javax.swing.JMenu jMenu1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JCheckBox line;    private javax.swing.JMenuBar menuBar;    private javax.swing.JMenuItem metal_menu;    private javax.swing.JMenuItem motif_menu;    private javax.swing.JMenuItem open_menu;    private javax.swing.JMenuItem pastebinSettings;    private javax.swing.JMenuItem publish;    private javax.swing.JRadioButtonMenuItem red_color;    private javax.swing.JMenuItem signature;    private javax.swing.JRadioButtonMenuItem standard_color;    private javax.swing.JMenu theme;    private javax.swing.JCheckBox unicodeIndent;    private javax.swing.JPanel viewTab;    private javax.swing.JTextArea viewTextBox;    private javax.swing.JMenuItem window_menu;    // End of variables declaration    //Actions for Themes menu    public void actionPerformed(ActionEvent e)    {	try	{	    if (e.getActionCommand().equals("Metal"))	    {		posterPrefs.setTheme(2);		lnf.setMetalTheme();	    } else if (e.getActionCommand().equals("Motif"))	    {		posterPrefs.setTheme(1);		lnf.setMotifTheme();	    } else if(e.getActionCommand().equals("Windows"))	    {		posterPrefs.setTheme(0);		lnf.setWindowsTheme();	    }	} catch (Exception ex1)	{	    JOptionPane.showConfirmDialog(null, "Theme you seleceted was not found in this platform"+"\nSetting to theme to Metal.", "Theme not supported", JOptionPane.PLAIN_MESSAGE);	    posterPrefs.setTheme(2);	    try	    {		lnf.setMetalTheme();	    } catch (Exception ex){}	}    }    public void windowOpened(WindowEvent e) { }    public void windowClosing(WindowEvent e)    {	posterPrefs.setHeight(getHeight());	posterPrefs.setWidth(getWidth());	posterPrefs.writePreferences();    }    public void windowClosed(WindowEvent e)   {}    public void windowIconified(WindowEvent e)    {}    public void windowDeiconified(WindowEvent e)    {}    public void windowActivated(WindowEvent e)    {}    public void windowDeactivated(WindowEvent e)    {}}