Пример #1
0
  /**
   * Constructs an SQLPanel using a given annotation for the 'ref' part of the URL (the part after
   * the '#' character).
   *
   * @param refString the string used for annotating
   * @param refArea true to use a multi-line text area for the ref field, false for a one-line field
   */
  public SQLPanel(String refString, boolean refArea) {
    super(new BorderLayout());
    stack = new LabelledComponentStack();
    add(stack, BorderLayout.NORTH);
    Font inputFont = stack.getInputFont();

    /* Protocol input field. */
    protoField = new JComboBox();
    protoField.addItem("");
    protoField.addItem("mysql");
    protoField.addItem("postgresql");
    protoField.setEditable(true);
    protoField.setFont(inputFont);
    stack.addLine("Protocol", "jdbc:", protoField);

    /* Host input field. */
    hostField = new JComboBox();
    hostField.addItem("");
    hostField.addItem("localhost");
    hostField.setEditable(true);
    hostField.setFont(inputFont);
    stack.addLine("Host", "://", hostField);

    /* Database field. */
    dbField = new JTextField(12);
    stack.addLine("Database name", "/", dbField);

    /* Reference field in the one-line case. */
    if (!refArea) {
      refField = new JTextField(32);
      stack.addLine(refString, "#", refField);
    }

    /* Username input field. */
    userField = new JTextField(12);
    userField.setText(System.getProperty("user.name"));
    stack.addLine("User name", null, userField);

    /* Password input field. */
    passField = new JPasswordField(12);
    stack.addLine("Password", null, passField);

    /* Reference field in the multi-line case. */
    if (refArea) {
      JComponent refHolder = new JPanel(new BorderLayout());
      Box labelBox = Box.createVerticalBox();
      labelBox.add(new JLabel(refString + ": # "));
      labelBox.add(Box.createVerticalGlue());
      refHolder.add(labelBox, BorderLayout.WEST);
      refField = new JTextArea();
      refField.setFont(Font.decode("Monospaced"));
      refHolder.add(Box.createVerticalStrut(5), BorderLayout.NORTH);
      refHolder.add(new JScrollPane(refField), BorderLayout.CENTER);
      refHolder.setPreferredSize(new Dimension(400, 100));
      add(refHolder, BorderLayout.CENTER);
    }
  }
 public BaseInputTextControl(final RenderableContext renderableContext, RenderState renderState) {
   super(renderableContext);
   this.renderState = renderState;
   this.setLayout(WrapperLayout.getInstance());
   String value = renderableContext.getAttribute("value");
   JTextComponent widget = this.createTextField();
   Font font = widget.getFont();
   widget.setFont(font.deriveFont(DEFAULT_FONT_SIZE));
   widget.setDocument(new LimitedDocument());
   widget.setText(value);
   String maxLengthText = renderableContext.getAttribute("maxlength");
   if (maxLengthText != null) {
     try {
       this.maxLength = Integer.parseInt(maxLengthText);
     } catch (NumberFormatException nfe) {
       // ignore
     }
   }
   this.widget = widget;
   this.add(widget);
 }
  /** Build the interface. */
  private void buildUI() {
    if (colorEnabled) {
      JTextPane text = new JTextPane();
      this.textComponent = text;
    } else {
      JTextArea text = new JTextArea();
      this.textComponent = text;
      text.setLineWrap(true);
    }
    textComponent.addMouseListener(this);
    textComponent.setFont(getMonospaceFont());
    textComponent.setEditable(false);
    DefaultCaret caret = (DefaultCaret) textComponent.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    document = textComponent.getDocument();
    document.addDocumentListener(new LimitLinesDocumentListener(numLines, true));

    JScrollPane scrollText = new JScrollPane(textComponent);
    scrollText.setBorder(null);
    scrollText.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    add(scrollText, BorderLayout.CENTER);
  }
Пример #4
0
 /** Create an editor to represent the given document. */
 protected JTextComponent createEditor() {
   JTextComponent c = new JTextArea();
   c.setDragEnabled(true);
   c.setFont(new Font("monospaced", Font.PLAIN, 12));
   return c;
 }