Added ETX factor to convert the ETX value

This commit is contained in:
nifi 2010-10-22 11:04:04 +00:00
parent 6e28b1d3fb
commit 39d1e09232

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MapPanel.java,v 1.5 2010/10/12 22:26:56 nifi Exp $ * $Id: MapPanel.java,v 1.6 2010/10/22 11:04:04 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/10/12 22:26:56 $ * Updated : $Date: 2010/10/22 11:04:04 $
* $Revision: 1.5 $ * $Revision: 1.6 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -55,13 +55,17 @@ import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFormattedTextField;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
@ -132,6 +136,8 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
private int layoutAttract = 50; private int layoutAttract = 50;
private int layoutGravity = 1; private int layoutGravity = 1;
private double etxFactor = 1.0;
private boolean isLayoutActive = true; private boolean isLayoutActive = true;
private boolean hideNetwork = false; private boolean hideNetwork = false;
@ -212,8 +218,19 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
}); });
configPanel.add(slider); configPanel.add(slider);
add(configPanel); final JFormattedTextField etxField = new JFormattedTextField(new Double(etxFactor));
etxField.setBorder(BorderFactory.createTitledBorder("ETX factor"));
etxField.setColumns(5);
etxField.addPropertyChangeListener("value", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
etxFactor = ((Number)etxField.getValue()).doubleValue();
repaint();
}
});
configPanel.add(etxField);
configPanel.setVisible(false); configPanel.setVisible(false);
add(configPanel);
addComponentListener(new ComponentAdapter() { addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ev) { public void componentResized(ComponentEvent ev) {
@ -477,7 +494,7 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
dy += fnHeight - fnDescent; dy += fnHeight - fnDescent;
} }
g.drawString( g.drawString(
Double.toString(((int) (link.getETX() * 100 + 0.5)) / 100.0), Double.toString(((int) (link.getETX() * etxFactor * 100 + 0.5)) / 100.0),
dx, dy); dx, dy);
} }
} }
@ -563,7 +580,7 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
double vy = n2.y - n.y; double vy = n2.y - n.y;
double dist = Math.sqrt(vx * vx + vy * vy); double dist = Math.sqrt(vx * vx + vy * vy);
dist = dist == 0 ? 0.00001 : dist; dist = dist == 0 ? 0.00001 : dist;
double etx = link.getETX(); double etx = link.getETX() * etxFactor;
if (etx > 5) etx = 5; if (etx > 5) etx = 5;
double factor = (etx * layoutAttract - dist) / (dist * 3); double factor = (etx * layoutAttract - dist) / (dist * 3);
double dx = factor * vx; double dx = factor * vx;