001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.component; 020 021import icy.gui.util.ComponentUtil; 022 023import javax.swing.BoundedRangeModel; 024import javax.swing.JSlider; 025 026/** 027 * @author Stephane 028 */ 029public class IcySlider extends JSlider 030{ 031 /** 032 * 033 */ 034 private static final long serialVersionUID = 3416400365856996824L; 035 036 private boolean smartTickMarkers; 037 038 /** 039 * 040 */ 041 public IcySlider() 042 { 043 super(); 044 045 smartTickMarkers = true; 046 } 047 048 /** 049 * @param brm 050 */ 051 public IcySlider(BoundedRangeModel brm) 052 { 053 super(brm); 054 055 smartTickMarkers = true; 056 } 057 058 /** 059 * @param orientation 060 * @param min 061 * @param max 062 * @param value 063 */ 064 public IcySlider(int orientation, int min, int max, int value) 065 { 066 super(orientation, min, max, value); 067 068 smartTickMarkers = true; 069 } 070 071 /** 072 * @param min 073 * @param max 074 * @param value 075 */ 076 public IcySlider(int min, int max, int value) 077 { 078 super(min, max, value); 079 080 smartTickMarkers = true; 081 } 082 083 /** 084 * @param min 085 * @param max 086 */ 087 public IcySlider(int min, int max) 088 { 089 super(min, max); 090 091 smartTickMarkers = true; 092 } 093 094 /** 095 * @param orientation 096 */ 097 public IcySlider(int orientation) 098 { 099 super(orientation); 100 101 smartTickMarkers = true; 102 } 103 104 /** 105 * @return the smartTickMarkers 106 */ 107 public boolean isSmartTickMarkers() 108 { 109 return smartTickMarkers; 110 } 111 112 /** 113 * @param value 114 * the smartTickMarkers to set 115 */ 116 public void setSmartTickMarkers(boolean value) 117 { 118 if (smartTickMarkers != value) 119 { 120 smartTickMarkers = value; 121 122 updateTicksAndLabels(); 123 } 124 } 125 126 private void updateTicksAndLabels() 127 { 128 if (smartTickMarkers && (getPaintTicks() || getPaintLabels())) 129 ComponentUtil.setTickMarkers(this); 130 } 131 132 @Override 133 public void setPaintLabels(boolean b) 134 { 135 super.setPaintLabels(b); 136 137 updateTicksAndLabels(); 138 } 139 140 @Override 141 public void setPaintTicks(boolean b) 142 { 143 super.setPaintTicks(b); 144 145 updateTicksAndLabels(); 146 } 147 148 @Override 149 protected void fireStateChanged() 150 { 151 super.fireStateChanged(); 152 153 updateTicksAndLabels(); 154 } 155}