Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright (c) 2011 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
   *  All rights reserved. This program and the accompanying materials
   *  are made available under the terms of the GNU Lesser Public License v2.1
   *  which accompanies this distribution, and is available at
   *  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
   *
   *  Contributors:
   *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany - initial API and implementation
  */
 package de.ipk_gatersleben.bit.bi.edal.rmi.client.gui.editor;
 
 
 import java.awt.Color;
 import java.awt.Font;
 import java.util.List;
 import java.util.Map;
 
 
MetasaveDialog provides a simple mechanism for the user to get the Metadata of EDAL File or Directory.

The following code pops up a MetasaveDialog:

 MetasaveDialog metasaveDialog = new MetasaveDialog();
 int returnVal = metasaveDialog.showOpenDialog();
 if (returnVal == metasaveDialog.APPROVE_OPTION) {
  Map<EnumDublinCoreElements, UntypedData> map = metasaveDialog
    .getMetadatavalue();
 }
 

Author(s):
Jinbo Chen
Version:
1.0
 
 public class MetaDataSaveDialog extends JDialog {
 	private static final long serialVersionUID = 1L;
 
 	private static final Font FONT = new Font("Courier New"., 12);

Return value if cancel is chosen.
 
 	public static final int CANCEL_OPTION = 1;
Return value if approve (yes, ok) is chosen.
 
 	public static final int APPROVE_OPTION = 0;
 
 	public int returnvalue;
 
 	private Map<StringJTextFielddetailmap = new HashMap<StringJTextField>();
 
 	private JButton savebtn;
 	private JButton cancelbtn;
Constructs a MetasaveDialog
	public MetaDataSaveDialog() {
		setTitle("Save Metadata");
	}

Constructs a MetasaveDialog that is initialized with dataentry as the EDAL dataentry

Parameters:
dataentry the EDAL dataentry
		setTitle("Metadata Dialog");
		this. = dataentry;
	}

Returns metadata information. This can be when you want to save file

Returns:
metadata informatin
	}

pop up a Metadata Dialog
	public int showOpenDialog() {
		setModal(true);
		return ;
	}
	private void initUi() {
		JPanel contents = (JPanelgetContentPane();
		contents.setLayout(new BorderLayout());
		contents.setBorder(new TitledBorder(""));
		this.setPreferredSize(new Dimension(450, 530));
		this.setMinimumSize(new Dimension(450, 530));
	}
	private JPanel buildFormui() {
		List<Stringcolumnlist = new ArrayList<String>();
		for (EnumDublinCoreElements elem : EnumDublinCoreElements.values()) {
			try {
				String dataName = elem.toString();
				try {
					if (dataName.equalsIgnoreCase("title")
							&& ( != null) && (.isDirectory())) {
						// the directory dont't need show title
						continue;
					}
catch (RemoteException e) {
					JOptionPane.showMessageDialog(
							null,
							"Call remote Edal server function exception:"
e.getMessage(), "EdalFileChooser",
				}
				columnlist.add(dataName);
				JOptionPane.showMessageDialog(null,
						"UnsupportedOperation Exception!""EdalFileChooser",
			}
		}
		final Object[] columnNames = columnlist.toArray(new String[0]);
		final double[][] detailsize = new double[2][];
		detailsize[0] = new double[2];
		detailsize[0][0] = 120;
		detailsize[0][1] = 0.99;
		int columnlen = columnNames.length;
		detailsize[1] = new double[columnlen];
		for (int i = 0; i < columnleni++) {
			detailsize[1][i] = 25;
		}
		JPanel detialpanel = new JPanel();
		detialpanel.setFont();
		final TableLayout detaillayout = new TableLayout(detailsize);
		detialpanel.setLayout(detaillayout);
		for (int i = 0; i < columnleni++) {
			JLabel label1 = new JLinkLabel(columnNames[i].toString() + ":",
			label1.setToolTipText("<html>"
					+ MetaDescription.getDescription(columnNames[i]
							.toString()) + "</html>");
			label1.setFont();
			detialpanel.add(label1"0," + i);
			JTextField text1 = new JTextField();
			text1.setFont();
			detialpanel.add(text1"1," + i);
			.put(columnNames[i].toString(), text1);
		}
		return detialpanel;
	}
	private JPanel createeditpanel() {
		JPanel detialpanel = buildFormui();
		if ( != null) {
			MetaData filemetadata;
			try {
				try {
catch (MetaDataException e1) {
					JOptionPane.showMessageDialog(null,
							"Can't load the value for "
							"EdalFileChooser".);
				}
				for (final EnumDublinCoreElements elem : EnumDublinCoreElements
						.values()) {
					final String dataName = elem.toString();
					if (.containsKey(dataName)) {
						UntypedData data = null;
						try {
							data = filemetadata.getElementValue(elem);
							String value = data.toString();
							.get(dataName).setText(value);
							if (value.trim().length() > 0) {
								.get(dataName).setToolTipText(value);
							}
catch (MetaDataException e) {
							JOptionPane.showMessageDialog(null,
									"Can't load the value for " + dataName
"!""EdalFileChooser",
						}
						.put(elemdata);
						final AbstractMetaDataEditor editor = EditorContainer
								.getEditor(EnumDublinCoreElements
										.valueOf(dataName));
						if (editor != null) {
							for (MouseListener al : .get(dataName)
							}
									new MouseAdapter() {
										public void mouseClicked(MouseEvent e) {
											if (e.getClickCount() == 1) {
												editor.setTitle(dataName+" Information");
														.get(elem));
												int ret = editor
													UntypedData untypedData = (UntypedDataeditor
															untypedData);
													if (untypedData != null) {
																.get(dataName)
																		untypedData
																.get(dataName)
																		0);
														if (untypedData
																.length() > 0) {
																	.get(dataName)
																			untypedData
														}
													}
												}
											}
										}
									});
							continue;
else {
						}
						.get(dataName).setEditable(false);
					}
				}
catch (RemoteException e1) {
						.error(StackTraceUtil.getStackTrace(e1));
				JOptionPane.showMessageDialog(
						null,
						"Call remote Edal server function exception:"
e1.getMessage(), "EdalFileChooser",
			}
else {
			for (final EnumDublinCoreElements elem : EnumDublinCoreElements
					.values()) {
				final String dataName = elem.toString();
				if (.containsKey(dataName)) {
					final AbstractMetaDataEditor editor = EditorContainer
							.getEditor(EnumDublinCoreElements.valueOf(dataName));
					if (editor != null) {
						for (MouseListener al : .get(dataName)
						}
								new MouseAdapter() {
									public void mouseClicked(MouseEvent e) {
										if (e.getClickCount() == 1) {
											editor.setValue(null);
											int ret = editor.showOpenDialog();
												UntypedData untypedData = (UntypedDataeditor
														untypedData);
												if (untypedData != null) {
															.get(dataName)
																	untypedData
															.get(dataName)
													if (untypedData.toString()
															.trim().length() > 0) {
																.get(dataName)
																		untypedData
													}
												}
											}
										}
									}
								});
						continue;
					}
					.get(dataName).setEditable(false);
				}
			}
		}
		return detialpanel;
	}
		JPanel buttonPane = new JPanel(new FlowLayout(., 5, 5));
		buttonPane.add();
		buttonPane.add();
		return buttonPane;
	}
	private void initEditors() {
		// ViewerContainer.clear();
				new TextEditor());
				new TextEditor());
		/*
		EditorContainer.registerEditor(EnumDublinCoreElements.CHECKSUM,
				new ChecksumEditor());
				*/
				new TextEditor());
				new TextEditor());
				new TextEditor());
		/*
		 * end user can't modify file name
		 * EditorContainer.registerEditor(EnumDublinCoreElements.TITLE,new
		 * TextEditor());
		 */
	}
	private Action okAction = new AbstractAction("Ok") {
		private static final long serialVersionUID = 1L;
		public void actionPerformed(ActionEvent e) {
		}
	};
	private Action cancelAction = new AbstractAction("Cancel") {
		private static final long serialVersionUID = 1L;
		public void actionPerformed(ActionEvent e) {
		}
	};
	private void focusEvt(java.awt.event.WindowEvent evt) {
	}
		return new WindowAdapter() {
			public void windowClosing(final WindowEvent we) {
			}
			public void windowOpened(java.awt.event.WindowEvent evt) {
			}
		};
	}
New to GrepCode? Check out our FAQ X