/*
* BinergabungView.java
*/
package binergabung;
import java.awt.Color;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.File;
import java.awt.Toolkit;
import java.awt.Image;
import java.awt.Cursor;
import javax.swing.ProgressMonitor;
/**
* The application's main frame.
*/
public class BinergabungView extends FrameView {
public BinergabungView(SingleFrameApplication app) {
super(app);
initComponents();
Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
//Image icon = Toolkit.getDefaultToolkit().getImage(this.getFrame().getClass().getResource("/icon.gif"));
this.getFrame().setIconImage(icon);
this.getFrame().setResizable(false);
this.getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
int counter = 0;
class ProgressMonitor implements Runnable{
public void run() {
//run untill 100% complete
while(counter < 100){
//update the progressbar
progress.setValue(++counter);
try {
//Sleep for .25 second
Thread.sleep(10);
} catch (InterruptedException ex) {}
}
System.out.println("We're done!");
}
}
@Action
public void gabung()
{
//create a new thread running a ProgressMonitor and start it
new Thread(new ProgressMonitor()).start();
String input1, input2, hasil;
JFrame mainFrame = BinergabungApp.getApplication().getMainFrame();
input1 = teks1.getText();
input2 = teks2.getText();
hasil = teks3.getText();
if (input1.isEmpty())
{
status.setForeground(Color.RED);
status.setText("Error : Please choose image file");
}
else if (input2.isEmpty())
{
status.setForeground(Color.RED);
status.setText("Error : Please choose archive file");
}
else if (hasil.isEmpty())
{
status.setForeground(Color.RED);
status.setText("Error : Please choose saved file");
}
else
{
status.setForeground(Color.BLUE);
status.setText("Status : Processing..");
mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try
{
FileInputStream fstream1 = new FileInputStream(input1);
FileInputStream fstream2 = new FileInputStream(input2);
DataInputStream in1 = new DataInputStream(fstream1);
DataInputStream in2 = new DataInputStream(fstream2);
FileOutputStream fos = new FileOutputStream(hasil, false);
while (in1.available() !=0)
{
fos.write(in1.readByte());
}
status.setForeground(Color.BLUE);
status.setText("Status : 50% Done");
while (in2.available() !=0)
{
fos.write(in2.readByte());
}
fos.close();
in1.close();
in2.close();
status.setForeground(Color.BLUE);
status.setText("Status : Completed");
}
catch(FileNotFoundException ex)
{
System.out.println("FileNotFoundException : " + ex);
status.setForeground(Color.RED);
status.setText("Error : File not found");
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
status.setForeground(Color.RED);
status.setText("Error : IO error");
}
mainFrame.setCursor(Cursor.getDefaultCursor());
}
}
@Action
public void browsefile(JTextField kotak, String status)
{
int pilih = bokspilih.showDialog(bokspilih, status);
if (pilih == bokspilih.APPROVE_OPTION)
{
File file = bokspilih.getSelectedFile();
try
{
kotak.setText(file.getAbsolutePath());
if (!teks1.getText().isEmpty() && !teks2.getText().isEmpty() && !status.equalsIgnoreCase("save"))
{
String namafile, ekstensi;
namafile = teks1.getText();
namafile = namafile.trim();
int posisi = namafile.lastIndexOf(".");
ekstensi = namafile.substring(posisi);
if (0 < posisi && posisi <= namafile.length() - 2 )
namafile = namafile.substring(0, posisi);
namafile = namafile.concat("-muxed").concat(ekstensi);
teks3.setText(namafile);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = BinergabungApp.getApplication().getMainFrame();
aboutBox = new BinergabungAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
BinergabungApp.getApplication().show(aboutBox);
}
/** 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() {
mainPanel = new javax.swing.JPanel();
teks1 = new javax.swing.JTextField();
teks2 = new javax.swing.JTextField();
teks3 = new javax.swing.JTextField();
tombol = new javax.swing.JButton();
browse1 = new javax.swing.JButton();
browse2 = new javax.swing.JButton();
browse3 = new javax.swing.JButton();
status = new javax.swing.JFormattedTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
statusPanel = new javax.swing.JPanel();
progress = new javax.swing.JProgressBar();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
bokspilih = new javax.swing.JFileChooser();
mainPanel.setName("mainPanel"); // NOI18N
teks1.setEditable(false);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(binergabung.BinergabungApp.class).getContext().getResourceMap(BinergabungView.class);
teks1.setText(resourceMap.getString("teks1.text")); // NOI18N
teks1.setName("teks1"); // NOI18N
teks2.setEditable(false);
teks2.setText(resourceMap.getString("teks2.text")); // NOI18N
teks2.setName("teks2"); // NOI18N
teks3.setEditable(false);
teks3.setText(resourceMap.getString("teks3.text")); // NOI18N
teks3.setName("teks3"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(binergabung.BinergabungApp.class).getContext().getActionMap(BinergabungView.class, this);
tombol.setAction(actionMap.get("gabung")); // NOI18N
tombol.setText(resourceMap.getString("tombol.text")); // NOI18N
tombol.setName("tombol"); // NOI18N
browse1.setText(resourceMap.getString("browse1.text")); // NOI18N
browse1.setActionCommand(resourceMap.getString("browse1.actionCommand")); // NOI18N
browse1.setName("browse1"); // NOI18N
browse1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browse1ActionPerformed(evt);
}
});
browse2.setText(resourceMap.getString("browse2.text")); // NOI18N
browse2.setName("browse2"); // NOI18N
browse2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browse2ActionPerformed(evt);
}
});
browse3.setText(resourceMap.getString("browse3.text")); // NOI18N
browse3.setName("browse3"); // NOI18N
browse3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browse3ActionPerformed(evt);
}
});
status.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createCompoundBorder(), javax.swing.BorderFactory.createEtchedBorder()));
status.setEditable(false);
status.setForeground(resourceMap.getColor("status.foreground")); // NOI18N
status.setText(resourceMap.getString("status.text")); // NOI18N
status.setName("status"); // NOI18N
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
jLabel3.setName("jLabel3"); // NOI18N
jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
jLabel4.setName("jLabel4"); // NOI18N
statusPanel.setBackground(resourceMap.getColor("statusPanel.background")); // NOI18N
statusPanel.setName("statusPanel"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 387, Short.MAX_VALUE)
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 13, Short.MAX_VALUE)
);
progress.setName("progress"); // NOI18N
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addGap(13, 13, 13))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(teks2)
.addComponent(teks1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(status)
.addComponent(teks3, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(browse3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(browse1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(browse2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(78, 78, 78)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tombol))))
.addContainerGap(13, Short.MAX_VALUE))
.addComponent(statusPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(teks1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(browse1))
.addGap(26, 26, 26))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4)
.addGap(18, 18, 18)))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(teks2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(browse2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(34, 34, 34)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(teks3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(browse3)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tombol)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
menuBar.setBackground(resourceMap.getColor("menuBar.background")); // NOI18N
menuBar.setName("menuBar"); // NOI18N
fileMenu.setBackground(resourceMap.getColor("fileMenu.background")); // NOI18N
fileMenu.setForeground(resourceMap.getColor("fileMenu.foreground")); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setBackground(resourceMap.getColor("helpMenu.background")); // NOI18N
helpMenu.setForeground(resourceMap.getColor("helpMenu.foreground")); // NOI18N
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
bokspilih.setName("bokspilih"); // NOI18N
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void browse1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.browsefile(teks1, "Open");
}
private void browse2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.browsefile(teks2, "Open");
}
private void browse3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.browsefile(teks3, "Save");
}
// Variables declaration - do not modify
private javax.swing.JFileChooser bokspilih;
private javax.swing.JButton browse1;
private javax.swing.JButton browse2;
private javax.swing.JButton browse3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progress;
private javax.swing.JFormattedTextField status;
private javax.swing.JPanel statusPanel;
private javax.swing.JTextField teks1;
private javax.swing.JTextField teks2;
private javax.swing.JTextField teks3;
private javax.swing.JButton tombol;
// End of variables declaration
private JDialog aboutBox;
}