|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * ImageJ software for multidimensional image processing and analysis. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2014 Board of Regents of the University of |
| 6 | + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck |
| 7 | + * Institute of Molecular Cell Biology and Genetics. |
| 8 | + * %% |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are met: |
| 11 | + * |
| 12 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer. |
| 14 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + * this list of conditions and the following disclaimer in the documentation |
| 16 | + * and/or other materials provided with the distribution. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 22 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | + * POSSIBILITY OF SUCH DAMAGE. |
| 29 | + * #L% |
| 30 | + */ |
| 31 | + |
| 32 | +package org.scijava.plugins.scripting.matlab; |
| 33 | + |
| 34 | +import java.io.File; |
| 35 | + |
| 36 | +import matlabcontrol.MatlabInvocationException; |
| 37 | +import matlabcontrol.MatlabProxyFactoryOptions; |
| 38 | + |
| 39 | +import org.scijava.app.StatusService; |
| 40 | +import org.scijava.menu.MenuConstants; |
| 41 | +import org.scijava.options.OptionsPlugin; |
| 42 | +import org.scijava.plugin.Menu; |
| 43 | +import org.scijava.plugin.Parameter; |
| 44 | +import org.scijava.plugin.Plugin; |
| 45 | +import org.scijava.widget.Button; |
| 46 | + |
| 47 | +/** |
| 48 | + * Allows the setting and persisting of {@link MatlabProxyFactoryOptions} |
| 49 | + * configuration. |
| 50 | + * |
| 51 | + * @author Mark Hiner |
| 52 | + */ |
| 53 | +@Plugin(type = OptionsPlugin.class, |
| 54 | + label = "MATLAB Options", menu = { |
| 55 | + @Menu(label = MenuConstants.EDIT_LABEL, weight = MenuConstants.EDIT_WEIGHT, |
| 56 | + mnemonic = MenuConstants.EDIT_MNEMONIC), @Menu(label = "Options"), |
| 57 | + @Menu(label = "MATLAB...") }) |
| 58 | +public class MATLABOptions extends OptionsPlugin |
| 59 | +{ |
| 60 | + |
| 61 | + @Parameter |
| 62 | + private StatusService statusService; |
| 63 | + |
| 64 | + // Fields |
| 65 | + |
| 66 | + @Parameter(label = "Hide MATLAB UI") |
| 67 | + private boolean hidden = true; |
| 68 | + |
| 69 | + @Parameter(label = "Allow multithreaded MATLAB") |
| 70 | + private boolean multithreaded = true; |
| 71 | + |
| 72 | + @Parameter(label = "License file path", required = false) |
| 73 | + private File licenseFile = null; |
| 74 | + |
| 75 | + @Parameter(label = "Exit MATLAB", persist = false, callback = "endSession") |
| 76 | + private Button endSession; |
| 77 | + |
| 78 | + // -- Option accessors -- |
| 79 | + |
| 80 | + public boolean isHidden() { |
| 81 | + return hidden; |
| 82 | + } |
| 83 | + |
| 84 | + public boolean isMultithreaded() { |
| 85 | + return multithreaded; |
| 86 | + } |
| 87 | + |
| 88 | + public String licensePath() { |
| 89 | + return licenseFile == null ? null : licenseFile.getAbsolutePath(); |
| 90 | + } |
| 91 | + |
| 92 | + // -- Callback methods -- |
| 93 | + |
| 94 | + @SuppressWarnings("unused") |
| 95 | + private void endSession() { |
| 96 | + if (MATLABControlUtils.hasProxy()) { |
| 97 | + try { |
| 98 | + MATLABControlUtils.proxy(this).exit(); |
| 99 | + statusService.showStatus("MATLAB shutdown successful"); |
| 100 | + } |
| 101 | + catch (MatlabInvocationException e) { |
| 102 | + statusService.showStatus("MATLAB shutdown failed"); |
| 103 | + } |
| 104 | + } |
| 105 | + else { |
| 106 | + statusService.showStatus("No MATLAB connection detected."); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments