Esempio n. 1
0
 public static Rectangle getBounds() {
   Point[] arr = ColorUtil.findAllColorWithinTolerance(MENU, new Color(1, 1, 1));
   try {
     Point left = Calc.getLeftMax(arr);
     Point right = Calc.getRightMax(arr);
     Point high = Calc.getNorthern(arr);
     Point low = Calc.getSouthern(arr);
     return new Rectangle(left.x, high.y, right.x - left.x, low.y - high.y);
   } catch (Exception ignored) {
   }
   return null;
 }
Esempio n. 2
0
  @Test
  public void testClassWrapper() throws Exception {
    Calc calc = new CalcImpl();

    WrapperProxetta proxetta =
        WrapperProxetta.withAspects(
            new ProxyAspect(
                StatCounterAdvice.class,
                new ProxyPointcutSupport() {
                  public boolean apply(MethodInfo methodInfo) {
                    return !isRootMethod(methodInfo) && isPublic(methodInfo);
                  }
                }));

    //		proxetta.setDebugFolder("d:\\");

    // wrapper over CLASS
    // resulting object has ALL interfaces
    // resulting object wraps ALL target class methods
    WrapperProxettaBuilder builder = proxetta.builder(calc.getClass());

    Class calc2Class = builder.define();

    Object object = calc2Class.newInstance();

    assertTrue(object instanceof Calc);
    assertEquals(CalcImpl.class, ProxettaUtil.getTargetClass(object.getClass()));
    assertEquals(1, calc2Class.getInterfaces().length);

    builder.injectTargetIntoWrapper(calc, object);

    assertEquals(1, StatCounter.counter); // counter in static block !!!

    Method method = calc2Class.getMethod("hello");
    assertNotNull(method);
    method.invoke(object);

    assertEquals(2, StatCounter.counter);

    method = calc2Class.getMethod("calculate", int.class, int.class);
    assertNotNull(method);
    Integer result = (Integer) method.invoke(object, 3, 7);
    assertEquals(10, result.intValue());

    assertEquals(3, StatCounter.counter);

    assertNotNull(calc2Class.getMethod("customMethod"));
  }
Esempio n. 3
0
 private void jButton21ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton21ActionPerformed
   // TODO add your handling code here:
   cal.a = Double.valueOf(Result.getText());
   Result.setText("");
   state = "/";
 } // GEN-LAST:event_jButton21ActionPerformed
Esempio n. 4
0
 public static void clickIndex(int index) {
   if (!isOpen()) {
     return;
   }
   Point[] arr = ColorUtil.findAllColorWithinTolerance(MENU, new Color(1, 1, 1));
   if (arr.length < 0) {
     return;
   }
   int menuY = 8;
   for (int x = 0; x < index; x++) {
     menuY += 16;
   }
   Point left = Calc.getLeftMax(arr);
   Point right = Calc.getRightMax(arr);
   Point high = Calc.getNorthern(arr);
   Mouse.click(left.x + (right.x - left.x) / 2, high.y + menuY, true);
 }
Esempio n. 5
0
 // ver 3
 @Test
 public void testDivZeroVer3() {
   try {
     c.div(10, 1);
     System.out.println("Here is error");
   } catch (Exception e) {
   }
 }
Esempio n. 6
0
 public static <FROM> Object eval(Calc<FROM> calc, FROM src) {
   try {
     return calc.calc(src);
   } catch (Exception e) {
     throw new RuntimeException(
         String.format("Cannot evaluate calculation %s on target: %s", calc, src), e);
   }
 }
Esempio n. 7
0
  @Test
  public void testInterfaceWrapper() throws Exception {
    Calc calc = new CalcImpl();

    WrapperProxetta proxetta =
        WrapperProxetta.withAspects(
            new ProxyAspect(
                StatCounterAdvice.class,
                new ProxyPointcutSupport() {
                  public boolean apply(MethodInfo methodInfo) {
                    return isTopLevelMethod(methodInfo) && isPublic(methodInfo);
                  }
                }));

    //		proxetta.setDebugFolder("d:\\");

    // wrapper over INTERFACE
    // resulting object has ONE interface
    // only interface methods are wrapped
    WrapperProxettaBuilder builder = proxetta.builder(Calc.class, ".CalcImpl3");

    Class<Calc> calc2Class = builder.define();

    Calc calc2 = calc2Class.newInstance();

    builder.injectTargetIntoWrapper(calc, calc2);

    assertEquals(1, StatCounter.counter); // counter in static block !!!

    calc2.hello();

    assertEquals(2, StatCounter.counter);

    assertEquals(10, calc2.calculate(3, 7));

    assertEquals(3, StatCounter.counter);

    try {
      calc2Class.getMethod("customMethod");
      fail();
    } catch (Exception ex) {
    }
  }
Esempio n. 8
0
 private void jButton17ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton17ActionPerformed
   // TODO add your handling code here:
   aftereq = true;
   cal.b = Double.valueOf(Result.getText());
   if (state == "+") {
     cal.tambah();
     Result.setText(String.valueOf(cal.c));
   } else if (state == "-") {
     cal.kurang();
     Result.setText(String.valueOf(cal.c));
   } else if (state == "*") {
     cal.kali();
     Result.setText(String.valueOf(cal.c));
   } else {
     cal.bagi();
     Result.setText(String.valueOf(cal.c));
   }
 } // GEN-LAST:event_jButton17ActionPerformed
Esempio n. 9
0
 public void fieldChange() {
   Double value = (Double) textField.getValue();
   log.debug("Changed isoFact to: " + value);
   if (value.isInfinite() || value.isNaN()) {
     value = 0.0;
   }
   Setting.getElement("/bat/isotope/calc/bg/factor").setText(value.toString());
   for (int i = 0; i < data.corrList.size(); i++) {
     data.corrList.get(i).isoFact = value;
   }
   data.calcAll();
   makeReg();
   dataSet = Func.getXY(data.get(dataType), null, x, y, x_multi, y_multi);
   chart.getXYPlot().setDataset(0, dataSet);
   log.debug(
       "Isobar correction factor set to: "
           + value
           + "-"
           + Setting.getDouble("/bat/isotope/calc/bg/factor"));
 }
Esempio n. 10
0
  private void makeReg() {
    slope = Func.slope(data.get(dataType), x, y);
    slopeField.setValue(slope[0]);
    slopeErrField.setValue(slope[1]);
    rField.setValue(slope[2]);
    //		Setting.getElement("/bat/isotope/calc/bg/factor").setText(((Double)slope[0]).toString());
    //		Setting.getElement("/bat/isotope/calc/bg/error").setText(((Double)slope[1]).toString());
    //		for (int i=0;i<data.corrList.size();i++) {
    //			data.corrList.get(i).isoFact=(Double)slope[0];
    //			data.corrList.get(i).isoErr=(Double)slope[1];
    //		}

  }
Esempio n. 11
0
  @Test
  public void testClassWrapperCastToInterface() throws Exception {
    Calc calc = new CalcImpl();

    WrapperProxetta proxetta =
        WrapperProxetta.withAspects(
            new ProxyAspect(
                StatCounterAdvice.class,
                new ProxyPointcutSupport() {
                  public boolean apply(MethodInfo methodInfo) {
                    return !isRootMethod(methodInfo) && isPublic(methodInfo);
                  }
                }));

    //		proxetta.setDebugFolder("d:\\");

    // wrapper over CLASS casted to interface,
    // resulting object has ONE interface
    // ALL target methods are wrapped
    WrapperProxettaBuilder builder = proxetta.builder(calc.getClass(), Calc.class, ".CalcImpl2");

    Class<Calc> calc2Class = builder.define();

    Calc calc2 = calc2Class.newInstance();

    builder.injectTargetIntoWrapper(calc, calc2);

    assertEquals(1, StatCounter.counter); // counter in static block !!!

    calc2.hello();

    assertEquals(2, StatCounter.counter);

    assertEquals(10, calc2.calculate(3, 7));

    assertEquals(3, StatCounter.counter);

    assertNotNull(calc2Class.getMethod("customMethod"));
  }
Esempio n. 12
0
  Images(String fileName) {
    File thisF = new File(fileName);

    InputStream thisStream = this.getClass().getClassLoader().getResourceAsStream(fileName);
    try {
      image = ImageIO.read(thisStream);
    } catch (Exception e) {;
    }
    if (image != null) {
      BufferedImage bi = Calc.newBImage(image.getWidth(), image.getHeight());
      bi.getGraphics().drawImage(image, 0, 0, null);
      image = bi;
    }
  }
Esempio n. 13
0
  public static void main(String[] args) {
    Calc calc = new Calc();
    System.out.println(calc.plus(10, 20));

    // 기능을 확장하는 방법 1.
    // - 기존 클래스를 변경하라!
    //  => 기존 클래스의 소스가 없으면 변경 불가!
    // - 기존의 코드를 잘못 손대면 잘되던 기능도 오류 발생!
    //  => 위험도 증가!

    // 추가한 기능 사용하기
    System.out.println(calc.minus(10, 20));

    // 기능을 확장하는 방법 2.
    // - 기존 클래스를 상속받는다.
    // - 기존 클래스의 소스가 없어도 된다.
    // - 단, 필요한 것만 선택적으로 상속할 수 없다.
    System.out.println("--------------------------");
    Calc2 calc2 = new Calc2();
    System.out.println(calc2.plus(10, 20));
    System.out.println(calc2.minus(10, 20));
    System.out.println(calc2.multiple(10, 20));
  }
Esempio n. 14
0
 public BufferedImage[] readImages(String baseName) {
   int n = 1;
   String urlString = "Images/" + baseName + n + ".png";
   InputStream thisStream = this.getClass().getClassLoader().getResourceAsStream(urlString);
   ArrayList<BufferedImage> temp = new ArrayList<BufferedImage>();
   BufferedImage image = null;
   while (thisStream != null) {
     try {
       image = ImageIO.read(thisStream);
     } catch (Exception e) {;
     }
     if (image != null) {
       BufferedImage bi = Calc.newBImage(image.getWidth(), image.getHeight());
       bi.getGraphics().drawImage(image, 0, 0, null);
       image = bi;
     }
     temp.add(image);
     n++;
     urlString = "Images/" + baseName + n + ".png";
     thisStream = this.getClass().getClassLoader().getResourceAsStream(urlString);
   }
   return temp.toArray(new BufferedImage[] {});
 }
Esempio n. 15
0
 public @Test void addWithLotsOfValuesReturnsTheirSum() {
   Assert.assertEquals(18, calc.add("1,2,3,0,10,2,0"));
 }
Esempio n. 16
0
 public @Test void addWithThreeValuesReturnsTheirSum() {
   Assert.assertEquals(0, calc.add("0,0,0"));
   Assert.assertEquals(4, calc.add("0,1,3"));
   Assert.assertEquals(6, calc.add("1,2,3"));
 }
Esempio n. 17
0
 public @Test void addWithTwoValuesReturnsTheirSum() {
   Assert.assertEquals(0, calc.add("0,0"));
   Assert.assertEquals(1, calc.add("0,1"));
   Assert.assertEquals(3, calc.add("1,2"));
 }
Esempio n. 18
0
 public @Test void addStringWithOneValueReturnsTheValue() {
   Assert.assertEquals(0, calc.add("0"));
   Assert.assertEquals(1, calc.add("1"));
   Assert.assertEquals(3, calc.add("3"));
 }
Esempio n. 19
0
 // ver 4
 @Test(expected = Exception.class)
 public void testDivZero() {
   c.div(10, 1);
 }
Esempio n. 20
0
 @Test
 public void testDiv() {
   assertTrue(2 == c.div(10, 5));
 }
Esempio n. 21
0
 @Test
 public void shouldParseFloatNumbers() {
   assertEquals("Should parse float numbers", 3.5, calc.evaluate("1 2 3.5"), 0);
 }
Esempio n. 22
0
 public @Test void addEmptyStringReturns0() {
   Assert.assertEquals(0, calc.add(""));
 }
Esempio n. 23
0
    public static void main(String[] args) {

        Calc calc = new Calc();
        calc.setVisible(true);
    }
Esempio n. 24
0
 @Test
 public void shouldSupportAddition() {
   assertEquals("Should support addition", 4, calc.evaluate("1 3 +"), 0);
 }
Esempio n. 25
0
 @Test
 public void shouldSupportMultiplication() {
   assertEquals("Should support multiplication", 3, calc.evaluate("1 3 *"), 0);
 }
Esempio n. 26
0
 @Test
 public void testAdd() {
   //		assertTrue("Right", , ));
   assertFalse("fdsfds", 67 == c.add(2, 5));
 }
Esempio n. 27
0
 public static void main(String[] args) {
   int result = Calc.add(1, 2);
   System.out.println("result=" + result);
 }
Esempio n. 28
0
 @Test
 public void shouldSupportSubstraction() {
   assertEquals("Should support substraction", -2, calc.evaluate("1 3 -"), 0);
 }
Esempio n. 29
0
 public static void main(String[] args) {
   Scanner user_input = new Scanner(System.in);
   try {
     String text;
     Op operator;
     Calc<?> calD;
     Expr expr;
     boolean parseExpression = true;
     calD = new CalcDouble<Double>(Double.class);
     expr = new Expr(calD);
     System.out.println("Operatorer: " + Op.toString(calD.operators));
     System.out.println("i: heltall d: desimal f: flyttall parse trace h: help s: slutt");
     do {
       System.out.print(": ");
       text = user_input.nextLine();
       calD.saveStack();
       // Check if the text is a valid operator for the type of
       // arguments
       operator = Op.operator(text, calD.operators);
       if (operator != null) {
         calD.op(operator);
       } else {
         // If the operator exists, but is invalid for the type write
         // that
         operator = Op.operator(text);
         if (operator != null)
           System.out.println(
               "Operator "
                   + operator.abbrev()
                   + " ugyldig for "
                   + calD.type.getSimpleName()
                   + ".");
         else {
           switch (text.toLowerCase()) {
             case "s":
               break;
             case "i":
               calD.clear();
               calD = new CalcBigInteger<BigInteger>(BigInteger.class);
               expr.setCalc(calD);
               System.out.println("Operatorer: " + Op.toString(calD.operators));
               break;
             case "d":
               calD.clear();
               calD = new CalcBigDecimal<BigDecimal>(BigDecimal.class);
               expr.setCalc(calD);
               System.out.println("Operatorer: " + Op.toString(calD.operators));
               break;
             case "f":
               calD.clear();
               calD = new CalcDouble<Double>(Double.class);
               expr.setCalc(calD);
               System.out.println("Operatorer: " + Op.toString(calD.operators));
               break;
             case "":
             case "help":
             case "h":
               System.out.println("Operatorer: " + Op.toString(calD.operators));
               System.out.println(
                   "i: heltall d: desimal f: flyttall parse trace h: help s: slutt");
               break;
             case "parse":
               parseExpression = !parseExpression;
               if (parseExpression) System.out.println("Parsing på.");
               else System.out.println("Parsing av.");
               break;
             case "trace":
               expr.setTrace();
               break;
             default:
               if (parseExpression) {
                 if (expr.parse(text)) expr.calculate();
               } else {
                 calD.enter(text);
               }
           }
         }
       }
     } while (!text.equals("s"));
   } catch (Exception e) {
     System.out.println("Alvorlig feil: " + e.getMessage());
   } finally {
     user_input.close();
   }
   System.out.println("Avsluttet kalkulator");
 }
Esempio n. 30
0
 @Test
 public void shouldSupportDivision() {
   assertEquals("Should support division", 2, calc.evaluate("4 2 /"), 0);
 }