Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ngat.opsgui.xcomp; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.TableModel; import ngat.astrometry.AstroLib; import ngat.astrometry.BasicSite; import ngat.astrometry.BasicTargetTrackCalculatorFactory; import ngat.astrometry.JAstroSlalib; import ngat.astrometry.TargetTrackCalculatorFactory; import ngat.astrometry.components.RotatorMountTimePanel2; import ngat.ems.SkyModelExtinctionUpdate; import ngat.ems.SkyModelSeeingUpdate; import ngat.opsgui.chart.TimeAxisChart; import ngat.opsgui.perspectives.meteorology.SeeingHistoryTableModel; import ngat.opsgui.perspectives.meteorology.SeeingHistoryTableRenderer; import ngat.opsgui.util.TimeAxisPanel; import ngat.rcsgui.test.SkyModelSeeingHistogram; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; /** * * @author eng */ public class SeeingPanel2 extends javax.swing.JPanel { private SeeingHistoryTableModel shtm; private SeeingHistoryTableRenderer shtr; private JDialog dlg; private TimeAxisChart tac; private SkyModelSeeingHistogram rawSeeingHistogram; private SkyModelSeeingHistogram correctedSeeingHistogram; /** * Creates new form SeeingPanel2 */ public SeeingPanel2() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); correctedSeeingField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); rawSeeingField = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); photomField = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); categoryField = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); elevationField = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); sourceNameField = new javax.swing.JTextField(); jPanel2 = new javax.swing.JPanel(); jPanel6 = makeRawSeeingHistogram(); jPanel7 = makeCorrectedSeeingHistogram(); jPanel4 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = createSeeingHistoryTable(); jPanel5 = new javax.swing.JPanel(); jPanel8 = makeChartPanel(); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Latest")); jLabel1.setText("Seeing"); jLabel2.setText("Raw"); jLabel3.setText("Photom"); jLabel4.setText("Category"); jLabel5.setText("Elevation"); jLabel6.setText("as"); jLabel7.setText("as"); jLabel8.setText("deg"); jLabel9.setText("Source"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( jPanel1Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel2) .addComponent(jLabel1).addComponent(jLabel3)) .addComponent(jLabel9)).addGap(18, 18, 18) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(rawSeeingField, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(correctedSeeingField)) .addGap(6, 6, 6) .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6).addComponent(jLabel7))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(photomField, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(53, 53, 53) .addComponent(jLabel8).addContainerGap(31, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(sourceNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(elevationField, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(categoryField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1) .addComponent(correctedSeeingField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(rawSeeingField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2).addComponent(jLabel7)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(photomField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sourceNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(jLabel8).addComponent(elevationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(categoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE))); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Statistics")); jPanel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE)); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 127, Short.MAX_VALUE)); jPanel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE)); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 124, Short.MAX_VALUE)); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); jPanel4.setBorder(javax.swing.BorderFactory .createTitledBorder(javax.swing.BorderFactory.createTitledBorder("History"))); jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jTable1.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N jScrollPane1.setViewportView(jTable1); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addContainerGap())); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Plot")); javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8); jPanel8.setLayout(jPanel8Layout); jPanel8Layout.setHorizontalGroup(jPanel8Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 369, Short.MAX_VALUE)); jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE)); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout .setHorizontalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField categoryField; private javax.swing.JTextField correctedSeeingField; private javax.swing.JTextField elevationField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; private javax.swing.JTextField photomField; private javax.swing.JTextField rawSeeingField; private javax.swing.JTextField sourceNameField; // End of variables declaration//GEN-END:variables public void createSeeingDisplay() { // shtm.setRows(); dlg = new JDialog(); dlg.getContentPane().add(this); dlg.pack(); dlg.setVisible(true); } /** * Update components with latest seeing update. */ public void seeingUpdate(SkyModelSeeingUpdate sm) { // Table shtm.addRow(sm); // Summary panel fields correctedSeeingField.setText(String.format("%4.2f", sm.getCorrectedSeeing())); rawSeeingField.setText(String.format("%4.2f", sm.getRawSeeing())); sourceNameField.setText(sm.getSource()); // Category field updateSeeingCategory(sm.getCorrectedSeeing()); // Elevation field elevationField.setText(String.format("%4.2f", Math.toDegrees(sm.getElevation()))); // Histograms rawSeeingHistogram.updateSeeing(sm.getRawSeeing()); correctedSeeingHistogram.updateSeeing(sm.getCorrectedSeeing()); // Time series plots if (sm.isStandard()) { tac.addData("RAW_STD", sm.getStatusTimeStamp(), sm.getRawSeeing()); tac.addData("CORR_STD", sm.getStatusTimeStamp(), sm.getCorrectedSeeing()); } else { tac.addData("RAW_SCI", sm.getStatusTimeStamp(), sm.getRawSeeing()); tac.addData("CORR_SCI", sm.getStatusTimeStamp(), sm.getCorrectedSeeing()); } // Prediction plot tac.addData("PRED", sm.getStatusTimeStamp(), sm.getPredictedSeeing()); } public void photomUpdate(SkyModelExtinctionUpdate se) { String photomStr = "UNKNOWN"; Color color = Color.gray; if (se.getExtinction() <= 0.5) { photomStr = "PHOTOM"; color = Color.green; } else { photomStr = "SPECTRO"; color = Color.red; } photomField.setText(photomStr); photomField.setBackground(color); } private JTable createSeeingHistoryTable() { shtm = new SeeingHistoryTableModel(); shtr = new SeeingHistoryTableRenderer(); JTable table = new JTable(shtm); int nc = table.getColumnModel().getColumnCount(); for (int ic = 0; ic < nc; ic++) { table.getColumnModel().getColumn(ic).setCellRenderer(shtr); } return table; } private JPanel makeChartPanel() { tac = new TimeAxisChart("Seeing"); tac.setTimeLabel("Time [UTC]"); tac.setYLabel("Seeing [asec]"); tac.setShowGridLines(true); tac.setTimeAxisRange(6 * 3600 * 1000L); tac.setYAxisStart(0.0); tac.setYAxisEnd(3.0); tac.setChartBackgroundColor(jPanel5.getBackground()); tac.addRangeBackground(0.0, 0.8, new Color(192, 248, 193)); tac.addRangeBackground(0.8, 1.3, new Color(248, 233, 192)); tac.addRangeBackground(1.3, 2.0, new Color(248, 198, 192)); tac.addRangeBackground(2.0, 3.0, new Color(192, 236, 248)); try { tac.createPlot("RAW_STD", "Standards Raw", TimeAxisChart.SHAPE_TRIANGLE, 0, Color.magenta, false, true); } catch (Exception e) { e.printStackTrace(); } try { tac.createPlot("CORR_STD", "Standards Corrected", TimeAxisChart.SHAPE_RECTANGLE, 0, Color.orange, false, true); } catch (Exception e) { e.printStackTrace(); } try { tac.createPlot("RAW_SCI", "Science Raw", TimeAxisChart.SHAPE_TRIANGLE, 0, Color.blue, false, true); } catch (Exception e) { e.printStackTrace(); } try { tac.createPlot("CORR_SCI", "Science Corrected", TimeAxisChart.SHAPE_RECTANGLE, 0, Color.green, false, true); } catch (Exception e) { e.printStackTrace(); } try { tac.createPlot("PRED", "Prediction", TimeAxisChart.SHAPE_NONE, 0, Color.red, true, true); } catch (Exception e) { e.printStackTrace(); } JPanel cp = tac.createChartPanel(); cp.setLayout(new BorderLayout()); cp.setPreferredSize(new Dimension(550, 320)); return cp; } private JPanel makeRawSeeingHistogram() { rawSeeingHistogram = new SkyModelSeeingHistogram("Raw Seeing"); return rawSeeingHistogram.getChartPanel(); } private JPanel makeCorrectedSeeingHistogram() { correctedSeeingHistogram = new SkyModelSeeingHistogram("Corrected Seeing"); return correctedSeeingHistogram.getChartPanel(); } private void updateSeeingCategory(double seeing) { if (seeing < 0.8) { categoryField.setText("GOOD"); categoryField.setBackground(Color.green); } else if (seeing < 1.3) { categoryField.setText("AVERAGE"); categoryField.setBackground(Color.orange); } else if (seeing < 2.0) { categoryField.setText("POOR"); categoryField.setBackground(Color.red); } else { categoryField.setText("USABLE"); categoryField.setBackground(Color.cyan.darker()); } } }