List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance(int style)
From source file:threads.HeapStat.java
/** * Creates a new instance of HeapStat//from w ww . j ava 2 s . c o m */ public HeapStat(JProgressBar jpHeap, JProgressBar jpTimeout, JLabel clock, Closure timeoutAction) { super(); this.jpTimeout = jpTimeout; this.timeoutAction = timeoutAction; uhrzeit = DateFormat.getTimeInstance(DateFormat.SHORT); datum = DateFormat.getDateInstance(DateFormat.LONG); touch(); this.clock = clock; this.setName("HeapStat"); this.interrupted = false; this.jpHeap = jpHeap; this.jpHeap.setStringPainted(true); }
From source file:org.jactr.tools.async.iterative.tracker.IterativeRunTracker.java
public IterativeRunTracker() { _ioHandler = new BaseIOHandler(); _ioHandler.addReceivedMessageHandler(StatusMessage.class, new MessageHandler<StatusMessage>() { public void handleMessage(IoSession arg0, StatusMessage message) throws Exception { update(message);/*from w w w. jav a2 s . c om*/ if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append(message.getIteration()).append("/").append(message.getTotalIterations()); if (message.isStart()) sb.append(" started @ "); else sb.append(" stopped @ "); DateFormat format = DateFormat.getTimeInstance(DateFormat.LONG); sb.append(format.format(new Date(message.getWhen()))); LOGGER.debug(sb.toString()); LOGGER.debug("Will finish @ " + format.format(new Date(getETA())) + " in " + getTimeToCompletion() + "ms"); } } }); _ioHandler.addReceivedMessageHandler(ExceptionMessage.class, new MessageHandler<ExceptionMessage>() { public void handleMessage(IoSession arg0, ExceptionMessage message) throws Exception { update(message); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder("Exception thrown during iteration "); sb.append(message.getIteration()).append(" by ").append(message.getModelName()).append(" "); LOGGER.debug(sb.toString(), message.getThrown()); } } }); _ioHandler.addReceivedMessageHandler(DeadLockMessage.class, new MessageHandler<DeadLockMessage>() { public void handleMessage(IoSession session, DeadLockMessage message) throws Exception { /** * Error : error */ LOGGER.error("Deadlock has been detected, notifying"); if (_listener != null) _listener.deadlockDetected(); } }); }
From source file:org.wso2.carbon.core.services.loggeduserinfo.LoggedUserInfoAdmin.java
public LoggedUserInfo getUserInfo() throws Exception { try {//www.j av a 2 s . c om MessageContext messageContext = MessageContext.getCurrentMessageContext(); HttpServletRequest request = (HttpServletRequest) messageContext .getProperty("transport.http.servletRequest"); String userName = (String) request.getSession().getAttribute(ServerConstants.USER_LOGGED_IN); int index = userName.indexOf("/"); if (index < 0) { String domainName = (String) request.getSession() .getAttribute(CarbonAuthenticationUtil.LOGGED_IN_DOMAIN); if (domainName != null) { userName = domainName + "/" + userName; } } LoggedUserInfo loggedUserInfo = new LoggedUserInfo(); UserRealm userRealm = (UserRealm) PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm(); List<String> userPermissions = getUserPermissions(userName, userRealm); String[] permissions = userPermissions.toArray(new String[userPermissions.size()]); loggedUserInfo.setUIPermissionOfUser(permissions); Date date = userRealm.getUserStoreManager().getPasswordExpirationTime(userName); loggedUserInfo.setUserName(userName); if (date != null) { DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM); String passwordExpiration = timeFormat.format(date) + " on " + dateFormat.format(date); loggedUserInfo.setPasswordExpiration(passwordExpiration); } return loggedUserInfo; } catch (Exception e) { log.error(e); throw e; } }
From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
public void displayQuickSilenceNotification(int quicksilenceDurationMinutes) { BetaPrefs betaPrefs = new BetaPrefs(context); if (betaPrefs.getDisableNotifications()) { Log.d(TAG, "asked to display quicksilence notification, but this has been disabled in " + "beta settings. Stopping any ongoing notifications"); cancelAllNotifications();/* www.j a v a 2 s . c om*/ } else { // the intent attached to the notification should only cancel the quick silence request, but // not launch the app Intent notificationIntent = new Intent(context, EventSilencerService.class); notificationIntent.putExtra(EventSilencerService.WAKE_REASON, RequestTypes.CANCEL_QUICKSILENCE.value); long endTime = System.currentTimeMillis() + (long) quicksilenceDurationMinutes * EventInstance.MILLISECONDS_IN_MINUTE; DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT); Date date = new Date(endTime); String formattedDate = dateFormat.format(date); String formattedString = String .format(context.getString(R.string.notification_quicksilence_description), formattedDate); // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in the new // pending intent PendingIntent pendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_CANCEL, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); //an intent to open the main app Intent openMainIntent = new Intent(context, MainActivity.class); openMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); openMainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent openMainPendIntent = PendingIntent.getActivity(context, REQUEST_CODES.QUICKSILENCE_OPEN_MAIN, openMainIntent, PendingIntent.FLAG_CANCEL_CURRENT); //An additional button to extend the quicksilence by 15min // this intent will be attached to the button on the notification Intent addMinutesIntent = new Intent(context, ExtendQuicksilenceService.class); addMinutesIntent.putExtra(ExtendQuicksilenceService.ORIGINAL_END_TIMESTAMP, endTime); addMinutesIntent.putExtra(ExtendQuicksilenceService.EXTEND_LENGTH, 15); PendingIntent addMinPendIntent = PendingIntent.getService(context, REQUEST_CODES.QUICKSILENCE_ADD_TIME, addMinutesIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.notification_quicksilence_title)) .setContentText(formattedString) .setTicker(context.getString(R.string.notification_quicksilence_ticker)) .setSmallIcon(R.drawable.not_silence).setAutoCancel(true).setOngoing(true) .setContentIntent(pendIntent).setColor(context.getResources().getColor(R.color.accent)) .setTicker(context.getString(R.string.notification_quicksilence_ticker)); notBuilder.addAction(R.drawable.app_mono_small, "Open Tacere", openMainPendIntent); //the +15 button should only be available in the Pro version Authenticator authenticator = new Authenticator(context); if (authenticator.isAuthenticated()) { notBuilder.addAction(R.drawable.not_clock, "+15", addMinPendIntent); } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID); nm.notify(NOTIFICATION_ID, notBuilder.build()); } }
From source file:Main.java
public Main() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);// w w w .j a va 2s . c om add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
From source file:com.bdb.weather.display.day.DayWindPane.java
@Override public List<SeriesControl> configure(Menu menu) { List<SeriesControl> controls = new ArrayList<>(); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_WIND_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_WIND_DIRECTION_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_WIND_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_WIND_DIRECTION_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_GUST_SPEED_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_GUST_DIRECTION_SERIES, false)); WindItemRenderer renderer = new WindItemRenderer(); getPlot().setRenderer(renderer);// w w w. j a v a 2 s . c o m WeatherSenseConstants.configureGustRenderer(renderer, GUST_SERIES_INDEX); StandardXYToolTipGenerator ttgen = new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(DateFormat.SHORT), Speed.getDefaultFormatter()); getPlot().getRenderer().setBaseToolTipGenerator(ttgen); return controls; }
From source file:org.codekaizen.vtj.text.BpDateFormatTest.java
/** * DOCUMENT ME!// www . j a v a 2 s . com */ public void testFormatting() { DateFormat fmt1 = null; DateFormat fmt2 = null; Date date = null; String s1 = null; String s2 = null; date = new Date(); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, null); fmt2 = DateFormat.getDateTimeInstance(); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_ONLY, null); fmt2 = DateFormat.getDateInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_TIME_ONLY, null); fmt2 = DateFormat.getTimeInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_FULL_DATE, null); fmt2 = DateFormat.getDateInstance(DateFormat.FULL); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, Locale.CANADA_FRENCH); fmt2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.CANADA_FRENCH); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); }
From source file:net.pmarks.chromadoze.MainFragment.java
@Override public void onNoiseServicePercentChange(int percent, Date stopTimestamp, int stopReasonId) { boolean showGenerating = false; boolean showStopReason = false; if (percent < 0) { mPercentBar.setVisibility(View.INVISIBLE); // While the service is stopped, show what event caused it to stop. showStopReason = (stopReasonId != 0); } else if (percent < 100) { mPercentBar.setVisibility(View.VISIBLE); mPercentBar.setProgress(percent); showGenerating = true;/*from w ww . j ava 2s . co m*/ } else { mPercentBar.setVisibility(View.INVISIBLE); // While the service is active, only the restart event is worth showing. showStopReason = (stopReasonId == R.string.stop_reason_restarted); } if (showStopReason) { // Expire the message after 12 hours, to avoid date ambiguity. long diff = new Date().getTime() - stopTimestamp.getTime(); if (diff > 12 * 3600 * 1000L) { showStopReason = false; } } if (showGenerating) { mStateText.setText(R.string.generating); } else if (showStopReason) { String timeFmt = DateFormat.getTimeInstance(DateFormat.SHORT).format(stopTimestamp); mStateText.setText(timeFmt + ": " + getString(stopReasonId)); } else { mStateText.setText(""); } }
From source file:SpinnerTest.java
public SpinnerFrame() { setTitle("SpinnerTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);/* www. jav a 2 s . c o m*/ add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
From source file:op.tools.SYSCalendar.java
public static ListCellRenderer getTimeRenderer() { return new ListCellRenderer() { DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); @Override/*w ww. ja v a 2s .c om*/ public Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected, boolean cellHasFocus) { String text; if (o == null) { text = SYSTools.xx("misc.commands.>>noselection<<"); } else if (o instanceof Date) { Date date = (Date) o; text = timeFormat.format(date) + " " + SYSTools.xx("misc.msg.Time.short"); } else { text = o.toString(); } return new DefaultListCellRenderer().getListCellRendererComponent(jList, text, i, isSelected, cellHasFocus); } }; }