BrightSide Workbench Full Report + Source Code
file/zul/PreviewButton.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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;
20 
21 import java.awt.image.BufferedImage;
22 import java.io.File;
23 import javax.imageio.ImageIO;
24 import org.turro.elephant.util.Images;
25 import org.turro.i18n.I_;
26 import org.turro.preview.Preview;
27 import org.turro.zkoss.dialog.Windows;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.Image;
32 import org.zkoss.zul.Toolbarbutton;
33 
38 public class PreviewButton extends Toolbarbutton implements EventListener<Event> {
39 
40  private final File file;
41 
42  public PreviewButton(File file) {
43  this.file = file;
44  setImage(Images.getImage("eye"));
45  setTooltiptext(I_.get("Preview"));
46  addEventListener(Events.ON_CLICK, this);
47  }
48 
49  @Override
50  public void onEvent(Event event) throws Exception {
51  Preview preview = Preview.from(file);
52  File result = preview.get();
53  if(result != null) {
54  BufferedImage bi = ImageIO.read(result);
55  Image image = new Image();
56  image.setContent(bi);
57  Windows.title(getTooltiptext())
58  .page(getPage())
59  .adaptWidth(bi.getWidth())
60  .adaptHeight(bi.getHeight())
61  .addComponent(image)
62  .closeable()
63  .onClose(w -> preview.close())
64  .show();
65  }
66  }
67 
68 }
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
static Windows title(String title)
Definition: Windows.java:138
Windows addComponent(HtmlBasedComponent component)
Definition: Windows.java:97
Windows adaptHeight(int height)
Definition: Windows.java:115
Windows onClose(Consumer< Windows > onClose)
Definition: Windows.java:81
Windows adaptWidth(int width)
Definition: Windows.java:111
Windows page(Page page)
Definition: Windows.java:46