Exemple #1
0
  /**
   * update the canvas with latest changes to model drawing. Zoom is managed. Changes performed by
   * tool are managed.
   */
  @Override
  protected void onDraw(Canvas canvas) {

    dLogger.start();
    Rect bounds = mModel.getBounds();
    Rect dummyBounds = new Rect();

    if (bounds != null && canvas.getClipBounds(dummyBounds)) {

      // Draw current path in a scratch buffer
      Rect tmp = (Rect) new Rect(mWindowRect); // TODO restore code to manage part of change only.
      // mCoordinateMapper.fromReference(bounds); // find out what part of the canvas is impacted.
      tmp.intersect(mWindowRect); // We don't update outside of the screen
      Rect srcRect = mCoordinateMapper.toReference(tmp);
      Log.i(
          "onDraw",
          "refreshing partial area "
              + tmp
              + " from "
              + srcRect
              + " clip bounds were "
              + dummyBounds);
      mModel.renderTentativeUpdates(mTool, srcRect);
      // update the impacted part from the corresponding input part.
      mModel.copyRendered(canvas, srcRect, tmp);

    } else {
      Rect srcRect = mCoordinateMapper.toReference(mWindowRect);
      Log.i("onDraw", "refreshing whole area" + mWindowRect + " from " + srcRect);
      mModel.copyReference(canvas, srcRect, mWindowRect);
    }
    // canvas.drawPath(mPath, mPaint); //TODO all drawing should be performed in reference bitmap
    dLogger.end();
  }
  /**
   * Parse and store the tokenized version of the macro.
   *
   * @layerV the array containing the layer description to be inherited.
   */
  private void macroStore(Vector<LayerDesc> layerV) {
    macro.setLibrary(library); // Inherit the library
    macro.setLayers(layerV); // Inherit the layers
    changed = true;

    if (macroDesc != null) {
      ParserActions pa = new ParserActions(macro);
      pa.parseString(new StringBuffer(macroDesc));
      // Recursive call
    }
  }
Exemple #3
0
 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
   super.onSizeChanged(w, h, oldw, oldh);
   if (mModel.getBitmap() == null) {
     mModel.createBlank(w, h);
   }
   mDrawingTool = new DrawingTool(mModel, mCoordinateMapper);
   mTool = mDrawingTool;
   mStampingTool = null;
   updateCoordinateMapper();
   mWindowRect = new Rect(0, 0, getWidth(), getHeight());
 }
Exemple #4
0
  protected static boolean saveFileAs() {
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(JvdExtensionFilter.getInstance());
    fc.setAcceptAllFileFilterUsed(false);

    int returnValue = fc.showSaveDialog(parent);

    if (returnValue != JFileChooser.APPROVE_OPTION) {
      return false;
    }

    File file = fc.getSelectedFile();

    if (!file.getAbsolutePath().endsWith(".jvd")) {
      file = new File(file.getAbsoluteFile() + ".jvd");
    }

    if (file.exists()) {
      int choice =
          JOptionPane.showOptionDialog(
              parent,
              "File " + file.getName() + " already exists. Do you want to replace it?",
              "Replace " + file.getName() + "?",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.WARNING_MESSAGE,
              null,
              null,
              null);
      if (choice != JOptionPane.YES_OPTION) {
        return false;
      }
    }

    try (BufferedWriter bw =
        new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(file, false), StandardCharsets.UTF_8))) {
      int count = drawingModel.getSize();
      for (int i = 0; i < count; i++) {
        bw.write(drawingModel.getObject(i).toJVD());
        bw.newLine();
      }

    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          parent, "Error saving file!", "Error!", JOptionPane.ERROR_MESSAGE);
    }

    drawingModel.changed = false;
    drawingModel.openedFile = file;
    return true;
  }
  /**
   * Each graphic primitive should call the appropriate exporting method of the export interface
   * specified.
   *
   * @param exp the export interface that should be used.
   * @param cs the actual coordinate mapping.
   * @throws IOException if a problem occurs, such as it is impossible to write on the output file.
   */
  public void export(ExportInterface exp, MapCoordinates cs) throws IOException {
    if (alreadyExported) return;

    // Call the macro interface, to see if the macro should be expanded

    if (exp.exportMacro(
        cs.mapX(virtualPoint[0].x, virtualPoint[0].y),
        cs.mapY(virtualPoint[0].x, virtualPoint[0].y),
        m,
        o * 90,
        macroName,
        macroDesc,
        name,
        cs.mapX(virtualPoint[1].x, virtualPoint[1].y),
        cs.mapY(virtualPoint[1].x, virtualPoint[1].y),
        value,
        cs.mapX(virtualPoint[2].x, virtualPoint[2].y),
        cs.mapY(virtualPoint[2].x, virtualPoint[2].y),
        macroFont,
        (int) (cs.mapYr(getMacroFontSize(), getMacroFontSize()) - cs.mapYr(0, 0)),
        library)) {
      alreadyExported = true;
      return;
    }
    /* in the macro primitive, the virtual point represents
    the position of the reference point of the macro to be drawn. */

    int x1 = virtualPoint[0].x;
    int y1 = virtualPoint[0].y;

    MapCoordinates macroCoord = new MapCoordinates();

    macroCoord.setXMagnitude(cs.getXMagnitude());
    macroCoord.setYMagnitude(cs.getYMagnitude());

    macroCoord.setXCenter(cs.mapXr(x1, y1));
    macroCoord.setYCenter(cs.mapYr(x1, y1));

    macroCoord.setOrientation((o + cs.getOrientation()) % 4);
    macroCoord.mirror = m ^ cs.mirror;
    macroCoord.isMacro = true;

    macro.setDrawOnlyLayer(drawOnlyLayer);

    if (getSelected()) new SelectionActions(macro).setSelectionAll(true);

    macro.setDrawOnlyPads(drawOnlyPads);
    new Export(macro).exportDrawing(exp, false, exportInvisible, macroCoord);
    exportText(exp, cs, drawOnlyLayer);
  }
  /**
   * Draw the macro contents.
   *
   * @param g the graphic context.
   * @param coordSys the coordinate system.
   * @param layerV the vector containing all layers.
   */
  private void drawMacroContents(GraphicsInterface g, MapCoordinates coordSys, Vector layerV) {
    /* in the macro primitive, the the virtual point represents
    the position of the reference point of the macro to be drawn. */
    if (changed) {
      changed = false;
      x1 = virtualPoint[0].x;
      y1 = virtualPoint[0].y;

      macroCoord.setXMagnitude(coordSys.getXMagnitude());
      macroCoord.setYMagnitude(coordSys.getYMagnitude());

      macroCoord.setXCenter(coordSys.mapXr(x1, y1));
      macroCoord.setYCenter(coordSys.mapYr(x1, y1));
      macroCoord.setOrientation((o + coordSys.getOrientation()) % 4);
      macroCoord.mirror = m ^ coordSys.mirror;
      macroCoord.isMacro = true;
      macroCoord.resetMinMax();

      macro.setChanged(true);
    }

    if (getSelected()) {
      new SelectionActions(macro).setSelectionAll(true);
      selected = true;
    } else if (selected) {
      new SelectionActions(macro).setSelectionAll(false);
      selected = false;
    }

    macro.setDrawOnlyLayer(drawOnlyLayer);
    macro.setDrawOnlyPads(drawOnlyPads);

    drawingAgent = new Drawing(macro);
    drawingAgent.draw(g, macroCoord);

    if (macroCoord.getXMax() > macroCoord.getXMin()
        && macroCoord.getYMax() > macroCoord.getYMin()) {
      coordSys.trackPoint(macroCoord.getXMax(), macroCoord.getYMax());
      coordSys.trackPoint(macroCoord.getXMin(), macroCoord.getYMin());
    }
  }
Exemple #7
0
  /**
   * Main method that handles low level touch events and calls the specific methods touch_up,
   * touch_down, touch_move.
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    float referenceCoords[] = mCoordinateMapper.toReferenceRounded(x, y);
    mTouchLogger.onTouchEvent(event);
    // mScaleDetector.onTouchEvent(event);
    mScrollDetector.onTouchEvent(event);
    if (!gestureInProgress) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          mTool.touch_start(referenceCoords[0], referenceCoords[1]);

          break;
        case MotionEvent.ACTION_MOVE:
          mTool.touch_move(referenceCoords[0], referenceCoords[1]);

          break;
        case MotionEvent.ACTION_UP:
          mTool.touch_up();

          break;

        default:
          Log.w("View", "unrecognized action" + event.getAction());
      }
      if (mModel.getBounds() != null) {
        invalidate(mCoordinateMapper.fromReference(mModel.getBounds()));
        // mBounds = null; // invalidate operation is destructive, so the pointer should not be kept

      } else {
        invalidate();
      }
    }
    return true;
  }
Exemple #8
0
  protected void updateCoordinateMapper() {
    float w = mModel.getBitmap().getWidth();
    float h = mModel.getBitmap().getHeight();
    float screenWidth = getWidth();
    float screenHeight = getHeight();
    float wRatio = screenWidth / w;
    float hRatio = screenHeight / h;
    if (wRatio > hRatio) {
      mCoordinateMapper =
          new CoordinateMapper(0, 0, w, screenHeight / wRatio, getWidth(), getHeight());

    } else {
      mCoordinateMapper =
          new CoordinateMapper(0, 0, screenWidth / hRatio, h, getWidth(), getHeight());
    }
  }
Exemple #9
0
 void blankCanvas(int width, int height, int fillMode) {
   mModel.createBlank(width, height, fillMode);
   updateCoordinateMapper();
   invalidate();
 }
Exemple #10
0
 /**
  * Get the maximum index of the layers contained in the macro.
  *
  * @return the maximum index of layers contained in the macro.
  */
 public int getMaxLayer() {
   return macro.getMaxLayer();
 }
Exemple #11
0
 /**
  * Set the layer vector.
  *
  * @param layerV the layer vector.
  */
 public void setLayers(Vector<LayerDesc> layerV) {
   macro.setLayers(layerV);
 }
Exemple #12
0
 /**
  * change the drawing to the given . Update coordinate mapping accordingly.
  *
  * @param bitmap
  */
 public void setBitmap(Bitmap bitmap) {
   mModel.setBitmap(bitmap);
   updateCoordinateMapper();
 }
Exemple #13
0
 /**
  * Specifies that the current primitive has been modified or not. If it is true, during the redraw
  * all parameters should be calulated from scratch.
  *
  * @param c the value of the parameter.
  */
 public void setChanged(boolean c) {
   super.setChanged(c);
   macro.setChanged(c);
 }
Exemple #14
0
 public void zoomOut(float d, float focusX, float focusY) {
   mCoordinateMapper.zoomOut(d, focusX, focusY);
   mModel.setBounds(null); // we update everything
   invalidate();
 }
Exemple #15
0
 /**
  * Returns true if the macro contains the specified layer. This is a calculation done at the
  * DrawingModel level.
  *
  * @param l the layer to be checked.
  * @return true if the layer is contained in the drawing and therefore should be drawn.
  */
 public boolean containsLayer(int l) {
   return macro.containsLayer(l);
 }
Exemple #16
0
 public void zoomIn(float d) {
   mCoordinateMapper.zoomIn(d);
   mModel.setBounds(null); // we update everything
   invalidate();
 }
Exemple #17
0
  public Bitmap getBitmap() {

    return mModel.getBitmap();
  }
Exemple #18
0
 public void undo() {
   mModel.undoLastChange();
   invalidate();
 }