List of usage examples for javax.swing SwingWorker SwingWorker
public SwingWorker()
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
/** * ??dll//from ww w.j a v a 2s . c om */ private void downDlls() { showWaitPanel("?......"); new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { if (!folder.exists()) { folder.mkdirs(); } if (file1.exists()) { file1.delete(); } if (file2.exists()) { file2.delete(); } if (file3.exists()) { file3.delete(); } if (file4.exists()) { file4.delete(); } HrmBiz.getInstance().downloadFile(file1.getPath(), "/download/potevio/cardapi3.dll"); HrmBiz.getInstance().downloadFile(file2.getPath(), "/download/potevio/license.dat"); HrmBiz.getInstance().downloadFile(file3.getPath(), "/download/potevio/sdtapi.dll"); HrmBiz.getInstance().downloadFile(file4.getPath(), "/download/potevio/WltRS.dll"); return null; } @Override protected void done() { try { get(); hideWaitPanel(); } catch (Exception e) { hideWaitPanel(); showErrorMsg(e); } } }.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
private void startRead() { new SwingWorker<String, Void>() { @Override// w ww . ja v a 2 s. c o m protected String doInBackground() throws Exception { int result; IdCard idCard = new IdCard(); String photoPath = System.getProperty("user.dir") + "/temp/" + "idCard.bmp"; WString imageFile = new WString(photoPath); result = IdCardLibrary.INSTANCE.OpenCardReader(0, 4, 115200); if (result != 0) { showErrorMsg(IdCard.getErrorMsg(result)); return null; } try { result = IdCardLibrary.INSTANCE.GetPersonMsgW(idCard, imageFile); if (result == 0) { uiName.setText(idCard.getName()); uiNamePy.setText(PinyinUtil.getPinpin(idCard.getName())); uiIdCard.setText(idCard.getCardId()); uiGender.setText(idCard.getSex()); uiBirthday.setText(idCard.getBirthday()); uiAge.setText(Integer.toString(Utils.getAge(idCard.getBirthday()))); uiCensusAddress.setText(idCard.getAddress()); RenderedImage imgOri = ImageIO.read(new File(photoPath)); File imgFile = File.createTempFile("photo_", ".png", new File(System.getProperty("user.dir") + "/temp")); ImageIO.write(imgOri, "png", imgFile); uiPhoto.setImage(imgFile.getPath()); uiPhoto.putClientProperty("path", imgFile.getPath()); FileImageInputStream fiis = new FileImageInputStream(new File(imgFile.getPath())); byte[] photoByte = new byte[(int) fiis.length()]; fiis.read(photoByte); fiis.flush(); fiis.close(); uiPhoto.putClientProperty("photo", photoByte); IdCardLibrary.INSTANCE.CloseCardReader(); } Thread.sleep(1000); } catch (Exception e) { showErrorMsg(e); } return null; } }.execute(); }
From source file:com.xilinx.virtex7.MainScreen.java
private JPanel testPanelItems3() { JPanel panel = new JPanel(); panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); /*panel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Test Parameters-1"), BorderFactory.createEmptyBorder()));*/ float w = (float) ((float) width * 0.4); //panel.setPreferredSize(new Dimension((int)w, 100)); panel.add(new JLabel("Data Path-3:")); t4_o1 = new JCheckBox("Loopback"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t4_o1.setToolTipText("This loops back software generated traffic at DMA user interface"); else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) t4_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY"); t4_o1.setSelected(true);/*from www . ja v a 2s. c om*/ t4_o1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { t4_o1.setSelected(true); return; } if (t4_o1.isSelected()) { // disable others test4_option = DriverInfo.ENABLE_LOOPBACK; t4_o2.setSelected(false); t4_o3.setSelected(false); } else { if (!t4_o2.isSelected() && !t4_o3.isSelected()) { test4_option = DriverInfo.CHECKER; t4_o2.setSelected(true); } } } }); //b1.setSelected(true); t4_o2 = new JCheckBox("HW Checker"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t4_o2.setToolTipText( "This enables Checker in hardware at DMA user interface verifying traffic generated by software"); t4_o2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (t4_o2.isSelected()) { // disable others test4_option = DriverInfo.CHECKER; t4_o1.setSelected(false); //t2_o3.setSelected(false); if (t4_o3.isSelected()) test4_option = DriverInfo.CHECKER_GEN; } else { if (t4_o3.isSelected()) test4_option = DriverInfo.GENERATOR; else { test4_option = DriverInfo.ENABLE_LOOPBACK; t4_o1.setSelected(true); } } } }); //b2.setEnabled(false); t4_o3 = new JCheckBox("HW Generator"); if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV) t4_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface"); t4_o3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (t4_o3.isSelected()) { // disable others test4_option = DriverInfo.GENERATOR; t4_o1.setSelected(false); //t2_o2.setSelected(false); if (t4_o2.isSelected()) test4_option = DriverInfo.CHECKER_GEN; } else { if (t4_o2.isSelected()) test4_option = DriverInfo.CHECKER; else { test4_option = DriverInfo.ENABLE_LOOPBACK; t4_o1.setSelected(true); } } } }); //b3.setEnabled(false); JPanel ip = new JPanel(); ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS)); ip.add(t4_o1); ip.add(t4_o2); ip.add(t4_o3); panel.add(ip); panel.add(new JLabel("Packet Size (bytes):")); t4_psize = new JTextField("32768", 5); panel.add(t4_psize); s4test = new JButton("Start"); if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { } else stest.setEnabled(false); s4test.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { //Check for led status and start the test if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF && (lstats.phy2 == LED_ON && lstats.phy3 == LED_ON)) { JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) { JOptionPane.showMessageDialog(null, "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) { JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error", JOptionPane.ERROR_MESSAGE); return; } } if (s4test.getText().equals("Start")) { int psize = 0; dataMismatch6 = errcnt3 = false; try { psize = Integer.parseInt(t4_psize.getText()); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error", JOptionPane.ERROR_MESSAGE); return; } if (psize < minpkt1 || psize > maxpkt1) { JOptionPane.showMessageDialog(null, "Packet size must be within " + minpkt1 + " to " + maxpkt1 + " bytes", "Error", JOptionPane.ERROR_MESSAGE); return; } di.startTest(3, test4_option, psize); t4_o1.setEnabled(false); t4_o2.setEnabled(false); t4_o3.setEnabled(false); t4_o2.setEnabled(false); t4_psize.setEnabled(false); s4test.setText("Stop"); testStarted3 = true; updateLog("[Test Started for Data Path-3]", logStatus); } else if (s4test.getText().equals("Stop")) { // Disable button to avoid multiple clicks s4test.setEnabled(false); SwingWorker worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { stopTest4(); } catch (Exception e) { e.printStackTrace(); } return null; } }; worker.execute(); } } }); panel.add(s4test); if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) { t4_o1.setSelected(false); t4_o2.setSelected(false); t4_o3.setSelected(false); t4_o1.setEnabled(false); t4_o2.setEnabled(false); t4_o3.setEnabled(false); t4_psize.setEnabled(false); t4_psize.setText(""); s4test.setEnabled(false); } return panel; }
From source file:com.mirth.connect.client.ui.Frame.java
public void doShowUsers() { if (userPanel == null) { userPanel = new UserPanel(); }/*from ww w . ja va2s.c o m*/ if (!confirmLeave()) { return; } final String workingId = startWorking("Loading users..."); setBold(viewPane, 2); setPanelName("Users"); setCurrentContentPage(userPanel); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { refreshUser(); return null; } public void done() { setFocus(userTasks); stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
public void doDeleteChannel() { if (isSaveEnabled() && !promptSave(true)) { return;//from w ww. jav a 2 s.c o m } if (isGroupSelected()) { JOptionPane.showMessageDialog(parent, "This operation can only be performed on channels."); return; } final List<Channel> selectedChannels = getSelectedChannels(); if (selectedChannels.size() == 0) { return; } if (!parent.alertOption(parent, "Are you sure you want to delete the selected channel(s)?\nAny selected deployed channel(s) will first be undeployed.")) { return; } final String workingId = parent.startWorking("Deleting channel..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { Set<String> channelIds = new HashSet<String>(selectedChannels.size()); for (Channel channel : selectedChannels) { channelIds.add(channel.getId()); } try { parent.mirthClient.removeChannels(channelIds); } catch (ClientException e) { parent.alertThrowable(parent, e); } return null; } public void done() { doRefreshChannels(); parent.stopWorking(workingId); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.Frame.java
public void doShowSettings() { if (settingsPane == null) { settingsPane = new SettingsPane(); }//w w w . ja v a 2s .c o m if (!confirmLeave()) { return; } final String workingId = startWorking("Loading settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { settingsPane.setSelectedSettingsPanel(0); return null; } public void done() { setBold(viewPane, 3); setPanelName("Settings"); setCurrentContentPage(settingsPane); stopWorking(workingId); } }; worker.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
protected void uiPrintLeaveCertifyActionPerformed(ActionEvent evt) { if (!"?".equals(employee.getState())) { showErrorMsg("???!"); return;/*w w w . j ava2 s . c o m*/ } if (Variables.appUser.haveNoRight("rePrintLeaveCertify") && uiTimeCardLeaveCertify.getText().equals("???")) { showErrorMsg("??????!"); return; } final String[] leaveParams = ChooseLeaveCertifyParams.showDialog(this); if (leaveParams != null && leaveParams.length == 2) { showWaitPanel("??......"); new SwingWorker<JasperPrint, String>() { @Override protected JasperPrint doInBackground() throws Exception { File file = File.createTempFile("report_", ".jasper", new File(System.getProperty("user.dir") + File.separator + "temp")); HrmBiz.getInstance().downloadFile(file.getPath(), "/download/reports/EmpLeaveCertificate.jasper"); String entryDate = UtilsClient.formatDateToCn(employee.getEntryDate()); String printDate = UtilsClient.formatDateToCn(leaveParams[1]); List<Employee> emps = new ArrayList<>(); emps.add(employee); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("leaveReason", leaveParams[0]); parameters.put("declare1", "" + entryDate + "??" + employee.getJob() + "?" + printDate + "??????"); parameters.put("declare2", "" + entryDate + "??" + employee.getJob() + "?" + printDate + "??????"); parameters.put("serverPath", "http://" + UtilsClient.getLocalProp("server") + ":" + UtilsClient.getStaticProp("server_port") + "/HRM_Server"); parameters.put("printDate", printDate); JasperReport jasperReport = (JasperReport) JRLoader.loadObject(file); return JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(emps)); } @Override protected void done() { try { JasperPrint jasperPrint = get(); hideWaitPanel(); LynkReportDialog.showDialog(InfoEmployee.this, jasperPrint); uiTimeCardLeaveCertify.setText("???"); // uiLeaveReason.setText(uiLeaveReason.getText() // + "\n???"); uiSaveActionPerformed(false); } catch (Exception e) { hideWaitPanel(); showErrorMsg(e); } } }.execute(); } }
From source file:com.mirth.connect.client.ui.Frame.java
public void doEditGlobalScripts() { if (globalScriptsPanel == null) { globalScriptsPanel = new GlobalScriptsPanel(); }//from w ww .j a v a2s .c o m final String workingId = startWorking("Loading global scripts..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { globalScriptsPanel.edit(); return null; } public void done() { editGlobalScripts(); stopWorking(workingId); } }; worker.execute(); }
From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java
protected void uiVacationRefreshActionPerformed(ActionEvent evt) { showWaitPanel("......"); new SwingWorker<AttendanceVacation, Void>() { @Override/*from w w w .ja v a 2s . com*/ protected AttendanceVacation doInBackground() throws Exception { AttendanceVacation av = HrmBiz.getInstance().getAttendanceVacationByEmp(uiId.getText()); if (av != null) { List<AttendanceVacationHistory> histories = HrmBiz.getInstance() .getAttendanceVacationHistoriesEmp(uiId.getText()); av.setHistories(histories); } else { av = new AttendanceVacation(); av.setStartDay(""); av.setEndDay(""); av.setLastTotal(0); av.setLastLeft(0); av.setCurrentTotal(0); av.setLeftHours(0); } return av; } @Override protected void done() { try { AttendanceVacation vacation = get(); if (vacation == null || "".equals(vacation.getStartDay())) { uiVacationStartEnd.setText(""); uiCurrentTotal.setText(""); uiLastLeft.setText(""); uiLeftHours.setText(""); } else { uiVacationStartEnd.setText(vacation.getStartDay() + " " + vacation.getEndDay()); uiCurrentTotal.setText(vacation.getCurrentTotal().toString()); uiLastTotal.setText(vacation.getLastTotal().toString()); uiLastLeft.setText(vacation.getLastLeft().toString()); uiLeftHours.setText(vacation.getLeftHours().toString()); if (vacation.getHistories() != null) { attendanceVacationModel.setHistories(vacation.getHistories()); } } hideWaitPanel(); } catch (Exception e) { hideWaitPanel(); showErrorMsg(e); } } }.execute(); }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
public void doEnableChannel() { if (isSaveEnabled() && !promptSave(true)) { return;//ww w . jav a2 s . co m } final List<Channel> selectedChannels = getSelectedChannels(); if (selectedChannels.size() == 0) { parent.alertWarning(parent, "Channel no longer exists."); return; } final Set<String> channelIds = new HashSet<String>(); Set<Channel> failedChannels = new HashSet<Channel>(); String firstValidationMessage = null; for (Iterator<Channel> it = selectedChannels.iterator(); it.hasNext();) { Channel channel = it.next(); String validationMessage = null; if (channel instanceof InvalidChannel) { failedChannels.add(channel); it.remove(); } else if ((validationMessage = parent.channelEditPanel.checkAllForms(channel)) != null) { if (firstValidationMessage == null) { firstValidationMessage = validationMessage; } failedChannels.add(channel); it.remove(); } else { channelIds.add(channel.getId()); } } if (!channelIds.isEmpty()) { final String workingId = parent.startWorking("Enabling channel..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { for (Channel channel : selectedChannels) { channel.setEnabled(true); } try { parent.mirthClient.setChannelEnabled(channelIds, true); } catch (ClientException e) { parent.alertThrowable(parent, e); } return null; } public void done() { doRefreshChannels(); parent.stopWorking(workingId); } }; worker.execute(); } if (!failedChannels.isEmpty()) { if (failedChannels.size() == 1) { Channel channel = failedChannels.iterator().next(); if (channel instanceof InvalidChannel) { InvalidChannel invalidChannel = (InvalidChannel) channel; Throwable cause = invalidChannel.getCause(); parent.alertThrowable(parent, cause, "Channel \"" + invalidChannel.getName() + "\" is invalid and cannot be enabled. " + getMissingExtensions(invalidChannel) + "Original cause:\n" + cause.getMessage()); } else { parent.alertCustomError(parent, firstValidationMessage, CustomErrorDialog.ERROR_ENABLING_CHANNEL); } } else { String message = "The following channels are invalid or not configured properly:\n\n"; for (Channel channel : failedChannels) { message += " " + channel.getName() + " (" + channel.getId() + ")\n"; } parent.alertError(parent, message); } } }