package org.netfpga.eventcap;
/*
* RateLimiterInternalFrame.java
*
* Created on May 7, 2007, 9:35 PM
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.Timer;
import org.netfpga.router.ControlCheckBox;
import org.netfpga.router.ControlRegGroup;
import org.netfpga.router.RegSliderGroupControl;
import org.netfpga.router.ValueTransformer;
import org.netfpga.backend.NFDevice;
import org.netfpga.backend.NFDeviceConsts;
/**
*
* @author jnaous
*/
@SuppressWarnings("serial")
public class RateLimiterInternalFrame extends javax.swing.JInternalFrame {
private RegSliderGroupControl sliderCtrl;
private ControlRegGroup ctrlRegGrp;
private Timer timer;
private ActionListener timerActionListener;
/**
* Creates new form RateLimiterInternalFrame
*/
public RateLimiterInternalFrame(NFDevice nf2, Timer timer) {
this.timer = timer;
initComponents();
sliderCtrl = new RegSliderGroupControl(nf2, this.rateSlider, this.rateValueLabel, NFDeviceConsts.RATE_LIMIT_1_SHIFT_REG);
sliderCtrl.setVt(new ValueTransformer() {
public int toSliderValue(int val) {
return 15-val;
}
public int toRegisterValue(int val) {
return 15-val;
}
public String toLabelStringFromReg(int val) {
double rate = 8.0/(1+java.lang.Math.pow(2, val));
String unit = "Gbps";
if(rate<0.001){
rate *= 1000000;
unit = "Kbps";
} else if(rate<1){
rate *= 1000;
unit = "Mbps";
}
return String.format("%.3f",rate)+unit;
}
public String toLabelStringFromComponent(int val) {
return toLabelStringFromReg(15-val);
}
});
AbstractButton[] buttons = {this.enabledCheckbox};
boolean[] invert = {false};
ctrlRegGrp = new ControlRegGroup(nf2, NFDeviceConsts.RATE_LIMIT_1_ENABLE_REG,
buttons, invert);
/* add listeners to the update the tables */
timerActionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
sliderCtrl.updateFromRegs();
ctrlRegGrp.updateFromRegs();
}
};
/* add action listener to the timer */
timer.addActionListener(timerActionListener);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
RateLimiterScrollPane = new javax.swing.JScrollPane();
RateLimiterPanel = new javax.swing.JPanel();
pageTitleLabel = new javax.swing.JLabel();
enabledCheckbox = new ControlCheckBox();
titleConfigSeparator = new javax.swing.JSeparator();
minRateLabel = new javax.swing.JLabel();
maxRateLabel = new javax.swing.JLabel();
rateSlider = new javax.swing.JSlider();
rateLabel = new javax.swing.JLabel();
rateValueLabel = new javax.swing.JLabel();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Rate Limiter");
setMinimumSize(new java.awt.Dimension(0, 0));
setPreferredSize(new java.awt.Dimension(350, 250));
setVisible(true);
addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
formInternalFrameClosed(evt);
}
public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
}
});
RateLimiterPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
pageTitleLabel.setFont(new java.awt.Font("Dialog", 1, 18));
pageTitleLabel.setText("Rate Limiter");
RateLimiterPanel.add(pageTitleLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));
enabledCheckbox.setText("Enabled");
enabledCheckbox.setToolTipText("Uncheck to disable receiving any packet on this port");
enabledCheckbox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
enabledCheckbox.setMargin(new java.awt.Insets(0, 0, 0, 0));
RateLimiterPanel.add(enabledCheckbox, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));
RateLimiterPanel.add(titleConfigSeparator, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 40, 330, 10));
minRateLabel.setText("244kbps");
RateLimiterPanel.add(minRateLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));
maxRateLabel.setText("4Gbps");
RateLimiterPanel.add(maxRateLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 120, -1, -1));
rateSlider.setMajorTickSpacing(1);
rateSlider.setMaximum(15);
rateSlider.setPaintTicks(true);
rateSlider.setSnapToTicks(true);
rateSlider.setToolTipText("Slide to change throughput of traffic though the module");
rateSlider.setValue(15);
RateLimiterPanel.add(rateSlider, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 270, -1));
rateLabel.setText("Current link-rate: ");
RateLimiterPanel.add(rateLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, -1, -1));
rateValueLabel.setText("4.0Gbps");
RateLimiterPanel.add(rateValueLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 190, 140, -1));
RateLimiterScrollPane.setViewportView(RateLimiterPanel);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(RateLimiterScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(RateLimiterScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
this.timer.removeActionListener(this.timerActionListener);
}//GEN-LAST:event_formInternalFrameClosed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel RateLimiterPanel;
private javax.swing.JScrollPane RateLimiterScrollPane;
private javax.swing.JCheckBox enabledCheckbox;
private javax.swing.JLabel maxRateLabel;
private javax.swing.JLabel minRateLabel;
private javax.swing.JLabel pageTitleLabel;
private javax.swing.JLabel rateLabel;
private javax.swing.JSlider rateSlider;
private javax.swing.JLabel rateValueLabel;
private javax.swing.JSeparator titleConfigSeparator;
// End of variables declaration//GEN-END:variables
}