📄 jmaint.java
字号:
return m1+"/"+d1+"/"+Integer.toString(CurCal.get(CurCal.YEAR)); } // GAS SECTION public void TableGasModel() { DefaultTableModel model = new DefaultTableModel(); TableCellRenderer renderer = new HighlightTableCellRenderer(); start_g = GasInfo.indexVehStart(CurVeh); end_g = GasInfo.indexVehEnd(CurVeh); if (start_g<end_g) model.setRowCount(end_g - start_g + 1); else model.setRowCount(0); model.setColumnCount(5); String[] s = {"Odometer","Date","MPG","Gallons","Cost"}; model.setColumnIdentifiers(s); GasTable.setModel(model); GasTable.setDefaultRenderer(Object.class, renderer); GasTable.setPreferredSize(new java.awt.Dimension(500,(end_g-start_g)*16)); GasGraphPanel.removeAll(); if (start_g<end_g) { GasEdit.setEnabled(true); GasDelete.setEnabled(true); float gal = 0; int odo = 0; int place = -1; for (int i = 0; i < (end_g-start_g+1); i++) { int z = start_g + i; GasTable.setValueAt(GasInfo.odo.get(z), i, 0); GasTable.setValueAt(GasInfo.date.get(z), i, 1); if (i != (end_g-start_g)) { if (!GasInfo.getTank(i)) { if (place == -1) { odo = GasInfo.getOdometer(i-1); place = i-1; gal = GasInfo.getAmount(i-1); } float g = gal; gal = g + GasInfo.getAmount(i); GasTable.setValueAt("---",i,2); } else { GasTable.setValueAt(new RoundDecimalPlaces().RoundDecimalPlaces((GasInfo.getOdometer(z) - GasInfo.getOdometer(z+1))/GasInfo.getAmount(z)), i, 2); if (place > -1) { GasTable.setValueAt(new RoundDecimalPlaces().RoundDecimalPlaces((odo - GasInfo.getOdometer(z))/gal), place, 2); gal = 0; odo = 0; place = -1; } } GasTable.setValueAt(Float.toString(GasInfo.getAmount(z)), i, 3); GasTable.setValueAt(new RoundDecimalPlaces().RoundDecimalPlaces(GasInfo.getCost(z) * GasInfo.getAmount(z)), i, 4); } else { GasTable.setValueAt(null, i, 2); GasTable.setValueAt(null, i, 3); GasTable.setValueAt(null, i, 4); } } GasTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); GasTable.setShowHorizontalLines(true); GasTable.setShowVerticalLines(false); GasTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); GasTable.setCellSelectionEnabled(false); GasTable.setRowSelectionAllowed(true); GasTable.setColumnSelectionAllowed(false); GasTable.setRowSelectionInterval(0,0); if ((end_g-start_g)>9) GasGraphPanel.add(new GasGraph()); GasViewer(); } else { GasEdit.setEnabled(false); GasDelete.setEnabled(false); GasBottomText.setText(""); } } public void GasViewer() { int r = GasTable.getSelectedRow() + start_g; SimpleAttributeSet label = new SimpleAttributeSet(); StyleConstants.setFontSize(label, 14); StyleConstants.setForeground(label, Color.BLACK); SimpleAttributeSet text = new SimpleAttributeSet(); StyleConstants.setBold(text, true); StyleConstants.setFontSize(text, 16); StyleConstants.setForeground(text, Color.BLACK); SimpleAttributeSet special = new SimpleAttributeSet(); StyleConstants.setItalic(special, true); StyleConstants.setFontSize(special, 12); StyleConstants.setForeground(special, Color.BLACK); Document doc = new DefaultStyledDocument(); String nl = String.valueOf('\n'); String t = String.valueOf('\t'); try { if (GasInfo.tank.get(r).toString().equalsIgnoreCase("T")) doc.insertString(doc.getLength(),"Full Tank" + nl,special); else doc.insertString(doc.getLength(),"Partial Tank" + nl,special); if (GasInfo.est.get(r).toString().equalsIgnoreCase("T")) doc.insertString(doc.getLength(),"Estimated Entry" + nl,special); doc.insertString(doc.getLength(),"Odometer: ",label); doc.insertString(doc.getLength(),GasInfo.getOdometer(r) + nl,text); doc.insertString(doc.getLength(),"Date: ",label); doc.insertString(doc.getLength(),GasInfo.getDate(r) + nl,text); doc.insertString(doc.getLength(),"Miles Driven: ",label); doc.insertString(doc.getLength(),Integer.toString(GasInfo.getOdometer(r) - GasInfo.getOdometer(r+1)) + nl,text); doc.insertString(doc.getLength(),"Vendor: ",label); doc.insertString(doc.getLength(),VenInfo.convertIDtoName(GasInfo.getVendorID(r)) + nl,text); doc.insertString(doc.getLength(),"Octane: ",label); if (GasInfo.getOctane(r) == 0) doc.insertString(doc.getLength(),"" + nl,text); else doc.insertString(doc.getLength(),GasInfo.getOctane(r) + nl,text); doc.insertString(doc.getLength(),"Amount: ",label); doc.insertString(doc.getLength(),GasInfo.getAmount(r) + nl,text); doc.insertString(doc.getLength(),"Cost: ",label); doc.insertString(doc.getLength(),GasInfo.getCost(r) + nl,text); doc.insertString(doc.getLength(),"Total: ",label); doc.insertString(doc.getLength(),GasTable.getValueAt(GasTable.getSelectedRow(), 4).toString() + nl,text); doc.insertString(doc.getLength(),"Comments: ",label); doc.insertString(doc.getLength(),GasInfo.getComment(r) + nl,text); } catch (BadLocationException e) { System.out.println("Gas Text View"); return; } GasBottomText.setDocument(doc); } public void ActivateGasEditor(int i) { NewEdit = i; int r = GasTable.getSelectedRow() + start_g; int x = VenInfo.size(); Vector v = VenInfo.createNameVector(); this.setEnabled(false); GasForm = new GasEditor(); if (NewEdit==0) GasForm.newEntry(v,DateToString()); if (NewEdit==1) GasForm.editEntry(v, String.valueOf(GasInfo.getOdometer(r)), String.valueOf(GasInfo.getOctane(r)), String.valueOf(GasInfo.getAmount(r)), String.valueOf(GasInfo.getCost(r)), GasInfo.getComment(r), GasInfo.getTank(r), GasInfo.getEstimated(r), VenInfo.indexOf(GasInfo.getVendorID(r)), GasInfo.getDate(r)); GasForm.addWindowFocusListener(new WindowFocusListener() { public void windowGainedFocus(WindowEvent evt) { } public void windowLostFocus(WindowEvent evt) { if (!GasForm.isShowing()) { if (GasForm.AllInfo.length > 0) { if (GasForm.NewVen.length > 0) { VenInfo.insertRecord(-1, GasForm.NewVen[0],GasForm.NewVen[1],GasForm.NewVen[2],GasForm.NewVen[3],GasForm.NewVen[4],GasForm.NewVen[5],GasForm.NewVen[6],GasForm.NewVen[7],GasForm.NewVen[8],GasForm.NewVen[9],GasForm.NewVen[10],GasForm.NewVen[11]); SetupListChange(); } if (NewEdit == 1) GasInfo.deleteRecord(GasInfo.indexOf(GasInfo.getOdometer(GasTable.getSelectedRow() + start_g))); String[] d = GasForm.AllInfo[0].split("/"); CurCal.set(Integer.parseInt(d[2]),Integer.parseInt(d[0])-1,Integer.parseInt(d[1])); GasInfo.insertRecord(GasForm.AllInfo[0], CurVeh, Integer.parseInt(GasForm.AllInfo[1]), Float.parseFloat(GasForm.AllInfo[2]), Float.parseFloat(GasForm.AllInfo[3]), Integer.parseInt(GasForm.AllInfo[4]), VenInfo.getID(VenInfo.indexOf(GasForm.AllInfo[5])), GasForm.AllInfo[6], GasForm.AllInfo[7], GasForm.AllInfo[8]); TableGasModel(); GasForm.AllInfo = new String[0]; TableMonModel(); } else if (start_g<end_g) GasViewer(); NewEdit = -1; setEnabled(true); } } }); } public class GasGraph extends JPanel { public void paintComponent(Graphics g) { String high = GasTable.getValueAt(0,2).toString(); String low = GasTable.getValueAt(0,2).toString(); float tot = Float.parseFloat(low); float f; int n = 1; for (int i=1; i<GasTable.getRowCount()-1; i++) if (!GasTable.getValueAt(i,2).toString().equalsIgnoreCase("---")) { n++; f = tot; tot = f + Float.parseFloat(GasTable.getValueAt(i,2).toString()); if (Float.parseFloat(GasTable.getValueAt(i,2).toString()) > Float.parseFloat(high)) high = GasTable.getValueAt(i,2).toString(); if (Float.parseFloat(GasTable.getValueAt(i,2).toString()) < Float.parseFloat(low)) low = GasTable.getValueAt(i,2).toString(); } float avg = tot/n; String a = Float.toString(avg); String a1 = a.substring(0,a.indexOf(".")+3); super.paintComponent(g); g.setFont(new Font("Dialog", 1, 10)); FontMetrics fm = g.getFontMetrics(); float[] fc = new float[3]; Color.RGBtoHSB(0,180,0,fc); g.setColor(Color.getHSBColor(fc[0],fc[1],fc[2])); g.drawLine(50,20,230,20); g.drawString(high,45-fm.stringWidth(high),25); f = ((Float.parseFloat(high) - Float.parseFloat(a1))*(190/(Float.parseFloat(high) - Float.parseFloat(low))))+20; String f1 = Float.toString(f); int y = Integer.parseInt(f1.substring(0,f1.indexOf("."))); Color.RGBtoHSB(0,0,180,fc); g.setColor(Color.getHSBColor(fc[0],fc[1],fc[2])); g.drawLine(50,y,230,y); g.drawString(a1,45-fm.stringWidth(a1),y+5); Color.RGBtoHSB(180,0,0,fc); g.setColor(Color.getHSBColor(fc[0],fc[1],fc[2])); g.drawLine(50,210,230,210); g.drawString(low,45-fm.stringWidth(low),215); g.setColor(Color.BLACK); String t = "Last 10 Tanks"; g.drawString(t, 125-(fm.stringWidth(t)/2), 15); int x = 10; for (int i=0; i<x; i++) { String s = GasTable.getValueAt(i,2).toString(); String s1 = GasTable.getValueAt(i,1).toString().substring(0,5); if (s.equalsIgnoreCase("---")) x++; else { if (i==0) g.drawString(s1,50,225); if (i==9) g.drawString(s1,230-fm.stringWidth(s1),225); f = ((Float.parseFloat(high) - Float.parseFloat(s))*(190/(Float.parseFloat(high) - Float.parseFloat(low))))+20; f1 = Float.toString(f); y = Integer.parseInt(f1.substring(0,f1.indexOf("."))); g.fillOval(57+i*18, y-3, 6, 6); } } } } // MAINTENANCE SECTION public void TableMaintModel() { DefaultTableModel model = new DefaultTableModel(); TableCellRenderer renderer = new HighlightTableCellRenderer(); start_m = MaintInfo.indexVehStart(CurVeh); end_m = MaintInfo.indexVehEnd(CurVeh); if (start_m>-1) model.setRowCount(end_m - start_m + 1); else model.setRowCount(0); model.setColumnCount(4); String[] s = {"Odometer","Date","Services","Comments"}; model.setColumnIdentifiers(s); MaintenanceTable.setModel(model); MaintenanceTable.setDefaultRenderer(Object.class, renderer); MaintenanceTable.setPreferredSize(new java.awt.Dimension(670,0)); if (start_m>-1) { MaintenanceEdit.setEnabled(true); MaintenanceDelete.setEnabled(true); for (int i = 0; i < (end_m-start_m+1); i++) { int z = start_m + i; MaintenanceTable.setValueAt(Integer.toString(MaintInfo.getOdometer(z)), i, 0); MaintenanceTable.setValueAt(MaintInfo.getDate(z), i, 1); String s1 = ""; if (!MaintInfo.getRegularServices(z).equalsIgnoreCase("")) { s = MaintInfo.getRegularServices(z).split(";"); for (int j=0; j < s.length; j++) { String s2 = s1; if (s2.equalsIgnoreCase("")) s1 = s2.concat(ServListInfo.convertIDtoName(Integer.parseInt(s[j]))); else s1 = s2.concat(" | ").concat(ServListInfo.convertIDtoName(Integer.parseInt(s[j]))); } } if (!MaintInfo.getIrregularServices(z).equalsIgnoreCase("")) { s = MaintInfo.getIrregularServices(z).split(":=:"); for (int j=0; j < s.length; j++) { String s2 = s1; if (s2.equalsIgnoreCase("")) s1 = s2.concat(s[j]); else s1 = s2.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -