package me.coley.recaf.ui.component.panel;

import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;

import me.coley.recaf.Program;
import me.coley.recaf.ui.component.action.ActionCheckBox;

/**
 * Panel for selecting ASM flags.
 * 
 * @author Matt
 */
@SuppressWarnings("serial")
public class AsmFlagsPanel extends JPanel {
	private ActionCheckBox inE, inD, inF, inC, outF, outM;

	public AsmFlagsPanel() {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		JPanel p1 = new JPanel();
		p1.setBorder(BorderFactory.createTitledBorder("Input Flags"));
		p1.setLayout(new GridLayout(0, 2));
		p1.add(inE = new ActionCheckBox("Expand Frames", true, (b) -> update()));
		p1.add(inD = new ActionCheckBox("Skip Debug", false, (b) -> update()));
		p1.add(inF = new ActionCheckBox("Skip Frames", false, (b) -> update()));
		p1.add(inC = new ActionCheckBox("Skip Code", false, (b) -> update()));
		JPanel p2 = new JPanel();
		p2.setBorder(BorderFactory.createTitledBorder("Output Flags"));
		p2.setLayout(new GridLayout(0, 2));
		p2.add(outF = new ActionCheckBox("Compute Frames", true, (b) -> update()));
		p2.add(outM = new ActionCheckBox("Compute Maxs", false, (b) -> update()));
		add(p1);
		add(p2);
	}

	private void update() {
		int in = 0;
		int out = 0;
		if (inE.isSelected()) {
			in |= ClassReader.EXPAND_FRAMES;
		}
		if (inD.isSelected()) {
			in |= ClassReader.SKIP_DEBUG;
		}
		if (inF.isSelected()) {
			in |= ClassReader.SKIP_FRAMES;
		}
		if (inC.isSelected()) {
			in |= ClassReader.SKIP_CODE;
		}
		if (outF.isSelected()) {
			out |= ClassWriter.COMPUTE_FRAMES;
		}
		if (outM.isSelected()) {
			out |= ClassWriter.COMPUTE_MAXS;
		}
		Program.getInstance().options.classFlagsInput = in;
		Program.getInstance().options.classFlagsOutput = out;
	}
}

@@ -257,23 +257,88 @@
 y.recaf.
-Program
+Options;%0Aimport me.coley.recaf.Program;%0Aimport me.coley.recaf.asm.Access
 ;%0Aimport
@@ -524,16 +524,80 @@
 Panel %7B%0A
+%09private final Options options = Program.getInstance().options;%0A
 %09private
@@ -671,16 +671,35 @@
 nel() %7B%0A
+%09%09//@formatter:off%0A
 %09%09setLay
@@ -916,36 +916,100 @@
 Expand Frames%22, 
-true
+Access.hasAccess(options.classFlagsInput, ClassReader.EXPAND_FRAMES)
 , (b) -%3E update(
@@ -1061,21 +1061,81 @@
 Debug%22, 
-false
+Access.hasAccess(options.classFlagsInput, ClassReader.SKIP_DEBUG)
 , (b) -%3E
@@ -1192,29 +1192,90 @@
 ip Frames%22, 
-false
+Access.hasAccess(options.classFlagsInput, ClassReader.SKIP_FRAMES)
 , (b) -%3E upd
@@ -1330,21 +1330,80 @@
  Code%22, 
-false
+Access.hasAccess(options.classFlagsInput, ClassReader.SKIP_CODE)
 , (b) -%3E
@@ -1604,12 +1604,78 @@
 s%22, 
-true
+Access.hasAccess(options.classFlagsOutput, ClassWriter.COMPUTE_FRAMES)
 , (b
@@ -1746,13 +1746,76 @@
 s%22, 
-false
+Access.hasAccess(options.classFlagsOutput, ClassWriter.COMPUTE_MAXS)
 , (b
@@ -1853,16 +1853,34 @@
 dd(p2);%0A
+%09%09//@formatter:on%0A
 %09%7D%0A%0A%09pri
@@ -2322,38 +2322,16 @@
 ;%0A%09%09%7D%0A%09%09
-Program.getInstance().
 options.
@@ -2354,38 +2354,16 @@
 = in;%0A%09%09
-Program.getInstance().
 options.

Access panel default values correctly display current settings now