001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.sequence; 020 021import icy.gui.component.model.XMLTreeModel; 022import icy.sequence.Sequence; 023import icy.system.thread.ThreadUtil; 024import icy.util.OMEUtil; 025 026import java.awt.BorderLayout; 027import java.awt.Dimension; 028 029import javax.swing.JLabel; 030import javax.swing.JPanel; 031import javax.swing.JScrollPane; 032import javax.swing.JTree; 033 034/** 035 * @author Stephane 036 */ 037public class SequenceMetadataPanel extends JPanel 038{ 039 /** 040 * 041 */ 042 private static final long serialVersionUID = -3889529459830025973L; 043 044 /** 045 * Create the panel. 046 */ 047 public SequenceMetadataPanel(final Sequence sequence) 048 { 049 super(); 050 051 setLayout(new BorderLayout()); 052 setPreferredSize(new Dimension(320, 360)); 053 054 final JTree tree = new JTree(); 055 tree.setVisible(false); 056 057 final JLabel loading = new JLabel("loading..."); 058 059 add(loading, BorderLayout.NORTH); 060 add(new JScrollPane(tree), BorderLayout.CENTER); 061 062 validate(); 063 064 // can take sometime so we do it in background 065 ThreadUtil.bgRun(new Runnable() 066 { 067 @Override 068 public void run() 069 { 070 tree.setModel(new XMLTreeModel(OMEUtil.getXMLDocument(sequence.getOMEXMLMetadata()))); 071 072 int row = 0; 073 while (row < tree.getRowCount()) 074 { 075 tree.expandRow(row); 076 row++; 077 } 078 079 ThreadUtil.invokeLater(new Runnable() 080 { 081 @Override 082 public void run() 083 { 084 tree.setVisible(true); 085 loading.setVisible(false); 086 } 087 }); 088 } 089 }); 090 } 091}