diff --git a/src/example/gui/Display.java b/src/example/gui/Display.java deleted file mode 100644 index a0e01fe42..000000000 --- a/src/example/gui/Display.java +++ /dev/null @@ -1,61 +0,0 @@ -package gui; - -import com.valkryst.VTerminal.component.VFrame; -import gui.view.View; -import lombok.Getter; -import lombok.NonNull; - -import javax.swing.*; -import java.awt.*; - -public class Display { - /** Singleton instance. */ - private final static Display INSTANCE = new Display(); - - @Getter private final JFrame frame = new VFrame(80, 40); - - /** Constructs a new Display. */ - private Display() { - frame.setBackground(Color.BLACK); - frame.setVisible(true); - frame.pack(); - frame.setLocationRelativeTo(null); // Must be called after pack() - } - - public void addView(final @NonNull View view) { - frame.add(view); - frame.revalidate(); - view.requestFocusInWindow(); - } - - public void addView(final @NonNull View view, final @NonNull Object constraints) { - frame.add(view, constraints); - frame.revalidate(); - view.requestFocusInWindow(); - } - - /** - * Removes a view from the frame. - * - * @param view The view to remove. - */ - public void removeView(final View view) { - if (view != null) { - frame.remove(view); - frame.revalidate(); - } - } - - /** - * Retrieves the singleton instance. - * - * @return The singleton instance. - */ - public static Display getInstance() { - return INSTANCE; - } - - public void setLayout(final LayoutManager layout) { - frame.setLayout(layout); - } -} diff --git a/src/example/gui/Driver.java b/src/example/gui/Driver.java deleted file mode 100644 index 299bfa53a..000000000 --- a/src/example/gui/Driver.java +++ /dev/null @@ -1,34 +0,0 @@ -package gui; - -import com.valkryst.VTerminal.palette.Palette; -import com.valkryst.VTerminal.plaf.VTerminalLookAndFeel; -import gui.controller.DefaultController; - -import javax.swing.*; -import java.io.IOException; - -public class Driver { - public static void main(final String[] args) { - SwingUtilities.invokeLater(() -> { - try { - Palette.loadAndRegisterProperties(Driver.class.getResourceAsStream("/Palettes/Dracula.properties")); - } catch (IOException e) { - e.printStackTrace(); - } - - final var laf = VTerminalLookAndFeel.getInstance(); - try { - UIManager.setLookAndFeel(laf); - } catch (UnsupportedLookAndFeelException e) { - e.printStackTrace(); - } - - final var controller = new DefaultController(); - controller.displayMainView(); - - final var frame = Display.getInstance().getFrame(); - frame.pack(); - frame.setLocationRelativeTo(null); - }); - } -} diff --git a/src/example/gui/controller/Controller.java b/src/example/gui/controller/Controller.java deleted file mode 100644 index 6a2563564..000000000 --- a/src/example/gui/controller/Controller.java +++ /dev/null @@ -1,146 +0,0 @@ -package gui.controller; - -import gui.Display; -import gui.model.Model; -import gui.view.View; -import lombok.NonNull; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -public abstract class Controller implements PropertyChangeListener { - /** The views. */ - private final List views = new ArrayList<>(); - /** The models. */ - private final List models = new ArrayList<>(); - - public void addView(final @NonNull View view) { - views.add(view); - Display.getInstance().addView(view); - } - - public void addView(final @NonNull View view, final Object constraints) { - views.add(view); - Display.getInstance().addView(view, constraints); - } - - /** - * Removes a view from the controller. - * - * @param view The view to remove. - */ - public void removeView(final View view) { - if (view != null) { - views.remove(view); - Display.getInstance().removeView(view); - } - } - - public void removeAllViews() { - final var display = Display.getInstance(); - - final var iterator = views.listIterator(); - while (iterator.hasNext()) { - display.removeView(iterator.next()); - iterator.remove(); - } - } - - /** - * Adds a model to the controller. - * - * @param model The model to add. - */ - public void addModel(final Model model) { - if (model != null) { - models.add(model); - model.addPropertyChangeListener(this); - model.fireInitialProperties(); - } - } - - /** - * Removes a model from the controller. - * - * @param model The model to remove. - */ - public void removeModel(final Model model) { - if (model != null) { - models.remove(model); - model.removePropertyChangeListener(this); - } - } - - public void removeAllModels() { - - - final var iterator = models.listIterator(); - while (iterator.hasNext()) { - iterator.next().removePropertyChangeListener(this); - iterator.remove(); - } - } - - @Override - public void propertyChange(final PropertyChangeEvent event) { - for (final var view : views) { - view.modelPropertyChange(event); - } - } - - /** - * This is a convenience method that subclasses can call upon to fire - * property changes back to the models. This method uses reflection to - * inspect each of the model classes to determine whether it's the owner of - * the property in question. - * - * @param propertyName Name of the property. - * - * @param newValue An object that represents the property's new value. - */ - protected void setModelProperty(final String propertyName, final Object newValue) { - for (final var model : models) { - try { - final var methodName = "set" + propertyName; - final var method = model.getClass().getMethod(methodName, newValue.getClass()); - - method.invoke(model, newValue); - } catch (final NoSuchMethodException e) { - /* - * We're iterating over the models, trying to find the model - * that has the 'setPropertyName' method, so this could be - * thrown a few times. - * - * Because this is intended behaviour, we display the exception - * and then ignore it. - */ - final var stackTraceElements = e.getStackTrace(); - for (final var element : stackTraceElements) { - final var className = element.getClassName(); - final var methodName = element.getMethodName(); - final var fileName = element.getFileName(); - final var lineNumber = element.getLineNumber(); - System.err.println("\tat " + className + "." + methodName + "(" + fileName + ":" + lineNumber + ")"); - } - } catch (final IllegalAccessException e) { - /* - * If we found the model with the 'setPropertyName' method, - * this can be thrown if the model is enforcing the Java - * language access control and the 'setPropertyName' method is - * inaccessible. - */ - e.printStackTrace(); - } catch (final InvocationTargetException e) { - /* - * If we found the model with the 'setPropertyName' method, this - * can be thrown if the 'setPropertyName' method throws an - * exception. - */ - e.printStackTrace(); - } - } - } -} diff --git a/src/example/gui/controller/DefaultController.java b/src/example/gui/controller/DefaultController.java deleted file mode 100644 index d136b48b6..000000000 --- a/src/example/gui/controller/DefaultController.java +++ /dev/null @@ -1,30 +0,0 @@ -package gui.controller; - -import gui.Display; -import gui.view.*; - -import java.awt.*; - -public class DefaultController extends Controller { - public void displayMainView() { - Display.getInstance().setLayout(new BorderLayout()); - - final var tabbedPaneView = new TabbedPaneView(); - this.addView(tabbedPaneView, BorderLayout.CENTER); - - tabbedPaneView.addTab("Button", new ButtonView()); - tabbedPaneView.addTab("Check Box", new CheckBoxView()); - tabbedPaneView.addTab("Editor Pane", new EditorPaneView()); - tabbedPaneView.addTab("Filtered VPanel", new FilteredPanelView()); - tabbedPaneView.addTab("Label", new LabelView()); - tabbedPaneView.addTab("Layered Pane", new LayeredPaneView()); - tabbedPaneView.addTab("Password Field", new PasswordFieldView()); - tabbedPaneView.addTab("Progress Bar", new ProgressBarView()); - tabbedPaneView.addTab("Radio Button", new RadioButtonView()); - tabbedPaneView.addTab("Scroll Pane", new ScrollPaneView()); - tabbedPaneView.addTab("Text Area", new TextAreaView()); - tabbedPaneView.addTab("Text Field", new TextFieldView()); - tabbedPaneView.addTab("Text Pane", new TextPaneView()); - tabbedPaneView.addTab("VPanel", new PanelView()); - } -} diff --git a/src/example/gui/model/Model.java b/src/example/gui/model/Model.java deleted file mode 100644 index b77987f16..000000000 --- a/src/example/gui/model/Model.java +++ /dev/null @@ -1,22 +0,0 @@ -package gui.model; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -public abstract class Model { - protected final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - - public final void addPropertyChangeListener(final PropertyChangeListener listener) { - propertyChangeSupport.addPropertyChangeListener(listener); - } - - public final void removePropertyChangeListener(final PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(listener); - } - - public final void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) { - propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - public abstract void fireInitialProperties(); -} diff --git a/src/example/gui/view/ButtonView.java b/src/example/gui/view/ButtonView.java deleted file mode 100644 index 67da5fbdb..000000000 --- a/src/example/gui/view/ButtonView.java +++ /dev/null @@ -1,20 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public class ButtonView extends View { - public ButtonView() { - var component = new JButton("[This JButton is enabled.]"); - component.setFocusable(true); - this.add(component); - - component = new JButton("[This JButton is disabled.]"); - component.setEnabled(false); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/CheckBoxView.java b/src/example/gui/view/CheckBoxView.java deleted file mode 100644 index 8db30d721..000000000 --- a/src/example/gui/view/CheckBoxView.java +++ /dev/null @@ -1,22 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public class CheckBoxView extends View { - public CheckBoxView() { - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - var component = new JCheckBox("Enabled Check Box"); - component.setFocusable(true); - this.add(component); - - component = new JCheckBox("Disabled Check Box"); - component.setEnabled(false); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/EditorPaneView.java b/src/example/gui/view/EditorPaneView.java deleted file mode 100644 index f09f50d0f..000000000 --- a/src/example/gui/view/EditorPaneView.java +++ /dev/null @@ -1,51 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VEditorPane; - -import java.awt.*; -import java.beans.PropertyChangeEvent; - -public class EditorPaneView extends View { - public EditorPaneView() { - this.setLayout(new BorderLayout()); - - var component = new VEditorPane(); - component.setContentType("text/html"); - component.setEditable(true); - component.setText("\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "

This VEditorPane is editable and enabled.

\n" + - " \n" + - "\n"); - this.add(component, BorderLayout.NORTH); - - component = new VEditorPane(); - component.setContentType("text/html"); - component.setEditable(true); - component.setEnabled(false); - component.setText("\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "

This VEditorPane is editable and disabled.

\n" + - " \n" + - "\n"); - this.add(component, BorderLayout.SOUTH); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/FilteredPanelView.java b/src/example/gui/view/FilteredPanelView.java deleted file mode 100644 index a9d2a7b56..000000000 --- a/src/example/gui/view/FilteredPanelView.java +++ /dev/null @@ -1,34 +0,0 @@ -package gui.view; - -import com.jhlabs.image.FlipFilter; -import com.jhlabs.image.GaussianFilter; -import com.valkryst.VTerminal.component.VPanel; -import com.valkryst.VTerminal.image.SequentialOp; - -import java.beans.PropertyChangeEvent; -import java.util.concurrent.ThreadLocalRandom; - -public class FilteredPanelView extends View { - public FilteredPanelView() { - final var component = new VPanel(64, 32); - - var sequentialOp = new SequentialOp( - new GaussianFilter(), - new FlipFilter(FlipFilter.FLIP_H), - new FlipFilter(FlipFilter.FLIP_V) - ); - - for (int y = 0 ; y < component.getHeightInTiles() ; y++) { - for (int x = 0 ; x < component.getWidthInTiles() ; x++) { - component.setCodePointAt(x, y, ThreadLocalRandom.current().nextInt(1000)); - component.setSequentialImageOpAt(x, y, sequentialOp); - } - } - - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/LabelView.java b/src/example/gui/view/LabelView.java deleted file mode 100644 index b6d567b8a..000000000 --- a/src/example/gui/view/LabelView.java +++ /dev/null @@ -1,19 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public class LabelView extends View { - public LabelView() { - var component = new JLabel("This JLabel is enabled."); - this.add(component); - - component = new JLabel("This JLabel is disabled."); - component.setEnabled(false); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/LayeredPaneView.java b/src/example/gui/view/LayeredPaneView.java deleted file mode 100644 index 9c772c7a8..000000000 --- a/src/example/gui/view/LayeredPaneView.java +++ /dev/null @@ -1,41 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VPanel; - -import javax.swing.*; -import java.awt.*; -import java.beans.PropertyChangeEvent; -import java.util.concurrent.ThreadLocalRandom; - -public class LayeredPaneView extends View { - public LayeredPaneView() { - final var layeredPane = new JLayeredPane(); - layeredPane.setLayout(new OverlayLayout(layeredPane)); - - var panel = new VPanel(64, 32); - panel.setBackground(new Color(0, 0, 255, 125)); - panel.setOpaque(false); - for (int y = 0 ; y < panel.getHeightInTiles() ; y++) { - for (int x = 0 ; x < panel.getWidthInTiles() ; x++) { - panel.setCodePointAt(x, y, ThreadLocalRandom.current().nextInt(255)); - } - } - layeredPane.add(panel, Integer.valueOf(0)); - - panel = new VPanel(64, 32); - panel.setBackground(new Color(255, 0, 0, 125)); - panel.setOpaque(false); - for (int y = 0 ; y < panel.getHeightInTiles() ; y++) { - for (int x = 0 ; x < panel.getWidthInTiles() ; x++) { - panel.setCodePointAt(x, y, ThreadLocalRandom.current().nextInt(255)); - } - } - layeredPane.add(panel, Integer.valueOf(1)); - - this.add(layeredPane); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/PanelView.java b/src/example/gui/view/PanelView.java deleted file mode 100644 index a8689b30b..000000000 --- a/src/example/gui/view/PanelView.java +++ /dev/null @@ -1,23 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VPanel; - -import java.beans.PropertyChangeEvent; -import java.util.concurrent.ThreadLocalRandom; - -public class PanelView extends View { - public PanelView() { - final var component = new VPanel(64, 32); - for (int y = 0 ; y < component.getHeightInTiles() ; y++) { - for (int x = 0 ; x < component.getWidthInTiles() ; x++) { - component.setCodePointAt(x, y, ThreadLocalRandom.current().nextInt(1000)); - } - } - - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/PasswordFieldView.java b/src/example/gui/view/PasswordFieldView.java deleted file mode 100644 index 14bcc8c89..000000000 --- a/src/example/gui/view/PasswordFieldView.java +++ /dev/null @@ -1,23 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VPasswordField; - -import java.beans.PropertyChangeEvent; - -public class PasswordFieldView extends View { - public PasswordFieldView() { - var component = new VPasswordField(); - component.setText("This VPasswordField is enabled."); - this.add(component); - - component = new VPasswordField(); - component.setEnabled(false); - component.setText("This VPasswordField is disabled."); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - - } -} diff --git a/src/example/gui/view/ProgressBarView.java b/src/example/gui/view/ProgressBarView.java deleted file mode 100644 index 9e60b6a59..000000000 --- a/src/example/gui/view/ProgressBarView.java +++ /dev/null @@ -1,32 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class ProgressBarView extends View { - public ProgressBarView() { - final var verticalProgressBar = new JProgressBar(SwingConstants.VERTICAL, 0, 100); - final var horizontalProgressBar = new JProgressBar(0, 100); - - this.add(verticalProgressBar); - this.add(horizontalProgressBar); - - final AtomicInteger progressValue = new AtomicInteger(0); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> { - progressValue.incrementAndGet(); - if (progressValue.incrementAndGet() > 100) { - progressValue.set(0); - } - - verticalProgressBar.setValue(progressValue.get()); - horizontalProgressBar.setValue(progressValue.get()); - }, 0, 100, TimeUnit.MILLISECONDS); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/RadioButtonView.java b/src/example/gui/view/RadioButtonView.java deleted file mode 100644 index 4acc11350..000000000 --- a/src/example/gui/view/RadioButtonView.java +++ /dev/null @@ -1,37 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public class RadioButtonView extends View { - public RadioButtonView() { - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - var radioButtonGroup = new ButtonGroup(); - var component = new JRadioButton("Enabled Radio Button A"); - component.setFocusable(true); - radioButtonGroup.add(component); - this.add(component); - - component = new JRadioButton("Enabled Radio Button B"); - component.setFocusable(true); - radioButtonGroup.add(component); - this.add(component); - - radioButtonGroup = new ButtonGroup(); - component = new JRadioButton("Disabled Radio Button A"); - component.setEnabled(false); - radioButtonGroup.add(component); - this.add(component); - - component = new JRadioButton("Disabled Radio Button B"); - component.setEnabled(false); - radioButtonGroup.add(component); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - - } -} diff --git a/src/example/gui/view/ScrollPaneView.java b/src/example/gui/view/ScrollPaneView.java deleted file mode 100644 index aada3481e..000000000 --- a/src/example/gui/view/ScrollPaneView.java +++ /dev/null @@ -1,29 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VPanel; - -import javax.swing.*; -import java.awt.*; -import java.beans.PropertyChangeEvent; -import java.util.concurrent.ThreadLocalRandom; - -public class ScrollPaneView extends View { - public ScrollPaneView() { - final var panel = new VPanel(250, 250); - for (int y = 0 ; y < panel.getHeightInTiles() ; y++) { - for (int x = 0 ; x < panel.getWidthInTiles() ; x++) { - panel.setCodePointAt(x, y, ThreadLocalRandom.current().nextInt(255)); - } - } - - final var scrollPane = new JScrollPane(); - scrollPane.setPreferredSize(new Dimension(512, 512)); - scrollPane.setViewportView(panel); - scrollPane.setFocusable(true); - this.add(scrollPane, BorderLayout.CENTER); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/TabbedPaneView.java b/src/example/gui/view/TabbedPaneView.java deleted file mode 100644 index 03ce9dba7..000000000 --- a/src/example/gui/view/TabbedPaneView.java +++ /dev/null @@ -1,21 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public class TabbedPaneView extends View { - private final JTabbedPane tabbedPane; - - public TabbedPaneView() { - tabbedPane = new JTabbedPane(); - this.add(tabbedPane); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } - - public void addTab(final String title, final View view) { - tabbedPane.addTab(title, view); - } -} diff --git a/src/example/gui/view/TextAreaView.java b/src/example/gui/view/TextAreaView.java deleted file mode 100644 index 8608a0d1d..000000000 --- a/src/example/gui/view/TextAreaView.java +++ /dev/null @@ -1,27 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VTextArea; - -import java.awt.*; -import java.beans.PropertyChangeEvent; - -public class TextAreaView extends View { - public TextAreaView() { - this.setLayout(new GridLayout(2, 1, 16, 16)); - - var component = new VTextArea(10, 32); - component.setLineWrap(true); - component.setText("This VTextArea is enabled."); - this.add(component); - - component = new VTextArea(10, 32); - component.setEnabled(false); - component.setLineWrap(true); - component.setText("This VTextArea is disabled."); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } -} diff --git a/src/example/gui/view/TextFieldView.java b/src/example/gui/view/TextFieldView.java deleted file mode 100644 index ba6c99688..000000000 --- a/src/example/gui/view/TextFieldView.java +++ /dev/null @@ -1,23 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VTextField; - -import java.beans.PropertyChangeEvent; - -public class TextFieldView extends View { - public TextFieldView() { - var component = new VTextField(); - component.setText("This VTextField is enabled."); - this.add(component); - - component = new VTextField(); - component.setEnabled(false); - component.setText("This VTextField is disabled."); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - - } -} diff --git a/src/example/gui/view/TextPaneView.java b/src/example/gui/view/TextPaneView.java deleted file mode 100644 index 1047c074b..000000000 --- a/src/example/gui/view/TextPaneView.java +++ /dev/null @@ -1,43 +0,0 @@ -package gui.view; - -import com.valkryst.VTerminal.component.VTextPane; - -import javax.swing.*; -import javax.swing.text.BadLocationException; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; -import java.awt.*; -import java.beans.PropertyChangeEvent; - -public class TextPaneView extends View { - public TextPaneView() { - var component = new VTextPane(); - component.setEditable(true); - addColoredText(component, "This VTextPane is enabled."); - this.add(component); - - component = new VTextPane(); - component.setEditable(true); - component.setEnabled(false); - addColoredText(component, "This VTextPane is disabled."); - this.add(component); - } - - @Override - public void modelPropertyChange(final PropertyChangeEvent event) { - } - - public static void addColoredText(JTextPane pane, String text) { - StyledDocument doc = pane.getStyledDocument(); - - Style style = pane.addStyle("Color Style", null); - StyleConstants.setForeground(style, (Color) UIManager.get("TextPane.foreground")); - try { - doc.insertString(doc.getLength(), text, style); - } - catch (BadLocationException e) { - e.printStackTrace(); - } - } -} diff --git a/src/example/gui/view/View.java b/src/example/gui/view/View.java deleted file mode 100644 index 9a304b1e8..000000000 --- a/src/example/gui/view/View.java +++ /dev/null @@ -1,8 +0,0 @@ -package gui.view; - -import javax.swing.*; -import java.beans.PropertyChangeEvent; - -public abstract class View extends JPanel { - public abstract void modelPropertyChange(final PropertyChangeEvent event); -}