From a7bfa545a53dea5d34d99a3a42a5d4ec45a24552 Mon Sep 17 00:00:00 2001 From: akardapolov Date: Fri, 26 Jul 2019 20:37:47 +0500 Subject: [PATCH] feat: Add hints and tooltip for url and open jar fields --- .../java/gui/connect/ConnectToDbArea.java | 7 +++-- .../main/java/gui/custom/HintTextField.java | 29 +++++++++++++++++++ ashv/src/main/resources/messages.properties | 4 +++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 ashv/src/main/java/gui/custom/HintTextField.java diff --git a/ashv/src/main/java/gui/connect/ConnectToDbArea.java b/ashv/src/main/java/gui/connect/ConnectToDbArea.java index 0544505..913a342 100644 --- a/ashv/src/main/java/gui/connect/ConnectToDbArea.java +++ b/ashv/src/main/java/gui/connect/ConnectToDbArea.java @@ -9,6 +9,7 @@ import gui.MainTabbedPane; import gui.MonitorDbPanel; import gui.chart.ChartDatasetManager; +import gui.custom.HintTextField; import gui.util.ProgressBarUtil; import lombok.extern.slf4j.Slf4j; import net.miginfocom.swing.MigLayout; @@ -85,8 +86,8 @@ public class ConnectToDbArea extends JDialog { private JTextField connNameTF = new JTextField(); private JTextField usernameTF = new JTextField(); private JPasswordField passwordTF = new JPasswordField(); - private JTextField urlTF = new JTextField(); - private JTextField jarTF = new JTextField(); + private JTextField urlTF = new HintTextField(Labels.getLabel("gui.connection.url.hint")); + private JTextField jarTF = new HintTextField(Labels.getLabel("gui.connection.jar.hint")); private JFileChooser jarFC = new JFileChooser(); private JCheckBox isOffline = new JCheckBox(); @@ -193,12 +194,12 @@ private void init_gui(){ detailJPanel.add(separatorLbl, "gapbottom 1, span, split 2, aligny center"); detailJPanel.add(new JSeparator(), "gapleft rel, growx"); - detailJPanel.add(connNameLbl, "skip"); detailJPanel.add(connNameTF, "span, growx"); detailJPanel.add(urlLbl, "skip"); detailJPanel.add(urlTF, "span, growx"); + urlTF.setToolTipText(Labels.getLabel("gui.connection.url.tooltip")); detailJPanel.add(usernameLbl, "skip"); detailJPanel.add(usernameTF, "span, growx"); diff --git a/ashv/src/main/java/gui/custom/HintTextField.java b/ashv/src/main/java/gui/custom/HintTextField.java new file mode 100644 index 0000000..f65a80e --- /dev/null +++ b/ashv/src/main/java/gui/custom/HintTextField.java @@ -0,0 +1,29 @@ +package gui.custom; + +import javax.swing.*; +import java.awt.*; + +public class HintTextField extends JTextField { + + public HintTextField(String hint) { + _hint = hint; + } + + @Override + public void paint(Graphics g) { + super.paint(g); + if (getText().length() == 0) { + int h = getHeight(); + ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + Insets ins = getInsets(); + FontMetrics fm = g.getFontMetrics(); + int c0 = getBackground().getRGB(); + int c1 = getForeground().getRGB(); + int m = 0xfefefefe; + int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1); + g.setColor(new Color(c2, true)); + g.drawString(_hint, ins.left, h / 2 + fm.getAscent() / 2 - 2); + } + } + private final String _hint; +} diff --git a/ashv/src/main/resources/messages.properties b/ashv/src/main/resources/messages.properties index 872cfb6..6ce4f16 100644 --- a/ashv/src/main/resources/messages.properties +++ b/ashv/src/main/resources/messages.properties @@ -22,6 +22,10 @@ gui.connection.password=Password gui.connection.url=URL gui.connection.profile=Profile +gui.connection.url.hint=jdbc:oracle:thin:@host:PORT:SID +gui.connection.url.tooltip=jdbc:oracle:thin:@host:PORT:SID or jdbc:postgresql://host:PORT/db +gui.connection.jar.hint=Open JDBC Driver jar file + gui.connection.jar=JAR file gui.connection.offline=Offline gui.connection.open=JAR file