├── .gitignore
├── Design.pdf
├── passed.png
├── bin
└── grid
│ ├── view
│ ├── GridFrame.class
│ └── GridPanel.class
│ ├── model
│ ├── PlanetMoon.class
│ └── GridTableModel.class
│ ├── tests
│ ├── FrameTest.class
│ ├── GridTests.class
│ ├── PanelTest.class
│ └── ControllerTest.class
│ ├── controller
│ ├── GridRunner.class
│ └── GridController.class
│ └── assets
│ └── planetMoons.txt
├── src
└── grid
│ ├── assets
│ └── planetMoons.txt
│ ├── controller
│ ├── GridRunner.java
│ └── GridController.java
│ ├── tests
│ ├── GridTests.java
│ ├── FrameTest.java
│ ├── ControllerTest.java
│ └── PanelTest.java
│ ├── model
│ ├── GridTableModel.java
│ └── PlanetMoon.java
│ └── view
│ ├── GridFrame.java
│ └── GridPanel.java
├── .classpath
├── .project
├── Design.uxf
└── .settings
└── org.eclipse.jdt.core.prefs
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | bin/
3 |
--------------------------------------------------------------------------------
/Design.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/Design.pdf
--------------------------------------------------------------------------------
/passed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/passed.png
--------------------------------------------------------------------------------
/bin/grid/view/GridFrame.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/view/GridFrame.class
--------------------------------------------------------------------------------
/bin/grid/view/GridPanel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/view/GridPanel.class
--------------------------------------------------------------------------------
/bin/grid/model/PlanetMoon.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/model/PlanetMoon.class
--------------------------------------------------------------------------------
/bin/grid/tests/FrameTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/tests/FrameTest.class
--------------------------------------------------------------------------------
/bin/grid/tests/GridTests.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/tests/GridTests.class
--------------------------------------------------------------------------------
/bin/grid/tests/PanelTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/tests/PanelTest.class
--------------------------------------------------------------------------------
/bin/grid/controller/GridRunner.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/controller/GridRunner.class
--------------------------------------------------------------------------------
/bin/grid/model/GridTableModel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/model/GridTableModel.class
--------------------------------------------------------------------------------
/bin/grid/tests/ControllerTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/tests/ControllerTest.class
--------------------------------------------------------------------------------
/bin/grid/controller/GridController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/2DArrayManipulator/master/bin/grid/controller/GridController.class
--------------------------------------------------------------------------------
/bin/grid/assets/planetMoons.txt:
--------------------------------------------------------------------------------
1 | moon
2 | Deimos,Phobos
3 | Adrastea,Callisto,Lo,Kale,Metis,Pasithee,Sinope,Taygete
4 | Despina,Galatea,Larissa,Laomedeia,Naiad,Nereid,Neso,Proteus
5 | Ariel,Belinda,Bianca,Caliban,Juliet,Mab,Margaret,Oberon,Umbriel
--------------------------------------------------------------------------------
/src/grid/assets/planetMoons.txt:
--------------------------------------------------------------------------------
1 | moon
2 | Deimos,Phobos
3 | Adrastea,Callisto,Lo,Kale,Metis,Pasithee,Sinope,Taygete
4 | Despina,Galatea,Larissa,Laomedeia,Naiad,Nereid,Neso,Proteus
5 | Ariel,Belinda,Bianca,Caliban,Juliet,Mab,Margaret,Oberon,Umbriel
--------------------------------------------------------------------------------
/src/grid/controller/GridRunner.java:
--------------------------------------------------------------------------------
1 | package grid.controller;
2 |
3 | public class GridRunner {
4 |
5 | public static void main(String[] args) {
6 | GridController controller = new GridController();
7 | controller.start();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/grid/tests/GridTests.java:
--------------------------------------------------------------------------------
1 | package grid.tests;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 | import org.junit.runners.Suite.SuiteClasses;
6 |
7 | @RunWith(Suite.class)
8 | @SuiteClasses({ ControllerTest.class, FrameTest.class, PanelTest.class })
9 | public class GridTests
10 | {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/grid/model/GridTableModel.java:
--------------------------------------------------------------------------------
1 | package grid.model;
2 |
3 | import javax.swing.table.DefaultTableModel;
4 |
5 | public class GridTableModel extends DefaultTableModel {
6 |
7 | public GridTableModel(){
8 | super();
9 | }
10 |
11 | @Override
12 | public boolean isCellEditable(int row, int column) {
13 | return false;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2DArrayManipulator
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/grid/model/PlanetMoon.java:
--------------------------------------------------------------------------------
1 | package grid.model;
2 |
3 | public class PlanetMoon {
4 |
5 | private String moonName;
6 |
7 | public PlanetMoon(String moonName){
8 | this.moonName = moonName;
9 | }
10 |
11 | @Override
12 | public String toString() {
13 | return "The moon name is: " + moonName;
14 | }
15 |
16 | public String getMoonName() {
17 | return moonName;
18 | }
19 |
20 | public void setMoonName(String moonName) {
21 | this.moonName = moonName;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Design.uxf:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10
4 |
5 | UMLClass
6 |
7 | 20
8 | 20
9 | 360
10 | 120
11 |
12 | PlanetMoon
13 | --
14 | - planetMoon : String
15 | --
16 | + toString() : void
17 | + setPlanetMoon() : void
18 | + getPlanetMoonName() : String
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=1.8
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=1.8
12 |
--------------------------------------------------------------------------------
/src/grid/view/GridFrame.java:
--------------------------------------------------------------------------------
1 | package grid.view;
2 |
3 | import javax.swing.JFrame;
4 |
5 | import grid.controller.GridController;
6 |
7 | public class GridFrame extends JFrame {
8 |
9 | private GridController gridController;
10 |
11 | private GridPanel gridPanel;
12 |
13 | public GridFrame(GridController gridController){
14 | super();
15 | this.gridController = gridController;
16 | this.gridPanel = new GridPanel(gridController);
17 |
18 | this.setupFrame();
19 | }
20 |
21 | public void setupFrame(){
22 | this.setContentPane(gridPanel);
23 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24 |
25 | this.setTitle("2D Array Manipulator");
26 |
27 | this.setSize(600, 570);
28 | this.setLocationRelativeTo(null);
29 |
30 | this.setVisible(true);
31 | }
32 |
33 | public GridController getBaseController(){
34 | return gridController;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/grid/tests/FrameTest.java:
--------------------------------------------------------------------------------
1 | package grid.tests;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import grid.view.GridFrame;
10 | import grid.view.GridPanel;
11 | import grid.controller.GridController;
12 |
13 | public class FrameTest
14 | {
15 | private GridFrame testFrame;
16 |
17 | @Before
18 | public void setUp() throws Exception
19 | {
20 | testFrame = new GridFrame(new GridController());
21 | }
22 |
23 | @After
24 | public void tearDown() throws Exception
25 | {
26 | testFrame = null;
27 | }
28 |
29 | @Test
30 | public void testGridFrame()
31 | {
32 | assertNotNull("Data member not initialized", testFrame.getBaseController());
33 | assertTrue("Data member is of incorrect type", testFrame.getBaseController() instanceof GridController);
34 | assertNotNull("Data member not initialized", testFrame.getContentPane());
35 | }
36 |
37 | @Test
38 | public void testSetupFrame()
39 | {
40 | assertTrue("Title must be more than 5 characters long.", testFrame.getTitle().trim().length() > 5);
41 | assertTrue("Correct panel not installed", testFrame.getContentPane() instanceof GridPanel);
42 | assertTrue("Minimum size not met", testFrame.getWidth() >= 500 && testFrame.getHeight() >= 500);
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/grid/tests/ControllerTest.java:
--------------------------------------------------------------------------------
1 | package grid.tests;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.*;
6 | import grid.controller.GridController;
7 | import grid.view.GridFrame;
8 |
9 | public class ControllerTest
10 | {
11 | private GridController testController;
12 |
13 | @Before
14 | public void setUp() throws Exception
15 | {
16 | testController = new GridController();
17 | }
18 |
19 | @After
20 | public void tearDown() throws Exception
21 | {
22 | testController = null;
23 | }
24 |
25 | @Test
26 | public void testGridController()
27 | {
28 | assertNotNull("Two Dimensional grid needs to exist", testController.getGrid());
29 | assertTrue("2D Grid needs at least 5 rows", testController.getGrid().length > 4);
30 | assertTrue("2D Grid needs at least 5 columns", testController.getGrid()[0].length >= 5);
31 | assertNotNull("GUI exists", testController.getFrame());
32 | assertTrue("GUI Frame is not of correct type", testController.getFrame() instanceof GridFrame);
33 | }
34 |
35 | @Test
36 | public void testGridModel()
37 | {
38 | for (int row = 0; row < testController.getGrid().length; row++)
39 | {
40 | for (int col = 0; col < testController.getGrid()[0].length; col++)
41 | {
42 | assertNotNull("Contents of grid must exist", testController.getGrid()[row][col]);
43 | assertFalse("@ symbol means default toString is in use", testController.getGrid()[row][col].toString().contains("@"));
44 | assertTrue("The toString method is long enough", testController.getGrid()[row][col].toString().length() > 5);
45 | }
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/grid/controller/GridController.java:
--------------------------------------------------------------------------------
1 | package grid.controller;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 |
6 | import javax.swing.JOptionPane;
7 |
8 | import grid.model.PlanetMoon;
9 | import grid.view.GridFrame;
10 |
11 | public class GridController {
12 |
13 | // Moon website: http://www.windows2universe.org/our_solar_system/moons_table.html
14 | // Earth, Mars, Jupiter, Neptune, Uranus
15 | private PlanetMoon[][] planetMoons;
16 | private GridFrame gridFrame;
17 |
18 | public GridController(){
19 | this.populatePlanetMoonArray();
20 | this.gridFrame = new GridFrame(this);
21 | }
22 |
23 | public void start(){
24 |
25 | }
26 |
27 | public void populatePlanetMoonArray(){
28 | try{
29 | BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/grid/assets/planetMoons.txt")));
30 | this.planetMoons = new PlanetMoon[5][10];
31 | for(int row = 0; row < this.planetMoons.length; row++){
32 | String[] moonData = reader.readLine().split(",");
33 | for(int col = 0; col < planetMoons[0].length; col++){
34 | if(moonData.length - 1 < col){
35 | planetMoons[row][col] = new PlanetMoon("");
36 | }else{
37 | planetMoons[row][col] = new PlanetMoon(moonData[col]);
38 | }
39 | }
40 | }
41 | }catch(Exception e){
42 | e.printStackTrace();
43 | JOptionPane.showMessageDialog(null, "Error", "Error in reading file!", JOptionPane.ERROR_MESSAGE);
44 | }
45 | }
46 |
47 | public PlanetMoon[][] getGrid(){
48 | return planetMoons;
49 | }
50 |
51 | public GridFrame getFrame() {
52 | return gridFrame;
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/grid/tests/PanelTest.java:
--------------------------------------------------------------------------------
1 | package grid.tests;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.awt.Component;
6 | import java.awt.event.ActionListener;
7 | import javax.swing.JButton;
8 | import javax.swing.JScrollPane;
9 | import javax.swing.JTable;
10 | import javax.swing.SpringLayout;
11 | import javax.swing.JTextField;
12 | import org.junit.*;
13 | import grid.controller.GridController;
14 | import grid.view.GridPanel;
15 |
16 | public class PanelTest
17 | {
18 | private GridPanel testPanel;
19 |
20 | @Before
21 | public void setUp() throws Exception
22 | {
23 | testPanel = new GridPanel(new GridController());
24 | }
25 |
26 | @After
27 | public void tearDown() throws Exception
28 | {
29 | testPanel = null;
30 | }
31 |
32 | @Test
33 | public void testPanelConstructor()
34 | {
35 | assertNotNull("Data member not initialized", testPanel.getBaseController());
36 | }
37 |
38 | @Test
39 | public void testSetupPanel()
40 | {
41 | assertTrue("Minimum component amount not met", testPanel.getComponentCount() > 8);
42 | assertTrue("Layout should be SpringLayout or absolute layout(not preferred)", (testPanel.getLayout() instanceof SpringLayout) || testPanel.getLayout() == null);
43 |
44 | int paneCount = 0;
45 | int tableCount = 0;
46 |
47 | for(Component current : testPanel.getComponents() )
48 | {
49 | if (current instanceof JScrollPane)
50 | {
51 | paneCount++;
52 | if(((JScrollPane)current).getViewport().getView() instanceof JTable)
53 | {
54 | tableCount++;
55 | }
56 | }
57 | if (current instanceof JTextField)
58 | {
59 | assertTrue("All text fields must be editable", ((JTextField)current).isEditable());
60 | }
61 | }
62 |
63 | assertTrue("JScrollPane not installed", paneCount > 0);
64 | assertTrue("JTable not inserted into JScrollPane", tableCount > 0);
65 | }
66 |
67 | @Test
68 | public void testSetupListeners()
69 | {
70 | for(Component button : testPanel.getComponents() )
71 | {
72 | if(button instanceof JButton)
73 | {
74 | assertNotNull("Listeners were not added to the button", ((JButton) button).getActionListeners());
75 | assertTrue("", ((JButton) button).getActionListeners()[0] instanceof ActionListener);
76 | }
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/grid/view/GridPanel.java:
--------------------------------------------------------------------------------
1 | package grid.view;
2 |
3 | import java.awt.Font;
4 | import java.awt.event.ActionEvent;
5 | import java.awt.event.ActionListener;
6 |
7 | import javax.swing.JButton;
8 | import javax.swing.JLabel;
9 | import javax.swing.JPanel;
10 | import javax.swing.JScrollPane;
11 | import javax.swing.JTable;
12 | import javax.swing.JTextField;
13 | import javax.swing.SpringLayout;
14 | import javax.swing.table.DefaultTableModel;
15 | import javax.swing.table.TableModel;
16 |
17 | import grid.controller.GridController;
18 | import grid.model.GridTableModel;
19 | import grid.model.PlanetMoon;
20 |
21 | public class GridPanel extends JPanel {
22 |
23 | private GridController gridController;
24 |
25 | private SpringLayout springLayout;
26 | private DefaultTableModel tableModel;
27 |
28 | private JScrollPane dataTableScrollPane;
29 | private JTable dataTable;
30 | private JLabel titleLabel;
31 | private JLabel currentDataLabel;
32 | private JTextField editCellField;
33 | private JButton insertButton;
34 | private JButton deleteButton;
35 | private JButton clearButton;
36 | private JButton quitButton;
37 | private JButton dontPushButton;
38 |
39 | public GridPanel(GridController gridController){
40 | super();
41 |
42 | this.gridController = gridController;
43 | this.springLayout = new SpringLayout();
44 |
45 | this.tableModel = new GridTableModel();
46 | this.dataTable = new JTable(tableModel);
47 | this.dataTableScrollPane = new JScrollPane(dataTable);
48 | this.titleLabel = new JLabel("Cell Editor");
49 | this.currentDataLabel = new JLabel("Edit Data:");
50 | this.editCellField = new JTextField();
51 | this.insertButton = new JButton("Insert");
52 | this.deleteButton = new JButton("Delete");
53 | this.clearButton = new JButton("Clear Table");
54 | this.quitButton = new JButton("Quit");
55 | this.dontPushButton = new JButton("Do Not Push");
56 |
57 | this.populateTableModel();
58 | this.setupComponents();
59 | this.setupPanel();
60 | this.setupLayout();
61 | this.setupListeners();
62 | }
63 |
64 | private void populateTableModel(){ // This method inverts the row and column data and populates the jTableModel
65 | PlanetMoon[][] planetMoons = gridController.getGrid();
66 |
67 | this.tableModel.setRowCount(planetMoons[0].length);
68 | this.tableModel.setColumnCount(planetMoons.length);
69 | this.tableModel.setColumnIdentifiers(new String[]{"Earth", "Mars", "Jupiter", "Neptune", "Uranus"});
70 |
71 | for(int row = 0; row < planetMoons.length; row++){
72 | for(int col = 0; col < planetMoons[0].length; col++){
73 | PlanetMoon planetMoon = planetMoons[row][col];
74 | this.tableModel.setValueAt(planetMoon.getMoonName(), col, row);
75 | }
76 | }
77 | }
78 |
79 | private void setupComponents(){
80 | this.dataTable.setRowSelectionAllowed(false);
81 | this.dataTable.setColumnSelectionAllowed(false);
82 | this.dataTable.setCellSelectionEnabled(true);
83 |
84 |
85 | Font font = new Font("Verdana", Font.PLAIN, 14);
86 | this.titleLabel.setFont(font.deriveFont(25f));
87 | this.dataTable.setFont(font.deriveFont(13f));
88 | this.currentDataLabel.setFont(font);
89 | this.editCellField.setFont(font);
90 | this.insertButton.setFont(font);
91 | this.deleteButton.setFont(font);
92 | this.clearButton.setFont(font);
93 | this.quitButton.setFont(font);
94 | this.dontPushButton.setFont(font);
95 | }
96 |
97 | private void setupPanel(){
98 | this.setLayout(springLayout);
99 | this.add(dataTableScrollPane);
100 | this.add(titleLabel);
101 | this.add(currentDataLabel);
102 | this.add(editCellField);
103 | this.add(insertButton);
104 | this.add(deleteButton);
105 | this.add(clearButton);
106 | this.add(quitButton);
107 | this.add(dontPushButton);
108 | }
109 |
110 | private void setupLayout(){
111 | springLayout.putConstraint(SpringLayout.NORTH, titleLabel, 20, SpringLayout.NORTH, this);
112 | springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, titleLabel, 0, SpringLayout.HORIZONTAL_CENTER, this);
113 |
114 | springLayout.putConstraint(SpringLayout.NORTH, dataTableScrollPane, 20, SpringLayout.SOUTH, titleLabel);
115 | springLayout.putConstraint(SpringLayout.SOUTH, dataTableScrollPane, 250, SpringLayout.NORTH, dataTableScrollPane);
116 | springLayout.putConstraint(SpringLayout.EAST, dataTableScrollPane, -20, SpringLayout.EAST, this);
117 | springLayout.putConstraint(SpringLayout.WEST, dataTableScrollPane, 20, SpringLayout.WEST, this);
118 |
119 | springLayout.putConstraint(SpringLayout.NORTH, currentDataLabel, 30, SpringLayout.SOUTH, dataTableScrollPane);
120 | springLayout.putConstraint(SpringLayout.WEST, currentDataLabel, 0, SpringLayout.WEST, dataTableScrollPane);
121 |
122 | springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, editCellField, 0, SpringLayout.VERTICAL_CENTER, currentDataLabel);
123 | springLayout.putConstraint(SpringLayout.EAST, editCellField, 0, SpringLayout.EAST, dataTableScrollPane);
124 | springLayout.putConstraint(SpringLayout.WEST, editCellField, 10, SpringLayout.EAST, currentDataLabel);
125 |
126 | springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, clearButton, 0, SpringLayout.HORIZONTAL_CENTER, dataTableScrollPane);
127 |
128 | springLayout.putConstraint(SpringLayout.NORTH, insertButton, 20, SpringLayout.SOUTH, editCellField);
129 | springLayout.putConstraint(SpringLayout.EAST, insertButton, 0, SpringLayout.WEST, clearButton);
130 |
131 | springLayout.putConstraint(SpringLayout.NORTH, deleteButton, 20, SpringLayout.SOUTH, editCellField);
132 | springLayout.putConstraint(SpringLayout.WEST, deleteButton, 0, SpringLayout.EAST, clearButton);
133 |
134 | springLayout.putConstraint(SpringLayout.NORTH, clearButton, 20, SpringLayout.SOUTH, insertButton);
135 |
136 | springLayout.putConstraint(SpringLayout.NORTH, quitButton, 20, SpringLayout.SOUTH, clearButton);
137 | springLayout.putConstraint(SpringLayout.EAST, quitButton, 0, SpringLayout.WEST, clearButton);
138 |
139 | springLayout.putConstraint(SpringLayout.NORTH, dontPushButton, 20, SpringLayout.SOUTH, clearButton);
140 | springLayout.putConstraint(SpringLayout.WEST, dontPushButton, 0, SpringLayout.EAST, clearButton);
141 | }
142 |
143 | private void setupListeners(){
144 | this.insertButton.addActionListener(new ActionListener() {
145 | @Override
146 | public void actionPerformed(ActionEvent e) {
147 | String text = editCellField.getText();
148 | if(text != null && !text.equals("") && dataTable.getSelectedRow() > 0 && dataTable.getSelectedColumn() > 0){
149 | editCellField.setText("");
150 | dataTable.getModel().setValueAt(text, dataTable.getSelectedRow(), dataTable.getSelectedColumn());
151 | }
152 | }
153 | });
154 | this.deleteButton.addActionListener(new ActionListener() {
155 | @Override
156 | public void actionPerformed(ActionEvent e) {
157 | if(dataTable.getSelectedRow() > 0 && dataTable.getSelectedColumn() > 0){
158 | dataTable.getModel().setValueAt(null, dataTable.getSelectedRow(), dataTable.getSelectedColumn());
159 | }
160 | }
161 | });
162 | this.clearButton.addActionListener(new ActionListener() {
163 | @Override
164 | public void actionPerformed(ActionEvent e) {
165 | TableModel tableModel = dataTable.getModel();
166 | for(int row = 0; row < tableModel.getRowCount(); row++){
167 | for(int col = 0; col < tableModel.getColumnCount(); col++){
168 | tableModel.setValueAt(null, row, col);
169 | }
170 | }
171 | }
172 | });
173 | this.quitButton.addActionListener(new ActionListener() {
174 | @Override
175 | public void actionPerformed(ActionEvent e) {
176 | System.exit(0);
177 | }
178 | });
179 | this.dontPushButton.addActionListener(new ActionListener() {
180 | @Override
181 | public void actionPerformed(ActionEvent e) {
182 | TableModel tableModel = dataTable.getModel();
183 | for(int row = 0; row < tableModel.getRowCount(); row++){
184 | for(int col = 0; col < tableModel.getColumnCount(); col++){
185 | String randomness = "";
186 | for(int rand = 0; rand < (int)(Math.random() * 15); rand++){
187 | randomness += (char)((int)(Math.random() * 255));
188 | }
189 | tableModel.setValueAt(randomness, row, col);
190 | }
191 | }
192 | }
193 | });
194 | }
195 |
196 |
197 | public GridController getBaseController(){
198 | return gridController;
199 | }
200 |
201 | }
202 |
--------------------------------------------------------------------------------