void JPlotFitQuad::JPlotFitQuadX ( J2DPlotWidget* plot, JPlotDataBase* fitData ) { JArray<JIndex> powers; powers.AppendElement(0); powers.AppendElement(1); powers.AppendElement(2); InitializePolynomial(powers); }
JFloat JPlotLinearFit::ChiSqr ( JFloat Bt ) { const JPlotDataBase* data = GetDataToFit(); J2DDataPoint point; const JSize count = data->GetElementCount(); JArray<JFloat> err; JArray<JFloat> W; JFloat temp1; JFloat temp2; JSize i; temp1 = 0; temp2 = 0; for ( i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat sy = point.yerr; if (sy == 0) { sy = 1; } JFloat e = point.xerr * point.xerr * Bt * Bt + sy * sy; err.AppendElement(e); JFloat w = 1/e; W.AppendElement(w); temp1 += w * (point.y - Bt*point.x); temp2 += w; } } itsAParameterT = temp1/temp2; JFloat c = 0; JSize counter = 1; for ( i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat val = point.y - itsAParameterT - Bt*point.x; c += (val*val)/(err.GetElement(counter)); counter++; } } return c;//sqrt(fabs(c)); }
void JXDockDirector::BuildWindow ( const JCharacter* title, const JBoolean splitHoriz ) { const JCoordinate kSize = 300; JArray<JCoordinate> sizes; sizes.AppendElement(kSize); sizes.AppendElement(kSize); JArray<JCoordinate> minSizes; minSizes.AppendElement(JXDockWidget::kDefaultMinSize); minSizes.AppendElement(JXDockWidget::kDefaultMinSize); const JCoordinate w = 2*kSize + (splitHoriz ? JPartition::kDragRegionSize : 0); const JCoordinate h = 2*kSize + (splitHoriz ? 0 : JPartition::kDragRegionSize); JXWindow* window = jnew JXWindow(this, w, h, title); assert( window != NULL ); JXImage* icon; if ((JXGetDockManager())->CreateIcon(&icon)) { window->SetIcon(icon); } if (splitHoriz) { itsHorizPartition = jnew JXHorizDockPartition(this, NULL, sizes, 0, minSizes, window, JXWidget::kHElastic, JXWidget::kVElastic, 0,0, w,h); assert( itsHorizPartition != NULL ); } else { itsVertPartition = jnew JXVertDockPartition(this, NULL, sizes, 0, minSizes, window, JXWidget::kHElastic, JXWidget::kVElastic, 0,0, w,h); assert( itsVertPartition != NULL ); } window->SetMinSize(100,100); window->SetWMClass("Dock", JXGetDockWindowClass()); }
JVariableList::MatchResult JVariableList::FindUniqueVarName ( const JCharacter* prefix, JIndex* index, JString* maxPrefix ) const { assert( !JStringEmpty(prefix) ); const JSize count = GetElementCount(); JArray<JIndex> matchList; for (JIndex i=1; i<=count; i++) { const JString& name = GetVariableName(i); if (name == prefix) { *index = i; *maxPrefix = name; return kSingleMatch; } else if (JStringBeginsWith(name, name.GetLength(), prefix)) { matchList.AppendElement(i); } } const JSize matchCount = matchList.GetElementCount(); if (matchCount == 0) { *index = 0; maxPrefix->Clear(); return kNoMatch; } else if (matchCount == 1) { *index = matchList.GetElement(1); *maxPrefix = GetVariableName(*index); return kSingleMatch; } else { *maxPrefix = GetVariableName( matchList.GetElement(1) ); for (JIndex i=2; i<=matchCount; i++) { const JString& varName = GetVariableName( matchList.GetElement(i) ); const JSize matchLength = JCalcMatchLength(*maxPrefix, varName); const JSize prefixLength = maxPrefix->GetLength(); if (matchLength < prefixLength) { maxPrefix->RemoveSubstring(matchLength+1, prefixLength); } } *index = 0; return kMultipleMatch; } }
void JXTabGroup::ScrollUpToTab ( const JIndex index ) { assert( itsTitles->IndexValid(index) ); assert( index > itsFirstDrawIndex ); const JFontManager* fontMgr = GetFontManager(); const JFontID fontID = fontMgr->GetFontID(itsFontName, itsFontSize, itsFontStyle); const JCoordinate scrollArrowWidth = 2*(kArrowWidth + kBorderWidth); const JRect ap = GetAperture(); const JCoordinate min = (itsEdge == kTop || itsEdge == kBottom ? ap.left : ap.top); const JCoordinate max = (itsEdge == kTop || itsEdge == kBottom ? ap.right : ap.bottom); JCoordinate left = min + kSelMargin; JCoordinate right = left; JArray<JCoordinate> widthList; const JSize count = itsTitles->GetElementCount(); JBoolean offScreen = kJFalse; for (JIndex i=itsFirstDrawIndex; i<=index; i++) { const TabInfo info = itsTabInfoList->GetElement(index); right += 2*kBorderWidth + info.preMargin + info.postMargin + fontMgr->GetStringWidth(fontID, itsFontSize, itsFontStyle, *(itsTitles->NthElement(i))); if (info.closable) { right += kCloseMarginWidth + itsCloseImage->GetWidth(); } widthList.AppendElement(right - left); if (!offScreen && right >= max - scrollArrowWidth && !(itsFirstDrawIndex == 1 && i == count && right <= max)) { offScreen = kJTrue; } left = right; } if (offScreen) { JIndex i = 1; while (right > max - scrollArrowWidth && itsFirstDrawIndex < index) { right -= widthList.GetElement(i); itsFirstDrawIndex++; i++; } } }
GLUndoElementsChange::GLUndoElementsChange ( GXRaggedFloatTable* table, const JPoint& start, const JPoint& end, const GLUndoElementsBase::UndoType type ) : GLUndoElementsBase(table, start, end, type) { itsValues = new JPtrArray<JArray<JFloat> >(JPtrArrayT::kDeleteAll); assert(itsValues != NULL); GRaggedFloatTableData* data = GetData(); JIndex colstart; JIndex colend; if (type == GLUndoElementsBase::kRows) { colstart = 1; colend = data->GetDataColCount(); } else { colstart = start.x; colend = end.x; } for (JSize i = colstart; i <= colend; i++) { JArray<JFloat>* col = new JArray<JFloat>; assert(col != NULL); itsValues->Append(col); JIndex rowstart; JIndex rowend; if (type == GLUndoElementsBase::kCols) { rowstart = 1; rowend = data->GetDataRowCount(i); } else { rowstart = start.y; rowend = JMin((JSize)end.y, data->GetDataRowCount(i)); } for (JSize j = rowstart; j <= rowend; j++) { JFloat value; if (data->GetElement(j, i, &value)) { col->AppendElement(value); } } } }
void JPlotLinearFit::LinearLSQ1() { const JPlotDataBase* data = GetDataToFit(); J2DDataPoint point; const JSize count = data->GetElementCount(); JArray<JFloat> weight; JArray<JFloat> sigma; JSize i; JFloat vx, vy; Variance(&vx,&vy); JFloat resize = vy/vx; JFloat num = 0; JFloat avgx = 0; for (i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat sy = point.yerr; JFloat sx = point.xerr; if (sy == 0) { sy = 1; } JFloat s = 0; if (!itsXIsLog) { if (!itsYIsLog) { s = sqrt(sy * sy + resize * resize * sx * sx); } else { s = sqrt(sy * sy + resize * resize * point.y * point.y * sx * sx); } } else { // do for power law; } sigma.AppendElement(s); JFloat w = 1/(s*s); weight.AppendElement(w); num += w; avgx += w * point.x; itsRealCount++; } } avgx /= num; JArray<JFloat> t; JFloat stt = 0; JFloat b = 0; JSize counter = 1; for (i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat tTemp = (point.x - avgx)/(sigma.GetElement(counter)); t.AppendElement(tTemp); stt += tTemp * tTemp; b += tTemp * point.y / sigma.GetElement(counter); counter++; } } b /= stt; JFloat a = 0; JFloat aerr = 0; counter = 1; for (i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat w = weight.GetElement(counter); a += w * (point.y - b * point.x); aerr += w * w * point.x * point.x; counter++; } } a /= num; aerr /= (num * stt); aerr += 1; aerr /= num; aerr = sqrt(aerr); JFloat berr = sqrt(1.0/stt); JFloat c = 0; JBoolean sytest = kJTrue; counter = 1; for (i = 1; i <= count; i++) { if (GetDataElement(i, &point)) { JFloat temp = (point.y - a - b * point.x)/(sigma.GetElement(counter)); c += temp * temp; if (sigma.GetElement(counter) != 1) { sytest = kJFalse; } counter++; } } if (sytest) { JFloat sig = sqrt(c/count); aerr = aerr * sig; berr = berr * sig; } itsAParameter = a; itsAErrParameter = aerr; itsBParameter = b; itsBErrParameter = berr; itsChi2 = c; }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName("Times"); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(GetFontManager()->GetDefaultFont()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.ShiftOrigin(-2, 0); p.SetPenColor(colormap->GetBlueColor()); JRect r(70, 290, 150, 390); p.Rect(r); /* for (JCoordinate y=70; y<150; y++) { p.SetPenColor(colormap->GetGrayColor(y-50)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,70, x,150); } p.SetLineWidth(2); for (JCoordinate y=70; y<150; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,70, x,150); } p.SetLineWidth(1); */ p.String( 0.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 90.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(180.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(270.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 0.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String( 90.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(180.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(270.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.SetPenColor(colormap->GetBlueColor()); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetDarkGreenColor()); p.SetFilling(kJTrue); p.Rect(290, 160, 100, 80); p.SetFilling(kJFalse); /* for (JCoordinate y=160; y<240; y++) { p.SetPenColor(colormap->GetGrayColor(y-140)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,160, x,240); } p.SetLineWidth(2); for (JCoordinate y=160; y<240; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,160, x,240); } p.SetLineWidth(1); */ textPt.Set(340, 200); p.SetFontName("Times"); p.SetFontStyle(colormap->GetBlueColor()); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.SetFontStyle(colormap->GetYellowColor()); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.SetPenColor(colormap->GetYellowColor()); r.Set(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); }
void CBStylerBase::ReadPrefs ( istream& input ) { JIndex i; JFileVersion vers; input >> vers; if (vers > kCurrentSetupVersion) { return; } JBoolean active; input >> active; // type styles JArray<JFontStyle> typeStyles; JSize typeCount; input >> typeCount; for (i=1; i<=typeCount; i++) { typeStyles.AppendElement(ReadStyle(input)); } JFileVersion typeListVers; input >> typeListVers; if (typeListVers > itsTypeNameVersion) { return; } SetActive(active); *itsTypeStyles = typeStyles; UpgradeTypeList(typeListVers, itsTypeStyles); assert( itsTypeStyles->GetElementCount() == itsTypeNameCount ); // word styles itsWordStyles->RemoveAll(); JSize wordCount; input >> wordCount; JString s; for (i=1; i<=wordCount; i++) { input >> s; itsWordStyles->SetElement(s, ReadStyle(input)); } Broadcast(WordListChanged(*itsWordStyles)); // dialog geometry input >> itsDialogGeom; }
TestWidget::TestWidget ( const JBoolean isMaster, const JBoolean isImage, const JBoolean allocDynamicColors, JXMenuBar* menuBar, JXScrollbarSet* scrollbarSet, JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, const JCoordinate x, const JCoordinate y, const JCoordinate w, const JCoordinate h ) : JXScrollableWidget(scrollbarSet, enclosure, hSizing, vSizing, x,y, w,h), itsRNG() { JIndex i; itsFillFlag = kJFalse; itsNextAnimColor = (GetColormap())->GetGreenColor(); itsRandPointCount = 10; itsResizeDialog = NULL; // cursors JXDisplay* display = GetDisplay(); itsTrekCursor = display->CreateBuiltInCursor("XC_trek", XC_trek); itsGumbyCursor = display->CreateBuiltInCursor("XC_gumby", XC_gumby); itsBogosityCursor = display->CreateBuiltInCursor("XC_bogosity", XC_bogosity); itsFleurCursor = display->CreateBuiltInCursor("XC_fleur", XC_fleur); SetDefaultCursor(itsTrekCursor); // dynamic colors itsAnimColorList = new JArray<JColorIndex>(kAnimColorCount); assert( itsAnimColorList != NULL ); JArray<JDynamicColorInfo>* colorList = new JArray<JDynamicColorInfo>(kAnimColorCount); assert( colorList != NULL ); JXColormap* colormap = GetColormap(); if (allocDynamicColors) { for (i=1; i<=kAnimColorCount; i++) { JDynamicColorInfo info; if (colormap->AllocateDynamicColor(0,0,0, &(info.index))) { colorList->AppendElement(info); itsAnimColorList->AppendElement(info.index); } else { cerr << "Unable to allocate dynamic color " << i << endl; break; } } } if (!colorList->IsEmpty()) { itsAnimColorTask = new AnimateColorTask(colormap, colorList); assert( itsAnimColorTask != NULL ); } else { delete colorList; itsAnimColorTask = NULL; } ListenTo(GetWindow()); // remove AnimateColorTask when iconified // menus itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr); itsActionsMenu->SetTitleFontStyle((GetColormap())->GetWhiteColor()); itsActionsMenu->SetShortcuts(kActionsMenuShortcutStr); itsActionsMenu->SetMenuItems(kActionsMenuStr); itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsActionsMenu); itsPointMenu = new JXTextMenu(itsActionsMenu, kPointMenuCmd, menuBar); assert( itsPointMenu != NULL ); itsPointMenu->SetMenuItems(kPointMenuStr); itsPointMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPointMenu); // This tests the JX response to an empty menu. JXTextMenu* emptyMenu = new JXTextMenu(itsActionsMenu, kEmptyMenuCmd, menuBar); assert( emptyMenu != NULL ); JXMenu* prevMenu = itsActionsMenu; JIndex prevMenuIndex = kAdviceMenuCmd; for (i=1; i<=kAdviceMenuCount; i++) { JXTextMenu* adviceMenu = new JXTextMenu(prevMenu, prevMenuIndex, menuBar); assert( adviceMenu != NULL ); adviceMenu->SetMenuItems(kAdviceMenuStr[i-1]); adviceMenu->SetUpdateAction(JXMenu::kDisableNone); if (i == kAdviceBoldMenuIndex) { adviceMenu->SetItemFontStyle(2, JFontStyle(kJTrue, kJFalse, 0, kJFalse, (GetColormap())->GetBlackColor())); } prevMenu = adviceMenu; prevMenuIndex = 2; } BuildXlsfontsMenu(itsActionsMenu, menuBar); // secret menus are a bad idea because the user can't find them! itsSecretMenu = new JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10); assert( itsSecretMenu != NULL ); itsSecretMenu->SetMenuItems(kSecretMenuStr); itsSecretMenu->SetUpdateAction(JXMenu::kDisableNone); itsSecretMenu->SetToHiddenPopupMenu(kJTrue); // will assert() otherwise itsSecretMenu->Hide(); ListenTo(itsSecretMenu); itsSecretSubmenu = new JXTextMenu(itsSecretMenu, kSecretSubmenuIndex, this); assert( itsSecretSubmenu != NULL ); itsSecretSubmenu->SetMenuItems(kSecretSubmenuStr); itsSecretSubmenu->SetUpdateAction(JXMenu::kDisableNone); // we don't ListenTo() it because it's only there for show // image from xpm itsXPMImage = new JXImage(GetDisplay(), GetColormap(), JXPM(macapp_xpm)); assert( itsXPMImage != NULL ); // partial image from image itsPartialXPMImage = new JXImage(*itsXPMImage, JRect(5,5,14,16)); assert( itsPartialXPMImage != NULL ); // home symbol itsHomeImage = new JXImage(GetDisplay(), GetColormap(), JXPM(home_xpm)); assert( itsHomeImage != NULL ); itsHomeRect = itsHomeImage->GetBounds(); itsHomeRect.Shift(120, 10); // buffer contents of Widget in JXImage itsImageBuffer = NULL; if (isImage) { CreateImageBuffer(); } // initial size SetBounds(400,400); // enclosed objects itsAnimButton = new JXTextButton("Start", this, JXWidget::kFixedLeft, JXWidget::kFixedTop, 37,175, 50,30); assert( itsAnimButton != NULL ); itsAnimButton->SetShortcuts("#A"); ListenTo(itsAnimButton); if (isMaster) { itsQuitButton = new JXTextButton("Quit", this, JXWidget::kFixedRight, JXWidget::kFixedBottom, x,y, 50,30); assert( itsQuitButton != NULL ); JXColormap* colormap = GetColormap(); itsQuitButton->CenterWithinEnclosure(kJTrue, kJTrue); itsQuitButton->SetFontStyle(JFontStyle(kJTrue, kJFalse, 0, kJFalse, colormap->GetRedColor())); itsQuitButton->SetNormalColor(colormap->GetCyanColor()); itsQuitButton->SetPushedColor(colormap->GetBlueColor()); ListenTo(itsQuitButton); } else { itsQuitButton = NULL; } // drops on iconfied window JXWindowIcon* windowIcon; const JBoolean hasIconWindow = (GetWindow())->GetIconWidget(&windowIcon); assert( hasIconWindow ); ListenTo(windowIcon); }
void GMessageViewDir::BuildWindow ( const JString& mailfile ) { JSize w = 500; JSize h = 300; JXWindow* window = new JXWindow(this, w,h, mailfile); assert( window != NULL ); window->SetWMClass(GMGetWMClassInstance(), GMGetViewWindowClass()); GGetPrefsMgr()->GetViewWindowSize(window); w = window->GetFrameWidth(); h = window->GetFrameHeight(); window->SetMinSize(w, 150); window->ShouldFocusWhenShow(kJTrue); JXMenuBar* menuBar = new JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 0, 0, w - kJXDefaultMenuBarHeight, kJXDefaultMenuBarHeight); assert(menuBar != NULL); JXEngravedRect* eRect = new JXEngravedRect(window, JXWidget::kFixedRight, JXWidget::kFixedTop, w - kJXDefaultMenuBarHeight, 0, kJXDefaultMenuBarHeight, kJXDefaultMenuBarHeight); assert(eRect != NULL); GMMessageDragSource* mds = new GMMessageDragSource(this, window, JXWidget::kFixedRight, JXWidget::kFixedTop, w - kJXDefaultMenuBarHeight + kJXDefaultBorderWidth, 0 + kJXDefaultBorderWidth, kJXDefaultMenuBarHeight - 2 * kJXDefaultBorderWidth + 1, kJXDefaultMenuBarHeight - 2 * kJXDefaultBorderWidth + 1); assert(mds != NULL); itsFileMenu = menuBar->AppendTextMenu(kFileMenuTitleStr); itsFileMenu->SetMenuItems(kFileMenuStr); itsFileMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsFileMenu); JPtrArray<JString> nodes(JPtrArrayT::kDeleteAll); GGetMailboxTreeDir()->GetTopLevelNodes(&nodes); itsTransferMenu = new JXFSDirMenu(nodes, itsFileMenu, kTransferToCmd, menuBar); assert(itsTransferMenu != NULL); ListenTo(itsTransferMenu); JDirInfo* info; if (itsTransferMenu->GetDirInfo(&info)) { info->SetContentFilter(GMGetMailRegexStr()); } itsCopyMenu = new JXFSDirMenu(nodes, itsFileMenu, kCopyToCmd, menuBar); assert(itsCopyMenu != NULL); ListenTo(itsCopyMenu); if (itsCopyMenu->GetDirInfo(&info)) { info->SetContentFilter(GMGetMailRegexStr()); } ListenTo(GGetMailboxTreeDir()); itsMessageMenu = menuBar->AppendTextMenu(kMessageMenuTitleStr); itsMessageMenu->SetMenuItems(kMessageMenuStr); itsMessageMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsMessageMenu); itsToolBar = new JXToolBar(GGetPrefsMgr(), kGViewToolBarID, menuBar, w, 150, window, JXWidget::kHElastic, JXWidget::kVElastic, 0, kJXDefaultMenuBarHeight, w, h - kJXDefaultMenuBarHeight); assert(itsToolBar != NULL); const JSize newHeight = itsToolBar->GetWidgetEnclosure()->GetBoundsHeight(); const JFontManager* fm = window->GetFontManager(); JSize lineHeight = fm->GetLineHeight(GGetPrefsMgr()->GetDefaultMonoFont(), GGetPrefsMgr()->GetDefaultFontSize(), JFontStyle()); const JCoordinate headerheight = (lineHeight * 4) + (lineHeight/2); //58; JArray<JCoordinate> sizes; JArray<JCoordinate> minSizes; sizes.AppendElement(headerheight); minSizes.AppendElement(20); sizes.AppendElement(w - headerheight); minSizes.AppendElement(50); JIndex elasticIndex = 2; itsPart = new JXVertPartition(sizes, elasticIndex, minSizes, itsToolBar->GetWidgetEnclosure(), JXWidget::kHElastic, JXWidget::kVElastic, 0, 0, w, newHeight); assert(itsPart != NULL); itsSBSet = new JXScrollbarSet(itsPart->GetCompartment(2), JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 100,100); assert(itsSBSet != NULL); itsSBSet->FitToEnclosure(kJTrue, kJTrue); itsView = new GMessageView(menuBar, itsSBSet, itsSBSet->GetScrollEnclosure(), JXWidget::kHElastic, JXWidget::kVElastic, 0,0,10,10); assert (itsView != NULL); itsView->FitToEnclosure(kJTrue, kJTrue); itsView->SetPTPrinter(GMGetAltPTPrinter()); window->InstallShortcuts(itsView, "#_"); ListenTo(itsView); JXScrollbarSet* sbs = new JXScrollbarSet(itsPart->GetCompartment(1), JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 100,50); assert(sbs != NULL); sbs->FitToEnclosure(kJTrue, kJTrue); itsHeader = new GMessageView(sbs, sbs->GetScrollEnclosure(), JXWidget::kHElastic, JXWidget::kVElastic, 0,0,10,10); assert (itsHeader != NULL); itsHeader->FitToEnclosure(kJTrue, kJTrue); itsHeader->ShareEditMenu(itsView); itsHeader->ShareSearchMenu(itsView); GMDirectorMenu* menu = new GMDirectorMenu(kWindowsMenuTitleStr, menuBar, JXWidget::kFixedLeft, JXWidget::kVElastic, 0,0, 10,10); assert(menu != NULL); menuBar->AppendMenu(menu); itsPrefsMenu = menuBar->AppendTextMenu(kPrefsMenuTitleStr); itsPrefsMenu->SetMenuItems(kPrefsMenuStr); itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPrefsMenu); itsHelpMenu = menuBar->AppendTextMenu(kHelpMenuTitleStr); itsHelpMenu->SetMenuItems(kHelpMenuStr); itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsHelpMenu); itsFileMenu->SetItemImage(kNewCmd, filenew); itsFileMenu->SetItemImage(kNewMBox, envelopes); itsFileMenu->SetItemImage(kOpenCmd, fileopen); itsFileMenu->SetItemImage(kSaveCmd, filefloppy); itsFileMenu->SetItemImage(kPrintCmd, fileprint); itsFileMenu->SetItemImage(kShowNextCmd, mini_right); itsFileMenu->SetItemImage(kDeleteShowNextCmd, mini_del_right); itsFileMenu->SetItemImage(kShowPrevCmd, mini_left); itsMessageMenu->SetItemImage(kDecryptCmd, unlock_xpm); itsMessageMenu->SetItemImage(kSaveAttachCmd, paperclip); itsMessageMenu->SetItemImage(kReplyCmd, reply_xpm); itsMessageMenu->SetItemImage(kReplySenderCmd, reply_sender_xpm); itsMessageMenu->SetItemImage(kReplyAllCmd, reply_all_xpm); itsMessageMenu->SetItemImage(kForwardCmd, forward_xpm); itsMessageMenu->SetItemImage(kRedirectCmd, redirect_xpm); itsHelpMenu->SetItemImage(kTOCCmd, jx_help_toc); itsHelpMenu->SetItemImage(kThisWindowCmd, JXPM(jx_help_specific)); itsToolBar->LoadPrefs(); if (itsToolBar->IsEmpty()) { itsToolBar->AppendButton(itsFileMenu, kNewCmd); itsToolBar->AppendButton(itsFileMenu, kOpenCmd); itsToolBar->NewGroup(); itsToolBar->AppendButton(itsFileMenu, kSaveCmd); itsToolBar->NewGroup(); itsToolBar->AppendButton(itsFileMenu, kPrintCmd); itsToolBar->NewGroup(); itsToolBar->AppendButton(itsFileMenu, kShowNextCmd); itsToolBar->AppendButton(itsFileMenu, kShowPrevCmd); itsToolBar->AppendButton(itsFileMenu, kDeleteShowNextCmd); itsToolBar->NewGroup(); itsToolBar->AppendButton(itsMessageMenu, kReplyCmd); itsToolBar->AppendButton(itsMessageMenu, kReplySenderCmd); itsToolBar->AppendButton(itsMessageMenu, kReplyAllCmd); itsToolBar->AppendButton(itsMessageMenu, kForwardCmd); itsToolBar->AppendButton(itsMessageMenu, kRedirectCmd); } itsMenuIcon = new JXImage(window->GetDisplay(), jx_plain_file_small); assert(itsMenuIcon != NULL); itsMenuIcon->ConvertToRemoteStorage(); }
void JPlotFitQuad2::CalculateFirstPass() { JFloat Y, X, X2, YX, X3, YX2, X4, Sig; JFloat tempa, tempb, tempc, det; JSize i,j, k; JArray<JFloat> yAdjError; const JPlotDataBase* data = GetData(); J2DDataPoint point; JSize rcount = GetRealElementCount(); for (i=1; i<= rcount; i++) { J2DDataPoint point = GetRealElement(i); JFloat newVal = 1; if (point.yerr != 0) { newVal = point.yerr; } yAdjError.AppendElement(newVal); } JMatrix odata(rcount, 3, 1.0); JVector yData(rcount); for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); odata.SetElement(i, 1, 1/(yerr*yerr)); odata.SetElement(i, 2, point.x/(yerr*yerr)); odata.SetElement(i, 3, point.x*point.x/(yerr*yerr)); yData.SetElement(i, point.y/(yerr*yerr)); } JMatrix tData = odata.Transpose(); JMatrix lData = tData * odata; JMatrix rData = tData * yData; JMatrix parms(3,1); JGaussianElimination(lData, rData, &parms); for (k=1; k<= 4; k++) { Y = 0; X = 0; X2 = 0; YX = 0; X3 = 0; YX2 = 0; X4 = 0; Sig = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); Y += point.y/(yerr*yerr); X += point.x/(yerr*yerr); X2 += point.x*point.x/(yerr*yerr); YX += point.y*point.x/(yerr*yerr); X3 += point.x*point.x*point.x/(yerr*yerr); YX2 += point.x*point.x*point.y/(yerr*yerr); X4 += point.x*point.x*point.x*point.x/(yerr*yerr); Sig += 1/(yerr*yerr); } JFloat cv1 = 0, cv2 = 0, cv3 = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat syi = yAdjError.GetElement(i); JFloat yi = point.y; JFloat xi = point.x; for (j = 1; j <= rcount; j++) { point = GetRealElement(j); JFloat syj = yAdjError.GetElement(j); JFloat yj = point.y; JFloat xj = point.x; cv1 += xi*xj*xj*(xi*yj-yi*xj)/(syi*syi*syj*syj); cv2 += (xi*xj*xj*(yi - yj))/(syi*syi*syj*syj); cv3 += (xi*xj*xj*(xj - xi))/(syi*syi*syj*syj); } } det = Sig*(X2*X4-X3*X3) + X*(X3*X2-X*X4) + X2*(X*X3-X2*X2); tempa = (Y*(X2*X4-X3*X3) + X*(X3*YX2-YX*X4) + X2*(YX*X3-X2*YX2))/det; tempb = (Sig*(YX*X4-YX2*X3) + Y*(X3*X2-X*X4) + X2*(X*YX2-YX*X2))/det; tempc = (Sig*cv1 + X*cv2 + Y*cv3)/det; for (i=1; i<=rcount; i++) { J2DDataPoint point = GetRealElement(i); JFloat newVal = sqrt(point.yerr*point.yerr + (tempb+2*tempc*point.x)*(tempb+2*tempc*point.x)*point.xerr*point.xerr); if (newVal == 0) { newVal = 1; } yAdjError.SetElement(i, newVal); } } // itsAParameter = tempa; // itsBParameter = tempb; // itsCParameter = tempc; itsAParameter = parms.GetElement(1, 1); itsBParameter = parms.GetElement(2, 1); itsCParameter = parms.GetElement(3, 1); itsChi2Start = 0; for (i=1; i<= rcount; i++) { point = GetRealElement(i); JFloat yerr = yAdjError.GetElement(i); itsChi2Start += pow(point.y - tempa - tempb*point.x - tempc*point.x*point.x,2)/(yerr*yerr); } itsAErrParameter = 0; itsBErrParameter = 0; itsCErrParameter = 0; }
void TestPartitionDirector::BuildWindow() { JIndex i; JArray<JCoordinate> sizes; JArray<JCoordinate> minSizes; for (i=1; i<=kInitCompartmentCount; i++) { sizes.AppendElement(kInitSize); minSizes.AppendElement(kMinSize); } // begin JXLayout JXWindow* window = jnew JXWindow(this, 310,340, ""); assert( window != NULL ); JXMenuBar* menuBar = jnew JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 310,30); assert( menuBar != NULL ); itsHorizPartition = jnew JXHorizPartition(sizes, kInitElasticIndex, minSizes, window, JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 310,310); assert( itsHorizPartition != NULL ); // end JXLayout itsVertPartition = jnew JXVertPartition(sizes, kInitElasticIndex, minSizes, itsHorizPartition->GetCompartment(kInitElasticIndex), JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 10,315); assert( itsVertPartition != NULL ); itsVertPartition->FitToEnclosure(kJTrue, kJTrue); window->SetTitle("Test Partitions"); window->SetWMClass("testjx", "TestPartitionDirector"); AdjustMinWindowSize(); itsHorizMenu = menuBar->AppendTextMenu(kHorizMenuTitleStr); itsHorizMenu->SetShortcuts(kHorizMenuShortcuts); itsHorizMenu->SetMenuItems(kHorizMenuStr); itsHorizMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsHorizMenu); itsVertMenu = menuBar->AppendTextMenu(kVertMenuTitleStr); itsVertMenu->SetShortcuts(kVertMenuShortcuts); itsVertMenu->SetMenuItems(kVertMenuStr); itsVertMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsVertMenu); for (i=1; i<=kInitCompartmentCount; i++) { if (i != kInitElasticIndex) { CreateTestWidget(itsHorizPartition, i); } CreateTestWidget(itsVertPartition, i); } }
int main() { long i; JSubset s1(10); // constructor cout << "subset s1 created" << endl << endl; cout << "s1 itemCount should be 0" << endl; cout << "s1 itemCount = " << s1.GetElementCount() << endl << endl; s1.AddRange(3,4); s1.Add(9); cout << "s1 itemCount should be 3" << endl; cout << "s1 itemCount = " << s1.GetElementCount() << endl << endl; cout << "s1 should contain: 10FFTTFFFFTF" << endl; cout << "s1 contains : " << s1 << endl; cout << "using Contains() : "; for (i=1; i<=10; i++) { cout << s1.Contains(i); } cout << endl; JSubset s2 = s1; cout << endl; cout << "subset s2 created" << endl << endl; s2.Remove(1); cout << "s1 should equal s2" << endl; cout << "s1 equals s2? " << (s1 == s2) << endl; s2.Remove(4); s2.Add(2); cout << "s2 should contain: 10FTTFFFFFTF" << endl; cout << "s2 contains : " << s2 << endl; cout << "s1 should not equal s2" << endl; cout << "s1 equals s2? " << (s1 == s2) << endl; JWaitForReturn(); JSubset s3 = s1 + s2; JSubset s4 = s1 - s2; JSubset s5 = s2 - s1; JSubset s7 = JIntersection(s4, s5); cout << "s3 should contain: 10FTTTFFFFTF" << endl; cout << "s3 contains : " << s3 << endl << endl; cout << "s4 should contain: 10FFFTFFFFFF" << endl; cout << "s4 contains : " << s4 << endl << endl; cout << "s5 should contain: 10FTFFFFFFFF" << endl; cout << "s5 contains : " << s5 << endl << endl; cout << "s7 should contain: 10FFFTFFFFFF" << endl; cout << "s7 contains : " << s4 << endl << endl; JWaitForReturn(); s3.RemoveAll(); s3.AddRange(3,8); s3.RemoveRange(4,6); cout << "s3 should contain: 10FFTFFFTTFF" << endl; cout << "s3 contains : " << s3 << endl << endl; JSubsetIterator iter = s3.NewIterator(); JIndex index; cout << "s3 contains: "; while (iter.Next(&index)) { cout << ' ' << index; } cout << endl << endl; JSubset s6 = s3.Complement(); cout << "s6 should contain: 10TTFTTTFFTT" << endl; cout << "s6 contains : " << s6 << endl << endl; s6 = s3; // assignment operator cout << "s6 assigned from s3" << endl << endl; cout << "s6 itemCount should be 3" << endl; cout << "s6 itemCount=" << s6.GetElementCount() << endl << endl; cout << "s6 should contain: 10FFTFFFTTFF" << endl; cout << "s6 contains : " << s6 << endl << endl; JWaitForReturn(); cout << "Twenty random samples of size 3:" << endl << endl; for (i=1; i<=20; i++) { if (JGetRandomSample(&s1, 3)) { assert( s1.GetElementCount() == 3 ); cout << s1 << endl; } else { cerr << "Unable to generate random subset of that size." << endl; } } // JGetRandomSample() JHistogram<JSize> h(10); for (i=1; i<=5000; i++) { JGetRandomSample(&s3, 3, 2,8); iter.MoveTo(kJIteratorStartAtBeginning, 0); while (iter.Next(&index)) { h.IncrementCount(index, 1); } } JProbDistr p = h.ConvertToProbabilities(); cout << endl; cout << "Probability of each element (2-8) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << p << endl; // JSubset::GetRandomSample() JBoolean ok = JGetRandomSample(&s1, 7); assert( ok ); h.Clear(); for (i=1; i<=5000; i++) { s1.GetRandomSample(&s3, 3); iter.MoveTo(kJIteratorStartAtBeginning, 0); while (iter.Next(&index)) { h.IncrementCount(index, 1); } } p = h.ConvertToProbabilities(); cout << endl; cout << "Probability of each element (sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << p << endl; // JSubset::GetRandomDisjointSamples() JPtrArray<JSubset> sampleList(JPtrArrayT::kDeleteAll); JArray<JSize> sampleSizeList; sampleSizeList.AppendElement(2); sampleSizeList.AppendElement(2); JHistogram<JSize> h1(10), h2(10); JHistogram<JSize>* hist[] = { &h1, &h2 }; for (i=1; i<=5000; i++) { s1.GetRandomDisjointSamples(&sampleList, sampleSizeList); for (JIndex j=1; j<=2; j++) { JSubsetIterator iter = (sampleList.NthElement(j))->NewIterator(); while (iter.Next(&index)) { hist[j-1]->IncrementCount(index, 1); assert( !(sampleList.NthElement(3-j))->Contains(index) ); } } } cout << endl; cout << "Probability of each element (2 from sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << "1) " << h1.ConvertToProbabilities() << endl; cout << "2) " << h2.ConvertToProbabilities() << endl; // JSubset::GetRandomDisjointSamples() -- partitioning sampleSizeList.SetElement(1, 3); sampleSizeList.SetElement(2, 4); h1.Clear(); h2.Clear(); for (i=1; i<=5000; i++) { s1.GetRandomDisjointSamples(&sampleList, sampleSizeList); for (JIndex j=1; j<=2; j++) { JSubsetIterator iter = (sampleList.NthElement(j))->NewIterator(); while (iter.Next(&index)) { hist[j-1]->IncrementCount(index, 1); assert( !(sampleList.NthElement(3-j))->Contains(index) ); } } } sampleList.DeleteAll(); cout << endl; cout << "Probability of each element (3,4 from sample of 7) being in the subset:" << endl; cout << "(averaged over ensemble of 5000 subsets)" << endl << endl; cout << "1) " << h1.ConvertToProbabilities() << endl; cout << "2) " << h2.ConvertToProbabilities() << endl; return 0; }
JParseResult JParseAsSummation ( const JCharacter* origExpr, const JSize origLength, const JVariableList* theVariableList, JFunction** theFunction, const JBoolean allowUIF ) { *theFunction = NULL; // remove enclosing parentheses const JCharacter* expr = origExpr; const JSize length = JStripParentheses(&expr, origLength); // build a list of the locations of all visible + and - operators const JCharacter* plusStr = JPGetAdditionString(); const JSize plusLength = JPGetAdditionStringLength(); const JCharacter* minusStr = JPGetSubtractionString(); const JSize minusLength = JPGetSubtractionStringLength(); JArray<JCharacter> opList; JArray<JSize> opOffsetList; JArray<JSize> argOffsetList; JSize lastOffset = 0; while (1) { JSize plusOffset; const JBoolean foundPlus = JFindFirstOperator(expr + lastOffset, length - lastOffset, plusStr, &plusOffset); plusOffset += lastOffset; JSize minusOffset; const JBoolean foundMinus = JFindFirstOperator(expr + lastOffset, length - lastOffset, minusStr, &minusOffset); minusOffset += lastOffset; JCharacter opType; JSize opOffset, argOffset; if (foundPlus && foundMinus && plusOffset < minusOffset) { opType = '+'; opOffset = plusOffset; argOffset = plusOffset + plusLength; } else if (foundPlus && foundMinus && minusOffset < plusOffset) { opType = '-'; opOffset = minusOffset; argOffset = minusOffset + minusLength; } else if (foundPlus) { opType = '+'; opOffset = plusOffset; argOffset = plusOffset + plusLength; } else if (foundMinus) { opType = '-'; opOffset = minusOffset; argOffset = minusOffset + minusLength; } else { break; } if (!JIsExponentSign(expr, opOffset, argOffset)) { opList.AppendElement(opType); opOffsetList.AppendElement(opOffset); argOffsetList.AppendElement(argOffset); } lastOffset = argOffset; } if (opList.IsEmpty()) { return kJNotMyProblem; } else if (opList.GetElementCount() == 1 && opOffsetList.GetElement(1) == 0) { const JSize argOffset = argOffsetList.GetElement(1); JFunction* arg = NULL; if (!JRecurseFunction(expr + argOffset, length - argOffset, theVariableList, &arg, allowUIF)) { return kJParseError; } if (opList.GetElement(1) == '-') { *theFunction = new JNegation(arg); assert( *theFunction != NULL ); return kJParsedOK; } else // we ignore leading + { *theFunction = arg; return kJParsedOK; } } else { JSummation* sum = new JSummation; assert( sum != NULL ); // No operand in front means implied + if (opOffsetList.GetElement(1) > 0) { opList.PrependElement('+'); opOffsetList.PrependElement(0); argOffsetList.PrependElement(0); } // We append an extra element at the end of the list // so our loop catches the last summand. opList.AppendElement('+'); opOffsetList.AppendElement(length); argOffsetList.AppendElement(length); // Parse each summand const JSize opCount = opList.GetElementCount(); for (JIndex i=1; i<opCount; i++) { const JCharacter opType = opList.GetElement(i); const JSize startOffset = argOffsetList.GetElement(i); const JSize endOffset = opOffsetList.GetElement(i+1); JFunction* arg = NULL; if (!JRecurseFunction(expr + startOffset, endOffset - startOffset, theVariableList, &arg, allowUIF)) { delete sum; return kJParseError; } else if (opType == '+') { sum->SetArg(i, arg); } else // opType == '-' { JNegation* negArg = new JNegation(arg); assert( negArg != NULL ); sum->SetArg(i, negArg); } } *theFunction = sum; return kJParsedOK; } }
SCCircuitVarList::SCCircuitVarList ( istream& input, const JFileVersion vers ) : JVariableList() { JIndex i; SCCircuitVarListX(); JSize varCount; input >> varCount; JArray<JIndex> misfitIndexList; JPtrArray<JString> misfitFnList(JPtrArrayT::kDeleteAll); for (i=1; i<=varCount; i++) { VarInfo info; info.name = new JString; assert( info.name != NULL ); input >> *(info.name); input >> info.value; JBoolean isFunction; input >> isFunction; if (isFunction) { JString* fStr = new JString; assert( fStr != NULL ); input >> *fStr; (JGetUserNotification())->SetSilent(kJTrue); // complain the second time if (JParseFunction(*fStr, this, &(info.f))) { delete fStr; } else { info.f = NULL; misfitIndexList.AppendElement(i); misfitFnList.Append(fStr); } (JGetUserNotification())->SetSilent(kJFalse); } input >> info.visible; itsVars->AppendElement(info); } const JSize misfitCount = misfitIndexList.GetElementCount(); for (i=1; i<=misfitCount; i++) { const JIndex j = misfitIndexList.GetElement(i); VarInfo info = itsVars->GetElement(j); const JString* fStr = misfitFnList.NthElement(i); if (JParseFunction(*fStr, this, &(info.f))) { itsVars->SetElement(j, info); } } }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName(JXGetTimesFontName()); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.Rect(310, 70, 80, 80); p.String( 0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetYellowColor()); JRect r(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // animated colors p.SetFilling(kJTrue); JCoordinate x = 25; const JSize animColorCount = itsAnimColorList->GetElementCount(); for (i=1; i<=animColorCount; i++) { p.SetPenColor(itsAnimColorList->GetElement(i)); p.Rect(x, 150, 10, 10); x += 10; } // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); // *NEVER* do this in your code! I do it here ONLY to test JXColormap. // (Besides, look at how messy it is!) unsigned long xPixel; if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel)) { JXDisplay* display = GetDisplay(); Display* xdisplay = display->GetXDisplay(); GC gc = DefaultGC(xdisplay, display->GetScreen()); XSetForeground(xdisplay, gc, xPixel); XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20); } }