1861 icon.paintIcon(c, graphics, |
1861 icon.paintIcon(c, graphics, |
1862 findCenteredX(x, icon.getIconWidth()), |
1862 findCenteredX(x, icon.getIconWidth()), |
1863 y - icon.getIconHeight() / 2); |
1863 y - icon.getIconHeight() / 2); |
1864 } |
1864 } |
1865 |
1865 |
1866 // This method is slow -- revisit when Java2D is ready. |
1866 /** |
1867 // assumes x1 <= x2 |
1867 * Draws a horizontal dashed line. It is assumed {@code x1} <= {@code x2}. |
1868 protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2){ |
1868 * If {@code x1} is greater than {@code x2}, the method draws nothing. |
|
1869 * |
|
1870 * @param g an instance of {@code Graphics} |
|
1871 * @param y an Y coordinate |
|
1872 * @param x1 an X1 coordinate |
|
1873 * @param x2 an X2 coordinate |
|
1874 */ |
|
1875 protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2) { |
1869 // Drawing only even coordinates helps join line segments so they |
1876 // Drawing only even coordinates helps join line segments so they |
1870 // appear as one line. This can be defeated by translating the |
1877 // appear as one line. This can be defeated by translating the |
1871 // Graphics by an odd amount. |
1878 // Graphics by an odd amount. |
1872 x1 += (x1 % 2); |
1879 drawDashedLine(g, y, x1, x2, false); |
1873 |
1880 } |
1874 for (int x = x1; x <= x2; x+=2) { |
1881 |
1875 g.drawLine(x, y, x, y); |
1882 /** |
1876 } |
1883 * Draws a vertical dashed line. It is assumed {@code y1} <= {@code y2}. |
1877 } |
1884 * If {@code y1} is greater than {@code y2}, the method draws nothing. |
1878 |
1885 * |
1879 // This method is slow -- revisit when Java2D is ready. |
1886 * @param g an instance of {@code Graphics} |
1880 // assumes y1 <= y2 |
1887 * @param x an X coordinate |
|
1888 * @param y1 an Y1 coordinate |
|
1889 * @param y2 an Y2 coordinate |
|
1890 */ |
1881 protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) { |
1891 protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) { |
1882 // Drawing only even coordinates helps join line segments so they |
1892 // Drawing only even coordinates helps join line segments so they |
1883 // appear as one line. This can be defeated by translating the |
1893 // appear as one line. This can be defeated by translating the |
1884 // Graphics by an odd amount. |
1894 // Graphics by an odd amount. |
1885 y1 += (y1 % 2); |
1895 drawDashedLine(g, x, y1, y2, true); |
1886 |
1896 } |
1887 for (int y = y1; y <= y2; y+=2) { |
1897 |
1888 g.drawLine(x, y, x, y); |
1898 private void drawDashedLine(Graphics g, int v, int v1, int v2, boolean isVertical) { |
1889 } |
1899 if (v1 >= v2) { |
1890 } |
1900 return; |
1891 |
1901 } |
|
1902 v1 += (v1 % 2); |
|
1903 Graphics2D g2d = (Graphics2D) g; |
|
1904 Stroke oldStroke = g2d.getStroke(); |
|
1905 |
|
1906 BasicStroke dashedStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, |
|
1907 BasicStroke.JOIN_ROUND, 0, new float[]{1}, 0); |
|
1908 g2d.setStroke(dashedStroke); |
|
1909 if (isVertical) { |
|
1910 g2d.drawLine(v, v1, v, v2); |
|
1911 } else { |
|
1912 g2d.drawLine(v1, v, v2, v); |
|
1913 } |
|
1914 |
|
1915 g2d.setStroke(oldStroke); |
|
1916 } |
1892 // |
1917 // |
1893 // Various local methods |
1918 // Various local methods |
1894 // |
1919 // |
1895 |
1920 |
1896 /** |
1921 /** |