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.

JavaDebugOptionsPanel.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 debug options.
  29. * Users should add this to the Ajde.getOptionsFrame()
  30. */
  31. public class JavaDebugOptionsPanel extends OptionsPanel {
  32. private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE};
  33. private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE};
  34. private static final long serialVersionUID = 4491319302490183151L;
  35. private JPanel parentPanel;
  36. private Border debugEtchedBorder;
  37. private TitledBorder debugTitleBorder;
  38. private Border debugCompoundBorder;
  39. private JPanel debugPanel;
  40. private Box debugBox = Box.createVerticalBox();
  41. private JavaBuildOptions javaBuildOptions;
  42. private Map<String,JComboBox<String>> debugComboBoxes = new HashMap();
  43. public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) {
  44. this.javaBuildOptions = javaBuildOptions;
  45. try {
  46. jbInit();
  47. this.setName("Java Debug Options");
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. @Override
  53. public void loadOptions() throws IOException {
  54. createDebugContents();
  55. }
  56. @Override
  57. public void saveOptions() throws IOException {
  58. Set<Map.Entry<String,JComboBox<String>>> s = debugComboBoxes.entrySet();
  59. for (Map.Entry<String,JComboBox<String>> entry : s) {
  60. String javaOption = entry.getKey();
  61. JComboBox<String> combo = 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 createDebugContents() {
  73. createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES);
  74. createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE);
  75. createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS);
  76. createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS);
  77. debugPanel.add(debugBox);
  78. }
  79. private void createDebugEntry(String labelText, String javaOptionToSet) {
  80. JPanel panel = new JPanel();
  81. panel.setLayout(new BorderLayout());
  82. JLabel label = new JLabel();
  83. label.setFont(new java.awt.Font("Dialog", 0, 11));
  84. label.setText(labelText);
  85. panel.add(label,BorderLayout.WEST);
  86. JComboBox<String> debug = null;
  87. if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) {
  88. debug = new JComboBox<String>(preserveOptions);
  89. String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
  90. if (value.equals(JavaOptions.PRESERVE)) {
  91. debug.setSelectedIndex(0);
  92. } else {
  93. debug.setSelectedIndex(1);
  94. }
  95. } else {
  96. debug = new JComboBox<String>(debugOptions);
  97. String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
  98. if (value.equals(JavaOptions.GENERATE)) {
  99. debug.setSelectedIndex(0);
  100. } else {
  101. debug.setSelectedIndex(1);
  102. }
  103. }
  104. panel.add(debug,BorderLayout.EAST);
  105. debugBox.add(panel,null);
  106. debugComboBoxes.put(javaOptionToSet,debug);
  107. }
  108. private void createBorders() {
  109. debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
  110. debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options");
  111. debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder,
  112. BorderFactory.createEmptyBorder(5, 5, 5, 5));
  113. debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
  114. }
  115. private void addBordersToPanel() {
  116. parentPanel = new JPanel();
  117. parentPanel.setLayout(new BorderLayout());
  118. debugPanel = new JPanel();
  119. debugPanel.setBorder(debugCompoundBorder);
  120. parentPanel.add(debugPanel,BorderLayout.CENTER);
  121. }
  122. }