|
|
|
@ -7,20 +7,22 @@ import java.awt.event.ActionEvent;
@@ -7,20 +7,22 @@ import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.TreeSet; |
|
|
|
|
import java.util.Vector; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import javax.swing.Box; |
|
|
|
|
import javax.swing.BoxLayout; |
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
|
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
@ -55,14 +57,13 @@ public class Toolbar extends JPanel {
@@ -55,14 +57,13 @@ public class Toolbar extends JPanel {
|
|
|
|
|
|
|
|
|
|
public interface PathListener{ |
|
|
|
|
public void setPath(String path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = -5834326573752788233L; |
|
|
|
|
|
|
|
|
|
private static final int OFFSET = 2; |
|
|
|
|
private static EmptyBorder BORDER = new EmptyBorder(0,5,5,5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Vector<Object> categories = new Vector<>(); |
|
|
|
|
private Vector<Object> paths = new Vector<>(); |
|
|
|
|
|
|
|
|
|
private HashMap<String,JPanel> additonalComponents = new HashMap<>(); |
|
|
|
@ -83,16 +84,18 @@ public class Toolbar extends JPanel {
@@ -83,16 +84,18 @@ public class Toolbar extends JPanel {
|
|
|
|
|
|
|
|
|
|
private JTextField width; |
|
|
|
|
private JTextField height; |
|
|
|
|
private SelectComboBox catPicker; |
|
|
|
|
|
|
|
|
|
public Toolbar(Configuration config) { |
|
|
|
|
this.config = config; |
|
|
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
|
|
|
|
add(datePicker()); |
|
|
|
|
add(input("Kategorie",categoryPicker(config))); |
|
|
|
|
add(input("Kategorie",catPicker = categoryPicker(config))); |
|
|
|
|
add(input("Pfad",pathPicker = pathPicker())); |
|
|
|
|
addFormatSelector(); |
|
|
|
|
add(scanButton()); |
|
|
|
|
add(new JPanel()); |
|
|
|
|
add(Box.createGlue()); |
|
|
|
|
Arrays.stream(getComponents()).filter(c -> c instanceof JPanel).map(JPanel.class::cast).forEach(p -> p.setBorder(BORDER)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,7 +104,7 @@ public class Toolbar extends JPanel {
@@ -101,7 +104,7 @@ public class Toolbar extends JPanel {
|
|
|
|
|
dummy.setLayout(new BorderLayout()); |
|
|
|
|
dummy.setMaximumSize(new Dimension(600, 40)); |
|
|
|
|
|
|
|
|
|
dummy.add(new JLabel("Breite:"),BorderLayout.WEST); |
|
|
|
|
dummy.add(new JLabel("Breite: "),BorderLayout.WEST); |
|
|
|
|
dummy.add(width = new JTextField(209+""),BorderLayout.CENTER); |
|
|
|
|
dummy.add(new JLabel("px"),BorderLayout.EAST); |
|
|
|
|
add(dummy); |
|
|
|
@ -110,7 +113,7 @@ public class Toolbar extends JPanel {
@@ -110,7 +113,7 @@ public class Toolbar extends JPanel {
|
|
|
|
|
dummy.setLayout(new BorderLayout()); |
|
|
|
|
dummy.setMaximumSize(new Dimension(600, 40)); |
|
|
|
|
|
|
|
|
|
dummy.add(new JLabel("Höhe:"),BorderLayout.WEST); |
|
|
|
|
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); |
|
|
|
@ -134,9 +137,9 @@ public class Toolbar extends JPanel {
@@ -134,9 +137,9 @@ public class Toolbar extends JPanel {
|
|
|
|
|
|
|
|
|
|
for (String name : marks) { |
|
|
|
|
if (additonalComponents.containsKey(name)) continue; |
|
|
|
|
Vector<Object> knownValues = new Vector<>(); |
|
|
|
|
SelectComboBox valuePicker = new SelectComboBox(knownValues).onUpdateText(newText -> updateField(name,newText)); |
|
|
|
|
SelectComboBox valuePicker = new SelectComboBox(new Vector<>()).onUpdateText(newText -> updateField(name,newText)); |
|
|
|
|
JPanel input = input(name, valuePicker); |
|
|
|
|
input.setBorder(BORDER); |
|
|
|
|
add(input,getComponentCount()-OFFSET); |
|
|
|
|
additonalComponents.put(name, input); |
|
|
|
|
} |
|
|
|
@ -173,12 +176,11 @@ public class Toolbar extends JPanel {
@@ -173,12 +176,11 @@ public class Toolbar extends JPanel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Component categoryPicker(Configuration config) { |
|
|
|
|
private SelectComboBox categoryPicker(Configuration config) { |
|
|
|
|
JSONObject elements = config.getOrCreate("app.categories",new JSONObject()); |
|
|
|
|
Set<String> cats = elements.keySet().stream().map(Object::toString).map(String::trim).collect(Collectors.toSet()); |
|
|
|
|
categories = new Vector<>(cats); |
|
|
|
|
categories.sort((a,b)->a.toString().compareTo(b.toString())); |
|
|
|
|
return new SelectComboBox(categories).onUpdateText(this::updateCat); |
|
|
|
|
return new SelectComboBox(elements.keySet()) |
|
|
|
|
.onUpdateText(this::updateCat) |
|
|
|
|
.onDelete(this::dropCategory); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Component datePicker() { |
|
|
|
@ -189,6 +191,16 @@ public class Toolbar extends JPanel {
@@ -189,6 +191,16 @@ public class Toolbar extends JPanel {
|
|
|
|
|
return date; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void dropCategory(String catName) { |
|
|
|
|
LOG.debug("dropCategory({})",catName); |
|
|
|
|
Object o = config.get("app.categories"); |
|
|
|
|
if (o instanceof JSONObject) { |
|
|
|
|
JSONObject json = (JSONObject)o; |
|
|
|
|
json.remove(catName); |
|
|
|
|
catPicker.setElements(json.keySet()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Date getDate() { |
|
|
|
|
return date.getSelectedDate(); |
|
|
|
|
} |
|
|
|
@ -203,11 +215,12 @@ public class Toolbar extends JPanel {
@@ -203,11 +215,12 @@ public class Toolbar extends JPanel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JPanel input(String caption, Component component) { |
|
|
|
|
private JPanel input(String caption, JComponent component) { |
|
|
|
|
component.setMaximumSize(new Dimension(600, 40)); |
|
|
|
|
component.setToolTipText("Drücken Sie Umschalt + Entf um einen Eintrag zu löschen"); |
|
|
|
|
JPanel panel = new JPanel(); |
|
|
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); |
|
|
|
|
panel.add(new JLabel(caption+" ")); |
|
|
|
|
panel.add(new JLabel(caption+": ")); |
|
|
|
|
panel.add(component); |
|
|
|
|
return panel; |
|
|
|
|
} |
|
|
|
@ -232,9 +245,8 @@ public class Toolbar extends JPanel {
@@ -232,9 +245,8 @@ public class Toolbar extends JPanel {
|
|
|
|
|
scanListeners.forEach(l->l.actionPerformed(evt)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void readyToScan(boolean val) { |
|
|
|
|
public void readyToScanX(boolean val) { |
|
|
|
|
scanButton.setEnabled(val); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -257,10 +269,8 @@ public class Toolbar extends JPanel {
@@ -257,10 +269,8 @@ public class Toolbar extends JPanel {
|
|
|
|
|
path = prefix+"fields."+fieldName; |
|
|
|
|
|
|
|
|
|
JSONArray arr = config.getOrCreateArray(path); |
|
|
|
|
TreeSet<Object> values = new TreeSet<>(); |
|
|
|
|
arr.forEach(elem -> values.add(elem.toString().trim())); |
|
|
|
|
SelectComboBox selector = getSelector(additonalComponents.get(fieldName)); |
|
|
|
|
if (selector != null) selector.setElements(values); |
|
|
|
|
if (selector != null) selector.setElements(arr.toList()).onDelete(tx -> selector.setElements(deleteValue(arr,tx))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LOG.debug("Trying to read size"); |
|
|
|
@ -274,6 +284,17 @@ public class Toolbar extends JPanel {
@@ -274,6 +284,17 @@ public class Toolbar extends JPanel {
|
|
|
|
|
} else LOG.debug("newCat is empty!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<Object> deleteValue(JSONArray arr, String tx) { |
|
|
|
|
for (int i = 0; i<arr.length(); i++) { |
|
|
|
|
if (arr.get(i).equals(tx)) { |
|
|
|
|
arr.remove(i); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return arr.toList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void updateDimensions() { |
|
|
|
|
LOG.debug("updateDimensions()"); |
|
|
|
|
try { |
|
|
|
|