/*
* cameracontrol
* Copyright (C) 2011 Stefano Fornari
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY Stefano Fornari, Stefano Fornari
* DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* 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 Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*/
/*
* TextViewerForm.java
*
* Created on Jan 5, 2011, 8:19:30 PM
*/
package ste.cameracontrol.ui;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author ste
*/
public class TextViewerForm extends javax.swing.JDialog {
/** Creates new form TextViewerForm */
public TextViewerForm(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setLocationRelativeTo(null);
}
/** 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();
textArea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
textArea.setBackground(java.awt.Color.white);
textArea.setColumns(40);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setRows(25);
textArea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
textArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
jScrollPane1.setViewportView(textArea);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Loads and display the text found in the resource whose name is given
* in <code>resourceName</code>. The resource is load with the current
* class loader.<br>
* Please note that if the resource is not found, an error message appears
* as text.
*
* @param resourceName the resource containing the text
*/
public void loadText(String resourceName) {
String text = "";
InputStream is = getClass().getClassLoader().getResourceAsStream(resourceName);
if (is == null) {
text = "Resource not found (" + resourceName + "=, please report...";
} else {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
byte[] buf = new byte[1024];
int read = 0;
while ((read = is.read(buf)) >= 0) {
os.write(buf, 0, read);
}
text = os.toString();
} catch (IOException e) {
text = "Error loading the license: "
+ e.getMessage()
+ "\nPlease report..."
;
} finally {
try { is.close(); is = null; } catch (IOException e) {}
try { os.close(); os = null; } catch (IOException e) {}
}
}
textArea.setText(text);
textArea.setCaretPosition(0);
}
public String getText() {
return textArea.getText();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
TextViewerForm dialog = new TextViewerForm(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea textArea;
// End of variables declaration//GEN-END:variables
}