Search in sources :

Example 76 with Clipboard

use of java.awt.datatransfer.Clipboard in project beast-mcmc by beast-dev.

the class MapperFrame method doCopy.

@Override
public void doCopy() {
    StringWriter writer = new StringWriter();
    PrintWriter pwriter = new PrintWriter(writer);
    // for (String tip : treesPanel.getSelectedTips()) {
    // pwriter.println(tip);
    // }
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection selection = new StringSelection(writer.toString());
    clipboard.setContents(selection, selection);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 77 with Clipboard

use of java.awt.datatransfer.Clipboard in project SIMVA-SoS by SESoS.

the class ChartPanel method doCopy.

/**
 * Copies the current chart to the system clipboard.
 *
 * @since 1.0.13
 */
public void doCopy() {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = getInsets();
    int w = getWidth() - insets.left - insets.right;
    int h = getHeight() - insets.top - insets.bottom;
    ChartTransferable selection = new ChartTransferable(this.chart, w, h, getMinimumDrawWidth(), getMinimumDrawHeight(), getMaximumDrawWidth(), getMaximumDrawHeight(), true);
    systemClipboard.setContents(selection, null);
}
Also used : Insets(java.awt.Insets) Clipboard(java.awt.datatransfer.Clipboard) Point(java.awt.Point) Paint(java.awt.Paint)

Example 78 with Clipboard

use of java.awt.datatransfer.Clipboard in project Terasology by MovingBlocks.

the class BehaviorEditorScreen method onCopyPressed.

private void onCopyPressed() {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    String data = behaviorEditor.save();
    StringSelection contents = new StringSelection(data);
    systemClipboard.setContents(contents, contents);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 79 with Clipboard

use of java.awt.datatransfer.Clipboard in project vcell by virtualcell.

the class BioModelEditor method popupMenuActionPerformed.

@Override
protected void popupMenuActionPerformed(DocumentEditorPopupMenuAction action, String actionCommand) {
    Model model = bioModel.getModel();
    final SimulationContext selectedSimulationContext = getSelectedSimulationContext();
    switch(action) {
        case add_new:
            try {
                Object obj = documentEditorTree.getLastSelectedPathComponent();
                if (obj == null || !(obj instanceof BioModelNode)) {
                    return;
                }
                BioModelNode selectedNode = (BioModelNode) obj;
                Object userObject = selectedNode.getUserObject();
                if (userObject instanceof DocumentEditorTreeFolderNode) {
                    DocumentEditorTreeFolderClass folderClass = ((DocumentEditorTreeFolderNode) userObject).getFolderClass();
                    Object newObject = null;
                    switch(folderClass) {
                        case REACTIONS_NODE:
                            // TODO: should add a Add New Rule menu item
                            newObject = model.createSimpleReaction(model.getStructure(0));
                            break;
                        case STRUCTURES_NODE:
                            newObject = model.createFeature();
                            break;
                        case SPECIES_NODE:
                            newObject = model.createSpeciesContext(model.getStructure(0));
                            break;
                        case MOLECULAR_TYPES_NODE:
                            MolecularType mt = model.getRbmModelContainer().createMolecularType();
                            model.getRbmModelContainer().addMolecularType(mt, true);
                            newObject = mt;
                            break;
                        case OBSERVABLES_NODE:
                            if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
                                PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
                                return;
                            }
                            RbmObservable o = model.getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
                            model.getRbmModelContainer().addObservable(o);
                            SpeciesPattern sp = new SpeciesPattern();
                            o.addSpeciesPattern(sp);
                            newObject = o;
                            break;
                        case SIMULATIONS_NODE:
                            if (selectedSimulationContext != null) {
                                AsynchClientTask task1 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        selectedSimulationContext.refreshMathDescription(callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                    }
                                };
                                AsynchClientTask task2 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        Object newsim = selectedSimulationContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                        selectionManager.setSelectedObjects(new Object[] { newsim });
                                    }
                                };
                                ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
                            }
                            break;
                        default:
                            break;
                    }
                    if (newObject != null) {
                        selectionManager.setSelectedObjects(new Object[] { newObject });
                    }
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case add_new_app_deterministic:
            newApplication(Application.NETWORK_DETERMINISTIC);
            break;
        case add_new_app_stochastic:
            newApplication(Application.NETWORK_STOCHASTIC);
            break;
        case add_new_app_rulebased:
            {
                // if(model.getStructures().length > 1) {
                // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                // return;
                // }
                newApplication(Application.RULE_BASED_STOCHASTIC);
                break;
            }
        case copyName:
            String name = bioModel.getName();
            StringSelection data = new StringSelection(name);
            Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
            c.setContents(data, data);
            break;
        case copy_app:
            ApplicationActionCommand acc = ApplicationActionCommand.lookup(actionCommand);
            switch(acc.actionType()) {
                case COPY_AS_IS:
                    copyApplication();
                    break;
                case COPY_CHANGE:
                    boolean bothSpatial = acc.isSourceSpatial() && acc.isDestSpatial();
                    // if(acc.getAppType().equals(SimulationContext.Application.RULE_BASED_STOCHASTIC) && model.getStructures().length > 1) {
                    // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                    // return;
                    // }
                    copyApplication(bothSpatial, acc.getAppType());
                    break;
                case CREATE:
                    // not used in this menu
                    throw new UnsupportedOperationException();
            }
            break;
        case app_new_biomodel:
            if (actionCommand.equals(GuiConstants.MENU_TEXT_APP_NEWBIOMODEL)) {
                createNewBiomodelFromApp();
            }
            break;
        case delete:
            try {
                if (selectedSimulationContext != null) {
                    String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application", "You are going to delete the Application '" + selectedSimulationContext.getName() + "'. Continue?");
                    if (confirm.equals(UserMessage.OPTION_CANCEL)) {
                        return;
                    }
                    deleteSimulationcontexts(new SimulationContext[] { selectedSimulationContext });
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case deleteChoose:
            try {
                SimulationContext[] allSimContexts = Arrays.copyOf(getBioModelWindowManager().getVCDocument().getSimulationContexts(), getBioModelWindowManager().getVCDocument().getSimulationContexts().length);
                Arrays.sort(allSimContexts, new Comparator<SimulationContext>() {

                    @Override
                    public int compare(SimulationContext o1, SimulationContext o2) {
                        return o1.getName().compareToIgnoreCase(o2.getName());
                    }
                });
                String[][] rowDataOrig = new String[allSimContexts.length][2];
                for (int i = 0; i < allSimContexts.length; i++) {
                    rowDataOrig[i][0] = allSimContexts[i].getName();
                    rowDataOrig[i][1] = allSimContexts[i].getSimulations().length + "";
                }
                final String DELETE = "Delete";
                final String CANCEL = "Cancel";
                TableListResult result = DialogUtils.showComponentOptionsTableList(this, "Select Applications (and associated Simulations) to delete.", new String[] { "Application", "# of Sims" }, rowDataOrig, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, null, new String[] { DELETE, CANCEL }, CANCEL, null);
                if (result != null && result.selectedOption != null && result.selectedOption.equals(DELETE) && result.selectedTableRows != null && result.selectedTableRows.length > 0) {
                    ArrayList<SimulationContext> deleteTheseSimcontexts = new ArrayList<SimulationContext>();
                    for (int i = 0; i < result.selectedTableRows.length; i++) {
                        deleteTheseSimcontexts.add(allSimContexts[result.selectedTableRows[i]]);
                    }
                    deleteSimulationcontexts(deleteTheseSimcontexts.toArray(new SimulationContext[0]));
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        default:
            break;
    }
}
Also used : TableListResult(org.vcell.util.gui.DialogUtils.TableListResult) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ApplicationActionCommand(cbit.vcell.client.constants.ApplicationActionCommand) ArrayList(java.util.ArrayList) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) StringSelection(java.awt.datatransfer.StringSelection) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) RbmObservable(cbit.vcell.model.RbmObservable) DocumentEditorTreeFolderNode(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode) SimulationContext(cbit.vcell.mapping.SimulationContext) DocumentEditorTreeFolderClass(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) BioPaxObject(org.vcell.pathway.BioPaxObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) CSGObject(cbit.vcell.geometry.CSGObject) Clipboard(java.awt.datatransfer.Clipboard)

Example 80 with Clipboard

use of java.awt.datatransfer.Clipboard in project vcell by virtualcell.

the class VCellTransferable method sendToClipboard.

/**
 * Insert the method's description here.
 * Creation date: (5/9/2003 8:43:19 AM)
 * @param obj java.lang.Object
 * @param flavor java.awt.datatransfer.DataFlavor
 */
public static void sendToClipboard(Object obj) {
    if (obj == null) {
        return;
    }
    VCellTransferable vct = new VCellTransferable(obj);
    Clipboard clipb = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    clipb.setContents(vct, vct);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)181 StringSelection (java.awt.datatransfer.StringSelection)117 Transferable (java.awt.datatransfer.Transferable)44 IOException (java.io.IOException)30 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)16 JDialog (javax.swing.JDialog)12 JOptionPane (javax.swing.JOptionPane)12 ActionEvent (java.awt.event.ActionEvent)11 Flame (org.jwildfire.create.tina.base.Flame)10 ActionListener (java.awt.event.ActionListener)8 JButton (javax.swing.JButton)8 JScrollPane (javax.swing.JScrollPane)8 JMenuItem (javax.swing.JMenuItem)7 JPanel (javax.swing.JPanel)7 JTextArea (javax.swing.JTextArea)7 Foundation (org.concord.energy3d.model.Foundation)7 HousePart (org.concord.energy3d.model.HousePart)7 FlameReader (org.jwildfire.create.tina.io.FlameReader)7 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)7 Point (java.awt.Point)6