List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:com.nikonhacker.gui.EmulatorUI.java
public EmulatorUI() { super(ApplicationInfo.getNameVersion() + " - (none) / (none)"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); prefs = Prefs.load();//from ww w. j a v a2s. c o m // Apply register label prefs immediately FrCPUState.initRegisterLabels(prefs.getOutputOptions(Constants.CHIP_FR)); TxCPUState.initRegisterLabels(prefs.getOutputOptions(Constants.CHIP_TX)); // Create and set up the Emulation Framework framework = new EmulationFramework(prefs); //Set up the GUI. setJMenuBar(createMenuBar()); toolbarButtonMargin = new Insets(2, 14, 2, 14); JPanel[] contentPane = new JPanel[2]; for (int chip = 0; chip < 2; chip++) { // This is the contentPane that will make one side of the JSplitPane contentPane[chip] = new JPanel(new BorderLayout()); // First we create a toolbar and put it on top toolBar[chip] = createToolBar(chip); contentPane[chip].add(toolBar[chip], BorderLayout.NORTH); // Then we prepare a "desktop" panel and put it at the center // This subclass of JDesktopPane implements Scrollable and has a size which auto-adapts dynamically // to the size and position of its internal frames mdiPane[chip] = new ScrollableDesktop(); mdiPane[chip].setBackground(Constants.CHIP_BACKGROUND_COLOR[chip]); mdiPane[chip].setOpaque(true); // We wrap it inside a panel to force a stretch to the size of the JSplitPane panel // Otherwise, as the size of the panel auto-adapts, it starts at 0,0 if no component is present, // so the background color would only be only visible in the bounding box surrounding the internal frames JPanel forcedStretchPanel = new JPanel(new BorderLayout()); forcedStretchPanel.add(mdiPane[chip], BorderLayout.CENTER); // And we wrap the result in a JScrollPane to take care of the actual scrolling, // before adding it at the center contentPane[chip].add(new JScrollPane(forcedStretchPanel), BorderLayout.CENTER); // Finally, we prepare the status bar and add it at the bottom statusBar[chip] = new JLabel(statusText[chip]); statusBar[chip].setOpaque(true); statusBar[chip].setBackground(STATUS_BGCOLOR_DEFAULT); statusBar[chip].setMinimumSize(new Dimension(0, 0)); contentPane[chip].add(statusBar[chip], BorderLayout.SOUTH); } setIconImages(Arrays.asList( Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_16x16.png")), Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_20x20.png")), Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_24x24.png")), Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_32x32.png")), Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_64x64.png")))); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, contentPane[Constants.CHIP_FR], contentPane[Constants.CHIP_TX]); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(0.5); setContentPane(splitPane); applyPrefsToUI(); for (int chip = 0; chip < 2; chip++) { if (imageFile[chip] != null) { // There was a command line argument. if (imageFile[chip].exists()) { initialize(chip); } else { JOptionPane.showMessageDialog(this, "Given " + Constants.CHIP_LABEL[chip] + " firmware file does not exist:\n" + imageFile[chip].getAbsolutePath(), "File not found", JOptionPane.WARNING_MESSAGE); } } else { // Check if a FW file is stored in the prefs String firmwareFilename = prefs.getFirmwareFilename(chip); if (firmwareFilename != null) { File firmwareFile = new File(firmwareFilename); if (firmwareFile.exists()) { imageFile[chip] = firmwareFile; initialize(chip); } else { JOptionPane.showMessageDialog(this, Constants.CHIP_LABEL[chip] + " firmware file stored in preference file cannot be found:\n" + firmwareFile.getAbsolutePath(), "File not found", JOptionPane.WARNING_MESSAGE); } } } } framework.setupCallbacks(getCallbackHandler(0), getCallbackHandler(1)); restoreMainWindowSettings(); pack(); updateStates(); //Make dragging a little faster but perhaps uglier. // mdiPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); // Update title bars with emulator statistics every second new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { updateStatusBar(Constants.CHIP_FR); updateStatusBar(Constants.CHIP_TX); } }).start(); }
From source file:junk.gui.HazardSpectrumApplication.java
/** * this function is called to draw the graph *//*ww w .jav a 2s . co m*/ private void addButton() { // do not show warning messages in IMR gui bean. this is needed // so that warning messages for site parameters are not shown when Add graph is clicked imrGuiBean.showWarningMessages(false); try { calc = new HazardCurveCalculator(); } catch (Exception e) { e.printStackTrace(); } // check if progress bar is desired and set it up if so if (this.progressCheckBox.isSelected()) { Thread t = new Thread(this); t.start(); timer = new Timer(200, new ActionListener() { public void actionPerformed(ActionEvent evt) { try { if (calc.getCurrRuptures() != -1) { progressClass.updateProgress(numSA_PeriodValDone, numSA_PeriodVals); } } catch (Exception e) { e.printStackTrace(); } if (isIndividualCurves) { drawGraph(); //isIndividualCurves = false; } if (hazCalcDone) { timer.stop(); progressClass.dispose(); drawGraph(); } } }); // timer for disaggregation progress bar /*disaggTimer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent evt) { if(disaggCalc.getCurrRuptures()!=-1) disaggProgressClass.updateProgress(disaggCalc.getCurrRuptures(), disaggCalc.getTotRuptures()); if (disaggCalc.done()) { // Toolkit.getDefaultToolkit().beep(); disaggTimer.stop(); disaggProgressClass.dispose(); } } });*/ } else { this.computeHazardCurve(); this.drawGraph(); } }
From source file:com.josue.tileset.editor.Editor.java
private void mountButtons(List<Tile> tiles, int cols, int rows) { imagePanel.removeAll();//from www .j av a 2 s.c o m if (animatedPerformer != null) { animatedPerformer.stop(); animatedPerformer = null; } imagePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); Dimension dimension = new Dimension(cols * TILE_SIZE, rows * TILE_SIZE); for (Tile tile : tiles) { final JLabel tileLabel = new JLabel(); tileLabel.setIcon(new ImageIcon(tile.getImage())); Dimension labelDimension = new Dimension(TILE_SIZE, TILE_SIZE); tileLabel.setMinimumSize(labelDimension); tileLabel.setMaximumSize(labelDimension); tileLabel.setPreferredSize(labelDimension); tileLabel.setSize(labelDimension); tileLabel.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) {//select animated sequence if (animatedAction.isSelected()) { addAnimatedTile(tile); } else { addLightSourceTile(tile); } } else { if (animatedPerformer != null) { animatedPerformer.stop(); } Iterator<JLabel> iterator = tileLabels.values().iterator(); while (iterator.hasNext()) { JLabel next = iterator.next(); next.revalidate(); } imagePanel.repaint(); for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) { Tile key = entry.getKey(); JLabel value = entry.getValue(); value.setBorder(null); //clear borders } selectedTile = tile;//this isolate for the next operations tileLabel.setBorder(new LineBorder(Color.RED, 2)); previewLabel.setIcon(new ImageIcon(tile.getImage())); animatedTb.setSelected(selectedTile.isAnimated()); lightTb.setSelected(selectedTile.isLight()); solidTb.setSelected(selectedTile.isSolid()); if (tile.isAnimated()) { for (Integer animatesTileOffset : selectedTile.getAnimation().getAnimatedSequence()) { //display animated borders for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) { Tile key = entry.getKey(); JLabel value = entry.getValue(); if (key.getId() == selectedTile.getId() + animatesTileOffset) { value.setBorder(new LineBorder(Color.BLUE, 2)); } } } animatedPerformer = new Timer( (int) (selectedTile.getAnimation().getAnimationInterval()), new TileAnimator(selectedTile, previewLabel, loadedTiles)); animatedPerformer.start(); } if (selectedTile.isLight()) {//light color has preference for (Tile tile : tiles) { if (tile.getId() == selectedTile.getLightTileId()) { JLabel found = tileLabels.get(tile); found.setBorder(new LineBorder(Color.YELLOW, 2)); break; } } } } } @Override public void mouseExited(MouseEvent e) { if (selectedTile != null && selectedTile.getAnimation() != null && selectedTile.getAnimation() .getAnimatedSequence().contains(tile.getId() - selectedTile.getId())) { tileLabel.setBorder(new LineBorder(Color.BLUE, 2)); } else if (selectedTile != null && selectedTile.isLight() && selectedTile.getLightTileId() == tile.getId()) { tileLabel.setBorder(new LineBorder(Color.YELLOW, 2)); } else if (selectedTile != null) { JLabel get = tileLabels.get(selectedTile); if (!get.equals(tileLabel)) { //keep the red border if is the selected tileLabel.setBorder(null); } } else { tileLabel.setBorder(null); } } @Override public void mouseEntered(MouseEvent e) { if (selectedTile != null && selectedTile.getAnimation() != null && !selectedTile.getAnimation().getAnimatedSequence() .contains(tile.getId() - selectedTile.getId()) && tile.getLight() != null && tile.getLight().getLightTileOffset() != 0) { tileLabel.setBorder(new LineBorder(Color.RED, 2)); } else if (selectedTile == null) { tileLabel.setBorder(new LineBorder(Color.RED, 2)); } } }); tileLabels.put(tile, tileLabel); imagePanel.add(tileLabel); } imagePanel.setMaximumSize(dimension); imagePanel.setMinimumSize(dimension); imagePanel.setPreferredSize(dimension); imagePanel.revalidate(); imagePanel.repaint(); this.pack(); }
From source file:net.sf.dvstar.transmission.TransmissionView.java
private void initTimers() { // status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { @Override//w w w.jav a 2s. c o m public void actionPerformed(ActionEvent e) { //!!statusMessageLabel.setText("");!! //String spd = updateStatusLine(); //deault info text //statusMessageLabel.setText(spd); } }); messageTimer.setRepeats(false); refreshTimer = new Timer(10000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ApplicationContext ctx = getApplication().getContext(); Task task = new DoRefreshTask(getApplication(), false, false); ctx.getTaskService().execute(task); } }); refreshTimer.setRepeats(true); refreshTimer.stop(); updaterTimer = new Timer(10000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ApplicationContext ctx = getApplication().getContext(); Task task = new DoUpdateStatusLine(getApplication()); ctx.getTaskService().execute(task); progressBar.setVisible(false); progressBar.setValue(0); /** @todo ? ? ? 0,5 ? ??? ? */ if ((rowSelectionNew = tblTorrentList.getSelectedRow()) > 0 && rowSelectionNew != rowSelectionOld) { rowSelectionOld = rowSelectionNew; } rowSelectionOld = tblTorrentList.getSelectedRow(); rowSelectionNew = -1; try { Thread.sleep(500); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } rowSelectionNew = tblTorrentList.getSelectedRow(); if (rowSelectionNew == rowSelectionOld) { if (tblTorrentList.getSelectedRow() > 0) { System.out.println("!!! [actionPerformed] Selected = " + rowSelectionNew); taskDoUpdateTorrentDetails = new DoUpdateTorrentDetails(getApplication(), rowSelectionNew); ctx.getTaskService().execute(taskDoUpdateTorrentDetails); progressBar.setVisible(false); progressBar.setValue(0); } } } }); updaterTimer.setRepeats(true); updaterTimer.stop(); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); }
From source file:com.josue.tileset.editor.Editor.java
private void addAnimatedTile(Tile tile) { if (!tile.equals(selectedTile) && selectedTile != null) { //cannot add the same tile as sequence JLabel label = tileLabels.get(tile); int animatedTileOffset = tile.getId() - selectedTile.getId(); if (selectedTile.getAnimation() != null && selectedTile.getAnimation().getAnimatedSequence().contains(animatedTileOffset)) { selectedTile.getAnimation().getAnimatedSequence() .remove(selectedTile.getAnimation().getAnimatedSequence().indexOf(animatedTileOffset)); if (selectedTile.getAnimation().getAnimatedSequence().isEmpty()) { //is not an animated tile anymore label.setBorder(null);//from www. jav a 2 s. co m selectedTile.setAnimation(null); } if (animatedPerformer != null) { animatedPerformer.stop(); } } else {//new animated tile if (animatedPerformer != null) { animatedPerformer.stop(); } if (!selectedTile.isAnimated()) { selectedTile.setAnimation(new Animation()); } selectedTile.getAnimation().getAnimatedSequence().add(animatedTileOffset); label.setBorder(new LineBorder(Color.BLUE, 2)); animatedTb.setSelected(true); animatedPerformer = new Timer((int) (selectedTile.getAnimation().getAnimationInterval()), new TileAnimator(selectedTile, previewLabel, loadedTiles)); animatedPerformer.start(); } } }
From source file:view.Dashboard.java
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed try {// ww w .j a v a 2 s . c o m if (cc.getReadStatus()) { timer.stop(); cc.stopReading(); setStartText(); } else { if (KPField.getText().isEmpty() || KIField.getText().isEmpty() || KDField.getText().isEmpty() || setPointField.getText().isEmpty()) { JOptionPane.showMessageDialog(rootPane, "KP, KD, KI, or Setpoint is still empty", "ERROR", JOptionPane.ERROR_MESSAGE); } else { if (Double.parseDouble(KPField.getText()) > 50 || Double.parseDouble(KPField.getText()) < 0) { JOptionPane.showMessageDialog(rootPane, "KP has to be in 0 to 50", "ERROR", JOptionPane.ERROR_MESSAGE); } else if (Double.parseDouble(KIField.getText()) > 50 || Double.parseDouble(KIField.getText()) < 0) { JOptionPane.showMessageDialog(rootPane, "KI has to be in 0 to 50", "ERROR", JOptionPane.ERROR_MESSAGE); } else if (Double.parseDouble(KDField.getText()) > 50 || Double.parseDouble(KDField.getText()) < 0) { JOptionPane.showMessageDialog(rootPane, "KD has to be in 0 to 50", "ERROR", JOptionPane.ERROR_MESSAGE); } else if (Double.parseDouble(setPointField.getText()) > 12 || Double.parseDouble(setPointField.getText()) <= 0) { JOptionPane.showMessageDialog(rootPane, "Setpoint has to be between 0 to 12", "ERROR", JOptionPane.ERROR_MESSAGE); } else { timer = new Timer(40, (ActionEvent e) -> { updateChart(); }); timer.start(); cc.startReading(getKP(), getKI(), getKD(), getSetPoint(), getRotation()); setStartText(); } } } } catch (SerialPortException ex) { Logger.getLogger(Dashboard.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE); } }
From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java
/** Runs simulation with plots and logs showing progress, then produces report when completed. **/ protected void runSimulation() throws Exception { // reset outputs this.chartPanel.setChart(null); this.reportArea.setText(""); this.monthlyLogArea.setText(""); this.tradeLogArea.setText(""); // create Account final double initialCash = ((Number) this.initialCashField.getValue()).doubleValue(); final double perTradeFee = ((Number) this.perTradeFeeField.getValue()).doubleValue(); final double perShareTradeCommission = ((Number) this.perShareTradeCommissionField.getValue()) .doubleValue();/*from w w w. j av a2 s. co m*/ final DefaultTradingAccount account = new DefaultTradingAccount(this.histories, perTradeFee, perShareTradeCommission); // add observers account.addTradeObserver( new TradeTraceObserver(true, new PrintWriter(new JTextAreaWriter(this.tradeLogArea), true))); account.addTradeObserver(new PeriodTraceObserver(1, Calendar.MONTH, true, new PrintWriter(new JTextAreaWriter(this.monthlyLogArea), true))); final BalanceHistoryObserver balanceObserver = new BalanceHistoryObserver(); account.addTradeObserver(balanceObserver); final TradeWinLossObserver winLossObserver = new TradeWinLossObserver(); account.addTradeObserver(winLossObserver); final PeriodWinLossObserver monthObserver = new PeriodWinLossObserver(1, Calendar.MONTH, true); account.addTradeObserver(monthObserver); final String betaCompareIndexSymbol = this.compareIndexSymbolField.getText(); final boolean hasBetaIndex = (histories.get(betaCompareIndexSymbol) != null); BetaObserver betaObserver = null; if (hasBetaIndex) { betaObserver = new BetaObserver(betaCompareIndexSymbol); account.addTradeObserver(betaObserver); } // create strategy final String strategyText = this.strategyField.getText().trim(); final TradingStrategy strategy = loadStrategy(strategyText); this.setTitle(strategy.toString()); // plot with timer update final BalanceHistoryXYDataset accountDataset = new BalanceHistoryXYDataset(balanceObserver); final Date startDate = (Date) this.startDateField.getValue(); final Date endDate = (Date) this.endDateField.getValue(); final ValueAxis[] yAxes = plotAccountHistory(accountDataset, strategy.toString(), startDate, endDate); final ActionListener plotUpdater = new PlotUpdater(accountDataset, yAxes); final Timer refreshTimer = new Timer(1000, plotUpdater);// 1000msec cycle refreshTimer.start(); // run simulation account.initialize(startDate, initialCash); final DefaultTradingSimulator simulator = new DefaultTradingSimulator(histories); simulator.runStrategy(strategy, account, startDate, endDate); // stop plot timer refreshTimer.stop(); plotUpdater.actionPerformed(null); // one last time. // report final StringWriter reportWriter = new StringWriter(); final PrintWriter out = new PrintWriter(reportWriter, true); reportSource(out, this.fileField.getText(), startDate, endDate, strategy); out.println(); reportValues(out, initialCash, account); if (account.getStockPositionCount() > 0) { out.println(); reportPositions(out, account); } out.println(); reportTrades(out, winLossObserver); out.println(); reportMonths(out, monthObserver); out.println(); reportBeta(out, betaObserver, betaCompareIndexSymbol); // display report this.reportArea.setText(reportWriter.toString()); this.reportArea.setCaretPosition(0); this.vSplit.resetToPreferredSizes(); }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * {@inheritDoc}/*from w w w.ja v a 2 s . co m*/ */ public void addNotify() { super.addNotify(); // Setup timer to update the value of _today. int secondsTillTomorrow = 86400; if (_todayTimer == null) { _todayTimer = new Timer(secondsTillTomorrow * 1000, new ActionListener() { public void actionPerformed(ActionEvent e) { updateToday(); } }); } // Modify the initial delay be the current time. secondsTillTomorrow = secondsTillTomorrow - (_cal.get(Calendar.HOUR_OF_DAY) * 3600) - (_cal.get(Calendar.MINUTE) * 60) - _cal.get(Calendar.SECOND); _todayTimer.setInitialDelay(secondsTillTomorrow * 1000); _todayTimer.start(); }
From source file:lejos.pc.charting.LogChartFrame.java
/** All the setup of components, etc. What's scary is Swing is a "lightweight" GUI framework... * @throws Exception//from www . j av a 2s .co m */ private void jbInit() throws Exception { this.setJMenuBar(menuBar); this.setSize(new Dimension(819, 613)); this.setMinimumSize(new Dimension(819, 613)); this.setTitle("NXT Charting Logger"); this.setEnabled(true); // enforce minimum window size this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JFrame theFrame = (JFrame) e.getSource(); Dimension d1 = theFrame.getMinimumSize(); Dimension d2 = theFrame.getSize(); boolean enforce = false; if (theFrame.getWidth() < d1.getWidth()) { d2.setSize(d1.getWidth(), d2.getHeight()); enforce = true; } if (theFrame.getHeight() < d1.getHeight()) { d2.setSize(d2.getWidth(), d1.getHeight()); enforce = true; } if (enforce) theFrame.setSize(d2); } }); this.getContentPane().setLayout(gridBagLayout1); MenuActionListener menuItemActionListener = new MenuActionListener(); MenuEventListener menuListener = new MenuEventListener(); menu = new JMenu("Edit"); menu.setMnemonic(KeyEvent.VK_E); menuBar.add(menu); menuItem = new JMenuItem("Copy Chart Image", KeyEvent.VK_I); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Copy Data Log", KeyEvent.VK_D); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menu = new JMenu("View"); menu.setMnemonic(KeyEvent.VK_V); menu.setActionCommand("VIEW_MENU"); menu.addMenuListener(menuListener); menuBar.add(menu); menuItem = new JMenuItem("Expand Chart", KeyEvent.VK_F); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Chart in New Window", KeyEvent.VK_N); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menu = new JMenu("Help"); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem("Chart controls", KeyEvent.VK_C); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Generate sample data", KeyEvent.VK_G); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("About", KeyEvent.VK_A); menuItem.addActionListener(menuItemActionListener); jTabbedPane1.setPreferredSize(new Dimension(621, 199)); jTabbedPane1.setMinimumSize(new Dimension(621, 199)); menu.add(menuItem); jButtonConnect.setText("Connect"); jButtonConnect.setBounds(new Rectangle(25, 65, 115, 25)); jButtonConnect.setToolTipText("Connect/disconnect toggle"); jButtonConnect.setMnemonic('C'); jButtonConnect.setSelected(true); jButtonConnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButtonConnect_actionPerformed(e); } }); UIPanel.setSize(new Dimension(820, 200)); UIPanel.setLayout(null); UIPanel.setPreferredSize(new Dimension(300, 200)); UIPanel.setMinimumSize(new Dimension(300, 200)); UIPanel.setBounds(new Rectangle(0, 350, 820, 200)); UIPanel.setMaximumSize(new Dimension(300, 32767)); connectionPanel.setBounds(new Rectangle(10, 10, 175, 100)); connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection")); connectionPanel.setLayout(null); connectionPanel.setFont(new Font("Tahoma", 0, 11)); jLabel1logfilename.setText("Log File:"); jLabel1logfilename.setBounds(new Rectangle(10, 125, 165, 20)); jLabel1logfilename.setHorizontalTextPosition(SwingConstants.RIGHT); jLabel1logfilename.setHorizontalAlignment(SwingConstants.LEFT); jLabel1logfilename.setToolTipText("Specify the name of your log file here"); jTextFieldNXTName.setBounds(new Rectangle(5, 40, 165, 20)); jTextFieldNXTName.setToolTipText( "The name or Address of the NXT. Leave empty and the first one found will be used."); jTextFieldNXTName.requestFocus(); jTextAreaStatus.setLineWrap(true); jTextAreaStatus.setFont(new Font("Tahoma", 0, 11)); jTextAreaStatus.setWrapStyleWord(true); jTextAreaStatus.setBackground(SystemColor.window); dataLogTextArea.setLineWrap(false); dataLogTextArea.setFont(new Font("Tahoma", 0, 11)); dataLogTextArea.setBackground(SystemColor.window); FQPathTextArea.setBounds(new Rectangle(5, 170, 185, 40)); FQPathTextArea.setLineWrap(true); FQPathTextArea.setText(getCanonicalName(new File(".", ""))); FQPathTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); FQPathTextArea.setRows(2); FQPathTextArea.setFont(new Font("Tahoma", 0, 9)); FQPathTextArea.setOpaque(false); FQPathTextArea.setEditable(false); selectFolderButton.setText("Folder..."); selectFolderButton.setBounds(new Rectangle(120, 125, 70, 20)); selectFolderButton.setMargin(new Insets(1, 1, 1, 1)); selectFolderButton.setFocusable(false); selectFolderButton.setMnemonic('F'); selectFolderButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectFolderButton_actionPerformed(e); } }); // domain display limits GUI chartOptionsPanel.setLayout(null); chartDomLimitsPanel.setBounds(new Rectangle(5, 35, 180, 135)); chartDomLimitsPanel.setLayout(gridLayout1); chartDomLimitsPanel.setBorder(BorderFactory.createTitledBorder("Domain Display Limiting")); domainDisplayLimitSlider.setEnabled(false); domainDisplayLimitSlider.setMaximum(MAXDOMAIN_DATAPOINT_LIMIT); domainDisplayLimitSlider.setMinimum(MINDOMAIN_LIMIT); domainDisplayLimitSlider.setValue(MAXDOMAIN_DATAPOINT_LIMIT); domainDisplayLimitSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { domainDisplayLimitSlider_stateChanged(e); } }); useTimeRadioButton.setText("By Time"); useTimeRadioButton.setEnabled(false); useTimeRadioButton.setMnemonic('I'); useTimeRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { domainDisplayLimitRadioButton_actionPerformed(e); } }); useDataPointsRadioButton.setText("By Data Points"); ButtonGroup bg1 = new ButtonGroup(); bg1.add(useTimeRadioButton); bg1.add(useDataPointsRadioButton); useDataPointsRadioButton.setSelected(true); useDataPointsRadioButton.setEnabled(false); useDataPointsRadioButton.setMnemonic('P'); useDataPointsRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { domainDisplayLimitRadioButton_actionPerformed(e); } }); datasetLimitEnableCheckBox.setText("Enable"); datasetLimitEnableCheckBox.setRolloverEnabled(true); datasetLimitEnableCheckBox.setMnemonic('A'); datasetLimitEnableCheckBox.setToolTipText("Enable Domain Clipping"); datasetLimitEnableCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { datasetLimitEnableCheckBox_actionPerformed(e); } }); domainLimitLabel.setText(String.format("%1$,d datapoints", MAXDOMAIN_DATAPOINT_LIMIT).toString()); domainLimitLabel.setEnabled(false); gridLayout1.setRows(5); gridLayout1.setColumns(1); jLabel1.setText("Chart Title:"); jLabel1.setBounds(new Rectangle(200, 10, 85, 20)); jLabel1.setPreferredSize(new Dimension(115, 14)); jLabel2.setText("Range Axis 1 Label:"); jLabel2.setBounds(new Rectangle(200, 35, 115, 20)); jLabel2.setSize(new Dimension(115, 20)); jLabel3.setText("Range Axis 2 Label:"); jLabel3.setBounds(new Rectangle(200, 60, 115, 20)); jLabel3.setSize(new Dimension(115, 20)); jLabel4.setText("Range Axis 3 Label:"); jLabel4.setBounds(new Rectangle(200, 85, 115, 20)); jLabel4.setSize(new Dimension(115, 20)); jLabel6.setText("Range Axis 4 Label:"); jLabel6.setBounds(new Rectangle(200, 110, 115, 20)); jLabel6.setSize(new Dimension(115, 20)); titleLabelChangeNotifier notifier = new titleLabelChangeNotifier(); chartTitleTextField.setBounds(new Rectangle(315, 10, 290, 20)); chartTitleTextField.getDocument().addDocumentListener(notifier); axis1LabelTextField.setBounds(new Rectangle(315, 35, 290, 20)); axis1LabelTextField.getDocument().addDocumentListener(notifier); axis2LabelTextField.setBounds(new Rectangle(315, 60, 290, 20)); axis2LabelTextField.getDocument().addDocumentListener(notifier); axis3LabelTextField.setBounds(new Rectangle(315, 85, 290, 20)); axis3LabelTextField.getDocument().addDocumentListener(notifier); axis4LabelTextField.setBounds(new Rectangle(315, 110, 290, 20)); showCommentsCheckBox.setText("Show Comment Markers"); showCommentsCheckBox.setBounds(new Rectangle(200, 140, 185, 25)); showCommentsCheckBox.setToolTipText("Show/Hide any comment markers on the chart"); showCommentsCheckBox.setRolloverEnabled(true); showCommentsCheckBox.setSelected(true); showCommentsCheckBox.setMnemonic('M'); showCommentsCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { customChartPanel.setCommentsVisible(e.getStateChange() == ItemEvent.SELECTED); } }); scrollDomainCheckBox.setText("Scroll Domain"); scrollDomainCheckBox.setBounds(new Rectangle(10, 5, 175, 20)); scrollDomainCheckBox.setSize(new Dimension(175, 25)); scrollDomainCheckBox.setSelected(true); scrollDomainCheckBox.setMnemonic('O'); scrollDomainCheckBox.setToolTipText("Checked to scroll domain as new data is received"); scrollDomainCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scrollDomainCheckBox_actionPerformed(e); } }); axis4LabelTextField.getDocument().addDocumentListener(notifier); logFileTextField.setBounds(new Rectangle(10, 145, 180, 20)); logFileTextField.setText("NXTData.txt"); logFileTextField.setPreferredSize(new Dimension(180, 20)); logFileTextField.setToolTipText("File name. Leave empty to not log to file."); statusScrollPane.setOpaque(false); dataLogScrollPane.setOpaque(false); customChartPanel.setMinimumSize(new Dimension(400, 300)); customChartPanel.setPreferredSize(new Dimension(812, 400)); jLabel5.setText("NXT Name/Address:"); jLabel5.setBounds(new Rectangle(5, 20, 160, 20)); jLabel5.setToolTipText(jTextFieldNXTName.getToolTipText()); jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT); jLabel5.setHorizontalAlignment(SwingConstants.LEFT); connectionPanel.add(jTextFieldNXTName, null); connectionPanel.add(jButtonConnect, null); connectionPanel.add(jLabel5, null); dataLogScrollPane.setViewportView(dataLogTextArea); jTabbedPane1.addTab("Data Log", dataLogScrollPane); statusScrollPane.setViewportView(jTextAreaStatus); jTabbedPane1.addTab("Status", statusScrollPane); jTabbedPane1.addTab("Chart", chartOptionsPanel); chartDomLimitsPanel.add(datasetLimitEnableCheckBox, null); chartDomLimitsPanel.add(useDataPointsRadioButton, null); chartDomLimitsPanel.add(useTimeRadioButton, null); chartDomLimitsPanel.add(domainDisplayLimitSlider, null); chartDomLimitsPanel.add(domainLimitLabel, null); chartOptionsPanel.add(scrollDomainCheckBox, null); chartOptionsPanel.add(showCommentsCheckBox, null); chartOptionsPanel.add(axis4LabelTextField, null); chartOptionsPanel.add(axis3LabelTextField, null); chartOptionsPanel.add(axis2LabelTextField, null); chartOptionsPanel.add(axis1LabelTextField, null); chartOptionsPanel.add(chartTitleTextField, null); chartOptionsPanel.add(jLabel6, null); chartOptionsPanel.add(jLabel4, null); chartOptionsPanel.add(jLabel3, null); chartOptionsPanel.add(jLabel2, null); chartOptionsPanel.add(jLabel1, null); chartOptionsPanel.add(chartDomLimitsPanel, null); tglbtnpauseplay = new JToggleButton(""); tglbtnpauseplay.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (lpm == null) return; boolean doPause = false; if (e.getStateChange() == ItemEvent.SELECTED) { doPause = true; } lpm.setReaderPaused(doPause); } }); // tglbtnpauseplay.addChangeListener(new ChangeListener() { // public void stateChanged(ChangeEvent e) { // System.out.println(e.toString()); // //lpm.setReaderPaused(doPause) // } // }); tglbtnpauseplay .setSelectedIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/play.png"))); tglbtnpauseplay.setIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/pause.png"))); tglbtnpauseplay.setBounds(571, 135, 30, 30); chartOptionsPanel.add(tglbtnpauseplay); jTabbedPane1.setToolTipTextAt(0, "The tab-delimited log of the data sent from the NXT"); jTabbedPane1.setToolTipTextAt(1, "Status output"); jTabbedPane1.setToolTipTextAt(2, "Chart options"); jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_D); jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_S); jTabbedPane1.setMnemonicAt(2, KeyEvent.VK_T); this.getContentPane().add(customChartPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); this.getContentPane().add(UIPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -107, 0)); this.getContentPane().add(jTabbedPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); UIPanel.add(connectionPanel, null); UIPanel.add(selectFolderButton, null); UIPanel.add(logFileTextField, null); UIPanel.add(jLabel1logfilename, null); UIPanel.add(FQPathTextArea, null); ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { String theData = null; for (;;) { theData = LogChartFrame.this.logDataQueue.poll(); if (theData == null) break; try { dataLogTextArea.getDocument().insertString(dataLogTextArea.getDocument().getLength(), theData, null); } catch (BadLocationException e) { System.out.print( "BadLocationException in datalog textarea updater thread:" + e.toString() + "\n"); } } } }; this.updateLogTextAreaTimer = new Timer(1000, taskPerformer); this.updateLogTextAreaTimer.start(); }
From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java
/** * Performs a login on a separate thread and then notifies the dialog if it was successful. *//* w w w. j a v a 2s .c om*/ public void doLogin() { DBConnection.resetEmbeddedDir(); isLoggingIn = true; save(); if (masterUsrPwdProvider != null && !masterUsrPwdProvider.hasMasterUserAndPwdInfo(getUserName(), getPassword(), getDatabaseName())) { if (!masterUsrPwdProvider.editMasterInfo(getUserName(), getDatabaseName(), true)) { isLoggingIn = false; return; } } final String clsName = getClass().getName(); statusBar.setIndeterminate(clsName, true); enableUI(false); setMessage(String.format(getResourceString("LoggingIn"), new Object[] { getDatabaseName() }), false); //$NON-NLS-1$ String basePrefName = getDatabaseName() + "." + getUserName() + "."; //$NON-NLS-1$ //$NON-NLS-2$ loginCount = AppPreferences.getLocalPrefs().getLong(basePrefName + "logincount", -1L); //$NON-NLS-1$ loginAccumTime = AppPreferences.getLocalPrefs().getLong(basePrefName + "loginaccumtime", -1L);//$NON-NLS-1$ if (loginCount != -1 && loginAccumTime != -1) { int timesPerSecond = 4; progressWorker = new ProgressWorker(statusBar.getProgressBar(), 0, (int) (((double) loginAccumTime / (double) loginCount) + 0.5), timesPerSecond); new Timer(1000 / timesPerSecond, progressWorker).start(); } else { loginCount = 0; } if (checkForProcesses && DBConnection.getInstance().isEmbedded() || UIRegistry.isMobile()) // isEmbdded may not be setup yet { ProcessListUtil.checkForMySQLProcesses(new ProcessListener() { @Override public void done(PROC_STATUS status) // called on the UI thread { checkForProcesses = false; if (status == PROC_STATUS.eOK || status == PROC_STATUS.eFoundAndKilled) { doLoginContinuing(clsName); // On UI Thread } } }); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doLoginContinuing(clsName); // Needs to be on the UI Thread } }); } }