Skip to content

Commit 5961df2

Browse files
add component structure
1 parent b636916 commit 5961df2

File tree

8 files changed

+117
-25
lines changed

8 files changed

+117
-25
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33

44
# Ignore Gradle build output directory
55
build
6+
7+
#IntelliJ
8+
.idea
9+
*.iml

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ dependencies {
2525
implementation("com.google.guava:guava:28.1-jre")
2626

2727
// Use JUnit test framework
28-
testImplementation("junit:junit:4.12")
28+
implementation(files("$projectDir/devlib/material-ui-swing-1.1.1-rc2.jar"))
2929
}
3.32 MB
Binary file not shown.

mock/lat_Lon.pdf

2.1 MB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.vincenzopalazzo.placeholder;
2+
3+
import javax.swing.*;
4+
import javax.swing.border.Border;
5+
import java.awt.*;
6+
7+
public class JTextFieldPlaceholder extends JPanel {
8+
9+
protected JLabel iconContainer;
10+
protected JLabel placeholder;
11+
private JSeparator separator;
12+
protected JTextField textField;
13+
14+
public JTextFieldPlaceholder() {
15+
super(new FlowLayout());
16+
initView();
17+
initStyle();
18+
}
19+
20+
protected void initView(){
21+
iconContainer = new JLabel();
22+
this.add(iconContainer);
23+
24+
placeholder = new JLabel();
25+
separator = new JSeparator(JSeparator.VERTICAL);
26+
placeholder.setBorder(BorderFactory.createEmptyBorder(5,0,5,2));
27+
this.add(placeholder);
28+
this.add(separator);
29+
30+
textField = new JTextField();
31+
textField.setMinimumSize(new Dimension(50, 20));
32+
textField.setPreferredSize(new Dimension(50, 20));
33+
textField.setSize(new Dimension(50, 20));
34+
super.add(textField);
35+
}
36+
37+
protected void initStyle(){
38+
setBackground(textField.getBackground());
39+
placeholder.setBackground(getBackground());
40+
iconContainer.setBackground(getBackground());
41+
}
42+
43+
public JTextFieldPlaceholder setIcon(Icon icon){
44+
if(icon == null) throw new IllegalArgumentException("icon null");
45+
iconContainer.setIcon(icon);
46+
return this;
47+
}
48+
49+
public JTextFieldPlaceholder setText(String text){
50+
if(text == null || text.isEmpty()) throw new IllegalArgumentException("Invalid text");
51+
placeholder.setText(text);
52+
return this;
53+
}
54+
55+
}

src/main/java/io/vincenzopalazzo/placeholder/Library.java

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.vincenzopalazzo.placeholder;
2+
3+
import jiconfont.icons.google_material_design_icons.GoogleMaterialDesignIcons;
4+
import mdlaf.MaterialLookAndFeel;
5+
import mdlaf.themes.JMarsDarkTheme;
6+
import mdlaf.utils.MaterialColors;
7+
import mdlaf.utils.MaterialImageFactory;
8+
9+
import javax.swing.*;
10+
import java.awt.*;
11+
12+
public class DemoFrame extends JFrame {
13+
14+
static {
15+
try {
16+
UIManager.setLookAndFeel(new MaterialLookAndFeel(new JMarsDarkTheme()));
17+
} catch (UnsupportedLookAndFeelException e) {
18+
e.printStackTrace();
19+
}
20+
}
21+
22+
private JPanel container;
23+
private JTextFieldPlaceholder textFieldPlaceholder;
24+
25+
public void initView() {
26+
initComponent();
27+
28+
super.setContentPane(container);
29+
super.setSize(new Dimension(400, 400));
30+
super.setTitle("New Swing component from @vincenzopalazzo");
31+
super.setLocationRelativeTo(null);
32+
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33+
super.setVisible(true);
34+
}
35+
36+
public void initComponent() {
37+
container = new JPanel();
38+
textFieldPlaceholder = new JTextFieldPlaceholder();
39+
textFieldPlaceholder.setIcon(MaterialImageFactory.getInstance().getImage(
40+
GoogleMaterialDesignIcons.BOOKMARK,
41+
MaterialColors.COSMO_DARK_GRAY
42+
))
43+
.setText("Lan/Lon")
44+
.setVisible(true);
45+
container.add(textFieldPlaceholder);
46+
}
47+
48+
public static void main(String[] args) {
49+
SwingUtilities.invokeLater(new Runnable() {
50+
@Override
51+
public void run() {
52+
DemoFrame demoFrame = new DemoFrame();
53+
demoFrame.initView();
54+
}
55+
});
56+
}
57+
}

src/test/java/io/vincenzopalazzo/placeholder/LibraryTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)