use of java.awt.event.MouseListener in project beast2 by CompEvol.
the class AlignmentListInputEditor method createListBox.
protected Component createListBox() {
String[] columnData = new String[] { "Name", "File", "Taxa", "Sites", "Data Type", "Site Model", "Clock Model", "Tree", "Ambiguities" };
initTableData();
// set up table.
// special features: background shading of rows
// custom editor allowing only Date column to be edited.
table = new JTable(tableData, columnData) {
private static final long serialVersionUID = 1L;
// method that induces table row shading
@Override
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
// even index, selected or not selected
if (isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.gray);
} else if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
comp.setBackground(new Color(237, 243, 255));
} else {
comp.setBackground(Color.white);
}
JComponent jcomp = (JComponent) comp;
switch(Index_col) {
case NAME_COLUMN:
case CLOCKMODEL_COLUMN:
case TREE_COLUMN:
case SITEMODEL_COLUMN:
jcomp.setToolTipText("Set " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case FILE_COLUMN:
case TAXA_COLUMN:
case SITES_COLUMN:
case TYPE_COLUMN:
jcomp.setToolTipText("Report " + table.getColumnName(Index_col).toLowerCase() + " for this partition");
break;
case USE_AMBIGUITIES_COLUMN:
jcomp.setToolTipText("<html>Flag whether to use ambiguities.<br>" + "If not set, the treelikelihood will treat ambiguities in the<br>" + "data as unknowns<br>" + "If set, the treelikelihood will use ambiguities as equally<br>" + "likely values for the tips.<br>" + "This will make the computation twice as slow.</html>");
break;
default:
jcomp.setToolTipText(null);
}
updateStatus();
return comp;
}
};
int size = table.getFont().getSize();
table.setRowHeight(25 * size / 13);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(true);
table.setName("alignmenttable");
setUpComboBoxes();
TableColumn col = table.getColumnModel().getColumn(NAME_COLUMN);
nameEditor = new JTextField();
nameEditor.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void insertUpdate(DocumentEvent e) {
processPartitionName();
}
@Override
public void changedUpdate(DocumentEvent e) {
processPartitionName();
}
});
col.setCellEditor(new DefaultCellEditor(nameEditor));
// // set up editor that makes sure only doubles are accepted as entry
// // and only the Date column is editable.
table.setDefaultEditor(Object.class, new TableCellEditor() {
JTextField m_textField = new JTextField();
int m_iRow, m_iCol;
@Override
public boolean stopCellEditing() {
// Log.warning.println("stopCellEditing()");
table.removeEditor();
String text = m_textField.getText();
try {
Double.parseDouble(text);
} catch (Exception e) {
return false;
}
tableData[m_iRow][m_iCol] = text;
return true;
}
@Override
public boolean isCellEditable(EventObject anEvent) {
// Log.warning.println("isCellEditable()");
return table.getSelectedColumn() == 0;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowNr, int colNr) {
return null;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return false;
}
@Override
public void removeCellEditorListener(CellEditorListener l) {
}
@Override
public Object getCellEditorValue() {
return null;
}
@Override
public void cancelCellEditing() {
}
@Override
public void addCellEditorListener(CellEditorListener l) {
}
});
// show alignment viewer when double clicking a row
table.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
try {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int best = 0;
BeautiAlignmentProvider provider = null;
for (BeautiAlignmentProvider provider2 : doc.beautiConfig.alignmentProvider) {
int match = provider2.matches(alignment);
if (match > best) {
best = match;
provider = provider2;
}
}
provider.editAlignment(alignment, doc);
} catch (Exception e1) {
e1.printStackTrace();
}
updateStatus();
} else if (e.getButton() == e.BUTTON3) {
int alignmemt = table.rowAtPoint(e.getPoint());
Alignment alignment = alignments.get(alignmemt);
int result = JOptionPane.showConfirmDialog(null, "Do you want to replace alignment " + alignment.getID());
if (result == JOptionPane.YES_OPTION) {
replaceItem(alignment);
}
}
}
});
scrollPane = new JScrollPane(table);
int rowsToDisplay = 3;
Dimension d = table.getPreferredSize();
scrollPane.setPreferredSize(new Dimension(d.width, table.getRowHeight() * rowsToDisplay + table.getTableHeader().getHeight()));
return scrollPane;
}
use of java.awt.event.MouseListener in project triplea by triplea-game.
the class ChatMessagePanel method createComponents.
private void createComponents() {
text = new JTextPane();
text.setEditable(false);
text.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(final MouseEvent e) {
final String markedText = text.getSelectedText();
if (markedText == null || markedText.length() == 0) {
nextMessage.requestFocusInWindow();
}
}
@Override
public void mousePressed(final MouseEvent e) {
}
@Override
public void mouseExited(final MouseEvent e) {
}
@Override
public void mouseEntered(final MouseEvent e) {
}
@Override
public void mouseClicked(final MouseEvent e) {
}
});
nextMessage = new JTextField(10);
// when enter is pressed, send the message
setStatus = new JButton(setStatusAction);
setStatus.setFocusable(false);
final Insets inset = new Insets(3, 3, 3, 3);
send = new JButton(SwingAction.of("Send", e -> sendMessage()));
send.setMargin(inset);
send.setFocusable(false);
}
use of java.awt.event.MouseListener in project triplea by triplea-game.
the class LobbyGamePanel method setupListeners.
private void setupListeners() {
hostGame.addActionListener(e -> hostGame());
joinGame.addActionListener(e -> joinGame());
bootGame.addActionListener(e -> bootGame());
gameTable.getSelectionModel().addListSelectionListener(e -> setWidgetActivation());
gameTable.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
joinGame();
}
mouseOnGamesList(e);
}
@Override
public void mousePressed(final MouseEvent e) {
// right clicks do not 'select' a row by default. so force a row selection at the mouse point.
final int r = gameTable.rowAtPoint(e.getPoint());
if (r >= 0 && r < gameTable.getRowCount()) {
gameTable.setRowSelectionInterval(r, r);
} else {
gameTable.clearSelection();
}
mouseOnGamesList(e);
}
@Override
public void mouseReleased(final MouseEvent e) {
mouseOnGamesList(e);
}
@Override
public void mouseEntered(final MouseEvent e) // ignore
{
}
@Override
public void mouseExited(final MouseEvent e) // ignore
{
}
});
}
use of java.awt.event.MouseListener in project opt4j by felixreimann.
the class PropertyPanel method addReferenceRow.
/**
* Adds a row showing the {@link Citation}. On the left hand side, "reference" is printed while on the right hand
* side, the {@link Citation} is added in a static {@link TextArea}.
*
* @param citation
* the citation to add
*/
protected void addReferenceRow(Citation citation) {
JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
JLabel label = new JLabel("reference");
label.setFocusable(false);
labelPanel.add(label);
panel.add(labelPanel);
final JTextArea field = new JTextArea();
field.setLineWrap(true);
field.setWrapStyleWord(true);
field.setFont(label.getFont());
field.setBackground(label.getBackground());
field.setEditable(false);
field.setText(Format.formatJava(citation));
if (!citation.doi().isEmpty()) {
final String doi = citation.doi();
field.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
field.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
try {
Desktop.getDesktop().browse(new URI("https://doi.org/" + doi));
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
}
});
}
JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(BorderLayout.NORTH, field);
rightPanel.setPreferredSize(new Dimension((int) (panel.getPreferredSize().width * 0.70), panel.getPreferredSize().height));
panel.add(rightPanel);
}
use of java.awt.event.MouseListener in project TrakEM2 by trakem2.
the class Tree method openImage.
/**
* Open an image in a separate thread and returns the thread. Frees up to 1 Gb for it.
*/
private Future<ImagePlus> openImage(final String path, final Node<T> last) {
return project.getLoader().doLater(new Callable<ImagePlus>() {
@Override
public ImagePlus call() {
try {
if (!new File(path).exists()) {
Utils.log("Could not find file " + path);
return null;
}
// 1 Gb : can't tell for jpegs and tif-jpg, TODO would have to read the header.
project.getLoader().releaseToFit(1000000000L);
final Opener op = new Opener();
op.setSilentMode(true);
// TODO WARNING should go via the Loader
final ImagePlus imp = op.openImage(path);
if (null == imp) {
Utils.log("ERROR: could not open " + path);
} else {
final StackWindow stack = new StackWindow(imp);
final MouseListener[] ml = stack.getCanvas().getMouseListeners();
for (final MouseListener m : ml) stack.getCanvas().removeMouseListener(m);
stack.getCanvas().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent me) {
if (2 == me.getClickCount()) {
me.consume();
// Go to the node
// Slices are 1-based: 1<=i<=N
final int slice = imp.getCurrentSlice();
if (slice == imp.getNSlices()) {
Display.centerAt(createCoordinate(last));
} else {
Node<T> parent = last.getParent();
int count = imp.getNSlices() - 1;
while (null != parent) {
if (count == slice) {
Display.centerAt(createCoordinate(parent));
break;
}
// next cycle
count--;
parent = parent.getParent();
}
;
}
}
}
@Override
public void mouseDragged(final MouseEvent me) {
if (2 == me.getClickCount()) {
me.consume();
}
}
@Override
public void mouseReleased(final MouseEvent me) {
if (2 == me.getClickCount()) {
me.consume();
}
}
});
for (final MouseListener m : ml) stack.getCanvas().addMouseListener(m);
}
return imp;
} catch (final Exception e) {
IJError.print(e);
}
return null;
}
});
}
Aggregations