1 package sk.stuba.fiit.foo07.genex.gui;
2
3 import java.awt.event.MouseAdapter;
4 import java.awt.event.MouseEvent;
5
6 import javax.swing.JComboBox;
7
8 public class ProgressbarMouseHandler extends MouseAdapter {
9
10 private int maxDifficultyPoints = 5;
11 private int difficultyRangePoint;
12 private ProgressCellRenderer difficultyBar;
13 private JComboBox difficultyCombo;
14
15 int xMousePosition;
16 int remainder;
17 int difficulty;
18 int offset;
19
20 ProgressbarMouseHandler(ProgressCellRenderer jbar, JComboBox jc) {
21 offset = 0;
22 difficultyBar = jbar;
23 difficultyCombo = jc;
24 int width = jbar.getSize().width;
25 difficultyRangePoint = width / maxDifficultyPoints;
26
27 }
28
29 ProgressbarMouseHandler(ProgressCellRenderer jbar, JComboBox jc, int off) {
30 offset = off;
31 difficultyBar = jbar;
32 difficultyCombo = jc;
33 int width = jbar.getSize().width;
34 difficultyRangePoint = width / maxDifficultyPoints;
35
36 }
37
38 @Override
39 public void mousePressed(MouseEvent e) {
40
41 xMousePosition = e.getX();
42 remainder = xMousePosition % difficultyRangePoint;
43 xMousePosition = xMousePosition - remainder;
44 difficulty = xMousePosition / difficultyRangePoint;
45
46 difficultyBar.setIntegerValue(difficulty);
47 difficultyCombo.setSelectedIndex(difficulty + offset);
48
49 }
50
51 @Override
52 public void mouseExited(MouseEvent e) {
53
54 return;
55 }
56 }