From eab6df10ab8292a59a05b25d18c413dd107bb94a Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Thu, 26 Apr 2018 05:48:09 -0700 Subject: Initial commit --- src/bjc/imgchain/ImgChain.java | 337 ++++++++++++++++++++++++++--------------- 1 file changed, 211 insertions(+), 126 deletions(-) (limited to 'src/bjc/imgchain/ImgChain.java') diff --git a/src/bjc/imgchain/ImgChain.java b/src/bjc/imgchain/ImgChain.java index f90ae78..e4e32cc 100644 --- a/src/bjc/imgchain/ImgChain.java +++ b/src/bjc/imgchain/ImgChain.java @@ -1,126 +1,211 @@ -package bjc.imgchain; - -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.JDesktopPane; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; - -public class ImgChain { - private final class LoadImageListener implements ActionListener { - @Override - public void actionPerformed(ActionEvent ev) { - JFileChooser jfc = new JFileChooser(); - jfc.setMultiSelectionEnabled(true); - - int res = jfc.showOpenDialog(desktop); - - if (res != JFileChooser.APPROVE_OPTION) { - return; - } - - for (File fle : jfc.getSelectedFiles()) { - ImgViewer view = new ImgViewer(ImgChain.this, fle); - - if (view.isInitialized()) { - desktop.add(view); - view.setVisible(true); - } - } - } - } - - private JDesktopPane desktop; - - private Map imageRepo; - - public static void main(String[] args) { - System.out.println("ImgChain Loading..."); - - ImgChain chn = new ImgChain(); - - chn.setupGUI(); - } - - public ImgChain() { - imageRepo = new HashMap<>(); - } - - private void setupGUI() { - JFrame frame = new JFrame("ImgChain v1"); - frame.setLayout(new GridLayout(1, 1)); - - desktop = new JDesktopPane(); - - JMenuBar menu = setupMenubar(frame); - - frame.setJMenuBar(menu); - - frame.add(desktop); - - frame.setSize(640, 480); - - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - frame.setVisible(true); - } - - private JMenuBar setupMenubar(JFrame frame) { - JMenuBar menu = new JMenuBar(); - - JMenu fileMenu = new JMenu("File"); - fileMenu.setMnemonic('F'); - - JMenuItem aboutItem = new JMenuItem("About"); - aboutItem.setMnemonic('A'); - aboutItem.addActionListener((ev) -> { - JOptionPane.showMessageDialog(frame, "ImgChain v1\nDeveloped by Benjamin Culkin", - "About ImgChain", JOptionPane.INFORMATION_MESSAGE); - }); - - JMenuItem closeItem = new JMenuItem("Close"); - closeItem.setMnemonic('C'); - closeItem.addActionListener((ev) -> { - frame.dispose(); - }); - - fileMenu.add(aboutItem); - fileMenu.addSeparator(); - fileMenu.add(closeItem); - - JMenu imageMenu = new JMenu("Images"); - imageMenu.setMnemonic('I'); - - JMenuItem loadImage = new JMenuItem("Load Images..."); - loadImage.setMnemonic('L'); - loadImage.addActionListener(new LoadImageListener()); - - imageMenu.add(loadImage); - - menu.add(fileMenu); - menu.add(imageMenu); - return menu; - } - - public void addImage(String name, Image img) { - if (imageRepo.containsKey(name)) { - String msg = String.format("Are you sure you want to overwrite stored image '%s'?", name); - - if (JOptionPane.showInternalConfirmDialog(desktop, msg) != JOptionPane.OK_OPTION) { - return; - } - } - - imageRepo.put(name, img); - } -} +package bjc.imgchain; + +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JDesktopPane; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; + +import bjc.imgchain.pipeline.Pipeline; + +/** + * Main class for ImgChain + * + * @author acm + * + */ +public class ImgChain { + /* + * Action to perform when loading an image. + */ + private final class LoadImageListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent ev) { + JFileChooser jfc = new JFileChooser(); + jfc.setMultiSelectionEnabled(true); + + int res = jfc.showOpenDialog(desktop); + + if (res != JFileChooser.APPROVE_OPTION) { + return; + } + + for (File fle : jfc.getSelectedFiles()) { + ImgViewer view = new ImgViewer(ImgChain.this, fle); + + if (view.isInitialized()) { + desktop.add(view); + view.setVisible(true); + } + } + } + } + + /** + * The desktop everything is attached to. + */ + public JDesktopPane desktop; + + /* + * The storage for images. + */ + public final Map imageRepo; + + /* + * The storage for images. + */ + public final Map pipelineRepo; + + /** + * The image chain instance. + */ + public static ImgChain chan; + + /** + * Main method + * + * @param args + * Unused CLI args + */ + public static void main(String[] args) { + System.out.println("ImgChain Loading..."); + + chan = new ImgChain(); + + chan.setupGUI(); + } + + /** + * Initialize image repo + */ + public ImgChain() { + imageRepo = new HashMap<>(); + pipelineRepo = new HashMap<>(); + } + + /* + * Setup the GUI + */ + private void setupGUI() { + JFrame frame = new JFrame("ImgChain v1"); + frame.setLayout(new GridLayout(1, 1)); + + desktop = new JDesktopPane(); + + JMenuBar menu = setupMenubar(frame); + + frame.setJMenuBar(menu); + + frame.add(desktop); + + frame.setSize(640, 480); + + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + frame.setVisible(true); + } + + /* + * Setup the menubar. + */ + private JMenuBar setupMenubar(JFrame frame) { + JMenuBar menu = new JMenuBar(); + + JMenu fileMenu = new JMenu("File"); + fileMenu.setMnemonic('F'); + + JMenuItem aboutItem = new JMenuItem("About"); + aboutItem.setMnemonic('A'); + aboutItem.addActionListener((ev) -> { + JOptionPane.showMessageDialog(frame, "ImgChain v2\nDeveloped by Benjamin Culkin", + "About ImgChain", JOptionPane.INFORMATION_MESSAGE); + }); + + JMenuItem closeItem = new JMenuItem("Close"); + closeItem.setMnemonic('C'); + closeItem.addActionListener((ev) -> { + frame.dispose(); + }); + + fileMenu.add(aboutItem); + fileMenu.addSeparator(); + fileMenu.add(closeItem); + + JMenu imageMenu = new JMenu("Images"); + imageMenu.setMnemonic('I'); + + JMenuItem loadImage = new JMenuItem("Load Images..."); + loadImage.setMnemonic('L'); + loadImage.addActionListener(new LoadImageListener()); + + imageMenu.add(loadImage); + + JMenu pipelineMenu = new JMenu("Pipelines"); + JMenuItem createPipe = new JMenuItem("Create Pipeline"); + createPipe.setMnemonic('C'); + createPipe.addActionListener((ev) -> { + ImgPipeline pip = new ImgPipeline(); + + desktop.add(pip); + pip.setVisible(true); + }); + + pipelineMenu.add(createPipe); + + menu.add(fileMenu); + menu.add(imageMenu); + menu.add(pipelineMenu); + + return menu; + } + + /** + * Add an image to the image repository. + * + * @param name + * The name of the image + * @param img + * The image to add. + */ + public void addImage(String name, Image img) { + if (imageRepo.containsKey(name)) { + String msg = String.format("Are you sure you want to overwrite stored image '%s'?", name); + + if (JOptionPane.showInternalConfirmDialog(desktop, msg) != JOptionPane.OK_OPTION) { + return; + } + } + + imageRepo.put(name, img); + } + + /** + * Add an pipeline to the pipeline repository. + * + * @param pipe + * The pipeline to add. + */ + public void addPipe(Pipeline pipe) { + String name = pipe.name(); + + if (pipelineRepo.containsKey(name)) { + String msg = String.format("Are you sure you want to overwrite stored pipeline '%s'?", name); + + if (JOptionPane.showInternalConfirmDialog(desktop, msg) != JOptionPane.OK_OPTION) { + return; + } + } + + pipelineRepo.put(name, pipe); + } +} -- cgit v1.2.3