CustomTextbox in Blackberry - blackberry-eclipse-plugin

Hi friends basically i am a android developer. i am newbie in blackberry development. i need to create the custom text box with image button.
in the right corner of the text box, i want the small image button and it's click listener the text box field should be empty.
i Can create the Custom Text box and also draw bitmap inside the text box. but i can't catch the focus and listener to the image button. please help me
Please give some idea and samples.
I tried this...
MyApp.java Class:
import net.rim.device.api.ui.UiApplication;
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
MyScreen.java class:
public final class MyScreen extends MainScreen {
public MyScreen() {
super(Manager.NO_VERTICAL_SCROLL);
setTitle("MyTitle");
VerticalFieldManager vfm = new VerticalFieldManager(
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_HEIGHT);
HorizontalFieldManager hfm = new HorizontalFieldManager(
Manager.USE_ALL_WIDTH);
HorizontalFieldManager hfm1 = new HorizontalFieldManager(
Manager.USE_ALL_WIDTH);
customManager ctm = new customManager(Manager.USE_ALL_WIDTH);
customManager ctm1 = new customManager(Manager.USE_ALL_WIDTH);
hfm.add(ctm);
hfm1.add(ctm1);
vfm.add(hfm);
vfm.add(hfm1);
add(vfm);
}
}
customManager.java Class:
public class customManager extends Manager implements FieldChangeListener {
private Textbox txt;
private Closebtn cls;
Bitmap bitmap;
protected customManager(long style) {
super(style);
// My Coustem TextBOX
txt = new Textbox(300, 100);
// My Coustem Button
cls = new Closebtn();
cls.setChangeListener(this);
add(txt);
add(cls);
}
protected void sublayout(int width, int height) {
setPositionChild(getField(0), 10, 10);
layoutChild(getField(0), getField(0).getPreferredWidth(), getField(0)
.getPreferredHeight());
setPositionChild(getField(1),
getField(0).getWidth() - (getField(1).getWidth()), getField(0)
.getHeight() / 2 - getField(1).getHeight() / 2);
layoutChild(getField(1), getField(1).getWidth(), getField(1)
.getHeight());
setExtent(width, height);
}
public void fieldChanged(Field field, int context) {
txt.setText("");
}
}
Textbox.java Class:
public class Textbox extends Manager {
private int managerWidth;
private int managerHeight;
private int arcWidth;
private VerticalFieldManager vfm = new VerticalFieldManager(
NO_VERTICAL_SCROLL | USE_ALL_WIDTH );
private EditField editField;
private Bitmap bagBitmap;
Textbox(int width, int height, long style) {
super(style | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
managerWidth = width;
managerHeight = height;
long innerStyle = style & (READONLY | FOCUSABLE_MASK); // at least
if (innerStyle == 0) {
innerStyle = FOCUSABLE;
}
editField = new EditField("", "", 10, innerStyle);
arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE; // make it even
EncodedImage en = EncodedImage.getEncodedImageResource("_text.png");
bagBitmap = Util.getScaledBitmapImage(en, width, height);
add(vfm);
vfm.add(editField);
}
public void setFont(Font font) {
super.setFont(font);
editField.setFont(font);
arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE;
updateLayout();
}
Textbox(int width, int height) {
this(width, height, 0L);
}
public String getText() {
return editField.getText();
}
public void setText(String newText) {
editField.setText(newText);
}
public int getPreferredWidth() {
return managerWidth;
}
public int getPreferredHeight() {
return managerHeight;
}
protected void sublayout(int w, int h) {
if (managerWidth == 0) {
managerWidth = w;
}
if (managerHeight == 0) {
managerHeight = h;
}
int actWidth = Math.min(managerWidth, w);
int actHeight = Math.min(managerHeight, h);
layoutChild(vfm, actWidth - arcWidth, actHeight - arcWidth);
setPositionChild(vfm, arcWidth / 2, arcWidth / 2);
setExtent(actWidth, actHeight);
}
protected void paint(Graphics g) {
g.drawBitmap(0, 0, getWidth(), getHeight(), bagBitmap, 0, 0);
super.paint(g);
}
}
Closebtn.java Class:
public class Closebtn extends Field {
private Bitmap bitmap;
public Closebtn() {
super(Manager.FOCUSABLE);
EncodedImage en = EncodedImage.getEncodedImageResource("close.png");
bitmap = Util.getScaledBitmapImage(en, 50, 50);
}
protected void layout(int width, int height) {
setExtent(bitmap.getWidth(), bitmap.getHeight());
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
bitmap, 0, 0);
}
protected void onFocus(int direction) {
bitmap = bitmap;
}
protected void onUnfocus() {
bitmap = bitmap;
}
protected boolean keyChar(char character, int status, int time) {
if (character == Characters.ENTER) {
clickButton();
return true;
}
return super.keyChar(character, status, time);
}
protected boolean navigationClick(int status, int time) {
clickButton();
return true;
}
protected boolean trackwheelClick(int status, int time) {
clickButton();
return true;
}
protected boolean invokeAction(int action) {
switch (action) {
case ACTION_INVOKE: {
clickButton();
return true;
}
}
return super.invokeAction(action);
}
public void setDirty(boolean dirty) {
}
public void setMuddy(boolean muddy) {
}
public void clickButton() {
fieldChangeNotify(0);
}
}
Util.java Class:
public class Util {
public static Bitmap getScaledBitmapImage(EncodedImage image, int width,
int height) {
if (image == null) {
return null;
}
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32,
requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32,
requiredHeightFixed32);
image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return image.getBitmap();
}
}
My problem is i can't add more then one fields here Pls help me..

Try this custom class:
public class TextFieldWithClear extends HorizontalFieldManager {
protected HorizontalFieldManager hfmEditTextPanel;
protected LabelField lblEditText;
protected EditField textField;
protected MyImageButton bitmapFieldClear;
int mHeight;
int mWidth;
String mLabel;
public TextFieldWithClear(String label, int width, int height) {
super(FOCUSABLE);
Border border = BorderFactory
.createSimpleBorder(new XYEdges(2, 2, 2, 2));
this.setBorder(border);
Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
this.setBackground(bg);
mWidth = width;
mHeight = height;
mLabel = label;
lblEditText = new LabelField(mLabel) {
protected void paint(Graphics graphics) {
graphics.setColor(0x4B4B4B);
super.paint(graphics);
}
};
add(lblEditText);
hfmEditTextPanel = new HorizontalFieldManager(FOCUSABLE
| VERTICAL_SCROLL | VERTICAL_SCROLLBAR) {
protected void sublayout(int maxWidth, int maxHeight) {
maxWidth = mWidth - 30;
maxHeight = mHeight;
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight);
}
};
textField = new EditField() {
// protected void layout(int width, int height)
// {
// width = mWidth - 50;
// height=35;
// super.layout(width, height);
// //setExtent(width, height);
// }
};
hfmEditTextPanel.add(textField);
add(hfmEditTextPanel);
bitmapFieldClear = new MyImageButton(
Bitmap.getBitmapResource("btn_delete_normal.png"),
Bitmap.getBitmapResource("btn_delete_focused.png"));
bitmapFieldClear.setChangeListener(buttonListener);
add(bitmapFieldClear);
}
public String getText() {
String value = "";
if (textField.getText().length() > 0)
value = textField.getText();
return value;
}
public void setString(String value) {
if (value != null) {
textField.setText(value);
}
}
FieldChangeListener buttonListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
textField.clear(0);
textField.setFocus();
}
};
public void onUndisplay()
{
textField.setEditable(false);
}
public void onDisplay()
{
textField.setEditable(true);
}
}

This is not easy to do just overriding EditField, so this is what I'd try:
Use an horizontal manager (for instance, HorizontalFieldManager or other custom manager, perhaps with fixed column widths. This manager would have two fields inside: at left an EditField, at right a custom buttonfield.
Set a Background to the manager. The bg would draw the green background as well as the blue border. You can use an scaled bitmap (have a look at BackgroundFactory.createBitmapBackground).
Create a new EditField subclass, and override its paintBackground method so that it does nothing. If it does not work, try overriding paint so that it does only draw the text. This is the trickiest part.
Create a custom Buttonfield subclass with the cross over gray circle image. You can read a good tutorial on how to do that here. You also have available an already made BitmapButtonField in the Advanced Ui Library. When the button is clicked, it would invoke EditField.setText("") on the EditField.

Related

Admob Native Ads after every 5 item display in recycler view android?

I am facing the issue with my Recycler view while placing Admob ads after every 5 items. First ads display after 5 items but when swept up/down the ads display random positions. What should I change to display ads after every 5 items?
AdapterFile:
public class TQuoteAdapter extends RecyclerView.Adapter<TQuoteAdapter.ImageHolder> {
private int ad_count = 0;
List<QuotesModel> quotesList;
Context context;
int width;
DBHelper_dbfile dbHelper;
int[] grid_colors;
int c = 0;
public TQuoteAdapter(List<QuotesModel> quotesList, Context context) {
this.quotesList = quotesList;
this.context = context;
dbHelper = new DBHelper_dbfile(context);
try {
dbHelper.openDatabase();
} catch (SQLException sqle) {
throw sqle;
}
DisplayMetrics displayMetrics = context.getResources()
.getDisplayMetrics();
width = displayMetrics.widthPixels;
grid_colors = context.getResources().getIntArray(R.array.grid_colors);
}
public static class ImageHolder extends RecyclerView.ViewHolder {
private NativeAdView nativeAdView;
ImageView favIV;
TextView quoteTV;
LinearLayout share, copy, wapp,fbapp,instaapp;
CardView cardView;
public ImageHolder(#NonNull View itemView) {
super(itemView);
nativeAdView = itemView.findViewById(R.id.native_ad_view);
quoteTV = itemView.findViewById(R.id.quoteTV);
favIV = itemView.findViewById(R.id.favIV);
share = itemView.findViewById(R.id.share);
copy = itemView.findViewById(R.id.copy);
wapp = itemView.findViewById(R.id.wapp);
fbapp = itemView.findViewById(R.id.fbapp);
instaapp = itemView.findViewById(R.id.instaapp);
cardView = itemView.findViewById(R.id.cardView);
}
}
#NonNull
#Override
public ImageHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_tquote, parent, false);
return new ImageHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull ImageHolder holder, int position) {
if(ad_count == 5){
AdLoader adLoader = new AdLoader.Builder(context,context.getString(R.string.native_unit_id))
.forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
#Override
public void onNativeAdLoaded(#NonNull NativeAd nativeAd) {
populateNativeAdView(nativeAd,holder.nativeAdView);
if (onDestroy()) {
nativeAd.destroy();
}
}
})
.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(LoadAdError adError) {
// Handle the failure by logging, altering the UI, and so on.
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build())
.build();
adLoader.loadAd(new AdRequest.Builder().build());
ad_count = 0;
}else {
holder.quoteTV.setText(quotesList.get(position).getQuotes());
ad_count ++;
}
setAnimation(holder.itemView);
if (quotesList.get(position).getFavourite().equals("no")) {
holder.favIV.setImageResource(R.drawable.unpress_download);
} else {
holder.favIV.setImageResource(R.drawable.press_download);
}
holder.favIV.setOnClickListener(v -> {
if (Utills.hasPermissions(context, Utills.permissions)) {
ActivityCompat.requestPermissions((Activity) context, Utills.permissions, Utills.perRequest);
} else {
if (quotesList.get(position).getFavourite().equals("no")) {
dbHelper.addToFavourite("yes", quotesList.get(position).getId());
quotesList.get(position).setFavourite("yes");
} else {
dbHelper.addToFavourite("no", quotesList.get(position).getId());
quotesList.get(position).setFavourite("no");
}
notifyDataSetChanged();
}
});
int color = grid_colors[c];
c++;
if (c == grid_colors.length) {
c = 0;
}
holder.cardView.setCardBackgroundColor(color);
}
private void setAnimation(View view){
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
view.setAnimation(animation);
}
protected boolean onDestroy() {
AdManager.destroyFbAd();
return false;
}
#Override
public int getItemCount() {
return quotesList.size();
}
private void populateNativeAdView(NativeAd nativeAd, NativeAdView nativeAdView) {
nativeAdView.setMediaView((MediaView) nativeAdView.findViewById(R.id.media_view));
nativeAdView.setCallToActionView(nativeAdView.findViewById(R.id.cta));
nativeAdView.setHeadlineView(nativeAdView.findViewById(R.id.primary));
nativeAdView.setAdvertiserView(nativeAdView.findViewById(R.id.secondary));
nativeAdView.setStarRatingView(nativeAdView.findViewById(R.id.rating_bar));
nativeAdView.setBodyView(nativeAdView.findViewById(R.id.body));
nativeAdView.setIconView(nativeAdView.findViewById(R.id.icon));
View headlineView = nativeAdView.getHeadlineView();
Objects.requireNonNull(headlineView);
((AppCompatTextView) headlineView).setText(nativeAd.getHeadline());
View bodyView = nativeAdView.getBodyView();
Objects.requireNonNull(bodyView);
((AppCompatTextView) bodyView).setText(nativeAd.getBody());
View callToActionView = nativeAdView.getCallToActionView();
Objects.requireNonNull(callToActionView);
((AppCompatButton) callToActionView).setText(nativeAd.getCallToAction());
MediaView mediaView = nativeAdView.getMediaView();
Objects.requireNonNull(mediaView);
MediaContent mediaContent = nativeAd.getMediaContent();
Objects.requireNonNull(mediaContent);
mediaView.setMediaContent(mediaContent);
if (nativeAd.getIcon() == null) {
View iconView = nativeAdView.getIconView();
Objects.requireNonNull(iconView);
iconView.setVisibility(View.INVISIBLE);
} else {
View iconView2 = nativeAdView.getIconView();
Objects.requireNonNull(iconView2);
((AppCompatImageView) iconView2).setImageDrawable(nativeAd.getIcon().getDrawable());
nativeAdView.getIconView().setVisibility(View.VISIBLE);
}
if (nativeAd.getStarRating() == null) {
View starRatingView = nativeAdView.getStarRatingView();
Objects.requireNonNull(starRatingView);
starRatingView.setVisibility(View.INVISIBLE);
} else {
View starRatingView2 = nativeAdView.getStarRatingView();
Objects.requireNonNull(starRatingView2);
((RatingBar) starRatingView2).setRating(nativeAd.getStarRating().floatValue());
nativeAdView.getStarRatingView().setVisibility(View.VISIBLE);
}
if (nativeAd.getAdvertiser() == null) {
View advertiserView = nativeAdView.getAdvertiserView();
Objects.requireNonNull(advertiserView);
advertiserView.setVisibility(View.INVISIBLE);
} else {
View advertiserView2 = nativeAdView.getAdvertiserView();
Objects.requireNonNull(advertiserView2);
((AppCompatTextView) advertiserView2).setText(nativeAd.getAdvertiser());
nativeAdView.getAdvertiserView().setVisibility(View.VISIBLE);
}
nativeAdView.setNativeAd(nativeAd);
nativeAdView.setVisibility(View.VISIBLE);
}

HLS not working in exoplayer in the following code

What changes do I need to make to the following code to get an m3u8 link to play?
I'm able to get regular MP4 videos to work, but not HLS. What would I need to do to make HLS links to work?
I would like to implement something like this, that allows for playback of different media sources. https://gist.github.com/navi25/7ab41931eb52bbcb693b5599e6955245#file-mediasourcebuilder-kt
public class VideoPlayerRecyclerView extends RecyclerView {
private static final String TAG = "VideoPlayerRecyclerView";
private enum VolumeState {ON, OFF};
// ui
private ImageView thumbnail, volumeControl;
private ProgressBar progressBar;
private View viewHolderParent;
private FrameLayout frameLayout;
private PlayerView videoSurfaceView;
private SimpleExoPlayer videoPlayer;
// vars
private ArrayList<MediaObject> mediaObjects = new ArrayList<>();
private int videoSurfaceDefaultHeight = 0;
private int screenDefaultHeight = 0;
private Context context;
private int playPosition = -1;
private boolean isVideoViewAdded;
private RequestManager requestManager;
// controlling playback state
private VolumeState volumeState;
public VideoPlayerRecyclerView(#NonNull Context context) {
super(context);
init(context);
}
public VideoPlayerRecyclerView(#NonNull Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context){
this.context = context.getApplicationContext();
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point point = new Point();
display.getSize(point);
videoSurfaceDefaultHeight = point.x;
screenDefaultHeight = point.y;
videoSurfaceView = new PlayerView(this.context);
videoSurfaceView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Create the player
videoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
// Bind the player to the view.
videoSurfaceView.setUseController(false);
videoSurfaceView.setPlayer(videoPlayer);
setVolumeControl(VolumeState.ON);
addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Log.d(TAG, "onScrollStateChanged: called.");
if(thumbnail != null){ // show the old thumbnail
thumbnail.setVisibility(VISIBLE);
}
// There's a special case when the end of the list has been reached.
// Need to handle that with this bit of logic
if(!recyclerView.canScrollVertically(1)){
playVideo(true);
}
else{
playVideo(false);
}
}
}
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
addOnChildAttachStateChangeListener(new OnChildAttachStateChangeListener() {
#Override
public void onChildViewAttachedToWindow(View view) {
}
#Override
public void onChildViewDetachedFromWindow(View view) {
if (viewHolderParent != null && viewHolderParent.equals(view)) {
resetVideoView();
}
}
});
videoPlayer.addListener(new Player.EventListener() {
#Override
public void onTimelineChanged(Timeline timeline, #Nullable Object manifest, int reason) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
case Player.STATE_BUFFERING:
Log.e(TAG, "onPlayerStateChanged: Buffering video.");
if (progressBar != null) {
progressBar.setVisibility(VISIBLE);
}
break;
case Player.STATE_ENDED:
Log.d(TAG, "onPlayerStateChanged: Video ended.");
videoPlayer.seekTo(0);
break;
case Player.STATE_IDLE:
break;
case Player.STATE_READY:
Log.e(TAG, "onPlayerStateChanged: Ready to play.");
if (progressBar != null) {
progressBar.setVisibility(GONE);
}
if(!isVideoViewAdded){
addVideoView();
}
break;
default:
break;
}
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity(int reason) {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
#Override
public void onSeekProcessed() {
}
});
}
public void playVideo(boolean isEndOfList) {
int targetPosition;
if(!isEndOfList){
int startPosition = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
int endPosition = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
// if there is more than 2 list-items on the screen, set the difference to be 1
if (endPosition - startPosition > 1) {
endPosition = startPosition + 1;
}
// something is wrong. return.
if (startPosition < 0 || endPosition < 0) {
return;
}
// if there is more than 1 list-item on the screen
if (startPosition != endPosition) {
int startPositionVideoHeight = getVisibleVideoSurfaceHeight(startPosition);
int endPositionVideoHeight = getVisibleVideoSurfaceHeight(endPosition);
targetPosition = startPositionVideoHeight > endPositionVideoHeight ? startPosition : endPosition;
}
else {
targetPosition = startPosition;
}
}
else{
targetPosition = mediaObjects.size() - 1;
}
Log.d(TAG, "playVideo: target position: " + targetPosition);
// video is already playing so return
if (targetPosition == playPosition) {
return;
}
// set the position of the list-item that is to be played
playPosition = targetPosition;
if (videoSurfaceView == null) {
return;
}
// remove any old surface views from previously playing videos
videoSurfaceView.setVisibility(INVISIBLE);
removeVideoView(videoSurfaceView);
int currentPosition = targetPosition - ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
View child = getChildAt(currentPosition);
if (child == null) {
return;
}
VideoPlayerViewHolder holder = (VideoPlayerViewHolder) child.getTag();
if (holder == null) {
playPosition = -1;
return;
}
thumbnail = holder.thumbnail;
progressBar = holder.progressBar;
volumeControl = holder.volumeControl;
viewHolderParent = holder.itemView;
requestManager = holder.requestManager;
frameLayout = holder.itemView.findViewById(R.id.media_container);
videoSurfaceView.setPlayer(videoPlayer);
viewHolderParent.setOnClickListener(videoViewClickListener);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
context, Util.getUserAgent(context, "RecyclerView VideoPlayer"));
String mediaUrl = mediaObjects.get(targetPosition).getMedia_url();
if (mediaUrl != null) {
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(mediaUrl));
videoPlayer.prepare(videoSource);
videoPlayer.setPlayWhenReady(true);
}
}
private OnClickListener videoViewClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
toggleVolume();
}
};
/**
* Returns the visible region of the video surface on the screen.
* if some is cut off, it will return less than the #videoSurfaceDefaultHeight
* #param playPosition
* #return
*/
private int getVisibleVideoSurfaceHeight(int playPosition) {
int at = playPosition - ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
Log.d(TAG, "getVisibleVideoSurfaceHeight: at: " + at);
View child = getChildAt(at);
if (child == null) {
return 0;
}
int[] location = new int[2];
child.getLocationInWindow(location);
if (location[1] < 0) {
return location[1] + videoSurfaceDefaultHeight;
} else {
return screenDefaultHeight - location[1];
}
}
// Remove the old player
private void removeVideoView(PlayerView videoView) {
ViewGroup parent = (ViewGroup) videoView.getParent();
if (parent == null) {
return;
}
int index = parent.indexOfChild(videoView);
if (index >= 0) {
parent.removeViewAt(index);
isVideoViewAdded = false;
viewHolderParent.setOnClickListener(null);
}
}
private void addVideoView(){
frameLayout.addView(videoSurfaceView);
isVideoViewAdded = true;
videoSurfaceView.requestFocus();
videoSurfaceView.setVisibility(VISIBLE);
videoSurfaceView.setAlpha(1);
thumbnail.setVisibility(GONE);
}
private void resetVideoView(){
if(isVideoViewAdded){
removeVideoView(videoSurfaceView);
playPosition = -1;
videoSurfaceView.setVisibility(INVISIBLE);
thumbnail.setVisibility(VISIBLE);
}
}
public void releasePlayer() {
if (videoPlayer != null) {
videoPlayer.release();
videoPlayer = null;
}
viewHolderParent = null;
}
private void toggleVolume() {
if (videoPlayer != null) {
if (volumeState == VolumeState.OFF) {
Log.d(TAG, "togglePlaybackState: enabling volume.");
setVolumeControl(VolumeState.ON);
} else if(volumeState == VolumeState.ON) {
Log.d(TAG, "togglePlaybackState: disabling volume.");
setVolumeControl(VolumeState.OFF);
}
}
}
private void setVolumeControl(VolumeState state){
volumeState = state;
if(state == VolumeState.OFF){
videoPlayer.setVolume(0f);
animateVolumeControl();
}
else if(state == VolumeState.ON){
videoPlayer.setVolume(1f);
animateVolumeControl();
}
}
private void animateVolumeControl(){
if(volumeControl != null){
volumeControl.bringToFront();
if(volumeState == VolumeState.OFF){
requestManager.load(R.drawable.ic_volume_off_grey_24dp)
.into(volumeControl);
}
else if(volumeState == VolumeState.ON){
requestManager.load(R.drawable.ic_volume_up_grey_24dp)
.into(volumeControl);
}
volumeControl.animate().cancel();
volumeControl.setAlpha(1f);
volumeControl.animate()
.alpha(0f)
.setDuration(600).setStartDelay(1000);
}
}
public void setMediaObjects(ArrayList<MediaObject> mediaObjects){
this.mediaObjects = mediaObjects;
}
}
You need to use HlsMediaSource instead of the default MediaSource for HLS.
Media sources

JavaFX typewriter effect for label

i have some problem with this method. it works fine, but with one little problem. there is too little time among i call this method. so only the last String is printed on a label. but i want that the next String starting printed, only after previous String is finished.
Sorry for my English((
public void some(final String s) {
final Animation animation = new Transition() {
{
setCycleDuration(Duration.millis(2000));
}
protected void interpolate(double frac) {
final int length = s.length();
final int n = Math.round(length * (float) frac);
javafx.application.Platform.runLater(new Runnable() {
#Override
public void run() {
status.setValue(s.substring(0, n));
}
}
);
}
};
animation.play();
}
Use the following code to get a typewriting effect.
public void AnimateText(Label lbl, String descImp) {
String content = descImp;
final Animation animation = new Transition() {
{
setCycleDuration(Duration.millis(2000));
}
protected void interpolate(double frac) {
final int length = content.length();
final int n = Math.round(length * (float) frac);
lbl.setText(content.substring(0, n));
}
};
animation.play();
}
I don't know if it is an effect that you are trying to achieve, but I have created (ugly) demo how you can do this with TimeLine
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
IntegerProperty letters= new SimpleIntegerProperty(0);
Label label = new Label();
Button animate = new Button("animate");
letters.addListener((a, b, c) -> {
label.setText("animate".substring(0, c.intValue()));
});
animate.setOnAction((e)->{
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(letters, "animate".length());
KeyFrame kf = new KeyFrame(Duration.seconds(3), kv);
timeline.getKeyFrames().add(kf);
timeline.play();
});
BorderPane pane = new BorderPane(label, null, null, animate, null);
primaryStage.setScene(new Scene(pane, 300,300));
primaryStage.show();
}
}

Java Painting issues

I need help with a "paint" program. I've got the GUI established, but I'm having issues with the actual drawing portion of the program. Everything I draw disappears immediately after I draw it, and I can't figure out why.
Here is what I have so far:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JPaint extends JFrame implements ActionListener, MouseListener, MouseMotionListener {
int x, y, x2, y2;
private int select = 0;
private Graphics g;
private PaintPanel DrawPanel = new PaintPanel(this);
private JPanel ButtonPanel = new JPanel();
private JTextArea Draw = new JTextArea(20,20);
private JButton jbtRed = new JButton("Red");
private JButton jbtGreen = new JButton("Green");
private JButton jbtBlue = new JButton("Blue");
private JButton jbtErase = new JButton("Eraser");
private JButton jbtClear = new JButton("Clear");
PaintPanel l=new PaintPanel(this);
public JPaint(){
super("Java Paint");
setSize(480,320);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//build draw panel
DrawPanel.setBackground(Color.WHITE);
add(DrawPanel, BorderLayout.CENTER);
DrawPanel.setVisible(true);
//build button panel
ButtonPanel.add(jbtRed);
ButtonPanel.add(jbtGreen);
ButtonPanel.add(jbtBlue);
ButtonPanel.add(jbtErase);
ButtonPanel.add(jbtClear);
add(ButtonPanel, BorderLayout.SOUTH);
ButtonPanel.setVisible(true);
jbtRed.addActionListener(this);
jbtGreen.addActionListener(this);
jbtBlue.addActionListener(this);
jbtErase.addActionListener(this);
jbtClear.addActionListener(this);
DrawPanel.addMouseMotionListener(this);
DrawPanel.addMouseListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jbtRed){
DrawPanel.setToolTipText("Color set to 'Red'");
select = 1;
}
if(e.getSource() == jbtGreen){
DrawPanel.setToolTipText("Color set to 'Green'");
}
if(e.getSource() == jbtBlue){
DrawPanel.setToolTipText("Color set to 'Blue'");
}
if(e.getSource() == jbtErase){
DrawPanel.setToolTipText("Erase Selected");
}
if(e.getSource() == jbtClear){
DrawPanel.setToolTipText("Drawing cleared");
}
}
#Override
public void mouseDragged(MouseEvent e) {
x = e.getX();
y = e.getY();
DrawPanel.repaint();
}
#Override
public void mouseMoved(MouseEvent e) {
}
#Override
public void mouseClicked(MouseEvent e) {
}
#Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
}
#Override
public void mouseReleased(MouseEvent e) {
x2 = e.getX();
y2 = e.getY();
DrawPanel.repaint();
}
}
class PaintPanel extends JPanel
{
JPaint p;
PaintPanel(JPaint in){
p=in;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// clear the screen
g.setColor(Color.white);
g.setColor(Color.RED);
g.drawLine(p.x, p.y, p.x2, p.y2);
p.x2 = p.x;
p.y2 = p.y;
}
}
class Run_JPaint {
public static void main(String[] args){
JPaint P = new JPaint();
P.setVisible(true);
}
}
You would probably want to remove the following line of code:
super.paintComponent(g);
from inside your PaintPanel class. Otherwise with each draw command your GUI resets the screen.
Good Luck!

Why is my magnifying glass not following the mouse?

Im trying to migrate the JavaFX 1.3 Magnifying Glass example to JavaFX 2.0 at http://docs.oracle.com/javafx/1.3/tutorials/FXImage/ , but i've come across a problem.
I might have become blind, but i really cant figure out, why the glassgroup doesn't follow the mouse.
Here's the code:
package javafxapplication18;
import javafx.application.Application;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class JavaFXApplication18 extends Application {
private ImageView bgImageView = new ImageView();
private Image image;
private Scene scene;
private DoubleProperty magnification = new SimpleDoubleProperty();
private DoubleProperty GLASS_SIZE = new SimpleDoubleProperty();
private DoubleProperty GLASS_CENTER = new SimpleDoubleProperty();
private DoubleProperty centerX = new SimpleDoubleProperty();
private DoubleProperty centerY = new SimpleDoubleProperty();
private DoubleProperty factor = new SimpleDoubleProperty();
private DoubleProperty viewportCenterX = new SimpleDoubleProperty();
private DoubleProperty viewportCenterY = new SimpleDoubleProperty();
private DoubleProperty viewportSize = new SimpleDoubleProperty();
private ImageView magGlass = new ImageView();
private Group glassGroup = new Group();
private Text desc = new Text();
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
DoubleBinding db = new DoubleBinding() {
{
super.bind(centerX, factor);
}
#Override
protected double computeValue() {
return centerX.get() * factor.get();
}
};
DoubleBinding db2 = new DoubleBinding() {
{
super.bind(centerY, factor);
}
#Override
protected double computeValue() {
return centerY.get() * factor.get();
}
};
viewportCenterX.bind(db);
viewportCenterY.bind(db2);
image = new Image(this.getClass().getResourceAsStream("/SANY0194.jpg"));
StackPane root = new StackPane();
scene = new Scene(root, 900, 700);
setupBgImageView();
setupFactor();
setupGLASS_SIZE();
magnification.setValue(1.5);
DoubleBinding db3 = new DoubleBinding() {
{
super.bind(GLASS_SIZE, factor, magnification);
}
#Override
protected double computeValue() {
return GLASS_SIZE.get() * factor.get() / magnification.get();
}
};
viewportSize.bind(db3);
setupMagGlass();
setupGlassGroup();
setupDesc();
bgImageView.requestFocus();
primaryStage.setTitle("Magnifying Glass");
primaryStage.setWidth(image.getWidth() / 2);
primaryStage.setHeight(image.getHeight() / 2);
root.getChildren().addAll(bgImageView, glassGroup, desc);
primaryStage.setScene(scene);
primaryStage.show();
//style: StageStyle.UNDECORATED
}
public void adjustMagnification(final double amount) {
DoubleProperty newMagnification = new SimpleDoubleProperty();
DoubleBinding db3 = new DoubleBinding() {
{
super.bind(magnification);
}
#Override
protected double computeValue() {
if (magnification.get() + amount / 4 < .5) {
return .5;
} else if (magnification.get() + amount / 4 > 10) {
return 10;
} else {
return magnification.get() + amount / 4;
}
}
};
newMagnification.bind(db3);
magnification.setValue(newMagnification.getValue());
}
private void setupGLASS_SIZE() {
DoubleBinding db = new DoubleBinding() {
{
super.bind(bgImageView.boundsInLocalProperty());
}
#Override
protected double computeValue() {
return bgImageView.boundsInLocalProperty().get().getWidth() / 4;
}
};
GLASS_SIZE.bind(db);
DoubleBinding db1 = new DoubleBinding() {
{
super.bind(GLASS_SIZE);
}
#Override
protected double computeValue() {
return GLASS_SIZE.get() / 2;
}
};
GLASS_CENTER.bind(db1);
}
private void setupFactor() {
DoubleBinding db = new DoubleBinding() {
{
super.bind(image.heightProperty(), bgImageView.boundsInLocalProperty());
}
#Override
protected double computeValue() {
return image.heightProperty().get() / bgImageView.boundsInLocalProperty().get().getHeight();
}
};
factor.bind(db);
}
private void setupBgImageView() {
bgImageView.setImage(image);
bgImageView.fitWidthProperty().bind(scene.widthProperty());
bgImageView.fitHeightProperty().bind(scene.heightProperty());
BooleanBinding bb = new BooleanBinding() {
{
super.bind(factor);
}
#Override
protected boolean computeValue() {
if (factor.get() != 1.0) {
return true;
} else {
return false;
}
}
};
bgImageView.cacheProperty().bind(bb);
bgImageView.setSmooth(true);
bgImageView.setPreserveRatio(true);
bgImageView.setOnMouseMoved(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
centerX.setValue(me.getX());
centerY.setValue(me.getY());
}
});
bgImageView.setOnKeyPressed(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.EQUALS || ke.getCode() == KeyCode.PLUS) {
adjustMagnification(1.0);
} else if (ke.getCode() == KeyCode.MINUS) {
adjustMagnification(-1.0);
}
}
});
bgImageView.impl_setOnMouseWheelRotated(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
adjustMagnification(me.impl_getWheelRotation());
}
});
bgImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
if (me.getButton() != MouseButton.PRIMARY) {
magGlass.setSmooth(magGlass.isSmooth());
}
bgImageView.requestFocus();
}
});
}
private void setupMagGlass() {
magGlass.setImage(image);
magGlass.setPreserveRatio(true);
magGlass.fitWidthProperty().bind(GLASS_SIZE);
magGlass.fitHeightProperty().bind(GLASS_SIZE);
magGlass.setSmooth(true);
ObjectBinding ob = new ObjectBinding() {
{
super.bind(viewportCenterX, viewportSize, viewportCenterY);
}
#Override
protected Object computeValue() {
return new Rectangle2D(viewportCenterX.get() - viewportSize.get() / 2, (viewportCenterY.get() - viewportSize.get() / 2), viewportSize.get(), viewportSize.get());
}
};
magGlass.viewportProperty().bind(ob);
Circle clip = new Circle();
clip.centerXProperty().bind(GLASS_CENTER);
clip.centerYProperty().bind(GLASS_CENTER);
DoubleBinding db1 = new DoubleBinding() {
{
super.bind(GLASS_CENTER);
}
#Override
protected double computeValue() {
return GLASS_CENTER.get() - 5;
}
};
clip.radiusProperty().bind(db1);
magGlass.setClip(clip);
}
private void setupGlassGroup() {
DoubleBinding db = new DoubleBinding() {
{
super.bind(centerX, GLASS_CENTER);
}
#Override
protected double computeValue() {
return centerX.get() - GLASS_CENTER.get();
}
};
DoubleBinding db2 = new DoubleBinding() {
{
super.bind(centerY, GLASS_CENTER);
}
#Override
protected double computeValue() {
return centerY.get() - GLASS_CENTER.get();
}
};
System.out.println("glassGroup.getLayoutX() " + glassGroup.getLayoutX());
System.out.println("glassGroup.getLayoutY() " + glassGroup.getLayoutY());
glassGroup.translateXProperty().bind(db);
glassGroup.translateYProperty().bind(db2);
Text text = new Text();
DoubleBinding db3 = new DoubleBinding() {
{
super.bind(GLASS_CENTER);
}
#Override
protected double computeValue() {
return GLASS_CENTER.get() + GLASS_CENTER.get() / 2;
}
};
text.xProperty().bind(db3);
text.yProperty().bind(GLASS_SIZE);
text.setText("x{%2.2f magnification}");
Circle circle = new Circle();
circle.centerXProperty().bind(GLASS_CENTER);
circle.centerYProperty().bind(GLASS_CENTER);
DoubleBinding db4 = new DoubleBinding() {
{
super.bind(GLASS_CENTER);
}
#Override
protected double computeValue() {
return GLASS_CENTER.get() - 2;
}
};
circle.radiusProperty().bind(db4);
circle.setStroke(Color.GREEN);
circle.setStrokeWidth(3);
circle.setFill(null);
glassGroup.getChildren().addAll(magGlass, text, circle);
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetY(4);
glassGroup.setEffect(dropShadow);
}
private void setupDesc() {
desc.setX(10);
desc.setY(15);
if (!bgImageView.isFocused()) {
desc.setText("Click image to focus");
} else {
desc.setText("Use the +/- or mouse wheel to zoom. Right-click to make the magnification "
+ "{if (magGlass.smooth) less smooth. else more smooth.}");
}
desc.setFont(new Font(12));
}
}
any help will be appreciated :-)
1. You may want to upgrade to JavaFX 2.1 (developers preview).
You would have to change only impl_setOnMouseWheel handler to
bgImageView.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent me) {
adjustMagnification(me.getDeltaY()/40);
}
});
2. To fix centering of the glass you need to fix your layout. StackPane put all chidren in the center which doesn't correlate with your math. Use Pane instead:
Pane root = new Pane();
scene = new Scene(root, 900, 700);
3. Then you do that your glassGroup will be positioned under the mouse, and mouse events will be consumed by it. So you should also add next call to setupGlassGroup:
glassGroup.setMouseTransparent(true);
4. Also, you can simplify your bindings. Instead of overriding computeValue each time you can use convenience methods like here: viewportCenterX.bind(centerX.multiply(factor));. See updated code below:
public class MagnifyingGlass extends Application {
private ImageView bgImageView = new ImageView();
private Image image;
private Scene scene;
private DoubleProperty magnification = new SimpleDoubleProperty();
private DoubleProperty GLASS_SIZE = new SimpleDoubleProperty();
private DoubleProperty GLASS_CENTER = new SimpleDoubleProperty();
private DoubleProperty centerX = new SimpleDoubleProperty();
private DoubleProperty centerY = new SimpleDoubleProperty();
private DoubleProperty factor = new SimpleDoubleProperty();
private DoubleProperty viewportCenterX = new SimpleDoubleProperty();
private DoubleProperty viewportCenterY = new SimpleDoubleProperty();
private DoubleProperty viewportSize = new SimpleDoubleProperty();
private ImageView magGlass = new ImageView();
private Group glassGroup = new Group();
private Text desc = new Text();
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
viewportCenterX.bind(centerX.multiply(factor));
viewportCenterY.bind(centerY.multiply(factor));
viewportSize.bind(GLASS_SIZE.multiply(factor).multiply(magnification));
image = new Image(this.getClass().getResourceAsStream("/sample.jpg"));
Pane root = new Pane();
scene = new Scene(root, 900, 700);
setupBgImageView();
setupFactor();
setupGLASS_SIZE();
magnification.setValue(1.5);
setupMagGlass();
setupGlassGroup();
setupDesc();
bgImageView.requestFocus();
primaryStage.setTitle("Magnifying Glass");
primaryStage.setWidth(image.getWidth() / 2);
primaryStage.setHeight(image.getHeight() / 2);
root.getChildren().addAll(bgImageView, glassGroup, desc);
primaryStage.setScene(scene);
primaryStage.show();
}
public void adjustMagnification(final double amount) {
// no bindings is needed here - it's one time operation
double newValue = magnification.get() + amount / 4;
if (newValue < .5) {
newValue = .5;
} else if (newValue > 10) {
newValue = 10;
}
magnification.setValue(newValue);
}
private void setupGLASS_SIZE() {
DoubleBinding db = new DoubleBinding() {
{
super.bind(bgImageView.boundsInLocalProperty());
}
#Override
protected double computeValue() {
return bgImageView.boundsInLocalProperty().get().getWidth() / 4;
}
};
GLASS_SIZE.bind(db);
GLASS_CENTER.bind(GLASS_SIZE.divide(2));
}
private void setupFactor() {
DoubleBinding db = new DoubleBinding() {
{
super.bind(image.heightProperty(), bgImageView.boundsInLocalProperty());
}
#Override
protected double computeValue() {
return image.heightProperty().get() / bgImageView.boundsInLocalProperty().get().getHeight();
}
};
factor.bind(db);
}
private void setupBgImageView() {
bgImageView.setImage(image);
bgImageView.fitWidthProperty().bind(scene.widthProperty());
bgImageView.fitHeightProperty().bind(scene.heightProperty());
// comparing double requires precision
bgImageView.cacheProperty().bind(factor.isNotEqualTo(1.0, 0.05));
bgImageView.setSmooth(true);
bgImageView.setPreserveRatio(true);
bgImageView.setOnMouseMoved(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
centerX.setValue(me.getX());
centerY.setValue(me.getY());
}
});
bgImageView.setOnKeyPressed(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.EQUALS || ke.getCode() == KeyCode.PLUS) {
adjustMagnification(1.0);
} else if (ke.getCode() == KeyCode.MINUS) {
adjustMagnification(-1.0);
}
}
});
bgImageView.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent me) {
adjustMagnification(me.getDeltaY() / 40);
}
});
bgImageView.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
if (me.getButton() != MouseButton.PRIMARY) {
magGlass.setSmooth(magGlass.isSmooth());
}
bgImageView.requestFocus();
}
});
}
private void setupMagGlass() {
magGlass.setImage(image);
magGlass.setPreserveRatio(true);
magGlass.fitWidthProperty().bind(GLASS_SIZE);
magGlass.fitHeightProperty().bind(GLASS_SIZE);
magGlass.setSmooth(true);
ObjectBinding ob = new ObjectBinding() {
{
super.bind(viewportCenterX, viewportSize, viewportCenterY);
}
#Override
protected Object computeValue() {
return new Rectangle2D(viewportCenterX.get() - viewportSize.get() / 2, (viewportCenterY.get() - viewportSize.get() / 2), viewportSize.get(), viewportSize.get());
}
};
magGlass.viewportProperty().bind(ob);
Circle clip = new Circle();
clip.centerXProperty().bind(GLASS_CENTER);
clip.centerYProperty().bind(GLASS_CENTER);
clip.radiusProperty().bind(GLASS_CENTER.subtract(5));
magGlass.setClip(clip);
}
private void setupGlassGroup() {
glassGroup.translateXProperty().bind(centerX.subtract(GLASS_CENTER));
glassGroup.translateYProperty().bind(centerY.subtract(GLASS_CENTER));
Text text = new Text();
text.xProperty().bind(GLASS_CENTER.multiply(1.5));
text.yProperty().bind(GLASS_SIZE);
text.textProperty().bind(Bindings.concat("x", magnification, " magnification"));
Circle circle = new Circle();
circle.centerXProperty().bind(GLASS_CENTER);
circle.centerYProperty().bind(GLASS_CENTER);
circle.radiusProperty().bind(GLASS_CENTER.subtract(2));
circle.setStroke(Color.GREEN);
circle.setStrokeWidth(3);
circle.setFill(null);
glassGroup.getChildren().addAll(magGlass, text, circle);
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetY(4);
glassGroup.setEffect(dropShadow);
glassGroup.setMouseTransparent(true);
}
private void setupDesc() {
desc.setX(10);
desc.setY(15);
if (!bgImageView.isFocused()) {
desc.setText("Click image to focus");
} else {
desc.setText("Use the +/- or mouse wheel to zoom. Right-click to make the magnification "
+ "{if (magGlass.smooth) less smooth. else more smooth.}");
}
desc.setFont(new Font(12));
}
}

Resources