Пример #1
0
  @SuppressWarnings("serial")
  @Override
  public void setupToolBar() {
    getToolbar()
        .add(
            new WebLabel("Resting Hour Report Entry") {
              {
                setDrawShade(true);
                setMargin(10);
              }
            });

    getToolbar().addSeparator();

    WebButton btnSaveNext =
        WebButton.createIconWebButton(
            getIconsHelper().loadIcon("common/save_all_16x16.png"),
            StyleConstants.smallRound,
            true);
    btnSaveNext.putClientProperty("command", "saveAndNext");
    btnSaveNext.addActionListener(this);
    btnSaveNext.setToolTipText("Save and move to next date (CTRL + Shift + S)");

    getToolbar().add(btnSaveNext);

    HotkeyManager.registerHotkey(getOwner(), btnSaveNext, Hotkey.CTRL_SHIFT_S);

    super.setupToolBar();
  }
  @Override
  public Component getPreview(WebLookAndFeelDemo owner) {
    // Hotkey and Tooltip managers integration
    final WebButton tip = new WebButton("Tooltip with hotkey", loadIcon("web.png"));
    HotkeyManager.registerHotkey(
        owner, tip, Hotkey.CTRL_S, new ButtonHotkeyRunnable(tip, 50), TooltipWay.trailing);
    TooltipManager.setTooltip(tip, "Increase counter", TooltipWay.trailing, 0);
    tip.addActionListener(
        new ActionListener() {
          private int count = 0;

          @Override
          public void actionPerformed(ActionEvent e) {
            count++;
            tip.setText("Pressed " + count + (count == 1 ? " time" : " times"));
          }
        });

    return new GroupPanel(tip);
  }
Пример #3
0
  private WebButton createClassSearch() {
    WebButton classSearch = new WebButton(classSearchIcon);
    classSearch.setDrawFocus(false);
    classSearch.setRolloverDecoratedOnly(true);
    classSearch.addHotkey(Hotkey.CTRL_N);
    classSearch.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            showClassSearchPopup();
          }
        });

    classSearchField = new WebTextField(20, false);
    classSearchField.setHideInputPromptOnFocus(false);
    classSearchField.setInputPrompt("Enter class name here...");
    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.ESCAPE,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            hideClassSearchPopup();
          }
        });

    final WebImage leadingComponent = new WebImage(classSearchIcon);
    leadingComponent.setMargin(2);
    classSearchField.setLeadingComponent(leadingComponent);

    classSearchPopup = new WebPopup();
    classSearchPopup.setCloseOnFocusLoss(true);
    classSearchPopup.add(classSearchField);
    classSearchPopup.setDefaultFocusComponent(classSearchField);

    classSearchHintsPopup =
        new WebWindow(classSearchPopup) {
          @Override
          public Dimension getPreferredSize() {
            final Dimension ps = super.getPreferredSize();
            ps.width = Math.max(classSearchField.getWidth(), ps.width);
            return ps;
          }
        };
    classSearchHintsPopup.setFocusable(false);
    classSearchHintsPopup.setAlwaysOnTop(true);
    classSearchPopup.addFocusableChild(classSearchHintsPopup);

    classSearchHintsList = new WebList(new DefaultListModel());
    classSearchHintsList.setFocusable(false);
    classSearchHintsList.setRolloverSelectionEnabled(true);
    classSearchHintsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    classSearchHintsList.setCellRenderer(
        new WebListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JarEntry entry = (JarEntry) value;
            WebListElement renderer =
                (WebListElement)
                    super.getListCellRendererComponent(
                        list, value, index, isSelected, cellHasFocus);
            renderer.setIcon(entry.getIcon());
            renderer.setText(entry.getName());
            return renderer;
          }
        });
    classSearchHintsList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtils.isLeftMouseButton(e)) {
              openSelectedHint();
            }
          }
        });

    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.HOME,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            if (classSearchHintsList.getModelSize() > 0) {
              classSearchHintsList.setSelectedIndex(0);
            }
          }
        });
    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.UP,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            if (classSearchHintsList.getModelSize() > 0) {
              int index = classSearchHintsList.getSelectedIndex();
              if (index > 0) {
                classSearchHintsList.setSelectedIndex(index - 1);
              } else {
                classSearchHintsList.setSelectedIndex(classSearchHintsList.getModelSize() - 1);
              }
            }
          }
        });
    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.DOWN,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            if (classSearchHintsList.getModelSize() > 0) {
              int index = classSearchHintsList.getSelectedIndex();
              if (index < classSearchHintsList.getModelSize() - 1) {
                classSearchHintsList.setSelectedIndex(index + 1);
              } else {
                classSearchHintsList.setSelectedIndex(0);
              }
            }
          }
        });
    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.END,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            if (classSearchHintsList.getModelSize() > 0) {
              classSearchHintsList.setSelectedIndex(classSearchHintsList.getModelSize() - 1);
            }
          }
        });
    HotkeyManager.registerHotkey(
        classSearchField,
        Hotkey.ENTER,
        new HotkeyRunnable() {
          @Override
          public void run(KeyEvent e) {
            openSelectedHint();
          }
        });

    WebScrollPane foundClassesScroll = new WebScrollPane(classSearchHintsList);
    foundClassesScroll.setShadeWidth(0);
    foundClassesScroll.setRound(0);
    classSearchHintsPopup.add(foundClassesScroll);

    classSearchPopup.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentMoved(ComponentEvent e) {
            updateHintsLocation();
          }

          @Override
          public void componentResized(ComponentEvent e) {
            updateHintsLocation();
          }
        });

    classSearchPopup.addPopupListener(
        new PopupAdapter() {
          @Override
          public void popupWillBeOpened() {
            lastSearchedText = null;
            lastFocusBeforeSearch = FocusManager.getFocusOwner();
          }

          @Override
          public void popupOpened() {
            updateHints();
          }

          @Override
          public void popupClosed() {
            hideHints();
            if (lastFocusBeforeSearch != null) {
              lastFocusBeforeSearch.requestFocusInWindow();
            }
          }
        });

    classSearchField.addCaretListener(
        new CaretListener() {
          @Override
          public void caretUpdate(CaretEvent e) {
            if (classSearchHintsDelay == null) {
              classSearchHintsDelay =
                  new WebTimer(
                      500,
                      new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                          updateHints();
                        }
                      });
              classSearchHintsDelay.setRepeats(false);
            }
            if (classSearchField.getText().trim().length() > 0) {
              classSearchHintsDelay.restart();
            } else {
              classSearchHintsDelay.stop();
              hideHints();
            }
          }
        });

    return classSearch;
  }
Пример #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);
  }