List of usage examples for java.awt.datatransfer StringSelection StringSelection
public StringSelection(String data)
From source file:net.sourceforge.pmd.util.designer.Designer.java
private void copyXmlToClipboard() { String xml = getXmlTreeCode(); if (xml != null) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(xml), this); }//w ww .j a v a 2s . c om }
From source file:com._17od.upm.gui.AccountDialog.java
/** * This method takes in a JTextArea object and then copies the selected text * in that text area to the system clipboard. * //from ww w. j a va2 s .co m * @param textArea */ public void copyTextArea(JTextArea textArea) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection selected = new StringSelection(textArea.getSelectedText()); clipboard.setContents(selected, selected); }
From source file:com.photon.phresco.framework.rest.api.UtilService.java
/** * Copy to clipboard.//from w w w. j a v a 2 s . co m * * @param content the content * @throws UnsupportedEncodingException */ private void copyToClipboard(String content) throws PhrescoException { try { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); String decodedContent = java.net.URLDecoder.decode(content, "UTF-8"); clipboard.setContents(new StringSelection(decodedContent.replaceAll("(?m)^[ \t]*\r?\n", "")), null); } catch (Exception e) { throw new PhrescoException(e); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
private boolean copyToInternalClipboard() { List<Attack> selection = getSelectedAttacks(); StringBuilder b = new StringBuilder(); int cnt = 0;/* w w w .j ava 2 s . c o m*/ for (Attack a : selection) { b.append(a.toInternalRepresentation()).append("\n"); cnt++; } try { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b.toString()), null); showSuccess(cnt + ((cnt == 1) ? " Angriff kopiert" : " Angriffe kopiert")); return true; } catch (HeadlessException hex) { showError("Fehler beim Kopieren der Angriffe"); return false; } }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
@Override public void dragGestureRecognized(DragGestureEvent dge) { TimeSpan span = null;/*w w w . j a va2 s. c o m*/ if (dge.getComponent().equals(jLabel5)) { span = getSendSpan(); } else if (dge.getComponent().equals(jLabel6)) { span = getArriveSpan(); } if (span != null) { dge.startDrag(null, new StringSelection(span.toPropertyString()), this); } }
From source file:net.sf.jabref.gui.BasePanel.java
private void copy() { List<BibEntry> bes = mainTable.getSelectedEntries(); if (bes.isEmpty()) { // The user maybe selected a single cell. // TODO: Check if this can actually happen int[] rows = mainTable.getSelectedRows(); int[] cols = mainTable.getSelectedColumns(); if ((cols.length == 1) && (rows.length == 1)) { // Copy single value. Object o = mainTable.getValueAt(rows[0], cols[0]); if (o != null) { StringSelection ss = new StringSelection(o.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this); output(Localization.lang("Copied cell contents") + '.'); }/*from w w w. j av a2 s .c om*/ } } else { TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes); // ! look at ClipBoardManager Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this); output(formatOutputMessage(Localization.lang("Copied"), bes.size())); } }
From source file:logdruid.ui.chart.GraphPanel.java
public void load(JPanel panel_2) { startDateJSpinner = (JSpinner) panel_2.getComponent(2); endDateJSPinner = (JSpinner) panel_2.getComponent(3); // scrollPane.setV panel.removeAll();//ww w. java 2 s . co m Dimension panelSize = this.getSize(); add(scrollPane, BorderLayout.CENTER); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // scrollPane.set trying to replace scroll where it was JCheckBox relativeCheckBox = (JCheckBox) panel_2.getComponent(5); estimatedTime = System.currentTimeMillis() - startTime; logger.info("gathering time: " + estimatedTime); startTime = System.currentTimeMillis(); // Map<Source, Map<String, MineResult>> Map<Source, Map<String, MineResult>> treeMap = new TreeMap<Source, Map<String, MineResult>>( mineResultSet.mineResults); Iterator mineResultSetIterator = treeMap.entrySet().iterator(); int ite = 0; logger.debug("mineResultSet size: " + mineResultSet.mineResults.size()); while (mineResultSetIterator.hasNext()) { final Map.Entry pairs = (Map.Entry) mineResultSetIterator.next(); logger.debug("mineResultSet key/source: " + ((Source) pairs.getKey()).getSourceName()); JCheckBox checkBox = (JCheckBox) panel_1.getComponent(ite++); logger.debug("checkbox: " + checkBox.getText() + ", " + checkBox.isSelected()); if (checkBox.isSelected()) { Map mrArrayList = (Map<String, MineResult>) pairs.getValue(); ArrayList<String> mineResultGroup = new ArrayList<String>(); Set<String> mrss = mrArrayList.keySet(); mineResultGroup.addAll(mrss); Collections.sort(mineResultGroup, new AlphanumComparator()); Iterator mrArrayListIterator = mineResultGroup.iterator(); while (mrArrayListIterator.hasNext()) { String key = (String) mrArrayListIterator.next(); logger.debug(key); final MineResult mr = (MineResult) mrArrayList.get(key); Map<String, ExtendedTimeSeries> statMap = mr.getStatTimeseriesMap(); Map<String, ExtendedTimeSeries> eventMap = mr.getEventTimeseriesMap(); // logger.info("mineResultSet hash size: " // +mr.getTimeseriesMap().size()); // logger.info("mineResultSet hash content: " + // mr.getStatTimeseriesMap()); logger.debug("mineResultSet mr.getStartDate(): " + mr.getStartDate() + " mineResultSet mr.getEndDate(): " + mr.getEndDate()); logger.debug("mineResultSet (Date)jsp.getValue(): " + (Date) startDateJSpinner.getValue()); logger.debug("mineResultSet (Date)jsp2.getValue(): " + (Date) endDateJSPinner.getValue()); if (mr.getStartDate() != null && mr.getEndDate() != null) { if ((mr.getStartDate().before((Date) endDateJSPinner.getValue())) && (mr.getEndDate().after((Date) startDateJSpinner.getValue()))) { ArrayList<String> mineResultGroup2 = new ArrayList<String>(); Set<String> mrss2 = statMap.keySet(); mineResultGroup2.addAll(mrss2); Collections.sort(mineResultGroup2, new AlphanumComparator()); Iterator statMapIterator = mineResultGroup2.iterator(); // Iterator statMapIterator = statMap.entrySet().iterator(); if (!statMap.entrySet().isEmpty() || !eventMap.entrySet().isEmpty()) { JPanel checkboxPanel = new JPanel(new WrapLayout()); checkboxPanel.setBackground(Color.white); int count = 1; chart = ChartFactory.createXYAreaChart(// Title mr.getSourceID() + " " + mr.getGroup(), // + null, // X-Axis // label null, // Y-Axis label null, // Dataset PlotOrientation.VERTICAL, false, // Show // legend true, // tooltips false // url ); TextTitle my_Chart_title = new TextTitle(mr.getSourceID() + " " + mr.getGroup(), new Font("Verdana", Font.BOLD, 17)); chart.setTitle(my_Chart_title); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis range = plot.getRangeAxis(); range.setVisible(false); final DateAxis domainAxis1 = new DateAxis(); domainAxis1.setTickLabelsVisible(true); // domainAxis1.setTickMarksVisible(true); logger.debug("getRange: " + domainAxis1.getRange()); if (relativeCheckBox.isSelected()) { domainAxis1.setRange((Date) startDateJSpinner.getValue(), (Date) endDateJSPinner.getValue()); } else { Date startDate = mr.getStartDate(); Date endDate = mr.getEndDate(); if (mr.getStartDate().before((Date) startDateJSpinner.getValue())) { startDate = (Date) startDateJSpinner.getValue(); logger.debug("setMinimumDate: " + (Date) startDateJSpinner.getValue()); } if (mr.getEndDate().after((Date) endDateJSPinner.getValue())) { endDate = (Date) endDateJSPinner.getValue(); logger.debug("setMaximumDate: " + (Date) endDateJSPinner.getValue()); } if (startDate.before(endDate)) { domainAxis1.setRange(startDate, endDate); } } XYToolTipGenerator tt1 = new XYToolTipGenerator() { public String generateToolTip(XYDataset dataset, int series, int item) { StringBuffer sb = new StringBuffer(); String htmlStr = "<html>"; Number x; FastDateFormat sdf = FastDateFormat.getInstance("dd-MMM-yyyy HH:mm:ss"); x = dataset.getX(series, item); sb.append(htmlStr); if (x != null) { sb.append("<p style='color:#000000;'>" + (sdf.format(x)) + "</p>"); sb.append("<p style='color:#000000;'>" + dataset.getSeriesKey(series).toString() + ": " + form.format(dataset.getYValue(0, item)) + "</p>"); if (mr.getFileLineForDate(new Date(x.longValue()), dataset.getSeriesKey(series).toString()) != null) { sb.append( "<p style='color:#0000FF;'>" + cd.sourceFileArrayListMap .get(pairs.getKey()).get(mr .getFileLineForDate( new Date(x.longValue()), dataset.getSeriesKey(series) .toString()) .getFileId()) .getFile().getName() + ":" + mr.getFileLineForDate(new Date(x.longValue()), dataset.getSeriesKey(series).toString()) .getLineNumber() + "</p>"); } } return sb.toString(); } }; while (statMapIterator.hasNext()) { TimeSeriesCollection dataset = new TimeSeriesCollection(); String me = (String) statMapIterator.next(); ExtendedTimeSeries ts = (ExtendedTimeSeries) statMap.get(me); // logger.info(((TimeSeries) // me.getValue()).getMaxY()); if (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY() > 0) dataset.addSeries(ts.getTimeSeries()); logger.debug("mineResultSet group: " + mr.getGroup() + ", key: " + me + " nb records: " + ((ExtendedTimeSeries) statMap.get(me)) .getTimeSeries().getItemCount()); logger.debug("(((TimeSeries) me.getValue()).getMaxY(): " + (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY())); logger.debug("(((TimeSeries) me.getValue()).getMinY(): " + (((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMinY())); XYPlot plot1 = chart.getXYPlot(); // LogarithmicAxis axis4 = new LogarithmicAxis(me.toString()); NumberAxis axis4 = new NumberAxis(me.toString()); axis4.setAutoRange(true); axis4.setAxisLineVisible(true); axis4.setAutoRangeIncludesZero(false); plot1.setDomainCrosshairVisible(true); plot1.setRangeCrosshairVisible(true); axis4.setRange(new Range( ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMinY(), ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY())); axis4.setLabelPaint(colors[count]); axis4.setTickLabelPaint(colors[count]); plot1.setRangeAxis(count, axis4); final ValueAxis domainAxis = domainAxis1; domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot1.setDomainAxis(domainAxis); plot1.setForegroundAlpha(0.5f); plot1.setDataset(count, dataset); plot1.mapDatasetToRangeAxis(count, count); final XYAreaRenderer renderer = new XYAreaRenderer(); // XYAreaRenderer2 // also // nice if ((((ExtendedTimeSeries) statMap.get(me)).getTimeSeries().getMaxY() - ((ExtendedTimeSeries) statMap.get(me)).getTimeSeries() .getMinY()) > 0) { // renderer.setToolTipGenerator(new // StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,new // FastDateFormat("d-MMM-yyyy HH:mm:ss"), // new DecimalFormat("#,##0.00"))); } renderer.setSeriesPaint(0, colors[count]); renderer.setSeriesVisible(0, true); renderer.setSeriesToolTipGenerator(0, tt1); plot1.setRenderer(count, renderer); int hits = 0; // ts.getStat()[1] int matchs = 0; if (((ExtendedTimeSeries) statMap.get(me)).getStat() != null) { hits = ((ExtendedTimeSeries) statMap.get(me)).getStat()[1]; // matchs= ((ExtendedTimeSeries) statMap.get(me)).getStat()[0]; } JCheckBox jcb = new JCheckBox(new VisibleAction(panel, checkboxPanel, axis4, me.toString() + "(" + hits + ")", 0)); Boolean selected = true; jcb.setSelected(true); jcb.setBackground(Color.white); jcb.setBorderPainted(true); jcb.setBorder(BorderFactory.createLineBorder(colors[count], 1, true)); jcb.setFont(new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize())); checkboxPanel.add(jcb); count++; } Iterator eventMapIterator = eventMap.entrySet().iterator(); while (eventMapIterator.hasNext()) { // HistogramDataset histoDataSet=new HistogramDataset(); TimeSeriesCollection dataset = new TimeSeriesCollection(); Map.Entry me = (Map.Entry) eventMapIterator.next(); // if (dataset.getEndXValue(series, item)) if (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMaxY() > 0) dataset.addSeries(((ExtendedTimeSeries) me.getValue()).getTimeSeries()); logger.debug("mineResultSet group: " + mr.getGroup() + ", key: " + me.getKey() + " nb records: " + ((ExtendedTimeSeries) me.getValue()).getTimeSeries().getItemCount()); logger.debug("mineResultSet hash content: " + mr.getEventTimeseriesMap()); logger.debug("(((TimeSeries) me.getValue()).getMaxY(): " + (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMaxY())); logger.debug("(((TimeSeries) me.getValue()).getMinY(): " + (((ExtendedTimeSeries) me.getValue()).getTimeSeries().getMinY())); XYPlot plot2 = chart.getXYPlot(); // LogarithmicAxis axis4 = new LogarithmicAxis(me.toString()); NumberAxis axis4 = new NumberAxis(me.getKey().toString()); axis4.setAutoRange(true); // axis4.setInverted(true); axis4.setAxisLineVisible(true); axis4.setAutoRangeIncludesZero(true); // axis4.setRange(new Range(((TimeSeries) // axis4.setRange(new Range(((TimeSeries) // me.getValue()).getMinY(), ((TimeSeries) // me.getValue()).getMaxY())); axis4.setLabelPaint(colors[count]); axis4.setTickLabelPaint(colors[count]); plot2.setRangeAxis(count, axis4); final ValueAxis domainAxis = domainAxis1; // domainAxis.setLowerMargin(0.001); // domainAxis.setUpperMargin(0.0); plot2.setDomainCrosshairVisible(true); plot2.setRangeCrosshairVisible(true); //plot2.setRangeCrosshairLockedOnData(true); plot2.setDomainAxis(domainAxis); plot2.setForegroundAlpha(0.5f); plot2.setDataset(count, dataset); plot2.mapDatasetToRangeAxis(count, count); XYBarRenderer rend = new XYBarRenderer(); // XYErrorRenderer rend.setShadowVisible(false); rend.setDrawBarOutline(true); Stroke stroke = new BasicStroke(5); rend.setBaseStroke(stroke); final XYItemRenderer renderer = rend; renderer.setSeriesToolTipGenerator(0, tt1); // renderer.setItemLabelsVisible(true); renderer.setSeriesPaint(0, colors[count]); renderer.setSeriesVisible(0, true); plot2.setRenderer(count, renderer); int hits = 0; int matchs = 0; if (((ExtendedTimeSeries) me.getValue()).getStat() != null) { hits = ((ExtendedTimeSeries) me.getValue()).getStat()[1]; // matchs= ((ExtendedTimeSeries) me.getValue()).getStat()[0]; } JCheckBox jcb = new JCheckBox(new VisibleAction(panel, checkboxPanel, axis4, me.getKey().toString() + "(" + hits + ")", 0)); jcb.setSelected(true); jcb.setBackground(Color.white); jcb.setBorderPainted(true); jcb.setBorder(BorderFactory.createLineBorder(colors[count], 1, true)); jcb.setFont(new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize())); checkboxPanel.add(jcb); count++; } JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); pan.setPreferredSize(new Dimension(600, Integer.parseInt((String) Preferences.getPreference("chartSize")))); // pan.setPreferredSize(panelSize); panel.add(pan); final ChartPanel cpanel = new ChartPanel(chart); cpanel.setMinimumDrawWidth(0); cpanel.setMinimumDrawHeight(0); cpanel.setMaximumDrawWidth(1920); cpanel.setMaximumDrawHeight(1200); // cpanel.setInitialDelay(0); cpanel.setDismissDelay(9999999); cpanel.setInitialDelay(50); cpanel.setReshowDelay(200); cpanel.setPreferredSize(new Dimension(600, 350)); // cpanel.restoreAutoBounds(); fix the tooltip // missing problem but then relative display is // broken panel.add(new JSeparator(SwingConstants.HORIZONTAL)); pan.add(cpanel, BorderLayout.CENTER); // checkboxPanel.setPreferredSize(new Dimension(600, // 0)); cpanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent chartmouseevent) { // chartmouseevent.getEntity(). ChartEntity entity = chartmouseevent.getEntity(); if (entity instanceof XYItemEntity) { XYItemEntity item = ((XYItemEntity) entity); if (item.getDataset() instanceof TimeSeriesCollection) { TimeSeriesCollection data = (TimeSeriesCollection) item .getDataset(); TimeSeries series = data.getSeries(item.getSeriesIndex()); TimeSeriesDataItem dataitem = series.getDataItem(item.getItem()); // logger.info(" Serie: "+series.getKey().toString() // + // " Period : "+dataitem.getPeriod().toString()); // mr.getFileForDate(new Date // (x.longValue()) ; int x = chartmouseevent.getTrigger().getX(); // logger.info(mr.getFileForDate(dataitem.getPeriod().getEnd())); int y = chartmouseevent.getTrigger().getY(); String myString = ""; if (dataitem.getPeriod() != null) { logger.info(dataitem.getPeriod().getEnd()); // myString = mr.getFileForDate(dataitem.getPeriod().getEnd()).toString(); String lineString = "" + mr.getFileLineForDate(dataitem.getPeriod().getEnd(), item.getDataset() .getSeriesKey(item.getSeriesIndex()) .toString()) .getLineNumber(); String fileString = cd.sourceFileArrayListMap .get(pairs.getKey()) .get(mr.getFileLineForDate( dataitem.getPeriod().getEnd(), item.getDataset() .getSeriesKey(item.getSeriesIndex()) .toString()) .getFileId()) .getFile().getAbsolutePath(); String command = Preferences.getPreference("editorCommand"); command = command.replace("$line", lineString); command = command.replace("$file", fileString); logger.info(command); Runtime rt = Runtime.getRuntime(); try { rt.exec(command); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringSelection stringSelection = new StringSelection( fileString); Clipboard clpbrd = Toolkit.getDefaultToolkit() .getSystemClipboard(); clpbrd.setContents(stringSelection, null); // cpanel.getGraphics().drawString("file name copied", x - 5, y - 5); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch // block e.printStackTrace(); } } // logger.info(mr.getFileForDate(dataitem.getPeriod().getStart())); } } } public void chartMouseMoved(ChartMouseEvent e) { } }); pan.add(checkboxPanel, BorderLayout.SOUTH); } } } else { logger.debug("mr dates null: " + mr.getGroup() + mr.getSourceID() + mr.getLogFiles()); } } } } // Map=miner.mine(sourceFiles,repo); estimatedTime = System.currentTimeMillis() - startTime; revalidate(); logger.info("display time: " + estimatedTime); }
From source file:com.netease.dagger.BrowserEmulator.java
/** * javascript executer which must contains one object to be affected * // w ww .j a v a 2 s . co m * @param js * @param by * */ public void uploadFile(String filepath) { try { //put file path in a clipboard StringSelection strSel = new StringSelection(filepath); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSel, null); //imitate mouse event ENTER/COPY/PASTE Robot robot = new Robot(); pause(500); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); logger.info("Success to upload file: " + filepath); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.clough.android.adbv.view.MainFrame.java
private void showTreeNodePopup(int x, int y, boolean isDatabasePopup) { JPopupMenu treeNodePopup = new JPopupMenu(); if (isDatabasePopup) { JMenuItem newTableMenuItem = new JMenuItem("New table"); newTableMenuItem.addActionListener(new ActionListener() { @Override/*from w w w. jav a 2 s . c om*/ public void actionPerformed(ActionEvent e) { System.out.println("new table"); new CreateTableDialog(MainFrame.this, true).setVisible(true); if (tableQueryList != null && tableQueryList.size() > 0) { for (String query : tableQueryList.values()) { inputQuery = query; runQuery(); } refreshDatabase(); tableQueryList = null; } } }); treeNodePopup.add(newTableMenuItem); } else { JMenuItem viewAllMenuItem = new JMenuItem("View table"); viewAllMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("view all"); inputQuery = "select * from `" + selectedTreeNodeValue + "`"; queryingTextArea.setText(inputQuery); runQuery(); } }); treeNodePopup.add(viewAllMenuItem); JMenuItem dropTableMenuItem = new JMenuItem("Drop table"); dropTableMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("drop table"); if (JOptionPane.showConfirmDialog(null, "All the data in table " + selectedTreeNodeValue + " will be lost!\nClick OK to delete the table", "Sqlite table dropping", JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { inputQuery = "drop table `" + selectedTreeNodeValue + "`"; queryingTextArea.setText(inputQuery); runQuery(); refreshDatabase(); } } }); treeNodePopup.add(dropTableMenuItem); JMenuItem updateTableMenuItem = new JMenuItem("Update table"); updateTableMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("update table"); final Object[] columnsOfTable = getColumnsOfTable(selectedTreeNodeValue); new SwingWorker<Void, Void>() { String result; @Override protected Void doInBackground() throws Exception { try { Thread.sleep(100); } catch (InterruptedException ex) { } result = ioManager.executeQuery("select * from `" + selectedTreeNodeValue + "`"); return null; } @Override protected void done() { closeProgressDialog(); new UpdateTableDialog(MainFrame.this, true, result, selectedTreeNodeValue, columnsOfTable).setVisible(true); } }.execute(); showProgressDialog(true, 0, "Recieving data from table " + selectedTreeNodeValue); if ((rowsToInsert != null && rowsToInsert.size() > 0) || (rowsToUpdate != null && rowsToUpdate.size() > 0) || (rowsToDelete != null && rowsToDelete.size() > 0)) { new SwingWorker<Void, Void>() { @Override protected Void doInBackground() { try { Thread.sleep(100); } catch (InterruptedException ex) { } String result = ""; try { for (Row row : rowsToInsert) { String insertQuery = createTableInsertQuery(selectedTreeNodeValue, row); System.out.println("insertQuery : " + insertQuery); result = ioManager.executeQuery(insertQuery); if (result.equals("[]")) { waitingDialog.incrementProgressBar(); } else { throw new Exception(); } } for (Row row : rowsToUpdate) { String updateQuery = createTableUpdateQuery(selectedTreeNodeValue, row); System.out.println("updateQuery : " + updateQuery); result = ioManager.executeQuery(updateQuery); if (result.equals("[]")) { waitingDialog.incrementProgressBar(); } else { throw new Exception(); } } for (Row row : rowsToDelete) { String deleteQuery = createTableDeleteQuery(selectedTreeNodeValue, row); System.out.println("deleteQuery : " + deleteQuery); result = ioManager.executeQuery(deleteQuery); if (result.equals("[]")) { waitingDialog.incrementProgressBar(); } else { throw new Exception(); } } } catch (Exception ex) { JOptionPane.showMessageDialog(null, result, "Result error", JOptionPane.ERROR_MESSAGE); } return null; } @Override protected void done() { closeProgressDialog(); refreshDatabase(); rowsToInsert = null; rowsToUpdate = null; rowsToDelete = null; } }.execute(); showProgressDialog(false, rowsToInsert.size() + rowsToUpdate.size() + rowsToDelete.size(), "Applying changes to the dialog " + selectedTreeNodeValue); } } }); treeNodePopup.add(updateTableMenuItem); JMenuItem copyCreateStatementMenuItem = new JMenuItem("Copy create statement"); copyCreateStatementMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("copy create statement"); for (int i = 0; i < tables.length; i++) { if (tables[i].equals(selectedTreeNodeValue)) { StringSelection selection = new StringSelection(queries[i]); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); JOptionPane.showMessageDialog(null, "Copied create statement of the table `" + selectedTreeNodeValue + "` to the clipboard", "Copy create statement", JOptionPane.INFORMATION_MESSAGE); break; } } } }); treeNodePopup.add(copyCreateStatementMenuItem); JMenuItem copyColumnNamesMenuItem = new JMenuItem("Copy column names"); copyColumnNamesMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("copy column names"); for (int i = 0; i < tables.length; i++) { if (tables[i].equals(selectedTreeNodeValue)) { String columnNames = ""; for (String column : columns[i]) { columnNames = columnNames.concat(column + ","); } StringSelection selection = new StringSelection( columnNames.substring(0, columnNames.length() - 1)); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); JOptionPane.showMessageDialog(null, "Copied create statement of the table `" + selectedTreeNodeValue + "` to the clipboard", "Copy create statement", JOptionPane.INFORMATION_MESSAGE); break; } } } }); treeNodePopup.add(copyColumnNamesMenuItem); } treeNodePopup.show(tableInfoTree, x, y); }
From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java
private void copyBBToExternalClipboardEvent() { try {// w w w. j a va 2 s. c o m List<Attack> attacks = getSelectedAttacks(); if (attacks.isEmpty()) { showInfo("Keine Angriffe ausgewhlt"); return; } boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this, "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code", "Nein", "Ja") == JOptionPane.YES_OPTION); StringBuilder buffer = new StringBuilder(); if (extended) { buffer.append("[u][size=12]Angriffsplan[/size][/u]\n\n"); } else { buffer.append("[u]Angriffsplan[/u]\n\n"); } buffer.append(new AttackListFormatter().formatElements(attacks, extended)); if (extended) { buffer.append("\n[size=8]Erstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n"); } else { buffer.append("\nErstellt am "); buffer.append( new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime())); buffer.append(" mit DS Workbench "); buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n"); } String b = buffer.toString(); StringTokenizer t = new StringTokenizer(b, "["); int cnt = t.countTokens(); if (cnt > 1000) { if (JOptionPaneHelper.showQuestionConfirmBox(this, "Die ausgewhlten Angriffe bentigen mehr als 1000 BB-Codes\n" + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?", "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) { return; } } Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null); String result = "Daten in Zwischenablage kopiert."; showSuccess(result); } catch (Exception e) { logger.error("Failed to copy data to clipboard", e); String result = "Fehler beim Kopieren in die Zwischenablage."; showError(result); } }