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

The following examples show how to use ij.gui.GenericDialog#addStringField() . 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: ReplaceLabelValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run(String arg0) 
{
	ImagePlus imagePlus = IJ.getImage();
	
	GenericDialog gd = new GenericDialog("Remove/Replace Label(s)");
	gd.addStringField("Label(s)", "1", 12);
	gd.addMessage("Separate label values by \",\"");
	gd.addNumericField("Final Value", 0, 0);
	gd.addMessage("Replacing by value 0\n will remove labels");
	gd.showDialog();
	
	if (gd.wasCanceled())
		return;
	
	String labelListString = gd.getNextString();
	double finalValue = gd.getNextNumber();

	float[] labelArray = parseLabels(labelListString);
	
	// replace values in original image
	LabelImages.replaceLabels(imagePlus, labelArray, (float) finalValue);
	imagePlus.updateAndDraw();
}
 
Example 2
Source File: Save3dTIFF.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void queryAdditionalParameters( final GenericDialog gd, final SpimData2 spimData )
{
	if ( defaultPath == null || defaultPath.length() == 0 )
	{
		defaultPath = spimData.getBasePath().getAbsolutePath();
		
		if ( defaultPath.endsWith( "/." ) )
			defaultPath = defaultPath.substring( 0, defaultPath.length() - 1 );
		
		if ( defaultPath.endsWith( "/./" ) )
			defaultPath = defaultPath.substring( 0, defaultPath.length() - 2 );
	}

	gd.addStringField( "Output_file_directory", defaultPath, 50 );
}
 
Example 3
Source File: LayerSet.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
protected Tag askForNewTag(final int keyCode) {
	GenericDialog gd = new GenericDialog("Define new tag");
	gd.addMessage("Define new tag for key: " + ((char)keyCode));
	TreeSet<Tag> ts = getTags(keyCode);
	gd.addStringField("New tag:", "", 40);
	if (null != ts && ts.size() > 0) {
		String[] names = new String[ts.size()];
		int next = 0;
		for (Tag t : ts) names[next++] = t.toString();
		gd.addChoice("Existing tags for " + ((char)keyCode) + ":", names, names[0]);
	}
	gd.showDialog();
	if (gd.wasCanceled()) return null;
	String tag = gd.getNextString().trim();
	if (0 == tag.length()) {
		Utils.logAll("Invalid tag " + tag);
		return null;
	}
	return putTag(tag, keyCode);
}
 
Example 4
Source File: ExportToRenderUsingBasisStack_Plugin.java    From render with GNU General Public License v2.0 5 votes vote down vote up
boolean setParametersFromDialog() {

            final GenericDialog dialog = new GenericDialog("Export Parameters");

            final int defaultTextColumns = 100;
            dialog.addStringField("Render Web Services Base URL", baseDataUrl, defaultTextColumns);
            dialog.addStringField("Basis Render Stack Owner", basisRenderOwner, defaultTextColumns);
            dialog.addStringField("Basis Render Stack Project", basisRenderProject, defaultTextColumns);
            dialog.addStringField("Basis Render Stack Name", basisRenderStack, defaultTextColumns);
            layerRange.addFieldsToDialog(dialog);
            dialog.addStringField("Target Render Stack Owner", targetRenderOwner, defaultTextColumns);
            dialog.addStringField("Target Render Stack Project", targetRenderProject, defaultTextColumns);
            dialog.addStringField("Target Render Stack Name", targetRenderStack, defaultTextColumns);
            dialog.addStringField("TrakEM2 Z to Target Z Map", trakZToTargetZMapString, defaultTextColumns);
            dialog.addMessage("  note: leave empty to skip mapping, format is a=b,c=d");
            dialog.addCheckbox("Complete Stack After Export", completeStackAfterExport);

            dialog.showDialog();
            dialog.repaint(); // seems to help with missing dialog elements, but shouldn't be necessary

            final boolean wasCancelled = dialog.wasCanceled();

            if (! wasCancelled) {
                baseDataUrl = dialog.getNextString().trim();
                basisRenderOwner = dialog.getNextString().trim();
                basisRenderProject = dialog.getNextString().trim();
                basisRenderStack =  dialog.getNextString().trim();
                layerRange.setFieldsFromDialog(dialog);
                targetRenderOwner = dialog.getNextString().trim();
                targetRenderProject = dialog.getNextString().trim();
                targetRenderStack =  dialog.getNextString().trim();
                trakZToTargetZMapString =  dialog.getNextString().trim();
                completeStackAfterExport = dialog.getNextBoolean();

                sectionIdToDataMap.clear();
                trakZToTargetZMap.clear();
            }

            return wasCancelled;
        }
 
Example 5
Source File: ExportToRenderAsIs_Plugin.java    From render with GNU General Public License v2.0 5 votes vote down vote up
boolean setParametersFromDialog() {

            final GenericDialog dialog = new GenericDialog("Export Parameters");

            final int defaultTextColumns = 100;
            dialog.addStringField("Render Web Services Base URL", baseDataUrl, defaultTextColumns);
            layerRange.addFieldsToDialog(dialog);
            dialog.addCheckbox("Only Export Visible Patches", onlyExportVisiblePatches);
            dialog.addCheckbox("Use Patch Title For Tile ID", usePatchTitleForTileId);
            dialog.addMessage("  note: leave unchecked to use TrakEM2 patch object ID as tile ID");
            dialog.addStringField("Target Render Stack Owner", targetRenderOwner, defaultTextColumns);
            dialog.addStringField("Target Render Stack Project", targetRenderProject, defaultTextColumns);
            dialog.addStringField("Target Render Stack Name", targetRenderStack, defaultTextColumns);
            dialog.addNumericField("Stack Resolution X (nm/pixel)", stackResolutionX, 0);
            dialog.addNumericField("Stack Resolution Y (nm/pixel)", stackResolutionY, 0);
            dialog.addNumericField("Stack Resolution Z (nm/pixel)", stackResolutionZ, 0);
            dialog.addCheckbox("Complete Stack After Export", completeStackAfterExport);

            dialog.showDialog();
            dialog.repaint(); // seems to help with missing dialog elements, but shouldn't be necessary

            final boolean wasCancelled = dialog.wasCanceled();

            if (! wasCancelled) {
                baseDataUrl = dialog.getNextString().trim();
                layerRange.setFieldsFromDialog(dialog);
                onlyExportVisiblePatches = dialog.getNextBoolean();
                usePatchTitleForTileId = dialog.getNextBoolean();
                targetRenderOwner = dialog.getNextString().trim();
                targetRenderProject = dialog.getNextString().trim();
                targetRenderStack =  dialog.getNextString().trim();
                stackResolutionX = dialog.getNextNumber();
                stackResolutionY = dialog.getNextNumber();
                stackResolutionZ = dialog.getNextNumber();
                completeStackAfterExport = dialog.getNextBoolean();
            }

            return wasCancelled;
        }
 
Example 6
Source File: SelectLabelsPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void run(String args) {
    ImagePlus imagePlus = IJ.getImage();
    
    // create the dialog, with operator options
    GenericDialog gd = new GenericDialog("Select Label(s)");
    gd.addMessage("Add labels seperated by comma.\nEx: [1, 2, 6, 9]");
    gd.addStringField("Label(s)", "1");
    gd.showDialog();
    
    // If cancel was clicked, do nothing
    if (gd.wasCanceled())
        return;
    
    // extract label index, and number of pixel border to add
    String labelString = (String) gd.getNextString();
  
    int[] labels = IJUtils.parseLabelList(labelString);
    ImagePlus selectedPlus = LabelImages.keepLabels(imagePlus, labels);
    		
    // copy settings
    selectedPlus.copyScale(imagePlus);
    selectedPlus.setDisplayRange(imagePlus.getDisplayRangeMin(), imagePlus.getDisplayRangeMax());
    selectedPlus.setLut( imagePlus.getProcessor().getLut() );

    // display and adapt visible slice
    selectedPlus.show();
    if (imagePlus.getStackSize() > 1)
    {	
    	selectedPlus.setSlice(imagePlus.getCurrentSlice());
    }
}
 
Example 7
Source File: Specify_Calibration.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static boolean queryNewCal( final ArrayList< Cal > calibrations, final Cal maxCal )
{
	final GenericDialog gd = new GenericDialog( "Define new calibration" );
	
	gd.addNumericField( "Calibration_x", maxCal.getCal()[ 0 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 0 ] );
	gd.addNumericField( "Calibration_y", maxCal.getCal()[ 1 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 1 ] );
	gd.addNumericField( "Calibration_z", maxCal.getCal()[ 2 ], 40, 20, "" );
	// ImageJ cuts of part of the number otherwise
	((TextField)gd.getNumericFields().lastElement()).setText( "" + maxCal.getCal()[ 2 ] );
	gd.addStringField( "Unit", maxCal.unit() );

	if ( calibrations.size() > 1 )
		gd.addMessage( "WARNING: Calibrations are not the same for all\n" +
					   "view setups! All calibrations will be overwritten\n" +
					   "for all view setups if defined here.",
					   GUIHelper.mediumstatusfont, GUIHelper.warning );

	gd.addMessage( "Note: These values will be applied to selected view\n" +
				   "setups, existing registration are not affected and\n" +
				   "will need to be recomputed if necessary.",
				   GUIHelper.mediumstatusfont );

	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return false;
	
	maxCal.getCal()[ 0 ] = gd.getNextNumber();
	maxCal.getCal()[ 1 ] = gd.getNextNumber();
	maxCal.getCal()[ 2 ] = gd.getNextNumber();
	maxCal.setUnit( gd.getNextString() );

	return true;
}
 
Example 8
Source File: ProjectTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public void rename(final ProjectThing thing) {
	final Object ob = thing.getObject();
	final String old_title;
	if (null == ob) old_title = thing.getType();
	else if (ob instanceof DBObject) old_title = ((DBObject)ob).getTitle();
	else old_title = ob.toString();
	GenericDialog gd = ControlWindow.makeGenericDialog("New name");
	gd.addMessage("Old name: " + old_title);
	gd.addStringField("New name: ", old_title, 40);
	gd.showDialog();
	if (gd.wasCanceled()) return;
	String title = gd.getNextString();
	if (null == title) {
		Utils.log("WARNING: avoided setting the title to null for " + thing);
		return;
	}
	title = title.replace('"', '\'').trim(); // avoid XML problems - could also replace by double '', then replace again by " when reading.
	project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
	if (title.length() == 0) {
		// Set the title to the template type
		thing.setTitle(thing.getTemplate().getType());
		return;
	}
	thing.setTitle(title);
	this.updateUILater();
	project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
}
 
Example 9
Source File: ImportFromRender_Plugin.java    From render with GNU General Public License v2.0 4 votes vote down vote up
boolean setParametersFromDialog() {

            final GenericDialog dialog = new GenericDialog("Import Parameters");

            final int defaultTextColumns = 80;
            dialog.addStringField("Render Web Services Base URL", baseDataUrl, defaultTextColumns);
            dialog.addStringField("Render Stack Owner", renderOwner, defaultTextColumns);
            dialog.addStringField("Render Stack Project", renderProject, defaultTextColumns);
            dialog.addStringField("Render Stack Name", renderStack, defaultTextColumns);
            dialog.addStringField("Channel (empty for default)", "", defaultTextColumns);
            dialog.addNumericField("Min Z", minZ, 1);
            dialog.addNumericField("Max Z", maxZ, 1);
            dialog.addNumericField("Image Plus Type (use '-1' to slowly derive dynamically)", imagePlusType, 0);
            dialog.addMessage("  note: image plus type values are: 0:GRAY8, 1:GRAY16, 2:GRAY32, 3:COLOR_256, 4:COLOR_RGB");
            dialog.addCheckbox("Load Masks", loadMasks);
            dialog.addCheckbox("Split Sections", splitSections);
            dialog.addCheckbox("Replace Last Transform With Stage", replaceLastWithStage);
            dialog.addNumericField("Number of threads for mipmaps", numberOfMipmapThreads, 0);

            dialog.showDialog();
            dialog.repaint(); // seems to help with missing dialog elements, but shouldn't be necessary

            final boolean wasCancelled = dialog.wasCanceled();

            if (! wasCancelled) {
                baseDataUrl = dialog.getNextString();
                renderOwner = dialog.getNextString();
                renderProject = dialog.getNextString();
                renderStack =  dialog.getNextString();
                String channelString = dialog.getNextString();
                if (channelString != null && channelString.length() > 0) {
                    channels.add(channelString);
                }
                minZ = dialog.getNextNumber();
                maxZ = dialog.getNextNumber();
                imagePlusType = new Double(dialog.getNextNumber()).intValue();
                loadMasks = dialog.getNextBoolean();
                splitSections = dialog.getNextBoolean();
                replaceLastWithStage = dialog.getNextBoolean();
                numberOfMipmapThreads = (int) dialog.getNextNumber();
            }

            return wasCancelled;
        }
 
Example 10
Source File: Define_Bounding_Box.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public BoundingBox defineBoundingBox(
		final SpimData2 data,
		final List< ViewId > viewIds,
		final String clusterExtension,
		final String xmlFileName,
		final boolean saveXML )
{
	final String[] boundingBoxDescriptions = new String[ staticBoundingBoxAlgorithms.size() ];

	for ( int i = 0; i < staticBoundingBoxAlgorithms.size(); ++i )
		boundingBoxDescriptions[ i ] = staticBoundingBoxAlgorithms.get( i ).getDescription();

	if ( defaultBoundingBoxAlgorithm >= boundingBoxDescriptions.length )
		defaultBoundingBoxAlgorithm = 0;

	final GenericDialog gd = new GenericDialog( "Image Fusion" );

	gd.addChoice( "Bounding_Box", boundingBoxDescriptions, boundingBoxDescriptions[ defaultBoundingBoxAlgorithm ] );
	gd.addStringField( "Bounding_Box_Name", defaultName, 30 );

	// assemble the last registration names of all viewsetups involved
	final HashMap< String, Integer > names = GUIHelper.assembleRegistrationNames( data, viewIds );
	gd.addMessage( "" );
	GUIHelper.displayRegistrationNames( gd, names );
	gd.addMessage( "" );

	GUIHelper.addWebsite( gd );

	if ( names.keySet().size() > 5 )
		GUIHelper.addScrollBars( gd );
	
	gd.showDialog();

	if ( gd.wasCanceled() )
		return null;

	final int boundingBoxAlgorithm = defaultBoundingBoxAlgorithm = gd.getNextChoiceIndex();
	final String boundingBoxName = gd.getNextString();

	for ( final BoundingBox bb : data.getBoundingBoxes().getBoundingBoxes() )
	{
		if ( bb.getTitle().equals( boundingBoxName ) )
		{
			IOFunctions.println( "A bounding box with the name '" + boundingBoxName + "' already exists." );
			defaultName = boundingBoxName + "1";
			return null;
		}
	}

	final BoundingBoxGUI boundingBox = staticBoundingBoxAlgorithms.get( boundingBoxAlgorithm ).newInstance( data, viewIds );

	if ( !boundingBox.queryParameters( null, null ) )
		return null;

	boundingBox.setTitle( boundingBoxName );
	defaultName = boundingBoxName + "1";

	data.getBoundingBoxes().addBoundingBox( boundingBox );

	if ( saveXML )
		SpimData2.saveXML( data, xmlFileName, clusterExtension );

	return boundingBox;
}
 
Example 11
Source File: GenericLoadParseQueryXML.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Querys a pattern of element from the list
 * 
 * @param name - type of elements (e.g. "Timepoints")
 * @param list - list of available elements
 * @param defaultSelectionArray - default selection (array of size 1 to be able to return it)
 * @return the selection or null if cancelled
 */
public static boolean[] queryPattern( final String name, final String[] list, final String[] defaultSelectionArray )
{
	String defaultSelection = defaultSelectionArray[ 0 ];

	if ( defaultSelection == null || defaultSelection.length() == 0 )
	{
		defaultSelection = list[ 0 ];
		
		for ( int i = 1; i < Math.min( list.length, 3 ); ++i )
			defaultSelection += "," + list[ i ];
	}
	
	final GenericDialog gd = new GenericDialog( "Select Range of " + name );
	
	gd.addMessage( "" );
	gd.addStringField( "Process_following_" + name, defaultSelection, 30 );
	gd.addMessage( "" );
	gd.addMessage( "Available " + name + ":" );
	
	final String singular = name.substring( 0, name.length() - 1 ) + " ";
	String allTps = singular + list[ 0 ];
	
	for ( int i = 1; i < list.length; ++i )
		allTps += "\n" + singular + list[ i ];
	
	gd.addMessage( allTps, GUIHelper.smallStatusFont );
	
	GUIHelper.addScrollBars( gd );
	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return null;
	
	// the result
	final boolean[] selected = new boolean[ list.length ];
	
	for ( int i = 0; i < list.length; ++i )
		selected[ i ] = false;
	
	try 
	{
		final ArrayList< String > nameList = NamePattern.parseNameString( defaultSelection = gd.getNextString(), true );
		
		for ( final String entry : nameList )
		{
			boolean found = false;
			
			for ( int i = 0; i < list.length && !found; ++i )
			{
				if ( entry.equals( list[ i ] ) )
				{
					selected[ i ] = true;
					found = true;
				}
			}
			
			if ( !found )
				IOFunctions.println( name + " " + entry + " not part of the list of " + name + "s. Ignoring it." );
		}				
	} 
	catch ( final ParseException e ) 
	{
		IOFunctions.println( "Cannot parse pattern '" + defaultSelection + "': " + e );
		return null;
	}
	
	defaultSelectionArray[ 0 ] = defaultSelection;
	
	return selected;
}
 
Example 12
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 13
Source File: Displayable.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
protected GenericDialog makeAdjustPropertiesDialog() {
	Rectangle box = getBoundingBox(null);
	GenericDialog gd = new GD("Properties of #" + id, this);
	gd.addStringField("title: ", title);
	gd.addNumericField("x: ", box.x, 2);
	gd.addNumericField("y: ", box.y, 2);
	gd.addNumericField("scale_x: ", 1, 2);
	gd.addNumericField("scale_y: ", 1, 2);
	gd.addNumericField("rot (degrees): ", 0, 2);
	gd.addSlider("alpha: ", 0, 100, (int)(alpha*100));
	gd.addCheckbox("visible", visible);
	gd.addSlider("Red: ", 0, 255, color.getRed());
	gd.addSlider("Green: ", 0, 255, color.getGreen());
	gd.addSlider("Blue: ", 0, 255, color.getBlue());
	gd.addCheckbox("locked", locked);
	// add slider listener
	final Scrollbar alp = (Scrollbar)gd.getSliders().get(0);
	final Scrollbar red = (Scrollbar)gd.getSliders().get(1);
	final Scrollbar green = (Scrollbar)gd.getSliders().get(2);
	final Scrollbar blue = (Scrollbar)gd.getSliders().get(3);
	final TextField talp = (TextField)gd.getNumericFields().get(5);
	final TextField tred = (TextField)gd.getNumericFields().get(6);
	final TextField tgreen = (TextField)gd.getNumericFields().get(7);
	final TextField tblue = (TextField)gd.getNumericFields().get(8);
	SliderListener sla = new SliderListener() {
		public void update() {
			setAlpha((float)alp.getValue()/100);
		}
	};
	SliderListener slc = new SliderListener() {
		public void update() {
			setColor(new Color(red.getValue(), green.getValue(), blue.getValue()));
		}
	};
	alp.addAdjustmentListener(sla);
	red.addAdjustmentListener(slc);
	green.addAdjustmentListener(slc);
	blue.addAdjustmentListener(slc);
	talp.addTextListener(sla);
	tred.addTextListener(slc);
	tgreen.addTextListener(slc);
	tblue.addTextListener(slc);
	
	gd.addChoice( "composite mode: ", compositeModes, compositeModes[ compositeMode ] );
	return gd;
}
 
Example 14
Source File: Compare.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public boolean setup(final boolean to_file, final String regex, final boolean plot, final boolean condense) {
	final GenericDialog gd = new GenericDialog("All to all");
	gd.addMessage("Choose a point interdistance to resample to, or 0 for the average of all.");
	gd.addNumericField("point_interdistance: ", delta, 2);
	gd.addCheckbox("skip insertion/deletion strings at ends when scoring", skip_ends);
	gd.addNumericField("maximum_ignorable consecutive muts in endings: ", max_mut, 0);
	gd.addNumericField("minimum_percentage that must remain: ", min_chunk, 2);
	gd.addCheckbox("Score mutations only", score_mut_only);
	Utils.addEnablerListener((Checkbox)gd.getCheckboxes().get(0), new Component[]{(Component)gd.getNumericFields().get(0), (Component)gd.getNumericFields().get(1)}, null);

	final String[] transforms = {"translate and rotate",
				     "translate, rotate and scale",
				     "translate, rotate, scale and shear",
				     "moving least squares",
				     "relative",
				     "direct"};
	gd.addChoice("Transform_type: ", transforms, transforms[transform_type]);
	gd.addCheckbox("Chain_branches", chain_branches);

	gd.addChoice("Presets: ", preset_names, preset_names[0]);
	gd.addMessage("");
	gd.addChoice("Scoring type: ", distance_types, distance_types[distance_type]);
	final String[] distance_types2 = {"Levenshtein", "Dissimilarity", "Average physical distance", "Median physical distance", "Cummulative physical distance", "Standard deviation", "Combined SLM", "Proximity", "Proximity of mutation pairs", "None"}; // CAREFUL when adding more entries: index 9 is used as None for sortMatches and as a conditional.
	gd.addChoice("Resort scores by: ", distance_types2, distance_types2[distance_type_2]);
	gd.addNumericField("Min_matches: ", min_matches, 0);
	if (to_file) {
		gd.addChoice("File format: ", formats, formats[2]);
	}
	gd.addCheckbox("normalize", normalize);
	gd.addCheckbox("direct", direct);
	gd.addCheckbox("substring_matching", substring_matching);
	gd.addStringField("regex: ", null != regex ? regex : "");
	if (plot) {
		gd.addNumericField("plot_width: ", plot_width, 0);
		gd.addNumericField("plot_height: ", plot_height, 0);
		gd.addNumericField("plot_max_x: ", plot_max_x, 2);
		gd.addNumericField("plot_max_y: ", plot_max_y, 2);
	}
	if (condense) {
		gd.addCheckbox("cut_uneven_ends", cut_uneven_ends);
		final String[] env = {"1 std dev", "2 std dev", "3 std dev", "average", "maximum"};
		gd.addChoice("envelope", env, env[envelope_type]);
		gd.addNumericField("delta envelope:", delta_envelope, 1);
	}

	//////

	gd.showDialog();
	if (gd.wasCanceled()) return false;

	delta = gd.getNextNumber();
	skip_ends = gd.getNextBoolean();
	max_mut = (int)gd.getNextNumber();
	min_chunk = (float)gd.getNextNumber();
	score_mut_only = gd.getNextBoolean();
	if (skip_ends) {
		if (max_mut < 0) max_mut = 0;
		if (min_chunk <= 0) skip_ends = false;
		if (min_chunk > 1) min_chunk = 1;
	}
	transform_type = gd.getNextChoiceIndex();
	chain_branches = gd.getNextBoolean();
	preset = presets[gd.getNextChoiceIndex()];

	distance_type = gd.getNextChoiceIndex();
	distance_type_2 = gd.getNextChoiceIndex();
	min_matches = (int) gd.getNextNumber();
	if (min_matches < 0) {
		Utils.log("Using 0 min_matches!");
		min_matches = 0;
	}

	format = formats[0];
	if (to_file) format = gd.getNextChoice().trim();

	normalize = gd.getNextBoolean();
	direct = gd.getNextBoolean();
	substring_matching = gd.getNextBoolean();

	this.regex = gd.getNextString().trim();
	if (0 == this.regex.length()) this.regex = null;

	if (plot) {
		plot_width = (int)gd.getNextNumber();
		plot_height = (int)gd.getNextNumber();
		plot_max_x = gd.getNextNumber();
		plot_max_y = gd.getNextNumber();
	}
	if (condense) {
		cut_uneven_ends = gd.getNextBoolean();
		envelope_type = gd.getNextChoiceIndex();
		delta_envelope = gd.getNextNumber();
		Utils.log2("delta_envelope has been set to " + delta_envelope);
	}

	return true;
}
 
Example 15
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Setup as a three step dialog.
 */
@Override
public boolean setup( final String title )
{
	source_dir = "";
	while ( source_dir == "" )
	{
		final DirectoryChooser dc = new DirectoryChooser( "Calibration Images" );
		source_dir = dc.getDirectory();
		if ( null == source_dir ) return false;

		source_dir = source_dir.replace( '\\', '/' );
		if ( !source_dir.endsWith( "/" ) ) source_dir += "/";
	}

	final String exts = ".tif.jpg.png.gif.tiff.jpeg.bmp.pgm";
	names = new File( source_dir ).list(
			new FilenameFilter()
			{
				@Override
                      public boolean accept( final File dir, final String name )
				{
					final int idot = name.lastIndexOf( '.' );
					if ( -1 == idot ) return false;
					return exts.contains( name.substring( idot ).toLowerCase() );
				}
			} );
	Arrays.sort( names );

	final GenericDialog gd = new GenericDialog( title );

	gd.addNumericField( "number_of_images :", 9, 0 );
	gd.addChoice( "first_image :", names, names[ 0 ] );
	gd.addNumericField( "power_of_polynomial_kernel :", dimension, 0 );
	gd.addNumericField( "lambda :", lambda, 6 );
	gd.addCheckbox( "apply_correction_to_images", applyCorrection );
	gd.addCheckbox( "visualize results", visualizeResults );
	final String[] options = new String[]{ "save", "load" };
	gd.addChoice( "What to do? ", options, options[ saveOrLoad ] );
	gd.addStringField( "file_name: ", saveFileName );
	gd.showDialog();

	if (gd.wasCanceled()) return false;

	numberOfImages = ( int )gd.getNextNumber();
	firstImageIndex = gd.getNextChoiceIndex();
	dimension = ( int )gd.getNextNumber();
	lambda = gd.getNextNumber();
	applyCorrection = gd.getNextBoolean();
	visualizeResults = gd.getNextBoolean();
	saveOrLoad = gd.getNextChoiceIndex();
	saveFileName = gd.getNextString();

	if ( saveOrLoad == 0 || visualizeResults )
	{
		final GenericDialog gds = new GenericDialog( title );
		SIFT.addFields( gds, sift );

		gds.addNumericField( "closest/next_closest_ratio :", rod, 2 );

		gds.addMessage( "Geometric Consensus Filter:" );
		gds.addNumericField( "maximal_alignment_error :", maxEpsilon, 2, 6, "px" );
		gds.addNumericField( "inlier_ratio :", minInlierRatio, 2 );
		gds.addChoice( "expected_transformation :", modelStrings, modelStrings[ expectedModelIndex ] );

		gds.showDialog();
		if ( gds.wasCanceled() ) return false;

		SIFT.readFields( gds, sift );

		rod = ( float )gds.getNextNumber();

		maxEpsilon = ( float )gds.getNextNumber();
		minInlierRatio = ( float )gds.getNextNumber();
		expectedModelIndex = gds.getNextChoiceIndex();

		return !( gd.invalidNumber() || gds.invalidNumber() );
	}

	return !gd.invalidNumber();
}