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