You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.2 KiB
59 lines
2.2 KiB
package de.srsoftware.belegscanner.gui; |
|
|
|
import de.srsoftware.belegscanner.Worker; |
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.awt.event.KeyAdapter; |
|
import java.awt.event.KeyEvent; |
|
|
|
import static de.srsoftware.belegscanner.Application.t; |
|
import static java.awt.BorderLayout.CENTER; |
|
import static java.awt.BorderLayout.NORTH; |
|
import static java.awt.BorderLayout.SOUTH; |
|
import static java.awt.BorderLayout.WEST; |
|
|
|
public class FormatSelector extends JPanel { |
|
private static final Logger LOG = LoggerFactory.getLogger(FormatSelector.class); |
|
private final JTextField height, width; |
|
|
|
public FormatSelector(Worker worker){ |
|
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); |
|
JPanel widthSelector = new JPanel(); |
|
widthSelector.setLayout(new BorderLayout()); |
|
widthSelector.setMaximumSize(new Dimension(600, 40)); |
|
|
|
widthSelector.add(new JLabel(t("Width")+": "), WEST); |
|
widthSelector.add(width = new JTextField(209+""), CENTER); |
|
widthSelector.add(new JLabel("px"),BorderLayout.EAST); |
|
add(widthSelector,NORTH); |
|
|
|
var heightSelector = new JPanel(); |
|
heightSelector.setLayout(new BorderLayout()); |
|
heightSelector.setMaximumSize(new Dimension(600, 40)); |
|
|
|
heightSelector.add(new JLabel(t("Height")+": "), WEST); |
|
heightSelector.add(height = new JTextField(297+""), CENTER); |
|
heightSelector.add(new JLabel("px"),BorderLayout.EAST); |
|
add(heightSelector,SOUTH); |
|
|
|
KeyAdapter dimensionListener = new KeyAdapter() { |
|
@Override |
|
public void keyReleased(KeyEvent e) { |
|
LOG.debug("updateDimensions()"); |
|
try { |
|
int w = Integer.parseInt(width.getText().trim()); |
|
int h = Integer.parseInt(height.getText().trim()); |
|
worker.setDimension(new Dimension(w < 0 ? 0 : w, h < 0 ? 0 : h)); |
|
} catch (NumberFormatException nfe) { |
|
LOG.warn("Invalid dimensions!"); |
|
} |
|
} |
|
}; |
|
|
|
width.addKeyListener(dimensionListener); |
|
height.addKeyListener(dimensionListener); |
|
} |
|
}
|
|
|