| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
package org.xmlhammer.gui.preferences; |
| 24 |
|
|
| 25 |
|
import java.awt.BorderLayout; |
| 26 |
|
import java.awt.Font; |
| 27 |
|
import java.awt.event.ItemEvent; |
| 28 |
|
import java.awt.event.ItemListener; |
| 29 |
|
import java.util.ArrayList; |
| 30 |
|
|
| 31 |
|
import javax.swing.Box; |
| 32 |
|
import javax.swing.ButtonGroup; |
| 33 |
|
import javax.swing.JLabel; |
| 34 |
|
import javax.swing.JPanel; |
| 35 |
|
import javax.swing.JRadioButton; |
| 36 |
|
import javax.swing.JTextField; |
| 37 |
|
import javax.swing.LookAndFeel; |
| 38 |
|
import javax.swing.UIManager; |
| 39 |
|
import javax.swing.UIManager.LookAndFeelInfo; |
| 40 |
|
import javax.swing.border.EmptyBorder; |
| 41 |
|
|
| 42 |
|
import org.bounce.FormLayout; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
0 |
public class LookAndFeelPanel extends PreferencesPanel { |
| 52 |
|
private static final long serialVersionUID = -7714462525621553549L; |
| 53 |
|
|
| 54 |
22 |
private ArrayList<JRadioButton> buttons = null; |
| 55 |
22 |
private JRadioButton otherButton = null; |
| 56 |
22 |
private JTextField otherField = null; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
public LookAndFeelPanel() { |
| 62 |
22 |
super("Look and Feel", "preferences.laf"); |
| 63 |
|
|
| 64 |
22 |
JPanel preferences = new JPanel(new FormLayout( 5, 2)); |
| 65 |
22 |
preferences.setBorder(new EmptyBorder(0, 10, 0, 0)); |
| 66 |
|
|
| 67 |
22 |
JLabel label = new JLabel("Restart the XML Hammer application for look and feel changes to take effect."); |
| 68 |
22 |
label.setFont(label.getFont().deriveFont(Font.PLAIN)); |
| 69 |
|
|
| 70 |
22 |
preferences.add(label, FormLayout.FULL); |
| 71 |
22 |
preferences.add(Box.createVerticalStrut(10), FormLayout.FULL); |
| 72 |
|
|
| 73 |
22 |
ButtonGroup group = new ButtonGroup(); |
| 74 |
22 |
buttons = new ArrayList<JRadioButton>(); |
| 75 |
22 |
LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels(); |
| 76 |
|
|
| 77 |
110 |
for (LookAndFeelInfo info : infos) { |
| 78 |
88 |
JRadioButton button = new JRadioButton(info.getName()); |
| 79 |
88 |
buttons.add(button); |
| 80 |
88 |
group.add(button); |
| 81 |
|
|
| 82 |
88 |
preferences.add(button, FormLayout.FULL); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
22 |
JPanel otherPanel = new JPanel(new BorderLayout()); |
| 86 |
22 |
otherField = new JTextField(); |
| 87 |
22 |
otherField.setEditable(false); |
| 88 |
|
|
| 89 |
22 |
otherButton = new JRadioButton("Other"); |
| 90 |
22 |
group.add(otherButton); |
| 91 |
22 |
otherButton.addItemListener(new ItemListener() { |
| 92 |
22 |
public void itemStateChanged(ItemEvent arg0) { |
| 93 |
0 |
otherField.setEditable(otherButton.isSelected()); |
| 94 |
0 |
} |
| 95 |
|
}); |
| 96 |
|
|
| 97 |
22 |
otherPanel.add(otherButton, BorderLayout.WEST); |
| 98 |
22 |
otherPanel.add(otherField, BorderLayout.CENTER); |
| 99 |
|
|
| 100 |
22 |
preferences.add(otherPanel, FormLayout.FULL_FILL); |
| 101 |
|
|
| 102 |
22 |
setCenterPane( preferences); |
| 103 |
22 |
} |
| 104 |
|
|
| 105 |
|
public void setLookAndFeel(String lookandfeel) { |
| 106 |
22 |
otherField.setText(""); |
| 107 |
|
|
| 108 |
22 |
if (lookandfeel == null || lookandfeel.length() == 0) { |
| 109 |
22 |
LookAndFeel laf = UIManager.getLookAndFeel(); |
| 110 |
22 |
lookandfeel = laf.getClass().getName(); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
22 |
LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels(); |
| 114 |
|
|
| 115 |
22 |
for (LookAndFeelInfo info : infos) { |
| 116 |
22 |
if (info.getClassName().equals(lookandfeel)) { |
| 117 |
22 |
setSelectedButton(info.getName()); |
| 118 |
22 |
return; |
| 119 |
|
} |
| 120 |
|
} |
| 121 |
|
|
| 122 |
0 |
otherField.setText(lookandfeel); |
| 123 |
0 |
otherField.setCaretPosition(0); |
| 124 |
0 |
otherButton.setSelected(true); |
| 125 |
0 |
} |
| 126 |
|
|
| 127 |
|
public String getLookAndFeel() { |
| 128 |
22 |
LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels(); |
| 129 |
22 |
JRadioButton button = getSelectedButton(); |
| 130 |
|
|
| 131 |
22 |
if (button != null) { |
| 132 |
22 |
for (LookAndFeelInfo info : infos) { |
| 133 |
22 |
if (info.getName().equals(button.getText())) { |
| 134 |
22 |
return info.getClassName(); |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
0 |
} else if (otherButton.isSelected()) { |
| 138 |
0 |
return otherField.getText(); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
0 |
return null; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
private JRadioButton getSelectedButton() { |
| 145 |
22 |
for (JRadioButton button : buttons) { |
| 146 |
22 |
if (button.isSelected()) { |
| 147 |
22 |
return button; |
| 148 |
|
} |
| 149 |
0 |
} |
| 150 |
|
|
| 151 |
0 |
return null; |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
private void setSelectedButton(String name) { |
| 155 |
22 |
for (JRadioButton button : buttons) { |
| 156 |
22 |
if (name.equals(button.getText())) { |
| 157 |
22 |
button.setSelected(true); |
| 158 |
22 |
return; |
| 159 |
|
} |
| 160 |
0 |
} |
| 161 |
0 |
} |
| 162 |
|
} |