The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-12 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../JuceDemoHeader.h"
  19. //==============================================================================
  20. class NetworkingDemo : public Component,
  21. private Button::Listener
  22. {
  23. public:
  24. NetworkingDemo()
  25. : resultsBox (resultsDocument, nullptr)
  26. {
  27. setOpaque (true);
  28. addAndMakeVisible (&urlBox);
  29. urlBox.setText ("http://www.google.com");
  30. addAndMakeVisible (&fetchButton);
  31. fetchButton.setButtonText ("Download URL Contents");
  32. fetchButton.addListener (this);
  33. addAndMakeVisible (&resultsBox);
  34. }
  35. ~NetworkingDemo()
  36. {
  37. fetchButton.removeListener (this);
  38. }
  39. void paint (Graphics& g) override
  40. {
  41. fillBrushedAluminiumBackground (g);
  42. }
  43. void resized() override
  44. {
  45. Rectangle<int> area (getLocalBounds());
  46. {
  47. Rectangle<int> topArea (area.removeFromTop (40));
  48. fetchButton.setBounds (topArea.removeFromRight (180).reduced (8));
  49. urlBox.setBounds (topArea.reduced (8));
  50. }
  51. resultsBox.setBounds (area.reduced (8));
  52. }
  53. private:
  54. TextEditor urlBox;
  55. TextButton fetchButton;
  56. CodeDocument resultsDocument;
  57. CodeEditorComponent resultsBox;
  58. void downloadUrl()
  59. {
  60. URL url (urlBox.getText());
  61. resultsBox.loadContent (url.readEntireTextStream());
  62. }
  63. void buttonClicked (Button* button) override
  64. {
  65. if (button == &fetchButton)
  66. downloadUrl();
  67. }
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkingDemo)
  69. };
  70. // This static object will register this demo type in a global list of demos..
  71. static JuceDemoType<NetworkingDemo> demo ("40 HTTP");