Skip to content

Commit

Permalink
Copy Content In Cell To Clipboard
Browse files Browse the repository at this point in the history
Lets users copy content in cells with a click.
  • Loading branch information
AvocadoMoon committed Nov 28, 2023
1 parent 989cac1 commit cebda9b
Showing 1 changed file with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
import org.vcell.util.document.VCDocument;

import javax.swing.*;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Enumeration;

public class ExportedDataViewer extends DocumentEditorSubPanel implements ActionListener, PropertyChangeListener {
public class ExportedDataViewer extends DocumentEditorSubPanel implements ActionListener, PropertyChangeListener, FocusListener, MouseListener {

private JScrollPane scrollPane;
private JTable exportLinksTable;
Expand All @@ -29,14 +31,18 @@ public ExportedDataViewer() {

String[] columns = {"Sim Name", "BioModel Name", "Sim ID", "Date Exported", "Date Sim Modified", "Format", "Link"};
DefaultTableModel tableModel = new DefaultTableModel(columns, 0);

tableModel.addRow(new Object[]{"Test Sim", "Bio Name", "1720480", "123", "123", "N5", "https://www.google.com"});
exportLinksTable = new JTable(tableModel);
exportLinksTable.setDefaultEditor(Object.class, null);
exportLinksTable.addMouseListener(this);
scrollPane = new JScrollPane(exportLinksTable);
scrollPane.setSize(400, 400);
scrollPane.setPreferredSize(new Dimension(400, 400));
scrollPane.setMinimumSize(new Dimension(400, 400));



this.setLayout(new BorderLayout());
this.add(scrollPane);

Expand Down Expand Up @@ -77,4 +83,43 @@ public void propertyChange(PropertyChangeEvent evt) {
protected void onSelectedObjectsChange(Object[] selectedObjects) {

}

@Override
public void focusGained(FocusEvent e) {

}

@Override
public void focusLost(FocusEvent e) {

}

@Override
public void mouseClicked(MouseEvent e) {
int row = exportLinksTable.getSelectedRow();
int column = exportLinksTable.getSelectedColumn();

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection( (String) exportLinksTable.getValueAt(row, column)), null);
}

@Override
public void mousePressed(MouseEvent e) {

}

@Override
public void mouseReleased(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {

}

@Override
public void mouseExited(MouseEvent e) {

}
}

0 comments on commit cebda9b

Please sign in to comment.