View Javadoc
1 /*** 2 * MainFrame.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 08.01.2003 pko modification 9 * 10.12.2002 pko modification 10 * 22.01.2002 ctr modification 11 * 08.01.2002 ctr creation 12 * 13 * Copyright 2003 ELCA Informatique SA 14 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 15 * www.elca.ch 16 * 17 * This library is free software; you can redistribute it and/or 18 * modify it under the terms of the GNU Lesser General Public License 19 * as published by the Free Software Foundation; either version 2.1 of 20 * the License, or (at your option) any later version. 21 * 22 * This library is distributed in the hope that it will be useful, but 23 * WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 * Lesser General Public License for more details. 26 * 27 * You should have received a copy of the GNU Lesser General Public 28 * License along with this library; if not, write to the Free Software 29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 30 * USA 31 */ 32 33 package ch.elca.dependency.gui; 34 35 import ch.elca.dependency.core.*; 36 import ch.elca.dependency.util.*; 37 import ch.elca.dependency.util.gui.*; 38 import ch.elca.dependency.view.*; 39 import java.awt.*; 40 import java.awt.event.*; 41 import java.beans.PropertyVetoException; 42 import java.lang.Runtime; 43 import javax.swing.*; 44 import org.apache.log4j.Logger; 45 46 /*** 47 * The <code>MainFrame</code> class is responsible for the 48 * initialisation at the startup of the DependencyTool. The components 49 * of the MVC Pattern are registred in the corresponding order. After 50 * all the startup is performed, the Gui is started. This is the main 51 * user of the whole DependencyTool frame work. It holds the 52 * application together and is responsible for the initialisation of 53 * all its components. 54 * 55 * @see ch.elca.dependency.core.RawModel 56 * 57 * @author Christoph Trutmann 58 * @author Pawel Kowalski 59 * @version 1.0-beta 60 */ 61 public class MainFrame extends PersistentJFrame implements StatusListener { 62 63 private static final Logger LOG = Logger.getLogger(MainFrame.class); 64 private static final String FRAME_NAME = "Dependency Tool"; 65 private static final float s_verticalFactor = 0.97F; 66 private static final float s_horizontalFactor = 0.93F; 67 68 private DependencyModel m_dependencyModel = null; 69 private DependencyContext m_dependencyCtx = null; 70 71 private View[] m_views = null; 72 private FilterDialog m_filterDialog = null; 73 private ReportDialog m_reportDialog = null; 74 private DependencyDialog m_dependencyDialog = null; 75 private JDesktopPane m_desktopPane = null; 76 private JTextField m_statusField = null; 77 78 //****************************************************************************************/ 79 // static tool entry point 80 //****************************************************************************************/ 81 82 public static void execute(DependencyContext dependencyContext) throws Exception { 83 try { 84 new MainFrame(dependencyContext); 85 LOG.info("Dependency Tool initialized successfully"); 86 } catch (Exception e) { 87 LOG.error("Could not initalize Depencency Tool..." + e.getMessage()); 88 throw e; 89 } 90 } 91 92 //****************************************************************************************/ 93 // tool main class constuctor 94 //****************************************************************************************/ 95 96 /*** 97 * Creates a new <code>MainFrame</code> instance. 98 * 99 * @param dependencyContext a <code>DependencyContext</code> value 100 * @exception Exception if an error occurs 101 */ 102 public MainFrame(DependencyContext dependencyContext) throws Exception { 103 try { 104 105 m_dependencyCtx = dependencyContext; 106 107 // init dependency tool 108 // 109 initData(); 110 initViews(); 111 initFrame(); 112 113 setContentPane(createMainPane()); 114 setJMenuBar(createMenuBar()); 115 createDialogWindows(); 116 117 activateFrame(); 118 119 // the analysis of package dependencies occurs here 120 // 121 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 122 analyzeInput(); 123 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 124 125 } catch (Exception e) { 126 super.dispose(); 127 throw e; 128 } 129 } 130 131 //****************************************************************************************/ 132 // init methods 133 //****************************************************************************************/ 134 135 private void initData() { 136 137 // instanciate a DependencyModel 138 // 139 if (m_dependencyModel == null) { 140 m_dependencyModel = new DependencyModel(); 141 m_dependencyModel.setStatusListener(this); 142 } 143 144 m_dependencyModel.put(DependencyModel.MAIN_FRAME_KEY, this); 145 } 146 147 private void initViews() { 148 149 m_views = new View[] { new ClassDepView(m_dependencyModel), 150 new GraphView(m_dependencyModel), 151 new OverView(m_dependencyModel), 152 new PackageDepView(m_dependencyModel), 153 new StatisticView(m_dependencyModel) }; 154 155 for (int i = 0; i < m_views.length; i++) { 156 m_views[i].setStatusListener(this); 157 } 158 } 159 160 private void initFrame() throws Exception { 161 162 // terminate on close event 163 // 164 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 165 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 166 167 // title, icon, size and position 168 // 169 setTitle(FRAME_NAME + " :: " + m_dependencyCtx.get(DependencyContext.ROOT_FILE_KEY)); 170 setIconImage(IconGrabber.getImage("dpticon.png")); 171 172 Toolkit tollkit = Toolkit.getDefaultToolkit(); 173 int screenWidth = tollkit.getScreenSize().width; 174 int screenHeight = tollkit.getScreenSize().height; 175 int frameWidth = (int)(screenWidth * s_verticalFactor); 176 int frameHeight = (int)(screenHeight * s_horizontalFactor); 177 int locationX = (screenWidth - frameWidth) / 2; 178 int locationY = ((screenHeight - frameHeight) / 2) - 14; 179 180 setDefaultBounds(new Rectangle(locationX, locationY, frameWidth, frameHeight)); 181 recallConfig(); 182 } 183 184 //****************************************************************************************/ 185 // creators 186 //****************************************************************************************/ 187 188 private JPanel createMainPane() { 189 190 JPanel panel = new JPanel(); 191 panel.setLayout(new BorderLayout()); 192 193 panel.add(new JScrollPane(createDesktopPanel()), BorderLayout.CENTER); 194 panel.add(createStatusPanel(), BorderLayout.AFTER_LAST_LINE); 195 196 return panel; 197 } 198 199 private JDesktopPane createDesktopPanel() { 200 201 // desktop pane setup 202 // 203 m_desktopPane = new JDesktopPane(); 204 m_desktopPane.setDesktopManager(new SnappingDesktopManager()); 205 206 207 return m_desktopPane; 208 } 209 210 private JComponent createStatusPanel() { 211 212 // create the StatusPanel 213 // 214 JPanel panel = new JPanel(); 215 panel.setLayout(new BorderLayout()); 216 panel.add(getStatusField(), BorderLayout.CENTER); 217 218 return panel; 219 } 220 221 private JMenuBar createMenuBar() { 222 223 JMenuBar menuBar = new JMenuBar(); 224 225 // ============================= File Menu BEGIN 226 // 227 JMenu fileMenu = new JMenu("File"); 228 fileMenu.setMnemonic(KeyEvent.VK_F); 229 230 JMenuItem exitItem = new JMenuItem(new ExitAction()); 231 fileMenu.add(exitItem); 232 233 menuBar.add(fileMenu); 234 // 235 // ============================= File Menu END 236 237 // ============================= View Menu BEGIN 238 // 239 JMenu viewMenu = new JMenu("View"); 240 viewMenu.setMnemonic(KeyEvent.VK_V); 241 242 JCheckBoxMenuItem checkBoxMenuItem = null; 243 for (int i = 0; i < m_views.length; i++) { 244 checkBoxMenuItem = new JCheckBoxMenuItem(new ViewAction(m_views[i])); 245 m_views[i].addComponentListener(new MyComponentAdaper(checkBoxMenuItem)); 246 checkBoxMenuItem.setSelected(m_views[i].isVisible()); 247 viewMenu.add(checkBoxMenuItem); 248 } 249 menuBar.add(viewMenu); 250 // 251 // ============================= File Menu END 252 253 // ============================= Tools Menu BEGIN 254 // 255 JMenu toolMenu = new JMenu("Tools"); 256 toolMenu.setMnemonic(KeyEvent.VK_T); 257 258 // Filter MenuItem 259 // 260 JMenuItem filterItem = new JMenuItem(new FilterAction()); 261 toolMenu.add(filterItem); 262 263 // Report MenuItem 264 // 265 JMenuItem reportItem = new JMenuItem(new ReportAction()); 266 toolMenu.add(reportItem); 267 268 menuBar.add(toolMenu); 269 // 270 // ============================= Tools Menu END 271 272 // ============================= Help Menu BEGIN 273 // 274 JMenu helpMenu = new JMenu("Help"); 275 helpMenu.setMnemonic(KeyEvent.VK_H); 276 277 JMenuItem helpItem = new JMenuItem(new HelpAction()); 278 helpMenu.add(helpItem); 279 280 JMenuItem aboutItem = new JMenuItem(new AboutAction()); 281 helpMenu.add(aboutItem); 282 283 menuBar.add(helpMenu); 284 // 285 // ============================= Help Menu END 286 287 return menuBar; 288 } 289 290 private void createDialogWindows() { 291 m_filterDialog = new FilterDialog(this); 292 m_reportDialog = new ReportDialog(this); 293 } 294 295 //****************************************************************************************/ 296 // getters 297 //****************************************************************************************/ 298 299 private void activateFrame() { 300 setVisible(true); 301 toFront(); 302 validate(); 303 } 304 305 private void analyzeInput() throws Exception { 306 307 if (m_dependencyCtx.suffices()) { 308 m_dependencyModel.create(m_dependencyCtx); 309 310 for (int i = 0; i < m_views.length; i++) { 311 m_desktopPane.add(m_views[i]); 312 m_views[i].initData(m_dependencyModel); 313 } 314 315 m_dependencyModel.notifyObserver(); 316 } 317 } 318 319 private JTextField getStatusField() { 320 if (m_statusField == null) { 321 m_statusField = new JTextField(); 322 m_statusField.setFont(new Font("Arial", Font.BOLD, 18)); 323 m_statusField.setEditable(false); 324 m_statusField.setForeground(Color.black); 325 m_statusField.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder())); 326 m_statusField.setMargin(new Insets(5, 5, 5, 5)); 327 } 328 return m_statusField; 329 } 330 331 private void terminateTool() { 332 Shutdown.shutdown(); 333 } 334 335 //****************************************************************************************/ 336 // StatusListener implementation and helper methods 337 //****************************************************************************************/ 338 339 /*** 340 * Post a message in this Frame. 341 * 342 * @param message a <code>String</code> value 343 */ 344 public void postMessage(final String message) { 345 SwingUtilities.invokeLater(new Runnable() { 346 public void run() { 347 showStatusMessage(message); 348 } 349 }); 350 } 351 352 /*** 353 * Post an error in this Frame. 354 * 355 * @param errorMessage a <code>String</code> value 356 */ 357 public void postError(final String errorMessage) { 358 SwingUtilities.invokeLater(new Runnable() { 359 public void run() { 360 showStatusError(errorMessage); 361 } 362 }); 363 } 364 365 private void showStatusMessage(final String message) { 366 getStatusField().setForeground(Color.black); 367 getStatusField().setText(" " + message); 368 } 369 370 private void showStatusError(final String errorMessage) { 371 getStatusField().setForeground(Color.red); 372 getStatusField().setText(" " + errorMessage); 373 } 374 375 //****************************************************************************************/ 376 // overriden methods 377 //****************************************************************************************/ 378 379 /*** 380 * Overriden <code>processWindowEvent</code> method. 381 * 382 * @param e a <code>WindowEvent</code> value 383 */ 384 protected void processWindowEvent(WindowEvent e) { 385 super.processWindowEvent(e); 386 if (e.getID() == WindowEvent.WINDOW_CLOSING) { 387 terminateTool(); 388 } 389 } 390 391 //****************************************************************************************/ 392 // Adapters 393 //****************************************************************************************/ 394 395 class MyComponentAdaper extends ComponentAdapter { 396 private JCheckBoxMenuItem m_checkBoxMenuItem; 397 public MyComponentAdaper(JCheckBoxMenuItem checkBoxMenuItem) { 398 m_checkBoxMenuItem = checkBoxMenuItem; 399 } 400 public void componentHidden(ComponentEvent event) { 401 m_checkBoxMenuItem.setState(false); 402 } 403 public void componentShown(ComponentEvent event) { 404 m_checkBoxMenuItem.setState(true); 405 } 406 } 407 408 //****************************************************************************************/ 409 // Actions 410 //****************************************************************************************/ 411 412 class ViewAction extends AbstractAction { 413 private View m_view = null; 414 public ViewAction(View view) { 415 super(view.getTitle(), view.getFrameIcon()); 416 m_view = view; 417 } 418 public void actionPerformed(ActionEvent event) { 419 JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) event.getSource(); 420 if (checkBoxMenuItem.getState()) { 421 m_view.setVisible(true); 422 } else { 423 if (m_view.isIcon()) { 424 try { 425 m_view.setIcon(false); 426 } catch (PropertyVetoException e) { 427 ; 428 } 429 } 430 m_view.setVisible(false); 431 } 432 } 433 } 434 435 class FilterAction extends AbstractAction { 436 public FilterAction() { 437 super("Filter packages", IconGrabber.getIcon("null.png")); 438 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK)); 439 putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_F)); 440 } 441 public void actionPerformed(ActionEvent event) { 442 m_filterDialog.setVisible(true); 443 } 444 } 445 446 class ReportAction extends AbstractAction { 447 public ReportAction() { 448 super("Generate Report", IconGrabber.getIcon("null.png")); 449 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK)); 450 putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R)); 451 } 452 public void actionPerformed(ActionEvent event) { 453 m_reportDialog.setVisible(true); 454 } 455 } 456 457 class HelpAction extends AbstractAction { 458 public HelpAction() { 459 super("Dependency Tool Help", IconGrabber.getIcon("help.gif")); 460 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); 461 putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_H)); 462 } 463 public void actionPerformed(ActionEvent event) { 464 String docuPath = IOManager.getToolInstallationPath() + "html/UserManual.html"; 465 try { 466 LOG.debug("Using docu: " + docuPath); 467 Runtime.getRuntime().exec("cmd /c \"start " + docuPath + "\""); 468 } catch (Exception e) { 469 LOG.warn("Could not launch help: " + docuPath); 470 } 471 } 472 } 473 474 class AboutAction extends AbstractAction { 475 public AboutAction() { 476 super("About Dependency Tool", IconGrabber.getIcon("about.gif")); 477 } 478 public void actionPerformed(ActionEvent event) { 479 AboutDialog.showAboutDialog(MainFrame.this); 480 } 481 } 482 483 class ExitAction extends AbstractAction { 484 public ExitAction() { 485 super("Exit", IconGrabber.getIcon("null.png")); 486 } 487 public void actionPerformed(ActionEvent event) { 488 terminateTool(); 489 } 490 } 491 }

This page was automatically generated by Maven