Beispiel #1
0
  private WebButton createSettings() {
    WebButton settings =
        new WebButton(new ImageIcon(SourceViewer.class.getResource("icons/settings.png")));
    settings.setDrawFocus(false);
    settings.setRolloverDecoratedOnly(true);

    WebButtonPopup wbp = new WebButtonPopup(settings, PopupWay.downLeft);

    WebPanel popupContent = new WebPanel(new VerticalFlowLayout(5, 5));
    popupContent.setMargin(5);
    popupContent.setOpaque(false);
    wbp.setContent(popupContent);

    theme = new WebComboBox(EditorTheme.values());
    theme.registerSettings(SETTINGS_PREFIX + "theme", 0);
    theme.setRenderer(
        new WebComboBoxCellRenderer(theme) {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            EditorTheme editorTheme = (EditorTheme) value;
            WebComboBoxElement renderer =
                (WebComboBoxElement)
                    super.getListCellRendererComponent(
                        list, value, index, isSelected, cellHasFocus);
            renderer.setIcon(editorTheme.getIcon());
            renderer.setText(editorTheme.getName());
            return renderer;
          }
        });
    theme.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            synchronized (activeEditorsLock) {
              final String themeName = theme.getSelectedItem().toString().toLowerCase();
              for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) {
                loadTheme(themeName, entry.getValue());
              }
            }
          }
        });
    popupContent.add(theme);

    allowCodeFolding = new WebToggleButton(loadEditorIcon("allowCodeFolding"));
    allowCodeFolding.registerSettings(SETTINGS_PREFIX + "allowCodeFolding", false);
    allowCodeFolding.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            synchronized (activeEditorsLock) {
              for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) {
                entry.getValue().setCodeFoldingEnabled(allowCodeFolding.isSelected());
              }
            }
          }
        });
    final WebLabel allowCodeFoldingLabel = new WebLabel("Allow code folding");
    allowCodeFoldingLabel.setDrawShade(true);
    allowCodeFoldingLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtils.isLeftMouseButton(e)) {
              allowCodeFolding.requestFocusInWindow();
              allowCodeFolding.doClick();
            }
          }
        });
    popupContent.add(new GroupPanel(5, allowCodeFolding, allowCodeFoldingLabel));

    paintTabLines = new WebToggleButton(loadEditorIcon("paintTabLines"));
    paintTabLines.registerSettings(SETTINGS_PREFIX + "paintTabLines", false);
    paintTabLines.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            synchronized (activeEditorsLock) {
              for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) {
                entry.getValue().setPaintTabLines(paintTabLines.isSelected());
              }
            }
          }
        });
    final WebLabel paintTabLinesLabel = new WebLabel("Paint tab lines");
    paintTabLinesLabel.setDrawShade(true);
    paintTabLinesLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtils.isLeftMouseButton(e)) {
              paintTabLines.requestFocusInWindow();
              paintTabLines.doClick();
            }
          }
        });
    popupContent.add(new GroupPanel(5, paintTabLines, paintTabLinesLabel));

    showWhitespaces = new WebToggleButton(loadEditorIcon("showWhitespaces"));
    showWhitespaces.registerSettings(SETTINGS_PREFIX + "showWhitespaces", false);
    showWhitespaces.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            synchronized (activeEditorsLock) {
              for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) {
                entry.getValue().setWhitespaceVisible(showWhitespaces.isSelected());
              }
            }
          }
        });
    final WebLabel showWhitespacesLabel = new WebLabel("Show whitespaces");
    showWhitespacesLabel.setDrawShade(true);
    showWhitespacesLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtils.isLeftMouseButton(e)) {
              showWhitespaces.requestFocusInWindow();
              showWhitespaces.doClick();
            }
          }
        });
    popupContent.add(new GroupPanel(5, showWhitespaces, showWhitespacesLabel));

    showEol = new WebToggleButton(loadEditorIcon("showEol"));
    showEol.registerSettings(SETTINGS_PREFIX + "showEol", false);
    showEol.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            synchronized (activeEditorsLock) {
              for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) {
                entry.getValue().setEOLMarkersVisible(showEol.isSelected());
              }
            }
          }
        });
    final WebLabel showEolLabel = new WebLabel("Show end of line");
    showEolLabel.setDrawShade(true);
    showEolLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (SwingUtils.isLeftMouseButton(e)) {
              showEol.requestFocusInWindow();
              showEol.doClick();
            }
          }
        });
    popupContent.add(new GroupPanel(5, showEol, showEolLabel));

    return settings;
  }
Beispiel #2
0
  /**
   * Constructs new calendar with the specified selected date.
   *
   * @param date selected date
   */
  public WebCalendar(final Date date) {
    super(true);

    this.date = date != null ? new Date(date.getTime()) : null;
    this.shownDate = date != null ? new Date(date.getTime()) : new Date();

    setDrawFocus(true);
    setRound(StyleConstants.smallRound);
    setLayout(new BorderLayout(0, 0));
    putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true);

    // Main layout
    final WebPanel centerPanel = new WebPanel();
    centerPanel.setOpaque(false);
    add(centerPanel, BorderLayout.CENTER);

    // Header panel
    final WebPanel header = new WebPanel();
    header.setOpaque(false);
    add(header, BorderLayout.NORTH);

    previousSkip = WebButton.createIconWebButton(previousSkipIcon, StyleConstants.smallRound, true);
    previousSkip.setDrawFocus(false);
    previousSkip.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            changeYear(-1);
          }
        });

    previous = WebButton.createIconWebButton(previousIcon, StyleConstants.smallRound, true);
    previous.setDrawFocus(false);
    previous.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            changeMonth(-1);
          }
        });

    final WebPanel leftHeader = new WebPanel(new BorderLayout());
    leftHeader.setOpaque(false);
    leftHeader.add(previousSkip, BorderLayout.WEST);
    leftHeader.add(previous, BorderLayout.EAST);
    header.add(leftHeader, BorderLayout.WEST);

    titlePanel = new ComponentTransition(createTitleLabel());
    titlePanel.setOpaque(false);
    titlePanel.setTransitionEffect(new FadeTransitionEffect());
    titlePanel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
              setShownDate(new Date());
            }
          }
        });
    header.add(titlePanel, BorderLayout.CENTER);

    next = WebButton.createIconWebButton(nextIcon, StyleConstants.smallRound, true);
    next.setDrawFocus(false);
    next.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            changeMonth(1);
          }
        });

    nextSkip = WebButton.createIconWebButton(nextSkipIcon, StyleConstants.smallRound, true);
    nextSkip.setDrawFocus(false);
    nextSkip.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            changeYear(1);
          }
        });

    final WebPanel rightHeader = new WebPanel(new BorderLayout());
    rightHeader.setOpaque(false);
    rightHeader.add(next, BorderLayout.WEST);
    rightHeader.add(nextSkip, BorderLayout.EAST);
    header.add(rightHeader, BorderLayout.EAST);

    // Week days
    weekHeaders = new WebPanel();
    weekHeaders.setUndecorated(false);
    weekHeaders.setDrawSides(true, false, true, false);
    weekHeaders.setShadeWidth(0);
    weekHeaders.setOpaque(false);
    weekHeaders.setMargin(
        StyleConstants.shadeWidth,
        StyleConstants.shadeWidth - 1,
        StyleConstants.shadeWidth + 1,
        StyleConstants.shadeWidth - 1);
    weekHeaders.setLayout(
        new TableLayout(
            new double[][] {
              {
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL,
                TableLayout.PREFERRED,
                TableLayout.FILL
              },
              {TableLayout.PREFERRED}
            }));
    centerPanel.add(weekHeaders, BorderLayout.NORTH);
    updateWeekHeaders();

    // Month days
    monthDays = createMonthPanel();
    updateMonth(monthDays);
    monthDaysTransition = new ComponentTransition(monthDays);
    monthDaysTransition.setOpaque(false);
    monthDaysTransition.addTransitionListener(
        new TransitionAdapter() {
          @Override
          public void transitionFinished() {
            requestFocusToSelected();
          }
        });
    centerPanel.add(monthDaysTransition, BorderLayout.CENTER);
  }
Beispiel #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;
  }