Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DeleteDialog.java
1 
16 package net.squiz.matrix.ui;
17 
18 import net.squiz.matrix.matrixtree.*;
19 import net.squiz.matrix.core.*;
20 import net.squiz.matrix.plaf.MatrixLookAndFeel;
21 
22 import java.util.*;
23 import java.io.IOException;
24 import net.squiz.matrix.debug.*;
25 import javax.swing.*;
26 import javax.swing.border.*;
27 
28 import java.awt.BorderLayout;
29 import java.awt.event.*;
30 import java.awt.FontMetrics;
31 import java.awt.*;
32 
39 public class DeleteDialog extends MatrixDialog
40  implements MatrixConstants, KeyListener {
41 
42  private JButton deleteBtn;
43  private JButton cancelBtn;
44  private MatrixTreeNode[] nodes;
45  private static Point prevScreenLocation = null;
46 
47  private DeleteDialog(MatrixTreeNode[] nodes) {
48  this.nodes = nodes;
49  JPanel contentPane = new JPanel(new BorderLayout());
50  setContentPane(contentPane);
51 
52  Border border = new EmptyBorder(1, 1, 1, 1);
53  contentPane.setBorder(border);
54 
55  JPanel midPanel = new JPanel();
56  midPanel.setBackground(MatrixLookAndFeel.PANEL_COLOUR);
57 
58  JLabel label;
59  // MM: what if nodes.length == 0 ? or nodes == null ?
60  if (nodes.length == 1) {
61  Object[] transArgs = {
62  new String(nodes[0].getName())
63  };
64  label = new JLabel(Matrix.translate("asset_map_confirm_move_child", transArgs));
65  } else {
66  Object[] transArgs = {
67  new Integer(nodes.length)
68  };
69  label = new JLabel(Matrix.translate("asset_map_confirm_move_children", transArgs));
70  }
71 
72  label.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
73  midPanel.add(label);
74 
75  contentPane.add(getTopPanel(Matrix.translate("asset_map_dialog_delete")), BorderLayout.NORTH);
76  contentPane.add(midPanel, BorderLayout.CENTER);
77  enableDrag(contentPane);
78 
79  JPanel bottomPanel = new JPanel();
80  final JLabel deleteButton = new JLabel();
81  deleteButton.setIcon(GUIUtilities.getAssetMapIcon("ok.png"));
82 
83  // mouse events
84  deleteButton.addMouseListener(new MouseAdapter(){
85  public void mouseClicked(MouseEvent e){
86  setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
87  delete();
88  dispose();
89  }
90 
91  public void mouseExited(MouseEvent e) {
92  deleteButton.setIcon(GUIUtilities.getAssetMapIcon("ok.png"));
93  setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
94  }
95 
96  public void mouseEntered(MouseEvent e) {
97  deleteButton.setIcon(GUIUtilities.getAssetMapIcon("ok_on.png"));
98  setCursor(new Cursor(Cursor.HAND_CURSOR));
99  }
100  });
101 
102  deleteButton.setOpaque(false);
103  bottomPanel.add(deleteButton);
104 
105  JLabel cancelButton = new JLabel();
106  cancelButton.setIcon(GUIUtilities.getAssetMapIcon("cancel.png"));
107 
108  closeOnClick(cancelButton, "cancel");
109  bottomPanel.add(cancelButton);
110 
111  bottomPanel.setBackground(MatrixLookAndFeel.PANEL_COLOUR);
112 
113  contentPane.add(bottomPanel, BorderLayout.SOUTH);
114 
115 
116  contentPane.setBackground(MatrixLookAndFeel.PANEL_BORDER_COLOUR);
117 
118  FontMetrics fm = getFontMetrics(label.getFont());
119  int textWidth = fm.stringWidth(label.getText());
120  setSize(textWidth + 32, 125);
121  addKeyListener(this);
122 
123  }
124 
125  public void dispose() {
126  prevScreenLocation = getPrevLoc();
127  super.dispose();
128  }
129 
130 
131  private void btn_pressed(ActionEvent evt) {
132  delete();
133  dispose();
134  }
135 
136  public void keyTyped(KeyEvent evt) {
137  }
138 
139  public void keyPressed(KeyEvent evt) {
140  if(evt.getKeyCode() == evt.VK_ENTER || evt.getKeyCode() == evt.VK_SPACE) {
141  delete();
142  dispose();
143  } else if(evt.getKeyCode() == evt.VK_ESCAPE) {
144  dispose();
145  }
146  }
147 
148  public void keyReleased(KeyEvent evt) {
149  }
150 
151 
152  private void delete() {
153  // there can only be on trash folder in the system.
154  String[] assetids = AssetManager.getAssetsOfType("trash_folder");
155  Asset trash = AssetManager.getAsset(assetids[0]);
156  Iterator nodes = trash.getTreeNodes();
157  MatrixTreeNode trashNode = null;
158  while (nodes.hasNext()) {
159  trashNode = (MatrixTreeNode) nodes.next();
160  }
161  MatrixTreeComm.createLink(NewLinkEvent.LINK_TYPE_MOVE, DeleteDialog.this.nodes, trashNode, 0, 0, null);
162  }
163 
170  public static DeleteDialog getDeleteDialog(MatrixTreeNode[] nodes, Point locationOnScreen, Dimension treeDimension) {
171  DeleteDialog deleteDialog = null;
172  if (!MatrixDialog.hasDialog(DeleteDialog.class)) {
173  deleteDialog = new DeleteDialog(nodes);
174  MatrixDialog.putDialog(deleteDialog);
175  } else {
176  // bring the selection dialog to the front
177  deleteDialog = (DeleteDialog) MatrixDialog.getDialog(DeleteDialog.class);
178  deleteDialog.toFront();
179  }
180 
181  deleteDialog.pack();
182  deleteDialog.centerDialogOnTree(locationOnScreen, treeDimension, prevScreenLocation);
183 
184  return deleteDialog;
185  }
186 
187 }//end class DeleteDialog