16 package net.squiz.matrix.ui;
18 import net.squiz.matrix.plaf.MatrixLookAndFeel;
19 import net.squiz.matrix.matrixtree.*;
20 import net.squiz.matrix.core.*;
22 import java.awt.event.*;
24 import javax.swing.border.*;
29 private JButton searchButton;
30 private JButton cancelButton;
31 private JTextField searchTerm;
32 private JLabel message;
33 private static Point prevScreenLocation = null;
35 private SearchDialog(Point locationOnScreen, Dimension treeDimension) {
36 JPanel contentPane =
new JPanel(
new BorderLayout());
37 setContentPane(contentPane);
38 contentPane.setBorder(
new EmptyBorder(1, 1, 1, 1));
40 contentPane.add(getTopPanel(Matrix.translate(
"asset_map_dialog_jump")),BorderLayout.NORTH);
42 contentPane.add(getSearcFormPanel());
44 enableDrag(contentPane);
48 public void dispose() {
49 prevScreenLocation = getPrevLoc();
62 searchDialog =
new SearchDialog(locationOnScreen, treeDimension);
67 searchDialog.toFront();
77 private JPanel getMessagePanel() {
78 JPanel messagePanel =
new JPanel();
79 message =
new JLabel(
"");
80 messagePanel.add(message);
85 private JPanel getSearcFormPanel() {
87 JPanel searchForm =
new JPanel();
88 searchForm.setBackground(MatrixLookAndFeel.PANEL_COLOUR);
91 searchTerm =
new JTextField(5);
92 searchTerm.setPreferredSize(
new Dimension(150,15));
93 searchTerm.setFont(MatrixTreeBus.getActiveTree().getFontInUse());
94 searchTerm.setOpaque(
false);
95 searchTerm.addKeyListener(
new KeyListener());
96 searchTerm.setBorder(
new LineBorder(MatrixLookAndFeel.PANEL_BORDER_COLOUR, 1) );
104 searchForm.add(searchTerm);
109 class ButtonHandler
implements ActionListener {
110 public void actionPerformed(ActionEvent evt) {
111 Object source = evt.getSource();
113 if (source == searchButton) {
115 MatrixTree tree = MatrixTreeBus.getActiveTree();
116 MatrixTreeNode[] nodes = tree.getSelectionNodes();
117 tree.loadChildAssets(nodes[0],
"",Integer.parseInt(searchTerm.getText())-1,-1);
119 }
catch (NullPointerException ex) {
120 message.setText(Matrix.translate(
"asset_map_error_invalid_node"));
121 }
catch (NumberFormatException ex) {
122 message.setText(Matrix.translate(
"asset_map_error_invalid_number"));
123 }
catch (Exception ex) {
124 Object[] transArgs = {
127 message.setText(Matrix.translate(
"asset_map_error_unknown_error", transArgs));
129 }
else if (source == cancelButton) {
135 private class KeyListener
extends KeyAdapter {
136 public void keyPressed(KeyEvent evt) {
137 if (evt.getSource() == searchTerm) {
138 if (evt.getKeyCode() == evt.VK_ENTER) {
139 MatrixTree tree = MatrixTreeBus.getActiveTree();
140 MatrixTreeNode[] nodes = tree.getSelectionNodes();
141 if (nodes[0].getAsset().getNumKids() >= (Integer.parseInt(searchTerm.getText())-1)) {
142 tree.loadChildAssets(nodes[0],
"",Integer.parseInt(searchTerm.getText())-1,-1);
145 }
else if(evt.getKeyCode() == evt.VK_ESCAPE) {