~tapaal-contributor/tapaal/autodetect-lens-check2

« back to all changes in this revision

Viewing changes to src/pipe/gui/widgets/ConstantsPane.java

merged in lp:~yrke/tapaal/evenMore-gui-cleanup doing GUI cleanup and fixing memory access check, about menu in Mac, exception in verification and reenabled quick draw

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 
20
20
import javax.swing.BorderFactory;
21
 
import javax.swing.ImageIcon;
22
21
import javax.swing.JButton;
23
22
import javax.swing.JList;
24
23
import javax.swing.JOptionPane;
51
50
        private JScrollPane constantsScroller;
52
51
        private final JPanel buttonsPanel;
53
52
 
54
 
        private final JList constantsList;
 
53
        private final JList<Constant> constantsList;
55
54
        private final ConstantsListModel listModel;
56
55
        private JButton editBtn;
57
56
        private JButton removeBtn;
95
94
                        
96
95
                });
97
96
 
98
 
                constantsList = new NonsearchableJList(listModel);
 
97
                constantsList = new NonsearchableJList<>(listModel);
99
98
                constantsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
100
99
                constantsList.addListSelectionListener(new ListSelectionListener() {
101
100
                        public void valueChanged(ListSelectionEvent e) {
141
140
                                        highlightConstant(index);
142
141
                                        
143
142
                                        if (arg0.getButton() == MouseEvent.BUTTON1 && arg0.getClickCount() == 2) {
144
 
                                                showEditConstantDialog(c,index);                                                
 
143
                                                showEditConstantDialog(c);
145
144
                                        }
146
145
                                }
147
146
                        }
295
294
                editBtn.setToolTipText(toolTipEditConstant);
296
295
                editBtn.addActionListener(e -> {
297
296
                        Constant c = (Constant) constantsList.getSelectedValue();
298
 
                        showEditConstantDialog(c,constantsList.getSelectedIndex());
 
297
                        showEditConstantDialog(c);
299
298
                });
300
299
                GridBagConstraints gbc = new GridBagConstraints();
301
300
                gbc.gridx = 0;
407
406
                constantsPanel.add(sortButton,gbc);
408
407
        }
409
408
 
410
 
        private void showEditConstantDialog(Constant constant) {        
411
 
                ConstantsDialogPanel panel = null;
412
 
                if (constant != null)
413
 
                        try {
414
 
                                panel = new ConstantsDialogPanel(new JRootPane(),
415
 
                                                parent.network(), constant);
416
 
                        } catch (IOException e) {
417
 
                                // TODO Auto-generated catch block
418
 
                                e.printStackTrace();
419
 
                        }
420
 
                else
421
 
                        try {
422
 
                                panel = new ConstantsDialogPanel(new JRootPane(),
423
 
                                                parent.network());
424
 
                        } catch (IOException e) {
425
 
                                // TODO Auto-generated catch block
426
 
                                e.printStackTrace();
427
 
                        }
428
 
                panel.showDialog();
429
 
                showConstants();
430
 
        }
 
409
        private void showEditConstantDialog(Constant constant) {
 
410
                ConstantsDialogPanel panel = new ConstantsDialogPanel(parent.network(), constant);
431
411
 
432
 
        private void showEditConstantDialog(Constant constant, int selectedIndex) {     
433
 
                ConstantsDialogPanel panel = null;
434
 
                if (constant != null)
435
 
                        try {
436
 
                                panel = new ConstantsDialogPanel(new JRootPane(),
437
 
                                                parent.network(), constant);
438
 
                        } catch (IOException e) {
439
 
                                e.printStackTrace();
440
 
                        }
441
 
                else
442
 
                        try {
443
 
                                panel = new ConstantsDialogPanel(new JRootPane(),
444
 
                                                parent.network());
445
 
                        } catch (IOException e) {
446
 
                                e.printStackTrace();
447
 
                        }
448
412
                panel.showDialog();
449
413
                showConstants();
450
414
        }
457
421
                                        "You cannot remove a constant that is used in the net.\nRemove all references "
458
422
                                                        + "to the constant in the net and try again.",
459
423
                                                        "Constant in use", JOptionPane.ERROR_MESSAGE);
460
 
                } else
461
 
                        parent.getUndoManager().addNewEdit(edit);
 
424
                } else {
 
425
            parent.getUndoManager().addNewEdit(edit);
 
426
        }
462
427
 
463
428
                //showConstants();
464
429
        }
485
450
    }
486
451
 
487
452
    @Override
488
 
    public JList getJList() {
 
453
    public JList<Constant> getJList() {
489
454
        return constantsList;
490
455
    }
491
456
}