Skip to content

Commit

Permalink
feat: Add hints and tooltip for url and open jar fields
Browse files Browse the repository at this point in the history
  • Loading branch information
akardapolov committed Jul 26, 2019
1 parent 40acf32 commit a7bfa54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ashv/src/main/java/gui/connect/ConnectToDbArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
29 changes: 29 additions & 0 deletions ashv/src/main/java/gui/custom/HintTextField.java
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 4 additions & 0 deletions ashv/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7bfa54

Please sign in to comment.