1 19 package org.openharmonise.him.configuration.sync; 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 30 import javax.swing.BorderFactory ; 31 import javax.swing.JComboBox ; 32 import javax.swing.JLabel ; 33 import javax.swing.JPanel ; 34 import javax.swing.JTextArea ; 35 36 import org.openharmonise.him.configuration.*; 37 38 39 47 public class SyncConfigOptions 48 extends AbstractConfigOptions 49 implements ApplyChangesListener, LayoutManager , ActionListener { 50 51 54 private JTextArea m_autoSyncLabel = null; 55 56 59 private JComboBox m_autoSyncCombo = null; 60 61 64 private boolean m_bAutoSyncChanged = false; 65 66 69 private JLabel m_optionsLabel = null; 70 71 74 private JPanel m_borderPanel = null; 75 76 81 public SyncConfigOptions(ConfigDialog dialog) { 82 super(dialog); 83 dialog.addApplyChangesListener(this); 84 this.setup(); 85 } 86 87 91 private void setup() { 92 this.setLayout(this); 93 94 this.m_optionsLabel = new JLabel ("Submit changes to server on exit"); 95 this.add(this.m_optionsLabel); 96 97 String [] aData = new String []{"Yes", "No"}; 98 99 String sValue = ConfigStore.getInstance().getPropertyValue("AUTO_SYNC_ON_EXIT"); 100 101 this.m_autoSyncLabel = new JTextArea ("Automatically submit all changes to the server on exit?"); 102 103 String fontName = "Dialog"; 104 int fontSize = 11; 105 Font font = new Font (fontName, Font.PLAIN, fontSize); 106 this.m_autoSyncLabel.setFont(font); 107 this.m_autoSyncLabel.setWrapStyleWord(true); 108 this.m_autoSyncLabel.setOpaque(false); 109 this.m_autoSyncLabel.setEditable(false); 110 this.m_autoSyncLabel.setLineWrap(true); 111 this.add(m_autoSyncLabel); 112 113 this.m_autoSyncCombo = new JComboBox (aData); 114 this.m_autoSyncCombo.setActionCommand("AUTOSYNC"); 115 this.m_autoSyncCombo.addActionListener(this); 116 this.add(m_autoSyncCombo); 117 if(sValue!=null) { 118 if(sValue.equals("Yes")) { 119 this.m_autoSyncCombo.setSelectedItem("Yes"); 120 } else { 121 this.m_autoSyncCombo.setSelectedItem("No"); 122 } 123 } 124 125 this.m_borderPanel = new JPanel (); 126 this.m_borderPanel.setBorder( BorderFactory.createLineBorder(Color.BLACK) ); 127 this.add(this.m_borderPanel); 128 } 129 130 133 public boolean applyChanges() { 134 if(this.m_bAutoSyncChanged) { 135 if(((String )this.m_autoSyncCombo.getSelectedItem()).equals("Yes")) { 136 ConfigStore.getInstance().setProperty("AUTO_SYNC_ON_EXIT", "Yes"); 137 } else { 138 ConfigStore.getInstance().setProperty("AUTO_SYNC_ON_EXIT", "No"); 139 } 140 this.m_bAutoSyncChanged = false; 141 } 142 return true; 143 } 144 145 148 public void discardChanges() { 149 } 151 152 155 public void layoutContainer(Container arg0) { 156 157 this.m_optionsLabel.setSize(this.m_optionsLabel.getPreferredSize()); 158 this.m_optionsLabel.setLocation(10, 0); 159 160 this.m_borderPanel.setSize(this.getSize().width-this.m_optionsLabel.getSize().width-10, 1); 161 this.m_borderPanel.setLocation(this.m_optionsLabel.getSize().width+this.m_optionsLabel.getLocation().x + 5, this.m_optionsLabel.getLocation().y+8); 162 this.m_autoSyncLabel.setSize(150, 50); 163 this.m_autoSyncLabel.setLocation(20, 20); 164 this.m_autoSyncCombo.setSize(150, 20); 165 this.m_autoSyncCombo.setLocation(200, 20); 166 } 167 168 171 public void actionPerformed(ActionEvent ae) { 172 if(ae.getActionCommand().equals("AUTOSYNC")) { 173 this.fireChangesMade(); 174 this.m_bAutoSyncChanged = true; 175 } 176 } 177 178 181 public Dimension getPreferredSize() { 182 return new Dimension (this.getParent().getSize().width, 60); 183 } 184 185 188 public void removeLayoutComponent(Component arg0) { 189 } 190 191 194 public void addLayoutComponent(String arg0, Component arg1) { 195 } 196 197 200 public Dimension minimumLayoutSize(Container arg0) { 201 return this.getPreferredSize(); 202 } 203 204 207 public Dimension preferredLayoutSize(Container arg0) { 208 return this.getPreferredSize(); 209 } 210 211 } 212 | Popular Tags |