it.tidalwave.netbeans.examples.nodes.example7.view.ViewerFrame Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* OpenBlueSky - NetBeans Platform Enhancements
* Copyright (C) 2006-2012 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://openbluesky.java.net
* SCM: https://bitbucket.org/tidalwave/openbluesky-src
*
**********************************************************************************************************************/
package it.tidalwave.netbeans.examples.nodes.example7.view;
import javax.annotation.Nonnull;
import lombok.Cleanup;
import java.util.concurrent.ExecutionException;
import java.io.IOException;
import java.io.Reader;
import javax.swing.JFrame;
import javax.swing.SwingWorker;
import org.apache.commons.io.IOUtils;
import it.tidalwave.netbeans.examples.nodes.example1.util.Launcher;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class ViewerFrame extends JFrame
{
public ViewerFrame (final @Nonnull Reader r)
{
initComponents();
Launcher.centerOnScreen(this);
SwingWorker swingWorker = new SwingWorker()
{
@Override @Nonnull
protected String doInBackground()
throws IOException
{
final @Cleanup Reader r2 = r;
return IOUtils.toString(r2);
}
@Override
protected void done()
{
try
{
epEditor.setText(get());
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
}
};
swingWorker.execute();
}
//@bluebook-ignore-begin
/*
*
* 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")
// //GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
epEditor = new javax.swing.JEditorPane();
btOk = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(800, 600));
epEditor.setEditable(false);
epEditor.setFont(new java.awt.Font("Courier New", 0, 13));
epEditor.setAutoscrolls(false);
epEditor.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jScrollPane1.setViewportView(epEditor);
btOk.setText(org.openide.util.NbBundle.getMessage(ViewerFrame.class, "ViewerFrame.btOk.text")); // NOI18N
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE)
.add(btOk, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
.add(18, 18, 18)
.add(btOk)
.addContainerGap())
);
pack();
}// //GEN-END:initComponents
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
dispose();
}//GEN-LAST:event_btOkActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btOk;
private javax.swing.JEditorPane epEditor;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
//@bluebook-ignore-end
}