コード例 #1
0
  public void drawFunctionToGraphic(Graphics2D g, int x, int y, int UNITYX, int UNITYY) {
    int _x, _y;

    g.setColor(Color.red);
    g.drawString("f(x) = " + F.toString(), 15, 20);

    g.setColor(Color.blue);
    for (double i = 0; ; i += EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }

    for (double i = 0; ; i -= EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }
  }
コード例 #2
0
 public void doit(
     String query,
     HashMap<String, String> render,
     HashMap<String, String> select,
     HashMap<String, String> insert,
     HashMap<String, String> update,
     DefaultTableModel dtm,
     int[] cellWidth,
     boolean diwarnai) {
   this.sql = query;
   this.renderKolom = render;
   this.selectKolom = select;
   this.insertKolom = insert;
   this.updateKolom = update;
   this.kolomWidth = cellWidth;
   this.model = dtm;
   selectTabel(dtm);
   if (cellWidth == null) {
   } else {
     CommonToolkit.setTitleAndWidthColumn(this, null, cellWidth);
   }
   if (diwarnai) {
     CommonToolkit.setCCellRenderer(this);
   }
   Function.setTableSearchAble(this);
 }
コード例 #3
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    this.setBackground(Color.WHITE);

    g.setColor(Color.BLACK);
    g.drawLine(mapX(xmin), mapY(0.0), mapX(xmax), mapY(0.0));
    g.drawLine(mapX(0), mapY(ymin), mapX(0), mapY(ymax));

    int lastY = mapY(f.eval(xmin));

    for (int i = 1; i < getWidth(); i++) {
      int newY = mapY(f.eval(invmapX(i)));
      g.drawLine(i - 1, lastY, i, newY);
      lastY = newY;
    }

    double x = 0;
    while (x <= xmax) {
      x += tickSpace;
      g.drawLine(mapX(x), mapY(0) - 10, mapX(x), mapY(0) + 10);
    }

    x = 0;
    while (x >= xmin) {
      x -= tickSpace;
      g.drawLine(mapX(x), mapY(0) - 10, mapX(x), mapY(0) + 10);
    }

    double y = 0;
    while (y <= xmax) {
      y += tickSpace;
      g.drawLine(mapX(0) - 10, mapY(y), mapX(0) + 10, mapY(y));
    }

    y = 0;
    while (y >= xmin) {
      y -= tickSpace;
      g.drawLine(mapX(0) - 10, mapY(y), mapX(0) + 10, mapY(y));
    }
  }
コード例 #4
0
 public void renderTable(HashMap<String, String> tipeKolom) {
   // tipeKolom = 1#Z#HCODE
   // tipeKolom = 1#D#NONE
   // tipeKolom = 1#N#FORMAT
   for (int i = 0; i < tipeKolom.size(); i++) {
     String temp = tipeKolom.get(i + "");
     String data[] = temp.split("#");
     int no = 0;
     try {
       no = Integer.parseInt(data[0].trim());
     } catch (Exception e) {
       no = 0;
     }
     if (data[1].trim().equals("Z")) {
       Function.setColumnRender(this, data[2], no);
     } else if (data[1].trim().equals("D")) {
       Function.setColumnRenderDate(this, data[2], no);
     } else if (data[1].trim().equals("N")) {
       Function.setColumnRenderNumeric(this, no);
     }
   }
 }
コード例 #5
0
  private static File getOldPath(
      final File oldInstallHome,
      final ConfigImportSettings settings,
      final String propertyName,
      final Function<String, String> fromPathSelector) {
    final File[] launchFileCandidates = getLaunchFilesCandidates(oldInstallHome, settings);

    // custom config folder
    for (File candidate : launchFileCandidates) {
      if (candidate.exists()) {
        String configDir =
            PathManager.substituteVars(
                getPropertyFromLaxFile(candidate, propertyName), oldInstallHome.getPath());
        if (configDir != null) {
          File probableConfig = new File(configDir);
          if (probableConfig.exists()) return probableConfig;
        }
      }
    }

    // custom config folder not found - use paths selector
    for (File candidate : launchFileCandidates) {
      if (candidate.exists()) {
        final String pathsSelector =
            getPropertyFromLaxFile(candidate, PathManager.PROPERTY_PATHS_SELECTOR);
        if (pathsSelector != null) {
          final String configDir = fromPathSelector.fun(pathsSelector);
          final File probableConfig = new File(configDir);
          if (probableConfig.exists()) {
            return probableConfig;
          }
        }
      }
    }

    return null;
  }
コード例 #6
0
ファイル: IrisVisualizer.java プロジェクト: jbudynk/iris
    public void valueChanged(TreeSelectionEvent e) {

      JTree tree = FunctionFactorySherpaHelper.GetJTree();

      DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      if (node == null) {
        return;
      }
      Object node_object = node.getUserObject();

      if (node.isLeaf()) {

        try {
          // analytic Sherpa functions.
          Function rf = (Function) node_object;
          try {
            if (rf instanceof Polynomial) {
              rf = new Polynomial(1);
            } else {
              rf = (Function) rf.clone();
            }
          } catch (CloneNotSupportedException ex) {
            rf = null;
          }

          FunctionFactorySherpaHelper.SetFunction(rf);

        } catch (ClassCastException e1) {

          // templates, tables and user files
          try {
            DefaultCustomModel model = (DefaultCustomModel) node_object;

            String functionName = model.getFunctionName();

            SherpaFunction function = new SherpaFunction();

            URL url = model.getUrl();
            String path = url.getPath();
            function.addPath(path);

            String name = model.getName();

            if (path.contains("/tables/")) {
              name = "tablemodel";
            }
            if (path.contains("/functions/")) {
              name = "usermodel";
            }
            if (path.contains("/templates/")) {
              name = "templatemodel";
            }

            function.setUserID(name);
            function.setName(name);
            function.setFunctionName(functionName);

            // Converting a DefaultCustomModel to a SherpaFunction might
            // require more than this. We'll see as we go further down
            // the road...

            // First, we need to break up the comma-separated string
            // parameters into something that can actually be used to
            // build instances of Function.

            String[] parNames = model.getParnames().split("\\,");
            String[] parVals = model.getParvals().split("\\,");
            String[] parMins = model.getParmins().split("\\,");
            String[] parMaxs = model.getParmaxs().split("\\,");
            String[] parFrozen = model.getParfrozen().split("\\,");

            int npars = parNames.length;

            if (npars != parVals.length
                || npars != parMins.length
                || npars != parMaxs.length
                || npars != parFrozen.length) {
              ExceptionHandler.handleException(
                  new Exception("Parameter lists wih different lengths."));
              tree.clearSelection();
              FunctionFactorySherpaHelper.dispose();
              return;
            }

            // now we loop over the parameter lists, building
            // each parameter in turn and adding it to the Function.

            for (int i = 0; i < npars; i++) {
              SherpaFParameter functionParameter = null;
              try {

                double value = Double.valueOf(parVals[i]);
                double min = Double.valueOf(parMins[i]);
                double max = Double.valueOf(parMaxs[i]);

                functionParameter =
                    new SherpaFParameter(parNames[i], value, min, max, new NonSupportedUnits(""));

                String frozen = parFrozen[i];
                if (frozen != null) {
                  boolean fixed = (frozen.equalsIgnoreCase("True")) ? true : false;
                  functionParameter.setFixed(fixed);
                }

              } catch (NumberFormatException ex) {
                ExceptionHandler.handleException(ex);
                tree.clearSelection();
                FunctionFactorySherpaHelper.dispose();
                return;
              } catch (ArrayIndexOutOfBoundsException ex) {
                ExceptionHandler.handleException(ex);
                tree.clearSelection();
                FunctionFactorySherpaHelper.dispose();
                return;
              }

              function.addParameter(functionParameter);
            }

            FunctionFactorySherpaHelper.SetFunction(function);

          } catch (ClassCastException e2) {
          }
        }
        tree.clearSelection();
        FunctionFactorySherpaHelper.dispose();
      }
    }
コード例 #7
0
  public void InsertDataTable() {
    for (int i = 0; i < dataBaru.size(); i++) {
      try {
        rowSet.moveToInsertRow();
        for (int ii = 0; ii < insertKolom.size(); ii++) {
          String temp = insertKolom.get(ii + "");
          String data[] = temp.split("#");
          int no = 0;
          boolean constanta = false;
          if (data[1].trim().toLowerCase().equals("c")) {
            constanta = true;
          } else {
            try {
              no = Integer.parseInt(data[1].trim());
            } catch (Exception e) {
              no = 0;
            }
          }
          if (data[0].trim().toLowerCase().contains("i")) {
            if (data[2].trim().toLowerCase().equals("boolean")) {
              String value = "";
              if (data[4].trim().toLowerCase().equals("int")) {
                if (getValueAt(
                        new Integer(dataBaru.get(i).toString()), Integer.parseInt(data[1].trim()))
                    .toString()
                    .equals("true")) {
                  if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                    value = "1";
                  } else {
                    value = "Y";
                  }
                } else {
                  if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                    value = "0";
                  } else {
                    value = "N";
                  }
                }
                try {
                  rowSet.updateInt(data[3].trim().toString(), Integer.parseInt(value));
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else {
                if (getValueAt(
                        new Integer(dataBaru.get(i).toString()), Integer.parseInt(data[1].trim()))
                    .toString()
                    .equals("true")) {
                  if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                    value = "1";
                  } else {
                    value = "Y";
                  }
                } else {
                  if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                    value = "0";
                  } else {
                    value = "N";
                  }
                }
                try {
                  rowSet.updateString(data[3].trim().toString(), value.trim());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }

            } else if (data[2].trim().toLowerCase().equals("date")) {
              String value = "";
              java.util.Date dd =
                  (java.util.Date) getValueAt(new Integer(dataBaru.get(i).toString()), no);
              if (data[4].equals("dd-MM-yyyy")) {
                value = Function.dateToString(dd);
              } else if (data[4].equals("MM-yyyy")) {
                value = Function.monthToString(dd).trim();
              } else if (data[4].equals("yyyy")) {
                //                                    value = Function.yearToDate(sql);
                JOptionPane.showMessageDialog(null, "Belom Support");
              }
              //                            JOptionPane.showMessageDialog(null, value.length());
              try {
                rowSet.updateString(data[3].trim().toString(), value.trim());
              } catch (Exception e) {
                e.printStackTrace();
              }
            } else if (data[2].trim().toLowerCase().equals("string")
                || data[2].trim().toLowerCase().equals("numeric")) {
              String value = "";
              if (constanta) {
                value = data[6].trim();
              } else {
                try {
                  value = getValueAt(new Integer(dataBaru.get(i).toString()), no).toString();
                } catch (Exception e) {
                  try {
                    value = getValueAt(new Integer(dataBaru.get(i).toString()), no).toString();
                  } catch (Exception ee) {
                    value = "";
                  }
                }
              }
              if (data[4].trim().toLowerCase().equals("int")) {
                try {
                  if (value.trim().equals("")) {
                    value = "0";
                  }
                  rowSet.updateLong(data[3].trim().toString(), Long.parseLong(value.trim()));
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else {
                try {
                  rowSet.updateString(data[3].trim().toString(), value.trim());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            } else if (data[2].trim().toLowerCase().equals("combo")) {
              String value = "";
              String valueKolom = "";
              try {
                valueKolom =
                    getValueAt(new Integer(dataBaru.get(i).toString()), no).toString().trim();
              } catch (Exception e) {
                valueKolom = "";
              }
              try {
                value = Function.getValueFromCell(data[5].trim(), valueKolom);
              } catch (Exception e) {
                value = "";
              }
              if (data[4].trim().toLowerCase().equals("int")) {
                try {
                  rowSet.updateString(data[3].trim().toString(), value.trim());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else {
                try {
                  rowSet.updateString(data[3].trim().toString(), value.trim());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
        }
        //                JOptionPane.showMessageDialog(null, rowSet.getCommand());
        rowSet.insertRow();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #8
0
  public void updateDataTable() {
    for (int i = 0; i < dataAsli.size(); i++) {
      try {
        rowSet.absolute(new Integer(dataAsli.elementAt(i).toString()));
        if (rowSet.next()) {
          for (int ii = 0; ii < updateKolom.size(); ii++) {
            String temp = updateKolom.get(ii + "");
            String data[] = temp.split("#");
            int no = 0;
            try {
              no = Integer.parseInt(data[1].trim());
            } catch (Exception e) {
              no = 0;
            }
            if (data[0].trim().toLowerCase().contains("u")) {
              if (data[2].trim().toLowerCase().equals("boolean")) {
                String value = "";
                if (data[4].trim().toLowerCase().equals("int")) {
                  if (getValueAt(
                          new Integer(dataAsli.get(i).toString()), Integer.parseInt(data[1].trim()))
                      .toString()
                      .equals("true")) {
                    if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                      value = "1";
                    } else {
                      value = "Y";
                    }
                  } else {
                    if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                      value = "0";
                    } else {
                      value = "N";
                    }
                  }
                  try {
                    rowSet.updateInt(data[3].trim().toString(), Integer.parseInt(value));
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  if (getValueAt(
                          new Integer(dataAsli.get(i).toString()), Integer.parseInt(data[1].trim()))
                      .toString()
                      .equals("true")) {
                    if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                      value = "1";
                    } else {
                      value = "Y";
                    }
                  } else {
                    if (data[5].trim().equals("1") || data[5].trim().equals("0")) {
                      value = "0";
                    } else {
                      value = "N";
                    }
                  }
                  try {
                    rowSet.updateString(data[3].trim().toString(), value.trim());
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }

              } else if (data[2].trim().toLowerCase().equals("date")) {
                String value = "";
                java.util.Date dd =
                    (java.util.Date) getValueAt(new Integer(dataAsli.get(i).toString()), no);
                if (data[4].equals("dd-MM-yyyy")) {
                  value = Function.dateToString(dd);
                } else if (data[4].equals("MM-yyyy")) {
                  value = Function.monthToString(dd);
                } else if (data[4].equals("yyyy")) {
                  //                                    value = Function.yearToDate(sql);
                  JOptionPane.showMessageDialog(null, "Belom Support");
                }
                try {
                  rowSet.updateString(data[3].trim().toString(), value.trim());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else if (data[2].trim().toLowerCase().equals("string")
                  || data[2].trim().toLowerCase().equals("numeric")) {
                String value = "";
                String data1 = data[1].trim();
                if (data1 == null || data1.equals("")) {
                  data1 = "0";
                }
                try {
                  value = getValueAt(new Integer(dataAsli.get(i).toString()), no).toString();
                } catch (Exception e) {
                  //                                    e.printStackTrace();
                  try {
                    value = getValueAt(new Integer(dataAsli.get(i).toString()), no).toString();
                  } catch (Exception ee) {
                    value = "";
                    //                                        e.printStackTrace();
                  }
                }
                if (data[4].trim().toLowerCase().equals("int")) {
                  try {
                    if (value.trim().equals("")) {
                      value = "0";
                    }
                    rowSet.updateLong(data[3].trim().toString(), Long.parseLong(value.trim()));
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  try {
                    rowSet.updateString(data[3].trim().toString(), value.trim());
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              } else if (data[2].trim().toLowerCase().equals("combo")) {
                String value = "";
                value =
                    Function.getValueFromCell(
                        data[5].trim(),
                        getValueAt(new Integer(dataAsli.get(i).toString()), no).toString().trim());
                if (data[4].trim().toLowerCase().equals("int")) {
                  try {
                    rowSet.updateString(data[3].trim().toString(), value.trim());
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  try {
                    rowSet.updateString(data[3].trim().toString(), value.trim());
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              }
            }
          }
          rowSet.updateRow();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #9
0
  // </editor-fold>
  // <editor-fold defaultstate="collapsed" desc="Select Table">
  public void selectTabel(DefaultTableModel tableM) {
    setModelTable(tableM);
    try {
      dataAsli = new Vector();
      rowSet.setCommand(sql);
      rowSet.execute();
      DefaultTableModel dtm = (DefaultTableModel) getModel();
      int i = 0;

      // tipeKolom =
      // untukASIU#noKolomJtable#tipeKolomJTable#namaKolomDB#tipeKolom#atributKolom#nilaiKolom
      // tipeKolom = boolean, Date, String, combo, Int, Numeric
      while (rowSet.next()) {
        Object[] dede = new Object[selectKolom.size()];
        for (int ii = 0; ii < selectKolom.size(); ii++) {
          String temp = selectKolom.get(ii + "");
          String data[] = temp.split("#");
          int no = 0;
          try {
            no = Integer.parseInt(data[1].trim());
          } catch (Exception e) {
            no = 0;
          }
          if (data[0].trim().toLowerCase().contains("s")) {
            if (data[2].trim().toLowerCase().equals("boolean")) {
              boolean value = false;
              if (data[4].trim().toLowerCase().equals("int")) {
                if (rowSet.getInt(data[3].trim()) == Integer.parseInt(data[5].trim())) {
                  value = true;
                } else {
                  value = false;
                }
              } else {
                if (rowSet.getString(data[3].trim()).equals(data[5].trim())) {
                  value = true;
                } else {
                  value = false;
                }
              }
              dede[no] = value;
            } else if (data[2].trim().toLowerCase().equals("date")) {
              java.util.Date value = new java.util.Date();
              if (data[4].equals("dd-MM-yyyy")) {
                value = Function.dateStringToDate(rowSet.getString(data[3].trim()));
              } else if (data[4].equals("MM-yyyy")) {
                value = Function.stringToMonth(rowSet.getString(data[3].trim()));
              } else if (data[4].equals("yyyy")) {
                value = Function.yearToDate(rowSet.getString(data[3].trim()));
              }
              dede[no] = value;
            } else if (data[2].trim().toLowerCase().equals("string")
                || data[2].trim().toLowerCase().equals("combo")
                || data[2].trim().toLowerCase().equals("numeric")) {
              String value = "";
              if (data[4].trim().toLowerCase().equals("int")) {
                value = rowSet.getLong(data[3].trim()) + "";
              } else {
                value = rowSet.getString(data[3].trim());
              }
              dede[no] = value;
            }
          }
        }
        dtm.addRow(dede);
        dataAsli.add(i);
        i++;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #10
0
  public void init(final Function function) {
    xAxis.clear();
    yAxis.clear();

    if (function != lastFunction) { // need to reset
      Slot.CIRCLE.clearList();
      Slot.CROSS.clearList();
      Slot.SQUARE.clearList();
      Slot.TRIANGLE.clearList();
    }

    data = new GridPointData(resolution, resolution, 1);
    plot = new InterpolatedPlot(data);

    useSlot.clearList();
    final List<List<ValuePointColored>> points = useSlot.getPoints();
    for (Slot slot : Slot.values()) {
      if (slot.isShow()) {
        for (List<ValuePointColored> valuePoints : slot.getPoints()) {
          for (ValuePointColored valuePoint : valuePoints) {
            xAxis.add(valuePoint);
            yAxis.add(valuePoint);
          }
        }
      }
    }

    // clean drawing panel
    drawablePanel.removeDrawables(InterpolatedPlot.class);
    drawablePanel.addDrawable(plot);

    datasetRecreation =
        new Closure() {

          public void execute(Object input) {
            List<ValuePointColored> vps = (List<ValuePointColored>) input;
            points.add(vps);
            for (ValuePointColored vp : vps) {
              xAxis.add(vp);
              yAxis.add(vp);
            }

            if (points.size() > maxPoints) {
              List<ValuePointColored> removed = points.remove(0);
              for (ValuePointColored valuePoint : removed) {
                xAxis.remove(valuePoint);
                yAxis.remove(valuePoint);
              }
            }

            // for ilustration
            if (xAxis.size() > 0 && yAxis.size() > 0) {
              double lowerXBound =
                  Math.min(
                      data.getLeft(), Math.floor(xAxis.first().getPoint().toArray()[0] - buffer));
              double upperXBound =
                  Math.max(
                      data.getRight(), Math.ceil(xAxis.last().getPoint().toArray()[0] + buffer));
              double lowerYBound =
                  Math.min(
                      data.getBottom(), Math.floor(yAxis.first().getPoint().toArray()[1] - buffer));
              double upperYBound =
                  Math.max(data.getTop(), Math.ceil(yAxis.last().getPoint().toArray()[1] + buffer));

              data.setScale(lowerXBound, upperXBound, lowerYBound, upperYBound);
              double[][][] xyz = data.getData();

              for (int i = 0; i < resolution; i++) {
                for (int j = 0; j < resolution; j++) {
                  Point p = Point.at(xyz[i][j]);
                  // check the cached value of the point
                  xyz[i][j][2] = /*cache.containsKey(p) ? cache.get(p) :*/ function.valueAt(p);
                }
              }
            }

            plot.setGridData(data);

            drawablePanel.repaint();
          }
        };

    lastFunction = function;

    // initialize to center point
    double lowerXBound = Math.floor(centerX - buffer);
    double upperXBound = Math.ceil(centerX + buffer);
    double lowerYBound = Math.floor(centerY - buffer);
    double upperYBound = Math.ceil(centerY + buffer);

    data.setScale(lowerXBound, upperXBound, lowerYBound, upperYBound);
    double[][][] xyz = data.getData();

    for (int i = 0; i < resolution; i++) {
      for (int j = 0; j < resolution; j++) {
        Point p = Point.at(xyz[i][j]);
        // check the cached value of the point
        xyz[i][j][2] = /*cache.containsKey(p) ? cache.get(p) :*/ function.valueAt(p);
      }
    }

    plot.setGridData(data);
    drawablePanel.repaint();
  }
コード例 #11
0
 public double evaluate_1(double value) {
   return F.evaluate_1(value);
 }