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

The following examples show how to use ij.gui.GenericDialog#setInsets() . 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: AnalyzeSkeleton_.java    From AnalyzeSkeleton with GNU General Public License v3.0 6 votes vote down vote up
private void createSettingsDialog() {
	settingsDialog = new GenericDialog("Analyze Skeleton");
	Font headerFont = new Font("SansSerif", Font.BOLD, 12);

	settingsDialog.setInsets(0, 0, 0);
	settingsDialog.addMessage("Elimination of Loops:", headerFont);
	settingsDialog.addChoice("Prune cycle method: ", AnalyzeSkeleton_.pruneCyclesModes,
			AnalyzeSkeleton_.pruneCyclesModes[pruneIndex]);

	settingsDialog.setInsets(20, 0, -15); //default top inset for 1st checkbox is 15
	settingsDialog.addMessage("Elimination of End-points:", headerFont);
	settingsDialog.addCheckbox("Prune ends", pruneEnds);
	settingsDialog.addCheckbox("Exclude ROI from pruning", protectRoi);

	settingsDialog.setInsets(20, 0, 0); //default top inset for subsequent checkboxes is 0
	settingsDialog.addMessage("Results and Output:", headerFont);
	settingsDialog.addCheckbox("Calculate largest shortest path", calculateShortestPath);
	settingsDialog.addCheckbox("Show detailed info", verbose);
	settingsDialog.addCheckbox("Display labeled skeletons", displaySkeletons);

	settingsDialog.addHelp(HELP_URL);
	dialogItemChanged(settingsDialog, null);
}
 
Example 2
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 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: 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 5
Source File: DistanceTransformWatershed.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
public int showDialog(
		ImagePlus imp,
		String command,
		PlugInFilterRunner pfr )
{
	if( !BinaryImages.isBinaryImage( imp ) )
	{
		IJ.error( "Distance Transform Watershed", "Input image is not"
				+ " binary (8-bit with only 0 or 255 values)" );
		return DONE;
	}
	// Store user data
	this.imagePlus = imp;
	this.baseImage = imp.getProcessor().duplicate();
	this.pfr = pfr;

	// Create a new generic dialog with appropriate options
	GenericDialog gd = new GenericDialog( "Distance Transform Watershed" );
	gd.setInsets( 0, 0, 0 );
	gd.addMessage( "Distance map options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addChoice( "Distances", ChamferWeights.getAllLabels(), weightLabel );
	String[] outputTypes = new String[]{"32 bits", "16 bits"};
	gd.addChoice( "Output Type", outputTypes, outputTypes[ floatProcessing ? 0:1 ]);
	gd.setInsets( 0, 0, 0 );
	gd.addCheckbox( "Normalize weights", normalize );
	gd.setInsets( 20, 0, 0 );
	gd.addMessage( "Watershed options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addNumericField( "Dynamic", dynamic, 2 );
	gd.addChoice( "Connectivity", Conn2D.getAllLabels(), connLabel );
	gd.setInsets( 20, 0, 0 );
	gd.addPreviewCheckbox( pfr );
	gd.addDialogListener(this);
	previewing = true;
	gd.addHelp( "http://imagej.net/MorphoLibJ#Utilities_for_binary_images" );
	gd.showDialog();
	previewing = false;

	// test cancel
	if (gd.wasCanceled())
		return DONE;

	// set up current parameters
	weightLabel = gd.getNextChoice();
	floatProcessing = gd.getNextChoiceIndex() == 0;
	normalize = gd.getNextBoolean();
	dynamic = (int) gd.getNextNumber();
	connLabel = gd.getNextChoice();
	connectivity = Conn2D.fromLabel( connLabel ).getValue();

	// identify which weights should be used
	weights = ChamferWeights.fromLabel( weightLabel );

	return flags;
}
 
Example 6
Source File: DistanceTransformWatershed3D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Plugin run method
 */
public void run(String arg) {
	
	ImagePlus image = WindowManager.getCurrentImage();
	if ( image == null ) 
	{
		IJ.error("Distance Transform Watershed 3D",
				"Need at least one image to work");
		return;
	}

	if( !BinaryImages.isBinaryImage( image ) )
	{
		IJ.error( "Distance Transform Watershed 3D", "Input image is not"
				+ " binary (8-bit with only 0 or 255 values)" );
	}

	// Create a new generic dialog with appropriate options
	GenericDialog gd = new GenericDialog( "Distance Transform Watershed 3D" );
	gd.setInsets( 0, 0, 0 );
	gd.addMessage( "Distance map options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addChoice( "Distances", ChamferWeights3D.getAllLabels(), weightLabel );
	String[] outputTypes = new String[]{"32 bits", "16 bits"};
	gd.addChoice( "Output Type", outputTypes, outputTypes[ floatProcessing ? 0:1 ]);
	gd.setInsets( 0, 0, 0 );
	gd.addCheckbox( "Normalize weights", normalize );
	gd.setInsets( 20, 0, 0 );
	gd.addMessage( "Watershed options:",
			new Font( "SansSerif", Font.BOLD, 12 ) );
	gd.addNumericField( "Dynamic", dynamic, 2 );
	gd.addChoice( "Connectivity", Conn3D.getAllLabels(),
			connectivity.label );
	gd.addHelp( "http://imagej.net/MorphoLibJ#Utilities_for_binary_images" );
	gd.showDialog();

	// test cancel
	if ( gd.wasCanceled() )
		return;

	// set up current parameters
	weightLabel = gd.getNextChoice();
	floatProcessing = gd.getNextChoiceIndex() == 0;
	normalize = gd.getNextBoolean();
	dynamic = (int) gd.getNextNumber();
	connectivity = Conn3D.fromLabel( gd.getNextChoice() );

	// identify which weights should be used
	weights = ChamferWeights3D.fromLabel( weightLabel );

	long t0 = System.currentTimeMillis();

	final ImagePlus result;
	if (floatProcessing)
		result = processFloat( image, weights.getFloatWeights(), normalize );
	else
		result = processShort( image, weights.getShortWeights(), normalize );

	Images3D.optimizeDisplayRange( result );

	// Display the result image
	result.show();
	result.setSlice( image.getCurrentSlice() );

	// Display elapsed time
	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime( "Distance Transform Watershed 3D",
			t1 - t0, image );
}
 
Example 7
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 8
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;
	}