forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.6 KiB
112 lines
4.6 KiB
package com.fr.plugin.db.redis.ui.proxy; |
|
|
|
import com.fanruan.api.design.DesignKit; |
|
import com.fanruan.api.design.ui.component.UIButton; |
|
import com.fanruan.api.design.ui.component.UICheckBox; |
|
import com.fanruan.api.design.ui.component.UIIntNumberField; |
|
import com.fanruan.api.design.ui.component.UILabel; |
|
import com.fanruan.api.design.ui.component.UIPasswordField; |
|
import com.fanruan.api.design.ui.component.UITextField; |
|
import com.fanruan.api.design.ui.container.BasicPane; |
|
import com.fanruan.api.design.ui.layout.TableLayoutKit; |
|
import com.fanruan.api.design.util.GUICoreKit; |
|
import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.io.File; |
|
|
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-03-21 |
|
*/ |
|
public class RedisConnectionProxyConfigPane extends BasicPane { |
|
|
|
private UICheckBox openCheckBox; |
|
private UITextField hostTextField; |
|
private UIIntNumberField portNumberField; |
|
private UITextField usernameTextField; |
|
private UIPasswordField passwordTextField; |
|
private UITextField privateKeyPathTextField; |
|
|
|
public RedisConnectionProxyConfigPane() { |
|
setLayout(new BorderLayout()); |
|
|
|
openCheckBox = new UICheckBox(); |
|
openCheckBox.setSelected(false); |
|
|
|
hostTextField = new UITextField(); |
|
|
|
portNumberField = new UIIntNumberField(); |
|
usernameTextField = new UITextField(); |
|
passwordTextField = new UIPasswordField(); |
|
|
|
privateKeyPathTextField = new UITextField(); |
|
privateKeyPathTextField.setPlaceholder(DesignKit.i18nText("Plugin-Redis_Proxy_Private_Key_Tip")); |
|
|
|
UIButton fileSelectButton = new UIButton("..."); |
|
|
|
UILabel description = new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Description"), SwingConstants.CENTER); |
|
|
|
JComponent[][] comps = new JComponent[][]{ |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Open") + ":"), GUICoreKit.createBorderLayoutPane( |
|
openCheckBox, BorderLayout.WEST, |
|
description, BorderLayout.CENTER |
|
)}, |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Host") + ":"), hostTextField}, |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Port") + ":"), portNumberField}, |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Username") + ":"), usernameTextField}, |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Password") + ":"), passwordTextField}, |
|
{new UILabel(DesignKit.i18nText("Plugin-Redis_Proxy_Private_Key_Path") + ":"), GUICoreKit.createBorderLayoutPane( |
|
privateKeyPathTextField, BorderLayout.CENTER, |
|
fileSelectButton, BorderLayout.EAST |
|
)}, |
|
}; |
|
fileSelectButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
JFileChooser chooser = new JFileChooser(); |
|
chooser.showOpenDialog(SwingUtilities.getWindowAncestor(RedisConnectionProxyConfigPane.this)); |
|
File file = chooser.getSelectedFile(); |
|
if (file != null) { |
|
privateKeyPathTextField.setText(file.getAbsolutePath()); |
|
} |
|
} |
|
}); |
|
|
|
double p = TableLayoutKit.PREFERRED; |
|
double f = TableLayoutKit.FILL; |
|
|
|
double[] rowSize = new double[]{p, p, p, p, p, p}; |
|
double[] columnSize = new double[]{p, f}; |
|
add(TableLayoutKit.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.CENTER); |
|
|
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return DesignKit.i18nText("Plugin-Redis_Proxy_Config"); |
|
} |
|
|
|
public void populate(RedisConnectionProxyConfig config) { |
|
openCheckBox.setSelected(config.isOpen()); |
|
hostTextField.setText(config.getHost()); |
|
portNumberField.setValue(config.getPort()); |
|
usernameTextField.setText(config.getUsername()); |
|
passwordTextField.setText(config.getPassword()); |
|
privateKeyPathTextField.setText(config.getPrivateKeyPath()); |
|
} |
|
|
|
public void update(RedisConnectionProxyConfig config) { |
|
config.setOpen(openCheckBox.isSelected()); |
|
config.setHost(hostTextField.getText()); |
|
config.setPort((int) portNumberField.getValue()); |
|
config.setUsername(usernameTextField.getText()); |
|
config.setPassword(passwordTextField.getText()); |
|
config.setPrivateKeyPath(privateKeyPathTextField.getText()); |
|
} |
|
}
|
|
|