Пример #1
0
public class Header extends Box {

  // orig: public static Color defaultPaintLeftColor = new Color (112, 149, 226);
  public static Color defaultPaintLeftColor = UIUtils.getColor("#516CA3");

  // public static Color defaultPaintLeftColor = new Color (77, 122, 244);
  public static Color defaultPaintRightColor = null;
  public static Insets defaultPadding = new Insets(3, 3, 3, 3);

  /*
  public static Font defaultFont = new Font ("Tahoma",
                                             Font.BOLD,
                                             12);
   */
  public static Color defaultTitleColor = Color.WHITE;

  private JLabel label = null;
  private PaintProvider paintProvider = null;
  private Component controls = null;

  public Header(String title, Icon icon, Component controls) {

    this();

    this.setTitle(title);
    this.setIcon(icon);

    this.setControls(controls);
  }

  public Header() {

    super(BoxLayout.LINE_AXIS);

    this.label = new JLabel();

    this.label.setAlignmentY(Component.TOP_ALIGNMENT);
    this.label.setOpaque(false);
    // this.label.setVerticalAlignment (SwingConstants.TOP);

    // this.label.setVerticalTextPosition (SwingConstants.TOP);

    this.add(this.label);
    this.add(Box.createHorizontalGlue());

    this.paintProvider =
        new GradientPainter(Header.defaultPaintLeftColor, Header.defaultPaintRightColor);

    this.setPadding(Header.defaultPadding);

    Font f = this.getFont().deriveFont(Font.BOLD, 14);

    this.setFont(f);
    this.setTitleColor(Header.defaultTitleColor);
  }

  public void setLabel(JLabel l) {

    this.label = l;
    this.label.setOpaque(false);

    this.remove(0);

    this.add(this.label, 0);

    this.validate();
    this.repaint();
  }

  public Component getControls() {

    return this.controls;
  }

  public void setControls(Component c) {

    if (c == null) {

      return;
    }

    if (c instanceof JComponent) {

      ((JComponent) c).setAlignmentY(Component.TOP_ALIGNMENT);
    }

    int ind = -1;

    if (this.controls != null) {

      for (int i = 0; i < this.getComponentCount(); i++) {

        if (this.getComponent(i) == this.controls) {

          ind = i;

          break;
        }
      }
    }

    if (ind > -1) {

      this.remove(ind);

      this.add(c, ind);

    } else {

      this.add(c);
    }

    this.controls = c;

    this.validate();
    this.repaint();
  }

  public JLabel getLabel() {

    return this.label;
  }

  public void setPadding(Insets i) {

    if (i == null) {

      this.setBorder(null);

      return;
    }

    this.setBorder(new EmptyBorder(i));
  }

  public Header getClone(String title, Icon icon, Component controls) {

    Header n = new Header(title, icon, controls);

    n.setTitleColor(this.label.getForeground());
    n.setPaintProvider(this.getPaintProvider().getClone());
    n.setFont(this.label.getFont());

    return n;
  }

  public Dimension getMaximumSize() {

    return new Dimension(Short.MAX_VALUE, this.getPreferredSize().height);
  }

  public Dimension getMinimumSize() {

    return new Dimension(
        this.label.getPreferredSize().width
            + 5
            + ((this.controls != null) ? this.controls.getMinimumSize().width : 0),
        this.getPreferredSize().height);
  }

  public PaintProvider getPaintProvider() {

    return this.paintProvider;
  }

  public void setPaintProvider(PaintProvider p) {

    this.paintProvider = p;
  }

  public String getTitle() {

    return this.label.getText();
  }

  public Icon getIcon() {

    return this.label.getIcon();
  }

  public void setIcon(Icon i) {

    this.label.setIcon(i);
  }

  public void setTitleColor(Color c) {

    this.label.setForeground(c);
  }

  public void setTitle(String t) {

    this.label.setText(
        String.format("<html>%s</html>", com.quollwriter.Environment.replaceObjectNames(t)));
  }

  public Font getFont() {

    return this.label.getFont();
  }

  public void setFont(Font f) {

    this.label.setFont(f);
  }

  public void setFontSize(float i) {

    this.label.setFont(this.label.getFont().deriveFont(i));
  }

  public void setBold(boolean b) {

    this.label.setFont(this.label.getFont().deriveFont((b ? Font.BOLD : Font.PLAIN)));
  }

  protected void paintComponent(Graphics g) {

    if (this.paintProvider != null) {

      Paint p = this.paintProvider.getPaint(this);

      Graphics2D g2d = (Graphics2D) g;

      int w = this.getWidth();
      int h = this.getHeight();

      g2d.setPaint(p);
      g2d.fillRect(0, 0, w, h);

      this.setOpaque(false);
    }

    super.paintComponent(g);

    // this.setOpaque (true);

  }

  public static Header createBoldSubHeader(String title, ImageIcon icon) {

    Header h = new Header(title, ((icon == null) ? null : icon), null);

    h.setFont(h.getFont().deriveFont(Font.BOLD, 12f));
    // h.setTitleColor (Color.BLACK);
    // h.setOpaque (false);
    // h.setBackground (new Color (0, 0, 0, 0));
    // h.setPaintProvider (null);

    h.setAlignmentX(Component.LEFT_ALIGNMENT);

    h.setBorder(new EmptyBorder(3, 3, 3, 3));

    return h;
  }
}
Пример #2
0
  public WizardStep getStage(String stage) {

    final WhatsNew _this = this;

    WizardStep ws = new WizardStep();

    int ind = stage.indexOf(":");

    Version v = new Version(stage.substring(0, ind));

    int lind = Integer.parseInt(stage.substring(ind + 1));

    java.util.List<WhatsNewItem> its = this.items.get(v);

    if (its == null) {

      return null;
    }

    WhatsNewItem item = its.get(lind);

    if (item == null) {

      return null;
    }

    ws.title = item.title;
    ws.helpText = this.getFirstHelpText();

    if ((item.description != null) || (item.component != null)) {

      final Box b = new Box(BoxLayout.Y_AXIS);

      if (item.description != null) {

        JTextPane hp = UIUtils.createHelpTextPane(item.description, this.projectViewer);

        hp.setBorder(null);
        hp.setSize(new Dimension(UIUtils.getPopupWidth() - 25, 500));

        Box hpb = new Box(BoxLayout.Y_AXIS);
        hpb.add(hp);
        hpb.setMaximumSize(hpb.getPreferredSize());
        hpb.setBorder(UIUtils.createPadding(0, 5, 0, 0));
        b.add(hpb);
      }

      if (item.component != null) {

        if (item.description != null) {

          b.add(Box.createVerticalStrut(5));
        }

        item.component.setAlignmentY(Component.TOP_ALIGNMENT);
        item.component.setBorder(UIUtils.createPadding(5, 10, 0, 0));

        b.add(item.component);
      }

      b.add(Box.createVerticalGlue());

      ws.panel = b;
    }

    return ws;
  }
Пример #3
0
  public TextArea(String placeholder, int rows, int maxChars) {

    super(BoxLayout.Y_AXIS);

    this.text = UIUtils.createTextArea(rows);

    if (placeholder != null) {

      this.placeholder = Environment.replaceObjectNames(placeholder);
      this.text.setText(this.placeholder);
      this.text.setForeground(UIUtils.getHintTextColor());
    }

    this.maxChars = maxChars;

    final TextArea _this = this;

    final JLabel maxText = new JLabel("Max " + Environment.formatNumber(maxChars) + " characters");
    maxText.setForeground(UIUtils.getHintTextColor());

    this.scrollPane = UIUtils.createScrollPane((JComponent) this.text);

    this.text.addKeyListener(
        new KeyAdapter() {

          public void keyPressed(KeyEvent ev) {

            if (_this.text.getForeground() != Color.BLACK) {

              _this.text.setText("");
            }

            _this.text.setForeground(Color.BLACK);

            if (_this.maxChars <= 0) {

              return;
            }

            maxText.setForeground(UIUtils.getHintTextColor());

            int l = _this.text.getText().trim().length();

            String t = "Max " + Environment.formatNumber(_this.maxChars) + " characters";

            if (l > 0) {

              if (l > 5000) {

                t += ", over " + Environment.formatNumber(_this.maxChars) + " characters";
                maxText.setForeground(Color.RED);

              } else {

                t += ", " + Environment.formatNumber((5000 - l)) + " remaining";
              }
            }

            maxText.setText(t);
          }
        });

    this.text.addMouseListener(
        new MouseEventHandler() {

          @Override
          public void mouseEntered(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() != Color.BLACK)) {

              _this.text.getCaret().setDot(0);
            }

            if (_this.isAutoGrabFocus()) {

              _this.text.grabFocus();
            }
          }

          @Override
          public void handlePress(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() == Color.BLACK)) {

              return;
            }

            _this.text.setText("");
            _this.text.setForeground(Color.BLACK);
          }
        });

    this.add(this.scrollPane);

    this.add(maxText);

    if (this.maxChars <= 0) {

      maxText.setVisible(false);
    }
  }