@Override
  public JComponent getContent() {

    if (this.obj == null) {

      throw new IllegalStateException("No object set.");
    }

    // TODO: Make this nicer later.
    if (this.obj instanceof Chapter) {

      Chapter c = (Chapter) this.obj;

      JComponent t = UIUtils.getChapterInfoPreview(c, null, this.viewer);

      if (t == null) {

        // May be a fake chapter, return null.
        return null;
      }

      t.setSize(new Dimension(300, Short.MAX_VALUE));

      return t;

    } else {

      String firstLine = "<b><i>No description.</i></b>";

      String t = (obj.getDescription() != null ? obj.getDescription().getText() : null);

      if ((t != null) && (t.length() > 0)) {

        firstLine = new Paragraph(t, 0).getFirstSentence().getText();
      }

      JEditorPane desc = UIUtils.createHelpTextPane(firstLine, null);

      FormLayout fl = new FormLayout("380px", "p");

      PanelBuilder pb = new PanelBuilder(fl);

      CellConstraints cc = new CellConstraints();

      pb.add(desc, cc.xy(1, 1));

      desc.setAlignmentX(Component.LEFT_ALIGNMENT);

      JPanel p = pb.getPanel();
      p.setOpaque(true);
      p.setBackground(UIUtils.getComponentColor());

      return p;
    }
  }
  public void doInit() {

    final InviteResponseMessageBox _this = this;

    if (!this.message.isDealtWith()) {

      // Show the response.
      this.responseBox = new Box(BoxLayout.Y_AXIS);

      this.add(this.responseBox);

      JComponent l =
          UIUtils.createBoldSubHeader(
              String.format(
                  "%s the invitation", (this.message.isAccepted() ? "Accepted" : "Rejected")),
              (this.message.isAccepted()
                  ? Constants.ACCEPTED_ICON_NAME
                  : Constants.REJECTED_ICON_NAME));

      this.responseBox.add(l);
      this.responseBox.setBorder(UIUtils.createPadding(5, 5, 0, 5));

      if (this.message.isAccepted()) {

        if ((this.message.getEditorName() != null) || (this.message.getEditorAvatar() != null)) {

          JTextPane desc =
              UIUtils.createHelpTextPane(
                  "Additionally they provided the following name/avatar.", this.projectViewer);

          this.responseBox.add(Box.createVerticalStrut(5));

          this.responseBox.add(desc);
          desc.setBorder(null);
          desc.setSize(new Dimension(UIUtils.getPopupWidth() - 20, desc.getPreferredSize().height));

          Box editorInfo = new Box(BoxLayout.X_AXIS);
          editorInfo.setAlignmentX(Component.LEFT_ALIGNMENT);
          editorInfo.setBorder(UIUtils.createPadding(5, 5, 5, 5));

          this.responseBox.add(editorInfo);

          if (this.message.getEditorAvatar() != null) {

            JLabel avatar = new JLabel();

            avatar.setAlignmentY(Component.TOP_ALIGNMENT);
            avatar.setVerticalAlignment(SwingConstants.TOP);

            editorInfo.add(avatar);
            avatar.setOpaque(false);

            avatar.setIcon(
                new ImageIcon(UIUtils.getScaledImage(_this.message.getEditorAvatar(), 50)));

            avatar.setBorder(
                new CompoundBorder(UIUtils.createPadding(0, 0, 0, 5), UIUtils.createLineBorder()));
          }

          if (this.message.getEditorName() != null) {

            JLabel name = new JLabel(this.message.getEditorName());
            editorInfo.add(name);

            name.setBorder(null);
            name.setAlignmentY(Component.TOP_ALIGNMENT);
            name.setVerticalAlignment(JLabel.TOP);
            name.setAlignmentX(Component.LEFT_ALIGNMENT);
            name.setFont(
                name.getFont()
                    .deriveFont((float) UIUtils.getScaledFontSize(14))
                    .deriveFont(java.awt.Font.PLAIN));
          }
        }
      }

      final EditorEditor ed = this.message.getEditor();

      JButton ok = new JButton("Ok, got it");

      ok.addActionListener(
          new ActionAdapter() {

            public void actionPerformed(ActionEvent ev) {

              try {

                if (_this.message.isAccepted()) {

                  ed.setEditorStatus(EditorEditor.EditorStatus.current);

                  if (_this.message.getEditorName() != null) {

                    ed.setName(_this.message.getEditorName());
                  }

                  if (_this.message.getEditorAvatar() != null) {

                    ed.setAvatar(_this.message.getEditorAvatar());
                  }

                  EditorsEnvironment.updateEditor(ed);

                  // Is this response for an invite message or just out of the blue from a web
                  // service invite?
                  if (!EditorsEnvironment.hasSentMessageOfTypeToEditor(
                      ed, InviteMessage.MESSAGE_TYPE)) {

                    EditorsEnvironment.sendUserInformationToEditor(ed, null, null, null);
                  }

                } else {

                  ed.setEditorStatus(EditorEditor.EditorStatus.rejected);

                  EditorsEnvironment.updateEditor(ed);
                }

                _this.message.setDealtWith(true);

                EditorsEnvironment.updateMessage(_this.message);

                _this.responseBox.setVisible(false);

              } catch (Exception e) {

                Environment.logError("Unable to update editor: " + ed, e);

                UIUtils.showErrorMessage(
                    _this.projectViewer,
                    "Unable to update {editor}, please contact Quoll Writer support for assitance.");

                return;
              }
            }
          });

      JButton[] buts = new JButton[] {ok};

      JPanel bb = UIUtils.createButtonBar2(buts, Component.LEFT_ALIGNMENT);
      bb.setOpaque(false);
      bb.setAlignmentX(Component.LEFT_ALIGNMENT);
      bb.setBorder(UIUtils.createPadding(5, 0, 0, 0));

      this.responseBox.add(bb);

      return;
    }

    boolean accepted = this.message.isAccepted();
    String iconName = (accepted ? Constants.ACCEPTED_ICON_NAME : Constants.REJECTED_ICON_NAME);

    String message = "Accepted invitation to be {an editor}";

    if (!accepted) {

      message = "Rejected invitation to be {an editor}";
    }

    JComponent h = UIUtils.createBoldSubHeader(message, iconName);

    this.add(h);
  }
Ejemplo n.º 3
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;
  }