Skip to content

Commit a7bfa54

Browse files
committed
feat: Add hints and tooltip for url and open jar fields
1 parent 40acf32 commit a7bfa54

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

ashv/src/main/java/gui/connect/ConnectToDbArea.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import gui.MainTabbedPane;
1010
import gui.MonitorDbPanel;
1111
import gui.chart.ChartDatasetManager;
12+
import gui.custom.HintTextField;
1213
import gui.util.ProgressBarUtil;
1314
import lombok.extern.slf4j.Slf4j;
1415
import net.miginfocom.swing.MigLayout;
@@ -85,8 +86,8 @@ public class ConnectToDbArea extends JDialog {
8586
private JTextField connNameTF = new JTextField();
8687
private JTextField usernameTF = new JTextField();
8788
private JPasswordField passwordTF = new JPasswordField();
88-
private JTextField urlTF = new JTextField();
89-
private JTextField jarTF = new JTextField();
89+
private JTextField urlTF = new HintTextField(Labels.getLabel("gui.connection.url.hint"));
90+
private JTextField jarTF = new HintTextField(Labels.getLabel("gui.connection.jar.hint"));
9091
private JFileChooser jarFC = new JFileChooser();
9192
private JCheckBox isOffline = new JCheckBox();
9293

@@ -193,12 +194,12 @@ private void init_gui(){
193194
detailJPanel.add(separatorLbl, "gapbottom 1, span, split 2, aligny center");
194195
detailJPanel.add(new JSeparator(), "gapleft rel, growx");
195196

196-
197197
detailJPanel.add(connNameLbl, "skip");
198198
detailJPanel.add(connNameTF, "span, growx");
199199

200200
detailJPanel.add(urlLbl, "skip");
201201
detailJPanel.add(urlTF, "span, growx");
202+
urlTF.setToolTipText(Labels.getLabel("gui.connection.url.tooltip"));
202203

203204
detailJPanel.add(usernameLbl, "skip");
204205
detailJPanel.add(usernameTF, "span, growx");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package gui.custom;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
6+
public class HintTextField extends JTextField {
7+
8+
public HintTextField(String hint) {
9+
_hint = hint;
10+
}
11+
12+
@Override
13+
public void paint(Graphics g) {
14+
super.paint(g);
15+
if (getText().length() == 0) {
16+
int h = getHeight();
17+
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
18+
Insets ins = getInsets();
19+
FontMetrics fm = g.getFontMetrics();
20+
int c0 = getBackground().getRGB();
21+
int c1 = getForeground().getRGB();
22+
int m = 0xfefefefe;
23+
int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
24+
g.setColor(new Color(c2, true));
25+
g.drawString(_hint, ins.left, h / 2 + fm.getAscent() / 2 - 2);
26+
}
27+
}
28+
private final String _hint;
29+
}

ashv/src/main/resources/messages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ gui.connection.password=Password
2222
gui.connection.url=URL
2323
gui.connection.profile=Profile
2424

25+
gui.connection.url.hint=jdbc:oracle:thin:@host:PORT:SID
26+
gui.connection.url.tooltip=jdbc:oracle:thin:@host:PORT:SID or jdbc:postgresql://host:PORT/db
27+
gui.connection.jar.hint=Open JDBC Driver jar file
28+
2529
gui.connection.jar=JAR file
2630
gui.connection.offline=Offline
2731
gui.connection.open=JAR file

0 commit comments

Comments
 (0)