public TipsDialog(JFrame parent, boolean tips) {
super(parent, GanttProject.correctLabel(GanttLanguage.getInstance()
.getText("tipsOfTheDay")), false);
appli = (GanttProject) parent;
GanttLanguage lang = GanttLanguage.getInstance();
Vector vTips = new Vector();
String prefix = "tips";
int ind = 1;
boolean moreTips = !lang.getText(prefix + ind).startsWith(
GanttLanguage.MISSING_RESOURCE);
while (moreTips) {
vTips.add(lang.getText(prefix + ind++));
moreTips = !lang.getText(prefix + ind).startsWith(
GanttLanguage.MISSING_RESOURCE);
}
tipsText = new String[vTips.size()];
vTips.toArray(tipsText);
// tipsText = new String []{
// lang.getText("tips1"), lang.getText("tips2"), lang.getText("tips3"),
// lang.getText("tips4"),
// lang.getText("tips5"), lang.getText("tips6"), lang.getText("tips7"),
// lang.getText("tips8"),
// lang.getText("tips9"), lang.getText("tips10"),
// lang.getText("tips11"),lang.getText("tips12") ,
// lang.getText("tips13"),lang.getText("tips14"),
// lang.getText("tips15"), lang.getText("tips16")
// };
index = (int) (Math.random() * tipsText.length);
pnPanel0 = new JPanel();
GridBagLayout gbPanel0 = new GridBagLayout();
GridBagConstraints gbcPanel0 = new GridBagConstraints();
pnPanel0.setLayout(gbPanel0);
// Light image
lbImg = new JLabel(new ImageIcon(getClass().getResource(
"/icons/info.png")));
gbcPanel0.gridx = 0;
gbcPanel0.gridy = 0;
gbcPanel0.gridwidth = 1;
gbcPanel0.gridheight = 18;
gbcPanel0.fill = GridBagConstraints.VERTICAL;
gbcPanel0.weightx = 0;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints(lbImg, gbcPanel0);
pnPanel0.add(lbImg);
// The panel
taArea0 = new JTextPane();
taArea0.setPreferredSize(new Dimension(200, 150));
taArea0.setEditable(false);
// Set a random text !!
changeText(tipsText[index]);
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 0;
gbcPanel0.gridwidth = 19;
gbcPanel0.gridheight = 18;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
JScrollPane scrollPane = new JScrollPane(taArea0);
gbPanel0.setConstraints(scrollPane, gbcPanel0);
pnPanel0.add(scrollPane);
// Close button,
btBut0 = new JButton(lang.getText("close"));
gbcPanel0.gridx = 15;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.HORIZONTAL;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints(btBut0, gbcPanel0);
pnPanel0.add(btBut0);
// Next button
btBut1 = new JButton(lang.getText("next"));
gbcPanel0.gridx = 10;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.HORIZONTAL;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints(btBut1, gbcPanel0);
pnPanel0.add(btBut1);
// Back button
btBut2 = new JButton(lang.getText("back"));
gbcPanel0.gridx = 5;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.HORIZONTAL;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints(btBut2, gbcPanel0);
pnPanel0.add(btBut2);
// Checkbox for open in the futur on startup ??
cbBox0 = new JCheckBox(lang.getText("showTipsOnStartup"), tips);
gbcPanel0.gridx = 0;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.HORIZONTAL;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints(cbBox0, gbcPanel0);
pnPanel0.add(cbBox0);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel mainPanel = new JPanel(new FlowLayout());
mainPanel.add(pnPanel0);
setContentPane(mainPanel);
// Listener for close event
btBut0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
appli.getOptions().setOpenTips(cbBox0.isSelected());
}
});
btBut1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
index = (index + 1) % tipsText.length;
changeText(tipsText[index]);
}
});
btBut2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
index--;
if (index == -1)
index = tipsText.length - 1;
changeText(tipsText[index]);
}
});
this.pack();
setResizable(false);
DialogAligner.center(this, getParent());
applyComponentOrientation(lang.getComponentOrientation());
}