Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 49d5b6fe authored by PECHOUX Romain's avatar PECHOUX Romain
Browse files

MainFrame.java reformat

parent 65476545
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@ limitations under the License.
package view;
import complexityparser.Model;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
......@@ -29,33 +28,27 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
/**
* a basic view to display a text editor containing the code that is analysed and displayed by the ANTLR tree
* A basic view to display a text editor containing the code that is analysed and displayed by the ANTLR tree.
*/
public class EditorView extends JPanel {
private JScrollPane panel;
private JTextArea area;
private JButton updateButton;
private MainFrame parent;
private Model m;
public EditorView(Model m, MainFrame parent) {
this.parent = parent;
this.m = m;
InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
area = new JTextArea(m.getCode());
area.setCaretColor(area.getForeground());
area.getCaret().setBlinkRate(0);
area.setTabSize(4);
area.setFont(new Font("monospaced", Font.PLAIN, 12));
panel = new JScrollPane(area);
panel.setWheelScrollingEnabled(true);
updateButton = new JButton("update");
Action action = new AbstractAction() {
@Override
......@@ -67,20 +60,16 @@ public class EditorView extends JPanel {
updateButton.addActionListener(action);
inputMap.put(KeyStroke.getKeyStroke("F6"), "F6");
getActionMap().put("F6", action);
BorderLayout layout = new BorderLayout();
setLayout(layout);
add(panel, BorderLayout.CENTER);
add(updateButton, BorderLayout.SOUTH);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK), "o");
getActionMap().put("o", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
if(JFileChooser.APPROVE_OPTION == fc.showOpenDialog(parent)) {
File f = fc.getSelectedFile();
try {
......@@ -96,9 +85,7 @@ public class EditorView extends JPanel {
}
}
});
setPreferredSize(new Dimension(400, 600));
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
getActionMap().put("escape", new AbstractAction() {
@Override
......@@ -107,4 +94,4 @@ public class EditorView extends JPanel {
}
});
}
}
}
\ No newline at end of file
......@@ -17,34 +17,29 @@ limitations under the License.
package view;
import complexityparser.Model;
import javax.swing.*;
import java.awt.*;
/**
* just the main window
* The main window.
*/
public class MainFrame extends JFrame {
public MainFrame(Model m) {
setTheme();
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("ComplexityParser");
BorderLayout layout = new BorderLayout();
setLayout(layout);
add(new EditorView(m, this), BorderLayout.WEST);
add(new TreePanel(m), BorderLayout.CENTER);
add(new MessageView(m), BorderLayout.EAST);
pack();
//setSize(600,600);
}
/**
* changes the look and feel of java swing to the OS theme
* Changes the look and feel of java swing to the OS theme.
*/
private static void setTheme() {
try {
......@@ -53,4 +48,4 @@ public class MainFrame extends JFrame {
e.printStackTrace();
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment