mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 17:04:42 -04:00
removed wire state, wires a drawn in element state
This commit is contained in:
parent
9e63bd4eca
commit
f4393f91d9
@ -236,6 +236,10 @@ public class Circuit {
|
||||
VisualElement el = getElementAt(pos);
|
||||
if (el == null) return false;
|
||||
|
||||
return isPinPos(pos, el);
|
||||
}
|
||||
|
||||
public boolean isPinPos(Vector pos, VisualElement el) {
|
||||
for (Pin p : el.getPins())
|
||||
if (p.getPos().equals(pos))
|
||||
return true;
|
||||
|
@ -73,7 +73,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
private ScheduledThreadPoolExecutor timerExecuter = new ScheduledThreadPoolExecutor(1);
|
||||
|
||||
private State elementState;
|
||||
private State wireState;
|
||||
//private State wireState;
|
||||
private State selectState;
|
||||
private State runModelState;
|
||||
private State runModelMicroState;
|
||||
@ -203,7 +203,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
JMenu edit = new JMenu(Lang.get("menu_edit"));
|
||||
bar.add(edit);
|
||||
|
||||
ToolTipAction wireStateAction = wireState.createToolTipAction(Lang.get("menu_wire"), ICON_WIRE).setToolTip(Lang.get("menu_wire_tt"));
|
||||
//ToolTipAction wireStateAction = wireState.createToolTipAction(Lang.get("menu_wire"), ICON_WIRE).setToolTip(Lang.get("menu_wire_tt"));
|
||||
ToolTipAction elementStateAction = elementState.createToolTipAction(Lang.get("menu_element"), ICON_ELEMENT).setToolTip(Lang.get("menu_element_tt"));
|
||||
ToolTipAction selectStateAction = selectState.createToolTipAction(Lang.get("menu_select"), ICON_SELECT).setToolTip(Lang.get("menu_select_tt"));
|
||||
|
||||
@ -242,7 +242,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
|
||||
|
||||
edit.add(elementStateAction.createJMenuItem());
|
||||
edit.add(wireStateAction.createJMenuItem());
|
||||
//edit.add(wireStateAction.createJMenuItem());
|
||||
edit.add(selectStateAction.createJMenuItem());
|
||||
edit.add(orderInputs.createJMenuItem());
|
||||
edit.add(orderOutputs.createJMenuItem());
|
||||
@ -330,7 +330,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
toolBar.add(save.createJButtonNoText());
|
||||
toolBar.addSeparator();
|
||||
toolBar.add(elementState.setIndicator(elementStateAction.createJButtonNoText()));
|
||||
toolBar.add(wireState.setIndicator(wireStateAction.createJButtonNoText()));
|
||||
//toolBar.add(wireState.setIndicator(wireStateAction.createJButtonNoText()));
|
||||
toolBar.add(selectState.setIndicator(selectStateAction.createJButtonNoText()));
|
||||
toolBar.add(circuitComponent.getDeleteAction().createJButtonNoText());
|
||||
toolBar.addSeparator();
|
||||
@ -356,7 +356,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
|
||||
private void setupStates() {
|
||||
elementState = stateManager.register(new ModeState(CircuitComponent.Mode.part));
|
||||
wireState = stateManager.register(new ModeState(CircuitComponent.Mode.wire));
|
||||
//wireState = stateManager.register(new ModeState(CircuitComponent.Mode.wire));
|
||||
selectState = stateManager.register(new ModeState(CircuitComponent.Mode.select));
|
||||
runModelState = stateManager.register(new State() {
|
||||
@Override
|
||||
|
@ -273,6 +273,7 @@ public class CircuitComponent extends JComponent {
|
||||
private class PartMouseListener extends Mouse {
|
||||
|
||||
private VisualElement partToInsert;
|
||||
private Wire wire;
|
||||
private boolean autoPick = false;
|
||||
private Vector delta;
|
||||
private boolean insert;
|
||||
@ -284,6 +285,10 @@ public class CircuitComponent extends JComponent {
|
||||
partToInsert.setPos(raster(pos.add(delta)));
|
||||
repaint();
|
||||
}
|
||||
if (wire != null) {
|
||||
wire.setP2(raster(getPosVector(e)));
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,12 +296,29 @@ public class CircuitComponent extends JComponent {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
if (partToInsert == null) {
|
||||
insert = false;
|
||||
Vector pos = getPosVector(e);
|
||||
VisualElement vp = circuit.getElementAt(pos);
|
||||
if (vp != null) {
|
||||
partToInsert = vp;
|
||||
delta = partToInsert.getPos().sub(pos);
|
||||
repaint();
|
||||
if (wire == null) {
|
||||
Vector pos = getPosVector(e);
|
||||
VisualElement vp = circuit.getElementAt(pos);
|
||||
if (vp != null) {
|
||||
Vector startPos = raster(pos);
|
||||
if (circuit.isPinPos(startPos)) {
|
||||
wire = new Wire(startPos, startPos);
|
||||
} else {
|
||||
partToInsert = vp;
|
||||
delta = partToInsert.getPos().sub(pos);
|
||||
}
|
||||
repaint();
|
||||
} else {
|
||||
Vector startPos = raster(pos);
|
||||
wire = new Wire(startPos, startPos);
|
||||
}
|
||||
} else {
|
||||
circuit.add(wire);
|
||||
Vector startPos = raster(getPosVector(e));
|
||||
if (circuit.isPinPos(startPos))
|
||||
wire = null;
|
||||
else
|
||||
wire = new Wire(startPos, startPos);
|
||||
}
|
||||
} else {
|
||||
partToInsert.setPos(raster(partToInsert.getPos()));
|
||||
@ -308,7 +330,11 @@ public class CircuitComponent extends JComponent {
|
||||
}
|
||||
deleteAction.setEnabled(partToInsert != null);
|
||||
} else {
|
||||
editAttributes(e);
|
||||
if (wire != null) {
|
||||
wire = null;
|
||||
repaint();
|
||||
} else
|
||||
editAttributes(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,6 +362,8 @@ public class CircuitComponent extends JComponent {
|
||||
public void drawTo(Graphic gr) {
|
||||
if (partToInsert != null && !autoPick)
|
||||
partToInsert.drawTo(gr, true);
|
||||
if (wire != null)
|
||||
wire.drawTo(gr, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user