Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/snap/games/DevConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* A class to provide developer controls to a GameController.
*/
public class DevConsole extends ViewController {
public class DevConsole extends DefaultViewController {

// The GameController
private GameController _gameController;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/games/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* The controller class for a GameView.
*/
public class GameController extends ViewController {
public class GameController extends DefaultViewController {

// The frame rate
private double _frameRate = 30;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/styler/FontPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* A panel to help users pick a font by preview.
*/
public class FontPicker extends ViewController {
public class FontPicker extends DefaultViewController {

// The DialogBox when running
private DialogBox _dbox;
Expand Down
3 changes: 2 additions & 1 deletion src/snap/styler/StylerOwner.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package snap.styler;
import snap.view.DefaultViewController;
import snap.view.ViewController;

/**
* A simple subclass of view controller to work with a Styler.
*/
public class StylerOwner extends ViewController {
public class StylerOwner extends DefaultViewController {

// The Styler
private Styler _styler;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/util/ActivityMonitorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void handleMonitorPropChange(PropChange propChange)
/**
* This view controller class shows UI for ActivityMonitorPanel.
*/
private class ActivityMonitorPanelViewOwner extends ViewController {
private class ActivityMonitorPanelViewOwner extends DefaultViewController {

// The dialog box
private DialogBox _dialogBox;
Expand Down
63 changes: 63 additions & 0 deletions src/snap/view/DefaultViewController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package snap.view;

/**
* An implementation of ViewController that has all abstract methods implemented with a standard default. To use this
* class properly, the class methods must be overridden methods to use this class.
*/
public class DefaultViewController extends SimpleViewController {

/**
* Constructor.
*/
public DefaultViewController() {super();}

/**
* Constructor with given View for UI.
*/
public DefaultViewController(View aView) {super(aView);}

/**
* Initializes the UI panel. This method provides the ability to alter any settings or components of the View that
* were not set by {@link #createUI()}.
* <br><br>
* This method is called automatically by SnapKit after the view has been initialized, and does not need to be
* called inside of an implementation.
* <br><br>
* Implementation note: It is not always necessary to implement this method, especially if the {@code createUI()}
* method was written by hand. It provides a way to add more initialization logic when the class has been loaded
* from a .snp file. By default, this method has no implementation.
*/
@Override
protected void initUI() {

}

/**
* Called automatically by SnapKit after a user reacts with a UI component, this method allows the resetting of
* the UI. It will not cause accidental {@code respondUI(ViewEvent)} calls. It allows the user to reset or change
* aspects of the UI after an interaction, such as might be required for an animation or image draw.
* <br> <br>
* This method is overridable with no default implementation.
*/
@Override
protected void resetUI() {

}

/**
* Called automatically by SnapKit when it detects a ViewEvent. This method should be overridden to respond to UI
* controls, and provide feedback to user interactions.
* <br>
* If you are coming from a Swing environment, this class serves the same purposes as the action listeners attached
* to each individual component. In this case, all of the events are funnelled into the same method, making it
* easier to keep track of interactions. Everything is managed from the same location.
* <br> <br>
* This method is overridable with no default implementation.
*
* @param anEvent
*/
@Override
protected void respondUI(ViewEvent anEvent) {

}
}
32 changes: 32 additions & 0 deletions src/snap/view/SimpleViewController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package snap.view;

/**
* A simple implementation of ViewController that has most functionality already implemented. This implementation will
* load the UI from a .snp file named the same as this class, located in the resources dir of the jar package. The UI
* can be managed by implementing the {@link #initUI()} method, and referencing the names of components inside of that
* loaded View. To add events or feedback to elements of the UI, implement the {@link #respondUI(ViewEvent)} method and
* add your logic there.
* <br>
* All abstract methods of this class can be implemented or left empty depending on your needs.
*/
public abstract class SimpleViewController extends ViewController {

/**
* Constructor.
*/
public SimpleViewController() {super();}
/**
* Constructor with given View for UI.
*/
public SimpleViewController(View aView) {super(aView);}

/**
* Creates the top level view for this controller by loading the UI from a .snp file in the 'resources' directory.
* The .snp file loaded must share the same name as this class.
* <br><br>
* This method is called automatically by SnapKit, and does not need to be called inside an implementation.
*/
@Override
protected View createUI() { return UILoader.loadViewForController(this); }

}
75 changes: 65 additions & 10 deletions src/snap/view/ViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,39 @@
import snap.util.*;

/**
* A base controller class that manages a UI View (usually loaded from a snp UI file).
* A base controller class that manages a UI View.
* <br><br>
* A standard ViewController works around five simple methods:
* <ol>
* <li>{@link #createUI()}</li>
* <li>{@link #initUI()}</li>
* <li>{@link #resetUI()}</li>
* <li>{@link #respondUI(ViewEvent)}</li>
* </ol>
* <br>
* <b>createUI()</b><br>
* Called by SnapKit when the View is initialized, this method is responsible for the creation of the view, and all of
* its components. The view can be created by hand, or loaded from a .snp file through the use of
* {@link UILoader#loadViewForController(ViewController)}.
* <br><br>
* <b>initUI()</b><br>
* Similar to {@code createUI()}, this method is also called during initialization, after {@code createUI()} has been
* run. This method is responsible for any additional initialization that needs to take place after the view has been
* created, such as setting settings.
* <br><br>
* <b>resetUI()</b><br>
* resetUI() is called automatically by SnapKit whenever the user reacts with any UI component, but will not cause
* accidental {@code respondUI(ViewEvent)} calls. It allows the user to reset or change aspects of the UI after an
* interaction, such as might be required for an animation or image draw.
* <br><br>
* <b>respondUI(ViewEvent)</b><br>
* Called automatically by SnapKit whenever a ViewEvent/user event has been detected. Use this method to provide
* interactions and feedback to buttons and other user tools. In Swing, the listeners are attached to individual
* components, but in SnapKit all of the controls are provided in a single place, allowing pieces to be swapped in
* and out as necessary.
* <br><br>
*/
public class ViewController extends PropObject {
public abstract class ViewController extends PropObject {

// The UI View
private View _ui;
Expand Down Expand Up @@ -124,14 +154,30 @@ public synchronized View getUI()
public <T extends View> T getUI(Class <T> aClass) { return aClass.cast(getUI()); }

/**
* Creates the top level view for this controller.
* Creates the top level view for this controller.
* <br><br>
* This method is called automatically by SnapKit at initialization, and does not need to be called inside an
* implementation.
* <br><br>
* Implementation Note: This is where all components and members of the view should be composed and initialized.
* This can be done by hand, or through use of the {@link UILoader#loadViewForController(ViewController)} loader
* method.
* @see UILoader#loadViewForController(ViewController)
*/
protected View createUI() { return UILoader.loadViewForController(this); }
abstract protected View createUI();

/**
* Initializes the UI panel.
* Initializes the UI panel. This method provides the ability to alter any settings or components of the View that
* were not set by {@link #createUI()}.
* <br><br>
* This method is called automatically by SnapKit after the view has been initialized, and does not need to be
* called inside of an implementation.
* <br><br>
* Implementation note: It is not always necessary to implement this method, especially if the {@code createUI()}
* method was written by hand. It provides a way to add more initialization logic when the class has been loaded
* from a .snp file.
*/
protected void initUI() { }
abstract protected void initUI();

/**
* Returns the first focus UI view for when window/dialog is made visible.
Expand Down Expand Up @@ -468,14 +514,23 @@ public ToggleGroup getToggleGroup(String aName)
}

/**
* Reset UI controls.
* Called automatically by SnapKit after a user reacts with a UI component, this method allows the resetting of
* the UI. It will not cause accidental {@code respondUI(ViewEvent)} calls. It allows the user to reset or change
* aspects of the UI after an interaction, such as might be required for an animation or image draw.
* <br> <br>
* This method is overridable with no default implementation.
*/
protected void resetUI() { }
abstract protected void resetUI();

/**
* Respond to UI controls.
* Called automatically by SnapKit when it detects a ViewEvent. This method should be overridden to respond to UI
* controls, and provide feedback to user interactions.
* <br>
* If you are coming from a Swing environment, this class serves the same purposes as the action listeners attached
* to each individual component. In this case, all of the events are funnelled into the same method, making it
* easier to keep track of interactions. Everything is managed from the same location.
*/
protected void respondUI(ViewEvent anEvent) { }
abstract protected void respondUI(ViewEvent anEvent);

/**
* Resets UI later.
Expand Down
7 changes: 6 additions & 1 deletion src/snap/view/ViewOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

/**
* Temporary support for legacy ViewOwner.
* @deprecated see {@link ViewController} for the new naming, or {@link DefaultViewController} for the new
* implementation.
* @see ViewController
* @see DefaultViewController
*/
public class ViewOwner extends ViewController {
@Deprecated(since="2026.03")
public class ViewOwner extends DefaultViewController {

}
2 changes: 1 addition & 1 deletion src/snap/view/ViewUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static void setShowFrameRate(boolean aValue)
_frameRateLabel.setMargin(10, 10, 10, 20);
_frameRateLabel.setPrefSize(100, 32);
_frameRateLabel.setFont(new Font("Arial", 24));
ViewController frameRateOwner = new ViewController(_frameRateLabel);
ViewController frameRateOwner = new DefaultViewController(_frameRateLabel);
frameRateOwner.getWindow().setType(WindowView.Type.UTILITY);
frameRateOwner.getWindow().setAlwaysOnTop(true);
frameRateOwner.setWindowVisible(true);
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/ColorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* This class provides UI for selecting a color.
*/
public class ColorPanel extends ViewController {
public class ColorPanel extends DefaultViewController {

// The currently selected color
private Color _color = Color.BLACK;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DefaultConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* This class is a real implementation of Console.
*/
public class DefaultConsole extends ViewController implements Console {
public class DefaultConsole extends DefaultViewController implements Console {

// The Console view
private ColView _consoleView;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* A view to allow inspection of View hierarchy.
*/
public class DevPane extends ViewController {
public class DevPane extends DefaultViewController {

// The RootView
private RootView _rootView;
Expand Down
8 changes: 3 additions & 5 deletions src/snap/viewx/DevPaneConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import snap.text.TextStyle;
import snap.util.Convert;
import snap.util.KeyChain;
import snap.view.BoxView;
import snap.view.ScrollView;
import snap.view.View;
import snap.view.ViewController;
import snap.view.*;

import java.io.PrintStream;

/**
* A DevPane to show the console.
*/
public class DevPaneConsole extends ViewController {
public class DevPaneConsole extends DefaultViewController {

// The ConsoleView
private static ConsoleTextArea _consoleTextArea;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPaneExceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* A DevPane to show the console.
*/
public class DevPaneExceptions extends ViewController {
public class DevPaneExceptions extends DefaultViewController {

// The selected index
private int _selIndex = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPaneFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A DevPane tab for inspecting Graphics.
*/
public class DevPaneFiles extends ViewController {
public class DevPaneFiles extends DefaultViewController {

// The root URL string
private String _rootUrlString;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPaneGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* A DevPane tab for inspecting Graphics.
*/
public class DevPaneGraphics extends ViewController {
public class DevPaneGraphics extends DefaultViewController {

// The DevPane
private DevPane _devPane;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPaneViewOwners.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* A DevPane tab for inspecting the view tree.
*/
public class DevPaneViewOwners extends ViewController {
public class DevPaneViewOwners extends DefaultViewController {

// The DevPane
private DevPane _devPane;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/DevPaneViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* A DevPane tab for inspecting the view tree.
*/
public class DevPaneViews extends ViewController {
public class DevPaneViews extends DefaultViewController {

// The DevPane
private DevPane _devPane;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/ExceptionReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* er.setInfo("MyApp Version X, Build Date: " + MyUtils.getBuildDate());
* Thread.setDefaultUncaughtExceptionHandler(er);
*/
public class ExceptionReporter extends ViewController implements Thread.UncaughtExceptionHandler {
public class ExceptionReporter extends DefaultViewController implements Thread.UncaughtExceptionHandler {

// Backtrace text
private String _backtraceText;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/FilePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* A class to select a file to open or save.
*/
public class FilePanel extends ViewController {
public class FilePanel extends DefaultViewController {

// Whether choosing file for save
private boolean _saving;
Expand Down
2 changes: 1 addition & 1 deletion src/snap/viewx/FormBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* A class to build a form.
*/
public class FormBuilder extends ViewController {
public class FormBuilder extends DefaultViewController {

// The root pane
protected ColView _formView;
Expand Down
Loading