package com.ruoyi.common.dev.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionListener;

public class InputField extends Box
{
    private final JTextField textField;
    private final JLabel     label;

    public InputField(String text)
    {
        super(BoxLayout.X_AXIS);
        textField = new JTextField();
        label = new JLabel(text);
        Setup();
    }

    private void Setup()
    {
        Dimension labelMinimumSize = label.getMinimumSize();
        Dimension compMinimumSize = textField.getMinimumSize();
        labelMinimumSize.width = 128;
        label.setHorizontalAlignment(SwingConstants.RIGHT);
        label.setMinimumSize(labelMinimumSize);
        label.setPreferredSize(labelMinimumSize);
        label.setMaximumSize(labelMinimumSize);
        compMinimumSize.width = 256;
        textField.setMinimumSize(compMinimumSize);
        Dimension compPreferredSize = textField.getPreferredSize();
        compPreferredSize.width = 256;
        textField.setPreferredSize(compPreferredSize);
        this.add(label);
        this.add(textField);
        this.setMinimumSize(new Dimension(labelMinimumSize.width + compMinimumSize.width, Math.max(labelMinimumSize.height, compMinimumSize.height)));
        this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Math.max(labelMinimumSize.height, compMinimumSize.height)));
    }

    public void SetToolTipText(String str)
    {
        label.setToolTipText(str);
        textField.setToolTipText(str);
    }

    public void AddActionListener(ActionListener l)
    {
        textField.addActionListener(l);
    }

    public void Reset()
    {
        textField.setText("");
    }

    public String Text()
    {
        return textField.getText();
    }

    public JTextField TextField()
    {
        return textField;
    }
}
