use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class AddTool method getBounds.
private Bounds getBounds() {
Bounds ret = bounds;
if (ret == null) {
ComponentFactory source = getFactory();
if (source == null) {
ret = Bounds.EMPTY_BOUNDS;
} else {
AttributeSet base = getBaseAttributes();
ret = source.getOffsetBounds(base).expand(5);
}
bounds = ret;
}
return ret;
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class AddTool method getFactory.
public ComponentFactory getFactory() {
ComponentFactory ret = factory;
if (ret != null || sourceLoadAttempted) {
return ret;
} else {
ret = description.getFactory(descriptionBase);
if (ret != null) {
AttributeSet base = getBaseAttributes();
Boolean value = (Boolean) ret.getFeature(ComponentFactory.SHOULD_SNAP, base);
shouldSnap = value == null ? true : value.booleanValue();
}
factory = ret;
sourceLoadAttempted = true;
return ret;
}
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class FactoryAttributes method getBase.
AttributeSet getBase() {
AttributeSet ret = baseAttrs;
if (ret == null) {
ComponentFactory fact = factory;
if (fact == null) {
fact = desc.getFactory(descBase);
factory = fact;
}
if (fact == null) {
ret = AttributeSets.EMPTY;
} else {
ret = fact.createAttributeSet();
ret.addAttributeListener(this);
}
baseAttrs = ret;
}
return ret;
}
use of com.cburch.logisim.data.AttributeSet 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.data.AttributeSet in project logisim-evolution by reds-heig.
the class NumericConfigurator method keyEventReceived.
public KeyConfigurationResult keyEventReceived(KeyConfigurationEvent event) {
if (event.getType() == KeyConfigurationEvent.KEY_TYPED) {
KeyEvent e = event.getKeyEvent();
int digit = Character.digit(e.getKeyChar(), radix);
if (digit >= 0 && e.getModifiersEx() == modsEx) {
long now = System.currentTimeMillis();
long sinceLast = now - whenTyped;
AttributeSet attrs = event.getAttributeSet();
int min = getMinimumValue(attrs);
int max = getMaximumValue(attrs);
int val = 0;
if (sinceLast < MAX_TIME_KEY_LASTS) {
val = radix * curValue;
if (val > max) {
val = 0;
}
}
val += digit;
if (val > max) {
val = digit;
if (val > max) {
return null;
}
}
event.consume();
whenTyped = now;
curValue = val;
if (val >= min) {
Object valObj = createValue(val);
return new KeyConfigurationResult(event, attr, valObj);
}
}
}
return null;
}
Aggregations