1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
package miage.jtreeindex;
import entagged.tageditor.ProgressDialog;
import entagged.tageditor.TagEditorFrame;
import entagged.tageditor.listeners.NavigatorListener;
import entagged.tageditor.resources.LangageManager;
import entagged.tageditor.resources.ResourcesRepository;
import java.io.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.color.ColorSpace;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
/**
* @author Waldo2188 & titof & tsou
*
*/
public class MainWindow extends JPanel {
private static final long serialVersionUID = 1L;
private JTree myTree;
public DefaultTreeModel MyDefaultTree;
private JButton jButtonIndex = null;
private JButton jButtonDesindex = null;
private JLabel jLabelGerer = null;
private TagEditorFrame TagEdit = null;
private PersonnalTreeCellRenderer myRenderer = new PersonnalTreeCellRenderer();
public MainWindow(){
//initialisation des composants
initComponent("C:"+File.separatorChar);
}
public MainWindow(File selectedRoot) {
String root = selectedRoot.getAbsolutePath();
initComponent(root);
}
public MainWindow(String root) {
initComponent(root);
}
public MainWindow(File selectedRoot,TagEditorFrame Tag) {
String root = selectedRoot.getAbsolutePath();
TagEdit = Tag;
initComponent(root);
}
public MainWindow(String root, TagEditorFrame Tag) {
TagEdit = Tag;
initComponent(root);
}
private void initComponent(String selectedRoot) {
//System.out.println(selectedRoot);
//arrete l'application java lon quite la fentre, mais le thread lanc continu son office
//Instanciation de la Class Jtree
//On passe en paramtre un Model
//MyTreeModel est une classe qui hrite de DefaultTreeModel
//File[] _roots=File.listRoots();
//System.out.println(_roots[0].toString());
//TagEditorFrame t = new TagEditorFrame();
MyDefaultTree = new MyTreeModel(new MyFile(selectedRoot));
JLabel j= new JLabel(LangageManager.getProperty("miage.diskexplorer")+selectedRoot.toString()) ;
myTree = new JTree(MyDefaultTree);
// Application de l'afficheur l'arbre.
myTree.setCellRenderer(myRenderer);
myTree.setShowsRootHandles(true);
//Ajout de l'arboressenece lorsqu'un rpertoire est ouvert
myTree.addTreeExpansionListener(new myExpensionListener());
//Slection d'une feuille
myTree.addTreeSelectionListener(new myTreeSelectionListener());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 1, 1, 1);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.weighty = 1;
GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.insets = new Insets(0, 1, 1, 1);
gbc2.gridx = 1;
gbc2.gridy = 1;
gbc2.gridwidth = 1;
gbc2.anchor = GridBagConstraints.CENTER;
gbc2.fill = GridBagConstraints.BOTH;
gbc2.weightx = 1;
gbc2.weighty = 1;
//Instanciation de La Class JScrollPanne afin de pouvoir bnficier des ascenceurs.
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(myTree);
scrollPane.add(new JLabel("hhh"));
scrollPane.setMinimumSize(new Dimension(600, 200));
jLabelGerer = new JLabel();
jLabelGerer.setText(LangageManager.getProperty("miage.stockfoldersoptimum"));
//jLabelGerer.setSize(400, 400);
jLabelGerer.setHorizontalAlignment(SwingConstants.CENTER);
JPanel Jp1 = new JPanel();
Jp1.setLayout(new BorderLayout());
Jp1.add(j, BorderLayout.NORTH);
JPanel Jp = new JPanel();
Jp.setLayout(new BorderLayout());
Jp.add(getJButtonIndex(), BorderLayout.NORTH);
Jp.add(getJButtonDesindex(),BorderLayout.SOUTH);
Jp.add(jLabelGerer, BorderLayout.CENTER);
//Jp.setMinimumSize(new Dimension(200,200));
//Jp.setBackground(Color.red);
setLayout(new GridBagLayout());
add(scrollPane, gbc);
add(Jp1);
add(Jp, gbc2);
setBorder(new EmptyBorder(3, 5, 5, 3));
setSize(600,400);
setVisible(true);
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
public static void main(String[] args) {
//instanciation de la fentre
new MainWindow();
}
public JTree getMyTree() {
return myTree;
}
public void setMyTree(JTree myTree) {
this.myTree = myTree;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButtonIndex() {
if (jButtonIndex == null) {
jButtonIndex = new JButton();
jButtonIndex.setText(LangageManager.getProperty("miage.index"));
jButtonIndex.setIcon( ResourcesRepository.getImageIcon("index.gif"));
jButtonIndex.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
final ProgressDialog progressDialog = new ProgressDialog(
TagEdit, LangageManager.getProperty("miage.foldertoupdate"),
LangageManager.getProperty("miage.updatingfolder"));
progressDialog.setAbortable(false);
progressDialog.hideAbortButton();
progressDialog.setModal(true);
new Thread(new Runnable() {
public void run() {
TreeUtil.ajoutdossier(myTreeSelectionListener.path);
progressDialog.dispose();
}
}, LangageManager.getProperty("miage.updatingfolder")).start();
progressDialog.setVisible(true);
progressDialog.dispose();
}
});
}
return jButtonIndex;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButtonDesindex() {
if (jButtonDesindex == null) {
jButtonDesindex = new JButton();
jButtonDesindex.setText(LangageManager.getProperty("miage.unindex"));
jButtonDesindex.setIcon( ResourcesRepository.getImageIcon("noindex.gif"));
jButtonDesindex.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
final ProgressDialog progressDialog = new ProgressDialog(
TagEdit, LangageManager.getProperty("miage.foldertoupdate"),
LangageManager.getProperty("miage.updatingfolder"));
progressDialog.setAbortable(false);
progressDialog.hideAbortButton();
progressDialog.setModal(true);
new Thread(new Runnable() {
public void run() {
TreeUtil.supprimerdossier(myTreeSelectionListener.path);
progressDialog.dispose();
}
}, LangageManager.getProperty("miage.updatingfolder")).start();
progressDialog.setVisible(true);
progressDialog.dispose();
}
});
}
return jButtonDesindex;
}
public DefaultTreeModel getMyDefaultTree() {
return MyDefaultTree;
}
}
|