PageRenderTime 63ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/org.mwc.cmap.TimeController/src/com/visutools/nav/bislider/BiSliderPresentation.java

https://bitbucket.org/haris_peco/debrief
Java | 1437 lines | 996 code | 210 blank | 231 comment | 271 complexity | 5aa582ce331ca49358a3da68e2e205ac MD5 | raw file
  1. package com.visutools.nav.bislider;
  2. import java.awt.AWTException;
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Graphics2D;
  10. import java.awt.Point;
  11. import java.awt.Polygon;
  12. import java.awt.Rectangle;
  13. import java.awt.RenderingHints;
  14. import java.awt.Robot;
  15. import java.awt.Shape;
  16. import java.awt.SystemColor;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.ComponentEvent;
  20. import java.awt.event.ComponentListener;
  21. import java.awt.event.InputEvent;
  22. import java.awt.event.KeyAdapter;
  23. import java.awt.event.KeyEvent;
  24. import java.awt.event.MouseAdapter;
  25. import java.awt.event.MouseEvent;
  26. import java.awt.event.MouseListener;
  27. import java.awt.event.MouseMotionListener;
  28. import java.awt.geom.Rectangle2D;
  29. import java.awt.geom.RoundRectangle2D;
  30. import java.io.Serializable;
  31. import java.text.ParseException;
  32. import java.util.Hashtable;
  33. import java.util.Vector;
  34. import javax.swing.BorderFactory;
  35. import javax.swing.JComponent;
  36. import javax.swing.JLabel;
  37. import javax.swing.JPanel;
  38. import javax.swing.JSlider;
  39. import javax.swing.JTextField;
  40. import javax.swing.Popup;
  41. import javax.swing.PopupFactory;
  42. import javax.swing.SwingConstants;
  43. import javax.swing.SwingUtilities;
  44. import javax.swing.UIManager;
  45. import javax.swing.event.ChangeEvent;
  46. import javax.swing.event.ChangeListener;
  47. import javax.swing.event.DocumentEvent;
  48. import javax.swing.event.DocumentListener;
  49. import javax.swing.plaf.ColorUIResource;
  50. import javax.swing.plaf.metal.MetalLookAndFeel;
  51. import MWC.Utilities.ReaderWriter.XML.MWCXMLReader;
  52. /**
  53. * The graphical interface of the bean (drawing and mouse event handling). <br>
  54. * <br>
  55. * <table border=1 width="90%">
  56. * <tr>
  57. * <td> Copyright 1997-2005 Frederic Vernier. All Rights Reserved.<br>
  58. * <br>
  59. * Permission to use, copy, modify and distribute this software and its
  60. * documentation for educational, research and non-profit purposes, without fee,
  61. * and without a written agreement is hereby granted, provided that the above
  62. * copyright notice and the following three paragraphs appear in all copies.<br>
  63. * <br>
  64. * To request Permission to incorporate this software into commercial products
  65. * contact Frederic Vernier, 19 butte aux cailles street, Paris, 75013, France.
  66. * Tel: (+33) 871 747 387. eMail: Frederic.Vernier@laposte.net / Web site:
  67. * http://vernier.frederic.free.fr <br>
  68. * IN NO EVENT SHALL FREDERIC VERNIER BE LIABLE TO ANY PARTY FOR DIRECT,
  69. * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
  70. * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  71. * IF FREDERIC VERNIER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.<br>
  72. * <br>
  73. * FREDERIC VERNIER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
  74. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  75. * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HERE UNDER IS ON AN "AS IS" BASIS,
  76. * AND FREDERIC VERNIER HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
  77. * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.<br>
  78. * </td>
  79. * </tr>
  80. * </table> <br>
  81. * <b>Project related :</b> FiCell, FieldExplorer<br>
  82. * <br>
  83. * <b>Dates:</b> <br>
  84. * <li> Format : 01/11/2001
  85. * <li> Last Modif : 11/02/2003 <br>
  86. * <b>Bugs:</b> <br>
  87. * <li> ??? <br>
  88. * <b>To Do:</b> <br>
  89. * <li> alt or shift pressed -> repaint
  90. *
  91. * @author Frederic Vernier, Frederic.Vernier@laposte.net
  92. * @version 1.4.1
  93. * @created 16 f�vrier 2004
  94. */
  95. public class BiSliderPresentation implements Serializable, MouseListener,
  96. MouseMotionListener, ComponentListener
  97. {
  98. // ------------ MODIFIERS|--------------------
  99. // Type|----------------------------------------------- Name = Init value
  100. protected final static javax.swing.text.html.parser.ParserDelegator MAXIMUM_VARIABLE_SIZE_FOR_NAME = null;
  101. final static long serialVersionUID = 6420110040552724883L;
  102. protected SwingBiSlider Ctrl = null;
  103. protected JComponent JComponent1 = null;
  104. protected int[][] ColorTable = null;
  105. protected long j = 0;
  106. protected int NbAff = 0;
  107. // for feedback
  108. protected final int NOTHING = 200;
  109. protected final int RIGHT_POLYGON = 201;
  110. protected final int LEFT_POLYGON = 202;
  111. protected final int SELECTION = 203;
  112. protected final int FIRST_LABEL = 204;
  113. protected final int LAST_LABEL = 205;
  114. protected int MouseUnder = NOTHING;
  115. // Triangle polygons for the rulers
  116. protected Polygon TheLeft_Polygon = null;
  117. protected Polygon TheRight_Polygon = null;
  118. protected Rectangle2D RectFirstLabel = null;
  119. protected Rectangle2D RectLastLabel = null;
  120. protected Rectangle2D RectangleSegment = null;
  121. // indicate if the tool has already been painted on screen or never.
  122. protected boolean NeverDrawn = true;
  123. // graduation variables
  124. protected double GraduationWidth = 1;
  125. // we need to remember the precise value opened when the precise popup shows
  126. // up because we will move around it
  127. protected double PreciseOpenedValue = 0;
  128. // Constants for the Dragging variable
  129. protected final static int NONE = 100;
  130. protected final static int LEFT_RULER = 101;
  131. protected final static int RIGHT_RULER = 102;
  132. protected final static int SHIFT_LEFT_RULER = 103;
  133. protected final static int SHIFT_RIGHT_RULER = 104;
  134. protected final static int SEGMENT = 105;
  135. protected final static int SHIFT_SEGMENT = 106;
  136. protected final static int ALT_LEFT_RULER = 107;
  137. protected final static int ALT_RIGHT_RULER = 108;
  138. protected final static int SEGMENT_SIZE = 109;
  139. protected final static int SEGMENT_SIZE_INT = 110;
  140. protected final static int PRECISE_LEFT_RULER = 111;
  141. protected final static int PRECISE_RIGHT_RULER = 112;
  142. protected int Dragging = NONE;
  143. protected int LeftValue = 0;
  144. protected int RightValue = 0;
  145. protected int DeplBef = 0;
  146. protected int DeplAft = 0;
  147. protected double Center = 0;
  148. // The width and height can change when the tool is resized
  149. protected int RulerWidth = 0;
  150. protected final static int MINIMUM_RULER_HEIGHT = 20;
  151. protected final static int PREFERRED_RULER_HEIGHT = 20;
  152. protected int RulerHeight = PREFERRED_RULER_HEIGHT;
  153. // but not the margins.
  154. protected final static int MARGIN_RULER_LEFT = 20;
  155. protected int Margin_Ruler_Top = 13;
  156. protected final static int MARGIN_RULER_RIGHT = 20;
  157. protected final static int MARGIN_RULER_BOTTOM = 3;
  158. // protected Dimension PreferredSize = new Dimension(5, 5);
  159. // protected Dimension MinimumSize = new Dimension(5, 5);
  160. protected JTextField JTextFieldMin = new JTextField("");
  161. protected JTextField JTextFieldMax = new JTextField("");
  162. protected Vector<Point> LastFiveEvents = null;
  163. protected JPanel JPanel1 = new JPanel();
  164. protected JSlider JSlider1 = new JSlider(JSlider.VERTICAL, -100, 100, 0);
  165. protected JLabel JLabel1 = new JLabel("0");
  166. protected ContentPainterSupport ContentPainterSupport1 = null;
  167. protected FormatLong _myFormatter;
  168. /**
  169. * Contructor, create the polygons and other nested object then register mouse
  170. * callbacks.
  171. *
  172. * @param Ctrl_Arg
  173. * Description of the Parameter
  174. */
  175. public BiSliderPresentation(SwingBiSlider Ctrl_Arg, ContentPainterSupport ContentPainterSupport_Arg,
  176. FormatLong formatter)
  177. {
  178. this.Ctrl = Ctrl_Arg;
  179. this.ContentPainterSupport1 = ContentPainterSupport_Arg;
  180. if(formatter != null)
  181. {
  182. _myFormatter = formatter;
  183. }
  184. else
  185. {
  186. _myFormatter = new FormatLong();
  187. }
  188. Ctrl.setBackground(null);
  189. JPanel1.setLayout(new BorderLayout());
  190. JPanel1.setBorder(BorderFactory.createLineBorder(Ctrl.getForeground()));
  191. JSlider1.setPaintLabels(true);
  192. JSlider1.setMajorTickSpacing(20);
  193. JSlider1.setMinorTickSpacing(1);
  194. JPanel1.add(JSlider1, BorderLayout.CENTER);
  195. JPanel1.add(JLabel1, BorderLayout.SOUTH);
  196. JLabel1.setHorizontalAlignment(SwingConstants.CENTER);
  197. JLabel1.setOpaque(true);
  198. JSlider1.setOpaque(true);
  199. JPanel1.revalidate();
  200. /*
  201. * JSlider1.addMouseListener(new MouseAdapter(){ public void
  202. * mousePressed(MouseEvent MouseEvent_Arg){
  203. * System.out.println(""+MouseEvent_Arg); } });
  204. */
  205. JSlider1.addChangeListener(new ChangeListener()
  206. {
  207. public void stateChanged(ChangeEvent ChangeEvent_Arg)
  208. {
  209. double MiddleVal = PreciseOpenedValue;
  210. double Amplitude = Ctrl.getSegmentSize() / Ctrl.getSegmentCount();
  211. if (Dragging == PRECISE_RIGHT_RULER
  212. && MiddleVal - Amplitude < Ctrl.getMinimumColoredValue())
  213. {
  214. MiddleVal = Ctrl.getMinimumColoredValue() + Amplitude;
  215. }
  216. else if (Dragging == PRECISE_LEFT_RULER
  217. && MiddleVal + Amplitude > Ctrl.getMaximumColoredValue())
  218. {
  219. MiddleVal = Ctrl.getMaximumColoredValue() - Amplitude;
  220. }
  221. else if (MiddleVal - Amplitude < Ctrl.getMinimumValue())
  222. {
  223. MiddleVal = Ctrl.getMinimumValue() + Amplitude;
  224. }
  225. else if (MiddleVal + Amplitude > Ctrl.getMaximumValue())
  226. {
  227. MiddleVal = Ctrl.getMaximumValue() - Amplitude;
  228. }
  229. double Val = MiddleVal + ((double) JSlider1.getValue()) / 100d * Amplitude;
  230. JLabel1.setText(Ctrl.getDecimalFormater().format(Val));
  231. if (Dragging == PRECISE_LEFT_RULER)
  232. Ctrl.setMinimumColoredValue(Val);
  233. if (Dragging == PRECISE_RIGHT_RULER)
  234. Ctrl.setMaximumColoredValue(Val);
  235. }
  236. });
  237. if (UIManager.getLookAndFeel().getName().equals("Metal"))
  238. {
  239. int[] xp1 = { LeftValue, LeftValue - 7, LeftValue - 7, LeftValue - 6,
  240. LeftValue + 6, LeftValue + 7, LeftValue + 7 };
  241. int[] yp1 = { Margin_Ruler_Top + RulerHeight + 1 - 14,
  242. Margin_Ruler_Top + RulerHeight + 1 - 7, Margin_Ruler_Top + RulerHeight + 1,
  243. Margin_Ruler_Top + RulerHeight + 1 + 1, Margin_Ruler_Top + RulerHeight + 1 + 1,
  244. Margin_Ruler_Top + RulerHeight + 1, Margin_Ruler_Top + RulerHeight + 1 - 7 };
  245. TheLeft_Polygon = new Polygon(xp1, yp1, 7);
  246. int[] xp2 = { RightValue - 7, RightValue - 7, RightValue - 6, RightValue + 6,
  247. RightValue + 7, RightValue + 7, RightValue };
  248. int[] yp2 = { Margin_Ruler_Top - 1 + 7, Margin_Ruler_Top - 1,
  249. Margin_Ruler_Top - 1 - 1, Margin_Ruler_Top - 1 - 1, Margin_Ruler_Top - 1,
  250. Margin_Ruler_Top - 1 + 7, Margin_Ruler_Top - 1 + 14, };
  251. TheRight_Polygon = new Polygon(xp2, yp2, 7);
  252. }
  253. else
  254. { // Triangles by default
  255. TheLeft_Polygon = new Polygon();
  256. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight - RulerHeight
  257. / 2 - 1);
  258. TheLeft_Polygon.addPoint(LeftValue + RulerHeight / 2 + 2, Margin_Ruler_Top
  259. + RulerHeight + 1);
  260. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight + 1);
  261. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight - RulerHeight
  262. / 2 - 1);
  263. TheRight_Polygon = new Polygon();
  264. TheRight_Polygon.addPoint(RightValue - 2 - RulerHeight / 2, Margin_Ruler_Top - 1);
  265. TheRight_Polygon.addPoint(RightValue, Margin_Ruler_Top - 1);
  266. TheRight_Polygon.addPoint(RightValue, Margin_Ruler_Top + RulerHeight / 2 + 1);
  267. TheRight_Polygon.addPoint(RightValue - 2 - RulerHeight / 2, Margin_Ruler_Top - 1);
  268. }
  269. JComponent1 = Ctrl;
  270. JComponent1.addMouseListener(this);
  271. JComponent1.addMouseMotionListener(this);
  272. JComponent1.addComponentListener(this);
  273. JComponent1.setLayout(null);
  274. // PreferredSize =
  275. // MinimumSize = );
  276. Ctrl.setPreferredSize(new Dimension(MARGIN_RULER_LEFT + MARGIN_RULER_RIGHT + 16
  277. * Ctrl.getSegmentCount(), Margin_Ruler_Top + MARGIN_RULER_BOTTOM
  278. + MINIMUM_RULER_HEIGHT));
  279. Ctrl.setMinimumSize(new Dimension(MARGIN_RULER_LEFT + MARGIN_RULER_RIGHT + 8
  280. * Ctrl.getSegmentCount(), Margin_Ruler_Top + MARGIN_RULER_BOTTOM
  281. + PREFERRED_RULER_HEIGHT));
  282. JTextFieldMin.setVisible(false);
  283. JTextFieldMax.setVisible(false);
  284. JTextFieldMin.getDocument().addDocumentListener(new DocumentListener()
  285. {
  286. public void changedUpdate(DocumentEvent DocumentEvent_Arg)
  287. {
  288. }
  289. public void insertUpdate(DocumentEvent DocumentEvent_Arg)
  290. {
  291. try
  292. {
  293. JTextFieldMin.setBackground(Color.WHITE);
  294. }
  295. catch (NumberFormatException NumberFormatException_Arg)
  296. {
  297. JTextFieldMin.setBackground(new Color(255, 128, 128));
  298. }
  299. }
  300. public void removeUpdate(DocumentEvent DocumentEvent_Arg)
  301. {
  302. try
  303. {
  304. JTextFieldMin.setBackground(Color.WHITE);
  305. }
  306. catch (NumberFormatException NumberFormatException_Arg)
  307. {
  308. JTextFieldMin.setBackground(new Color(255, 128, 128));
  309. }
  310. }
  311. });
  312. JTextFieldMin.addKeyListener(new KeyAdapter()
  313. {
  314. public void keyTyped(KeyEvent e)
  315. {
  316. if (e.getKeyChar() == KeyEvent.VK_ESCAPE)
  317. {
  318. while (JTextFieldMin.getActionListeners().length > 0)
  319. {
  320. JTextFieldMin.removeActionListener(JTextFieldMin.getActionListeners()[0]);
  321. }
  322. JTextFieldMin.setVisible(false);
  323. }
  324. JTextFieldMin.setSize(JTextFieldMin.getPreferredSize().width + 10, JTextFieldMin
  325. .getPreferredSize().height);
  326. }
  327. });
  328. JComponent1.add(JTextFieldMin);
  329. JTextFieldMax.getDocument().addDocumentListener(new DocumentListener()
  330. {
  331. public void changedUpdate(DocumentEvent DocumentEvent_Arg)
  332. {
  333. }
  334. public void insertUpdate(DocumentEvent DocumentEvent_Arg)
  335. {
  336. try
  337. {
  338. JTextFieldMax.setBackground(Color.WHITE);
  339. }
  340. catch (NumberFormatException NumberFormatException_Arg)
  341. {
  342. JTextFieldMax.setBackground(new Color(255, 128, 128));
  343. }
  344. }
  345. public void removeUpdate(DocumentEvent DocumentEvent_Arg)
  346. {
  347. try
  348. {
  349. JTextFieldMax.setBackground(Color.WHITE);
  350. }
  351. catch (NumberFormatException NumberFormatException_Arg)
  352. {
  353. JTextFieldMax.setBackground(new Color(255, 128, 128));
  354. }
  355. }
  356. });
  357. JTextFieldMax.addKeyListener(new KeyAdapter()
  358. {
  359. public void keyTyped(KeyEvent e)
  360. {
  361. if (e.getKeyChar() == KeyEvent.VK_ESCAPE)
  362. {
  363. while (JTextFieldMax.getActionListeners().length > 0)
  364. {
  365. JTextFieldMax.removeActionListener(JTextFieldMax.getActionListeners()[0]);
  366. }
  367. JTextFieldMax.setVisible(false);
  368. }
  369. int OldX = JTextFieldMax.getLocation().x;
  370. int OldWidth = JTextFieldMax.getSize().width;
  371. JTextFieldMax.setSize(JTextFieldMax.getPreferredSize().width + 10, JTextFieldMax
  372. .getPreferredSize().height);
  373. JTextFieldMax.setLocation(OldX + (OldWidth - JTextFieldMax.getSize().width),
  374. JTextFieldMax.getLocation().y);
  375. }
  376. });
  377. JComponent1.add(JTextFieldMax);
  378. JComponent1.setDoubleBuffered(true);
  379. // JComponent1.setSize(300, 50);
  380. } // constructor()
  381. /**
  382. * @param Color_Arg
  383. * Description of the Parameter
  384. * @return the opposite color to make shadow of text with it
  385. */
  386. protected Color getOppositeColor(Color Color_Arg)
  387. {
  388. int R = Color_Arg.getRed();
  389. int G = Color_Arg.getGreen();
  390. int B = Color_Arg.getBlue();
  391. R = 255 - R;
  392. int R2 = (Color_Arg.getRed() + 128) % 255;
  393. if (Math.abs(R - Color_Arg.getRed()) < Math.abs(R2 - Color_Arg.getRed()))
  394. {
  395. R = R2;
  396. }
  397. G = 255 - G;
  398. int G2 = (Color_Arg.getGreen() + 128) % 255;
  399. if (Math.abs(G - Color_Arg.getGreen()) < Math.abs(G2 - Color_Arg.getGreen()))
  400. {
  401. G = G2;
  402. }
  403. B = 255 - B;
  404. int B2 = (Color_Arg.getBlue() + 128) % 255;
  405. if (Math.abs(B - Color_Arg.getBlue()) < Math.abs(B2 - Color_Arg.getBlue()))
  406. {
  407. B = B2;
  408. }
  409. return new Color(R, G, B);
  410. } // getOppositeColor()
  411. /**
  412. * Sets the rulers value if the new values are coherents.
  413. *
  414. * @param Min_Arg
  415. * the value of the min triangle
  416. * @param Max_Arg
  417. * the value of the max triangle
  418. */
  419. public void setRulerValues(double Min_Arg, double Max_Arg)
  420. {
  421. int SegmentCount = Ctrl.getSegmentCount();
  422. if (SegmentCount == 0)
  423. {
  424. SegmentCount = 1;
  425. }
  426. RulerWidth = JComponent1.getSize().width - MARGIN_RULER_LEFT - MARGIN_RULER_RIGHT;
  427. GraduationWidth = (RulerWidth * Ctrl.getSegmentSize())
  428. / (Ctrl.getMaximumValue() - Ctrl.getMinimumValue());
  429. NeverDrawn = false;
  430. int NewLeftValue = (int) (MARGIN_RULER_LEFT + ((Min_Arg - Ctrl.getMinimumValue()) * RulerWidth)
  431. / (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()));
  432. int NewRightValue = (int) (MARGIN_RULER_LEFT + ((Max_Arg - Ctrl.getMinimumValue()) * RulerWidth)
  433. / (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()));
  434. if (NewLeftValue <= NewRightValue && NewLeftValue >= MARGIN_RULER_LEFT
  435. && NewRightValue <= MARGIN_RULER_LEFT + RulerWidth)
  436. {
  437. LeftValue = NewLeftValue;
  438. RightValue = NewRightValue;
  439. int TriangleSide = RulerHeight / 2;
  440. TriangleSide = Math.max(Math.min(TriangleSide, 20), 10);
  441. if (UIManager.getLookAndFeel().getName().equals("Metal"))
  442. {
  443. int[] xp1 = { LeftValue, LeftValue - 7, LeftValue - 7, LeftValue - 6,
  444. LeftValue + 6, LeftValue + 7, LeftValue + 7 };
  445. int[] yp1 = { Margin_Ruler_Top + RulerHeight + 1 - 14,
  446. Margin_Ruler_Top + RulerHeight + 1 - 7, Margin_Ruler_Top + RulerHeight + 1,
  447. Margin_Ruler_Top + RulerHeight + 1 + 1,
  448. Margin_Ruler_Top + RulerHeight + 1 + 1, Margin_Ruler_Top + RulerHeight + 1,
  449. Margin_Ruler_Top + RulerHeight + 1 - 7 };
  450. TheLeft_Polygon = new Polygon(xp1, yp1, 7);
  451. int[] xp2 = { RightValue - 7, RightValue - 7, RightValue - 6, RightValue + 6,
  452. RightValue + 7, RightValue + 7, RightValue };
  453. int[] yp2 = { Margin_Ruler_Top - 1 + 7, Margin_Ruler_Top - 1,
  454. Margin_Ruler_Top - 1 - 1, Margin_Ruler_Top - 1 - 1, Margin_Ruler_Top - 1,
  455. Margin_Ruler_Top - 1 + 7, Margin_Ruler_Top - 1 + 14, };
  456. TheRight_Polygon = new Polygon(xp2, yp2, 7);
  457. }
  458. else
  459. { // Triangles by default
  460. TheLeft_Polygon = new Polygon();
  461. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight - TriangleSide
  462. - 1);
  463. TheLeft_Polygon.addPoint(LeftValue + TriangleSide + 2, Margin_Ruler_Top
  464. + RulerHeight + 1);
  465. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight + 1);
  466. TheLeft_Polygon.addPoint(LeftValue, Margin_Ruler_Top + RulerHeight - TriangleSide
  467. - 1);
  468. TheRight_Polygon = new Polygon();
  469. TheRight_Polygon.addPoint(RightValue - 2 - TriangleSide, Margin_Ruler_Top - 1);
  470. TheRight_Polygon.addPoint(RightValue, Margin_Ruler_Top - 1);
  471. TheRight_Polygon.addPoint(RightValue, Margin_Ruler_Top + TriangleSide + 1);
  472. TheRight_Polygon.addPoint(RightValue - 2 - TriangleSide, Margin_Ruler_Top - 1);
  473. }
  474. }
  475. else if (Ctrl.getSize().width == 0 || Ctrl.getSize().height == 0)
  476. {
  477. }
  478. else
  479. {
  480. System.err.println("\nsetRulerValues()");
  481. System.err.println(" Size = " + Ctrl.getSize());
  482. System.err.println(" NewLeftValue = " + NewLeftValue);
  483. System.err.println(" NewRightValue = " + NewRightValue);
  484. System.err.println(" MARGIN_RULER_LEFT = " + MARGIN_RULER_LEFT);
  485. System.err.println(" MARGIN_RULER_LEFT + RulerWidth = "
  486. + (MARGIN_RULER_LEFT + RulerWidth));
  487. // Debug.debug(0, "");
  488. }
  489. } // setRulerValues()
  490. /**
  491. * Method called by the awt-swing mechanism when the area needs to be
  492. * refreshed
  493. *
  494. * @param Graphics_Arg
  495. * the graphic context to draw things
  496. */
  497. public void paint(Graphics Graphics_Arg)
  498. {
  499. if (Graphics_Arg == null)
  500. {
  501. return;
  502. }
  503. Graphics2D Graphics2 = (Graphics2D) Graphics_Arg;
  504. RenderingHints RenderingHints2 = new RenderingHints(null);
  505. RenderingHints2.put(RenderingHints.KEY_INTERPOLATION,
  506. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
  507. RenderingHints2.put(RenderingHints.KEY_TEXT_ANTIALIASING,
  508. RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  509. RenderingHints2.put(RenderingHints.KEY_ANTIALIASING,
  510. RenderingHints.VALUE_ANTIALIAS_OFF);
  511. RenderingHints2.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
  512. Graphics2.setRenderingHints(RenderingHints2);
  513. Font Font1 = Ctrl.getFont();
  514. Font Font2 = new Font(Font1.getName(), Font.BOLD, Font1.getSize());
  515. Shape OldClip = Graphics2.getClip();
  516. // Shape NewClip = new Rectangle2D.Float(MARGIN_RULER_LEFT,
  517. // Margin_Ruler_Top,RulerWidth, RulerHeight);
  518. Shape NewClip = new RoundRectangle2D.Float(MARGIN_RULER_LEFT + 2, Margin_Ruler_Top,
  519. RulerWidth - 3, RulerHeight, Ctrl.getArcSize(), Ctrl.getArcSize());
  520. int SegmentCount = Ctrl.getSegmentCount();
  521. FontMetrics TheFontMetrics = Graphics2.getFontMetrics();
  522. RulerWidth = JComponent1.getSize().width - MARGIN_RULER_LEFT - MARGIN_RULER_RIGHT;
  523. double ValuesWidth = Ctrl.getMaximumValue() - Ctrl.getMinimumValue();
  524. if (NeverDrawn)
  525. {
  526. LeftValue = (int) (MARGIN_RULER_LEFT + ((Ctrl.getMinimumColoredValue() - Ctrl
  527. .getMinimumValue()) * RulerWidth)
  528. / (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()));
  529. RightValue = (int) (MARGIN_RULER_LEFT + ((Ctrl.getMaximumColoredValue() - Ctrl
  530. .getMinimumValue()) * RulerWidth)
  531. / (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()));
  532. TheRight_Polygon.translate(RulerWidth, 0);
  533. NeverDrawn = false;
  534. }
  535. if (RulerWidth != JComponent1.getSize().width - MARGIN_RULER_LEFT
  536. - MARGIN_RULER_RIGHT)
  537. {
  538. int NewRulerWidth = JComponent1.getSize().width - MARGIN_RULER_LEFT
  539. - MARGIN_RULER_RIGHT;
  540. NewRulerWidth = NewRulerWidth - NewRulerWidth % SegmentCount;
  541. int NewLeftValue = MARGIN_RULER_LEFT
  542. + ((LeftValue - MARGIN_RULER_LEFT) * (NewRulerWidth)) / RulerWidth;
  543. int NewRightValue = MARGIN_RULER_LEFT
  544. + ((RightValue - MARGIN_RULER_LEFT) * (NewRulerWidth)) / RulerWidth;
  545. TheLeft_Polygon.translate(NewLeftValue - LeftValue, 0);
  546. TheRight_Polygon.translate(NewRightValue - RightValue, 0);
  547. LeftValue = NewLeftValue;
  548. RightValue = NewRightValue;
  549. RulerWidth = NewRulerWidth;
  550. GraduationWidth = (float) ((RulerWidth * Ctrl.getSegmentSize()) / (Ctrl
  551. .getMaximumValue() - Ctrl.getMinimumValue()));
  552. }
  553. Color BackColor = null;
  554. Object SliderBackColor = UIManager.getLookAndFeel().getDefaults().get(
  555. "Slider.background");
  556. if (SliderBackColor != null || !(SliderBackColor instanceof ColorUIResource))
  557. BackColor = (Color) SliderBackColor;
  558. if (BackColor == null || Ctrl.getBackground() != null)
  559. BackColor = Ctrl.getBackground();
  560. if (BackColor != null)
  561. Graphics2.setColor(BackColor);
  562. Graphics2.fillRect(0, 0, JComponent1.getSize().width, JComponent1.getSize().height);
  563. Graphics2.setClip(NewClip);
  564. Graphics2.setColor(Ctrl.getSliderBackground());
  565. Graphics2.fillRoundRect(MARGIN_RULER_LEFT, Margin_Ruler_Top, RulerWidth, RulerHeight,
  566. Ctrl.getArcSize(), Ctrl.getArcSize());
  567. Graphics2.setColor(Ctrl.getSliderBackground().darker());
  568. Graphics2.drawArc(MARGIN_RULER_LEFT + 1, Margin_Ruler_Top, Ctrl.getArcSize(), Ctrl
  569. .getArcSize(), 90, 90);
  570. Graphics2.drawArc(MARGIN_RULER_LEFT + RulerWidth - Ctrl.getArcSize() - 1,
  571. Margin_Ruler_Top, Ctrl.getArcSize(), Ctrl.getArcSize(), 0, 90);
  572. Graphics2.setColor(Ctrl.getSliderBackground().brighter());
  573. Graphics2.drawArc(MARGIN_RULER_LEFT + RulerWidth - Ctrl.getArcSize() - 1,
  574. Margin_Ruler_Top + RulerHeight - Ctrl.getArcSize(), Ctrl.getArcSize(), Ctrl
  575. .getArcSize(), 270, 90);
  576. Graphics2.drawArc(MARGIN_RULER_LEFT + 1, Margin_Ruler_Top + RulerHeight
  577. - Ctrl.getArcSize(), Ctrl.getArcSize(), Ctrl.getArcSize(), 180, 90);
  578. Graphics2.setColor(Ctrl.getSliderBackground().darker());
  579. Graphics2.drawLine(MARGIN_RULER_LEFT + Ctrl.getArcSize() / 2 - 1,
  580. Margin_Ruler_Top + 1, MARGIN_RULER_LEFT + RulerWidth - Ctrl.getArcSize() / 2 + 1,
  581. Margin_Ruler_Top + 1);
  582. Graphics2.drawLine(MARGIN_RULER_LEFT + 1, Margin_Ruler_Top + Ctrl.getArcSize() / 2,
  583. MARGIN_RULER_LEFT + 1, Margin_Ruler_Top + RulerHeight - Ctrl.getArcSize() / 2);
  584. Graphics2.setColor(Ctrl.getSliderBackground().brighter());
  585. Graphics2.drawLine(MARGIN_RULER_LEFT + Ctrl.getArcSize() / 2 - 1, Margin_Ruler_Top
  586. + RulerHeight - 1, MARGIN_RULER_LEFT + RulerWidth - Ctrl.getArcSize() / 2 + 1,
  587. Margin_Ruler_Top + RulerHeight - 1);
  588. Graphics2.drawLine(MARGIN_RULER_LEFT + RulerWidth - 1, Margin_Ruler_Top
  589. + Ctrl.getArcSize() / 2 + 1, MARGIN_RULER_LEFT + RulerWidth - 1, Margin_Ruler_Top
  590. + RulerHeight - Ctrl.getArcSize() / 2);
  591. Graphics2.setClip(OldClip);
  592. int LastMax = 0;
  593. /*
  594. * NewClip = new RoundRectangle2D.Float( MARGIN_RULER_LEFT+2,
  595. * Margin_Ruler_Top, RulerWidth-3, RulerHeight, Ctrl.getArcSize(),
  596. * Ctrl.getArcSize());
  597. */
  598. // it is the right opportunity to look for how many full non colored
  599. // segments there are before the fisrt one
  600. int SegmentCountBefore = 0;
  601. double[][] ColTable = Ctrl.getColorTable();
  602. // Graphics2.setClip(NewClip);
  603. for (int i = 0; i <= SegmentCount; i++)
  604. {
  605. double Val = Ctrl.getMinimumValue() + i * Ctrl.getSegmentSize();
  606. double Val2 = Ctrl.getMinimumValue() + (i + 1) * Ctrl.getSegmentSize();
  607. if (Val <= ColTable[0][0] && ColTable[0][0] < Val2)
  608. SegmentCountBefore = i;
  609. String Unit = Ctrl.getUnit();
  610. String NumberString = "";
  611. int NumberWidth = 0;
  612. int x = 0;
  613. String MaxNumberString = "";
  614. if (Ctrl.getMaximumValue() == (long) Ctrl.getMaximumValue())
  615. {
  616. MaxNumberString = "" + (_myFormatter.format((long) Ctrl.getMaximumValue())) + Unit;
  617. }
  618. else
  619. {
  620. MaxNumberString = "" + _myFormatter.format((((long) (Ctrl.getMaximumValue() * 10)) / 10)) + Unit;
  621. }
  622. if (Val > Ctrl.getMaximumValue())
  623. {
  624. Val = Ctrl.getMaximumValue();
  625. if (Val == (long) Val)
  626. {
  627. NumberString = "" + _myFormatter.format(((long) Val)) + Unit;
  628. }
  629. else
  630. {
  631. NumberString = "" + _myFormatter.format((long)(((long) (Val * 10)) / 10f)) + Unit;
  632. }
  633. NumberWidth = TheFontMetrics.stringWidth(NumberString);
  634. x = JComponent1.getSize().width - MARGIN_RULER_RIGHT - NumberWidth;
  635. }
  636. else
  637. {
  638. if (Val == (long) Val)
  639. {
  640. NumberString = "" + _myFormatter.format(((long) Val)) + Unit;
  641. }
  642. else
  643. {
  644. NumberString = "" + _myFormatter.format((long)(((long) (Val * 10)) / 10f)) + Unit;
  645. }
  646. NumberWidth = TheFontMetrics.stringWidth(NumberString);
  647. x = MARGIN_RULER_LEFT + (int) (GraduationWidth * i)
  648. - (int) ((NumberWidth * ((float) i / SegmentCount)));
  649. }
  650. // get the color
  651. Graphics_Arg.setColor(Ctrl.getForeground());
  652. if (Val == Ctrl.getMaximumValue() || Val == Ctrl.getMinimumValue())
  653. {
  654. Graphics2.setFont(Font2);
  655. Graphics2.drawString(NumberString, x, Margin_Ruler_Top - 1);
  656. // restore the font
  657. Graphics2.setFont(Font1);
  658. LastMax = x + NumberWidth;
  659. } // if not too close to the last one or too close to the previous one
  660. else if (x + NumberWidth < JComponent1.getSize().width - MARGIN_RULER_RIGHT
  661. - TheFontMetrics.stringWidth(MaxNumberString)
  662. && x >= LastMax + 8)
  663. {
  664. Graphics2.drawString(NumberString, x, Margin_Ruler_Top - 1);
  665. LastMax = x + NumberWidth;
  666. }
  667. if (LastMax == x + NumberWidth)
  668. {
  669. Graphics2.setColor(Ctrl.getSliderBackground().darker().darker());
  670. }
  671. else
  672. {
  673. Graphics2.setColor(Ctrl.getSliderBackground().darker());
  674. }
  675. if (ContentPainterSupport1.getPainterListenerNumber() > 0
  676. && Val < Ctrl.getMaximumValue())
  677. {
  678. int x0 = MARGIN_RULER_LEFT + (int) (GraduationWidth * i);
  679. int x3 = MARGIN_RULER_LEFT + (int) (GraduationWidth * (i + 1));
  680. Rectangle Rect1bis = new Rectangle(x0, Margin_Ruler_Top + 2, x3 - x0,
  681. RulerHeight - 3);
  682. x3 = Math.min(x3, MARGIN_RULER_LEFT + RulerWidth);
  683. Rectangle RectClip = new Rectangle(x0, Margin_Ruler_Top + 2, x3 - x0 + 2,
  684. RulerHeight - 3);
  685. Shape ShapeClip = Graphics2.getClip();
  686. Color Color0 = Graphics2.getColor();
  687. Graphics2.setClip(RectClip);
  688. ContentPainterSupport1.firePaint(Ctrl, Graphics2, Val, Val2, i, null, Rect1bis,
  689. Rect1bis);
  690. Graphics2.setClip(ShapeClip);
  691. Graphics2.setColor(Color0);
  692. }
  693. if (i != 0 && Val < Ctrl.getMaximumValue())
  694. {
  695. if (ContentPainterSupport1.getPainterListenerNumber() == 0)
  696. Graphics2.drawLine(MARGIN_RULER_LEFT + (int) (GraduationWidth * i),
  697. Margin_Ruler_Top + 2, MARGIN_RULER_LEFT + (int) (GraduationWidth * i),
  698. Margin_Ruler_Top + RulerHeight - 2);
  699. }
  700. if (i == 0)
  701. {
  702. RectFirstLabel = new Rectangle(x - 1, Margin_Ruler_Top
  703. - TheFontMetrics.getAscent(), NumberWidth + 1, TheFontMetrics.getAscent());
  704. }
  705. if (i == SegmentCount)
  706. {
  707. RectLastLabel = new Rectangle(x - 1, Margin_Ruler_Top
  708. - TheFontMetrics.getAscent(), NumberWidth + 1, TheFontMetrics.getAscent());
  709. }
  710. if (MouseUnder == FIRST_LABEL)
  711. {
  712. Graphics2.draw(RectFirstLabel);
  713. }
  714. if (MouseUnder == LAST_LABEL)
  715. {
  716. Graphics2.draw(RectLastLabel);
  717. }
  718. }
  719. if (MouseUnder == SEGMENT && RectangleSegment != null)
  720. {
  721. Graphics2.setColor(SystemColor.control.darker());
  722. Graphics2.draw(RectangleSegment);
  723. }
  724. // ColorisationEvent CE1 = new ColorisationEvent(this,
  725. // Ctrl.getColorTable());
  726. // colored segment
  727. for (int i = 0; i < ColTable.length; i++)
  728. {
  729. Graphics2.setColor(new Color((int) (ColTable[i][2])));
  730. if (ColTable[i][0] < ColTable[i][1])
  731. {
  732. // the selection only
  733. int x1 = (int) (MARGIN_RULER_LEFT + (RulerWidth * (ColTable[i][0] - Ctrl
  734. .getMinimumValue()))
  735. / ValuesWidth) + 1;
  736. int x2 = (int) (MARGIN_RULER_LEFT + (RulerWidth * ((ColTable[i][1]) - Ctrl
  737. .getMinimumValue()))
  738. / ValuesWidth);
  739. // the full segment
  740. int x0 = MARGIN_RULER_LEFT + (int) (GraduationWidth * (int) ColTable[i][3]);
  741. int x3 = MARGIN_RULER_LEFT + (int) (GraduationWidth * (int) (ColTable[i][3] + 1));
  742. Rectangle Rect1bis = new Rectangle(x1, Margin_Ruler_Top + 2, x2 - x1,
  743. RulerHeight - 3);
  744. x3 = Math.min(x3, MARGIN_RULER_LEFT + RulerWidth);
  745. Rectangle Rect1 = new Rectangle(x1, Margin_Ruler_Top + 2, x2 - x1,
  746. RulerHeight - 3);
  747. Rectangle RectClip = new Rectangle(x1 - 1, Margin_Ruler_Top + 2, x2 - x1 + 2,
  748. RulerHeight - 3);
  749. Rectangle Rect2 = new Rectangle(x0, Margin_Ruler_Top + 2, x3 - x0,
  750. RulerHeight - 3);
  751. if (ContentPainterSupport1.getPainterListenerNumber() == 0)
  752. {
  753. Graphics2.fill(Rect1);
  754. if (i != 0)
  755. {
  756. Graphics2.setColor(new Color(Graphics2.getColor().getRed(), Graphics2
  757. .getColor().getGreen(), Graphics2.getColor().getBlue(), 192));
  758. Graphics2.drawLine(x1 - 1, Margin_Ruler_Top + 3, x1 - 1, Margin_Ruler_Top
  759. + RulerHeight - 3);
  760. }
  761. }
  762. else
  763. {
  764. Color Color0 = Graphics2.getColor();
  765. Graphics2.setClip(NewClip);
  766. Graphics2.clip(RectClip);
  767. ContentPainterSupport1.firePaint(Ctrl, Graphics2, ColTable[i][0],
  768. ColTable[i][1], i + SegmentCountBefore, Graphics2.getColor(), Rect1bis,
  769. Rect2);
  770. Graphics2.setClip(OldClip);
  771. Graphics2.setColor(Color0);
  772. }
  773. }
  774. }
  775. Graphics2.setClip(OldClip);
  776. if (Dragging == ALT_LEFT_RULER || Dragging == ALT_RIGHT_RULER)
  777. {
  778. Rectangle Rect1 = TheRight_Polygon.getBounds();
  779. Rectangle Rect2 = TheLeft_Polygon.getBounds();
  780. Rectangle2D Rectangle2D1 = Rect1.createUnion(Rect2);
  781. Graphics2.setColor(SystemColor.scrollbar.darker());
  782. Graphics2.fillRect((int) (Rectangle2D1.getX() + Rectangle2D1.getWidth() / 2),
  783. Margin_Ruler_Top, 2, RulerHeight);
  784. }
  785. // Graphics2.setColor(getOppositeColor(Ctrl.getBackground()));
  786. Graphics2.setColor(Color.BLACK);
  787. Graphics2.drawRoundRect(MARGIN_RULER_LEFT, Margin_Ruler_Top, RulerWidth, RulerHeight,
  788. Ctrl.getArcSize(), Ctrl.getArcSize());
  789. paintThumbs(Graphics2);
  790. if (Dragging == ALT_RIGHT_RULER || Dragging == ALT_LEFT_RULER
  791. || Dragging == RIGHT_RULER || Dragging == SEGMENT || Dragging == SHIFT_SEGMENT
  792. || Dragging == SHIFT_RIGHT_RULER)
  793. {
  794. String ValString = "";
  795. if (Math.abs(((int) Ctrl.getMaximumColoredValue()) - Ctrl.getMaximumColoredValue()) < 0.0001)
  796. {
  797. ValString = "" + _myFormatter.format((int) Ctrl.getMaximumColoredValue());
  798. }
  799. else
  800. {
  801. ValString = _myFormatter.format((long) Ctrl.getMaximumColoredValue());
  802. }
  803. Graphics2.setColor(getOppositeColor(Ctrl.getForeground()));
  804. Graphics2.drawString(ValString, RightValue + 3, Margin_Ruler_Top
  805. + TheFontMetrics.getAscent() + 1);
  806. Graphics2.setColor(Ctrl.getForeground());
  807. Graphics2.drawString(ValString, RightValue + 2, Margin_Ruler_Top
  808. + TheFontMetrics.getAscent());
  809. }
  810. if (Dragging == ALT_RIGHT_RULER || Dragging == ALT_LEFT_RULER
  811. || Dragging == LEFT_RULER || Dragging == SEGMENT || Dragging == SHIFT_SEGMENT
  812. || Dragging == SHIFT_LEFT_RULER)
  813. {
  814. String ValString = "";
  815. if (Math.abs(((int) Ctrl.getMinimumColoredValue()) - Ctrl.getMinimumColoredValue()) < 0.0001)
  816. {
  817. ValString = "" + _myFormatter.format((int) Ctrl.getMinimumColoredValue());
  818. }
  819. else
  820. {
  821. ValString = _myFormatter.format((long) Ctrl.getMinimumColoredValue());
  822. }
  823. Graphics2.setColor(getOppositeColor(Ctrl.getForeground()));
  824. Graphics2.drawString(ValString, LeftValue - TheFontMetrics.stringWidth(ValString)
  825. - 1, Margin_Ruler_Top + RulerHeight - 1);
  826. Graphics2.setColor(Ctrl.getForeground());
  827. Graphics2.drawString(ValString, LeftValue - TheFontMetrics.stringWidth(ValString)
  828. - 2, Margin_Ruler_Top + RulerHeight - 2);
  829. }
  830. if (JTextFieldMax.isVisible())
  831. {
  832. JTextFieldMax.repaint();
  833. }
  834. if (JTextFieldMin.isVisible())
  835. {
  836. JTextFieldMin.repaint();
  837. }
  838. } // paint()
  839. /**
  840. * paint a thumb
  841. */
  842. public void paintThumbs(Graphics Graphics_Arg)
  843. {
  844. Graphics2D Graphics2 = (Graphics2D) Graphics_Arg;
  845. // System.out.println("getLookAndFeel="+UIManager.getLookAndFeel().getName());
  846. // System.out.println("getCurrentTheme="+MetalLookAndFeel.getCurrentTheme().getName());
  847. // TODO : Ocean Theme
  848. if (UIManager.getLookAndFeel().getName().equals("Metal"))
  849. {
  850. if (Dragging == LEFT_RULER || Dragging == SHIFT_LEFT_RULER
  851. || Dragging == ALT_LEFT_RULER)
  852. paintThumb(Graphics_Arg, true, TheLeft_Polygon, MetalLookAndFeel
  853. .getPrimaryControlShadow(), MetalLookAndFeel.getPrimaryControlDarkShadow(),
  854. MetalLookAndFeel.getPrimaryControl());
  855. else if (MouseUnder == LEFT_POLYGON)
  856. paintThumb(Graphics_Arg, true, TheLeft_Polygon, MetalLookAndFeel
  857. .getControlShadow(), MetalLookAndFeel.getControlDarkShadow(),
  858. MetalLookAndFeel.getControl());
  859. else
  860. paintThumb(Graphics_Arg, true, TheLeft_Polygon, MetalLookAndFeel.getControl(),
  861. MetalLookAndFeel.getControlShadow(), MetalLookAndFeel.getControlHighlight());
  862. if (Dragging == RIGHT_RULER || Dragging == SHIFT_RIGHT_RULER
  863. || Dragging == ALT_RIGHT_RULER)
  864. paintThumb(Graphics_Arg, false, TheRight_Polygon, MetalLookAndFeel
  865. .getPrimaryControlShadow(), MetalLookAndFeel.getPrimaryControlDarkShadow(),
  866. MetalLookAndFeel.getPrimaryControl());
  867. else if ((MouseUnder == RIGHT_POLYGON))
  868. paintThumb(Graphics_Arg, false, TheRight_Polygon, MetalLookAndFeel
  869. .getControlShadow(), MetalLookAndFeel.getControlDarkShadow(),
  870. MetalLookAndFeel.getControl());
  871. else
  872. paintThumb(Graphics_Arg, false, TheRight_Polygon, MetalLookAndFeel.getControl(),
  873. MetalLookAndFeel.getControlShadow(), MetalLookAndFeel.getControlHighlight());
  874. }
  875. else
  876. { // default thumb = triangle
  877. Graphics2.setColor(SystemColor.control);
  878. if (Dragging == LEFT_RULER || Dragging == SHIFT_LEFT_RULER
  879. || Dragging == ALT_LEFT_RULER)
  880. Graphics2.setColor(MetalLookAndFeel.getPrimaryControlShadow());
  881. else if (MouseUnder == LEFT_POLYGON)
  882. Graphics2.setColor(MetalLookAndFeel.getControlHighlight());
  883. Graphics2.fillPolygon(TheLeft_Polygon);
  884. Graphics2.setColor(SystemColor.control);
  885. if (Dragging == RIGHT_RULER || Dragging == SHIFT_RIGHT_RULER
  886. || Dragging == ALT_RIGHT_RULER)
  887. Graphics2.setColor(MetalLookAndFeel.getPrimaryControlShadow());
  888. else if (MouseUnder == RIGHT_POLYGON)
  889. Graphics2.setColor(MetalLookAndFeel.getControlHighlight());
  890. Graphics2.fillPolygon(TheRight_Polygon);
  891. // shadow
  892. Graphics2.setColor(SystemColor.control.brighter());
  893. Graphics2.drawLine(TheLeft_Polygon.xpoints[0] + 1, TheLeft_Polygon.ypoints[0] + 2,
  894. TheLeft_Polygon.xpoints[2] + 1, TheLeft_Polygon.ypoints[2] - 1);
  895. Graphics2.drawLine(TheRight_Polygon.xpoints[0] + 1,
  896. TheRight_Polygon.ypoints[0] + 1, TheRight_Polygon.xpoints[1] - 1,
  897. TheRight_Polygon.ypoints[1] + 1);
  898. Graphics2.setColor(SystemColor.control.darker());
  899. Graphics2.drawLine(TheLeft_Polygon.xpoints[1] - 2, TheLeft_Polygon.ypoints[1] - 1,
  900. TheLeft_Polygon.xpoints[2] + 1, TheLeft_Polygon.ypoints[2] - 1);
  901. Graphics2.drawLine(TheRight_Polygon.xpoints[1] - 1,
  902. TheRight_Polygon.ypoints[1] + 1, TheRight_Polygon.xpoints[2] - 1,
  903. TheRight_Polygon.ypoints[2] - 1);
  904. if (MouseUnder == SELECTION)
  905. {
  906. Rectangle Rect1 = TheRight_Polygon.getBounds();
  907. Rectangle Rect2 = TheLeft_Polygon.getBounds();
  908. Rectangle2D Rectangle2D1 = Rect1.createUnion(Rect2);
  909. Graphics2.draw(Rectangle2D1);
  910. }
  911. else if (MouseUnder == LEFT_POLYGON)
  912. {
  913. // Graphics2.fillPolygon(TheLeft_Polygon);
  914. Graphics2.setColor(SystemColor.control.darker().darker());
  915. Graphics2.drawLine(TheLeft_Polygon.xpoints[0] + 1,
  916. TheLeft_Polygon.ypoints[0] + 2, TheLeft_Polygon.xpoints[2] + 1,
  917. TheLeft_Polygon.ypoints[2] - 1);
  918. Graphics2.setColor(SystemColor.control);
  919. Graphics2.drawLine(TheLeft_Polygon.xpoints[1] - 2,
  920. TheLeft_Polygon.ypoints[1] - 1, TheLeft_Polygon.xpoints[2] + 1,
  921. TheLeft_Polygon.ypoints[2] - 1);
  922. }
  923. else if (MouseUnder == RIGHT_POLYGON)
  924. {
  925. // Graphics2.fillPolygon(TheRight_Polygon);
  926. Graphics2.setColor(SystemColor.control.darker().darker());
  927. Graphics2.drawLine(TheRight_Polygon.xpoints[0] + 1,
  928. TheRight_Polygon.ypoints[0] + 1, TheRight_Polygon.xpoints[1] - 1,
  929. TheRight_Polygon.ypoints[1] + 1);
  930. Graphics2.setColor(SystemColor.control);
  931. Graphics2.drawLine(TheRight_Polygon.xpoints[1] - 1,
  932. TheRight_Polygon.ypoints[1] + 1, TheRight_Polygon.xpoints[2] - 1,
  933. TheRight_Polygon.ypoints[2] - 1);
  934. }
  935. // Graphics2.setColor(getOppositeColor(Ctrl.getBackground()));
  936. Graphics2.setColor(Color.BLACK);
  937. Graphics2.drawPolygon(TheLeft_Polygon);
  938. Graphics2.drawPolygon(TheRight_Polygon);
  939. }
  940. }// paintThumb()
  941. // Parameters of the widget
  942. /**
  943. * Paints shadowed dots on the given <tt>Graphics</tt> objects. The
  944. * coordinates of the points must be given in arrays.
  945. *
  946. * @param g
  947. * the <tt>Graphics</tt> object on which we wand to paint the dots
  948. * @param xCoords
  949. * array containing the X coordinates of the dots
  950. * @param yCoords
  951. * array containing the Y coordinates of the dots
  952. * @param num
  953. * the number of dots
  954. * @author Christophe Jacquet, Frederic Vernier
  955. */
  956. private void paintShadowedDots(Graphics g, int[] xCoords, int[] yCoords, int num,
  957. Color DarkColor_Arg, Color BrightColor_Arg)
  958. {
  959. for (int s = 0; s < 2; s++)
  960. {
  961. g.setColor(s == 0 ? BrightColor_Arg : DarkColor_Arg);
  962. for (int i = 0; i < num; i++)
  963. {
  964. g.drawLine(xCoords[i] + s, yCoords[i] + s, xCoords[i] + s, yCoords[i] + s);
  965. }
  966. }
  967. }// paintShadowedDots()
  968. /**
  969. * Draws an arrow (upward or downward) on a given <tt>Graphics</tt> object.
  970. *
  971. * @param g
  972. * the <tt>Graphics</tt> object on which we want to paint the arrow
  973. * @param up
  974. * if <tt>true</tt>, the arrow will be painted upward. If
  975. * @author Christophe Jacquet, Frederic Vernier <tt>false</tt>, it will be
  976. * painted downward
  977. */
  978. private void paintThumb(Graphics Graphics_Arg, boolean up, Polygon Thumb_Arg,
  979. Color MainColor_Arg, Color DarkColor_Arg, Color BrightColor_Arg)
  980. {
  981. Graphics2D G2 = (Graphics2D) Graphics_Arg;
  982. // HACK: commented out the next block of code. Because it's being compared with
  983. // 'false', it can never run anyway. I suspect it's part of Borlander's workaround
  984. //
  985. // if (UIManager.getLookAndFeel().getName().equals("Metal") && false)
  986. // {
  987. // Color BackColor = null;
  988. // Object SliderBackColor = UIManager.getLookAndFeel().getDefaults().get(
  989. // "Slider.gradient");
  990. // if (SliderBackColor != null && SliderBackColor instanceof List)
  991. // {
  992. // List GradientProperties = (List) SliderBackColor;
  993. // Float Cut1 = (Float) GradientProperties.get(0);
  994. // Float Cut2 = (Float) GradientProperties.get(1);
  995. // Color Color1 = (Color) GradientProperties.get(2);
  996. // Color Color2 = (Color) GradientProperties.get(3);
  997. // Color Color3 = (Color) GradientProperties.get(4);
  998. // float Rem = 1f - Cut2.floatValue() - 2 * Cut1.floatValue();
  999. // int x1 = up ? Thumb_Arg.xpoints[0] : Thumb_Arg.xpoints[6];
  1000. // int y1 = up ? Thumb_Arg.ypoints[0] : Thumb_Arg.ypoints[6];
  1001. //
  1002. // int x2 = up ? Thumb_Arg.xpoints[1] : Thumb_Arg.xpoints[5];
  1003. // int y2 = up ? Thumb_Arg.ypoints[1] : Thumb_Arg.ypoints[5];
  1004. //
  1005. // Shape Shape0 = G2.getClip();
  1006. // G2.setClip(Thumb_Arg);
  1007. // if (up)
  1008. // {
  1009. // GradientPaint GradientPaint1 = new GradientPaint(x1 - 7, y1, Color3, x1, y1
  1010. // + (int) (16f * Rem), Color1);
  1011. // GradientPaint GradientPaint2 = new GradientPaint(x1, y1 + (int) (16f * Rem),
  1012. // Color1, x1, y1 + (int) (16f * (Rem + Cut1.floatValue())), Color2);
  1013. // GradientPaint GradientPaint3 = new GradientPaint(x1, y1
  1014. // + (int) (16f * (Rem + Cut1.floatValue() + Cut2.floatValue())), Color2, x1,
  1015. // y1 + 16, Color3);
  1016. //
  1017. // G2.setPaint(GradientPaint1);
  1018. // G2.fillRect(x1 - 7, y1, 15, (int) (16f * Rem));
  1019. // G2.setPaint(GradientPaint2);
  1020. // G2.fillRect(x1 - 7, y1 + (int) (16f * Rem), 15,
  1021. // (int) (16f * Cut1.floatValue()) + 1);
  1022. // G2.setColor(Color2);
  1023. // G2.fillRect(x1 - 7, y1 + (int) (16f * (Rem + Cut1.floatValue())), 15,
  1024. // (int) (16f * Cut2.floatValue()) + 1);
  1025. // G2.setPaint(GradientPaint3);
  1026. // G2.fillRect(x1 - 7, y1
  1027. // + (int) (16f * (Rem + Cut1.floatValue() + Cut2.floatValue())), 15,
  1028. // (int) (16f * Cut1.floatValue()) + 1);
  1029. // }
  1030. // else
  1031. // {
  1032. // GradientPaint GradientPaint1 = new GradientPaint(x1 - 7, y1, Color3, x1, y1
  1033. // - (int) (16f * Rem), Color1);
  1034. // GradientPaint GradientPaint2 = new GradientPaint(x1, y1 - (int) (16f * Rem),
  1035. // Color1, x1, y1 - (int) (16f * (Rem + Cut1.floatValue())), Color2);
  1036. // GradientPaint GradientPaint3 = new GradientPaint(x1, y1
  1037. // - (int) (16f * (Rem + Cut1.floatValue() + Cut2.floatValue())), Color2, x1,
  1038. // y1 - 16, Color3);
  1039. //
  1040. // G2.setPaint(GradientPaint1);
  1041. // G2.fillRect(x1 - 7, y1 - (int) (16f * Rem), 15, (int) (16f * Rem));
  1042. // G2.setPaint(GradientPaint2);
  1043. // G2.fillRect(x1 - 7, y1 - (int) (16f * (Rem + Cut1.floatValue())), 15,
  1044. // (int) (16f * Cut1.floatValue()) + 1);
  1045. // G2.setColor(Color2);
  1046. // G2.fillRect(x1 - 7, y1
  1047. // - (int) (16f * (Rem + Cut1.floatValue() + Cut2.floatValue())), 15,
  1048. // (int) (16f * Cut2.floatValue()) + 1);
  1049. // G2.setPaint(GradientPaint3);
  1050. // G2.fillRect(x1 - 7, y1 - 16, 15, (int) (16f * Cut1.floatValue()) + 1);
  1051. // }
  1052. // G2.setClip(Shape0);
  1053. // }
  1054. //
  1055. // }
  1056. // else
  1057. // {
  1058. G2.setColor(new Color(MainColor_Arg.getRed(), MainColor_Arg.getGreen(),
  1059. MainColor_Arg.getBlue(), 196));
  1060. G2.fillPolygon(Thumb_Arg);
  1061. // }
  1062. G2.setColor(Color.BLACK);
  1063. G2.drawPolygon(Thumb_Arg);
  1064. int yy = up ? Thumb_Arg.ypoints[0] + 8 : Thumb_Arg.ypoints[6] - 13;
  1065. int xx = up ? Thumb_Arg.xpoints[0] : Thumb_Arg.xpoints[6];
  1066. int[] xp = { xx - 5, xx - 1, xx + 3, xx - 3, xx + 1, xx - 5, xx - 1, xx + 3 };
  1067. int[] yp = { yy, yy, yy, yy + 2, yy + 2, yy + 4, yy + 4, yy + 4 };
  1068. paintShadowedDots(G2, xp, yp, 8, DarkColor_Arg, BrightColor_Arg);
  1069. }// paintThumb()
  1070. /**
  1071. * Method called by the awt-swing mechanism when the user press the mouse
  1072. * button over this component
  1073. *
  1074. * @param MouseEvent_Arg
  1075. * the mouse event generatedby the awt-swing mechanism
  1076. */
  1077. public void mousePressed(MouseEvent MouseEvent_Arg)
  1078. {
  1079. LastFiveEvents = new Vector<Point>();
  1080. LastFiveEvents.add(MouseEvent_Arg.getPoint());
  1081. if (JTextFieldMin.isVisible())
  1082. {
  1083. JTextFieldMin.postActionEvent();
  1084. while (JTextFieldMin.getActionListeners().length > 0)
  1085. {
  1086. JTextFieldMin.removeActionListener(JTextFieldMin.getActionListeners()[0]);
  1087. }
  1088. JTextFieldMin.setVisible(false);
  1089. Ctrl.requestFocus();
  1090. }
  1091. if (JTextFieldMax.isVisible())
  1092. {
  1093. JTextFieldMax.postActionEvent();
  1094. while (JTextFieldMax.getActionListeners().length > 0)
  1095. {
  1096. JTextFieldMax.removeActionListener(JTextFieldMax.getActionListeners()[0]);
  1097. }
  1098. JTextFieldMax.setVisible(false);
  1099. Ctrl.requestFocus();
  1100. }
  1101. if (Ctrl.isPrecise() && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1102. && MouseEvent_Arg.getClickCount() > 1
  1103. && TheLeft_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY()))
  1104. {
  1105. openPrecisionPopup(LEFT_POLYGON, new Point(MouseEvent_Arg.getX(), MouseEvent_Arg
  1106. .getY()));
  1107. return;
  1108. }
  1109. else if (Ctrl.isPrecise() && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1110. && MouseEvent_Arg.getClickCount() > 1
  1111. && TheRight_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY()))
  1112. {
  1113. openPrecisionPopup(RIGHT_POLYGON, new Point(MouseEvent_Arg.getX(), MouseEvent_Arg
  1114. .getY()));
  1115. return;
  1116. } // Clic the first number to drag it and change the SegmentCount
  1117. else if (RectFirstLabel != null && MouseEvent_Arg.getClickCount() == 1
  1118. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1119. && RectFirstLabel.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1120. && MouseEvent_Arg.isShiftDown())
  1121. {
  1122. Dragging = SEGMENT_SIZE_INT;
  1123. }
  1124. else if (RectFirstLabel != null && MouseEvent_Arg.getClickCount() == 1
  1125. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1126. && RectFirstLabel.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1127. && !MouseEvent_Arg.isShiftDown())
  1128. {
  1129. Dragging = SEGMENT_SIZE;
  1130. } // The user want to modify the minimum by draging the left triangle
  1131. else if (TheLeft_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1132. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1133. && !MouseEvent_Arg.isAltDown() && !MouseEvent_Arg.isShiftDown())
  1134. {
  1135. Dragging = LEFT_RULER;
  1136. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1137. DeplAft = RightValue - MouseEvent_Arg.getX();
  1138. JComponent1.repaint();
  1139. }
  1140. else if (TheLeft_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1141. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1142. && !MouseEvent_Arg.isAltDown() && MouseEvent_Arg.isShiftDown())
  1143. {
  1144. Dragging = SHIFT_LEFT_RULER;
  1145. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1146. DeplAft = RightValue - MouseEvent_Arg.getX();
  1147. JComponent1.repaint();
  1148. } // the user want to modify the maximum by draging the left triangle
  1149. else if (TheRight_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1150. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1151. && !MouseEvent_Arg.isAltDown() && !MouseEvent_Arg.isShiftDown())
  1152. {
  1153. Dragging = RIGHT_RULER;
  1154. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1155. DeplAft = RightValue - MouseEvent_Arg.getX();
  1156. JComponent1.repaint();
  1157. } // the user want to modify the maximum by draging the left triangle
  1158. else if (TheRight_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1159. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1160. && !MouseEvent_Arg.isAltDown() && MouseEvent_Arg.isShiftDown())
  1161. {
  1162. Dragging = SHIFT_RIGHT_RULER;
  1163. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1164. DeplAft = RightValue - MouseEvent_Arg.getX();
  1165. JComponent1.repaint();
  1166. } // The user may want to drag the segment.
  1167. else if (MouseEvent_Arg.getX() > LeftValue
  1168. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1169. && MouseEvent_Arg.getX() < RightValue && MouseEvent_Arg.getY() > Margin_Ruler_Top
  1170. && MouseEvent_Arg.getY() < Margin_Ruler_Top + RulerHeight
  1171. && !MouseEvent_Arg.isAltDown() && !MouseEvent_Arg.isShiftDown())
  1172. {
  1173. Dragging = SEGMENT;
  1174. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1175. DeplAft = RightValue - MouseEvent_Arg.getX();
  1176. JComponent1.repaint();
  1177. } // The user may want to drag the segment (but stay aligned on graduations)
  1178. else if (MouseEvent_Arg.getX() > LeftValue
  1179. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1180. && MouseEvent_Arg.getX() < RightValue && MouseEvent_Arg.getY() > Margin_Ruler_Top
  1181. && MouseEvent_Arg.getY() < Margin_Ruler_Top + RulerHeight
  1182. && !MouseEvent_Arg.isAltDown() && MouseEvent_Arg.isShiftDown())
  1183. {
  1184. Dragging = SHIFT_SEGMENT;
  1185. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1186. DeplAft = RightValue - MouseEvent_Arg.getX();
  1187. JComponent1.repaint();
  1188. } // The user may want to drag the segment.
  1189. else if (TheRight_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1190. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1 && MouseEvent_Arg.isAltDown())
  1191. {
  1192. Dragging = ALT_RIGHT_RULER;
  1193. Center = (Ctrl.getMinimumColoredValue() + Ctrl.getMaximumColoredValue()) / 2;
  1194. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1195. DeplAft = RightValue - MouseEvent_Arg.getX();
  1196. JComponent1.repaint();
  1197. } // The user may want to drag the segment.
  1198. else if (TheLeft_Polygon.contains(MouseEvent_Arg.getX(), MouseEvent_Arg.getY())
  1199. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1 && MouseEvent_Arg.isAltDown())
  1200. {
  1201. Dragging = ALT_LEFT_RULER;
  1202. Center = (Ctrl.getMinimumColoredValue() + Ctrl.getMaximumColoredValue()) / 2;
  1203. DeplBef = MouseEvent_Arg.getX() - LeftValue;
  1204. DeplAft = RightValue - MouseEvent_Arg.getX();
  1205. JComponent1.repaint();
  1206. } // Double click in a new segment with SHIFT pressed for concatenation of
  1207. // the segment
  1208. else if (MouseEvent_Arg.isShiftDown()
  1209. && MouseEvent_Arg.getButton() == MouseEvent.BUTTON1
  1210. && MouseEvent_Arg.getClickCount() > 1
  1211. && MouseEvent_Arg.getX() > MARGIN_RULER_LEFT
  1212. && MouseEvent_Arg.getX() < MARGIN_RULER_LEFT + RulerWidth
  1213. && MouseEvent_Arg.getY() > Margin_Ruler_Top
  1214. && MouseEvent_Arg.getY() < Margin_Ruler_Top + RulerHeight)
  1215. {
  1216. int d1 = MouseEvent_Arg.getX() - MARGIN_RULER_LEFT;
  1217. int GraduationCount = (int) Math.floor(d1 / GraduationWidth);
  1218. double Min = Ctrl.getMinimumValue()
  1219. + (float) ((GraduationCount * GraduationWidth)
  1220. * (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()) / RulerWidth);
  1221. double Max = Ctrl.getMinimumValue()
  1222. + (float) (((GraduationCount + 1) * GraduationWidth)
  1223. * (Ctrl.getMaximumValue() - Ctrl.getMinimumValue()) / RulerWidth);
  1224. // because the last segment is maybe smaller than a regular one
  1225. if (Max > Ctrl.getMaximumValue())
  1226. {
  1227. Max = Ctrl.getMaximumValue