Skip to content

Commit 7a44840

Browse files
authored
Merge pull request atarw#31 from vincenzopalazzo/pull_jprogressbar
added support to RadioButtonMenuItem
2 parents 4c94c16 + 6b2ea0c commit 7a44840

File tree

7 files changed

+75
-32
lines changed

7 files changed

+75
-32
lines changed

lib/material-ui-swing.jar

780 Bytes
Binary file not shown.

src/MaterialUISwingDemo.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,7 @@
22
import mdlaf.animation.MaterialUIMovement;
33
import mdlaf.resources.MaterialColors;
44

5-
import javax.swing.JButton;
6-
import javax.swing.JCheckBox;
7-
import javax.swing.JComboBox;
8-
import javax.swing.JFrame;
9-
import javax.swing.JLabel;
10-
import javax.swing.JMenu;
11-
import javax.swing.JMenuBar;
12-
import javax.swing.JMenuItem;
13-
import javax.swing.JPanel;
14-
import javax.swing.JPasswordField;
15-
import javax.swing.JProgressBar;
16-
import javax.swing.JRadioButton;
17-
import javax.swing.JScrollPane;
18-
import javax.swing.JSlider;
19-
import javax.swing.JSpinner;
20-
import javax.swing.JTabbedPane;
21-
import javax.swing.JTable;
22-
import javax.swing.JTextField;
23-
import javax.swing.JToggleButton;
24-
import javax.swing.JToolBar;
25-
import javax.swing.JTree;
26-
import javax.swing.SpinnerListModel;
27-
import javax.swing.UIManager;
28-
import javax.swing.UnsupportedLookAndFeelException;
5+
import javax.swing.*;
296
import java.awt.BorderLayout;
307
import java.awt.Dimension;
318

@@ -52,6 +29,11 @@ public static void main (String[] args) {
5229
JMenuItem item1 = new JMenuItem ("Item 1 (Animated)");
5330
JMenuItem item2 = new JMenuItem ("Item 2 (Not animated)");
5431

32+
//Test RadioButtonMenuItem
33+
JRadioButtonMenuItem jRadioButtonMenuItem = new JRadioButtonMenuItem();
34+
jRadioButtonMenuItem.setText("prova RadioButtonMenuItem");
35+
menu1.add(jRadioButtonMenuItem);
36+
5537
menu1.add (item1);
5638
menu2.add (item2);
5739

@@ -121,6 +103,12 @@ public static void main (String[] args) {
121103
progressBar.setMaximum(12);
122104
pn.add(progressBar);
123105

106+
//test cange coloro maximum value progress bar
107+
progressBar = new JProgressBar();
108+
progressBar.setMaximum(5);
109+
progressBar.setValue(5);
110+
pn.add(progressBar);
111+
124112
// make everything visible to the world
125113
frame.pack ();
126114
frame.setVisible (true);

src/mdlaf/MaterialLookAndFeel.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import mdlaf.components.popupmenu.MaterialPopupMenuUI;
1313
import mdlaf.components.progressbar.MaterialProgressBarUI;
1414
import mdlaf.components.radiobutton.MaterialRadioButtonUI;
15+
import mdlaf.components.radiobuttonmenuitem.MaterialRadioButtonMenuItemUI;
1516
import mdlaf.components.scrollbar.MaterialScrollBarUI;
1617
import mdlaf.components.slider.MaterialSliderUI;
1718
import mdlaf.components.spinner.MaterialSpinnerUI;
@@ -55,7 +56,12 @@ public class MaterialLookAndFeel extends MetalLookAndFeel {
5556
private static final String toolbarUI = MaterialToolBarUI.class.getCanonicalName ();
5657
private static final String sliderUI = MaterialSliderUI.class.getCanonicalName ();
5758
private static final String progressBarUI = MaterialProgressBarUI.class.getCanonicalName();
58-
59+
private static final String radioButtonMenuItemUI = MaterialRadioButtonMenuItemUI.class.getCanonicalName();
60+
61+
public static String getRadioButtonMenuItemUI() {
62+
return radioButtonMenuItemUI;
63+
}
64+
5965
public static String getProgressbarui() {
6066
return progressBarUI;
6167
}
@@ -110,6 +116,7 @@ protected void initClassDefaults (UIDefaults table) {
110116
table.put ("ToolBarUI", toolbarUI);
111117
table.put ("SliderUI", sliderUI);
112118
table.put("ProgressBarUI", progressBarUI);
119+
table.put("RadioButtonMenuItemUI", radioButtonMenuItemUI);
113120
}
114121

115122
@Override
@@ -260,5 +267,8 @@ protected void initComponentDefaults (UIDefaults table) {
260267
table.put ("Tree.closedIcon", new ImageIcon (MaterialImages.RIGHT_ARROW));
261268
table.put ("Tree.openIcon", new ImageIcon (MaterialImages.DOWN_ARROW));
262269
table.put ("Tree.selectionBorderColor", null);
270+
271+
//table.put("RadioButtonMenuItem.selectedIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON));
272+
//table.put("RadioButtonMenuItem.icon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF));
263273
}
264274
}

src/mdlaf/components/progressbar/MaterialProgressBarUI.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import javax.swing.plaf.ComponentUI;
88
import javax.swing.plaf.basic.BasicProgressBarUI;
99

10+
import mdlaf.animation.MaterialUIMovement;
11+
import mdlaf.animation.MaterialUITimer;
1012
import mdlaf.resources.MaterialBorders;
1113
import mdlaf.resources.MaterialColors;
1214
import mdlaf.resources.MaterialDrawingUtils;
@@ -28,16 +30,14 @@ public void installUI(JComponent c) {
2830
super.installUI(c);
2931

3032
JProgressBar progressBar = (JProgressBar) c;
31-
c.setBorder(MaterialBorders.LIGHT_LINE_BORDER);
32-
c.setBackground(MaterialColors.GRAY_200);
33-
c.setForeground(MaterialColors.LIGHT_BLUE_400);
33+
progressBar.setBorder(MaterialBorders.LIGHT_LINE_BORDER);
34+
progressBar.setBackground(MaterialColors.GRAY_200);
35+
progressBar.setForeground(MaterialColors.LIGHT_BLUE_400);
3436
}
3537

3638
@Override
3739
public void paint(Graphics g, JComponent c) {
3840
super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c);
3941
}
40-
41-
4242

4343
}

src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/*
1313
* Contributed by https://github.com/downToHell
1414
* */
15-
1615
public class MaterialRadioButtonUI extends BasicRadioButtonUI {
1716

1817
public static ComponentUI createUI (JComponent c) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package mdlaf.components.radiobuttonmenuitem;
2+
3+
import mdlaf.resources.MaterialBorders;
4+
import mdlaf.resources.MaterialColors;
5+
import mdlaf.resources.MaterialDrawingUtils;
6+
import mdlaf.resources.MaterialImages;
7+
8+
import javax.swing.*;
9+
import javax.swing.plaf.ComponentUI;
10+
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
11+
import java.awt.*;
12+
13+
/**
14+
*
15+
* @author https://github.com/vincenzopalazzo
16+
*
17+
*/
18+
19+
public class MaterialRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI {
20+
21+
public static ComponentUI createUI(JComponent c){
22+
return new MaterialRadioButtonMenuItemUI();
23+
}
24+
25+
@Override
26+
public void installUI(JComponent c) {
27+
super.installUI(c);
28+
JRadioButtonMenuItem j = (JRadioButtonMenuItem) c;
29+
j.setBackground(MaterialColors.WHITE);
30+
j.setBorder(UIManager.getBorder ("MenuItem.border"));
31+
}
32+
33+
@Override
34+
public void paint(Graphics g, JComponent c) {
35+
super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c);
36+
}
37+
38+
@Override
39+
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
40+
JRadioButtonMenuItem j = (JRadioButtonMenuItem) c;
41+
if(j.isSelected()){
42+
super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, new ImageIcon(MaterialImages.RADIO_BUTTON_ON), arrowIcon, background, foreground, defaultTextIconGap);
43+
return;
44+
}
45+
super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, new ImageIcon(MaterialImages.RADIO_BUTTON_OFF), arrowIcon, background, foreground, defaultTextIconGap);
46+
}
47+
}

src/mdlaf/components/togglebutton/MaterialToggleButtonUI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/*
1313
* Contributed by https://github.com/downToHell
1414
* */
15-
1615
public class MaterialToggleButtonUI extends BasicToggleButtonUI {
1716

1817
public static ComponentUI createUI (JComponent c) {

0 commit comments

Comments
 (0)