下面列出了javax.swing.JSlider#VERTICAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Dimension getThumbSize()
{
boolean isPaintNoTrangle = isPaintNoTrangleThumb();
Dimension size = new Dimension();
if (slider.getOrientation() == JSlider.VERTICAL)
{
size.width = 17;//20;
size.height = isPaintNoTrangle?16:12;//14;
}
else
{
size.width = isPaintNoTrangle?16:12;//14;
size.height = 17;//20;
}
return size;
}
@Override
public void paintThumb( Graphics g ) {
g.setColor( FlatUIUtils.deriveColor( slider.isEnabled()
? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor))
: disabledForeground,
thumbColor ) );
if( isRoundThumb() )
g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height );
else {
double w = thumbRect.width;
double h = thumbRect.height;
double wh = w / 2;
Path2D thumb = FlatUIUtils.createPath( 0,0, w,0, w,(h - wh), wh,h, 0,(h - wh) );
Graphics2D g2 = (Graphics2D) g.create();
try {
g2.translate( thumbRect.x, thumbRect.y );
if( slider.getOrientation() == JSlider.VERTICAL ) {
if( slider.getComponentOrientation().isLeftToRight() ) {
g2.translate( 0, thumbRect.height );
g2.rotate( Math.toRadians( 270 ) );
} else {
g2.translate( thumbRect.width, 0 );
g2.rotate( Math.toRadians( 90 ) );
}
}
g2.fill( thumb );
} finally {
g2.dispose();
}
}
}
private Point getClickPoint(ComponentOperator oper, int direction, int orientation) {
int x, y;
boolean inverted = ((JSliderOperator) oper).getInverted();
int realDirection = ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
if (inverted) {
if (direction == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
realDirection = ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
} else if (direction == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
realDirection = ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
} else {
return null;
}
} else {
realDirection = direction;
}
if (orientation == JSlider.HORIZONTAL) {
if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
x = oper.getWidth() - 1;
} else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
x = 0;
} else {
return null;
}
y = oper.getHeight() / 2;
} else if (orientation == JSlider.VERTICAL) {
if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
y = 0;
} else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
y = oper.getHeight() - 1;
} else {
return null;
}
x = oper.getWidth() / 2;
} else {
return null;
}
return new Point(x, y);
}
public Dimension getPreferredSize(JComponent c) {
recalculateIfInsetsChanged();
Dimension d = new Dimension(contentDim);
if (slider.getOrientation() == JSlider.VERTICAL) {
d.height = 200;
} else {
d.width = 200;
}
return d;
}
public Dimension getMinimumSize(JComponent c) {
recalculateIfInsetsChanged();
Dimension d = new Dimension(contentDim);
if (slider.getOrientation() == JSlider.VERTICAL) {
d.height = thumbRect.height + insetCache.top + insetCache.bottom;
} else {
d.width = thumbRect.width + insetCache.left + insetCache.right;
}
return d;
}
protected Dimension getThumbSize() {
Dimension size = new Dimension();
if (slider.getOrientation() == JSlider.VERTICAL) {
size.width = thumbHeight;
size.height = thumbWidth;
} else {
size.width = thumbWidth;
size.height = thumbHeight;
}
return size;
}
/**
* Paints the background of the thumb of a slider.
*
* @param context SynthContext identifying the <code>JComponent</code>
* and <code>Region</code> to paint to
* @param g <code>Graphics</code> to paint to
* @param x X coordinate of the area to paint to
* @param y Y coordinate of the area to paint to
* @param w Width of the area to paint to
* @param h Height of the area to paint to
* @param orientation One of <code>JSlider.HORIZONTAL</code> or <code>
* JSlider.VERTICAL</code>
*/
public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) {
if (context.getComponent().getClientProperty("Slider.paintThumbArrowShape") == Boolean.TRUE) {
if (orientation == JSlider.HORIZONTAL) {
orientation = JSlider.VERTICAL;
} else {
orientation = JSlider.HORIZONTAL;
}
paintBackground(context, g, x, y, w, h, orientation);
} else {
paintBackground(context, g, x, y, w, h, orientation);
}
}
private JComponent createControlComponent(FloatControl control) {
int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL;
BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control);
JSlider slider = new JSlider(model);
slider.setOrientation(orientation);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setSize(10, 50);
return slider;
}
@Override
public void mousePressed(final MouseEvent EVENT) {
if (!slider.isEnabled()) {
return;
}
currentMouseX = EVENT.getX();
currentMouseY = EVENT.getY();
if (slider.isRequestFocusEnabled()) {
slider.requestFocus();
}
// Determine which thumb is pressed. If the upper thumb is
// selected (last one dragged), then check its position first;
// otherwise check the position of the lower thumb first.
boolean lowerPressed = false;
boolean upperPressed = false;
if (((RangeSlider) slider).isRangeSelectionEnabled()) {
if (upperThumbSelected) {
if (upperThumbRect.contains(currentMouseX, currentMouseY)) {
upperPressed = true;
} else if (thumbRect.contains(currentMouseX, currentMouseY)) {
lowerPressed = true;
}
} else {
if (thumbRect.contains(currentMouseX, currentMouseY)) {
lowerPressed = true;
} else if (upperThumbRect.contains(currentMouseX, currentMouseY)) {
upperPressed = true;
}
}
} else {
if (thumbRect.contains(currentMouseX, currentMouseY)) {
lowerPressed = true;
}
}
// Handle lower thumb pressed.
if (lowerPressed) {
switch (slider.getOrientation()) {
case JSlider.HORIZONTAL:
offset = currentMouseX - thumbRect.x;
break;
case JSlider.VERTICAL:
offset = currentMouseY - thumbRect.y;
break;
}
upperThumbSelected = false;
lowerDragging = true;
return;
}
lowerDragging = false;
// Handle upper thumb pressed.
if (upperPressed) {
switch (slider.getOrientation()) {
case JSlider.HORIZONTAL:
offset = currentMouseX - upperThumbRect.x;
break;
case JSlider.VERTICAL:
offset = currentMouseY - upperThumbRect.y;
break;
}
upperThumbSelected = true;
upperDragging = true;
return;
}
upperDragging = false;
// Following options only available if rangeSelectionEnabled
if (((RangeSlider) slider).isRangeSelectionEnabled()) {
// Handle range pressed
if (RANGE.contains(EVENT.getPoint())) {
rangeDragging = true;
formerExtent = slider.getExtent();
switch (slider.getOrientation()) {
case JSlider.HORIZONTAL:
offset = currentMouseX - (int) RANGE.getMinX() + thumbRect.width / 2;
break;
case JSlider.VERTICAL:
if (slider.getInverted()) {
offset = currentMouseY - (int) RANGE.getMinY() + thumbRect.height / 2;
} else {
offset = currentMouseY - (int) RANGE.getMaxY() + thumbRect.height / 2;
}
break;
}
}
}
}
private void moveLowerThumb(final int ADDITIONAL_OFFSET) {
int thumbMiddle = 0;
switch (slider.getOrientation()) {
case JSlider.HORIZONTAL:
int halfThumbWidth = thumbRect.width / 2;
int thumbLeft = currentMouseX - offset + ADDITIONAL_OFFSET;
int trackLeft = trackRect.x;
int trackRight = trackRect.x + (trackRect.width - 1);
int hMax;
if (((RangeSlider) slider).isRangeSelectionEnabled()) {
hMax = xPositionForValue(slider.getValue() + slider.getExtent());
} else {
hMax = xPositionForValue(slider.getMaximum());
}
// Apply bounds to thumb position.
if (drawInverted()) {
trackLeft = hMax;
} else {
trackRight = hMax;
}
thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
setThumbLocation(thumbLeft, thumbRect.y);
// Update slider value.
thumbMiddle = thumbLeft + halfThumbWidth;
slider.setValue(valueForXPosition(thumbMiddle));
break;
case JSlider.VERTICAL:
int halfThumbHeight = thumbRect.height / 2;
int thumbTop = currentMouseY - offset + ADDITIONAL_OFFSET;
int trackTop = trackRect.y;
int trackBottom = trackRect.y + (trackRect.height - 1);
int vMax;
if (((RangeSlider) slider).isRangeSelectionEnabled()) {
vMax = yPositionForValue(slider.getValue() + slider.getExtent());
} else {
vMax = yPositionForValue(slider.getMaximum());
}
// Apply bounds to thumb position.
if (drawInverted()) {
trackBottom = vMax;
} else {
trackTop = vMax;
}
thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
setThumbLocation(thumbRect.x, thumbTop);
// Update slider value.
thumbMiddle = thumbTop + halfThumbHeight;
slider.setValue(valueForYPosition(thumbMiddle));
break;
default:
return;
}
}
private void moveUpperThumb(final int ADDITIONAL_OFFSET) {
int thumbMiddle = 0;
switch (slider.getOrientation()) {
case JSlider.HORIZONTAL:
int halfThumbWidth = thumbRect.width / 2;
int thumbLeft = currentMouseX - offset + ADDITIONAL_OFFSET;
int trackLeft = trackRect.x;
int trackRight = trackRect.x + (trackRect.width - 1);
int hMin = xPositionForValue(slider.getValue());
// Apply bounds to thumb position.
if (drawInverted()) {
trackRight = hMin;
} else {
trackLeft = hMin;
}
thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
setUpperThumbLocation(thumbLeft, thumbRect.y);
// Update slider extent.
thumbMiddle = thumbLeft + halfThumbWidth;
slider.setExtent(valueForXPosition(thumbMiddle) - slider.getValue());
break;
case JSlider.VERTICAL:
int halfThumbHeight = thumbRect.height / 2;
int thumbTop = currentMouseY - offset + ADDITIONAL_OFFSET;
int trackTop = trackRect.y;
int trackBottom = trackRect.y + (trackRect.height - 1);
int vMin = yPositionForValue(slider.getValue());
// Apply bounds to thumb position.
if (drawInverted()) {
trackTop = vMin;
} else {
trackBottom = vMin;
}
thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
setUpperThumbLocation(thumbRect.x, thumbTop);
// Update slider extent.
thumbMiddle = thumbTop + halfThumbHeight;
slider.setExtent(valueForYPosition(thumbMiddle) - slider.getValue());
break;
default:
return;
}
}
public void init(){
this.trackSolo = new JCheckBox("Solo");
this.trackSolo.setFont( TGConfig.FONT_WIDGETS );
this.trackMute = new JCheckBox("Mute");
this.trackMute.setFont( TGConfig.FONT_WIDGETS );
this.trackBalance = new JSlider(JSlider.HORIZONTAL);
this.trackBalance.setMinimum(0);
this.trackBalance.setMaximum(127);
this.trackBalance.setExtent(1);
this.trackBalance.setPaintTicks(false);
this.trackBalance.setPaintLabels(false);
JPanel northPanel = new JPanel();
northPanel.setLayout(new GridBagLayout());
northPanel.add( this.trackSolo , getConstraints(0,0,1f,0f,GridBagConstraints.BOTH));
northPanel.add( this.trackMute , getConstraints(0,1,1f,0f,GridBagConstraints.BOTH));
northPanel.add( this.trackBalance , getConstraints(0,2,1f,0f,GridBagConstraints.BOTH));
this.trackVolume = new JSlider(JSlider.VERTICAL);
this.trackVolume.setMinimum(0);
this.trackVolume.setMaximum(127);
this.trackVolume.setExtent(1);
this.trackVolume.setPaintTicks(false);
this.trackVolume.setPaintLabels(false);
JPanel trackVolumePanel = new JPanel();
trackVolumePanel.setLayout(new BoxLayout(trackVolumePanel,BoxLayout.X_AXIS));
trackVolumePanel.add( Box.createHorizontalGlue());
trackVolumePanel.add( this.trackVolume );
trackVolumePanel.add( Box.createHorizontalGlue());
JLabel trackVolumeLabel = new JLabel("Volume:");
trackVolumeLabel.setFont( TGConfig.FONT_WIDGETS );
this.trackVolumeValue = new JLabel();
this.trackVolumeValue.setFont( TGConfig.FONT_WIDGETS );
this.trackVolumeValue.setBackground(Color.WHITE);
JPanel trackVolumeValuePanel = new JPanel();
trackVolumeValuePanel.setLayout(new GridBagLayout());
trackVolumeValuePanel.setBorder(BorderFactory.createEtchedBorder());
trackVolumeValuePanel.add(trackVolumeLabel, getConstraints(0,0,0f,0f,GridBagConstraints.BOTH,1,1,4));
trackVolumeValuePanel.add(this.trackVolumeValue , getConstraints(1,0,1f,0f,GridBagConstraints.BOTH,1,1,4));
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEtchedBorder());
this.setPreferredSize(new Dimension(100,300));
this.add(northPanel, BorderLayout.NORTH);
this.add(trackVolumePanel, BorderLayout.CENTER);
this.add(trackVolumeValuePanel, BorderLayout.SOUTH);
this.update();
}
public void mouseDragged(MouseEvent e) {
int thumbMiddle = 0;
if (!slider.isEnabled()) {
return;
}
currentMouseX = e.getX();
currentMouseY = e.getY();
if (!isDragging()) {
return;
}
slider.setValueIsAdjusting(true);
switch (slider.getOrientation()) {
case JSlider.VERTICAL:
int halfThumbHeight = thumbRect.height / 2;
int thumbTop = e.getY() - offset;
int trackTop = trackRect.y;
int trackBottom = trackRect.y + trackRect.height - halfThumbHeight - trackBorder;
int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent());
if (drawInverted()) {
trackBottom = vMax;
trackTop = trackTop + halfThumbHeight;
} else {
trackTop = vMax;
}
thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
setThumbLocation(thumbRect.x, thumbTop);
thumbMiddle = thumbTop + halfThumbHeight;
slider.setValue(valueForYPosition(thumbMiddle));
break;
case JSlider.HORIZONTAL:
int halfThumbWidth = thumbRect.width / 2;
int thumbLeft = e.getX() - offset;
int trackLeft = trackRect.x + halfThumbWidth + trackBorder;
int trackRight = trackRect.x + trackRect.width - halfThumbWidth - trackBorder;
int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent());
if (drawInverted()) {
trackLeft = hMax;
} else {
trackRight = hMax;
}
thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
setThumbLocation(thumbLeft, thumbRect.y);
thumbMiddle = thumbLeft + halfThumbWidth;
slider.setValue(valueForXPosition(thumbMiddle));
break;
default:
return;
}
if (slider.getValueIsAdjusting()) {
setThumbActive(true);
}
}
@SuppressWarnings("unchecked")
public DeobfuscationDialog() {
setDefaultCloseOperation(HIDE_ON_CLOSE);
setSize(new Dimension(330, 270));
setTitle(translate("dialog.title"));
Container cp = getContentPane();
cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
codeProcessingLevel = new JSlider(JSlider.VERTICAL, 1, 3, 3);
codeProcessingLevel.setMajorTickSpacing(1);
codeProcessingLevel.setPaintTicks(true);
codeProcessingLevel.setMinorTickSpacing(1);
codeProcessingLevel.setSnapToTicks(true);
JLabel lab1 = new JLabel(translate("deobfuscation.level"));
//lab1.setBounds(30, 0, getWidth() - 60, 25);
lab1.setAlignmentX(0.5f);
cp.add(lab1);
Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
//labelTable.put(LEVEL_NONE, new JLabel("None"));
labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_DEAD_CODE.getLevel(), new JLabel(translate("deobfuscation.removedeadcode")));
labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_TRAPS.getLevel(), new JLabel(translate("deobfuscation.removetraps")));
labelTable.put(DeobfuscationLevel.LEVEL_RESTORE_CONTROL_FLOW.getLevel(), new JLabel(translate("deobfuscation.restorecontrolflow")));
codeProcessingLevel.setLabelTable(labelTable);
codeProcessingLevel.setPaintLabels(true);
codeProcessingLevel.setAlignmentX(Component.CENTER_ALIGNMENT);
//codeProcessingLevel.setSize(300, 200);
//codeProcessingLevel.setBounds(30, 25, getWidth() - 60, 125);
codeProcessingLevel.setAlignmentX(0.5f);
add(codeProcessingLevel);
//processAllCheckbox.setBounds(50, 150, getWidth() - 100, 25);
processAllCheckbox.setAlignmentX(0.5f);
add(processAllCheckbox);
processAllCheckbox.setSelected(true);
JButton cancelButton = new JButton(translate("button.cancel"));
cancelButton.addActionListener(this::cancelButtonActionPerformed);
JButton okButton = new JButton(translate("button.ok"));
okButton.addActionListener(this::okButtonActionPerformed);
JPanel buttonsPanel = new JPanel(new FlowLayout());
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
buttonsPanel.setAlignmentX(0.5f);
cp.add(buttonsPanel);
setModal(true);
View.centerScreen(this);
setIconImage(View.loadImage("deobfuscate16"));
}