Package com.agifans.picedit.picture

Examples of com.agifans.picedit.picture.Picture


                if (application.hasVisiblePictureFrame() && !application.getPicture().getCurrentPictureCode().isDataCode()) {
                    Point mousePoint = event.getPoint();
                    Rectangle colourBox = new Rectangle(30, 5, 30, 23);
                    boolean clickInColourBox = colourBox.contains(mousePoint);
                    EditStatus editStatus = application.getEditStatus();
                    Picture picture = application.getPicture();
                   
                    switch (colourType) {
                        case VISUAL:
                            if (editStatus.isVisualDrawEnabled() && !clickInColourBox) {
                                // If click is on the visual button but not in the colour box and visual
                                // drawing is currently on then turn off visual drawing.
                                picture.processVisualColourOff();
                            } else {
                                // Pop up colour chooser.
                                ColourChooserDialog dialog = new ColourChooserDialog(ColourButton.this);
                                dialog.setVisible(true);
                               
                                // Process the chosen visual colour.
                                if (dialog.getChosenColour() != -1) {
                                    picture.processVisualColourChange(dialog.getChosenColour());
                                }
                            }
                            break;
                        case PRIORITY:
                            if (editStatus.isPriorityDrawEnabled() && !clickInColourBox) {
                                // If click is on the priority button but not in the colour box and priority
                                // drawing is currently on then turn off priority drawing.
                                picture.processPriorityColourOff();
                            } else {
                                // Pop up colour chooser.
                                ColourChooserDialog dialog = new ColourChooserDialog(ColourButton.this);
                                dialog.setVisible(true);
                               
                                // Process the chosen priority colour.
                                if (dialog.getChosenColour() != -1) {
                                    picture.processPriorityColourChange(dialog.getChosenColour());
                                }
                            }
                            break;
                    }
                }
View Full Code Here


    public PictureFrame(final PicEdit application, int initialZoomFactor, String defaultPictureName) {
        this.application = application;
        this.defaultPictureName = defaultPictureName;
        this.editStatus = new EditStatus();
        this.editStatus.setZoomFactor(initialZoomFactor);
        this.picture = new Picture(editStatus);
        this.pictureCodeList = new PictureCodeList(picture);
        this.picture.addPictureChangeListener(pictureCodeList);
        this.egoTestHandler = new EgoTestHandler(editStatus, picture);
        this.picturePanel = new PicturePanel(editStatus, picture, egoTestHandler);
        mouseHandler = new MouseHandler(this, application);
View Full Code Here

            }
        };
       
        StatusBarSection positionPanel = new StatusBarSection(200) {
            void drawSectionDetail(Graphics2D graphics) {
                Picture picture = application.getPicture();
                int picturePosition = picture.getPicturePosition();
                int pictureSize = picture.getPictureCodes().size() - 1;
                String posStr = String.format("Position: %d/%d", picturePosition, pictureSize);
                graphics.drawString(posStr, 8, 15);
            }
        };
       
View Full Code Here

    public void processMouseClick(Point mousePoint, int mouseButton) {
        int x = (int) mousePoint.getX();
        int y = (int) mousePoint.getY();
       
        EditStatus editStatus = application.getEditStatus();
        Picture picture = application.getPicture();

        // Is it the LEFT mouse button?
        if (mouseButton == MouseEvent.BUTTON1) {
            // Is a tool active?
            if (editStatus.getTool() != ToolType.NONE) {
                // Register the new left mouse click in the edit status.
                editStatus.addClickPoint();

                // Get the 'adjusted' X & Y position back from the edit status.
                Point pictureClickPoint = editStatus.getClickPoint();
                x = (int) pictureClickPoint.getX();
                y = (int) pictureClickPoint.getY();

                // Get the previous mouse click point for use with Line, Pen, Step.
                int previousX = 0;
                int previousY = 0;
                Point previousClickPoint = editStatus.getPreviousClickPoint();
                if (previousClickPoint != null) {
                    previousX = (int) previousClickPoint.getX();
                    previousY = (int) previousClickPoint.getY();
                }

                // If a given tool is active then update the AGI picture.
                if (editStatus.isFillActive()) {
                    picture.fill(x, y);
                    if (editStatus.isFirstClick()) {
                        picture.addPictureCode(PictureCodeType.DRAW_FILL);
                    }
                    picture.addPictureCode(PictureCodeType.FILL_POINT_DATA, x, y);
                } else if (editStatus.isLineActive()) {
                    switch (editStatus.getNumOfClicks()) {
                        case 1:
                            picture.addPictureCode(PictureCodeType.DRAW_LINE);
                            picture.addPictureCode(x, y);
                            picture.putPixel(x, y);
                            break;
                        default:
                            picture.addPictureCode(x, y);
                            picture.drawLine(previousX, previousY, x, y);
                            break;
                    }
                } else if (editStatus.isPenActive()) {
                    int disp = 0;
                    int dX = 0;
                    int dY = 0;

                    switch (editStatus.getNumOfClicks()) {
                        case 1:
                            picture.addPictureCode(PictureCodeType.DRAW_SHORT_LINE);
                            picture.addPictureCode(x, y);
                            picture.putPixel(x, y);
                            break;
                        default:
                            dX = adjustForPen(x - previousX, 6);
                            dY = adjustForPen(y - previousY, 7);
                            x = previousX + dX;
                            y = previousY + dY;

                            if (dX < 0) {
                                disp = (0x80 | ((((-1) * dX) - 0) << 4));
                            } else {
                                disp = (dX << 4);
                            }
                            if (dY < 0) {
                                disp |= (0x08 | (((-1) * dY) - 0));
                            } else {
                                disp |= dY;
                            }
                            picture.addPictureCode(PictureCodeType.RELATIVE_POINT_DATA, disp, new Point(x, y));
                            picture.drawLine(previousX, previousY, x, y);
                            editStatus.setClickPoint(new Point(x, y));
                            break;
                    }
                } else if (editStatus.isBrushActive()) {
                    int patNum = 0;

                    if (editStatus.isFirstClick()) {
                        picture.addPictureCode(PictureCodeType.SET_BRUSH_TYPE);
                        picture.addPictureCode(PictureCodeType.BRUSH_TYPE_DATA, editStatus.getBrushCode());
                        picture.addPictureCode(PictureCodeType.DRAW_BRUSH_POINT);
                    }
                    patNum = (((new java.util.Random().nextInt(255)) % 0xEE) >> 1) & 0x7F;
                    picture.plotPattern(patNum, x, y);
                    if (editStatus.getBrushTexture() == BrushTexture.SPRAY) {
                        picture.addPictureCode(PictureCodeType.BRUSH_PATTERN_DATA, patNum << 1);
                    }
                    picture.addPictureCode(PictureCodeType.BRUSH_POINT_DATA, x, y);
                } else if (editStatus.isStepActive()) {
                    int dX = 0;
                    int dY = 0;

                    switch (editStatus.getNumOfClicks()) {
                        case 1:
                            break;

                        case 2:
                            dX = x - previousX;
                            dY = y - previousY;
                            if (Math.abs(dX) > Math.abs(dY)) { /* X or Y corner */
                                y = previousY;
                                editStatus.setStepType(StepType.XCORNER);
                                picture.addPictureCode(PictureCodeType.DRAW_HORIZONTAL_STEP_LINE);
                                picture.addPictureCode(previousX, previousY);
                                picture.addPictureCode(PictureCodeType.X_POSITION_DATA, x, new Point(x, y));
                            } else {
                                x = previousX;
                                editStatus.setStepType(StepType.YCORNER);
                                picture.addPictureCode(PictureCodeType.DRAW_VERTICAL_STEP_LINE);
                                picture.addPictureCode(previousX, previousY);
                                picture.addPictureCode(PictureCodeType.Y_POSITION_DATA, y, new Point(x, y));
                            }
                            picture.drawLine(previousX, previousY, x, y);
                            editStatus.setClickPoint(new Point(x, y));
                            break;

                        default:
                            if ((editStatus.isXCornerActive() && ((editStatus.getNumOfClicks() % 2) > 0)) || (editStatus.isYCornerActive() && ((editStatus.getNumOfClicks() % 2) == 0))) {
                                // X and Y corners toggle different direction based on number of clicks. 
                                x = previousX;
                                picture.addPictureCode(PictureCodeType.Y_POSITION_DATA, y, new Point(x, y));
                            } else {
                                y = previousY;
                                picture.addPictureCode(PictureCodeType.X_POSITION_DATA, x, new Point(x, y));
                            }
                            picture.drawLine(previousX, previousY, x, y);
                            editStatus.setClickPoint(new Point(x, y));
                            break;
                    }
                }
            }
        }
       
        // Is it the RIGHT mouse button?
        if (mouseButton == MouseEvent.BUTTON3) {
            // Right-clicking on the AGI picture will clear the current tool selection.
            if ((editStatus.getNumOfClicks() == 1) && (editStatus.isStepActive())) {
                // Single point line support for the Step tool.
               
                // Get the 'adjusted' X & Y position back from the edit status.
                editStatus.addClickPoint();
                Point pictureClickPoint = editStatus.getClickPoint();
                x = (int) pictureClickPoint.getX();
                y = (int) pictureClickPoint.getY();

                // Get the previous mouse click point for use with single point Step.
                int previousX = 0;
                int previousY = 0;
                Point previousClickPoint = editStatus.getPreviousClickPoint();
                if (previousClickPoint != null) {
                    previousX = (int) previousClickPoint.getX();
                    previousY = (int) previousClickPoint.getY();
                }
               
                // The X/Y corner decision for single point is based on where right click was.
                int dX = x - previousX;
                int dY = y - previousY;
                if (Math.abs(dX) > Math.abs(dY)) { /* X or Y corner */
                    picture.addPictureCode(PictureCodeType.DRAW_HORIZONTAL_STEP_LINE);
                    picture.addPictureCode(previousX, previousY);
                } else {
                    picture.addPictureCode(PictureCodeType.DRAW_VERTICAL_STEP_LINE);
                    picture.addPictureCode(previousX, previousY);
                }
               
                picture.putPixel(previousX, previousY);
            }
            if (editStatus.getNumOfClicks() > 0) {
                // If a tool is active (i.e. has a least one click) then right click resets
                // number of clicks, which allows the user to move to new location.
                editStatus.resetTool();
View Full Code Here

     */
    private boolean processMenuSelection(MenuOption menuOption) {
        boolean success = true;
       
        EditStatus editStatus = application.getEditStatus();
        Picture picture = application.getPicture();
       
        switch (menuOption) {
            case NEW:
                newPicture();
                break;

            case OPEN:
                if (fileChooser.showOpenDialog(this.application) == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    if (selectedFile != null) {
                        if ((!application.hasVisiblePictureFrame()) ||
                            (application.getPicture().getPictureCodes().size() > 1)) {
                            // If there are no picture frames, or if the current picture is not empty
                            // then launch a new picture frame.
                            newPicture();
                        } else {
                            // Otherwise reuse the old frame. We need to clear off the background image
                            // since the EditStatus clear call doesn't handle this.
                            application.getPicturePanel().setBackgroundImage(null);
                        }
                        application.getPicture().loadPicture(selectedFile);
                        application.updateRecentPictures(selectedFile);
                    }
                }
                break;

            case SAVE_AS:
            case SAVE:
                if ((editStatus.getPictureFile() == null) || MenuOption.SAVE_AS.equals(menuOption)) {
                    if (fileChooser.showSaveDialog(this.application) == JFileChooser.APPROVE_OPTION) {
                        File selectedFile = fileChooser.getSelectedFile();
                        if (selectedFile != null) {
                            application.getPicture().savePicture(selectedFile);
                            application.updateRecentPictures(selectedFile);
                        }
                    }
                } else {
                    application.getPicture().savePicture(editStatus.getPictureFile());
                    application.updateRecentPictures(editStatus.getPictureFile());
                }
                break;

            case LOAD_BACKGROUND:
                if (fileChooser.showOpenDialog(this.application) == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    if (selectedFile != null) {
                        loadBackgroundImage(selectedFile);
                    }
                }
                success = editStatus.isBackgroundEnabled();
                backgroundMenuItem.setSelected(success);
                break;
               
            case EXIT:
                Object[] quitOptions = { "Quit", "Cancel" };
                int quitAnswer = JOptionPane.showOptionDialog(application, "Are you sure you want to Quit?", "", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, quitOptions, quitOptions[0]);
                if (quitAnswer == JOptionPane.YES_OPTION) {
                    application.savePreferences();
                    System.exit(0);
                }
                break;

            case ABOUT:
                showAboutMessage();
                break;

            case HELP:
                showHelp();
                break;
           
            case ZOOM_IN:
                if (editStatus.getZoomFactor() < 5) {
                    application.resizeScreen(editStatus.getZoomFactor() + 1);
                }
                break;
               
            case ZOOM_OUT:
                if (editStatus.getZoomFactor() > 1) {
                    application.resizeScreen(editStatus.getZoomFactor() - 1);
                }
                break;
               
            case ZOOM_X1:
                application.resizeScreen(1);
                break;

            case ZOOM_X2:
                application.resizeScreen(2);
                break;

            case ZOOM_X3:
                application.resizeScreen(3);
                break;

            case ZOOM_X4:
                application.resizeScreen(4);
                break;

            case ZOOM_X5:
                application.resizeScreen(5);
                break;

            case BACKGROUND:
                processToggleBackground();
                break;

            case BANDS:
                editStatus.setBandsOn(!editStatus.isBandsOn());
                break;

            case DUAL_MODE:
                editStatus.setDualModeEnabled(!editStatus.isDualModeEnabled());
                break;
               
            case EGO_TEST:
                editStatus.setEgoTestEnabled(!editStatus.isEgoTestEnabled());
                break;
               
            case NORMAL_FILL:
                editStatus.setFillType(FillType.NORMAL);
                picture.clearPictureCache();
                picture.drawPicture();
                break;
           
            case TRANSPARENT_FILL:
                editStatus.setFillType(FillType.TRANSPARENT);
                picture.clearPictureCache();
                picture.drawPicture();
                break;
               
            case NO_FILL:
                editStatus.setFillType(FillType.NONE);
                picture.clearPictureCache();
                picture.drawPicture();
                break;
               
            case LINE:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.LINE);
                }
                break;
               
            case PEN:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.SHORTLINE);
                }
                break;
               
            case STEP:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.STEPLINE);
                }
                break;
           
            case FILL:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.FILL);
                }
                break;
           
            case BRUSH:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.BRUSH);
                    application.getEditStatus().setBrushShape(BrushShape.CIRCLE);
                    application.getEditStatus().setBrushTexture(BrushTexture.SOLID);
                    application.getEditStatus().setBrushSize(0);
                }
                break;
               
            case AIRBRUSH:
                if (application.hasVisiblePictureFrame() && !picture.getCurrentPictureCode().isDataCode()) {
                    processToolSelect(ToolType.AIRBRUSH);
                    application.getEditStatus().setBrushShape(BrushShape.CIRCLE);
                    application.getEditStatus().setBrushTexture(BrushTexture.SPRAY);
                    application.getEditStatus().setBrushSize(0);
                }
                break;
           
            case START:
                picture.moveToStartOfPictureBuffer();
                break;
               
            case PREV:
                picture.moveBackOnePictureCode();
                break;
               
            case PREV_TOOL:
                picture.moveBackOnePictureAction();
                break;
               
            case NEXT:
                picture.moveForwardOnePictureCode();
                break;
               
            case NEXT_TOOL:
                picture.moveForwardOnePictureAction();
                break;
               
            case END:
                picture.moveToEndOfPictureBuffer();
                break;
               
            case GOTO:
                processEnterPosition();
                break;
               
            case DELETE:
                picture.deleteSelectedPictureCodes();
                break;
               
            case VISUAL:
                if (editStatus.isPriorityShowing()) {
                    processTogglePriorityScreen();
View Full Code Here

     * @param e the KeyEvent representing the key that was typed.
     */
    public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();
        EditStatus editStatus = application.getEditStatus();
        Picture picture = application.getPicture();
       
        if (editStatus.isEgoTestEnabled()) {
            // If Ego Test mode enabled, delegate to the EgoTestHandler.
            this.egoTestHandler.handleKeyEvent(e);
           
        } else {
            // Handle picture buffer navigation keys.
            if (key == KeyEvent.VK_HOME) {
                picture.moveToStartOfPictureBuffer();
            }
            if (key == KeyEvent.VK_LEFT) {
                picture.moveBackOnePictureAction();
            }
            if (key == KeyEvent.VK_RIGHT) {
                picture.moveForwardOnePictureAction();
            }
            if (key == KeyEvent.VK_UP) {
                picture.moveBackOnePictureCode();
            }
            if (key == KeyEvent.VK_DOWN) {
                picture.moveForwardOnePictureCode();
            }
            if (key == KeyEvent.VK_END) {
                picture.moveToEndOfPictureBuffer();
            }
        }
       
        // Handle picture action delete key.
        if (key == KeyEvent.VK_DELETE) {
            picture.deleteSelectedPictureCodes();
        }
    }
View Full Code Here

     */
    protected void processEnterPosition() {
        String positionStr = JOptionPane.showInputDialog(application, "Enter a picture position:", "Goto", JOptionPane.QUESTION_MESSAGE);
        if ((positionStr != null) && (!positionStr.trim().equals(""))) {
            try {
                Picture picture = application.getPicture();
               
                // If the entered value is valid, apply the new position.
                LinkedList<PictureCode> pictureCodes = picture.getPictureCodes();
                int newPosition = Integer.parseInt(positionStr.toString());
                if ((newPosition >= 0) && (newPosition < pictureCodes.size())) {
                    if (newPosition < (pictureCodes.size() - 1)) {
                        // Find the closest picture action to the entered position.
                        while (pictureCodes.get(newPosition).getCode() < 0xF0) {
                            newPosition = newPosition - 1;
                        }
                    }
                    picture.setPicturePosition(newPosition);
                    picture.drawPicture();
                }
            } catch (NumberFormatException nfe) {
                // Ignore. The user has entered a non-numeric value.
            }
        }
View Full Code Here

            int lastPictureSize;

            boolean shouldPaintOffscreenImage() {
                boolean shouldPaintOffscreenImage = false;
                EditStatus editStatus = getEditStatus();
                Picture picture = getPicture();
               
                // We return true at least every second, but there are other updates that trigger a render immediately.
                if (((editStatus.hasUnrenderedChanges()) || editStatus.isEgoTestEnabled() || !lastPictureBeingDrawn ||
                    ((lastPicturePosition != picture.getPicturePosition()) || (lastPictureSize != picture.getSize()))) &&
                      !picture.isBeingDrawn()) {
                    shouldPaintOffscreenImage = true;
                }
               
                editStatus.clearUnrenderedChanges();
                lastPicturePosition = picture.getPicturePosition();
                lastPictureSize = picture.getSize();
                return shouldPaintOffscreenImage;
            }

            public void run() {
                // Check if selected PictureFrame needs to process mouse motion.
View Full Code Here

TOP

Related Classes of com.agifans.picedit.picture.Picture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.