Skip to content

Instantly share code, notes, and snippets.

@fanjavaid
Created July 15, 2013 21:54
Show Gist options
  • Save fanjavaid/6003845 to your computer and use it in GitHub Desktop.
Save fanjavaid/6003845 to your computer and use it in GitHub Desktop.
Method untuk menampilkan gambar/video dari File
public void getStreamData(final PanelEntry view, final String data) {
String files = null;
String path = null;
if(isImages()) {
path = "data/"+data+"/images";
} else {
path = "data/"+data+"/videos/thumbs";
}
File folder = new File(path);
// Selalu hapus label yg menampung gambar yang sebelumnya jika user data selanjutnya, dipilih.
view.getPanelStream().removeAll();
if (!folder.exists()) {
JLabel label = new JLabel("No Stream Data");
label.setForeground(Color.red);
label.setVisible(true);
// Tambah ke panelGallery
view.getPanelStream().add(label);
view.getPanelStream().revalidate();
view.getPanelStream().repaint();
} else {
File [] listOfFiles = folder.listFiles();
int maxFiles = listOfFiles.length;
int maxView = 15;
// Loop untuk mendapatkan gambar dari File
for (int i = listOfFiles.length; i > 0 ; i--) {
if(listOfFiles[i].isFile()) {
files = listOfFiles[i].getName();
final String videoFiles = files;
if(files.endsWith(".jpg") || files.endsWith(".JPG") ||
files.endsWith(".jpeg") || files.endsWith(".JPEG") ||
files.endsWith(".png") || files.endsWith(".PNG")) {
final String newPath = path+"/"+files;
try {
File showFile = new File(newPath);
ImageIcon imgSource = new ImageIcon(newPath);
JPanel labelGallery = new BackgroundImageRounded(showFile);
labelGallery.setLayout(null);
labelGallery.setPreferredSize(new Dimension(160, 120));
labelGallery.setVisible(true);
JLabel labelName = new JLabel(files);
labelName.setSize(150,15);
labelName.setLocation(8, 8);
labelName.setVisible(true);
labelName.setForeground(Color.ORANGE);
labelGallery.add(labelName);
String videoPath = "data/"+data+"/videos/";
String video = videoFiles.replace(".jpg", ".wmv");
String videoFile = video.replace("thumb_", "video_");
final String videoPlayer = videoPath+videoFile;
if (isImages()) {
labelGallery.setToolTipText("View Image");
} else {
labelGallery.setToolTipText("Play Video");
JLabel iconPlayer = new JLabel();
iconPlayer.setIcon(new ImageIcon(getClass().getResource("/com/ikbiz/gastroscope/resources/player.png")));
iconPlayer.setSize(61,42);
iconPlayer.setVisible(true);
iconPlayer.setLocation(50, 35);
labelGallery.add(iconPlayer);
}
labelGallery.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(isImages()) {
ImageViewer viewer = new ImageViewer(newPath);
viewer.setVisible(true);
} else {
VideoViewer videoViewer = new VideoViewer();
videoViewer.setViewer(videoPlayer);
videoViewer.setLocationRelativeTo(null);
videoViewer.pack();
videoViewer.setVisible(true);
}
}
});
// Tambah label gambar ke panelGallery
view.getPanelStream().add(labelGallery);
view.getPanelStream().revalidate();
view.getPanelStream().repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment