⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 一个应用timer的小程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               v.add (mgr.getTask(mRowsSelected[i]));         }         fileExport.show( v);      }      setButtonState();   }   /**    *  Description of the Method    *    *@param  event  Description of Parameter    */   public void valueChanged( ListSelectionEvent event ) {      // Jtable selections      if ( event.getValueIsAdjusting() )      {         return;      }      // avoid redundant mesg      if ( Global.traceLevel >= 3 )      {         Global.logWriter.log( event.toString() );      }      ListSelectionModel lsm = ( ListSelectionModel ) event.getSource();      // we have some rows selected      int mFirstIndex = lsm.getMinSelectionIndex();      int mLastIndex = lsm.getMaxSelectionIndex();      int totalRowsSelected = 0;      for ( int index = mFirstIndex; index <= mLastIndex; ++index )      {         if ( lsm.isSelectedIndex( index ) )         {            if ( Global.traceLevel >= 2 )            {               Global.logWriter.log( " List Selection, row = " + index );            }            totalRowsSelected++;         }      }      // now update the array      mRowsSelected = new int[totalRowsSelected];      int index = 0;      for ( int i = mFirstIndex; i <= mLastIndex; ++i )      {         if ( lsm.isSelectedIndex( i ) )         {            mRowsSelected[index] = i;            index++;         }      }      setButtonState();   }   /**    *  Description of the Method    */   public void tick() {      if ( Global.traceLevel >= 3 )      {         Global.logWriter.log( new Date().toString() + " : Main : tick () " );      }      if ( !notSaved )      {         try         {            mgr.writeToDisk();            if ( Global.traceLevel >= 3 )            {               Global.logWriter.log( "\t main: wrote to disk" );            }         }         catch ( Exception e )         {         }      }      saveConfigFile();   }   /**    *  Description of the Method    *    *@exception  Exception  Description of Exception    */   private void jbInit() throws Exception {      table = new JTable( mTableModel );      table.setAutoResizeMode( JTable.AUTO_RESIZE_ALL_COLUMNS );      JPanel mainPanel = new JPanel( new BorderLayout() );      JToolBar jToolBar1 = new JToolBar();      this.setDefaultCloseOperation( 3 );      this.getContentPane().add( jToolBar1, BorderLayout.NORTH );      this.getContentPane().add(mainPanel, BorderLayout.CENTER);      table.getSelectionModel().addListSelectionListener( this );      JScrollPane scrollPane = new JScrollPane( table );      //mTimeSlider = new TimeSlider( new Date(), new Date(), "Show Tasks active..." );      //mTimeSlider.setEnabled(false);      JSplitPane split = new JSplitPane( JSplitPane.VERTICAL_SPLIT );      //mainPanel.add( mTimeSlider, BorderLayout.NORTH );      mainPanel.add(scrollPane, BorderLayout.CENTER);      //mainPanel.setPreferredSize( new Dimension( configFile.readIntProperty("Window.width",500),                                  //configFile.readIntProperty("Window.height",400)));      //this.getContentPane().add(statusArea, BorderLayout.SOUTH);      //this.getContentPane().add(split, BorderLayout.CENTER);      this.getContentPane().add( mainPanel, BorderLayout.CENTER );      //split.setTopComponent(mainPanel);      //split.setBottomComponent(statusArea);      //split.setOneTouchExpandable(true);      // initialize buttons...      mButtonNewFile = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.NewFile", true ) ) ) );      mButtonNewFile.setToolTipText( "New File" );      mButtonSaveFile = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.SaveFile", true ) ) ) );      mButtonSaveFile.setToolTipText( "Save File" );      mButtonOpenFile = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.OpenFile", true ) ) ) );      mButtonOpenFile.setToolTipText( "Open File" );      mButtonNewTask = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.NewTask", true ) ) ) );      mButtonNewTask.setToolTipText( "New Task" );      mButtonDelTask = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.DeleteTask", true ) ) ) );      mButtonDelTask.setToolTipText( "Delete Task" );      mButtonEditTask = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.EditTask", true ) ) ) );      mButtonEditTask.setToolTipText( "Edit Task" );      mButtonStartTask = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.StartTask", true ) ) ) );      mButtonStartTask.setToolTipText( "Start Task" );      mButtonStopTask = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.StopTask", true ) ) ) );      mButtonStopTask.setToolTipText( "Stop Task" );      mButtonChart = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.Chart", true ) ) ) );      mButtonChart.setToolTipText( "Charts" );      mButtonAbout = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.About", true ) ) ) );      mButtonAbout.setToolTipText( "About" );      mButtonExit = new JButton( new ImageIcon( configFile.getFileLocation( configFile.getConfigProperty( "Icon.Exit", true ) ) ) );      mButtonExit.setToolTipText( "Exit" );      // add action listeners to buttons      mButtonNewFile.addActionListener( this );      mButtonSaveFile.addActionListener( this );      mButtonOpenFile.addActionListener( this );      mButtonNewTask.addActionListener( this );      mButtonEditTask.addActionListener( this );      mButtonDelTask.addActionListener( this );      mButtonStartTask.addActionListener( this );      mButtonStopTask.addActionListener( this );      mButtonChart.addActionListener( this );      mButtonAbout.addActionListener( this );      mButtonExit.addActionListener( this );      // initialize combo box      if (Global.DEBUG)      {         mTraceCombo = new JComboBox();         mTraceCombo.addItem( "None" );         mTraceCombo.addItem( "One" );         mTraceCombo.addItem( "Two" );         mTraceCombo.addItem( "Three" );         mTraceCombo.addActionListener( this );         tracePanel = new JPanel();         tracePanel.add( new JLabel( "Trace Level" ) );         tracePanel.add( mTraceCombo );         mTraceCombo.setToolTipText( "Set the trace Level" );      }      jToolBar1.add( mButtonNewFile );      jToolBar1.add( mButtonOpenFile );      jToolBar1.add( mButtonSaveFile );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( mButtonNewTask );      jToolBar1.add( mButtonEditTask );      jToolBar1.add( mButtonDelTask );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( mButtonStartTask );      jToolBar1.add( mButtonStopTask );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( mButtonChart );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( mButtonAbout );      if (tracePanel != null)        jToolBar1.add( tracePanel );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( new JToolBar.Separator() );      jToolBar1.add( mButtonExit );      // Disable all the buttons except NEWFILe      mButtonNewFile.setEnabled( true );      mButtonOpenFile.setEnabled( true );      mButtonSaveFile.setEnabled( false );      mButtonNewTask.setEnabled( false );      mButtonEditTask.setEnabled( false );      mButtonDelTask.setEnabled( false );      mButtonStartTask.setEnabled( false );      mButtonStopTask.setEnabled( false );      mButtonChart.setEnabled( false );      mButtonAbout.setEnabled( true );      mButtonExit.setEnabled( true );      addWindowListener(         new WindowAdapter()         {            /**             *  Description of the Method             *             *@param  e  Description of Parameter             */            public void windowClosing( WindowEvent e ) {               exit();            }         } );      String[] needed = {"Task Name", "Task Description"};      userInput = new GetUserInput( this, needed );      setSize( new Dimension( configFile.readIntProperty("Window.Main.width",500),                                  configFile.readIntProperty("Window.Main.height",400)));      setLocation (configFile.readIntProperty("Window.Main.x", 100),                configFile.readIntProperty("Window.Main.y", 100));      pack();      setVisible( true );   }   /**    *  Description of the Method    *    *@return    Description of the Returned Value    */   private boolean saveToFile() {      // if the file hasn't been saved before, prompt the user for      // a new file name      if ( notSaved && ( mCurrentFile == null ) )      {         int ret = fileChooser.showSaveDialog( this );         if ( ret == JFileChooser.APPROVE_OPTION )         {            mCurrentFile = fileChooser.getSelectedFile();            // if name doesn't end with .tmr extension            // set the extension            if ( !mCurrentFile.getName().endsWith( ".tmr" ) )            {               mCurrentFile = new File( fileChooser.getSelectedFile().getAbsolutePath() + ".tmr" );            }         }         else         {            return false;         }      }      // save only if buffers are dirty      //if (notSaved && (mCurrentFile != null))      if ( notSaved )      {         try         {            mgr.setFile( mCurrentFile );            mgr.writeToDisk();            notSaved = false;            mButtonSaveFile.setEnabled( false );            if ( Global.traceLevel >= 1 )            {               Global.logWriter.log( "Saved to : " + mCurrentFile );            }            return true;         }         catch ( Exception e )         {            Global.logWriter.log( e.toString() );         }      }      return false;   }   /**    *  Description of the Method    *    *@param  name     Description of Parameter    *@param  c        Description of Parameter    *@param  x        Description of Parameter    *@param  y        Description of Parameter    *@param  w        Description of Parameter    *@param  h        Description of Parameter    *@param  visible  Description of Parameter    *@return          Description of the Returned Value    */   private JInternalFrame createInternalFrame( String name, Component c,         int x, int y, int w, int h, boolean visible ) {      JInternalFrame f = new JInternalFrame( name, true, false, true, true );      f.addInternalFrameListener(         new InternalFrameAdapter()         {            /**             *  Description of the Method             *             *@param  e  Description of Parameter             */            public void internalFrameClosing( InternalFrameEvent e ) {               ( ( JInternalFrame ) ( e.getSource() ) ).setVisible( false );               System.out.println( "Clossing" );            }            /**             *  Description of the Method             *             *@param  e  Description of Parameter             */            public void internalFrameClosed( InternalFrameEvent e ) {               ( ( JInternalFrame ) ( e.getSource() ) ).setVisible( false );               System.out.println( "Clossed" );            }         } );      f.setBounds( x, y, w, h );      f.getContentPane().add( c );      f.setVisible( visible );      return f;   }   // never return from this function.   /**    *  Description of the Method    */   private void exit() {     saveConfigFile();      if ( notSaved && ( mCurrentFile == null ) )      {         int ans = JOptionPane.showConfirmDialog( this,               "Do you want to save the tasks to a file before exiting?" );         if ( ans == JOptionPane.YES_OPTION )         {            saveToFile();            if ( Global.traceLevel >= 3 )            {               Global.logWriter.log( "written tasks to file" );            }         }         else if ( ans == JOptionPane.CANCEL_OPTION )         {            return;         }      }      System.exit( 0 );   }   // FIXME, use this as a central point of refreshing   /**    *  Description of the Method    */   private void saveConfigFile ()   {      // this window      Rectangle r = getBounds();      configFile.setProperty  ("Window.Main.width",""+ r.width);      configFile.setProperty  ("Window.Main.height",""+ r.height );      configFile.setProperty  ("Window.Main.x",""+ r.x);      configFile.setProperty  ("Window.Main.y",""+ r.y);      // dialog window      configFile.setProperty  ("Window.Export.width",""+ fileExport.getWidth());      configFile.setProperty  ("Window.Export.height",""+ fileExport.getHeight());      // last file opened      if (mCurrentFile != null)         configFile.setProperty  ("LastFile" , mCurrentFile.getAbsolutePath());      configFile.savePropertiesToFile  ();   }   /**    *  The main program for the Main class    *    *@param  args  The command line arguments    */   public static void main( String[] args ) {      try      {         Main mainGUI = new Main();      }      catch ( Exception e )      {         e.printStackTrace();      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -