use of java.awt.datatransfer.StringSelection in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method copyURLSelectedFile.
private void copyURLSelectedFile() {
BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
StringSelection selection = new StringSelection(fileSelection.getUri());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}
}
use of java.awt.datatransfer.StringSelection in project azure-tools-for-java by Microsoft.
the class ProjectUtil method createSparkSDKTipsPanel.
public static JPanel createSparkSDKTipsPanel() {
final JPanel panel = new JPanel();
GridBagLayout layout = new GridBagLayout();
JLabel[] labels = new JLabel[] { new JLabel("You can either download Spark library from"), new JLabel("<HTML><FONT color=\"#000099\"><U>here</U></FONT>,</HTML>"), new JLabel("or add Apache Spark packages from Maven repository in the project manually.") };
for (int i = 0; i < labels.length; ++i) {
panel.add(labels[i]);
}
labels[1].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labels[1].setToolTipText(downloadSparkSDKUrl);
labels[1].addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
StringSelection stringSelection = new StringSelection(downloadSparkSDKUrl);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
JOptionPane.showMessageDialog(panel, "Already copy Download URL to Clipboard");
} else if (SwingUtilities.isLeftMouseButton(e)) {
try {
URI uri = new URI(downloadSparkSDKUrl);
Desktop.getDesktop().browse(uri);
} catch (Exception exception) {
DefaultLoader.getUIHelper().showError(exception.getMessage(), exception.getClass().getName());
}
}
}
});
GridBagConstraints constraints = new GridBagConstraints(GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
layout.setConstraints(labels[0], constraints);
layout.setConstraints(labels[1], constraints);
layout.setConstraints(labels[2], constraints);
JPanel mainPanel = new JPanel();
GridBagLayout mainLayout = new GridBagLayout();
mainPanel.setLayout(mainLayout);
mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
//make sure label message on the head of left
mainPanel.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
return mainPanel;
}
use of java.awt.datatransfer.StringSelection in project cloudstack by apache.
the class VncServerPacketReceiver method serverCutText.
/**
* Handle packet with server clip-board.
*/
private void serverCutText(DataInputStream is) throws IOException {
ServerCutText clipboardContent = new ServerCutText(is);
StringSelection contents = new StringSelection(clipboardContent.getContent());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
s_logger.info("Server clipboard buffer: " + clipboardContent.getContent());
}
use of java.awt.datatransfer.StringSelection in project adempiere by adempiere.
the class VTableExcelAdapter method actionPerformed.
/**
* This method is activated on the Keystrokes we are listening to
* in this implementation. Here it listens for Copy and Paste ActionCommands.
*
* @param e event
*/
public void actionPerformed(ActionEvent e) {
// Only GridTable model is supported
if (!(table.getModel() instanceof GridTable)) {
if (CLogMgt.isLevelFine())
log.fine("Not supported - " + table.getModel());
return;
}
boolean isCopy = CMD_Copy.equals(e.getActionCommand());
boolean isCopyWithHeaders = CMD_CopyWithHeaders.equals(e.getActionCommand());
if (isCopy || isCopyWithHeaders) {
try {
int[] selectedRows = table.getSelectedRows();
if (selectedRows == null || selectedRows.length == 0) {
return;
}
int colscount = table.getColumnCount();
StringBuffer sb = new StringBuffer();
GridTable model = (GridTable) table.getModel();
GridField[] fields = model.getFields();
// Header
if (isCopyWithHeaders) {
for (int col = 0; col < colscount; col++) {
String value = "";
try {
GridField field = fields[col];
if (!field.isDisplayed(false)) {
continue;
}
value = field.getHeader();
} catch (Exception ex) {
log.log(Level.WARNING, "Copy-headers", ex);
}
value = fixString(value);
sb.append(value).append("\t");
}
sb.append(Env.NL);
}
// Selected rows
for (int row : selectedRows) {
for (int col = 0; col < colscount; col++) {
Lookup lookup = null;
String value = null;
Object key = null;
GridField field = null;
try {
key = table.getValueAt(row, col);
field = fields[col];
if (!field.isDisplayed(false))
continue;
if (field.isEncryptedColumn() || field.isEncryptedField()) {
value = "*";
} else if (key instanceof Boolean) {
value = Msg.getMsg(Env.getCtx(), ((Boolean) key).booleanValue() ? "Yes" : "No");
} else if (key instanceof BigDecimal) {
try {
value = sysNumberFormat.format(key != null ? key : Env.ZERO);
} catch (Exception ex) {
}
} else if (key instanceof Date) {
try {
value = sysDateFormat.format(key);
} catch (Exception ex) {
}
} else {
lookup = (field != null ? field.getLookup() : null);
value = (lookup != null && key != null ? lookup.getDisplay(key) : null);
if (value == null && key != null)
value = key.toString();
}
} catch (Exception ex) {
log.log(Level.WARNING, "Copy-rows", ex);
}
value = fixString(value);
sb.append(value).append("\t");
if (CLogMgt.isLevelFinest())
log.finest("col=" + col + ", row=" + row + ": key=" + key + " => value=" + value + ", " + field + ", " + lookup);
}
sb.append(Env.NL);
}
StringSelection stsel = new StringSelection(sb.toString());
system = Toolkit.getDefaultToolkit().getSystemClipboard();
system.setContents(stsel, stsel);
} catch (Exception ex) {
log.log(Level.WARNING, "Copy", ex);
}
}
}
use of java.awt.datatransfer.StringSelection in project pcgen by PCGen.
the class NameGenPanel method jButton1ActionPerformed.
//GEN-END:initComponents
private void jButton1ActionPerformed(ActionEvent evt) {
//GEN-FIRST:event_jButton1ActionPerformed
Clipboard cb = getToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(name.getText());
cb.setContents(ss, ss);
}
Aggregations