예제 #1
0
 public void viewEntry(JarEntry entry) {
   if (viewTabbedPane.isOpenedEntry(entry)) {
     viewTabbedPane.selectEntry(entry);
   } else {
     viewTabbedPane.viewEntry(entry, createEntryViewer(entry));
   }
   viewTabbedPane.transferFocus();
 }
예제 #2
0
 public void closeEntryView(JarEntry entry) {
   viewTabbedPane.closeEntry(entry);
 }
예제 #3
0
  public void updateClassPath(final JarEntry lastEntry, boolean openInEditor) {
    classPath.removeAll();

    // Root element
    final JarEntry root = jarStructure.getRoot();
    final WebBreadcrumbButton rootElement = new WebBreadcrumbButton();
    rootElement.setIcon(root.getIcon());
    TooltipManager.setTooltip(rootElement, root.getIcon(), jarStructure.getJarLocation());
    rootElement.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final WebPopupMenu rootMenu = new WebPopupMenu();

            WebMenuItem showInFS = new WebMenuItem("Show in folder", browseIcon);
            showInFS.addActionListener(
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    try {
                      File jarFile = new File(jarStructure.getJarLocation());
                      Desktop.getDesktop().browse(jarFile.getParentFile().toURI());
                    } catch (Throwable ex) {
                      ex.printStackTrace();
                    }
                  }
                });
            rootMenu.add(showInFS);

            List<JarEntry> entries = jarStructure.getChildEntries(root);
            if (entries.size() > 0) {
              rootMenu.addSeparator();
              for (JarEntry entry : entries) {
                rootMenu.add(createEntryMenuItem(entry));
              }
            }

            rootMenu.showBelowMiddle(rootElement);
          }
        });
    classPath.add(rootElement);

    if (lastEntry != null) {
      // All other elements
      List<JarEntry> path = lastEntry.getPath();
      for (final JarEntry entry : path) {
        if (entry.getType().equals(JarEntryType.packageEntry)) {
          final WebBreadcrumbButton element = new WebBreadcrumbButton();
          element.setIcon(entry.getIcon());
          element.setText(entry.getName());
          element.addActionListener(
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  List<JarEntry> entries = jarStructure.getChildEntries(entry);
                  if (entries.size() > 0) {
                    final WebPopupMenu packageMenu = new WebPopupMenu();
                    for (JarEntry menuEntry : entries) {
                      packageMenu.add(createEntryMenuItem(menuEntry));
                    }
                    packageMenu.showBelowMiddle(element);
                  }
                }
              });
          classPath.add(element);
        } else {
          WebBreadcrumbLabel element = new WebBreadcrumbLabel();
          element.setIcon(entry.getIcon());
          element.setText(entry.getName());
          classPath.add(element);
        }
      }
    }

    classPath.updateBreadcrumb();

    if (openInEditor && lastEntry != null) {
      if (lastEntry.getType().equals(JarEntryType.jarEntry)
          || lastEntry.getType().equals(JarEntryType.packageEntry)) {
        // Queueing last element menu to let breadcrumb update element locations first
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                // Opening last element menu if it is a package
                ((WebBreadcrumbButton) classPath.getLastComponent()).doClick();
              }
            });
      } else {
        // Viewing last element if it is a file
        viewTabbedPane.removeChangeListener(viewChangeListener);
        viewEntry(lastEntry);
        viewTabbedPane.addChangeListener(viewChangeListener);
      }
    }
  }
예제 #4
0
  public SourceViewer(JarStructure jarStructure) {
    super();

    this.jarStructure = jarStructure;

    toolBar = new WebPanel(true, new ToolbarLayout());
    toolBar.setDrawSides(false, false, true, false);
    toolBar.setShadeWidth(0);
    add(toolBar, BorderLayout.NORTH);

    classPath = new WebBreadcrumb(false);
    classPath.setEncloseLastElement(true);
    classPath.setElementMargin(4, 6, 4, 6);
    classPath.setOpaque(false);
    toolBar.add(classPath, ToolbarLayout.FILL);

    toolBar.add(createClassSearch(), ToolbarLayout.END);
    toolBar.add(createSettings(), ToolbarLayout.END);

    viewTabbedPane = new ViewTabbedPane();
    viewTabbedPane.setTabbedPaneStyle(TabbedPaneStyle.attached);
    viewChangeListener =
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            updateClassPath(viewTabbedPane.getSelectedEntry(), false);
          }
        };
    viewTabbedPane.addChangeListener(viewChangeListener);
    viewTabbedPane.addViewListener(
        new ViewListener() {
          @Override
          public void viewOpened(JarEntry entry) {
            //
          }

          @Override
          public void viewClosed(JarEntry entry) {
            synchronized (activeEditorsLock) {
              // Removing opened editor
              activeEditors.remove(entry);
            }
            updateClassPath(viewTabbedPane.getSelectedEntry(), false);
          }
        });
    HotkeyManager.registerHotkey(
        viewTabbedPane,
        Hotkey.ALT_LEFT,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            final int tabCount = viewTabbedPane.getTabCount();
            if (tabCount > 0) {
              final int index = viewTabbedPane.getSelectedIndex();
              viewTabbedPane.setSelectedIndex(index > 0 ? index - 1 : tabCount - 1);
            }
          }
        });
    HotkeyManager.registerHotkey(
        viewTabbedPane,
        Hotkey.ALT_RIGHT,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            final int tabCount = viewTabbedPane.getTabCount();
            if (tabCount > 0) {
              final int index = viewTabbedPane.getSelectedIndex();
              viewTabbedPane.setSelectedIndex(index < tabCount - 1 ? index + 1 : 0);
            }
          }
        });
    add(viewTabbedPane, BorderLayout.CENTER);

    updateClassPath(null, false);
  }