Those friends who are never engaged in GIS development and application but have quite some knowledge of TNetwork often feel confused about how to develop a system interface involving GIS application when they are using TWaver GIS development.
General TNetwork components are used to display the logical relationship between nodes in network, that is, for example, the connecting relationship between node a and node b from n nodes in an Internet network. TWaver GIS is used to help users to display the physical meaning of nodes in network through TNetwork components. In brief, it is used to correspond the latitude and longitude of a specific node in real world with its position on the screen of the interface of a computer system, hence the real presentation of the physical position of network nodes.
In a network, the interactive modes in the logical relationship and physical meaning of nodes are separate from and independent of each other. For example, interactive acts like pan and zoom in/out of general TNetwork components cannot be applied on GIS interaction and the same as those of GIS application scenes. Because of that, many users are confused about the two interactive scenes, mixing them up. So they have no idea how to orderly establish the interactions of interfaces in practice. Now I introduce a common way of interaction to you to help reduce puzzlement during early stages in development.
This typical application mode is actually very simple as you can just use a page particular for displaying physical network (involving Map, GIS application of longitude and latitude). When users need to see logical network (like the structure of service network, equipment panels, etc.) due to their needs in business, they can open another new page to display these logical network. Based on such basic thoughts, we could choose JTabbedPane as the main container to meet our requirements.
Here's the details:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import twaver.GeoCoordinate;
import twaver.Link;
import twaver.Node;
import twaver.PopupMenuGenerator;
import twaver.SubNetwork;
import twaver.TDataBox;
import twaver.TView;
import twaver.gis.GeographyMap;
import twaver.gis.GisNetworkAdapter;
import twaver.gis.TWaverGisConst;
import twaver.network.TNetwork;
public class MapAndLogicNetwork {
private JFrame frame;
private Random random = new Random();
private JTabbedPane tabbed = new JTabbedPane();
public MapAndLogicNetwork(){
initLayout();
initContents();
}
private void initLayout(){
frame = new JFrame();
Container container = frame.getContentPane();
container.setLayout(new BorderLayout());
container.add(tabbed,BorderLayout.CENTER);
frame.setSize(800,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initContents(){
initMap();
}
private void removeLogicNetworkComponent(){
TNetwork source = (TNetwork)tabbed.getComponentAt(1);
tabbed.removeTabAt(1);
}
private void insertLogicNetwork(TDataBox box){
if(tabbed.getTabCount()>1){
removeLogicNetworkComponent();
}
final TNetwork logicNetwork = new TNetwork(box);
logicNetwork.setPopupMenuGenerator(new PopupMenuGenerator() {
public JPopupMenu generate(TView tview, MouseEvent mouseEvent) {
JPopupMenu pop = new JPopupMenu();
JMenuItem item = new JMenuItem("close");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeLogicNetworkComponent();
}
});
pop.add(item);
return pop;
}
});
tabbed.add("LogicNetwork "+box.getName(),logicNetwork);
tabbed.setSelectedIndex(1);
}
private void initMap(){
TNetwork network = new TNetwork();
GisNetworkAdapter adapter = new GisNetworkAdapter(network);
adapter.installAdapter();
GeographyMap map = adapter.getMap();
map.addLayer("Googlemap", TWaverGisConst.EXECUTOR_TYPE_GOOGLEMAP);
map.setZoom(2);
TDataBox box = network.getDataBox();
Node node = new Node();
node.putLabelColor(Color.RED);
node.setName("Double click on me");
node.putClientProperty(TWaverGisConst.GEOCOORDINATE, new GeoCoordinate(-90,40));
box.addElement(node);
tabbed.addTab("Map Container", network);
network.addElementDoubleClickedActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TDataBox box = new TDataBox();
SubNetwork n1 = new SubNetwork();
n1.setDataSource("/data.xml");
n1.setName("Logic n1");
Node n2 = new Node();
n2.setName("Logic n2");
Link l = new Link(n1,n2);
n1.setLocation(Math.abs(random.nextInt(500)), Math.abs(random.nextInt(500)));
n2.setLocation(Math.abs(random.nextInt(50)), Math.abs(random.nextInt(400)));
box.addElement(n1);
box.addElement(n2);
box.addElement(l);
box.setName("Random box "+Math.abs(random.nextInt()));
insertLogicNetwork(box);
}
});
}
public void showup(){
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
public static void main(String[] args){
new MapAndLogicNetwork().showup();
}
}
At first: Master Boot-the interface displayed with maps:
Double click a specific node on the map, thus a logical-network page is added. That page is added on a JTabbed one.
You can choose “close” on the menu appeared at the click of the right button of the mouse to exit the presentation of the logical network and this page to return to the main interface displayed with the map.
No comments:
Post a Comment