Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
ab350eaecd | |||
48d8d3a411 | |||
82847fd740 |
@ -5,14 +5,19 @@ import java.awt.*;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public final class ImageLib {
|
public final class ImageLib {
|
||||||
|
|
||||||
|
private static HashMap<Image,File> save = new HashMap<Image,File>();
|
||||||
|
|
||||||
public static Image createScaledImage(File file, int iconWidth, int iconHeight) {
|
public static Image createScaledImage(File file, int iconWidth, int iconHeight) {
|
||||||
final BufferedImage img;
|
final BufferedImage img;
|
||||||
try {
|
try {
|
||||||
if ((img = ImageIO.read(file)) != null) {
|
if ((img = ImageIO.read(file)) != null) {
|
||||||
return img.getScaledInstance(iconWidth, iconHeight, Image.SCALE_DEFAULT);
|
Image image = img.getScaledInstance(iconWidth, iconHeight, Image.SCALE_DEFAULT);
|
||||||
|
save.put(image, file);
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -21,4 +26,8 @@ public final class ImageLib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ImageLib() {}
|
private ImageLib() {}
|
||||||
|
|
||||||
|
public static File getFileFromImage(Image img) {
|
||||||
|
return save.get(img);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package fr.uha.gabalier.util.languages;
|
||||||
|
|
||||||
|
import java.beans.Beans;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class StringSources {
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Constructor
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
private StringSources() {
|
||||||
|
// do not instantiate
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Bundle access
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
private static final String BUNDLE_NAME = "fr.uha.gabalier.util.languages.stringsources"; //$NON-NLS-1$
|
||||||
|
private static final ResourceBundle RESOURCE_BUNDLE = loadBundle();
|
||||||
|
private static ResourceBundle loadBundle() {
|
||||||
|
return ResourceBundle.getBundle(BUNDLE_NAME);
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Strings access
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
public static String getString(String key) {
|
||||||
|
try {
|
||||||
|
ResourceBundle bundle = Beans.isDesignTime() ? loadBundle() : RESOURCE_BUNDLE;
|
||||||
|
return bundle.getString(key);
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
return "!" + key + "!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
#Eclipse messages class
|
||||||
|
#Thu Sep 27 17:27:39 CEST 2018
|
||||||
|
Preview.cancelItem.text=Cancel
|
||||||
|
Preview.exitItem.text=Exit
|
||||||
|
Preview.fileMenu.text=File
|
||||||
|
Preview.loadItem.text=Load
|
||||||
|
Preview.other.text=status \:
|
||||||
|
Preview.statusText.text=0000 images loaded
|
||||||
|
Preview.this.title=Image Loader
|
@ -0,0 +1,9 @@
|
|||||||
|
#Eclipse messages class
|
||||||
|
#Thu Sep 27 17:27:39 CEST 2018
|
||||||
|
Preview.cancelItem.text=Cancel
|
||||||
|
Preview.exitItem.text=Exit
|
||||||
|
Preview.fileMenu.text=File
|
||||||
|
Preview.loadItem.text=Load
|
||||||
|
Preview.other.text=status \:
|
||||||
|
Preview.statusText.text=0000 images loaded
|
||||||
|
Preview.this.title=Image Loader
|
@ -0,0 +1,9 @@
|
|||||||
|
#Eclipse messages class
|
||||||
|
#Thu Sep 27 17:27:40 CEST 2018
|
||||||
|
Preview.cancelItem.text=Cancelar
|
||||||
|
Preview.exitItem.text=Salir
|
||||||
|
Preview.fileMenu.text=Archivo
|
||||||
|
Preview.loadItem.text=Carga
|
||||||
|
Preview.other.text=Estatus \:
|
||||||
|
Preview.statusText.text=0000 im\u00E1genes cargadas
|
||||||
|
Preview.this.title=Cargador de im\u00E1genes
|
@ -0,0 +1,9 @@
|
|||||||
|
#Eclipse messages class
|
||||||
|
#Thu Sep 27 17:27:39 CEST 2018
|
||||||
|
Preview.cancelItem.text=Annuler
|
||||||
|
Preview.exitItem.text=Quitter
|
||||||
|
Preview.fileMenu.text=Fichier
|
||||||
|
Preview.loadItem.text=Charger
|
||||||
|
Preview.other.text=Status \:
|
||||||
|
Preview.statusText.text=0000 images charg\u00E9es
|
||||||
|
Preview.this.title=Visionneuse d'image
|
BIN
src/main/java/fr/uha/gabalier/util/ressources/logo.jpg
Normal file
BIN
src/main/java/fr/uha/gabalier/util/ressources/logo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
44
src/main/java/fr/uha/gabalier/view/BigView.java
Normal file
44
src/main/java/fr/uha/gabalier/view/BigView.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package fr.uha.gabalier.view;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import fr.uha.gabalier.util.ImageLib;
|
||||||
|
|
||||||
|
public class BigView extends JPanel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1197679995105162808L;
|
||||||
|
private BufferedImage image;
|
||||||
|
|
||||||
|
public BigView(Image image) {
|
||||||
|
setLayout(new BorderLayout(0, 0));
|
||||||
|
JPanel imageDisplay = new JPanel();
|
||||||
|
add(imageDisplay, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.image = ImageIO.read(ImageLib.getFileFromImage(image));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JLabel imageName = new JLabel(ImageLib.getFileFromImage(image).getName());
|
||||||
|
imageName.setEnabled(false);
|
||||||
|
imageName.setHorizontalAlignment(SwingConstants.LEADING);
|
||||||
|
add(imageName, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
g.drawImage(this.image, 0, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,10 +9,16 @@ import java.awt.event.InputEvent;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import fr.uha.gabalier.util.languages.StringSources;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class Preview extends JFrame {
|
public class Preview extends JFrame {
|
||||||
|
|
||||||
static final int VIEW_WIDTH = 256;
|
private static final long serialVersionUID = -8104236322964434859L;
|
||||||
|
|
||||||
|
static final int VIEW_WIDTH = 256;
|
||||||
static final int VIEW_HEIGHT = 128;
|
static final int VIEW_HEIGHT = 128;
|
||||||
|
|
||||||
public static final String LEFT_COMMAND = "<";
|
public static final String LEFT_COMMAND = "<";
|
||||||
@ -22,6 +28,7 @@ public class Preview extends JFrame {
|
|||||||
private List<Image> model;
|
private List<Image> model;
|
||||||
private ImageLoader loader;
|
private ImageLoader loader;
|
||||||
private ImageView imageView;
|
private ImageView imageView;
|
||||||
|
protected ImageController<?> controller;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
private JMenuItem loadItem;
|
private JMenuItem loadItem;
|
||||||
@ -30,29 +37,46 @@ public class Preview extends JFrame {
|
|||||||
private JButton leftNavButton;
|
private JButton leftNavButton;
|
||||||
private final JTextField statusText;
|
private final JTextField statusText;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Preview() throws HeadlessException {
|
public Preview() throws HeadlessException {
|
||||||
|
setIconImage(Toolkit.getDefaultToolkit().getImage(Preview.class.getResource("/fr/uha/gabalier/util/ressources/logo.jpg")));
|
||||||
|
setTitle(StringSources.getString("Preview.this.title")); //$NON-NLS-1$
|
||||||
model = new ArrayList<>();
|
model = new ArrayList<>();
|
||||||
|
|
||||||
|
this.controller = new ImageController(model);
|
||||||
|
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
JMenu fileMenu = new JMenu("File");
|
JMenu fileMenu = new JMenu(StringSources.getString("Preview.fileMenu.text")); //$NON-NLS-1$
|
||||||
menuBar.add(fileMenu);
|
menuBar.add(fileMenu);
|
||||||
|
|
||||||
loadItem = new JMenuItem("Load");
|
loadItem = new JMenuItem(StringSources.getString("Preview.loadItem.text")); //$NON-NLS-1$
|
||||||
fileMenu.add(loadItem);
|
fileMenu.add(loadItem);
|
||||||
loadItem.addActionListener(actionEvent -> doLoad());
|
loadItem.addActionListener(actionEvent -> doLoad());
|
||||||
cancelItem = new JMenuItem("Cancel");
|
cancelItem = new JMenuItem(StringSources.getString("Preview.cancelItem.text")); //$NON-NLS-1$
|
||||||
fileMenu.add(cancelItem);
|
fileMenu.add(cancelItem);
|
||||||
cancelItem.addActionListener(actionEvent -> doCancel());
|
cancelItem.addActionListener(actionEvent -> doCancel());
|
||||||
final JMenuItem exitItem = new JMenuItem("Exit");
|
final JMenuItem exitItem = new JMenuItem(StringSources.getString("Preview.exitItem.text")); //$NON-NLS-1$
|
||||||
exitItem.addActionListener(actionEvent -> doExit());
|
exitItem.addActionListener(actionEvent -> doExit());
|
||||||
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK));
|
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK));
|
||||||
fileMenu.add(exitItem);
|
fileMenu.add(exitItem);
|
||||||
|
|
||||||
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
|
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
imageView = new ImageView(model);
|
imageView = new ImageView(model);
|
||||||
final ImageController controller = new ImageController(model);
|
imageView.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
JFrame bigViewFrame = new JFrame();
|
||||||
|
bigViewFrame.add(new BigView(model.get(controller.getIndex())));
|
||||||
|
bigViewFrame.repaint();
|
||||||
|
bigViewFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
imageView.setController(controller);
|
imageView.setController(controller);
|
||||||
controller.setView(imageView);
|
controller.setView(imageView);
|
||||||
getContentPane().add(imageView);
|
getContentPane().add(imageView);
|
||||||
@ -68,8 +92,8 @@ public class Preview extends JFrame {
|
|||||||
|
|
||||||
final JPanel statusPanel = new JPanel();
|
final JPanel statusPanel = new JPanel();
|
||||||
getContentPane().add(statusPanel);
|
getContentPane().add(statusPanel);
|
||||||
statusText = new JTextField("0000 images loaded");
|
statusText = new JTextField(StringSources.getString("Preview.statusText.text")); //$NON-NLS-1$
|
||||||
statusPanel.add(new JLabel("status :"));
|
statusPanel.add(new JLabel(StringSources.getString("Preview.other.text"))); //$NON-NLS-1$
|
||||||
statusPanel.add(statusText);
|
statusPanel.add(statusText);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
|
Loading…
Reference in New Issue
Block a user