List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
private void addDocuments(JList list, Set fileSet) { DefaultListModel model = (DefaultListModel) list.getModel(); for (Iterator i = fileSet.iterator(); i.hasNext();) { File file = (File) i.next(); Document doc = new Document(file); String text = doc.getText(); if (30 < text.split(" ").length) { // ???????? doc.setLang("en"); }/*from www . j a v a 2s . c o m*/ model.addElement(doc); } }
From source file:ListCutPaste.java
/** * Perform the actual data import./*from w w w.j av a 2 s . c o m*/ */ public boolean importData(TransferHandler.TransferSupport info) { String data = null; // If we can't handle the import, bail now. if (!canImport(info)) { return false; } JList list = (JList) info.getComponent(); DefaultListModel model = (DefaultListModel) list.getModel(); // Fetch the data -- bail if this fails try { data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException ufe) { System.out.println("importData: unsupported data flavor"); return false; } catch (IOException ioe) { System.out.println("importData: I/O exception"); return false; } if (info.isDrop()) { // This is a drop JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); int index = dl.getIndex(); if (dl.isInsert()) { model.add(index, data); return true; } else { model.set(index, data); return true; } } else { // This is a paste int index = list.getSelectedIndex(); // if there is a valid selection, // insert data after the selection if (index >= 0) { model.add(list.getSelectedIndex() + 1, data); // else append to the end of the list } else { model.addElement(data); } return true; } }
From source file:cis_690_report.DynamicReporter.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: jTextField1.setText(""); JFileChooser choose = new JFileChooser(); choose.showOpenDialog(null);/*from ww w. j a va2s . c o m*/ f = choose.getSelectedFile(); String path = f.getAbsolutePath(); jTextField1.setText(path); jPanel2.setVisible(true); header = new String[120]; for (int x = 0; x < 120; x++) { header[x] = ""; } String line = ""; BufferedReader br2 = null; try { br2 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex); } try { while ((line = br2.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); // System.out.println(Bull.length); if (number_of_rows == 0) { for (int i = 0; i < Bull.length; i++) { header[i] = Bull[i]; } } number_of_rows++; } } catch (IOException ex) { Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex); } Bulls = new String[number_of_rows - 1]; for (int x = 0; x < Bulls.length; x++) { Bulls[x] = ""; } BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex); } try { int k = 0; while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); // System.out.println(Bull.length); if (k != 0) { if (!Bull[2].equals("")) { Bulls[k - 1] += Bull[2] + ("(Brand) "); } if (!Bull[6].equals("")) { Bulls[k - 1] += Bull[6] + ("(RFID) "); } if (!Bull[7].equals("")) { Bulls[k - 1] += Bull[7] + ("(Tag) "); } if (!Bull[8].equals("")) { Bulls[k - 1] += Bull[8] + ("(Tattoo) "); } if (!Bull[9].equals("")) { Bulls[k - 1] += Bull[9] + ("(Other) "); } Bulls[k - 1] += ":" + k; } k++; } } catch (IOException ex) { Logger.getLogger(DynamicReporter.class.getName()).log(Level.SEVERE, null, ex); } for (int y = 0; y < Bulls.length; y++) { System.out.print(Bulls[y]); } DefaultListModel dlm = new DefaultListModel(); for (int y = 0; y < header.length; y++) { dlm.addElement(header[y] + ": " + y); } jList1.setModel(dlm); jPanel1.setVisible(false); }
From source file:de.pavloff.spark4knime.jsnippet.ui.JarListPanel.java
@SuppressWarnings("null") private void onJarURLAdd() { DefaultListModel<String> model = (DefaultListModel<String>) m_addJarList.getModel(); Set<String> hash = new HashSet<>(Collections.list(model.elements())); String input = "knime://knime.workflow/example.jar"; boolean valid; do {//from www . j ava 2s . c o m input = JOptionPane.showInputDialog(this, "Enter a \"knime:\" URL to a JAR file", input); if (StringUtils.isEmpty(input)) { valid = true; } else { URL url; try { url = new URL(input); File file = FileUtil.getFileFromURL(url); CheckUtils.checkArgument(file != null, "Could not resolve to local file"); CheckUtils.checkArgument(file.exists(), "File does not exists; location resolved to\n%s", file.getAbsolutePath()); valid = true; } catch (MalformedURLException | IllegalArgumentException mfe) { JOptionPane.showMessageDialog(this, "Invalid URL\n" + mfe.getMessage(), "Error parsing URL", JOptionPane.ERROR_MESSAGE); valid = false; continue; } } } while (!valid); if (!StringUtils.isEmpty(input) && hash.add(input)) { model.addElement(input); } }
From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java
/** * * @param advanceFocus/*from w w w .j a v a 2s.co m*/ */ protected void showDialog(final int advanceFocus) { final Vector<Integer> idListLocal = (Vector<Integer>) idList.clone(); final Vector<String> listLocal = (Vector<String>) list.clone(); final String enteredText = StringUtils.isEmpty(prevEnteredText) ? cachedPrevText : prevEnteredText; DefaultListModel<String> model = new DefaultListModel<String>(); if (doAddAddItem) { model.addElement(UIRegistry.getResourceString("TFWQ_ADD_LABEL")); //$NON-NLS-1$ } for (String val : list) { model.addElement(val); } final JList<String> listBox = new JList<String>(model); JPanel panel = new JPanel(new BorderLayout()); panel.add(createLabel(UIRegistry.getResourceString("TFWQ_CHOOSE_LABEL"), SwingConstants.CENTER), //$NON-NLS-1$ BorderLayout.NORTH); panel.add(UIHelper.createScrollPane(listBox, true), BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); // Had to do inner class in order to get it to select an item // before being shown class PopUpDialog extends CustomDialog { protected JList<String> pListBox; public PopUpDialog(final Frame frame, final boolean isModal, final Component contentPanel, JList<String> pListBoxArg) throws HeadlessException { super(frame, UIRegistry.getResourceString("TFWQ_CHOOSE_TITLE"), isModal, contentPanel); //$NON-NLS-1$ this.pListBox = pListBoxArg; initialize(); } public PopUpDialog(final Dialog dialog, final boolean isModal, final Component contentPanel, JList<String> pListBoxArg) throws HeadlessException { super(dialog, UIRegistry.getResourceString("TFWQ_CHOOSE_TITLE"), isModal, OK_BTN | CANCEL_BTN, //$NON-NLS-1$ contentPanel); this.pListBox = pListBoxArg; initialize(); } /** * */ protected void initialize() { pListBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (okBtn != null && pListBox != null) { okBtn.setEnabled(listBox.getSelectedIndex() != -1); } } } }); pListBox.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { okBtn.setEnabled(true); okBtn.doClick(); } } }); } @Override public void setVisible(final boolean visible) { if (visible) { listBox.setSelectedIndex(doAddAddItem ? 1 : 0); } super.setVisible(visible); } } hasNewText = false; Window mostRecent = UIRegistry.getMostRecentWindow(); CustomDialog dlg; if (mostRecent instanceof Dialog) { dlg = new PopUpDialog((Dialog) UIRegistry.getMostRecentWindow(), true, panel, listBox); } else { dlg = new PopUpDialog((Frame) UIRegistry.getMostRecentWindow(), true, panel, listBox); } dlg.setVisible(true); if (!dlg.isCancelled()) { int inx = listBox.getSelectedIndex(); boolean isDoingAdd = inx == 0 && doAddAddItem; inx = doAddAddItem ? inx - 1 : inx; if (!isDoingAdd && inx < idListLocal.size()) { selectedId = idListLocal.get(inx); setText(listLocal.get(inx)); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { transferFocus(advanceFocus); notifyListenersOfChange(isDoingAdd ? new AddItemEvent(enteredText) : listBox); } }); } else { setText(""); //$NON-NLS-1$ } }
From source file:de.tor.tribes.ui.views.DSWorkbenchAttackFrame.java
@Override public void actionPerformed(ActionEvent e) { AttackTableTab activeTab = getActiveTab(); int idx = jAttackTabPane.getSelectedIndex(); if (e.getActionCommand() != null && activeTab != null) { if (e.getActionCommand().equals("TimeChange")) { activeTab.fireChangeTimeEvent(); } else if (e.getActionCommand().equals("UnitChange")) { activeTab.fireChangeUnitEvent(); } else if (e.getActionCommand().equals("Recolor")) { activeTab.updateSortHighlighter(); } else if (e.getActionCommand().equals("ExportScript")) { activeTab.fireExportScriptEvent(); } else if (e.getActionCommand().equals("Copy")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("BBCopy")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CLIPBOARD_BB); } else if (e.getActionCommand().equals("Cut")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD); jAttackTabPane.setSelectedIndex(idx); } else if (e.getActionCommand().equals("Paste")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD); jAttackTabPane.setSelectedIndex(idx); } else if (e.getActionCommand().equals("Delete")) { activeTab.deleteSelection(true); } else if (e.getActionCommand().equals("Find")) { BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT); Graphics g = back.getGraphics(); g.setColor(new Color(120, 120, 120, 120)); g.fillRect(0, 0, back.getWidth(), back.getHeight()); g.setColor(new Color(120, 120, 120)); g.drawLine(0, 0, 3, 3);/*from www . j a v a 2 s . co m*/ g.dispose(); TexturePaint paint = new TexturePaint(back, new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight())); jxSearchPane.setBackgroundPainter(new MattePainter(paint)); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < activeTab.getAttackTable().getColumnCount(); i++) { TableColumnExt col = activeTab.getAttackTable().getColumnExt(i); if (col.isVisible()) { if (!col.getTitle().equals("Einheit") && !col.getTitle().equals("Typ") && !col.getTitle().equals("Sonstiges") && !col.getTitle().equals("Abschickzeit") && !col.getTitle().equals("Ankunftzeit") && !col.getTitle().equals("Verbleibend")) { model.addElement(col.getTitle()); } } } jXColumnList.setModel(model); jXColumnList.setSelectedIndex(0); jxSearchPane.setVisible(true); } } }
From source file:edu.umn.natsrl.ticas.plugin.srte.SRTEMainPanel.java
/** * Load eventlist info/*from w ww. j a v a2 s .co m*/ */ private void setEventListinfo() { selectedEventList = (TimeEventLists) this.cbxeventlists.getSelectedItem(); DefaultListModel dm = new DefaultListModel(); if (selectedEventList == null) return; for (TimeEvent te : selectedEventList.getTimeEvents()) { dm.addElement(te); } // _list.setModel(dm); lbxeventlist.setModel(dm); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java
@Override public void actionPerformed(ActionEvent e) { ReportTableTab activeTab = getActiveTab(); if (e.getActionCommand() != null && activeTab != null) { if (e.getActionCommand().equals("Copy")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("BBCopy")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CLIPBOARD_BB); } else if (e.getActionCommand().equals("Cut")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("Paste")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("Delete")) { activeTab.deleteSelection(true); } else if (e.getActionCommand().equals("Find")) { BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT); Graphics g = back.getGraphics(); g.setColor(new Color(120, 120, 120, 120)); g.fillRect(0, 0, back.getWidth(), back.getHeight()); g.setColor(new Color(120, 120, 120)); g.drawLine(0, 0, 3, 3);//from w ww . java2 s . c o m g.dispose(); TexturePaint paint = new TexturePaint(back, new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight())); jxSearchPane.setBackgroundPainter(new MattePainter(paint)); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < activeTab.getReportTable().getColumnCount(); i++) { TableColumnExt col = activeTab.getReportTable().getColumnExt(i); if (col.isVisible()) { if (!col.getTitle().equals("Status") && !col.getTitle().equals("Typ") && !col.getTitle().equals("Sonstiges")) { model.addElement(col.getTitle()); } } } jXColumnList.setModel(model); jXColumnList.setSelectedIndex(0); jxSearchPane.setVisible(true); } } }
From source file:gtu._work.ui.ExportSVNModificationFilesUI.java
private void initGUI() { try {/*from w w w. j av a2 s.com*/ final SwingActionUtil swingUtil = SwingActionUtil.newInstance(this); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setTitle("SVN BACKUP"); this.setPreferredSize(new java.awt.Dimension(734, 442)); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { swingUtil.invokeAction("jTabbedPane1_changeEvent", evt); } }); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("src text", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { srcArea = new JTextArea(); jScrollPane1.setViewportView(srcArea); } } { loadSrcTextarea = new JButton(); jPanel1.add(loadSrcTextarea, BorderLayout.SOUTH); loadSrcTextarea.setText("load src textarea"); loadSrcTextarea.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("loadSrcTextarea.actionPerformed", evt); } }); } { srcBaseDir = new JButton(); jPanel1.add(srcBaseDir, BorderLayout.NORTH); srcBaseDir.setText("set src base dir"); srcBaseDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("srcBaseDir.actionPerformed", evt); } }); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("src list", null, jPanel2, null); { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(531, 317)); { ListModel srcListModel = new DefaultListModel(); srcList = new JList(); jScrollPane2.setViewportView(srcList); srcList.setModel(srcListModel); srcList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("srcList.mouseClicked", evt); } }); srcList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { swingUtil.invokeAction("srcList.keyPressed", evt); } }); } } { srcListQuery = new JTextField(); srcListQuery.getDocument() .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() { public void process(DocumentEvent event) { String scan = JCommonUtil.getDocumentText(event); DefaultListModel model = new DefaultListModel(); Pattern pat = Pattern.compile(scan); for (LineParser line : copySrcListForQuerySet) { if (!line.file.exists()) { continue; } if (line.file.getAbsolutePath().contains(scan)) { model.addElement(line); continue; } try { if (pat.matcher(line.file.getAbsolutePath()).find()) { model.addElement(line); continue; } } catch (Exception ex) { } } srcList.setModel(model); } })); jPanel2.add(srcListQuery, BorderLayout.NORTH); } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("out list", null, jPanel3, null); { jScrollPane3 = new JScrollPane(); jPanel3.add(jScrollPane3, BorderLayout.CENTER); { ListModel outPutListModel = new DefaultListModel(); outPutList = new JList(); jScrollPane3.setViewportView(outPutList); outPutList.setModel(outPutListModel); outPutList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("outPutList.mouseClicked", evt); } }); outPutList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { swingUtil.invokeAction("outPutList.keyPressed", evt); } }); } } { outPutDir = new JButton(); jPanel3.add(outPutDir, BorderLayout.NORTH); outPutDir.setText("set output dir"); outPutDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("outPutDir.actionPerformed", evt); } }); } { execute = new JButton(); jPanel3.add(execute, BorderLayout.SOUTH); execute.setText("execute backup"); execute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("execute.actionPerformed", evt); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("compre", null, jPanel4, null); { jScrollPane4 = new JScrollPane(); jPanel4.add(jScrollPane4, BorderLayout.CENTER); jScrollPane4.setPreferredSize(new java.awt.Dimension(713, 339)); { TableModel compareTableModel = new DefaultTableModel(); compareTable = new JTable(); jScrollPane4.setViewportView(compareTable); compareTable.setModel(compareTableModel); JTableUtil.defaultSetting(compareTable); compareTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { swingUtil.invokeAction("compareTable.mouseClicked", evt); } }); } } { jPanel5 = new JPanel(); jPanel4.add(jPanel5, BorderLayout.NORTH); jPanel5.setPreferredSize(new java.awt.Dimension(713, 42)); { openExternalSrcFolder = new JButton(); jPanel5.add(openExternalSrcFolder); openExternalSrcFolder.setText("open external src folder"); openExternalSrcFolder.setPreferredSize(new java.awt.Dimension(280, 29)); openExternalSrcFolder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("openExternalSrcFolder.actionPerformed", evt); } }); } { startCompareMatch = new JButton(); jPanel5.add(startCompareMatch); startCompareMatch.setText("start compare source"); startCompareMatch.setPreferredSize(new java.awt.Dimension(280, 29)); startCompareMatch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { swingUtil.invokeAction("startCompareMatch.actionPerformed", evt); } }); } } } { jPanel6 = new JPanel(); GroupLayout jPanel6Layout = new GroupLayout((JComponent) jPanel6); jPanel6.setLayout(jPanel6Layout); jTabbedPane1.addTab("configuration", null, jPanel6, null); { DefaultComboBoxModel exportModeComboModel = new DefaultComboBoxModel(); for (ParseMode mode : ParseMode.values()) { exportModeComboModel.addElement(mode); } exportModeCombo = new JComboBox(); exportModeCombo.setModel(exportModeComboModel); } jPanel6Layout.setHorizontalGroup(jPanel6Layout .createSequentialGroup().addContainerGap(41, 41).addComponent(exportModeCombo, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE) .addContainerGap(505, Short.MAX_VALUE)); jPanel6Layout .setVerticalGroup(jPanel6Layout.createSequentialGroup().addContainerGap(30, 30) .addComponent(exportModeCombo, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap(321, Short.MAX_VALUE)); } { jPanel7 = new JPanel(); BorderLayout jPanel7Layout = new BorderLayout(); jPanel7.setLayout(jPanel7Layout); jTabbedPane1.addTab("error log", null, jPanel7, null); { jScrollPane5 = new JScrollPane(); jPanel7.add(jScrollPane5, BorderLayout.CENTER); { DefaultListModel errorLogListModel = new DefaultListModel(); errorLogList = new JList(); jScrollPane5.setViewportView(errorLogList); errorLogList.setModel(errorLogListModel); } } } } this.setSize(734, 442); swingUtil.addAction("openExternalSrcFolder.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (dir == null) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog("file is not correct!", "ERROR"); return; } externalDir = dir; } }); swingUtil.addAction("startCompareMatch.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { Validate.notNull(manualBaseDir, "source folder not set!!"); Validate.notNull(externalDir, "external folder not set!!"); Validate.isTrue(!manualBaseDir.equals(externalDir), "source dir : " + manualBaseDir + "\nexternal dir : " + externalDir + "\n cant be the same!!"); List<File> externalSrcFolderList = new ArrayList<File>(); FileUtil.searchFileMatchs(externalDir, ".*", externalSrcFolderList); System.out.println("externalSrcFolderList = " + externalSrcFolderList.size()); List<File> manualBaseSourceList = new ArrayList<File>(); FileUtil.searchFileMatchs(manualBaseDir, ".*", manualBaseSourceList); System.out.println("manualBaseSourceList = " + manualBaseSourceList.size()); String cutExternalPath = FileUtil.exportReceiveBaseDir(externalSrcFolderList).getAbsolutePath(); System.out.println("cutExternalPath = " + cutExternalPath); int cutExternalLength = cutExternalPath.length(); List<CompareFile> _compareList = new ArrayList<CompareFile>(); CompareFile compare = null; File mostCloseFile = null; List<File> searchMatchSrcList = new ArrayList<File>(); for (File external : externalSrcFolderList) { compare = new CompareFile(); compare.external = external; searchMatchSrcList.clear(); mostCloseFile = new File(manualBaseDir, external.getAbsolutePath().substring(cutExternalLength)); System.out.println(mostCloseFile.exists() + " == close file : " + mostCloseFile); if (mostCloseFile.exists()) { searchMatchSrcList.add(mostCloseFile); } else { for (File src : manualBaseSourceList) { if (src.getName().equalsIgnoreCase(external.getName())) { searchMatchSrcList.add(src); } } } System.out.println(external.getName() + " => match source : " + searchMatchSrcList.size()); compare.srcSet = new HashSet<File>(searchMatchSrcList); _compareList.add(compare); } compareList = _compareList; reloadCompareTable(); } }); swingUtil.addAction("compareTable.mouseClicked", new Action() { String tortoiseMergeFormat = "cmd /c call TortoiseMerge /base:\"%s\" /theirs:\"%s\""; String openFileFormat = "cmd /c call \"%s\""; void openFile(File file) { String command = String.format(openFileFormat, file); System.out.println(command); try { ProcessWatcher.newInstance(Runtime.getRuntime().exec(command)).getStreamSync(); System.out.println("do reload..."); reloadCompareTable(); } catch (IOException e1) { JCommonUtil.handleException(e1); } } public void action(EventObject evt) throws Exception { MouseEvent event = (MouseEvent) evt; int rowPos = JTableUtil.newInstance(compareTable).getSelectedRow(); final File external = (File) JTableUtil.newInstance(compareTable).getModel().getValueAt(rowPos, CompareTableIndex.EXTERNAL_FILE.pos); final File srcFile = (File) JTableUtil.newInstance(compareTable).getModel().getValueAt(rowPos, CompareTableIndex.SOURCE_FILE.pos); System.out.println("external : " + external); System.out.println("srcFile : " + srcFile); if (JMouseEventUtil.buttonLeftClick(2, event)) { String command = String.format(tortoiseMergeFormat, external, srcFile); System.out.println(command); Runtime.getRuntime().exec(command); } if (JMouseEventUtil.buttonRightClick(1, event)) { JMenuItem showInfoMenu = new JMenuItem(); showInfoMenu.setText("information"); showInfoMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(// "source file : \n" + srcFile + "\n" + DateFormatUtils.format(srcFile.lastModified(), "yyyy/MM/dd HH:mm:ss") + "\n" + "size : " + srcFile.length() / 1024 + "\n\n" + "external file : \n" + external + "\n" + DateFormatUtils.format(external.lastModified(), "yyyy/MM/dd HH:mm:ss") + "\n" + "size : " + external.length() / 1024, "INFORMATION"); } }); JMenuItem openFileMenu = new JMenuItem(); openFileMenu.setText("OPEN : source"); openFileMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(srcFile); } }); JMenuItem openExternalMenu = new JMenuItem(); openExternalMenu.setText("OPEN : external"); openExternalMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(external); } }); JMenuItem openPairlMenu = new JMenuItem(); openPairlMenu.setText("OPEN : all"); openPairlMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(srcFile); openFile(external); } }); JPopupMenuUtil.newInstance(compareTable).applyEvent(event) .addJMenuItem(showInfoMenu, openFileMenu, openExternalMenu, openPairlMenu).show(); } } }); swingUtil.addAction("loadSrcTextarea.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { loadSrcTextarea(); } }); swingUtil.addAction("srcList.mouseClicked", new Action() { public void action(EventObject evt) throws Exception { if (JMouseEventUtil.buttonRightClick(1, evt)) { JPopupMenuUtil.newInstance(srcList).applyEvent(evt) .addJMenuItem("mark svn delete", new ActionListener() { public void actionPerformed(ActionEvent e) { if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil .newInstance().confirmButtonYesNo().showConfirmDialog( "are you sure, mark delete file : " + srcList.getSelectedValues().length, "SVN DELETE")) { return; } StringBuilder sb = new StringBuilder(); Process process = null; InputStream in = null; for (Object obj : srcList.getSelectedValues()) { LineParser l = (LineParser) obj; String command = String.format("svn delete \"%s\"", l.file); System.out.println(command); try { process = Runtime.getRuntime().exec(command); in = process.getInputStream(); for (; in.read() != -1;) ; if (l.file.exists()) { sb.append(l.file.getName() + "\n"); } } catch (IOException e1) { e1.printStackTrace(); sb.append(l.file.getName() + "\n"); } } if (sb.length() > 0) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("error : \n" + sb, "ERROR"); } else { JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("mark delete completed!!", "SUCCESS"); } DefaultListModel model = (DefaultListModel) srcList.getModel(); for (int ii = 0; ii < model.getSize(); ii++) { LineParser l = (LineParser) model.getElementAt(ii); if (!l.file.exists()) { model.remove(ii); ii--; } } } }).show(); } if (!JListUtil.newInstance(srcList).isCorrectMouseClick(evt)) { return; } LineParser lineParser = (LineParser) JListUtil.getLeadSelectionObject(srcList); if (lineParser == null) { return; } Runtime.getRuntime().exec("cmd /c call \"" + lineParser.file + "\""); } }); swingUtil.addAction("srcList.keyPressed", new Action() { public void action(EventObject evt) throws Exception { JListUtil.newInstance(srcList).defaultJListKeyPressed(evt); } }); swingUtil.addAction("outPutList.mouseClicked", new Action() { public void action(EventObject evt) throws Exception { if (!JListUtil.newInstance(outPutList).isCorrectMouseClick(evt)) { return; } } }); swingUtil.addAction("outPutList.keyPressed", new Action() { public void action(EventObject evt) throws Exception { JListUtil.newInstance(outPutList).defaultJListKeyPressed(evt); } }); swingUtil.addAction("outPutDir.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (dir == null) { outputDir = DEFAULT_OUTPUT_DIR; } else { outputDir = dir; } reflushOutputList(); } }); swingUtil.addAction("srcBaseDir.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); Validate.notNull(dir, "src base directory is not correct!"); manualBaseDir = dir; } }); swingUtil.addAction("execute.actionPerformed", new Action() { public void action(EventObject evt) throws Exception { DefaultListModel model = (DefaultListModel) outPutList.getModel(); for (int ii = 0; ii < model.size(); ii++) { OutputFile file = (OutputFile) model.getElementAt(ii); if (!file.destFile.getParentFile().exists()) { file.destFile.getParentFile().mkdirs(); } FileUtil.copyFile(file.srcFile, file.destFile); } JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("copy success!!\nsize = " + model.getSize(), getTitle()); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:stockit.Manager.java
/** * Creates new form Trader//w w w. j av a 2 s. com */ public Manager() { initComponents(); try { DefaultListModel demoList = new DefaultListModel(); DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT tc.username" + " FROM trader as t, manager_account as mc," + " trader_account as tc" + " WHERE t.Manager_SSN = mc.Manager_SSN AND tc.Trader_SSN = t.Trader_SSN" + " AND mc.username = \"" + username + "\""); while (rs.next()) { demoList.addElement(rs.getString("username")); } dbcon.con.close(); listOfTraders = new JList(demoList); jScrollPane3.setViewportView(listOfTraders); //setUpTable(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } }