Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
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;
  }