BrightSide Workbench Full Report + Source Code
FilePreview.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.file.zul.tree;
20 
21 import java.awt.image.BufferedImage;
22 import java.io.File;
23 import javax.imageio.ImageIO;
24 import org.turro.preview.Preview;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.event.OpenEvent;
28 import org.zkoss.zul.Image;
29 import org.zkoss.zul.Popup;
30 
35 public class FilePreview extends Popup implements EventListener<OpenEvent> {
36 
37  private File file;
38 
39  public FilePreview(File file) {
40  this.file = file;
41  addEventListener(Events.ON_OPEN, this);
42  }
43 
44  @Override
45  public void onEvent(OpenEvent event) throws Exception {
46  getChildren().clear();
47  Preview preview = Preview.from(file);
48  File result = preview.get();
49  if(result != null) {
50  BufferedImage bi = ImageIO.read(result);
51  setHeight((bi.getHeight() + 12) + "px");
52  setWidth((bi.getWidth() + 12) + "px");
53  Image image = new Image();
54  image.setContent(bi);
55  appendChild(image);
56  preview.close();
57  }
58  }
59 
60 }