public DocumentAnalyzer()

in uimaj-tools/src/main/java/org/apache/uima/tools/docanalyzer/DocumentAnalyzer.java [274:571]


  public DocumentAnalyzer(String outputFileSelected, boolean interactiveDA, boolean jvucrbis) {
    super("Document Analyzer");
    prefsMed = new PrefsMediator();

    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // I don't think this should ever happen, but if it does just print
      // error and continue
      // with defalt look and feel
      System.err.println("Could not set look and feel: " + e.getMessage());
    }
    // UIManager.put("Panel.background",Color.WHITE);
    // Need to set other colors as well

    // Set frame icon image
    try {
      this.setIconImage(Images.getImage(Images.MICROSCOPE));
      // new
      // ImageIcon(getClass().getResource(FRAME_ICON_IMAGE)).getImage());
    } catch (IOException e) {
      System.err.println("Image could not be loaded: " + e.getMessage());
    }

    // create about dialog
    aboutDialog = new AboutDialog(this, "About Document Analyzer");
    this.outputFileSelected = outputFileSelected;
    this.interactive = interactiveDA;
    this.javaViewerUCRBisSelected = jvucrbis;

    // Creating Menu Bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    JMenu helpMenu = new JMenu("Help");

    // Menu Items
    JMenuItem aboutMenuItem = new JMenuItem("About");
    JMenuItem helpMenuItem = new JMenuItem("Help");
    JMenuItem exitMenuItem = new JMenuItem("Exit");

    // menuBar.add(Box.createHorizontalGlue());
    // ...create the rightmost menu...
    fileMenu.add(exitMenuItem);
    helpMenu.add(aboutMenuItem);
    helpMenu.add(helpMenuItem);
    menuBar.add(fileMenu);
    menuBar.add(helpMenu);

    // setResizable(false);

    // Labels to identify the text fields
    final Caption labelInputFile;
    final Caption labelInputFileFormat;
    final Caption labelOutputFile;
    final Caption labelXmlFile;
    final Caption labelRunParameters;
    final Caption labelLanguage;
    final Caption labelEncoding;

    // Strings for the labels
    final String inputString = "Input Directory: ";
    final String inputFileFormatString = "Input File Format: ";
    final String outputString = "Output Directory: ";
    final String xmlString = "Location of Analysis Engine XML Descriptor: ";
    final String runParametersString = "XML Tag containing Text (optional): ";

    // Create field label captions (right-aligned JLabel):

    labelInputFile = new Caption(inputString);

    labelInputFileFormat = new Caption(inputFileFormatString);

    labelOutputFile = new Caption(outputString);

    labelXmlFile = new Caption(xmlString);

    labelRunParameters = new Caption(runParametersString);

    labelLanguage = new Caption("Language: ");

    labelEncoding = new Caption("Character Encoding: ");

    JPanel controlPanel = new JPanel();
    controlPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    controlPanel.setLayout(new SpringLayout());

    // Once we add components to controlPanel, we'll
    // call SpringUtilities::makeCompactGrid on it.

    // controlPanel.setLayout(new GridLayout(4, 2, 8, 4));

    // Set default values for input fields
    outputDirectory = new File(prefsMed.getOutputDir());

    File browserRootDir = new File(System.getProperty("user.dir"));

    TfFocusListener tlf = new TfFocusListener(prefsMed);
    TfFileSelectorListener fsl = new TfFileSelectorListener(prefsMed);
    TfDocumentListener dl = new TfDocumentListener(prefsMed);
    inputFileSelector = new FileSelector(prefsMed.getInputDir(), "Input Directory",
            JFileChooser.DIRECTORIES_ONLY, browserRootDir);
    // inputFileSelector.addFocusListener(tlf);
    inputFileSelector.addFileSelectorListener(fsl);
    inputFileSelector.addDocumentListener(dl);

    // UIMA-2305.

    lenientCheckbox = new JCheckBox("Lenient deserialization");
    lenientCheckbox.setToolTipText(
            "Allow extra types and features in the input CAS, not defined by the annotator type system, to be ignored");
    lenientCheckbox.setSelected(prefsMed.getLenient());

    JPanel inputFileFormatPanel = new JPanel();

    inputFileFormatPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    inputFileFormatComboBox = new JComboBox(new Object[] { "text", "xmi", "xcas" });
    inputFileFormatComboBox.setEditable(false);
    inputFileFormatComboBox.setSelectedItem(prefsMed.getInputFileFormat());
    inputFileFormatComboBox.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        String inputFileFormat = (String) inputFileFormatComboBox.getSelectedItem();
        lenientCheckbox.setEnabled("xcas".equalsIgnoreCase(inputFileFormat)
                || "xmi".equalsIgnoreCase(inputFileFormat));
      }
    });

    String inputFileFormat = (String) inputFileFormatComboBox.getSelectedItem();
    lenientCheckbox.setEnabled(
            "xcas".equalsIgnoreCase(inputFileFormat) || "xmi".equalsIgnoreCase(inputFileFormat));

    inputFileFormatPanel.add(inputFileFormatComboBox);

    inputFileFormatPanel.add(lenientCheckbox);

    Map<String, Charset> charsetMap = Charset.availableCharsets();
    Set<String> charsets = charsetMap.keySet();
    String[] charsetArr = charsets.toArray(new String[charsets.size()]);
    encodingComboBox = new JComboBox(charsetArr);
    encodingComboBox.setEditable(false);
    encodingComboBox.setSelectedItem(prefsMed.getEncoding());

    JPanel displayEncodingFormatPanel = new JPanel();
    displayEncodingFormatPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    displayEncodingFormatPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    displayEncodingFormatPanel.add(labelEncoding);
    displayEncodingFormatPanel.add(encodingComboBox);

    inputFileFormatPanel.add(displayEncodingFormatPanel);

    outputFileSelector = new FileSelector(prefsMed.getOutputDir(), "Output Directory",
            JFileChooser.DIRECTORIES_ONLY, browserRootDir);
    // outputFileSelector.addFocusListener( tlf);
    outputFileSelector.addFileSelectorListener(fsl);
    outputFileSelector.addDocumentListener(dl);

    xmlFileSelector = new FileSelector(prefsMed.getTAEfile(), "Analysis Engine Descriptor XML file",
            JFileChooser.FILES_ONLY, browserRootDir);
    // xmlFileSelector.addFocusListener( tlf);
    xmlFileSelector.addFileSelectorListener(fsl);
    xmlFileSelector.addDocumentListener(dl);

    prefsMed.setFileSelectors(inputFileSelector, outputFileSelector, xmlFileSelector);
    runParametersField = new JTextField(16);
    runParametersField.setText(prefsMed.getXmlTag());

    JPanel runParametersPanel = new JPanel();
    runParametersPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2));
    runParametersPanel.add(runParametersField);

    languageComboBox = new JComboBox(new Object[] { "en", "de", "es", "fr", "it", "pt", "ja",
        "ko-kr", "pt-br", "zh-cn", "zh-tw", "x-unspecified" });
    languageComboBox.setEditable(true);
    languageComboBox.setSelectedItem(prefsMed.getLanguage());
    JPanel languagePanel = new JPanel();
    languagePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2));
    languagePanel.add(languageComboBox);

    controlPanel.add(labelInputFile);
    controlPanel.add(inputFileSelector);
    controlPanel.add(labelInputFileFormat);
    controlPanel.add(inputFileFormatPanel);
    controlPanel.add(labelOutputFile);
    controlPanel.add(outputFileSelector);
    controlPanel.add(labelXmlFile);
    controlPanel.add(xmlFileSelector);
    controlPanel.add(labelRunParameters);
    controlPanel.add(runParametersPanel);
    controlPanel.add(labelLanguage);
    controlPanel.add(languagePanel);

    SpringUtilities.makeCompactGrid(controlPanel, 6, 2, // rows, cols
            4, 4, // initX, initY
            4, 4); // xPad, yPad

    // Event Handlling of "Exit" Menu Item
    exitMenuItem.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent evt) {
        savePreferences();
        System.exit(0);
      }
    });

    // Event Handlling of "About" Menu Item
    aboutMenuItem.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent evt) {
        aboutDialog.setVisible(true);
      }
    });

    // Event Handlling of "Help" Menu Item
    helpMenuItem.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent evt) {
        JOptionPane.showMessageDialog(DocumentAnalyzer.this, HELP_MESSAGE, "Document Analyzer Help",
                JOptionPane.PLAIN_MESSAGE);
      }
    });

    // Add the panels to the frame
    Container contentPanel = getContentPane();
    contentPanel.setBackground(Color.WHITE);
    JLabel banner = new JLabel(Images.getImageIcon(Images.BANNER));
    contentPanel.add(banner, BorderLayout.NORTH);
    contentPanel.add(controlPanel, BorderLayout.CENTER);

    // contentPanel.add(parameterPane, BorderLayout.WEST);
    // Add the run Button to run AE
    runButton = new JButton("Run");
    runButton.setToolTipText("Runs Analysis Engine and displays results");
    // Add the interactive Button to run AE on entered text
    interButton = new JButton("Interactive");
    interButton.setToolTipText("Type in text to analyze");
    // add view button
    JButton viewButton = new JButton("View");
    // viewButton.setToolTipText( "View results of already processed data");
    viewButton.setDefaultCapable(true);
    viewButton.setRequestFocusEnabled(true);
    viewButton.requestFocus();
    viewButton.addFocusListener(tlf);

    // copy into the mediator
    prefsMed.setDocButtons(runButton, interButton, viewButton);
    // Add the run button to another panel
    JPanel lowerButtonsPanel = new JPanel();
    lowerButtonsPanel.add(runButton, BorderLayout.WEST);
    lowerButtonsPanel.add(interButton, BorderLayout.EAST);
    lowerButtonsPanel.add(viewButton, BorderLayout.EAST);
    lowerButtonsPanel.setFocusCycleRoot(true);

    contentPanel.add(lowerButtonsPanel, BorderLayout.SOUTH);
    setContentPane(contentPanel);

    // Event Handling of run Button
    runButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent ee) {
        interactive = false;
        savePreferences();
        analyzeDocuments(null); // JMP added arg
      }
    });

    // Event Handling of interactive Button
    interButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent ee) {
        if (outputFileSelector.getSelected().length() == 0)
          displayError("Need to specify an output directory for temporary results.");
        else {
          interactive = true;
          savePreferences();
          analyzeInputarea();
        }
      }
    });

    // event to display already processed data
    viewButton.addActionListener(this);
    // new ActionListener() {
    // }
    // );

    // load user preferences
    restorePreferences();

    progressTimer = new Timer(100, new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent ee) {
        checkProgressMonitor();
      }
    });
  }