/** Starts adding points to the mouseEvents list every 2 milliseconds */ private void collect() { int same = 0; // The number of times that the mouse has been in same position. pause = false; // whether or not the mouse is currently idle while (record) { if (!pause) { // If the mouse is not currently idle, A new point is added to the "mouseEvents" List. point // has x and y coordinates mouseEvents.add( new SimpleMouseEvent( MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y, 0)); } // If the mouse is currently set as idle, but mouvement has been detected: that is, if the // current position is different than // where the mouse is when it was set as idle... if (pause && ((MouseInfo.getPointerInfo().getLocation().x) != mouseEvents.getLast().gx() || MouseInfo.getPointerInfo().getLocation().y != mouseEvents.getLast().gy())) { unpause(); } // Detects if the current position of the mouse is the same as the last time it was checked. if (mouseEvents.size() > 5 && (mouseEvents .getLast() .toString() .equals(mouseEvents.get(mouseEvents.size() - 2).toString()))) { // If position is the same, the "same" count is increased. same++; // Once the mouse has been in the same place for 10 cycles, it is said to be idle. if (same == 10) { pause = true; // The stopwatch will count how long the mouse has been idle for stopWatch.start(); System.out.println("Pause"); } } else { // If the mouse has moved since last cycle, then the number of times it has been in the same // position is set to 0. same = 0; } try { Thread.sleep(2); // Delay between cycles. } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (!record) { gui.log("Recording Stopped."); gui.refreshActionList(); } } }
// ------------------------------------------ // Local methods: // ------------------------------------------ public void actionPerformed(ActionEvent arg0) { String userName = gui.getUserName(); String title = "Conversation create error"; String[] convNameList; try { convNameList = server.getConversations(userName); } catch (Exception e) { e.printStackTrace(); this.gui.printConnexionError(title); return; } if (convNameList == null) { this.gui.printServerError(ChatServerAnswer.SERVER_USER_UNKNOWN, title); return; } if (convNameList.length == 0) { String msg = "There currently are no conversations"; JOptionPane.showMessageDialog(null, msg, title, JOptionPane.INFORMATION_MESSAGE); return; } String convName = gui.askUserToPickConversationName(convNameList); if (convName == null) return; Conversation conversation; try { conversation = server.JoinConversation(userName, convName); } catch (Exception e) { e.printStackTrace(); this.gui.printConnexionError(title); return; } if (conversation == null) { this.gui.printServerError(ChatServerAnswer.SERVER_INTERNAL_ERROR, title); } else { this.gui.setCurrentConversation(conversation); } }
@FXML private void handleAction(ActionEvent event) { List<IIOImage> iioImageList = GuiController.getInstance().iioImageList; List<BufferedImage> imageList = GuiController.getInstance().imageList; int imageIndex = GuiController.getInstance().imageIndex; if (iioImageList == null && (event.getSource() != chmiScreenshotMode) && event.getSource() != chmiSegmentedRegions) { Alert alert = new Alert(Alert.AlertType.INFORMATION, bundle.getString("Please_load_an_image.")); alert.show(); return; } if (event.getSource() == miMetadata) { try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ImageInfoDialog.fxml")); Parent root = fxmlLoader.load(); ImageInfoDialogController controller = fxmlLoader.getController(); controller.setImage(iioImageList.get(imageIndex)); Stage imageInfoDialog = new Stage(); imageInfoDialog.setResizable(false); imageInfoDialog.initStyle(StageStyle.UTILITY); imageInfoDialog.setAlwaysOnTop(true); // imageInfoDialog.setX(prefs.getDouble(strChangeCaseX, imageInfoDialog.getX())); // imageInfoDialog.setY(prefs.getDouble(strChangeCaseY, imageInfoDialog.getY())); Scene scene1 = new Scene(root); imageInfoDialog.setScene(scene1); imageInfoDialog.setTitle("Image Properties"); imageInfoDialog.toFront(); imageInfoDialog.show(); } catch (Exception e) { } } else if (event.getSource() == miAutocrop) { menuBar.getScene().setCursor(Cursor.WAIT); originalImage = (BufferedImage) iioImageList.get(imageIndex).getRenderedImage(); BufferedImage croppedImage = net.sourceforge.vietocr.util.ImageHelper.autoCrop(originalImage, 0.1); // if same image, skip if (originalImage != croppedImage) { stack.push(originalImage); imageList.set(imageIndex, croppedImage); iioImageList.get(imageIndex).setRenderedImage((BufferedImage) croppedImage); GuiController.getInstance().loadImage(); } menuBar.getScene().setCursor(Cursor.DEFAULT); } else if (event.getSource() == miBrightness) { } else if (event.getSource() == miContrast) { } else if (event.getSource() == miDeskew) { menuBar.getScene().setCursor(Cursor.WAIT); Platform.runLater( new Runnable() { @Override public void run() { ImageDeskew deskew = new ImageDeskew((BufferedImage) iioImageList.get(imageIndex).getRenderedImage()); double imageSkewAngle = deskew.getSkewAngle(); if ((imageSkewAngle > MINIMUM_DESKEW_THRESHOLD || imageSkewAngle < -(MINIMUM_DESKEW_THRESHOLD))) { originalImage = (BufferedImage) iioImageList.get(imageIndex).getRenderedImage(); stack.push(originalImage); BufferedImage rotatedImage = rotateImage(originalImage, Math.toRadians(-imageSkewAngle)); imageList.set(imageIndex, rotatedImage); // persist the rotated image iioImageList.get(imageIndex).setRenderedImage(rotatedImage); GuiController.getInstance().loadImage(); } menuBar.getScene().setCursor(Cursor.DEFAULT); } }); } else if (event.getSource() == miGrayscale) { } else if (event.getSource() == miInvert) { } else if (event.getSource() == miMonochrome) { } else if (event.getSource() == miSharpen) { } else if (event.getSource() == miSmooth) { } else if (event.getSource() == miUndo) { if (stack.isEmpty()) { return; } BufferedImage image = stack.pop(); imageList.set(imageIndex, image); iioImageList.get(imageIndex).setRenderedImage(image); GuiController.getInstance().loadImage(); } else if (event.getSource() == chmiScreenshotMode) { Label labelScreenShotMode = (Label) menuBar.getScene().lookup("#labelScreenShotMode"); labelScreenShotMode.setText(this.chmiScreenshotMode.isSelected() ? "On" : "Off"); } else if (event.getSource() == chmiSegmentedRegions) { Node segmentedRegionsBox = menuBar.getScene().lookup("#segmentedRegionsBox"); segmentedRegionsBox.setVisible(chmiSegmentedRegions.isSelected()); } }
/** Starts collection mouse information. Clears previous mouse events. */ public void startRecording() { gui.log("Recording Macro..."); mouseEvents.clear(); this.record = true; }