You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JavaCompilerWarningsOptionsPanel.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version (bug 148190)
  10. *******************************************************************/
  11. package org.aspectj.ajde.ui.javaoptions;
  12. import java.awt.BorderLayout;
  13. import java.awt.Color;
  14. import java.io.IOException;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17. import java.util.Map.Entry;
  18. import java.util.Set;
  19. import javax.swing.BorderFactory;
  20. import javax.swing.Box;
  21. import javax.swing.JComboBox;
  22. import javax.swing.JLabel;
  23. import javax.swing.JPanel;
  24. import javax.swing.border.Border;
  25. import javax.swing.border.TitledBorder;
  26. import org.aspectj.ajde.core.JavaOptions;
  27. import org.aspectj.ajde.ui.swing.OptionsPanel;
  28. /**
  29. * An options panel which displays the java compiler warning options.
  30. * Users should add this to the Ajde.getOptionsFrame()
  31. */
  32. public class JavaCompilerWarningsOptionsPanel extends OptionsPanel {
  33. private final String[] ignoreOrWarning = new String[] {JavaOptions.IGNORE,JavaOptions.WARNING};
  34. private static final long serialVersionUID = 4491319302490183151L;
  35. private JPanel parentPanel;
  36. private Border warningsEtchedBorder;
  37. private TitledBorder warningsTitleBorder;
  38. private Border warningsCompoundBorder;
  39. private JPanel warningsPanel;
  40. private Box warningsBox = Box.createVerticalBox();
  41. private JavaBuildOptions javaBuildOptions;
  42. private Map/*String --> JComboBox*/ warningComboBoxes = new HashMap();
  43. public JavaCompilerWarningsOptionsPanel(JavaBuildOptions javaBuildOptions) {
  44. this.javaBuildOptions = javaBuildOptions;
  45. try {
  46. jbInit();
  47. this.setName("Java Compiler Warning Options");
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. public void loadOptions() throws IOException {
  53. createWarningContents();
  54. }
  55. public void saveOptions() throws IOException {
  56. Set s = warningComboBoxes.entrySet();
  57. for (Object o : s) {
  58. Entry entry = (Entry) o;
  59. String javaOption = (String) entry.getKey();
  60. JComboBox combo = (JComboBox) entry.getValue();
  61. String value = (String) combo.getSelectedItem();
  62. javaBuildOptions.setOption(javaOption, value);
  63. }
  64. }
  65. private void jbInit() throws Exception {
  66. this.setLayout(new BorderLayout());
  67. createBorders();
  68. addBordersToPanel();
  69. this.add(parentPanel,BorderLayout.NORTH);
  70. }
  71. private void createWarningContents() {
  72. createWarningsEntry("Method with a constructor name",JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME);
  73. createWarningsEntry("Method overriden but not package visible",JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD);
  74. createWarningsEntry("Deprecated API's",JavaOptions.WARN_DEPRECATION);
  75. createWarningsEntry("Hidden catch block",JavaOptions.WARN_HIDDEN_CATCH_BLOCKS);
  76. createWarningsEntry("Unused local or private member",JavaOptions.WARN_UNUSED_LOCALS);
  77. createWarningsEntry("Parameter is never read",JavaOptions.WARN_UNUSED_PARAMETER);
  78. createWarningsEntry("Unused import",JavaOptions.WARN_UNUSED_IMPORTS);
  79. createWarningsEntry("Synthetic access",JavaOptions.WARN_SYNTHETIC_ACCESS);
  80. createWarningsEntry("Assert identifier",JavaOptions.WARN_ASSERT_IDENITIFIER);
  81. createWarningsEntry("Non-externalized strings",JavaOptions.WARN_NON_NLS);
  82. warningsPanel.add(warningsBox,null);
  83. }
  84. private void createWarningsEntry(String labelText, String javaOptionToSet) {
  85. JPanel panel = new JPanel();
  86. panel.setLayout(new BorderLayout());
  87. JLabel label = new JLabel();
  88. label.setFont(new java.awt.Font("Dialog", 0, 11));
  89. label.setText(labelText);
  90. panel.add(label,BorderLayout.WEST);
  91. JComboBox warnings = new JComboBox(ignoreOrWarning);
  92. String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
  93. if (value.equals(JavaOptions.IGNORE)) {
  94. warnings.setSelectedIndex(0);
  95. } else {
  96. warnings.setSelectedIndex(1);
  97. }
  98. panel.add(warnings,BorderLayout.EAST);
  99. warningsBox.add(panel,null);
  100. warningComboBoxes.put(javaOptionToSet,warnings);
  101. }
  102. private void createBorders() {
  103. warningsEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
  104. warningsTitleBorder = new TitledBorder(warningsEtchedBorder, "Warning Options");
  105. warningsCompoundBorder = BorderFactory.createCompoundBorder(warningsTitleBorder,
  106. BorderFactory.createEmptyBorder(5, 5, 5, 5));
  107. warningsTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
  108. }
  109. private void addBordersToPanel() {
  110. parentPanel = new JPanel();
  111. parentPanel.setLayout(new BorderLayout());
  112. warningsPanel = new JPanel();
  113. warningsPanel.setBorder(warningsCompoundBorder);
  114. parentPanel.add(warningsPanel,BorderLayout.CENTER);
  115. }
  116. }