Blacklist.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. ==============================================================================
  3. This is an automatically generated GUI class created by the Introjucer!
  4. Be careful when adding custom code to these files, as only the code within
  5. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  6. and re-saved.
  7. Created with Introjucer version: 3.1.1
  8. ------------------------------------------------------------------------------
  9. The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  10. Copyright 2004-13 by Raw Material Software Ltd.
  11. ==============================================================================
  12. */
  13. //[Headers] You can add your own extra header files here...
  14. #include "Constants.h"
  15. //[/Headers]
  16. #include "Blacklist.h"
  17. //[MiscUserDefs] You can add your own user definitions and misc code here...
  18. //[/MiscUserDefs]
  19. //==============================================================================
  20. BlacklistEntry::BlacklistEntry (ValueTree blacklist_store)
  21. : blacklistStore(blacklist_store)
  22. {
  23. //[Constructor_pre] You can add your own custom stuff here..
  24. //[/Constructor_pre]
  25. addAndMakeVisible (removeButton = new TextButton ("removeButton"));
  26. removeButton->setButtonText (TRANS("X"));
  27. removeButton->addListener (this);
  28. removeButton->setColour (TextButton::buttonColourId, Colour (0xff400000));
  29. removeButton->setColour (TextButton::buttonOnColourId, Colours::maroon);
  30. removeButton->setColour (TextButton::textColourOnId, Colours::red);
  31. removeButton->setColour (TextButton::textColourOffId, Colours::red);
  32. addAndMakeVisible (userLabel = new Label ("userLabel",
  33. TRANS("label text")));
  34. userLabel->setFont (Font (15.00f, Font::plain));
  35. userLabel->setJustificationType (Justification::centredLeft);
  36. userLabel->setEditable (false, false, false);
  37. userLabel->setColour (Label::textColourId, Colours::grey);
  38. userLabel->setColour (TextEditor::textColourId, Colours::black);
  39. userLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  40. //[UserPreSize]
  41. //[/UserPreSize]
  42. setSize (132, 16);
  43. //[Constructor] You can add your own custom stuff here..
  44. setSize(GUI::BLACKLIST_ENTRY_W , GUI::BLACKLIST_ENTRY_H) ;
  45. userLabel->setText(STRING(blacklist_store.getType()) , juce::dontSendNotification) ;
  46. //[/Constructor]
  47. }
  48. BlacklistEntry::~BlacklistEntry()
  49. {
  50. //[Destructor_pre]. You can add your own custom destruction code here..
  51. //[/Destructor_pre]
  52. removeButton = nullptr;
  53. userLabel = nullptr;
  54. //[Destructor]. You can add your own custom destruction code here..
  55. //[/Destructor]
  56. }
  57. //==============================================================================
  58. void BlacklistEntry::paint (Graphics& g)
  59. {
  60. //[UserPrePaint] Add your own custom painting code here..
  61. //[/UserPrePaint]
  62. g.setColour (Colours::black);
  63. g.fillRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), 16.0f, 10.000f);
  64. g.setColour (Colours::white);
  65. g.drawRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), 16.0f, 10.000f, 1.000f);
  66. //[UserPaint] Add your own custom painting code here..
  67. //[/UserPaint]
  68. }
  69. void BlacklistEntry::resized()
  70. {
  71. //[UserPreResize] Add your own custom resize code here..
  72. //[/UserPreResize]
  73. removeButton->setBounds (0, 0, 15, 16);
  74. userLabel->setBounds (16, 0, getWidth() - 16, 16);
  75. //[UserResized] Add your own custom resize handling here..
  76. //[/UserResized]
  77. }
  78. void BlacklistEntry::buttonClicked (Button* buttonThatWasClicked)
  79. {
  80. //[UserbuttonClicked_Pre]
  81. //[/UserbuttonClicked_Pre]
  82. if (buttonThatWasClicked == removeButton)
  83. {
  84. //[UserButtonCode_removeButton] -- add your button handler code here..
  85. // destroy storage for this subscription (configures NJClient asynchronously)
  86. this->blacklistStore.getParent().removeChild(this->blacklistStore , nullptr) ;
  87. // destroy this GUI component
  88. ((Blacklist*)this->getParentComponent())->removeBlacklistEntry(this) ;
  89. //[/UserButtonCode_removeButton]
  90. }
  91. //[UserbuttonClicked_Post]
  92. //[/UserbuttonClicked_Post]
  93. }
  94. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  95. Blacklist::Blacklist(ValueTree blacklist_store) : blacklistStore(blacklist_store)
  96. {
  97. this->blacklistStore.addListener(this) ;
  98. for (int user_n = 0 ; user_n < this->blacklistStore.getNumChildren() ; ++user_n)
  99. addAndMakeVisible(new BlacklistEntry(this->blacklistStore.getChild(user_n))) ;
  100. resize() ;
  101. }
  102. Blacklist::~Blacklist() { deleteAllChildren() ; }
  103. void Blacklist::resized()
  104. {
  105. bool is_scrollbar_visible = getHeight() > GUI::BLACKLIST_H ;
  106. int blacklist_entry_w = (is_scrollbar_visible)?
  107. GUI::BLACKLIST_W - GUI::CONFIG_SCROLLBAR_W - GUI::PAD :
  108. GUI::BLACKLIST_W ;
  109. int blacklist_entry_x = 0 ;
  110. int blacklist_entry_y = 0 ;
  111. // resize and arrange user entries
  112. for (int user_n = 0 ; user_n < getNumChildComponents() ; ++user_n)
  113. {
  114. Component* blacklist_entry = getChildComponent(user_n) ;
  115. blacklist_entry->setSize( blacklist_entry_w , GUI::BLACKLIST_ENTRY_H) ;
  116. blacklist_entry->setTopLeftPosition(blacklist_entry_x , blacklist_entry_y ) ;
  117. blacklist_entry_y += GUI::BLACKLIST_ENTRY_H + GUI::PAD ;
  118. }
  119. }
  120. void Blacklist::resize()
  121. {
  122. setSize(GUI::BLACKLIST_W ,
  123. GUI::PAD + (getNumChildComponents() * (GUI::BLACKLIST_ENTRY_H + GUI::PAD))) ;
  124. }
  125. void Blacklist::removeBlacklistEntry(BlacklistEntry* blacklist_entry)
  126. {
  127. delete blacklist_entry ; resize() ;
  128. }
  129. void Blacklist::valueTreeChildAdded(ValueTree& /*parent_node*/ , ValueTree& node)
  130. {
  131. addAndMakeVisible(new BlacklistEntry(node)) ; resize() ;
  132. }
  133. //[/MiscUserCode]
  134. //==============================================================================
  135. #if 0
  136. /* -- Introjucer information section --
  137. This is where the Introjucer stores the metadata that describe this GUI layout, so
  138. make changes in here at your peril!
  139. BEGIN_JUCER_METADATA
  140. <JUCER_COMPONENT documentType="Component" className="BlacklistEntry" componentName=""
  141. parentClasses="public Component" constructorParams="ValueTree blacklist_store"
  142. variableInitialisers="blacklistStore(blacklist_store)" snapPixels="8"
  143. snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="1"
  144. initialWidth="132" initialHeight="16">
  145. <BACKGROUND backgroundColour="0">
  146. <ROUNDRECT pos="0 0 0M 16" cornerSize="10" fill="solid: ff000000" hasStroke="1"
  147. stroke="1, mitered, butt" strokeColour="solid: ffffffff"/>
  148. </BACKGROUND>
  149. <TEXTBUTTON name="removeButton" id="5ea28eb29c334aeb" memberName="removeButton"
  150. virtualName="" explicitFocusOrder="0" pos="0 0 15 16" bgColOff="ff400000"
  151. bgColOn="ff800000" textCol="ffff0000" textColOn="ffff0000" buttonText="X"
  152. connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  153. <LABEL name="userLabel" id="4316b113334d5ced" memberName="userLabel"
  154. virtualName="" explicitFocusOrder="0" pos="16 0 16M 16" textCol="ff808080"
  155. edTextCol="ff000000" edBkgCol="0" labelText="label text" editableSingleClick="0"
  156. editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
  157. fontsize="15" bold="0" italic="0" justification="33"/>
  158. </JUCER_COMPONENT>
  159. END_JUCER_METADATA
  160. */
  161. #endif
  162. //[EndFile] You can add extra defines here...
  163. //[/EndFile]