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.

JavaComplianceOptionsPanel.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 compliance options.
  31. * Users should add this to the Ajde.getOptionsFrame()
  32. */
  33. public class JavaComplianceOptionsPanel extends OptionsPanel {
  34. private final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16};
  35. private static final long serialVersionUID = 4491319302490183151L;
  36. private JPanel parentPanel;
  37. private Border complianceEtchedBorder;
  38. private TitledBorder complianceTitleBorder;
  39. private Border complianceCompoundBorder;
  40. private JPanel compliancePanel;
  41. private Box complianceBox = Box.createVerticalBox();
  42. private JavaBuildOptions javaBuildOptions;
  43. private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap();
  44. public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) {
  45. this.javaBuildOptions = javaBuildOptions;
  46. try {
  47. jbInit();
  48. this.setName("Java Compliance Options");
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. public void loadOptions() throws IOException {
  54. createComplianceContents();
  55. }
  56. public void saveOptions() throws IOException {
  57. Set s = complianceComboBoxes.entrySet();
  58. for (Iterator iterator = s.iterator(); iterator.hasNext();) {
  59. Map.Entry entry = (Entry) iterator.next();
  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 createComplianceContents() {
  73. createComplianceEntry("AjCompiler compliance level: ",JavaOptions.COMPLIANCE_LEVEL);
  74. createComplianceEntry("Source compatibility: ",JavaOptions.SOURCE_COMPATIBILITY_LEVEL);
  75. createComplianceEntry("Generated class file compatibility: ",JavaOptions.TARGET_COMPATIBILITY_LEVEL);
  76. compliancePanel.add(complianceBox);
  77. }
  78. private void createComplianceEntry(String labelText, String javaOptionToSet) {
  79. JPanel panel = new JPanel();
  80. panel.setLayout(new BorderLayout());
  81. JLabel label = new JLabel();
  82. label.setFont(new java.awt.Font("Dialog", 0, 11));
  83. label.setText(labelText);
  84. panel.add(label,BorderLayout.WEST);
  85. JComboBox levels = new JComboBox(complianceLevels);
  86. String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
  87. if (value == null) {
  88. // default to 1.5
  89. levels.setSelectedIndex(2);
  90. } else if (value.equals(JavaOptions.VERSION_13)) {
  91. levels.setSelectedIndex(0);
  92. } else if (value.equals(JavaOptions.VERSION_14)){
  93. levels.setSelectedIndex(1);
  94. } else if (value.equals(JavaOptions.VERSION_15)){
  95. levels.setSelectedIndex(2);
  96. } else if (value.equals(JavaOptions.VERSION_16)){
  97. levels.setSelectedIndex(3);
  98. }
  99. panel.add(levels,BorderLayout.EAST);
  100. complianceBox.add(panel,null);
  101. complianceComboBoxes.put(javaOptionToSet,levels);
  102. }
  103. private void createBorders() {
  104. complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
  105. complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options");
  106. complianceCompoundBorder = BorderFactory.createCompoundBorder(complianceTitleBorder,
  107. BorderFactory.createEmptyBorder(5, 5, 5, 5));
  108. complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
  109. }
  110. private void addBordersToPanel() {
  111. parentPanel = new JPanel();
  112. parentPanel.setLayout(new BorderLayout());
  113. compliancePanel = new JPanel();
  114. compliancePanel.setBorder(complianceCompoundBorder);
  115. parentPanel.add(compliancePanel,BorderLayout.CENTER);
  116. }
  117. }