1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| package ihm.help;
import ihm.FrameMain;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.rtf.RTFEditorKit;
public class FrameHelp extends JFrame {
private static final long serialVersionUID = 8271955189656078654L;
private FrameMain frame;
private JPanel panelMenu;
private JTextPane panelHelp;
private JList listHelp;
private JScrollPane scrollPaneHelp;
private RTFEditorKit rtfEditor = new RTFEditorKit();
private String[] menus = new String[]{"Step 1", "Step 2",
"Step 3", "Step 4", "Menu"};
public FrameHelp(FrameMain frame) {
this.frame = frame;
this.setTitle("Help");
this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
this.setSize(new Dimension(600, 400));
panelMenu = new JPanel();
panelMenu.setLayout(new BorderLayout());
listHelp = new JList(menus);
listHelp.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listHelp.setBorder(BorderFactory.createEmptyBorder());
listHelp.setBackground(getBackground());
listHelp.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
displayHelp();
}
});
JScrollPane scrollPaneMenu = new JScrollPane();
scrollPaneMenu.setViewportView(listHelp);
panelMenu.add(scrollPaneMenu);
scrollPaneHelp = new JScrollPane();
panelHelp = new JTextPane();
panelHelp.setEditable(false);
panelHelp.setBackground(getBackground());
panelHelp.setLayout(new BorderLayout());
scrollPaneHelp.setViewportView(panelHelp);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
panelMenu, scrollPaneHelp);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(100);
selectCurrentStep();
this.setContentPane(splitPane);
this.setVisible(true);
}
public void selectCurrentStep() {
if (frame.getTabPanelStep4() != null) {
listHelp.setSelectedIndex(3);
} else if (frame.getTabPanelStep3() != null) {
listHelp.setSelectedIndex(2);
} else if (frame.getTabPanelStep2() != null) {
listHelp.setSelectedIndex(1);
} else if (frame.getPanelStep1() != null) {
listHelp.setSelectedIndex(0);
} else {
listHelp.setSelectedIndex(4);
}
}
private void displayHelp() {
Document doc = panelHelp.getDocument();
try {
doc.remove(0, doc.getLength());
} catch (BadLocationException e) {
e.printStackTrace();
}
try {
switch (listHelp.getSelectedIndex()) {
case 0:
rtfEditor.read(new FileInputStream(new File("./help/step 1.rtf")), doc, 0);
break;
case 1:
rtfEditor.read(new FileInputStream(new File("./help/step 2.rtf")), doc, 0);
break;
case 2:
rtfEditor.read(new FileInputStream(new File("./help/step 3.rtf")), doc, 0);
break;
case 3:
rtfEditor.read(new FileInputStream(new File("./help/step 4.rtf")), doc, 0);
break;
case 4:
rtfEditor.read(new FileInputStream(new File("./help/menu.rtf")), doc, 0);
break;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
} |
Partager