/*
 * Copyright 2000-2017 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ui.components;

import com.intellij.util.ui.StatusText;
import org.jetbrains.annotations.NotNull;

import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

/**
* @author nik
*/
class TextComponentEmptyText extends StatusText {
  private final JTextComponent myOwner;
  private String myStatusTriggerText = "";

  public TextComponentEmptyText(JTextComponent owner) {
    super(owner);
    myOwner = owner;
    clear();
    myOwner.addFocusListener(new FocusListener() {
      @Override
      public void focusGained(FocusEvent e) {
        myOwner.repaint();
      }

      @Override
      public void focusLost(FocusEvent e) {
        myOwner.repaint();
      }
    });
  }

  public void setTextToTriggerStatus(@NotNull String defaultText) {
    myStatusTriggerText = defaultText;
  }

  @NotNull
  public String getStatusTriggerText() {
    return myStatusTriggerText;
  }

  public void paintStatusText(Graphics g) {
    getComponent().setFont(myOwner.getFont());
    if (!isVerticalFlow()) {
      getSecondaryComponent().setFont(myOwner.getFont());
    }
    paint(myOwner, g);
  }

  @Override
  protected boolean isStatusVisible() {
    return myOwner.getText().equals(myStatusTriggerText) && !myOwner.isFocusOwner();
  }

  @Override
  protected Rectangle getTextComponentBound() {
    Rectangle b = myOwner.getBounds();
    Insets insets = myOwner.getInsets();
    int left = insets.left >> 1;
    int right = insets.right >> 1;
    return new Rectangle(left, insets.top + insets.bottom,
                         b.width - left - right,
                         b.height - insets.top - insets.bottom);
  }
}

@@ -631,16 +631,88 @@
 nents;%0A%0A
+import com.intellij.util.ObjectUtils;%0Aimport com.intellij.util.ui.JBUI;%0A
 import c
@@ -2115,25 +2115,192 @@
 s = 
-myOwner.getInsets
+ObjectUtils.notNull(myOwner.getInsets(), JBUI.emptyInsets());%0A    Insets margin = ObjectUtils.notNull(myOwner.getMargin(), JBUI.emptyInsets());%0A    Insets ipad = getComponent().getIpad
 ();%0A
@@ -2326,20 +2326,41 @@
 ts.left 
-%3E%3E 1
++ margin.left - ipad.left
 ;%0A    in
@@ -2386,52 +2386,111 @@
 ght 
-%3E%3E 1;%0A    return new Rectangle(left,
++ margin.right - ipad.right;%0A    int top = insets.top + margin.top - ipad.top;%0A    int bottom =
  insets.
 top 
@@ -2489,27 +2489,80 @@
 ets.
+bot
 to
-p + insets.bottom
+m + margin.bottom - ipad.bottom;%0A    return new Rectangle(left, top
 ,%0A  
@@ -2648,28 +2648,14 @@
 t - 
-insets.top - insets.
+top - 
 bott

fix empty text positioning in text fields