Search in sources :

Example 6 with ProblemGenerator

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

the class ProblemListPanel method generateProblems.

public void generateProblems() {
    if (selectedProblems.isEmpty()) {
        JOptionPane.showMessageDialog(null, "No problems are selected.", ERROR, JOptionPane.ERROR_MESSAGE);
        return;
    }
    int num = getNumberFromUser();
    if (num == -1) {
        // user cancelled the action
        return;
    }
    String directions = selectedProblems.get(0).getDirections();
    if (selectedProblems.size() > 1) {
        // there is more than one problem, check to make sure they
        // have the same directions, or prompt the user for a
        // new set of directions that applies to all of them.
        boolean directionsMatch = true;
        for (ProblemGenerator gen : selectedProblems) {
            if (!gen.getDirections().equalsIgnoreCase(directions)) {
                directionsMatch = false;
                break;
            }
        }
        if (!directionsMatch) {
            // prompt user for new set of directions
            directions = promtForDirections(selectedProblems);
            if (directions == null) {
                return;
            }
        }
    }
    notebookPanel.getCurrentDocViewer().getDoc().generateProblems(selectedProblems, selectedFrequencies, num, directions);
    notebookPanel.getCurrentDocViewer().resizeViewWindow();
    notebookPanel.getCurrentDocViewer().addUndoState();
}
Also used : ProblemGenerator(doc.mathobjects.ProblemGenerator)

Example 7 with ProblemGenerator

use of doc.mathobjects.ProblemGenerator 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 8 with ProblemGenerator

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

the class ProblemListPanel method promtForDirections.

public String promtForDirections(Vector<ProblemGenerator> generators) {
    final JComponent[] inputs = new JComponent[generators.size() + 3];
    inputs[0] = new JLabel("<html>The directions form the selected problems are different.<br>" + "Enter a set of directions suitable for all of the problems below,<br>" + "each individual problem's directions are listed for reference.<html>");
    int index = 1;
    for (ProblemGenerator gen : generators) {
        // TODO - insert line breaks for long directions, might have to include ... with tooltip for really long text
        // might want to limit number of chars overall for directions.
        inputs[index] = new JLabel("<html><font size=-2>" + gen.getDirections() + "</font></html");
        index++;
    }
    inputs[index] = new JLabel("Directions for list of problems");
    index++;
    JTextArea directions = new JTextArea(3, 10);
    inputs[index] = new JScrollPane(directions);
    directions.setWrapStyleWord(true);
    directions.setLineWrap(true);
    while (true) {
        int input = JOptionPane.showConfirmDialog(null, inputs, "Enter Directions", JOptionPane.PLAIN_MESSAGE);
        if (input == -1) {
            return null;
        }
        if (!directions.getText().equals("")) {
            return directions.getText();
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) ProblemGenerator(doc.mathobjects.ProblemGenerator)

Aggregations

ProblemGenerator (doc.mathobjects.ProblemGenerator)8 AttributeException (doc.attributes.AttributeException)3 MathObject (doc.mathobjects.MathObject)2 JComponent (javax.swing.JComponent)2 MathObjectAttribute (doc.attributes.MathObjectAttribute)1 GeneratedProblem (doc.mathobjects.GeneratedProblem)1 Component (java.awt.Component)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JSeparator (javax.swing.JSeparator)1