I want to add a bar at the bottom of the screen which has images and a string ,i wanted to have the spacing equally like
img1 string img2|img3 ,this is how the bottom bar should look like,below code is not wroking properly i am gettign the alignment and the last iamge is getting disappeared.
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(
FIELD_BOTTOM) {
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x316AC5);
graphics.clear();
super.paint(graphics);
}
};
Bitmap fadeBitmap = Bitmap
.getBitmapResource("GE_TimeZone_Fade_blue.PNG");
Bitmap clockBitmap = Bitmap.getBitmapResource("GE_Cal_icon_blue.PNG");
Bitmap tzBitmap = Bitmap
.getBitmapResource("GE_TimeZone_Button_blue.PNG");
final ImageButtonField unfocus = new ImageButtonField("",
Field.FOCUSABLE | FIELD_LEFT, "GE_TimeZone_Fade_blue.PNG",
"GE_TimeZone_Fade_blue.PNG", 0xFFFFFF);
LabelField test = new LabelField("hello");
final ImageButtonField bitmapField = new ImageButtonField("",
Field.FOCUSABLE | FIELD_HCENTER, "GE_Cal_icon_blue.PNG",
"GE_Cal_icon_onSelect.PNG", 0xFFFFFF);
final ImageButtonField bitmapField1 = new ImageButtonField("",
Field.FOCUSABLE | FIELD_RIGHT, "GE_TimeZone_Button_blue.PNG",
"GE_TimeZone_Btn_OnSelect.PNG", 0xFFFFFF);
int margin = ((Display.getWidth() - (fadeBitmap.getWidth()
+ clockBitmap.getWidth() + tzBitmap.getWidth() + test
.getWidth())) / 4);
unfocus.setMargin(0, margin, 0, 0);
test.setMargin(0, margin, 0, 0);
bitmapField.setMargin(0, margin, 0, 0);
bitmapField1.setMargin(0, margin, 0, 0);
horizontalFieldManager.add(unfocus);
horizontalFieldManager.add(test);
horizontalFieldManager.add(bitmapField);
horizontalFieldManager.add(bitmapField1);
this.setStatus(horizontalFieldManager);
There is a problem on the code you are using. Check following line.
int margin = ((Display.getWidth() - (fadeBitmap.getWidth()
+ clockBitmap.getWidth() + tzBitmap.getWidth() + test
.getWidth())) / 4);
The getWidth() and getHeight() of any Field will return valid values if the layout method of it's parent manager gets called.
So, adjusting the margin using getWidth(), getHeight() is not safe.
But it is possible to control the alignment and position of the Fields via extending HorizontalFieldManager. Check the following codes and output to get an idea about how it can be done.
Output
Using the StatusFieldManager:
StatusFieldManager statusFieldManager = new StatusFieldManager();
statusFieldManager.setBackground(BackgroundFactory.createSolidBackground(0x316AC5));
final Bitmap bmTest = Bitmap.getBitmapResource("bitmap.png");
BitmapField bmOne = new BitmapField(bmTest, Field.FOCUSABLE | FIELD_LEFT);
BitmapField bmTwo = new BitmapField(bmTest, Field.FOCUSABLE | FIELD_LEFT);
BitmapField bmThree = new BitmapField(bmTest, Field.FOCUSABLE | FIELD_LEFT);
LabelField lblTest = new LabelField("Test");
statusFieldManager.add(bmOne);
statusFieldManager.add(lblTest);
statusFieldManager.add(bmTwo);
statusFieldManager.add(bmThree);
setStatus(statusFieldManager);
Implementation of StatusFieldManager
class StatusFieldManager extends HorizontalFieldManager {
protected void sublayout(int width, int height) {
int numField = getFieldCount();
Field f;
int nHeight = 0, maxFieldWidth = width / 4;
if (numField == 4) {
f = getField(0);
layoutChild(f, maxFieldWidth, height);
nHeight = Math.max(nHeight, f.getHeight());
f = getField(1);
layoutChild(f, maxFieldWidth, height);
nHeight = Math.max(nHeight, f.getHeight());
f = getField(2);
layoutChild(f, maxFieldWidth, height);
nHeight = Math.max(nHeight, f.getHeight());
f = getField(3);
layoutChild(f, maxFieldWidth, height);
nHeight = Math.max(nHeight, f.getHeight());
// set position of the child fields
int x = 0, y = 0;
int requiredFieldWidth = 0;
for (int i=0;i<numField;i++) {
requiredFieldWidth += getField(i).getWidth();
}
int spaceBetweenFields = (width - requiredFieldWidth) / (numField - 1);
for (int i=0;i<numField;i++) {
setPositionChild(getField(i), x, (nHeight - getField(i).getHeight()) / 2);
x += getField(i).getWidth() + spaceBetweenFields;
}
setExtent(width, nHeight);
} else {
setExtent(0, 0);
}
}
}
try this -
unfocus.setMargin(0, margin, 0, 0);
test.setMargin(0, 10, 0, 0);
bitmapField.setMargin(0, 10, 0, 0);
bitmapField1.setMargin(0, 10, 0, 0);
Related
I'm trying to create a scrolling image that wraps around a canvas to follow its own tail. I've been trying to use PixelWriters and Readers to save off the vertical pixel lines that are scrolling off the screen to the West, and append these to a new image which, should grow on the RHS (East) of the screen.
It scrolls, but that's all that's happening. I don't understand how to calculate the scanlines, so apologies for this part.
Any help appreciated.
package controller;
import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.*;
import javafx.scene.layout.*;
import util.GraphicsUtils;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.nio.file.Paths;
class ImageContainer extends HBox {
int w, h;
int translatedAmount = 0;
Image image;
Canvas canvas;
long startNanoTime = System.nanoTime();
WritableImage eastImage = null;
public ImageContainer() {
setVisible(true);
load();
w = (int) image.getWidth();
h = (int) image.getHeight();
canvas = new Canvas(w, h);
int edgeX = (int) canvas.getWidth(); //You can set this a little west for visibility sake...whilst debugging
getChildren().addAll(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
canvas.setVisible(true);
gc.drawImage(image, 0, 0, w, h);
setPrefSize(w, h);
eastImage = new WritableImage(translatedAmount+1, h); //create a new eastImage
new AnimationTimer() {
public void handle(long currentNanoTime) {
if (((System.nanoTime() - startNanoTime) / 1000000000.0) < 0.05) {
return;
} else {
startNanoTime = System.nanoTime();
}
translatedAmount++;
Image westLine = getSubImageRectangle(image, 1, 0, 1, h); //get a 1 pixel strip from west of main image
PixelReader westLinepixelReader = westLine.getPixelReader(); //create a pixel reader for this image
byte[] westLinePixelBuffer = new byte[1 * h * 4]; //create a buffer to store the pixels collected from the about to vanish westLine
westLinepixelReader.getPixels(0, 0, 1, h, PixelFormat.getByteBgraInstance(), westLinePixelBuffer, 0, 4); //collect the pixels from westLine strip
Image tempImg = eastImage; //save away the current east side image
byte[] tempBuffer = new byte[(int)tempImg.getWidth() * h * 4];
PixelReader tempImagePixelReader = tempImg.getPixelReader(); //create a pixel reader for our temp copy of the east side image
tempImagePixelReader.getPixels(0, 0, (int)tempImg.getWidth(), h, PixelFormat.getByteBgraInstance(), tempBuffer, 0, 4); //save the tempImage into the tempBuffer
eastImage = new WritableImage(translatedAmount+1, h); //create a new eastImage, but one size larger
PixelWriter eastImagePixelWriter = eastImage.getPixelWriter(); //create a pixel writer for this new east side image
eastImagePixelWriter.setPixels(1, 0, (int)tempImg.getWidth(), h, PixelFormat.getByteBgraInstance(), tempBuffer, 0, 4); //copy the temp image in at x=1
eastImagePixelWriter.setPixels((int)tempImg.getWidth(), 0, 1, h, PixelFormat.getByteBgraInstance(), westLinePixelBuffer, 0, 4); //copy the westLine at x=tempImg.width
image = getSubImageRectangle(image, 1, 0, (int) image.getWidth() - 1, h);
gc.drawImage(image, 0, 0); //draw main image
System.out.println(edgeX-eastImage.getWidth());
gc.drawImage(eastImage, edgeX-eastImage.getWidth(), 0); //add lost image lines
}
}.start();
}
public void load() {
Path imagePath = Paths.get("./src/main/resources/ribbonImages/clouds.png");
File f = imagePath.toFile();
assert f.exists();
image = new Image(f.toURI().toString());
}
public Image getSubImageRectangle(Image image, int x, int y, int w, int h) {
PixelReader pixelReader = image.getPixelReader();
WritableImage newImage = new WritableImage(pixelReader, x, y, w, h);
ImageView imageView = new ImageView();
imageView.setImage(newImage);
return newImage;
}
}
Why make this more difficult than necessary? Simply draw the image to the Canvas twice:
public static void drawImage(Canvas canvas, Image sourceImage, double offset, double wrapWidth) {
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
// make |offset| < wrapWidth
offset %= wrapWidth;
if (offset < 0) {
// make sure positive offsets do not result in the previous version
// of the image not being drawn
offset += wrapWidth;
}
gc.drawImage(sourceImage, -offset, 0);
gc.drawImage(sourceImage, wrapWidth - offset, 0);
}
#Override
public void start(Stage primaryStage) {
Image image = new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg");
Canvas canvas = new Canvas(image.getWidth(), image.getHeight());
primaryStage.setResizable(false);
Scene scene = new Scene(new Group(canvas));
DoubleProperty offset = new SimpleDoubleProperty();
offset.addListener((observable, oldOffset, newOffset) -> drawImage(canvas, image, newOffset.doubleValue(), canvas.getWidth()));
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(offset, 0, Interpolator.LINEAR)),
new KeyFrame(Duration.seconds(10), new KeyValue(offset, image.getWidth()*2, Interpolator.LINEAR))
);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
I have written the following code here the background image is displaying but the image did not cover the full background
private Bitmap background;
int mWidth = Display.getWidth();
int mHeight = Display.getHeight();
public MyScreen()
{
// Set the displayed title of the screen
//backgroundBitmap = Bitmap.getBitmapResource("slidimage.png");
final Bitmap background = Bitmap.getBitmapResource("slidimage.png");
HorizontalFieldManager vfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public void paint(Graphics g) {
g.drawBitmap(0, 0,mWidth, mHeight, background, 0, 0);
super.paint(g);
}
};
add(vfm);
public static Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int rgb[] = new int[image.getWidth()*image.getHeight()];
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
You can use the above method to resize the image
just pass the image to be resized and its width and height .
and the function will return the resized image .
where rescale Array is the below method
private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}
I am trying to type in characters to fill an editfield, if the text is still on the first line I have got no problem but when the first line is full then it goes to the next line and I get the following error:
0:01:56.609: Uncaught: StackOverflowError
Here is my custom_editfield:
public class Custom_EditField extends EditField {
int width, row;
Custom_EditField(long style, int width, int row) {
super(style);
this.width = width;
this.row = row;
}
public int getPreferredHeight() {
return Font.getDefault().getHeight() * row;
}
public int getPreferredWidth() {
return width;
}
protected void layout(int maxWidth, int maxHeight) {
super.layout(maxWidth,
Math.min(maxHeight, Font.getDefault().getHeight() * row));
super.setExtent(maxWidth,
Math.min(maxHeight, Font.getDefault().getHeight() * row));
}
/*public int drawText(Graphics graphics, int offset, int length, int x,
int y, DrawTextParam drawTextParam) {
graphics.setBackgroundColor(Color.GRAY);
graphics.clear();
graphics.setColor(Color.BLACK);
int labelWidth = getFont().getAdvance(getLabel());
graphics.drawRect(labelWidth, 0, getWidth() - labelWidth, getHeight());
return graphics.drawText(
this.getText().substring(offset, offset + length), x, y);
}*/
protected void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
graphics.setBackgroundColor(Color.GRAY);
graphics.clear();
graphics.setColor(Color.BLACK);
graphics.drawRect(0, 0, rectWidth, rectHeight);
super.paint(graphics);
}
}
I also noticed that the cursor is transparent. Do you think that the cursor could cause this problem?
Here is I call the editfield
extends VerticalFIeldManager
protected void sublayout(int width, int height) {
comments = new Custom_EditField(Field.FIELD_HCENTER
| Field.FIELD_VCENTER | Field.FOCUSABLE,
getPreferredWidth() - 10, 3);
add(comments);
namelabel = new Custom_LabelField("姓名:", DrawStyle.ELLIPSIS
| LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | Field.FIELD_LEFT);
namelabel.setFont(Font.getDefault().derive(Font.BOLD, 20));
namelabel.setFontColor(Color.BLACK);
add(namelabel);
postbtn = new ButtonField("留言", DrawStyle.HCENTER | Field.FIELD_RIGHT);
postbtn.setPadding(0, 20, 0, 20);
postbtn.setChangeListener(this);
add(postbtn);
name = new Custom_EditField(Field.FIELD_HCENTER | Field.FIELD_VCENTER
| Field.FOCUSABLE, getPreferredWidth()
- namelabel.getPreferredWidth() - postbtn.getContentWidth() - 5
* 4, 1);
add(name);
Field field = getField(0);
layoutChild(field, getPreferredWidth() - 10,
comments.getPreferredHeight());
setPositionChild(field, 5, 5);
field = getField(1);
layoutChild(field, Font.getDefault().getAdvance(namelabel.getText()),
namelabel.getContentHeight());
setPositionChild(field, 5, comments.getPreferredHeight() + 5 * 2);
field = getField(2);
layoutChild(field, postbtn.getPreferredWidth() + postbtn.getWidth(),
name.getPreferredHeight());
setPositionChild(field, getPreferredWidth() - (postbtn.getWidth() + 5),
comments.getPreferredHeight() + 5 * 2);
field = getField(3);
layoutChild(field, getPreferredWidth() * 2 / 3,
name.getPreferredHeight());
setPositionChild(field, namelabel.getWidth(),
comments.getPreferredHeight() + 5 * 2);
width = Math.min(width, getPreferredWidth());
height = Math.min(height, getPreferredHeight());
setExtent(width, height);
}
The Solution
I still can't build your code, because the Manager code posted uses the class Custom_LabelField, which you haven't shown. However, I would assume that Custom_LabelField is somewhat like a LabelField. If I assign name to be a LabelField, then I see your StackOverflowError.
Just as #EugenMartynov said, you are setting the text of a label field inside your implementation of sublayout(). This actually causes sublayout() to be called again, from within itself. This causes namelabel to be created again, and the process repeats infinitely until the stack is exhausted.
Really, the sublayout() method should only be used for layout operations: positioning and sizing. You should normally create your Field objects before that. Normally, that happens in the constructor. If you move the first half of your sublayout method to the constructor, you'll fix this problem:
public class MyManager extends VerticalFieldManager {
public MyManager() {
super(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
comments = new Custom_EditField(Field.FIELD_HCENTER
| Field.FIELD_VCENTER | Field.FOCUSABLE,
getPreferredWidth() - 10, 3);
add(comments);
namelabel = new Custom_LabelField("姓名:", DrawStyle.ELLIPSIS
| LabelField.USE_ALL_WIDTH | DrawStyle.LEFT | Field.FIELD_LEFT);
namelabel.setFont(Font.getDefault().derive(Font.BOLD, 20));
namelabel.setFontColor(Color.BLACK);
add(namelabel);
postbtn = new ButtonField("留言", DrawStyle.HCENTER | Field.FIELD_RIGHT);
postbtn.setPadding(0, 20, 0, 20);
postbtn.setChangeListener(this);
add(postbtn);
name = new Custom_EditField(Field.FIELD_HCENTER | Field.FIELD_VCENTER
| Field.FOCUSABLE, getPreferredWidth()
- namelabel.getPreferredWidth() - postbtn.getContentWidth() - 5
* 4, 1);
add(name);
}
}
Then sublayout() becomes simpler:
protected void sublayout(int height, int width) {
Field field = getField(0);
layoutChild(field, getPreferredWidth() - 10,
comments.getPreferredHeight());
setPositionChild(field, 5, 5);
field = getField(1);
layoutChild(field, Font.getDefault().getAdvance(namelabel.getText()),
namelabel.getContentHeight());
setPositionChild(field, 5, comments.getPreferredHeight() + 5 * 2);
field = getField(2);
layoutChild(field, postbtn.getPreferredWidth() + postbtn.getWidth(),
name.getPreferredHeight());
setPositionChild(field, getPreferredWidth() - (postbtn.getWidth() + 5),
comments.getPreferredHeight() + 5 * 2);
field = getField(3);
layoutChild(field, getPreferredWidth() * 2 / 3,
name.getPreferredHeight());
setPositionChild(field, namelabel.getWidth(),
comments.getPreferredHeight() + 5 * 2);
width = Math.min(width, getPreferredWidth());
height = Math.min(height, getPreferredHeight());
setExtent(width, height);
}
General Information
If you want to know how to catch a StackOverflowError, put this code in your top level UiApplication subclass (just for debugging ... remove it before releasing your app):
try {
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
} catch (Throwable e) {
e.printStackTrace();
}
After it hits the line e.printStackTrace(), your Eclipse Console window will show something like this:
[375.664] 0x16
[375.664] HelloBlackBerry(4FF4123E)
[375.664] MyManager
[375.664] sublayout
[375.664] 0x16
[375.664] HelloBlackBerry(4FF4123E)
[375.664] MyManager
[375.664] sublayout
[375.664] 0x16
[375.664] HelloBlackBerry(4FF4123E)
[375.664] MyManager
[375.664] sublayout
[375.664] 0x16
[375.664] HelloBlackBerry(4FF4123E)
[375.664] MyManager
[375.664] sublayout
[375.664] 0x16
[375.664] HelloBlackBerry(4FF4123E)
You can see, over and over, with almost the exact same timestamp (375.664), the sublayout method in the MyManager class is being called. When you see that, you know you need to look at that method, because it's calling itself.
I am working a UI based application in BlackBerry. UI is like the following:
label-1 : Oject choice field-1
label-2 : Oject choice field-2
label-3 : Oject choice field-3
label-4 : Oject choice field-4
label-5 : Oject choice field-5
It is really getting difficult to generate this UI. The width and height is the main issue for my difficulty.
public HomeScreen() {
super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
_dbOperations = new DBOperations();
_mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
_mainVFM.setMargin(10, 10, 40, 10);
_menuFieldVFM = new VerticalFieldManager();
_menuFieldVFM.setMargin(0, 5, 0, 0);
_menuDropDownVFM = new VerticalFieldManager();
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));
XYEdges padding = new XYEdges(1, 1, 1, 1);
Border roundedBorder = BorderFactory.createSimpleBorder(padding);
// HEADING
_headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
_headingLabelField = new LabelField(Constants.Text_heading);
_headingLabelField.setFont(ApplicationFont.labelFont);
_headingHFM.add(_headingLabelField);
_headingHFM.setMargin(0, 0, 20, 0);
// _productLine LINE
_productLineLabelField = new LabelField(Constants.Text_ProductLine);
_productLineLabelField.setFont(ApplicationFont.explainationFont);
_productLineLabelField.setMargin(8, 0, 0, 0);
_menuFieldVFM.add(_productLineLabelField);
int plSetTo1 = 0;
_productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_productLineOCF.setFont(ApplicationFont.explainationFont);
_productLineOCF.setChangeListener(this);
_menuDropDownVFM.add(_productLineOCF);
// HP
_HPLabelField = new LabelField(Constants.Text_HP);
_HPLabelField.setFont(ApplicationFont.explainationFont);
_HPLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_HPLabelField);
int hpSetTo1 = 0;
String data_HP[] = { "Select HP" };
_HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_HP_OCF.setFont(ApplicationFont.explainationFont);
_HP_OCF.setChangeListener(this);
_menuDropDownVFM.add(_HP_OCF);
_RPMLabelField = new LabelField(Constants.Text_RPM);
_RPMLabelField.setFont(ApplicationFont.explainationFont);
_RPMLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_RPMLabelField);
int rpmSetTo1 = 0;
String data_RPM[] = { "Select RPM" };
_RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_RPM_OCF.setChangeListener(this);
_menuDropDownVFM.add(_RPM_OCF);
// VOLTAGE
_voltageLabelField = new LabelField(Constants.Text_voltage);
_voltageLabelField.setFont(ApplicationFont.explainationFont);
_voltageLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_voltageLabelField);
int volSetTo1 = 0;
String data_voltage[] = { "Select Voltage" };
_voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_voltageOCF.setChangeListener(this);
_menuDropDownVFM.add(_voltageOCF);
// FRAME SIZE
_frameSizeLabelField = new LabelField(Constants.Text_frameSize);
_frameSizeLabelField.setFont(ApplicationFont.explainationFont);
_frameSizeLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_frameSizeLabelField);
// int iSetTo1 = 0;
_frameSizeOCF = new ObjectChoiceField("", _frameArray, plSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_frameSizeOCF.setChangeListener(this);
_menuDropDownVFM.add(_frameSizeOCF);
_menuMainHFM = new HorizontalFieldManager();
_menuMainHFM.add(_menuFieldVFM);
_menuMainHFM.add(_menuDropDownVFM);
// -OR- LABEL
_orLabelField = new LabelField(Constants.Text_or);
_orLabelField.setMargin(20, 0, 0, 0);
_orLabelField.setFont(ApplicationFont.labelFont);
// SEARCH BY PART NUMBER
_SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
_SearchByPartNumberField.setMargin(20, 0, 0, 0);
_SearchByPartNumberField.setFont(ApplicationFont.labelFont);
// ENTER PART NUMBER
_enterPartNoHFM = new HorizontalFieldManager();
_enterPartNoLabelField = new LabelField("Enter Part Number: ");
_partNumberEditField = new EditField();
_partNumberEditField.setBorder(roundedBorder);
_enterPartNoHFM.add(_enterPartNoLabelField);
_enterPartNoHFM.add(_partNumberEditField);
_enterPartNoHFM.setMargin(20, 0, 0, 0);
// SAERCH BUTTON
_searchButtonField = new ButtonField(" Search ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_searchButtonField.setChangeListener(this);
_searchButtonField.setMargin(20, 0, 0, 0);
_checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_checkForUpdates.setMargin(10, 0, 0, 0);
_checkForUpdates.setChangeListener(this);
_mainVFM.add(_headingHFM);
_mainVFM.add(_menuMainHFM);
_mainVFM.add(_orLabelField);
_mainVFM.add(_SearchByPartNumberField);
_mainVFM.add(_enterPartNoHFM);
_mainVFM.add(_searchButtonField);
_mainVFM.add(_checkForUpdates);
add(_mainVFM);
}
Now I am using following code. But no progress, I am at the same stage.
public HomeScreen() {
super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
_dbOperations = new DBOperations();
_mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
_mainVFM.setMargin(10, 10, 40, 10);
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));
// HEADING
_headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
_headingLabelField = new LabelField(Constants.Text_heading);
_headingLabelField.setFont(ApplicationFont.labelFont);
_headingHFM.add(_headingLabelField);
_headingHFM.setMargin(0, 0, 20, 0);
// IMPORTANT CALCULATION
String productLineString = Constants.Text_ProductLine;
int charWidth = 0;
for (int i = 0; i < productLineString.length(); i++) {
charWidth = Font.getDefault().getAdvance(String.valueOf(productLineString.charAt(i)));
totalWidth += charWidth;
System.out.println(totalWidth + "===>>>>>>total width" + i);
}
System.out.println(totalWidth + "===>>>>>>total width");
totalWidth = totalWidth + 10;
// _productLine LINE
_productLineLabelField = new LabelField(Constants.Text_ProductLine);
_productLineLabelField.setFont(ApplicationFont.explainationFont);
_productLineLabelField.setMargin(8, 0, 0, 0);
int plSetTo1 = 0;
_productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT);
_productLineOCF.setFont(ApplicationFont.explainationFont);
_productLineOCF.setChangeListener(this);
_productHFM = new HorizontalFieldManager(USE_ALL_WIDTH | FOCUSABLE);
_productHFM.add(_productLineLabelField);
_productHFM.add(_productLineOCF);
// HP
_hp1 = new VerticalFieldManager();
_HPLabelField = new LabelField(Constants.Text_HP);
_HPLabelField.setFont(ApplicationFont.explainationFont);
_HPLabelField.setMargin(25, 0, 0, 0);
_hp1.add(_HPLabelField);
_hp2 = new VerticalFieldManager();
int hpSetTo1 = 0;
String data_HP[] = { " Select HP" };
_HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT | USE_ALL_WIDTH);
_HP_OCF.setMinimalWidth(totalWidth + 50);
_HP_OCF.setFont(ApplicationFont.explainationFont);
_HP_OCF.setChangeListener(this);
_hp2.add(_HP_OCF);
_hpHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
int x = totalWidth;
setPositionChild(_hp2, x, 0);
}
};
_hpHFM.add(_hp1);
_hpHFM.add(_hp2);
_RPM_HFM = new HorizontalFieldManager();
// RPM
_RPMLabelField = new LabelField(Constants.Text_RPM);
_RPMLabelField.setFont(ApplicationFont.explainationFont);
_RPMLabelField.setMargin(25, 0, 0, 0);
_RPM_HFM.add(_RPMLabelField);
int rpmSetTo1 = 0;
String data_RPM[] = { "Select RPM" };
_RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT);
_RPM_OCF.setMinimalWidth(totalWidth + 50);
_RPM_OCF.setChangeListener(this);
_RPM_HFM.add(_RPM_OCF);
_voltageHFM = new HorizontalFieldManager();
// VOLTAGE
_voltageLabelField = new LabelField(Constants.Text_voltage);
_voltageLabelField.setFont(ApplicationFont.explainationFont);
_voltageLabelField.setMargin(25, 0, 0, 0);
_voltageHFM.add(_voltageLabelField);
int volSetTo1 = 0;
String data_voltage[] = { "Select Voltage" };
_voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT);
_voltageOCF.setMinimalWidth(totalWidth + 50);
_voltageOCF.setChangeListener(this);
_voltageHFM.add(_voltageOCF);
_frameHFM = new HorizontalFieldManager();
// FRAME SIZE
_frameSizeLabelField = new LabelField(Constants.Text_frameSize);
_frameSizeLabelField.setFont(ApplicationFont.explainationFont);
_frameSizeLabelField.setMargin(25, 0, 0, 0);
_frameHFM.add(_frameSizeLabelField);
int fSetTo1 = 0;
_frameSizeOCF = new ObjectChoiceField("", _frameArray, fSetTo1, Field.FIELD_RIGHT);
_frameSizeOCF.setMinimalWidth(totalWidth + 50);
_frameSizeOCF.setChangeListener(this);
_frameHFM.add(_frameSizeOCF);
// -OR- LABEL
_orLabelField = new LabelField(Constants.Text_or);
_orLabelField.setMargin(20, 0, 0, 0);
_orLabelField.setFont(ApplicationFont.labelFont);
// SEARCH BY PART NUMBER
_SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
_SearchByPartNumberField.setMargin(20, 0, 0, 0);
_SearchByPartNumberField.setFont(ApplicationFont.labelFont);
// ENTER PART NUMBER
_enterPartNoHFM = new HorizontalFieldManager();
_enterPartNoLabelField = new LabelField("Enter Part Number: ");
_partNumberEditField = new EditField();
_partNumberEditField.setBorder(roundedBorder);
_enterPartNoHFM.add(_enterPartNoLabelField);
_enterPartNoHFM.add(_partNumberEditField);
_enterPartNoHFM.setMargin(20, 0, 0, 0);
// SAERCH BUTTON
_searchButtonField = new ButtonField(" Search ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_searchButtonField.setChangeListener(this);
_searchButtonField.setMargin(20, 0, 0, 0);
_checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_checkForUpdates.setMargin(10, 0, 0, 0);
_checkForUpdates.setChangeListener(this);
add(_pageHeaderHFM);
_mainVFM.add(_headingHFM);
_mainVFM.add(_productHFM);
_mainVFM.add(_hpHFM);
_mainVFM.add(_RPM_HFM);
_mainVFM.add(_voltageHFM);
_mainVFM.add(_frameHFM);
_mainVFM.add(_orLabelField);
_mainVFM.add(_SearchByPartNumberField);
_mainVFM.add(_enterPartNoHFM);
_mainVFM.add(_searchButtonField);
_mainVFM.add(_checkForUpdates);
add(_mainVFM);
}
I am fine with the width of the OCF but height and the position of the OCF must be settled as required. This is the output I am getting with this code.
This answer is based on following links:
Align Field in HorizontalFieldManager.
BlackBerry HorizontalFieldManager alignment.
Try following code:
class HomeScreen extends MainScreen {
public HomeScreen() {
super(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT | MainScreen.VERTICAL_SCROLL);
VerticalFieldManager vfmMain = new VerticalFieldManager(Field.USE_ALL_WIDTH);
// LabelField
LabelField lblFOne = new LabelField("LabelField One", Field.FIELD_LEFT | Field.FIELD_VCENTER);
// ObjectChoiceField
VerticalFieldManager vfmChoiceFieldContainerOne = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_RIGHT);
final String[] options = new String[] { "Choice One - A very long string.", "Choice B", "Choice C" };
ObjectChoiceField ocfOne = new ObjectChoiceField("", options, 0, Field.FIELD_RIGHT | ObjectChoiceField.FORCE_SINGLE_LINE);
vfmChoiceFieldContainerOne.add(ocfOne);
// Contain a row of LabelField and ObjectChoiceField
HorizontalFieldManager hfmRowOne = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FOCUSABLE);
hfmRowOne.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
hfmRowOne.add(lblFOne);
hfmRowOne.add(vfmChoiceFieldContainerOne);
vfmMain.add(hfmRowOne);
add(vfmMain);
}
}
I have the following program does not work
NOTE: compiled on windows 7.
Gdk.Screen screen = Gdk.Screen.get_default ();
Gdk.Window rootWin2 = screen.get_active_window ();
int width, height;
rootWin2.get_size (out width, out height);
Gdk.Colormap? colormap= rootWin2.get_colormap ();
Gdk.Pixbuf? dest = new Gdk.Pixbuf (Gdk.Colorspace.RGB, false, 8, width, height);
Gdk.pixbuf_get_from_drawable (dest, rootWin2, colormap, 0, 0, 0, 0, width, height);
try {
dest.save("screenShoot2.jpg", "jpeg");
} catch (Error e) {
stdout.printf("\n eerorrr " + e.message + "\n");
}
using Gtk;
int main (string[] args) {
Gtk.init (ref args);
int width, height;
Gdk.Window win = Gdk.get_default_root_window();
width = win.get_width();
height = win.get_height();
Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height);
screenshot.save("screenshot.png","png");
return 0;
}
// valac --pkg gtk+-3.0 --pkg gdk-3.0 screenshot.vala