Changeset 198 for trunk/loci/visbio/view


Ignore:
Timestamp:
03/02/05 17:20:35 (15 years ago)
Author:
curtis
Message:

Add arrow key functionality for traversing displays.

Location:
trunk/loci/visbio/view
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/view/DisplayWindow.java

    r193 r198  
    2525 
    2626import java.awt.*; 
    27 import java.awt.event.ActionEvent; 
    28 import java.awt.event.ActionListener; 
     27import java.awt.event.*; 
    2928import javax.swing.JFrame; 
    3029import javax.swing.JPanel; 
     
    4342 */ 
    4443public class DisplayWindow extends JFrame 
    45   implements ActionListener, DisplayListener, Dynamic 
     44  implements ActionListener, DisplayListener, Dynamic, KeyListener 
    4645{ 
    4746 
     
    288287  /** Listens for keyboard presses within the display. */ 
    289288  public void displayChanged(DisplayEvent e) { 
    290     // CTR TODO 
    291289    int id = e.getId(); 
    292290    if (id == DisplayEvent.KEY_PRESSED) { 
    293       int code = e.getKeyCode(); 
    294       /*TEMP*/System.out.println("Key pressed: " + code); 
     291      keyPressed((KeyEvent) e.getInputEvent()); 
    295292    } 
    296293    else if (id == DisplayEvent.KEY_RELEASED) { 
    297       int code = e.getKeyCode(); 
    298       /*TEMP*/System.out.println("Key released: " + code); 
     294      keyReleased((KeyEvent) e.getInputEvent()); 
    299295    } 
    300296  } 
     
    379375      wm.addWindow(controls.getWindow()); 
    380376 
     377      // listen for key presses 
     378      //addKeyListener(this); 
     379      //controls.addKeyListener(this); 
     380 
     381      // Note: adding the KeyListener directly to frames and panels is not 
     382      // effective, because some child always has the keyboard focus and eats 
     383      // the event. Better would be to add the keyboard listener to each 
     384      // component that does not need the arrow keys for its own purposes. For 
     385      // now, the display itself must have the focus (just click it first). 
     386 
    381387      // lay out components 
    382388      pane.add(display.getComponent(), BorderLayout.CENTER); 
     
    398404 
    399405 
     406  // -- KeyListener API methods -- 
     407 
     408  /** Handles key presses. */ 
     409  public void keyPressed(KeyEvent e) { 
     410    int code = e.getKeyCode(); 
     411    int mods = e.getModifiers(); 
     412    if (mods != 0) return; 
     413    if (code == KeyEvent.VK_LEFT || code == KeyEvent.VK_RIGHT) { 
     414      int axis = transformHandler.getPanel().getLeftRightAxis(); 
     415      BioSlideWidget bsw = transformHandler.getSlider(axis); 
     416      if (bsw == null) return; 
     417      if (code == KeyEvent.VK_LEFT) bsw.step(false); 
     418      else bsw.step(true); // code == KeyEvent.VK_RIGHT 
     419    } 
     420    else if (code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) { 
     421      int axis = transformHandler.getPanel().getUpDownAxis(); 
     422      BioSlideWidget bsw = transformHandler.getSlider(axis); 
     423      if (bsw == null) return; 
     424      if (code == KeyEvent.VK_DOWN) bsw.step(false); 
     425      else bsw.step(true); // code == KeyEvent.VK_UP 
     426    } 
     427  } 
     428 
     429  /** Handles key releases. */ 
     430  public void keyReleased(KeyEvent e) { } 
     431 
     432  public void keyTyped(KeyEvent e) { } 
     433 
     434 
    400435  // -- Helper methods -- 
    401436 
  • trunk/loci/visbio/view/TransformHandler.java

    r155 r198  
    188188  /** Gets a panel containing sliders widgets for linked transforms. */ 
    189189  public JPanel getSliderPanel() { return sliderPanel; } 
     190 
     191  /** Gets the slider at the given index, or null if no such slider exists. */ 
     192  public BioSlideWidget getSlider(int index) { 
     193    if (index < 0 || index >= sliders.size()) return null; 
     194    return (BioSlideWidget) sliders.elementAt(index); 
     195  } 
    190196 
    191197  /** 
  • trunk/loci/visbio/view/TransformPanel.java

    r193 r198  
    2424package loci.visbio.view; 
    2525 
     26import com.jgoodies.forms.builder.PanelBuilder; 
    2627import com.jgoodies.forms.builder.ButtonStackBuilder; 
     28import com.jgoodies.forms.layout.CellConstraints; 
     29import com.jgoodies.forms.layout.FormLayout; 
    2730import java.awt.BorderLayout; 
    2831import java.awt.event.ActionEvent; 
     
    4447  protected TransformHandler handler; 
    4548 
     49  /** List of linked data transforms. */ 
     50  protected JList transformList; 
     51 
     52  /** List model for linked data transform list. */ 
     53  protected DefaultListModel transformModel; 
     54 
     55  /** Checkbox for toggling data transform visibility. */ 
     56  protected JCheckBox visible; 
     57 
     58  /** Button for removing selected data transform. */ 
     59  protected JButton removeTransform; 
     60 
     61  /** Button for editing colors for the selected data transform. */ 
     62  protected JButton dataColors; 
     63 
     64  /** Button for showing controls for the selected data transform. */ 
     65  protected JButton dataControls; 
     66 
     67  /** Button for moving data objects upward in the list. */ 
     68  protected JButton moveUp; 
     69 
     70  /** Button for moving data objects downward in the list. */ 
     71  protected JButton moveDown; 
     72 
    4673  /** Spinner for adjusting burn-in delay. */ 
    4774  protected JSpinner delayTime; 
    4875 
    49   /** List of linked data transforms. */ 
    50   protected JList transformList; 
    51  
    52   /** List model for linked data transform list. */ 
    53   protected DefaultListModel transformModel; 
    54  
    55   /** Checkbox for toggling data transform visibility. */ 
    56   protected JCheckBox visible; 
    57  
    58   /** Button for removing selected data transform. */ 
    59   protected JButton removeTransform; 
    60  
    61   /** Button for editing colors for the selected data transform. */ 
    62   protected JButton dataColors; 
    63  
    64   /** Button for showing controls for the selected data transform. */ 
    65   protected JButton dataControls; 
    66  
    67   /** Button for moving data objects upward in the list. */ 
    68   protected JButton moveUp; 
    69  
    70   /** Button for moving data objects downward in the list. */ 
    71   protected JButton moveDown; 
     76  /** List of axes for left/right arrow mapping. */ 
     77  protected JComboBox leftRightBox; 
     78 
     79  /** List of axes for up/down arrow mapping. */ 
     80  protected JComboBox upDownBox; 
    7281 
    7382  /** Button for toggling status of animation. */ 
     
    135144  /** Adds a dimensional axis. */ 
    136145  public void addAxis(String axis) { 
    137     String s = "<" + animBox.getItemCount() + "> " + axis; 
     146    int count = animBox.getItemCount(); 
     147    String s = "<" + count + "> " + axis; 
     148    leftRightBox.addItem(s); 
     149    upDownBox.addItem(s); 
    138150    animBox.addItem(s); 
    139151    if (axis.equals("Time")) { 
    140       // Time axes are good defaults for animation 
     152      // time axis is a good default for left/right and animation 
     153      leftRightBox.setSelectedItem(s); 
    141154      animBox.setSelectedItem(s); 
     155    } 
     156    else if (axis.equals("Slice")) { 
     157      // slice axis is a good default for up/down 
     158      upDownBox.setSelectedItem(s); 
    142159    } 
    143160  } 
     
    145162  /** Removes all dimensional axes. */ 
    146163  public void removeAllAxes() { 
    147     while (animBox.getItemCount() > 1) animBox.removeItemAt(1); 
     164    while (animBox.getItemCount() > 1) { 
     165      leftRightBox.removeItemAt(1); 
     166      upDownBox.removeItemAt(1); 
     167      animBox.removeItemAt(1); 
     168    } 
    148169  } 
    149170 
    150171  /** Gets number of registered dimensional axes. */ 
    151172  public int getAxisCount() { return animBox.getItemCount() - 1; } 
     173 
     174  /** Gets axis mapped to left/right arrow keys. */ 
     175  public int getLeftRightAxis() { return leftRightBox.getSelectedIndex() - 1; } 
     176 
     177  /** Gets axis mapped to up/down arrow keys. */ 
     178  public int getUpDownAxis() { return upDownBox.getSelectedIndex() - 1; } 
    152179 
    153180  /** Updates controls to reflect current handler status. */ 
     
    275302  /** Creates a panel with data transform-related components. */ 
    276303  protected JPanel doDataPanel() { 
    277     // burn-in checkbox 
    278     JCheckBox delayBurn = new JCheckBox("Delay burn-in", true); 
    279     delayBurn.setActionCommand("delayBurn"); 
    280     delayBurn.addActionListener(this); 
    281     if (!LAFUtil.isMacLookAndFeel()) delayBurn.setMnemonic('n'); 
    282     delayBurn.setToolTipText( 
    283       "Toggles whether full-resolution burn-in is delayed"); 
    284  
    285     // burn-in delay 
    286     delayTime = new JSpinner(new SpinnerNumberModel( 
    287       handler.getBurnDelay() / 1000, 1, 99, 1)); 
    288     delayTime.addChangeListener(this); 
    289     delayTime.setToolTipText( 
    290       "Adjusts the time before full-resolution burn-in"); 
    291  
    292304    // linked data transforms 
    293305    transformModel = new DefaultListModel(); 
     
    354366    visible.addActionListener(this); 
    355367    visible.setEnabled(false); 
     368 
     369    // burn-in checkbox 
     370    JCheckBox delayBurn = new JCheckBox("Delay burn-in", true); 
     371    delayBurn.setActionCommand("delayBurn"); 
     372    delayBurn.addActionListener(this); 
     373    if (!LAFUtil.isMacLookAndFeel()) delayBurn.setMnemonic('n'); 
     374    delayBurn.setToolTipText( 
     375      "Toggles whether full-resolution burn-in is delayed"); 
     376 
     377    // burn-in delay 
     378    delayTime = new JSpinner(new SpinnerNumberModel( 
     379      handler.getBurnDelay() / 1000, 1, 99, 1)); 
     380    delayTime.addChangeListener(this); 
     381    delayTime.setToolTipText( 
     382      "Adjusts the time before full-resolution burn-in"); 
    356383 
    357384    // lay out buttons 
     
    372399    // lay out components 
    373400    return FormsUtil.makeColumn( 
    374       FormsUtil.makeRow(delayBurn, delayTime, "seconds"), 
    375401      FormsUtil.makeRow(new Object[] {listPane, buttons, 
    376         doDataProperties()}, "fill:pref:grow", false) 
     402        doDataProperties()}, "fill:pref:grow", false), 
     403      FormsUtil.makeRow(delayBurn, delayTime, "seconds") 
    377404    ); 
    378405  } 
     
    380407  /** Creates a panel with animation-related components. */ 
    381408  protected JPanel doAnimationPanel() { 
     409    // left/right combo box 
     410    leftRightBox = new JComboBox(new String[] {"None"}); 
     411    leftRightBox.setToolTipText("The axis " + 
     412      "traversed by the left and right arrow keys"); 
     413 
     414    // up/down combo box 
     415    upDownBox = new JComboBox(new String[] {"None"}); 
     416    upDownBox.setToolTipText("The axis " + 
     417      "traversed by the up and down arrow keys"); 
     418 
    382419    // animate button 
    383420    animate = new JButton("Animate"); 
     
    403440 
    404441    // lay out components 
    405     return FormsUtil.makeRow(new Object[] {animate, "&FPS", fps, animBox}); 
     442    PanelBuilder builder = new PanelBuilder(new FormLayout( 
     443      "pref:grow", "pref, 3dlu, pref, 9dlu")); 
     444    CellConstraints cc = new CellConstraints(); 
     445    builder.add(FormsUtil.makeRow(new Object[] {"Arrow keys:", 
     446      "Le&ft/right", leftRightBox, "Up/do&wn", upDownBox}), cc.xy(1, 1)); 
     447    builder.add(FormsUtil.makeRow(new Object[] 
     448      {animate, "&FPS", fps, animBox}), cc.xy(1, 3)); 
     449    return builder.getPanel(); 
    406450  } 
    407451 
  • trunk/loci/visbio/view/ViewPanel.java

    r155 r198  
    208208    // lay out components 
    209209    Object[] o = threeD ? new Object[] { 
    210       "Aspect ratio", "&X", aspectX, "&Y", aspectY, "&Z", aspectZ} : 
    211       new Object[] {"Aspect ratio", "&X", aspectX, "&Y", aspectY}; 
     210      "Aspect ratio:", "&X", aspectX, "&Y", aspectY, "&Z", aspectZ} : 
     211      new Object[] {"Aspect ratio:", "&X", aspectX, "&Y", aspectY}; 
    212212    return FormsUtil.makeRow(o); 
    213213  } 
Note: See TracChangeset for help on using the changeset viewer.