//package lu.tudor.santec.gecamed.formeditor.gui.view.dialog;
//
//import java.awt.Color;
//import java.awt.Component;
//import java.awt.Window;
//import java.awt.event.ActionEvent;
//import java.awt.event.WindowEvent;
//import java.awt.event.WindowListener;
//
//import javax.swing.AbstractAction;
//import javax.swing.Action;
//import javax.swing.BorderFactory;
//import javax.swing.Icon;
//import javax.swing.JButton;
//import javax.swing.JDialog;
//import javax.swing.JFrame;
//import javax.swing.JPanel;
//import javax.swing.JScrollPane;
//import javax.swing.JTextArea;
//import javax.swing.JTextField;
//
//import lu.tudor.santec.gecamed.core.gui.GECAMedColors;
//import lu.tudor.santec.gecamed.core.gui.GECAMedIconNames;
//import lu.tudor.santec.gecamed.core.gui.GECAMedModule;
//import lu.tudor.santec.gecamed.core.gui.IconFetcher;
//import lu.tudor.santec.gecamed.core.gui.widgets.GECAMedBaseDialog;
//import lu.tudor.santec.gecamed.formeditor.utils.FormWidgets;
//import lu.tudor.santec.i18n.Translatrix;
//
//import com.jgoodies.forms.layout.CellConstraints;
//import com.jgoodies.forms.layout.FormLayout;
//
//public class FormEditorDialog extends GECAMedBaseDialog implements WindowListener {
//	/**
//	 * 
//	 */
//	private static final long serialVersionUID = 1L;
//	
////	public static final int OK_BUTTON 		= GECAMedBaseDialog.OK_OPTION;
////	public static final int YES_BUTTON 		= GECAMedBaseDialog.YES_OPTION;
////	public static final int NO_BUTTON 		= GECAMedBaseDialog.NO_OPTION;
////	public static final int CANCEL_BUTTON 	= GECAMedBaseDialog.CANCEL_OPTION;
//	
////	private static final int DEFAULT_HEIGHT = 35; // [dlu]
////	private static final int DEFAULT_WIDTH = 200; // [dlu]
//	
//	private int buttonPressed = -1;
////	private String input = null;
//	private JTextField inputField;
////	private ButtonBarBuilder buttonBarBuilder;
//	
//	public static FormEditorDialog getNewInstance(Component parent, String title, JPanel mainPanel, int buttonMode) {
//		/* ======================================== */
//		Window owner = getFrame(parent);
//		
//		if (owner instanceof JDialog) {
//			return new FormEditorDialog((JDialog)owner, title, mainPanel, buttonMode);
//		} else {
//			return new FormEditorDialog((JFrame)owner, title, mainPanel, buttonMode);
//		}
//		/* ======================================== */
//	}
//	
//	protected FormEditorDialog (JFrame owner, String title, JPanel mainPanel, int buttonMode) {
//		super(owner, title, buttonMode);
//		init(mainPanel, buttonMode);
//	}
//
//	protected FormEditorDialog (JDialog owner, String title, JPanel mainPanel, int buttonMode) {
//		super(owner, title, buttonMode);
//		init(mainPanel, buttonMode);
//	}
//	
//	private void init (JPanel mainPanel, int buttonMode) {
//		mainPanel.setBackground(GECAMedColors.c_GECAMedBackground);
//		JScrollPane sp = new JScrollPane(mainPanel);
//		sp.getVerticalScrollBar().setUnitIncrement(16);
//		super.addMainPanel(sp);
//		super.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
//		this.addWindowListener(this);
//		this.setDefaultActions(buttonMode);
//	}
//	
//	/**
//	 * renders a dialog with the specified buttons. Like JContentPane, but GECAM-Style
//	 * 
//	 * @param parent
//	 * @param title
//	 * @param message
//	 * @param buttonMode
//	 * @return
//	 * 		an int-value, specifying the pressed button
//	 */
//	public static int showMessageDialog (Component parent, String title, String message, int buttonMode) {
//		JPanel mainPanel = new JPanel(new FormLayout(
//				"5dlu, f:400px:g, 5dlu", 	// column
////				"15px, f:400px, 0px", 	// column
//				"10dlu, f:100px:g, 15dlu"));// row
////				"10px, f:p, 0px"));// row
//		
//		// prepare TextArea
//		JTextArea textArea = FormEditorDialog.getFormatedTextArea(message);
//		textArea.setOpaque(false);
//		
//		// prepare ScrollPane
//		JScrollPane scrollPane = new JScrollPane(textArea);
//		scrollPane.setBorder(BorderFactory.createEmptyBorder());
//		scrollPane.getViewport().setBackground(GECAMedColors.c_GECAMedBackground);
//		
//		mainPanel.add(scrollPane, new CellConstraints(2, 2));
//		FormEditorDialog dialog = FormEditorDialog.getNewInstance(parent, title, mainPanel, buttonMode);
//		
//		dialog.setDefaultActions(buttonMode);
//		
//		dialog.pack();
////		dialog.setLocation(
////		centerWindowOnOwner();
////		dialog.setVisible(true);
//		
//		return dialog.showDialog();
//	}
//	
//	
//	/**
//	 * renders an input-dialog with OK- and cancel-buttons. Like JContentPane, but GECAM-Stile.
//	 * 
//	 * @param parent
//	 * @param title
//	 * @param message
//	 * @param startValue
//	 * @return
//	 * 		the text, entered in the text field or null, if cancel button was pressed
//	 */
//	public static String showInputDialog (Component parent, String title, 
//			String message, String startValue) {
//		/* ======================================== */
//		JPanel mainPanel = new JPanel(new FormLayout(
//				"5dlu, f:400px:g, 5dlu", 	// column
////				"15px, f:400px, 0px", 	// column
//				"10dlu, f:100px:g, 5dlu, f:18dlu, 15dlu"));// row
////				"10px, f:p, 5dlu, f:18dlu, 0px"));// row
////				"10dlu, f:min(129px;p):g, 5dlu, f:18dlu, 15dlu"));// row
//		
//		// prepare TextArea
//		JTextArea textArea = FormEditorDialog.getFormatedTextArea(message);
//		textArea.setOpaque(false);
//		
//		// prepare ScrollPane
////		JScrollPane scrollPane = new JScrollPane(textArea);
////		scrollPane.setBorder(BorderFactory.createEmptyBorder());
////		scrollPane.getViewport().setBackground(GECAMedColors.c_GECAMedBackground);
//		
//		// the TextField, where the new value is entered
//		JTextField inputField = new JTextField(startValue);
//		
//		mainPanel.add(textArea, new CellConstraints(2, 2));
//		mainPanel.add(inputField, new CellConstraints(2, 4));
//		FormEditorDialog dialog = FormEditorDialog.getNewInstance(parent, title, mainPanel, OK_CANCEL_BUTTON_MODE);
//
//		dialog.inputField = inputField;
//		dialog.setDefaultActions(OK_CANCEL_BUTTON_MODE);
//		
//		dialog.pack();
////		dialog.setLocation(
////		centerWindowOnOwner(dialog, dialog.getOwner());
//		int buttonPressed = dialog.showDialog();
//		
//		if (buttonPressed == CANCEL_OPTION) {
//			return null;
//		} else /* if (dialog.buttonPressed == OK_BUTTON) */ {
//			return dialog.inputField.getText();
//		}
//		/* ======================================== */
//	}
//	
//	
//	public int showDialog () {
//		centerWindowOnOwner();
//		super.setVisible(true);
//		return buttonPressed;
//	}
//	
//	public void hideDialog () {
//		super.setVisible(false);
//	}
//	
//	@Deprecated
//	@Override
//	public void setVisible (boolean visible) {
//		super.setVisible(visible);
//	}
//	
//	public int getButtonPressed () {
//		return this.buttonPressed;
//	}
//	
////	@Override
////	public void pack () {
////		/* ======================================== */
////		for (int i = 0; i < 10; i++)
////			super.pack();
////		
////		int h = super.getHeight();
////		super.setSize(super.getWidth() + 15, (h > 600 ? 600 : h) + 30);
////		/* ======================================== */
////	}
////	
////	@Override
////	public void setVisible (boolean b) {
////		super.setVisible(b);
////		if (b)
////			this.pack();
////	}
//	
//	/**
//	 * adds a new button to the button bar
//	 * @param button
//	 */
////	public void addButton (JButton button) {
////		if (buttonBarBuilder == null) {
////			createNewButtonPanel();
////		}
////		buttonBarBuilder.addGridded(button);
////		buttonBarBuilder.addRelatedGap();
////	}
//		
//	
//	/**********************************
//	 ********** HELP-METHODS **********
//	 **********************************/
//	
//	
////	private void createNewButtonPanel () {
////		buttonBarBuilder = new ButtonBarBuilder();
////		buttonBarBuilder.addGlue();
////		buttonBarBuilder.addRelatedGap();
////		buttonBarBuilder.getPanel().setOpaque(false);
////		
////		// a panel to make a gap between the dialog border and the buttons
////		JPanel gapPanel = new JPanel(new BorderLayout(5,5));
////		gapPanel.setBackground(Color.WHITE);
//////		gapPanel.setOpaque(true);
////		gapPanel.setBackground(Color.WHITE);
////		gapPanel.add(buttonBarBuilder.getPanel(), BorderLayout.CENTER);
////		gapPanel.add(new JLabel(""), BorderLayout.SOUTH);
////		gapPanel.add(new JLabel(""), BorderLayout.EAST);
////		gapPanel.add(new JLabel(""), BorderLayout.NORTH);
////		/* ------------------------------------------------------- */
////		this.add(gapPanel, BorderLayout.SOUTH);
////		/* ================================================== */
////	}
//	
//	// set the default actions to all buttons
//	public void setDefaultActions(int buttonMode) {
//		
//		super.setButtonMode(buttonMode);
//		
//		switch (buttonMode) {
//		case OK_CANCEL_BUTTON_MODE:
//			/* ---------------------------------------- */
//			// cancel
////			addButton(cancelButton);
//			cancelAction = new AbstractAction(
//					Translatrix.getTranslationString("formeditor.cancel"),
//					IconFetcher.getMiniIcon(GECAMedModule.class, GECAMedIconNames.CANCEL)) {
//				private static final long serialVersionUID = 1L;
//				
//				public void actionPerformed(ActionEvent e) {
//					buttonPressed = CANCEL_OPTION;
//					setVisible(false);
//				}
//			};
////			cancelButton.setAction(cancelAction);
//			this.setAction(CANCEL_OPTION, cancelAction);
//			/* ---------------------------------------- */
//		case OK_BUTTON_MODE:
//			/* ---------------------------------------- */
//			// OK
////			addButton(okButton);
//			okAction = new AbstractAction(
//					Translatrix.getTranslationString("formeditor.ok"),
//					IconFetcher.getMiniIcon(GECAMedModule.class, GECAMedIconNames.OK)) {
//				private static final long serialVersionUID = 1L;
//				
//				public void actionPerformed(ActionEvent e) {
//					buttonPressed = OK_OPTION;
//					setVisible(false);
//				}
//			};
////			okButton.setAction(okAction);
//			this.setAction(OK_OPTION, okAction);
//			enableOkKeyMapping(true);
//			break;
//			/* ---------------------------------------- */
//		case YES_NO_CANCEL_BUTTON_MODE:
//			/* ---------------------------------------- */
//			// cancel
////			addButton(cancelButton);
//			cancelAction = new AbstractAction(
//					Translatrix.getTranslationString("formeditor.cancel"),
//					IconFetcher.getMiniIcon(GECAMedModule.class, GECAMedIconNames.CANCEL)) {
//				private static final long serialVersionUID = 1L;
//				
//				public void actionPerformed(ActionEvent e) {
//					buttonPressed = CANCEL_OPTION;
//					setVisible(false);
//				}
//			};
//			this.setAction(CANCEL_OPTION, cancelAction);
////			cancelButton.setAction(cancelAction);
//			/* ---------------------------------------- */
//		case YES_NO_BUTTON_MODE:
//			/* ---------------------------------------- */
//			// yes
////			addButton(yesButton);
//			okAction = new AbstractAction(
//					Translatrix.getTranslationString("formeditor.yes"),
//					IconFetcher.getMiniIcon(GECAMedModule.class, GECAMedIconNames.OK)) {
//				private static final long serialVersionUID = 1L;
//				
//				public void actionPerformed(ActionEvent e) {
//					buttonPressed = YES_OPTION;
//					setVisible(false);
//				}
//			};
//			this.setAction(YES_OPTION, okAction);
////			yesButton.setAction(okAction);
//			
//			// no
////			addButton(noButton);
//			noAction = new AbstractAction(
//					Translatrix.getTranslationString("formeditor.no"),
//					IconFetcher.getMiniIcon(GECAMedModule.class, GECAMedIconNames.NO)) {
//				private static final long serialVersionUID = 1L;
//				
//				public void actionPerformed(ActionEvent e) {
//					buttonPressed = NO_OPTION;
//					setVisible(false);
//				}
//			};
//			this.setAction(NO_OPTION, noAction);
//			/* ---------------------------------------- */
//		}
//		
//		enableCancelKeyMapping(true);
//		enableOkKeyMapping(true);
//	}
//	
//	// set the action, to return the value of the inputField, if the OK-button is pressed
////	private void setInputDialogActions () {	
//////		addButton(okButton);
////		okButton.addActionListener(new ActionListener() {
////			private static final long serialVersionUID = 1L;			
////
////			public void actionPerformed(ActionEvent e) {
////				input = inputField.getText();
////				setVisible(false);
////			}
////		});
////	}
//	
//	/**********************************
//	 ********* STATIC-METHODS *********
//	 **********************************/
//	
//	public static String formatMessage(String msg, int minRowLenght, boolean useHtml) {
//		StringBuffer newMsg = new StringBuffer();
//		if (useHtml) {
//			newMsg.append("<html><body>");
//		}
//		int leftIndex = 0;
//		int rightIndex = minRowLenght;
//		while (rightIndex < msg.length()) {
//			
//			while (msg.charAt(rightIndex) != ' '
//					&& msg.charAt(rightIndex) != ','
//					&& msg.charAt(rightIndex) != ';'
//					&& msg.charAt(rightIndex) != '.'
//					&& msg.charAt(rightIndex) != ':'
//					&& msg.charAt(rightIndex) != '!'
//					&& msg.charAt(rightIndex) != '?'
//					&& msg.charAt(rightIndex) != '-') {
//				rightIndex++;
//			}
//			rightIndex++;
//			if (useHtml && msg.substring(leftIndex, rightIndex).contains("<br>")) {
//				rightIndex = msg.indexOf("<br>", leftIndex) + 4;
//				newMsg.append(msg.substring(leftIndex, rightIndex));
//			} else if (msg.substring(leftIndex, rightIndex).contains(FormWidgets.NEWLINE)) {
//				rightIndex = msg.indexOf(FormWidgets.NEWLINE, leftIndex) + 1;
//				newMsg.append(msg.substring(leftIndex, rightIndex));
//			} else {
//				newMsg.append(msg.substring(leftIndex, rightIndex));
//				newMsg.append(useHtml ? "<br>" : FormWidgets.NEWLINE);
//			}
//			leftIndex = rightIndex;
//			rightIndex += minRowLenght;
//		}
//		if (leftIndex < msg.length()) {
//			newMsg.append(msg.substring(leftIndex, msg.length()));
//			newMsg.append(useHtml ? "</body></html>" : "");
//		}
//		return newMsg.toString();
//	}
//
//	public static Window getFrame (Component c) {
//		Component tmp = c;
//		while (c != null
//				&& !(c instanceof Window)) {
//			c = c.getParent();
//			tmp = c;
//		}
//		return (Window)tmp;
//	}
//	
//	public void centerWindowOnOwner () {
//		Component owner = GECAMedModule.getCurrentModule();
//		while (!(owner instanceof Window)) {
//			owner = owner.getParent();
//		}
//		
//		this.setLocation(
//				owner.getX() + owner.getWidth() / 2 - this.getWidth() / 2, 
//				owner.getY() + owner.getHeight() / 2 - this.getHeight() / 2);
//	}
//	
//	
//	public static JTextArea getFormatedTextArea (String text) {
//		JTextArea textArea = new JTextArea();
//		textArea.setText(text);
//		textArea.setEnabled(false);
//		textArea.setOpaque(false);
//		textArea.setDisabledTextColor(Color.black);
//		textArea.setLineWrap(true);
//		textArea.setWrapStyleWord(true);
//		textArea.setCaretPosition(0);
//		
//		return textArea;
//	}
//
//	/**
//	 * Sets the action on the specified Button and returns the button.
//	 * 
//	 * @param button
//	 * @param action
//	 * @return
//	 */
//	public JButton setAction (int button, Action action) {
//		JButton b;
//		
//		switch(button) {
//		case GECAMedBaseDialog.OK_CANCEL_BUTTON_MODE:
//			cancelAction = (AbstractAction) action;
//			b = cancelButton; //.setAction(action);
//			enableCancelKeyMapping(true);
//			break;
//		case GECAMedBaseDialog.YES_NO_CANCEL_BUTTON_MODE:
//			noAction = (AbstractAction) action;
//			b = noButton; //.setAction(action);
////			return noButton;
//			break;
//		case GECAMedBaseDialog.OK_BUTTON_MODE:
//			okAction = (AbstractAction) action;
//			b = okButton; //.setAction(action);
//			enableOkKeyMapping(true);
//			break;
////			return okButton;
//		case GECAMedBaseDialog.YES_NO_BUTTON_MODE:
//			yesAction = (AbstractAction) action;
//			b = yesButton; //.setAction(action);
//			enableOkKeyMapping(true);
//			break;
////			return yesButton;
//		default:
//			return null;
//		}
//		
//		Icon icon = b.getIcon();
//		String name = b.getText();
//		b.setAction(action);
//		if (b.getIcon() == null) {
//			/* ---------------------------------------- */
//			b.setIcon(icon);
//			/* ---------------------------------------- */
//		}
//		if (b.getText() == null
//				|| b.getText().length() == 0) {
//			/* ---------------------------------------- */
//			b.setText(name);
//			/* ---------------------------------------- */
//		}
//		
//		return b;
//	}
//	
//	public JButton getButton (int button) {
//		switch(button) {
//		case GECAMedBaseDialog.CANCEL_OPTION:
//			return cancelButton;
//		case GECAMedBaseDialog.NO_OPTION:
//			return noButton;
//		case GECAMedBaseDialog.OK_OPTION:
////		case GECAMedBaseDialog.YES_OPTION:
//			if (createOkButton && !createYesButton)
//				return okButton;
//			else if (!createOkButton && createYesButton)
//				return yesButton;
//			else 
//				throw new RuntimeException("Cannot get button. Wrong button mode " +
//						"configuration, because OK & Yes buttons are created.");
//		default:
//			return null;
//		}
//	}
//	
//	/**********************************
//	 ******** LISTENER-METHODS ********
//	 **********************************/
//
//	public void windowClosing(WindowEvent e) {
//		/* ======================================== */
//		if (buttonPressed == -1) 
//		{
//			buttonOption = CLOSED_OPTION;
//			super.setVisible(false);
//		}
//		/* ======================================== */
//	}
//
//	public void windowActivated(WindowEvent e) {}
//	public void windowClosed(WindowEvent e) {}
//	public void windowDeactivated(WindowEvent e) {}
//	public void windowDeiconified(WindowEvent e) {}
//	public void windowIconified(WindowEvent e) {}
//	public void windowOpened(WindowEvent e) {}
//}
