|
|
|
@ -1,9 +1,12 @@
@@ -1,9 +1,12 @@
|
|
|
|
|
package de.srsoftware.belegscanner.gui; |
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
@ -15,6 +18,7 @@ import javax.swing.BoxLayout;
@@ -15,6 +18,7 @@ import javax.swing.BoxLayout;
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
|
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
@ -22,6 +26,7 @@ import org.slf4j.Logger;
@@ -22,6 +26,7 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.belegscanner.Configuration; |
|
|
|
|
import de.srsoftware.belegscanner.Constants; |
|
|
|
|
import de.srsoftware.tools.gui.DateChooser; |
|
|
|
|
import de.srsoftware.tools.gui.SelectComboBox; |
|
|
|
|
|
|
|
|
@ -37,6 +42,11 @@ public class Toolbar extends JPanel {
@@ -37,6 +42,11 @@ public class Toolbar extends JPanel {
|
|
|
|
|
public void setDate(Date date); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public interface DimensionListener{ |
|
|
|
|
public void setDimension(Dimension dimension); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface FieldListener{ |
|
|
|
|
public void setField(String name, String value); |
|
|
|
|
} |
|
|
|
@ -59,6 +69,7 @@ public class Toolbar extends JPanel {
@@ -59,6 +69,7 @@ public class Toolbar extends JPanel {
|
|
|
|
|
private HashSet<FieldListener> fieldListeners = new HashSet<>(); |
|
|
|
|
private HashSet<PathListener> pathListeners = new HashSet<>(); |
|
|
|
|
private HashSet<ActionListener> scanListeners = new HashSet<>(); |
|
|
|
|
private HashSet<DimensionListener> dimensionListeners = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
private DateChooser date; |
|
|
|
|
|
|
|
|
@ -68,16 +79,59 @@ public class Toolbar extends JPanel {
@@ -68,16 +79,59 @@ public class Toolbar extends JPanel {
|
|
|
|
|
|
|
|
|
|
private JButton scanButton; |
|
|
|
|
|
|
|
|
|
private JTextField width; |
|
|
|
|
private JTextField height; |
|
|
|
|
|
|
|
|
|
public Toolbar(Configuration config) { |
|
|
|
|
this.config = config; |
|
|
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
|
|
|
|
add(datePicker()); |
|
|
|
|
add(input("Kategorie",categoryPicker(config))); |
|
|
|
|
add(input("Pfad",pathPicker = pathPicker())); |
|
|
|
|
addFormatSelector(); |
|
|
|
|
add(scanButton()); |
|
|
|
|
add(externButton()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addFormatSelector() { |
|
|
|
|
JPanel dummy = new JPanel(); |
|
|
|
|
dummy.setLayout(new BorderLayout()); |
|
|
|
|
|
|
|
|
|
dummy.add(new JLabel("Breite:"),BorderLayout.WEST); |
|
|
|
|
dummy.add(width = new JTextField(209+""),BorderLayout.CENTER); |
|
|
|
|
dummy.add(new JLabel("px"),BorderLayout.EAST); |
|
|
|
|
add(dummy); |
|
|
|
|
|
|
|
|
|
dummy = new JPanel(); |
|
|
|
|
dummy.setLayout(new BorderLayout()); |
|
|
|
|
|
|
|
|
|
dummy.add(new JLabel("Höhe:"),BorderLayout.WEST); |
|
|
|
|
dummy.add(height = new JTextField(297+""),BorderLayout.CENTER); |
|
|
|
|
dummy.add(new JLabel("px"),BorderLayout.EAST); |
|
|
|
|
add(dummy); |
|
|
|
|
|
|
|
|
|
KeyAdapter dimensionListener = new KeyAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void keyReleased(KeyEvent e) { |
|
|
|
|
updateDimensions(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
width.addKeyListener(dimensionListener); |
|
|
|
|
height.addKeyListener(dimensionListener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void updateDimensions() { |
|
|
|
|
try { |
|
|
|
|
int w = Integer.parseInt(width.getText().trim()); |
|
|
|
|
int h = Integer.parseInt(height.getText().trim()); |
|
|
|
|
dimensionListeners.forEach(listener -> listener.setDimension(new Dimension(w < 0 ? 0 : w, h < 0 ? 0 : h))); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
LOG.warn("Invalid dimensions!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addFieldsFor(Vector<String> marks) { |
|
|
|
|
LOG.debug("addFieldsFor({})",marks); |
|
|
|
|
|
|
|
|
@ -102,6 +156,11 @@ public class Toolbar extends JPanel {
@@ -102,6 +156,11 @@ public class Toolbar extends JPanel {
|
|
|
|
|
public Toolbar addDateListener(DateListener listener) { |
|
|
|
|
dateListeners.add(listener); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Toolbar addDimensionListener(DimensionListener listener) { |
|
|
|
|
dimensionListeners.add(listener); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Toolbar addFieldListener(FieldListener listener) { |
|
|
|
@ -139,6 +198,7 @@ public class Toolbar extends JPanel {
@@ -139,6 +198,7 @@ public class Toolbar extends JPanel {
|
|
|
|
|
return btn; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Date getDate() { |
|
|
|
|
return date.getSelectedDate(); |
|
|
|
|
} |
|
|
|
@ -187,9 +247,10 @@ public class Toolbar extends JPanel {
@@ -187,9 +247,10 @@ public class Toolbar extends JPanel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void updateCat(String newCat) { |
|
|
|
|
private void updateCat(String newCat) { |
|
|
|
|
LOG.debug("updateCat({})",newCat); |
|
|
|
|
categoryListeners.forEach(l -> l.setCategory(newCat)); |
|
|
|
|
LOG.debug("Listeners notified."); |
|
|
|
|
if (!newCat.isEmpty()) { |
|
|
|
|
String prefix = "app.categories."+newCat+"."; |
|
|
|
|
String path = config.get(prefix+"path"); |
|
|
|
@ -199,18 +260,26 @@ public class Toolbar extends JPanel {
@@ -199,18 +260,26 @@ public class Toolbar extends JPanel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONObject fields = config.get(prefix+"fields"); |
|
|
|
|
if (fields == null) return; |
|
|
|
|
LOG.debug("fields: {}",fields); |
|
|
|
|
for (String fieldName : fields.keySet()) { |
|
|
|
|
path = prefix+"fields."+fieldName; |
|
|
|
|
|
|
|
|
|
JSONArray arr = config.getOrCreateArray(path); |
|
|
|
|
HashSet<Object> values = new HashSet<>(); |
|
|
|
|
arr.forEach(values::add); |
|
|
|
|
SelectComboBox selector = getSelector(additonalComponents.get(fieldName)); |
|
|
|
|
if (selector != null) selector.setElements(values); |
|
|
|
|
if (fields != null) { |
|
|
|
|
LOG.debug("fields: {}",fields); |
|
|
|
|
for (String fieldName : fields.keySet()) { |
|
|
|
|
path = prefix+"fields."+fieldName; |
|
|
|
|
|
|
|
|
|
JSONArray arr = config.getOrCreateArray(path); |
|
|
|
|
HashSet<Object> values = new HashSet<>(); |
|
|
|
|
arr.forEach(values::add); |
|
|
|
|
SelectComboBox selector = getSelector(additonalComponents.get(fieldName)); |
|
|
|
|
if (selector != null) selector.setElements(values); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LOG.debug("Trying to read size"); |
|
|
|
|
Integer w = config.get(prefix+"size.w"); |
|
|
|
|
LOG.debug("w: {}",w); |
|
|
|
|
width.setText(w == null ? Constants.DEFAULT_WIDTH : w+""); |
|
|
|
|
Integer h = config.get(prefix+"size.h"); |
|
|
|
|
LOG.debug("h: {}",h); |
|
|
|
|
height.setText(h == null ? Constants.DEFAULT_HEIGHT : h+""); |
|
|
|
|
} else LOG.debug("newCat is empty!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateField(String name, String val) { |
|
|
|
|