1. Dmytro Kovalchuk
  2. cross-stitch

Commits

Dmytro Kovalchuk  committed 004fbf3 Draft

Initial quite buggy and incomplete version of menu service
Issue #CROS-7 - Develop menu service to allow declarative creation and modification of application menu

  • Participants
  • Parent commits 85253fa
  • Branches default

Comments (0)

Files changed (23)

File cross-stitch-app/pom.xml

View file
  • Ignore whitespace
       <artifactId>swing-api-impl</artifactId>
       <version>1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>viewer</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
 </project>

File cross-stitch-app/src/main/java/net/anatolich/cstitch/Application.java

View file
  • Ignore whitespace
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import javax.swing.SwingUtilities;
-import net.anatolich.cstitch.ui.editor.tools.service.ToolsConfiguration;
+import net.anatolich.cstitch.ui.MainWindow;
 
 /**
  * Application entry point
             @Override
             public void run() {
                 final Injector injector = Guice.createInjector(
-                        new UIConfiguration(),
-                        new ToolsConfiguration(),
                         new ServiceConfiguration());
                 MainWindow mainWindow = injector.getInstance(MainWindow.class);
                 mainWindow.initialize();

File cross-stitch-app/src/main/java/net/anatolich/cstitch/MainWindow.java

  • Ignore whitespace
-/*
- * Copyright 2012 anatolich.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.anatolich.cstitch;
-
-import com.google.inject.Inject;
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.*;
-import net.anatolich.cstitch.palette.api.PaletteService;
-import net.anatolich.cstitch.schema.Canvas;
-import net.anatolich.cstitch.schema.file.api.FileService;
-import net.anatolich.cstitch.ui.dialogs.CreateSchemaDialog;
-import net.anatolich.cstitch.ui.editor.JSchemaEditor;
-import net.anatolich.cstitch.ui.editor.legend.JLegendPanel;
-import net.anatolich.cstitch.ui.editor.tools.EditorTool;
-import net.anatolich.cstitch.ui.editor.tools.service.ToolsService;
-
-/**
- * Application main window.
- *
- * @author anatolich
- */
-public class MainWindow extends JFrame {
-
-    private static final String APPLICATION_NAME = "Cross-Stitch assistant";
-    private static final Dimension TOOLBAR_BUTTON_SIZE = new Dimension(42, 42);
-    private SaveSchemaAsAction saveSchemaAsAction;
-    private JSchemaEditor schemaEditor;
-    private JLegendPanel legendPanel;
-    private JMenuBar menuBar;
-    private JMenu menuFile;
-    private JMenu menuRecentlyUsedFiles;
-    private JMenuItem menuFileNew;
-    private JMenu menuTools;
-    private JToolBar toolbar;
-    private ToolsService toolsService;
-    private PaletteService paletteService;
-    private FileService ioService;
-
-    void initialize() {
-        setTitle(APPLICATION_NAME);
-        setDefaultCloseOperation(EXIT_ON_CLOSE);
-        setLayout(new BorderLayout());
-
-        schemaEditor = new JSchemaEditor();
-        schemaEditor.setToolsService(toolsService);
-
-        legendPanel = new JLegendPanel(paletteService);
-        legendPanel.setLegend(schemaEditor.getSchema().getUsedColors());
-
-        final JScrollPane schemaEditorScrollPane = new JScrollPane(schemaEditor);
-        final JScrollPane legendPanelScrollPane = new JScrollPane(legendPanel);
-
-        JSplitPane mainSplitPane = new JSplitPane(
-                JSplitPane.HORIZONTAL_SPLIT, true, schemaEditorScrollPane, legendPanelScrollPane);
-
-        final Dimension mainSplitterSize = new Dimension(
-                schemaEditor.getPreferredSize().width
-                + legendPanel.getPreferredSize().width
-                + mainSplitPane.getDividerSize() + 40,
-                schemaEditor.getPreferredSize().height + 40);
-
-        mainSplitPane.setPreferredSize(mainSplitterSize);
-        mainSplitPane.setSize(mainSplitterSize);
-        mainSplitPane.setDividerLocation(schemaEditor.getPreferredSize().width + mainSplitPane.getDividerSize());
-        mainSplitPane.setResizeWeight(1.0);
-        add(mainSplitPane, BorderLayout.CENTER);
-
-        createMenu();
-
-        schemaEditor.addPropertyChangeListener("schema", legendPanel);
-
-        pack();
-        setVisible(true);
-    }
-
-    private void createMenu() {
-        menuBar = new JMenuBar();
-        menuFile = new JMenu("File");
-        menuFile.setMnemonic('F');
-        menuFileNew = new JMenuItem(new CreateSchemaAction());
-        menuFile.add(menuFileNew);
-        menuFile.addSeparator();
-        menuFile.add(new OpenSchemaAction());
-        menuFile.add(new SaveSchemaAction());
-        saveSchemaAsAction = new SaveSchemaAsAction();
-        menuFile.add(saveSchemaAsAction);
-
-        menuFile.addSeparator();
-        menuRecentlyUsedFiles = new JMenu("Recent Files");
-        menuFile.add(menuRecentlyUsedFiles);
-        createRecentFilesMenuItems();
-        
-        menuFile.addSeparator();
-        menuFile.add(new ExitAction());
-
-        menuBar.add(menuFile);
-
-        menuTools = new JMenu("Tools");
-        menuTools.setMnemonic('T');
-
-        toolbar = new JToolBar("editorToolbar", JToolBar.VERTICAL);        
-        add(toolbar, BorderLayout.WEST);
-
-        ButtonGroup toolsMenuGroup = new ButtonGroup();
-        ButtonGroup toolsToolbarGroup = new ButtonGroup();
-
-        for (EditorTool tool : toolsService.getTools()) {
-            final AbstractAction toolAction = tool.createToolAction(schemaEditor);
-            final JRadioButtonMenuItem toolMenuItem = new JRadioButtonMenuItem(toolAction);
-            menuTools.add(toolMenuItem);
-            toolsMenuGroup.add(toolMenuItem);
-
-            final JToggleButton toolbarButton = new JToggleButton(toolAction);
-            toolbarButton.setSize(TOOLBAR_BUTTON_SIZE);
-            toolbarButton.setPreferredSize(TOOLBAR_BUTTON_SIZE);
-            toolbar.add(toolbarButton);
-            toolbarButton.setText("");
-            toolsToolbarGroup.add(toolbarButton);
-        }
-
-        menuBar.add(menuTools);
-
-        setJMenuBar(menuBar);
-    }
-
-    private class CreateSchemaAction extends AbstractAction {
-
-        public CreateSchemaAction() {
-            putValue(NAME, "New...");
-            putValue(MNEMONIC_KEY, KeyEvent.VK_N);
-            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK));
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent e) {
-            CreateSchemaDialog dialog = new CreateSchemaDialog(MainWindow.this);
-            if (dialog.showCreateSchemaDialog() == CreateSchemaDialog.Result.OK) {
-                displaySchema(dialog.getSchema());
-                ioService.newCanvasCreated();
-            }
-        }
-    }
-
-    private class OpenSchemaAction extends AbstractAction {
-
-        public OpenSchemaAction() {
-            putValue(NAME, "Open...");
-            putValue(MNEMONIC_KEY, KeyEvent.VK_O);
-            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', InputEvent.CTRL_DOWN_MASK));
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent evt) {
-            JFileChooser fileOpenDialog = new JFileChooser(ioService.getCurrentFile());
-            fileOpenDialog.setFileFilter(ioService.getFileFilter());
-            int saveDialogResult = fileOpenDialog.showOpenDialog(MainWindow.this);
-            if (saveDialogResult == JFileChooser.APPROVE_OPTION) {
-                File selectedFile = fileOpenDialog.getSelectedFile();
-                try {
-                    openFile(selectedFile);
-
-                } catch (IOException ex) {
-                    //TODO - replace with convenient error handling mechanism.
-                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-                }
-            }
-        }
-    }
-
-    private class OpenRecentFileAction extends AbstractAction {
-
-        private final File recentFile;
-
-        public OpenRecentFileAction(File recentFile) {
-            this.recentFile = recentFile;
-            putValue(NAME, recentFile.getName());
-            putValue(SHORT_DESCRIPTION, "Open file: " + recentFile.getPath());
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent arg0) {
-            try {
-                openFile(recentFile);
-            } catch (IOException ex) {
-                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-            }
-        }
-    }
-
-    private void openFile(File file) throws IOException {
-        schemaEditor.setSchema(ioService.readCanvas(file));
-    }
-
-    private class SaveSchemaAsAction extends AbstractAction {
-
-        public SaveSchemaAsAction() {
-            putValue(NAME, "Save As...");
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent evt) {
-            JFileChooser fileSaveDialog = new JFileChooser(ioService.getCurrentFile());
-            fileSaveDialog.setFileFilter(ioService.getFileFilter());
-            int saveDialogResult = fileSaveDialog.showSaveDialog(MainWindow.this);
-            if (saveDialogResult == JFileChooser.APPROVE_OPTION) {
-                File file = fileSaveDialog.getSelectedFile();
-                try {
-                    ioService.writeCanvas(schemaEditor.getSchema(), file);
-                } catch (IOException ex) {
-                    //TODO - replace with convenient error handling mechanism.
-                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-                }
-            }
-        }
-    }
-
-    private class SaveSchemaAction extends AbstractAction {
-
-        public SaveSchemaAction() {
-            putValue(NAME, "Save");
-            putValue(MNEMONIC_KEY, KeyEvent.VK_S);
-            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK));
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent evt) {
-            if (ioService.getCurrentFile() != null) {
-                try {
-                    ioService.writeCanvas(schemaEditor.getSchema(), ioService.getCurrentFile());
-                } catch (IOException ex) {
-                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-                }
-            } else {
-                saveSchemaAsAction.actionPerformed(evt);
-            }
-        }
-    }
-
-    public void displaySchema(Canvas schema) {
-        schemaEditor.setSchema(schema);
-    }
-
-    @Inject
-    public void setPaletteService(PaletteService paletteService) {
-        this.paletteService = paletteService;
-    }
-
-    @Inject
-    public void setToolsService(ToolsService toolsService) {
-        this.toolsService = toolsService;
-    }
-
-    @Inject
-    public void setIoService(FileService ioService) {
-        this.ioService = ioService;
-        ioService.addPropertyChangeListener(FileService.PROPERTY_CURRENT_FILE, new PropertyChangeListener() {
-
-            @Override
-            public void propertyChange(PropertyChangeEvent evt) {
-                File currentFile = (File) evt.getNewValue();
-                if (currentFile != null) {
-                    setTitle(APPLICATION_NAME + " - " + currentFile.getName());
-                    createRecentFilesMenuItems();
-                } else {
-                    setTitle(APPLICATION_NAME);
-                }
-            }
-        });
-    }
-
-    private void createRecentFilesMenuItems() {
-        menuRecentlyUsedFiles.removeAll();
-        for (File file : MainWindow.this.ioService.getRecentFileList()) {
-            final JMenuItem recentFileMenuItem = new JMenuItem(new OpenRecentFileAction(file));
-            menuRecentlyUsedFiles.add(recentFileMenuItem);
-        }
-    }
-
-    private class ExitAction extends AbstractAction {
-
-        public ExitAction() {
-            putValue(NAME, "Exit");
-        }
-
-        @Override
-        public void actionPerformed(ActionEvent e) {
-            MainWindow.this.dispose();
-        }
-    }
-}

File cross-stitch-app/src/main/java/net/anatolich/cstitch/UIConfiguration.java

  • Ignore whitespace
-/*
- * Copyright 2012 anatolich.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.anatolich.cstitch;
-
-import com.google.inject.AbstractModule;
-
-/**
- *
- * @author anatolich
- */
-public class UIConfiguration extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        bind(MainWindow.class);
-    }
-    
-}

File media/preview.png

  • Ignore whitespace
Added
New image

File media/preview.svg

View file
  • Ignore whitespace
Added
New image

File media/preview_16.png

  • Ignore whitespace
Added
New image

File pom.xml

View file
  • Ignore whitespace
     <module>base-palettes</module>
     <module>swing-api</module>
     <module>swing-api-impl</module>
+    <module>viewer</module>
   </modules>
 </project>

File swing-api/src/main/java/net/anatolich/cstitch/ui/MainWindow.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 anatolich.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui;
+
+import com.google.inject.Inject;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.*;
+import net.anatolich.cstitch.palette.api.PaletteService;
+import net.anatolich.cstitch.schema.Canvas;
+import net.anatolich.cstitch.schema.file.api.FileService;
+import net.anatolich.cstitch.ui.dialogs.CreateSchemaDialog;
+import net.anatolich.cstitch.ui.editor.JSchemaEditor;
+import net.anatolich.cstitch.ui.editor.legend.JLegendPanel;
+import net.anatolich.cstitch.ui.editor.tools.EditorTool;
+import net.anatolich.cstitch.ui.editor.tools.service.ToolsService;
+import net.anatolich.cstitch.ui.menu.MenuService;
+
+/**
+ * Application main window.
+ *
+ * @author anatolich
+ */
+public class MainWindow extends JFrame {
+
+    private static final String APPLICATION_NAME = "Cross-Stitch assistant";
+    private static final Dimension TOOLBAR_BUTTON_SIZE = new Dimension(42, 42);
+    private SaveSchemaAsAction saveSchemaAsAction;
+    private JSchemaEditor schemaEditor;
+    private JLegendPanel legendPanel;
+    private JToolBar toolbar;
+    private ToolsService toolsService;
+    private PaletteService paletteService;
+    private FileService ioService;
+    private MenuService menuService;
+
+    public void initialize() {
+        setTitle(APPLICATION_NAME);
+        setDefaultCloseOperation(EXIT_ON_CLOSE);
+        setLayout(new BorderLayout());
+
+        schemaEditor = new JSchemaEditor();
+        schemaEditor.setToolsService(toolsService);
+
+        legendPanel = new JLegendPanel(paletteService);
+        legendPanel.setLegend(schemaEditor.getSchema().getUsedColors());
+
+        final JScrollPane schemaEditorScrollPane = new JScrollPane(schemaEditor);
+        final JScrollPane legendPanelScrollPane = new JScrollPane(legendPanel);
+
+        JSplitPane mainSplitPane = new JSplitPane(
+                JSplitPane.HORIZONTAL_SPLIT, true, schemaEditorScrollPane, legendPanelScrollPane);
+
+        final Dimension mainSplitterSize = new Dimension(
+                schemaEditor.getPreferredSize().width
+                + legendPanel.getPreferredSize().width
+                + mainSplitPane.getDividerSize() + 40,
+                schemaEditor.getPreferredSize().height + 40);
+
+        mainSplitPane.setPreferredSize(mainSplitterSize);
+        mainSplitPane.setSize(mainSplitterSize);
+        mainSplitPane.setDividerLocation(schemaEditor.getPreferredSize().width + mainSplitPane.getDividerSize());
+        mainSplitPane.setResizeWeight(1.0);
+        add(mainSplitPane, BorderLayout.CENTER);
+
+        createMenu();
+
+        schemaEditor.addPropertyChangeListener("schema", legendPanel);
+
+        pack();
+        setVisible(true);
+    }
+
+    private void createMenu() {
+
+        menuService.registerMenu("File", "File", 0);
+        menuService.registerMenu("Tools", "Tools", 400);
+
+        menuService.registerMenuItem("File/New", new CreateSchemaAction(), 100);
+
+        menuService.registerMenuItem("File/Open", new OpenSchemaAction(), 200);
+        
+        menuService.registerMenuItem("File/Save", new SaveSchemaAction(), 300);
+
+        saveSchemaAsAction = new SaveSchemaAsAction();
+        menuService.registerMenuItem("File/SaveAs", saveSchemaAsAction, 400);
+
+        createRecentFilesMenuItems();
+
+        menuService.registerMenuItem("File/Exit", new ExitAction(), 10000);
+
+        toolbar = new JToolBar("editorToolbar", JToolBar.VERTICAL);
+        add(toolbar, BorderLayout.WEST);
+
+        ButtonGroup toolsToolbarGroup = new ButtonGroup();
+
+        int position = 0;
+        for (EditorTool tool : toolsService.getTools()) {
+            position += 100;
+            final AbstractAction toolAction = tool.createToolAction(schemaEditor);
+            menuService.registerRadioMenuItem("Tools/" + toolAction.getValue(AbstractAction.NAME), "EditorTools", toolAction, position);
+
+            final JToggleButton toolbarButton = new JToggleButton(toolAction);
+            toolbarButton.setSize(TOOLBAR_BUTTON_SIZE);
+            toolbarButton.setPreferredSize(TOOLBAR_BUTTON_SIZE);
+            toolbar.add(toolbarButton);
+            toolbarButton.setText("");
+            toolsToolbarGroup.add(toolbarButton);
+        }
+        
+        final JMenuBar menuBar = new JMenuBar();
+        
+        List<JMenu> menus = menuService.getMenus();
+        for (JMenu menu : menus) {
+            menuBar.add(menu);
+        }
+
+        setJMenuBar(menuBar);
+    }
+
+    private class CreateSchemaAction extends AbstractAction {
+
+        public CreateSchemaAction() {
+            putValue(NAME, "New...");
+            putValue(MNEMONIC_KEY, KeyEvent.VK_N);
+            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK));
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            CreateSchemaDialog dialog = new CreateSchemaDialog(MainWindow.this);
+            if (dialog.showCreateSchemaDialog() == CreateSchemaDialog.Result.OK) {
+                displaySchema(dialog.getSchema());
+                ioService.newCanvasCreated();
+            }
+        }
+    }
+
+    private class OpenSchemaAction extends AbstractAction {
+
+        public OpenSchemaAction() {
+            putValue(NAME, "Open...");
+            putValue(MNEMONIC_KEY, KeyEvent.VK_O);
+            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', InputEvent.CTRL_DOWN_MASK));
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent evt) {
+            JFileChooser fileOpenDialog = new JFileChooser(ioService.getCurrentFile());
+            fileOpenDialog.setFileFilter(ioService.getFileFilter());
+            int saveDialogResult = fileOpenDialog.showOpenDialog(MainWindow.this);
+            if (saveDialogResult == JFileChooser.APPROVE_OPTION) {
+                File selectedFile = fileOpenDialog.getSelectedFile();
+                try {
+                    openFile(selectedFile);
+
+                } catch (IOException ex) {
+                    //TODO - replace with convenient error handling mechanism.
+                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+        }
+    }
+
+    private class OpenRecentFileAction extends AbstractAction {
+
+        private final File recentFile;
+
+        public OpenRecentFileAction(File recentFile) {
+            this.recentFile = recentFile;
+            putValue(NAME, recentFile.getName());
+            putValue(SHORT_DESCRIPTION, "Open file: " + recentFile.getPath());
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent arg0) {
+            try {
+                openFile(recentFile);
+            } catch (IOException ex) {
+                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        }
+    }
+
+    private void openFile(File file) throws IOException {
+        schemaEditor.setSchema(ioService.readCanvas(file));
+    }
+
+    private class SaveSchemaAsAction extends AbstractAction {
+
+        public SaveSchemaAsAction() {
+            putValue(NAME, "Save As...");
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent evt) {
+            JFileChooser fileSaveDialog = new JFileChooser(ioService.getCurrentFile());
+            fileSaveDialog.setFileFilter(ioService.getFileFilter());
+            int saveDialogResult = fileSaveDialog.showSaveDialog(MainWindow.this);
+            if (saveDialogResult == JFileChooser.APPROVE_OPTION) {
+                File file = fileSaveDialog.getSelectedFile();
+                try {
+                    ioService.writeCanvas(schemaEditor.getSchema(), file);
+                } catch (IOException ex) {
+                    //TODO - replace with convenient error handling mechanism.
+                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }
+        }
+    }
+
+    private class SaveSchemaAction extends AbstractAction {
+
+        public SaveSchemaAction() {
+            putValue(NAME, "Save");
+            putValue(MNEMONIC_KEY, KeyEvent.VK_S);
+            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK));
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent evt) {
+            if (ioService.getCurrentFile() != null) {
+                try {
+                    ioService.writeCanvas(schemaEditor.getSchema(), ioService.getCurrentFile());
+                } catch (IOException ex) {
+                    Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            } else {
+                saveSchemaAsAction.actionPerformed(evt);
+            }
+        }
+    }
+
+    public void displaySchema(Canvas schema) {
+        schemaEditor.setSchema(schema);
+    }
+
+    @Inject
+    public void setPaletteService(PaletteService paletteService) {
+        this.paletteService = paletteService;
+    }
+
+    @Inject
+    public void setToolsService(ToolsService toolsService) {
+        this.toolsService = toolsService;
+    }
+
+    @Inject
+    public void setIoService(FileService ioService) {
+        this.ioService = ioService;
+        ioService.addPropertyChangeListener(FileService.PROPERTY_CURRENT_FILE, new PropertyChangeListener() {
+
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                File currentFile = (File) evt.getNewValue();
+                if (currentFile != null) {
+                    setTitle(APPLICATION_NAME + " - " + currentFile.getName());
+                    createRecentFilesMenuItems();
+                } else {
+                    setTitle(APPLICATION_NAME);
+                }
+            }
+        });
+    }
+
+    private void createRecentFilesMenuItems() {
+        menuService.registerMenu("File/RecentFiles", "Recent Files", 500);
+        int counter = 0;
+        for (File file : MainWindow.this.ioService.getRecentFileList()) {
+            menuService.registerMenuItem("File/RecentFiles/file" + counter, new OpenRecentFileAction(file), 500 + counter);
+            counter++;
+
+        }
+    }
+
+    private class ExitAction extends AbstractAction {
+
+        public ExitAction() {
+            putValue(NAME, "Exit");
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            MainWindow.this.dispose();
+        }
+    }
+
+    @Inject
+    public void setMenuService(MenuService menuService) {
+        this.menuService = menuService;
+    }
+}

File swing-api/src/main/java/net/anatolich/cstitch/ui/UIConfiguration.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 anatolich.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui;
+
+import com.google.inject.AbstractModule;
+import net.anatolich.cstitch.ui.editor.tools.service.ToolsConfiguration;
+import net.anatolich.cstitch.ui.menu.MenuService;
+import net.anatolich.cstitch.ui.menu.impl.MenuServiceImpl;
+
+/**
+ *
+ * @author anatolich
+ */
+public class UIConfiguration extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(MainWindow.class);
+        install(new ToolsConfiguration());
+        bind(MenuService.class).to(MenuServiceImpl.class).asEagerSingleton();
+    }
+    
+}

File swing-api/src/main/java/net/anatolich/cstitch/ui/menu/MenuService.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui.menu;
+
+import java.util.List;
+import javax.swing.AbstractAction;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+
+/**
+ * Creates application main menu.
+ * @author Anatolich <anatolich@anatolich.net>
+ * @since 1.0
+ * @version 1.0
+ */
+public interface MenuService {
+
+    /**
+     * Registers menu name in menu.
+     * @param path path to menu holding name. It should begin with top-level menu 
+     * name name. E.g. file/save_as registers save_as menu name in File menu. tools/compile/full registers 
+     * sub-name of Tools/Compile menu name.
+     * @param name name to be registered.
+     */
+    void registerMenu(String path, String name, int position);
+    
+    void registerMenuItem(String path, AbstractAction action, int position);
+    
+    void registerCheckboxMenuItem(String path, String group, AbstractAction item, int position);
+    
+    void registerRadioMenuItem(String path, String group, AbstractAction item, int position);
+    
+    /**
+     * Gets menu item associated with provided path.
+     * @param path
+     * @return menu item or null if no menu item is associated with this path.
+     */
+    <T extends JMenuItem> T getMenuItem(String path);
+
+    /**
+     * Gets list of top-level menus. Modification of returned list must not change
+     * actual list of menus.
+     * @return 
+     */
+    public List<JMenu> getMenus();
+    
+}

File swing-api/src/main/java/net/anatolich/cstitch/ui/menu/impl/MenuServiceImpl.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui.menu.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.*;
+import net.anatolich.cstitch.ui.menu.MenuService;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+public class MenuServiceImpl implements MenuService {
+
+    private final MenuTree menuTree;
+
+    public MenuServiceImpl() {
+        menuTree = new MenuTree();
+    }
+
+    @Override
+    public void registerMenu(String path, String name, int position) {
+        createNode(new JMenu(name), position, path, null);
+    }
+
+    @Override
+    public void registerMenuItem(String path, AbstractAction action, int position) {
+        createNode(new JMenuItem(action), position, path, null);
+    }
+
+    @Override
+    public void registerCheckboxMenuItem(String path, String group, AbstractAction action, int position) {
+        createNode(new JCheckBoxMenuItem(action), position, path, group);
+    }
+
+    @Override
+    public void registerRadioMenuItem(String path, String group, AbstractAction action, int position) {
+        createNode(new JRadioButtonMenuItem(action), position, path, group);
+    }
+
+    private void createNode(JMenuItem item, int position, String path, String group) {
+        MenuTreeNode node = new MenuTreeNode();
+        node.setItem(item);
+        node.setPosition(position);
+        if (group != null) {
+            node.setGroup(group);
+        }
+        menuTree.addNode(path, node);
+    }
+
+    @Override
+    public JMenuItem getMenuItem(String path) {
+        final MenuTreeNode node = menuTree.getNode(path);
+        if (node != null) {
+            return node.getItem();
+        }
+        return null;
+    }
+
+    @Override
+    public List<JMenu> getMenus() {
+        List<MenuTreeNode> menuNodes = menuTree.getRootNode().getChildren();
+
+        List<JMenu> menus = new ArrayList<>();
+        for (MenuTreeNode menuTreeNode : menuNodes) {
+            menus.add((JMenu) menuTreeNode.getItem());
+        }
+
+        return menus;
+    }
+}

File swing-api/src/main/java/net/anatolich/cstitch/ui/menu/impl/MenuTree.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui.menu.impl;
+
+import java.util.*;
+import javax.swing.ButtonGroup;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+class MenuTree {
+
+    private static final Logger log = LoggerFactory.getLogger(MenuTree.class);
+    private final MenuTreeNode root;
+    private final Map<String, ButtonGroup> groups;
+
+    public MenuTree() {
+        root = new MenuTreeNode();
+        groups = new HashMap<>();
+    }
+
+    public void addNode(String path, MenuTreeNode node) {
+        log.debug(String.format("Adding menu %1$s", path));
+        log.debug("Parsing path");
+
+        MenuTreeNode parentNode = root;
+        List<String> pathSteps = Arrays.asList(path.split("/"));
+        Iterator<String> pathIterator = pathSteps.iterator();
+        while (pathIterator.hasNext()) {
+            String step = pathIterator.next();
+
+            if (pathIterator.hasNext()) {
+                log.debug(String.format("Processing step %1$s", step));
+                MenuTreeNode stepNode = parentNode.getOrCreateChild(step);
+                parentNode = stepNode;
+            } else {
+                node.setId(step);
+                parentNode.addChild(node);
+            }
+        }
+
+    }
+
+    private JMenuItem traverseNode(MenuTreeNode node) {
+        JMenuItem menuItem = node.getItem();
+        if (node.getGroup() != null) {
+            log.debug(String.format("Adding node to group %1$s", node.getGroup()));
+            ButtonGroup group = getOrCreateGroup(node.getGroup());
+            group.add(node.getItem());
+        }
+        for (MenuTreeNode menuTreeNode : node.getChildren()) {
+            menuItem.add(traverseNode(menuTreeNode));
+        }
+        return menuItem;
+    }
+
+    private ButtonGroup getOrCreateGroup(String groupName) {
+        ButtonGroup group = groups.get(groupName);
+        if (group == null) {
+            log.debug(String.format("Creating group %1$s", groupName));
+            group = new ButtonGroup();
+            groups.put(groupName, group);
+        }
+        return group;
+    }
+
+    MenuTreeNode getRootNode() {
+        return root;
+    }
+
+    MenuTreeNode getNode(String path) {
+        MenuTreeNode parentNode = root;
+        List<String> pathSteps = Arrays.asList(path.split("/"));
+        Iterator<String> pathIterator = pathSteps.iterator();
+
+        while (pathIterator.hasNext()) {
+            String step = pathIterator.next();
+            MenuTreeNode stepNode = parentNode.getChild(step);
+            if(stepNode == null){
+                return null;
+            }
+            parentNode = stepNode;
+        }
+        
+        return parentNode;
+    }
+}

File swing-api/src/main/java/net/anatolich/cstitch/ui/menu/impl/MenuTreeNode.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui.menu.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+class MenuTreeNode implements Comparable<MenuTreeNode> {
+
+    private static final Logger log = LoggerFactory.getLogger(MenuTreeNode.class);
+    private JMenuItem item;
+    private MenuTreeNode parent;
+    private List<MenuTreeNode> children;
+    private int position;
+    private String path;
+    private String id;
+    private String group;
+
+    public MenuTreeNode() {
+        children = new ArrayList<>();
+    }
+
+    public List<MenuTreeNode> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<MenuTreeNode> children) {
+        this.children = children;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public JMenuItem getItem() {
+        return item;
+    }
+
+    public void setItem(JMenuItem item) {
+        this.item = item;
+    }
+
+    public MenuTreeNode getParent() {
+        return parent;
+    }
+
+    public void setParent(MenuTreeNode parent) {
+        this.parent = parent;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public int getPosition() {
+        return position;
+    }
+
+    public void setPosition(int position) {
+        this.position = position;
+    }
+
+    public String getGroup() {
+        return group;
+    }
+
+    public void setGroup(String group) {
+        this.group = group;
+    }
+
+    /**
+     * Gets named child of current node.
+     *
+     * @param id
+     * @return instance of MenuTreeNode or null if no item exists.
+     */
+    public MenuTreeNode getChild(String id) {
+        for (MenuTreeNode menuTreeNode : children) {
+            if (menuTreeNode.getId().equals(id)) {
+                return menuTreeNode;
+            }
+        }
+        return null;
+    }
+
+    public MenuTreeNode getOrCreateChild(String id) {
+        log.debug(String.format("Searching for node %1$s", id));
+        
+        MenuTreeNode child = getChild(id);
+        if (child != null) {
+            return child;
+        }
+
+        log.debug("Node not found. Creating new one");
+        MenuTreeNode newChildNode = new MenuTreeNode();
+        newChildNode.setId(id);
+        newChildNode.setParent(this);
+        newChildNode.setItem(new JMenu(id));
+        children.add(newChildNode);
+        return newChildNode;
+    }
+
+    void addChild(MenuTreeNode node) {
+        log.debug(String.format("Adding new child %1$s", node));
+        MenuTreeNode child = getOrCreateChild(node.id);
+        
+        child.setId(node.getId());
+        child.setItem(node.getItem());
+        child.setGroup(node.getGroup());
+        child.setPosition(node.getPosition());
+        child.setChildren(new ArrayList<MenuTreeNode>());
+        Collections.sort(children);
+        
+        if(item != null){
+            item.add(node.getItem());
+        }
+        
+    }
+
+    @Override
+    public String toString() {
+        return "MenuTreeNode{" + "item=" + item + ", parent=" + parent + ", children=" + children + ", position=" + position + ", path=" + path + ", id=" + id + '}';
+    }
+
+    @Override
+    public int compareTo(MenuTreeNode o) {
+        final int comparation = position - o.position;
+        if (comparation == 0) {
+            return id.compareTo(o.id);
+        }
+        return comparation;
+    }
+}

File swing-api/src/main/resources/META-INF/services/com.google.inject.Module

View file
  • Ignore whitespace
+net.anatolich.cstitch.ui.UIConfiguration

File swing-api/src/test/java/net/anatolich/cstitch/ui/menu/impl/MenuServiceImplTest.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.ui.menu.impl;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+public class MenuServiceImplTest {
+
+    private MenuServiceImpl menuManagerImpl;
+
+    @Before
+    public void setUp() {
+        menuManagerImpl = new MenuServiceImpl();
+    }
+
+    @Test
+    public void testAddRootItem() {
+        String path = "File";
+        int position = 0;
+        final String itemTitle = "File";
+        
+        menuManagerImpl.registerMenu(path, itemTitle, position);
+        
+        JMenuItem fileMenu = menuManagerImpl.getMenuItem(path);
+        assertEquals(itemTitle, fileMenu.getText());
+    }
+    
+    @Test
+    public void testAddFileSaveItem(){
+        final String path = "File/Save";
+        final int position = 400;
+        final String itemTitle = "Save";
+        
+        AbstractAction saveAction = new EmptyAction(itemTitle);
+        
+        menuManagerImpl.registerMenuItem(path, saveAction, position);
+        
+        JMenuItem fileMenu = menuManagerImpl.getMenuItem("File");
+        
+        assertEquals("File", fileMenu.getText());
+        
+        JMenuItem fileSaveItem = menuManagerImpl.getMenuItem(path);
+        
+        assertEquals(itemTitle, fileSaveItem.getText());
+    }
+    
+    @Test
+    public void testAddTwoItems(){
+        menuManagerImpl.registerMenuItem("A1/A1", new EmptyAction("A1"), 0);
+        menuManagerImpl.registerMenuItem("A2/A2", new EmptyAction("A2"), 0);
+        
+        assertEquals(2, menuManagerImpl.getMenus().size());
+        
+        assertEquals("A1", menuManagerImpl.getMenuItem("A1/A1").getText());
+        assertEquals("A2", menuManagerImpl.getMenuItem("A2/A2").getText());
+    }
+    
+    @Test
+    public void testAddThreeItems(){
+        menuManagerImpl.registerMenuItem("A1/A1", new EmptyAction("A1A1"), 10);
+        menuManagerImpl.registerMenuItem("A2/A2", new EmptyAction("A2A2"), 20);
+        menuManagerImpl.registerMenuItem("A2/A1", new EmptyAction("A2A1"), 10);
+        
+        assertEquals(2, menuManagerImpl.getMenus().size());
+        
+        final JMenu menuA1 = (JMenu) menuManagerImpl.getMenuItem("A1");
+        final JMenu menuA2 = (JMenu) menuManagerImpl.getMenuItem("A2");
+        
+        assertEquals("A1", menuA1.getText());
+        assertEquals("A2", menuA2.getText());
+        
+        final JMenuItem a1a1 = menuManagerImpl.getMenuItem("A1/A1");        
+        assertEquals("A1A1", a1a1.getText());
+        
+        final JMenuItem a2a1 = menuManagerImpl.getMenuItem("A2/A1");        
+        assertEquals("A2A1", a2a1.getText());
+        
+        final JMenuItem a2a2 = menuManagerImpl.getMenuItem("A2/A2");
+        assertEquals("A2A2", a2a2.getText());
+        
+    }
+    
+    @Test
+    public void testAddThreeRadioItems(){
+        menuManagerImpl.registerRadioMenuItem("A1/A1", "A1G", new EmptyAction("A1A1"), 10);
+        menuManagerImpl.registerRadioMenuItem("A2/A2", "A2G", new EmptyAction("A2A2"), 20);
+        menuManagerImpl.registerRadioMenuItem("A2/A1", "A2G", new EmptyAction("A2A1"), 10);
+        
+        assertEquals(2, menuManagerImpl.getMenus().size());
+        
+        final JMenu menuA1 = (JMenu) menuManagerImpl.getMenuItem("A1");
+        final JMenu menuA2 = (JMenu) menuManagerImpl.getMenuItem("A2");
+        
+        assertEquals("A1", menuA1.getText());
+        assertEquals("A2", menuA2.getText());
+        
+        final JMenuItem a1a1 = menuManagerImpl.getMenuItem("A1/A1");        
+        assertEquals("A1A1", a1a1.getText());
+        
+        final JMenuItem a2a1 = menuManagerImpl.getMenuItem("A2/A1");        
+        assertEquals("A2A1", a2a1.getText());
+        
+        final JMenuItem a2a2 = menuManagerImpl.getMenuItem("A2/A2");
+        assertEquals("A2A2", a2a2.getText());
+        
+    }
+    
+    @Test
+    public void testGetMenuItem(){
+        menuManagerImpl.registerMenuItem("A1/A1", new EmptyAction("A1A1"), 10);
+        
+        final JMenuItem a1 = menuManagerImpl.getMenuItem("A1");
+        
+        assertNotNull(a1);
+        assertTrue(a1 instanceof JMenu);
+        assertEquals("A1", a1.getText());
+        
+        final JMenuItem a1a1 = menuManagerImpl.getMenuItem("A1/A1");
+        assertNotNull(a1a1);
+        assertEquals("A1A1", a1a1.getText());
+        
+        assertNull(menuManagerImpl.getMenuItem("A1/A1/A1"));
+        
+    }
+
+    private class EmptyAction extends AbstractAction {
+
+        public EmptyAction(String name) {
+            super(name);
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            // DO NOTHING
+        }
+    }
+}

File viewer/pom.xml

View file
  • Ignore whitespace
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>net.anatolich.cstitch</groupId>
+    <artifactId>cross-stitch</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <groupId>net.anatolich.cstitch</groupId>
+  <artifactId>viewer</artifactId>
+  <name>viewer</name>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+      <version>3.0</version>
+      <type>jar</type>
+    </dependency>
+    <dependency>
+      <groupId>net.anatolich.cstitch</groupId>
+      <artifactId>swing-api</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <type>jar</type>
+    </dependency>
+  </dependencies>
+</project>

File viewer/src/main/java/net/anatolich/cstitch/viewer/ModuleConfiguration.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.viewer;
+
+import com.google.inject.AbstractModule;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+public class ModuleConfiguration extends AbstractModule{
+
+    @Override
+    protected void configure() {
+        bind(ToolsInjector.class).asEagerSingleton();
+    }
+    
+}

File viewer/src/main/java/net/anatolich/cstitch/viewer/ToolsInjector.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.viewer;
+
+import com.google.inject.Inject;
+import net.anatolich.cstitch.ui.editor.tools.service.ToolsService;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+public class ToolsInjector {
+    
+    @Inject
+    public ToolsInjector(ToolsService service){
+        service.registerTool(new ViewerTool());
+    }
+}

File viewer/src/main/java/net/anatolich/cstitch/viewer/ViewerTool.java

View file
  • Ignore whitespace
+/*
+ * Copyright 2012 Anatolich <anatolich@anatolich.net>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.anatolich.cstitch.viewer;
+
+import javax.swing.ImageIcon;
+import net.anatolich.cstitch.ui.editor.tools.AbstractSwingTool;
+
+/**
+ *
+ * @author Anatolich <anatolich@anatolich.net>
+ */
+class ViewerTool extends AbstractSwingTool {
+
+    public ViewerTool() {
+    }
+
+    @Override
+    public String getName() {
+        return "Viewer";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Opens schema in stitching mode";
+    }
+
+    @Override
+    protected ImageIcon getIcon() {
+        return new ImageIcon(getClass().getResource("/net/anatolich/cstitch/viewer/icons/view.png"));
+    }
+
+    @Override
+    protected ImageIcon getSmallIcon() {
+        return new ImageIcon(getClass().getResource("/net/anatolich/cstitch/viewer/icons/view_16.png"));
+    }
+    
+}

File viewer/src/main/resources/META-INF/services/com.google.inject.Module

View file
  • Ignore whitespace
+net.anatolich.cstitch.viewer.ModuleConfiguration

File viewer/src/main/resources/net/anatolich/cstitch/viewer/icons/view.png

  • Ignore whitespace
Added
New image

File viewer/src/main/resources/net/anatolich/cstitch/viewer/icons/view_16.png

  • Ignore whitespace
Added
New image