|
|
@ -166,6 +166,9 @@ public class MainWindow { |
|
|
|
p.add(itemControl, BorderLayout.SOUTH); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Open a new terminal window, calls {@link #makeTerm()} to make the internal panel |
|
|
|
*/ |
|
|
|
public static void openTerm() { |
|
|
|
|
|
|
|
instance.term = makeWindow(makeTerm(), "Interactive Cypher Terminal", false, 400, 600, true, 50, 50, 300, 400); |
|
|
@ -184,25 +187,36 @@ public class MainWindow { |
|
|
|
public void windowActivated(WindowEvent e) {} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* makes a new terminal interface for making manual Cypher Queries |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private static JPanel makeTerm() { |
|
|
|
JPanel panel = new JPanel(); |
|
|
|
panel.setLayout(new BorderLayout()); |
|
|
|
JPanel mainPanel = new JPanel(); |
|
|
|
mainPanel.setLayout(new BorderLayout()); //<---------------------------------Main window panel |
|
|
|
|
|
|
|
|
|
|
|
JPanel contents = new JPanel(); |
|
|
|
contents.setLayout(new BoxLayout(contents, BoxLayout.PAGE_AXIS)); |
|
|
|
//<--- Center query results section ---> |
|
|
|
|
|
|
|
JPanel padder = new JPanel(new BorderLayout()); |
|
|
|
padder.add(contents, BorderLayout.NORTH); |
|
|
|
JPanel resultsPanel = new JPanel(); |
|
|
|
resultsPanel.setLayout(new BoxLayout(resultsPanel, BoxLayout.PAGE_AXIS)); |
|
|
|
|
|
|
|
JPanel resultsTopAlignPanel = new JPanel(new BorderLayout()); |
|
|
|
resultsTopAlignPanel.add(resultsPanel, BorderLayout.NORTH); |
|
|
|
|
|
|
|
panel.add(new JScrollPane(padder), BorderLayout.CENTER); |
|
|
|
|
|
|
|
JPanel input = new JPanel(); |
|
|
|
input.setLayout(new BorderLayout()); |
|
|
|
mainPanel.add(new JScrollPane(resultsTopAlignPanel), BorderLayout.CENTER); |
|
|
|
|
|
|
|
JTextField textfield = new JTextField(); |
|
|
|
textfield.addKeyListener(new KeyListener() { |
|
|
|
|
|
|
|
//<--- Bottom input panel section ---> |
|
|
|
|
|
|
|
JPanel inputPanel = new JPanel(); |
|
|
|
inputPanel.setLayout(new BorderLayout()); |
|
|
|
|
|
|
|
JTextField inputTextfield = new JTextField(); |
|
|
|
inputTextfield.addKeyListener(new KeyListener() { |
|
|
|
public void keyTyped(KeyEvent e) {} |
|
|
|
public void keyReleased(KeyEvent e) {} |
|
|
|
@Override |
|
|
@ -211,7 +225,7 @@ public class MainWindow { |
|
|
|
case KeyEvent.VK_UP:{ |
|
|
|
if(instance.termHistoryDepth == -1) { |
|
|
|
instance.termHistoryDepth = instance.termHistory.size()-1; //If the list is empty it ends up -1 anyways |
|
|
|
if(instance.termHistoryDepth != -1)instance.termTempText = textfield.getText(); |
|
|
|
if(instance.termHistoryDepth != -1)instance.termTempText = inputTextfield.getText(); |
|
|
|
}else if(instance.termHistoryDepth > 0)instance.termHistoryDepth--; |
|
|
|
break; |
|
|
|
} |
|
|
@ -224,18 +238,18 @@ public class MainWindow { |
|
|
|
} |
|
|
|
if(instance.termHistoryDepth == -1) { |
|
|
|
if(instance.termTempText!=null) { |
|
|
|
textfield.setText(instance.termTempText); |
|
|
|
inputTextfield.setText(instance.termTempText); |
|
|
|
instance.termTempText = null; |
|
|
|
} |
|
|
|
}else { |
|
|
|
textfield.setText(instance.termHistory.get(instance.termHistoryDepth)); |
|
|
|
inputTextfield.setText(instance.termHistory.get(instance.termHistoryDepth)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
ActionListener submit = (e)->{ |
|
|
|
String q = textfield.getText(); |
|
|
|
textfield.setText(""); |
|
|
|
String q = inputTextfield.getText(); |
|
|
|
inputTextfield.setText(""); |
|
|
|
|
|
|
|
if(q.trim().equals(""))return; //No empty inputs |
|
|
|
|
|
|
@ -247,44 +261,75 @@ public class MainWindow { |
|
|
|
JLabel querryResLabel = new JLabel("Loading..."); |
|
|
|
querryResult.add(querryResLabel, new GridBagConstraints(0, 0, 1, 0, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); |
|
|
|
querryResult.add(a(new JButton("❌"), (ev)->{ |
|
|
|
contents.remove(querryResult); |
|
|
|
contents.revalidate(); |
|
|
|
contents.repaint(); |
|
|
|
resultsPanel.remove(querryResult); |
|
|
|
resultsPanel.revalidate(); |
|
|
|
resultsPanel.repaint(); |
|
|
|
}), new GridBagConstraints(1, 0, 1, 0, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0)); |
|
|
|
contents.add(querryResult, contents.getComponentCount()); |
|
|
|
resultsPanel.add(querryResult, resultsPanel.getComponentCount()); |
|
|
|
|
|
|
|
instance.db.postTerminalQuerry(new TerminalQuerry(contents, querryResult, querryResLabel, q)); |
|
|
|
instance.db.postTerminalQuerry(new TerminalQuerry(resultsPanel, querryResult, querryResLabel, q)); |
|
|
|
|
|
|
|
contents.revalidate(); |
|
|
|
contents.repaint(); |
|
|
|
resultsPanel.revalidate(); |
|
|
|
resultsPanel.repaint(); |
|
|
|
}; |
|
|
|
|
|
|
|
input.add(b(a(textfield, submit), i(4)), BorderLayout.CENTER); |
|
|
|
input.add(b(newButton("submit", submit), i(4)), BorderLayout.EAST); |
|
|
|
inputPanel.add(b(a(inputTextfield, submit), i(4)), BorderLayout.CENTER); |
|
|
|
inputPanel.add(b(newButton("submit", submit), i(4)), BorderLayout.EAST); |
|
|
|
|
|
|
|
panel.add(input, BorderLayout.SOUTH); |
|
|
|
mainPanel.add(inputPanel, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
return panel; |
|
|
|
return mainPanel; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Make insets object |
|
|
|
* @param i amount to pad |
|
|
|
* @return Insets |
|
|
|
*/ |
|
|
|
public static Insets i(int i) { |
|
|
|
return new Insets(i, i, i, i); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make insets object |
|
|
|
* @param i amount to pad vertically |
|
|
|
* @param j amount to pad horizontally |
|
|
|
* @return Insets |
|
|
|
*/ |
|
|
|
public static Insets i(int i, int j) { |
|
|
|
return new Insets(i, j, i, j); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make insets object |
|
|
|
* @param i amount to pad top |
|
|
|
* @param j amount to pad bottom |
|
|
|
* @param k amount to pad horizontally |
|
|
|
* @return Insets |
|
|
|
*/ |
|
|
|
public static Insets i(int i, int j, int k) { |
|
|
|
return new Insets(i, j, k, j); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make insets object |
|
|
|
* @param i amount to pad top |
|
|
|
* @param j amount to pad left |
|
|
|
* @param k amount to pad bottom |
|
|
|
* @param l amount to pad right |
|
|
|
* @return Insets |
|
|
|
*/ |
|
|
|
public static Insets i(int i, int j, int k, int l) { |
|
|
|
return new Insets(i, j, k, l); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Add padding to a component by putting it in a new panel with the insets applied. |
|
|
|
* Layout is set to a GridLayout(1, 1) |
|
|
|
* @param c component to pad |
|
|
|
* @param i insets object for padding amount |
|
|
|
* @return a JPanel with the padding applied containing the given component |
|
|
|
*/ |
|
|
|
private static JComponent b(JComponent c, Insets i) { |
|
|
|
//if(c.getBorder() != null)c.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(i, i, i, i), new LineBorder(Color.BLACK)), c.getBorder())); |
|
|
|
//else c.setBorder(new EmptyBorder(i, i, i, i)); |
|
|
@ -307,6 +352,12 @@ public class MainWindow { |
|
|
|
return f; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Add on input listener |
|
|
|
* @param text field |
|
|
|
* @param lambda/IOnInput with function to run, gets document event as argument |
|
|
|
* @return original text field |
|
|
|
*/ |
|
|
|
public static JTextField a(JTextField f, IOnInput i) { |
|
|
|
f.getDocument().addDocumentListener(new DocumentListener() { |
|
|
|
|
|
|
@ -327,12 +378,23 @@ public class MainWindow { |
|
|
|
}); |
|
|
|
return f; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Add action listeners to a button |
|
|
|
* @param b JButton |
|
|
|
* @param actionListeners list of action listeners |
|
|
|
* @return the original button |
|
|
|
*/ |
|
|
|
public static JButton a(JButton b, ActionListener ... actionListeners) { |
|
|
|
for(ActionListener a : actionListeners)b.addActionListener(a); |
|
|
|
return b; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Make a new button |
|
|
|
* @param label Text label for button |
|
|
|
* @param actionListeners list of action listeners to apply |
|
|
|
* @return a new JButton with the text label and action listeners applied |
|
|
|
*/ |
|
|
|
private static JButton newButton(String label, ActionListener ... actionListeners) { |
|
|
|
JButton b = new JButton(label); |
|
|
|
for(ActionListener a : actionListeners)b.addActionListener(a); |
|
|
|