Exemple #1
0
  private void show(int _current) {
    OpenDefinitionsDocument doc = _docs.get(_current);

    String text = getTextFor(doc);

    _label.setText(_displayManager.getName(doc));
    _label.setIcon(_displayManager.getIcon(doc));

    if (text.length() > 0) {
      // as wide as the text area wants, but only 200px high
      _textpane.setText(text);
      _scroller.setPreferredSize(_textpane.getPreferredScrollableViewportSize());
      if (_scroller.getPreferredSize().getHeight() > 200)
        _scroller.setPreferredSize(
            new Dimension((int) _scroller.getPreferredSize().getWidth(), 200));

      _scroller.setVisible(_showSource);
    } else _scroller.setVisible(false);

    Dimension d = _label.getMinimumSize();
    d.setSize(d.getWidth() + _padding * 2, d.getHeight() + _padding * 2);
    _label.setPreferredSize(d);
    _label.setHorizontalAlignment(SwingConstants.CENTER);
    _label.setVerticalAlignment(SwingConstants.CENTER);
    pack();
    centerH();
  }
Exemple #2
0
  public RecentDocFrame(MainFrame f) {
    super();
    _frame = f;
    _current = 0;
    _label =
        new JLabel("...") {
          // Enable anti-aliased text by overriding paintComponent.
          protected void paintComponent(Graphics g) {
            if (_antiAliasText && g instanceof Graphics2D) {
              Graphics2D g2d = (Graphics2D) g;
              g2d.setRenderingHint(
                  RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            }
            super.paintComponent(g);
          }
        };
    _panel = new JPanel();
    _scroller = new JScrollPane();
    _textpane =
        new JTextPane() {
          // Enable anti-aliased text by overriding paintComponent.
          protected void paintComponent(Graphics g) {
            if (_antiAliasText && g instanceof Graphics2D) {
              Graphics2D g2d = (Graphics2D) g;
              g2d.setRenderingHint(
                  RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            }
            super.paintComponent(g);
          }
        };

    _textpane.setText("...");
    _scroller.getViewport().add(_textpane);
    _scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    _scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    _scroller.setMaximumSize(new Dimension(300, 200));

    _panel.setLayout(new BorderLayout());
    _panel.add(_label, BorderLayout.NORTH);
    _panel.add(_scroller, BorderLayout.SOUTH);

    getContentPane().add(_panel);
    pack();
    updateFontColor();
    _showSource = DrJava.getConfig().getSetting(OptionConstants.SHOW_SOURCE_WHEN_SWITCHING);
    DrJava.getConfig()
        .addOptionListener(OptionConstants.DEFINITIONS_BACKGROUND_COLOR, _colorListener);
    DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_NORMAL_COLOR, _colorListener);
    DrJava.getConfig().addOptionListener(OptionConstants.FONT_MAIN, _fontListener);
    DrJava.getConfig().addOptionListener(OptionConstants.TEXT_ANTIALIAS, _antialiasListener);
    DrJava.getConfig()
        .addOptionListener(OptionConstants.SHOW_SOURCE_WHEN_SWITCHING, _showSourceListener);
  }