Commit 73f2042f authored by Clemens Krug's avatar Clemens Krug
Browse files

Grid cells are now destroy by Shift+Leftclick instead leftclick only

This modification was introduced to avoid destroying cells when clicking a node
parent 835d7fdd
......@@ -32,12 +32,7 @@ import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.HashMap;
......@@ -46,16 +41,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.Timer;
import javax.swing.*;
import com.google.common.collect.Maps;
......@@ -153,6 +139,7 @@ public class VisualizationTopologyView extends JFrame
this.setPreferredSize(new Dimension(800, 600));
this.setExtendedState(Frame.MAXIMIZED_BOTH);
Thread t = new Thread(this);
t.start();
}
......@@ -602,6 +589,7 @@ public class VisualizationTopologyView extends JFrame
if (me.getID() == MouseEvent.MOUSE_CLICKED) {
l.mouseClicked(x, y);
l.mouseClicked(x, y, me.getModifiers());
} else {
if (l instanceof MouseListener) {
switch (me.getID()) {
......@@ -635,16 +623,24 @@ public class VisualizationTopologyView extends JFrame
}, eventMask);
}
public static interface MouseClickListener {
public void mouseClicked(int x, int y);
@Deprecated
/**
* Method is deprecated. Uses mouseClicked(int x, int y, int modifier) instead.
*/
default void mouseClicked(int x, int y){}
default void mouseClicked(int x, int y, int modifier) {}
}
public static interface MouseListener extends MouseClickListener {
public void mouseDragged(int x, int y);
public interface MouseListener extends MouseClickListener {
void mouseDragged(int x, int y);
public void mousePressed(int x, int y);
void mousePressed(int x, int y);
public void mouseReleased(int x, int y);
void mouseReleased(int x, int y);
}
public static JComponent getWorldPanel() {
......@@ -659,6 +655,7 @@ public class VisualizationTopologyView extends JFrame
mouseListeners.remove(listener);
}
/**
* Listener is informed, whenever the user clicks on a node
*
......
......@@ -20,17 +20,6 @@
package de.tud.kom.p2psim.impl.topology.views.visualization.world;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.fiveg.AbstractGridBasedTopologyDatabase;
......@@ -38,13 +27,18 @@ import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry;
import de.tudarmstadt.maki.simonstrator.api.Rate;
import de.tudarmstadt.maki.simonstrator.api.Time;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
/**
* Visualization for the {@link FiveGTopologyView}
*
* @author Bjoern Richerzhagen
* @version 1.0, Nov 5, 2015
*/
public class FiveGVisualization extends JComponent implements VisualizationInjector.MouseClickListener{
public class FiveGVisualization extends JComponent implements VisualizationInjector.MouseClickListener {
protected BufferedImage image;
......@@ -171,17 +165,16 @@ public class FiveGVisualization extends JComponent implements VisualizationInjec
}
/**
* When a grid cell is clicked, the cell changes it connectivity.
* @param x
* @param y
*/
@Override
public void mouseClicked(int x, int y)
public void mouseClicked(int x, int y, int modifier)
{
int segID = database.getSegmentID(x,y);
Entry entry = database.getEntryFor(segID, false);
entry.setConnectivity(!entry.getConnectivity());
needsRedraw = true;
// 17 == Shift
if(modifier == 17)
{
int segID = database.getSegmentID(x, y);
Entry entry = database.getEntryFor(segID, false);
entry.setConnectivity(!entry.getConnectivity());
needsRedraw = true;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment