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.9KB

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