選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JavaComplianceOptionsPanel.java 4.7KB

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