public void updateComponents(boolean b) { GuiItem item = ((Config) Config.getInstance()).getOptionsConfig() .getGuiItem(); if (b) { // look and feel theme = item.getString(GuiItem.THEME, GuiItem.NAME); oldLookAndFeelName = theme; lfComboBox.setSelectedItem(theme); // fonts String mainName = item.getStringWithDefault(GuiItem.FONT_MAIN, GuiItem.NAME, "default"); int mainSize = item.getIntegerWithDefault(GuiItem.FONT_MAIN, GuiItem.SIZE_INT, 12); mainFont = new Font(mainName, Font.PLAIN, mainSize); String textName = item.getStringWithDefault(GuiItem.FONT_TEXT, GuiItem.NAME, "default"); int textSize = item.getIntegerWithDefault(GuiItem.FONT_TEXT, GuiItem.SIZE_INT, 12); textFont = new Font(textName, Font.PLAIN, textSize); mainFontButton.setText(mainName); mainFontButton.setFont(mainFont); textFontButton.setText(textName); textFontButton.setFont(textFont); boolean overwrite = item.getBooleanWithDefault(GuiItem.FONT, GuiItem.OVERWRITE_BOOL, false); overwriteCheckBox.setSelected(overwrite); // enable/disable button, too textFontButton.setEnabled(overwrite); textFontLabel.setEnabled(overwrite); mainFontButton.setEnabled(overwrite); mainFontLabel.setEnabled(overwrite); // language Locale[] available = GlobalResourceLoader.getAvailableLocales(); languageComboBox.setModel(new DefaultComboBoxModel(available)); // select Locale in ComboBox for (int i = 0; i < available.length; i++) { if (available[i].equals(Locale.getDefault())) { languageComboBox.setSelectedIndex(i); break; } } boolean enableText = item.getBooleanWithDefault(GuiItem.TOOLBAR, GuiItem.ENABLE_TEXT_BOOL, true); boolean alignment = item.getBooleanWithDefault(GuiItem.TOOLBAR, GuiItem.TEXT_POSITION_BOOL, true); if (enableText) { toolbarComboBox.setSelectedIndex(alignment ? 1 : 2); } proxyHost = System.getProperty("http.proxyHost"); String proxyPortString = System.getProperty("http.proxyPort", "-1"); proxyPort = Integer.parseInt(proxyPortString); updateProxyButtonText(); } else { // fonts item.setString(GuiItem.FONT_MAIN, GuiItem.NAME, getMainFont() .getName()); item.setInteger(GuiItem.FONT_MAIN, GuiItem.SIZE_INT, getMainFont() .getSize()); item.setString(GuiItem.FONT_TEXT, GuiItem.NAME, getTextFont() .getName()); item.setInteger(GuiItem.FONT_TEXT, GuiItem.SIZE_INT, getTextFont() .getSize()); item.setBoolean(GuiItem.FONT, GuiItem.OVERWRITE_BOOL, overwriteCheckBox.isSelected()); // notify all listeners // @see org.columba.core.gui.util.FontProperties // @see org.columba.mail.gui.message.TextViewer // @see org.columba.mail.gui.composer.text.TextEditorController item.getElement("fonts").notifyObservers(); // look and feel item.setString(GuiItem.THEME, GuiItem.NAME, (String) lfComboBox .getSelectedItem()); // remember if Look And Feel has been changed if (!oldLookAndFeelName.equals((String) lfComboBox .getSelectedItem())) restartRequired = true; // get language configuration XmlElement locale = Config.getInstance().get("options").getElement( "/options/locale"); // set language config based on selected item Locale l = (Locale) languageComboBox.getSelectedItem(); locale.addAttribute("language", l.getLanguage()); locale.addAttribute("country", l.getCountry()); locale.addAttribute("variant", l.getVariant()); int state = toolbarComboBox.getSelectedIndex(); if (state == 0) { item.setBoolean(GuiItem.TOOLBAR, GuiItem.ENABLE_TEXT_BOOL, false); } else { item .setBoolean(GuiItem.TOOLBAR, GuiItem.ENABLE_TEXT_BOOL, true); item.setBoolean(GuiItem.TOOLBAR, GuiItem.TEXT_POSITION_BOOL, state == 1 ? true : false); } XmlElement options = Config.getInstance().get("options") .getElement("/options"); XmlElement proxy = options.getElement("proxy"); if (proxyHost != null && proxyPort > 0) { System.setProperty("http.proxyHost", proxyHost); System.setProperty("http.proxyPort", Integer .toString(proxyPort)); if (proxy == null) { proxy = options.addSubElement("proxy"); } proxy.addAttribute("host", proxyHost); proxy.addAttribute("port", Integer.toString(proxyPort)); } else { Properties properties = System.getProperties(); properties.remove("http.proxyHost"); properties.remove("http.proxyPort"); if (proxy != null) { options.removeElement(proxy); } } } }
protected void initComponents() { defaultAccountCheckBox = new CheckBoxWithMnemonic(MailResourceLoader .getString("dialog", "account", "use_default_account_settings")); defaultAccountCheckBox.setActionCommand("DEFAULT_ACCOUNT"); defaultAccountCheckBox.addActionListener(this); // defaultAccountCheckBox.setEnabled(false); typeLabel = new LabelWithMnemonic(MailResourceLoader.getString( "dialog", "account", "server_type")); typeComboBox = new JComboBox(); typeComboBox.addItem("POP3"); typeComboBox.addItem("IMAP4"); if (accountItem.isPopAccount()) { typeComboBox.setSelectedIndex(0); } else { typeComboBox.setSelectedIndex(1); } typeLabel.setLabelFor(typeComboBox); typeComboBox.setEnabled(false); // TODO (@author fdietz): i18n typeDescriptionLabel = new JLabel( "Description: To connect to and fetch new messages from a POP3-server."); typeDescriptionLabel.setEnabled(false); loginLabel = new LabelWithMnemonic(MailResourceLoader.getString( "dialog", "account", "login")); loginTextField = new JTextField(); loginLabel.setLabelFor(loginTextField); passwordTextField = new JTextField(); hostLabel = new LabelWithMnemonic(MailResourceLoader.getString( "dialog", "account", IncomingItem.HOST)); hostTextField = new JTextField(); hostLabel.setLabelFor(hostTextField); portLabel = new LabelWithMnemonic(MailResourceLoader.getString( "dialog", "account", IncomingItem.PORT)); portSpinner = new JSpinner(new SpinnerNumberModel(100, 1, 65535, 1)); portSpinner.setEditor(new JSpinner.NumberEditor(portSpinner, "#####")); portLabel.setLabelFor(portSpinner); storePasswordCheckBox = new CheckBoxWithMnemonic(MailResourceLoader .getString("dialog", "account", "store_password_in_configuration_file")); storePasswordCheckBox.setActionCommand("SAVE"); storePasswordCheckBox.addActionListener(this); secureCheckBox = new CheckBoxWithMnemonic(MailResourceLoader.getString( "dialog", "account", "use_SSL_for_secure_connection")); secureCheckBox.setActionCommand("SSL"); secureCheckBox.addActionListener(this); authenticationLabel = new LabelWithMnemonic(MailResourceLoader .getString("dialog", "account", "authentication_type")); authenticationComboBox = new JComboBox(); authenticationComboBox .setRenderer(new AuthenticationListCellRenderer()); authenticationLabel.setLabelFor(authenticationComboBox); updateAuthenticationComboBox(); checkAuthMethods = new ButtonWithMnemonic(MailResourceLoader.getString( "dialog", "account", "authentication_checkout_methods")); checkAuthMethods.setActionCommand("CHECK_AUTHMETHODS"); checkAuthMethods.addActionListener(this); sslComboBox = new JComboBox(); if (isPopAccount()) { sslComboBox.addItem(MailResourceLoader.getString("dialog", "account", "pop3s_in_checkbox")); } else { sslComboBox.addItem(MailResourceLoader.getString("dialog", "account", "imaps_in_checkbox")); } sslComboBox.addItem(MailResourceLoader.getString("dialog", "account", "tls_in_checkbox")); sslComboBox.setActionCommand("SSL"); sslComboBox.addActionListener(this); }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/core/src/main/java/org/columba/core/gui/config/GeneralOptionsDialog.java File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/gui/config/account/IncomingServerPanel.java
Method name: void updateComponents(boolean) Method name: void initComponents()
Number of AST nodes: 1 Number of AST nodes: 3
1
public void updateComponents(boolean b) {
1
protected void initComponents() {
2
2
		defaultAccountCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
3
		GuiItem item = ((Config) Config.getInstance()).getOptionsConfig()
3
				.getString("dialog", "account", "use_default_account_settings"));
4
				.getGuiItem();
4
5
5
		defaultAccountCheckBox.setActionCommand("DEFAULT_ACCOUNT");
6
		if (b) {
6
		defaultAccountCheckBox.addActionListener(this);
7
			// look and feel
7
8
			theme = item.getString(GuiItem.THEME, GuiItem.NAME);
8
		// defaultAccountCheckBox.setEnabled(false);
9
			oldLookAndFeelName = theme;
9
		typeLabel = new LabelWithMnemonic(MailResourceLoader.getString(
10
10
				"dialog", "account", "server_type"));
11
			lfComboBox.setSelectedItem(theme);
11
12
12
		typeComboBox = new JComboBox();
13
			// fonts
13
		typeComboBox.addItem("POP3");
14
			String mainName = item.getStringWithDefault(GuiItem.FONT_MAIN,
14
		typeComboBox.addItem("IMAP4");
15
					GuiItem.NAME, "default");
15
16
			int mainSize = item.getIntegerWithDefault(GuiItem.FONT_MAIN,
16
		if (accountItem.isPopAccount()) {
17
					GuiItem.SIZE_INT, 12);
17
			typeComboBox.setSelectedIndex(0);
18
			mainFont = new Font(mainName, Font.PLAIN, mainSize);
18
		} else {
19
19
			typeComboBox.setSelectedIndex(1);
20
			String textName = item.getStringWithDefault(GuiItem.FONT_TEXT,
20
		}
21
					GuiItem.NAME, "default");
21
22
			int textSize = item.getIntegerWithDefault(GuiItem.FONT_TEXT,
22
		typeLabel.setLabelFor(typeComboBox);
23
					GuiItem.SIZE_INT, 12);
23
		typeComboBox.setEnabled(false);
24
			textFont = new Font(textName, Font.PLAIN, textSize);
24
25
25
		// TODO (@author fdietz):  i18n
26
			mainFontButton.setText(mainName);
26
		typeDescriptionLabel = new JLabel(
27
			mainFontButton.setFont(mainFont);
27
				"Description: To connect to and fetch new messages from a POP3-server.");
28
			textFontButton.setText(textName);
28
		typeDescriptionLabel.setEnabled(false);
29
			textFontButton.setFont(textFont);
29
30
30
		loginLabel = new LabelWithMnemonic(MailResourceLoader.getString(
31
			boolean overwrite = item.getBooleanWithDefault(GuiItem.FONT,
31
				"dialog", "account", "login"));
32
					GuiItem.OVERWRITE_BOOL, false);
32
33
33
		loginTextField = new JTextField();
34
			overwriteCheckBox.setSelected(overwrite);
34
		loginLabel.setLabelFor(loginTextField);
35
35
36
			// enable/disable button, too
36
		passwordTextField = new JTextField();
37
			textFontButton.setEnabled(overwrite);
37
38
			textFontLabel.setEnabled(overwrite);
38
		hostLabel = new LabelWithMnemonic(MailResourceLoader.getString(
39
			mainFontButton.setEnabled(overwrite);
39
				"dialog", "account", IncomingItem.HOST));
40
			mainFontLabel.setEnabled(overwrite);
40
41
41
		hostTextField = new JTextField();
42
			// language
42
		hostLabel.setLabelFor(hostTextField);
43
			Locale[] available = GlobalResourceLoader.getAvailableLocales();
43
44
			languageComboBox.setModel(new DefaultComboBoxModel(available));
44
		portLabel = new LabelWithMnemonic(MailResourceLoader.getString(
45
45
				"dialog", "account", IncomingItem.PORT));
46
			// select Locale in ComboBox
46
47
			for (int i = 0; i < available.length; i++) {
47
		portSpinner = new JSpinner(new SpinnerNumberModel(100, 1, 65535, 1));
48
				if (available[i].equals(Locale.getDefault())) {
48
		portSpinner.setEditor(new JSpinner.NumberEditor(portSpinner, "#####"));
49
					languageComboBox.setSelectedIndex(i);
49
		portLabel.setLabelFor(portSpinner);
50
					break;
50
51
				}
51
		storePasswordCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
52
			}
52
				.getString("dialog", "account",
53
53
						"store_password_in_configuration_file"));
54
			boolean enableText = item.getBooleanWithDefault(GuiItem.TOOLBAR,
54
55
					GuiItem.ENABLE_TEXT_BOOL, true);
55
		storePasswordCheckBox.setActionCommand("SAVE");
56
56
		storePasswordCheckBox.addActionListener(this);
57
			boolean alignment = item.getBooleanWithDefault(GuiItem.TOOLBAR,
57
58
					GuiItem.TEXT_POSITION_BOOL, true);
58
		secureCheckBox = new CheckBoxWithMnemonic(MailResourceLoader.getString(
59
59
				"dialog", "account", "use_SSL_for_secure_connection"));
60
			if (enableText) {
60
		secureCheckBox.setActionCommand("SSL");
61
				toolbarComboBox.setSelectedIndex(alignment ? 1 : 2);
61
		secureCheckBox.addActionListener(this);
62
			}
62
63
63
		authenticationLabel = new LabelWithMnemonic(MailResourceLoader
64
			proxyHost = System.getProperty("http.proxyHost");
64
				.getString("dialog", "account", "authentication_type"));
65
			String proxyPortString = System.getProperty("http.proxyPort", "-1");
65
66
			proxyPort = Integer.parseInt(proxyPortString);
66
		authenticationComboBox = new JComboBox();
67
			updateProxyButtonText();
67
		authenticationComboBox
68
		} else {
68
				.setRenderer(new AuthenticationListCellRenderer());
69
			// fonts
69
		authenticationLabel.setLabelFor(authenticationComboBox);
70
			item.setString(GuiItem.FONT_MAIN, GuiItem.NAME, getMainFont()
70
71
					.getName());
71
		updateAuthenticationComboBox();
72
			item.setInteger(GuiItem.FONT_MAIN, GuiItem.SIZE_INT, getMainFont()
72
73
					.getSize());
73
		checkAuthMethods = new ButtonWithMnemonic(MailResourceLoader.getString(
74
74
				"dialog", "account", "authentication_checkout_methods"));
75
			item.setString(GuiItem.FONT_TEXT, GuiItem.NAME, getTextFont()
75
		checkAuthMethods.setActionCommand("CHECK_AUTHMETHODS");
76
					.getName());
76
		checkAuthMethods.addActionListener(this);
77
			item.setInteger(GuiItem.FONT_TEXT, GuiItem.SIZE_INT, getTextFont()
77
78
					.getSize());
78
		sslComboBox = new JComboBox();
79
79
		if (isPopAccount()) {
80
			item.setBoolean(GuiItem.FONT, GuiItem.OVERWRITE_BOOL,
80
			sslComboBox.addItem(MailResourceLoader.getString("dialog",
81
					overwriteCheckBox.isSelected());
81
					"account", "pop3s_in_checkbox"));
82
82
		} else {
83
			// notify all listeners
83
			sslComboBox.addItem(MailResourceLoader.getString("dialog",
84
			// @see org.columba.core.gui.util.FontProperties
84
					"account", "imaps_in_checkbox"));
85
			// @see org.columba.mail.gui.message.TextViewer
85
		}
86
			// @see org.columba.mail.gui.composer.text.TextEditorController
86
		sslComboBox.addItem(MailResourceLoader.getString("dialog", "account",
87
			item.getElement("fonts").notifyObservers();
87
				"tls_in_checkbox"));
88
88
		sslComboBox.setActionCommand("SSL");
89
			// look and feel
89
		sslComboBox.addActionListener(this);
90
			item.setString(GuiItem.THEME, GuiItem.NAME, (String) lfComboBox
90
	}
91
					.getSelectedItem());
92
93
			// remember if Look And Feel has been changed
94
			if (!oldLookAndFeelName.equals((String) lfComboBox
95
					.getSelectedItem()))
96
				restartRequired = true;
97
98
			// get language configuration
99
			XmlElement locale = Config.getInstance().get("options").getElement(
100
					"/options/locale");
101
102
			// set language config based on selected item
103
			Locale l = (Locale) languageComboBox.getSelectedItem();
104
			locale.addAttribute("language", l.getLanguage());
105
			locale.addAttribute("country", l.getCountry());
106
			locale.addAttribute("variant", l.getVariant());
107
108
			int state = toolbarComboBox.getSelectedIndex();
109
			if (state == 0) {
110
				item.setBoolean(GuiItem.TOOLBAR, GuiItem.ENABLE_TEXT_BOOL,
111
						false);
112
113
			} else {
114
				item
115
						.setBoolean(GuiItem.TOOLBAR, GuiItem.ENABLE_TEXT_BOOL,
116
								true);
117
118
				item.setBoolean(GuiItem.TOOLBAR, GuiItem.TEXT_POSITION_BOOL,
119
						state == 1 ? true : false);
120
121
			}
122
123
			XmlElement options = Config.getInstance().get("options")
124
					.getElement("/options");
125
126
			XmlElement proxy = options.getElement("proxy");
127
			if (proxyHost != null && proxyPort > 0) {
128
				System.setProperty("http.proxyHost", proxyHost);
129
				System.setProperty("http.proxyPort", Integer
130
						.toString(proxyPort));
131
				if (proxy == null) {
132
					proxy = options.addSubElement("proxy");
133
				}
134
				proxy.addAttribute("host", proxyHost);
135
				proxy.addAttribute("port", Integer.toString(proxyPort));
136
			} else {
137
				Properties properties = System.getProperties();
138
				properties.remove("http.proxyHost");
139
				properties.remove("http.proxyPort");
140
				if (proxy != null) {
141
					options.removeElement(proxy);
142
				}
143
			}
144
		}
145
	}
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.500
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    31
    toolbarComboBox.setSelectedIndex(alignment ? 1 : 2);
    31
    toolbarComboBox.setSelectedIndex(alignment ? 1 : 2);
    8
    if (accountItem.isPopAccount())
    Differences
    Expression1Expression2Difference
    alignmentaccountItem.isPopAccount()TYPE_COMPATIBLE_REPLACEMENT
    toolbarComboBoxtypeComboBoxVARIABLE_NAME_MISMATCH
    toolbarComboBoxtypeComboBoxVARIABLE_NAME_MISMATCH
    10LITERAL_VALUE_MISMATCH
    21LITERAL_VALUE_MISMATCH
    8
    if (accountItem.isPopAccount())
                                                                            
    9
    typeComboBox.setSelectedIndex(0);
    Differences
    Expression1Expression2Difference
    toolbarComboBoxtypeComboBoxVARIABLE_NAME_MISMATCH
    10LITERAL_VALUE_MISMATCH
    9
    typeComboBox.setSelectedIndex(0);
            
    else
                                                                              
    10
    typeComboBox.setSelectedIndex(1);
    Differences
    Expression1Expression2Difference
    toolbarComboBoxtypeComboBoxVARIABLE_NAME_MISMATCH
    21LITERAL_VALUE_MISMATCH
    10
    typeComboBox.setSelectedIndex(1);
    Precondition Violations (0)
    Row Violation