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

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