use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Frame method placeToolbar.
private void placeToolbar() {
String loc = AppPreferences.TOOLBAR_PLACEMENT.get();
Container contents = getContentPane();
contents.remove(toolbar);
mainPanelSuper.remove(toolbar);
if (AppPreferences.TOOLBAR_HIDDEN.equals(loc)) {
// don't place value anywhere
;
} else if (AppPreferences.TOOLBAR_DOWN_MIDDLE.equals(loc)) {
toolbar.setOrientation(Toolbar.VERTICAL);
mainPanelSuper.add(toolbar, BorderLayout.WEST);
} else {
// it is a BorderLayout constant
Object value = BorderLayout.NORTH;
for (Direction dir : Direction.cardinals) {
if (dir.toString().equals(loc)) {
if (dir == Direction.EAST) {
value = BorderLayout.EAST;
} else if (dir == Direction.SOUTH) {
value = BorderLayout.SOUTH;
} else if (dir == Direction.WEST) {
value = BorderLayout.WEST;
} else {
value = BorderLayout.NORTH;
}
}
}
contents.add(toolbar, value);
boolean vertical = value == BorderLayout.WEST || value == BorderLayout.EAST;
toolbar.setOrientation(vertical ? Toolbar.VERTICAL : Toolbar.HORIZONTAL);
}
contents.validate();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AddTool method setFacing.
private void setFacing(Canvas canvas, Direction facing) {
ComponentFactory source = getFactory();
if (source == null)
return;
AttributeSet base = getBaseAttributes();
Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
@SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
if (attr != null) {
Action act = ToolAttributeAction.create(this, attr, facing);
canvas.getProject().doAction(act);
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AddTool method keyPressed.
@Override
public void keyPressed(Canvas canvas, KeyEvent event) {
processKeyEvent(canvas, event, KeyConfigurationEvent.KEY_PRESSED);
if (!event.isConsumed() && event.getModifiersEx() == 0) {
int KeybEvent = event.getKeyCode();
String Component = getFactory().getDisplayName();
if (!GateKeyboardModifier.TookKeyboardStrokes(KeybEvent, null, attrs, canvas, null, false))
if (AutoLabler.LabelKeyboardHandler(KeybEvent, getAttributeSet(), Component, null, getFactory(), canvas.getCircuit(), null, false)) {
canvas.repaint();
} else
switch(KeybEvent) {
case KeyEvent.VK_UP:
setFacing(canvas, Direction.NORTH);
break;
case KeyEvent.VK_DOWN:
setFacing(canvas, Direction.SOUTH);
break;
case KeyEvent.VK_LEFT:
setFacing(canvas, Direction.WEST);
break;
case KeyEvent.VK_RIGHT:
setFacing(canvas, Direction.EAST);
break;
case KeyEvent.VK_R:
Direction current = getFacing();
if (current == Direction.NORTH)
setFacing(canvas, Direction.EAST);
else if (current == Direction.EAST)
setFacing(canvas, Direction.SOUTH);
else if (current == Direction.SOUTH)
setFacing(canvas, Direction.WEST);
else
setFacing(canvas, Direction.NORTH);
break;
case KeyEvent.VK_ESCAPE:
Project proj = canvas.getProject();
Library base = proj.getLogisimFile().getLibrary("Base");
Tool next = (base == null) ? null : base.getTool("Edit Tool");
if (next != null) {
proj.setTool(next);
Action act = SelectionActions.dropAll(canvas.getSelection());
if (act != null) {
proj.doAction(act);
}
}
break;
case KeyEvent.VK_BACK_SPACE:
if (lastAddition != null && canvas.getProject().getLastAction() == lastAddition) {
canvas.getProject().undoAction();
lastAddition = null;
}
}
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class EditTool method attemptReface.
private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
if (e.getModifiersEx() == 0) {
final Circuit circuit = canvas.getCircuit();
final Selection sel = canvas.getSelection();
SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
for (Component comp : sel.getComponents()) {
if (!(comp instanceof Wire)) {
Attribute<Direction> attr = getFacingAttribute(comp);
if (attr != null) {
act.set(comp, attr, facing);
}
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
e.consume();
}
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class PullResistor method paintBase.
private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
boolean color = painter.shouldDrawColor();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Graphics g = painter.getGraphics();
Color baseColor = g.getColor();
GraphicsUtil.switchToWidth(g, 3);
if (color && inColor != null)
g.setColor(inColor);
if (facing == Direction.EAST) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
} else if (facing == Direction.WEST) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
} else if (facing == Direction.NORTH) {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
} else {
GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
double rotate = 0.0;
if (g instanceof Graphics2D) {
rotate = Direction.SOUTH.toRadians() - facing.toRadians();
if (rotate != 0.0)
((Graphics2D) g).rotate(rotate);
}
g.drawLine(0, -30, 0, -26);
g.drawLine(-6, -30, 6, -30);
if (color && outColor != null)
g.setColor(outColor);
g.drawLine(0, -4, 0, 0);
g.setColor(baseColor);
GraphicsUtil.switchToWidth(g, 2);
if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
int[] xp = { 0, -5, 5, -5, 5, -5, 0 };
int[] yp = { -25, -23, -19, -15, -11, -7, -5 };
g.drawPolyline(xp, yp, xp.length);
} else {
g.drawRect(-5, -25, 10, 20);
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
}
Aggregations