diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BlockWindow.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BlockWindow.java index 0d4688b..9c2284e 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BlockWindow.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BlockWindow.java @@ -22,7 +22,6 @@ import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; -import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -68,7 +67,17 @@ public void run(){ JMenu menu = new JMenu("File");//Build the first menu. //a group of JMenuItems - JMenuItem menuItem = new JMenuItem("Open"); + JMenuItem menuItem = new JMenuItem("New"); + menuItem.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + int dialogResult = JOptionPane.showConfirmDialog (null, "Clear the current Signature? (Might not be saved)","Warning",JOptionPane.YES_NO_OPTION); + if(dialogResult == JOptionPane.YES_OPTION){ + blocks.clear(); + } + } + }); + menu.add(menuItem); + menuItem = new JMenuItem("Open"); menuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ final JFileChooser fc = new JFileChooser(System.getProperty("user.dir")); @@ -97,7 +106,6 @@ public void actionPerformed(ActionEvent e){ } }); menu.add(menuItem); - //a group of JMenuItems menuItem = new JMenuItem("Save"); menuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ @@ -116,20 +124,23 @@ public void actionPerformed(ActionEvent e){ BuildingBlock block = blocks.getRootNode(); if(file.exists()){ if(file.canWrite()){ - try { - Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block)); - JOptionPane.showMessageDialog(blockFrame, "Saved"); - } catch (IOException e1) {JOptionPane.showMessageDialog(blockFrame, "ERROR: Cannot save file!");} - }else{JOptionPane.showMessageDialog(blockFrame, "File is not rewritable");} + int dialogResult = JOptionPane.showConfirmDialog (null, "Overwrite the existing file?","Warning",JOptionPane.YES_NO_OPTION); + if(dialogResult == JOptionPane.YES_OPTION){ + try { + Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block)); + JOptionPane.showMessageDialog(null, "Saved"); + } catch (IOException e1) {JOptionPane.showMessageDialog(null, "ERROR: Cannot save file!");} + } + }else{JOptionPane.showMessageDialog(null, "File is not rewritable");} } else{ try { Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block)); - JOptionPane.showMessageDialog(blockFrame, "Saved"); + JOptionPane.showMessageDialog(null, "Signature Saved"); } catch (IOException e1) {JOptionPane.showMessageDialog(blockFrame, "ERROR: Cannot save file!");} } } - }else{JOptionPane.showMessageDialog(blockFrame, "Dir is not writable");} + }else{JOptionPane.showMessageDialog(null, "Dir is not writable");} } }); menu.add(menuItem); @@ -281,8 +292,11 @@ public void actionPerformed(ActionEvent e){ public void actionPerformed(ActionEvent e){ if(blocks.getCurrentNode() != null){ if(blocks.getCurrentNode() != blocks.getRootNode()){ - confirmDeleteBlockDialog(); - Main.ImageWindow.update(); + int dialogResult = JOptionPane.showConfirmDialog (null, "Delete the selected Block?","Warning",JOptionPane.YES_NO_OPTION); + if(dialogResult == JOptionPane.YES_OPTION){ + blocks.removeCurrentNode(); + Main.ImageWindow.update(); + } } } } @@ -429,50 +443,4 @@ public void actionPerformed(ActionEvent e){ return d; } - /** - * Creates JDialog confirming to delete the currently selected Block - * @return the JDialog window - */ - public JDialog confirmDeleteBlockDialog(){ - final JDialog d = new JDialog(blockFrame, "Delete Block", true); - - JPanel textPane = new JPanel(); - textPane.setLayout(new BoxLayout(textPane, BoxLayout.PAGE_AXIS)); - textPane.add(Box.createRigidArea(new Dimension(0,5))); - textPane.add(new JLabel("Are you sure you wish to Delete this Block?")); - textPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); - - JButton deleteButton = new JButton("Delete"); - deleteButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - d.dispose(); - blocks.removeCurrentNode(); - } - }); - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - d.dispose(); - } - }); - - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); - buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3)); - buttonPane.add(Box.createHorizontalGlue()); - buttonPane.add(deleteButton); - buttonPane.add(Box.createRigidArea(new Dimension(25, 0))); - buttonPane.add(cancelButton); - buttonPane.add(Box.createHorizontalGlue()); - - Container contentPane = d.getContentPane(); - contentPane.add(textPane, BorderLayout.CENTER); - contentPane.add(buttonPane, BorderLayout.PAGE_END); - - d.pack(); - d.setLocationRelativeTo(blockFrame); - d.setVisible(true); - return d; - } - } diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddBackground.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddBackground.java index da17185..5bb66e1 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddBackground.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddBackground.java @@ -12,6 +12,8 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JDialog; @@ -45,6 +47,10 @@ public void setRgb(String rgb) { this.rgb = rgb; } @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/bgIcon.png"); + } + @Override public JDialog settingsDialog(Frame owner){ final String oldname = getName(); final String oldrgb = getRgb(); diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddEmptyImage.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddEmptyImage.java index 5d11c8c..4ed4a54 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddEmptyImage.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddEmptyImage.java @@ -6,6 +6,8 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; @@ -49,6 +51,10 @@ public void setSizeY(int sizeY) { this.sizeY = sizeY; } @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/blankIcon.png"); + } + @Override protected JPanel settingsImage(final JDialog owner){ //locations diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddImage.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddImage.java index 1dadb86..ee7c39e 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddImage.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddImage.java @@ -14,6 +14,7 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; @@ -56,7 +57,10 @@ public String getFilename() { public void setFilename(String filename) { this.filename = filename; } - + @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/imgIcon.png"); + } protected JPanel settingsImage(final JDialog owner){ //Image diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddText.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddText.java index b04262b..3e4759e 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddText.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddText.java @@ -17,6 +17,8 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JComboBox; @@ -113,6 +115,10 @@ public void setAlign(String align) { public void setAngdeg(int angdeg) { this.angdeg = angdeg; } + @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/textIcon.png"); + } protected JPanel settingsText(){ JLabel textLab = new JLabel("Text:"); final JTextField textField = new JTextField();textField.setText(getText()); diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddThumbnail.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddThumbnail.java index 4a2e84b..7a079bc 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddThumbnail.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddThumbnail.java @@ -7,6 +7,7 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JDialog; @@ -35,7 +36,10 @@ public int getId() { public void setId(int id) { this.id = id; } - + @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/thumbIcon.png"); + } @Override protected JPanel settingsImage(final JDialog owner){ diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/BuildingBlock.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/BuildingBlock.java index d5d5e98..f623fbc 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/BuildingBlock.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/BuildingBlock.java @@ -2,6 +2,8 @@ import java.awt.Frame; import java.awt.image.BufferedImage; + +import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.tree.DefaultMutableTreeNode; @@ -82,6 +84,9 @@ public void setName(String name) { public String toString(){ return getName(); } + public Icon getIcon() { + return null; + } public JDialog settingsDialog(Frame owner){ return new JDialog(owner, "Null", true); } @@ -144,4 +149,5 @@ public String createScript(String filteronly){ public String generateScript(){ return ""; } + } diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/Filter/Filter.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/Filter/Filter.java index f9e59c0..9bb77e3 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/Filter/Filter.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/Filter/Filter.java @@ -2,6 +2,8 @@ import java.awt.image.BufferedImage; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.tree.DefaultMutableTreeNode; import com.inverseinnovations.VisualMALSignatureDesigner.Main; @@ -17,7 +19,10 @@ public Filter(String name,Main Main){ public boolean isFilter(){ return true; } - + @Override + public Icon getIcon() { + return new ImageIcon(System.getProperty("user.dir") + "/system/filterIcon.png"); + } @Override public BufferedImage display(BufferedImage image){ image = generateImage(image); diff --git a/src/com/inverseinnovations/VisualMALSignatureDesigner/DynamicTree.java b/src/com/inverseinnovations/VisualMALSignatureDesigner/DynamicTree.java index f67907d..4db4435 100644 --- a/src/com/inverseinnovations/VisualMALSignatureDesigner/DynamicTree.java +++ b/src/com/inverseinnovations/VisualMALSignatureDesigner/DynamicTree.java @@ -1,5 +1,6 @@ package com.inverseinnovations.VisualMALSignatureDesigner; +import java.awt.Component; import java.awt.GridLayout; import java.awt.Toolkit; import java.io.ByteArrayInputStream; @@ -17,6 +18,7 @@ import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreePath; @@ -67,6 +69,19 @@ public DynamicTree(Main Main) { tree = new JTree(treeModel); tree.setEditable(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + //tree.setCellRenderer(renderer);//TODO + tree.setCellRenderer(new DefaultTreeCellRenderer() { + private static final long serialVersionUID = 1L; + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) { + Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused); + if(value instanceof BuildingBlock){ + setIcon(((BuildingBlock)value).getIcon()); + } + return c; + } + }); + tree.setShowsRootHandles(true); JScrollPane scrollPane = new JScrollPane(tree); @@ -75,8 +90,7 @@ public DynamicTree(Main Main) { /** Remove all nodes except the root node. */ public void clear() { - rootNode.removeAllChildren(); - treeModel.reload(); + setRootNode(new InitSignature(Main)); } public BuildingBlock getRootNode(){ diff --git a/system/bgIcon.png b/system/bgIcon.png new file mode 100644 index 0000000..9fdee84 Binary files /dev/null and b/system/bgIcon.png differ diff --git a/system/blankIcon.png b/system/blankIcon.png new file mode 100644 index 0000000..2c81d64 Binary files /dev/null and b/system/blankIcon.png differ diff --git a/system/filterIcon.png b/system/filterIcon.png new file mode 100644 index 0000000..a6273e5 Binary files /dev/null and b/system/filterIcon.png differ diff --git a/system/imgIcon.png b/system/imgIcon.png new file mode 100644 index 0000000..f3d7e2a Binary files /dev/null and b/system/imgIcon.png differ diff --git a/system/textIcon.png b/system/textIcon.png new file mode 100644 index 0000000..cd99550 Binary files /dev/null and b/system/textIcon.png differ diff --git a/system/thumbIcon.png b/system/thumbIcon.png new file mode 100644 index 0000000..6f8ef33 Binary files /dev/null and b/system/thumbIcon.png differ