@Override public void mouseMoved(MouseEvent evt) { Point point = evt.getPoint(); updateCursor(editor.findView((Container) evt.getSource()), point); DrawingView view = editor.findView((Container) evt.getSource()); updateCursor(view, point); if (view == null || editor.getActiveView() != view) { clearHoverHandles(); } else { // Search first, if one of the selected figures contains // the current mouse location. Only then search for other // figures. This search sequence is consistent with the // search sequence of the SelectionTool. Figure figure = null; Point2D.Double p = view.viewToDrawing(point); for (Figure f : view.getSelectedFigures()) { if (f.contains(p)) { figure = f; } } if (figure == null) { figure = view.findFigure(point); Drawing drawing = view.getDrawing(); while (figure != null && !figure.isSelectable()) { figure = drawing.findFigureBehind(p, figure); } } updateHoverHandles(view, figure); } }
protected DrawingView createDrawingView(Drawing newDrawing) { Dimension d = getDrawingViewSize(); DrawingView newDrawingView = new StandardDrawingView(this, d.width, d.height); newDrawingView.setDrawing(newDrawing); fireViewCreatedEvent(newDrawingView); return newDrawingView; }
public void execute() { PointConstrainer grid = fView.getConstrainer(); if (grid != null) { fView.setConstrainer(null); } else { fView.setConstrainer(new GridConstrainer(fGrid.x, fGrid.y)); } }
/** Inserts a vector of figures and translates them by the given offset. */ protected void insertFigures(Vector figures, int dx, int dy) { FigureEnumeration e = new FigureEnumerator(figures); while (e.hasMoreElements()) { Figure figure = e.nextFigure(); figure.moveBy(dx, dy); figure = fView.add(figure); fView.addToSelection(figure); } }
public void classify() { if (nb.isTrained()) { Features features = new Features(drawView.getPoints(), drawView.getStrokes()); double predicted = nb.classifyInstance(features); resultText.setText(Integer.toString((int) predicted)); } else { showAlertDialog("Bład", "Klasyfikator nie został wyuczony"); } }
public void add() { if (digitEditText.getText().toString().equals("")) { showAlertDialog("Bład", "Nie podano cyfry do dodania"); } else if (drawView.getPoints().size() == 0) { showAlertDialog("Bład", "Obrazek nie został narysowany"); } else { Features features = new Features(drawView.getPoints(), drawView.getStrokes()); List<Double> featureValues = features.calculateFeatures(); drawView.cleanDrawing(); writeToFile(featureValues); } }
protected ConnectionFigure createConnection() { try { Class cLayer = Class.forName(objType); LayerConnection lc = (LayerConnection) cLayer.newInstance(); lc.setParams(params); // Each component is provided with a pointer to the parent NeuralNet object NeuralNetDrawing nnd = (NeuralNetDrawing) view.drawing(); lc.setParam("NeuralNet", nnd.getNeuralNet()); return lc; } catch (ClassNotFoundException cnfe) { log.warn( "ClassNotFoundException exception thrown while ConnectionFigure. Message is : " + cnfe.getMessage(), cnfe); } catch (InstantiationException ie) { log.warn( "InstantiationException exception thrown while ConnectionFigure. Message is : " + ie.getMessage(), ie); } catch (IllegalAccessException iae) { log.warn( "IllegalAccessException exception thrown while ConnectionFigure. Message is : " + iae.getMessage(), iae); } return null; }
/** Connects the figures if the mouse is released over another figure. */ public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { Connector target = findConnectionTarget(x, y, view.drawing()); if (target != null) { getConnection().connectStart(startConnector()); getConnection().connectEnd(target); getConnection().updateConnection(); } else { view.drawing().remove(getConnection()); setUndoActivity(null); } setConnection(null); if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(false, null); setTargetFigure(null); } }
/** * Connects the figure to the new target. If there is no new target the connection reverts to its * original one. */ public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { Connector target = findConnectionTarget(x, y, view.drawing()); if (target == null) { target = fOriginalTarget; } setPoint(x, y); connect(target); getConnection().updateConnection(); Connector oldConnector = ((ChangeConnectionHandle.UndoActivity) getUndoActivity()).getOldConnector(); // there has been no change so there is nothing to undo if ((oldConnector == null) || (target() == null) || (oldConnector.owner() == target().owner())) { setUndoActivity(null); } else { getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getConnection())); } if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(false); setTargetFigure(null); } }
public void paintClicked(View view) { // use chosen color if (view != currPaint) { // update color ImageButton imgView = (ImageButton) view; String color = (String) view.getTag(); drawView.setColor(Color.parseColor(color), clientID); drawView.paintColor = Color.parseColor(color); imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed)); currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint)); currPaint = (ImageButton) view; } }
/** Refreshes the drawing if there is some accumulated damage */ public synchronized void checkDamage() { Iterator each = drawing().drawingChangeListeners(); while (each.hasNext()) { Object l = each.next(); if (l instanceof DrawingView) { ((DrawingView) l).repairDamage(); } } }
/** Finds a new target of the connection. */ public void invokeStep(int x, int y, int anchorX, int anchorY, DrawingView view) { Point p = new Point(x, y); Figure f = findConnectableFigure(x, y, view.drawing()); // track the figure containing the mouse if (f != getTargetFigure()) { if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(false); } setTargetFigure(f); if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(true); } } Connector target = findConnectionTarget(p.x, p.y, view.drawing()); if (target != null) { p = Geom.center(target.displayBox()); } setPoint(p.x, p.y); }
/** Handles a mouse click. */ @Override public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) { if (evt.getClickCount() == 2 && view.getHandleDetailLevel() % 2 == 0) { willChange(); final int index = splitSegment(p, 5f / view.getScaleFactor()); if (index != -1) { final BezierPath.Node newNode = getNode(index); fireUndoableEditHappened( new AbstractUndoableEdit() { private static final long serialVersionUID = 1L; @Override public String getPresentationName() { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); return labels.getString("edit.bezierPath.splitSegment.text"); } @Override public void redo() throws CannotRedoException { super.redo(); willChange(); addNode(index, newNode); changed(); } @Override public void undo() throws CannotUndoException { super.undo(); willChange(); removeNode(index); changed(); } }); changed(); evt.consume(); return true; } } return false; }
/** Creates the connection */ public void invokeStart(int x, int y, DrawingView view) { setConnection(createConnection()); setUndoActivity(createUndoActivity(view)); Vector v = new Vector(); v.add(getConnection()); getUndoActivity().setAffectedFigures(new FigureEnumerator(v)); Point p = locate(); getConnection().startPoint(p.x, p.y); getConnection().endPoint(p.x, p.y); view.drawing().add(getConnection()); }
/** * captures the current bitmap. Calls the save Async task and then loads the new bitmap. * * @param rootview */ private void dispatchDisplayNextImage(View rootview) { if (images != null && !images.isEmpty()) { Image image = images.get(0); if (LABEL_VIEW_TRUE) { toggleLableView(rootview); } drawView.setDrawingCacheEnabled(true); Bitmap bMap = drawView.getDrawingCache(true).copy(Bitmap.Config.RGB_565, false); drawView.destroyDrawingCache(); image.setQuestionComments(commentsEnter.getText().toString()); image.setGrade((float) GRADE); image.setGradeActual((float) GRADEACTUAL); Student student = new Student(); student.setStatus(2); student.setStudentID(ASUAD); new SaveGradedImage(getBaseContext(), student).execute(image, bMap, label, Weights); images.remove(0); if (!images.isEmpty()) { imageLocation = images.get(0).getLocation(); QR_CODE_QUESTION = images.get(0).getQrCodeSolution(); LABEL_VIEW_TRUE = false; Log.d(TAG, "dispatchDisplayNextImage: changing label view to " + false); if (generateQuestionWeights(rootview)) { new ShowNewGradableImage(this, drawView).execute(imageLocation); } else finish(); } else { imageLocation = null; new StudentDao(this).updateStatus(SelectedClass.getInstance().getCurrentClass(), student); Toast.makeText( getBaseContext(), "Image Saved. No more gradable images available", Toast.LENGTH_SHORT) .show(); this.finish(); } dispatchGenerateGrade(); } }
@Override public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) { if (evt.getClickCount() == 2 /* && view.getHandleDetailLevel() == 0*/) { willChange(); // Apply inverse of transform to point if (get(TRANSFORM) != null) { try { p = (Point2D.Double) get(TRANSFORM).inverseTransform(p, new Point2D.Double()); } catch (NoninvertibleTransformException ex) { System.err.println( "Warning: SVGBezierFigure.handleMouseClick. Figure has noninvertible Transform."); } } final int index = splitSegment(p, (float) (5f / view.getScaleFactor())); if (index != -1) { final BezierPath.Node newNode = getNode(index); fireUndoableEditHappened( new AbstractUndoableEdit() { @Override public String getPresentationName() { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); return labels.getString("edit.bezierPath.splitSegment.text"); } @Override public void redo() throws CannotRedoException { super.redo(); willChange(); addNode(index, newNode); changed(); } @Override public void undo() throws CannotUndoException { super.undo(); willChange(); removeNode(index); changed(); } }); changed(); evt.consume(); return true; } } return false; }
/** Draws a pattern background pattern by replicating an image. */ protected void drawPattern(Graphics g, Image image, DrawingView view) { int iwidth = image.getWidth(view); int iheight = image.getHeight(view); Dimension d = view.getSize(); int x = 0; int y = 0; while (y < d.height) { while (x < d.width) { g.drawImage(image, x, y, view); x += iwidth; } y += iheight; x = 0; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawView = (DrawingView) findViewById(R.id.drawing); smallBrush = getResources().getInteger(R.integer.small_size); mediumBrush = getResources().getInteger(R.integer.medium_size); largeBrush = getResources().getInteger(R.integer.large_size); drawBtn = (ImageButton) findViewById(R.id.draw_btn); drawBtn.setOnClickListener(this); drawView.setBrushSize(mediumBrush); eraseBtn = (ImageButton) findViewById(R.id.erase_btn); eraseBtn.setOnClickListener(this); newBtn = (ImageButton) findViewById(R.id.new_btn); newBtn.setOnClickListener(this); equalsBtn = (ImageButton) findViewById(R.id.equals_btn); equalsBtn.setOnClickListener(this); }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.CleanButton: drawView.cleanDrawing(); resultText.setText(""); break; case R.id.AddButton: add(); break; case R.id.ClassifyButton: classify(); break; case R.id.TrainButton: train(); break; default: break; } }
/** * Creates the drawing view used in this application. You need to override this method to use a * DrawingView subclass in your application. By default a standard DrawingView is returned. */ protected DrawingView createDrawingView() { DrawingView createdDrawingView = createDrawingView(createDrawing()); createdDrawingView.drawing().setTitle(getDefaultDrawingTitle()); return createdDrawingView; }
/** * Tracks the end of the interaction. * * @param x the current x position * @param y the current y position * @param anchorX the x position where the interaction started * @param anchorY the y position where the interaction started */ public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { invokeEnd(x - anchorX, y - anchorY, view.drawing()); }
/** * @param x the x position where the interaction started * @param y the y position where the interaction started * @param view the handles container */ public void invokeStart(int x, int y, DrawingView view) { invokeStart(x, y, view.drawing()); }
public void increaseHandleDetaiLevel() { DrawingView view = getView(); if (view != null) { view.setHandleDetailLevel(view.getHandleDetailLevel() + 1); } }
/** Copies the selection to the clipboard. */ protected void copySelection() { FigureSelection selection = fView.getFigureSelection(); Clipboard.getClipboard().setContents(selection); }
/** Deletes the selection from the drawing. */ protected void deleteSelection() { fView.drawing().removeAll(fView.selection()); fView.clearSelection(); }
@Override public void onClick(View view) { if (view.getId() == R.id.draw_btn) { if (!drawView.getErase()) { final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Brush size:"); brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(smallBrush); drawView.setLastBrushSize(smallBrush); brushDialog.dismiss(); } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(mediumBrush); drawView.setLastBrushSize(mediumBrush); brushDialog.dismiss(); } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(largeBrush); drawView.setLastBrushSize(largeBrush); brushDialog.dismiss(); } }); brushDialog.show(); } drawView.setErase(false); } else if (view.getId() == R.id.erase_btn) { if (drawView.getErase()) { final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Eraser size:"); brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(smallBrush); brushDialog.dismiss(); } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(mediumBrush); brushDialog.dismiss(); } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(largeBrush); brushDialog.dismiss(); } }); brushDialog.show(); } drawView.setErase(true); } else if (view.getId() == R.id.new_btn) { AlertDialog.Builder newDialog = new AlertDialog.Builder(this); newDialog.setTitle("New equation"); newDialog.setMessage("Start new equation?"); newDialog.setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { drawView.startNew(); dialog.dismiss(); } }); newDialog.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); newDialog.show(); } else if (view.getId() == R.id.equals_btn) { // save drawing } }
/** * Loads the first gradable image for the student. Verifies if the label data for the image * exists. Inflates the layout activity_grading_screen. * * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grading_screen); Bundle extras = getIntent().getExtras(); ASUAD = extras.getString("ASUAD"); Log.d(TAG, "onCreate: entered image fragment " + ASUAD); gradeGenerated = (TextView) findViewById(R.id.grade_show); imageDAO = new ImageDAO(getBaseContext()); images = imageDAO.getAllNonGradedImageLocations(ASUAD); if (images != null && !images.isEmpty()) { imageLocation = images.get(0).getLocation(); QR_CODE_QUESTION = images.get(0).getQrCodeSolution(); } else { Log.e(TAG, "onCreate: images is empty or null"); Toast.makeText(getBaseContext(), "No images available to grade", Toast.LENGTH_SHORT).show(); finish(); } final View rootView = findViewById(android.R.id.content); drawView = (DrawingView) rootView.findViewById(R.id.drawing); ImageButton save = (ImageButton) rootView.findViewById(R.id.process_next); ImageButton showLabels = (ImageButton) rootView.findViewById(R.id.process_show_labels); if (imageLocation != null) { if (generateQuestionWeights(rootView)) { new ShowNewGradableImage(this, drawView).execute(imageLocation); showLabels.setEnabled(true); } else finish(); } else { showLabels.setEnabled(false); Toast.makeText(getBaseContext(), "No images available to grade", Toast.LENGTH_SHORT).show(); finish(); } drawView.setDrawingCacheEnabled(true); save.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (imageLocation != null) { dispatchDisplayNextImage(rootView); } } }); rootView .findViewById(R.id.process_refresh_labels) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (layout_horizontal != null) { for (LinearLayout layout : layout_horizontal) layout.setVisibility(View.GONE); } generateQuestionWeights(rootView); dispatchGenerateGrade(); } }); ImageButton undo = (ImageButton) rootView.findViewById(R.id.process_erase); undo.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { drawView.undo(); } }); showLabels.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { toggleLableView(rootView); } }); ImageButton done = (ImageButton) rootView.findViewById(R.id.process_done); done.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
@Override public void mousePressed(MouseEvent evt) { if (getView() != null && getView().isEnabled()) { super.mousePressed(evt); DrawingView view = getView(); Handle handle = view.findHandle(anchor); Tool newTracker = null; if (handle != null) { newTracker = getHandleTracker(handle); } else { Figure figure; Drawing drawing = view.getDrawing(); Point2D.Double p = view.viewToDrawing(anchor); if (isSelectBehindEnabled() && (evt.getModifiersEx() & (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) != 0) { // Select a figure behind the current selection figure = view.findFigure(anchor); while (figure != null && !figure.isSelectable()) { figure = drawing.findFigureBehind(p, figure); } HashSet<Figure> ignoredFigures = new HashSet<Figure>(view.getSelectedFigures()); ignoredFigures.add(figure); Figure figureBehind = view.getDrawing().findFigureBehind(view.viewToDrawing(anchor), ignoredFigures); if (figureBehind != null) { figure = figureBehind; } } else { // Note: The search sequence used here, must be // consistent with the search sequence used by the // DefaultHandleTracker, the DefaultSelectAreaTracker and DelegationSelectionTool. // If possible, continue to work with the current selection figure = null; if (isSelectBehindEnabled()) { for (Figure f : view.getSelectedFigures()) { if (f.contains(p)) { figure = f; break; } } } // If the point is not contained in the current selection, // search for a figure in the drawing. if (figure == null) { figure = view.findFigure(anchor); while (figure != null && !figure.isSelectable()) { figure = drawing.findFigureBehind(p, figure); } } } if (figure != null && figure.isSelectable()) { newTracker = getDragTracker(figure); } else { if (!evt.isShiftDown()) { view.clearSelection(); view.setHandleDetailLevel(0); } newTracker = getSelectAreaTracker(); } } if (newTracker != null) { setTracker(newTracker); } tracker.mousePressed(evt); } }
public static void clearScreen() { drawView.clearCanvas(); }