Search in sources :

Example 6 with XJTable

use of gate.swing.XJTable in project gate-core by GateNLP.

the class CorpusQualityAssurance method initGuiComponents.

protected void initGuiComponents() {
    setLayout(new BorderLayout());
    JPanel sidePanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // toolbar
    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);
    toolbar.add(openDocumentAction = new OpenDocumentAction());
    openDocumentAction.setEnabled(false);
    toolbar.add(openAnnotationDiffAction = new OpenAnnotationDiffAction());
    openAnnotationDiffAction.setEnabled(false);
    toolbar.add(exportToHtmlAction = new ExportToHtmlAction());
    toolbar.add(reloadCacheAction = new ReloadCacheAction());
    toolbar.add(new HelpAction());
    gbc.anchor = GridBagConstraints.NORTHWEST;
    sidePanel.add(toolbar, gbc);
    gbc.anchor = GridBagConstraints.NORTH;
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // annotation sets list
    JLabel label = new JLabel("Annotation Sets A/Key & B/Response");
    label.setToolTipText("aka 'Key & Response sets'");
    gbc.fill = GridBagConstraints.BOTH;
    sidePanel.add(label, gbc);
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    setList = new JList();
    setList.setSelectionModel(new ToggleSelectionABModel(setList));
    setList.setPrototypeCellValue("present in every document");
    setList.setVisibleRowCount(4);
    gbc.weighty = 1;
    sidePanel.add(new JScrollPane(setList), gbc);
    gbc.weighty = 0;
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    setCheck = new JCheckBox("present in every document", false);
    setCheck.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateSetList();
        }
    });
    sidePanel.add(setCheck, gbc);
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // annotation types list
    label = new JLabel("Annotation Types");
    label.setToolTipText("Annotation types to compare");
    sidePanel.add(label, gbc);
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    typeList = new JList();
    typeList.setSelectionModel(new ToggleSelectionModel());
    typeList.setPrototypeCellValue("present in every document");
    typeList.setVisibleRowCount(4);
    gbc.weighty = 1;
    sidePanel.add(new JScrollPane(typeList), gbc);
    gbc.weighty = 0;
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    typeCheck = new JCheckBox("present in every selected set", false);
    typeCheck.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setList.getListSelectionListeners()[0].valueChanged(null);
        }
    });
    sidePanel.add(typeCheck, gbc);
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // annotation features list
    label = new JLabel("Annotation Features");
    label.setToolTipText("Annotation features to compare");
    sidePanel.add(label, gbc);
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    featureList = new JList();
    featureList.setSelectionModel(new ToggleSelectionModel());
    featureList.setPrototypeCellValue("present in every document");
    featureList.setVisibleRowCount(4);
    gbc.weighty = 1;
    sidePanel.add(new JScrollPane(featureList), gbc);
    gbc.weighty = 0;
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    featureCheck = new JCheckBox("present in every selected type", false);
    featureCheck.addActionListener(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            typeList.getListSelectionListeners()[0].valueChanged(null);
        }
    });
    sidePanel.add(featureCheck, gbc);
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // measures tabbed panes
    label = new JLabel("Measures");
    label.setToolTipText("Measures used to compare annotations");
    optionsButton = new JToggleButton("Options");
    optionsButton.setMargin(new Insets(1, 1, 1, 1));
    JPanel labelButtonPanel = new JPanel(new BorderLayout());
    labelButtonPanel.add(label, BorderLayout.WEST);
    labelButtonPanel.add(optionsButton, BorderLayout.EAST);
    sidePanel.add(labelButtonPanel, gbc);
    sidePanel.add(Box.createVerticalStrut(2), gbc);
    final JScrollPane measureScrollPane = new JScrollPane();
    measureList = new JList();
    measureList.setSelectionModel(new ToggleSelectionModel());
    String prefix = getClass().getName() + '.';
    double beta = (userConfig.getDouble(prefix + "fscorebeta") == null) ? 1.0 : userConfig.getDouble(prefix + "fscorebeta");
    double beta2 = (userConfig.getDouble(prefix + "fscorebeta2") == null) ? 0.5 : userConfig.getDouble(prefix + "fscorebeta2");
    String fscore = "F" + beta + "-score ";
    String fscore2 = "F" + beta2 + "-score ";
    measureList.setModel(new ExtendedListModel(new String[] { fscore + "strict", fscore + "lenient", fscore + "average", fscore + "strict BDM", fscore + "lenient BDM", fscore + "average BDM", fscore2 + "strict", fscore2 + "lenient", fscore2 + "average", fscore2 + "strict BDM", fscore2 + "lenient BDM", fscore2 + "average BDM" }));
    measureList.setPrototypeCellValue("present in every document");
    measureList.setVisibleRowCount(4);
    measureScrollPane.setViewportView(measureList);
    final JScrollPane measure2ScrollPane = new JScrollPane();
    measure2List = new JList();
    measure2List.setSelectionModel(new ToggleSelectionModel());
    measure2List.setModel(new ExtendedListModel(new String[] { "Observed agreement", "Cohen's Kappa", "Pi's Kappa" }));
    measure2List.setPrototypeCellValue("present in every document");
    measure2List.setVisibleRowCount(4);
    measure2ScrollPane.setViewportView(measure2List);
    measureTabbedPane = new JTabbedPane();
    measureTabbedPane.addTab("F-Score", null, measureScrollPane, "Inter-annotator agreement");
    measureTabbedPane.addTab("Classification", null, measure2ScrollPane, "Classification agreement");
    gbc.weighty = 1;
    sidePanel.add(measureTabbedPane, gbc);
    gbc.weighty = 0;
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    sidePanel.add(Box.createVerticalGlue(), gbc);
    // options panel for fscore measures
    final JPanel measureOptionsPanel = new JPanel();
    measureOptionsPanel.setLayout(new BoxLayout(measureOptionsPanel, BoxLayout.Y_AXIS));
    JPanel betaPanel = new JPanel();
    betaPanel.setLayout(new BoxLayout(betaPanel, BoxLayout.X_AXIS));
    JLabel betaLabel = new JLabel("Fscore Beta 1:");
    final JSpinner betaSpinner = new JSpinner(new SpinnerNumberModel(beta, 0, 1, 0.1));
    betaSpinner.setToolTipText("<html>Relative weight of precision and recall." + "<ul><li>1 weights equally precision and recall" + "<li>0.5 weights precision twice as much as recall" + "<li>2 weights recall twice as much as precision</ul></html>");
    betaPanel.add(betaLabel);
    betaPanel.add(Box.createHorizontalStrut(5));
    betaPanel.add(betaSpinner);
    betaPanel.add(Box.createHorizontalGlue());
    measureOptionsPanel.add(betaPanel);
    betaSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, Math.round(betaLabel.getPreferredSize().height * 1.5f)));
    JPanel beta2Panel = new JPanel();
    beta2Panel.setLayout(new BoxLayout(beta2Panel, BoxLayout.X_AXIS));
    JLabel beta2Label = new JLabel("Fscore Beta 2:");
    final JSpinner beta2Spinner = new JSpinner(new SpinnerNumberModel(beta2, 0, 1, 0.1));
    beta2Spinner.setToolTipText(betaSpinner.getToolTipText());
    beta2Panel.add(beta2Label);
    beta2Panel.add(Box.createHorizontalStrut(5));
    beta2Panel.add(beta2Spinner);
    beta2Panel.add(Box.createHorizontalGlue());
    measureOptionsPanel.add(beta2Panel);
    beta2Spinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, Math.round(beta2Label.getPreferredSize().height * 1.5f)));
    JPanel bdmFilePanel = new JPanel();
    bdmFilePanel.setLayout(new BoxLayout(bdmFilePanel, BoxLayout.X_AXIS));
    JLabel bdmFileLabel = new JLabel("BDM file:");
    JButton bdmFileButton = new JButton(new SetBdmFileAction());
    bdmFilePanel.add(bdmFileLabel);
    bdmFilePanel.add(Box.createHorizontalStrut(5));
    bdmFilePanel.add(bdmFileButton);
    bdmFilePanel.add(Box.createHorizontalGlue());
    measureOptionsPanel.add(bdmFilePanel);
    // options panel for classification measures
    final JPanel measure2OptionsPanel = new JPanel();
    measure2OptionsPanel.setLayout(new BoxLayout(measure2OptionsPanel, BoxLayout.Y_AXIS));
    JPanel verbosePanel = new JPanel();
    verbosePanel.setLayout(new BoxLayout(verbosePanel, BoxLayout.X_AXIS));
    boolean verbose = (userConfig.getBoolean(prefix + "verbose") == null) ? false : userConfig.getBoolean(prefix + "verbose");
    verboseOptionCheckBox = new JCheckBox("Output ignored annotations", verbose);
    verbosePanel.add(verboseOptionCheckBox);
    verbosePanel.add(Box.createHorizontalGlue());
    measure2OptionsPanel.add(verbosePanel);
    // options button action
    optionsButton.setAction(new AbstractAction("Options") {

        int[] selectedIndices;

        @Override
        public void actionPerformed(ActionEvent e) {
            JToggleButton button = (JToggleButton) e.getSource();
            // switch measure options panel and measure list
            if (button.isSelected()) {
                if (measuresType == FSCORE_MEASURES) {
                    selectedIndices = measureList.getSelectedIndices();
                    measureScrollPane.setViewportView(measureOptionsPanel);
                } else if (measuresType == CLASSIFICATION_MEASURES) {
                    selectedIndices = measure2List.getSelectedIndices();
                    measure2ScrollPane.setViewportView(measure2OptionsPanel);
                }
            } else {
                String prefix = getClass().getEnclosingClass().getName() + '.';
                if (measuresType == FSCORE_MEASURES) {
                    // update beta with new values
                    String fscore = "F" + betaSpinner.getValue() + "-score ";
                    String fscore2 = "F" + beta2Spinner.getValue() + "-score ";
                    measureList.setModel(new ExtendedListModel(new String[] { fscore + "strict", fscore + "lenient", fscore + "average", fscore + "strict BDM", fscore + "lenient BDM", fscore + "average BDM", fscore2 + "strict", fscore2 + "lenient", fscore2 + "average", fscore2 + "strict BDM", fscore2 + "lenient BDM", fscore2 + "average BDM" }));
                    // save in GATE preferences
                    userConfig.put(prefix + "fscorebeta", betaSpinner.getValue());
                    userConfig.put(prefix + "fscorebeta2", beta2Spinner.getValue());
                    // put back the list and its selection
                    measureScrollPane.setViewportView(measureList);
                    measureList.setSelectedIndices(selectedIndices);
                } else if (measuresType == CLASSIFICATION_MEASURES) {
                    userConfig.put(prefix + "verbose", verboseOptionCheckBox.isSelected());
                    measure2ScrollPane.setViewportView(measure2List);
                    measure2List.setSelectedIndices(selectedIndices);
                }
            }
        }
    });
    // compare button and progress bar
    JButton compareButton = new JButton(compareAction = new CompareAction());
    compareAction.setEnabled(false);
    sidePanel.add(compareButton, gbc);
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setString("");
    sidePanel.add(progressBar, gbc);
    sidePanel.add(Box.createVerticalStrut(5), gbc);
    // tables
    annotationTable = new XJTable() {

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }

        @Override
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {

                @Override
                public String getToolTipText(MouseEvent event) {
                    int index = columnModel.getColumnIndexAtX(event.getPoint().x);
                    if (index == -1) {
                        return null;
                    }
                    int modelIndex = columnModel.getColumn(index).getModelIndex();
                    String columnName = this.table.getModel().getColumnName(modelIndex);
                    return createToolTipFromColumnName(columnName);
                }
            };
        }
    };
    annotationTable.setModel(annotationTableModel);
    annotationTable.setSortable(false);
    annotationTable.setEnableHidingColumns(true);
    annotationTable.setAutoResizeMode(XJTable.AUTO_RESIZE_ALL_COLUMNS);
    documentTable = new XJTable() {

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }

        @Override
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {

                @Override
                public String getToolTipText(MouseEvent event) {
                    int index = columnModel.getColumnIndexAtX(event.getPoint().x);
                    if (index == -1) {
                        return null;
                    }
                    int modelIndex = columnModel.getColumn(index).getModelIndex();
                    String columnName = this.table.getModel().getColumnName(modelIndex);
                    return createToolTipFromColumnName(columnName);
                }
            };
        }
    };
    documentTable.setModel(documentTableModel);
    documentTable.setSortable(false);
    documentTable.setEnableHidingColumns(true);
    documentTable.setAutoResizeMode(XJTable.AUTO_RESIZE_ALL_COLUMNS);
    document2Table = new XJTable() {

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }
    };
    document2Table.setModel(document2TableModel);
    confusionTable = new XJTable() {

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }
    };
    confusionTable.setModel(confusionTableModel);
    confusionTable.setSortable(false);
    tableTabbedPane = new JTabbedPane();
    tableTabbedPane.addTab("Corpus statistics", null, new JScrollPane(annotationTable), "Compare each annotation type for the whole corpus");
    tableTabbedPane.addTab("Document statistics", null, new JScrollPane(documentTable), "Compare each documents in the corpus with theirs annotations");
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.80);
    splitPane.setLeftComponent(tableTabbedPane);
    splitPane.setRightComponent(new JScrollPane(sidePanel));
    add(splitPane);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) XJTable(gate.swing.XJTable) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BorderLayout(java.awt.BorderLayout) JToggleButton(javax.swing.JToggleButton) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) JSpinner(javax.swing.JSpinner) JSplitPane(javax.swing.JSplitPane) JList(javax.swing.JList)

Example 7 with XJTable

use of gate.swing.XJTable in project gate-core by GateNLP.

the class AnnotationDiffGUI method initGUI.

protected void initGUI() {
    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(2, 2, 2, 2);
    constraints.weightx = 1;
    /**
     *****************************************
     * First row - Settings and 'Compare' button *
     ******************************************
     */
    constraints.gridy = 0;
    JLabel keyDocLabel = new JLabel("Key doc:");
    keyDocLabel.setToolTipText("Key document");
    getContentPane().add(keyDocLabel, constraints);
    keyDocCombo = new JComboBox<String>();
    keyDocCombo.setPrototypeDisplayValue("long_document_name");
    // add the value of the combobox in a tooltip for long value
    keyDocCombo.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                Rectangle textRectangle = new Rectangle(keyDocCombo.getSize().width, getPreferredSize().height);
                String shortText = SwingUtilities.layoutCompoundLabel(this, getFontMetrics(getFont()), value.toString(), null, getVerticalAlignment(), getHorizontalAlignment(), getHorizontalTextPosition(), getVerticalTextPosition(), textRectangle, new Rectangle(), textRectangle, getIconTextGap());
                if (shortText.equals(value)) {
                    // no tooltip
                    if (index == -1) {
                        keyDocCombo.setToolTipText(null);
                    } else {
                        setToolTipText(null);
                    }
                } else {
                    // add tooltip because text is shortened
                    if (index == -1) {
                        keyDocCombo.setToolTipText(value.toString());
                    } else {
                        setToolTipText(value.toString());
                    }
                }
            }
            return this;
        }
    });
    constraints.weightx = 3;
    getContentPane().add(keyDocCombo, constraints);
    constraints.weightx = 1;
    JLabel keySetLabel = new JLabel("Key set:");
    keySetLabel.setToolTipText("Key annotation set");
    getContentPane().add(keySetLabel, constraints);
    keySetCombo = new JComboBox<String>();
    keySetCombo.setPrototypeDisplayValue("long_set_name");
    getContentPane().add(keySetCombo, constraints);
    JLabel typeLabel = new JLabel("Type:");
    typeLabel.setToolTipText("Annotation type");
    getContentPane().add(typeLabel, constraints);
    annTypeCombo = new JComboBox<String>();
    annTypeCombo.setPrototypeDisplayValue("very_long_type");
    constraints.gridwidth = 3;
    getContentPane().add(annTypeCombo, constraints);
    constraints.gridwidth = 1;
    JLabel weightLabel = new JLabel("Weight");
    weightLabel.setToolTipText("F-measure weight");
    getContentPane().add(weightLabel, constraints);
    diffAction = new DiffAction();
    diffAction.setEnabled(false);
    doDiffBtn = new JButton(diffAction);
    doDiffBtn.setDisabledIcon(new RunIcon(MainFrame.ICON_DIMENSION, true));
    doDiffBtn.setForeground((Color) UIManager.getDefaults().get("Button.disabledText"));
    doDiffBtn.setToolTipText("Choose two annotation sets " + "that have at least one annotation type in common.");
    constraints.gridheight = 2;
    getContentPane().add(doDiffBtn, constraints);
    constraints.gridheight = 1;
    /**
     ***********************
     * Second row - Settings *
     ************************
     */
    constraints.gridy++;
    constraints.gridx = 0;
    JLabel responseDocLabel = new JLabel("Resp. doc:");
    responseDocLabel.setToolTipText("Response document");
    getContentPane().add(responseDocLabel, constraints);
    constraints.gridx = GridBagConstraints.RELATIVE;
    resDocCombo = new JComboBox<String>();
    resDocCombo.setPrototypeDisplayValue("long_document_name");
    resDocCombo.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                Rectangle textRectangle = new Rectangle(resDocCombo.getSize().width, getPreferredSize().height);
                String shortText = SwingUtilities.layoutCompoundLabel(this, getFontMetrics(getFont()), value.toString(), null, getVerticalAlignment(), getHorizontalAlignment(), getHorizontalTextPosition(), getVerticalTextPosition(), textRectangle, new Rectangle(), textRectangle, getIconTextGap());
                if (shortText.equals(value)) {
                    // no tooltip
                    if (index == -1) {
                        resDocCombo.setToolTipText(null);
                    } else {
                        setToolTipText(null);
                    }
                } else {
                    // add tooltip because text is shortened
                    if (index == -1) {
                        resDocCombo.setToolTipText(value.toString());
                    } else {
                        setToolTipText(value.toString());
                    }
                }
            }
            return this;
        }
    });
    constraints.weightx = 3;
    getContentPane().add(resDocCombo, constraints);
    constraints.weightx = 1;
    JLabel responseSetLabel = new JLabel("Resp. set:");
    responseSetLabel.setToolTipText("Response annotation set");
    getContentPane().add(responseSetLabel, constraints);
    resSetCombo = new JComboBox<String>();
    resSetCombo.setPrototypeDisplayValue("long_set_name");
    getContentPane().add(resSetCombo, constraints);
    getContentPane().add(new JLabel("Features:"), constraints);
    ButtonGroup btnGrp = new ButtonGroup();
    allFeaturesBtn = new JRadioButton("all");
    allFeaturesBtn.setOpaque(false);
    allFeaturesBtn.setMargin(new Insets(0, 0, 0, 1));
    allFeaturesBtn.setIconTextGap(1);
    btnGrp.add(allFeaturesBtn);
    constraints.insets = new Insets(0, 0, 0, 0);
    getContentPane().add(allFeaturesBtn, constraints);
    someFeaturesBtn = new JRadioButton("some");
    someFeaturesBtn.setOpaque(false);
    someFeaturesBtn.setMargin(new Insets(0, 0, 0, 1));
    someFeaturesBtn.setIconTextGap(1);
    btnGrp.add(someFeaturesBtn);
    getContentPane().add(someFeaturesBtn, constraints);
    noFeaturesBtn = new JRadioButton("none");
    noFeaturesBtn.setOpaque(false);
    noFeaturesBtn.setMargin(new Insets(0, 0, 0, 1));
    noFeaturesBtn.setIconTextGap(1);
    btnGrp.add(noFeaturesBtn);
    getContentPane().add(noFeaturesBtn, constraints);
    constraints.insets = new Insets(2, 2, 2, 2);
    noFeaturesBtn.setSelected(true);
    weightTxt = new JTextField("1.0");
    weightTxt.setToolTipText("<html>Relative weight of precision and recall aka beta." + "<ul><li>1 weights equally precision and recall" + "<li>0.5 weights precision twice as much as recall" + "<li>2 weights recall twice as much as precision</ul></html>");
    constraints.fill = GridBagConstraints.HORIZONTAL;
    getContentPane().add(weightTxt, constraints);
    constraints.fill = GridBagConstraints.NONE;
    /**
     ******************************
     * Third row - Comparison table *
     *******************************
     */
    constraints.gridy++;
    constraints.gridx = 0;
    diffTableModel = new DiffTableModel();
    diffTable = new XJTable(diffTableModel);
    diffTable.setDefaultRenderer(String.class, new DiffTableCellRenderer());
    diffTable.setDefaultRenderer(Boolean.class, new DiffTableCellRenderer());
    diffTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    diffTable.setComparator(DiffTableModel.COL_MATCH, new Comparator<String>() {

        @Override
        public int compare(String label1, String label2) {
            int match1 = 0;
            while (!label1.equals(matchLabel[match1])) match1++;
            int match2 = 0;
            while (!label2.equals(matchLabel[match2])) match2++;
            return match1 - match2;
        }
    });
    diffTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    diffTable.setRowSelectionAllowed(true);
    diffTable.setColumnSelectionAllowed(true);
    diffTable.setEnableHidingColumns(true);
    diffTable.hideColumn(DiffTableModel.COL_KEY_COPY);
    diffTable.hideColumn(DiffTableModel.COL_RES_COPY);
    Comparator<String> startEndComparator = new Comparator<String>() {

        @Override
        public int compare(String no1, String no2) {
            if (no1.trim().equals("") && no2.trim().equals("")) {
                return 0;
            } else if (no1.trim().equals("")) {
                return -1;
            } else if (no2.trim().equals("")) {
                return 1;
            }
            int n1 = Integer.parseInt(no1);
            int n2 = Integer.parseInt(no2);
            if (n1 == n2)
                return 0;
            else if (n1 > n2)
                return 1;
            else
                return -1;
        }
    };
    diffTable.setComparator(DiffTableModel.COL_KEY_START, startEndComparator);
    diffTable.setComparator(DiffTableModel.COL_KEY_END, startEndComparator);
    diffTable.setComparator(DiffTableModel.COL_RES_START, startEndComparator);
    diffTable.setComparator(DiffTableModel.COL_RES_END, startEndComparator);
    diffTable.setSortable(true);
    diffTable.setSortedColumn(DiffTableModel.COL_MATCH);
    diffTable.setAscending(true);
    scroller = new JScrollPane(diffTable);
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    getContentPane().add(scroller, constraints);
    constraints.gridwidth = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    /**
     ***********************************************
     * Fourth row - Tabbed panes, status and buttons *
     ************************************************
     */
    bottomTabbedPane = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.WRAP_TAB_LAYOUT);
    // statistics pane will be added to the bottom tabbed pane
    statisticsPane = new JPanel(new GridBagLayout());
    GridBagConstraints constraints2 = new GridBagConstraints();
    constraints2.insets = new Insets(2, 2, 2, 2);
    // first column
    constraints2.gridx = 0;
    constraints2.anchor = GridBagConstraints.WEST;
    JLabel lbl = new JLabel("Correct:");
    lbl.setToolTipText("Correct:");
    lbl.setBackground(diffTable.getBackground());
    statisticsPane.add(lbl, constraints2);
    lbl = new JLabel("Partially correct:");
    lbl.setToolTipText("Partially correct:");
    lbl.setBackground(PARTIALLY_CORRECT_BG);
    lbl.setOpaque(true);
    statisticsPane.add(lbl, constraints2);
    lbl = new JLabel("Missing:");
    lbl.setToolTipText("Missing:");
    lbl.setBackground(MISSING_BG);
    lbl.setOpaque(true);
    statisticsPane.add(lbl, constraints2);
    lbl = new JLabel("False positives:");
    lbl.setToolTipText("False positives:");
    lbl.setBackground(FALSE_POSITIVE_BG);
    lbl.setOpaque(true);
    statisticsPane.add(lbl, constraints2);
    // second column
    constraints2.gridx++;
    correctLbl = new JLabel("0");
    statisticsPane.add(correctLbl, constraints2);
    partiallyCorrectLbl = new JLabel("0");
    statisticsPane.add(partiallyCorrectLbl, constraints2);
    missingLbl = new JLabel("0");
    statisticsPane.add(missingLbl, constraints2);
    falsePozLbl = new JLabel("0");
    statisticsPane.add(falsePozLbl, constraints2);
    // third column
    constraints2.gridx++;
    constraints2.insets = new Insets(4, 30, 4, 4);
    statisticsPane.add(Box.createGlue());
    lbl = new JLabel("Strict:");
    statisticsPane.add(lbl, constraints2);
    lbl = new JLabel("Lenient:");
    statisticsPane.add(lbl, constraints2);
    lbl = new JLabel("Average:");
    statisticsPane.add(lbl, constraints2);
    // fourth column
    constraints2.gridx++;
    constraints2.insets = new Insets(4, 4, 4, 4);
    lbl = new JLabel("Recall");
    statisticsPane.add(lbl, constraints2);
    recallStrictLbl = new JLabel("0.00");
    statisticsPane.add(recallStrictLbl, constraints2);
    recallLenientLbl = new JLabel("0.00");
    statisticsPane.add(recallLenientLbl, constraints2);
    recallAveLbl = new JLabel("0.00");
    statisticsPane.add(recallAveLbl, constraints2);
    // fifth column
    constraints2.gridx++;
    lbl = new JLabel("Precision");
    statisticsPane.add(lbl, constraints2);
    precisionStrictLbl = new JLabel("0.00");
    statisticsPane.add(precisionStrictLbl, constraints2);
    precisionLenientLbl = new JLabel("0.00");
    statisticsPane.add(precisionLenientLbl, constraints2);
    precisionAveLbl = new JLabel("0.00");
    statisticsPane.add(precisionAveLbl, constraints2);
    // sixth column
    constraints2.gridx++;
    lbl = new JLabel("F-measure");
    lbl.setToolTipText("<html>F-measure =<br>" + "   ((weight² + 1) * precision * recall)<br>" + " / (weight² * precision + recall))</html>");
    statisticsPane.add(lbl, constraints2);
    fmeasureStrictLbl = new JLabel("0.00");
    statisticsPane.add(fmeasureStrictLbl, constraints2);
    fmeasureLenientLbl = new JLabel("0.00");
    statisticsPane.add(fmeasureLenientLbl, constraints2);
    fmeasureAveLbl = new JLabel("0.00");
    statisticsPane.add(fmeasureAveLbl, constraints2);
    bottomTabbedPane.add("Statistics", statisticsPane);
    // adjudication pane will be added to the bottom tabbed pane
    JPanel adjudicationPane = new JPanel(new GridBagLayout());
    constraints2 = new GridBagConstraints();
    constraints2.insets = new Insets(2, 2, 2, 2);
    // first row
    constraints2.gridy = 0;
    adjudicationPane.add(new JLabel("Target set:"), constraints2);
    consensusASTextField = new JTextField("consensus", 15);
    consensusASTextField.setToolTipText("Annotation set name where to copy the selected annotations");
    adjudicationPane.add(consensusASTextField, constraints2);
    // second row
    constraints2.gridy++;
    constraints2.gridx = 0;
    copyToTargetSetAction = new CopyToTargetSetAction();
    copyToTargetSetAction.setEnabled(false);
    copyToConsensusBtn = new JButton(copyToTargetSetAction);
    copyToConsensusBtn.setDisabledIcon(new RightArrowIcon(MainFrame.ICON_DIMENSION, true));
    constraints2.gridwidth = 2;
    adjudicationPane.add(copyToConsensusBtn, constraints2);
    bottomTabbedPane.add("Adjudication", adjudicationPane);
    JPanel bottomPanel = new JPanel(new GridBagLayout());
    constraints2 = new GridBagConstraints();
    constraints2.insets = new Insets(2, 2, 2, 2);
    // add the bottom tabbed pane to the bottom panel
    constraints2.gridx = 0;
    constraints2.gridy = 0;
    constraints2.gridheight = 3;
    constraints2.anchor = GridBagConstraints.WEST;
    bottomPanel.add(bottomTabbedPane, constraints2);
    constraints2.gridheight = 1;
    // status bar
    constraints2.gridx++;
    statusLabel = new JLabel();
    statusLabel.setBackground(diffTable.getBackground());
    constraints2.insets = new Insets(2, 6, 6, 2);
    bottomPanel.add(statusLabel, constraints2);
    // toolbar
    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);
    if (!isStandalone) {
        showDocumentAction = new ShowDocumentAction();
        showDocumentAction.setEnabled(false);
        showDocumentBtn = new JButton(showDocumentAction);
        showDocumentBtn.setDisabledIcon(new DocumentIcon(MainFrame.ICON_DIMENSION, true));
        showDocumentBtn.setToolTipText("Use first the \"Compare\"" + " button then select an annotation in the table.");
        toolbar.add(showDocumentBtn);
    }
    htmlExportAction = new HTMLExportAction();
    htmlExportAction.setEnabled(false);
    htmlExportBtn = new JButton(htmlExportAction);
    htmlExportBtn.setDisabledIcon(new DownIcon(MainFrame.ICON_DIMENSION, true));
    htmlExportBtn.setToolTipText("Use first the \"Compare\" button.");
    toolbar.add(htmlExportBtn);
    if (!isStandalone) {
        toolbar.add(new HelpAction());
    }
    constraints2.gridy++;
    constraints2.fill = GridBagConstraints.NONE;
    constraints2.anchor = GridBagConstraints.NORTHWEST;
    bottomPanel.add(toolbar, constraints2);
    // progress bar
    progressBar = new JProgressBar();
    progressBar.setMinimumSize(new Dimension(5, 5));
    progressBar.setBackground(diffTable.getBackground());
    progressBar.setOpaque(true);
    constraints2.gridy++;
    constraints2.anchor = GridBagConstraints.SOUTHWEST;
    bottomPanel.add(progressBar, constraints2);
    // add the bottom panel to the fourth row
    constraints.gridy++;
    constraints.gridx = 0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.gridheight = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(0, 0, 0, 0);
    getContentPane().add(bottomPanel, constraints);
    constraints.insets = new Insets(2, 2, 2, 2);
    // set the background colour
    Color background = diffTable.getBackground();
    getContentPane().setBackground(background);
    scroller.setBackground(background);
    scroller.getViewport().setBackground(background);
    statisticsPane.setBackground(background);
    adjudicationPane.setBackground(background);
    bottomPanel.setBackground(background);
    bottomTabbedPane.setBackground(background);
    featureslistModel = new DefaultListModel<String>();
    featuresList = new JList<String>(featureslistModel);
    featuresList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    keySetCombo.requestFocusInWindow();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) XJTable(gate.swing.XJTable) JTabbedPane(javax.swing.JTabbedPane) Rectangle(java.awt.Rectangle) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) Comparator(java.util.Comparator) RunIcon(gate.resources.img.svg.RunIcon) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) JComponent(javax.swing.JComponent) JScrollPane(javax.swing.JScrollPane) DocumentIcon(gate.resources.img.svg.DocumentIcon) Color(java.awt.Color) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) RightArrowIcon(gate.resources.img.svg.RightArrowIcon) ButtonGroup(javax.swing.ButtonGroup) DownIcon(gate.resources.img.svg.DownIcon)

Example 8 with XJTable

use of gate.swing.XJTable in project gate-core by GateNLP.

the class AnnotationListView method initGUI.

/* (non-Javadoc)
    * @see gate.gui.docview.AbstractDocumentView#initGUI()
    */
@Override
protected void initGUI() {
    tableModel = new AnnotationTableModel();
    table = new XJTable(tableModel);
    table.setAutoResizeMode(XJTable.AUTO_RESIZE_LAST_COLUMN);
    table.setSortable(true);
    table.setSortedColumn(START_COL);
    table.setIntercellSpacing(new Dimension(2, 0));
    table.setEnableHidingColumns(true);
    scroller = new JScrollPane(table);
    mainPanel = new JPanel();
    mainPanel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridwidth = 4;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    mainPanel.add(scroller, constraints);
    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.gridwidth = 1;
    constraints.gridy = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.WEST;
    statusLabel = new JLabel();
    mainPanel.add(statusLabel, constraints);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.EAST;
    mainPanel.add(Box.createHorizontalStrut(10), constraints);
    mainPanel.add(new JLabel("Select: "), constraints);
    filterTextField = new JTextField(20);
    filterTextField.setToolTipText("Select the rows containing this text.");
    mainPanel.add(filterTextField, constraints);
    // get a pointer to the text view used to display
    // the selected annotations
    Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator();
    while (textView == null && centralViewsIter.hasNext()) {
        DocumentView aView = centralViewsIter.next();
        if (aView instanceof TextualDocumentView)
            textView = (TextualDocumentView) aView;
    }
    initListeners();
}
Also used : XJTable(gate.swing.XJTable)

Aggregations

XJTable (gate.swing.XJTable)8 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 JButton (javax.swing.JButton)5 JPanel (javax.swing.JPanel)5 JScrollPane (javax.swing.JScrollPane)5 BorderLayout (java.awt.BorderLayout)4 Dimension (java.awt.Dimension)4 Insets (java.awt.Insets)4 JLabel (javax.swing.JLabel)4 Color (java.awt.Color)3 JSplitPane (javax.swing.JSplitPane)3 JTabbedPane (javax.swing.JTabbedPane)3 Document (gate.Document)2 ResourceInstantiationException (gate.creole.ResourceInstantiationException)2 GateRuntimeException (gate.util.GateRuntimeException)2 Component (java.awt.Component)2 ActionEvent (java.awt.event.ActionEvent)2 MouseEvent (java.awt.event.MouseEvent)2 Comparator (java.util.Comparator)2