private static Component createPresentationButton(final Example example) {
    final WebToggleButton presentation = new WebToggleButton(presentationIcon);
    presentation.setRolloverDecoratedOnly(true);
    presentation.setFocusable(false);

    presentation.setEnabled(example.isPresentationAvailable());
    TooltipManager.setTooltip(
        presentation,
        presentationIcon,
        example.isPresentationAvailable()
            ? "Show presentation"
            : "There is no presentation available for this component",
        TooltipWay.up);

    if (presentation.isEnabled()) {
      presentation.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (presentation.isSelected()) {
                example.startPresentation();
                TooltipManager.setTooltip(
                    presentation, presentationIcon, "Stop presentation", TooltipWay.up);
              } else {
                example.stopPresentation();
                TooltipManager.setTooltip(
                    presentation, presentationIcon, "Show presentation", TooltipWay.up);
              }
            }
          });

      example.doWhenPresentationFinished(
          new Runnable() {
            @Override
            public void run() {
              presentation.setSelected(false);
              TooltipManager.setTooltip(
                  presentation, presentationIcon, "Show presentation", TooltipWay.up);

              ThreadUtils.sleepSafely(250);

              final WebCustomTooltip end =
                  TooltipManager.showOneTimeTooltip(
                      presentation, null, "Presentation has ended", TooltipWay.up);
              WebTimer.delay(
                  1500,
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      end.closeTooltip();
                    }
                  });
            }
          });
    }

    return new CenterPanel(presentation, false, true);
  }
Beispiel #2
0
  /**
   * Updates displayed month date buttons.
   *
   * @param monthDays panel to update
   */
  protected void updateMonth(final JPanel monthDays) {
    monthDays.removeAll();
    lastSelectedDayButton = null;

    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "1,0,1,5");
    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "3,0,3,5");
    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "5,0,5,5");
    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "7,0,7,5");
    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "9,0,9,5");
    monthDays.add(new WebSeparator(WebSeparator.VERTICAL), "11,0,11,5");

    final ButtonGroup dates = new ButtonGroup();

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(shownDate);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    int col = 0;
    int row = 0;

    // Month before
    final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    final int shift;
    switch (dayOfWeek) {
      case Calendar.MONDAY:
        shift = startWeekFromSunday ? 1 : 7;
        break;
      case Calendar.TUESDAY:
        shift = startWeekFromSunday ? 2 : 1;
        break;
      case Calendar.WEDNESDAY:
        shift = startWeekFromSunday ? 3 : 2;
        break;
      case Calendar.THURSDAY:
        shift = startWeekFromSunday ? 4 : 3;
        break;
      case Calendar.FRIDAY:
        shift = startWeekFromSunday ? 5 : 4;
        break;
      case Calendar.SATURDAY:
        shift = startWeekFromSunday ? 6 : 5;
        break;
      case Calendar.SUNDAY:
        shift = startWeekFromSunday ? 7 : 6;
        break;
      default:
        shift = 0;
        break;
    }
    TimeUtils.changeByDays(calendar, -shift);
    while (calendar.get(Calendar.DAY_OF_MONTH) > 1) {
      final Date thisDate = calendar.getTime();
      final WebToggleButton day = new WebToggleButton();
      day.setForeground(otherMonthForeground);
      day.setText("" + calendar.get(Calendar.DAY_OF_MONTH));
      day.setRolloverDecoratedOnly(true);
      day.setHorizontalAlignment(WebButton.RIGHT);
      day.setRound(StyleConstants.smallRound);
      day.setFocusable(false);
      day.addItemListener(
          new ItemListener() {
            @Override
            public void itemStateChanged(final ItemEvent e) {
              final WebToggleButton dayButton = (WebToggleButton) e.getSource();
              if (dayButton.isSelected()) {
                setDateImpl(thisDate);
              }
            }
          });
      if (dateCustomizer != null) {
        dateCustomizer.customize(day, thisDate);
      }
      monthDays.add(day, col * 2 + "," + row);
      dates.add(day);

      TimeUtils.increaseByDay(calendar);

      col++;
      if (col > 6) {
        col = 0;
        row++;
      }
    }

    // Current month
    do {
      final boolean weekend =
          calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7;
      final boolean selected = date != null && TimeUtils.isSameDay(calendar, date.getTime());

      final Date thisDate = calendar.getTime();
      final WebToggleButton day = new WebToggleButton();
      day.setForeground(weekend ? weekendsForeground : currentMonthForeground);
      day.setText("" + calendar.get(Calendar.DAY_OF_MONTH));
      day.setSelected(selected);
      day.setRolloverDecoratedOnly(true);
      day.setHorizontalAlignment(WebButton.RIGHT);
      day.setRound(StyleConstants.smallRound);
      day.setFocusable(false);
      day.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
              lastSelectedDayButton = (WebToggleButton) e.getSource();
              setDateImpl(thisDate);
            }
          });
      if (dateCustomizer != null) {
        dateCustomizer.customize(day, thisDate);
      }
      monthDays.add(day, col * 2 + "," + row);
      dates.add(day);

      if (selected) {
        lastSelectedDayButton = day;
      }

      TimeUtils.increaseByDay(calendar);

      col++;
      if (col > 6) {
        col = 0;
        row++;
      }
    } while (calendar.get(Calendar.DAY_OF_MONTH) > 1);

    // Month after
    final int left = 6 * 7 - (monthDays.getComponentCount() - 6);
    for (int i = 1; i <= left; i++) {
      final Date thisDate = calendar.getTime();
      final WebToggleButton day = new WebToggleButton();
      day.setForeground(otherMonthForeground);
      day.setText("" + calendar.get(Calendar.DAY_OF_MONTH));
      day.setRolloverDecoratedOnly(true);
      day.setHorizontalAlignment(WebButton.RIGHT);
      day.setRound(StyleConstants.smallRound);
      day.setFocusable(false);
      day.addItemListener(
          new ItemListener() {
            @Override
            public void itemStateChanged(final ItemEvent e) {
              final WebToggleButton dayButton = (WebToggleButton) e.getSource();
              if (dayButton.isSelected()) {
                setDateImpl(thisDate);
              }
            }
          });
      if (dateCustomizer != null) {
        dateCustomizer.customize(day, thisDate);
      }
      monthDays.add(day, col * 2 + "," + row);
      dates.add(day);

      TimeUtils.increaseByDay(calendar);

      col++;
      if (col > 6) {
        col = 0;
        row++;
      }
    }

    monthDays.revalidate();
  }
Beispiel #3
0
  private Component createEntryViewer(JarEntry entry) {
    if (entry.getType().equals(JarEntryType.classEntry)
        || entry.getType().equals(JarEntryType.javaEntry)
        || entry.getType().equals(JarEntryType.fileEntry)) {
      String ext = FileUtils.getFileExtPart(entry.getName(), false).toLowerCase();
      if (GlobalConstants.IMAGE_FORMATS.contains(ext)) {
        // todo A better image viewer (actually a new component - WebImageViewer)

        // Image file viewer
        WebImage image = new WebImage();
        image.setIcon(ImageUtils.loadImage(getEntryInputStream(entry)));

        // Image scroll
        WebScrollPane imageScroll = new WebScrollPane(image, false);
        imageScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        imageScroll.setHorizontalScrollBarPolicy(WebScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        return imageScroll;
      } else {
        // Source code viewer
        final RSyntaxTextArea source = new RSyntaxTextArea();

        // Syntax style
        boolean libraryCode = false;
        if (ext.equals("java") || ext.equals("class")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
          libraryCode = true;
        } else if (ext.equals("xml")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        } else if (ext.equals("html")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
        } else if (ext.equals("css")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
        } else if (ext.equals("js")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        } else if (ext.equals("php")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
        } else if (ext.equals("sql")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
        } else {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
        }

        // Settings
        source.setEditable(false);
        source.setMargin(new Insets(0, 5, 0, 0));
        source.setAntiAliasingEnabled(true);
        source.setUseFocusableTips(true);
        source.setTabSize(4);
        // source.setLineWrap ( true );
        // source.setWrapStyleWord ( true );
        source.setCodeFoldingEnabled(allowCodeFolding.isSelected());
        source.setPaintTabLines(paintTabLines.isSelected());
        source.setWhitespaceVisible(showWhitespaces.isSelected());
        source.setEOLMarkersVisible(showEol.isSelected());
        source.addHyperlinkListener(
            new HyperlinkListener() {
              @Override
              public void hyperlinkUpdate(HyperlinkEvent e) {
                WebUtils.browseSiteSafely(e.getURL().toExternalForm());
              }
            });
        ((RSyntaxTextAreaHighlighter) source.getHighlighter()).setDrawsLayeredHighlights(false);

        // Source code
        source.setText(libraryCode ? loadSource(entry) : loadString(entry));
        source.setCaretPosition(0);

        // "Jump to source"-like action
        source.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                // todo Fix when clicked in class "MyName" on string "MyName"
                // Additional feature to dive into related classes
                if (SwingUtilities.isMiddleMouseButton(e)
                    || SwingUtils.isCtrl(e) && SwingUtilities.isLeftMouseButton(e)) {
                  int pos = source.getUI().viewToModel(source, e.getPoint());
                  String word = TextUtils.getWord(source.getText(), pos);
                  if (word != null) {
                    JarEntry classByName = jarStructure.findEntryByName(word);
                    if (classByName != null
                        && (classByName.getType().equals(JarEntryType.classEntry)
                            || classByName.getType().equals(JarEntryType.javaEntry))) {
                      updateClassPath(classByName, true);
                    }
                  }
                }
              }
            });

        // Saving opened editor
        synchronized (activeEditorsLock) {
          activeEditors.put(entry, source);
        }

        // Special code viewer scroll pane
        RTextScrollPane sourceScroll = new RTextScrollPane(source);
        sourceScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        ((WebScrollPaneUI) sourceScroll.getUI()).setDrawBorder(false);

        // Source code viewer theme
        loadTheme(theme.getSelectedItem().toString().toLowerCase(), source);

        return sourceScroll;
      }
    }
    return new WebLabel();
  }
Beispiel #4
0
 /** Requests focus to last selected date button. */
 protected void requestFocusToSelected() {
   if (lastSelectedDayButton != null) {
     lastSelectedDayButton.requestFocusInWindow();
   }
 }
Beispiel #5
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;
  }