List of usage examples for javax.swing JList JList
public JList()
JList
with an empty, read-only, model. From source file:gtu._work.ui.RegexDirReplacer.java
private void initGUI() { try {/*from ww w . j a v a2s . c om*/ { } 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); jTabbedPane1.addTab("source", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { ListModel srcListModel = new DefaultListModel(); srcList = new JList(); jScrollPane1.setViewportView(srcList); srcList.setModel(srcListModel); { panel = new JPanel(); jScrollPane1.setRowHeaderView(panel); panel.setLayout(new FormLayout( new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); { childrenDirChkbox = new JCheckBox("??"); childrenDirChkbox.setSelected(true); panel.add(childrenDirChkbox, "1, 1"); } { subFileNameText = new JTextField(); panel.add(subFileNameText, "1, 2, fill, default"); subFileNameText.setColumns(10); subFileNameText.setText("(txt|java)"); } { replaceOldFileChkbox = new JCheckBox(""); replaceOldFileChkbox.setSelected(true); panel.add(replaceOldFileChkbox, "1, 3"); } { charsetText = new JTextField(); panel.add(charsetText, "1, 5, fill, default"); charsetText.setColumns(10); charsetText.setText("UTF8"); } } srcList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JListUtil.newInstance(srcList).defaultMouseClickOpenFile(evt); JPopupMenuUtil.newInstance(srcList).applyEvent(evt)// .addJMenuItem("load files from clipboard", new ActionListener() { public void actionPerformed(ActionEvent arg0) { String content = ClipboardUtil.getInstance().getContents(); DefaultListModel model = (DefaultListModel) srcList.getModel(); StringTokenizer tok = new StringTokenizer(content, "\t\n\r\f", false); for (; tok.hasMoreElements();) { String val = ((String) tok.nextElement()).trim(); model.addElement(new File(val)); } } }).show(); } }); srcList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(srcList).defaultJListKeyPressed(evt); } }); } } { addDirFiles = new JButton(); jPanel1.add(addDirFiles, BorderLayout.NORTH); addDirFiles.setText("add dir files"); addDirFiles.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null || !file.isDirectory()) { return; } List<File> fileLst = new ArrayList<File>(); String subName = StringUtils.trimToEmpty(subFileNameText.getText()); if (StringUtils.isBlank(subName)) { subName = ".*"; } String patternStr = ".*\\." + subName; if (childrenDirChkbox.isSelected()) { FileUtil.searchFileMatchs(file, patternStr, fileLst); } else { for (File f : file.listFiles()) { if (f.isFile() && f.getName().matches(patternStr)) { fileLst.add(f); } } } DefaultListModel model = new DefaultListModel(); for (File f : fileLst) { model.addElement(f); } srcList.setModel(model); } }); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("param", null, jPanel2, null); { exeucte = new JButton(); jPanel2.add(exeucte, BorderLayout.SOUTH); exeucte.setText("exeucte"); exeucte.setPreferredSize(new java.awt.Dimension(491, 125)); exeucte.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.CENTER); { repFromText = new JTextField(); } { repToText = new JTextField(); } jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup() .addContainerGap(25, 25) .addGroup(jPanel3Layout.createParallelGroup() .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repFromText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repToText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(repFromText, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(repToText, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { prop.put(repFromText.getText(), repToText.getText()); reloadTemplateList(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); { ListModel newRepListModel = new DefaultListModel(); newRepList = new JList(); jScrollPane2.setViewportView(newRepList); newRepList.setModel(newRepListModel); newRepList.addMouseListener(new MouseAdapter() { static final String tortoiseMergeExe = "TortoiseMerge.exe"; static final String commandFormat = "cmd /c call \"%s\" /base:\"%s\" /theirs:\"%s\""; public void mouseClicked(MouseEvent evt) { if (!JListUtil.newInstance(newRepList).isCorrectMouseClick(evt)) { return; } OldNewFile oldNewFile = (OldNewFile) JListUtil .getLeadSelectionObject(newRepList); String base = oldNewFile.newFile.getAbsolutePath(); String theirs = oldNewFile.oldFile.getAbsolutePath(); String command = String.format(commandFormat, tortoiseMergeExe, base, theirs); System.out.println(command); try { Runtime.getRuntime().exec(command); } catch (IOException e) { JCommonUtil.handleException(e); } } }); newRepList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { Object[] objects = (Object[]) newRepList.getSelectedValues(); if (objects == null || objects.length == 0) { return; } DefaultListModel model = (DefaultListModel) newRepList.getModel(); int lastIndex = model.getSize() - 1; Object swap = null; StringBuilder dsb = new StringBuilder(); for (Object current : objects) { int index = model.indexOf(current); switch (evt.getKeyCode()) { case 38:// up if (index != 0) { swap = model.getElementAt(index - 1); model.setElementAt(swap, index); model.setElementAt(current, index - 1); } break; case 40:// down if (index != lastIndex) { swap = model.getElementAt(index + 1); model.setElementAt(swap, index); model.setElementAt(current, index + 1); } break; case 127:// del OldNewFile current_ = (OldNewFile) current; dsb.append(current_.newFile.getName() + "\t" + (current_.newFile.delete() ? "T" : "F") + "\n"); current_.newFile.delete(); model.removeElement(current); } } if (dsb.length() > 0) { JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("del result!\n" + dsb, "DELETE"); } } }); } } { replaceOrignFile = new JButton(); jPanel4.add(replaceOrignFile, BorderLayout.SOUTH); replaceOrignFile.setText("replace orign file"); replaceOrignFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { DefaultListModel model = (DefaultListModel) newRepList.getModel(); StringBuilder sb = new StringBuilder(); for (int ii = 0; ii < model.size(); ii++) { OldNewFile file = (OldNewFile) model.getElementAt(ii); boolean delSuccess = false; boolean renameSuccess = false; if (delSuccess = file.oldFile.delete()) { renameSuccess = file.newFile.renameTo(file.oldFile); } sb.append(file.oldFile.getName() + " del:" + (delSuccess ? "T" : "F") + " rename:" + (renameSuccess ? "T" : "F") + "\n"); } JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(sb, getTitle()); } }); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jTabbedPane1.addTab("template", null, jPanel5, null); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); { templateList = new JList(); reloadTemplateList(); jScrollPane3.setViewportView(templateList); templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } Entry<Object, Object> entry = (Entry<Object, Object>) JListUtil .getLeadSelectionObject(templateList); repFromText.setText((String) entry.getKey()); repToText.setText((String) entry.getValue()); } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); } } { scheduleExecute = new JButton(); jPanel5.add(scheduleExecute, BorderLayout.SOUTH); scheduleExecute.setText("schedule execute"); scheduleExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scheduleExecuteActionPerformed(evt); } }); } } } this.setSize(512, 350); JCommonUtil.setFontAll(this.getRootPane()); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (StringUtils.isNotBlank(repFromText.getText())) { prop.put(repFromText.getText(), repToText.getText()); } try { prop.store(new FileOutputStream(propFile), "regexText"); } catch (Exception e) { JCommonUtil.handleException("properties store error!", e); } setVisible(false); dispose(); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
JPanel createMoviehitsList() { /* Movies List panel...*/ JPanel panelMoviesList = new JPanel(); panelMoviesList.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-movie-list.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(5, 5, 5, 5))); listMovies = new JList() { public String getToolTipText(MouseEvent e) { if (getCellBounds(0, 0) == null) return null; String retVal = null; int row = (int) e.getPoint().getY() / (int) getCellBounds(0, 0).getHeight(); if (row >= 0 && row < getModel().getSize() && getMoviesList().getModel().getElementAt(row) instanceof ModelIMDbSearchHit) { retVal = ((ModelIMDbSearchHit) getMoviesList().getModel().getElementAt(row)).getAka(); if (retVal != null && retVal.trim().equals("")) //$NON-NLS-1$ retVal = null;/* w w w.j a va2s. c o m*/ } return retVal; } public JToolTip createToolTip() { JMultiLineToolTip tooltip = new JMultiLineToolTip(); tooltip.setComponent(this); return tooltip; } }; // Unfortunately setting tooltip timeout affects ALL tooltips ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.registerComponent(listMovies); ttm.setInitialDelay(0); ttm.setReshowDelay(0); listMovies.setFixedCellHeight(18); listMovies.setFont(new Font(listMovies.getFont().getName(), Font.PLAIN, listMovies.getFont().getSize())); listMovies.setLayoutOrientation(JList.VERTICAL); listMovies.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMovies.setCellRenderer(new MovieHitListCellRenderer()); listMovies.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // Open we page if (SwingUtilities.isRightMouseButton(event)) { int index = listMovies.locationToIndex(event.getPoint()); if (index >= 0) { ModelIMDbSearchHit hit = (ModelIMDbSearchHit) listMovies.getModel().getElementAt(index); if (hit.getUrlID() != null && !hit.getUrlID().equals("")) { BrowserOpener opener = new BrowserOpener(hit.getCompleteUrl()); opener.executeOpenBrowser(MovieManager.getConfig().getSystemWebBrowser(), MovieManager.getConfig().getBrowserPath()); } } } else if (SwingUtilities.isLeftMouseButton(event) && event.getClickCount() >= 2) { buttonSelect.doClick(); } } }); KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); ActionListener listKeyBoardActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { log.debug("ActionPerformed: " + "Movielist - ENTER pressed."); //$NON-NLS-1$ buttonSelect.doClick(); } }; listMovies.registerKeyboardAction(listKeyBoardActionListener, enterKeyStroke, JComponent.WHEN_FOCUSED); JScrollPane scrollPaneMovies = new JScrollPane(listMovies); scrollPaneMovies.setAutoscrolls(true); //scrollPaneMovies.registerKeyboardAction(listKeyBoardActionListener,enterKeyStroke, JComponent.WHEN_FOCUSED); panelMoviesList.setLayout(new BorderLayout()); panelMoviesList.add(scrollPaneMovies, BorderLayout.CENTER); return panelMoviesList; }
From source file:gtu._work.ui.RegexTestUI.java
private void initGUI() { try {//from w ww . j a v a 2s . c o m DocumentListener docListener = JCommonUtil.getDocumentListener(new HandleDocumentEvent() { public void process(DocumentEvent event) { jText1OrJArea1Change(event); } }); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { jText1OrJArea1Change(null); } }); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { 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); srcArea.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(srcArea); srcArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { jText1OrJArea1Change(null); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("group", null, jPanel2, null); { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(398, 234)); { ListModel groupListModel = new DefaultComboBoxModel(); groupList = new JList(); jScrollPane2.setViewportView(groupList); groupList.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); groupList.setModel(groupListModel); JCommonUtil.setFont(groupList); } } { regexText0 = new JTextField(); jPanel2.add(regexText0, BorderLayout.NORTH); regexText0.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(regexText0); regexText0.getDocument().addDocumentListener(docListener); } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("scanner", null, jPanel3, null); { jScrollPane3 = new JScrollPane(); jPanel3.add(jScrollPane3, BorderLayout.CENTER); { ListModel scannerListModel = new DefaultComboBoxModel(); scannerList = new JList(); jScrollPane3.setViewportView(scannerList); scannerList.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); scannerList.setModel(scannerListModel); JCommonUtil.setFont(scannerList); } } { regexText = new JTextField(); jPanel3.add(regexText, BorderLayout.NORTH); regexText.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(regexText); regexText.getDocument().addDocumentListener(docListener); } } } this.setTitle("\u6b63\u5247\u8868\u793a\u5f0f"); this.setSize(419, 320); } catch (Exception e) { e.printStackTrace(); } }
From source file:dpcs.UninstallSystemApps.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public UninstallSystemApps() { setResizable(false);// w w w.jav a2 s. c o m setTitle("Uninstall System Apps"); setIconImage( Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 482, 475); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel AppStatus = new JLabel(""); AppStatus.setBounds(12, 393, 456, 17); contentPane.add(AppStatus); SystemAppUninstallDone = new JLabel(""); SystemAppUninstallDone.setBounds(151, 312, 186, 56); contentPane.add(SystemAppUninstallDone); JLabel lblSelect = new JLabel("Select an app to remove"); lblSelect.setBounds(26, 12, 405, 17); contentPane.add(lblSelect); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 41, 428, 259); contentPane.add(scrollPane); final JButton btnUninstall = new JButton("Uninstall"); btnUninstall.setToolTipText("Uninstall the selected app"); btnUninstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SystemAppUninstallDone.setText(""); if (list.getSelectedValue() == null) { JOptionPane.showMessageDialog(null, "Please select an app first"); } else { try { AppStatus.setText("Uninstalling..."); Process p1 = Runtime.getRuntime().exec("adb remount"); p1.waitFor(); String[] commands = new String[3]; commands[0] = "adb shell su -c rm -r "; commands[1] = "/system/app/"; commands[2] = " " + list.getSelectedValue(); Process p2 = Runtime.getRuntime().exec(commands, null); p2.waitFor(); Process p3 = Runtime.getRuntime() .exec("adb shell ls /system/app/ > /sdcard/.systemapps.txt"); p3.waitFor(); Process p4 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt"); p4.waitFor(); Process p5 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt"); p5.waitFor(); lines = IOUtils.readLines(new FileInputStream(".systemapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".systemapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } AppStatus.setText("App has been uninstalled successfully"); SystemAppUninstallDone .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png"))); btnUninstall.setSelected(false); } catch (Exception e1) { System.err.println(e1); } } } }); btnUninstall.setBounds(26, 327, 107, 27); contentPane.add(btnUninstall); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime().exec("adb shell ls /system/app/ > /sdcard/.systemapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".systemapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".systemapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(344, 327, 107, 27); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell ls /system/app/ > /sdcard/.systemapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.systemapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.systemapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".systemapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); JLabel lblNewLabel = new JLabel("Note: You should also remove app's odex file if it exists"); lblNewLabel.setBounds(25, 374, 438, 17); contentPane.add(lblNewLabel); JLabel label = new JLabel("Needs root and does not work on production android builds!"); label.setBounds(25, 413, 454, 17); contentPane.add(label); File file = new File(".systemapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e) { System.err.println(e); } }
From source file:dpcs.UninstallPrivApps.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public UninstallPrivApps() { setResizable(false);// ww w . ja v a2 s .com setTitle("Uninstall Priv-apps"); setIconImage( Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 482, 500); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel AppStatus = new JLabel(""); AppStatus.setBounds(8, 404, 456, 17); contentPane.add(AppStatus); PrivAppUninstallDone = new JLabel(""); PrivAppUninstallDone.setText(""); PrivAppUninstallDone.setBounds(151, 312, 186, 56); contentPane.add(PrivAppUninstallDone); JLabel lblSelect = new JLabel("Select an app to remove"); lblSelect.setBounds(25, 12, 405, 17); contentPane.add(lblSelect); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 41, 428, 259); contentPane.add(scrollPane); final JButton btnUninstall = new JButton("Uninstall"); btnUninstall.setToolTipText("Uninstall the selected app"); btnUninstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PrivAppUninstallDone.setText(""); if (list.getSelectedValue() == null) { JOptionPane.showMessageDialog(null, "Please select an app first"); } else { try { AppStatus.setText("Uninstalling..."); Process p1 = Runtime.getRuntime().exec("adb remount"); p1.waitFor(); String[] commands = new String[3]; commands[0] = "adb shell su -c rm -r"; commands[1] = "/system/priv-app/"; commands[2] = " " + list.getSelectedValue(); Process p2 = Runtime.getRuntime().exec(commands, null); p2.waitFor(); Process p3 = Runtime.getRuntime() .exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p3.waitFor(); Process p4 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p4.waitFor(); Process p5 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p5.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } AppStatus.setText("App has been uninstalled successfully"); PrivAppUninstallDone .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png"))); btnUninstall.setSelected(false); } catch (Exception e1) { System.err.println(e1); } } } }); btnUninstall.setBounds(26, 327, 107, 27); contentPane.add(btnUninstall); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime() .exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(344, 327, 107, 27); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell ls /system/priv-app/ > /sdcard/.privapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.privapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.privapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".privapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return values.length; } public Object getElementAt(int index) { return values[index]; } }); scrollPane.setViewportView(list); JLabel lblNewLabel = new JLabel("Note: You should also remove app's odex file if it exits "); lblNewLabel.setBounds(25, 374, 438, 17); contentPane.add(lblNewLabel); JLabel lblNeedsRootAnd = new JLabel("Needs root and does not work on production android builds!"); lblNeedsRootAnd.setBounds(25, 426, 454, 17); contentPane.add(lblNeedsRootAnd); JLabel lblOnlyForAndroid = new JLabel("Uninstallation only for android 4.4.x and higher!"); lblOnlyForAndroid.setBounds(8, 452, 450, 15); contentPane.add(lblOnlyForAndroid); File file = new File(".privapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e) { System.err.println(e); } }
From source file:gtu._work.ui.CheckJavaClassPathUI.java
private void initGUI() { try {/*from w w w .jav a 2 s. c o m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); setTitle("??importjava"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("", null, jPanel1, null); { classPathText = new JTextField(); jPanel1.add(classPathText, BorderLayout.NORTH); classPathText.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (StringUtils.isNotBlank(classPathText.getText())) { String text = classPathText.getText(); DefaultListModel model = (DefaultListModel) classPathList.getModel(); boolean findOk = false; for (int ii = 0; ii < model.size(); ii++) { String val = (String) model.getElementAt(ii); if (StringUtils.equals(val, text)) { findOk = true; } } if (!findOk) { model.addElement(text); } } } }); } { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(492, 302)); { DefaultListModel classPathListModel = new DefaultListModel(); classPathList = new JList(); Set<String> clzSet = new HashSet<String>(); for (Enumeration<?> enu = configBean.getConfigProp().keys(); enu.hasMoreElements();) { String key = (String) enu.nextElement(); if (key.contains(CLASSNAME_KEY)) { clzSet.add(configBean.getConfigProp().getProperty(key)); } } for (String clzName : clzSet) { classPathListModel.addElement(clzName); } jScrollPane1.setViewportView(classPathList); classPathList.setModel(classPathListModel); classPathList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(classPathList).defaultJListKeyPressed(evt); } }); } } { executeBtn = new JButton(); jPanel1.add(executeBtn, BorderLayout.WEST); executeBtn.setText("\u57f7\u884c"); executeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { executeBtnActionPerformed(evt); } }); } { srcPathText = new JTextField(); if (configBean.getConfigProp().containsKey(SRCPATHTEXT_KEY)) { srcPathText.setText(configBean.getConfigProp().getProperty(SRCPATHTEXT_KEY)); } jPanel1.add(srcPathText, BorderLayout.SOUTH); JCommonUtil.jTextFieldSetFilePathMouseEvent(srcPathText, true); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("log", null, jPanel2, null); { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(530, 350)); { logArea = new JTextArea(); jScrollPane2.setViewportView(logArea); } } } } pack(); this.setSize(551, 417); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:dpcs.UninstallUserApps.java
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) public UninstallUserApps() { setResizable(false);//from w w w. j a v a 2s . co m setTitle("Uninstall User Apps"); setIconImage( Toolkit.getDefaultToolkit().getImage(UninstallSystemApps.class.getResource("/graphics/Icon.png"))); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 482, 430); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel AppStatus = new JLabel(""); AppStatus.setBounds(12, 366, 456, 17); contentPane.add(AppStatus); UserAppUninstallDone = new JLabel(""); UserAppUninstallDone.setText(""); UserAppUninstallDone.setBounds(151, 312, 186, 56); contentPane.add(UserAppUninstallDone); JLabel lblSelect = new JLabel("Select an app to remove"); lblSelect.setBounds(26, 12, 405, 17); contentPane.add(lblSelect); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(22, 41, 428, 259); contentPane.add(scrollPane); final JButton btnUninstall = new JButton("Uninstall"); btnUninstall.setToolTipText("Uninstall the selected app"); btnUninstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { UserAppUninstallDone.setText(""); if (list.getSelectedValue() == null) { JOptionPane.showMessageDialog(null, "Please select an app first"); } else { try { AppStatus.setText("Uninstalling..."); String[] commands = new String[3]; commands[0] = "adb"; commands[1] = "uninstall"; commands[2] = "" + list.getSelectedValue(); Process p1 = Runtime.getRuntime().exec(commands, null); p1.waitFor(); Process p2 = Runtime.getRuntime() .exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p3.waitFor(); Process p4 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p4.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } AppStatus.setText("App has been uninstalled successfully"); UserAppUninstallDone .setIcon(new ImageIcon(Interface.class.getResource("/graphics/Smalldone.png"))); btnUninstall.setSelected(false); } catch (Exception e1) { System.err.println(e1); } } } }); btnUninstall.setBounds(26, 327, 107, 27); contentPane.add(btnUninstall); JButton btnRefresh = new JButton("Refresh"); btnRefresh.setToolTipText("Refresh the apps list"); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } } }); btnRefresh.setBounds(344, 327, 107, 27); contentPane.add(btnRefresh); try { Process p1 = Runtime.getRuntime().exec("adb shell pm list packages -3 > /sdcard/.userapps.txt"); p1.waitFor(); Process p2 = Runtime.getRuntime().exec("adb pull /sdcard/.userapps.txt"); p2.waitFor(); Process p3 = Runtime.getRuntime().exec("adb shell rm /sdcard/.userapps.txt"); p3.waitFor(); lines = IOUtils.readLines(new FileInputStream(".userapps.txt")); values = new String[lines.size()]; values = lines.toArray(values); moddedvalues = new String[values.length]; for (int i = 0; i < values.length; i++) { moddedvalues[i] = values[i].substring(8); } list = new JList(); list.setModel(new AbstractListModel() { public int getSize() { return moddedvalues.length; } public Object getElementAt(int index) { return moddedvalues[index]; } }); scrollPane.setViewportView(list); File file = new File(".userapps.txt"); if (file.exists() && !file.isDirectory()) { file.delete(); } } catch (Exception e1) { System.err.println(e1); } }
From source file:gtu._work.ui.JarFinderUI.java
private void initGUI() { try {//w w w . j ava 2s . co m BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setTitle("Jar finder"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("src dir", null, jPanel1, null); { openDir = new JButton(); jPanel1.add(openDir, BorderLayout.NORTH); openDir.setText("open dir"); openDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(406, 255)); { DefaultListModel jList1Model = new DefaultListModel(); try { prop.load(new FileInputStream(CONFIG_FILE)); for (Enumeration<?> enu = prop.keys(); enu.hasMoreElements();) { File val = new File((String) enu.nextElement()); jList1Model.addElement(val); } } catch (Exception ex) { JCommonUtil.handleException("??:" + CONFIG_FILE, ex); } jarFileDirs = new JList(); jScrollPane1.setViewportView(jarFileDirs); jarFileDirs.setModel(jList1Model); jarFileDirs.setPreferredSize(new java.awt.Dimension(406, 221)); jarFileDirs.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (!JListUtil.newInstance(jarFileDirs).isCorrectMouseClick(evt)) { return; } File file = (File) JListUtil.getLeadSelectionObject(jarFileDirs); try { Desktop.getDesktop().open(file); } catch (IOException e) { JCommonUtil.handleException(e); } } }); jarFileDirs.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(jarFileDirs).defaultJListKeyPressed(evt); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("result", null, jPanel2, null); { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.NORTH); jPanel3.setPreferredSize(new java.awt.Dimension(406, 26)); { searchText = new JTextField(); jPanel3.add(searchText, BorderLayout.WEST); searchText.setPreferredSize(new java.awt.Dimension(326, 26)); } { search = new JButton(); jPanel3.add(search, BorderLayout.CENTER); search.setText("search"); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton2ActionPerformed(evt); } }); } } { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(406, 231)); { ListModel searchResultModel = new DefaultListModel(); searchResult = new JList(); jScrollPane2.setViewportView(searchResult); searchResult.setModel(searchResultModel); searchResult.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jList1MouseClicked(evt); } }); searchResult.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(searchResult).defaultJListKeyPressed(evt); } }); } } { resetFinder = new JButton(); jPanel2.add(resetFinder, BorderLayout.SOUTH); resetFinder.setText("reset finder"); resetFinder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jarfinder.clear(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("copy to", null, jPanel4, null); { copyToBtn = new JButton(); jPanel4.add(copyToBtn, BorderLayout.NORTH); copyToBtn.setText("copy to"); copyToBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("copy to dir undefined!", getTitle()); return; } else { copyToFile = file; } } }); } { jScrollPane3 = new JScrollPane(); jPanel4.add(jScrollPane3, BorderLayout.CENTER); { DefaultListModel copyToListModel = new DefaultListModel(); copyToList = new JList(); jScrollPane3.setViewportView(copyToList); copyToList.setModel(copyToListModel); { panel = new JPanel(); jTabbedPane1.addTab("config", null, panel, null); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); { lblNewLabel = new JLabel("JD Gui"); panel.add(lblNewLabel, "2, 2, right, default"); } { jdGuiText = new JTextField(); JCommonUtil.jTextFieldSetFilePathMouseEvent(jdGuiText, false); panel.add(jdGuiText, "4, 2, fill, default"); jdGuiText.setColumns(10); } { saveConfigBtn = new JButton(""); saveConfigBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { configBean.reflectSetConfig(JarFinderUI.this); configBean.store(); JCommonUtil._jOptionPane_showMessageDialog_info("?!"); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); panel.add(saveConfigBtn, "2, 24"); } } copyToList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { // copyToFile if (evt.getClickCount() != 2) { return; } if (copyToList.getLeadSelectionIndex() == -1) { return; } if (copyToFile == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("copy to dir undefined!", getTitle()); return; } DefaultListModel model = (DefaultListModel) copyToList.getModel(); Object val = model.getElementAt(copyToList.getLeadSelectionIndex()); StringBuilder sb = new StringBuilder(); sb.append("?\n"); sb.append("file : " + val + "\n"); sb.append("copy to dir : " + copyToFile + "\n"); ComfirmDialogResult result = JOptionPaneUtil.newInstance().confirmButtonYesNo() .showConfirmDialog(sb, getTitle()); File srcFile = new File((String) val); if (!srcFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog(srcFile + " not found!", getTitle()); return; } File copyDestFile = new File(copyToFile, srcFile.getName()); switch (result) { case YES_OK_OPTION: System.out.println("yes.."); try { FileUtil.copyFile(srcFile, copyDestFile); } catch (IOException e) { JCommonUtil.handleException(e.toString(), e); } if (srcFile != null && // copyDestFile != null && // srcFile.length() == copyDestFile.length()) { JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("success!\n" + copyDestFile, getTitle()); } else { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("failed!\n" + copyDestFile, getTitle()); } break; case NO_OPTION: System.out.println("no.."); break; } } }); } } } jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { copyToList.setModel(searchResult.getModel()); } }); } this.setSize(562, 407); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (CONFIG_FILE.exists()) { DefaultListModel model = (DefaultListModel) jarFileDirs.getModel(); for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) { Object obj = enu.nextElement(); prop.setProperty(((File) obj).getAbsolutePath(), ""); } try { prop.store(new FileOutputStream(CONFIG_FILE), "testtesttesttest"); } catch (Exception e) { JCommonUtil.handleException("", e); } } setVisible(false); dispose(); } }); { configBean.reflectInit(this); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gtu._work.etc._3DSMovieRenamer.java
private void initGUI() { try {/*from w ww.j av a 2s . c o m*/ 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(); } }
From source file:gtu._work.ui.QuartzCronTestUI.java
private void initGUI() { try {//from w w w . j a v a2 s .co m BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("CronExpression", null, jPanel1, null); { jPanel2 = new JPanel(); jPanel1.add(jPanel2, BorderLayout.NORTH); jPanel2.setPreferredSize(new java.awt.Dimension(439, 34)); { cronText = new JTextField(); jPanel2.add(cronText); cronText.setText(""); cronText.setPreferredSize(new java.awt.Dimension(229, 27)); } { executeBtn = new JButton(); jPanel2.add(executeBtn); executeBtn.setText("execute"); executeBtn.setPreferredSize(new java.awt.Dimension(85, 28)); executeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //XXX try { CronExpression cexp = new CronExpression(cronText.getText()); Date current = new Date(); setTitle(DateFormatUtils.format(current, "yyyy/MM/dd HH:mm:ss")); DefaultListModel cronListModel = new DefaultListModel(); for (int ii = 0, total = Integer .parseInt(limitText.getText()); ii < total; ii++) { current = cexp.getNextValidTimeAfter(current); if (current == null) { break; } cronListModel.addElement(ii + " : " + DateFormatUtils.format(current, "yyyy/MM/dd HH:mm:ss")); } cronList.setModel(cronListModel); } catch (Exception e) { e.printStackTrace(); JCommonUtil.handleException(e); return; } } }); } { limitText = new JTextField(); jPanel2.add(limitText); limitText.setText("2000"); limitText.setPreferredSize(new java.awt.Dimension(61, 24)); } } { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(439, 253)); { DefaultListModel cronListModel = new DefaultListModel(); cronList = new JList(); jScrollPane1.setViewportView(cronList); cronList.setModel(cronListModel); } } } } pack(); this.setSize(460, 354); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }