use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.
the class JogPanel method syncWithJogService.
private void syncWithJogService() {
Settings s = backend.getSettings();
xyStepSizeSpinner.setValue(s.getManualModeStepSize());
zStepSizeSpinner.setValue(s.getzJogStepSize());
feedRateSpinner.setValue(s.getJogFeedRate());
}
use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.
the class MacroActionPanel method doLayout.
@Override
public void doLayout() {
Settings s = backend.getSettings();
// Lookup macros.
if (macrosDirty) {
Integer lastMacroIndex = s.getLastMacroIndex() + 1;
macros.clear();
for (int i = 0; i < lastMacroIndex; i++) {
Macro m = s.getMacro(i);
if (StringUtils.isNotEmpty(m.getGcode())) {
macros.add(s.getMacro(i));
}
}
}
// Cache the largest width amongst the buttons.
int maxWidth = 0;
int maxHeight = 0;
// Create buttons.
for (int i = 0; i < macros.size(); i++) {
final int index = i;
Macro macro = macros.get(i);
JButton button;
if (customGcodeButtons.size() <= i) {
button = new JButton(i + "");
button.setEnabled(false);
customGcodeButtons.add(button);
// Add action listener
button.addActionListener((ActionEvent evt) -> {
customGcodeButtonActionPerformed(index);
});
} else {
button = customGcodeButtons.get(i);
}
if (!StringUtils.isEmpty(macro.getName())) {
button.setText(macro.getName());
} else if (!StringUtils.isEmpty(macro.getDescription())) {
button.setText(macro.getDescription());
}
if (!StringUtils.isEmpty(macro.getDescription())) {
button.setToolTipText(macro.getDescription());
}
if (button.getPreferredSize().width > maxWidth)
maxWidth = button.getPreferredSize().width;
if (button.getPreferredSize().height > maxHeight)
maxHeight = button.getPreferredSize().height;
}
// If button count was reduced, clear out any extras.
if (customGcodeButtons.size() > macros.size()) {
this.macroPanel.removeAll();
this.macroPanel.repaint();
for (int i = customGcodeButtons.size(); i > macros.size(); i--) {
JButton b = customGcodeButtons.remove(i - 1);
}
}
// Calculate columns/rows which can fit in the space we have.
int columns = (getWidth() - (2 * INSET)) / (maxWidth + PADDING);
int rows = (getHeight() - (2 * INSET)) / (maxHeight + PADDING);
// At least one column.
columns = Math.max(columns, 1);
// Update number of rows if more are needed.
if (columns * rows < customGcodeButtons.size()) {
rows = customGcodeButtons.size() / columns;
if (customGcodeButtons.size() % columns != 0)
rows++;
}
// Layout for buttons.
StringBuilder columnConstraint = new StringBuilder();
for (int i = 0; i < columns; i++) {
if (i > 0) {
columnConstraint.append("unrelated");
}
columnConstraint.append("[fill, sg 1]");
}
MigLayout layout = new MigLayout("fillx, wrap " + columns + ", inset " + INSET, columnConstraint.toString());
macroPanel.setLayout(layout);
// Put buttons in grid.
int x = 0;
int y = 0;
for (JButton button : customGcodeButtons) {
macroPanel.add(button, "cell " + x + " " + y);
y++;
if (y == rows) {
x++;
y = 0;
}
}
super.doLayout();
}
use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.
the class GUIBackendTest method getSettingsShouldBeOk.
@Test
public void getSettingsShouldBeOk() {
Settings result = instance.getSettings();
assertEquals(settings, result);
}
use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.
the class shutdown method run.
@Override
public void run() {
// Save settings.
Settings settings = CentralLookup.getDefault().lookup(Settings.class);
SettingsFactory.saveSettings(settings);
}
use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.
the class GUIBackendTest method setUp.
@Before
public void setUp() throws Exception {
// We need to mock the method that loads the controller
instance = spy(new GUIBackend());
IFirmwareSettings firmwareSettings = mock(IFirmwareSettings.class);
controller = mock(AbstractController.class);
doReturn(controller).when(instance).fetchControllerFromFirmware(any());
doReturn(firmwareSettings).when(controller).getFirmwareSettings();
// Add a event listener that stores events in the argument captor
UGSEventListener ugsEventListener = mock(UGSEventListener.class);
eventArgumentCaptor = ArgumentCaptor.forClass(UGSEvent.class);
doNothing().when(ugsEventListener).UGSEvent(eventArgumentCaptor.capture());
instance.addUGSEventListener(ugsEventListener);
// Add settings
settings = new Settings();
instance.applySettings(settings);
}
Aggregations