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 127 128 129 130 131 132 133
|
package IHM;
/**
* IHM of Converter application
*
* @author t0163126
*/
public class IhmConverter extends JFrame {
private static final long serialVersionUID = 1L;
private static ToolBar toolBar;
private JPanel panCustomer;
private JPanel panTab;
private JPanel panLog;
private JTextArea txtaLog;
private JSplitPane split;
private JScrollPane ascenseur;
private static JTabbedPane tabs;
private static TabHDMT HDMT;
private static TabNEMO NEMO;
private int maxW = 0;
private int maxH = 0;
private static Dimension panelDim;
private Dimension newDim;
// ============================================================
/**
* Ihm constructorr
*/
private IhmConverter() {
initIhmConverter();
}
/**
* Method initialization
*/
private void initIhmConverter() {
// window event
this.addWindowListener(new ActionWindow());
HDMT = new TabHDMT(); //1er sous onglet
NEMO = new TabNEMO(); //2ème sous onglet (même structure)
tabs = new JTabbedPane(SwingConstants.NORTH); //onglet principale
// Add tabs
tabs.add("HDMT", HDMT); //Je cherche à modifier les couleurs du titre soit ce qui est entre guillemet
tabs.add("NEMO", NEMO);
tabs.setOpaque(true);
tabs.setMnemonicAt(0, KeyEvent.VK_H); //ALT+H
tabs.setMnemonicAt(1, KeyEvent.VK_N); //ALT+N
// Dimension
final Dimension originalTabsDim = tabs.getPreferredSize();
panelDim = new Dimension();
tabs.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
Component p = ((JTabbedPane) e.getSource()).getSelectedComponent();
panelDim = p.getPreferredSize();
newDim = new Dimension(originalTabsDim.width
- (maxW - panelDim.width), originalTabsDim.height
- (maxH - panelDim.height));
tabs.getSelectedComponent().setPreferredSize(newDim);
//ceci change le texte qui est à l'intérieur de l'onglet pour ainsi dire le sous titre et non le titre de l'onglet
tabs.getComponentAt(tabs.getSelectedIndex()).setForeground(Color.white);
//même chose mais pour la couleur de fond
tabs.getComponentAt(tabs.getSelectedIndex()).setBackground(Color.GRAY);
pack();
}
});
panTab = new JPanel();
panTab.setLayout(new BorderLayout());
HDMT.setPreferredSize(panTab.getPreferredSize());
NEMO.setPreferredSize(panTab.getPreferredSize());
panTab.add(tabs, BorderLayout.CENTER);
txtaLog = new JTextArea();
txtaLog.setFont(new Font("Calibri", Font.PLAIN, 10));
txtaLog.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
txtaLog.setEnabled(false);
txtaLog.setDisabledTextColor(Color.black);
txtaLog.setBackground(Color.lightGray);
//Return to automatically line
txtaLog.setLineWrap(true);
ascenseur = new JScrollPane(txtaLog);
panLog = new JPanel();
panLog.setLayout(new BorderLayout());
panLog.setBackground(Color.lightGray);
panLog.add(ascenseur, BorderLayout.CENTER);
// Customer area
panCustomer = (JPanel) this.getContentPane();
panCustomer.setLayout(new BorderLayout());
//Separator between panTabs and tabLog
split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panTab, panLog);
split.setOneTouchExpandable(true);
//add to customer pane
panCustomer.add(split, BorderLayout.CENTER);
// Add toolBar
toolBar = new ToolBar();
this.add(toolBar, BorderLayout.NORTH);
}
// ============================================================
// instenciation
private static IhmConverter hdmt;
public static IhmConverter getInstance() {
if (hdmt == null) {
hdmt = new IhmConverter();
}
return hdmt;
}
// ============================================================
// Getter and setter
public static TabHDMT getHDMT() {
return IhmConverter.HDMT;
}
public static TabNEMO getNEMO() {
return IhmConverter.NEMO;
}
public static ToolBar getToolBar() {
return IhmConverter.toolBar;
}
} |
Partager