Changeset 4191


Ignore:
Timestamp:
07/11/08 12:00:21 (12 years ago)
Author:
curtis
Message:

Add drag and drop support to shortcut window; closes #277.

Location:
trunk/loci/plugins
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/plugins/ShortcutPanel.java

    r4186 r4191  
    5555  // -- Constants -- 
    5656 
     57  /** Name of plugin to use for opening dropped files. */ 
     58  protected static final String OPENER_PLUGIN = "Bio-Formats Importer"; 
     59 
     60  /** Name of this plugin, ignored when parsing the plugins list. */ 
     61  protected static final String SHORTCUT_PLUGIN = 
     62    "LOCI Plugins Shortcut Window"; 
     63 
     64  /** Name of the 'LOCI' submenu. */ 
     65  protected static final String NORMAL_MENU = "Plugins>LOCI"; 
     66 
     67  /** Name of the 'About Plugins' submenu. */ 
     68  protected static final String HELP_MENU = "Help>About Plugins"; 
     69 
    5770  /** Number of pixels for window border. */ 
    5871  protected static final int BORDER = 10; 
     
    6073  // -- Fields -- 
    6174 
     75  /** Index of plugin to use to open dropped files. */ 
     76  protected static int openerIndex; 
     77 
    6278  /** Details for installed LOCI plugins. */ 
    6379  protected static String[] names, plugins, args; 
    6480 
    6581  static { 
     82    // load list of LOCI plugins 
     83    int index = -1; 
    6684    Vector vNames = new Vector(); 
    6785    Vector vPlugins = new Vector(); 
    6886    Vector vArgs = new Vector(); 
    6987 
    70     // read list of plugins from configuration file 
     88    // read from configuration file 
    7189    try { 
    7290      URL url = ShortcutPanel.class.getResource("ShortcutPanel.class"); 
     
    8199 
    82100        // determine plugin type 
    83         boolean normal = line.startsWith("Plugins>LOCI"); 
    84         boolean help = line.startsWith("Help>About Plugins"); 
     101        boolean normal = line.startsWith(NORMAL_MENU); 
     102        boolean help = line.startsWith(HELP_MENU); 
    85103        if (!normal && !help) continue; 
    86104 
     
    98116        String plugin = line.substring(quote2 + 2, quote3 - 1).trim(); 
    99117        String arg = line.substring(quote3 + 1, quote4); 
    100         vNames.add(name); 
    101         vPlugins.add(plugin); 
    102         vArgs.add(arg); 
     118        if (name.equals(OPENER_PLUGIN)) index = vNames.size(); 
     119        if (!name.equals(SHORTCUT_PLUGIN)) { 
     120          vNames.add(name); 
     121          vPlugins.add(plugin); 
     122          vArgs.add(arg); 
     123        } 
    103124      } 
    104125      in.close(); 
     
    108129    } 
    109130 
     131    openerIndex = index; 
    110132    names = new String[vNames.size()]; 
    111133    vNames.copyInto(names); 
     
    118140  // -- Constructor -- 
    119141 
     142  /** Constructs a shortcut panel. */ 
    120143  public ShortcutPanel() { 
    121144    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 
    122145    setBorder(new EmptyBorder(BORDER, BORDER, BORDER, BORDER)); 
     146    setTransferHandler(new ShortcutTransferHandler(this)); 
    123147    JButton[] b = new JButton[names.length]; 
    124148    Dimension prefSize = new Dimension(-1, -1); 
     
    138162  } 
    139163 
     164  // -- ShortcutPanel API methods -- 
     165 
     166  /** Opens the given file with the Bio-Formats Importer plugin. */ 
     167  public void open(File f) { 
     168    String arg = args[openerIndex] + "open=[" + f + "] "; 
     169    IJ.runPlugIn(plugins[openerIndex], arg); 
     170  } 
     171 
    140172  // -- ActionListener API methods -- 
    141173 
     174  /** Handles button presses. */ 
    142175  public void actionPerformed(ActionEvent e) { 
    143176    JButton b = (JButton) e.getSource(); 
Note: See TracChangeset for help on using the changeset viewer.