#include "TStructNodeEditor.h"
#include "TStructNode.h"
#include "TStructNodeProperty.h"
#include <TGColorSelect.h>
#include <TColor.h>
#include <TGNumberEntry.h>
#include <TGLabel.h>
#include <TGTextEntry.h>
#include <TClass.h>
ClassImp(TStructNodeEditor)
TStructNodeEditor::TStructNodeEditor(TList* colors, const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
: TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
{
MakeTitle("TStructNode");
fInit = kFALSE;
TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
fNodeNameLabel = new TGLabel(this, "No node selected");
this->AddFrame(fNodeNameLabel, expandX);
fTypeName = new TGLabel(this);
this->AddFrame(fTypeName, expandX);
TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
maxObjectsFrame->AddFrame(fMaxObjectslabel);
fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
fMaxObjectsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
fMaxObjectsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
fMaxObjectsNumberEntry->SetState(kFALSE);
fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
this->AddFrame(maxObjectsFrame, expandX);
TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
maxLevelFrame->AddFrame(fMaxLevelsLabel);
fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
fMaxLevelsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
fMaxLevelsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
fMaxLevelsNumberEntry->SetState(kFALSE);
fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
this->AddFrame(maxLevelFrame, expandX);
fNameEntry = new TGTextEntry(this, fName.Data());
this->AddFrame(fNameEntry, expandX);
fNameEntry->SetState(kFALSE);
fColorSelect = new TGColorSelect(this);
fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
this->AddFrame(fColorSelect, expandX);
fColorSelect->SetEnabled(kFALSE);
fAutoRefesh = new TGCheckButton(this, "Auto refesh");
fAutoRefesh->SetOn();
fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
fAutoRefesh->SetEnabled(kFALSE);
this->AddFrame(fAutoRefesh, expandX);
fDefaultButton = new TGTextButton(this, "Default color");
fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
this->AddFrame(fDefaultButton, expandX);
fDefaultButton->SetEnabled(kFALSE);
fApplyButton = new TGTextButton(this, "Apply");
fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
fApplyButton->SetEnabled(kFALSE);
this->AddFrame(fApplyButton, expandX);
}
TStructNodeEditor::~TStructNodeEditor()
{
}
void TStructNodeEditor::ApplyButtonSlot()
{
Bool_t needReset = false;
if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
needReset = true;
}
if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
needReset = true;
}
if (fSelectedPropert) {
fSelectedPropert->SetColor(fColorSelect->GetColor());
fSelectedPropert->SetName(fNameEntry->GetText());
}
Update(needReset);
}
void TStructNodeEditor::AutoRefreshButtonSlot(Bool_t on)
{
if (on) {
Update(kTRUE);
}
}
void TStructNodeEditor::ColorSelectedSlot(Pixel_t color)
{
if (fAvoidSignal) {
return;
}
TStructNodeProperty* prop = FindNodeProperty(fNode);
if (prop) {
prop->SetColor(color);
} else {
prop = new TStructNodeProperty(fNode->GetTypeName(), color);
fColors->Add(prop);
fColors->Sort();
fSelectedPropert = prop;
fNameEntry->SetText(fNode->GetTypeName());
}
Update();
}
void TStructNodeEditor::DefaultButtonSlot()
{
if (TStructNodeProperty* prop = FindNodeProperty(fNode)) {
fColors->Remove(prop);
fSelectedPropert = GetDefaultProperty();
fNameEntry->SetText(fSelectedPropert->GetName());
fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
Update();
}
}
TStructNodeProperty* TStructNodeEditor::FindNodeProperty(TStructNode* node)
{
TIter it(fColors);
TStructNodeProperty* prop;
while ((prop = (TStructNodeProperty*) it() )) {
TString propName(prop->GetName());
if (propName.EndsWith("+")) {
if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
propName.Remove(propName.Length()-1, 1);
if (cl->InheritsFrom(propName.Data())) {
return prop;
}
}
} else {
if (propName == TString(node->GetTypeName())) {
return prop;
}
}
}
return NULL;
}
TStructNodeProperty* TStructNodeEditor::GetDefaultProperty()
{
return (TStructNodeProperty*)fColors->Last();
}
void TStructNodeEditor::Init()
{
fMaxObjectsNumberEntry->SetState(kTRUE);
fMaxLevelsNumberEntry->SetState(kTRUE);
fNameEntry->SetState(kTRUE);
fColorSelect->SetEnabled(kTRUE);
fDefaultButton->SetEnabled(kTRUE);
fApplyButton->SetEnabled(kTRUE);
fAutoRefesh->SetEnabled(kTRUE);
fInit = kTRUE;
}
void TStructNodeEditor::MaxLevelsValueSetSlot(Long_t)
{
fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
if(fAutoRefesh->IsOn()) {
Update(kTRUE);
}
}
void TStructNodeEditor::MaxObjectsValueSetSlot(Long_t)
{
fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
if(fAutoRefesh->IsOn()) {
Update(kTRUE);
}
}
void TStructNodeEditor::SetModel(TObject* obj)
{
fNode = dynamic_cast<TStructNode *>(obj);
fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
fTypeName->SetText(fNode->GetTypeName());
fNodeNameLabel->SetText(fNode->GetName());
fSelectedPropert = FindNodeProperty(fNode);
if (!fSelectedPropert)
{
fSelectedPropert = GetDefaultProperty();
}
fNameEntry->SetText(fSelectedPropert->GetName());
fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
if (!fInit) {
Init();
}
}
void TStructNodeEditor::Update()
{
Emit("Update(Bool_t)", false);
}
void TStructNodeEditor::Update(Bool_t resetCamera)
{
Emit("Update(Bool_t)", resetCamera);
}
TStructNodeEditor.cxx:100 TStructNodeEditor.cxx:101 TStructNodeEditor.cxx:102 TStructNodeEditor.cxx:103 TStructNodeEditor.cxx:104 TStructNodeEditor.cxx:105 TStructNodeEditor.cxx:106 TStructNodeEditor.cxx:107 TStructNodeEditor.cxx:108 TStructNodeEditor.cxx:109 TStructNodeEditor.cxx:110 TStructNodeEditor.cxx:111 TStructNodeEditor.cxx:112 TStructNodeEditor.cxx:113 TStructNodeEditor.cxx:114 TStructNodeEditor.cxx:115 TStructNodeEditor.cxx:116 TStructNodeEditor.cxx:117 TStructNodeEditor.cxx:118 TStructNodeEditor.cxx:119 TStructNodeEditor.cxx:120 TStructNodeEditor.cxx:121 TStructNodeEditor.cxx:122 TStructNodeEditor.cxx:123 TStructNodeEditor.cxx:124 TStructNodeEditor.cxx:125 TStructNodeEditor.cxx:126 TStructNodeEditor.cxx:127 TStructNodeEditor.cxx:128 TStructNodeEditor.cxx:129 TStructNodeEditor.cxx:130 TStructNodeEditor.cxx:131 TStructNodeEditor.cxx:132 TStructNodeEditor.cxx:133 TStructNodeEditor.cxx:134 TStructNodeEditor.cxx:135 TStructNodeEditor.cxx:136 TStructNodeEditor.cxx:137 TStructNodeEditor.cxx:138 TStructNodeEditor.cxx:139 TStructNodeEditor.cxx:140 TStructNodeEditor.cxx:141 TStructNodeEditor.cxx:142 TStructNodeEditor.cxx:143 TStructNodeEditor.cxx:144 TStructNodeEditor.cxx:145 TStructNodeEditor.cxx:146 TStructNodeEditor.cxx:147 TStructNodeEditor.cxx:148 TStructNodeEditor.cxx:149 TStructNodeEditor.cxx:150 TStructNodeEditor.cxx:151 TStructNodeEditor.cxx:152 TStructNodeEditor.cxx:153 TStructNodeEditor.cxx:154 TStructNodeEditor.cxx:155 TStructNodeEditor.cxx:156 TStructNodeEditor.cxx:157 TStructNodeEditor.cxx:158 TStructNodeEditor.cxx:159 TStructNodeEditor.cxx:160 TStructNodeEditor.cxx:161 TStructNodeEditor.cxx:162 TStructNodeEditor.cxx:163 TStructNodeEditor.cxx:164 TStructNodeEditor.cxx:165 TStructNodeEditor.cxx:166 TStructNodeEditor.cxx:167 TStructNodeEditor.cxx:168 TStructNodeEditor.cxx:169 TStructNodeEditor.cxx:170 TStructNodeEditor.cxx:171 TStructNodeEditor.cxx:172 TStructNodeEditor.cxx:173 TStructNodeEditor.cxx:174 TStructNodeEditor.cxx:175 TStructNodeEditor.cxx:176 TStructNodeEditor.cxx:177 TStructNodeEditor.cxx:178 TStructNodeEditor.cxx:179 TStructNodeEditor.cxx:180 TStructNodeEditor.cxx:181 TStructNodeEditor.cxx:182 TStructNodeEditor.cxx:183 TStructNodeEditor.cxx:184 TStructNodeEditor.cxx:185 TStructNodeEditor.cxx:186 TStructNodeEditor.cxx:187 TStructNodeEditor.cxx:188 TStructNodeEditor.cxx:189 TStructNodeEditor.cxx:190 TStructNodeEditor.cxx:191 TStructNodeEditor.cxx:192 TStructNodeEditor.cxx:193 TStructNodeEditor.cxx:194 TStructNodeEditor.cxx:195 TStructNodeEditor.cxx:196 TStructNodeEditor.cxx:197 TStructNodeEditor.cxx:198 TStructNodeEditor.cxx:199 TStructNodeEditor.cxx:200 TStructNodeEditor.cxx:201 TStructNodeEditor.cxx:202 TStructNodeEditor.cxx:203 TStructNodeEditor.cxx:204 TStructNodeEditor.cxx:205 TStructNodeEditor.cxx:206 TStructNodeEditor.cxx:207 TStructNodeEditor.cxx:208 TStructNodeEditor.cxx:209 TStructNodeEditor.cxx:210 TStructNodeEditor.cxx:211 TStructNodeEditor.cxx:212 TStructNodeEditor.cxx:213 TStructNodeEditor.cxx:214 TStructNodeEditor.cxx:215 TStructNodeEditor.cxx:216 TStructNodeEditor.cxx:217 TStructNodeEditor.cxx:218 TStructNodeEditor.cxx:219 TStructNodeEditor.cxx:220 TStructNodeEditor.cxx:221 TStructNodeEditor.cxx:222 TStructNodeEditor.cxx:223 TStructNodeEditor.cxx:224 TStructNodeEditor.cxx:225 TStructNodeEditor.cxx:226 TStructNodeEditor.cxx:227 TStructNodeEditor.cxx:228 TStructNodeEditor.cxx:229 TStructNodeEditor.cxx:230 TStructNodeEditor.cxx:231 TStructNodeEditor.cxx:232 TStructNodeEditor.cxx:233 TStructNodeEditor.cxx:234 TStructNodeEditor.cxx:235 TStructNodeEditor.cxx:236 TStructNodeEditor.cxx:237 TStructNodeEditor.cxx:238 TStructNodeEditor.cxx:239 TStructNodeEditor.cxx:240 TStructNodeEditor.cxx:241 TStructNodeEditor.cxx:242 TStructNodeEditor.cxx:243 TStructNodeEditor.cxx:244 TStructNodeEditor.cxx:245 TStructNodeEditor.cxx:246 TStructNodeEditor.cxx:247 TStructNodeEditor.cxx:248 TStructNodeEditor.cxx:249 TStructNodeEditor.cxx:250 TStructNodeEditor.cxx:251 TStructNodeEditor.cxx:252 TStructNodeEditor.cxx:253 TStructNodeEditor.cxx:254 TStructNodeEditor.cxx:255 TStructNodeEditor.cxx:256 TStructNodeEditor.cxx:257 TStructNodeEditor.cxx:258 TStructNodeEditor.cxx:259 TStructNodeEditor.cxx:260 TStructNodeEditor.cxx:261 TStructNodeEditor.cxx:262 TStructNodeEditor.cxx:263 TStructNodeEditor.cxx:264 TStructNodeEditor.cxx:265 TStructNodeEditor.cxx:266 TStructNodeEditor.cxx:267 TStructNodeEditor.cxx:268 TStructNodeEditor.cxx:269 TStructNodeEditor.cxx:270 TStructNodeEditor.cxx:271 TStructNodeEditor.cxx:272 TStructNodeEditor.cxx:273 TStructNodeEditor.cxx:274 TStructNodeEditor.cxx:275 TStructNodeEditor.cxx:276 TStructNodeEditor.cxx:277 TStructNodeEditor.cxx:278 TStructNodeEditor.cxx:279 TStructNodeEditor.cxx:280 TStructNodeEditor.cxx:281 TStructNodeEditor.cxx:282 TStructNodeEditor.cxx:283 TStructNodeEditor.cxx:284 TStructNodeEditor.cxx:285 TStructNodeEditor.cxx:286 TStructNodeEditor.cxx:287 TStructNodeEditor.cxx:288 TStructNodeEditor.cxx:289 TStructNodeEditor.cxx:290 TStructNodeEditor.cxx:291 TStructNodeEditor.cxx:292 TStructNodeEditor.cxx:293 TStructNodeEditor.cxx:294 TStructNodeEditor.cxx:295 TStructNodeEditor.cxx:296 TStructNodeEditor.cxx:297 TStructNodeEditor.cxx:298 TStructNodeEditor.cxx:299 TStructNodeEditor.cxx:300 TStructNodeEditor.cxx:301 TStructNodeEditor.cxx:302 TStructNodeEditor.cxx:303 TStructNodeEditor.cxx:304 TStructNodeEditor.cxx:305