Example #1
0
  // {{{ BrowserView constructor
  BrowserView(final VFSBrowser browser) {
    this.browser = browser;

    tmpExpanded = new HashSet<String>();
    DockableWindowManager dwm = jEdit.getActiveView().getDockableWindowManager();
    KeyListener keyListener = dwm.closeListener(VFSBrowser.NAME);

    parentDirectories = new ParentDirectoryList();
    parentDirectories.addKeyListener(keyListener);
    parentDirectories.setName("parent");

    parentDirectories.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    parentDirectories.setCellRenderer(new ParentDirectoryRenderer());
    parentDirectories.setVisibleRowCount(5);
    parentDirectories.addMouseListener(new ParentMouseHandler());

    final JScrollPane parentScroller = new JScrollPane(parentDirectories);
    parentScroller.setMinimumSize(new Dimension(0, 0));

    table = new VFSDirectoryEntryTable(this);
    table.addMouseListener(new TableMouseHandler());
    table.addKeyListener(new TableKeyListener());
    table.setName("file");
    JScrollPane tableScroller = new JScrollPane(table);
    tableScroller.setMinimumSize(new Dimension(0, 0));
    tableScroller.getViewport().setBackground(table.getBackground());
    tableScroller.getViewport().addMouseListener(new TableMouseHandler());
    splitPane =
        new JSplitPane(
            browser.isHorizontalLayout() ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT,
            parentScroller,
            tableScroller);
    splitPane.setOneTouchExpandable(true);

    EventQueue.invokeLater(
        new Runnable() {
          public void run() {
            String prop =
                browser.isHorizontalLayout()
                    ? "vfs.browser.horizontalSplitter"
                    : "vfs.browser.splitter";
            int loc = jEdit.getIntegerProperty(prop, -1);
            if (loc == -1) loc = parentScroller.getPreferredSize().height;

            splitPane.setDividerLocation(loc);
            parentDirectories.ensureIndexIsVisible(parentDirectories.getModel().getSize());
          }
        });

    if (browser.isMultipleSelectionEnabled())
      table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    else table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    setLayout(new BorderLayout());

    add(BorderLayout.CENTER, splitPane);

    propertiesChanged();
  } // }}}
Example #2
0
 @Override
 protected void processKeyEvent(KeyEvent evt) {
   if (evt.getID() == KeyEvent.KEY_PRESSED) {
     ActionContext ac = VFSBrowser.getActionContext();
     int row = parentDirectories.getSelectedIndex();
     switch (evt.getKeyCode()) {
       case KeyEvent.VK_DOWN:
         evt.consume();
         if (row < parentDirectories.getSize().height - 1)
           parentDirectories.setSelectedIndex(++row);
         break;
       case KeyEvent.VK_LEFT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.previousDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_RIGHT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.nextDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_TAB:
         evt.consume();
         if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent();
         else table.requestFocus();
         break;
       case KeyEvent.VK_UP:
         evt.consume();
         if (row > 0) {
           parentDirectories.setSelectedIndex(--row);
         }
         break;
       case KeyEvent.VK_BACK_SPACE:
         evt.consume();
         EditAction up = ac.getAction("vfs.browser.up");
         ac.invokeAction(evt, up);
         break;
       case KeyEvent.VK_F5:
         evt.consume();
         EditAction reload = ac.getAction("vfs.browser.reload");
         ac.invokeAction(evt, reload);
         break;
       case KeyEvent.VK_ENTER:
         evt.consume();
         if (row != -1) {
           // basically the same handling as in ParentMouseHandler#mouseReleased
           Object obj = parentDirectories.getModel().getElementAt(row);
           if (obj instanceof VFSFile) {
             VFSFile dirEntry = (VFSFile) obj;
             browser.setDirectory(dirEntry.getPath());
             if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
           }
         }
         break;
         /* These actions don't work because they look at the EntryTable for the current selected
         * 	item. We need actions that look at the parentDirectoryList item instead.
         *
         			case KeyEvent.VK_DELETE:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.delete");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.CTRL_MASK | KeyEvent.VK_N:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-file");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.VK_INSERT:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-directory");
         				ac.invokeAction(evt, ea);
         				break; */
     }
   } else if (evt.getID() == KeyEvent.KEY_TYPED) {
     if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) {
       evt.consume();
       return;
     }
     switch (evt.getKeyChar()) {
       case '~':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER)
           browser.setDirectory(System.getProperty("user.home"));
         break;
       case '/':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory();
         break;
       case '-':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) {
           browser.setDirectory(browser.getView().getBuffer().getDirectory());
         }
         break;
     }
   }
   if (!evt.isConsumed()) super.processKeyEvent(evt);
 }