Skip to content

Commit

Permalink
Added File Browser (#2460)
Browse files Browse the repository at this point in the history
Added a File Browser panel, similar to how most CNCs with control boards have file lists.
  • Loading branch information
andrewmurraydavid committed Feb 12, 2024
1 parent 425f582 commit f06322c
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2014-2023 Will Winder
Copyright 2014-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
Expand Down Expand Up @@ -29,8 +29,20 @@ This file is part of Universal Gcode Sender (UGS).

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.List;



public class Settings {
private static final Logger logger = Logger.getLogger(Settings.class.getName());
Expand Down Expand Up @@ -120,6 +132,11 @@ public class Settings {
*/
private boolean showTranslationsWarning = true;

/**
* The last working directory used by the file browser
*/
private String lastWorkingDirectory = System.getProperty("user.home");

/**
* The GSON deserialization doesn't do anything beyond initialize what's in the json document. Call finalizeInitialization() before using the Settings.
*/
Expand Down Expand Up @@ -556,6 +573,14 @@ public void setShowTranslationsWarning(boolean showTranslationsWarning) {
this.showTranslationsWarning = showTranslationsWarning;
}

public String getLastWorkingDirectory() {
return lastWorkingDirectory;
}

public void setLastWorkingDirectory(String lastWorkingDirectory) {
this.lastWorkingDirectory = lastWorkingDirectory;
}

public static class FileStats {
public Position minCoordinate;
public Position maxCoordinate;
Expand Down
2 changes: 2 additions & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ platform.window.serialconsole = Console
platform.window.serialconsole.tooltip = Console displaying messages to and from the controller.
platform.window.visualizer = Visualizer
platform.window.visualizer.tooltip = 3D view of the current operation.
platform.window.fileBrowser = File Browser
platform.window.fileBrowser.tooltip = Load a folder to view and work with files.
platform.visualizer.edit.options.title = Visualizer options
platform.visualizer.color.background = Background Color
platform.visualizer.tool = Show tool location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ This file is part of Universal Gcode Sender (UGS).
)
@TopComponent.Registration(
mode = Mode.LEFT_TOP,
openAtStartup = true
openAtStartup = true,
position = 100
)
@ActionID(
category = LocalizingService.LocationStatusCategory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2016-2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.core.control;

import com.willwinder.ugs.nbp.lib.Mode;
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup;
import com.willwinder.ugs.nbp.lib.services.TopComponentLocalizer;
import com.willwinder.universalgcodesender.model.BackendAPI;
import com.willwinder.ugs.nbp.core.panels.FileBrowserPanel;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.FileBrowserPanelCategory;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.FileBrowserPanelActionId;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.FileBrowserPanelWindowPath;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.FileBrowserPanelTitle;
import static com.willwinder.ugs.nbp.lib.services.LocalizingService.FileBrowserPanelTooltip;


import java.awt.BorderLayout;

import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.modules.OnStart;
import org.openide.windows.TopComponent;

/**
* Top component which displays something.
*/
@TopComponent.Description(
preferredID = "FileBrowserTopComponent"
)
@TopComponent.Registration(mode = Mode.LEFT_TOP, openAtStartup = false, position = 2200)
@ActionID(category = FileBrowserPanelCategory, id = FileBrowserPanelActionId)
@ActionReference(path = FileBrowserPanelWindowPath)
@TopComponent.OpenActionRegistration(
displayName = "<Not localized:FileBrowserTopComponent>",
preferredID = "FileBrowserTopComponent"
)
public final class FileBrowserTopComponent extends TopComponent {

public FileBrowserTopComponent() {
this.setLayout(new BorderLayout());
BackendAPI backend = CentralLookup.getDefault().lookup(BackendAPI.class);
FileBrowserPanel panel = new FileBrowserPanel(backend);
this.add(panel, BorderLayout.CENTER);
}

@Override
public void componentOpened() {
setName(FileBrowserPanelTitle);
setToolTipText(FileBrowserPanelTooltip);
}

@Override
public void componentClosed() {
// TODO add custom code on component closing
}

public void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
}

public void readProperties(java.util.Properties p) {
}

@OnStart
public static class Localizer extends TopComponentLocalizer {
public Localizer() {
super(FileBrowserPanelCategory, FileBrowserPanelActionId, FileBrowserPanelTitle);
}
}
}

0 comments on commit f06322c

Please sign in to comment.