mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 23:06:22 -04:00
better adaptive toolbar
This commit is contained in:
parent
e26c4f643d
commit
3f098ea1a2
@ -24,7 +24,8 @@ public class SpeedTest {
|
||||
|
||||
|
||||
Clock clock = clocks.get(0);
|
||||
model.init(true);
|
||||
clock.disableTimer();
|
||||
model.init();
|
||||
ObservableValue clockValue = clock.getOutputs()[0];
|
||||
int state = (int) clockValue.getValue();
|
||||
|
||||
|
@ -20,6 +20,7 @@ public class Clock implements Element {
|
||||
|
||||
private final ObservableValue output;
|
||||
private final int frequency;
|
||||
public boolean startThisTimer = true;
|
||||
|
||||
public Clock(ElementAttributes attributes) {
|
||||
output = new ObservableValue("C", 1);
|
||||
@ -36,10 +37,13 @@ public class Clock implements Element {
|
||||
return new ObservableValue[]{output};
|
||||
}
|
||||
|
||||
public void disableTimer() {
|
||||
this.startThisTimer = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
model.addObserver(new ModelStateObserver() {
|
||||
public boolean startThisTimer = true;
|
||||
public Timer timer;
|
||||
|
||||
@Override
|
||||
@ -67,7 +71,7 @@ public class Clock implements Element {
|
||||
break;
|
||||
case FETCHCLOCK:
|
||||
event.registerClock(Clock.this);
|
||||
startThisTimer = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.neemann.digital.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@ -8,24 +9,69 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class InsertHistory {
|
||||
|
||||
private static final int MAX_ICONS = 6;
|
||||
private final JToolBar bar;
|
||||
private final ArrayList<AbstractAction> actions;
|
||||
private final int removePos;
|
||||
private final ArrayList<WrapperAction> wrappers;
|
||||
private int mainTime;
|
||||
|
||||
public InsertHistory(JToolBar bar) {
|
||||
this.bar = bar;
|
||||
actions = new ArrayList<>();
|
||||
removePos = bar.getComponentCount();
|
||||
wrappers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(AbstractAction action) {
|
||||
if (!actions.contains(action)) {
|
||||
actions.add(action);
|
||||
bar.add(action);
|
||||
if (actions.size() > 3) {
|
||||
actions.remove(0);
|
||||
bar.remove(removePos);
|
||||
if (!contains(action)) {
|
||||
WrapperAction wrapper = new WrapperAction(action, bar.getComponentCount());
|
||||
wrappers.add(wrapper);
|
||||
bar.add(wrapper);
|
||||
if (wrappers.size() > MAX_ICONS) {
|
||||
int oldest = findOldestIndex();
|
||||
wrapper = wrappers.get(oldest);
|
||||
bar.remove(wrapper.componentPosition);
|
||||
for (int i = oldest; i < wrappers.size(); i++)
|
||||
wrappers.get(i).componentPosition--;
|
||||
wrappers.remove(oldest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int findOldestIndex() {
|
||||
int found = -1;
|
||||
int oldestTime = mainTime;
|
||||
for (int i = 0; i < wrappers.size(); i++) {
|
||||
WrapperAction wrapper = wrappers.get(i);
|
||||
if (wrapper.time < oldestTime) {
|
||||
found = i;
|
||||
oldestTime = wrapper.time;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private boolean contains(AbstractAction action) {
|
||||
for (WrapperAction wrapper : wrappers)
|
||||
if (wrapper.action == action)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public class WrapperAction extends AbstractAction {
|
||||
|
||||
private final AbstractAction action;
|
||||
private int componentPosition;
|
||||
private int time;
|
||||
|
||||
public WrapperAction(AbstractAction action, int componentPosition) {
|
||||
super(action.getValue(Action.NAME).toString(), (Icon) action.getValue(Action.SMALL_ICON));
|
||||
this.action = action;
|
||||
this.componentPosition = componentPosition;
|
||||
time = mainTime++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
action.actionPerformed(e);
|
||||
time = mainTime++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,9 @@ public class LEDShape implements Shape {
|
||||
|
||||
@Override
|
||||
public void drawTo(Graphic graphic) {
|
||||
boolean fill = false;
|
||||
boolean fill = true;
|
||||
if (ioState != null) {
|
||||
fill = false;
|
||||
ObservableValue value = ioState.getInput(0);
|
||||
if (!value.isHighZ() && (value.getValue() != 0))
|
||||
fill = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user