/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSMidiInstrumentTree.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/std/JSMidiInstrumentTree.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1766 by iliev, Mon Jun 2 03:33:11 2008 UTC revision 1767 by iliev, Mon Sep 8 00:19:27 2008 UTC
# Line 22  Line 22 
22    
23  package org.jsampler.view.std;  package org.jsampler.view.std;
24    
25    import java.awt.Dimension;
26    
27    import java.beans.PropertyChangeEvent;
28    import java.beans.PropertyChangeListener;
29    
30  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
31  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
32  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
33  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
34  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
35    
36    import java.util.Vector;
37    
38  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
39  import javax.swing.Action;  import javax.swing.Action;
40    import javax.swing.Box;
41    import javax.swing.BoxLayout;
42  import javax.swing.JComponent;  import javax.swing.JComponent;
43    import javax.swing.JLabel;
44    import javax.swing.JMenu;
45  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
46    import javax.swing.JPanel;
47  import javax.swing.JPopupMenu;  import javax.swing.JPopupMenu;
48    import javax.swing.JScrollPane;
49    import javax.swing.JTable;
50  import javax.swing.JTree;  import javax.swing.JTree;
51  import javax.swing.KeyStroke;  import javax.swing.KeyStroke;
52    
# Line 56  import org.jsampler.event.MidiInstrument Line 70  import org.jsampler.event.MidiInstrument
70  import org.linuxsampler.lscp.MidiInstrumentInfo;  import org.linuxsampler.lscp.MidiInstrumentInfo;
71  import org.linuxsampler.lscp.MidiInstrumentMapInfo;  import org.linuxsampler.lscp.MidiInstrumentMapInfo;
72    
73    import net.sf.juife.OkCancelDialog;
74    
75    import static org.jsampler.JSPrefs.FIRST_MIDI_BANK_NUMBER;
76    import static org.jsampler.JSPrefs.FIRST_MIDI_PROGRAM_NUMBER;
77  import static org.jsampler.view.std.StdI18n.i18n;  import static org.jsampler.view.std.StdI18n.i18n;
78    
79    
# Line 66  import static org.jsampler.view.std.StdI Line 84  import static org.jsampler.view.std.StdI
84  public class JSMidiInstrumentTree extends JTree {  public class JSMidiInstrumentTree extends JTree {
85          private DefaultTreeModel model;          private DefaultTreeModel model;
86          private MidiInstrumentMap midiInstrumentMap;          private MidiInstrumentMap midiInstrumentMap;
87            private final ContextMenu contextMenu;
88                    
89          /**          /**
90           * Creates a new instance of <code>JSMidiInstrumentTree</code>           * Creates a new instance of <code>JSMidiInstrumentTree</code>
# Line 93  public class JSMidiInstrumentTree extend Line 112  public class JSMidiInstrumentTree extend
112                  setMidiInstrumentMap(null);                  setMidiInstrumentMap(null);
113                                    
114                  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);                  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
115                  ContextMenu contextMenu = new ContextMenu();                  contextMenu = new ContextMenu();
116                  addMouseListener(contextMenu);                  addMouseListener(contextMenu);
117                  addTreeSelectionListener(contextMenu);                  
118                    addTreeSelectionListener(getHandler());
119                                    
120                  Action a = new AbstractAction() {                  Action a = new AbstractAction() {
121                          public void                          public void
# Line 107  public class JSMidiInstrumentTree extend Line 127  public class JSMidiInstrumentTree extend
127                  KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);                  KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
128                  getInputMap(JComponent.WHEN_FOCUSED).put(k, "removeSelectedInstrumentOrBank");                  getInputMap(JComponent.WHEN_FOCUSED).put(k, "removeSelectedInstrumentOrBank");
129                  getActionMap().put("removeSelectedInstrumentOrBank", a);                  getActionMap().put("removeSelectedInstrumentOrBank", a);
130                    
131                    String s = FIRST_MIDI_BANK_NUMBER;
132                    CC.preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
133                            public void
134                            propertyChange(PropertyChangeEvent e) {
135                                    model.reload();
136                            }
137                    });
138                    
139                    s = FIRST_MIDI_PROGRAM_NUMBER;
140                    CC.preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
141                            public void
142                            propertyChange(PropertyChangeEvent e) {
143                                    model.reload();
144                                    contextMenu.updateChangeProgramMenu();
145                            }
146                    });
147          }          }
148                    
149          /**          /**
# Line 171  public class JSMidiInstrumentTree extend Line 208  public class JSMidiInstrumentTree extend
208                          model.insertNodeInto (                          model.insertNodeInto (
209                                  bankNode,                                  bankNode,
210                                  (DefaultMutableTreeNode)model.getRoot(),                                  (DefaultMutableTreeNode)model.getRoot(),
211                                  findBankPosition(bank.getID())                                  findBankPosition(bank.getId())
212                          );                          );
213                  }                  }
214                                    
# Line 193  public class JSMidiInstrumentTree extend Line 230  public class JSMidiInstrumentTree extend
230                  DefaultMutableTreeNode bankNode = findBank(bank);                  DefaultMutableTreeNode bankNode = findBank(bank);
231                                    
232                  if(bankNode == null)                  if(bankNode == null)
233                          throw new IllegalArgumentException("Missing MIDI bank: " + bank.getID());                          throw new IllegalArgumentException("Missing MIDI bank: " + bank.getId());
234                                    
235                  removeProgram(bankNode, instr.getInfo().getMidiProgram());                  removeProgram(bankNode, instr.getInfo().getMidiProgram());
236                  if(bankNode.getChildCount() == 0) model.removeNodeFromParent(bankNode);                  if(bankNode.getChildCount() == 0) model.removeNodeFromParent(bankNode);
# Line 214  public class JSMidiInstrumentTree extend Line 251  public class JSMidiInstrumentTree extend
251          }          }
252                    
253          /**          /**
254             * Gets the selected MIDI bank.
255             * @return The selected MIDI bank, or
256             * <code>null</code> if there is no MIDI bank selected.
257             */
258            public MidiBank
259            getSelectedMidiBank() {
260                    if(getSelectionCount() == 0) return null;
261                    
262                    Object obj = getSelectionPath().getLastPathComponent();
263                    if(!(obj instanceof BankTreeNode)) return null;
264                    
265                    BankTreeNode n = (BankTreeNode)obj;
266                    return (MidiBank)n.getUserObject();
267            }
268            
269            /**
270           * Removes (on the backend side) the selected MIDI instrument or MIDI bank.           * Removes (on the backend side) the selected MIDI instrument or MIDI bank.
271           */           */
272          public void          public void
# Line 261  public class JSMidiInstrumentTree extend Line 314  public class JSMidiInstrumentTree extend
314                  for(int i = 0; i < root.getChildCount(); i++) {                  for(int i = 0; i < root.getChildCount(); i++) {
315                          DefaultMutableTreeNode node = (DefaultMutableTreeNode)root.getChildAt(i);                          DefaultMutableTreeNode node = (DefaultMutableTreeNode)root.getChildAt(i);
316                          MidiBank bank = (MidiBank)node.getUserObject();                          MidiBank bank = (MidiBank)node.getUserObject();
317                          if(bank.getID() > bankID) return i;                          if(bank.getId() > bankID) return i;
318                  }                  }
319                                    
320                  return root.getChildCount();                  return root.getChildCount();
# Line 316  public class JSMidiInstrumentTree extend Line 369  public class JSMidiInstrumentTree extend
369                    
370                    
371          private class MidiBank {          private class MidiBank {
372                  int id;                  private int id;
373                                    
374                  MidiBank(int id) {                  MidiBank(int id) {
375                          this.id = id;                          this.id = id;
376                  }                  }
377                                    
378                  public int                  public int
379                  getID() { return id; }                  getId() { return id; }
380                                    
381                  public boolean                  public boolean
382                  equals(Object obj) {                  equals(Object obj) {
383                          if(obj == null) return false;                          if(obj == null) return false;
384                          if(!(obj instanceof MidiBank)) return false;                          if(!(obj instanceof MidiBank)) return false;
385                          if(getID() == ((MidiBank)obj).getID()) return true;                          if(getId() == ((MidiBank)obj).getId()) return true;
386                          return false;                          return false;
387                  }                  }
388                                    
389                  public String                  public String
390                  toString() { return i18n.getLabel("JSMidiInstrumentTree.MidiBank.name", id); }                  toString() {
391                            int i = CC.getViewConfig().getFirstMidiBankNumber();
392                            return i18n.getLabel("JSMidiInstrumentTree.MidiBank.name", i + id);
393                    }
394          }          }
395                    
396          protected class BankTreeNode extends DefaultMutableTreeNode {          protected class BankTreeNode extends DefaultMutableTreeNode {
# Line 392  public class JSMidiInstrumentTree extend Line 448  public class JSMidiInstrumentTree extend
448                  );                  );
449          }          }
450                    
451            private void
452            copyMidiBankTo() { copyOrMoveMidiBankTo(true); }
453            
454            private void
455            moveMidiBankTo() { copyOrMoveMidiBankTo(false); }
456            
457            private void
458            copyOrMoveMidiBankTo(boolean copy) {
459                    MidiBank bank = getSelectedMidiBank();
460                    if(bank == null) return;
461                    
462                    JSMidiBankChooser dlg = new JSMidiBankChooser();
463                    
464                    if(copy) dlg.setTitle(i18n.getLabel("JSMidiInstrumentTree.copyTo"));
465                    else dlg.setTitle(i18n.getLabel("JSMidiInstrumentTree.moveTo"));
466                    
467                    dlg.setSelectedMidiInstrumentMap(getMidiInstrumentMap());
468                    dlg.setVisible(true);
469                    if(dlg.isCancelled()) return;
470                    
471                    MidiInstrumentMap smap = dlg.getSelectedMidiInstrumentMap();
472                    
473                    if(smap == null) {
474                            HF.showErrorMessage(i18n.getMessage("JSMidiInstrumentTree.noMap!"), this);
475                            return;
476                    }
477                    
478                    if(dlg.getMidiBank() == bank.getId() && smap.getMapId() == getMidiInstrumentMap().getMapId()) {
479                            String s = "JSMidiInstrumentTree.sameSourceAndDestination!";
480                            HF.showErrorMessage(i18n.getMessage(s), this);
481                            return;
482                    }
483                    
484                    MidiInstrument[] instrs = getMidiInstrumentMap().getMidiInstruments(bank.getId());
485                    int mapId = smap.getMapId();
486                    int bnkId = dlg.getMidiBank();
487                    
488                    Vector<MidiInstrument> v = new Vector<MidiInstrument>();
489                    for(MidiInstrument i : instrs) {
490                            MidiInstrument instr;
491                            instr = smap.getMidiInstrument(bnkId, i.getInfo().getMidiProgram());
492                            if(instr != null) v.add(instr);
493                    }
494                    
495                    if(!v.isEmpty()) {
496                            String[] instrumentNames = new String[v.size()];
497                            for(int i = 0; i < v.size(); i++) {
498                                    int base = CC.getViewConfig().getFirstMidiProgramNumber();
499                                    int p = v.get(i).getInfo().getMidiProgram();
500                                    instrumentNames[i] = (base + p) + ". " + v.get(i).getName();
501                            }
502                            JSOverrideInstrumentsConfirmDlg dlg2;
503                            dlg2 = new JSOverrideInstrumentsConfirmDlg(instrumentNames);
504                            dlg2.setVisible(true);
505                            if(dlg2.isCancelled()) return;
506                    }
507                    
508                    for(MidiInstrument i : instrs) {
509                            int p = i.getInfo().getMidiProgram();
510                            CC.getSamplerModel().mapBackendMidiInstrument(mapId, bnkId, p, i.getInfo());
511                    }
512                    
513                    if(copy) return;
514                    
515                    mapId = getMidiInstrumentMap().getMapId();
516                    bnkId = bank.getId();
517                    
518                    for(MidiInstrument i : instrs) {
519                            int p = i.getInfo().getMidiProgram();
520                            CC.getSamplerModel().unmapBackendMidiInstrument(mapId, bnkId, p);
521                    }
522            }
523            
524            private void
525            copyMidiInstrumentTo() { copyOrMoveMidiInstrumentTo(true); }
526            
527            private void
528            moveMidiInstrumentTo() { copyOrMoveMidiInstrumentTo(false); }
529            
530            private void
531            copyOrMoveMidiInstrumentTo(boolean copy) {
532                    MidiInstrument instr = getSelectedInstrument();
533                    if(instr == null) return;
534                    
535                    JSMidiBankChooser dlg = new JSMidiBankChooser();
536                    
537                    if(copy) dlg.setTitle(i18n.getLabel("JSMidiInstrumentTree.copyTo"));
538                    else dlg.setTitle(i18n.getLabel("JSMidiInstrumentTree.moveTo"));
539                    
540                    dlg.setSelectedMidiInstrumentMap(getMidiInstrumentMap());
541                    dlg.setVisible(true);
542                    if(dlg.isCancelled()) return;
543                    
544                    MidiInstrumentMap smap = dlg.getSelectedMidiInstrumentMap();
545                    
546                    if(smap == null) {
547                            HF.showErrorMessage(i18n.getMessage("JSMidiInstrumentTree.noMap!"), this);
548                            return;
549                    }
550                    
551                    int bank = instr.getInfo().getMidiBank();
552                    if(dlg.getMidiBank() == bank && smap.getMapId() == getMidiInstrumentMap().getMapId()) {
553                            String s = "JSMidiInstrumentTree.sameSourceAndDestination!";
554                            HF.showErrorMessage(i18n.getMessage(s), this);
555                            return;
556                    }
557                    
558                    int mapId = smap.getMapId();
559                    int bnkId = dlg.getMidiBank();
560                    int prgId = instr.getInfo().getMidiProgram();
561                    MidiInstrument oldInstr = smap.getMidiInstrument(bnkId, prgId);
562                    
563                    if(oldInstr != null) {
564                            String[] iS = new String [1];
565                            int base = CC.getViewConfig().getFirstMidiProgramNumber();
566                            iS[0] = (base + prgId) + ". " + oldInstr.getName();
567                            JSOverrideInstrumentsConfirmDlg dlg2;
568                            dlg2 = new JSOverrideInstrumentsConfirmDlg(iS);
569                            dlg2.setVisible(true);
570                            if(dlg2.isCancelled()) return;
571                    }
572                    
573                    CC.getSamplerModel().mapBackendMidiInstrument(mapId, bnkId, prgId, instr.getInfo());
574                    
575                    if(copy) return;
576                    
577                    mapId = getMidiInstrumentMap().getMapId();
578                    
579                    CC.getSamplerModel().unmapBackendMidiInstrument(mapId, bank, prgId);
580            }
581            
582            private void
583            moveSelectedInstrumentUp() {
584                    MidiInstrument instr = getSelectedInstrument();
585                    if(instr == null) return;
586                    moveSelectedInstrument(instr.getInfo().getMidiProgram() - 1);
587            }
588            
589            private void
590            moveSelectedInstrumentDown() {
591                    MidiInstrument instr = getSelectedInstrument();
592                    if(instr == null) return;
593                    moveSelectedInstrument(instr.getInfo().getMidiProgram() + 1);
594            }
595            
596            private void
597            moveSelectedInstrument(int newProgram) {
598                    if(newProgram < 0 || newProgram > 127) return;
599                    MidiInstrument instr = getSelectedInstrument();
600                    if(instr == null) return;
601                    
602                    int bnk = instr.getInfo().getMidiBank();
603                    int prg = instr.getInfo().getMidiProgram();
604                    
605                    MidiInstrument oldInstr = getMidiInstrumentMap().getMidiInstrument(bnk, newProgram);
606                    if(oldInstr != null) {
607                            String[] iS = new String [1];
608                            int base = CC.getViewConfig().getFirstMidiProgramNumber();
609                            iS[0] = (base + prg) + ". " + oldInstr.getName();
610                            JSOverrideInstrumentsConfirmDlg dlg;
611                            dlg = new JSOverrideInstrumentsConfirmDlg(iS);
612                            dlg.setVisible(true);
613                            if(dlg.isCancelled()) return;
614                    }
615                    
616                    int map = this.getMidiInstrumentMap().getMapId();
617                    CC.getSamplerModel().mapBackendMidiInstrument(map, bnk, newProgram, instr.getInfo());
618                    CC.getSamplerModel().unmapBackendMidiInstrument(map, bnk, prg);
619            }
620            
621          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
622                    
623          private EventHandler          private EventHandler
624          getHandler() { return eventHandler; }          getHandler() { return eventHandler; }
625                    
626          private class EventHandler implements MidiInstrumentListener, MidiInstrumentMapListener {          private class EventHandler implements MidiInstrumentListener, MidiInstrumentMapListener,
627                                                  TreeSelectionListener {
628                                    
629                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */                  /** Invoked when a MIDI instrument in a MIDI instrument map is changed. */
630                  public void                  public void
# Line 423  public class JSMidiInstrumentTree extend Line 650  public class JSMidiInstrumentTree extend
650                          unmapInstrument(e.getInstrument());                          unmapInstrument(e.getInstrument());
651                          e.getInstrument().removeMidiInstrumentListener(getHandler());                          e.getInstrument().removeMidiInstrumentListener(getHandler());
652                  }                  }
653                    
654                    public void
655                    valueChanged(TreeSelectionEvent e) {
656                            MidiInstrument instr = getSelectedInstrument();
657                            if(instr != null) {
658                                    int p = instr.getInfo().getMidiProgram();
659                                    contextMenu.miMoveInstrumentDown.setEnabled(p < 127);
660                                    contextMenu.miMoveInstrumentUp.setEnabled(p > 0);
661                            }
662                    }
663          }          }
664                    
665          class ContextMenu extends MouseAdapter implements TreeSelectionListener {          class ContextMenu extends MouseAdapter {
666                  private final JPopupMenu cmenu = new JPopupMenu();                  private final JPopupMenu bankMenu = new JPopupMenu();
667                  JMenuItem miEdit = new JMenuItem(i18n.getMenuLabel("ContextMenu.edit"));                  
668                    private final JPopupMenu instrumentMenu = new JPopupMenu();
669                    
670                    private final JMenu changeProgramMenu =
671                            new JMenu(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.changeProgram"));
672                    
673                    private final JMenuItem miMoveInstrumentUp =
674                            new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.moveUp"));
675                    
676                    private final JMenuItem miMoveInstrumentDown =
677                            new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.moveDown"));
678                    
679                    private final JMenu programGroup1Menu = new JMenu();
680                    private final JMenu programGroup2Menu = new JMenu();
681                    private final JMenu programGroup3Menu = new JMenu();
682                    private final JMenu programGroup4Menu = new JMenu();
683                    private final JMenu programGroup5Menu = new JMenu();
684                    private final JMenu programGroup6Menu = new JMenu();
685                    private final JMenu programGroup7Menu = new JMenu();
686                    private final JMenu programGroup8Menu = new JMenu();
687                    
688                                    
689                  ContextMenu() {                  ContextMenu() {
690                          cmenu.add(miEdit);                          JMenuItem mi = new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.moveTo"));
691                          miEdit.addActionListener(new ActionListener() {                          bankMenu.add(mi);
692                            mi.addActionListener(new ActionListener() {
693                                    public void
694                                    actionPerformed(ActionEvent e) {
695                                            moveMidiBankTo();
696                                    }
697                            });
698                            
699                            mi = new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.copyTo"));
700                            bankMenu.add(mi);
701                            mi.addActionListener(new ActionListener() {
702                                    public void
703                                    actionPerformed(ActionEvent e) {
704                                            copyMidiBankTo();
705                                    }
706                            });
707                            
708                            bankMenu.addSeparator();
709                            
710                            mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.delete"));
711                            bankMenu.add(mi);
712                            mi.addActionListener(new ActionListener() {
713                                    public void
714                                    actionPerformed(ActionEvent e) {
715                                            removeSelectedInstrumentOrBank();
716                                    }
717                            });
718                            
719                            // MIDI Instrument Menu
720                            
721                            mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.edit"));
722                            instrumentMenu.add(mi);
723                            mi.addActionListener(new ActionListener() {
724                                  public void                                  public void
725                                  actionPerformed(ActionEvent e) {                                  actionPerformed(ActionEvent e) {
726                                          editSelectedInstrument();                                          editSelectedInstrument();
727                                  }                                  }
728                          });                          });
729                                                    
730                          JMenuItem mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.delete"));                          instrumentMenu.addSeparator();
731                          cmenu.add(mi);                          
732                            mi = new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.moveTo"));
733                            instrumentMenu.add(mi);
734                            mi.addActionListener(new ActionListener() {
735                                    public void
736                                    actionPerformed(ActionEvent e) {
737                                            moveMidiInstrumentTo();
738                                    }
739                            });
740                            
741                            mi = new JMenuItem(i18n.getMenuLabel("JSMidiInstrumentTree.ContextMenu.copyTo"));
742                            instrumentMenu.add(mi);
743                            mi.addActionListener(new ActionListener() {
744                                    public void
745                                    actionPerformed(ActionEvent e) {
746                                            copyMidiInstrumentTo();
747                                    }
748                            });
749                            
750                            instrumentMenu.add(changeProgramMenu);
751                            
752                            changeProgramMenu.add(miMoveInstrumentUp);
753                            miMoveInstrumentUp.addActionListener(new ActionListener() {
754                                    public void
755                                    actionPerformed(ActionEvent e) {
756                                            moveSelectedInstrumentUp();
757                                    }
758                            });
759                            
760                            changeProgramMenu.add(miMoveInstrumentDown);
761                            miMoveInstrumentDown.addActionListener(new ActionListener() {
762                                    public void
763                                    actionPerformed(ActionEvent e) {
764                                            moveSelectedInstrumentDown();
765                                    }
766                            });
767                            
768                            changeProgramMenu.addSeparator();
769                            
770                            changeProgramMenu.add(programGroup1Menu);
771                            addProgramMenuItems(programGroup1Menu, 0, 15);
772                            changeProgramMenu.add(programGroup2Menu);
773                            addProgramMenuItems(programGroup2Menu, 16, 31);
774                            changeProgramMenu.add(programGroup3Menu);
775                            addProgramMenuItems(programGroup3Menu, 32, 47);
776                            changeProgramMenu.add(programGroup4Menu);
777                            addProgramMenuItems(programGroup4Menu, 48, 63);
778                            changeProgramMenu.add(programGroup5Menu);
779                            addProgramMenuItems(programGroup5Menu, 64, 79);
780                            changeProgramMenu.add(programGroup6Menu);
781                            addProgramMenuItems(programGroup6Menu, 80, 95);
782                            changeProgramMenu.add(programGroup7Menu);
783                            addProgramMenuItems(programGroup7Menu, 96, 111);
784                            changeProgramMenu.add(programGroup8Menu);
785                            addProgramMenuItems(programGroup8Menu, 112, 127);
786                            
787                            instrumentMenu.addSeparator();
788                            updateChangeProgramMenu();
789                            
790                            mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.delete"));
791                            instrumentMenu.add(mi);
792                          mi.addActionListener(new ActionListener() {                          mi.addActionListener(new ActionListener() {
793                                  public void                                  public void
794                                  actionPerformed(ActionEvent e) {                                  actionPerformed(ActionEvent e) {
# Line 449  public class JSMidiInstrumentTree extend Line 798  public class JSMidiInstrumentTree extend
798                                                    
799                  }                  }
800                                    
801                    private void
802                    addProgramMenuItems(JMenu menu, int prgStart, int prgEnd) {
803                            for(int i = prgStart; i <= prgEnd; i++) {
804                                    menu.add(new ProgramMenuItem(i));
805                            }
806                    }
807                    
808                    private void
809                    updateChangeProgramMenu() {
810                            updateProgramGroupMenu(programGroup1Menu, 0, 15);
811                            updateProgramGroupMenu(programGroup2Menu, 16, 31);
812                            updateProgramGroupMenu(programGroup3Menu, 32, 47);
813                            updateProgramGroupMenu(programGroup4Menu, 48, 63);
814                            updateProgramGroupMenu(programGroup5Menu, 64, 79);
815                            updateProgramGroupMenu(programGroup6Menu, 80, 95);
816                            updateProgramGroupMenu(programGroup7Menu, 96, 111);
817                            updateProgramGroupMenu(programGroup8Menu, 112, 127);
818                    }
819                    
820                    private void
821                    updateProgramGroupMenu(JMenu menu, int prgStart, int prgEnd) {
822                            int base = CC.getViewConfig().getFirstMidiProgramNumber();
823                            String s = "JSMidiInstrumentTree.ContextMenu.programGroup";
824                            String grp = "(" + (base + prgStart) + "-" + (base + prgEnd) + ")";
825                            menu.setText(i18n.getMenuLabel(s, grp));
826                            
827                            updateProgramGroupMenuItems(menu);
828                    }
829                    
830                    private void
831                    updateProgramGroupMenuItems(JMenu menu) {
832                            for(int i = 0; i < menu.getItemCount(); i++) {
833                                    ((ProgramMenuItem)menu.getItem(i)).updateProgramNumber();
834                            }
835                    }
836                    
837                  public void                  public void
838                  mousePressed(MouseEvent e) {                  mousePressed(MouseEvent e) {
839                          if(e.isPopupTrigger()) show(e);                          if(e.isPopupTrigger()) show(e);
840                  }                  }
841                            
842                  public void                  public void
843                  mouseReleased(MouseEvent e) {                  mouseReleased(MouseEvent e) {
844                          if(e.isPopupTrigger()) show(e);                          if(e.isPopupTrigger()) show(e);
845                  }                  }
846                            
847                  void                  void
848                  show(MouseEvent e) {                  show(MouseEvent e) {
849                          if(getSelectionCount() == 0) return;                          if(getSelectionCount() == 0) return;
850                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          
851                            if(getSelectedInstrument() != null) {
852                                    instrumentMenu.show(e.getComponent(), e.getX(), e.getY());
853                            } else {
854                                    bankMenu.show(e.getComponent(), e.getX(), e.getY());
855                            }
856                  }                  }
857                                    
858                  public void                  private class ProgramMenuItem extends JMenuItem implements ActionListener {
859                  valueChanged(TreeSelectionEvent e) {                          int program;
860                          miEdit.setVisible(getSelectedInstrument() != null);                          
861                            ProgramMenuItem(int program) {
862                                    this.program = program;
863                                    updateProgramNumber();
864                                    addActionListener(this);
865                            }
866                            
867                            public void
868                            updateProgramNumber() {
869                                    int base = CC.getViewConfig().getFirstMidiProgramNumber();
870                                    setText(String.valueOf(base + program));
871                            }
872                            
873                            public void
874                            actionPerformed(ActionEvent e) {
875                                    moveSelectedInstrument(program);
876                            }
877                    }
878            }
879    }
880            
881    class JSOverrideInstrumentsConfirmDlg extends OkCancelDialog {
882            private final JLabel lMsg = new JLabel(i18n.getMessage("JSOverrideInstrumentsConfirmDlg.lMsg"));
883            private final JTable table;
884            
885            JSOverrideInstrumentsConfirmDlg(String[] instrumentNames) {
886                    super(CC.getMainFrame());
887                    
888                    JPanel mainPane = new JPanel();
889                    mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
890                    
891                    lMsg.setIcon(CC.getViewConfig().getBasicIconSet().getWarning32Icon());
892                    lMsg.setAlignmentX(LEFT_ALIGNMENT);
893                    mainPane.add(lMsg);
894                    
895                    mainPane.add(Box.createRigidArea(new Dimension(0, 12)));
896                    
897                    String[][] instrs = new String[instrumentNames.length][1];
898                    for(int i = 0; i < instrumentNames.length; i++) {
899                            instrs[i][0] = instrumentNames[i];
900                  }                  }
901                    
902                    String[] columns = new String[1];
903                    columns[0] = "";
904                    
905                    table = new JTable(instrs, columns);
906                    JScrollPane sp = new JScrollPane(table);
907                    Dimension d = new Dimension(200, 200);
908                    sp.setMinimumSize(d);
909                    sp.setPreferredSize(d);
910                    sp.setAlignmentX(LEFT_ALIGNMENT);
911                    mainPane.add(sp);
912                    
913                    setMainPane(mainPane);
914                    setMinimumSize(getPreferredSize());
915                    setResizable(true);
916          }          }
917            
918            protected void
919            onOk() {
920                    if(!btnOk.isEnabled()) return;
921                    
922                    setVisible(false);
923                    setCancelled(false);
924            }
925            
926            protected void
927            onCancel() { setVisible(false); }
928  }  }

Legend:
Removed from v.1766  
changed lines
  Added in v.1767

  ViewVC Help
Powered by ViewVC