FileDocCategorySizeDatePackage
AbstractUIInputReceiver.javaAPI DocAzureus 3.0.3.45130Sat Jan 06 14:25:20 GMT 2007org.gudy.azureus2.pluginsimpl.local.ui

AbstractUIInputReceiver

public abstract class AbstractUIInputReceiver extends Object implements org.gudy.azureus2.plugins.ui.UIInputReceiver
Abstract class to make it easy for class to implement UIInputReceiver classes. The common convention is that it has all the necessary set methods needed, and all settings passed are accessible through protected attributes. Checks are made to ensure only certain methods are called at the right time.

Fields Summary
private boolean
prompted
protected String[]
messages
protected String
title
protected boolean
multiline_mode
protected String
preentered_text
protected boolean
preentered_text_is_old_value
protected org.gudy.azureus2.plugins.ui.UIInputValidator
validator
private boolean
result_recorded
private boolean
result_input_submitted
private String
result_input
protected boolean
maintain_whitespace
protected boolean
allow_empty_input
Constructors Summary
public AbstractUIInputReceiver()

	
Methods Summary
public voidallowEmptyInput(boolean empty_input)

	
	    
		this.allow_empty_input = empty_input;
	
protected final voidassertPostPrompt()

		if (!prompted) {
			throw new RuntimeException("cannot before after prompt has been called");
		}		
	
protected final voidassertPrePrompt()

	
	// Helper methods.
	    
		if (prompted) {
			throw new RuntimeException("cannot invoke after prompt has been called");
		}
	
public java.lang.StringgetSubmittedInput()

		assertPostPrompt();
		return this.result_input;
	
public booleanhasSubmittedInput()

		assertPostPrompt();
		return this.result_input_submitted;
	
protected final java.lang.Stringlocalise(java.lang.String key)

		return MessageText.getString(key); 
	
public voidmaintainWhitespace(boolean keep_whitespace)

	
	    
		this.maintain_whitespace = keep_whitespace;
	
public final voidprompt()


	    
		assertPrePrompt();
		this.promptForInput();
		if (!result_recorded) {
			throw new RuntimeException(this.toString() + " did not record a result.");
		}
		this.prompted = true;
	
protected abstract voidpromptForInput()
Subclasses must override this method to receive input from the user. This method must call either recordUserInput or recordUserAbort before returning.

protected final voidrecordUserAbort()

		this.result_recorded = true;
		this.result_input_submitted = false;
		this.result_input = null;
	
protected final voidrecordUserInput(java.lang.String input)

	
	                      	 
	   
	
	     
		this.result_recorded = true;
		this.result_input_submitted = true;
		this.result_input = input;
		
		// The subclass should strip the output before it sets
		// the value here - but just in case they forget, we remember.
		//
		// Subclasses should do it that the validator can validate the stripped string.
		if (!this.maintain_whitespace) {
			this.result_input = input.trim();
		}
	
public voidsetInputValidator(org.gudy.azureus2.plugins.ui.UIInputValidator validator)


	    
		assertPrePrompt();
		this.validator = validator;
	
public voidsetLocalisedMessage(java.lang.String message)

		this.setLocalisedMessages(new String[]{message});
	
public voidsetLocalisedMessages(java.lang.String[] messages)


	    
		assertPrePrompt();
		this.messages = messages;
	
public voidsetLocalisedTitle(java.lang.String title)


	    
		assertPrePrompt();
		this.title = title;
	
public voidsetMessage(java.lang.String message)

		this.setLocalisedMessage(this.localise(message));
	
public voidsetMessages(java.lang.String[] messages)

		String[] new_messages = new String[messages.length];
		for (int i=0; i<new_messages.length; i++) {
			new_messages[i] = this.localise(messages[i]);
		}
		this.setLocalisedMessages(new_messages);
	
public voidsetMultiLine(boolean multiline)


	    
		assertPrePrompt();
		this.multiline_mode = multiline;
	
public voidsetPreenteredText(java.lang.String text, boolean as_suggested)

	
	      
		assertPrePrompt();
		this.preentered_text = text;
		this.preentered_text_is_old_value = !as_suggested;
	
public voidsetTitle(java.lang.String title)

		this.setLocalisedTitle(this.localise(title));