Examples: ColorObject class

This agent builds a rich text item that contains one line for each Domino® color. The line identifies the Domino® color, the RGB values, and the HSL values. The line displays in the color being represented so some lines are not visible depending on the background color of the form. The form, named Colors, has two fields named Subject (text) and Body (rich text).

import lotus.domino.*;

public class JavaAgent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      // (Your code goes here) 
      Database db = agentContext.getCurrentDatabase();
      Document doc = db.createDocument();
      doc.replaceItemValue("Form", "Colors");
      doc.replaceItemValue("Subject", "Colors");
      ColorObject color = session.createColorObject();
      RichTextItem rti = doc.createRichTextItem("Body");
      RichTextStyle rts = session.createRichTextStyle();
      rts.setFontSize(12);
      rts.setBold(RichTextStyle.YES);
      for (int i=0; i<=240; i++)
      {
        color.setNotesColor(i);
        rts.setColor(i);
        rti.appendStyle(rts);
        rti.appendText(to3String(i));
        rti.addTab(1);
        rti.appendText("Red " + to3String(color.getRed()));
        rti.addTab(1);
        rti.appendText("Green " + to3String(color.getGreen()));
        rti.addTab(1);
        rti.appendText("Blue " + to3String(color.getBlue()));
        rti.addTab(1);
        rti.appendText("Hue " + to3String(color.getHue()));
        rti.addTab(1);
        rti.appendText("Saturation " + to3String(color.getSaturation()));
        rti.addTab(1);
        rti.appendText("Luminance " + to3String(color.getLuminance()));
        if (i != 240) rti.addNewLine(1);
      }
      doc.save(true, true);

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
  
  String str = new String();
  String to3String(int i)
  {
    str = str.valueOf(i);
    if (str.length() == 3);
    else if (str.length() == 2) str = "0" + str;
    else str = "00" + str;
    return(str);
  }
}