List of usage examples for java.awt.datatransfer Clipboard setContents
public synchronized void setContents(Transferable contents, ClipboardOwner owner)
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public void doCopy() { // if (focusedPlot != null) { // focusedPlot.doCopy(); // }//from www . jav a2 s . c om final Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Cursor currentCursor = getCursor(); setCursor(StaticValues.WAIT_CURSOR); // Rectangle2D plotArea = getBounds(); final CompositePlotTransferable selection = new CompositePlotTransferable(this); if (selection != null) { systemClipboard.setContents(selection, null); } setCursor(currentCursor); }
From source file:de.codesourcery.eve.skills.ui.components.impl.AssetListComponent.java
@Override protected JPanel createPanel() { // Merge controls. final JPanel mergeControlsPanel = new JPanel(); mergeControlsPanel.setLayout(new GridBagLayout()); mergeControlsPanel.setBorder(BorderFactory.createTitledBorder("Merging")); int y = 0;//w w w . jav a 2 s . c o m // merge by type mergeAssetsByType.setSelected(true); mergeAssetsByType.addActionListener(actionListener); mergeControlsPanel.add(mergeAssetsByType, constraints(0, y).anchorWest().end()); mergeControlsPanel.add(new JLabel("Merge assets by type", SwingConstants.LEFT), constraints(1, y++).width(2).end()); // "ignore different packaging" ignorePackaging.setSelected(true); ignorePackaging.addActionListener(actionListener); mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end()); mergeControlsPanel.add(ignorePackaging, constraints(1, y).anchorWest().end()); final JLabel label1 = new JLabel("Merge different packaging", SwingConstants.RIGHT); mergeControlsPanel.add(label1, constraints(2, y++).end()); // "ignore different locations" ignoreLocations.setSelected(true); ignoreLocations.addActionListener(actionListener); mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end()); mergeControlsPanel.add(ignoreLocations, constraints(1, y).anchorWest().end()); final JLabel label2 = new JLabel("Merge different locations", SwingConstants.RIGHT); mergeControlsPanel.add(label2, constraints(2, y++).end()); linkComponentEnabledStates(mergeAssetsByType, ignoreLocations, ignorePackaging, label1, label2); /* * Filter controls. */ final JPanel filterControlsPanel = new JPanel(); filterControlsPanel.setLayout(new GridBagLayout()); filterControlsPanel.setBorder(BorderFactory.createTitledBorder("Filters")); y = 0; // filter by location combo box filterByLocation.addActionListener(actionListener); locationComboBox.addActionListener(actionListener); filterByLocation.setSelected(false); linkComponentEnabledStates(filterByLocation, locationComboBox); locationComboBox.setRenderer(new LocationRenderer()); locationComboBox.setPreferredSize(new Dimension(150, 20)); locationComboBox.setModel(locationModel); filterControlsPanel.add(filterByLocation, constraints(0, y).end()); filterControlsPanel.add(locationComboBox, constraints(1, y++).end()); // filter by type combo box filterByType.addActionListener(actionListener); typeComboBox.addActionListener(actionListener); filterByType.setSelected(false); linkComponentEnabledStates(filterByType, typeComboBox); typeComboBox.setPreferredSize(new Dimension(150, 20)); typeComboBox.setModel(typeModel); filterControlsPanel.add(filterByType, constraints(0, y).end()); filterControlsPanel.add(typeComboBox, constraints(1, y++).end()); // filter by item category combobox filterByCategory.addActionListener(actionListener); categoryComboBox.addActionListener(actionListener); categoryComboBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setText(getDisplayName((InventoryCategory) value)); setEnabled(categoryComboBox.isEnabled()); return this; } }); filterByCategory.setSelected(false); linkComponentEnabledStates(filterByCategory, categoryComboBox); categoryComboBox.setPreferredSize(new Dimension(150, 20)); categoryComboBox.setModel(categoryModel); filterControlsPanel.add(filterByCategory, constraints(0, y).end()); filterControlsPanel.add(categoryComboBox, constraints(1, y++).end()); // filter by item group combobox filterByGroup.addActionListener(actionListener); groupComboBox.addActionListener(actionListener); filterByGroup.setSelected(false); linkComponentEnabledStates(filterByGroup, groupComboBox); groupComboBox.setPreferredSize(new Dimension(150, 20)); groupComboBox.setModel(groupModel); filterControlsPanel.add(filterByGroup, constraints(0, y).end()); filterControlsPanel.add(groupComboBox, constraints(1, y++).end()); /* * Table panel. */ table = new JTable() { @Override public TableCellRenderer getCellRenderer(int row, int column) { // subclassing hack is needed because table // returns different renderes depending on column type final TableCellRenderer result = super.getCellRenderer(row, column); return new TableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component comp = result.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); final int modelRow = table.convertRowIndexToModel(row); final Asset asset = model.getRow(modelRow); final StringBuilder label = new StringBuilder("<HTML><BODY>"); label.append(asset.getItemId() + " - flags: " + asset.getFlags() + "<BR>"); if (asset.hasMultipleLocations()) { label.append("<BR>"); for (ILocation loc : asset.getLocations()) { label.append(loc.getDisplayName()).append("<BR>"); } } label.append("</BODY></HTML>"); ((JComponent) comp).setToolTipText(label.toString()); return comp; } }; } }; model.setViewFilter(this.viewFilter); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelectedVolume(); } }); FixedBooleanTableCellRenderer.attach(table); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setModel(model); table.setBorder(BorderFactory.createLineBorder(Color.BLACK)); table.setRowSorter(model.getRowSorter()); popupMenuBuilder.addItem("Refine...", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } final ICharacter c = selectionProvider.getSelectedItem(); final RefiningComponent comp = new RefiningComponent(c); comp.setItemsToRefine(assets); ComponentWrapper.wrapComponent("Refining", comp).setVisible(true); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); popupMenuBuilder.addItem("Copy selection to clipboard (text)", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } new PlainTextTransferable(toPlainText(assets)).putOnClipboard(); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); popupMenuBuilder.addItem("Copy selection to clipboard (CSV)", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new PlainTextTransferable(toCsv(assets)), null); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.popupMenuBuilder.attach(table); final JScrollPane scrollPane = new JScrollPane(table); /* * Name filter */ final JPanel nameFilterPanel = new JPanel(); nameFilterPanel.setLayout(new GridBagLayout()); nameFilterPanel.setBorder(BorderFactory.createTitledBorder("Filter by name")); nameFilterPanel.setPreferredSize(new Dimension(150, 70)); nameFilter.setColumns(10); nameFilter.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { model.viewFilterChanged(); } @Override public void insertUpdate(DocumentEvent e) { model.viewFilterChanged(); } @Override public void removeUpdate(DocumentEvent e) { model.viewFilterChanged(); } }); nameFilterPanel.add(nameFilter, constraints(0, 0).resizeHorizontally().end()); final JButton clearButton = new JButton("Clear"); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { nameFilter.setText(null); } }); nameFilterPanel.add(clearButton, constraints(1, 0).noResizing().end()); // Selected volume final JPanel selectedVolumePanel = this.selectedVolume.getPanel(); // add control panels to result panel final JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); topPanel.add(mergeControlsPanel, constraints(0, 0).height(2).weightX(0).anchorWest().end()); topPanel.add(filterControlsPanel, constraints(1, 0).height(2).anchorWest().weightX(0).end()); topPanel.add(nameFilterPanel, constraints(2, 0).height(1).anchorWest().useRemainingWidth().end()); topPanel.add(selectedVolumePanel, constraints(2, 1).height(1).anchorWest().useRemainingWidth().end()); final JSplitPane splitPane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, scrollPane); splitPane.setDividerLocation(0.3d); final JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); content.add(splitPane, constraints().resizeBoth().useRemainingSpace().end()); return content; }
From source file:org.rdv.viz.chart.ChartViz.java
/** * Takes the chart and puts it on the clipboard as an image. *//* www . j av a 2 s .co m*/ private void copyChart() { // get the system clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // create an image of the chart with the preferred dimensions Dimension preferredDimension = chartPanel.getPreferredSize(); Image image = chart.createBufferedImage((int) preferredDimension.getWidth(), (int) preferredDimension.getHeight()); // wrap image in the transferable and put on the clipboard ImageSelection contents = new ImageSelection(image); clipboard.setContents(contents, null); }
From source file:de.codesourcery.eve.skills.ui.components.impl.OreChartComponent.java
protected void saveSummaryToClipboard() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); final StringBuffer buffer = new StringBuffer(); buffer.append("Current date: " + DateHelper.format(new Date()) + "\n"); buffer.append("Region: " + getDefaultRegion().getName() + "\n"); buffer.append("\n"); for (int i = 0; i < mineralPriceTableModel.getRowCount(); i++) { final MineralPrice minPrice = mineralPriceTableModel.getRow(i); buffer.append(StringUtils.rightPad(minPrice.itemName(), 13)).append(" : "); buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(minPrice.getSellPrice()), 10) + " ISK"); buffer.append("\n"); }// w ww . j av a2 s .c om buffer.append("\n"); final List<CsvRow> data = new ArrayList<CsvRow>(); for (int i = 0; i < tableModel.getRowCount(); i++) { final TableRow row = tableModel.getRow(i); final ISKAmount amount = tableModel.getISKperM3(row); data.add(new CsvRow(row.oreName, amount)); } Collections.sort(data); for (CsvRow r : data) { buffer.append(StringUtils.rightPad(r.oreName, 13)).append(" : "); buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(r.iskPerM3), 10) + " ISK / m3"); buffer.append("\n"); } clipboard.setContents(new PlainTextTransferable(buffer.toString()), null); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Creates an instance of <tt>ChatConversationPanel</tt>. * * @param chatContainer The parent <tt>ChatConversationContainer</tt>. *//*from w w w . j av a 2 s. c o m*/ public ChatConversationPanel(ChatConversationContainer chatContainer) { editorKit = new ChatConversationEditorKit(this); this.chatContainer = chatContainer; isHistory = (chatContainer instanceof HistoryWindow); this.rightButtonMenu = new ChatRightButtonMenu(this); this.document = (HTMLDocument) editorKit.createDefaultDocument(); this.document.addDocumentListener(editorKit); this.chatTextPane.setEditorKitForContentType("text/html", editorKit); this.chatTextPane.setEditorKit(editorKit); this.chatTextPane.setEditable(false); this.chatTextPane.setDocument(document); this.chatTextPane.setDragEnabled(true); chatTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); Constants.loadSimpleStyle(document.getStyleSheet(), chatTextPane.getFont()); this.chatTextPane.addHyperlinkListener(this); this.chatTextPane.addMouseListener(this); this.chatTextPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); this.addChatLinkClickedListener(showPreview); this.setWheelScrollingEnabled(true); this.setViewportView(chatTextPane); this.setBorder(null); this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); ToolTipManager.sharedInstance().registerComponent(chatTextPane); String copyLinkString = GuiActivator.getResources().getI18NString("service.gui.COPY_LINK"); copyLinkItem = new JMenuItem(copyLinkString, new ImageIcon(ImageLoader.getImage(ImageLoader.COPY_ICON))); copyLinkItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { StringSelection stringSelection = new StringSelection(currentHref); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, ChatConversationPanel.this); } }); String openLinkString = GuiActivator.getResources().getI18NString("service.gui.OPEN_IN_BROWSER"); openLinkItem = new JMenuItem(openLinkString, new ImageIcon(ImageLoader.getImage(ImageLoader.BROWSER_ICON))); openLinkItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GuiActivator.getBrowserLauncher().openURL(currentHref); // after opening the link remove the currentHref to avoid // clicking on the window to gain focus to open the link again ChatConversationPanel.this.currentHref = ""; } }); openLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.OPEN_IN_BROWSER")); copyLinkItem.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.COPY_LINK")); configureReplacementItem = new JMenuItem( GuiActivator.getResources().getI18NString("plugin.chatconfig.replacement.CONFIGURE_REPLACEMENT"), GuiActivator.getResources().getImage("service.gui.icons.CONFIGURE_ICON")); configureReplacementItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final ConfigurationContainer configContainer = GuiActivator.getUIService() .getConfigurationContainer(); ConfigurationForm chatConfigForm = getChatConfigForm(); if (chatConfigForm != null) { configContainer.setSelected(chatConfigForm); configContainer.setVisible(true); } } }); this.isSimpleTheme = ConfigurationUtils.isChatSimpleThemeEnabled(); /* * When we append a new message (regardless of whether it is a string or * an UI component), we want to make it visible in the viewport of this * JScrollPane so that the user can see it. */ ComponentListener componentListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { synchronized (scrollToBottomRunnable) { if (!scrollToBottomIsPending) return; scrollToBottomIsPending = false; /* * Yana Stamcheva, pointed out that Java 5 (on Linux only?) * needs invokeLater for JScrollBar. */ SwingUtilities.invokeLater(scrollToBottomRunnable); } } }; chatTextPane.addComponentListener(componentListener); getViewport().addComponentListener(componentListener); }
From source file:ru.goodfil.catalog.ui.forms.CarsPanel.java
private void miCopyToExcelActionPerformed(ActionEvent e) { StringBuilder sb = new StringBuilder(); if (listsPopupMenu.getInvoker() == vechicleTypesList) { for (VechicleType vechicleType : vechicleTypes) { sb.append(String.format("%s\n", vechicleType.getName())); }// w w w .j ava 2 s . c o m } if (listsPopupMenu.getInvoker() == manufactorsList) { for (Manufactor manufactor : manufactors) { sb.append(String.format("%s\n", manufactor.getName())); } } if (listsPopupMenu.getInvoker() == seriesList) { for (Seria seria : series) { sb.append(String.format("%s\n", seria.getName())); } } if (listsPopupMenu.getInvoker() == motorsTable) { SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); for (Motor motor : motors) { String dateF = motor.getDateF() != null ? sdf.format(motor.getDateF()) : ""; String dateT = motor.getDateT() != null ? sdf.format(motor.getDateT()) : ""; sb.append(String.format("%s\t%s\t%s\t%s\t%s\t%s\n", motor.getName(), motor.getEngine(), motor.getKw(), motor.getHp(), dateF, dateT)); } } if (listsPopupMenu.getInvoker() == filtersTable) { for (Filter filter : filters) { sb.append(String.format("%s\t%s\n", filter.getName(), filterTypeResolver.resolve(filter.getFilterTypeCode()))); } } if (listsPopupMenu.getInvoker() == allFiltersTable) { for (Filter filter : allFilters) { sb.append(String.format("%s\t%s\n", filter.getName(), filterTypeResolver.resolve(filter.getFilterTypeCode()))); } } if (!StringUtils.isBlank(sb.toString())) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(sb.toString()), this); String text = " ? . ? Microsoft Excel."; UIUtils.info(text); } }
From source file:ded.ui.DiagramController.java
/** Copy the selected entities to the (application) clipboard. */ public void copySelected() { IdentityHashSet<Controller> selControllers = this.getAllSelected(); if (selControllers.isEmpty()) { this.errorMessageBox("Nothing is selected to copy."); return;/* w ww .ja v a 2s. c o m*/ } // Collect all the selected elements. IdentityHashSet<Entity> selEntities = new IdentityHashSet<Entity>(); IdentityHashSet<Inheritance> selInheritances = new IdentityHashSet<Inheritance>(); IdentityHashSet<Relation> selRelations = new IdentityHashSet<Relation>(); for (Controller c : selControllers) { if (c instanceof EntityController) { selEntities.add(((EntityController) c).entity); } if (c instanceof InheritanceController) { selInheritances.add(((InheritanceController) c).inheritance); } if (c instanceof RelationController) { selRelations.add(((RelationController) c).relation); } } // Map from elements in the original to their counterpart in the copy. IdentityHashMap<Entity, Entity> entityToCopy = new IdentityHashMap<Entity, Entity>(); IdentityHashMap<Inheritance, Inheritance> inheritanceToCopy = new IdentityHashMap<Inheritance, Inheritance>(); // Construct a new Diagram with just the selected elements. Diagram copy = new Diagram(); for (Entity e : selEntities) { Entity eCopy = new Entity(e); entityToCopy.put(e, eCopy); copy.entities.add(eCopy); } for (Inheritance i : selInheritances) { // See if the parent entity is among those we are copying. Entity parentCopy = entityToCopy.get(i.parent); if (parentCopy == null) { // No, so we'll skip the inheritance too. } else { Inheritance iCopy = new Inheritance(i, parentCopy); inheritanceToCopy.put(i, iCopy); copy.inheritances.add(iCopy); } } for (Relation r : selRelations) { RelationEndpoint startCopy = copyRelationEndpoint(r.start, entityToCopy, inheritanceToCopy); RelationEndpoint endCopy = copyRelationEndpoint(r.end, entityToCopy, inheritanceToCopy); if (startCopy == null || endCopy == null) { // Skip the relation. } else { copy.relations.add(new Relation(r, startCopy, endCopy)); } } // Make sure the Diagram is well-formed. try { // This is quadratic... copy.selfCheck(); } catch (Throwable t) { this.errorMessageBox("Internal error: failed to create a well-formed copy: " + t); return; } // Copy it as a string to the system clipboard. StringSelection data = new StringSelection(copy.toJSONString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(data, data); clipboard = Toolkit.getDefaultToolkit().getSystemSelection(); if (clipboard != null) { clipboard.setContents(data, data); } }
From source file:neembuu.uploader.NeembuuUploader.java
private void getLogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getLogButtonActionPerformed Path nuLogPath = Paths.get(System.getProperty("user.home") + File.separatorChar + ".neembuuuploader" + File.separatorChar + "nu.log"); try {//from ww w. j a v a2 s . c om String contents = new String(Files.readAllBytes(nuLogPath), StandardCharsets.UTF_8); StringSelection stringSelection = new StringSelection(contents); Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.huxhorn.lilith.swing.MainFrame.java
public static void copyText(String text) { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferableText = new StringSelection(text); systemClipboard.setContents(transferableText, null); }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void doCopy() { final Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Rectangle2D screenArea = getScreenDataArea(); final ChartTransferableWithMask selection = new ChartTransferableWithMask(getChart(), getWidth(), getHeight(), screenArea, maskList, shapeMap, textContentMap); //TODO: the below command take too long to run. 6 seconds for Wombat data. Cursor currentCursor = getCursor(); setCursor(WAIT_CURSOR);/*from w w w. j a va 2 s . com*/ systemClipboard.setContents(selection, null); setCursor(currentCursor); }