private XMLGregorianCalendar populateDate(OpaAttribute input) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date = null; XMLGregorianCalendar xmlDate = null; try { date = df.parse(input.getValue()); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); xmlDate = DatatypeFactory.newInstance() .newXMLGregorianCalendarDate( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.getTimeZone().LONG); } catch (ParseException e) { throw new RuntimeException("Cannot convert inputValue to Date : " + input.getValue()); } catch (DatatypeConfigurationException e) { throw new RuntimeException("Cannot convert inputValue to Date : " + input.getValue()); } return xmlDate; }
private String formatDateTimeZone(final XMLGregorianCalendar calendar) { final GregorianCalendar gc = calendar.toGregorianCalendar(); final Date dateTime = gc.getTime(); final TimeZone timeZone = gc.getTimeZone(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); sdf.setTimeZone(timeZone); return sdf.format(dateTime); }
private String getTimeStamp() { GregorianCalendar cal = new GregorianCalendar(); TimeZone tz = TimeZone.getTimeZone("EST5EDT"); TimeZone calTz = cal.getTimeZone(); long millis = cal.getTimeInMillis(); int differenceTz = calTz.getOffset(millis) - tz.getOffset(millis); millis = cal.getTimeInMillis() - (long) differenceTz; return DATE_FORMAT.format(new Date(millis)); }
public DateTimePropertyInputField( final Object value, final UpdateStatus status, final Color bgColor) { setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); setBackground(bgColor); GregorianCalendar cal = (value == null ? new GregorianCalendar() : (GregorianCalendar) value); timezone = cal.getTimeZone(); day = new SpinnerNumberModel(cal.get(Calendar.DATE), 1, 31, 1); addSpinner(new JSpinner(day), status); month = new SpinnerListModel(MONTH_STRINGS); month.setValue(MONTH_STRINGS[cal.get(Calendar.MONTH)]); JSpinner monthSpinner = new JSpinner(month); JComponent editor = monthSpinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { JFormattedTextField tf = ((JSpinner.DefaultEditor) editor).getTextField(); tf.setColumns(6); tf.setHorizontalAlignment(JTextField.RIGHT); } addSpinner(monthSpinner, status); year = new SpinnerNumberModel(cal.get(Calendar.YEAR), 0, 9999, 1); JSpinner yearSpinner = new JSpinner(year); yearSpinner.setEditor(new JSpinner.NumberEditor(yearSpinner, "#")); yearSpinner.getEditor().setBackground(bgColor); addSpinner(yearSpinner, status); add(new JLabel(" ")); hour = new SpinnerNumberModel(cal.get(Calendar.HOUR_OF_DAY), 0, 23, 1); JSpinner hourSpinner = new JSpinner(hour); addSpinner(hourSpinner, status); add(new JLabel(":")); min = new SpinnerNumberModel(cal.get(Calendar.MINUTE), 0, 59, 1); JSpinner minSpinner = new JSpinner(min); addSpinner(minSpinner, status); add(new JLabel(":")); sec = new SpinnerNumberModel(cal.get(Calendar.SECOND), 0, 59, 1); JSpinner secSpinner = new JSpinner(sec); addSpinner(secSpinner, status); add(new JLabel(" " + timezone.getDisplayName(true, TimeZone.SHORT))); }
/** * @param years [1960-20xx] * @param months [1-12] * @param days [1-31] * @param hours [0-23] * @param minutes [0-59] * @param seconds [0-59] * @param millis [0-99] * @param micros [0-99] * @param nanos [0-99] * @return Timestamp */ public static TimestampValue from( final int years, final int months, final int days, final int hours, final int minutes, final int seconds, final int millis, final int micros, final int nanos) { final GregorianCalendar cal = new GregorianCalendar(years, months - 1, days, hours, minutes, seconds); final long offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()); final Timestamp timestamp = new Timestamp(cal.getTimeInMillis() + offset); timestamp.setNanos( (millis * TimestampValue.MILLIS_TO_NANOS) + (micros * TimestampValue.MICROS_TO_NANOS) + nanos); return TimestampValue.from(timestamp); }
/* * (non-Javadoc) * @see org.datanucleus.store.mapping.JavaTypeMapping#setObject(org.datanucleus.ExecutionContext, java.lang.Object, * int[], java.lang.Object) */ public void setObject(ExecutionContext ec, PreparedStatement ps, int[] exprIndex, Object value) { GregorianCalendar cal = (GregorianCalendar) value; if (singleColumn) { // (Timestamp) implementation Timestamp ts = null; if (cal != null) { ts = new Timestamp(cal.getTimeInMillis()); } // Server timezone will be applied in the RDBMSMapping at persistence getDatastoreMapping(0).setObject(ps, exprIndex[0], ts); } else { // (Timestamp millisecs, Timezone) implementation if (cal == null) { getDatastoreMapping(0).setObject(ps, exprIndex[0], null); getDatastoreMapping(1).setObject(ps, exprIndex[1], null); } else { getDatastoreMapping(0).setLong(ps, exprIndex[0], cal.getTime().getTime()); getDatastoreMapping(1).setString(ps, exprIndex[1], cal.getTimeZone().getID()); } } }
public OrderDlg(SampleFrame owner) { super(owner, true); m_parent = owner; setTitle("Sample"); java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.weighty = 100; gbc.fill = GridBagConstraints.BOTH; gbc.gridheight = 1; // create id panel IBGridBagPanel pId = new IBGridBagPanel(); pId.setBorder(BorderFactory.createTitledBorder("Message Id")); addGBComponent(pId, new JLabel("Id"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pId, m_Id, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create contract panel IBGridBagPanel pContractDetails = new IBGridBagPanel(); pContractDetails.setBorder(BorderFactory.createTitledBorder("Contract Info")); addGBComponent( pContractDetails, new JLabel("Contract Id"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_conId, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Symbol"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_symbol, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Security Type"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_secType, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Expiry"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_expiry, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Strike"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_strike, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Put/Call"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_right, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Option Multiplier"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_multiplier, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Exchange"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_exchange, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Primary Exchange"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_primaryExch, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Currency"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_currency, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Local Symbol"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_localSymbol, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Trading Class"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_tradingClass, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Include Expired"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pContractDetails, m_includeExpired, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Sec Id Type"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_secIdType, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pContractDetails, new JLabel("Sec Id"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pContractDetails, m_secId, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create order panel IBGridBagPanel pOrderDetails = new IBGridBagPanel(); pOrderDetails.setBorder(BorderFactory.createTitledBorder("Order Info")); addGBComponent( pOrderDetails, new JLabel("Action"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_action, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Total Order Size"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_totalQuantity, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Order Type"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_orderType, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Lmt Price / Option Price / Volatility"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_lmtPrice, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Aux Price / Underlying Price"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_auxPrice, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Good After Time"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_goodAfterTime, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOrderDetails, new JLabel("Good Till Date"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pOrderDetails, m_goodTillDate, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create marketDepth panel IBGridBagPanel pMarketDepth = new IBGridBagPanel(); pMarketDepth.setBorder(BorderFactory.createTitledBorder("Market Depth")); addGBComponent( pMarketDepth, new JLabel("Number of Rows"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pMarketDepth, m_marketDepthRowTextField, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create marketData panel IBGridBagPanel pMarketData = new IBGridBagPanel(); pMarketData.setBorder(BorderFactory.createTitledBorder("Market Data")); addGBComponent( pMarketData, new JLabel("Generic Tick Tags"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pMarketData, m_genericTicksTextField, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pMarketData, m_snapshotMktDataTextField, gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); // create options exercise panel IBGridBagPanel pOptionsExercise = new IBGridBagPanel(); pOptionsExercise.setBorder(BorderFactory.createTitledBorder("Options Exercise")); addGBComponent( pOptionsExercise, new JLabel("Action (1 or 2)"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pOptionsExercise, m_exerciseActionTextField, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOptionsExercise, new JLabel("Number of Contracts"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pOptionsExercise, m_exerciseQuantityTextField, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pOptionsExercise, new JLabel("Override (0 or 1)"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pOptionsExercise, m_overrideTextField, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create historical data panel IBGridBagPanel pBackfill = new IBGridBagPanel(); pBackfill.setBorder(BorderFactory.createTitledBorder("Historical Data Query")); GregorianCalendar gc = new GregorianCalendar(); gc.setTimeZone(TimeZone.getTimeZone("GMT")); String dateTime = "" + gc.get(Calendar.YEAR) + pad(gc.get(Calendar.MONTH) + 1) + pad(gc.get(Calendar.DAY_OF_MONTH)) + " " + pad(gc.get(Calendar.HOUR_OF_DAY)) + ":" + pad(gc.get(Calendar.MINUTE)) + ":" + pad(gc.get(Calendar.SECOND)) + " " + gc.getTimeZone().getDisplayName(false, TimeZone.SHORT); m_BackfillEndTime.setText(dateTime); addGBComponent( pBackfill, new JLabel("End Date/Time"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_BackfillEndTime, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent(pBackfill, new JLabel("Duration"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_BackfillDuration, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pBackfill, new JLabel("Bar Size Setting (1 to 11)"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_BarSizeSetting, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pBackfill, new JLabel("What to Show"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_WhatToShow, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pBackfill, new JLabel("Regular Trading Hours (1 or 0)"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_UseRTH, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); addGBComponent( pBackfill, new JLabel("Date Format Style (1 or 2)"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent(pBackfill, m_FormatDate, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create marketDataType panel IBGridBagPanel pMarketDataType = new IBGridBagPanel(); pMarketDataType.setBorder(BorderFactory.createTitledBorder("Market Data Type")); addGBComponent( pMarketDataType, new JLabel("Market Data Type"), gbc, COL1_WIDTH, GridBagConstraints.RELATIVE); addGBComponent( pMarketDataType, m_marketDataTypeCombo, gbc, COL2_WIDTH, GridBagConstraints.REMAINDER); // create mid Panel JPanel pMidPanel = new JPanel(); pMidPanel.setLayout(new BoxLayout(pMidPanel, BoxLayout.Y_AXIS)); pMidPanel.add(pContractDetails, BorderLayout.CENTER); pMidPanel.add(pOrderDetails, BorderLayout.CENTER); pMidPanel.add(pMarketDepth, BorderLayout.CENTER); pMidPanel.add(pMarketData, BorderLayout.CENTER); pMidPanel.add(pOptionsExercise, BorderLayout.CENTER); pMidPanel.add(pBackfill, BorderLayout.CENTER); pMidPanel.add(pMarketDataType, BorderLayout.CENTER); // create order button panel JPanel pOrderButtonPanel = new JPanel(); pOrderButtonPanel.add(m_sharesAlloc); pOrderButtonPanel.add(m_comboLegs); pOrderButtonPanel.add(m_btnUnderComp); pOrderButtonPanel.add(m_btnAlgoParams); pOrderButtonPanel.add(m_btnSmartComboRoutingParams); pMidPanel.add(pOrderButtonPanel, BorderLayout.CENTER); // create button panel JPanel buttonPanel = new JPanel(); buttonPanel.add(m_ok); buttonPanel.add(m_cancel); // create action listeners m_sharesAlloc.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onSharesAlloc(); } }); m_comboLegs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onAddComboLegs(); } }); m_btnUnderComp.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onBtnUnderComp(); } }); m_btnAlgoParams.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onBtnAlgoParams(); } }); m_btnSmartComboRoutingParams.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onBtnSmartComboRoutingParams(); } }); m_ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOk(); } }); m_cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); // create top panel JPanel topPanel = new JPanel(); topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS)); topPanel.add(pId); topPanel.add(pMidPanel); // create dlg box getContentPane().add(topPanel, BorderLayout.CENTER); getContentPane().add(buttonPanel, BorderLayout.SOUTH); JScrollPane scroller = new JScrollPane(topPanel); this.add(scroller, BorderLayout.CENTER); pack(); }