Search in sources :

Example 6 with MathObject

use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.

the class ProblemListPanel method createPanelForProblems.

public JPanel createPanelForProblems() {
    ProblemList panel = new ProblemList();
    JPanel tempPanel;
    GridBagConstraints con = new GridBagConstraints();
    JComboBox frequencyChoices;
    Component[] othersInRow = new Component[2];
    ;
    int numProblemsToShow = notebookPanel.getDatabase().getAllProblems().size();
    if (numProblemsToShow > 20) {
        // limit the number of problems in the list
        // to 20 at a time
        numProblemsToShow = 20;
    }
    con.gridy = 0;
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new GridBagLayout());
    for (final ProblemGenerator g : notebookPanel.getDatabase().getAllProblems()) {
        // add checkbox
        con.fill = GridBagConstraints.NONE;
        con.gridx = 0;
        con.gridwidth = 1;
        con.weightx = 0;
        con.insets = new Insets(0, 0, 0, 0);
        final JCheckBox checkbox = new JCheckBox();
        checkbox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent ev) {
                if (ev.getStateChange() == ItemEvent.SELECTED) {
                    selectedFrequencies.add(10);
                    selectedProblems.add(g);
                } else {
                    selectedFrequencies.remove(selectedProblems.indexOf(g));
                    selectedProblems.remove(g);
                }
                previewPanel.getDoc().getPage(0).removeAllObjects();
                // set the page size big to prevent problem generation from spawning pages
                previewPanel.getDoc().setHeight(5000);
                previewPanel.getDoc().setWidth(5000);
                previewPanel.getDoc().generateProblem(g);
                previewPanel.resizeViewWindow();
                MathObject mObj = previewPanel.getDoc().getPage(0).getObjects().get(0);
                previewPanel.getDoc().setWidth(mObj.getWidth() + 2 * problemBuffer);
                previewPanel.getDoc().setHeight(mObj.getHeight() + 2 * problemBuffer);
                mObj.setxPos(problemBuffer);
                mObj.setyPos(problemBuffer);
                previewPanel.resizeViewWindow();
            }
        });
        frequencyChoices = new JComboBox(frequencies);
        panel.add(checkbox, con);
        othersInRow[0] = checkbox;
        othersInRow[1] = frequencyChoices;
        con.fill = GridBagConstraints.HORIZONTAL;
        con.insets = new Insets(0, 5, 0, 0);
        con.weightx = 1;
        con.gridx = 1;
        tempPanel = new ProblemDescriptionPanel(g, othersInRow);
        tempPanel.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent arg0) {
            }

            public void mouseEntered(MouseEvent arg0) {
            }

            public void mouseExited(MouseEvent arg0) {
            }

            @Override
            public void mousePressed(MouseEvent arg0) {
                checkbox.setSelected(!checkbox.isSelected());
            }

            public void mouseReleased(MouseEvent arg0) {
            }
        });
        panel.add(tempPanel, con);
        //			// add frequency selection menu
        //			con.fill = GridBagConstraints.NONE;
        //			con.gridx = 2;
        //			con.weightx = 0;
        //			con.insets = new Insets(0, 5, 0, 5);
        //			frequencyChoices.setSelectedItem(AVERAGE);
        //			panel.add(frequencyChoices, con);
        con.gridy++;
        con.gridx = 0;
        con.gridwidth = 2;
        con.insets = new Insets(0, 0, 0, 0);
        panel.add(new JSeparator(), con);
        con.gridy++;
    }
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) GridBagLayout(java.awt.GridBagLayout) JSeparator(javax.swing.JSeparator) ProblemGenerator(doc.mathobjects.ProblemGenerator) JCheckBox(javax.swing.JCheckBox) MouseListener(java.awt.event.MouseListener) ItemListener(java.awt.event.ItemListener) JComponent(javax.swing.JComponent) Component(java.awt.Component) MathObject(doc.mathobjects.MathObject)

Example 7 with MathObject

use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.

the class DocMouseListener method adjustTempGroupSelection.

/**
	 * Method to change the temporary group selection based on the current
	 * selection rectangle. Removes objects no longer contacted, and adds new
	 * objects that are not yet group members.
	 * 
	 * @return - whether or not a redraw event is needed
	 */
private boolean adjustTempGroupSelection() {
    // need to modify this code to take into account the current stacking of
    // the objects
    // large objects automatically cover up smaller ones using this system
    Rectangle selectRect = docPanel.getSelectionRect().getBounds();
    Grouping tempGroup = docPanel.getTempGroup();
    Vector<MathObject> pageObjects = docPanel.getSelectionRect().getParentPage().getObjects();
    // temporary storage of objects that collide with the selection
    // rectangle
    Vector<MathObject> collisionObjects = new Vector<>();
    for (MathObject mObj : pageObjects) {
        // selection rectangle
        if (selectRect.intersects(mObj.getBounds())) {
            collisionObjects.add(mObj);
        }
    }
    if (collisionObjects.isEmpty()) {
        // no objects were contacted
        docPanel.ungroupTempGroup();
        docPanel.setFocusedObject(null);
        return true;
    }
    if (collisionObjects.size() == 1) {
        // only one object was contacted
        MathObject contactedObj = collisionObjects.get(0);
        if (contactedObj.equals(docPanel.getFocusedObject())) {
            // do nothing
            ;
            if (contactedObj != tempGroup) {
                collisionObjects.remove(contactedObj);
                return true;
            }
        } else {
            docPanel.setFocusedObject(contactedObj);
            collisionObjects.remove(contactedObj);
            return true;
        }
    }
    if (collisionObjects.contains(tempGroup)) {
        MathObject mObj;
        // otherwise remove them
        for (int i = 0; i < tempGroup.getObjects().size(); i++) {
            mObj = tempGroup.getObjects().get(i);
            if (!selectRect.intersects(mObj.getBounds())) {
                tempGroup.removeObject(mObj);
                tempGroup.getParentContainer().addObject(mObj);
                mObj.setParentContainer(tempGroup.getParentContainer());
                i--;
            }
        }
        // remove the temporary group from the contacted list, it now
        // contains only elements that were
        // in it before and were contacted by the current selection
        // rectangle
        collisionObjects.remove(tempGroup);
    }
    if (!collisionObjects.isEmpty()) {
        tempGroup.setParentContainer(collisionObjects.get(0).getParentContainer());
        collisionObjects.get(0).getParentContainer().addObject(tempGroup);
        for (MathObject mObj : collisionObjects) {
            mObj.getParentContainer().removeObject(mObj);
            mObj.setParentContainer(null);
            tempGroup.addObjectFromPage(mObj);
            mObj.setParentContainer(tempGroup);
        }
        docPanel.getDoc().refactorPageNumbers();
        docPanel.setFocusedObject(tempGroup);
    }
    if (tempGroup.getParentContainer() != null) {
        if (tempGroup.getObjects().size() == 1) {
            // there is one one object
            // left in the temporary group
            docPanel.setFocusedObject(tempGroup.getObjects().get(0));
            docPanel.ungroupTempGroup();
        }
    }
    return false;
}
Also used : Rectangle(java.awt.Rectangle) Grouping(doc.mathobjects.Grouping) MathObject(doc.mathobjects.MathObject) Vector(java.util.Vector) Point(java.awt.Point)

Example 8 with MathObject

use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.

the class DocMouseListener method mousePressed.

@Override
public void mousePressed(MouseEvent e) {
    docPanel.requestFocus();
    draggingDot = false;
    PointInDocument clickedPt = docPanel.panelPt2DocPt(e.getX(), e.getY());
    MathObject objToPlace = docPanel.getObjToPlace();
    if (docPanel.isPlacingObject()) {
        objToPlace.setxPos(clickedPt.getxPos());
        objToPlace.setyPos(clickedPt.getyPos());
        objToPlace.setWidth(1);
        objToPlace.setHeight(1);
        objToPlace.setParentContainer(docPanel.getDoc().getPage(clickedPt.getPage()));
        objToPlace.getParentContainer().addObject(objToPlace);
        docPanel.repaintDoc();
        docPanel.updateObjectToolFrame();
        objPlacementRequiresMouseDrag = true;
        docPanel.setFocusedObject(objToPlace);
        return;
    } else if (detectResizeOrMove(e)) {
        // resize dot or the selected object
        return;
    } else if (clickedPt.isOutSidePage()) {
        // click was outside of page
        if (docPanel.isPlacingObject()) {
            docPanel.getNotebookPanel().objHasBeenPlaced();
            docPanel.ungroupTempGroup();
        }
    } else {
        // create a box to select multiple objects
        if (!docPanel.isInStudentMode()) {
            docPanel.ungroupTempGroup();
            RectangleObject rect = new RectangleObject(docPanel.getDoc().getPage(clickedPt.getPage()));
            rect.setxPos(clickedPt.getxPos());
            rect.setyPos(clickedPt.getyPos());
            rect.setWidth(1);
            rect.setHeight(1);
            docPanel.setSelectionRect(rect);
            selectionRectRequiresMouseDrag = true;
        }
    }
}
Also used : RectangleObject(doc.mathobjects.RectangleObject) MathObject(doc.mathobjects.MathObject) PointInDocument(doc.PointInDocument)

Example 9 with MathObject

use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.

the class NotebookKeyboardListener method keyPressed.

@Override
public void keyPressed(KeyEvent e) {
    try {
        MathObject foc = notebook.getNotebookPanel().getCurrentDocViewer().getFocusedObject();
        if (foc == null) {
            // There is no focused object to accept the event
            return;
        }
        switch(e.getKeyCode()) {
            case KeyEvent.VK_DOWN:
                if (notebook.getNotebookPanel().getCurrentDocViewer().getPageGUI().getGUIForObj(foc).keyPressed(foc, PageGUI.DOWN)) {
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                    return;
                }
                if (foc != null) {
                    foc.setyPos(foc.getyPos() + 1);
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                }
                break;
            case KeyEvent.VK_UP:
                if (notebook.getNotebookPanel().getCurrentDocViewer().getPageGUI().getGUIForObj(foc).keyPressed(foc, PageGUI.UP)) {
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                    return;
                }
                if (foc != null) {
                    foc.setyPos(foc.getyPos() - 1);
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                }
                break;
            case KeyEvent.VK_LEFT:
                if (notebook.getNotebookPanel().getCurrentDocViewer().getPageGUI().getGUIForObj(foc).keyPressed(foc, PageGUI.LEFT)) {
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                    return;
                }
                if (foc != null) {
                    foc.setxPos(foc.getxPos() - 1);
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                }
                break;
            case KeyEvent.VK_RIGHT:
                if (notebook.getNotebookPanel().getCurrentDocViewer().getPageGUI().getGUIForObj(foc).keyPressed(foc, PageGUI.RIGHT)) {
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                    return;
                }
                if (foc != null) {
                    foc.setxPos(foc.getxPos() + 1);
                    notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                }
                break;
            default:
                notebook.getNotebookPanel().getCurrentDocViewer().getPageGUI().getGUIForObj(foc).keyPressed(foc, e.getKeyChar());
                notebook.getNotebookPanel().getCurrentDocViewer().repaintDoc();
                break;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : MathObject(doc.mathobjects.MathObject)

Example 10 with MathObject

use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.

the class GroupingGUI method drawInteractiveComponents.

public void drawInteractiveComponents(Grouping group, Graphics g, Point pageOrigin, float zoomLevel) {
    drawMathObject(group, g, pageOrigin, zoomLevel);
    for (MathObject mathObj : group.getObjects()) {
        g.setColor(Color.BLUE);
        ((Graphics2D) g).setStroke(new BasicStroke(2));
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawPolygon(pageGui.getGUIForObj(mathObj).getCollisionAndSelectionPolygon(mathObj, pageOrigin, zoomLevel));
        ((Graphics2D) g).setStroke(new BasicStroke(1));
    }
}
Also used : MathObject(doc.mathobjects.MathObject)

Aggregations

MathObject (doc.mathobjects.MathObject)31 Grouping (doc.mathobjects.Grouping)6 PointInDocument (doc.PointInDocument)4 Point (java.awt.Point)4 AttributeException (doc.attributes.AttributeException)3 Page (doc.Page)2 GeneratedProblem (doc.mathobjects.GeneratedProblem)2 ProblemGenerator (doc.mathobjects.ProblemGenerator)2 ProblemNumberObject (doc.mathobjects.ProblemNumberObject)2 TextObject (doc.mathobjects.TextObject)2 Rectangle (java.awt.Rectangle)2 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 RectangleObject (doc.mathobjects.RectangleObject)1 VariableValueInsertionProblem (doc.mathobjects.VariableValueInsertionProblem)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Graphics2D (java.awt.Graphics2D)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1