use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.
the class Document method findFirstWhitespace.
public PointInDocument findFirstWhitespace() {
Page lastPageWithStuff = getPage(0);
for (Page p : getPages()) {
if (!p.getObjects().isEmpty()) {
lastPageWithStuff = p;
}
}
int lastObjectYPos = getyMargin() + 10;
for (MathObject mObj : lastPageWithStuff.getObjects()) {
if (mObj.getyPos() + mObj.getHeight() > lastObjectYPos) {
lastObjectYPos = mObj.getyPos() + mObj.getHeight();
}
}
return new PointInDocument(getPageIndex(lastPageWithStuff), getxMargin() + 10, lastObjectYPos + 10);
}
use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.
the class ObjectToolBar method addObjectButtons.
public void addObjectButtons(JComponent c, final NotebookPanel notebookPanel) {
ImageIcon objIcon;
int i = 0;
ImageIcon lockImg = notebookPanel.getIcon("img/small_lock2.png");
ImageIcon oneImg = notebookPanel.getIcon("img/small_one.png");
for (MathObject mObj : MathObject.objects) {
if (mObj == null) {
continue;
}
final String s = mObj.getType();
if (s.equals(MathObject.GROUPING) || s.equals(MathObject.VAR_INSERTION_PROBLEM) || s.equals(MathObject.GENERATED_PROBLEM) || s.equals(MathObject.PROBLEM_NUMBER_OBJECT)) {
// all classes that extend grouping cannot be created with a
// button and mouse drag. They do not need buttons
i++;
continue;
}
if (s.equals(MathObject.PYRAMID_OBJECT)) {
// these objects have not been created yet, they will be added
// soon
i++;
continue;
}
objIcon = notebookPanel.getIcon("img/" + MathObject.getObjectImageName(s));
final ImageIcon objImage = objIcon;
final ImageIcon objCreateImage = notebookPanel.getIcon("img/" + MathObject.getObjectImageName(s));
objCreateImage.getImage().getGraphics().drawImage(oneImg.getImage(), objCreateImage.getIconWidth() - oneImg.getIconWidth(), objCreateImage.getIconHeight() - oneImg.getIconHeight(), null);
final ImageIcon objCreateLockImage = notebookPanel.getIcon("img/" + MathObject.getObjectImageName(s));
objCreateLockImage.getImage().getGraphics().drawImage(lockImg.getImage(), objCreateLockImage.getIconWidth() - lockImg.getIconWidth(), objCreateLockImage.getIconHeight() - lockImg.getIconHeight(), null);
this.objectButtons[i] = new ImageSwitcherButton(objIcon, "Add " + s, 1, 1, 0, 0, c) {
@Override
public void associatedAction() {
// mathObj
if (lastHit != null && lastHit != this) {
notebookPanel.setObjectCreationMode(NotebookPanel.ObjectCreationMode.NOT_PLACING_OBJECT);
lastHit.updateImage();
}
lastHit = this;
notebookPanel.getCurrentDocViewer().createMathObject(s);
updateImage();
}
public void updateImage() {
if (notebookPanel.getObjectCreationMode() == NotebookPanel.ObjectCreationMode.NOT_PLACING_OBJECT) {
this.setIcon(objImage);
lastHit = null;
} else if (notebookPanel.getObjectCreationMode() == NotebookPanel.ObjectCreationMode.PLACING_SINGLE_OBJECT) {
setIcon(objCreateImage);
} else if (notebookPanel.getObjectCreationMode() == NotebookPanel.ObjectCreationMode.MULTIPLE_OBJECTS) {
setIcon(objCreateLockImage);
return;
}
}
};
i++;
}
}
use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.
the class PageGUI method drawPageWithDecorations.
public void drawPageWithDecorations(Graphics g, Page p, Point pageOrigin, Rectangle visiblePageSection, float zoomLevel) {
int adjustedWidth = (int) (p.getWidth() * zoomLevel);
int adjustedHeight = (int) (p.getHeight() * zoomLevel);
int pageXOrigin = (int) pageOrigin.getX();
int pageYOrigin = (int) pageOrigin.getY();
if (docPanel.getSelectedPage() == p) {
g.setColor(new Color(230, 240, 255));
} else {
g.setColor(Color.WHITE);
}
g.fillRect(pageXOrigin, pageYOrigin, adjustedWidth, adjustedHeight);
//draw gray box to show margins
int adjustedxMargin = (int) (p.getxMargin() * zoomLevel);
int adjustedyMargin = (int) (p.getyMargin() * zoomLevel);
printableXOrigin = pageXOrigin + adjustedxMargin;
printableYOrigin = pageYOrigin + adjustedyMargin;
g.setColor(Color.GRAY.brighter());
g.drawRect(printableXOrigin, printableYOrigin, adjustedWidth - 2 * adjustedxMargin, adjustedHeight - adjustedyMargin * 2);
if (docPanel.getSelectedPage() == p) {
g.setColor(Color.BLUE);
} else {
g.setColor(Color.BLACK);
}
g.fillRect(pageXOrigin + 3, pageYOrigin + adjustedHeight, adjustedWidth, 3);
g.fillRect(pageXOrigin + adjustedWidth, pageYOrigin + 3, 3, adjustedHeight);
g.drawRect(pageXOrigin, pageYOrigin, adjustedWidth, adjustedHeight);
drawPage(g, p, pageOrigin, visiblePageSection, zoomLevel);
if (docPanel.getFocusedObject() != null) {
MathObject focusedObj = docPanel.getFocusedObject();
if (p.objectContainedBelow(focusedObj)) {
//the focused object is on this page, print the resize dots
//the temporary rectangle used for selecting a group of objects is
//created using a RectangleObject, but it is not added to its parent page
//in that case the dots are not drawn
getGUIForObj(focusedObj).drawInteractiveComponents(focusedObj, g, pageOrigin, zoomLevel);
if ((!focusedObj.isHorizontallyResizable() && !focusedObj.isVerticallyResizable()) || docPanel.isInStudentMode()) {
// if the object cannot be resized, or if in student mode (where users cannot resize objects)
g.setColor(Color.GRAY);
((Graphics2D) g).setStroke(new BasicStroke(3));
g.drawRect((int) (pageOrigin.getX() + focusedObj.getxPos() * zoomLevel) - 3, (int) (pageOrigin.getY() + focusedObj.getyPos() * zoomLevel) - 3, (int) (focusedObj.getWidth() * zoomLevel) + 6, (int) (focusedObj.getHeight() * zoomLevel) + 6);
((Graphics2D) g).setStroke(new BasicStroke(1));
} else {
MathObjectGUI.drawResizingDots(focusedObj, g, new Point((int) pageOrigin.getX(), (int) pageOrigin.getY()), zoomLevel);
}
}
}
}
use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.
the class DocReader method endElement.
@Override
public void endElement(String uri, String localName, String qName) {
if (MathObject.isMathObjectType(qName)) {
mObj = null;
overridenLists = new Vector<>();
}
if (qName.equals(MathObject.GROUPING) || qName.equals(MathObject.VAR_INSERTION_PROBLEM) || qName.equals(PROBLEM) || qName.equals(MathObject.GENERATED_PROBLEM)) {
if (qName.equals(MathObject.VAR_INSERTION_PROBLEM) || qName.equals(PROBLEM) || qName.equals(MathObject.GENERATED_PROBLEM)) {
if (readingGenerators) {
try {
doc.addGenerator((ProblemGenerator) containerStack.get(containerStack.size() - 1));
} catch (Exception e) {
if (DEBUG) {
e.printStackTrace();
}
}
} else if (readingProblemDatabase) {
database.addProblem((VariableValueInsertionProblem) containerStack.get(containerStack.size() - 1));
}
}
for (MathObject mathObj : objectsInGroup.get(objectsInGroup.size() - 1)) {
containerStack.get(containerStack.size() - 1).addObjectFromPage(mathObj);
}
objectsInGroup.remove(objectsInGroup.size() - 1);
containerStack.remove(containerStack.get(containerStack.size() - 1));
}
if (qName.equals("Page")) {
page = null;
} else if (qName.equals(ListAttribute.LIST)) {
readingList = false;
} else if (qName.equals(Document.OPEN_NOTEBOOK_DOC)) {
} else if (qName.equals(Document.GENERATORS)) {
readingGenerators = false;
}
}
use of doc.mathobjects.MathObject in project OpenNotebook by jaltekruse.
the class DocMouseListener method dragMouseToResizeObj.
private boolean dragMouseToResizeObj(MouseEvent e) {
if (!(draggingDot || selectionRectBeingResized)) {
// method is needed
return false;
}
// one of the dots of an object is being moved to make it larger or
// smaller
// or the temporary selection rectangle is being resized
PointInDocument docPt = docPanel.panelPt2DocPt(e.getX(), e.getY());
MathObject objToResize = null;
if (draggingDot) {
// an object is focused and one of its resizing dots
// has been contacted
// resize the focues object
objToResize = docPanel.getFocusedObject();
} else if (selectionRectBeingResized) {
// the user drew a selection
// rectangle on the screen,
// resize the selection
// rectangle
objToResize = docPanel.getSelectionRect();
}
Page pageOfResizeObject = objToResize.getParentPage();
Page contactedPage = docPanel.getDoc().getPage(docPt.getPage());
if (!docPt.isOutSidePage() && pageOfResizeObject == contactedPage) {
if (selectionRectBeingResized) {
// a special object that does note
// exist in the document was
// resized, it is used
// to select multiple objects at
// once and create groups
MathObjectGUI.moveResizeDot(docPanel.getSelectionRect(), currentDragDot, docPt, this);
adjustTempGroupSelection();
} else {
// a regular object was resized
MathObjectGUI.moveResizeDot(objToResize, currentDragDot, docPt, this);
}
docPanel.repaintDoc();
return true;
} else {
// the mouse moved outside of the page where the object to
// resize resides
Point pageOrigin = null;
pageOrigin = docPanel.getPageOrigin(objToResize.getParentPage());
// flags to indicate that a position has not been assigned to the
// click
int xMouseRequest = Integer.MAX_VALUE;
int yMouseRequest = Integer.MAX_VALUE;
if (e.getX() <= pageOrigin.getX()) {
// event was to the left of the
// document, send an resize
// request with the edge of page
// and the events given y
// position
xMouseRequest = 0;
} else if (e.getX() >= pageOrigin.getX() + (int) (pageOfResizeObject.getWidth() * docPanel.getZoomLevel())) {
xMouseRequest = pageOfResizeObject.getWidth();
}
if (e.getY() <= pageOrigin.getY()) {
yMouseRequest = 0;
} else if (e.getY() >= pageOrigin.getY() + (int) (pageOfResizeObject.getHeight() * docPanel.getZoomLevel())) {
yMouseRequest = pageOfResizeObject.getHeight();
}
if (yMouseRequest == Integer.MAX_VALUE) {
yMouseRequest = docPt.getyPos();
}
if (xMouseRequest == Integer.MAX_VALUE) {
xMouseRequest = docPt.getxPos();
}
MathObjectGUI.moveResizeDot(objToResize, currentDragDot, new PointInDocument(1, xMouseRequest, yMouseRequest), this);
if (objToResize.getParentContainer() instanceof Grouping) {
((Grouping) objToResize.getParentContainer()).adjustSizeToFitChildren();
}
if (selectionRectBeingResized) {
// a special object that does note
// exist in the document was
// resized, it is used
// to select multiple objects at
// once and create groups
adjustTempGroupSelection();
}
docPanel.repaintDoc();
}
return true;
}
Aggregations