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

The following examples show how to use ij.gui.GenericDialog#getNextString() . 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: 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 3
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 4
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 5
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 6
Source File: SnippetCreator.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
	final Object source = (e == null) ? null : e.getSource();
	final Vector<?> choices = gd.getChoices();
	final Vector<?> fields = gd.getStringFields();
	final Button[] buttons = gd.getButtons();
	final Choice fChoice = (Choice) choices.elementAt(0);
	final TextField fField = (TextField) fields.elementAt(0);
	final Button okButton = buttons[0];

	sFilename = gd.getNextString();
	sType = gd.getNextChoiceIndex();
	infoMsg = (MultiLineLabel) gd.getMessage();

	// Populate text area
	if (source == fChoice) {
		String header = "";
		switch (sType) {
		case BSH:
			header = bshHeader();
			break;
		case CLJ:
			header = cljHeader();
			break;
		case GRV:
			header = grvHeader();
			break;
		case IJM:
			header = ijmHeader();
			break;
		case JS:
			header = jsHeader();
			break;
		case PY:
			header = pyHeader();
			break;
		case RB:
			header = rbHeader();
			break;
		}
		if (header != "")
			appendToTextArea(header);

		// Ensure adequate filename extension
		if (!sFilename.endsWith(S_EXTS[sType])) {
			final int index = sFilename.lastIndexOf(".");
			if (index > -1)
				sFilename = sFilename.substring(0, index);
			sFilename += S_EXTS[sType];
			fField.setText(sFilename);
		}

	}

	// Adjust labels and fields
	final File f = new File(Utils.getMyRoutinesDir() + sFilename);
	final boolean invalidName = invalidFilename(sFilename);
	okButton.setLabel(f.exists() ? "Replace and Open" : " Create and Open ");
	fField.setForeground((f.exists()||invalidName) ? Color.RED : Color.BLACK);

	// Adjust messages
	final StringBuilder sb = new StringBuilder();
	if (invalidName) {
		sb.append("\nInvalid Filename");
	} else if (f.exists()) {
		sb.append("File already exists in BAR/My_Routines!");
	} else if (sFilename.indexOf("_") == -1) {
		sb.append("\nFile does not contain an underscore");
		sb.append("\nand will not be listed in the BAR Menu.");
	} else {
		sb.append("\nFile will be listed in the BAR Menu.");
	}
	infoMsg.setText(sb.toString());
	infoMsg.setForeground(Color.DARK_GRAY);

	return !invalidName;
}
 
Example 7
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();
}