View Javadoc

1   /*
2    *  UnBBayes
3    *  Copyright (C) 2002, 2008 Universidade de Brasilia - http://www.unb.br
4    *
5    *  This file is part of UnBBayes.
6    *
7    *  UnBBayes is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  UnBBayes is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with UnBBayes.  If not, see <http://www.gnu.org/licenses/>.
19   *
20   */
21  package unbbayes.controller;
22  
23  import java.awt.Component;
24  import java.awt.Cursor;
25  import java.awt.Graphics2D;
26  import java.awt.Rectangle;
27  import java.awt.event.KeyEvent;
28  import java.awt.event.KeyListener;
29  import java.awt.image.BufferedImage;
30  import java.awt.image.RenderedImage;
31  import java.awt.print.PageFormat;
32  import java.awt.print.PrinterException;
33  import java.io.File;
34  import java.io.IOException;
35  import java.util.ArrayList;
36  import java.util.List;
37  import java.util.ResourceBundle;
38  
39  import javax.imageio.ImageIO;
40  import javax.swing.JComponent;
41  import javax.swing.JDialog;
42  import javax.swing.JFileChooser;
43  import javax.swing.JOptionPane;
44  import javax.swing.JTable;
45  import javax.swing.JTextArea;
46  
47  import unbbayes.evaluation.controller.EvaluationController;
48  import unbbayes.gui.FileIcon;
49  import unbbayes.gui.NetworkWindow;
50  import unbbayes.gui.SimpleFileFilter;
51  import unbbayes.gui.util.TextAreaDialog;
52  import unbbayes.io.BaseIO;
53  import unbbayes.io.extension.jpf.PluginAwareFileExtensionIODelegator;
54  import unbbayes.prs.Edge;
55  import unbbayes.prs.Graph;
56  import unbbayes.prs.Network;
57  import unbbayes.prs.Node;
58  import unbbayes.prs.bn.ProbabilisticNetwork;
59  import unbbayes.prs.bn.ProbabilisticNode;
60  import unbbayes.prs.bn.SingleEntityNetwork;
61  import unbbayes.prs.hybridbn.ContinuousNode;
62  import unbbayes.util.extension.bn.inference.IInferenceAlgorithm;
63  
64  /**
65   * This class is responsible for delegating instructions that is going to be 
66   * executed in a SingleEntityNetwork or MultiEntityBayesianNetwork. Insert node 
67   * and propagate evidences, for instance.
68   *
69   * @author     Rommel Novaes Carvalho
70   * @author     Michael S. Onishi
71   * @created    27 de Junho de 2001
72   * @version    1.5 2006/09/12
73   */
74  
75  public class NetworkController implements KeyListener {
76  
77      private NetworkWindow screen;
78      private SingleEntityNetwork singleEntityNetwork;
79      
80      
81      private SENController senController;
82      
83      private BaseIO baseIO;
84      
85      // TODO ROMMEL - CHANGE THIS!! NEW MODELING!!
86      public IInferenceAlgorithm getInferenceAlgorithm() {
87      	if (senController != null) {
88      		return senController.getInferenceAlgorithm();
89      	}
90      	return null;
91  	}
92  
93  	public void setInferenceAlgorithm(IInferenceAlgorithm inferenceAlgorithm) {
94  		if (senController != null) {
95      		senController.setInferenceAlgorithm(inferenceAlgorithm);
96      	}
97  	}
98      
99  	/** Load resource file from this package */
100     private static ResourceBundle resource = unbbayes.util.ResourceController.newInstance().getBundle(
101     		unbbayes.controller.resources.ControllerResources.class.getName());
102     
103     
104     
105     /**
106      * This is the default constructor, initializing nothing.
107      * This is made protected in order to make it easier to extend.
108      */
109     protected NetworkController() {}
110     
111     
112 
113     /***************** BEGIN CONTROLLING SINGLE ENTTITY NETWORK *********************/
114     
115     /**
116      *  Constructs a controller for SingleEntityNetwork.
117      *
118      */
119     public NetworkController(SingleEntityNetwork singleEntityNetwork, NetworkWindow screen) {
120         this.singleEntityNetwork = singleEntityNetwork;
121         this.screen = screen;
122         this.senController = new SENController(singleEntityNetwork, screen);
123         this.setBaseIO(PluginAwareFileExtensionIODelegator.newInstance());
124     }
125     
126     public SENController getSENController(){
127     	return this.senController; 
128     }
129     
130     /**
131      *  Get the single entity network.
132      *
133      * @return The single entity network.
134      */
135     public SingleEntityNetwork getSingleEntityNetwork() {
136     	//TODO VERIFICAR SE POSSO RETIRAR ESSE M�TODO!!
137         return this.singleEntityNetwork;
138     }
139     
140     /**
141      * Get the network being controlled.
142      * @return The network being controlled.
143      */
144     public Network getNetwork() {
145     	return singleEntityNetwork;
146     }
147     
148     /**
149      * Obtains the network in a Graph format
150      * @return
151      */
152     public Graph getGraph(){
153     	return singleEntityNetwork;
154     }
155 
156     /**
157      * Initialize the junction tree beliefs.
158      */
159     public void initialize() {
160     	if (senController != null) senController.initialize();
161     }
162     
163     /**
164 	 * Creates and shows the panel to edit the node's table.
165 	 * @param node The table owner.
166 	 */
167 	public void createTable(Node node) {
168 		if (node == null) {
169 			return;
170 		}
171 		if (node.getType() == Node.CONTINUOUS_NODE_TYPE) {
172 			createContinuousDistribution((ContinuousNode)node);
173 		} else {
174 			createDiscreteTable(node);
175 		}
176 	}
177     
178 
179 	/**
180 	 * Creates and shows the panel where the user can edit the 
181 	 * continuous node normal distribution.
182 	 * @param node The continuous node to create the distribution pane for.
183 	 */
184 	public void createContinuousDistribution(ContinuousNode node) {
185 		if (senController != null) senController.createContinuousDistribution(node);
186 	}
187 	
188 	/**
189 	 * Creates and shows the panel where the user can edit the discrete 
190 	 * node table.
191 	 * @param node The discrete node to create the table pan for.
192 	 */
193 	public void createDiscreteTable(Node node) {
194 		if (senController != null) senController.createDiscreteTable(node);
195 	}
196 
197     /**
198      * Construct a potential table of the given node.
199      *
200      * @param node The node to get the data for the table.
201      */
202     public JTable makeTable(final Node node) {
203     	if (senController != null) return senController.makeTable(node);
204     	return null;
205     }
206 
207     /**
208      *  Propagate the evidences of the SingleEntityNetwork.
209      */
210     public void propagate() {
211     	if (senController != null) senController.propagate();
212     }
213 
214     /**
215      *  Compile the SingleEntityNetwork.
216      *
217      * @return True if it compiles with no error and false otherwise.
218      */
219     public boolean compileNetwork() {
220     	if (senController != null) return senController.compileNetwork();
221     	return false;
222     }
223     
224     /**
225      * Change the GUI to allow PN evaluation.
226      */
227     public void evaluateNetwork() {
228     	if (singleEntityNetwork != null && singleEntityNetwork instanceof ProbabilisticNetwork) {
229     		EvaluationController evaluationController = new EvaluationController((ProbabilisticNetwork)singleEntityNetwork);
230     		screen.changeToPNEvaluationPane(evaluationController.getView());
231     	} else {
232     		JOptionPane.showMessageDialog(screen, "Evaluation can only be done in probabilistic networks.", "Evaluation Error", JOptionPane.ERROR_MESSAGE);
233     	}
234     }
235 
236     /**
237      * Insert a new continuous node in the SingleEntityNetwork with 
238      * the standard label and description.
239      *
240      * @param x The x position of the new node.
241      * @param y The y position of the new node.
242      */
243     public Node insertContinuousNode(double x, double y) {
244     	if (senController != null) return senController.insertContinuousNode(x,y);
245     	return null;
246     }
247 
248     /**
249      * Insert a new probabilistic node in the SingleEntityNetwork with 
250      * the standard label and description.
251      *
252      * @param x The x position of the new node.
253      * @param y The y position of the new node.
254      */
255     public Node insertProbabilisticNode(double x, double y) {
256     	if (senController != null) return senController.insertProbabilisticNode(x,y);
257     	return null;
258     }
259 
260 
261     /**
262      * Insert a new decision node in the SingleEntityNetwork with
263      * the standard label and description.
264      *
265      * @param x The x position of the new node.
266      * @param y The y position of the new node.
267      */
268     public Node insertDecisionNode(double x, double y) {
269     	if (senController != null) return senController.insertDecisionNode(x, y);
270     	return null;
271     }
272 
273     /**
274      * Insert a new utility node in the SingleEntityNetwork with
275      * the standard label and description.
276      *
277      * @param x The x position of the new node.
278      * @param y The y position of the new node.
279      */
280     public Node insertUtilityNode(double x, double y) {
281     	if (senController != null) return senController.insertUtilityNode(x, y);
282     	return null;
283     }
284 
285     /**
286      * Show the explanation properties for the given node.
287      * @param node The node to show the explanation properties.
288      */
289     public void showExplanationProperties(ProbabilisticNode node) {
290     	if (senController != null) senController.showExplanationProperties(node);
291     }
292     
293     /***************** END CONTROLLING SINGLE ENTTITY NETWORK *********************/
294 
295     
296     /***************** BEGIN CONTROLLING BOTH *********************/
297     
298     /**
299      * Insert a new edge in the network.
300      *
301      * @param edge The new edge to be inserted.
302      */
303     public boolean insertEdge(Edge edge) throws Exception{
304     	if (senController != null) return senController.insertEdge(edge); 
305     	return false;
306     }
307     
308     /**
309      *  Insert a new state for the given node.
310      *
311      * @param node The selected node to insert the new state.
312      */
313     public void insertState(Node node) {
314     	if (senController != null) senController.insertState(node);
315     }
316 
317     /**
318      *  Remove the last state from the given node.
319      *
320      * @param node The selected node to remove the last state.
321      */
322     public void removeState(Node node) {
323     	if (senController != null) senController.removeState(node);
324     }
325 
326     /**
327      * Delete the selected object from the network.
328      * @param selected The selected object to delete.
329      */
330     //by young
331     public void deleteSelected(Object selected) {
332     	if (senController != null) senController.deleteSelected(selected);
333     }
334     
335     /***************** END CONTROLLING BOTH *********************/
336     
337     
338     
339     /****************** BEGIN KEY LISTENER METHODS *********************/
340     
341     /**
342      * It does nothing when a key is typed.
343      *
344      * @param e The <code>KeyEvent</code> that is passed from the <code>KeyListener</code>
345      * @see KeyEvent
346      * @see KeyListener
347      */
348     public void keyTyped(KeyEvent e) { }
349 
350 
351     /**
352      *  Delete all selected objects of the network when the key (KeyEvent.VK_DELETE) is
353      *  pressed.
354      *
355      * @param e The <code>KeyEvent</code> that is passed from the <code>KeyListener</code>
356      * @see KeyEvent
357      * @see KeyListener
358      */
359     public void keyPressed(KeyEvent e) {
360 
361     	//by young
362       /*  if (e.getKeyCode() == KeyEvent.VK_DELETE) {
363             Object selecionado = screen.getGraphPane().getSelected();
364             deleteSelected(selecionado);
365             
366             for (int i = 0; i < screen.getGraphPane().getSelectedGroup().size(); i++) {
367                 selecionado = screen.getGraphPane().getSelectedGroup().get(i);
368                 deleteSelected(selecionado);
369             }
370         }
371         screen.getGraphPane().update();*/
372     }
373     
374     /**
375      * It does nothing when a key is released.
376      *
377      * @param e The <code>KeyEvent</code> that is passed from the <code>KeyListener</code>
378      * @see KeyEvent
379      * @see KeyListener
380      */
381     public void keyReleased(KeyEvent e) {
382     }
383     
384     /****************** END KEY LISTENER METHODS *********************/
385     
386     /****************** BEGIN GENERIC METHODS *********************/
387     
388     /**
389      *  Get the network window.
390      *
391      * @return    The network window.
392      */
393     public NetworkWindow getScreen() {
394         return this.screen;
395     }
396 
397     /**
398      * Save the network image to a file.
399      */
400     public void saveNetImage() {
401         String images[] = { "PNG", "JPG", "GIF", "BMP" };
402         JFileChooser chooser = new JFileChooser(FileHistoryController.getInstance().getCurrentDirectory());
403         chooser.setMultiSelectionEnabled(false);
404 
405         chooser.setFileView(new FileIcon(screen));
406         chooser.addChoosableFileFilter(new SimpleFileFilter( images, resource.getString("imageFileFilter")));
407 
408         int opcao = chooser.showSaveDialog(screen);
409         if (opcao == JFileChooser.APPROVE_OPTION) {
410         	Rectangle r = calculateNetRectangle();
411         	Component comp = screen.getGraphPane().getGraphViewport();
412         	File file = new File(chooser.getSelectedFile().getPath());
413         	saveComponentAsImage(comp, r.width, r.height, file);
414         	FileHistoryController.getInstance().setCurrentDirectory(chooser.getCurrentDirectory());
415         }
416     }
417     
418     protected void saveComponentAsImage(Component comp, int width, int height, File file) {
419     	BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
420 
421         Graphics2D g2d = bufferedImage.createGraphics();
422 
423         comp.paint(g2d);
424         g2d.dispose();
425         RenderedImage rendImage = bufferedImage;
426         
427         boolean wrongName = false;
428 
429         String fileName = file.getName();
430         if (fileName.length() > 4) {
431         	String fileExt = fileName.substring(fileName.length() - 3);
432         	try {
433     	        if (fileExt.equalsIgnoreCase("png")) {
434     				ImageIO.write(rendImage, "png", file);
435     	        } else if (fileExt.equalsIgnoreCase("jpg")) {
436     	        	ImageIO.write(rendImage, "jpg", file);
437     	        } else if (fileExt.equalsIgnoreCase("gif")) {
438     	        	ImageIO.write(rendImage, "gif", file);
439     	        } else if (fileExt.equalsIgnoreCase("bmp")) {
440     	        	ImageIO.write(rendImage, "bmp", file);
441     	        } else {
442     	        	wrongName = true;
443     	        }
444     		} catch (IOException e1) {
445     			// TODO SHOW MESSAGE TO USER
446     			e1.printStackTrace();
447     		}
448         }  else {
449         	wrongName = true;
450         }
451         
452         if (wrongName) {
453         	// TODO SHOW MESSAGE TO USER
454         }
455         
456     }
457 
458     /**
459      * Save the table image to a file.
460      */
461     public void saveTableImage() {
462     	String images[] = { "PNG", "JPG", "GIF", "BMP" };
463         JFileChooser chooser = new JFileChooser(FileHistoryController.getInstance().getCurrentDirectory());
464         chooser.setMultiSelectionEnabled(false);
465 
466         chooser.setFileView(new FileIcon(screen));
467         chooser.addChoosableFileFilter(new SimpleFileFilter( images, resource.getString("imageFileFilter")));
468 
469         int opcao = chooser.showSaveDialog(screen);
470         if (opcao == JFileChooser.APPROVE_OPTION) {
471         	// TODO MAKE IT SHOW THE HEADER ALSO
472         	Component comp = screen.getTable();
473         	File file = new File(chooser.getSelectedFile().getPath());
474         	saveComponentAsImage(comp, comp.getWidth(), comp.getHeight(), file);
475         	FileHistoryController.getInstance().setCurrentDirectory(chooser.getCurrentDirectory());
476         }
477     }
478     
479     /**
480      * This method is called inside {@link #showLog()} to retrieve the 
481      * content of LOG. Extend this method in order to customize the log message
482      * (e.g. customize where the log content is stored, and how to retrieve it)
483      * @return a non null string. If {@link #singleEntityNetwork} is null, it returns
484      * an empty string.
485      */
486     protected String getLogContent() {
487     	if (singleEntityNetwork != null) {
488     		return singleEntityNetwork.getLog();
489     	}
490     	return "";
491     }
492     
493     /**
494      * This is just a delegator to {@link #getLogContent()},
495      * which is a delegator to {@link SingleEntityNetwork#getLog()}.
496      * The visibility of {@link #getLogContent()} was not altered, for
497      * backward compatibility.
498      * @return log content
499      */
500     public String getLog() {
501     	return this.getLogContent();
502     }
503 
504     /**
505      *  Show every single step taken during the compilation of the 
506      *  SingleEntityNetwork.
507      *  @deprecated avoid GUI methods in controllers. Use {@link unbbayes.gui.util.TextAreaDialog} instead
508      */
509     public JDialog showLog() {
510     	TextAreaDialog dialog = new TextAreaDialog(this.getScreen().getUnbbayesFrame(), false);
511         dialog.setTextContent(this.getLog());
512         return dialog; 
513     }
514 
515     /**
516      * Open Warning dialog.
517      * Currently, this is only a stub.
518      */
519     public void openWarningDialog(){
520     	System.out.println("Not implemented yet");
521     }
522     
523     /**
524      * Close current warning dialog.
525      * This is a stub yet.
526      */
527     public void closeWarningDialog(){
528     	System.out.println("Not implemented yet");
529     }
530     
531     
532     /**
533      * Preview the log printing.
534      * @deprecated moved to {@link unbbayes.gui.util.TextAreaDialog}
535      */
536     public void previewPrintLog(final JTextArea texto, final JDialog dialog) {
537         screen.setCursor(new Cursor(Cursor.WAIT_CURSOR));
538         Thread t = new Thread(new Runnable() {
539           public void run() {
540             PrintText it = new PrintText(texto,
541                 new PageFormat());
542             PrintPreviewer pp = new PrintPreviewer(
543                 it, 0);
544 
545             JDialog dlg = new JDialog(dialog,
546                 resource.getString("previewLogToolTip"));
547             dlg.getContentPane().add(pp);
548             dlg.setSize(640, 480);
549             dlg.setVisible(true);
550           }
551         });
552 
553         t.start();
554         screen.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
555     }
556 
557 
558     /**
559      * Preview the table printing.
560      */
561     public void previewPrintTable() {
562         screen.setCursor(new Cursor(Cursor.WAIT_CURSOR));
563         Thread t = new Thread(new Runnable() {
564           public void run() {
565             List<JTable> tabelas = new ArrayList<JTable>();
566             List<Object> donos = new ArrayList<Object>();
567             List temp = screen.getGraphPane().getSelectedGroup();
568             if (temp.size() == 0) {
569                tabelas.add(screen.getTable());
570                donos.add(screen.getTableOwner());
571             }  else {
572                 for (int i = 0; i< temp.size(); i++) {
573                     if (temp.get(i) instanceof Node) {
574                         donos.add(((Node)temp.get(i)).toString());
575                         tabelas.add(makeTable((Node)temp.get(i)));
576                     }
577                 }
578             }
579 
580             PrintTable tp = new PrintTable(tabelas, donos, new PageFormat());
581             PrintPreviewer pp = new PrintPreviewer(
582                 tp, 0);
583             JDialog dlg = new JDialog();
584             dlg.getContentPane().add(pp);
585             dlg.setSize(400, 300);
586             dlg.setVisible(true);
587           }
588         });
589         t.start();
590         screen.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
591     }
592 
593 
594     /**
595      * Preview the net printing.
596      */
597     public void previewPrintNet(final JComponent rede, final Rectangle retangulo) {
598         screen.setCursor(new Cursor(Cursor.WAIT_CURSOR));
599         Thread t = new Thread(new Runnable() {
600           public void run() {
601             String rotulo = JOptionPane.showInputDialog(screen, resource.getString("askTitle"), resource.getString("informationText"), JOptionPane.INFORMATION_MESSAGE);
602             if (rotulo == null) {
603                 rotulo = "";
604             }
605             PrintNet it = new PrintNet(rotulo, rede, retangulo, new PageFormat());
606             PrintPreviewer pp = new PrintPreviewer(
607                 it, 0);
608 
609             JDialog dlg = new JDialog();
610             dlg.getContentPane().add(pp);
611             dlg.setSize(640, 480);
612             dlg.setVisible(true);
613           }
614         });
615 
616         t.start();
617         screen.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
618     }
619 
620 
621     /**
622      * Print the given area of the given network.
623      *
624      * @param network A component representing the graphical 
625      * representation of the network to be printed.
626      * @param rectangle The area to be printed.
627      */
628     public void printNet(final JComponent network, final Rectangle rectangle) {
629         screen.setCursor(new Cursor(Cursor.WAIT_CURSOR));
630         Thread t = new Thread(new Runnable() {
631           public void run() {
632             String rotulo = JOptionPane.showInputDialog(screen, resource.getString("askTitle"), resource.getString("informationText"), JOptionPane.INFORMATION_MESSAGE);
633             if (rotulo == null) {
634                 rotulo = "";
635             }
636             PrintNet it = new PrintNet(rotulo, network, rectangle, new PageFormat());
637             PrintMonitor pm = new PrintMonitor(it);
638             try {
639               pm.performPrint(true);
640             } catch (PrinterException pe) {
641               JOptionPane.showMessageDialog(
642                   screen,
643                   resource.getString("printException") +
644                   pe.getMessage());
645             }
646           }
647         });
648         t.start();
649         screen.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
650     }
651 
652 
653     /**
654      * Print the table.
655      */
656     public void printTable() {
657         screen.setCursor(new Cursor(Cursor.WAIT_CURSOR));
658         Thread t = new Thread(new Runnable() {
659           public void run() {
660             List<JTable> tabelas = new ArrayList<JTable>();
661             List<Object> donos = new ArrayList<Object>();
662             List temp = screen.getGraphPane().getSelectedGroup();
663             if (temp.size() == 0) {
664                tabelas.add(screen.getTable());
665                donos.add(screen.getTableOwner());
666             }  else {
667                 for (int i = 0; i< temp.size(); i++) {
668                     if (temp.get(i) instanceof Node) {
669                         donos.add(((Node)temp.get(i)).toString());
670                         tabelas.add(makeTable((Node)temp.get(i)));
671                     }
672                 }
673             }
674             PrintTable impressora = new PrintTable(tabelas, donos, new PageFormat());
675             PrintMonitor pm = new PrintMonitor(impressora);
676             try {
677               pm.performPrint(true);
678             } catch (PrinterException pe) {
679               JOptionPane.showMessageDialog(
680                   screen,
681                   resource.getString("printException") +
682                   pe.getMessage());
683             }
684           }
685         });
686         t.start();
687         screen.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
688     }
689 
690 
691     /**
692      * Print the log contained in the given <code>JTextArea</code>.
693      *
694      * @param textArea The text area containing the log.
695      * @deprecated this method was moved to {@link unbbayes.gui.util.TextAreaDialog}
696      */
697     protected void printLog(final JTextArea textArea) {
698         Thread t = new Thread(new Runnable() {
699           public void run() {
700             PrintText it = new PrintText(textArea,
701                 new PageFormat());
702             PrintMonitor pm = new PrintMonitor(it);
703             try {
704               pm.performPrint(true);
705             } catch (PrinterException pe) {
706               JOptionPane.showMessageDialog(
707                   screen,
708                   resource.getString("printException") +
709                   pe.getMessage());
710             }
711           }
712         });
713         t.start();
714     }
715 
716     /**
717      * Method responsible for calculating the network border. If there are
718      * selected objects, the resulting rectangle consider only these objects.
719      * Otherwise, all objects from the network are considered.
720      */
721     public Rectangle calculateNetRectangle() {
722     	
723     	//by young
724     	/*
725     	ArrayList<Node> nos;
726         List vetorAux = screen.getGraphPane().getSelectedGroup();
727 
728         if (vetorAux.size() == 0) {
729             nos = new ArrayList<Node>();
730             for (int i = 0; i < singleEntityNetwork.getNodeCount(); i++) {
731             	nos.add(i, singleEntityNetwork.getNodeAt(i));
732             }
733         } else {
734             nos = new ArrayList<Node>();
735             for (int i = 0; i < vetorAux.size(); i++) {
736                 if (vetorAux.get(i) instanceof Node) {
737                     nos.add((Node)vetorAux.get(i));
738                 }
739             }
740         }
741         int maiorX = 0;
742         int menorX = Integer.MAX_VALUE;
743         int maiorY = 0;
744         int menorY = Integer.MAX_VALUE;
745         Node noAux;
746         Point2D pontoAux;
747         int xAux;
748         int yAux;
749         for (int i = 0; i < nos.size(); i++) {
750             noAux = (Node)nos.get(i);
751             pontoAux = noAux.getPosition();
752             xAux = (int)pontoAux.getX();
753             yAux = (int)pontoAux.getY();
754             if (xAux > maiorX) {
755                 maiorX = xAux;
756             }
757             if (xAux < menorX) {
758                 menorX = xAux;
759             }
760             if (yAux > maiorY) {
761                 maiorY = yAux;
762             }
763             if (yAux < menorY) {
764                 menorY = yAux;
765             }
766         }
767         //by young
768          
769         double nodeWidth = noAux.getWidth();
770         maiorX += nodeWidth;
771         maiorY += nodeWidth;
772         menorX -= nodeWidth;
773         menorY -= nodeWidth;
774         
775         return new Rectangle(menorX, menorY, maiorX - menorX, maiorY - menorY);*/
776     	
777     	return new Rectangle(0, 0, (int)screen.getGraphPane().getBiggestPoint().x, (int)screen.getGraphPane().getBiggestPoint().y);
778         
779         
780     }
781     
782     /**
783      * Returns the selected node.
784      * @return the selected node.
785      */
786     public Node getSelectedNode(){
787     	System.out.println("Node selection is currently only available for subclasses");
788     	return null;
789     }
790     
791     /**
792      * Selects a node
793      * @param node
794      */
795     public void selectNode(Node node){
796     	System.out.println("Node selection is currently only available for subclasses");
797     }
798     
799     /**
800      * Unselects all graphical elements
801      */
802     public void unselectAll(){
803     	System.out.println("Node selection is currently only available for subclasses");
804     }
805 
806 	/**
807 	 * This is the class responsible for storing the network controlled by this controller.
808 	 * {@link #setBaseIO(BaseIO)} must be set to a correct controller depending to what type of
809 	 * network this controller is dealing.
810 	 * @return the baseIO
811 	 */
812 	public BaseIO getBaseIO() {
813 		return baseIO;
814 	}
815 
816 	/**
817 	 * This is the class responsible for storing the network controlled by this controller.
818 	 * {@link #setBaseIO(BaseIO)} must be set to a correct controller depending to what type of
819 	 * network this controller is dealing.
820 	 * @param baseIO the baseIO to set
821 	 */
822 	public void setBaseIO(BaseIO baseIO) {
823 		this.baseIO = baseIO;
824 	}
825 
826 	/**
827 	 * @param screen the screen to set
828 	 */
829 	public void setScreen(NetworkWindow screen) {
830 		this.screen = screen;
831 	}
832     
833     /****************** END GENERIC METHODS *********************/
834 }