List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance()
From source file:FieldValidator.java
private static JComponent createContent() { Dimension labelSize = new Dimension(80, 20); Box box = Box.createVerticalBox(); // A single LayerUI for all the fields. LayerUI<JFormattedTextField> layerUI = new ValidationLayerUI(); // Number field. JLabel numberLabel = new JLabel("Number:"); numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); numberLabel.setPreferredSize(labelSize); NumberFormat numberFormat = NumberFormat.getInstance(); JFormattedTextField numberField = new JFormattedTextField(numberFormat); numberField.setColumns(16);/*www .ja v a 2s .c o m*/ numberField.setFocusLostBehavior(JFormattedTextField.PERSIST); numberField.setValue(42); JPanel numberPanel = new JPanel(); numberPanel.add(numberLabel); numberPanel.add(new JLayer<JFormattedTextField>(numberField, layerUI)); // Date field. JLabel dateLabel = new JLabel("Date:"); dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); dateLabel.setPreferredSize(labelSize); DateFormat dateFormat = DateFormat.getDateInstance(); JFormattedTextField dateField = new JFormattedTextField(dateFormat); dateField.setColumns(16); dateField.setFocusLostBehavior(JFormattedTextField.PERSIST); dateField.setValue(new java.util.Date()); JPanel datePanel = new JPanel(); datePanel.add(dateLabel); datePanel.add(new JLayer<JFormattedTextField>(dateField, layerUI)); // Time field. JLabel timeLabel = new JLabel("Time:"); timeLabel.setHorizontalAlignment(SwingConstants.RIGHT); timeLabel.setPreferredSize(labelSize); DateFormat timeFormat = DateFormat.getTimeInstance(); JFormattedTextField timeField = new JFormattedTextField(timeFormat); timeField.setColumns(16); timeField.setFocusLostBehavior(JFormattedTextField.PERSIST); timeField.setValue(new java.util.Date()); JPanel timePanel = new JPanel(); timePanel.add(timeLabel); timePanel.add(new JLayer<JFormattedTextField>(timeField, layerUI)); // Put them all in the box. box.add(Box.createGlue()); box.add(numberPanel); box.add(Box.createGlue()); box.add(datePanel); box.add(Box.createGlue()); box.add(timePanel); return box; }
From source file:com.haulmont.chile.core.datatypes.impl.TimeDatatype.java
@Override public Date parse(String value) throws ParseException { if (StringUtils.isBlank(value)) { return null; }//from w w w . j av a2s . c om DateFormat format; if (formatPattern != null) { format = new SimpleDateFormat(formatPattern); } else { format = DateFormat.getTimeInstance(); } return format.parse(value.trim()); }
From source file:org.kalypso.model.wspm.core.profil.validator.ValidatorRuleSet.java
public IStatus validateProfile(final IProfile profil, final IValidatorMarkerCollector collector, final String[] excludeIDs, final IProgressMonitor monitor) { final IValidatorRule[] rules = m_rules; final List<IStatus> stati = new ArrayList<>(); final List<String> excludeRules = java.util.Arrays.asList(excludeIDs); monitor.beginTask("Validating profile", ArrayUtils.getLength(rules)); //$NON-NLS-1$ for (final IValidatorRule rule : rules) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; if (!excludeRules.contains(rule.getID())) { try { KalypsoModelWspmCoreDebug.DEBUG_VALIDATION_MARKER.printf("rule: %s, %s\n", rule.getID(), //$NON-NLS-1$ DateFormat.getTimeInstance().format(Calendar.getInstance().getTime())); rule.validate(profil, collector); KalypsoModelWspmCoreDebug.DEBUG_VALIDATION_MARKER.printf(" end: %s, %s\n", rule.getID(), //$NON-NLS-1$ DateFormat.getTimeInstance().format(Calendar.getInstance().getTime())); } catch (final CoreException e) { stati.add(e.getStatus()); }// w w w.j a v a 2s. c o m } monitor.worked(1); } monitor.done(); if (stati.size() == 0) return Status.OK_STATUS; return new MultiStatus(KalypsoModelWspmCorePlugin.getID(), 0, stati.toArray(new IStatus[stati.size()]), Messages.getString("org.kalypso.model.wspm.core.profil.validator.ValidatorRuleSet.0"), null); //$NON-NLS-1$ }
From source file:com.example.android.customnotifications.MainActivity.java
/** * This sample demonstrates notifications with custom content views. * * <p>On API level 16 and above a big content view is also defined that is used for the * 'expanded' notification. The notification is created by the NotificationCompat.Builder. * The expanded content view is set directly on the {@link android.app.Notification} once it has been build. * (See {@link android.app.Notification#bigContentView}.) </p> * * <p>The content views are inflated as {@link android.widget.RemoteViews} directly from their XML layout * definitions using {@link android.widget.RemoteViews#RemoteViews(String, int)}.</p> *//*from ww w .j av a 2s . c om*/ private void createNotification() { // BEGIN_INCLUDE(notificationCompat) NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // END_INCLUDE(notificationCompat) // BEGIN_INCLUDE(intent) //Create Intent to launch this Activity again if the notification is clicked. Intent i = new Intent(this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(intent); // END_INCLUDE(intent) // BEGIN_INCLUDE(ticker) // Sets the ticker text builder.setTicker(getResources().getString(R.string.custom_notification)); // Sets the small icon for the ticker builder.setSmallIcon(R.drawable.ic_stat_custom); // END_INCLUDE(ticker) // BEGIN_INCLUDE(buildNotification) // Cancel the notification when clicked builder.setAutoCancel(true); // Build the notification Notification notification = builder.build(); // END_INCLUDE(buildNotification) // BEGIN_INCLUDE(customLayout) // Inflate the notification layout as RemoteViews RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); // Set text on a TextView in the RemoteViews programmatically. final String time = DateFormat.getTimeInstance().format(new Date()).toString(); final String text = getResources().getString(R.string.collapsed, time); contentView.setTextViewText(R.id.textView, text); /* Workaround: Need to set the content view here directly on the notification. * NotificationCompatBuilder contains a bug that prevents this from working on platform * versions HoneyComb. * See https://code.google.com/p/android/issues/detail?id=30495 */ notification.contentView = contentView; // Add a big content view to the notification if supported. // Support for expanded notifications was added in API level 16. // (The normal contentView is shown when the notification is collapsed, when expanded the // big content view set here is displayed.) if (Build.VERSION.SDK_INT >= 16) { // Inflate and set the layout for the expanded notification view RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded); notification.bigContentView = expandedView; } // END_INCLUDE(customLayout) // START_INCLUDE(notify) // Use the NotificationManager to show the notification NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, notification); // END_INCLUDE(notify) }
From source file:org.onebusaway.nyc.webapp.actions.wiki.IndexAction.java
public String getLastModifiedTimestamp() { if (lastModifiedTimestamp == null) return "Unknown"; return DateFormat.getDateInstance().format(lastModifiedTimestamp) + " at " + DateFormat.getTimeInstance().format(lastModifiedTimestamp); }
From source file:com.prey.actions.location.PreyGooglePlayServiceLocation.java
@Override public void onLocationChanged(Location location) { PreyLogger.d("onLocationChanged"); mCurrentLocation = location;/*from w w w. j a v a 2s . c o m*/ if (location != null) { mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); PreyLogger.d("latitude:" + location.getLatitude() + " longitude:" + location.getLongitude() + " accuracy:" + location.getAccuracy()); stopLocationUpdates(); } }
From source file:com.bdb.weather.display.day.DayTemperaturePane.java
@Override public List<SeriesControl> configure(Menu menu) { menu.getItems().add(minMaxLabelsItem); minMaxLabelsItem.setOnAction(this); List<SeriesControl> controls = new ArrayList<>(); controls.add(new SeriesControl(HistoricalSeriesInfo.INDOOR_TEMPERATURE_SERIES, true)); controls.add(new SeriesControl(HistoricalSeriesInfo.LOW_OUTDOOR_TEMPERATURE_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HIGH_OUTDOOR_TEMPERATURE_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.AVG_OUTDOOR_TEMPERATURE_SERIES, true)); controls.add(new SeriesControl(HistoricalSeriesInfo.DEW_POINT_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.HEAT_INDEX_SERIES, false)); controls.add(new SeriesControl(HistoricalSeriesInfo.WIND_CHILL_SERIES, false)); SensorManager.getInstance().getExtraSensors(SensorType.THERMOMETER).stream().forEach((sensor) -> { controls.add(new SeriesControl(sensor.getName(), false)); });// w w w . ja v a 2 s. c om XYToolTipGenerator ttg = new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getTimeInstance(), Temperature.getDefaultFormatter()); getPlot().getRenderer().setBaseToolTipGenerator(ttg); return controls; }
From source file:org.ut.biolab.medsavant.shared.util.MiscUtils.java
/** * Get a string representation of the the current time * * @return A string representing the current time *//*from www .j a v a 2 s . c om*/ public static String now() { Calendar cal = Calendar.getInstance(); return DateFormat.getTimeInstance().format(cal.getTime()); }
From source file:edu.harvard.mcz.imagecapture.RunnableJobTableModel.java
@Override public Object getValueAt(int rowIndex, int columnIndex) { Object returnvalue = null;//w w w .j a v a 2s.c om try { switch (columnIndex) { case 0: returnvalue = (Integer) rowIndex; break; case 1: returnvalue = ((RunnableJob) jobs.toArray()[rowIndex]).getName(); break; case 2: if (((RunnableJob) jobs.toArray()[rowIndex]).getStartTime() == null) { returnvalue = "----"; } else { returnvalue = DateFormat.getTimeInstance() .format(((RunnableJob) jobs.toArray()[rowIndex]).getStartTime()); } break; case 3: returnvalue = ((RunnableJob) jobs.toArray()[rowIndex]).percentComplete(); log.debug(returnvalue); break; } } catch (ArrayIndexOutOfBoundsException e) { log.debug(e.getMessage()); fireTableDataChanged(); } catch (NullPointerException e) { log.debug(e.getMessage()); fireTableDataChanged(); } return returnvalue; }
From source file:org.pentaho.platform.scheduler.QuartzExecute.java
public void execute(final JobExecutionContext context) { PentahoSystem.systemEntryPoint();//from w w w . ja v a2 s . c o m setLoggingLevel(PentahoSystem.loggingLevel); try { LocaleHelper.setLocale(Locale.getDefault()); logId = "Schedule:" + context.getJobDetail().getName(); //$NON-NLS-1$ Date now = new Date(); QuartzExecute.logger .info(Messages.getString("QuartzExecute.INFO_TRIGGER_TIME", context.getJobDetail().getName(), //$NON-NLS-1$ DateFormat.getDateInstance().format(now), DateFormat.getTimeInstance().format(now))); JobDataMap dataMap = context.getJobDetail().getJobDataMap(); // Save the user parameters for use as an agument to // parameterProvider HashMap parameters = new HashMap(); String[] keys = dataMap.getKeys(); for (String element : keys) { parameters.put(element, dataMap.get(element)); } // we need to generate a unique session id // String sessionId = "scheduler-"+this.hashCode()+"-"+new // Date().getTime(); //$NON-NLS-1$ //$NON-NLS-2$ String sessionId = "scheduler-" + UUIDUtil.getUUIDAsString(); //$NON-NLS-1$ StandaloneSession executeSession = new StandaloneSession(context.getJobDetail().getName(), sessionId); String solutionName = dataMap.getString("solution"); //$NON-NLS-1$ String actionPath = dataMap.getString("path"); //$NON-NLS-1$ String actionName = dataMap.getString("action"); //$NON-NLS-1$ String instanceId = null; String processId = this.getClass().getName(); IPentahoSession userSession = null; if (solutionName == null) { error(Messages.getErrorString("QuartzExecute.ERROR_0001_SOLUTION_NAME_MISSING")); //$NON-NLS-1$ return; } if (actionPath == null) { error(Messages.getErrorString("QuartzExecute.ERROR_0002_ACTION_PATH_MISSING")); //$NON-NLS-1$ return; } if (actionName == null) { error(Messages.getErrorString("QuartzExecute.ERROR_0003_ACTION_NAME_MISSING")); //$NON-NLS-1$ return; } if (QuartzExecute.debug) { debug(Messages.getString("QuartzExecute.DEBUG_EXECUTION_INFO", //$NON-NLS-1$ solutionName + "/" + actionPath + "/" + actionName)); //$NON-NLS-1$ //$NON-NLS-2$ } boolean backgroundExecution = "true" //$NON-NLS-1$ .equals(dataMap.getString(QuartzBackgroundExecutionHelper.BACKGROUND_EXECUTION_FLAG)); IOutputHandler outputHandler = null; SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters); IBackgroundExecution backgroundExecutionHandler = PentahoSystem.get(IBackgroundExecution.class, executeSession); if (backgroundExecution) { String location = dataMap .getString(QuartzBackgroundExecutionHelper.BACKGROUND_CONTENT_LOCATION_STR); String fileName = dataMap.getString(QuartzBackgroundExecutionHelper.BACKGROUND_CONTENT_GUID_STR); String userName = dataMap.getString(QuartzBackgroundExecutionHelper.BACKGROUND_USER_NAME_STR); userSession = backgroundExecutionHandler.getEffectiveUserSession(userName); // session.setAuthenticated(userName); outputHandler = backgroundExecutionHandler.getContentOutputHandler(location, fileName, solutionName, userSession, parameterProvider); } else { outputHandler = new SimpleOutputHandler((OutputStream) null, false); // Check to see if the user was authenticated (via the portal) // in the JobSchedulerComponent String userName = dataMap.getString("username"); //$NON-NLS-1$ if (userName != null) { // Well, we got a valid user name - let's try to use the // background execute component to establish the user userSession = backgroundExecutionHandler.getEffectiveUserSession(userName); } else { // User wasn't authenticated when the job was scheduled - // use default behavior from old... userSession = executeSession; } } // set the session so that anything who needs to access it will have // a single safe place to get one. in particular, some content generators // will need a session. PentahoSessionHolder.setSession(userSession); // get content generator int lastDot = actionName.lastIndexOf('.'); String type = actionName.substring(lastDot + 1); IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, userSession); IContentGenerator generator = null; try { generator = pluginManager.getContentGeneratorForType(type, userSession); } catch (Throwable t) { // no generator } if (generator == null) { IRuntimeContext rt = null; try { BaseRequestHandler requestHandler = new BaseRequestHandler(userSession, null, outputHandler, parameterProvider, null); requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(userSession)); requestHandler.setInstanceId(instanceId); requestHandler.setProcessId(processId); requestHandler.setAction(actionPath, actionName); requestHandler.setSolutionName(solutionName); rt = requestHandler.handleActionRequest(0, 0); if (backgroundExecution) { if (!outputHandler.contentDone()) { IContentItem outputContentItem = outputHandler.getOutputContentItem( IOutputHandler.RESPONSE, IOutputHandler.CONTENT, rt.getActionTitle(), null, rt.getSolutionName(), rt.getInstanceId(), "text/html"); //$NON-NLS-1$ outputContentItem.setMimeType("text/html"); //$NON-NLS-1$ try { if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) { StringBuffer buffer = new StringBuffer(); PentahoSystem.get(IMessageFormatter.class, userSession) .formatSuccessMessage("text/html", rt, buffer, false); //$NON-NLS-1$ OutputStream os = outputContentItem.getOutputStream(actionName); os.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding())); os.close(); } else { // we need an error message... StringBuffer buffer = new StringBuffer(); PentahoSystem.get(IMessageFormatter.class, userSession).formatFailureMessage( "text/html", rt, buffer, requestHandler.getMessages()); //$NON-NLS-1$ OutputStream os = outputContentItem.getOutputStream(actionName); os.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding())); os.close(); } } catch (IOException ex) { QuartzExecute.logger.error(ex.getLocalizedMessage()); } } } IContentItem outputContentItem = outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, rt.getSolutionName(), rt.getInstanceId(), "text/html"); //$NON-NLS-1$ if (outputContentItem != null) { context.put(QuartzBackgroundExecutionHelper.BACKGROUND_CONTENT_GUID_STR, outputContentItem.getId()); } } finally { if (rt != null) { rt.dispose(); } // Destroy the session: it was only created to execute this job. PentahoSessionHolder.removeSession(); } } else { // use content generator to execute generator.setOutputHandler(outputHandler); generator.setItemName(actionName); generator.setInstanceId(instanceId); generator.setSession(userSession); Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>(); parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider); parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(userSession)); generator.setParameterProviders(parameterProviders); try { generator.createContent(); // we succeeded if (backgroundExecution && !outputHandler.contentDone()) { IContentItem outputContentItem = outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, actionName, null, solutionName, instanceId, "text/html"); //$NON-NLS-1$ outputContentItem.setMimeType("text/html"); //$NON-NLS-1$ String message = Messages.getString("QuartzExecute.DEBUG_FINISHED_EXECUTION", context.getJobDetail().getName()); OutputStream os = outputContentItem.getOutputStream(actionName); os.write(message.getBytes(LocaleHelper.getSystemEncoding())); os.close(); } } catch (Exception e) { e.printStackTrace(); // we need an error message... if (backgroundExecution && !outputHandler.contentDone()) { IContentItem outputContentItem = outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, actionName, null, solutionName, instanceId, "text/html"); //$NON-NLS-1$ outputContentItem.setMimeType("text/html"); //$NON-NLS-1$ String message = Messages.getString("QuartzExecute.DEBUG_FAILED_EXECUTION", context.getJobDetail().getName()); try { OutputStream os = outputContentItem.getOutputStream(actionName); os.write(message.getBytes(LocaleHelper.getSystemEncoding())); os.close(); } catch (Exception ex) { QuartzExecute.logger.debug(Messages.getString("QuartzExecute.DEBUG_FAILED_EXECUTION", //$NON-NLS-1$ context.getJobDetail().getName())); } } } finally { // Destroy the session: it was only created to execute this job. PentahoSessionHolder.removeSession(); } } if (QuartzExecute.debug) { QuartzExecute.logger.debug(Messages.getString("QuartzExecute.DEBUG_FINISHED_EXECUTION", //$NON-NLS-1$ context.getJobDetail().getName())); } } finally { PentahoSystem.systemExitPoint(); } }