picture viewer fixes
This commit is contained in:
parent
d223d2a2a1
commit
c99f4b6782
@ -18,6 +18,8 @@ public class FileEditor extends JDialog {
|
|||||||
private JTextArea textArea;
|
private JTextArea textArea;
|
||||||
private JScrollPane scrollPane;
|
private JScrollPane scrollPane;
|
||||||
private File file;
|
private File file;
|
||||||
|
private java.util.List<File> imageFiles = new java.util.ArrayList<>();
|
||||||
|
private int currentImageIndex = -1;
|
||||||
private AppConfig config;
|
private AppConfig config;
|
||||||
private boolean modified = false;
|
private boolean modified = false;
|
||||||
private boolean readOnly;
|
private boolean readOnly;
|
||||||
@ -54,6 +56,10 @@ public class FileEditor extends JDialog {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
|
|
||||||
|
if (isImageFile(file)) {
|
||||||
|
initImageList();
|
||||||
|
}
|
||||||
|
|
||||||
initComponents();
|
initComponents();
|
||||||
loadFile();
|
loadFile();
|
||||||
|
|
||||||
@ -580,6 +586,19 @@ public class FileEditor extends JDialog {
|
|||||||
if (undoManager.canRedo()) undoManager.redo();
|
if (undoManager.canRedo()) undoManager.redo();
|
||||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
|
// Doprava/Doleva a Mezerník pro listování obrázků
|
||||||
|
rootPane.registerKeyboardAction(e -> {
|
||||||
|
if (isImageFile(file)) nextImage();
|
||||||
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
|
rootPane.registerKeyboardAction(e -> {
|
||||||
|
if (isImageFile(file)) prevImage();
|
||||||
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
|
rootPane.registerKeyboardAction(e -> {
|
||||||
|
if (isImageFile(file)) nextImage();
|
||||||
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
|
||||||
// Ctrl+Shift+Z - Redo (alternative shortcut)
|
// Ctrl+Shift+Z - Redo (alternative shortcut)
|
||||||
rootPane.registerKeyboardAction(e -> {
|
rootPane.registerKeyboardAction(e -> {
|
||||||
if (undoManager.canRedo()) undoManager.redo();
|
if (undoManager.canRedo()) undoManager.redo();
|
||||||
@ -867,16 +886,45 @@ public class FileEditor extends JDialog {
|
|||||||
try {
|
try {
|
||||||
ImageIcon icon = new ImageIcon(file.getAbsolutePath());
|
ImageIcon icon = new ImageIcon(file.getAbsolutePath());
|
||||||
if (icon.getImageLoadStatus() == MediaTracker.COMPLETE) {
|
if (icon.getImageLoadStatus() == MediaTracker.COMPLETE) {
|
||||||
|
// Get image dimensions
|
||||||
|
int imgW = icon.getIconWidth();
|
||||||
|
int imgH = icon.getIconHeight();
|
||||||
|
|
||||||
|
// Get screen size constraints
|
||||||
|
GraphicsConfiguration gc = getGraphicsConfiguration();
|
||||||
|
Rectangle screenBounds = gc.getBounds();
|
||||||
|
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
|
||||||
|
int maxW = screenBounds.width - screenInsets.left - screenInsets.right - 40;
|
||||||
|
int maxH = screenBounds.height - screenInsets.top - screenInsets.bottom - 100;
|
||||||
|
|
||||||
|
// Scale image if it's too large
|
||||||
|
Image scaledImage = icon.getImage();
|
||||||
|
boolean scaled = false;
|
||||||
|
if (imgW > maxW || imgH > maxH) {
|
||||||
|
double ratio = Math.min((double) maxW / imgW, (double) maxH / imgH);
|
||||||
|
imgW = (int) (imgW * ratio);
|
||||||
|
imgH = (int) (imgH * ratio);
|
||||||
|
scaledImage = scaledImage.getScaledInstance(imgW, imgH, Image.SCALE_SMOOTH);
|
||||||
|
icon = new ImageIcon(scaledImage);
|
||||||
|
scaled = true;
|
||||||
|
}
|
||||||
|
|
||||||
JLabel label = new JLabel(icon);
|
JLabel label = new JLabel(icon);
|
||||||
label.setHorizontalAlignment(JLabel.CENTER);
|
label.setHorizontalAlignment(JLabel.CENTER);
|
||||||
scrollPane.setViewportView(label);
|
scrollPane.setViewportView(label);
|
||||||
|
|
||||||
statusPosLabel.setText(String.format("Obraz: %d x %d px",
|
String statusText = String.format("Obraz: %d x %d px", imgW, imgH);
|
||||||
icon.getIconWidth(), icon.getIconHeight()));
|
if (scaled) statusText += " (zmenšeno)";
|
||||||
statusSelLabel.setText(String.format("Velikost: %s", formatSize(file.length())));
|
statusPosLabel.setText(statusText);
|
||||||
|
|
||||||
// Adjust window size based on image size
|
String labelText = String.format("Velikost: %s", formatSize(file.length()));
|
||||||
adjustWindowSizeForImage(icon.getIconWidth(), icon.getIconHeight());
|
if (imageFiles.size() > 1) {
|
||||||
|
labelText += String.format(" [%d / %d]", currentImageIndex + 1, imageFiles.size());
|
||||||
|
}
|
||||||
|
statusSelLabel.setText(labelText);
|
||||||
|
|
||||||
|
// Adjust window size based on (possibly scaled) image size
|
||||||
|
adjustWindowSizeForImage(imgW, imgH);
|
||||||
|
|
||||||
// Disable search and hex for images
|
// Disable search and hex for images
|
||||||
if (northPanel != null) {
|
if (northPanel != null) {
|
||||||
@ -928,6 +976,46 @@ public class FileEditor extends JDialog {
|
|||||||
String pre = "KMGTPE".charAt(exp-1) + "";
|
String pre = "KMGTPE".charAt(exp-1) + "";
|
||||||
return String.format("%.1f %sB", size / Math.pow(1024, exp), pre);
|
return String.format("%.1f %sB", size / Math.pow(1024, exp), pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initImageList() {
|
||||||
|
File parent = file.getParentFile();
|
||||||
|
if (parent != null && parent.isDirectory()) {
|
||||||
|
File[] files = parent.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
java.util.Arrays.sort(files);
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.isFile() && isImageFile(f)) {
|
||||||
|
imageFiles.add(f);
|
||||||
|
if (f.equals(file)) {
|
||||||
|
currentImageIndex = imageFiles.size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextImage() {
|
||||||
|
if (imageFiles.size() > 1) {
|
||||||
|
currentImageIndex = (currentImageIndex + 1) % imageFiles.size();
|
||||||
|
file = imageFiles.get(currentImageIndex);
|
||||||
|
updateTitle();
|
||||||
|
loadImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prevImage() {
|
||||||
|
if (imageFiles.size() > 1) {
|
||||||
|
currentImageIndex = (currentImageIndex - 1 + imageFiles.size()) % imageFiles.size();
|
||||||
|
file = imageFiles.get(currentImageIndex);
|
||||||
|
updateTitle();
|
||||||
|
loadImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTitle() {
|
||||||
|
setTitle((readOnly ? "Prohlížeč - " : "Editor - ") + file.getName() + (modified ? " *" : ""));
|
||||||
|
}
|
||||||
|
|
||||||
private void saveFile() {
|
private void saveFile() {
|
||||||
try {
|
try {
|
||||||
@ -969,14 +1057,6 @@ public class FileEditor extends JDialog {
|
|||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTitle() {
|
|
||||||
String title = (readOnly ? "Prohlížeč - " : "Editor - ") + file.getName();
|
|
||||||
if (!readOnly && modified) {
|
|
||||||
title += " *";
|
|
||||||
}
|
|
||||||
setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeFont() {
|
private void changeFont() {
|
||||||
Font newFont = FontChooserDialog.showDialog(this, textArea.getFont());
|
Font newFont = FontChooserDialog.showDialog(this, textArea.getFont());
|
||||||
if (newFont != null) {
|
if (newFont != null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user