/*
* Copyright (C) 2014 Shashank Tulsyan
*
* 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 neembuu.vfs.test;
import neembuu.vfs.test.graphprovider.SpeedGraphs;
import java.text.NumberFormat;
import javax.swing.JFormattedTextField;
import neembuu.vfs.test.graphprovider.SpeedGraphJFluid;
/**
*
* @author Shashank Tulsyan
*/
public class MonitoredFilePanel extends javax.swing.JPanel {
MonitorableNonHttpFile file;
final int maxAge = 1000*12;
SpeedGraphJFluid speedGraphs;
/** Creates new form MonitoredFilePanel */
public MonitoredFilePanel(MonitorableNonHttpFile file) {
this.file = file;
speedGraphs = new SpeedGraphJFluid();
initComponents();
filenameLabel.setText(
filenameLabel.getText()+file.getName()
);
fileSizeLabel.setText(
fileSizeLabel.getText()+
(file.getFileSize()/(1024*1024))+" MB");
}
double r,d;
/*package private*/final void setSupplySpeed(double supplySpeed){
this.supplySpeed.setText("Supply Speed : " + ((int)supplySpeed) +"KB/s");
d= supplySpeed;
if(Math.abs(supplySpeed) < 10*1000)
((SpeedGraphJFluid)speedGraphs).speedChanged(d,r);
}
/*package private*/final void setRequestSpeed(double requestSpeed){
r = requestSpeed;
this.requestSpeed.setText("Watching Speed : " + ((int)requestSpeed) +"KB/s");
if(Math.abs(requestSpeed) < 10*1000)
((SpeedGraphJFluid)speedGraphs).speedChanged(d,r);
}
/** 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() {
rangeArrayView = new neembuu.swing.RangeArrayComponent(file.getRequestedRegion());
filenameLabel = new javax.swing.JLabel();
fileSizeLabel = new javax.swing.JLabel();
deleteHistoryButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
throttledSpeedBox = new JFormattedTextField(NumberFormat.getInstance());
printButton = new javax.swing.JButton();
pendingRequestsButton = new javax.swing.JButton();
speedChartPanel = speedGraphs;
setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
setMaximumSize(new java.awt.Dimension(428, 1000));
setMinimumSize(new java.awt.Dimension(100, 100));
filenameLabel.setText("Filename :");
fileSizeLabel.setText("FileSize :");
deleteHistoryButton.setText("Delete History");
deleteHistoryButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteHistoryButtonActionPerformed(evt);
}
});
jLabel1.setText("Throttle supply speed to (KBps) :");
throttledSpeedBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
throttledSpeedBoxActionPerformed(evt);
}
});
printButton.setText("Print State");
printButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButtonActionPerformed(evt);
}
});
pendingRequestsButton.setText("Show Pending Requests");
pendingRequestsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pendingRequestsButtonActionPerformed(evt);
}
});
requestSpeed.setText("Watching Speed : KB/s");
supplySpeed.setText("Supply Speed : KB/s");
speedChartPanel.setMaximumSize(new java.awt.Dimension(404, 350));
speedChartPanel.setMinimumSize(new java.awt.Dimension(404, 200));
speedChartPanel.setName(""); // NOI18N
speedChartPanel.setPreferredSize(new java.awt.Dimension(404, 200));
javax.swing.GroupLayout speedChartPanelLayout = new javax.swing.GroupLayout(speedChartPanel);
speedChartPanel.setLayout(speedChartPanelLayout);
speedChartPanelLayout.setHorizontalGroup(
speedChartPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 385, Short.MAX_VALUE)
);
speedChartPanelLayout.setVerticalGroup(
speedChartPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 179, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(fileSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(filenameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(rangeArrayView, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pendingRequestsButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(printButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(requestSpeed, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(73, 73, 73)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(supplySpeed, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(deleteHistoryButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(speedChartPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(5, 5, 5)
.addComponent(throttledSpeedBox, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(filenameLabel)
.addGap(2, 2, 2)
.addComponent(fileSizeLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rangeArrayView, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(throttledSpeedBox, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(speedChartPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(requestSpeed)
.addComponent(supplySpeed))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(deleteHistoryButton)
.addComponent(printButton)
.addComponent(pendingRequestsButton))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void deleteHistoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteHistoryButtonActionPerformed
throw new UnsupportedOperationException();
//file.getRequestedRegion().removeElement(0, file.getFileSize());
//rangeArrayView.repaint();
//System.out.println("repaintnig");
}//GEN-LAST:event_deleteHistoryButtonActionPerformed
private void throttledSpeedBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_throttledSpeedBoxActionPerformed
// TODO add your handling code here:
if(file instanceof ThrottledRealFile){
try{
((ThrottledRealFile)file).setCps(
Integer.parseInt(
throttledSpeedBox.getText()
)*1024
);
}catch(Exception any){
((ThrottledRealFile)file).setCps(
ThrottledRealFile.INVALID_CPS
);
}
}
}//GEN-LAST:event_throttledSpeedBoxActionPerformed
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
System.out.println("+++++++"+file.getName()+"++++++");
System.out.println(file.getRequestedRegion());
System.out.println("-------"+file.getName()+"------");
}//GEN-LAST:event_printButtonActionPerformed
private void pendingRequestsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pendingRequestsButtonActionPerformed
// TODO add your handling code here:
ThrottledRealFile f;
if(this.file instanceof ThrottledRealFile){
f = (ThrottledRealFile)this.file;
}else {
System.out.println("This is not an instance of ThrottledReadlFile");
return;
}
f.printPendingRequests(System.out);
}//GEN-LAST:event_pendingRequestsButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton deleteHistoryButton;
private javax.swing.JLabel fileSizeLabel;
private javax.swing.JLabel filenameLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton pendingRequestsButton;
private javax.swing.JButton printButton;
protected javax.swing.JProgressBar rangeArrayView;
final javax.swing.JLabel requestSpeed = new javax.swing.JLabel();
private javax.swing.JPanel speedChartPanel;
final javax.swing.JLabel supplySpeed = new javax.swing.JLabel();
private javax.swing.JFormattedTextField throttledSpeedBox;
// End of variables declaration//GEN-END:variables
}