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