123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /********************************************************************
- * Copyright (c) 2007 Contributors. All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v 2.0
- * which accompanies this distribution and is available at
- * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
- *
- * Contributors: IBM Corporation - initial API and implementation
- * Helen Hawkins - initial version (bug 148190)
- *******************************************************************/
- package org.aspectj.ajde.ui.javaoptions;
-
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Set;
-
- import javax.swing.BorderFactory;
- import javax.swing.Box;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.border.Border;
- import javax.swing.border.TitledBorder;
-
- import org.aspectj.ajde.core.JavaOptions;
- import org.aspectj.ajde.ui.swing.OptionsPanel;
-
- /**
- * An options panel which displays the java compiler warning options.
- * Users should add this to the Ajde.getOptionsFrame()
- */
- public class JavaCompilerWarningsOptionsPanel extends OptionsPanel {
-
- private final String[] ignoreOrWarning = new String[] {JavaOptions.IGNORE,JavaOptions.WARNING};
- private static final long serialVersionUID = 4491319302490183151L;
-
- private JPanel parentPanel;
-
- private Border warningsEtchedBorder;
- private TitledBorder warningsTitleBorder;
- private Border warningsCompoundBorder;
- private JPanel warningsPanel;
- private Box warningsBox = Box.createVerticalBox();
-
- private JavaBuildOptions javaBuildOptions;
-
- private Map/*String --> JComboBox*/ warningComboBoxes = new HashMap();
-
- public JavaCompilerWarningsOptionsPanel(JavaBuildOptions javaBuildOptions) {
- this.javaBuildOptions = javaBuildOptions;
- try {
- jbInit();
- this.setName("Java Compiler Warning Options");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void loadOptions() throws IOException {
- createWarningContents();
- }
-
- public void saveOptions() throws IOException {
- Set s = warningComboBoxes.entrySet();
- for (Object o : s) {
- Entry entry = (Entry) o;
- String javaOption = (String) entry.getKey();
- JComboBox combo = (JComboBox) entry.getValue();
- String value = (String) combo.getSelectedItem();
- javaBuildOptions.setOption(javaOption, value);
- }
- }
-
- private void jbInit() throws Exception {
- this.setLayout(new BorderLayout());
- createBorders();
- addBordersToPanel();
- this.add(parentPanel,BorderLayout.NORTH);
- }
-
-
- private void createWarningContents() {
- createWarningsEntry("Method with a constructor name",JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME);
- createWarningsEntry("Method overriden but not package visible",JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD);
- createWarningsEntry("Deprecated API's",JavaOptions.WARN_DEPRECATION);
- createWarningsEntry("Hidden catch block",JavaOptions.WARN_HIDDEN_CATCH_BLOCKS);
- createWarningsEntry("Unused local or private member",JavaOptions.WARN_UNUSED_LOCALS);
- createWarningsEntry("Parameter is never read",JavaOptions.WARN_UNUSED_PARAMETER);
- createWarningsEntry("Unused import",JavaOptions.WARN_UNUSED_IMPORTS);
- createWarningsEntry("Synthetic access",JavaOptions.WARN_SYNTHETIC_ACCESS);
- createWarningsEntry("Assert identifier",JavaOptions.WARN_ASSERT_IDENITIFIER);
- createWarningsEntry("Non-externalized strings",JavaOptions.WARN_NON_NLS);
- warningsPanel.add(warningsBox,null);
- }
-
- private void createWarningsEntry(String labelText, String javaOptionToSet) {
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
-
- JLabel label = new JLabel();
- label.setFont(new java.awt.Font("Dialog", 0, 11));
- label.setText(labelText);
- panel.add(label,BorderLayout.WEST);
-
- JComboBox warnings = new JComboBox(ignoreOrWarning);
- String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
- if (value.equals(JavaOptions.IGNORE)) {
- warnings.setSelectedIndex(0);
- } else {
- warnings.setSelectedIndex(1);
- }
- panel.add(warnings,BorderLayout.EAST);
- warningsBox.add(panel,null);
- warningComboBoxes.put(javaOptionToSet,warnings);
- }
-
- private void createBorders() {
- warningsEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
- warningsTitleBorder = new TitledBorder(warningsEtchedBorder, "Warning Options");
- warningsCompoundBorder = BorderFactory.createCompoundBorder(warningsTitleBorder,
- BorderFactory.createEmptyBorder(5, 5, 5, 5));
- warningsTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
- }
-
- private void addBordersToPanel() {
- parentPanel = new JPanel();
- parentPanel.setLayout(new BorderLayout());
-
- warningsPanel = new JPanel();
- warningsPanel.setBorder(warningsCompoundBorder);
- parentPanel.add(warningsPanel,BorderLayout.CENTER);
- }
-
-
- }
|