use of javax.swing.event.TableModelListener in project mafscaling by vimsh.
the class MafCompare method initialize.
/**
* Initialize the contents of the frame.
*/
private void initialize() {
try {
ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg"));
setTitle(Title);
setIconImage(tableImage.getImage());
setBounds(100, 100, 621, 372);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setSize(Config.getCompWindowSize());
setLocation(Config.getCompWindowLocation());
setLocationRelativeTo(null);
setVisible(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Utils.clearTable(origMafTable);
Utils.clearTable(newMafTable);
Utils.clearTable(compMafTable);
Config.setCompWindowSize(getSize());
Config.setCompWindowLocation(getLocation());
origMafData.clear();
newMafData.clear();
}
});
JPanel dataPanel = new JPanel();
GridBagLayout gbl_dataPanel = new GridBagLayout();
gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 };
gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 };
gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 };
gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
dataPanel.setLayout(gbl_dataPanel);
getContentPane().add(dataPanel);
JLabel origLabel = new JLabel(origMaf);
GridBagConstraints gbc_origLabel = new GridBagConstraints();
gbc_origLabel.anchor = GridBagConstraints.PAGE_START;
gbc_origLabel.insets = new Insets(1, 1, 1, 5);
gbc_origLabel.weightx = 0;
gbc_origLabel.weighty = 0;
gbc_origLabel.gridx = 0;
gbc_origLabel.gridy = 0;
gbc_origLabel.gridheight = 2;
dataPanel.add(origLabel, gbc_origLabel);
JLabel newLabel = new JLabel(newMaf);
GridBagConstraints gbc_newLabel = new GridBagConstraints();
gbc_newLabel.anchor = GridBagConstraints.PAGE_START;
gbc_newLabel.insets = new Insets(1, 1, 1, 5);
gbc_newLabel.weightx = 0;
gbc_newLabel.weighty = 0;
gbc_newLabel.gridx = 0;
gbc_newLabel.gridy = 2;
gbc_newLabel.gridheight = 2;
dataPanel.add(newLabel, gbc_newLabel);
JLabel compLabel = new JLabel("Change");
GridBagConstraints gbc_compLabel = new GridBagConstraints();
gbc_compLabel.anchor = GridBagConstraints.PAGE_START;
gbc_compLabel.insets = new Insets(1, 1, 1, 5);
gbc_compLabel.weightx = 0;
gbc_compLabel.weighty = 0;
gbc_compLabel.gridx = 0;
gbc_compLabel.gridy = 4;
dataPanel.add(compLabel, gbc_compLabel);
JLabel origVoltLabel = new JLabel("volt");
GridBagConstraints gbc_origVoltLabel = new GridBagConstraints();
gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START;
gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5);
gbc_origVoltLabel.weightx = 0;
gbc_origVoltLabel.weighty = 0;
gbc_origVoltLabel.gridx = 1;
gbc_origVoltLabel.gridy = 0;
dataPanel.add(origVoltLabel, gbc_origVoltLabel);
JLabel origGsLabel = new JLabel(" g/s");
GridBagConstraints gbc_origGsLabel = new GridBagConstraints();
gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START;
gbc_origGsLabel.insets = new Insets(1, 1, 1, 5);
gbc_origGsLabel.weightx = 0;
gbc_origGsLabel.weighty = 0;
gbc_origGsLabel.gridx = 1;
gbc_origGsLabel.gridy = 1;
dataPanel.add(origGsLabel, gbc_origGsLabel);
JLabel newVoltLabel = new JLabel("volt");
GridBagConstraints gbc_newVoltLabel = new GridBagConstraints();
gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START;
gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5);
gbc_newVoltLabel.weightx = 0;
gbc_newVoltLabel.weighty = 0;
gbc_newVoltLabel.gridx = 1;
gbc_newVoltLabel.gridy = 2;
dataPanel.add(newVoltLabel, gbc_newVoltLabel);
JLabel newGsLabel = new JLabel(" g/s");
GridBagConstraints gbc_newGsLabel = new GridBagConstraints();
gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START;
gbc_newGsLabel.insets = new Insets(1, 1, 1, 5);
gbc_newGsLabel.weightx = 0;
gbc_newGsLabel.weighty = 0;
gbc_newGsLabel.gridx = 1;
gbc_newGsLabel.gridy = 3;
dataPanel.add(newGsLabel, gbc_newGsLabel);
JLabel compPctLabel = new JLabel(" % ");
GridBagConstraints gbc_compPctLabel = new GridBagConstraints();
gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START;
gbc_compPctLabel.insets = new Insets(1, 1, 1, 5);
gbc_compPctLabel.weightx = 0;
gbc_compPctLabel.weighty = 0;
gbc_compPctLabel.gridx = 1;
gbc_compPctLabel.gridy = 4;
dataPanel.add(compPctLabel, gbc_compPctLabel);
JPanel tablesPanel = new JPanel();
GridBagLayout gbl_tablesPanel = new GridBagLayout();
gbl_tablesPanel.columnWidths = new int[] { 0 };
gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 };
gbl_tablesPanel.columnWeights = new double[] { 0.0 };
gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 };
tablesPanel.setLayout(gbl_tablesPanel);
JScrollPane mafScrollPane = new JScrollPane(tablesPanel);
mafScrollPane.setMinimumSize(new Dimension(1600, 107));
mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20));
mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
GridBagConstraints gbc_mafScrollPane = new GridBagConstraints();
gbc_mafScrollPane.weightx = 1.0;
gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START;
gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL;
gbc_mafScrollPane.gridx = 2;
gbc_mafScrollPane.gridy = 0;
gbc_mafScrollPane.gridheight = 5;
dataPanel.add(mafScrollPane, gbc_mafScrollPane);
origMafTable = new JTable();
origMafTable.setColumnSelectionAllowed(true);
origMafTable.setCellSelectionEnabled(true);
origMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
origMafTable.setRowHeight(RowHeight);
origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
origMafTable.setTableHeader(null);
origMafTable.putClientProperty("terminateEditOnFocusLost", true);
Utils.initializeTable(origMafTable, ColumnWidth);
GridBagConstraints gbc_origMafTable = new GridBagConstraints();
gbc_origMafTable.anchor = GridBagConstraints.PAGE_START;
gbc_origMafTable.insets = new Insets(0, 0, 0, 0);
gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL;
gbc_origMafTable.weightx = 1.0;
gbc_origMafTable.weighty = 0;
gbc_origMafTable.gridx = 0;
gbc_origMafTable.gridy = 0;
tablesPanel.add(origMafTable, gbc_origMafTable);
excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true);
newMafTable = new JTable();
newMafTable.setColumnSelectionAllowed(true);
newMafTable.setCellSelectionEnabled(true);
newMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
newMafTable.setRowHeight(RowHeight);
newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
newMafTable.setTableHeader(null);
newMafTable.putClientProperty("terminateEditOnFocusLost", true);
Utils.initializeTable(newMafTable, ColumnWidth);
GridBagConstraints gbc_newMafTable = new GridBagConstraints();
gbc_newMafTable.anchor = GridBagConstraints.PAGE_START;
gbc_newMafTable.insets = new Insets(0, 0, 0, 0);
gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL;
gbc_newMafTable.weightx = 1.0;
gbc_newMafTable.weighty = 0;
gbc_newMafTable.gridx = 0;
gbc_newMafTable.gridy = 1;
tablesPanel.add(newMafTable, gbc_newMafTable);
excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true);
compMafTable = new JTable();
compMafTable.setColumnSelectionAllowed(true);
compMafTable.setCellSelectionEnabled(true);
compMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
compMafTable.setRowHeight(RowHeight);
compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount));
compMafTable.setTableHeader(null);
compMafTable.putClientProperty("terminateEditOnFocusLost", true);
Utils.initializeTable(compMafTable, ColumnWidth);
NumberFormatRenderer numericRenderer = new NumberFormatRenderer();
numericRenderer.setFormatter(new DecimalFormat("0.000"));
compMafTable.setDefaultRenderer(Object.class, numericRenderer);
GridBagConstraints gbc_compMafTable = new GridBagConstraints();
gbc_compMafTable.anchor = GridBagConstraints.PAGE_START;
gbc_compMafTable.insets = new Insets(0, 0, 0, 0);
gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL;
gbc_compMafTable.weightx = 1.0;
gbc_compMafTable.weighty = 0;
gbc_compMafTable.gridx = 0;
gbc_compMafTable.gridy = 2;
tablesPanel.add(compMafTable, gbc_compMafTable);
compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true);
TableModelListener origTableListener = new TableModelListener() {
public void tableChanged(TableModelEvent tme) {
if (tme.getType() == TableModelEvent.UPDATE) {
int colCount = origMafTable.getColumnCount();
Utils.ensureColumnCount(colCount, newMafTable);
Utils.ensureColumnCount(colCount, compMafTable);
origMafData.clear();
String origY, origX, newY;
for (int i = 0; i < colCount; ++i) {
origY = origMafTable.getValueAt(1, i).toString();
if (Pattern.matches(Utils.fpRegex, origY)) {
origX = origMafTable.getValueAt(0, i).toString();
if (Pattern.matches(Utils.fpRegex, origX))
origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false);
newY = newMafTable.getValueAt(1, i).toString();
if (Pattern.matches(Utils.fpRegex, newY))
compMafTable.setValueAt(((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
} else
break;
}
origMafData.fireSeriesChanged();
}
}
};
TableModelListener newTableListener = new TableModelListener() {
public void tableChanged(TableModelEvent tme) {
if (tme.getType() == TableModelEvent.UPDATE) {
int colCount = newMafTable.getColumnCount();
Utils.ensureColumnCount(colCount, origMafTable);
Utils.ensureColumnCount(colCount, compMafTable);
newMafData.clear();
String newY, newX, origY;
for (int i = 0; i < colCount; ++i) {
newY = newMafTable.getValueAt(1, i).toString();
if (Pattern.matches(Utils.fpRegex, newY)) {
newX = newMafTable.getValueAt(0, i).toString();
if (Pattern.matches(Utils.fpRegex, newX))
newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false);
origY = origMafTable.getValueAt(1, i).toString();
if (Pattern.matches(Utils.fpRegex, origY))
compMafTable.setValueAt(((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
} else
break;
}
newMafData.fireSeriesChanged();
}
}
};
origMafTable.getModel().addTableModelListener(origTableListener);
newMafTable.getModel().addTableModelListener(newTableListener);
Action action = new AbstractAction() {
private static final long serialVersionUID = 8148393537657380215L;
public void actionPerformed(ActionEvent e) {
TableCellListener tcl = (TableCellListener) e.getSource();
if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) {
if (Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, tcl.getColumn()).toString())) {
double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString()) / 100.0 + 1.0;
newMafTable.setValueAt(Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr, 1, tcl.getColumn());
}
} else
compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn());
}
};
setCompMafCellListener(new TableCellListener(compMafTable, action));
// CHART
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setFocusable(true);
chartPanel.setAutoscrolls(true);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.insets = new Insets(1, 1, 1, 1);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 5;
gbl_chartPanel.gridheight = 1;
gbl_chartPanel.gridwidth = 3;
dataPanel.add(chartPanel, gbl_chartPanel);
XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesStroke(1, stroke);
lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = -4045338273187150888L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
NumberAxis mafvDomain = new NumberAxis(XAxisName);
mafvDomain.setAutoRangeIncludesZero(false);
mafvDomain.setAutoRange(true);
mafvDomain.setAutoRangeStickyZero(false);
NumberAxis mafgsRange = new NumberAxis(YAxisName);
mafgsRange.setAutoRangeIncludesZero(false);
mafgsRange.setAutoRange(true);
mafgsRange.setAutoRangeStickyZero(false);
XYSeriesCollection lineDataset = new XYSeriesCollection();
origMafData.setDescription(origMaf);
newMafData.setDescription(newMaf);
lineDataset.addSeries(origMafData);
lineDataset.addSeries(newMafData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, mafvDomain);
plot.setRangeAxis(0, mafgsRange);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
chartPanel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
chartPanel.requestFocusInWindow();
}
});
chartPanel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!chartPanel.hasFocus())
return;
int keyCode = e.getKeyCode();
if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
return;
ValueAxis axis = null;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getDomainAxis();
else
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getRangeAxis();
if (axis != null) {
double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
});
} catch (Exception e) {
logger.error(e);
}
}
use of javax.swing.event.TableModelListener in project gate-core by GateNLP.
the class AnnotationDiffGUI method initListeners.
protected void initListeners() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
new CloseAction().actionPerformed(null);
}
});
addWindowFocusListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
populateGUI();
}
});
keyDocCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
int keyDocSelectedIndex = keyDocCombo.getSelectedIndex();
if (keyDocSelectedIndex == -1) {
return;
}
Document newDoc = (Document) documents.get(keyDocSelectedIndex);
if (keyDoc == newDoc) {
return;
}
pairings.clear();
diffTableModel.fireTableDataChanged();
copyToTargetSetAction.setEnabled(false);
keyDoc = newDoc;
keySets = new ArrayList<AnnotationSet>();
List<String> keySetNames = new ArrayList<String>();
keySets.add(keyDoc.getAnnotations());
keySetNames.add("[Default set]");
if (keyDoc.getNamedAnnotationSets() != null) {
for (Object o : keyDoc.getNamedAnnotationSets().keySet()) {
String name = (String) o;
keySetNames.add(name);
keySets.add(keyDoc.getAnnotations(name));
}
}
keySetCombo.setModel(new DefaultComboBoxModel<String>(keySetNames.toArray(new String[keySetNames.size()])));
if (!keySetNames.isEmpty()) {
keySetCombo.setSelectedIndex(0);
if (resSetCombo.getItemCount() > 0) {
// find first annotation set with annotation type in common
for (int res = 0; res < resSetCombo.getItemCount(); res++) {
resSetCombo.setSelectedIndex(res);
for (int key = 0; key < keySetCombo.getItemCount(); key++) {
if (keyDoc.equals(resDoc) && resSetCombo.getItemAt(res).equals(keySetCombo.getItemAt(key))) {
// same document, skip it
continue;
}
keySetCombo.setSelectedIndex(key);
if (annTypeCombo.getSelectedItem() != null) {
break;
}
}
if (annTypeCombo.getSelectedItem() != null) {
break;
}
}
if (annTypeCombo.getSelectedItem() == null) {
statusLabel.setText("There is no annotation type in common.");
statusLabel.setForeground(Color.RED);
} else if (statusLabel.getText().equals("There is no annotation type in common.")) {
statusLabel.setText("The first annotation sets with" + " annotation type in common have been automatically selected.");
statusLabel.setForeground(Color.BLACK);
}
}
}
}
});
resDocCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
int resDocSelectedIndex = resDocCombo.getSelectedIndex();
if (resDocSelectedIndex == -1) {
return;
}
Document newDoc = (Document) documents.get(resDocSelectedIndex);
if (resDoc == newDoc) {
return;
}
resDoc = newDoc;
pairings.clear();
diffTableModel.fireTableDataChanged();
copyToTargetSetAction.setEnabled(false);
resSets = new ArrayList<AnnotationSet>();
List<String> resSetNames = new ArrayList<String>();
resSets.add(resDoc.getAnnotations());
resSetNames.add("[Default set]");
if (resDoc.getNamedAnnotationSets() != null) {
for (Object o : resDoc.getNamedAnnotationSets().keySet()) {
String name = (String) o;
resSetNames.add(name);
resSets.add(resDoc.getAnnotations(name));
}
}
resSetCombo.setModel(new DefaultComboBoxModel<String>(resSetNames.toArray(new String[resSetNames.size()])));
if (!resSetNames.isEmpty()) {
resSetCombo.setSelectedIndex(0);
if (keySetCombo.getItemCount() > 0) {
// find annotation sets with annotations in common
for (int res = 0; res < resSetCombo.getItemCount(); res++) {
resSetCombo.setSelectedIndex(res);
for (int key = 0; key < keySetCombo.getItemCount(); key++) {
if (keyDoc.equals(resDoc) && resSetCombo.getItemAt(res).equals(keySetCombo.getItemAt(key))) {
continue;
}
keySetCombo.setSelectedIndex(key);
if (annTypeCombo.getSelectedItem() != null) {
break;
}
}
if (annTypeCombo.getSelectedItem() != null) {
break;
}
}
if (annTypeCombo.getSelectedItem() == null) {
statusLabel.setText("There is no annotations in common.");
statusLabel.setForeground(Color.RED);
} else if (statusLabel.getText().equals("There is no annotations in common.")) {
statusLabel.setText("The first annotation sets with" + " annotations in common have been selected.");
statusLabel.setForeground(Color.BLACK);
}
}
}
}
});
/**
* This populates the types combo when set selection changes
*/
ActionListener setComboActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
keySet = keySets == null || keySets.isEmpty() ? null : keySets.get(keySetCombo.getSelectedIndex());
resSet = resSets == null || resSets.isEmpty() ? null : resSets.get(resSetCombo.getSelectedIndex());
Set<String> keyTypes = (keySet == null || keySet.isEmpty()) ? new HashSet<String>() : keySet.getAllTypes();
Set<String> resTypes = (resSet == null || resSet.isEmpty()) ? new HashSet<String>() : resSet.getAllTypes();
Set<String> types = new HashSet<String>(keyTypes);
types.retainAll(resTypes);
List<String> typesList = new ArrayList<String>(types);
Collections.sort(typesList);
annTypeCombo.setModel(new DefaultComboBoxModel<String>(typesList.toArray(new String[typesList.size()])));
if (typesList.size() > 0) {
annTypeCombo.setSelectedIndex(0);
diffAction.setEnabled(true);
doDiffBtn.setForeground((Color) UIManager.getDefaults().get("Button.foreground"));
doDiffBtn.setToolTipText((String) diffAction.getValue(Action.SHORT_DESCRIPTION));
} else {
diffAction.setEnabled(false);
doDiffBtn.setForeground((Color) UIManager.getDefaults().get("Button.disabledText"));
doDiffBtn.setToolTipText("Choose two annotation sets " + "that have at least one annotation type in common.");
}
}
};
keySetCombo.addActionListener(setComboActionListener);
resSetCombo.addActionListener(setComboActionListener);
someFeaturesBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
if (someFeaturesBtn.isSelected()) {
if (keySet == null || keySet.isEmpty() || annTypeCombo.getSelectedItem() == null)
return;
Iterator<Annotation> annIter = keySet.get((String) annTypeCombo.getSelectedItem()).iterator();
Set<String> featureSet = new HashSet<String>();
while (annIter.hasNext()) {
Annotation ann = annIter.next();
Map<Object, Object> someFeatures = ann.getFeatures();
if (someFeatures == null) {
continue;
}
for (Object feature : someFeatures.keySet()) {
featureSet.add((String) feature);
}
}
List<String> featureList = new ArrayList<String>(featureSet);
Collections.sort(featureList);
featureslistModel.clear();
Iterator<String> featIter = featureList.iterator();
int index = 0;
while (featIter.hasNext()) {
String aFeature = featIter.next();
featureslistModel.addElement(aFeature);
if (significantFeatures.contains(aFeature))
featuresList.addSelectionInterval(index, index);
index++;
}
int ret = JOptionPane.showConfirmDialog(AnnotationDiffGUI.this, new JScrollPane(featuresList), "Select features", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (ret == JOptionPane.OK_OPTION) {
significantFeatures.clear();
int[] selIdxs = featuresList.getSelectedIndices();
for (int selIdx : selIdxs) {
significantFeatures.add(featureslistModel.get(selIdx));
}
}
}
}
});
// enable/disable buttons according to the table state
diffTableModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(javax.swing.event.TableModelEvent e) {
if (diffTableModel.getRowCount() > 0) {
htmlExportAction.setEnabled(true);
htmlExportBtn.setToolTipText((String) htmlExportAction.getValue(Action.SHORT_DESCRIPTION));
showDocumentAction.setEnabled(true);
showDocumentBtn.setToolTipText((String) showDocumentAction.getValue(Action.SHORT_DESCRIPTION));
} else {
htmlExportAction.setEnabled(false);
htmlExportBtn.setToolTipText("Use first the \"Compare\" button.");
showDocumentAction.setEnabled(false);
showDocumentBtn.setToolTipText("Use first the \"Compare\"" + " button then select an annotation in the table.");
}
}
});
// enable/disable buttons according to the table selection
diffTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int row = diffTable.rowViewToModel(diffTable.getSelectedRow());
if (row == -1) {
showDocumentAction.setEnabled(false);
return;
}
AnnotationDiffer.Pairing pairing = pairings.get(row);
Annotation key = pairing.getKey();
Annotation response = pairing.getResponse();
int column = diffTable.convertColumnIndexToModel(diffTable.getSelectedColumn());
boolean enabled;
switch(column) {
case DiffTableModel.COL_KEY_START:
case DiffTableModel.COL_KEY_END:
case DiffTableModel.COL_KEY_STRING:
case DiffTableModel.COL_KEY_FEATURES:
enabled = (key != null);
break;
case DiffTableModel.COL_RES_START:
case DiffTableModel.COL_RES_END:
case DiffTableModel.COL_RES_STRING:
case DiffTableModel.COL_RES_FEATURES:
enabled = (response != null);
break;
default:
enabled = false;
}
showDocumentAction.setEnabled(enabled);
}
});
// enable/disable buttons according to the table selection
diffTable.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
@Override
public void columnAdded(TableColumnModelEvent e) {
/* do nothing */
}
@Override
public void columnRemoved(TableColumnModelEvent e) {
/* do nothing */
}
@Override
public void columnMoved(TableColumnModelEvent e) {
/* do nothing */
}
@Override
public void columnMarginChanged(ChangeEvent e) {
/* do nothing */
}
@Override
public void columnSelectionChanged(ListSelectionEvent e) {
int row = diffTable.rowViewToModel(diffTable.getSelectedRow());
if (row == -1) {
showDocumentAction.setEnabled(false);
return;
}
AnnotationDiffer.Pairing pairing = pairings.get(row);
Annotation key = pairing.getKey();
Annotation response = pairing.getResponse();
int column = diffTable.convertColumnIndexToModel(diffTable.getSelectedColumn());
boolean enabled;
switch(column) {
case DiffTableModel.COL_KEY_START:
case DiffTableModel.COL_KEY_END:
case DiffTableModel.COL_KEY_STRING:
case DiffTableModel.COL_KEY_FEATURES:
enabled = (key != null);
break;
case DiffTableModel.COL_RES_START:
case DiffTableModel.COL_RES_END:
case DiffTableModel.COL_RES_STRING:
case DiffTableModel.COL_RES_FEATURES:
enabled = (response != null);
break;
default:
enabled = false;
}
showDocumentAction.setEnabled(enabled);
}
});
// inverse state of selected checkboxes when Space key is pressed
diffTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() != KeyEvent.VK_SPACE || !(diffTable.isColumnSelected(DiffTableModel.COL_KEY_COPY) || diffTable.isColumnSelected(DiffTableModel.COL_RES_COPY))) {
return;
}
// disable normal behavior of Space key in a table
e.consume();
int[] cols = { DiffTableModel.COL_KEY_COPY, DiffTableModel.COL_RES_COPY };
for (int col : cols) {
for (int row : diffTable.getSelectedRows()) {
if (diffTable.isCellSelected(row, col) && diffTable.isCellEditable(row, col)) {
diffTable.setValueAt(!(Boolean) diffTable.getValueAt(row, col), row, col);
diffTableModel.fireTableCellUpdated(row, col);
}
}
}
}
});
// context menu for the check boxes to easily change their state
diffTable.addMouseListener(new MouseAdapter() {
private JPopupMenu mousePopup;
JMenuItem menuItem;
@Override
public void mousePressed(MouseEvent e) {
showContextMenu(e);
}
@Override
public void mouseReleased(MouseEvent e) {
showContextMenu(e);
}
private void showContextMenu(MouseEvent e) {
int col = diffTable.convertColumnIndexToModel(diffTable.columnAtPoint(e.getPoint()));
if (!e.isPopupTrigger() || (col != DiffTableModel.COL_KEY_COPY && col != DiffTableModel.COL_RES_COPY)) {
return;
}
mousePopup = new JPopupMenu();
for (final String tick : new String[] { "Tick", "Untick" }) {
menuItem = new JMenuItem(tick + " selected check boxes");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
int keyCol = diffTable.convertColumnIndexToView(DiffTableModel.COL_KEY_COPY);
int responseCol = diffTable.convertColumnIndexToView(DiffTableModel.COL_RES_COPY);
for (int row = 0; row < diffTable.getRowCount(); row++) {
int rowModel = diffTable.rowViewToModel(row);
AnnotationDiffer.Pairing pairing = pairings.get(rowModel);
if (diffTable.isCellSelected(row, keyCol) && pairing.getKey() != null) {
diffTable.setValueAt(tick.equals("Tick"), row, keyCol);
}
if (diffTable.isCellSelected(row, responseCol) && pairing.getResponse() != null) {
diffTable.setValueAt(tick.equals("Tick"), row, responseCol);
}
}
diffTableModel.fireTableDataChanged();
}
});
mousePopup.add(menuItem);
}
mousePopup.addSeparator();
String[] types = new String[] { "correct", "partially correct", "missing", "false positives", "mismatch" };
String[] symbols = new String[] { "=", "~", "-?", "?-", "<>" };
for (int i = 0; i < types.length; i++) {
menuItem = new JMenuItem("Tick " + types[i] + " annotations");
final String symbol = symbols[i];
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
int matchCol = diffTable.convertColumnIndexToView(DiffTableModel.COL_MATCH);
for (int row = 0; row < diffTable.getRowCount(); row++) {
int rowModel = diffTable.rowViewToModel(row);
AnnotationDiffer.Pairing pairing = pairings.get(rowModel);
if (diffTable.getValueAt(row, matchCol).equals(symbol) && pairing.getKey() != null) {
keyCopyValueRows.set(diffTable.rowViewToModel(row), true);
} else if (diffTable.getValueAt(row, matchCol).equals(symbol) && pairing.getResponse() != null) {
resCopyValueRows.set(diffTable.rowViewToModel(row), true);
}
}
diffTableModel.fireTableDataChanged();
}
});
mousePopup.add(menuItem);
}
mousePopup.show(e.getComponent(), e.getX(), e.getY());
}
});
// revert to default name if the field is empty and lost focus
consensusASTextField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String target = consensusASTextField.getText().trim();
if (target.length() == 0) {
consensusASTextField.setText("consensus");
}
if (keyDoc != null && keyDoc.getAnnotationSetNames().contains(target)) {
statusLabel.setText("Be careful, the annotation set " + target + " already exists.");
statusLabel.setForeground(Color.RED);
}
}
});
bottomTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (bottomTabbedPane.getSelectedIndex() == 0) {
diffTable.hideColumn(DiffTableModel.COL_KEY_COPY);
diffTable.hideColumn(DiffTableModel.COL_RES_COPY);
} else {
int middleIndex = Math.round(diffTable.getColumnCount() / 2);
diffTable.showColumn(DiffTableModel.COL_KEY_COPY, middleIndex);
diffTable.showColumn(DiffTableModel.COL_RES_COPY, middleIndex + 2);
diffTable.getColumnModel().getColumn(DiffTableModel.COL_KEY_COPY).setPreferredWidth(10);
diffTable.getColumnModel().getColumn(DiffTableModel.COL_RES_COPY).setPreferredWidth(10);
diffTable.doLayout();
}
}
});
// define keystrokes action bindings at the level of the main window
InputMap inputMap = ((JComponent) this.getContentPane()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = ((JComponent) this.getContentPane()).getActionMap();
inputMap.put(KeyStroke.getKeyStroke("F1"), "Help");
actionMap.put("Help", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
new HelpAction().actionPerformed(null);
}
});
}
use of javax.swing.event.TableModelListener in project netbeans-mmd-plugin by raydac.
the class KeyShortCutEditPanel method updateCurrentSelectedForKey.
private void updateCurrentSelectedForKey(final KeyEvent evt) {
final int index = this.tableKeyShortcuts.getSelectedRow();
if (index >= 0) {
final KeyShortcut oldShortcut = this.listOfKeys.get(index);
final int keyCode = evt.getKeyCode();
final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK);
final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(), keyCode, modifiers);
this.listOfKeys.set(index, newShortCut);
for (final TableModelListener l : this.listeners) {
l.tableChanged(new TableModelEvent(this, index));
}
}
updateForSelected();
}
use of javax.swing.event.TableModelListener in project netbeans-mmd-plugin by raydac.
the class KeyShortCutEditPanel method updateCurrentSelectedForKey.
private void updateCurrentSelectedForKey(final KeyEvent evt) {
final int index = this.tableKeyShortcuts.getSelectedRow();
if (index >= 0) {
final KeyShortcut oldShortcut = this.listOfKeys.get(index);
final int keyCode = evt.getKeyCode();
final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK);
final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(), keyCode, modifiers);
this.listOfKeys.set(index, newShortCut);
for (final TableModelListener l : this.listeners) {
l.tableChanged(new TableModelEvent(this, index));
}
}
updateForSelected();
}
use of javax.swing.event.TableModelListener in project netbeans-mmd-plugin by raydac.
the class KeyShortCutEditPanel method updateCurrentSelectedForKey.
private void updateCurrentSelectedForKey(final KeyEvent evt) {
final int index = this.tableKeyShortcuts.getSelectedRow();
if (index >= 0) {
final KeyShortcut oldShortcut = this.listOfKeys.get(index);
final int keyCode = evt.getKeyCode();
final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK);
final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(), keyCode, modifiers);
this.listOfKeys.set(index, newShortCut);
for (final TableModelListener l : this.listeners) {
l.tableChanged(new TableModelEvent(this, index));
}
}
updateForSelected();
}
Aggregations