| 1 | package panels;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.*;
|
|---|
| 4 | import java.awt.event.*;
|
|---|
| 5 | import java.util.EnumMap;
|
|---|
| 6 |
|
|---|
| 7 | import javax.swing.*;
|
|---|
| 8 | import javax.swing.table.*;
|
|---|
| 9 |
|
|---|
| 10 | import oseam.Messages;
|
|---|
| 11 | import oseam.OSeaMAction;
|
|---|
| 12 | import seamarks.SeaMark;
|
|---|
| 13 | import seamarks.SeaMark.*;
|
|---|
| 14 |
|
|---|
| 15 | public class PanelSectors extends JFrame {
|
|---|
| 16 |
|
|---|
| 17 | private OSeaMAction dlg;
|
|---|
| 18 | private JPanel panel;
|
|---|
| 19 | private TableModel model;
|
|---|
| 20 | private JTable table;
|
|---|
| 21 |
|
|---|
| 22 | public JButton minusButton;
|
|---|
| 23 | private ActionListener alMinusButton = new ActionListener() {
|
|---|
| 24 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 25 | if ((getSectorCount() > 1) && (table.getSelectedRow() != 0))
|
|---|
| 26 | deleteSector(table.getSelectedRow());
|
|---|
| 27 | }
|
|---|
| 28 | };
|
|---|
| 29 | public JButton plusButton;
|
|---|
| 30 | private ActionListener alPlusButton = new ActionListener() {
|
|---|
| 31 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
|---|
| 32 | if (table.getSelectedRow() < 0)
|
|---|
| 33 | addSector(table.getRowCount());
|
|---|
| 34 | else
|
|---|
| 35 | addSector(table.getSelectedRow()+1);
|
|---|
| 36 | }
|
|---|
| 37 | };
|
|---|
| 38 | public JComboBox colourBox;
|
|---|
| 39 | public EnumMap<Col, ImageIcon> colours = new EnumMap<Col, ImageIcon>(Col.class);
|
|---|
| 40 | public JComboBox visibilityBox;
|
|---|
| 41 | public EnumMap<Vis, String> visibilities = new EnumMap<Vis, String>(Vis.class);
|
|---|
| 42 | public JComboBox exhibitionBox;
|
|---|
| 43 | public EnumMap<Exh, String> exhibitions = new EnumMap<Exh, String>(Exh.class);
|
|---|
| 44 |
|
|---|
| 45 | public PanelSectors(OSeaMAction dia) {
|
|---|
| 46 | super(Messages.getString("SectorTable"));
|
|---|
| 47 | dlg = dia;
|
|---|
| 48 | setLayout(null);
|
|---|
| 49 | setSize(900, 100);
|
|---|
| 50 | setAlwaysOnTop(true);
|
|---|
| 51 | setLocation(450, 0);
|
|---|
| 52 | setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
|---|
| 53 | minusButton = new JButton(new ImageIcon(getClass().getResource("/images/MinusButton.png")));
|
|---|
| 54 | minusButton.setBounds(0, 0, 32, 34);
|
|---|
| 55 | minusButton.addActionListener(alMinusButton);
|
|---|
| 56 | add(minusButton);
|
|---|
| 57 | plusButton = new JButton(new ImageIcon(getClass().getResource("/images/PlusButton.png")));
|
|---|
| 58 | plusButton.setBounds(0, 34, 32, 34);
|
|---|
| 59 | plusButton.addActionListener(alPlusButton);
|
|---|
| 60 | add(plusButton);
|
|---|
| 61 | panel = new JPanel(new BorderLayout());
|
|---|
| 62 | panel.setBounds(40, 0, 860, 512);
|
|---|
| 63 | model = new SectorTable();
|
|---|
| 64 | table = new JTable(model);
|
|---|
| 65 | table.setBounds(0, 0, 860, 34);
|
|---|
| 66 | table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
|---|
| 67 | panel.add(new JScrollPane(table));
|
|---|
| 68 | getContentPane().add(panel);
|
|---|
| 69 |
|
|---|
| 70 | table.setSize(860, ((table.getRowCount() * 16) + 28));
|
|---|
| 71 |
|
|---|
| 72 | table.setDefaultRenderer(String.class, new CentreRenderer());
|
|---|
| 73 | table.getColumnModel().getColumn(1).setCellRenderer(new ColourCellRenderer());
|
|---|
| 74 |
|
|---|
| 75 | TableColumn colColumn = table.getColumnModel().getColumn(1);
|
|---|
| 76 | colourBox = new JComboBox();
|
|---|
| 77 | addColItem(new ImageIcon(getClass().getResource("/images/DelButton.png")), Col.UNKCOL);
|
|---|
| 78 | addColItem(new ImageIcon(getClass().getResource("/images/WhiteButton.png")), Col.WHITE);
|
|---|
| 79 | addColItem(new ImageIcon(getClass().getResource("/images/RedButton.png")), Col.RED);
|
|---|
| 80 | addColItem(new ImageIcon(getClass().getResource("/images/GreenButton.png")), Col.GREEN);
|
|---|
| 81 | addColItem(new ImageIcon(getClass().getResource("/images/YellowButton.png")), Col.YELLOW);
|
|---|
| 82 | addColItem(new ImageIcon(getClass().getResource("/images/OrangeButton.png")), Col.ORANGE);
|
|---|
| 83 | addColItem(new ImageIcon(getClass().getResource("/images/AmberButton.png")), Col.AMBER);
|
|---|
| 84 | addColItem(new ImageIcon(getClass().getResource("/images/BlueButton.png")), Col.BLUE);
|
|---|
| 85 | addColItem(new ImageIcon(getClass().getResource("/images/VioletButton.png")), Col.VIOLET);
|
|---|
| 86 | colColumn.setCellEditor(new DefaultCellEditor(colourBox));
|
|---|
| 87 |
|
|---|
| 88 | TableColumn visColumn = table.getColumnModel().getColumn(12);
|
|---|
| 89 | visibilityBox = new JComboBox();
|
|---|
| 90 | addVisibItem("", Vis.UNKVIS);
|
|---|
| 91 | addVisibItem(Messages.getString("Intensified"), Vis.INTEN);
|
|---|
| 92 | addVisibItem(Messages.getString("Unintensified"), Vis.UNINTEN);
|
|---|
| 93 | addVisibItem(Messages.getString("PartiallyObscured"), Vis.PARTOBS);
|
|---|
| 94 | visColumn.setCellEditor(new DefaultCellEditor(visibilityBox));
|
|---|
| 95 |
|
|---|
| 96 | TableColumn exhColumn = table.getColumnModel().getColumn(13);
|
|---|
| 97 | exhibitionBox = new JComboBox();
|
|---|
| 98 | addExhibItem("", Exh.UNKEXH);
|
|---|
| 99 | addExhibItem(Messages.getString("24h"), Exh.H24);
|
|---|
| 100 | addExhibItem(Messages.getString("Day"), Exh.DAY);
|
|---|
| 101 | addExhibItem(Messages.getString("Night"), Exh.NIGHT);
|
|---|
| 102 | addExhibItem(Messages.getString("Fog"), Exh.FOG);
|
|---|
| 103 | exhColumn.setCellEditor(new DefaultCellEditor(exhibitionBox));
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | private class SectorTable extends AbstractTableModel {
|
|---|
| 107 |
|
|---|
| 108 | private String[] headings = { Messages.getString("Sector"), Messages.getString("Colour"), Messages.getString("Character"),
|
|---|
| 109 | Messages.getString("Group"), Messages.getString("Sequence"), Messages.getString("Period"), Messages.getString("Directional"),
|
|---|
| 110 | Messages.getString("Start"), Messages.getString("End"), Messages.getString("Radius"), Messages.getString("Height"),
|
|---|
| 111 | Messages.getString("Range"), Messages.getString("Visibility"), Messages.getString("Exhibition") };
|
|---|
| 112 |
|
|---|
| 113 | public SectorTable() {
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | public String getColumnName(int col) {
|
|---|
| 117 | return headings[col];
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | public int getColumnCount() {
|
|---|
| 121 | return headings.length;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | public int getRowCount() {
|
|---|
| 125 | if (dlg.panelMain == null)
|
|---|
| 126 | return 1;
|
|---|
| 127 | else
|
|---|
| 128 | return dlg.panelMain.mark.getSectorCount();
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | public boolean isCellEditable(int row, int col) {
|
|---|
| 132 | return ((col > 0) && (row > 0));
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | public Class getColumnClass(int col) {
|
|---|
| 136 | switch (col) {
|
|---|
| 137 | case 1:
|
|---|
| 138 | return Col.class;
|
|---|
| 139 | case 6:
|
|---|
| 140 | return Boolean.class;
|
|---|
| 141 | default:
|
|---|
| 142 | return String.class;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | public Object getValueAt(int row, int col) {
|
|---|
| 147 | switch (col) {
|
|---|
| 148 | case 0:
|
|---|
| 149 | if (row == 0)
|
|---|
| 150 | return Messages.getString("Default");
|
|---|
| 151 | else
|
|---|
| 152 | return row;
|
|---|
| 153 | case 1:
|
|---|
| 154 | if (((String)dlg.panelMain.mark.getLightAtt(Att.CHR, row)).contains("Al")) {
|
|---|
| 155 | if (dlg.panelMain.mark.getLightAtt(Att.COL, row) == Col.UNKCOL) {
|
|---|
| 156 | return Col.UNKCOL;
|
|---|
| 157 | } else {
|
|---|
| 158 | return dlg.panelMain.mark.getLightAtt(Att.ALT, row);
|
|---|
| 159 | }
|
|---|
| 160 | } else {
|
|---|
| 161 | return dlg.panelMain.mark.getLightAtt(Att.COL, row);
|
|---|
| 162 | }
|
|---|
| 163 | case 6:
|
|---|
| 164 | return (dlg.panelMain.mark.getLightAtt(Att.LIT, row) == Lit.DIR);
|
|---|
| 165 | case 7:
|
|---|
| 166 | case 8:
|
|---|
| 167 | if (dlg.panelMain.mark.getLightAtt(Att.LIT, row) == Lit.DIR)
|
|---|
| 168 | return dlg.panelMain.mark.getLightAtt(Att.ORT, row);
|
|---|
| 169 | else
|
|---|
| 170 | return dlg.panelMain.mark.getLightAtt(col - 1, row);
|
|---|
| 171 | case 12:
|
|---|
| 172 | return visibilities.get(dlg.panelMain.mark.getLightAtt(Att.VIS, row));
|
|---|
| 173 | case 13:
|
|---|
| 174 | return exhibitions.get(dlg.panelMain.mark.getLightAtt(Att.EXH, row));
|
|---|
| 175 | default:
|
|---|
| 176 | return dlg.panelMain.mark.getLightAtt(col - 1, row);
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | public void setValueAt(Object value, int row, int col) {
|
|---|
| 181 | switch (col) {
|
|---|
| 182 | case 1:
|
|---|
| 183 | for (Col colour : colours.keySet()) {
|
|---|
| 184 | ImageIcon img = colours.get(colour);
|
|---|
| 185 | if (img == value)
|
|---|
| 186 | if (((String)dlg.panelMain.mark.getLightAtt(Att.CHR, row)).contains("Al")) {
|
|---|
| 187 | if (((colour == Col.UNKCOL) && (dlg.panelMain.mark.getLightAtt(Att.ALT, row) == Col.UNKCOL))
|
|---|
| 188 | || (dlg.panelMain.mark.getLightAtt(Att.COL, row) == Col.UNKCOL)) {
|
|---|
| 189 | dlg.panelMain.mark.setLightAtt(Att.COL, row, colour);
|
|---|
| 190 | } else {
|
|---|
| 191 | dlg.panelMain.mark.setLightAtt(Att.ALT, row, colour);
|
|---|
| 192 | }
|
|---|
| 193 | } else {
|
|---|
| 194 | dlg.panelMain.mark.setLightAtt(Att.COL, row, colour);
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | break;
|
|---|
| 198 | case 5:
|
|---|
| 199 | case 9:
|
|---|
| 200 | case 10:
|
|---|
| 201 | case 11:
|
|---|
| 202 | dlg.panelMain.mark.setLightAtt(col - 1, row, value);
|
|---|
| 203 | break;
|
|---|
| 204 | case 6:
|
|---|
| 205 | if ((Boolean) value == true) {
|
|---|
| 206 | dlg.panelMain.mark.setLightAtt(Att.LIT, row, Lit.DIR);
|
|---|
| 207 | dlg.panelMain.mark.setLightAtt(Att.BEG, row, "");
|
|---|
| 208 | dlg.panelMain.mark.setLightAtt(Att.END, row, "");
|
|---|
| 209 | } else {
|
|---|
| 210 | dlg.panelMain.mark.setLightAtt(Att.LIT, row, Lit.UNKLIT);
|
|---|
| 211 | dlg.panelMain.mark.setLightAtt(Att.ORT, row, "");
|
|---|
| 212 | }
|
|---|
| 213 | break;
|
|---|
| 214 | case 7:
|
|---|
| 215 | case 8:
|
|---|
| 216 | if (dlg.panelMain.mark.getLightAtt(Att.LIT, row) == Lit.DIR) {
|
|---|
| 217 | dlg.panelMain.mark.setLightAtt(Att.ORT, row, value);
|
|---|
| 218 | } else {
|
|---|
| 219 | dlg.panelMain.mark.setLightAtt(col - 1, row, value);
|
|---|
| 220 | }
|
|---|
| 221 | break;
|
|---|
| 222 | case 12:
|
|---|
| 223 | for (Vis vis : visibilities.keySet()) {
|
|---|
| 224 | String str = visibilities.get(vis);
|
|---|
| 225 | if (str.equals(value))
|
|---|
| 226 | dlg.panelMain.mark.setLightAtt(Att.VIS, row, vis);
|
|---|
| 227 | }
|
|---|
| 228 | break;
|
|---|
| 229 | case 13:
|
|---|
| 230 | for (Exh exh : exhibitions.keySet()) {
|
|---|
| 231 | String str = exhibitions.get(exh);
|
|---|
| 232 | if (str.equals(value))
|
|---|
| 233 | dlg.panelMain.mark.setLightAtt(Att.EXH, row, exh);
|
|---|
| 234 | }
|
|---|
| 235 | break;
|
|---|
| 236 | default:
|
|---|
| 237 | dlg.panelMain.mark.setLightAtt(col - 1, row, value);
|
|---|
| 238 | }
|
|---|
| 239 | }
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | static class CentreRenderer extends DefaultTableCellRenderer {
|
|---|
| 243 | public CentreRenderer() {
|
|---|
| 244 | super();
|
|---|
| 245 | setHorizontalAlignment(SwingConstants.CENTER);
|
|---|
| 246 | }
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | public class ColourCellRenderer extends JPanel implements TableCellRenderer {
|
|---|
| 250 | private JLabel col1Label;
|
|---|
| 251 | private JLabel col2Label;
|
|---|
| 252 | public ColourCellRenderer() {
|
|---|
| 253 | super();
|
|---|
| 254 | setLayout(new GridLayout(1, 2, 0, 0));
|
|---|
| 255 | col1Label = new JLabel();
|
|---|
| 256 | col1Label.setOpaque(true);
|
|---|
| 257 | add(col1Label);
|
|---|
| 258 | col2Label = new JLabel();
|
|---|
| 259 | col2Label.setOpaque(true);
|
|---|
| 260 | add(col2Label);
|
|---|
| 261 | }
|
|---|
| 262 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
|
|---|
| 263 | if (!((String)dlg.panelMain.mark.getLightAtt(Att.CHR, rowIndex)).contains("Al")) {
|
|---|
| 264 | col2Label.setBackground(SeaMark.ColMAP.get(dlg.panelMain.mark.getLightAtt(Att.COL, rowIndex)));
|
|---|
| 265 | } else {
|
|---|
| 266 | col2Label.setBackground(SeaMark.ColMAP.get(dlg.panelMain.mark.getLightAtt(Att.ALT, rowIndex)));
|
|---|
| 267 | }
|
|---|
| 268 | col1Label.setBackground(SeaMark.ColMAP.get(dlg.panelMain.mark.getLightAtt(Att.COL, rowIndex)));
|
|---|
| 269 | return this;
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | public int getSectorCount() {
|
|---|
| 274 | return model.getRowCount();
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | public void addSector(int idx) {
|
|---|
| 278 | dlg.panelMain.mark.addLight(idx);
|
|---|
| 279 | table.setSize(860, ((table.getRowCount() * 16) + 28));
|
|---|
| 280 | if (table.getRowCount() > 3) {
|
|---|
| 281 | setSize(900, ((table.getRowCount() * 16) + 48));
|
|---|
| 282 | } else {
|
|---|
| 283 | setSize(900, 100);
|
|---|
| 284 | }
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | public void deleteSector(int idx) {
|
|---|
| 288 | if (idx > 0) {
|
|---|
| 289 | dlg.panelMain.mark.delLight(idx);
|
|---|
| 290 | table.setSize(860, ((table.getRowCount() * 16) + 28));
|
|---|
| 291 | if (table.getRowCount() > 3) {
|
|---|
| 292 | setSize(900, ((table.getRowCount() * 16) + 48));
|
|---|
| 293 | } else {
|
|---|
| 294 | setSize(900, 100);
|
|---|
| 295 | }
|
|---|
| 296 | }
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | public void syncPanel() {
|
|---|
| 300 | table.updateUI();
|
|---|
| 301 | table.setSize(860, ((table.getRowCount() * 16) + 28));
|
|---|
| 302 | if (table.getRowCount() > 3) {
|
|---|
| 303 | setSize(900, ((table.getRowCount() * 16) + 48));
|
|---|
| 304 | } else {
|
|---|
| 305 | setSize(900, 100);
|
|---|
| 306 | }
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | private void addColItem(ImageIcon img, Col col) {
|
|---|
| 310 | colours.put(col, img);
|
|---|
| 311 | colourBox.addItem(img);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | private void addVisibItem(String str, Vis vis) {
|
|---|
| 315 | visibilities.put(vis, str);
|
|---|
| 316 | visibilityBox.addItem(str);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | private void addExhibItem(String str, Exh exh) {
|
|---|
| 320 | exhibitions.put(exh, str);
|
|---|
| 321 | exhibitionBox.addItem(str);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | }
|
|---|