Skip to content

Commit 96aeb41

Browse files
committed
Jtree Icon per Block
+New file option
1 parent 0541f9d commit 96aeb41

File tree

15 files changed

+82
-63
lines changed

15 files changed

+82
-63
lines changed

src/com/inverseinnovations/VisualMALSignatureDesigner/BlockWindow.java

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import javax.swing.JDialog;
2323
import javax.swing.JFileChooser;
2424
import javax.swing.JFrame;
25-
import javax.swing.JLabel;
2625
import javax.swing.JList;
2726
import javax.swing.JMenu;
2827
import javax.swing.JMenuBar;
@@ -68,7 +67,17 @@ public void run(){
6867
JMenu menu = new JMenu("File");//Build the first menu.
6968

7069
//a group of JMenuItems
71-
JMenuItem menuItem = new JMenuItem("Open");
70+
JMenuItem menuItem = new JMenuItem("New");
71+
menuItem.addActionListener(new ActionListener(){
72+
public void actionPerformed(ActionEvent e){
73+
int dialogResult = JOptionPane.showConfirmDialog (null, "Clear the current Signature? (Might not be saved)","Warning",JOptionPane.YES_NO_OPTION);
74+
if(dialogResult == JOptionPane.YES_OPTION){
75+
blocks.clear();
76+
}
77+
}
78+
});
79+
menu.add(menuItem);
80+
menuItem = new JMenuItem("Open");
7281
menuItem.addActionListener(new ActionListener(){
7382
public void actionPerformed(ActionEvent e){
7483
final JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
@@ -97,7 +106,6 @@ public void actionPerformed(ActionEvent e){
97106
}
98107
});
99108
menu.add(menuItem);
100-
//a group of JMenuItems
101109
menuItem = new JMenuItem("Save");
102110
menuItem.addActionListener(new ActionListener(){
103111
public void actionPerformed(ActionEvent e){
@@ -116,20 +124,23 @@ public void actionPerformed(ActionEvent e){
116124
BuildingBlock block = blocks.getRootNode();
117125
if(file.exists()){
118126
if(file.canWrite()){
119-
try {
120-
Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block));
121-
JOptionPane.showMessageDialog(blockFrame, "Saved");
122-
} catch (IOException e1) {JOptionPane.showMessageDialog(blockFrame, "ERROR: Cannot save file!");}
123-
}else{JOptionPane.showMessageDialog(blockFrame, "File is not rewritable");}
127+
int dialogResult = JOptionPane.showConfirmDialog (null, "Overwrite the existing file?","Warning",JOptionPane.YES_NO_OPTION);
128+
if(dialogResult == JOptionPane.YES_OPTION){
129+
try {
130+
Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block));
131+
JOptionPane.showMessageDialog(null, "Saved");
132+
} catch (IOException e1) {JOptionPane.showMessageDialog(null, "ERROR: Cannot save file!");}
133+
}
134+
}else{JOptionPane.showMessageDialog(null, "File is not rewritable");}
124135
}
125136
else{
126137
try {
127138
Files.write(Paths.get(file.getPath()), blocks.nodeToBytes(block));
128-
JOptionPane.showMessageDialog(blockFrame, "Saved");
139+
JOptionPane.showMessageDialog(null, "Signature Saved");
129140
} catch (IOException e1) {JOptionPane.showMessageDialog(blockFrame, "ERROR: Cannot save file!");}
130141
}
131142
}
132-
}else{JOptionPane.showMessageDialog(blockFrame, "Dir is not writable");}
143+
}else{JOptionPane.showMessageDialog(null, "Dir is not writable");}
133144
}
134145
});
135146
menu.add(menuItem);
@@ -281,8 +292,11 @@ public void actionPerformed(ActionEvent e){
281292
public void actionPerformed(ActionEvent e){
282293
if(blocks.getCurrentNode() != null){
283294
if(blocks.getCurrentNode() != blocks.getRootNode()){
284-
confirmDeleteBlockDialog();
285-
Main.ImageWindow.update();
295+
int dialogResult = JOptionPane.showConfirmDialog (null, "Delete the selected Block?","Warning",JOptionPane.YES_NO_OPTION);
296+
if(dialogResult == JOptionPane.YES_OPTION){
297+
blocks.removeCurrentNode();
298+
Main.ImageWindow.update();
299+
}
286300
}
287301
}
288302
}
@@ -429,50 +443,4 @@ public void actionPerformed(ActionEvent e){
429443
return d;
430444
}
431445

432-
/**
433-
* Creates JDialog confirming to delete the currently selected Block
434-
* @return the JDialog window
435-
*/
436-
public JDialog confirmDeleteBlockDialog(){
437-
final JDialog d = new JDialog(blockFrame, "Delete Block", true);
438-
439-
JPanel textPane = new JPanel();
440-
textPane.setLayout(new BoxLayout(textPane, BoxLayout.PAGE_AXIS));
441-
textPane.add(Box.createRigidArea(new Dimension(0,5)));
442-
textPane.add(new JLabel("Are you sure you wish to Delete this Block?"));
443-
textPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
444-
445-
JButton deleteButton = new JButton("Delete");
446-
deleteButton.addActionListener(new ActionListener(){
447-
public void actionPerformed(ActionEvent e){
448-
d.dispose();
449-
blocks.removeCurrentNode();
450-
}
451-
});
452-
JButton cancelButton = new JButton("Cancel");
453-
cancelButton.addActionListener(new ActionListener(){
454-
public void actionPerformed(ActionEvent e){
455-
d.dispose();
456-
}
457-
});
458-
459-
JPanel buttonPane = new JPanel();
460-
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
461-
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 3, 3, 3));
462-
buttonPane.add(Box.createHorizontalGlue());
463-
buttonPane.add(deleteButton);
464-
buttonPane.add(Box.createRigidArea(new Dimension(25, 0)));
465-
buttonPane.add(cancelButton);
466-
buttonPane.add(Box.createHorizontalGlue());
467-
468-
Container contentPane = d.getContentPane();
469-
contentPane.add(textPane, BorderLayout.CENTER);
470-
contentPane.add(buttonPane, BorderLayout.PAGE_END);
471-
472-
d.pack();
473-
d.setLocationRelativeTo(blockFrame);
474-
d.setVisible(true);
475-
return d;
476-
}
477-
478446
}

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddBackground.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import javax.swing.BorderFactory;
1313
import javax.swing.Box;
1414
import javax.swing.BoxLayout;
15+
import javax.swing.Icon;
16+
import javax.swing.ImageIcon;
1517
import javax.swing.JButton;
1618
import javax.swing.JColorChooser;
1719
import javax.swing.JDialog;
@@ -45,6 +47,10 @@ public void setRgb(String rgb) {
4547
this.rgb = rgb;
4648
}
4749
@Override
50+
public Icon getIcon() {
51+
return new ImageIcon(System.getProperty("user.dir") + "/system/bgIcon.png");
52+
}
53+
@Override
4854
public JDialog settingsDialog(Frame owner){
4955
final String oldname = getName();
5056
final String oldrgb = getRgb();

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddEmptyImage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import javax.swing.BorderFactory;
77
import javax.swing.Box;
88
import javax.swing.BoxLayout;
9+
import javax.swing.Icon;
10+
import javax.swing.ImageIcon;
911
import javax.swing.JDialog;
1012
import javax.swing.JLabel;
1113
import javax.swing.JPanel;
@@ -49,6 +51,10 @@ public void setSizeY(int sizeY) {
4951
this.sizeY = sizeY;
5052
}
5153
@Override
54+
public Icon getIcon() {
55+
return new ImageIcon(System.getProperty("user.dir") + "/system/blankIcon.png");
56+
}
57+
@Override
5258
protected JPanel settingsImage(final JDialog owner){
5359

5460
//locations

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddImage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.swing.BorderFactory;
1515
import javax.swing.Box;
1616
import javax.swing.BoxLayout;
17+
import javax.swing.Icon;
1718
import javax.swing.ImageIcon;
1819
import javax.swing.JButton;
1920
import javax.swing.JDialog;
@@ -56,7 +57,10 @@ public String getFilename() {
5657
public void setFilename(String filename) {
5758
this.filename = filename;
5859
}
59-
60+
@Override
61+
public Icon getIcon() {
62+
return new ImageIcon(System.getProperty("user.dir") + "/system/imgIcon.png");
63+
}
6064
protected JPanel settingsImage(final JDialog owner){
6165

6266
//Image

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddText.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import javax.swing.BorderFactory;
1818
import javax.swing.Box;
1919
import javax.swing.BoxLayout;
20+
import javax.swing.Icon;
21+
import javax.swing.ImageIcon;
2022
import javax.swing.JButton;
2123
import javax.swing.JColorChooser;
2224
import javax.swing.JComboBox;
@@ -113,6 +115,10 @@ public void setAlign(String align) {
113115
public void setAngdeg(int angdeg) {
114116
this.angdeg = angdeg;
115117
}
118+
@Override
119+
public Icon getIcon() {
120+
return new ImageIcon(System.getProperty("user.dir") + "/system/textIcon.png");
121+
}
116122
protected JPanel settingsText(){
117123
JLabel textLab = new JLabel("Text:");
118124
final JTextField textField = new JTextField();textField.setText(getText());

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/AddThumbnail.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.swing.BorderFactory;
88
import javax.swing.Box;
99
import javax.swing.BoxLayout;
10+
import javax.swing.Icon;
1011
import javax.swing.ImageIcon;
1112
import javax.swing.JComboBox;
1213
import javax.swing.JDialog;
@@ -35,7 +36,10 @@ public int getId() {
3536
public void setId(int id) {
3637
this.id = id;
3738
}
38-
39+
@Override
40+
public Icon getIcon() {
41+
return new ImageIcon(System.getProperty("user.dir") + "/system/thumbIcon.png");
42+
}
3943
@Override
4044
protected JPanel settingsImage(final JDialog owner){
4145

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/BuildingBlock.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.awt.Frame;
44
import java.awt.image.BufferedImage;
5+
6+
import javax.swing.Icon;
57
import javax.swing.JDialog;
68
import javax.swing.tree.DefaultMutableTreeNode;
79

@@ -82,6 +84,9 @@ public void setName(String name) {
8284
public String toString(){
8385
return getName();
8486
}
87+
public Icon getIcon() {
88+
return null;
89+
}
8590
public JDialog settingsDialog(Frame owner){
8691
return new JDialog(owner, "Null", true);
8792
}
@@ -144,4 +149,5 @@ public String createScript(String filteronly){
144149
public String generateScript(){
145150
return "";
146151
}
152+
147153
}

src/com/inverseinnovations/VisualMALSignatureDesigner/BuildingBlock/Filter/Filter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.awt.image.BufferedImage;
44

5+
import javax.swing.Icon;
6+
import javax.swing.ImageIcon;
57
import javax.swing.tree.DefaultMutableTreeNode;
68

79
import com.inverseinnovations.VisualMALSignatureDesigner.Main;
@@ -17,7 +19,10 @@ public Filter(String name,Main Main){
1719
public boolean isFilter(){
1820
return true;
1921
}
20-
22+
@Override
23+
public Icon getIcon() {
24+
return new ImageIcon(System.getProperty("user.dir") + "/system/filterIcon.png");
25+
}
2126
@Override
2227
public BufferedImage display(BufferedImage image){
2328
image = generateImage(image);

src/com/inverseinnovations/VisualMALSignatureDesigner/DynamicTree.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.inverseinnovations.VisualMALSignatureDesigner;
22

3+
import java.awt.Component;
34
import java.awt.GridLayout;
45
import java.awt.Toolkit;
56
import java.io.ByteArrayInputStream;
@@ -17,6 +18,7 @@
1718
import javax.swing.event.TreeModelEvent;
1819
import javax.swing.event.TreeModelListener;
1920
import javax.swing.tree.DefaultMutableTreeNode;
21+
import javax.swing.tree.DefaultTreeCellRenderer;
2022
import javax.swing.tree.DefaultTreeModel;
2123
import javax.swing.tree.MutableTreeNode;
2224
import javax.swing.tree.TreePath;
@@ -67,6 +69,19 @@ public DynamicTree(Main Main) {
6769
tree = new JTree(treeModel);
6870
tree.setEditable(true);
6971
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
72+
//tree.setCellRenderer(renderer);//TODO
73+
tree.setCellRenderer(new DefaultTreeCellRenderer() {
74+
private static final long serialVersionUID = 1L;
75+
@Override
76+
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
77+
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
78+
if(value instanceof BuildingBlock){
79+
setIcon(((BuildingBlock)value).getIcon());
80+
}
81+
return c;
82+
}
83+
});
84+
7085
tree.setShowsRootHandles(true);
7186

7287
JScrollPane scrollPane = new JScrollPane(tree);
@@ -75,8 +90,7 @@ public DynamicTree(Main Main) {
7590

7691
/** Remove all nodes except the root node. */
7792
public void clear() {
78-
rootNode.removeAllChildren();
79-
treeModel.reload();
93+
setRootNode(new InitSignature(Main));
8094
}
8195

8296
public BuildingBlock getRootNode(){

system/bgIcon.png

2.99 KB
Loading

0 commit comments

Comments
 (0)