use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.
the class SketchFrame method buildMenu.
/**
* Builds the menu
*/
private void buildMenu() {
final JMenuBar mainMenu;
final JMenu menuFile;
final JMenu menuHelp;
mainMenu = new JMenuBar();
// Make the File Menu
menuFile = new JMenu("File");
mainMenu.add(menuFile);
menuFile.setMnemonic(KeyEvent.VK_F);
final JMenu exportMenu = new JMenu("Export to");
menuFile.add(exportMenu);
// Export to server:
addMenuItem(exportMenu, new JMenuItem(new ExportDatabaseAction(this, _ourSketch)), KeyEvent.VK_D);
// Export to SQL text dump:
addMenuItem(exportMenu, new JMenuItem(new ExportFileAction(this, _ourSketch)), KeyEvent.VK_F);
addMenuItem(exportMenu, new JMenuItem(new ExportImageAction<>(this)), null);
addMenuItem(exportMenu, new JMenuItem(new SketchExportAction(this)), null);
menuFile.addSeparator();
addMenuItem(menuFile, new JMenuItem(new DocumentInfoAction(this)), KeyEvent.VK_I);
menuFile.addSeparator();
addMenuItem(menuFile, new JMenuItem(new FileQuitAction(this)), KeyEvent.VK_W);
// Make the Edit menu for "edit mode"
menuEditEdit = new JMenu("Edit");
mainMenu.add(menuEditEdit);
addMenuItem(menuEditEdit, _UndoItem = new JMenuItem(new UndoAction(_ourSketch)), KeyEvent.VK_Z);
addMenuItem(menuEditEdit, _RedoItem = new JMenuItem(new RedoAction(_ourSketch)), KeyEvent.VK_Y);
menuEditEdit.addSeparator();
menuEditEdit.add(menuEditAdd = new JMenu("Add"));
addMenuItem(menuEditAdd, _AddEntityItem = new JMenuItem(new NewEntityAction<>(null, this)), null);
menuEditAdd.add(menuEditAddEdge = new JMenu("Add edge"));
addMenuItem(menuEditAddEdge, addEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.NORMAL)), null);
addMenuItem(menuEditAddEdge, addInjEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.INJECTIVE)), null);
addMenuItem(menuEditAddEdge, addParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.PARTIAL)), null);
addMenuItem(menuEditAddEdge, addSelfParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.SELF)), null);
addMenuItem(menuEditAdd, addAtt = new JMenuItem(new AddAttributeAction<>(this)), null);
addMenuItem(menuEditAdd, addUK = new JMenuItem(new AddUniqueKeyAction<>(this)), null);
addMenuItem(menuEditEdit, del = new JMenuItem(new DeleteFromSketchAction(this)), null);
addMenuItem(menuEditEdit, rename = new JMenuItem(new RenameInSketchAction(this)), KeyEvent.VK_R);
menuEditEdit.add(new JSeparator());
addMenuItem(menuEditEdit, editEdge = new JMenuItem(new EditSketchEdgeAction(this)), KeyEvent.VK_E);
menuEditEdit.add(new JSeparator());
// If
addMenuItem(menuEditEdit, _ProgramSettingsItem = new JMenuItem("Preferences"), KeyEvent.VK_P);
// you
// change
// this
// title,
// update
// OSX.java
_ProgramSettingsItem.setToolTipText("Set global EASIK preferences");
_ProgramSettingsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
final ProgramSettingsUI myUI = new ProgramSettingsUI(SketchFrame.this);
myUI.showDialog();
}
});
// add listener to enable appropriate menu items
menuEditEdit.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuSelected(final MenuEvent e) {
final Object[] selection = _ourSketch.getSelectionCells();
final SketchGraphModel model = _ourSketch.getGraphModel();
final boolean undoable = model.canUndo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
final boolean redoable = model.canRedo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
_UndoItem.setEnabled(undoable);
_RedoItem.setEnabled(redoable);
menuEditAdd.setEnabled(true);
menuEditAddEdge.setEnabled(true);
_AddEntityItem.setEnabled(false);
addEdge.setEnabled(false);
addInjEdge.setEnabled(false);
addParEdge.setEnabled(false);
addSelfParEdge.setEnabled(false);
addAtt.setEnabled(false);
addUK.setEnabled(false);
rename.setEnabled(false);
del.setEnabled(false);
editEdge.setEnabled(false);
if (selection.length == 0) {
_AddEntityItem.setEnabled(true);
menuEditAddEdge.setEnabled(false);
}
if (selection.length >= 1) {
del.setEnabled(true);
if (selection.length == 1) {
if (selection[0] instanceof EntityNode) {
rename.setEnabled(true);
}
if (selection[0] instanceof EntityNode) {
addSelfParEdge.setEnabled(true);
addAtt.setEnabled(true);
addUK.setEnabled(true);
} else if (selection[0] instanceof SketchEdge) {
editEdge.setEnabled(true);
}
}
// if selection contains an edge, dissable edit|add...
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof SketchEdge) {
menuEditAdd.setEnabled(false);
}
}
if (selection.length >= 3) {
menuEditAdd.setEnabled(false);
}
}
if ((selection.length == 2) && (selection[0] instanceof EntityNode) && (selection[1] instanceof EntityNode)) {
addEdge.setEnabled(true);
addInjEdge.setEnabled(true);
addParEdge.setEnabled(true);
}
}
});
// Make the Edit menu for "manipulate mode"
@SuppressWarnings("unused") final JMenuItem updateRowMenuItem;
@SuppressWarnings("unused") final JMenuItem viewDataMenuItem;
menuEditManip = new JMenu("Edit");
mainMenu.add(menuEditManip);
menuEditManip.add(addRowMenuItem = new JMenuItem(new AddRowAction(_ourSketch)));
menuEditManip.add(insertQueryMenuItem = new JMenuItem(new ExecPreparedInsertAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(updateRowMenuItem = new JMenuItem(new UpdateRowAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(deleteRowMenuItem = new JMenuItem(new DeleteRowAction(_ourSketch)));
menuEditManip.add(deleteQueryMenuItem = new JMenuItem(new ExecPreparedDeleteAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(viewDataMenuItem = new JMenuItem(new ViewDataAction(_ourSketch)));
menuEditManip.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuSelected(final MenuEvent e) {
final Object[] selection = _ourSketch.getSelectionCells();
final boolean enable = (selection.length == 1) && (selection[0] instanceof EntityNode);
for (final Component c : menuEditManip.getMenuComponents()) {
c.setEnabled(enable);
}
if (!enable) {
return;
}
if (!_ourSketch.editable((EntityNode) selection[0])) {
addRowMenuItem.setEnabled(false);
insertQueryMenuItem.setEnabled(false);
deleteRowMenuItem.setEnabled(false);
deleteQueryMenuItem.setEnabled(false);
}
}
});
menuView = new JMenu("View");
mainMenu.add(menuView);
menuView.add(_ShowAttributesToggle = new JCheckBoxMenuItem("Attributes/keys visible"));
_ShowAttributesToggle.setToolTipText("Toggle display of attributes and unique keys");
_ShowAttributesToggle.setState("show".equals(Easik.getInstance().getSettings().getProperty("attrib_display", "show")));
_ShowAttributesToggle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
_ourSketch.refresh();
}
});
menuView.add(_ShowConstraintToggle = new JCheckBoxMenuItem("Constraints visible"));
_ShowConstraintToggle.setToolTipText("Toggle display of constraints");
_ShowConstraintToggle.setState(true);
_ShowConstraintToggle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
ModelConstraint.setAllConstraintsVisible(_ourSketch.getConstraints(), _ShowConstraintToggle.getState());
}
});
// Create constraints menu
menuConstraint = new JMenu("Constraints");
menuConstraint.setMnemonic(KeyEvent.VK_C);
mainMenu.add(menuConstraint);
addMenuItem(menuConstraint, _AddCommutativeDiagramMenuItem = new JMenuItem(new AddCommutativeDiagramAction<>(this)), null);
addMenuItem(menuConstraint, _AddSumMenuItem = new JMenuItem(new AddSumConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddProductMenuItem = new JMenuItem(new AddProductConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddPullbackMenuItem = new JMenuItem(new AddPullbackConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddEqualizerMenuItem = new JMenuItem(new AddEqualizerConstraintAction(this)), null);
// addMenuItem(menuConstraint, _AddLimMenuItem = new JMenuItem(new
// AddLimitConstraintAction<SketchFrame,
// SketchGraphModel,Sketch,EntityNode, SketchEdge>(this)), null);
// Make SQL connection menu
menuSQL = new JMenu("SQL Connection");
menuSQL.setMnemonic(KeyEvent.VK_S);
mainMenu.add(menuSQL);
addMenuItem(menuSQL, new JMenuItem(new DisconnectAction(_ourSketch)), null);
// DTRIG
addMenuItem(menuSQL, new JMenuItem(new OverrideConstraintAction(_ourSketch)), null);
// CF2012
// Create help menu
menuHelp = new JMenu("Help");
mainMenu.add(menuHelp);
menuHelp.setMnemonic(KeyEvent.VK_H);
menuHelp.add(new HelpAction());
menuHelp.add(new AboutAction());
setJMenuBar(mainMenu);
}
use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.
the class JDBCUpdateMonitor method insert.
/**
* Determines if insertion into a given table requires special handling due
* to constraints it may be in. As of now, special cases that may result
* from being in multiple constraints are not supported.
*
* @param table
* The table into which we wish to insert data
* @return Success of the insertion
*/
@Override
public boolean insert(final EntityNode table) {
final DialogOptions dOpts = getDialogOptions(table);
final String lineSep = EasikTools.systemLineSeparator();
// a set of column-value pairs of which we wish to force a specific
// value, leaving the user out
final Set<ColumnEntry> forced = new HashSet<>(10);
// contstraint. Tighten up?
for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : table.getConstraints()) {
if (c instanceof SumConstraint) {
// of its foreign key, so remove it from the dialog's selection
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sp : c.getPaths()) {
if (sp.getDomain() == table) {
// we force the value 0 to avoid out driver to kick back
// an error for having a null fKey
final String columnName = cn.tableFK(sp.getFirstEdge());
dOpts.fKeys.remove(columnName);
forced.add(new ColumnEntry(columnName, "0", new Int()));
break;
}
}
}
if (c instanceof CommutativeDiagram) {
// commute
if (c.getPaths().get(0).getDomain() == table) {
JOptionPane.showMessageDialog(null, "Be sure that the following paths commute:" + lineSep + EasikTools.join(lineSep, c.getPaths()), "Commutative diagram", JOptionPane.INFORMATION_MESSAGE);
try {
return promptAndInsert(table, dOpts, forced);
} catch (SQLException e) {
/*
* if(e instanceof com.mysql.jdbc.exceptions.jdbc4.
* MySQLIntegrityConstraintViolationException){
* //injective property violated
* JOptionPane.showMessageDialog(null, e.getMessage(),
* "Injective property violation",
* JOptionPane.ERROR_MESSAGE); }else{
*/
JOptionPane.showMessageDialog(null, "Not all of the following paths commute -- insert aborted!" + lineSep + EasikTools.join(lineSep, c.getPaths()), "Commutative diagram failure", JOptionPane.ERROR_MESSAGE);
// }
}
}
}
if (c instanceof PullbackConstraint) {
// happens, we want to let the user update the new record
if (((PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c).getTarget() != table) {
final EntityNode pullback = ((PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c).getSource();
try {
// get row count pre-insert
ResultSet result = dbd.executeQuery("SELECT COUNT(*) FROM " + pullback.getName() + " X");
result.next();
final int preRowCount = result.getInt(1);
if (!promptAndInsert(table, dOpts)) {
return false;
}
// get row count post-insert
result = dbd.executeQuery("SELECT COUNT(*) FROM " + pullback.getName() + " X");
result.next();
final int postRowCount = result.getInt(1);
// new row (the one with the highest primary ID)
if (postRowCount > preRowCount) {
result = dbd.executeQuery("SELECT MAX(" + cn.tablePK(pullback) + ") FROM " + pullback.getName() + " X");
result.next();
final int pk = result.getInt(1);
if (JOptionPane.showConfirmDialog(null, "New record in pullback table '" + pullback.getName() + "'. Enter column data?", "Insert column data?", JOptionPane.YES_NO_OPTION) == 0) {
updateRow(pullback, pk);
}
}
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Could not execute update. MYSQL Error output:\n" + e.getMessage());
}
}
}
if (c instanceof ProductConstraint) {
// inserting into the product.
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sp : c.getPaths()) {
if (sp.getCoDomain() == table) {
final EntityNode product = sp.getDomain();
try {
if (!promptAndInsert(table, dOpts)) {
return false;
}
// get the new records from the product. They are
// any record who's fk to our INSERT factor matches
// the primary id of the last insert
ResultSet result = dbd.executeQuery("SELECT MAX(" + cn.tablePK(table) + ") FROM " + table.getName() + " X");
result.next();
final int newPK = result.getInt(1);
result = dbd.executeQuery("SELECT * FROM " + product.getName() + " WHERE " + cn.tableFK(sp.getFirstEdge()) + " = " + newPK);
// get count of new rows as result of INSERT
result.last();
final int newRows = result.getRow();
result.beforeFirst();
if ((newRows > 0) && (JOptionPane.showConfirmDialog(null, newRows + " new rows in product table '" + product.getName() + "'. Insert column data?", "Insert column data?", JOptionPane.YES_NO_OPTION) == 0)) {
while (result.next()) {
updateRow(product, result.getInt(1));
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
return true;
}
}
}
if (c instanceof LimitConstraint) {
// TRIANGLES TODO CF2012 Incomplete
}
}
try {
return promptAndInsert(table, dOpts, forced);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Could not execute update. MYSQL Error output:\n" + e.getMessage());
System.err.println(e.getMessage());
return false;
}
}
use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.
the class JDBCUpdateMonitor method updateRow.
/**
* Pops up a row entry dialog for the given table. The default field values
* will be the values stored in the row of the table who's primary ID
* matches the one given. Some cases call for use to restrict the update of
* foreign keys. Those cases are: a) A pullback b) The summands of a sum
* constrain c) The product of a product constraint If the table is in a
* constraint and the user wishes to break it the update is aborted leaving
* the old values in the record. Note: There are currently no checks to
* ensure that pk matches a record in our table.
*
* @param table
* The EntityNode representing the table we wish to update.
* @param pk
* The primary ID of the row whos data will be used to set
* defaults for our row entry dialog.
* @return The Success of the update.
*/
@Override
public boolean updateRow(final EntityNode table, final int pk) {
final DialogOptions dOpts = getDialogOptions(table);
try {
// Remove option to update foreign keys restricted by constraints
for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : table.getConstraints()) {
for (final SketchEdge se : table.getOutgoingEdges()) {
if (c.hasEdge(se)) {
dOpts.fKeys.remove(cn.tableFK(se));
}
}
}
// Display dialog for user with defaults as old record values
final RowEntryDialog red = new RowEntryDialog(_theSketch.getFrame(), "Update " + table.getName() + ": " + cn.tablePK(table) + " = " + pk, dOpts.attToType, dOpts.fKeys, DatabaseUtil.getRecord(table, pk));
if (red.isAccepted()) {
final Set<ColumnEntry> input = new LinkedHashSet<>(red.getInput());
// if we do not have any new input, no need to execute an update
if (input.isEmpty()) {
return true;
}
final StringBuilder sb = new StringBuilder("UPDATE " + table.getName() + " SET ");
for (final ColumnEntry ce : input) {
sb.append(dbd.quoteId(ce.getColumnName())).append('=' + "?,");
}
// remove last comma
sb.delete(sb.length() - 1, sb.length());
sb.append(" WHERE ").append(cn.tablePK(table)).append('=').append(pk);
dbd.executePreparedUpdate(sb.toString(), input);
return true;
}
return false;
} catch (SQLException e) {
JOptionPane.showMessageDialog(table.getMModel().getFrame(), "Could not update record: " + e.getMessage());
return false;
}
}
use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.
the class SketchHandler method startElement.
/**
* Overloaded method that is called any time the start of an element is
* found
*
* @param namespace
* @see org.xml.sax.helpers.DefaultHandler
* @param localName
* @see org.xml.sax.helpers.DefaultHandler
* @param qName
* @see org.xml.sax.helpers.DefaultHandler
* @param atts
* @see org.xml.sax.helpers.DefaultHandler
*/
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
_currNode = qName;
if (qName.equals("entity")) {
String name = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
if (_entityNodes.containsKey(name)) {
System.err.println("Duplicate nodes found in XML");
return;
}
_newNode = new EntityNode(name, x, y, _theFrame.getMModel());
_entityNodes.put(name, _newNode);
_curNodeAtts = new LinkedHashMap<>();
} else if (qName.equals("attribute")) {
EasikType type;
// attributeType was created by old Easik versions, and is the SQL
// type signature
// (such as "VARCHAR(255)"). Easik now uses attributeTypeClass,
// containing the
// class name, and any number of extra attributes which
// EasikType.newType() uses to
// recreate the appropriate EasikType object.
String typesig = atts.getValue("attributeType");
if (typesig != null) {
type = EasikType.typeFromSignature(typesig);
} else {
String typename = atts.getValue("attributeTypeClass");
try {
type = EasikType.newType(typename, attributeMap(atts, "attributeType", "attributeTypeClass", "name"));
} catch (ClassNotFoundException e) {
System.err.println("Invalid type found in XML: '" + typename + "' (" + e.getMessage() + ")");
return;
}
}
EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> myAtt = new EntityAttribute<>(atts.getValue("name"), type, _newNode);
_curNodeAtts.put(atts.getValue("name"), myAtt);
_newNode.addEntityAttribute(myAtt);
} else if (qName.equals("uniqueKey")) {
// New EASIK has noderef, telling us what we refer to. In old easik,
// uniqueKey is under
// the node itself (but as a result, cannot contain edge
// references).
String noderef = atts.getValue("noderef");
if (noderef != null) {
// Restore _newNode and _curNodeAtts, since we're going to need
// them:
_newNode = _entityNodes.get(noderef);
_curNodeAtts = new LinkedHashMap<>();
for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> att : _newNode.getEntityAttributes()) {
_curNodeAtts.put(att.getName(), att);
}
}
_curUniqueKeyName = atts.getValue("name");
_curUniqueKeyElems = new LinkedList<>();
} else if (qName.equals("attref")) {
_curUniqueKeyElems.add(_curNodeAtts.get(atts.getValue("name")));
} else if (qName.equals("edgekeyref")) {
SketchEdge e = _edges.get(atts.getValue("id"));
if (e instanceof UniqueIndexable) {
_curUniqueKeyElems.add((UniqueIndexable) e);
} else {
System.err.println("Encountered an non-unique-indexable <edgekeyref> " + e);
}
} else if (qName.equals("edge")) {
SketchEdge newEdge;
String edgeType = atts.getValue("type");
// injective is an old EASIK attribute:
String injective = atts.getValue("injective");
if (injective != null) {
edgeType = atts.getValue("injective").equals("true") ? "injective" : "normal";
}
EntityNode source = _entityNodes.get(atts.getValue("source"));
EntityNode target = _entityNodes.get(atts.getValue("target"));
String id = atts.getValue("id");
String cascadeAtt = atts.getValue("cascade");
if (cascadeAtt == null) {
// This is from an export before Easik had per-edge cascading
// (in other words, before r583)
// We use the global preferences for cascading
String key = "sql_cascade", def = "restrict";
if (edgeType.equals("partial")) {
key = "sql_cascade_partial";
def = "set_null";
}
cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
}
SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
if (edgeType.equals("injective")) {
newEdge = new InjectiveEdge(source, target, id, cascade);
} else if (edgeType.equals("partial")) {
newEdge = new PartialEdge(source, target, id, cascade);
} else {
newEdge = new NormalEdge(source, target, id, cascade);
}
_edges.put(id, newEdge);
} else if (qName.equals("path")) {
_curPath = new LinkedList<>();
_curPathId = atts.getValue("id");
_curDomain = _entityNodes.get(atts.getValue("domain"));
} else if (qName.equals("edgeref")) {
_curPath.add(_edges.get(atts.getValue("id")));
} else if (// TRIANGLES
qName.equals("sumconstraint") || qName.equals("pullbackconstraint") || qName.equals("productconstraint") || qName.equals("commutativediagram") || qName.equals("equalizerconstraint") || qName.equals("limitconstraint")) // CF2012
{
_curConstraintX = Integer.parseInt(atts.getValue("x"));
_curConstraintY = Integer.parseInt(atts.getValue("y"));
_curConstraintVisible = atts.getValue("isVisible").equals("true");
_curConstraintPaths = new ArrayList<>();
_allConstraintsVisible = atts.getValue("isVisible").equals("true");
} else if (qName.equals("pathref")) {
// This is for compatibility with old versions of Easik (pre-2.0);
// new versions
// put <path> elements directly inside the various constraint
// elements.
_curConstraintPaths.add(_allPaths.get(atts.getValue("id")));
} else if (qName.equals("connectionParam")) {
_connParams.put(atts.getValue("name"), atts.getValue("value"));
} else if (qName.equals("synchronized")) {
// The existance of this tag tells us the sketch is synchronized
_curSketchSync = true;
}
}
use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.
the class SketchGraphModel method getAttributes.
/**
* Overridden method to get cell attributes; we make sure the appropriate
* attributes are applied to the Easik objects before returning them.
*
* @see DefaultGraphModel.getAttributes(Object)
*
* @param o
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
_mode = (_sketch.getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
if (o instanceof GraphCell) {
GraphCell cell = (GraphCell) o;
AttributeMap attribs = cell.getAttributes();
AttributeMap easikAttribs = null;
if (cell instanceof SketchEdge) {
easikAttribs = (cell instanceof InjectiveEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
} else if (cell instanceof TriangleEdge) {
easikAttribs = triangleEdgeAttributes((TriangleEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell);
} else if (cell instanceof GuideEdge) {
easikAttribs = ((GuideEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
} else if (cell instanceof ModelConstraint) {
easikAttribs = virtualVertexAttributes();
} else if (cell instanceof EntityNode) {
easikAttribs = vertexAttributes();
}
if (easikAttribs != null) {
if (_sketch.isCellSelected(cell)) {
Color selColor;
float lineWidth;
if (_sketch.getStateManager().peekState() instanceof GetPathState) {
selColor = getColor("path_selection");
lineWidth = getWidth("path_selection", 2);
} else {
selColor = getColor("selection");
lineWidth = getWidth("selection", 3);
}
int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
GraphConstants.setForeground(easikAttribs, selColor);
GraphConstants.setLineColor(easikAttribs, selColor);
GraphConstants.setLineWidth(easikAttribs, lineWidth);
}
if (attribs == null) {
cell.setAttributes(easikAttribs);
attribs = easikAttribs;
} else {
attribs.applyMap(easikAttribs);
}
return attribs;
}
}
return super.getAttributes(o);
}
Aggregations