Changeset 1172


Ignore:
Timestamp:
Jul 7, 2011, 11:38:11 AM (6 years ago)
Author:
joerg
Message:

created object for the rows of a document for more fine grained syncs

Location:
trunk/src/sce
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sce/codehelper/CodeHelperPane.java

    r1163 r1172  
    88import java.awt.event.KeyEvent;
    99import java.awt.event.KeyListener;
     10import java.awt.event.MouseEvent;
     11import java.awt.event.MouseListener;
    1012import java.util.ArrayList;
    1113import java.util.regex.Matcher;
     
    1820 * @author Stefan Endrullis
    1921 */
    20 public class CodeHelperPane extends JScrollPane implements KeyListener, SCEDocumentListener {
     22public class CodeHelperPane extends JScrollPane implements KeyListener, SCEDocumentListener, MouseListener {
    2123  // the source code pane
    2224  protected SCEPane pane = null;
     
    6062    list.setSelectionBackground(new Color(0, 82, 164));
    6163    list.setSelectionForeground(Color.WHITE);
     64
     65    // put us first in the listner list
     66    MouseListener[] listeners = list.getMouseListeners();
     67    for(MouseListener listener : listeners) list.removeMouseListener(listener);
     68    list.addMouseListener(this);
     69    for(MouseListener listener : listeners) list.addMouseListener(listener);
    6270
    6371    // add the component to the viewport
     
    308316      // enter
    309317      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    310         WordWithPos oldWord = wordPos;
    311         setVisible(false);
    312 
    313         // remove the current text and then start the template
    314         CHCommand command = (CHCommand) list.getSelectedValue();
    315 
    316         SCECaret caret = pane.getCaret();
    317         document.remove(oldWord.getStartPos(), caret);
    318 
    319         Template newTemplate = Template.startTemplate(pane, command.getUsage(), command.getArguments(), oldWord.getStartRow(), oldWord.getStartCol());
    320         if (newTemplate != null) {
    321           template = newTemplate;
    322         }
    323 
     318        doIt();
    324319        e.consume();
    325320        return;
     
    355350  }
    356351
     352  private void doIt() {
     353    WordWithPos oldWord = wordPos;
     354    setVisible(false);
     355
     356    // remove the current text and then start the template
     357    CHCommand command = (CHCommand) list.getSelectedValue();
     358
     359    SCECaret caret = pane.getCaret();
     360    document.remove(oldWord.getStartPos(), caret);
     361
     362    Template newTemplate = Template.startTemplate(pane, command.getUsage(), command.getArguments(), oldWord.getStartRow(), oldWord.getStartCol());
     363    if (newTemplate != null) {
     364      template = newTemplate;
     365    }
     366  }
     367
    357368  public void callCodeHelperWithCompletion() {
    358369    if (popup.isVisible()) return;
     
    429440  }
    430441
    431   public static class SCEListCellRenderer extends DefaultListCellRenderer {
     442  /**
     443   * MouseListener.
     444   */
     445  private int selectedIndex = -1;
     446  public void mouseClicked(MouseEvent e) {
     447    if(selectedIndex == list.getSelectedIndex() || e.getClickCount() >= 2) {
     448      doIt();
     449    }
     450  }
     451
     452  public void mousePressed(MouseEvent e) {
     453    selectedIndex = list.getSelectedIndex();
     454  }
     455
     456  public void mouseReleased(MouseEvent e) {
     457  }
     458
     459  public void mouseEntered(MouseEvent e) {
     460  }
     461
     462  public void mouseExited(MouseEvent e) {
     463  }
     464
     465
     466  // inner classes
     467
     468  public static class SCEListCellRenderer extends DefaultListCellRenderer {
    432469    public static final Color BACKGROUND = new Color(219, 224, 253);
    433470
  • trunk/src/sce/codehelper/SCEPopup.java

    r1050 r1172  
    1010import java.awt.event.KeyEvent;
    1111import java.awt.event.KeyListener;
     12import java.awt.event.MouseEvent;
     13import java.awt.event.MouseListener;
    1214import java.util.List;
    1315
     
    1820 * @author Stefan Endrullis
    1921 */
    20 public class SCEPopup extends JScrollPane implements KeyListener {
     22public class SCEPopup extends JScrollPane implements KeyListener, MouseListener {
    2123  // the source code pane
    2224  SCEPane pane = null;
     
    5355    list.setSelectionBackground(new Color(0, 82, 164));
    5456    list.setSelectionForeground(Color.WHITE);
     57
     58    // put us first in the listner list
     59    MouseListener[] listeners = list.getMouseListeners();
     60    for(MouseListener listener : listeners) list.removeMouseListener(listener);
     61    list.addMouseListener(this);
     62    for(MouseListener listener : listeners) list.addMouseListener(listener);
    5563
    5664    // add the component to the viewport
     
    204212    // enter
    205213    if ((e.getKeyCode() == KeyEvent.VK_ENTER || (e.getKeyCode() == KeyEvent.VK_SPACE) && !e.isControlDown())) {
    206       if (model.size() == 0) return;
    207 
    208       setVisible(false);
    209 
    210       // pass the selected item to the item handler
    211       Object item = list.getSelectedValue();
    212       itemHandler.perform(item);
     214      doIt();
    213215      e.consume();
    214216    }
     
    217219      setVisible(false);
    218220    }
     221  }
     222
     223  private void doIt() {
     224    if (model.size() == 0) return;
     225
     226    setVisible(false);
     227
     228    // pass the selected item to the item handler
     229    Object item = list.getSelectedValue();
     230    itemHandler.perform(item);
    219231  }
    220232
     
    232244  }
    233245
     246  /**
     247   * MouseListener.
     248   */
     249  private int selectedIndex = -1;
     250  public void mouseClicked(MouseEvent e) {
     251    if(selectedIndex == list.getSelectedIndex() || e.getClickCount() >= 2) {
     252      doIt();
     253    }
     254  }
     255
     256  public void mousePressed(MouseEvent e) {
     257    selectedIndex = list.getSelectedIndex();
     258  }
     259
     260  public void mouseReleased(MouseEvent e) {
     261  }
     262
     263  public void mouseEntered(MouseEvent e) {
     264  }
     265
     266  public void mouseExited(MouseEvent e) {
     267  }
     268
    234269
    235270  // inner classes
  • trunk/src/sce/component/SCESearch.java

    r1171 r1172  
    479479  public void selectionChanged(SCEDocument sender, SCEDocumentPosition start, SCEDocumentPosition end) {
    480480    if (start == null || end == null) {
    481       replaceEnabled(false);
     481      replaceEnabled(false, results.size() > 0);
    482482      return;
    483483    }
     
    488488
    489489      if (start.equals(rstart) && end.equals(rend)) {
    490         replaceEnabled(true);
     490        replaceEnabled(true, results.size() > 0);
    491491        return;
    492492      }
    493493    }
    494494
    495     replaceEnabled(false);
    496   }
    497 
    498   private void replaceEnabled(boolean enabled) {
    499     buttonReplace.setEnabled(enabled);
    500     buttonReplaceAll.setEnabled(enabled);
     495    replaceEnabled(false, results.size() > 0);
     496  }
     497
     498  private void replaceEnabled(boolean replaceEnabled, boolean replaceAllEnabled) {
     499    buttonReplace.setEnabled(replaceEnabled);
     500    buttonReplaceAll.setEnabled(replaceAllEnabled);
    501501  }
    502502
Note: See TracChangeset for help on using the changeset viewer.