/*
* PanelSheduleWeek.java
*
* Created on 27 Декабрь 2007 г., 3:25
*/
package clips.shedule.week;
import TimeTable.Day;
import TimeTable.DayOfWeek;
import TimeTable.JTimeTable;
import TimeTable.relocators.SimpleRectangleEngine;
import TimeTable.scaler.TimeScalerTraditional;
import beans.shedule.week.TimeOffset;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
import clips.delegate.shedule.week.SheduleWeekLocal;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.report.TableReportOptions;
import cli_fmw.utils.table_config_states.StateSaver;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
*
* @author Axe Ilshat
*/
public class PanelSheduleWeek extends PageGeneric
implements Persistentable, Printable {
SheduleWeekLocal swl;
JTimeTable tt[] = new JTimeTable[7];
/**
* Creates new form PanelSheduleWeek
*/
public PanelSheduleWeek(PageContainer container) throws ClipsException {
super(container);
initComponents();
swl = SheduleWeekLocal.getInstance();
swl.addContentStateListener(container);
GridLayout ga = new GridLayout(1, 7);
mainPanel.setLayout(ga);
TimeScalerTraditional scaler = new TimeScalerTraditional(7, 21, 0.3f);
ruler.setScaler(scaler);
SimpleRectangleEngine sre = new SimpleRectangleEngine();
SheduleWeekTimeTableModel model = new SheduleWeekTimeTableModel(swl);
boolean ableModify = swl.canModify();
for (int i = 0; i < tt.length; i++) {
JPanel panel = new JPanel();
mainPanel.add(panel);
BorderLayout bl = new BorderLayout();
panel.setLayout(bl);
bl.setVgap(10);
JLabel label = new JLabel(TimeLocal.WEEK[i]);
label.setHorizontalAlignment(JLabel.CENTER);
panel.add(label, BorderLayout.NORTH);
tt[i] = new JTimeTable(new Day(2007, 0, i+1), model, sre, scaler);
panel.add(tt[i]);
if(!ableModify) {
tt[i].setReadOnly(true);
}
}
StateSaver.attachTo(this);
}
/**
* returns title for the page
* @return String, HUD title for page
*/
@Override
public String getPageTitle() {
return "Еженедельное расписание";
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
mainPanel = new javax.swing.JPanel();
rulePanel = new javax.swing.JPanel();
ruler = new TimeTable.JTableRuler();
ruleLabel = new javax.swing.JLabel();
setLayout(new java.awt.BorderLayout());
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 502, Short.MAX_VALUE)
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE)
);
add(mainPanel, java.awt.BorderLayout.CENTER);
rulePanel.setLayout(new java.awt.BorderLayout(0, 10));
javax.swing.GroupLayout rulerLayout = new javax.swing.GroupLayout(ruler);
ruler.setLayout(rulerLayout);
rulerLayout.setHorizontalGroup(
rulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 40, Short.MAX_VALUE)
);
rulerLayout.setVerticalGroup(
rulerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 570, Short.MAX_VALUE)
);
rulePanel.add(ruler, java.awt.BorderLayout.CENTER);
ruleLabel.setText(" ");
rulePanel.add(ruleLabel, java.awt.BorderLayout.PAGE_START);
add(rulePanel, java.awt.BorderLayout.WEST);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel mainPanel;
private javax.swing.JLabel ruleLabel;
private javax.swing.JPanel rulePanel;
private TimeTable.JTableRuler ruler;
// End of variables declaration//GEN-END:variables
@Override
public boolean isDirty() {
return swl.isDirty();
}
@Override
public void save() throws ClipsException {
swl.save1();
}
@Override
public void restore() {
swl.restore();
SheduleWeekTimeTableModel model = new SheduleWeekTimeTableModel(swl);
for (int i = 0; i < tt.length; i++) {
tt[i].setModel(model);
}
}
@Override
public DelegateLine2 getDelegate() {
return null;
}
@Override
public boolean readyForPrint() {
return !isDirty();
}
@Override
public void print() {
if (readyForPrint()) {
TableModel model = new PrintTableModel();
String title = "Недельное расписание клиники: ";
TableReportOptions ops = new TableReportOptions(TableReportOptions.PageOrentation.horizontal);
PrintCreators.createGeneratedReport(title, ops, null, null, model, getClass());
}
}
class PrintTableModel extends AbstractTableModel {
@Override
public int getRowCount() {
return 1;
}
@Override
public int getColumnCount() {
return 7;
}
@Override
public String getColumnName(int column) {
DayOfWeek dayOfWeek = DayOfWeek.createEurope(column);
return dayOfWeek.getTitle();
}
@Override
public Object getValueAt(int rowIndex, int col) {
DayOfWeek dayOfWeek = DayOfWeek.createEurope(col);
if (swl.isWeekend(dayOfWeek)) {
return "Выходной день";
} else {
TimeOffset begin = swl.getTimeBegin(dayOfWeek);
TimeOffset end = swl.getTimeEnd(dayOfWeek);
String timeTxt = String.format("%02d:%02d-%02d:%02d ",
begin.getHours(), begin.getMinutes(), end.getHours(), end.getMinutes());
return timeTxt;
}
}
}
}