Added Button for File-Open-Dialog
This commit is contained in:
parent
522899eb1e
commit
bf9a7f56e0
|
@ -301,14 +301,15 @@ public class KorrekturHelper
|
||||||
|
|
||||||
private final JButton btn_toClipboard;
|
private final JButton btn_toClipboard;
|
||||||
|
|
||||||
|
private final JPanel contentPanel, menuPanel;
|
||||||
private String currentHtml = "";
|
private String currentHtml = "";
|
||||||
/** The JFrame for this {@link KorrekturHelper} */
|
/** The JFrame for this {@link KorrekturHelper} */
|
||||||
public final JFrame frm;
|
public final JFrame frm;
|
||||||
private final HtmlContext hc;
|
|
||||||
|
private HtmlContext hc;
|
||||||
|
|
||||||
private boolean inReset = false;
|
private boolean inReset = false;
|
||||||
|
private LinkedHashSet<Node> nodes;
|
||||||
private final LinkedHashSet<Node> nodes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nodes Nodes
|
* @param nodes Nodes
|
||||||
|
@ -316,16 +317,13 @@ public class KorrekturHelper
|
||||||
*/
|
*/
|
||||||
public KorrekturHelper(LinkedHashSet<Node> nodes, HtmlContext hc)
|
public KorrekturHelper(LinkedHashSet<Node> nodes, HtmlContext hc)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.nodes = nodes;
|
|
||||||
this.hc = hc;
|
|
||||||
frm = new JFrame("Pinggers Korrektur Helper");
|
frm = new JFrame("Pinggers Korrektur Helper");
|
||||||
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
var contentPanel = new JPanel(new BorderLayout(), true);
|
contentPanel = new JPanel(new BorderLayout(), true);
|
||||||
/*
|
/*
|
||||||
* Menu Panel
|
* Menu Panel
|
||||||
*/
|
*/
|
||||||
var menuPanel = new JPanel(true);
|
menuPanel = new JPanel(true);
|
||||||
menuPanel.setLayout(new BoxLayout(menuPanel, BoxLayout.X_AXIS));
|
menuPanel.setLayout(new BoxLayout(menuPanel, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
var jtb_aot = new JToggleButton("Always on Top");
|
var jtb_aot = new JToggleButton("Always on Top");
|
||||||
|
@ -339,28 +337,20 @@ public class KorrekturHelper
|
||||||
btn_toClipboard = new JButton("Copy to Clipboard");
|
btn_toClipboard = new JButton("Copy to Clipboard");
|
||||||
btn_toClipboard.addActionListener(e -> copyToClipboard());
|
btn_toClipboard.addActionListener(e -> copyToClipboard());
|
||||||
menuPanel.add(btn_toClipboard);
|
menuPanel.add(btn_toClipboard);
|
||||||
|
var btn_drop = new JButton("Open Schema");
|
||||||
|
btn_drop.addActionListener(e -> fileDialog());
|
||||||
|
menuPanel.add(btn_drop);
|
||||||
var btn_reset = new JButton("Reset");
|
var btn_reset = new JButton("Reset");
|
||||||
btn_reset.addActionListener(e -> reset());
|
btn_reset.addActionListener(e -> reset());
|
||||||
menuPanel.add(btn_reset);
|
menuPanel.add(btn_reset);
|
||||||
contentPanel.add(menuPanel, BorderLayout.NORTH);
|
contentPanel.add(menuPanel, BorderLayout.NORTH);
|
||||||
|
setNodes(nodes, hc);
|
||||||
/*
|
|
||||||
* Node-Panel with Scrollpane
|
|
||||||
*/
|
|
||||||
var panel = new JPanel(true);
|
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
||||||
var jsp = new JScrollPane(panel);
|
|
||||||
jsp.getVerticalScrollBar().setUnitIncrement(16);
|
|
||||||
Consumer<Node> c = n -> verifyClipboard();
|
|
||||||
for (var n : nodes)
|
|
||||||
{
|
|
||||||
n.addChangeListener(c);
|
|
||||||
panel.add(n.getComponent());
|
|
||||||
}
|
|
||||||
contentPanel.add(jsp, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
frm.setContentPane(contentPanel);
|
frm.setContentPane(contentPanel);
|
||||||
frm.pack();
|
frm.pack();
|
||||||
|
if (frm.getHeight() > 900)
|
||||||
|
{
|
||||||
|
frm.setSize(frm.getWidth(), 900);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -384,6 +374,29 @@ public class KorrekturHelper
|
||||||
btn_toClipboard.setBackground(Color.GREEN);
|
btn_toClipboard.setBackground(Color.GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fileDialog()
|
||||||
|
{
|
||||||
|
var x = new JFileChooser();
|
||||||
|
if (x.showOpenDialog(frm) == JFileChooser.APPROVE_OPTION)
|
||||||
|
{
|
||||||
|
var f = x.getSelectedFile();
|
||||||
|
try (
|
||||||
|
var in = new FileInputStream(f);
|
||||||
|
var isr = new InputStreamReader(in, StandardCharsets.UTF_8);
|
||||||
|
var br = new BufferedReader(isr, 1024 * 1024)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var hc = new HtmlContext();
|
||||||
|
var n = parseSchema(br, hc);
|
||||||
|
setNodes(n, hc);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the Input Mask
|
* Resets the Input Mask
|
||||||
*/
|
*/
|
||||||
|
@ -395,6 +408,34 @@ public class KorrekturHelper
|
||||||
verifyClipboard();
|
verifyClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Nodes and {@link HtmlContext}
|
||||||
|
*
|
||||||
|
* @param nodes nodes
|
||||||
|
* @param hc context
|
||||||
|
*/
|
||||||
|
public void setNodes(LinkedHashSet<Node> nodes, HtmlContext hc)
|
||||||
|
{
|
||||||
|
this.nodes = nodes;
|
||||||
|
this.hc = hc;
|
||||||
|
/*
|
||||||
|
* Node-Panel with Scrollpane
|
||||||
|
*/
|
||||||
|
var panel = new JPanel(true);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
var jsp = new JScrollPane(panel);
|
||||||
|
jsp.getVerticalScrollBar().setUnitIncrement(16);
|
||||||
|
Consumer<Node> c = n -> verifyClipboard();
|
||||||
|
for (var n : nodes)
|
||||||
|
{
|
||||||
|
n.addChangeListener(c);
|
||||||
|
panel.add(n.getComponent());
|
||||||
|
}
|
||||||
|
contentPanel.removeAll();
|
||||||
|
contentPanel.add(menuPanel, BorderLayout.NORTH);
|
||||||
|
contentPanel.add(jsp, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on change of data or when the System signifies, the Clipboard changed
|
* Called on change of data or when the System signifies, the Clipboard changed
|
||||||
*/
|
*/
|
||||||
|
|
Reference in New Issue