List of usage examples for java.text NumberFormat getNumberInstance
public static final NumberFormat getNumberInstance()
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void processFrame() { long newTime = System.currentTimeMillis(); long time = newTime - mLastTime; boolean end = false; if (time > 60) { Log.e("LONG", "Frame time took too long! Time: " + time + " Last process frame: " + mLastFrameTime + " Count: " + mBackgroundCount + " Level: " + mLevel); }// w w w .j a va 2 s .co m // We don't want to jump too far so, if real time is > 60 treat it as 33. On screen will seem to slow // down instaead of "jump" if (time > 60) { time = 33; } // Score is based on time + presents. Right now 100 point per second played. No presents yet if (mLevel < 6) { mScore += time; } if (mIsTv) { mScoreText.setText(mScoreLabel + ": " + NumberFormat.getNumberInstance().format((mScore / 10))); } else { mScoreText.setText(NumberFormat.getNumberInstance().format((mScore / 10))); } float scroll = mElfVelX * time; // Do collision detection first... // The elf can't collide if it is within 2 seconds of colliding previously. if (mElfIsHit) { if ((newTime - mElfHitTime) > 2000) { // Move to next state. if (mElfState < 4) { mElfState++; AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket), getString(R.string.analytics_action_rocket_hit), null, mElfState); if (mElfState == 4) { mSoundPool.play(mGameOverSound, 1.0f, 1.0f, 2, 0, 1.0f); // No more control... mControlView.setOnTouchListener(null); mElfAccelY = 0.0f; if (mJetThrustStream != 0) { mSoundPool.stop(mJetThrustStream); } } } updateElf(false); mElfIsHit = false; } } else if (mElfState == 4) { // Don't do any collision detection for parachute elf. Just let him fall... } else { // Find the obstacle(s) we might be colliding with. It can only be one of the first 3 obstacles. for (int i = 0; i < 3; i++) { View view = mObstacleLayout.getChildAt(i); if (view == null) { // No more obstacles... break; } int[] tmp = new int[2]; view.getLocationOnScreen(tmp); // If the start of this view is past the center of the elf, we are done if (tmp[0] > mElfPosX) { break; } if (RelativeLayout.class.isInstance(view)) { // this is an obstacle layout. View topView = view.findViewById(R.id.top_view); View bottomView = view.findViewById(R.id.bottom_view); if ((topView != null) && topView.getVisibility() == View.VISIBLE) { topView.getLocationOnScreen(tmp); Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + topView.getWidth(), tmp[1] + topView.getHeight()); if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) { handleCollision(); } } if (!mElfIsHit) { if ((bottomView != null) && bottomView.getVisibility() == View.VISIBLE) { bottomView.getLocationOnScreen(tmp); Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + bottomView.getWidth(), tmp[1] + bottomView.getHeight()); if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) { // Special case for the mammoth obstacle... if (bottomView.getTag() != null) { if (((mElfPosX - tmp[0]) / (float) bottomView.getWidth()) > 0.25f) { // We are over the mammoth not the spike. lower the top of the rect and test again. obsRect.top = (int) (tmp[1] + ((float) bottomView.getHeight() * 0.18f)); if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) { handleCollision(); } } } else { handleCollision(); } } } } } else if (FrameLayout.class.isInstance(view)) { // Present view FrameLayout frame = (FrameLayout) view; if (frame.getChildCount() > 0) { ImageView presentView = (ImageView) frame.getChildAt(0); presentView.getLocationOnScreen(tmp); Rect presentRect = new Rect(tmp[0], tmp[1], tmp[0] + presentView.getWidth(), tmp[1] + presentView.getHeight()); mElfLayout.getLocationOnScreen(tmp); Rect elfRect = new Rect(tmp[0], tmp[1], tmp[0] + mElfLayout.getWidth(), tmp[1] + mElfLayout.getHeight()); if (elfRect.intersect(presentRect)) { // We got a present! mPresentCount++; if (mPresentCount < 4) { mSoundPool.play(mScoreSmallSound, 1.0f, 1.0f, 2, 0, 1.0f); mScore += 1000; // 100 points. Score is 10x displayed score. mPlus100.setVisibility(View.VISIBLE); if (mElfPosY > (mScreenHeight / 2)) { mPlus100.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight())); } else { mPlus100.setY(mElfPosY + mElfLayout.getHeight()); } mPlus100.setX(mElfPosX); if (m100Anim.hasStarted()) { m100Anim.reset(); } mPlus100.startAnimation(m100Anim); } else { mSoundPool.play(mScoreBigSound, 1.0f, 1.0f, 2, 0, 1.0f); mScore += 5000; // 500 points. Score is 10x displayed score. if (!mRainingPresents) { mPresentCount = 0; } mPlus500.setVisibility(View.VISIBLE); if (mElfPosY > (mScreenHeight / 2)) { mPlus500.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight())); } else { mPlus500.setY(mElfPosY + mElfLayout.getHeight()); } mPlus500.setX(mElfPosX); if (m500Anim.hasStarted()) { m500Anim.reset(); } mPlus500.startAnimation(m500Anim); mPresentBonus = true; } frame.removeView(presentView); } else if (elfRect.left > presentRect.right) { mPresentCount = 0; } } } } } if (mForegroundLayout.getChildCount() > 0) { int currentX = mForegroundScroll.getScrollX(); View view = mForegroundLayout.getChildAt(0); int newX = currentX + (int) scroll; if (newX > view.getWidth()) { newX -= view.getWidth(); mForegroundLayout.removeViewAt(0); } mForegroundScroll.setScrollX(newX); } // Scroll obstacle views if (mObstacleLayout.getChildCount() > 0) { int currentX = mObstacleScroll.getScrollX(); View view = mObstacleLayout.getChildAt(0); int newX = currentX + (int) scroll; if (newX > view.getWidth()) { newX -= view.getWidth(); mObstacleLayout.removeViewAt(0); } mObstacleScroll.setScrollX(newX); } // Scroll the background and foreground if (mBackgroundLayout.getChildCount() > 0) { int currentX = mBackgroundScroll.getScrollX(); View view = mBackgroundLayout.getChildAt(0); int newX = currentX + (int) scroll; if (newX > view.getWidth()) { newX -= view.getWidth(); mBackgroundLayout.removeViewAt(0); if (view.getTag() != null) { Pair<Integer, Integer> pair = (Pair<Integer, Integer>) view.getTag(); int type = pair.first; int level = pair.second; if (type == 0) { if (mBackgrounds[level] != null) { mBackgrounds[level].recycle(); mBackgrounds[level] = null; } else if (mBackgrounds2[level] != null) { mBackgrounds2[level].recycle(); mBackgrounds2[level] = null; } } else if (type == 1) { if (mExitTransitions[level] != null) { mExitTransitions[level].recycle(); mExitTransitions[level] = null; } } else if (type == 2) { if (mEntryTransitions[level] != null) { mEntryTransitions[level].recycle(); mEntryTransitions[level] = null; } } } if (mBackgroundCount == 5) { if (mLevel < 6) { // Pre-fetch next levels backgrounds // end level uses the index 1 background... int level = (mLevel == 5) ? 1 : (mLevel + 1); BackgroundLoadTask task = new BackgroundLoadTask(getResources(), mLevel + 1, BACKGROUNDS[level], EXIT_TRANSITIONS[mLevel], // Exit transitions are for the current level... ENTRY_TRANSITIONS[level], mScaleX, mScaleY, mBackgrounds, mBackgrounds2, mExitTransitions, mEntryTransitions, mScreenWidth, mScreenHeight); task.execute(); addNextImages(mLevel, true); addNextObstacles(mLevel, 2); } // Fetch first set of obstacles if the next level changes from woods to cave or cave to factory if (mLevel == 1) { // Next level will be caves. Get bitmaps for the first 20 obstacles. ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles, mCaveObstacleList, 0, 2, mScaleX, mScaleY); task.execute(); } else if (mLevel == 3) { // Next level will be factory. Get bitmaps for the first 20 obstacles. ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES, mFactoryObstacles, mFactoryObstacleList, 0, 2, mScaleX, mScaleY); task.execute(); } mBackgroundCount++; } else if (mBackgroundCount == 7) { // Add transitions and/or next level if (mLevel < 5) { addNextTransitionImages(mLevel + 1); if (mTransitionImagesCount > 0) { addNextObstacleSpacer(mTransitionImagesCount); } addNextImages(mLevel + 1); // First screen of each new level has no obstacles if ((mLevel % 2) == 1) { addNextObstacleSpacer(1); addNextObstacles(mLevel + 1, 1); } else { addNextObstacles(mLevel + 1, 2); } } else if (mLevel == 5) { addNextTransitionImages(mLevel + 1); if (mTransitionImagesCount > 0) { addNextObstacleSpacer(mTransitionImagesCount); } addFinalImages(); } mBackgroundCount++; } else if (mBackgroundCount == 9) { // Either the transition or the next level is showing if (this.mTransitionImagesCount > 0) { mTransitionImagesCount--; } else { if (mLevel == 1) { // Destroy the wood obstacle bitmaps Thread thread = new Thread(new Runnable() { @Override public void run() { synchronized (mWoodObstacles) { for (Bitmap bmp : mWoodObstacles.values()) { bmp.recycle(); } mWoodObstacles.clear(); } } }); thread.start(); } else if (mLevel == 3) { // Destroy the cave obstacle bitmaps Thread thread = new Thread(new Runnable() { @Override public void run() { synchronized (mCaveObstacles) { for (Bitmap bmp : mCaveObstacles.values()) { bmp.recycle(); } mCaveObstacles.clear(); } } }); thread.start(); } else if (mLevel == 5) { // Destroy the factory obstacle bitmaps Thread thread = new Thread(new Runnable() { @Override public void run() { synchronized (mFactoryObstacles) { for (Bitmap bmp : mFactoryObstacles.values()) { bmp.recycle(); } mFactoryObstacles.clear(); } } }); thread.start(); } mLevel++; // Add an event for clearing this level - note we don't increment mLevel as // it's 0-based and we're tracking the previous level. AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket), getString(R.string.analytics_action_rocket_level), null, mLevel); // Achievements if (!mHitLevel) { mCleanLevel = true; } mHitLevel = false; if (mLevel == 5) { mPlus100.setSelected(true); mPlus500.setSelected(true); } else if (mLevel == 6) { mPlus100.setSelected(false); mPlus500.setSelected(false); } if (mLevel < 6) { mSoundPool.play(mLevelUpSound, 1.0f, 1.0f, 2, 0, 1.0f); addNextImages(mLevel); addNextObstacles(mLevel, 2); } mBackgroundCount = 0; } } else { if ((mBackgroundCount % 2) == 1) { if (mLevel < 6) { addNextImages(mLevel); addNextObstacles(mLevel, 2); } } mBackgroundCount++; } } int current = mBackgroundScroll.getScrollX(); mBackgroundScroll.setScrollX(newX); if ((mLevel == 6) && (mBackgroundScroll.getScrollX() == current)) { end = true; } } // Check on the elf boolean hitBottom = false; boolean hitTop = false; float deltaY = mElfVelY * time; mElfPosY = mElfLayout.getY() + deltaY; if (mElfPosY < 0.0f) { mElfPosY = 0.0f; mElfVelY = 0.0f; hitTop = true; } else if (mElfPosY > (mScreenHeight - mElfLayout.getHeight())) { mElfPosY = mScreenHeight - mElfLayout.getHeight(); mElfVelY = 0.0f; hitBottom = true; } else { // Remember -Y is up! mElfVelY += (mGravityAccelY * time - mElfAccelY * time); } mElfLayout.setY(mElfPosY); // Rotate the elf to indicate thrust, dive. float rot = (float) (Math.atan(mElfVelY / mElfVelX) * 120.0 / Math.PI); mElfLayout.setRotation(rot); mElf.invalidate(); // Update the time and spawn the next call to processFrame. mLastTime = newTime; mLastFrameTime = System.currentTimeMillis() - newTime; if (!end) { if ((mElfState < 4) || !hitBottom) { if (mLastFrameTime < 16) { mHandler.postDelayed(mGameLoop, 16 - mLastFrameTime); } else { mHandler.post(mGameLoop); } } else { endGame(); } } else { // Whatever the final stuff is, do it here. mPlayPauseButton.setEnabled(false); mPlayPauseButton.setVisibility(View.INVISIBLE); endGame(); } }
From source file:op.care.bhp.PnlBHP.java
private CollapsiblePane createCP4(final BHP bhp) { final CollapsiblePane bhpPane = new CollapsiblePane(); bhpPane.setCollapseOnTitleClick(false); ActionListener applyActionListener = new ActionListener() { @Override/*from w ww. j a va 2 s . co m*/ public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (bhp.getPrescription().isClosed()) { return; } if (BHPTools.isChangeable(bhp)) { outcomeText = null; if (bhp.getNeedsText()) { new DlgYesNo(SYSConst.icon48comment, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { outcomeText = null; } else { outcomeText = o.toString(); } } }, "nursingrecords.bhp.describe.outcome", null, null); } if (bhp.getNeedsText() && outcomeText == null) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage("nursingrecords.bhp.notext.nooutcome", DisplayMessage.WARNING)); return; } if (bhp.getPrescription().isWeightControlled()) { new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { weight = null; } else { weight = (BigDecimal) o; } } }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() { @Override public boolean isValid(String value) { BigDecimal bd = parse(value); return bd != null && bd.compareTo(BigDecimal.ZERO) > 0; } @Override public BigDecimal parse(String text) { return SYSTools.parseDecimal(text); } }); } if (bhp.getPrescription().isWeightControlled() && weight == null) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage( "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING)); return; } EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); if (myBHP.isOnDemand()) { em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC_FORCE_INCREMENT); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC_FORCE_INCREMENT); } else { em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); } myBHP.setState(BHPTools.STATE_DONE); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); myBHP.setText(outcomeText); Prescription involvedPresciption = null; if (myBHP.shouldBeCalculated()) { MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()); MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(), weight, myBHP); // Was the prescription closed during this withdraw ? involvedPresciption = em.find(Prescription.class, myBHP.getPrescription().getID()); } BHP outcomeBHP = null; // add outcome check BHP if necessary if (!myBHP.isOutcomeText() && myBHP.getPrescriptionSchedule().getCheckAfterHours() != null) { outcomeBHP = em.merge(new BHP(myBHP)); mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND).add(outcomeBHP); } em.getTransaction().commit(); if (myBHP.shouldBeCalculated() && involvedPresciption.isClosed()) { // && reload(); } else if (outcomeBHP != null) { reload(); } else { mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(myBHP.getShift()).remove(position); mapShift2BHP.get(myBHP.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { // This whole thing here is only to handle the BPHs on Demand // Fix the other BHPs on demand. If not, you will get locking exceptions, // we FORCED INCREMENTED LOCKS on the Schedule and the Prescription. ArrayList<BHP> changeList = new ArrayList<BHP>(); for (BHP bhp : mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)) { if (bhp.getPrescription().getID() == myBHP.getPrescription().getID() && bhp.getBHPid() != myBHP.getBHPid()) { bhp.setPrescription(myBHP.getPrescription()); bhp.setPrescriptionSchedule(myBHP.getPrescriptionSchedule()); changeList.add(bhp); } } for (BHP bhp : changeList) { mapBHP2Pane.put(bhp, createCP4(myBHP)); position = mapShift2BHP.get(bhp.getShift()).indexOf(bhp); mapShift2BHP.get(myBHP.getShift()).remove(position); mapShift2BHP.get(myBHP.getShift()).add(position, bhp); } Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (RollbackException ole) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }; // JPanel titlePanelleft = new JPanel(); // titlePanelleft.setLayout(new BoxLayout(titlePanelleft, BoxLayout.LINE_AXIS)); MedStock stock = mapPrescription2Stock.get(bhp.getPrescription()); if (bhp.hasMed() && stock == null) { stock = MedStockTools .getStockInUse(TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm())); mapPrescription2Stock.put(bhp.getPrescription(), stock); } String title; if (bhp.isOutcomeText()) { title = "<html><font size=+1>" + SYSConst.html_italic(SYSTools .left("“" + PrescriptionTools.getShortDescriptionAsCompactText( bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH) + BHPTools.getScheduleText(bhp.getOutcome4(), "”, ", "")) + " [" + bhp.getPrescriptionSchedule().getCheckAfterHours() + " " + SYSTools.xx("misc.msg.Hour(s)") + "] " + BHPTools.getScheduleText(bhp, ", ", "") + (bhp.getPrescription().isWeightControlled() ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? "" : (bhp.getStockTransaction().isEmpty() ? " " : NumberFormat.getNumberInstance() .format(bhp.getStockTransaction().get(0).getWeight()) + "g ")) : "") + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>" : "") + "</font></html>"; } else { title = "<html><font size=+1>" + SYSTools.left(PrescriptionTools.getShortDescriptionAsCompactText( bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH) + (bhp.hasMed() ? ", <b>" + SYSTools.getAsHTML(bhp.getDose()) + " " + DosageFormTools.getUsageText( bhp.getPrescription().getTradeForm().getDosageForm()) + "</b>" : "") + BHPTools.getScheduleText(bhp, ", ", "") + (bhp.getPrescription().isWeightControlled() ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? "" : (bhp.getStockTransaction().isEmpty() ? " " : NumberFormat.getNumberInstance() .format(bhp.getStockTransaction().get(0).getWeight()) + "g ")) : "") + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>" : "") + "</font></html>"; } DefaultCPTitle cptitle = new DefaultCPTitle(title, OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener : null); JLabel icon1 = new JLabel(BHPTools.getIcon(bhp)); icon1.setOpaque(false); if (!bhp.isOpen()) { icon1.setToolTipText(DateFormat.getDateTimeInstance().format(bhp.getIst())); } JLabel icon2 = new JLabel(BHPTools.getWarningIcon(bhp, stock)); icon2.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon1); cptitle.getAdditionalIconPanel().add(icon2); if (bhp.getPrescription().isClosed()) { JLabel icon3 = new JLabel(SYSConst.icon22stopSign); icon3.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon3); } if (bhp.isOutcomeText()) { JLabel icon4 = new JLabel(SYSConst.icon22comment); icon4.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon4); } if (!bhp.isOutcomeText() && bhp.getPrescriptionSchedule().getCheckAfterHours() != null) { JLabel icon4 = new JLabel(SYSConst.icon22intervalBySecond); icon4.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon4); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { if (!bhp.getPrescription().isClosed()) { /*** * _ _ _ _ * | |__ | |_ _ __ / \ _ __ _ __ | |_ _ * | '_ \| __| '_ \ / _ \ | '_ \| '_ \| | | | | * | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| | * |_.__/ \__|_| |_/_/ \_\ .__/| .__/|_|\__, | * |_| |_| |___/ */ JButton btnApply = new JButton(SYSConst.icon22apply); btnApply.setPressedIcon(SYSConst.icon22applyPressed); btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT); btnApply.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnApply.tooltip")); btnApply.addActionListener(applyActionListener); btnApply.setContentAreaFilled(false); btnApply.setBorder(null); btnApply.setEnabled(bhp.isOpen() && (!bhp.hasMed() || mapPrescription2Stock.containsKey(bhp.getPrescription()))); cptitle.getRight().add(btnApply); /*** * ____ _ _ * ___ _ __ ___ _ __ / ___|| |_ ___ ___| | __ * / _ \| '_ \ / _ \ '_ \\___ \| __/ _ \ / __| |/ / * | (_) | |_) | __/ | | |___) | || (_) | (__| < * \___/| .__/ \___|_| |_|____/ \__\___/ \___|_|\_\ * |_| */ if (bhp.hasMed() && stock == null && MedInventoryTools.getNextToOpen( TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm())) != null) { final JButton btnOpenStock = new JButton(SYSConst.icon22ledGreenOn); btnOpenStock.setPressedIcon(SYSConst.icon22ledGreenOff); btnOpenStock.setAlignmentX(Component.RIGHT_ALIGNMENT); btnOpenStock.setContentAreaFilled(false); btnOpenStock.setBorder(null); btnOpenStock.setToolTipText(SYSTools .toHTMLForScreen(SYSTools.xx("nursingrecords.inventory.stock.btnopen.tooltip"))); btnOpenStock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); MedStock myStock = em.merge(MedInventoryTools.openNext( TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()))); em.lock(myStock, LockModeType.OPTIMISTIC); em.getTransaction().commit(); OPDE.getDisplayManager() .addSubMessage(new DisplayMessage( String.format(SYSTools.xx("newstocks.stock.has.been.opened"), myStock.getID().toString()))); reload(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); cptitle.getRight().add(btnOpenStock); } if (!bhp.isOutcomeText()) { /*** * _ _ ____ __ * | |__ | |_ _ __ | _ \ ___ / _|_ _ ___ ___ * | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \ * | |_) | |_| | | | _ < __/ _| |_| \__ \ __/ * |_.__/ \__|_| |_|_| \_\___|_| \__,_|___/\___| * */ final JButton btnRefuse = new JButton(SYSConst.icon22cancel); btnRefuse.setPressedIcon(SYSConst.icon22cancelPressed); btnRefuse.setAlignmentX(Component.RIGHT_ALIGNMENT); btnRefuse.setContentAreaFilled(false); btnRefuse.setBorder(null); btnRefuse.setToolTipText( SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuse.tooltip"))); btnRefuse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (BHPTools.isChangeable(bhp)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); myBHP.setState(BHPTools.STATE_REFUSED); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } em.getTransaction().commit(); mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnRefuse.setEnabled(!bhp.isOnDemand() && bhp.isOpen()); cptitle.getRight().add(btnRefuse); /*** * _ _ ____ __ ____ _ _ * | |__ | |_ _ __ | _ \ ___ / _|_ _ ___ ___| _ \(_)___ ___ __ _ _ __ __| | * | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \ | | | / __|/ __/ _` | '__/ _` | * | |_) | |_| | | | _ < __/ _| |_| \__ \ __/ |_| | \__ \ (_| (_| | | | (_| | * |_.__/ \__|_| |_|_| \_\___|_| \__,_|___/\___|____/|_|___/\___\__,_|_| \__,_| * */ final JButton btnRefuseDiscard = new JButton(SYSConst.icon22deleteall); btnRefuseDiscard.setPressedIcon(SYSConst.icon22deleteallPressed); btnRefuseDiscard.setAlignmentX(Component.RIGHT_ALIGNMENT); btnRefuseDiscard.setContentAreaFilled(false); btnRefuseDiscard.setBorder(null); btnRefuseDiscard.setToolTipText( SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuseDiscard.tooltip"))); btnRefuseDiscard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (BHPTools.isChangeable(bhp)) { if (bhp.getPrescription().isWeightControlled()) { new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { weight = null; } else { weight = (BigDecimal) o; } } }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() { @Override public boolean isValid(String value) { BigDecimal bd = parse(value); return bd != null && bd.compareTo(BigDecimal.ZERO) > 0; } @Override public BigDecimal parse(String text) { return SYSTools.parseDecimal(text); } }); } if (bhp.getPrescription().isWeightControlled() && weight == null) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage( "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING)); return; } EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); myBHP.setState(BHPTools.STATE_REFUSED_DISCARDED); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); if (myBHP.shouldBeCalculated()) { MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()); if (inventory != null) { MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(), weight, myBHP); } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage("nursingrecords.bhp.NoInventory")); } } mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } em.getTransaction().commit(); mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnRefuseDiscard.setEnabled( !bhp.isOnDemand() && bhp.hasMed() && bhp.shouldBeCalculated() && bhp.isOpen()); cptitle.getRight().add(btnRefuseDiscard); } /*** * _ _ _____ _ * | |__ | |_ _ __ | ____|_ __ ___ _ __ | |_ _ _ * | '_ \| __| '_ \| _| | '_ ` _ \| '_ \| __| | | | * | |_) | |_| | | | |___| | | | | | |_) | |_| |_| | * |_.__/ \__|_| |_|_____|_| |_| |_| .__/ \__|\__, | * |_| |___/ */ final JButton btnEmpty = new JButton(SYSConst.icon22empty); btnEmpty.setPressedIcon(SYSConst.icon22emptyPressed); btnEmpty.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEmpty.setContentAreaFilled(false); btnEmpty.setBorder(null); btnEmpty.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnEmpty.tooltip")); btnEmpty.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() == BHPTools.STATE_OPEN) { return; } BHP outcomeBHP = BHPTools.getComment(bhp); if (outcomeBHP != null && !outcomeBHP.isOpen()) { // already commented return; } if (BHPTools.isChangeable(bhp)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); // the normal BHPs (those assigned to a NursingProcess) are reset to the OPEN state. // TXs are deleted myBHP.setState(BHPTools.STATE_OPEN); myBHP.setUser(null); myBHP.setIst(null); myBHP.setiZeit(null); myBHP.setMDate(new Date()); myBHP.setText(null); if (myBHP.shouldBeCalculated()) { for (MedStockTransaction tx : myBHP.getStockTransaction()) { em.remove(tx); } myBHP.getStockTransaction().clear(); } if (outcomeBHP != null) { BHP myOutcomeBHP = em.merge(outcomeBHP); em.remove(myOutcomeBHP); } if (myBHP.isOnDemand()) { em.remove(myBHP); } em.getTransaction().commit(); if (myBHP.isOnDemand()) { reload(); } else { mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnEmpty.setEnabled(!bhp.isOpen()); cptitle.getRight().add(btnEmpty); } /*** * _ _ ___ __ * | |__ | |_ _ __ |_ _|_ __ / _| ___ * | '_ \| __| '_ \ | || '_ \| |_ / _ \ * | |_) | |_| | | || || | | | _| (_) | * |_.__/ \__|_| |_|___|_| |_|_| \___/ * */ final JButton btnInfo = new JButton(SYSConst.icon22info); btnInfo.setPressedIcon(SYSConst.icon22infoPressed); btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT); btnInfo.setContentAreaFilled(false); btnInfo.setBorder(null); btnInfo.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnInfo.tooltip")); final JTextPane txt = new JTextPane(); txt.setContentType("text/html"); txt.setEditable(false); final JidePopup popupInfo = new JidePopup(); popupInfo.setMovable(false); popupInfo.setContentPane(new JScrollPane(txt)); popupInfo.removeExcludedComponent(txt); popupInfo.setDefaultFocusComponent(txt); btnInfo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { popupInfo.setOwner(btnInfo); if (bhp.isOutcomeText() && !bhp.isOpen()) { txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getText()))); } else { txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText()))); } // txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText()))); GUITools.showPopup(popupInfo, SwingConstants.SOUTH_WEST); } }); if (bhp.isOutcomeText() && !bhp.isOpen()) { btnInfo.setEnabled(true); } else { btnInfo.setEnabled(!SYSTools.catchNull(bhp.getPrescription().getText()).isEmpty()); } cptitle.getRight().add(btnInfo); } bhpPane.setTitleLabelComponent(cptitle.getMain()); bhpPane.setSlidingDirection(SwingConstants.SOUTH); final JTextPane contentPane = new JTextPane(); contentPane.setEditable(false); contentPane.setContentType("text/html"); bhpPane.setContentPane(contentPane); bhpPane.setBackground(bhp.getBG()); bhpPane.setForeground(bhp.getFG()); try { bhpPane.setCollapsed(true); } catch (PropertyVetoException e) { OPDE.error(e); } bhpPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { contentPane.setText(SYSTools.toHTML( PrescriptionTools.getPrescriptionAsHTML(bhp.getPrescription(), false, false, true, false))); } }); bhpPane.setHorizontalAlignment(SwingConstants.LEADING); bhpPane.setOpaque(false); return bhpPane; }
From source file:gda.plots.SimplePlot.java
/** * Creates the linear and logarithmic x axes * /*from w w w . ja v a 2s . c o m*/ * @param autoRange */ private void createXAxes(boolean autoRange) { xAxisNumberFormat = NumberFormat.getNumberInstance(); linearXAxis = new SimpleNumberAxis("xaxis"); initAxis(linearXAxis, autoRange, xAxisNumberFormat); logarithmicXAxis = new LogarithmicAxis("xaxis"); initLogAxis(logarithmicXAxis, autoRange, xAxisNumberFormat); }
From source file:gda.plots.SimplePlot.java
/** * Creates the linear and logarithmic y axes * // ww w .j a v a 2 s . com * @param autoRange */ private void createYAxes(boolean autoRange) { yAxisNumberFormat = NumberFormat.getNumberInstance(); yAxisNumberFormat.setGroupingUsed(false); linearYAxis = new SimpleNumberAxis("yaxis"); initAxis(linearYAxis, autoRange, yAxisNumberFormat); logarithmicYAxis = new LogarithmicAxis("yaxis"); initLogAxis(logarithmicYAxis, autoRange, yAxisNumberFormat); }
From source file:gda.plots.SimplePlot.java
/** * Creates the linear and logarithmic second y axes * /* w w w. j a v a 2 s . c o m*/ * @param autoRange */ private void createYAxesTwo(boolean autoRange) { yAxisTwoNumberFormat = NumberFormat.getNumberInstance(); yAxisTwoNumberFormat.setGroupingUsed(false); linearYAxisTwo = new SimpleNumberAxis("Second Y Axis"); initAxis(linearYAxis, autoRange, yAxisTwoNumberFormat); logarithmicYAxisTwo = new LogarithmicAxis("Second Y Axis"); initLogAxis(logarithmicYAxisTwo, autoRange, yAxisTwoNumberFormat); }
From source file:org.slc.sli.dashboard.manager.impl.PopulationManagerImpl.java
@Override @LogExecutionTime/* w w w . ja v a 2 s. c om*/ public GenericEntity getAttendance(String token, Object studentIdObj, Config.Data config) { // get yearsBack from param String yearsBack = config.getParams() == null ? null : (String) config.getParams().get("yearsBack"); int intYearsBack = DEFAULT_YEARS_BACK; if (yearsBack != null) { try { intYearsBack = Integer.parseInt(yearsBack); } catch (NumberFormatException e) { LOG.error("params: value of yearsBack was not integer. [" + intYearsBack + "]. Using default value [" + DEFAULT_YEARS_BACK + "]"); intYearsBack = DEFAULT_YEARS_BACK; } } GenericEntity attendance = new GenericEntity(); String studentId = (String) studentIdObj; // get Enrollment History List<GenericEntity> enrollments = getApiClient().getEnrollmentForStudent(token, studentId); // creating lookup index for enrollment, key is term (yyyy-yyyy) int currentSchoolYear = 0; Map<String, LinkedHashMap<String, Object>> enrollmentsIndex = new HashMap<String, LinkedHashMap<String, Object>>(); for (LinkedHashMap<String, Object> enrollment : enrollments) { String entryDateYear = ""; String exitWithdrawDateYear = ""; String entryDate = (String) enrollment.get(Constants.ATTR_ENROLLMENT_ENTRY_DATE); String exitWithdrawDate = (String) enrollment.get(Constants.ATTR_ENROLLMENT_EXIT_WITHDRAW_DATE); // find a year for entryDate if (entryDate != null && entryDate.length() > 3) { entryDateYear = entryDate.substring(0, 4); } // find a year for exitWithdarwDate if (exitWithdrawDate != null && exitWithdrawDate.length() > 3) { exitWithdrawDateYear = exitWithdrawDate.substring(0, 4); } else { // exitWithdrawDate is null because it is in current term. // add one year to entryDateYear. currentSchoolYear = Integer.parseInt(entryDateYear); exitWithdrawDateYear = Integer.toString(currentSchoolYear + 1); } // creating index lookup key String key = entryDateYear + "-" + exitWithdrawDateYear; enrollmentsIndex.put(key, enrollment); } // Numberformat for %Present - no fraction NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(0); // get attendance for the student List<GenericEntity> attendanceList = this.getStudentAttendance(token, studentId, null, null); for (Map<String, Object> targetAttendance : attendanceList) { // get schoolYearAttendance List<Map<String, Object>> schoolYearAttendances = (List<Map<String, Object>>) targetAttendance .get(Constants.ATTR_ATTENDANCE_SCHOOLYEAR_ATTENDANCE); if (schoolYearAttendances != null) { // sort by schoolYear GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_SCHOOL_YEAR, String.class); Collections.sort(schoolYearAttendances, Collections.reverseOrder(comparator)); for (Map<String, Object> schoolYearAttendance : schoolYearAttendances) { int inAttendanceCount = 0; int absenceCount = 0; int excusedAbsenceCount = 0; int unexcusedAbsenceCount = 0; int tardyCount = 0; int earlyDepartureCount = 0; int totalCount = 0; // get schoolYear String schoolYear = (String) schoolYearAttendance.get(Constants.ATTR_SCHOOL_YEAR); // if some reasons we cannot find currentSchoolYear, then // display all histories // if intYearsBack is not set to NO_LIMIT (-1) and found // currentSchoolYear, // then exam whether current loop is within user defined // yearsBack if (intYearsBack != NO_LIMIT && currentSchoolYear != 0) { int targetYear = Integer.parseInt(schoolYear.substring(0, 4)); // if yearsBack is 1, it means current schoolYear. // break from the loop if currentSchoolYear-targetYear // is over yearsBack. if ((currentSchoolYear - targetYear) >= intYearsBack) { break; } } // get target school year enrollment LinkedHashMap<String, Object> enrollment = enrollmentsIndex.get(schoolYear); GenericEntity currentTermAttendance = new GenericEntity(); // set school term currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TERM, schoolYear); String nameOfInstitution = ""; boolean enrollmentExistsForAttendance = false; // get school name from enrollment if (enrollment != null) { Map<String, Object> school = (Map<String, Object>) enrollment.get(Constants.ATTR_SCHOOL); if (school != null) { nameOfInstitution = (String) school.get(Constants.ATTR_NAME_OF_INST); } String enrollmentSchoolId = (String) enrollment.get(Constants.ATTR_SCHOOL_ID); String attendanceSchoolId = (String) targetAttendance.get(Constants.ATTR_SCHOOL_ID); if (enrollmentSchoolId.equals(attendanceSchoolId) == true) { // only show attendances that are for the school in the // target enrollment enrollmentExistsForAttendance = true; } } // get attendanceEvent List<LinkedHashMap<String, Object>> attendanceEvents = (List<LinkedHashMap<String, Object>>) schoolYearAttendance .get(Constants.ATTR_ATTENDANCE_ATTENDANCE_EVENT); // count each attendance event if (attendanceEvents != null && enrollmentExistsForAttendance) { for (Map<String, Object> attendanceEvent : attendanceEvents) { String event = (String) attendanceEvent.get(Constants.ATTR_ATTENDANCE_EVENT_CATEGORY); if (event != null) { totalCount++; if (event.equals(Constants.ATTR_ATTENDANCE_IN_ATTENDANCE)) { inAttendanceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_ABSENCE)) { absenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_EXCUSED_ABSENCE)) { excusedAbsenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_UNEXCUSED_ABSENCE)) { unexcusedAbsenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_TARDY)) { tardyCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_EARLY_DEPARTURE)) { earlyDepartureCount++; } } } } // set school name currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_SCHOOL, nameOfInstitution); String gradeLevel = ""; // set grade level if (enrollment != null) { gradeLevel = (String) enrollment.get(Constants.ATTR_ENROLLMENT_ENTRY_GRADE_LEVEL_CODE); } currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_GRADE_LEVEL, gradeLevel); // set %Present currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_PRESENT, numberFormat.format(totalCount == 0 ? 0 : ((inAttendanceCount + tardyCount + earlyDepartureCount) / (double) totalCount) * 100)); // set In Attendance currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_IN_ATTENDANCE, inAttendanceCount); // set Total Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TOTAL_ABSENCES, absenceCount + excusedAbsenceCount + unexcusedAbsenceCount); // set Absence currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_ABSENCE, absenceCount); // set Excused Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_EXCUSED, excusedAbsenceCount); // set Unexcused Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_UNEXCUSED, unexcusedAbsenceCount); // set Tardy currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TARDY, tardyCount); // set Early departure currentTermAttendance.put(Constants.ATTENDANCE_EARLY_DEPARTURE, earlyDepartureCount); // Add to attendance list attendance.appendToList("attendance", currentTermAttendance); } } } return attendance; }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
public void buttonSICUpdate_actionPerformed(ActionEvent event) { try {//from www . j a v a 2 s . c om NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); String answer = nf.format(_precursorChromatogramWindow); String newAnswer = JOptionPane.showInputDialog("New value for MS1 SIC tolerance:", answer); _precursorChromatogramWindow = (float) Double.parseDouble(newAnswer); for (MRMTransition t : _mrmTransitions) { t.setGraphData(null); for (MRMDaughter d : t.getDaughters().values()) { d.setGraphData(null); } } updateChartsAndFields(false); } catch (Exception e) { ApplicationContext.infoMessage("Bad value for MZ tolerance, please try again"); } }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
public void buttonPDT_actionPerformed(ActionEvent event) { try {//from ww w. ja v a2 s . c o m NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); String answer = nf.format(_precursorDiscoveryMzTolerance); String newAnswer = JOptionPane.showInputDialog("New value for precursor tolerance:", answer); _precursorDiscoveryMzTolerance = (float) Double.parseDouble(newAnswer); initStuff(); } catch (Exception e) { ApplicationContext.infoMessage("Bad value for precursor tolerance."); } }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiToHTMLUtils.java
public static String toHtmlFormField(CustomFormField field, WikiToHTMLContext context) { // Set a default value if (field.getValue() == null) { field.setValue(field.getDefaultValue()); }/*from w w w.j a v a 2 s . c o m*/ // Protect against any arbitrary input String fieldName = StringUtils.toHtmlValue(field.getName()); // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: String textAreaValue = StringUtils.replace(field.getValue(), "^", CRLF); return ("<textarea cols=\"" + field.getColumns() + "\" rows=\"" + field.getRows() + "\" name=\"" + fieldName + "\">" + StringUtils.toString(textAreaValue) + "</textarea>"); case CustomFormField.SELECT: LookupList lookupList = field.getLookupList(); int selectedItemId = -1; for (LookupElement thisElement : lookupList) { if (field.getValue().equals(thisElement.getDescription())) { selectedItemId = thisElement.getCode(); } } return lookupList.getHtmlSelect(fieldName, selectedItemId); case CustomFormField.CHECKBOX: return ("<input type=\"checkbox\" name=\"" + fieldName + "\" value=\"ON\" " + ("true".equals(field.getValue()) ? "checked" : "") + ">"); case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error("toHtmlFormField calendar", e); } } // Output with a calendar control String language = System.getProperty("LANGUAGE"); String country = System.getProperty("COUNTRY"); return ("<input type=\"text\" name=\"" + fieldName + "\" id=\"" + fieldName + "\" size=\"10\" value=\"" + StringUtils.toHtmlValue(calendarValue) + "\" > " + "<a href=\"javascript:popCalendar('inputForm', '" + fieldName + "','" + language + "','" + country + "');\">" + "<img src=\"" + context.getServerUrl() + "/images/icons/stock_form-date-field-16.gif\" " + "border=\"0\" align=\"absmiddle\" height=\"16\" width=\"16\"/></a>"); case CustomFormField.PERCENT: return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"5\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\"> " + "%"); case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not format integer: " + field.getValue()); } } return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + integerValue + "\"> "); case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + decimalValue + "\"> "); case CustomFormField.CURRENCY: // Use a currencyCode for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } HtmlSelect currencyCodeList = HtmlSelectCurrencyCode.getSelect(fieldName + "Currency", currencyCode); // Determine the valut to display in the field String currencyValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(currencyValue)) { try { NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMaximumFractionDigits(2); currencyValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not currencyCode format: " + field.getValue()); } } return (currencyCodeList.getHtml() + "<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + currencyValue + "\"> "); case CustomFormField.EMAIL: return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"255\" size=\"40\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); case CustomFormField.PHONE: return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"60\" size=\"20\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + field.getValue(); } } return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"255\" size=\"40\" value=\"" + StringUtils.toHtmlValue(value) + "\" />"); default: int maxlength = field.getMaxLength(); int size = -1; if (maxlength > -1) { if (maxlength > 40) { size = 40; } else { size = maxlength; } } return ("<input type=\"text\" " + "name=\"" + fieldName + "\" " + (maxlength == -1 ? "" : "maxlength=\"" + maxlength + "\" ") + (size == -1 ? "" : "size=\"" + size + "\" ") + "value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); } }