forked from I2P_Developers/i2p.i2p

To use the application, you need to (by default) add the following to clients.config : # desktopgui clientApp.6.args= clientApp.6.delay=5 clientApp.6.main=desktopgui.Main clientApp.6.name=desktopgui clientApp.6.startOnLoad=true
287 lines
15 KiB
Java
287 lines
15 KiB
Java
/*
|
|
* ProfileSelector3.java
|
|
*
|
|
* Created on 3 april 2009, 15:17
|
|
*/
|
|
|
|
package gui;
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.Point;
|
|
import java.util.Properties;
|
|
import persistence.PropertyManager;
|
|
import router.configuration.SpeedHandler;
|
|
import router.configuration.SpeedHelper;
|
|
|
|
/**
|
|
*
|
|
* @author mathias
|
|
*/
|
|
public class SpeedSelector3 extends javax.swing.JFrame {
|
|
Properties props;
|
|
|
|
/** Creates new form ProfileSelector3 */
|
|
public SpeedSelector3(Point point, Dimension dimension) {
|
|
this.props = PropertyManager.getProps();
|
|
initComponents();
|
|
this.setLocation(point);
|
|
this.setSize(dimension);
|
|
initSpeeds();
|
|
this.setVisible(true);
|
|
}
|
|
|
|
/** 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() {
|
|
|
|
finishButton = new javax.swing.JButton();
|
|
previousButton = new javax.swing.JButton();
|
|
jLabel1 = new javax.swing.JLabel();
|
|
uploadLabel = new javax.swing.JLabel();
|
|
downloadLabel = new javax.swing.JLabel();
|
|
uploadBurstLabel = new javax.swing.JLabel();
|
|
downloadBurstLabel = new javax.swing.JLabel();
|
|
uploadUsageLabel = new javax.swing.JLabel();
|
|
downloadUsageLabel = new javax.swing.JLabel();
|
|
uploadField = new javax.swing.JTextField();
|
|
uploadBurstField = new javax.swing.JTextField();
|
|
downloadField = new javax.swing.JTextField();
|
|
downloadBurstField = new javax.swing.JTextField();
|
|
uploadMonth = new javax.swing.JLabel();
|
|
downloadMonth = new javax.swing.JLabel();
|
|
|
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
|
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopgui.Main.class).getContext().getResourceMap(SpeedSelector3.class);
|
|
setTitle(resourceMap.getString("Form.title")); // NOI18N
|
|
setName("Form"); // NOI18N
|
|
|
|
finishButton.setText(resourceMap.getString("finishButton.text")); // NOI18N
|
|
finishButton.setName("finishButton"); // NOI18N
|
|
finishButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
|
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
|
finishButtonMouseClicked(evt);
|
|
}
|
|
});
|
|
|
|
previousButton.setText(resourceMap.getString("previousButton.text")); // NOI18N
|
|
previousButton.setName("previousButton"); // NOI18N
|
|
previousButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
|
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
|
previousButtonMouseClicked(evt);
|
|
}
|
|
});
|
|
|
|
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
|
|
jLabel1.setName("jLabel1"); // NOI18N
|
|
|
|
uploadLabel.setText(resourceMap.getString("uploadLabel.text")); // NOI18N
|
|
uploadLabel.setName("uploadLabel"); // NOI18N
|
|
|
|
downloadLabel.setText(resourceMap.getString("downloadLabel.text")); // NOI18N
|
|
downloadLabel.setName("downloadLabel"); // NOI18N
|
|
|
|
uploadBurstLabel.setText(resourceMap.getString("uploadBurstLabel.text")); // NOI18N
|
|
uploadBurstLabel.setName("uploadBurstLabel"); // NOI18N
|
|
|
|
downloadBurstLabel.setText(resourceMap.getString("downloadBurstLabel.text")); // NOI18N
|
|
downloadBurstLabel.setName("downloadBurstLabel"); // NOI18N
|
|
|
|
uploadUsageLabel.setText(resourceMap.getString("uploadUsageLabel.text")); // NOI18N
|
|
uploadUsageLabel.setName("uploadUsageLabel"); // NOI18N
|
|
|
|
downloadUsageLabel.setText(resourceMap.getString("downloadUsageLabel.text")); // NOI18N
|
|
downloadUsageLabel.setName("downloadUsageLabel"); // NOI18N
|
|
|
|
uploadField.setText(resourceMap.getString("uploadField.text")); // NOI18N
|
|
uploadField.setMinimumSize(new java.awt.Dimension(77, 27));
|
|
uploadField.setName("uploadField"); // NOI18N
|
|
uploadField.addKeyListener(new java.awt.event.KeyAdapter() {
|
|
public void keyReleased(java.awt.event.KeyEvent evt) {
|
|
speedFieldKeyReleased(evt);
|
|
}
|
|
});
|
|
|
|
uploadBurstField.setText(resourceMap.getString("uploadBurstField.text")); // NOI18N
|
|
uploadBurstField.setMinimumSize(new java.awt.Dimension(77, 27));
|
|
uploadBurstField.setName("uploadBurstField"); // NOI18N
|
|
|
|
downloadField.setText(resourceMap.getString("downloadField.text")); // NOI18N
|
|
downloadField.setMinimumSize(new java.awt.Dimension(77, 27));
|
|
downloadField.setName("downloadField"); // NOI18N
|
|
downloadField.addKeyListener(new java.awt.event.KeyAdapter() {
|
|
public void keyReleased(java.awt.event.KeyEvent evt) {
|
|
speedFieldKeyReleased(evt);
|
|
}
|
|
});
|
|
|
|
downloadBurstField.setText(resourceMap.getString("downloadBurstField.text")); // NOI18N
|
|
downloadBurstField.setMinimumSize(new java.awt.Dimension(77, 27));
|
|
downloadBurstField.setName("downloadBurstField"); // NOI18N
|
|
|
|
uploadMonth.setText(resourceMap.getString("uploadMonth.text")); // NOI18N
|
|
uploadMonth.setName("uploadMonth"); // NOI18N
|
|
|
|
downloadMonth.setText(resourceMap.getString("downloadMonth.text")); // NOI18N
|
|
downloadMonth.setName("downloadMonth"); // NOI18N
|
|
|
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
|
getContentPane().setLayout(layout);
|
|
layout.setHorizontalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
|
.addComponent(jLabel1)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(uploadLabel)
|
|
.addComponent(uploadBurstLabel)
|
|
.addComponent(uploadUsageLabel))
|
|
.addGap(18, 18, 18)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
|
.addComponent(uploadBurstField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(uploadField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(uploadMonth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
.addGap(46, 46, 46)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(downloadLabel)
|
|
.addComponent(downloadBurstLabel)
|
|
.addComponent(downloadUsageLabel))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
|
.addComponent(downloadField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(downloadMonth, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(downloadBurstField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
|
|
.addGap(18, 18, 18))
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
.addComponent(previousButton)
|
|
.addGap(18, 18, 18)
|
|
.addComponent(finishButton)
|
|
.addGap(33, 33, 33)))
|
|
.addGap(400, 400, 400))
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
.addGap(81, 81, 81)
|
|
.addComponent(jLabel1)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(uploadLabel)
|
|
.addComponent(downloadLabel)
|
|
.addComponent(uploadField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(downloadField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGap(18, 18, 18)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(uploadBurstLabel)
|
|
.addComponent(downloadBurstLabel)
|
|
.addComponent(downloadBurstField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(uploadBurstField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGap(18, 18, 18)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(uploadUsageLabel)
|
|
.addComponent(downloadUsageLabel)
|
|
.addComponent(uploadMonth)
|
|
.addComponent(downloadMonth))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(previousButton)
|
|
.addComponent(finishButton))
|
|
.addContainerGap())
|
|
);
|
|
|
|
pack();
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
private void previousButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previousButtonMouseClicked
|
|
saveSpeeds();
|
|
PropertyManager.saveProps(props);
|
|
new SpeedSelector2(this.getLocationOnScreen(), this.getSize()).setVisible(true);
|
|
this.dispose();
|
|
}//GEN-LAST:event_previousButtonMouseClicked
|
|
|
|
private void finishButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_finishButtonMouseClicked
|
|
saveSpeeds();
|
|
PropertyManager.saveProps(props);
|
|
|
|
int maxDownload = Integer.parseInt(props.getProperty(SpeedSelectorConstants.MAXDOWNLOAD));
|
|
int maxUpload = Integer.parseInt(props.getProperty(SpeedSelectorConstants.MAXUPLOAD));
|
|
int maxUploadBurst = Integer.parseInt(props.getProperty(SpeedSelectorConstants.MAXUPLOADBURST));
|
|
int maxDownloadBurst = Integer.parseInt(props.getProperty(SpeedSelectorConstants.MAXDOWNLOADBURST));
|
|
|
|
//Working in kB, not kb!
|
|
SpeedHandler.setInboundBandwidth(maxDownload/8);
|
|
SpeedHandler.setOutboundBandwidth(maxUpload/8);
|
|
SpeedHandler.setInboundBurstBandwidth(maxDownloadBurst);
|
|
SpeedHandler.setOutboundBurstBandwidth(maxUploadBurst/8);
|
|
|
|
this.dispose();
|
|
}//GEN-LAST:event_finishButtonMouseClicked
|
|
|
|
private void speedFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_speedFieldKeyReleased
|
|
try {
|
|
initUsage(uploadField.getText(), downloadField.getText());
|
|
}
|
|
catch(NumberFormatException e) {
|
|
return;
|
|
}
|
|
}//GEN-LAST:event_speedFieldKeyReleased
|
|
|
|
protected void initSpeeds() {
|
|
String up = "" + SpeedHelper.calculateSpeed(
|
|
props.getProperty(SpeedSelectorConstants.MAXUPLOADCAPABLE), props.getProperty(SpeedSelectorConstants.USERTYPE));
|
|
String upBurst = "" + SpeedHelper.calculateSpeed(
|
|
props.getProperty(SpeedSelectorConstants.MAXUPLOADCAPABLE), props.getProperty(SpeedSelectorConstants.USERTYPE));
|
|
String down = "" + SpeedHelper.calculateSpeed(
|
|
props.getProperty(SpeedSelectorConstants.MAXDOWNLOADCAPABLE), props.getProperty(SpeedSelectorConstants.USERTYPE));
|
|
String downBurst = "" + SpeedHelper.calculateSpeed(
|
|
props.getProperty(SpeedSelectorConstants.MAXDOWNLOADCAPABLE), props.getProperty(SpeedSelectorConstants.USERTYPE));
|
|
String userType = props.getProperty(SpeedSelectorConstants.USERTYPE);
|
|
|
|
uploadField.setText(up);
|
|
uploadBurstField.setText(upBurst);
|
|
downloadField.setText(down);
|
|
downloadBurstField.setText(downBurst);
|
|
|
|
initUsage(up, down);
|
|
}
|
|
|
|
protected void saveSpeeds() {
|
|
props.setProperty(SpeedSelectorConstants.MAXUPLOAD, uploadField.getText());
|
|
props.setProperty(SpeedSelectorConstants.MAXUPLOADBURST, uploadBurstField.getText());
|
|
props.setProperty(SpeedSelectorConstants.MAXDOWNLOAD, downloadField.getText());
|
|
props.setProperty(SpeedSelectorConstants.MAXDOWNLOADBURST, downloadBurstField.getText());
|
|
}
|
|
|
|
protected void initUsage(String upload, String download) {
|
|
uploadMonth.setText(SpeedHelper.calculateMonthlyUsage(Integer.parseInt(upload)/8) + " GB");
|
|
downloadMonth.setText(SpeedHelper.calculateMonthlyUsage(Integer.parseInt(download)/8) + " GB");
|
|
}
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JTextField downloadBurstField;
|
|
private javax.swing.JLabel downloadBurstLabel;
|
|
private javax.swing.JTextField downloadField;
|
|
private javax.swing.JLabel downloadLabel;
|
|
private javax.swing.JLabel downloadMonth;
|
|
private javax.swing.JLabel downloadUsageLabel;
|
|
private javax.swing.JButton finishButton;
|
|
private javax.swing.JLabel jLabel1;
|
|
private javax.swing.JButton previousButton;
|
|
private javax.swing.JTextField uploadBurstField;
|
|
private javax.swing.JLabel uploadBurstLabel;
|
|
private javax.swing.JTextField uploadField;
|
|
private javax.swing.JLabel uploadLabel;
|
|
private javax.swing.JLabel uploadMonth;
|
|
private javax.swing.JLabel uploadUsageLabel;
|
|
// End of variables declaration//GEN-END:variables
|
|
|
|
}
|