use of com.cburch.logisim.comp.ComponentUserEvent in project logisim-evolution by reds-heig.
the class Canvas method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
boolean showTips = AppPreferences.COMPONENT_TIPS.getBoolean();
if (showTips) {
Canvas.snapToGrid(event);
Location loc = Location.create(event.getX(), event.getY());
ComponentUserEvent e = null;
for (Component comp : getCircuit().getAllContaining(loc)) {
Object makerObj = comp.getFeature(ToolTipMaker.class);
if (makerObj != null && makerObj instanceof ToolTipMaker) {
ToolTipMaker maker = (ToolTipMaker) makerObj;
if (e == null) {
e = new ComponentUserEvent(this, loc.getX(), loc.getY());
}
String ret = maker.getToolTip(e);
if (ret != null) {
unrepairMouseEvent(event);
return ret;
}
}
}
}
return null;
}
use of com.cburch.logisim.comp.ComponentUserEvent in project logisim-evolution by reds-heig.
the class TextTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
if (!proj.getLogisimFile().contains(circ)) {
if (caret != null)
caret.cancelEditing();
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
return;
}
// Maybe user is clicking within the current caret.
if (caret != null) {
if (caret.getBounds(g).contains(e.getX(), e.getY())) {
// Yes
caret.mousePressed(e);
proj.repaintCanvas();
return;
} else {
// No. End the current caret.
caret.stopEditing();
}
}
// caret will be null at this point
// Otherwise search for a new caret.
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
// First search in selection.
for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
// Then search in circuit
if (caret == null) {
for (Component comp : circ.getAllContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
}
// if nothing found, create a new label
if (caret == null) {
if (loc.getX() < 0 || loc.getY() < 0)
return;
AttributeSet copy = (AttributeSet) attrs.clone();
caretComponent = Text.FACTORY.createComponent(loc, copy);
caretCreatingText = true;
TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
proj.getFrame().viewComponentAttributes(circ, caretComponent);
}
}
if (caret != null) {
caretCanvas = canvas;
caretCircuit = canvas.getCircuit();
caret.addCaretListener(listener);
caretCircuit.addCircuitListener(listener);
}
proj.repaintCanvas();
}
use of com.cburch.logisim.comp.ComponentUserEvent in project logisim-evolution by reds-heig.
the class PokeTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
boolean dirty = false;
canvas.setHighlightedWires(WireSet.EMPTY);
if (pokeCaret != null && !pokeCaret.getBounds(g).contains(loc)) {
dirty = true;
removeCaret(true);
}
if (pokeCaret == null) {
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
Circuit circ = canvas.getCircuit();
for (Component c : circ.getAllContaining(loc, g)) {
if (pokeCaret != null)
break;
if (c instanceof Wire) {
Caret caret = new WireCaret(canvas, (Wire) c, x, y, canvas.getProject().getOptions().getAttributeSet());
setPokedComponent(circ, c, caret);
canvas.setHighlightedWires(circ.getWireSet((Wire) c));
} else {
Pokable p = (Pokable) c.getFeature(Pokable.class);
if (p != null) {
Caret caret = p.getPokeCaret(event);
setPokedComponent(circ, c, caret);
AttributeSet attrs = c.getAttributeSet();
if (attrs != null && attrs.getAttributes().size() > 0) {
Project proj = canvas.getProject();
proj.getFrame().viewComponentAttributes(circ, c);
}
}
}
}
}
if (pokeCaret != null) {
dirty = true;
pokeCaret.mousePressed(e);
}
if (dirty)
canvas.getProject().repaintCanvas();
}
Aggregations