package ui; import cs.min2phase.Tools; import cs.min2phase.Search; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.Color; import java.awt.event.*; import java.io.*; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //A simple GUI example to demonstrate how to use the package org.kociemba.twophase /** * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, company or business for any purpose whatever) then * you should purchase a license for each developer using Jigloo. Please visit www.cloudgarden.com for details. Use of * Jigloo implies acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR THIS MACHINE, SO * JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class MainProgram extends javax.swing.JFrame { // +++++++++++++These variables used only in the GUI-interface+++++++++++++++++++++++++++++++++++++++++++++++++++++++ private static final long serialVersionUID = 1L; private JButton[][] facelet = new JButton[6][9]; private final JButton[] colorSel = new JButton[6]; private final int FSIZE = 45; private final int[] XOFF = { 3, 6, 3, 3, 0, 9 };// Offsets for facelet display private final int[] YOFF = { 0, 3, 3, 6, 3, 3 }; private final Color[] COLORS = { Color.white, Color.red, Color.green, Color.yellow, Color.orange, Color.blue }; private JTextPane jTextPane1; private JCheckBox checkBoxShowStr; private JButton buttonRandom; private JCheckBox checkBoxUseSep; private JCheckBox checkBoxInv; private JCheckBox checkBoxShowLen; private JButton Solve; private JLabel jLabel2; private JLabel jLabel1; private JSpinner spinnerMaxMoves; private JSpinner spinnerTimeout; private Color curCol = COLORS[0]; private int maxDepth = 21, maxTime = 5; boolean useSeparator = true; boolean showString = false; boolean inverse = true; boolean showLength = true; Search search = new Search(); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static void main(String[] args) { String fileName = "m2p" + (Search.USE_TWIST_FLIP_PRUN ? "T" : "") + (Search.EXTRA_PRUN_LEVEL > 0 ? "F" : "") + ".data"; try { DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName))); Tools.initFrom(dis); } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); System.exit(1); } if (!Search.isInited()) { Search.init(); try { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); Tools.saveTo(dos); dos.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } SwingUtilities.invokeLater(new Runnable() { public void run() { MainProgram inst = new MainProgram(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public MainProgram() { super(); initGUI(); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private void initGUI() { getContentPane().setLayout(null); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("Two-Phase Package GUI-Example"); this.setPreferredSize(new java.awt.Dimension(546, 521)); // ++++++++++++++++++++++++++++++++++ Set up Solve Cube Button ++++++++++++++++++++++++++++++++++++++++++++++++++++ Solve = new JButton("Solve Cube"); getContentPane().add(Solve); Solve.setBounds(422, 64, 114, 48); Solve.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { solveCube(evt); } }); // ++++++++++++++++++++++++++++++++++ Set up Move Limit Spinner +++++++++++++++++++++++++++++++++++++++++++++++++++ { jLabel1 = new JLabel(); getContentPane().add(jLabel1); jLabel1.setText("Move Limit"); jLabel1.setBounds(282, 65, 72, 16); } { SpinnerModel model = new SpinnerNumberModel(21, 1, 24, 1); spinnerMaxMoves = new JSpinner(model); getContentPane().add(spinnerMaxMoves); spinnerMaxMoves.setBounds(354, 62, 56, 21); spinnerMaxMoves.getEditor().setPreferredSize(new java.awt.Dimension(37, 19)); spinnerMaxMoves.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { maxDepth = ((Integer) spinnerMaxMoves.getValue()).intValue(); } }); } // ++++++++++++++++++++++++++++++++++ Set up Time Limit Spinner +++++++++++++++++++++++++++++++++++++++++++++++++++ { jLabel2 = new JLabel(); getContentPane().add(jLabel2); jLabel2.setText("Time Limit"); jLabel2.setBounds(282, 93, 72, 16); } { SpinnerModel model = new SpinnerNumberModel(5, 1, 3600, 1); spinnerTimeout = new JSpinner(model); getContentPane().add(spinnerTimeout); spinnerTimeout.setModel(model); spinnerTimeout.setBounds(354, 90, 56, 21); spinnerTimeout.getEditor().setPreferredSize(new java.awt.Dimension(36, 17)); spinnerTimeout.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { maxTime = ((Integer) spinnerTimeout.getValue()).intValue(); } }); } // ++++++++++++++++++++++++++++++++++ Set up Use Separator CheckBox +++++++++++++++++++++++++++++++++++++++++++++++ { checkBoxInv = new JCheckBox("Inverse", true); getContentPane().add(checkBoxInv); checkBoxInv.setBounds(12, 297, 121, 20); checkBoxInv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { inverse = checkBoxInv.isSelected(); } }); checkBoxUseSep = new JCheckBox("Use Separator", true); getContentPane().add(checkBoxUseSep); checkBoxUseSep.setBounds(12, 320, 121, 20); checkBoxUseSep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { useSeparator = checkBoxUseSep.isSelected(); } }); } { checkBoxShowStr = new JCheckBox("Show String", false); getContentPane().add(checkBoxShowStr); checkBoxShowStr.setBounds(12, 343, 121, 20); checkBoxShowStr.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { showString = checkBoxShowStr.isSelected(); } }); checkBoxShowLen = new JCheckBox("Show Length", true); getContentPane().add(checkBoxShowLen); checkBoxShowLen.setBounds(12, 366, 121, 20); checkBoxShowLen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { showLength = checkBoxShowLen.isSelected(); } }); } // ++++++++++++++++++++++++++++++++++ Set up Random Button ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { buttonRandom = new JButton("Random Cube"); getContentPane().add(buttonRandom); buttonRandom.setBounds(422, 17, 114, 22); buttonRandom.setText("Scramble"); buttonRandom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // +++++++++++++++++++++++++++++ Call Random function from package org.kociemba.twophase ++++++++++++++++++++ String r = Tools.randomCube(); jTextPane1.setText(r); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ for (int i = 0; i