use of doc.attributes.MathObjectAttribute in project OpenNotebook by jaltekruse.
the class Grouping method clone.
@Override
public Grouping clone() {
// this creation method allows for subclasses of grouping to use this clone method
Grouping o = (Grouping) newInstanceWithType(getType());
o.setParentContainer(getParentContainer());
o.removeAllAttributes();
for (MathObjectAttribute mAtt : getAttributes()) {
o.addAttribute(mAtt.clone());
}
o.removeAllLists();
for (ListAttribute list : getLists()) {
o.addList(list.clone());
}
for (MathObject mObj : getObjects()) {
mObj.setParentContainer(null);
o.addObjectFromPage(mObj.clone());
mObj.setParentContainer(this);
}
return o;
}
use of doc.attributes.MathObjectAttribute in project OpenNotebook by jaltekruse.
the class MathObject method exportToXML.
public String exportToXML() {
String output = "";
output += "<" + getType() + ">\n";
for (MathObjectAttribute mAtt : attributes) {
output += mAtt.exportToXML();
}
for (ListAttribute lAtt : attrLists) {
output += lAtt.exportToXML();
}
output += "</" + getType() + ">\n";
return output;
}
use of doc.attributes.MathObjectAttribute in project OpenNotebook by jaltekruse.
the class MathObject method clone.
@Override
public MathObject clone() {
MathObject o = newInstanceWithType(getType());
o.setParentContainer(getParentContainer());
o.removeAllAttributes();
for (MathObjectAttribute mAtt : getAttributes()) {
o.addAttribute(mAtt.clone());
}
o.removeAllLists();
for (ListAttribute list : getLists()) {
o.addList(list.clone());
}
return o;
}
use of doc.attributes.MathObjectAttribute in project OpenNotebook by jaltekruse.
the class AnswerBoxGUI method drawMathObject.
public void drawMathObject(AnswerBoxObject object, Graphics g, Point pageOrigin, float zoomLevel) {
ScaledSizeAndPosition sap = getSizeAndPositionWithFontSize(object, pageOrigin, zoomLevel, object.getFontSize());
// TODO - decide how extra whitespace should be handled, should it always be stored?
// students may use it to format a multi-line answer
// although useful whitespace will likely not coming at the very beginning or very end
// of an answer
List<? extends MathObjectAttribute> correctAnswers = object.getListWithName(AnswerBoxObject.CORRECT_ANSWERS).getValues();
if (!object.getStudentAnswer().trim().equals("") || !correctAnswers.isEmpty()) {
Font f = g.getFont();
g.setColor(new Color(150, 210, 255));
g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
String message = object.getStudentAnswer();
for (MathObjectAttribute mAtt : correctAnswers) {
message += mAtt.getValue().toString() + ";";
}
message = message.substring(0, message.length() - 1);
if (message.isEmpty()) {
// cannot have an empty string in AttributedString
message = " ";
}
g.setFont(f.deriveFont(sap.getFontSize()));
g.setColor(Color.BLACK);
Graphics2D graphics2D = (Graphics2D) g;
GraphicsEnvironment.getLocalGraphicsEnvironment();
AttributedString messageAS = new AttributedString(message);
messageAS.addAttribute(TextAttribute.FONT, g.getFont());
AttributedCharacterIterator messageIterator = messageAS.getIterator();
FontRenderContext messageFRC = graphics2D.getFontRenderContext();
LineBreakMeasurer messageLBM = new LineBreakMeasurer(messageIterator, messageFRC);
Insets insets = new Insets(2, 2, 2, 2);
float wrappingWidth = sap.getWidth() - insets.left - insets.right;
float x = sap.getxOrigin() + insets.left;
float y = sap.getyOrigin() + insets.top;
while (messageLBM.getPosition() < messageIterator.getEndIndex()) {
TextLayout textLayout = messageLBM.nextLayout(wrappingWidth);
y += textLayout.getAscent();
textLayout.draw(graphics2D, x, y);
y += textLayout.getDescent() + textLayout.getLeading();
x = sap.getxOrigin() + insets.left;
}
g.setFont(f);
} else {
g.setColor(new Color(230, 230, 230));
g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
}
g.setColor(Color.BLACK);
g.drawRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
}
use of doc.attributes.MathObjectAttribute in project OpenNotebook by jaltekruse.
the class ListAdjuster method addPanelContent.
public void addPanelContent() {
// TODO - stopwatch and logging
// System.out.println("start list gui" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
this.removeAll();
GridBagConstraints con = new GridBagConstraints();
con.gridx = 0;
con.gridy = 0;
con.fill = GridBagConstraints.NONE;
// this code below ended up not working as well as I thought it would
// I really need to revalidate the parent frame, but I don't want to limit its
// functionality in different uses, so for now I'm just going to disable it
// if (expanded){
// JButton expandButton = new JButton(docPanel.getIcon(EXPANDED_PIC));
// expandButton.addActionListener(new ExpandedButtonListener());
// this.add(expandButton, con);
// }
// else{
// JButton notExpandedButton = new JButton(docPanel.getIcon(NOT_EXPANDED_PIC));
// notExpandedButton.addActionListener(new NotExpandedButtonListener());
// this.add(notExpandedButton, con);
// con.gridx = 1;
// con.weightx = 1;
// con.weighty = 1;
// con.fill = GridBagConstraints.HORIZONTAL;
// this.add(new JLabel(lAtt.getName()), con);
// this.revalidate();
// return;
// }
con.gridx = 1;
con.weightx = 1;
con.weighty = 1;
con.fill = GridBagConstraints.HORIZONTAL;
this.add(new JLabel(lAtt.getName()), con);
con.gridx = 0;
con.gridy++;
con.gridwidth = 2;
GridBagConstraints pcon = new GridBagConstraints();
pcon.gridx = 0;
pcon.gridy = 0;
pcon.fill = GridBagConstraints.BOTH;
pcon.weightx = 1;
pcon.weighty = 1;
int index = 0;
JPanel p;
for (MathObjectAttribute mAtt : (Vector<MathObjectAttribute>) lAtt.getValues()) {
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
last = ObjectPropertiesFrame.getAdjuster(mAtt, notebookPanel, p);
p.add(last);
p.add(Box.createRigidArea(new Dimension(3, 0)));
JButton button = new JButton("x");
button.setMargin(new Insets(0, 0, 0, 0));
button.addActionListener(new CloseButtonListener(index));
button.setMaximumSize(new Dimension(15, 15));
p.add(button);
p.add(Box.createRigidArea(new Dimension(3, 0)));
this.add(p, con);
con.gridy++;
index++;
}
con.fill = GridBagConstraints.HORIZONTAL;
JButton addButton = new JButton("Add new");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
try {
lAtt.addNewValue();
// if ( lAtt.getParentObject() != null)
// {// forces the object property frame to be layed out again
// notebookPanel.getCurrentDocViewer().setFocusedObject(lAtt.getParentObject());
// }
// notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
// notebookPanel.getCurrentDocViewer().repaintDoc();
addPanelContent();
notebookPanel.getCurrentDocViewer().propertiesFrameRefacoringNeeded = true;
notebookPanel.getCurrentDocViewer().repaintDoc();
} catch (AttributeException e) {
if (!showingDialog) {
showingDialog = true;
JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
showingDialog = false;
}
}
}
});
this.add(addButton, con);
// this.revalidate();
// System.out.println("finish list gui" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Aggregations