| 1 19 package org.openharmonise.him.configuration.lnf; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.LayoutManager ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.util.HashMap ; 30 31 import javax.swing.BorderFactory ; 32 import javax.swing.JComboBox ; 33 import javax.swing.JLabel ; 34 import javax.swing.JPanel ; 35 import javax.swing.JTextArea ; 36 import javax.swing.UIManager ; 37 38 import org.openharmonise.him.configuration.*; 39 40 41 50 public class LookAndFeelConfigOptions 51 extends AbstractConfigOptions 52 implements ApplyChangesListener, LayoutManager , ActionListener { 53 54 57 private JLabel m_label = null; 58 59 62 private JComboBox m_combo = null; 63 64 67 private HashMap m_options = new HashMap (); 68 69 72 private boolean m_bChanged = false; 73 74 77 private JTextArea m_autoMetadataLabel = null; 78 79 82 private JComboBox m_autoMetadataCombo = null; 83 84 87 private boolean m_bAutoMetadataChanged = false; 88 89 92 private JLabel m_optionsLabel = null; 93 94 97 private JPanel m_borderPanel = null; 98 99 public LookAndFeelConfigOptions() { 100 super(null); 101 this.setup(); 102 } 103 104 109 public LookAndFeelConfigOptions(ConfigDialog dialog) { 110 super(dialog); 111 dialog.addApplyChangesListener(this); 112 this.setup(); 113 } 114 115 119 private void setup() { 120 this.setLayout(this); 121 122 this.m_optionsLabel = new JLabel ("Look and feel"); 123 this.add(this.m_optionsLabel); 124 125 this.m_options.put("Native", new ConfigLnF( UIManager.getSystemLookAndFeelClassName(), this.m_dialog )); 126 this.m_options.put("Java", new ConfigLnF( UIManager.getCrossPlatformLookAndFeelClassName(), this.m_dialog )); 127 this.m_options.put("Modern", new ConfigSkinLnF("/themes/modernthemepack.zip", this.m_dialog)); 128 this.m_options.put("Toxic", new ConfigSkinLnF("/themes/toxicthemepack.zip", this.m_dialog)); 129 this.m_options.put("Whistler", new ConfigSkinLnF("/themes/whistlerthemepack.zip", this.m_dialog)); 130 132 this.m_combo = new JComboBox (this.m_options.keySet().toArray()); 133 134 String sValue = ConfigStore.getInstance().getPropertyValue("LnF"); 135 if(sValue!=null) { 136 this.m_combo.setSelectedItem(sValue); 137 } else { 138 this.m_combo.setSelectedItem("Whistler"); 139 } 140 this.m_combo.addActionListener(this); 141 this.m_combo.setActionCommand("LNFLIST"); 142 143 this.add(m_combo); 144 145 this.m_label = new JLabel ("Choose skin"); 146 this.add(m_label); 147 148 sValue = ConfigStore.getInstance().getPropertyValue("AUTO_METADATA_POSITION"); 149 150 this.m_autoMetadataLabel = new JTextArea ("Automatically position metadata panel?"); 151 152 String fontName = "Dialog"; 153 int fontSize = 11; 154 Font font = new Font (fontName, Font.PLAIN, fontSize); 155 this.m_autoMetadataLabel.setFont(font); 156 this.m_autoMetadataLabel.setOpaque(false); 157 this.m_autoMetadataLabel.setEditable(false); 158 this.m_autoMetadataLabel.setLineWrap(true); 159 this.add(this.m_autoMetadataLabel); 160 161 this.m_autoMetadataCombo = new JComboBox ( new String []{"Yes","No"}); 162 if(sValue!=null && sValue.equals("Yes")) { 163 this.m_autoMetadataCombo.setSelectedItem("Yes"); 164 } else if(sValue!=null && sValue.equals("No")) { 165 this.m_autoMetadataCombo.setSelectedItem("No"); 166 } else if(sValue==null) { 167 this.m_autoMetadataCombo.setSelectedItem("No"); 168 } 169 this.m_autoMetadataCombo.addActionListener(this); 170 this.m_autoMetadataCombo.setActionCommand("AUTOMETADATA"); 171 this.add(this.m_autoMetadataCombo); 172 173 this.m_borderPanel = new JPanel (); 174 this.m_borderPanel.setBorder( BorderFactory.createLineBorder(Color.BLACK) ); 175 this.add(this.m_borderPanel); 176 177 } 178 179 184 public void setStoredLnF() { 185 String sValue = ConfigStore.getInstance().getPropertyValue("LnF"); 186 if(sValue!=null) { 187 ConfigLnF lnf = (ConfigLnF) this.m_options.get(sValue); 188 if(lnf!=null) { 189 lnf.setLookAndFeel(); 190 } 191 } else { 192 ConfigLnF lnf = (ConfigLnF) this.m_options.get("Whistler"); 193 if(lnf!=null) { 194 lnf.setLookAndFeel(); 195 } 196 } 197 } 198 199 202 public void actionPerformed(ActionEvent ae) { 203 if(ae.getActionCommand().equals("LNFLIST")) { 204 this.fireChangesMade(); 205 this.m_bChanged = true; 206 } else if(ae.getActionCommand().equals("AUTOMETADATA")) { 207 this.fireChangesMade(); 208 this.m_bAutoMetadataChanged = true; 209 } 210 } 211 212 215 public boolean applyChanges() { 216 if(this.m_bChanged) { 217 ConfigLnF lnf = (ConfigLnF) this.m_options.get(this.m_combo.getSelectedItem()); 218 lnf.setLookAndFeel(); 219 ConfigStore.getInstance().setProperty("LnF", (String )this.m_combo.getSelectedItem()); 220 this.m_bChanged = false; 221 } 222 if(this.m_bAutoMetadataChanged) { 223 ConfigStore.getInstance().setProperty("AUTO_METADATA_POSITION", (String )this.m_autoMetadataCombo.getSelectedItem()); 224 this.m_bAutoMetadataChanged = false; 225 } 226 return true; 227 } 228 229 232 public Dimension getPreferredSize() { 233 return new Dimension (this.getParent().getSize().width, 100); 234 } 235 236 239 public void removeLayoutComponent(Component arg0) { 240 } 241 242 245 public void layoutContainer(Container arg0) { 246 247 this.m_optionsLabel.setSize(this.m_optionsLabel.getPreferredSize()); 248 this.m_optionsLabel.setLocation(10, 0); 249 250 this.m_borderPanel.setSize(this.getSize().width-this.m_optionsLabel.getSize().width-10, 1); 251 this.m_borderPanel.setLocation(this.m_optionsLabel.getSize().width+this.m_optionsLabel.getLocation().x + 5, this.m_optionsLabel.getLocation().y+8); 252 253 this.m_label.setSize(150, 20); 254 this.m_label.setLocation(20, 20); 255 this.m_combo.setSize(150, 20); 256 this.m_combo.setLocation(200, 20); 257 258 this.m_autoMetadataLabel.setSize(150, 50); 259 this.m_autoMetadataLabel.setLocation(20, 50); 260 this.m_autoMetadataCombo.setSize(150, 20); 261 this.m_autoMetadataCombo.setLocation(200, 50); 262 } 263 264 267 public void addLayoutComponent(String arg0, Component arg1) { 268 } 269 270 273 public Dimension minimumLayoutSize(Container arg0) { 274 return this.getPreferredSize(); 275 } 276 277 280 public Dimension preferredLayoutSize(Container arg0) { 281 return this.getPreferredSize(); 282 } 283 284 287 public void discardChanges() { 288 } 290 291 } 292 | Popular Tags |