1 | package oseam.panels;
|
---|
2 |
|
---|
3 | import java.awt.event.*;
|
---|
4 | import javax.swing.*;
|
---|
5 |
|
---|
6 | import oseam.seamarks.*;
|
---|
7 |
|
---|
8 | public class PanelSectors extends JFrame {
|
---|
9 |
|
---|
10 | public JPanel panel;
|
---|
11 | public JButton minusButton;
|
---|
12 | public JButton plusButton;
|
---|
13 | public JTable table;
|
---|
14 | public Light light;
|
---|
15 | private JScrollPane tablePane;
|
---|
16 | private ActionListener alMinusButton;
|
---|
17 | private ActionListener alPlusButton;
|
---|
18 |
|
---|
19 | public PanelSectors(Light lit) {
|
---|
20 | super("Sector Table");
|
---|
21 | light = lit;
|
---|
22 | panel = new JPanel();
|
---|
23 | this.setSize(700, 100);
|
---|
24 | panel.setBounds(0, 0, 700, 512);
|
---|
25 | this.getContentPane().add(panel);
|
---|
26 | table = new JTable(light);
|
---|
27 | tablePane = new JScrollPane(table);
|
---|
28 | tablePane.setBounds(40, 0, 660, 34);
|
---|
29 | panel.setLayout(null);
|
---|
30 | panel.add(tablePane);
|
---|
31 |
|
---|
32 | alMinusButton = new ActionListener() {
|
---|
33 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
34 | deleteSector(2);
|
---|
35 | }
|
---|
36 | };
|
---|
37 | minusButton = new JButton(new ImageIcon(getClass().getResource("/images/MinusButton.png")));
|
---|
38 | minusButton.setBounds(0, 0, 32, 34);
|
---|
39 | minusButton.addActionListener(alMinusButton);
|
---|
40 | panel.add(minusButton);
|
---|
41 |
|
---|
42 | alPlusButton = new ActionListener() {
|
---|
43 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
44 | addSector(2);
|
---|
45 | }
|
---|
46 | };
|
---|
47 | plusButton = new JButton(new ImageIcon(getClass().getResource("/images/PlusButton.png")));
|
---|
48 | plusButton.setBounds(0, 34, 32, 34);
|
---|
49 | plusButton.addActionListener(alPlusButton);
|
---|
50 | panel.add(plusButton);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public int getSectorCount() {
|
---|
54 | return light.getRowCount();
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void addSector(int idx) {
|
---|
58 | light.addSector(idx);
|
---|
59 | tablePane.setSize(660, ((light.getRowCount() * 16) + 18));
|
---|
60 | if (light.getRowCount() > 3) {
|
---|
61 | this.setSize(700, ((light.getRowCount() * 16) + 40));
|
---|
62 | } else {
|
---|
63 | this.setSize(700, 100);
|
---|
64 | }
|
---|
65 | light.fireTableRowsInserted(idx, idx);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void deleteSector(int idx) {
|
---|
69 | light.deleteSector(idx);
|
---|
70 | tablePane.setSize(660, ((light.getRowCount() * 16) + 18));
|
---|
71 | if (light.getRowCount() > 3) {
|
---|
72 | this.setSize(700, ((light.getRowCount() * 16) + 40));
|
---|
73 | } else {
|
---|
74 | this.setSize(700, 100);
|
---|
75 | }
|
---|
76 | light.fireTableRowsDeleted(idx, idx);
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|