Search in sources :

Example 1 with Settings

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());
}
Also used : Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 2 with Settings

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();
}
Also used : Macro(com.willwinder.universalgcodesender.types.Macro) ActionEvent(java.awt.event.ActionEvent) MigLayout(net.miginfocom.swing.MigLayout) Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 3 with Settings

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);
}
Also used : IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) Settings(com.willwinder.universalgcodesender.utils.Settings) Test(org.junit.Test)

Example 4 with Settings

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);
}
Also used : Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 5 with 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);
}
Also used : UGSEventListener(com.willwinder.universalgcodesender.listeners.UGSEventListener) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) Settings(com.willwinder.universalgcodesender.utils.Settings) AbstractController(com.willwinder.universalgcodesender.AbstractController) Before(org.junit.Before)

Aggregations

Settings (com.willwinder.universalgcodesender.utils.Settings)14 Macro (com.willwinder.universalgcodesender.types.Macro)3 IFirmwareSettings (com.willwinder.universalgcodesender.firmware.IFirmwareSettings)2 AbstractUGSSettings (com.willwinder.universalgcodesender.uielements.helpers.AbstractUGSSettings)2 MigLayout (net.miginfocom.swing.MigLayout)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 ActionRegistrationService (com.willwinder.ugs.nbp.lib.services.ActionRegistrationService)1 AbstractController (com.willwinder.universalgcodesender.AbstractController)1 UGSEventListener (com.willwinder.universalgcodesender.listeners.UGSEventListener)1 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)1 StepSizeOption (com.willwinder.universalgcodesender.pendantui.PendantConfigBean.StepSizeOption)1 ActionEvent (java.awt.event.ActionEvent)1 Before (org.junit.Before)1 FileObject (org.openide.filesystems.FileObject)1