use of java.awt.datatransfer.Transferable in project android by JetBrains.
the class PTableTest method assertHasClipboardValue.
private void assertHasClipboardValue(@Nullable String value) throws Exception {
ArgumentCaptor<Transferable> captor = ArgumentCaptor.forClass(Transferable.class);
verify(myCopyPasteManager).setContents(captor.capture());
Transferable transferable = captor.getValue();
assertThat(transferable).isNotNull();
assertThat(transferable.isDataFlavorSupported(DataFlavor.stringFlavor)).isTrue();
assertThat(transferable.getTransferData(DataFlavor.stringFlavor)).isEqualTo(value);
}
use of java.awt.datatransfer.Transferable in project JMRI by JMRI.
the class RosterFrame method createTop.
JComponent createTop() {
Object selectedRosterGroup = prefsMgr.getProperty(getWindowFrameRef(), SELECTED_ROSTER_GROUP);
groups = new RosterGroupsPanel((selectedRosterGroup != null) ? selectedRosterGroup.toString() : null);
groups.setNewWindowMenuAction(this.getNewWindowAction());
setTitle(groups.getSelectedRosterGroup());
final JPanel rosters = new JPanel();
rosters.setLayout(new BorderLayout());
// set up roster table
rtable = new RosterTable(true, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
rtable.setRosterGroup(this.getSelectedRosterGroup());
rtable.setRosterGroupSource(groups);
rosters.add(rtable, BorderLayout.CENTER);
// add selection listener
rtable.getTable().getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
JTable table = rtable.getTable();
if (!e.getValueIsAdjusting()) {
if (rtable.getSelectedRosterEntries().length == 1 && table.getSelectedRow() >= 0) {
log.debug("Selected row ", table.getSelectedRow());
locoSelected(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()), RosterTableModel.IDCOL).toString());
} else if (rtable.getSelectedRosterEntries().length > 1 || table.getSelectedRow() < 0) {
locoSelected(null);
}
// leave last selected item visible if no selection
}
});
//Set all the sort and width details of the table first.
String rostertableref = getWindowFrameRef() + ":roster";
rtable.getTable().setName(rostertableref);
// Allow only one column to be sorted at a time -
// Java allows multiple column sorting, but to effectly persist that, we
// need to be intelligent about which columns can be meaningfully sorted
// with other columns; this bypasses the problem by only allowing the
// last column sorted to affect sorting
RowSorterUtil.addSingleSortableColumnListener(rtable.getTable().getRowSorter());
// Reset and then persist the table's ui state
JTablePersistenceManager tpm = InstanceManager.getNullableDefault(JTablePersistenceManager.class);
if (tpm != null) {
tpm.resetState(rtable.getTable());
tpm.persist(rtable.getTable());
}
rtable.getTable().setDragEnabled(true);
rtable.getTable().setTransferHandler(new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public Transferable createTransferable(JComponent c) {
JTable table = rtable.getTable();
ArrayList<String> Ids = new ArrayList<>(table.getSelectedRowCount());
for (int i = 0; i < table.getSelectedRowCount(); i++) {
Ids.add(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRows()[i]), RosterTableModel.IDCOL).toString());
}
return new RosterEntrySelection(Ids);
}
@Override
public void exportDone(JComponent c, Transferable t, int action) {
// nothing to do
}
});
MouseListener rosterMouseListener = new rosterPopupListener();
rtable.getTable().addMouseListener(rosterMouseListener);
try {
clickDelay = ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval"));
} catch (RuntimeException e) {
clickDelay = 500;
log.debug("Unable to get the double click speed, Using JMRI default of half a second" + e.toString());
}
// assemble roster/groups splitpane
rosterGroupSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, groups, rosters);
rosterGroupSplitPane.setOneTouchExpandable(true);
// emphasis rosters
rosterGroupSplitPane.setResizeWeight(0);
Object w = prefsMgr.getProperty(getWindowFrameRef(), "rosterGroupPaneDividerLocation");
if (w != null) {
groupSplitPaneLocation = (Integer) w;
rosterGroupSplitPane.setDividerLocation(groupSplitPaneLocation);
}
if (!Roster.getDefault().getRosterGroupList().isEmpty()) {
if (prefsMgr.getSimplePreferenceState(this.getClass().getName() + ".hideGroups")) {
hideGroupsPane(true);
}
} else {
enableRosterGroupMenuItems(false);
}
PropertyChangeListener propertyChangeListener = (PropertyChangeEvent changeEvent) -> {
JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
String propertyName = changeEvent.getPropertyName();
if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
hideGroups = current <= 1;
Integer last = (Integer) changeEvent.getNewValue();
if (current >= 2) {
groupSplitPaneLocation = current;
} else if (last >= 2) {
groupSplitPaneLocation = last;
}
}
};
groups.addPropertyChangeListener(SELECTED_ROSTER_GROUP, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
prefsMgr.setProperty(this.getClass().getName(), SELECTED_ROSTER_GROUP, pce.getNewValue());
setTitle((String) pce.getNewValue());
}
});
rosterGroupSplitPane.addPropertyChangeListener(propertyChangeListener);
Roster.getDefault().addPropertyChangeListener((PropertyChangeEvent e) -> {
if (e.getPropertyName().equals("RosterGroupAdded") && Roster.getDefault().getRosterGroupList().size() == 1) {
// if the pane is hidden, show it when 1st group is created
hideGroupsPane(false);
enableRosterGroupMenuItems(true);
} else if (!rtable.isVisible() && (e.getPropertyName().equals("saved"))) {
if (firstHelpLabel != null) {
firstHelpLabel.setVisible(false);
}
rtable.setVisible(true);
rtable.resetColumnWidths();
}
});
if (Roster.getDefault().numEntries() == 0) {
try {
BufferedImage myPicture = ImageIO.read(FileUtil.findURL(("resources/" + Bundle.getMessage("ThrottleFirstUseImage")), FileUtil.Location.INSTALLED));
//rosters.add(new JLabel(new ImageIcon( myPicture )), BorderLayout.CENTER);
firstHelpLabel = new JLabel(new ImageIcon(myPicture));
rtable.setVisible(false);
rosters.add(firstHelpLabel, BorderLayout.NORTH);
//tableArea.add(firstHelpLabel);
rtable.setVisible(false);
} catch (IOException ex) {
// handle exception...
}
}
return rosterGroupSplitPane;
}
use of java.awt.datatransfer.Transferable in project processdash by dtuma.
the class WBSClipSelection method getNodeListFromClipboard.
/** Interact with the system clipboard to retrieve a list of WBSNodes.
*
* @param prototype if the system clipboard contains plain text, a list
* of nodes modeled after this prototype will be returned.
*/
public static List getNodeListFromClipboard(WBSNode prototype) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = clipboard.getContents(prototype);
// on the clipboard).
try {
Object d = t.getTransferData(WBS_LIST_FLAVOR);
List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
if (result != null)
return result;
} catch (Exception e) {
}
// clipboard by some other WBS Editor.
try {
Object d = t.getTransferData(WBS_FLAVOR);
List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
if (result != null)
return result;
} catch (Exception e) {
}
// names, and create some ultra-simple nodes with those names.
try {
String plainText = (String) t.getTransferData(DataFlavor.stringFlavor);
String[] lines = plainText.split("\n");
int baseIndent = Math.max(1, prototype.getIndentLevel());
List result = new ArrayList();
for (int i = 0; i < lines.length; i++) {
Matcher m = PLAINTEXT_PATTERN.matcher(lines[i]);
if (!m.find())
continue;
String nodeName = scrubName(m.group(2)).trim();
int indent = baseIndent;
if (m.group(1) != null && m.group(1).length() > 0) {
Matcher mi = INDENT_PATTERN.matcher(m.group(1));
while (mi.find()) indent++;
}
WBSNode node = new WBSNode(prototype.getWbsModel(), nodeName, WBSNode.UNKNOWN_TYPE, indent, true);
result.add(node);
}
return result;
} catch (Exception e) {
}
// if all else fails, return null to indicate failure.
return null;
}
use of java.awt.datatransfer.Transferable in project cayenne by apache.
the class CayenneModelerController method initBindings.
protected void initBindings() {
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
PROJECT_STATE_UTIL.saveLastState(projectController);
getApplication().getActionManager().getAction(ExitAction.class).exit();
}
});
// This is in Mac OSX only.
if (System.getProperty("os.name").startsWith("Mac OS")) {
Runnable runner = new Runnable() {
@Override
public void run() {
PROJECT_STATE_UTIL.saveLastState(projectController);
}
};
Runtime.getRuntime().addShutdownHook(new Thread(runner, "Window Prefs Hook"));
}
new DropTarget(frame, new DropTargetAdapter() {
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(dtde.getDropAction());
Transferable transferable = dtde.getTransferable();
dtde.dropComplete(processDropAction(transferable));
}
});
ComponentGeometry geometry = new ComponentGeometry(frame.getClass(), null);
geometry.bind(frame, 1200, 720, 0);
}
use of java.awt.datatransfer.Transferable in project knime-core by knime.
the class SelectionPanel method drop.
/**
* {@inheritDoc}
*/
@Override
public void drop(final DropTargetDropEvent dtde) {
if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
dtde.acceptDrop(dtde.getDropAction());
Transferable t = dtde.getTransferable();
String s = "default";
try {
s = (String) t.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
int i = m_config.drop(s);
Pane dp = getNewPane(m_includePanel, m_config, i);
m_includePanel.add(dp.getComponentPanel(), m_gbc);
m_gbc.gridy++;
m_includePanel.setBackground(UIManager.getColor("Panel.background"));
m_scrollPane.revalidate();
dtde.dropComplete(true);
}
}
Aggregations