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); } } } }
public void updateComponents(boolean b) { if (b) { IFilterRule filterRule = destFolder.getFilter().getFilterRule(); String value = filterRule.getCondition(); if (value.equals("matchall")) { condList.setSelectedIndex(0); } else { condList.setSelectedIndex(1); } boolean isInclude = Boolean.valueOf( destFolder.getConfiguration().getString("property", "include_subfolders")).booleanValue(); includeSubfolderButton.setSelected(isInclude); String uid = destFolder.getConfiguration().getString("property", "source_uid"); IMailFolder f = (IMailFolder) FolderTreeModel.getInstance() .getFolder(uid); // If f==null because of deleted AbstractMessageFolder fallback to // Inbox if (f == null) { uid = "101"; destFolder.getConfiguration().setString("property", "source_uid", uid); f = (IMailbox) FolderTreeModel.getInstance().getFolder(uid); } selectButton.setText(f.getTreePath()); criteriaList.updateComponents(b); } else { // get values from components IFilterRule filterRule = destFolder.getFilter().getFilterRule(); int index = condList.getSelectedIndex(); if (index == 0) { filterRule.setCondition("matchall"); } else { filterRule.setCondition("matchany"); } if (includeSubfolderButton.isSelected()) { destFolder.getConfiguration().setString("property", "include_subfolders", "true"); } else { destFolder.getConfiguration().setString("property", "include_subfolders", "false"); } String path = selectButton.getText(); TreeNodeList list = new TreeNodeList(path); IMailFolder folder = (IMailFolder) FolderTreeModel.getInstance() .getFolder(list); String uid = folder.getId(); destFolder.getConfiguration().setString("property", "source_uid", uid); criteriaList.updateComponents(b); } }
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/search/SearchFrame.java
Method name: void updateComponents(boolean) Method name: void updateComponents(boolean)
Number of AST nodes: 1 Number of AST nodes: 3
1
public void updateComponents(boolean b) {
1
public void updateComponents(boolean b) {
2
2
		if (b) {
3
		GuiItem item = ((Config) Config.getInstance()).getOptionsConfig()
3
			IFilterRule filterRule = destFolder.getFilter().getFilterRule();
4
				.getGuiItem();
4
			String value = filterRule.getCondition();
5
5
6
		if (b) {
6
			if (value.equals("matchall")) {
7
			// look and feel
7
				condList.setSelectedIndex(0);
8
			theme = item.getString(GuiItem.THEME, GuiItem.NAME);
8
			} else {
9
			oldLookAndFeelName = theme;
9
				condList.setSelectedIndex(1);
10
10
			}
11
			lfComboBox.setSelectedItem(theme);
11
12
12
			boolean isInclude = Boolean.valueOf(
13
			// fonts
13
					destFolder.getConfiguration().getString("property",
14
			String mainName = item.getStringWithDefault(GuiItem.FONT_MAIN,
14
							"include_subfolders")).booleanValue();
15
					GuiItem.NAME, "default");
15
16
			int mainSize = item.getIntegerWithDefault(GuiItem.FONT_MAIN,
16
			includeSubfolderButton.setSelected(isInclude);
17
					GuiItem.SIZE_INT, 12);
17
18
			mainFont = new Font(mainName, Font.PLAIN, mainSize);
18
			String uid = destFolder.getConfiguration().getString("property",
19
19
					"source_uid");
20
			String textName = item.getStringWithDefault(GuiItem.FONT_TEXT,
20
21
					GuiItem.NAME, "default");
21
			IMailFolder f = (IMailFolder) FolderTreeModel.getInstance()
22
			int textSize = item.getIntegerWithDefault(GuiItem.FONT_TEXT,
22
					.getFolder(uid);
23
					GuiItem.SIZE_INT, 12);
23
24
			textFont = new Font(textName, Font.PLAIN, textSize);
24
			// If f==null because of deleted AbstractMessageFolder fallback to
25
25
			// Inbox
26
			mainFontButton.setText(mainName);
26
			if (f == null) {
27
			mainFontButton.setFont(mainFont);
27
				uid = "101";
28
			textFontButton.setText(textName);
28
				destFolder.getConfiguration().setString("property",
29
			textFontButton.setFont(textFont);
29
						"source_uid", uid);
30
30
				f = (IMailbox) FolderTreeModel.getInstance().getFolder(uid);
31
			boolean overwrite = item.getBooleanWithDefault(GuiItem.FONT,
31
			}
32
					GuiItem.OVERWRITE_BOOL, false);
32
33
33
			selectButton.setText(f.getTreePath());
34
			overwriteCheckBox.setSelected(overwrite);
34
35
35
			criteriaList.updateComponents(b);
36
			// enable/disable button, too
36
		} else {
37
			textFontButton.setEnabled(overwrite);
37
			// get values from components
38
			textFontLabel.setEnabled(overwrite);
38
			IFilterRule filterRule = destFolder.getFilter().getFilterRule();
39
			mainFontButton.setEnabled(overwrite);
39
			int index = condList.getSelectedIndex();
40
			mainFontLabel.setEnabled(overwrite);
40
41
41
			if (index == 0) {
42
			// language
42
				filterRule.setCondition("matchall");
43
			Locale[] available = GlobalResourceLoader.getAvailableLocales();
43
			} else {
44
			languageComboBox.setModel(new DefaultComboBoxModel(available));
44
				filterRule.setCondition("matchany");
45
45
			}
46
			// select Locale in ComboBox
46
47
			for (int i = 0; i < available.length; i++) {
47
			if (includeSubfolderButton.isSelected()) {
48
				if (available[i].equals(Locale.getDefault())) {
48
				destFolder.getConfiguration().setString("property",
49
					languageComboBox.setSelectedIndex(i);
49
						"include_subfolders", "true");
50
					break;
50
			} else {
51
				}
51
				destFolder.getConfiguration().setString("property",
52
			}
52
						"include_subfolders", "false");
53
53
			}
54
			boolean enableText = item.getBooleanWithDefault(GuiItem.TOOLBAR,
54
55
					GuiItem.ENABLE_TEXT_BOOL, true);
55
			String path = selectButton.getText();
56
56
			TreeNodeList list = new TreeNodeList(path);
57
			boolean alignment = item.getBooleanWithDefault(GuiItem.TOOLBAR,
57
			IMailFolder folder = (IMailFolder) FolderTreeModel.getInstance()
58
					GuiItem.TEXT_POSITION_BOOL, true);
58
					.getFolder(list);
59
59
			String uid = folder.getId();
60
			if (enableText) {
60
			destFolder.getConfiguration().setString("property", "source_uid",
61
				toolbarComboBox.setSelectedIndex(alignment ? 1 : 2);
61
					uid);
62
			}
62
63
63
			criteriaList.updateComponents(b);
64
			proxyHost = System.getProperty("http.proxyHost");
64
		}
65
			String proxyPortString = System.getProperty("http.proxyPort", "-1");
65
	}
66
			proxyPort = Integer.parseInt(proxyPortString);
67
			updateProxyButtonText();
68
		} else {
69
			// fonts
70
			item.setString(GuiItem.FONT_MAIN, GuiItem.NAME, getMainFont()
71
					.getName());
72
			item.setInteger(GuiItem.FONT_MAIN, GuiItem.SIZE_INT, getMainFont()
73
					.getSize());
74
75
			item.setString(GuiItem.FONT_TEXT, GuiItem.NAME, getTextFont()
76
					.getName());
77
			item.setInteger(GuiItem.FONT_TEXT, GuiItem.SIZE_INT, getTextFont()
78
					.getSize());
79
80
			item.setBoolean(GuiItem.FONT, GuiItem.OVERWRITE_BOOL,
81
					overwriteCheckBox.isSelected());
82
83
			// notify all listeners
84
			// @see org.columba.core.gui.util.FontProperties
85
			// @see org.columba.mail.gui.message.TextViewer
86
			// @see org.columba.mail.gui.composer.text.TextEditorController
87
			item.getElement("fonts").notifyObservers();
88
89
			// look and feel
90
			item.setString(GuiItem.THEME, GuiItem.NAME, (String) lfComboBox
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);
    4
    if (value.equals("matchall"))
    Differences
    Expression1Expression2Difference
    alignmentvalue.equals("matchall")TYPE_COMPATIBLE_REPLACEMENT
    toolbarComboBoxcondListVARIABLE_NAME_MISMATCH
    toolbarComboBoxcondListVARIABLE_NAME_MISMATCH
    10LITERAL_VALUE_MISMATCH
    21LITERAL_VALUE_MISMATCH
    4
    if (value.equals("matchall"))
                                                                    
    5
    condList.setSelectedIndex(0);
    Differences
    Expression1Expression2Difference
    toolbarComboBoxcondListVARIABLE_NAME_MISMATCH
    10LITERAL_VALUE_MISMATCH
    5
    condList.setSelectedIndex(0);
            
    else
                                                                    
    6
    condList.setSelectedIndex(1);
    Differences
    Expression1Expression2Difference
    toolbarComboBoxcondListVARIABLE_NAME_MISMATCH
    21LITERAL_VALUE_MISMATCH
    6
    condList.setSelectedIndex(1);
    Precondition Violations (0)
    Row Violation