示例#1
0
  public void updateView() {
    CubieCube cc = cube;
    int corner = cc.c.a[Corner.URF.ordinal()].c.ordinal();
    int ori = cc.c.a[Corner.URF.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      up[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      right[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      front[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      up[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      right[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      front[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.UFL.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.UFL.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      up[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      front[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      left[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      up[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      front[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      left[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.ULB.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.ULB.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      up[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      left[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      back[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      up[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      left[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      back[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.UBR.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.UBR.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      up[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      back[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      right[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      up[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      back[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      right[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.DFR.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.DFR.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      down[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      front[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      right[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      down[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      front[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      right[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.DLF.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.DLF.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      down[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      left[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      front[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      down[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      left[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      front[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.DBL.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.DBL.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      down[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      back[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      left[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      down[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      back[0][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      left[0][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    corner = cc.c.a[Corner.DRB.ordinal()].c.ordinal();
    ori = cc.c.a[Corner.DRB.ordinal()].o;
    if (ori % 3 == 2) {
      ori -= 1;
    } else if (ori % 3 == 1) {
      ori += 1;
    }
    if (ori >= 3) {
      down[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori % 3]));
      right[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
      back[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
    } else {
      down[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][ori]));
      right[2][2].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 1) % 3]));
      back[2][0].setBackground(model.ColorIndexToColor(model.CCI.a[corner][(ori + 2) % 3]));
    }

    int edge = cc.e.a[Edge.UR.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.UR.ordinal()].o;
    up[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    right[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.UF.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.UF.ordinal()].o;
    up[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    front[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.UL.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.UL.ordinal()].o;
    up[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    left[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.UB.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.UB.ordinal()].o;
    up[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    back[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.DR.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.DR.ordinal()].o;
    down[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    right[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.DF.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.DF.ordinal()].o;
    down[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    front[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.DL.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.DL.ordinal()].o;
    down[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    left[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.DB.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.DB.ordinal()].o;
    down[1][2].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    back[1][0].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.FR.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.FR.ordinal()].o;
    front[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    right[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.FL.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.FL.ordinal()].o;
    front[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    left[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.BL.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.BL.ordinal()].o;
    back[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    left[0][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    edge = cc.e.a[Edge.BR.ordinal()].e.ordinal();
    ori = cc.e.a[Edge.BR.ordinal()].o;
    back[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][ori]));
    right[2][1].setBackground(model.ColorIndexToColor(model.ECI.a[edge][(ori + 1) % 2]));

    up[1][1].setBackground(Color.ORANGE);
    down[1][1].setBackground(Color.RED);
    left[1][1].setBackground(Color.GREEN);
    right[1][1].setBackground(Color.BLUE);
    back[1][1].setBackground(Color.YELLOW);
    front[1][1].setBackground(Color.WHITE);

    up[1][1].setEnabled(false);
    down[1][1].setEnabled(false);
    left[1][1].setEnabled(false);
    right[1][1].setEnabled(false);
    back[1][1].setEnabled(false);
    front[1][1].setEnabled(false);
  }
示例#2
0
  private void btn_saveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btn_saveActionPerformed
    CubieCube cc = new CubieCube();
    try {
      cc.c.a[Corner.URF.ordinal()] =
          model.IDCorner(
              up[2][2].getBackground(), right[0][0].getBackground(), front[2][0].getBackground());
      cc.c.a[Corner.UFL.ordinal()] =
          model.IDCorner(
              up[0][2].getBackground(), front[0][0].getBackground(), left[2][0].getBackground());
      cc.c.a[Corner.ULB.ordinal()] =
          model.IDCorner(
              up[0][0].getBackground(), left[0][0].getBackground(), back[0][2].getBackground());
      cc.c.a[Corner.UBR.ordinal()] =
          model.IDCorner(
              up[2][0].getBackground(), back[2][2].getBackground(), right[2][0].getBackground());
      cc.c.a[Corner.DFR.ordinal()] =
          model.IDCorner(
              down[2][0].getBackground(), front[2][2].getBackground(), right[0][2].getBackground());
      cc.c.a[Corner.DLF.ordinal()] =
          model.IDCorner(
              down[0][0].getBackground(), left[2][2].getBackground(), front[0][2].getBackground());
      cc.c.a[Corner.DBL.ordinal()] =
          model.IDCorner(
              down[0][2].getBackground(), back[0][0].getBackground(), left[0][2].getBackground());
      cc.c.a[Corner.DRB.ordinal()] =
          model.IDCorner(
              down[2][2].getBackground(), right[2][2].getBackground(), back[2][0].getBackground());

      cc.e.a[Edge.UR.ordinal()] =
          model.IDEdge(up[2][1].getBackground(), right[1][0].getBackground());
      cc.e.a[Edge.UF.ordinal()] =
          model.IDEdge(up[1][2].getBackground(), front[1][0].getBackground());
      cc.e.a[Edge.UL.ordinal()] =
          model.IDEdge(up[0][1].getBackground(), left[1][0].getBackground());
      cc.e.a[Edge.UB.ordinal()] =
          model.IDEdge(up[1][0].getBackground(), back[1][2].getBackground());
      cc.e.a[Edge.DR.ordinal()] =
          model.IDEdge(down[2][1].getBackground(), right[1][2].getBackground());
      cc.e.a[Edge.DF.ordinal()] =
          model.IDEdge(down[1][0].getBackground(), front[1][2].getBackground());
      cc.e.a[Edge.DL.ordinal()] =
          model.IDEdge(down[0][1].getBackground(), left[1][2].getBackground());
      cc.e.a[Edge.DB.ordinal()] =
          model.IDEdge(down[1][2].getBackground(), back[1][0].getBackground());
      cc.e.a[Edge.FR.ordinal()] =
          model.IDEdge(front[2][1].getBackground(), right[0][1].getBackground());
      cc.e.a[Edge.FL.ordinal()] =
          model.IDEdge(front[0][1].getBackground(), left[2][1].getBackground());
      cc.e.a[Edge.BL.ordinal()] =
          model.IDEdge(back[0][1].getBackground(), left[0][1].getBackground());
      cc.e.a[Edge.BR.ordinal()] =
          model.IDEdge(back[2][1].getBackground(), right[2][1].getBackground());
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, "Cube is not valid!");
      return;
    }
    if (model.verifyCube(cc)) {
      cube = cc;
      canEdit = false;
      updateC();
      btn_Solve.setEnabled(true);
      btn_input.setEnabled(true);
      btn_save.setEnabled(false);
    } else {
      JOptionPane.showMessageDialog(this, "Cube is not valid!");
    }
  } // GEN-LAST:event_btn_saveActionPerformed