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.gui;
22  
23  import java.awt.BorderLayout;
24  import java.awt.GridLayout;
25  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;
27  import java.util.ResourceBundle;
28  
29  import javax.swing.JButton;
30  import javax.swing.JPanel;
31  import javax.swing.JSplitPane;
32  import javax.swing.JToolBar;
33  
34  import unbbayes.controller.IconController;
35  import unbbayes.controller.NetworkController;
36  
37  
38  /**
39   * <p>Title: UnBBayes</p>
40   * <p>Description: </p>
41   * <p>Copyright: Copyright (c) 2001</p>
42   * <p>Company: UnB</p>
43   * @author Rommel Novaes Carvalho, Michael Onishi
44   * @version 1.0
45   */
46  
47  public class EditNet extends JPanel {
48  
49  	/** Serialization runtime version number */
50  	private static final long serialVersionUID = 0;		
51  	
52      private final NetworkWindow netWindow;
53  
54      private final NetworkController controller;
55      private final IconController iconController = IconController.getInstance();
56      private final JSplitPane centerPanel;
57  
58      private final JPanel topPanel;
59      private final JToolBar jtbEdition;
60  
61      private final JButton compile;
62      private final JButton arc;
63      private final JButton printNet;
64      private final JButton previewNet;
65      private final JButton saveNetImage;
66  
67      /** Load resource file from this package */
68      private static ResourceBundle resource = unbbayes.util.ResourceController.newInstance().getBundle(
69      		unbbayes.gui.resources.GuiResources.class.getName());
70  
71      public EditNet(NetworkWindow _netWindow,
72                              NetworkController _controller) {
73          super();
74          this.netWindow     = _netWindow;
75          this.controller    = _controller;
76          this.setLayout(new BorderLayout());
77  
78          topPanel    = new JPanel(new GridLayout(0,1));
79          jtbEdition  = new JToolBar();
80          centerPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
81          
82          // Create buttons used by nodeList toolbars
83  
84          compile           = new JButton(iconController.getCompileIcon());
85          arc               = new JButton(iconController.getEdgeIcon());
86          printNet          = new JButton(iconController.getPrintNetIcon());
87          previewNet        = new JButton(iconController.getPrintPreviewNetIcon());
88          saveNetImage      = new JButton(iconController.getSaveNetIcon());
89  
90          // Set tooltip for those buttons
91  
92          compile.setToolTipText(resource.getString("compileToolTip"));
93          arc.setToolTipText(resource.getString("arcToolTip"));
94          printNet.setToolTipText(resource.getString("printNetToolTip"));
95          previewNet.setToolTipText(resource.getString("previewNetToolTip"));
96          saveNetImage.setToolTipText(resource.getString("saveNetImageToolTip"));
97  
98          // By clicking the compile button, calls compilation method of the network and
99          // updates the toolbars
100 
101         compile.addActionListener(new ActionListener() {
102             public void actionPerformed(ActionEvent ae) {
103             	System.out.println("i came to edit net \n");
104                 if (! controller.compileNetwork()) {
105                     return;
106                 }
107                 netWindow.changeToPNCompilationPane();
108             }
109         });
110 
111         // by clicking the button arc, we set those boolean variables and states of the buttons.
112         
113         arc.addActionListener(new ActionListener() {
114             public void actionPerformed(ActionEvent ae) {
115                 //netWindow.getIGraph().setbSelect(false);
116                 //netWindow.getIGraph().setbArc(true);
117             	netWindow.getGraphPane().setAction(GraphAction.CREATE_EDGE);
118             }
119         });
120 
121         // action para imprimir a rede
122         printNet.addActionListener(new ActionListener() {
123             public void actionPerformed(ActionEvent ae) {
124                 controller.printNet(netWindow.getGraphPane(), controller.calculateNetRectangle());
125             }
126         });
127 
128         // action para visualizar a rede.
129         previewNet.addActionListener(new ActionListener() {
130             public void actionPerformed(ActionEvent ae) {
131                 controller.previewPrintNet(netWindow.getGraphPane(), controller.calculateNetRectangle());
132             }
133         });
134 
135 
136         saveNetImage.addActionListener(new ActionListener() {
137             public void actionPerformed(ActionEvent e) {
138                 controller.saveNetImage();
139             }
140         });
141 
142         // Puts buttons and controllers of look-and-feel into toolbar and this is for topPanel.
143         
144         jtbEdition.add(printNet);
145         jtbEdition.add(previewNet);
146         jtbEdition.add(saveNetImage);
147 
148         jtbEdition.addSeparator();
149 
150         jtbEdition.add(arc);
151         jtbEdition.add(compile);
152 
153         topPanel.add(jtbEdition);
154 
155         //setar os tamanho de cada jsp(tabela e graph) para os seus PreferredSizes
156         centerPanel.resetToPreferredSizes();
157 
158         //adiciona containers para o contentPane
159         this.add(topPanel, BorderLayout.NORTH);
160         this.add(centerPanel, BorderLayout.CENTER);
161         setVisible(true);
162 
163     }
164 
165     /**
166      *  Retorna o painel do centro onde fica o graph e a table.
167      *
168      *@return    retorna o centerPanel (<code>JSplitPane</code>)
169      *@see       JSplitPane
170      */
171     public JSplitPane getCenterPanel() {
172       return this.centerPanel;
173     }
174 
175     public JButton getArc() {
176         return this.arc;
177     }
178 
179     public JButton getCompile() {
180         return this.compile;
181     }
182 
183     public JButton getPreviewNet() {
184         return this.previewNet;
185     }
186 
187     public JButton getPrintNet() {
188         return this.printNet;
189     }
190 
191     public JButton getSaveNetImage() {
192         return this.saveNetImage;
193     }
194 }