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.component.sequence; 020 021import icy.gui.component.sequence.SequenceChooser.SequenceChooserListener; 022import icy.sequence.AbstractSequenceModel; 023import icy.sequence.Sequence; 024import icy.util.StringUtil; 025 026import java.awt.BorderLayout; 027import java.awt.image.BufferedImage; 028 029import javax.swing.JLabel; 030import javax.swing.JPanel; 031import javax.swing.border.EmptyBorder; 032 033public class SequenceChooserPreviewPanel extends JPanel implements SequenceChooserListener 034{ 035 private class SequenceChooserPreviewModel extends AbstractSequenceModel 036 { 037 public SequenceChooserPreviewModel() 038 { 039 super(); 040 } 041 042 @Override 043 public int getSizeX() 044 { 045 final Sequence sequence = sequenceChooser.getSelectedSequence(); 046 047 if (sequence != null) 048 return sequence.getSizeX(); 049 050 return 0; 051 } 052 053 @Override 054 public int getSizeY() 055 { 056 final Sequence sequence = sequenceChooser.getSelectedSequence(); 057 058 if (sequence != null) 059 return sequence.getSizeY(); 060 061 return 0; 062 } 063 064 @Override 065 public int getSizeZ() 066 { 067 final Sequence sequence = sequenceChooser.getSelectedSequence(); 068 069 if (sequence != null) 070 return sequence.getSizeZ(); 071 072 return 0; 073 } 074 075 @Override 076 public int getSizeT() 077 { 078 final Sequence sequence = sequenceChooser.getSelectedSequence(); 079 080 if (sequence != null) 081 return sequence.getSizeT(); 082 083 return 0; 084 } 085 086 @Override 087 public int getSizeC() 088 { 089 final Sequence sequence = sequenceChooser.getSelectedSequence(); 090 091 if (sequence != null) 092 return sequence.getSizeC(); 093 094 return 0; 095 } 096 097 @Override 098 public BufferedImage getImage(int t, int z) 099 { 100 final Sequence sequence = sequenceChooser.getSelectedSequence(); 101 102 if (sequence != null) 103 return sequence.getImage(t, z); 104 105 return null; 106 } 107 108 @Override 109 public BufferedImage getImage(int t, int z, int c) 110 { 111 final Sequence sequence = sequenceChooser.getSelectedSequence(); 112 113 if (sequence != null) 114 return sequence.getImage(t, z, c); 115 116 return null; 117 } 118 } 119 120 /** 121 * 122 */ 123 private static final long serialVersionUID = -1637532468722270264L; 124 125 protected JLabel titleLabel; 126 protected SequenceChooser sequenceChooser; 127 SequencePreviewPanel sequencePreviewPanel; 128 129 /** 130 * Create the panel. 131 */ 132 public SequenceChooserPreviewPanel(String title) 133 { 134 super(); 135 136 initialize(title); 137 138 sequenceChanged(sequenceChooser.getSelectedSequence()); 139 140 sequencePreviewPanel.setModel(new SequenceChooserPreviewModel()); 141 sequenceChooser.addListener(this); 142 } 143 144 /** 145 * Create the panel. 146 */ 147 public SequenceChooserPreviewPanel() 148 { 149 this(null); 150 } 151 152 private void initialize(String title) 153 { 154 setLayout(new BorderLayout(0, 0)); 155 156 sequencePreviewPanel = new SequencePreviewPanel(); 157 sequencePreviewPanel.setBorder(new EmptyBorder(4, 0, 0, 0)); 158 add(sequencePreviewPanel, BorderLayout.CENTER); 159 160 JPanel panel = new JPanel(); 161 add(panel, BorderLayout.NORTH); 162 panel.setLayout(new BorderLayout(0, 0)); 163 164 sequenceChooser = new SequenceChooser(); 165 panel.add(sequenceChooser); 166 167 if (!StringUtil.isEmpty(title)) 168 { 169 titleLabel = new JLabel(title); 170 titleLabel.setBorder(new EmptyBorder(4, 0, 0, 8)); 171 panel.add(titleLabel, BorderLayout.WEST); 172 } 173 } 174 175 /** 176 * @return the sequenceChooser 177 */ 178 public SequenceChooser getSequenceChooser() 179 { 180 return sequenceChooser; 181 } 182 183 /** 184 * @return the sequencePreviewPanel 185 */ 186 public SequencePreviewPanel getSequencePreviewPanel() 187 { 188 return sequencePreviewPanel; 189 } 190 191 public boolean getPreviewVisible() 192 { 193 return sequencePreviewPanel.isVisible(); 194 } 195 196 public void setPreviewVisible(boolean value) 197 { 198 sequencePreviewPanel.setVisible(value); 199 } 200 201 public void setTitle(String value) 202 { 203 sequencePreviewPanel.setTitle(value); 204 } 205 206 @Override 207 public void sequenceChanged(Sequence sequence) 208 { 209 sequencePreviewPanel.dimensionChanged(); 210 } 211 212 /** 213 * @see SequencePreviewPanel#dimensionChanged() 214 */ 215 public void dimensionChanged() 216 { 217 sequencePreviewPanel.dimensionChanged(); 218 } 219 220 /** 221 * @see SequencePreviewPanel#imageChanged() 222 */ 223 public void imageChanged() 224 { 225 sequencePreviewPanel.imageChanged(); 226 } 227}