Skip to content

Commit

Permalink
Jtree Icon per Block
Browse files Browse the repository at this point in the history
+New file option
  • Loading branch information
apocist committed Aug 9, 2014
1 parent 0541f9d commit 96aeb41
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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){
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -144,4 +149,5 @@ public String createScript(String filteronly){
public String generateScript(){
return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.inverseinnovations.VisualMALSignatureDesigner;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.io.ByteArrayInputStream;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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(){
Expand Down
Binary file added system/bgIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added system/blankIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added system/filterIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added system/imgIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added system/textIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added system/thumbIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 96aeb41

Please sign in to comment.