List of usage examples for javax.swing DefaultListModel getElementAt
public E getElementAt(int index)
From source file:gtu._work.ui.ExportSVNModificationFilesUI.java
void reflushOutputList() { DefaultListModel model = (DefaultListModel) srcList.getModel(); LineParser lineParser = null;//from w w w. ja va2 s .co m OutputFile outputFile = null; List<File> list = new ArrayList<File>(); for (int ii = 0; ii < model.size(); ii++) { lineParser = (LineParser) model.getElementAt(ii); list.add(lineParser.file); } File baseDir = FileUtil.exportReceiveBaseDir(list); Validate.notNull(baseDir, "no common base directory!"); DefaultListModel outputModel = new DefaultListModel(); for (int ii = 0; ii < model.size(); ii++) { lineParser = (LineParser) model.getElementAt(ii); outputFile = new OutputFile(); outputFile.srcFile = lineParser.file; outputFile.destFile = FileUtil.exportFileToTargetPath(lineParser.file, baseDir, outputDir); outputModel.addElement(outputFile); } outPutList.setModel(outputModel); }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
/** * Try to add a new timespan. Before it is checked for intersection * * @param s The new timespan//from w w w. jav a2 s . co m */ protected void addTimeSpan(TimeSpan s) { if (s == null) { JOptionPaneHelper.showWarningBox(this, "Der angegebene Zeitrahmen ist ungltig", "Warnung"); return; } //check if timeframe exists or intersects with other existing frame int intersection = -1; DefaultListModel model = (DefaultListModel) jTimeFrameList.getModel(); int entryId = 0; for (int i = 0; i < model.getSize(); i++) { TimeSpan existingSpan = (TimeSpan) model.getElementAt(i); if (!existingSpan.getDirection().equals(TimeSpan.DIRECTION.NONE)) { //not for divider! if (s.intersects(existingSpan)) { intersection = entryId + 1; break; } entryId++; } } if (intersection == -1) { //add span if (s.getDirection().equals(TimeSpan.DIRECTION.SEND)) { ((DefaultListModel) jTimeFrameList.getModel()).add(0, s); } else { ((DefaultListModel) jTimeFrameList.getModel()).add(jTimeFrameList.getModel().getSize(), s); } List<TimeSpan> spans = new LinkedList<>(); for (int i = 0; i < model.getSize(); i++) { spans.add((TimeSpan) model.getElementAt(i)); } Collections.sort(spans); model = new DefaultListModel(); for (TimeSpan span : spans) { model.addElement(span); } jTimeFrameList.setModel(model); } else { JOptionPaneHelper.showWarningBox(this, "Das gewhlte Zeitfenster berschneidet sich mit dem " + intersection + ". Eintrag.\n" + "Bitte whle die Zeitfenster so, dass es zu keinen berschneidungen kommt.", "Warnung"); return; } fireTimeFrameChangedEvent(); }
From source file:gtu._work.ui.RegexDirReplacer.java
private void exeucteActionPerformed(ActionEvent evt) { try {//from www .ja v a 2 s . c o m String fromPattern = null; String toFormat = repToText.getText(); Validate.notEmpty((fromPattern = repFromText.getText()), "replace regex can't empty"); DefaultListModel model = (DefaultListModel) srcList.getModel(); DefaultListModel rmodel = new DefaultListModel(); errMsg = new StringBuilder(); successMsg = new StringBuilder(); String replaceText = null; String bakupReplaceText = null; File newFile = null; File oldFile = null; OldNewFile oldNewFile = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); replaceText = FileUtil.loadFromFile(oldFile, getCharset()); bakupReplaceText = replaceText.toString(); replaceText = replacer(fromPattern, toFormat, replaceText, oldFile); if (!bakupReplaceText.equals(replaceText)) { if (replaceOldFileChkbox.isSelected()) { oldFile.renameTo(new File(oldFile.getParentFile(), oldFile.getName() + ".bak")); } newFile = oldFile; FileUtil.saveToFile(newFile, replaceText, getCharset()); successMsg.append(newFile.getName() + "\n"); oldNewFile = new OldNewFile(); oldNewFile.oldFile = oldFile; oldNewFile.newFile = newFile; rmodel.addElement(oldNewFile); successMsg.append(oldFile.getName() + "\n"); } } newRepList.setModel(rmodel); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog(String.format(MESSAGE, successMsg, errMsg), getTitle()); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:gtu._work.ui.RegexDirReplacer.java
private void scheduleExecuteActionPerformed(ActionEvent evt) { try {//from w ww .j a va2 s . com DefaultListModel model = (DefaultListModel) srcList.getModel(); DefaultListModel rmodel = new DefaultListModel(); DefaultListModel pmodel = (DefaultListModel) templateList.getModel(); errMsg = new StringBuilder(); successMsg = new StringBuilder(); String replaceText = null; String bakupReplaceText = null; File newFile = null; File oldFile = null; OldNewFile oldNewFile = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); replaceText = FileUtil.loadFromFile(oldFile, getCharset()); bakupReplaceText = replaceText.toString(); for (int jj = 0; jj < pmodel.getSize(); jj++) { Entry<Object, Object> entry = (Entry<Object, Object>) pmodel.getElementAt(jj); replaceText = replacer((String) entry.getKey(), (String) entry.getValue(), replaceText, oldFile); } if (!bakupReplaceText.equals(replaceText)) { newFile = new File(oldFile.getParent(), oldFile.getName() + ".replace"); FileUtil.saveToFile(newFile, replaceText, getCharset()); successMsg.append(newFile.getName() + "\n"); oldNewFile = new OldNewFile(); oldNewFile.oldFile = oldFile; oldNewFile.newFile = newFile; rmodel.addElement(oldNewFile); } } newRepList.setModel(rmodel); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog(String.format(MESSAGE, successMsg, errMsg), getTitle()); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:imageuploader.ImgWindow.java
private void generatedImages(String code, File[] files) throws IOException, IllegalStateException, FTPIllegalReplyException, FTPException, FtpException { int ubicacion; File directory = new File(code); ArrayList<File> imageList = new ArrayList(); DefaultListModel mod = (DefaultListModel) jL_Info.getModel(); if (!directory.exists()) { boolean result = directory.mkdir(); if (!result) { JOptionPane.showMessageDialog(rootPane, "Directory -- Error"); } else {/*from w ww . j av a 2 s.c om*/ File dir, img; boolean rst; FileChannel source = null; FileChannel dest = null; FtpCredentials.getInstancia().connect(); for (int i = 0; i < files.length; i++) { int val = 1 + i; //Create the Angle directory dir = new File(directory, "Angle" + val); rst = dir.mkdir(); //Copy Images //DefaultListModel mod = (DefaultListModel)jL_Info.getModel(); for (int j = 0; j < mod.getSize(); j++) { img = new File(dir, code + "~" + mod.getElementAt(j).toString() + ".jpg"); rst = img.createNewFile(); imageList.add(img); source = new RandomAccessFile(files[i], "rw").getChannel(); dest = new RandomAccessFile(img, "rw").getChannel(); long position = 0; long count = source.size(); source.transferTo(position, count, dest); if (source != null) { source.close(); } if (dest != null) { dest.close(); } } ubicacion = i + 1; /*Using the private library */ if (jCHBox_MY.isSelected()) { FtpCredentials.getInstancia().getClient().setDir("/Myron/angle" + ubicacion + "Flash"); FtpCredentials.getInstancia().copyImage(imageList); } if (jCHB_CA.isSelected()) { FtpCredentials.getInstancia().getClient().setDir("/canada/angle" + ubicacion + "Flash"); FtpCredentials.getInstancia().copyImage(imageList); } if (jCHB_AZ.isSelected()) { FtpCredentials.getInstancia().getClient().setDir("/australia/angle" + ubicacion + "Flash"); FtpCredentials.getInstancia().copyImage(imageList); } imageList.clear(); } mod.removeAllElements(); jTF_StyleCode.setText(""); //jL_Info.removeAll(); //list.removeAllElements(); JOptionPane.showMessageDialog(rootPane, "Images uploaded"); } } else { JOptionPane.showMessageDialog(rootPane, "There is a folder with the same name in the same location"); } }
From source file:gtu._work.mvn.MavenRepositoryUI.java
private void initGUI() { try {/*from w ww. java 2 s.co m*/ { } BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); scanList = new JList(); jTabbedPane1.addTab("repository", null, jPanel1, null); { scanText = new JTextField(); jPanel1.add(scanText, BorderLayout.NORTH); } { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { ListModel scanListModel = new DefaultListModel(); jScrollPane1.setViewportView(scanList); scanList.setModel(scanListModel); scanList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { defaultJListClick(scanList, evt); } }); } } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("repository only jar", null, jPanel4, null); jPanel4.setPreferredSize(new java.awt.Dimension(520, 298)); { scanText2 = new JTextField(); jPanel4.add(scanText2, BorderLayout.NORTH); } { jScrollPane3 = new JScrollPane(); jPanel4.add(jScrollPane3, BorderLayout.CENTER); { scanList2 = new JList(); jScrollPane3.setViewportView(scanList2); ListModel scanList2Model = new DefaultListModel(); scanList2.setModel(scanList2Model); scanList2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { defaultJListClick(scanList2, evt); } }); } } { } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jar find", null, jPanel2, null); { jarFindText = new JTextField(); jPanel2.add(jarFindText, BorderLayout.NORTH); } { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); { ListModel jarFindListModel = new DefaultListModel(); jarFindList = new JList(); jScrollPane2.setViewportView(jarFindList); jarFindList.setModel(jarFindListModel); jarFindList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { defaultJListClick(jarFindList, evt); } }); } } { jarFindExecute = new JButton(); jPanel2.add(jarFindExecute, BorderLayout.SOUTH); jarFindExecute.setText("find"); jarFindExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String searchtext = jarFindText.getText(); if (StringUtils.isEmpty(searchtext) || searchtext.length() < 2) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("", "error"); return; } try { DefaultListModel model = new DefaultListModel(); jarFindList.setModel(model); searchtext = searchtext.trim(); searchtext = searchtext.replace('/', '.'); searchtext = searchtext.replace('\\', '.'); if (jarfinder == null) { jarfinder = JarFinder.newInstance(); } else { jarfinder.clear(); } jarfinder.pattern(searchtext); DefaultListModel scanModel = (DefaultListModel) scanList.getModel(); PomFile pomFile = null; for (int ii = 0; ii < scanModel.getSize(); ii++) { pomFile = (PomFile) scanModel.getElementAt(ii); if (pomFile.jarFile == null) { continue; } jarfinder.setDir(pomFile.jarFile); if (!jarfinder.execute().isEmpty()) { model.addElement(pomFile); } jarfinder.getMap().clear(); } } catch (Exception ex) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog(ex.getMessage(), "error"); ex.printStackTrace(); } } }); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jTabbedPane1.addTab("detail", null, jPanel5, null); jPanel5.setLayout(jPanel5Layout); { jScrollPane4 = new JScrollPane(); jPanel5.add(jScrollPane4, BorderLayout.CENTER); { TableModel scanTableModel = new DefaultTableModel(); scanTable = new JTable(); BorderLayout scanTableLayout = new BorderLayout(); scanTable.setLayout(scanTableLayout); jScrollPane4.setViewportView(scanTable); scanTable.setModel(scanTableModel); JTableUtil.defaultSetting(scanTable); scanTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { tableMouseClicked(scanTable, 0, evt); } }); } } } { jPanel3 = new JPanel(); jTabbedPane1.addTab("config", null, jPanel3, null); GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3); jPanel3.setLayout(jPanel3Layout); { copyToDir = new JButton(); copyToDir.setText("set copy to dir"); copyToDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null || !file.exists() || !file.isDirectory()) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir is not correct!, set default desktop", "error"); file = FileUtil.DESKTOP_DIR; } copyTo = file; System.out.println("copyTo: " + copyTo); } }); } { resetM2Dir = new JButton(); resetM2Dir.setText("set .m2 dir"); resetM2Dir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null || !file.exists() || !file.isDirectory()) { showErrorMsg(); repositoryDir = DEFAULT_REPOSITORY_DIR; reloadRepositoryDir(); return; } File newRepository = new File(file, "repository"); File settings = new File(file, "settings.xml"); if (settings.exists() && settings.isFile() && newRepository.exists() && newRepository.isDirectory()) { repositoryDir = newRepository; reloadRepositoryDir(); } else { showErrorMsg(); } } void showErrorMsg() { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir is not correct!, set default .m2 dir", "error"); } }); } { saveCurrentDataBtn = new JButton(); saveCurrentDataBtn.setText("save current data"); saveCurrentDataBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File cfgFile = new File(PropertiesUtil.getJarCurrentPath(MavenRepositoryUI.class), MavenRepositoryUI.class.getSimpleName() + "_" + DateFormatUtil .format(System.currentTimeMillis(), "yyyyMMdd_HHmmss") + ".cfg"); try { ObjectOutputStream writer = new ObjectOutputStream( new FileOutputStream(cfgFile)); writer.writeObject(pomFileList); writer.writeObject(pomFileJarList); writer.writeObject(pomFileMap); writer.flush(); writer.close(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("save completed!\n" + cfgFile, "SUCCESS"); } catch (Exception ex) { JCommonUtil.handleException(ex); ex.printStackTrace(); } } }); } { loadConfigDataBtn = new JButton(); loadConfigDataBtn.setText("load config data"); loadConfigDataBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File cfgFile = JFileChooserUtil.newInstance().selectFileOnly() .addAcceptFile("cfg", ".cfg").showOpenDialog().getApproveSelectedFile(); if (cfgFile == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { ObjectInputStream reader = new ObjectInputStream(new FileInputStream(cfgFile)); pomFileList = (Set<PomFile>) reader.readObject(); pomFileJarList = (Set<PomFile>) reader.readObject(); pomFileMap = (Map<DependencyKey, PomFile>) reader.readObject(); reader.close(); resetUIStatus(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("load completed!\n" + cfgFile, "SUCCESS"); } catch (Exception ex) { JCommonUtil.handleException(ex); ex.printStackTrace(); } } }); } jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(24, 24) .addGroup(jPanel3Layout.createParallelGroup() .addGroup(jPanel3Layout.createSequentialGroup().addComponent(loadConfigDataBtn, GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(saveCurrentDataBtn, GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(copyToDir, GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(resetM2Dir, GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(getJButton1(), GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))) .addContainerGap(281, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(25, 25) .addComponent(copyToDir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE) .addGap(22) .addComponent(resetM2Dir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE) .addGap(24) .addComponent(saveCurrentDataBtn, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE) .addGap(25) .addComponent(loadConfigDataBtn, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE) .addGap(28) .addComponent(getJButton1(), GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE) .addContainerGap(34, Short.MAX_VALUE)); } { jPanel6 = new JPanel(); BorderLayout jPanel6Layout = new BorderLayout(); jPanel6.setLayout(jPanel6Layout); jTabbedPane1.addTab("pom dency", null, jPanel6, null); { openPom = new JButton(); jPanel6.add(openPom, BorderLayout.NORTH); openPom.setText("open"); openPom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileAndDirectory() .showDialog("?pom,pom").getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!!", "ERROR"); return; } List<File> pomList = new ArrayList<File>(); if (file.isFile() && (file.getName().endsWith(".xml") || file.getName().endsWith(".pom"))) { pomList.add(file); } else { FileUtil.searchFileMatchs(file, "pom.xml", pomList); } Set<PomFile> poms = loadPomList(pomList); resetUIStatus(); Map<DependencyKey, PomFile> map = new HashMap<DependencyKey, PomFile>(); Set<LoadPomListDependency.DependencyKey> errorSet = new HashSet<LoadPomListDependency.DependencyKey>(); for (PomFile p : poms) { openPomFetchDependency(p.pom, map, errorSet); } PomFile pfile = null; DefaultTableModel model = JTableUtil.createModel(true, "groupId", "artifactId", "jar", "pomFile"); for (DependencyKey key : map.keySet()) { pfile = map.get(key); model.addRow(new Object[] { pfile.pom.groupId, pfile.pom.artifactId, (pfile.jarFile == null ? "" : pfile.jarFile.getName()), pfile }); } for (LoadPomListDependency.DependencyKey key : errorSet) { model.addRow(new Object[] { key.groupId, key.artifactId, "ERROR" }); } pomDenpendencyTable.setModel(model); } }); } { jScrollPane5 = new JScrollPane(); jPanel6.add(jScrollPane5, BorderLayout.CENTER); { TableModel pomDenpendencyTableModel = new DefaultTableModel(); pomDenpendencyTable = new JTable(); jScrollPane5.setViewportView(pomDenpendencyTable); pomDenpendencyTable.setModel(pomDenpendencyTableModel); pomDenpendencyTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { tableMouseClicked(pomDenpendencyTable, 3, evt); } }); JTableUtil.defaultSetting(pomDenpendencyTable); } } { jPanel7 = new JPanel(); FlowLayout jPanel7Layout = new FlowLayout(); jPanel7Layout.setAlignOnBaseline(true); jPanel6.add(jPanel7, BorderLayout.SOUTH); jPanel7.setLayout(jPanel7Layout); jPanel7.setPreferredSize(new java.awt.Dimension(520, 36)); { clipboardListJar = new JButton(); jPanel7.add(clipboardListJar); clipboardListJar.setText("jar list to clipboard"); clipboardListJar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { List<File> list = fetchPomDependencyTableJarList(); StringBuilder sb = new StringBuilder(); for (File f : list) { sb.append(f + "\n"); } ClipboardUtil.getInstance().setContents(sb); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("clipboard set ok!", "SUCCESS"); } }); } { pomOutputJarDir = new JButton(); jPanel7.add(pomOutputJarDir); pomOutputJarDir.setText("set output jar dir"); pomOutputJarDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly() .showDialog("?Jar").getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir is not correct!!", "ERROR"); return; } pomOutputJarDir_ = file; } }); } { exportListJar = new JButton(); jPanel7.add(exportListJar); exportListJar.setText("export list jar"); exportListJar.setPreferredSize(new java.awt.Dimension(113, 24)); exportListJar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { List<File> list = fetchPomDependencyTableJarList(); if (pomOutputJarDir_ == null || !pomOutputJarDir_.exists() || !pomOutputJarDir_.isDirectory()) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("output dir is not correct!!", "ERROR"); return; } if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil .newInstance().confirmButtonYesNo().iconWaringMessage() .showConfirmDialog("are you sure copy list jar count:(" + list.size() + ") to\n" + pomOutputJarDir_, "WARN")) { StringBuilder sb = new StringBuilder(); StringBuilder fsb = new StringBuilder(); sb.append("total : " + list.size() + "\n"); int ok = 0; int noOk = 0; for (File f : list) { try { FileUtil.copyFile(f, new File(pomOutputJarDir_, f.getName())); ok++; } catch (IOException e) { e.printStackTrace(); noOk++; fsb.append(f + "\n"); } } sb.append("success : " + ok + "\n"); sb.append("failed : " + noOk + "\n"); sb.append("Failed jar :\n"); sb.append(fsb); JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(sb, "COPY RESULT"); } } }); } } } } this.setSize(541, 365); reloadRepositoryDir(); } catch (Exception e) { e.printStackTrace(); } }
From source file:dnd.BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); //Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); //LEFT COLUMN //Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); //Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); //RIGHT COLUMN //Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); //Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); //Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/* w w w .j av a 2s .c om*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** This is commented out for the basicdemo.html tutorial page. ** If you add this code snippet back and delete the ** "return false;" line, the list will accept drops ** of type string. // Perform the actual import. if (insert) { listModel.add(index, data); } else { listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); //Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); //Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); // Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); // LEFT COLUMN // Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); // Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); // RIGHT COLUMN // Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); // Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); // Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/*from w w w .j a v a2s . c om*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** * This is commented out for the basicdemo.html tutorial page. * If you * add this code snippet back and delete the * "return false;" line, the * list will accept drops * of type string. // Perform the actual * import. if (insert) { listModel.add(index, data); } else { * listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); // Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); // Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void fireAddVillagesEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddVillagesEvent List<Village> villages = new ArrayList<Village>(); if (evt.getSource() == jAllSources) { DefaultListModel model = (DefaultListModel) jSourceVillageList.getModel(); for (int i = 0; i < model.getSize(); i++) { villages.add((Village) model.getElementAt(i)); }/*from ww w . j a va 2 s.c o m*/ fireAddSourcesEvent(villages); } else if (evt.getSource() == jSelectedSources) { Object[] selection = jSourceVillageList.getSelectedValues(); if (selection == null || selection.length == 0) { showInfo("Keine Drfer gewhlt"); return; } for (Object v : selection) { villages.add((Village) v); } fireAddSourcesEvent(villages); } else if (evt.getSource() == jAllTargets) { DefaultListModel model = (DefaultListModel) jTargetVillageList.getModel(); for (int i = 0; i < model.getSize(); i++) { villages.add((Village) model.getElementAt(i)); } fireAddTargetsEvent(villages); } else if (evt.getSource() == jSelectedTargets) { Object[] selection = jTargetVillageList.getSelectedValues(); if (selection == null || selection.length == 0) { showInfo("Keine Drfer gewhlt"); return; } for (Object v : selection) { villages.add((Village) v); } fireAddTargetsEvent(villages); } showInfo(villages.size() + ((villages.size() == 1) ? " Dorf " : " Drfer ") + "eingefgt"); }
From source file:gtu._work.etc._3DSMovieRenamer.java
private void initGUI() { try {// www . j a v a2s .com final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("3DS Rename"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("vid list", null, jPanel1, null); { openDir = new JButton(); jPanel1.add(openDir, BorderLayout.NORTH); openDir.setText("open dir"); openDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("openDir.actionPerformed", evt); } }); } { ListModel vidListModel = new DefaultListModel(); vidList = new JList(); jPanel1.add(vidList, BorderLayout.CENTER); vidList.setModel(vidListModel); vidList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("vidList.mouseClicked", evt); } }); vidList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { swingUtil.invokeAction("vidList.keyPressed", evt); } }); } { jPanel3 = new JPanel(); jPanel1.add(jPanel3, BorderLayout.SOUTH); jPanel3.setPreferredSize(new java.awt.Dimension(445, 34)); { renameText = new JTextField(); jPanel3.add(renameText); renameText.setPreferredSize(new java.awt.Dimension(187, 24)); } { renameBtn = new JButton(); jPanel3.add(renameBtn); renameBtn.setText("rename"); renameBtn.setPreferredSize(new java.awt.Dimension(106, 24)); renameBtn.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("renameBtn.mouseClicked", evt); } }); } { forceChange = new JCheckBox(); jPanel3.add(forceChange); forceChange.setText("force"); forceChange.setPreferredSize(new java.awt.Dimension(64, 21)); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("copy", null, jPanel2, null); { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); { ListModel copyToListModel = new DefaultListModel(); copyToList = new JList(); jScrollPane1.setViewportView(copyToList); copyToList.setModel(copyToListModel); copyToList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("copyToList.mouseClicked", evt); } }); } } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("BT Movie", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.WEST); jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355)); { btDirTree = new JTree(); jScrollPane2.setViewportView(btDirTree); btDirTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction(evt); } }); btDirTree.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { swingUtil.invokeAction(evt); } }); JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jPanel4.add(jPanel5, BorderLayout.CENTER); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355)); { DefaultListModel btMovListModel = new DefaultListModel(); btMovList = new JList(); jScrollPane3.setViewportView(btMovList); btMovList.setModel(btMovListModel); btMovList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction(evt); } }); btMovList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt); } }); } } } } { jPanel6 = new JPanel(); FlowLayout jPanel6Layout = new FlowLayout(); jTabbedPane1.addTab("common", null, jPanel6, null); jPanel6.setLayout(jPanel6Layout); { execute3dsVidTransfer = new JButton(); jPanel6.add(execute3dsVidTransfer); execute3dsVidTransfer.setText("execute 3ds video transfer"); execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42)); execute3dsVidTransfer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe"; try { Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat)); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } { openMovieAppDir = new JButton(); jPanel6.add(openMovieAppDir); openMovieAppDir.setText("open movie app dir"); openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42)); openMovieAppDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { Desktop.getDesktop().open(new File("C:/apps/_movie")); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } { jPanel7 = new JPanel(); BorderLayout jPanel7Layout = new BorderLayout(); jTabbedPane1.addTab("fake rename", null, jPanel7, null); jPanel7.setLayout(jPanel7Layout); { openFakeRenameDir = new JButton(); jPanel7.add(openFakeRenameDir, BorderLayout.NORTH); openFakeRenameDir.setText("open dir"); openFakeRenameDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JCommonUtil._jFileChooser_selectDirectoryOnly(); if (file != null) { DefaultListModel model = new DefaultListModel(); for (File f : file.listFiles()) { model.addElement(f); } openFakeRenameDirList.setModel(model); } } }); } { DefaultListModel openFakeRenameDirListModel = new DefaultListModel(); openFakeRenameDirList = new JList(); jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER); openFakeRenameDirList.setModel(openFakeRenameDirListModel); openFakeRenameDirList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList); try { Process process = Runtime.getRuntime() .exec(String.format("cmd /c call \"%s\"", file)); InputStream ins = process.getInputStream(); while (ins.read() != -1) { //TODO } ins.close(); System.out.println("done..."); } catch (IOException e) { e.printStackTrace(); } } }); openFakeRenameDirList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt); } }); } { jPanel8 = new JPanel(); jPanel7.add(jPanel8, BorderLayout.SOUTH); jPanel8.setPreferredSize(new java.awt.Dimension(681, 43)); { openFakeRenameDir_newName = new JTextField(); jPanel8.add(openFakeRenameDir_newName); openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27)); } { fakeRenameExecute = new JButton(); jPanel8.add(fakeRenameExecute); fakeRenameExecute.setText("execute"); fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27)); fakeRenameExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel(); //TODO } }); } } } swingUtil.addAction("copyToList.mouseClicked", new Action() { public void action(EventObject evt) throws Exception { try { if (((MouseEvent) evt).getButton() == 3) { JMenuItem reloadMenu = new JMenuItem(); reloadMenu.setText("reload SD card directory"); reloadMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultListModel copyToListModel = new DefaultListModel(); for (final File f : load3DSDir.listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) { return true; } return false; } })) { copyToListModel.addElement(f); } copyToList.setModel(copyToListModel); } }); JMenuItem copyAllToMenu = new JMenuItem(); { copyAllToMenu.setText( String.format("move %d vids to...", vidList.getModel().getSize())); final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList); if (toDir == null || !toDir.exists() || !toDir.isDirectory()) { copyAllToMenu.setEnabled(false); } if (vidList.getModel().getSize() == 0) { copyAllToMenu.setText("copy no file..."); copyAllToMenu.setEnabled(false); } copyAllToMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultListModel model = JListUtil.newInstance(vidList).getModel(); if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil .newInstance().iconWaringMessage().confirmButtonYesNo() .showConfirmDialog("are you sure copy files : " + model.getSize() + "\n to dir : " + toDir, "COPY VIDS")) { return; } for (int ii = 0; ii < model.getSize(); ii++) { File src = (File) model.getElementAt(ii); src.renameTo(new File(toDir, src.getName())); } JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("copy completed!", "SUCCESS"); loadDirVids(); } }); } JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt) .addJMenuItem(reloadMenu, copyAllToMenu).show(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); swingUtil.addAction("openDir.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir not corrent!, set desktop", getTitle()); loadDir = FileUtil.DESKTOP_DIR; } else { loadDir = file; } loadDirVids(); } }); swingUtil.addAction("vidList.mouseClicked", new Action() { // final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE"; public void action(EventObject evt) throws Exception { int pos = -1; if ((pos = vidList.getLeadSelectionIndex()) == -1) { return; } MouseEvent mevt = (MouseEvent) evt; final File selectItem = (File) vidList.getModel().getElementAt(pos); List<JMenuItem> menuList = new ArrayList<JMenuItem>(); JMenuItem simpleRenamer = new JMenuItem(); final String simpleRenamePrefix = RandomUtil.upperCase(3); simpleRenamer.setText("Rename : " + simpleRenamePrefix); simpleRenamer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { String value = StringUtils.defaultString(JOptionPaneUtil.newInstance() .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix); if (value != null && value.matches("[a-zA-Z]{3}")) { selectItem.renameTo(getNewFile(selectItem.getParentFile(), value)); loadDirVids(); } else { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("prefix is not correct!", "ERROR"); } } }); menuList.add(simpleRenamer); if (load3DSDir == null) { reload3DSDir(); if (load3DSDir == null) { JMenuItem disable = new JMenuItem(); disable.setText("MOVE : SD card is not set!"); disable.setEnabled(false); menuList.add(disable); } } else { for (final File f : load3DSDir.listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) { return true; } return false; } })) { JMenuItem copyTo = new JMenuItem(); copyTo.setText("MOVE : " + f.getName()); copyTo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil .newInstance().iconQuestionMessage().confirmButtonYesNo() .showConfirmDialog(// "are you sure move file\n" + // selectItem + "\n" + // "to\n" + // "dir : " + f + " ??"// , "COPY FILE")) { File copyToNewDirFile = new File(f, selectItem.getName()); if (copyToNewDirFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog( "target dir file already exist!, need rename!", "FILE ALREADY EXIST"); return; } selectItem.renameTo(copyToNewDirFile); loadDirVids(); JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("move completed!", "MOVE FILE"); } } }); menuList.add(copyTo); } } JPopupMenuUtil.newInstance(vidList).applyEvent(mevt) .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show(); if (mevt.getClickCount() != 2) { return; } String clkItemPath = selectItem.getAbsolutePath(); String command = "cmd /c call \"" + clkItemPath + "\""; System.out.println(command); Runtime.getRuntime().exec(command); } }); swingUtil.addAction("vidList.keyPressed", new Action() { public void action(EventObject evt) throws Exception { JListUtil.newInstance(vidList).defaultJListKeyPressed(evt); } }); swingUtil.addAction("renameBtn.mouseClicked", new Action() { Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$"); public void action(EventObject evt) throws Exception { String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3)); System.out.println("name = " + name + ", force : " + forceChange.isSelected()); if (!name.matches("[a-zA-Z]{3}")) { renameText.setText(""); JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("rename must eng 3 char!", "ERROR"); return; } DefaultListModel model = (DefaultListModel) vidList.getModel(); boolean matchOk = false; if (model.size() != 0) { File oldFile = null; Matcher matcher = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); if (!oldFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog( "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle()); return; } matcher = aviNamePattern.matcher(oldFile.getName()); matchOk = matcher.find(); System.out.println("matchOk = " + matchOk); if (matchOk && !forceChange.isSelected()) { oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1))); } else { oldFile.renameTo(getNewFile(oldFile.getParentFile(), name)); } } JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!", getTitle()); } loadDirVids(); } }); ToolTipManager.sharedInstance().setInitialDelay(0); swingUtil.addAction(btMovList, MouseEvent.class, new Action() { public void action(EventObject evt) throws Exception { final File file = (File) JListUtil.getLeadSelectionObject(btMovList); if (JMouseEventUtil.buttonLeftClick(1, evt)) { btMovList.setToolTipText( DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:" + (file.length() / 1024) + "k"); } final Object[] objects = btMovList.getSelectedValues(); JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)// .addJMenuItem("move out", (objects != null && objects.length > 0), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { List<File> list = new ArrayList<File>(); for (Object val : objects) { list.add((File) val); } if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure move file from\n" + list.toString().replace(',', '\n') + "\nto\n" + DEFAULT_BT_DIR, "MOVE")) { return; } StringBuilder sb = new StringBuilder(); File moveTo = null; for (File file : list) { sb.append((file.renameTo( moveTo = new File(DEFAULT_BT_DIR, file.getName())) && moveTo.exists()) ? "" : file + "\n"); } JCommonUtil._jOptionPane_showMessageDialog_info( sb.length() == 0 ? "move success!" : "move failed!\n" + sb); } }) .addJMenuItem("delete this", file.exists(), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete file \n" + file, "DELETE")) { return; } boolean result = file.delete(); System.out.println("!!!!!" + result + "..." + file.exists()); JCommonUtil._jOptionPane_showMessageDialog_info( result ? "delete success!" : "delete failed!"); } }).show(); if (JMouseEventUtil.buttonLeftClick(2, evt)) { Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file)); } } }); swingUtil.addAction(btDirTree, MouseEvent.class, new Action() { File getSingleFile() { return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile(); } public void action(EventObject evt) throws Exception { int selectCount = btDirTree.getSelectionModel().getSelectionCount(); if (selectCount == 1) { final File file = getSingleFile(); JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this", selectCount == 1 && file.exists(), new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { if (file.isFile()) { if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete FILE : \n" + file, "WARNING")) { file.delete(); JCommonUtil._jOptionPane_showMessageDialog_info( (file.exists() ? "delete failed!" : "delete success!")); } } if (file.isDirectory()) { StringBuilder sb = new StringBuilder(); if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption( "sure delete DIR : \n" + file, "WARNING")) { List<Boolean> delL = new ArrayList<Boolean>(); for (File f : file.listFiles()) { if (fileExtensionPattern.matcher(f.getName()).find() || f.length() > 1000000L) { if (!JCommonUtil ._JOptionPane_showConfirmDialog_yesNoOption( "delete this : \n" + f, "CHECK AGAIN")) { continue; } delL.add(f.delete()); } delL.add(f.delete()); } for (File f : file.listFiles()) { if (f.exists()) { sb.append(f + "\n"); } } System.out.println("delL.contains(false)==================>" + delL.contains(false)); } if (!file.delete()) { sb.append(file + "\n"); } JCommonUtil._jOptionPane_showMessageDialog_info( sb.length() > 0 ? "delete failed!\nlist:\n" + sb : "delete success!"); if (sb.length() == 0) { DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree) .getSelectItem(); System.out.println( JTreeUtil.newInstance(btDirTree).removeNode(node)); } } } }).addJMenuItem("open dir", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { File openTarget = file; if (file.isFile()) { openTarget = file.getParentFile(); } try { Desktop.getDesktop().open(openTarget); } catch (IOException e) { JCommonUtil.handleException(e); } } }).show(); } } }); swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() { public void action(EventObject evt) throws Exception { List<File> list = new ArrayList<File>(); for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) { JFile jfile = (JFile) node.getUserObject(); if (jfile.getFile().isDirectory()) { for (File f : jfile.getFile().listFiles(new FilenameFilter() { public boolean accept(File paramFile, String paramString) { return fileExtensionPattern.matcher(paramString).find(); } })) { System.out.println(f.getName() + "...." + f.length()); list.add(f); } } } Collections.sort(list, new Comparator<File>() { public int compare(File paramT1, File paramT2) { return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1; } }); btMovList.setModel(JListUtil.createModel(list.iterator())); } }); } this.setSize(702, 422); loadDirVids(); reload3DSDir(); } catch (Exception e) { e.printStackTrace(); } }