⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guicontroller.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:
/*
 * Created on 10-nov-2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package gui;

//import graph.NetworkGraph;
import java.awt.Frame;
import java.awt.Color;

//import java.util.Map;

import javax.swing.JOptionPane;
import javax.swing.JColorChooser;

//import graph.Properties;
//import org.jgraph.graph.GraphConstants;

//import org.jgraph.layout.LayoutDialog;
import org.jgraph.layout.LayoutAlgorithm;
import org.jgraph.layout.LayoutController;
//import org.jgraph.layout.SpringEmbeddedLayoutAlgorithm;
//import org.jgraph.layout.AnnealingLayoutAlgorithm;
import org.jgraph.layout.GEMLayoutAlgorithm;
import org.jgraph.layout.GEMLayoutController;

//import org.jgraph.layout.LayoutController;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultGraphCell;

import javax.swing.JFileChooser;

import graph.GraphEventManager;

public class GUIController
{


	private Hoofdscherm hoofdscherm;
	private GraphConstructionDialog1 gcd1;
	private GraphConstructionDialog2 gcd2;
	private JFileChooser jfc;

	private ResourceLibraryDialog resourceLibraryDialog;

	public void start()
	{
		GUIEventManager.getReference().addGUIController(this);
		setHoofdscherm(new Hoofdscherm());
		setGcd1(new GraphConstructionDialog1());
		setGcd2(new GraphConstructionDialog2());
		
		jfc=new JFileChooser();
	}
	
	
	public void updateModel(DefaultGraphModel model)
	{
		getHoofdscherm().updateModel(model);
		getHoofdscherm().show();
	}



	public Hoofdscherm getHoofdscherm()
	{
		return hoofdscherm;
	}

	public void setHoofdscherm(Hoofdscherm hoofdscherm)
	{
		this.hoofdscherm = hoofdscherm;
	}

	public void showLayoutDialog() {
			//Frame f = JOptionPane.getFrameForComponent(getHoofdscherm());
			//final org.jgraph.layout.LayoutDialog dlg = new org.jgraph.layout.LayoutDialog(f);
			final org.jgraph.layout.LayoutDialog dlg = new org.jgraph.layout.LayoutDialog(getHoofdscherm());
			dlg.show();

			if (dlg.isCanceled())
				return;

			final LayoutController controller = dlg.getSelectedLayoutController();
			if (controller == null)
				return;
			Thread t = new Thread("Layout Algorithm " + controller.toString()) {
				public void run() {
					LayoutAlgorithm algorithm = controller.getLayoutAlgorithm();
					algorithm.perform(
						getHoofdscherm().getNetworkGraph(),
						dlg.isApplyLayoutToAll(),
						controller.getConfiguration());
				}
			};
			t.start();
	}
	
	public void showGraphConstructionDialog1()
	{
		getGcd1().show();	
	}
	
	public void askParametersForLevel(int nbLevels)
	{
		getGcd2().askParametersForLevels(nbLevels);
	}
	
	public void showSaveDialog()
	{
		jfc.setDialogTitle("Save current network-graph");
		if (JFileChooser.APPROVE_OPTION == jfc.showSaveDialog(getHoofdscherm()))
		{
			System.out.println(jfc.getSelectedFile().getAbsolutePath());
			GraphEventManager.getReference().eventSaveModel(jfc.getSelectedFile().getAbsolutePath());
		}	
	}
	
	public void showOpenDialog(String message)
	{
		jfc.setDialogTitle(message);
		if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(getHoofdscherm()))
		{
			System.out.println(jfc.getSelectedFile().getAbsolutePath());
			GraphEventManager.getReference().eventOpenModel(jfc.getSelectedFile().getAbsolutePath());
		}		
	}
	
	public void showLoadExistingGraphDialog(String message)
	{
		jfc.setDialogTitle(message);
		if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(getHoofdscherm()))
		{
			System.out.println(jfc.getSelectedFile().getAbsolutePath());
			GraphEventManager.getReference().eventGetExistingGraph(jfc.getSelectedFile().getAbsolutePath());
		}
	}
	
	public void applyStandardLayoutAlgorithm()
	{
		//SpringEmbeddedLayoutAlgorithm sela = new SpringEmbeddedLayoutAlgorithm();
		GEMLayoutController glc = new GEMLayoutController();
		GEMLayoutAlgorithm gla = (GEMLayoutAlgorithm)glc.getLayoutAlgorithm();
		gla.perform(getHoofdscherm().getNetworkGraph(),true,glc.getConfiguration());
	}
	
	public void showColorChooserDialog(DefaultGraphCell dgc)
	{
		Frame f = JOptionPane.getFrameForComponent(getHoofdscherm());
		Color newColor = JColorChooser.showDialog(f,"Choose the new color",null);
		System.out.println(newColor);
		
		GraphEventManager.getReference().eventChangeColorFor(dgc, newColor);
		//Properties p = (Properties) GraphConstants.getValue(dgc.getAttributes());
		
		//p.setColor(newColor);
	}
	
	public void zoom(double factor)
	{
		getHoofdscherm().getNetworkGraph().setScale(getHoofdscherm().getNetworkGraph().getScale() * factor);
	}
	
	public void updateInfoJPanel(DefaultGraphCell dgc)
	{
		getHoofdscherm().updateInfoJPanel(dgc);
	}
	
	public void redrawGraph()
	{
		getHoofdscherm().getNetworkGraph().repaint();
	}

	private GraphConstructionDialog1 getGcd1()
	{
		return gcd1;
	}

	private void setGcd1(GraphConstructionDialog1 gcd1)
	{
		this.gcd1 = gcd1;
	}

	private GraphConstructionDialog2 getGcd2()
	{
		return gcd2;
	}

	private void setGcd2(GraphConstructionDialog2 gcd2)
	{
		this.gcd2 = gcd2;
	}

	private ResourceLibraryDialog getResourceLibraryDialog()
	{
		return resourceLibraryDialog;
	}

	private void setResourceLibraryDialog(ResourceLibraryDialog resourceLibraryDialog)
	{
		this.resourceLibraryDialog = resourceLibraryDialog;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -