List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:org.opencastproject.staticfiles.impl.StaticFileServiceImpl.java
@Override public String storeFile(String filename, InputStream inputStream) throws IOException { notNull(filename, "filename"); notNull(inputStream, "inputStream"); final String uuid = UUID.randomUUID().toString(); final String org = securityService.getOrganization().getId(); Path file = getTemporaryStorageDir(org).resolve(Paths.get(uuid, filename)); try (ProgressInputStream progressInputStream = new ProgressInputStream(inputStream)) { progressInputStream.addPropertyChangeListener(new PropertyChangeListener() { @Override/*from ww w . ja v a 2 s.c o m*/ public void propertyChange(PropertyChangeEvent evt) { long totalNumBytesRead = (Long) evt.getNewValue(); long oldTotalNumBytesRead = (Long) evt.getOldValue(); staticFileStatistics.add(totalNumBytesRead - oldTotalNumBytesRead); } }); Files.createDirectories(file.getParent()); Files.copy(progressInputStream, file); } catch (IOException e) { logger.error("Unable to save file '{}' to {} because: {}", new Object[] { filename, file, ExceptionUtils.getStackTrace(e) }); throw e; } return uuid; }
From source file:org.company.processmaker.TreeFilesTopComponent.java
public TreeFilesTopComponent() { initComponents();/*from www . ja v a 2s . c o m*/ setName(Bundle.CTL_TreeFilesTopComponent()); setToolTipText(Bundle.HINT_TreeFilesTopComponent()); // new codes instance = this; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = jTree1.getRowForLocation(e.getX(), e.getY()); TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY()); if (selRow != -1) { if (e.getClickCount() == 1) { //mySingleClick(selRow, selPath); } else if (e.getClickCount() == 2) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1 .getLastSelectedPathComponent(); if (node == null) { return; } Object nodeInfo = node.getUserObject(); int node_level = node.getLevel(); if (node_level < 2) { return; } // for each dyna form if (node_level == 2) { Global gl_obj = Global.getInstance(); //myDoubleClick(selRow, selPath); conf = Config.getInstance(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); String parentName = (String) parent.getUserObject(); // handle triggers if (parentName.equals("Triggers")) { String filePath = ""; for (String[] s : res_trigger) { if (s[0].equals(nodeInfo.toString())) { // get path of dyna in xml forms filePath = conf.tmp + "triggers/" + s[3] + "/" + s[2] + ".php"; break; } } File toAdd = new File(filePath); try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); try { String content = new String( Files.readAllBytes(Paths.get(filePath))); // remote php tag and info "<?php //don't remove this tag! \n" content = content.substring(6, content.length()); String query = "update triggers set TRI_WEBBOT = '" + StringEscapeUtils.escapeSql(content) + "' where TRI_UID = '" + fileName + "'"; GooglePanel.updateQuery(query); } catch (Exception e) { //Exceptions.printStackTrace(e); String msg = "Can not update trigger"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Trigger not found"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } return; } List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(nodeInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //String msg = "selRow" + nodeInfo.toString() + "|" + conf.getXmlForms() + FileDir; String filePath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); filePath = conf.get("local_tmp_for_remote") + "/" + FileDir + "/" + res[1] + ".xml"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } if (conf.isRemote()) { boolean res_Upload = SSH.getInstance().uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not find xml file"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } // for each js file if (node_level == 3) { TreeNode parentInfo = node.getParent(); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(parentInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //myDoubleClick(selRow, selPath); conf = Config.getInstance(); String filePath = conf.tmp + "xmlForms/" + FileDir + "/" + nodeInfo.toString() + ".js"; if (conf.isRemote()) { filePath = conf.get("local_tmp_for_remote") + FileDir + "/" + nodeInfo.toString() + ".js"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { JTextComponent ed = EditorRegistry.lastFocusedComponent(); String jsDoc = ""; try { jsDoc = ed.getText(); } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not get text from editor"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } String fullPath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); fullPath = conf.get("local_tmp_for_remote") + FileDir + "/" + res[1] + ".xml"; } try { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document mainDoc = builder.parse(fullPath); XPath xPath = XPathFactory.newInstance().newXPath(); Node startDateNode = (Node) xPath .compile("//dynaForm/" + fileName) .evaluate(mainDoc, XPathConstants.NODE); Node cdata = mainDoc.createCDATASection(jsDoc); startDateNode.setTextContent(""); startDateNode.appendChild(cdata); /*String msg = evt.getPropertyName() + "-" + fileName; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ // write the content into xml file TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory .newTransformer(); DOMSource source = new DOMSource(mainDoc); StreamResult result = new StreamResult(new File(fullPath)); transformer.transform(source, result); if (conf.isRemote()) { boolean res_Upload = SSH.getInstance() .uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } } }; jTree1.addMouseListener(ml); jTree1.setModel(null); }
From source file:org.photovault.swingui.framework.AbstractController.java
/** * Register an action that can be executed by this controller. * * @param source The source component, this method sets action command and registers the controller as listener. * @param actionCommand The action command, used as a key when registering and executing actions. * @param action An actual action implementation. */// w ww .j av a 2 s . c o m public void registerAction(AbstractButton source, String actionCommand, DefaultAction action) { source.setActionCommand(actionCommand); source.addActionListener(this); this.actions.put(actionCommand, action); final String cmd = actionCommand; final AbstractController ctrl = this; // TODO: Is this really needed??? action.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("enabled")) { fireEvent(new ActionStateChangeEvent(ctrl, cmd, (Boolean) evt.getNewValue())); } } }); }
From source file:EditorPaneExample9.java
public EditorPaneExample9() { super("JEditorPane Example 9"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from w ww . j a va 2 s . co m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(32); panel.add(textField, c); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = textField.getText(); try { // Check if the new page and the old // page are the same. URL newURL = new URL(url); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(newURL)) { return; } // Try to display the page textField.setEnabled(false); // Disable input textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(new URL(url)); loadComplete(); pane.setDocument(doc); displayLoadTime(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); textField.setEnabled(true); setCursor(Cursor.getDefaultCursor()); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); } } }); }
From source file:dk.teachus.frontend.TeachUsApplication.java
private void loadConfiguration() { configuration = getApplicationDAO().loadConfiguration(); configuration.addPropertyListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { getApplicationDAO().saveConfiguration(configuration); }// w ww . j a va 2s. co m }); }
From source file:org.tros.torgo.ControllerBase.java
/** * Initialize the window. This is called here from run() and not the * constructor so that the Service Provider doesn't load up all of the * necessary resources when the application loads. *///from w w w.j a va2 s . c o m private void initSwing() { this.torgoPanel = createConsole((Controller) this); this.torgoCanvas = createCanvas(torgoPanel); //init the GUI w/ the components... Container contentPane = window.getContentPane(); JToolBar tb = createToolBar(); if (tb != null) { contentPane.add(tb, BorderLayout.NORTH); } final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(NamedWindow.class); if (torgoCanvas != null) { final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, torgoCanvas.getComponent(), torgoPanel.getComponent()); int dividerLocation = prefs.getInt(this.getClass().getName() + "divider-location", window.getWidth() - 300); splitPane.setDividerLocation(dividerLocation); splitPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent pce) { prefs.putInt(this.getClass().getName() + "divider-location", splitPane.getDividerLocation()); } }); contentPane.add(splitPane); } else { contentPane.add(torgoPanel.getComponent()); } JMenuBar mb = createMenuBar(); if (mb == null) { mb = new TorgoMenuBar(window, this); } window.setJMenuBar(mb); JMenu helpMenu = new JMenu("Help"); JMenuItem aboutMenu = new JMenuItem("About Torgo"); try { java.util.Enumeration<URL> resources = ClassLoader.getSystemClassLoader() .getResources(ABOUT_MENU_TORGO_ICON); ImageIcon ico = new ImageIcon(resources.nextElement()); aboutMenu.setIcon(ico); } catch (IOException ex) { Logger.getLogger(ControllerBase.class.getName()).log(Level.SEVERE, null, ex); } aboutMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { AboutWindow aw = new AboutWindow(); aw.setVisible(true); } }); helpMenu.add(aboutMenu); JMenu vizMenu = new JMenu("Visualization"); for (String name : TorgoToolkit.getVisualizers()) { JCheckBoxMenuItem item = new JCheckBoxMenuItem(name); viz.add(item); vizMenu.add(item); } if (vizMenu.getItemCount() > 0) { mb.add(vizMenu); } mb.add(helpMenu); window.setJMenuBar(mb); window.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } /** * We only care if the window is closing so we can kill the * interpreter thread. * * @param e */ @Override public void windowClosing(WindowEvent e) { stopInterpreter(); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); }
From source file:org.openvpms.web.component.im.edit.IMTableCollectionEditor.java
/** * Constructs an {@link IMTableCollectionEditor}. * * @param editor the editor/*from www . j a v a 2 s.com*/ * @param object the parent object * @param context the layout context */ public IMTableCollectionEditor(CollectionPropertyEditor editor, IMObject object, LayoutContext context) { super(editor, object, context); context = getContext(); // filter out the "id" field NodeFilter idFilter = new NamedNodeFilter("id"); NodeFilter filter = FilterHelper.chain(idFilter, context.getDefaultNodeFilter()); context.setNodeFilter(filter); componentListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { onComponentChange(event); } }; editorListener = new ModifiableListener() { public void modified(Modifiable modifiable) { onCurrentEditorModified(); } }; }
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
public DialogVisualElement(Lookup lkp) { obj = lkp.lookup(DialogDataObject.class); assert obj != null; undoRedo = new UndoRedo.Manager(); undoRedo.addChangeListener(new ChangeListener() { @Override/*from w w w . j a v a 2 s . com*/ public void stateChanged(ChangeEvent e) { obj.setModified(true); } }); initComponents(); contentPanel = new JPanel() { @Override public void paint(Graphics g) { super.paint(g); for (JComponent c : overlayComponents) { c.setBounds(this.getBounds()); c.paint(g); } } }; contentPanel.setLayout(new VerticalFlowLayout(GAP_Y * 2)); contentPanel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (!e.isConsumed()) { requestFocus(); callback.requestActive(); } } }); personsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { personsListSelectionEvent(); } }); removeButton.setEnabled(false); Action editNames = new EditListAction(); ListAction ls = new ListAction(personsList, editNames); personsList.getModel().addListDataListener(new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { updatePersons(); } @Override public void intervalRemoved(ListDataEvent e) { updatePersons(); } @Override public void contentsChanged(ListDataEvent e) { updatePersons(); } }); setupVisuals(); contentParent = new JPanel(); contentParent.setLayout(new BorderLayout()); // contentPanel.setBounds(contentPanel.getBounds()); // contentParent.setBounds(contentPanel.getBounds()); contentParent.add(contentPanel); scrollPane.setViewportView(contentParent); jumpListener = new JumpListener(this); dropListener = new DropListener(this); DropTarget dt = new DropTarget(contentParent, dropListener); contentParent.setDropTarget(dt); obj.getPrimaryFile().addFileChangeListener(new FileChangeAdapter() { @Override public void fileChanged(FileEvent fe) { refresh(); } }); obj.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && callback != null) { if (obj.isModified()) { callback.updateTitle("<html><b>" + obj.getName() + "</b></html>"); } else { callback.updateTitle("<html>" + obj.getName() + "</html>"); } } } }); }
From source file:com.anrisoftware.prefdialog.fields.filechooser.FileChooserField.java
/** * @see FileChooserFieldFactory#create(Object, String) *//*w ww. ja v a 2 s . co m*/ @Inject FileChooserField(FileChooserFieldLogger logger, UiPanel panel, FileTextField fileTextField, OpenDialogAction openDialogAction, @Assisted Object parentObject, @Assisted String fieldName) { super(panel, parentObject, fieldName); this.panel = panel; this.log = logger; this.fileTextField = fileTextField; this.openDialogAction = openDialogAction; this.fileListener = lockedVetoableChangeListener(new VetoableChangeListener() { @Override public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { try { fileListener.lock(); setValue(evt.getNewValue()); } finally { fileListener.unlock(); } } }); this.fileTextFieldValueListener = lockedPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { try { setValue(evt.getNewValue()); } catch (PropertyVetoException e) { } } }); this.fileAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { setValue(FileChooserField.this.fileTextField.getValue()); } catch (PropertyVetoException e1) { } } }; setupPanel(); }
From source file:com.jwrapper.maven.java.JavaDownloadMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { try {//from www .j a va2 s. co m setupNonVerifingSSL(); final String javaRemoteURL = javaRemoteURL(); final String javaLocalURL = javaLocalURL(); logger().info("javaRemoteURL: {}", javaRemoteURL); logger().info("javaLocalURL : {}", javaLocalURL); final File file = new File(javaLocalURL()); if (!javaEveryTime() && file.exists()) { logger().info("Java artifact is present, skip download."); return; } else { logger().info("Java artifact is missing, make download."); } file.getParentFile().mkdirs(); /** Oracle likes redirects. */ HttpURLConnection connection = connection(javaRemoteURL()); while (connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) { connection = connection(connection.getHeaderField("Location")); logger().info("redirect: {}", connection); } final ProgressInputStream input = new ProgressInputStream(connection.getInputStream(), connection.getContentLengthLong()); final PropertyChangeListener listener = new PropertyChangeListener() { long current = System.currentTimeMillis(); @Override public void propertyChange(final PropertyChangeEvent event) { if (System.currentTimeMillis() - current > 1000) { current = System.currentTimeMillis(); logger().info("progress: {}", event.getNewValue()); } } }; input.addPropertyChangeListener(listener); final OutputStream output = new FileOutputStream(file); IOUtils.copy(input, output); IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); if (file.length() < 1000 * 1000) { throw new IllegalStateException("Download failure."); } logger().info("Java artifact downloaded: {} bytes.", file.length()); } catch (final Throwable e) { logger().error("", e); throw new MojoExecutionException("", e); } }