use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.
the class LogisimFile method removeCircuit.
public void removeCircuit(Circuit circuit) {
if (tools.size() <= 1) {
throw new RuntimeException("Cannot remove last circuit");
}
int index = getCircuits().indexOf(circuit);
if (index >= 0) {
Tool circuitTool = tools.remove(index);
if (main == circuit) {
AddTool dflt_tool = tools.get(0);
SubcircuitFactory factory = (SubcircuitFactory) dflt_tool.getFactory();
setMainCircuit(factory.getSubcircuit());
}
fireEvent(LibraryEvent.REMOVE_TOOL, circuitTool);
}
}
use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.
the class Project method setTool.
public void setTool(Tool value) {
if (tool == value)
return;
Tool old = tool;
Canvas canvas = frame.getCanvas();
if (old != null)
old.deselect(canvas);
Selection selection = canvas.getSelection();
if (selection != null && !selection.isEmpty()) {
if (value == null || !getOptions().getMouseMappings().containsSelectTool()) {
Action act = SelectionActions.anchorAll(selection);
/*
* Circuit circuit = canvas.getCircuit(); CircuitMutation xn =
* new CircuitMutation(circuit); if (value == null) { Action act
* = SelectionActions.dropAll(selection); if (act != null) {
* doAction(act); } } else if
* (!getOptions().getMouseMappings().containsSelectTool()) {
* Action act = SelectionActions.dropAll(selection);
*/
if (act != null) {
doAction(act);
}
}
/*
* if (!xn.isEmpty()) doAction(xn.toAction(null));
*/
}
startupScreen = false;
tool = value;
if (tool != null)
tool.select(frame.getCanvas());
fireEvent(ProjectEvent.ACTION_SET_TOOL, old, tool);
}
use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.
the class ProjectActions method doSave.
private static boolean doSave(Project proj, File f) {
Loader loader = proj.getLogisimFile().getLoader();
Tool oldTool = proj.getTool();
proj.setTool(null);
boolean ret = loader.save(proj.getLogisimFile(), f);
if (ret) {
AppPreferences.updateRecentFile(f);
proj.setFileAsClean();
}
proj.setTool(oldTool);
return ret;
}
use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.
the class CanvasPainter method drawWithUserState.
private void drawWithUserState(Graphics base, Graphics g, Project proj) {
Circuit circ = proj.getCurrentCircuit();
Selection sel = proj.getSelection();
Set<Component> hidden;
Tool dragTool = canvas.getDragTool();
if (dragTool == null) {
hidden = NO_COMPONENTS;
} else {
hidden = dragTool.getHiddenComponents(canvas);
if (hidden == null)
hidden = NO_COMPONENTS;
}
// draw halo around component whose attributes we are viewing
boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
GraphicsUtil.switchToWidth(g, 3);
g.setColor(Canvas.HALO_COLOR);
Bounds bds = haloedComponent.getBounds(g).expand(5);
int w = bds.getWidth();
int h = bds.getHeight();
double a = Canvas.SQRT_2 * w;
double b = Canvas.SQRT_2 * h;
g.drawOval((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
GraphicsUtil.switchToWidth(g, 1);
g.setColor(Color.BLACK);
}
// draw circuit and selection
CircuitState circState = proj.getCircuitState();
boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
context.setHighlightedWires(highlightedWires);
circ.draw(context, hidden);
sel.draw(context, hidden);
// draw tool
Tool tool = dragTool != null ? dragTool : proj.getTool();
if (tool != null && !canvas.isPopupMenuUp()) {
Graphics gCopy = g.create();
context.setGraphics(gCopy);
tool.draw(canvas, context);
gCopy.dispose();
}
}
use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.
the class LayoutToolbarModel method itemSelected.
@Override
public void itemSelected(ToolbarItem item) {
if (item instanceof ToolItem) {
Tool tool = ((ToolItem) item).tool;
proj.setTool(tool);
}
}
Aggregations