Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2009-2011, EzWare
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * Redistributions of source code must retain the above copyright notice,
  * this list of conditions and the following disclaimer.Redistributions
  * in binary form must reproduce the above copyright notice, this list of
  * conditions and the following disclaimer in the documentation and/or
  * other materials provided with the distribution.Neither the name of the
  * EzWare nor the names of its contributors may be used to endorse or
  * promote products derived from this software without specific prior
  * written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
 package org.oxbow.swingbits.dialog.task;
 
 import java.util.List;
 import java.util.Set;
 
 
 
 
 public class TaskDialog extends SwingBean {
 
 	private static final String INSTANCE_PROPERTY = "task.dialog.instance";
 	private static final String DEBUG_PROPERTY    = "task.dialog.debug";
 	
 	public static final String DESIGN_PROPERTY    = "task.dialog.design";
 
 	static final String I18N_PREFIX = "@@";
 	private static final String LOCALE_BUNDLE_NAME = "task-dialog";
 
 	private static IContentDesign design = prepareDesign(); //ContentDesignFactory.getDesignByOperatingSystem();
 
 	static {
 	}
 
 	private static IContentDesign prepareDesign()  {
 		String property = System.getProperty();
 		if (property != null) {
 			try {
 				return (IContentDesign) Class.forName(property).newInstance();
 			} catch (Throwable ex) {
 				throw new TaskDialogException"Could not instantiate content design: " + property , ex);
 			}
 		}
 		return ContentDesignFactory.getDesignByOperatingSystem();
 	}	
 	
 
 	static final IContentDesign getDesign() {
 		return ;
 	}

Makes resource bundle key based on the provided text

Parameters:
text
Returns:
	public static final String makeKeyString text ) {
		return  + text;
	}

Returns task dialog instance associated with source component

Parameters:
source
Returns:
task dialog instance associated with source component or null if none
	public final static TaskDialog getInstanceComponent source ) {
		Window w = SwingUtilities.getWindowAncestor(source);
		if ( w instanceof JDialog ) {
		}
		return null;
	}

Sets debug mode for task dialog framework.

Parameters:
debug
	public final static void setDebugModeboolean debug ) {
		if ( debug ) {
			System.setProperty("true");
else {
		}
	}

True if debug mode is set. In debug mode component bounds and grid cells are outlined. This helps with debugging overall appearance of task dialog UI.

Returns:
true if debug mode is set
	public final static boolean isDebugMode() {
		return System.getProperty() != null;
	}


Set of standard dialog icons. Look and Feel dependent
	public static enum StandardIcon implements Icon {
		INFO    ( . ),     // "OptionPane.informationIcon"
		QUESTION( . ), // "OptionPane.questionIcon" 
		WARNING ( . ),  // "OptionPane.warningIcon"    
		ERROR   ( . );    // "OptionPane.errorIcon"      
		private final String key;
		private StandardIconString key ) {
			this. = key;
		}
		public int getIconHeight() {
		}
		public int getIconWidth() {
			return getIcon().getIconWidth();
		}
		public void paintIcon(Component cGraphics gint xint y) {
			getIcon().paintIcon(cgxy);
		}


Always returns an valid instance of icon.

Returns:
		private synchronized javax.swing.Icon getIcon() {
			Icon icon = UIManager.getIcon(); // No caching to facilitate LAF switching.
			return icon == nullgetEmptyIcon(): icon;
		}
		private Icon emptyIcon;
		private synchronized Icon getEmptyIcon() {
			if ( == null = EmptyIcon.hidden();
			return ;
		}
	}
	private static final KeyStroke KS_ESCAPE = KeyStroke.getKeyStroke(.,0);
	private static final KeyStroke KS_ENTER  = KeyStroke.getKeyStroke(.,0);
	private static final KeyStroke KS_F1     = KeyStroke.getKeyStroke(.,0);

Standard Command Tags, correspond directly to button tags in MigLayout
	public static enum CommandTag {
		OK("ok"truetrue ),        // OK button
		CANCEL("cancel"true ),     // Cancel button
		HELP("help"false ),            // Help button that is normally on the right
		HELP2("help2""Help"false),   // Help button that on some platforms are placed on the left
		YES("yes"truetrue),       // Yes button
		NO("yes"true),             // No button
		APPLY("apply"),                         // Apply button
		NEXT("next"truefalse),              // Next or Forward Button
		BACK("back"),                           // Previous or Back Button
		FINISH("finish"truetrue), // Finish button
		LEFT("left"),                           // Button that should normally always be placed on the far left
		RIGHT("right");                         // Button that should normally always be placed on the far right
		private String tag;
		private final String defaultTitle;
		private boolean useValidationResult = false;
		private boolean closing;
		CommandTagString tagString defaultTitleKeyStroke defaultKeyStrokeboolean useValidationResultboolean closing ) {
			this. = "tag " + tag;
			this. =  makeKey(Strings.isEmpty(defaultTitle)? Strings.capitalize(tag) :defaultTitle);
			this. = useValidationResult;
			this. = closing;
			this. = defaultKeyStroke;
		}
		CommandTagString tagString defaultTitleKeyStroke defaultKeyStrokeboolean closing ) {
			thistagdefaultTitledefaultKeyStrokefalseclosing );
		}
		CommandTagString tagKeyStroke defaultKeyStrokeboolean closing ) {
			thistagnulldefaultKeyStrokefalseclosing );
		}
		CommandTagString tagboolean closing ) {
			thistagnullclosing );
		}
		CommandTagString tag) {
			thistagfalse );
		}
		CommandTagString tagKeyStroke defaultKeyStrokeboolean useValidationResultboolean closing ) {
			thistagnulldefaultKeyStrokeuseValidationResultclosing );
		}
		CommandTagString tagboolean useValidationResultboolean closing ) {
			thistagnulluseValidationResultclosing );
		}
		public String getDefaultTitle() {
			return ;
		}
		public String toString() {
			return ;
		}
		public boolean isEnabledboolean validationResult ) {
			return validationResulttrue;
		}
		public boolean isClosing() {
			return ;
		}
		}
	}
	public interface ValidationListener {
		void validationFinishedboolean validationResult ); // possibly need a collection of errors/warnings
	}

Interface to define task dialog commands
	public interface Command {
		public String getTitle();
		public CommandTag getTag();
		public boolean isClosing();
		public int getWaitInterval(); // in seconds
		public boolean isEnabledboolean validationResult );
	}


Set of standard task dialog commands
	public static enum StandardCommand implements Command {
		OK    ( .  ),
		CANCEL( . );
		private final CommandTag tag;
			this.     = tag;
		}
		public String getDescription() {
			return null;
		}
		public CommandTag getTag() {
			return ;
		}
		public String getTitle() {
		}
		public boolean isClosing() {
			return .isClosing();
		}
		public int getWaitInterval() {
			return 0;
		}
		public boolean isEnabledboolean validationResult ) {
			return .isEnabled(validationResult);
		}
		public KeyStroke getKeyStroke() {
		}

Creates a copy of the command with specified title

Parameters:
title new title. Used as key for i18n if starts with I18N_PREFIX
waitInterval in seconds
Returns:
copy of the command
		public Command derivefinal String titlefinal int waitInterval ) {
			return new CustomCommandStandardCommand.this ) {
				public String getTitle() {
					return title;
				}
				public int getWaitInterval() {
					return waitInterval;
				}
			};
		}

Creates a copy of the command with specified title

Parameters:
title new title. Used as key for i18n if starts with #I18N_PREFIX
Returns:
copy of the command
		public Command derivefinal String title ) {
			return new CustomCommandStandardCommand.this ) {
				public String getTitle() {
					return title;
				}
			};
		}
	}
	public static abstract class CustomCommand implements Command {
		private final StandardCommand command;
		public CustomCommandStandardCommand command ) {
			if ( command == null ) throw new IllegalArgumentException("Command should not be null");
			this. = command;
		}
		public String getDescription() {
		}
		public CommandTag getTag() {
			return .getTag();
		}
		public String getTitle() {
			return .getTitle();
		}
		public boolean isClosing() {
			return .isClosing();
		}
		public int getWaitInterval() {
		}
		public boolean isEnabledboolean validationResult ) {
			return .isEnabled(validationResult);
		}
		public boolean equals(Object obj) {
			return .equals(obj);
		}
		public int hashCode() {
			return .hashCode();
		}
		public KeyStroke getKeyStroke() {
		}
	}

Task Dialog Details
	public interface Details {

 
Return text for collapsed label

Returns:
Sets text for collapsed label

Parameters:
label
		 void setCollapsedLabelString label );

 
Returns text for expanded label

Returns:
Sets text for expanded label

Parameters:
label
		 void setExpandedLabelString label );

 
Checks if details are in expansion state

Returns:
		 boolean isExpanded();

 
Sets expansion state

Parameters:
expanded
		 void setExpandedboolean expanded );

 
Sets the state always expanded and hide the expand checkbox.

Parameters:
always
		 void setAlwaysExpandedboolean always );

 
Checks if the details are always expanded.

Returns:
		 boolean isAlwaysExpanded();
 
 
Returns component which becomes visible when details are expanded

Returns:
Sets component which becomes visible when details are expanded

Parameters:
cmpt
	}


Task Dialog Footer
	public interface Footer {


True if footer's check box is selected (checked)

Returns:
		boolean isCheckBoxSelected();

Sets footer's check box selection status

Parameters:
selected
		void setCheckBoxSelectedboolean selected );


Returns footer's check box text

Returns:
Sets footer's check box text. Check box is only visible if it has a text

Parameters:
text
		void setCheckBoxTextString text );

Returns footer's text icon

Returns:
Sets footer's text icon. Icon is only visible if corresponding text is not empty

Parameters:
icon
		void setIconIcon icon );


Returns footer's text

Returns:
Sets footer's text. The text and corresponding icon are visible if text is not empty

Parameters:
text
		void setText(String text);
	}
  /*----------------------------------------------------------------------------------------------*/
	private final Property<Stringinstruction = new Property<String>( "instruction" ) {
		@Override public String get() { return .getInstruction(); }
		@Override protected void setValue(String instruction) { .setInstruction(instruction); }
	};
	private final Property<Stringtext = new Property<String>( "text" ) {
		@Override public String get() { return .getMainText(); }
		@Override protected void setValue(String text) { .setMainText(text); }
	};
	private final Property<Booleanvisible = new Property<Boolean>( "visible" ) {
		@Override public Boolean get() { return .isVisible(); }
		@Override protected void setValue(Boolean visible) { 
			if ( visible ) {
				// set commands first because they may depend on "visible" property change
			}
			if ( visible ) {
				// location is set relative to currently active window or dialog owner if no active window found
				// this way task dialog stays on the same monitor as it's owner
				Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
				if ( window == null || !window.isDisplayable() ) {
					window = .getOwner();
				}
else {
				.dispose(); // releases native resources
			}
	    }
	};
	private final Property<Iconicon = new Property<Icon>( "icon" ) {
		@Override public Icon get() { return .getMainIcon(); }
		@Override protected void setValue(Icon icon) { .setMainIconicon ); }
	};
	private final Property<Commandresult = new Property<Command>( "result"true ) {
		@Override public Command get() { return ; }
		@Override protected void setValue(Command command ) {  = command; }
	};	
	private Locale resourceBundleLocale = null// has to be null
	private ResourceBundle resourceBundle = null;
	private final JDialog dlg;
	private final TaskDialogContent content;
Creates a task dialog.
Automatically pick up currently active window as a parent window

Parameters:
title
	public TaskDialogfinal Window parentfinal String title ) {
		Window pWnd = parent;
		if ( pWnd == null ) {
			// find active visible top level window 
			pWnd = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
			while (pWnd != null && !pWnd.isVisible() && pWnd.getParent() != null) {
				pWnd = (WindowpWnd.getParent();
            }
		}
		 = new JDialogpWnd );
		if ( pWnd != null ) { // make sure parent's icon is used 
		}
		.setMinimumSizenew Dimension(300,150)); //TODO: make constants - should be based on LAF
		setModalityType(.); //TODO explore different modality types
			public void windowClosing(WindowEvent e) {
			}
		});
		setTitle(title);
		// store task dialog instance
	}
//	/**
//	 * This constructor is deprecated and may be removed in the next version.
//	 * Use the constructor with parent and title parameters   
//	 * @param title
//	 */
//	@Deprecated()
//	public TaskDialog( String title ) {
//		this( null, title );
//	}
	}
	public void setModalityTypeModalityType modalityType ) {
		.setModalityType(modalityType);
	}
	public boolean isResizable() {
		return .isResizable();
	}
	public void setResizableboolean resizable ) {
		.setResizable(resizable);
	}
	public final void addValidationListenerValidationListener listener ) {
		if ( listener != null ) {
		}
	}
	public final void removeValidationListenerValidationListener listener ) {
		if ( listener != null ) {
		}
	}

Notifies all listeners that validation is finished with given result Listeners are notified in the reverse sequence, meaning that first listener is notified last

Parameters:
validationResult
	public final void fireValidationFinishedboolean validationResult ) {
		// Iterate in reverse sequence so 'newer' listeners get message first
	    while (iter.hasPrevious()) {
	    	iter.previous().validationFinished(validationResult);
	    }
	}


Gets the Locale object that is associated with this window, if the locale has been set. If no locale has been set, then the default locale is returned.

Returns:
the locale that is set for this dialog
	public Locale getLocale() {
		return .getLocale();
	}

Sets locale which will be used as dialog's locale

Parameters:
newLocale null is allowed and will be interpreted as default locale
	public void setLocalefinal Locale locale ) {
		.setLocale(locale);
	}
	private synchronized final ResourceBundle getLocaleBundle() {
		Locale currentLocale = getLocale();
		if ( !currentLocale.equals()) {
			 = currentLocale;
			 = ResourceBundle.getBundle(
		}
	}


Returns a string localized using currently set locale

Parameters:
key
Returns:
	public String getLocalizedStringString key ) {
		try {
			return getLocaleBundle().getString(key);
catch ( MissingResourceException ex ) {
			return String.format("<%s>"key);
		}
	}

Tries to use text as a key to get localized text. If not found the text itself is returned

Parameters:
text
Returns:
	public String getStringString text ) {
	}
	public Object getClientPropertyObject key ) {
	}
	public void putClientPropertyObject keyObject value ) {
	}

Shows or hides this Dialog depending on the value of parameter

Parameters:
visible if true dialog is shown
	public void setVisibleboolean visible ) {
		this..set(visible);
	}

Determines whether this component should be visible when its parent is visible.

Returns:
true if visible
	public boolean isVisible() {
		return this..get();
	}
	public Command getResult() {
		return .get();
	}
	public void setResultCommand result ) {
		this..set(result);
	}


Shows the dialog

Returns:
dialog result
	public Command show() {
		return getResult();
	}
	public String toString() {
		return getTitle();
	}


Returns the title of the dialog

Returns:
	public String getTitle() {
		return .getTitle();
	}

Sets the title of the dialog

Parameters:
title
	public void setTitleString title ) {
	}

Sets icon for the dialog

Parameters:
icon
	public void setIconIcon icon) {
		this..set(icon);
	}

Returns dialog's icon

Returns:
	public Icon getIcon() {
		return this..get();
	}

Sets dialog's instruction

Parameters:
instruction
	public void setInstructionString instruction ) {
		this..set(instruction);
	}

Returns dialog instruction

Returns:
	public String getInstruction() {
		return this..get();
	}

Sets dialog text

Parameters:
text
	public void setTextString text ) {
		this..set(text);
	}

Returns Dialog text

Returns:
	public String getText() {
		return this..get();
	}

Sets Dialog component

Parameters:
c
	public void setFixedComponentJComponent c ) {
	}

Returns dialog's component

Returns:
	}
		return ;
	}
		return ;
	}
	public void setCommands(Collection<TaskDialog.Commandcommands) {
		this. = new LinkedHashSet<Command>(commands);
	}
	public void setCommandsTaskDialog.Command... commands) {
		setCommands( Arrays.asList(commands));
	}
		return ;
	}
	public boolean isCommandsVisible() {
	}
	public void setCommandsVisibleboolean visible ) {
	}
New to GrepCode? Check out our FAQ X