Java Code Examples for ij.gui.GenericDialog#wasOKed()

The following examples show how to use ij.gui.GenericDialog#wasOKed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 6 votes vote down vote up
private void setPreferences() {
	final GenericDialog gd = new GenericDialog("Preferences");
	gd.addChoice("Secondary style color:", Colors.colors, dColor2);
	gd.setInsets(0, 0, 0);
	gd.addMessage("(Used by styles 'box', 'circle', 'connected', etc.)");
	gd.setInsets(30, 0, 0);
	gd.addMessage("After plotting a series:");
	gd.setInsets(0, 20, 0);
	gd.addCheckbox("Auto-select_next_Y-values", autoNextValues);
	gd.addCheckbox("Auto-select_next_shape", autoNextShape);
	gd.addCheckbox("Auto-select_next_color", autoNextColor);
	showAsSubDialog(gd);
	if (gd.wasOKed()) {
		dColor2 = Colors.colors[gd.getNextChoiceIndex()];
		autoNextValues = gd.getNextBoolean();
		autoNextShape = gd.getNextBoolean();
		autoNextColor = gd.getNextBoolean();
	}
}
 
Example 2
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 6 votes vote down vote up
private void setTemplate() {
	if (plot == null)
		return;
	final ArrayList<PlotInstance> plots = getPlots();
	if (plots == null || plots.size() == 0) {
		showMessage("No Plots Available", "No open plots to be used as template!");
		return;
	}
	final GenericDialog gd = new GenericDialog("Apply Template");
	final String[] choices = new String[plots.size()];
	for (int i = 0; i < choices.length; i++)
		choices[i] = plots.get(i).title;
	gd.addChoice("Use_this_plot as template:", choices, null);
	showAsSubDialog(gd);
	if (!gd.wasOKed())
		return;
	plot.useTemplate(plots.get(gd.getNextChoiceIndex()).plot);
	plot.updateImage();
}
 
Example 3
Source File: SkeletonPlugin.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
private boolean showDialog() {

		gd = new GenericDialog("Render Paths as Topographic Skeletons");
		final String[] pwScopes = { "Render all paths", "Render only selected paths" };
		gd.addRadioButtonGroup("Path selection:", pwScopes, 2, 1, pwScopes[useOnlySelectedPaths ? 1 : 0]);
		final String[] roiScopes = { "None", "Render only segments contained by ROI" };
		gd.addRadioButtonGroup("ROI filtering:", roiScopes, 2, 1, roiScopes[restrictByRoi ? 1 : 0]);

		// Assemble SWC choices
		final ArrayList<String> swcTypeNames = Path.getSWCtypeNames();
		final int nTypes = swcTypeNames.size();
		final String[] typeNames = swcTypeNames.toArray(new String[nTypes]);
		final boolean[] typeChoices = new boolean[nTypes];
		for (int i = 0; i < nTypes; i++)
			typeChoices[i] = typeNames[i].contains("dendrite");
		final String[] swcScopes = { "None", "Include only the following SWC types:" };
		gd.addRadioButtonGroup("SWC filtering:", swcScopes, 2, 1, swcScopes[restrictBySWCType ? 1 : 0]);
		gd.setInsets(0, 40, 0);
		gd.addCheckboxGroup(nTypes / 2, 2, typeNames, typeChoices);

		final String[] analysisScopes = { "None", "Obtain summary", "Run \"Analyze Skeleton\" plugin" };
		gd.addRadioButtonGroup("Analysis of rendered paths:", analysisScopes, 3, 1, analysisScopes[0]);
		gd.addDialogListener(this);
		dialogItemChanged(gd, null);
		gd.showDialog();
		if (gd.wasCanceled())
			return false;
		else if (gd.wasOKed()) {
			return dialogItemChanged(gd, null);
		}
		return false;

	}
 
Example 4
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) 
{
	if (gd.wasCanceled() || gd.wasOKed()) 
	{
		return true;
	}
	
	@SuppressWarnings({ "unchecked" })
       Vector<Choice> choices = gd.getChoices();
	if (choices == null) 
	{
		IJ.log("empty choices array...");
		return false;
	}
	
	// Change of the data table
       if (evt.getSource() == choices.get(0)) 
	{
		String tableName = ((Choice) evt.getSource()).getSelectedItem();
		Frame tableFrame = WindowManager.getFrame(tableName);
		this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
		
		// Choose current headings
		String[] headings = this.table.getHeadings();		
		replaceStrings(choices.get(1), headings, chooseDefaultHeading(headings, xPosHeaderName));
           replaceStrings(choices.get(2), headings, chooseDefaultHeading(headings, yPosHeaderName));
           replaceStrings(choices.get(3), headings, chooseDefaultHeading(headings, valueHeaderName));
	}
	
	return true;
}
 
Example 5
Source File: ShenCastan.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads dialog parameters (during preview and upon dismissal of dialog
 * prompt).
 * 
 * @return <code>true</code>, if user specified valid input values
 */
@Override
public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
	f = gd.getNextNumber();
	if (f < 0) f = 0d;
	if (f > 1) f = 1d;
	canceled = gd.invalidNumber();
	if (gd.wasOKed() && canceled) {
		IJ.error("Value is invalid.");
		return false;
	}
	return true;
}
 
Example 6
Source File: Commander.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
void showOptionsDialog() {
	log("Prompting for options...");
	final GenericDialog gd = new GenericDialog("Commander Preferences", frame);
	gd.addNumericField("Maximum number of items in file list", maxSize, 0);
	gd.addCheckbox("Hide Commander after opening a file", hideOnOpen);
	gd.addCheckbox("Open IJM files in ImageJ 1 (legacy) editor", ijmLegacy);
	gd.addCheckbox("Enable Tooltips (toggling requires a restart)", tooltips);
	gd.addMessage("");
	gd.addCheckbox("Clear Favorites", false);
	gd.addCheckbox("Clear Recent folders", false);
	gd.addCheckbox("Clear Saved searches", false);
	gd.enableYesNoCancel("OK", "Defaults...");
	gd.addHelp(helpMessage());
	gd.showDialog();
	if (gd.wasCanceled()) {
		log("Prompt dismissed...");
		return;
	} else if (gd.wasOKed()) {
		maxSize = (int) Math.max(1, gd.getNextNumber());
		hideOnOpen = gd.getNextBoolean();
		ijmLegacy = gd.getNextBoolean();
		tooltips = gd.getNextBoolean();
		if (gd.getNextBoolean())
			clearBookmarks();
		if (gd.getNextBoolean())
			clearRecentPaths();
		if (gd.getNextBoolean())
			clearSearches();
	} else {
		clearPreferences();
	}
	updateList();
}
 
Example 7
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 5 votes vote down vote up
private void setDestinationPlot() {
	if (plot == null)
		return;

	final String NEW_PLOT_LABEL = "New plot window";
	final ArrayList<PlotInstance> plots = getPlots();
	final ArrayList<String> choices = new ArrayList<>();
	for (final PlotInstance p : plots)
		choices.add(p.title);
	choices.add(NEW_PLOT_LABEL);

	final GenericDialog gd = new GenericDialog("Set Destination Plot");
	final int cols = (choices.size() < 18) ? 1 : 2;
	final int rows = (choices.size() % cols > 0) ? choices.size() / cols + 1 : choices.size() / cols;
	gd.addRadioButtonGroup("Append datasets to:", choices.toArray(new String[choices.size()]), rows, cols,
			NEW_PLOT_LABEL);
	showAsSubDialog(gd);
	if (!gd.wasOKed())
		return;

	final String choice = gd.getNextRadioButton();
	if (choice.equals(NEW_PLOT_LABEL)) {
		resetPlot();
		updateDatasetButton();
	} else {
		final int idx = choices.indexOf(choice);
		pw = plots.get(idx).plotWindow;
		plot = plots.get(idx).plot;
		datasetCounter = plot.getPlotObjectDesignations().length;
		WindowManager.toFront(pw);
	}
	updateDatasetButton();

}
 
Example 8
Source File: SNTPrefs.java    From SNT with GNU General Public License v3.0 4 votes vote down vote up
protected void promptForOptions() {

		final int startupOptions = 7;
		final int pluginOptions = 2;

		final String[] startupLabels = new String[startupOptions];
		final int[] startupItems = new int[startupOptions];
		final boolean[] startupStates = new boolean[startupOptions];
		int idx = 0;

		startupItems[idx] = ENFORCE_LUT;
		startupLabels[idx] = "Enforce non-inverted grayscale LUT";
		startupStates[idx++] = snt.forceGrayscale;

		startupItems[idx] = USE_THREE_PANE;
		startupLabels[idx] = "Use_three-pane view";
		startupStates[idx++] = !snt.getSinglePane();

		startupItems[idx] = USE_3D_VIEWER;
		startupLabels[idx] = "Use_3D Viewer";
		startupStates[idx++] = snt.use3DViewer;

		startupItems[idx] = LOOK_FOR_TUBES;
		startupLabels[idx] = "Load_Tubeness \".tubes.tif\" pre-processed file (if present)";
		startupStates[idx++] = snt.look4tubesFile;

		startupItems[idx] = LOOK_FOR_OOF;
		startupLabels[idx] = "Load_Tubular_Geodesics \".oof.ext\" pre-processed file (if present)";
		startupStates[idx++] = snt.look4oofFile;

		startupItems[idx] = LOOK_FOR_TRACES;
		startupLabels[idx] = "Load_default \".traces\" file (if present)";
		startupStates[idx++] = snt.look4tracesFile;

		startupItems[idx] = STORE_WIN_LOCATIONS;
		startupLabels[idx] = "Remember window locations across restarts";
		startupStates[idx++] = isSaveWinLocations();

		final String[] pluginLabels = new String[pluginOptions];
		final int[] pluginItems = new int[pluginOptions];
		final boolean[] pluginStates = new boolean[pluginOptions];
		idx = 0;

		pluginItems[idx] = COMPRESSED_XML;
		pluginLabels[idx] = "Use compression when saving traces";
		pluginStates[idx++] = snt.useCompressedXML;

		pluginItems[idx] = DEBUG;
		pluginLabels[idx] = "Enable_debug mode";
		pluginStates[idx++] = SimpleNeuriteTracer.verbose;

		final GenericDialog gd = new GenericDialog("SNT v" + SNT.VERSION + " Preferences");
		final Font font = new Font("SansSerif", Font.BOLD, 12);
		gd.setInsets(0, 0, 0);
		gd.addMessage("Startup Options:", font);
		gd.setInsets(0, 0, 0);
		gd.addCheckboxGroup(startupOptions, 1, startupLabels, startupStates);
		gd.setInsets(20, 0, 0);
		gd.addMessage("Advanced Options:", font);
		gd.setInsets(0, 0, 0);
		gd.addCheckboxGroup(pluginOptions, 1, pluginLabels, pluginStates);

		gd.enableYesNoCancel("OK", "Revert to Defaults");
		gd.showDialog();
		if (gd.wasCanceled()) {
			return;
		} else if (gd.wasOKed()) {

			for (int i = 0; i < startupOptions; i++) {
				if (gd.getNextBoolean())
					currentBooleans |= startupItems[i];
				else
					currentBooleans &= ~startupItems[i];
			}
			for (int i = 0; i < pluginOptions; i++) {
				if (gd.getNextBoolean())
					currentBooleans |= pluginItems[i];
				else
					currentBooleans &= ~pluginItems[i];
			}
			Prefs.set(BOOLEANS, currentBooleans);

		} else {
			resetOptions();
		}

		Prefs.savePreferences();
		loadPluginPrefs();

	}
 
Example 9
Source File: MarkerControlledWatershed3DPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Plugin run method to be called from ImageJ
 */
@Override
public void run(String arg) 
{
	int nbima = WindowManager.getImageCount();
	
	if( nbima < 2 )
	{
		IJ.error( "Marker-controlled Watershed", 
				"ERROR: At least two images need to be open to run Marker-controlled Watershed.");
		return;
	}
	
       String[] names = new String[ nbima ];
       String[] namesMask = new String[ nbima + 1 ];

       namesMask[ 0 ] = "None";
       
       for (int i = 0; i < nbima; i++) 
       {
           names[ i ] = WindowManager.getImage(i + 1).getTitle();
           namesMask[ i + 1 ] = WindowManager.getImage(i + 1).getTitle();
       }
       
       GenericDialog gd = new GenericDialog("Marker-controlled Watershed");

       int inputIndex = 0;
       int markerIndex = nbima > 1 ? 1 : 0;
       
       gd.addChoice( "Input", names, names[ inputIndex ] );
       gd.addChoice( "Marker", names, names[ markerIndex ] );
       gd.addChoice( "Mask", namesMask, namesMask[ 0 ] );
       gd.addCheckbox("Binary markers", true);
       gd.addCheckbox( "Calculate dams", getDams );
       gd.addCheckbox( "Use diagonal connectivity", use26neighbors );

       gd.showDialog();
       
       if (gd.wasOKed()) 
       {
           inputIndex = gd.getNextChoiceIndex();
           markerIndex = gd.getNextChoiceIndex();
           int maskIndex = gd.getNextChoiceIndex();
           binaryMarkers = gd.getNextBoolean();
           getDams = gd.getNextBoolean();
           use26neighbors = gd.getNextBoolean();

           ImagePlus inputImage = WindowManager.getImage( inputIndex + 1 );
           ImagePlus markerImage = WindowManager.getImage( markerIndex + 1 );
           ImagePlus maskImage = maskIndex > 0 ? WindowManager.getImage( maskIndex ) : null;
           
           // a 3D image is assumed but it will use 2D connectivity if the
           // input is 2D
           int connectivity = use26neighbors ? 26 : 6;
           if( inputImage.getImageStackSize() == 1 )
           	connectivity = use26neighbors ? 8 : 4;

           ImagePlus result = process( inputImage, markerImage, maskImage, connectivity );
                                   
   		// Set result slice to the current slice in the input image
           result.setSlice( inputImage.getCurrentSlice() );
           
           // optimize display range
           Images3D.optimizeDisplayRange( result );
           
           // show result
           result.show();
       }
	
}
 
Example 10
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) 
{
	if (gd.wasCanceled() || gd.wasOKed()) 
	{
		return true;
	}
	
	@SuppressWarnings("rawtypes")
	Vector choices = gd.getChoices();
	if (choices == null) 
	{
		IJ.log("empty choices array...");
		return false;
	}
	
	// Change of the data table
       if (evt.getSource() == choices.get(0)) 
	{
		String tableName = ((Choice) evt.getSource()).getSelectedItem();
		Frame tableFrame = WindowManager.getFrame(tableName);
		this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
		
		// Choose current heading
		String[] headings = this.table.getHeadings();
		String defaultHeading = headings[0];
		if (defaultHeading.equals("Label") && headings.length > 1) 
		{
			defaultHeading = headings[1];
		}
		
		Choice headingChoice = (Choice) choices.get(1);
		headingChoice.removeAll();
		for (String heading : headings) 
		{
			headingChoice.add(heading);
		}
		headingChoice.select(defaultHeading);

		changeColumnHeader(defaultHeading);
	}
	
	// Change of the column heading
	if (evt.getSource() == choices.get(1)) 
	{
		String headerName = ((Choice) evt.getSource()).getSelectedItem();
           changeColumnHeader(headerName);
	}
	
	return true;
}
 
Example 11
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotOptions() {

		if (plot == null)
			return;

		final int DEF_LINE_WIDTH = 1;
		final int DEF_MAX_INTERVALS = 12;
		final int DEF_TICK_LENGTH = 7;
		final int DEF_MINOR_TICK_LENGTH = 3;
		final int[] NUM_DEFAULTS = { DEF_LINE_WIDTH, DEF_MAX_INTERVALS, DEF_TICK_LENGTH, DEF_MINOR_TICK_LENGTH };
		final String DEF_BACKGROUND_COLOR = "white";
		final String title = plot.getTitle();
		final GenericDialog ogd = new GenericDialog("Options for " + title);
		ogd.setInsets(0, 10, 10);
		ogd.addMessage("This prompt allows you access customizations that\n"
				+ "are not accessible through the plot's \"More \u00bb\" menu");
		if (!pwClosed)
			ogd.addStringField("Plot title:", title, 27);
		ogd.addSlider("Line width:", 1, 20, 1);
		ogd.addSlider("Max. n. of intervals:", 1, 40, 12);
		ogd.addSlider("Major ticks length:", 1, 14, 7);
		ogd.addSlider("Minor ticks length:", 1, 14, 3);
		ogd.addChoice("Backgrond color:", Colors.colors, DEF_BACKGROUND_COLOR);
		final Panel buttonPanel = new Panel();
		final Button fontButton = new Button("  Text & Font...  ");
		fontButton.addActionListener(ogd);
		buttonPanel.add(fontButton);
		final Button templateButton = new Button("Apply Template...");
		templateButton.addActionListener(ogd);
		buttonPanel.add(templateButton);
		ogd.addPanel(buttonPanel, GridBagConstraints.EAST, new Insets(0, 0, 0, 0));
		ogd.hideCancelButton();
		ogd.addHelp("");
		ogd.setHelpLabel("Apply Defaults");
		ogd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {

				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<TextField> nFields = gd.getNumericFields();
					for (final TextField field : nFields)
						field.setText(Integer.toString(NUM_DEFAULTS[nFields.indexOf(field)]));
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					nChoices.firstElement().select(DEF_BACKGROUND_COLOR);
				} else if (e != null && e.toString().contains("Font")) {
					setPlotFont();
					return true;
				} else if (e != null && e.toString().contains("Template")) {
					setTemplate();
					return true;
				}

				plot.setLineWidth((int) ogd.getNextNumber());
				plot.setMaxIntervals((int) ogd.getNextNumber());
				plot.setTickLength((int) ogd.getNextNumber());
				plot.setBackgroundColor(Colors.colors[ogd.getNextChoiceIndex()]);
				plot.updateImage();
				return true;

			}
		});
		showAsSubDialog(ogd);
		if (!ogd.wasOKed())
			return;
		if (!pwClosed)
			plot.getImagePlus().setTitle(WindowManager.makeUniqueName(ogd.getNextString()));

	}
 
Example 12
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotFont() {

		if (plot == null)
			return;

		final String[] FONTS = new String[] { Font.SANS_SERIF, Font.MONOSPACED, Font.SERIF };
		final String[] STYLES = { "Plain", "Bold", "Italic", "Bold+Italic" };
		final String[] JUSTIFICATIONS = { "Left", "Center", "Right" };
		final String[] SCOPES = { "Plot", "Both Axes Titles", "X-axis Title", "Y-axis Title" };
		final String[] CHOICE_DEFAULTS = { FONTS[0], STYLES[0], JUSTIFICATIONS[0], SCOPES[0] };
		final int[] INT_STYLES = { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD + Font.ITALIC };
		final int[] INT_JUSTIFICATIONS = { Plot.LEFT, Plot.CENTER, Plot.RIGHT };
		final int DEF_SIZE = 12;
		final boolean DEF_ANTIALISED = true;

		final GenericDialog fgd = new GenericDialog("Font Options");
		fgd.addChoice("Type:", FONTS, CHOICE_DEFAULTS[0]);
		fgd.addChoice("Style:", STYLES, CHOICE_DEFAULTS[1]);
		fgd.addChoice("Justification:", JUSTIFICATIONS, CHOICE_DEFAULTS[2]);
		fgd.addSlider("Size:", 9, 24, DEF_SIZE);
		fgd.setInsets(0, 20, 15);
		fgd.addCheckbox("Antialiased text", DEF_ANTIALISED);
		fgd.addChoice("Apply to:", SCOPES, CHOICE_DEFAULTS[3]);
		fgd.hideCancelButton();
		fgd.addHelp("");
		fgd.setHelpLabel("Apply Defaults");
		fgd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					for (final Choice choice : nChoices)
						choice.select(CHOICE_DEFAULTS[nChoices.indexOf(choice)]);
					((TextField) gd.getNumericFields().get(0)).setText(Integer.toString(DEF_SIZE));
					((Checkbox) gd.getCheckboxes().get(0)).setState(DEF_ANTIALISED);
				}

				final String type = FONTS[fgd.getNextChoiceIndex()];
				final int style = INT_STYLES[fgd.getNextChoiceIndex()];
				final int justification = INT_JUSTIFICATIONS[fgd.getNextChoiceIndex()];
				final int size = (int) fgd.getNextNumber();
				final int scopeIdx = fgd.getNextChoiceIndex();

				plot.setJustification(justification);
				plot.setAntialiasedText(fgd.getNextBoolean());
				final Font font = new Font(type, style, size);
				switch (scopeIdx) {
				case 1: // SCOPES[1]
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				case 2: // SCOPES[2]
					plot.setXLabelFont(font);
					break;
				case 3: // SCOPES[3]
					plot.setYLabelFont(font);
					break;
				default:
					plot.setFont(font);
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				}

				plot.updateImage();
				return true;
			}
		});
		showAsSubDialog(fgd);
		if (!fgd.wasOKed())
			return;
	}