All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aspectj.ajde.ui.javaoptions.JavaDebugOptionsPanel Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/********************************************************************
 * 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.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 debug options.
 * Users should add this to the Ajde.getOptionsFrame()
 */
public class JavaDebugOptionsPanel extends OptionsPanel {

	private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE};
	private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE};

	private static final long serialVersionUID = 4491319302490183151L;

	private JPanel parentPanel;

	private Border debugEtchedBorder;
	private TitledBorder debugTitleBorder;
	private Border debugCompoundBorder;
	private JPanel debugPanel;
	private Box debugBox = Box.createVerticalBox();

	private JavaBuildOptions javaBuildOptions;

	private Map> debugComboBoxes = new HashMap();

	public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) {
		this.javaBuildOptions = javaBuildOptions;
		try {
			jbInit();
			this.setName("Java Debug Options");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void loadOptions() throws IOException {
		createDebugContents();
	}

	@Override
	public void saveOptions() throws IOException {
		Set>> s = debugComboBoxes.entrySet();
		for (Map.Entry> entry : s) {
			String javaOption = entry.getKey();
			JComboBox combo = 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 createDebugContents() {
		createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES);
		createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE);
		createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS);
		createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS);
		debugPanel.add(debugBox);
	}

	private void createDebugEntry(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 debug = null;
		if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) {
			debug = new JComboBox<>(preserveOptions);
			String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
			if (value.equals(JavaOptions.PRESERVE)) {
				debug.setSelectedIndex(0);
			} else {
				debug.setSelectedIndex(1);
			}
		} else {
			debug = new JComboBox<>(debugOptions);
			String value = javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet);
			if (value.equals(JavaOptions.GENERATE)) {
				debug.setSelectedIndex(0);
			} else {
				debug.setSelectedIndex(1);
			}
		}
		panel.add(debug,BorderLayout.EAST);
		debugBox.add(panel,null);
		debugComboBoxes.put(javaOptionToSet,debug);
	}


	private void createBorders() {
		debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158));
		debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options");
		debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder,
				BorderFactory.createEmptyBorder(5, 5, 5, 5));
		debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11));
	}

	private void addBordersToPanel() {
		parentPanel = new JPanel();
		parentPanel.setLayout(new BorderLayout());

		debugPanel = new JPanel();
		debugPanel.setBorder(debugCompoundBorder);

		parentPanel.add(debugPanel,BorderLayout.CENTER);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy