Beispiel #1
0
  /** Enable or disable menu in accordance with contents of current check-list */
  public void updateButtons() {
    int nbRows = getStepNumber();
    int indexSelected = tabbedPane.getSelectedIndex();
    if (indexSelected < 0 || indexSelected >= analysisPlugins.size()) {
      return;
    }
    AnalysisGUICommon guiCommonSelected = getSelectedAnalysisPane();
    int nbRowCurrentTabSelected = guiCommonSelected.getCheckListTable().getSelectedRowCount();
    int nbRowCurrentTab = guiCommonSelected.getCheckListTable().getStepNumber();
    boolean copiedRow = guiCommonSelected.hasCopiedRow();

    if (nbRows == 0) {
      MatosAction.SAVEALLALL.setEnabled(false);
      MatosAction.SAVEAS.setEnabled(false);
      MatosAction.SAVESELECTIONAS.setEnabled(false);
      MatosAction.NEWCHECKLIST.setEnabled(false);
      MatosAction.COPY.setEnabled(false);
      MatosAction.PASTE.setEnabled(false);
      MatosAction.REMOVE.setEnabled(false);
      MatosAction.PROPERTIES.setEnabled(false);
      MatosAction.VIEWREPORT.setEnabled(false);
      MatosAction.SELECTALLALL.setEnabled(false);
      MatosAction.UNSELECTALLALL.setEnabled(false);

      MatosAction.ANALYSEALLCURRENTTAB.setEnabled(false);
      MatosAction.ANALYSESELECTIONCURRENTTAB.setEnabled(false);
      MatosAction.ANALYSEALLALLTAB.setEnabled(false);
      MatosAction.ANALYSESELECTIONALLTAB.setEnabled(false);
      MatosAction.CONFIRMVERDICT.setEnabled(false);
      MatosAction.MODIFYVERDICT.setEnabled(false);
      MatosAction.STATISTICSALL.setEnabled(false);

    } else /*if (nbRows > 0)*/ {
      MatosAction.NEWCHECKLIST.setEnabled(true);
      MatosAction.SAVEALLALL.setEnabled(isModified());
      MatosAction.SAVEAS.setEnabled(true);
      MatosAction.SELECTALLALL.setEnabled(true);
      MatosAction.UNSELECTALLALL.setEnabled(true);

      MatosAction.ANALYSEALLCURRENTTAB.setEnabled(nbRowCurrentTab > 0);
      MatosAction.ANALYSEALLALLTAB.setEnabled(true);
      MatosAction.ANALYSESELECTIONALLTAB.setEnabled(true);
      MatosAction.STATISTICSALL.setEnabled(true);

      if (nbRowCurrentTabSelected > 0) {
        MatosAction.SAVESELECTIONAS.setEnabled(true);
        MatosAction.COPY.setEnabled(true);
        if (copiedRow) {
          MatosAction.PASTE.setEnabled(true);
        } else {
          MatosAction.REMOVE.setEnabled(false);
        }
        MatosAction.REMOVE.setEnabled(true);

        MatosAction.PROPERTIES.setEnabled(nbRowCurrentTabSelected == 1);
        MatosAction.CONFIRMVERDICT.setEnabled(nbRowCurrentTabSelected == 1);
        MatosAction.MODIFYVERDICT.setEnabled(nbRowCurrentTabSelected == 1);

        MatosAction.ANALYSESELECTIONCURRENTTAB.setEnabled(true);
        // MatosAction.VIEWREPORT.setEnabled(true);
      } else {
        MatosAction.SAVESELECTIONAS.setEnabled(false);
        MatosAction.COPY.setEnabled(false);
        MatosAction.PASTE.setEnabled(false);
        MatosAction.REMOVE.setEnabled(false);
        MatosAction.ANALYSESELECTIONCURRENTTAB.setEnabled(false);
        MatosAction.VIEWREPORT.setEnabled(false);
        MatosAction.PROPERTIES.setEnabled(false);
        MatosAction.CONFIRMVERDICT.setEnabled(false);
        MatosAction.MODIFYVERDICT.setEnabled(false);
      }
    }

    // selected analisys tab hav to to so
    guiCommonSelected.updateButtons();

    // no analysis GUI plugins have to do so...
    for (IGUICommon guiCommon : othersPlugins /*CoreGUIPlugin.guiCommons*/) {
      guiCommon.updateButtons();
    }
  }
Beispiel #2
0
  /**
   * Create components and show the user interface
   *
   * @throws Exception
   */
  public void createAndShowGUI() throws Exception {

    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout());

    menuBar = new JMenuBar();
    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            // int selected = tabbedPane.getSelectedIndex();
            Component selectedComp = tabbedPane.getSelectedComponent();
            for (IGUICommon plugin : allPlugins) {
              JPanel panel = plugin.getMainPanel();
              if ((panel != null) && (panel.equals(selectedComp))) {
                plugin.notifySelected();
                if (CoreGUIPlugin.mainFrame != null) CoreGUIPlugin.mainFrame.updateButtons();
              }
            }
            //				MatosGUI.this.getSelectedAnalysisPane();
            //				if ((selected>0)&&(selected<MatosGUI.analysisPlugins.size())) {
            //					IGUICommon selectedTab = MatosGUI.analysisPlugins.get(selected);
            //					selectedTab.notifySelected();
            //				} else {
            //					IGUICommon selectedTab = MatosGUI.othersPlugins.get(selected);
            //					selectedTab.notifySelected();
            //				}
          }
        });
    analysisPlugins = new ArrayList<AnalysisGUICommon>();
    othersPlugins = new ArrayList<IGUICommon>();
    allPlugins = new ArrayList<IGUICommon>();
    int nbAnalysisPlugins = 0;
    for (IGUICommon guiCommon : CoreGUIPlugin.guiCommons) {
      if (guiCommon instanceof AnalysisGUICommon) {
        nbAnalysisPlugins++;
        analysisPlugins.add((AnalysisGUICommon) guiCommon);
        // Add to the campaign list
        Campaign.campaignsList.add(
            ((AnalysisGUICommon) guiCommon).getCheckListTable().getCampaign());
      } else {
        othersPlugins.add(guiCommon);
      }
      allPlugins.add(guiCommon);
    }

    JMenuItem itemNew = MatosAction.NEWCHECKLIST.getAsMenuItem("New");
    JMenuItem itemOpen = MatosAction.OPEN.getAsMenuItem("Open...");
    JMenuItem itemSave = MatosAction.SAVEALLALL.getAsMenuItem("Save");
    JMenuItem itemSaveAs = MatosAction.SAVEAS.getAsMenuItem("Save as...");
    JMenuItem itemSaveSelectionAs =
        MatosAction.SAVESELECTIONAS.getAsMenuItem("Save selection as...");

    // handla analysis plugins
    JMenu itemAddFile = new JMenu("Add file to analyse");
    for (AnalysisGUICommon guiCommon : analysisPlugins) {
      JMenuItem itemAddFilePlugin = guiCommon.getAddStepMenuItem();
      if (itemAddFilePlugin != null) {
        itemAddFile.add(itemAddFilePlugin);
      }
    }

    JMenuItem itemDirectory = MatosAction.ADDDIR.getAction().getAsMenuItem("Add directory...");
    JMenuItem itemCheckList =
        MatosAction.ADDCHECKLIST.getAction().getAsMenuItem("Add check-list...");
    JMenuItem itemQuit = MatosAction.EXIT.getAction().getAsMenuItem("Exit");

    JMenu menuFile = new JMenu("File");
    menuFile.add(itemNew);
    menuFile.add(new JSeparator());
    menuFile.add(itemOpen);
    menuFile.add(itemSave);
    menuFile.add(itemSaveAs);
    menuFile.add(itemSaveSelectionAs);
    menuFile.add(new JSeparator());
    menuFile.add(itemAddFile);
    menuFile.add(itemDirectory);
    menuFile.add(itemCheckList);
    menuFile.add(new JSeparator());

    // handle other plugins in File menu
    //		ArrayList<IGUICommon> nonAnalysisPlugins = new ArrayList<IGUICommon>();
    //		nonAnalysisPlugins.addAll(CoreGUIPlugin.guiCommons);
    //		nonAnalysisPlugins.removeAll(analysisPlugin);
    int nbSubMenu = 0;
    for (IGUICommon gui : othersPlugins) {
      JMenuItem item = gui.getFileMenuItem();
      if (item != null) {
        menuFile.add(item);
        nbSubMenu++;
      }
    }
    if (nbSubMenu > 0) {
      menuFile.add(new JSeparator());
    }
    menuFile.add(itemQuit);

    menuBar.add(menuFile);

    JMenuItem itemSelectAll = MatosAction.SELECTALLALL.getAsMenuItem("Select all");
    JMenuItem itemUnselectAll = MatosAction.UNSELECTALLALL.getAsMenuItem("Unselect all");
    JMenuItem itemCopy = MatosAction.COPY.getAsMenuItem("Copy");
    JMenuItem itemPaste = MatosAction.PASTE.getAsMenuItem("Paste under");
    JMenuItem itemRemove = MatosAction.REMOVE.getAsMenuItem("Remove");
    JMenuItem itemProperties = MatosAction.PROPERTIES.getAsMenuItem("Properties...");
    JMenuItem itemConfiguration = MatosAction.CONFIGURATION.getAsMenuItem("Configuration...");

    JMenu menuEdit = new JMenu("Edit");
    menuEdit.add(itemSelectAll);
    menuEdit.add(itemUnselectAll);
    menuEdit.add(new JSeparator());
    menuEdit.add(itemCopy);
    menuEdit.add(itemPaste);
    menuEdit.add(itemRemove);
    menuEdit.add(new JSeparator());
    menuEdit.add(itemProperties);
    menuEdit.add(itemConfiguration);

    menuBar.add(menuEdit);

    JMenu menuTools = new JMenu("Tools");
    menuTools.add(MatosAction.VIEWREPORT.getAsMenuItem("View latest report"));
    menuTools.add(new JSeparator());

    // add analysis menus according to plugins
    if (nbAnalysisPlugins > 1) { // need sub-menus
      JMenu analyseAllSubMenu = new JMenu("Analyse all");
      JMenuItem itemAnalyseAllAll =
          MatosAction.ANALYSEALLALLTAB.getAsMenuItem("All"); /*"analyseAllAll"*/
      analyseAllSubMenu.add(itemAnalyseAllAll);
      JMenu analyseSelectionSubMenu = new JMenu("Analyse selection");
      JMenuItem itemAnalyseSelAllAll =
          MatosAction.ANALYSESELECTIONALLTAB.getAsMenuItem("All"); /*"analyseSelectionAll"*/
      analyseSelectionSubMenu.add(itemAnalyseSelAllAll);

      for (AnalysisGUICommon guiCommon : analysisPlugins) {
        JMenuItem analyseAllItem = guiCommon.getAnalyseAllMenuItem();
        if (analyseAllItem != null) {
          analyseAllSubMenu.add(analyseAllItem);
        }
        JMenuItem analyseSelectionItem = guiCommon.getAnalyseSelectionMenuItem();
        if (analyseSelectionItem != null) {
          analyseSelectionSubMenu.add(analyseSelectionItem);
        }
      }

      menuTools.add(analyseAllSubMenu);
      menuTools.add(analyseSelectionSubMenu);
    } else { // no need sub-menu
      JMenuItem itemAnalyseAll = MatosAction.ANALYSEALLALLTAB.getAsMenuItem("Analyse all");
      menuTools.add(itemAnalyseAll);
      JMenuItem itemAnalyseSelection =
          MatosAction.ANALYSESELECTIONALLTAB.getAsMenuItem("Analyse selection");
      menuTools.add(itemAnalyseSelection);
    }

    menuTools.add(new JSeparator());
    // menuTools.add(MatosAction.CONFIRMVERDICT.getAsMenuItem("Confirm the verdict"));
    // menuTools.add( MatosAction.MODIFYVERDICT.getAsMenuItem("Modify the verdict"));
    menuTools.add(new JSeparator());
    menuTools.add(MatosAction.STATISTICSALL.getAsMenuItem("View statistics"));
    menuTools.add(new JSeparator());
    menuTools.add(MatosAction.VIEWLOG.getAsMenuItem("Open log file"));

    // handle other plugins in Tools menu
    nbSubMenu = 0;
    for (IGUICommon gui : othersPlugins) {
      JMenuItem item = gui.getToolsMenuItem();
      if (item != null) {
        menuTools.add(item);
        nbSubMenu++;
      }
    }
    //		if (nbSubMenu>0) {
    //			menuFile.add(new JSeparator());
    //		}

    menuBar.add(menuTools);

    // add tabbed panes of analysis plugins
    for (AnalysisGUICommon guiCommon : analysisPlugins) {
      JPanel mainPanel = guiCommon.getMainPanel();
      if (guiCommon.getDisplayName() != null && mainPanel != null) {
        tabbedPane.addTab(guiCommon.getDisplayName(), mainPanel);
      }
    }

    // add tabbed panes of others plugins
    for (IGUICommon gui : othersPlugins) {
      JPanel mainPanel = gui.getMainPanel();
      if (gui.getDisplayName() != null && mainPanel != null) {
        tabbedPane.addTab(gui.getDisplayName(), mainPanel);
      }
    }

    JMenuItem aboutItem = MatosAction.ABOUT.getAsMenuItem("About...");
    JMenuItem userGuideItem = MatosAction.USERGUIDE.getAsMenuItem("ATK User Guide");

    JMenu menuHelp = new JMenu("Help");
    menuHelp.add(aboutItem);
    menuHelp.add(userGuideItem);

    // add help menu at rightmost
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(menuHelp);

    statusBar = new StatusBar("");

    // building the tool bar
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.add(MatosAction.NEWCHECKLIST.getAsJButton());
    toolBar.add(MatosAction.OPEN.getAsJButton());
    toolBar.add(MatosAction.ADDDIR.getAsJButton());
    toolBar.add(MatosAction.SAVEALLALL.getAsJButton());
    toolBar.add(MatosAction.SAVEAS.getAsJButton());
    toolBar.addSeparator();
    toolBar.add(MatosAction.COPY.getAsJButton());
    toolBar.add(MatosAction.PASTE.getAsJButton());
    toolBar.add(MatosAction.REMOVE.getAsJButton());
    toolBar.addSeparator();
    toolBar.add(MatosAction.OPENRECORDER.getAsJButton());

    toolBar.addSeparator();
    toolBar.add(MatosAction.MONITOR.getAsJButton());

    // adds an Exit nutton at rigthmost
    toolBar.add(Box.createHorizontalGlue());
    phoneStatusButton = new JPhoneStatusButton();
    toolBar.add(phoneStatusButton);

    toolBar.add(MatosAction.EXIT.getAsJButton());

    JPanel upperBars = new JPanel();
    upperBars.setLayout(new BorderLayout());
    upperBars.add(menuBar, BorderLayout.NORTH);
    upperBars.add(toolBar, BorderLayout.CENTER);
    pane.add(upperBars, BorderLayout.NORTH);
    pane.add(tabbedPane, BorderLayout.CENTER);
    pane.add(statusBar, BorderLayout.SOUTH);
    add(pane, BorderLayout.CENTER);

    // Graphics stuff
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    GraphicsConfiguration[] gc = gs[0].getConfigurations();
    Rectangle bounds = gc[0].getBounds();
    int width = 800;
    int height = 600;
    locationX = bounds.x + (bounds.width - width) / 2;
    locationY = bounds.y + (bounds.height - height) / 2;
    // remember last dimension & location
    width = Integer.valueOf(Configuration.getProperty(Configuration.GUI_WIDTH, "" + width));
    height = Integer.valueOf(Configuration.getProperty(Configuration.GUI_HEIGTH, "" + height));
    locationX =
        Integer.valueOf(Configuration.getProperty(Configuration.GUI_LOCATION_X, "" + locationX));
    locationY =
        Integer.valueOf(Configuration.getProperty(Configuration.GUI_LOCATION_Y, "" + locationY));

    setSize(width, height);
    setLocation(locationX, locationY);
    addWindowListener(
        new WindowAdapter() {

          /* (non-Javadoc)
           * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
           */
          @Override
          public void windowClosing(WindowEvent e) {
            AutomaticPhoneDetection.getInstance().stopDetection(phoneStatusButton);
            ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), MatosAction.EXIT.getName());
            MatosAction.EXIT.getAction().actionPerformed(ae);
            dispose();
          }
        });
    // hide splash
    URL iconURL = CoreGUIPlugin.getMainIcon();
    icon = new ImageIcon(iconURL, icondescr);
    setIconImage(icon.getImage());
    updateButtons();
    setTitle(baseTitle);
    // show this frame
    setVisible(true);
    statusBar.uiPostInit();
  }