mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -04:00
adds also a copy handler for the data editor, closes #719
This commit is contained in:
parent
f855750e5f
commit
b20673c27e
@ -25,6 +25,7 @@ import javax.swing.table.TableModel;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.datatransfer.Clipboard;
|
import java.awt.datatransfer.Clipboard;
|
||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
@ -42,7 +43,9 @@ public class DataEditor extends JDialog {
|
|||||||
private static final Color MYGRAY = new Color(230, 230, 230);
|
private static final Color MYGRAY = new Color(230, 230, 230);
|
||||||
private static File lastUsedFileName;
|
private static File lastUsedFileName;
|
||||||
private final ValueFormatter addrFormat;
|
private final ValueFormatter addrFormat;
|
||||||
|
private final ValueFormatter dataFormat;
|
||||||
private final int addrBits;
|
private final int addrBits;
|
||||||
|
private final int dataBits;
|
||||||
private final DataField localDataField;
|
private final DataField localDataField;
|
||||||
private final JTable table;
|
private final JTable table;
|
||||||
private boolean ok = false;
|
private boolean ok = false;
|
||||||
@ -64,6 +67,8 @@ public class DataEditor extends JDialog {
|
|||||||
super(SwingUtilities.windowForComponent(parent), Lang.get("key_Data"), modelIsRunning ? ModalityType.MODELESS : ModalityType.APPLICATION_MODAL);
|
super(SwingUtilities.windowForComponent(parent), Lang.get("key_Data"), modelIsRunning ? ModalityType.MODELESS : ModalityType.APPLICATION_MODAL);
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
this.addrBits = addrBits;
|
this.addrBits = addrBits;
|
||||||
|
this.dataBits = dataBits;
|
||||||
|
this.dataFormat = dataFormat;
|
||||||
if (dataFormat.isSuitedForAddresses())
|
if (dataFormat.isSuitedForAddresses())
|
||||||
addrFormat = dataFormat;
|
addrFormat = dataFormat;
|
||||||
else
|
else
|
||||||
@ -194,6 +199,17 @@ public class DataEditor extends JDialog {
|
|||||||
}
|
}
|
||||||
}.setAcceleratorCTRLplus('V').enableAcceleratorIn(table);
|
}.setAcceleratorCTRLplus('V').enableAcceleratorIn(table);
|
||||||
|
|
||||||
|
new ToolTipAction(Lang.get("menu_copy")) {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
int[] rows = table.getSelectedRows();
|
||||||
|
if (rows.length > 0) {
|
||||||
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
clipboard.setContents(new DataTransferable(((MyTableModel) table.getModel()).toString(rows)), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.setAcceleratorCTRLplus('C').enableAcceleratorIn(table);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
if (getWidth() < 150)
|
if (getWidth() < 150)
|
||||||
setSize(new Dimension(150, getHeight()));
|
setSize(new Dimension(150, getHeight()));
|
||||||
@ -377,6 +393,20 @@ public class DataEditor extends JDialog {
|
|||||||
fireEvent(new TableModelEvent(this, addr / cols));
|
fireEvent(new TableModelEvent(this, addr / cols));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString(int[] rows) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int r : rows) {
|
||||||
|
int offs = r * cols;
|
||||||
|
sb.append(addrFormat.formatToEdit(new Value(offs, addrBits)));
|
||||||
|
for (int c = 0; c < cols; c++) {
|
||||||
|
long val = dataField.getDataWord(offs + c);
|
||||||
|
sb.append("\t").append(dataFormat.formatToEdit(new Value(val, dataBits)));
|
||||||
|
}
|
||||||
|
sb.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class MyRenderer extends DefaultTableCellRenderer {
|
private static final class MyRenderer extends DefaultTableCellRenderer {
|
||||||
@ -499,4 +529,30 @@ public class DataEditor extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class DataTransferable implements Transferable {
|
||||||
|
private final String data;
|
||||||
|
|
||||||
|
private DataTransferable(String data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{DataFlavor.stringFlavor};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor == DataFlavor.stringFlavor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (!isDataFlavorSupported(flavor))
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user