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();
}
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;
}
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();
}
}
}
Aggregations