Disable window resizing in SWT - using composite - java

Am developing an eclipse plugin which has few wizard pages. I need the wizard window size to be constant, with "BOTH MAXIMISE and MINIMISE disabled", "window RESIZE disabled".
The point is I am not using SHELL. I am using COMPOSITE instead, which doesn't have any style bits.
How can I do that? I am just providing a part of my entire code:
public void createControl(Composite parent)
{
// TODO Auto-generated method stub
composite = new Composite(parent, SWT.NONE );
composite.setLayout(new GridLayout());
Composite selectAdapterComposite = new Composite(composite, SWT.NONE);
FormLayout reportOptionsCompositeLayout = new FormLayout();
reportOptionsCompositeLayout.marginHeight = 1;
reportOptionsCompositeLayout.marginWidth = 1;
selectAdapterComposite.setLayout(reportOptionsCompositeLayout);
buttonInterfaceSelection = new Button(selectAdapterComposite,SWT.RADIO);
//SWT.CHECK);
buttonInterfaceSelection.setText("Generate adapter using interface !");
buttonInterfaceSelection.setSelection(true);
buttonInterfaceSelection.addListener(SWT.Selection, this);
FormData exportInToExcelButtonData = new FormData();
exportInToExcelButtonData.left = new FormAttachment(null, 5);
buttonInterfaceSelection.setLayoutData(exportInToExcelButtonData);
// One Text Box
Label searchBoxLabel = new Label(selectAdapterComposite, SWT.None);
searchBoxLabel.setText("Search to select [Type to get the results below]");
FormData destinationLabelData = new FormData();
destinationLabelData.top = new FormAttachment(buttonInterfaceSelection, 10);
destinationLabelData.left = new FormAttachment(null, 5);
searchBoxLabel.setLayoutData(destinationLabelData);
searchTextBox = new Text(selectAdapterComposite, SWT.BORDER);
searchTextBox.setSize(20, 2);
FormData searchTextBoxData = new FormData();
searchTextBoxData.top = new FormAttachment(searchBoxLabel, 8);
searchTextBoxData.left = new FormAttachment(null, 5);
// destinationFolderPathData.left = new
// FormAttachment(destinationLabel,15);
searchTextBoxData.width = 400;
searchTextBox.addListener(SWT.Modify, this);
searchTextBox.setEnabled(true);
searchTextBox.setLayoutData(searchTextBoxData);
.
.
.
.
.
setControl(composite);
}
Please help me out.

Your code snippet is irrelevant to your question. The key word is wizard. When you create that wizard, it requires a Shell, so you can set its style bits there.
A WizardDialog's constructor:
public WizardDialog(Shell parentShell, IWizard newWizard)
Example of shell style bits:
parentShell.setShellStyle(parentShell.getShellStyle() | (~SWT.RESIZE));

Thanks for your reply... am a newbie to swt and your answer gave me an important info which I dint know before. Now then, I just took some time to go through widgets documentation and found something.
Composite : Instances of this class are controls which are capable of containing other controls.
Shell : Instances of this class represent the "windows" which the desktop or "window manager" is managing.
I realised that my understanding of SHELL and COMPOSITE was wrong.
Conclusion: So I have to depend upon SHELL to give window resizing controls and using a COMPOSITE does not give me any resizing option...
Correct me if am wrong please.. hope this will be useful to other noobs too...
Thanks.
P.S.: now i understoood, my code segment is irrelevant to my question cos, I am working on someone else's code and trying to make some changes to it. instead of making changes in SHELL (which is created in some other class) i am doing it in COMPOSITE.

Related

LibGDX - How to save generated FreeType fonts

I have problem with fonts lin LibGDX. I have three different fonts and parameters:
parameter_score = new FreeTypeFontGenerator.FreeTypeFontParameter();
//Some parameters..
font_score = generator.generateFont(parameter_score);
parameter_Big = new FreeTypeFontGenerator.FreeTypeFontParameter();
//Some parameters..
font_Big = generator.generateFont(parameter_Big);
parameter_Small = new FreeTypeFontGenerator.FreeTypeFontParameter();
//Some parameters..
font_Small = generator.generateFont(parameter_Small);
and it is very slow to generate fonts. When the app starts, i see black screen for about 3 seconds. I heard about method, when I generate fonts only first time, then I save it to some file, and when I lunch app next time, it will get generated fonts from file. But i dont know how to save, and load generated fonts. Do anyone know?
BitmapFontWriter
BitmapFontWriter is a class in gdx-tools which can write BMFont files from a BitmapFontData instance. This allows a font to be generated using FreeTypeFontGenerator, then written to a font file and PNG files. BitmapFontWriter has the benefit that it can be more easily run from scripts and can make use of FreeTypeFontGenerator's shadows and borders. Otherwise, the output is very similar to Hiero, though Hiero avoids writing a glyph image multiple times if different character codes render the same glyph.
Usage can look like this:
new LwjglApplication(new ApplicationAdapter() {
public void create () {
FontInfo info = new FontInfo();
info.padding = new Padding(1, 1, 1, 1);
FreeTypeFontParameter param = new FreeTypeFontParameter();
param.size = 13;
param.gamma = 2f;
param.shadowOffsetY = 1;
param.renderCount = 3;
param.shadowColor = new Color(0, 0, 0, 0.45f);
param.characters = Hiero.EXTENDED_CHARS;
param.packer = new PixmapPacker(512, 512, Format.RGBA8888, 2, false, new SkylineStrategy());
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.absolute("some-font.ttf"));
FreeTypeBitmapFontData data = generator.generateData(param);
BitmapFontWriter.writeFont(data, new String[] {"font.png"},
Gdx.files.absolute("font.fnt"), info, 512, 512);
BitmapFontWriter.writePixmaps(param.packer.getPages(), Gdx.files.absolute("imageDir"), name);
System.exit(0);
}
});
https://github.com/libgdx/libgdx/wiki/Hiero#bitmapfontwriter

Adding help button to SWT GUI

I have a simple swt GUI in my Eclipse application, which looks like the following:
It is implemented very simply:
// creating the label
Label label = new Label(composite, SWT.NONE);
label.setText("Label");
// creating the input field
Text text = new Text(composite, SWT.BORDER);
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
text.setLayoutData(gridData);
I would like to add an button between the label and the input element, so that the user can get additional help on what to add inide the field.
It can either be a help button or just a icon which shows information in mouse hover.
How do I implement that? I would appreciate any help!
One of the many ways to do this is to use an information field decoration.
Something like:
Text text = new Text(composite, SWT.BORDER);
FieldDecorationRegistry decRegistry = FieldDecorationRegistry.getDefault();
FieldDecoration infoField = decRegistry.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
ControlDecoration decoration = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
decoration.setImage(infoField.getImage());
decoration.setDescriptionText("Info decoration text");
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
// Space for decoration image
gridData.horizontalIndent = decRegistry.getMaximumDecorationWidth();
text.setLayoutData(gridData);

Positioning SWT Text free in Window/Shell

How is it possible to position text in an SWT Shell?
My problem is that I don't know which Layout to use. I've tried Row and Fill-Layout, but this won't work if I do it like text.setLocation(x,y).
Can anyone help me?
Solved it.
If you use no Layout, put the elements you want in a SWT Group, you can position it free inside this group.
Group group = new Group(parent, SWT.NONE);
Text text = new Text(group, SWT.BORDER);
group.setSize(parent.getSize());
text.setLocation(parent.getSize().x/2, parent.getSize().y/2);
Will look like this:
Might be worth taking a look at FormLayout. Would go something like:
Group group = new Group(parent, SWT.NONE);
group.setLayout(new FormLayout());
Text text = new Text(group, SWT.BORDER);
text.setText("Text1");
FormData fd = new FormData();
fd.top = new FormAttachment(50,0);
fd.left = new FormAttachment(50,0);
text.setLayoutData(fd);
The FormAttachment class lets you specify both a percentage of the container width (50% in this case), and also a fixed offset(0).

Why is there no text in JFreeChart?

JFreeChart seems to be working, except for all the text. It just doesn't show up at all, and I've no idea why. I attached a picture of a window with a pie graph that I got from a tutorial site. As you can see, the text isn't visible. (sorry my twitter feed was really long)
Thanks
Edit:
Here is the code that generates the above graph:
package analyzer_main;
import java.awt.Font;
public class FloatChart extends Composite implements Screen {
JFreeChart floatChart;
public FloatChart(Composite parent, int style){
super(parent,style);
createContents();
}
private void createContents(){
this.setLayout(new FormLayout());
floatChart = createChart(createDataset());
ChartComposite chartComposite = new ChartComposite(this,SWT.NONE,floatChart, true);
FormData fd_chartComposite = new FormData();
fd_chartComposite.left = new FormAttachment(0);
fd_chartComposite.right = new FormAttachment(100,0);
fd_chartComposite.top = new FormAttachment(0);
fd_chartComposite.bottom= new FormAttachment(100,0);
chartComposite.setLayoutData(fd_chartComposite);
}
/** * Creates the Dataset for the Pie chart */
private PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", new Double(43.2));
dataset.setValue("Two", new Double(10.0));
dataset.setValue("Three", new Double(27.5));
dataset.setValue("Four", new Double(17.5));
dataset.setValue("Five", new Double(11.0));
dataset.setValue("Six", new Double(19.4));
return dataset;
}
private JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart
// title
dataset, // data
true, // include legend
true, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(false);
plot.setLabelGap(0.02);
return chart;
}
#Override
public void Load() {
}
}
As you can see, it's pretty much the same as from the tutorial.
I was having the same problem using Linux Mint 11, Eclipse, and JFreeChart 1.0.14. I found that backing up to 1.0.13 resolved the problem.
First of all, like Kevin Stembridge said, check your JDK. You are using Ubuntu, then try this command in a terminal:
sudo update-alternatives --config java
You can see the JDKs installed on your system and the JDK (is selected at left with a *) you are using for this project.
If you have the Oracle JDK (from package java-6-sun) and OpenJDK (the openjdk-6-jdk package), try to select the Oracle JDK, because the OpenJDK has some graphical differences from the Oracle JDK and maybe these are the reason of this strange behavior on your JFreeChart. Select the Oracle JDK, recompile the Java project, and see if something in your JFreeChart is changed.
Check this Ubuntu Help page for details about Java, or read this old question of SO, or this page if you want to install the latest Oracle JDK.
About the code, it's very similar as from the tutorial, like you said. I have tested your code on Ubuntu, using Eclipse and Oracle JDK 6. The result is this:
adding the chart to a panel, editing only the createContents method (and commenting the ChartComposite parts, because I don't know what is ChartComposite), with this code:
private void createContents(){
//this.setLayout(new FormLayout());
floatChart = createChart(createDataset());
ChartPanel chartPanel = new ChartPanel(floatChart);
// default size
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
// add it to our application
setContentPane(chartPanel);
/*ChartComposite chartComposite = new ChartComposite(this,SWT.NONE,floatChart, true);
FormData fd_chartComposite = new FormData();
fd_chartComposite.left = new FormAttachment(0);
fd_chartComposite.right = new FormAttachment(100,0);
fd_chartComposite.top = new FormAttachment(0);
fd_chartComposite.bottom= new FormAttachment(100,0);
chartComposite.setLayoutData(fd_chartComposite);*/
}
Then, my advice is to review all your code used for the GUI I saw in your screenshot, and you should solve the problem.
Comment this answer if you have questions or problems.

How to print a JFace TreeViewer on to the printer

I am developing a plugin in Eclipse, that shows the results in a scrolledComposite. The composite contains a JFace TreeViewer. I want to print this TreeViewer to the printer. I found import org.eclipse.swt.printing.Printer; to print to the printer.
But when i am printing using following snippet
GC gc= new GC(printer);
Control abc[] = Composite.getChildren();
abc[0].print(gc);
The tree that i want to print contains the workspace, project explorer.
The print output is showing only the icons. it is not displaying the names of classes, methods.
i cant post screenshot till my reputation is above 10.check it here
Please let me know if i am not clear..
Thanks in advance
Ramesh Emandi
Tree myWidget = treeViewer.getTree();
Point size = myWidget.getSize();
Image image = new Image(display, size.x, size.y);
GC gc = new GC(myWidget);
gc.copyArea(image, 0, 0);
gc.dispose();
// Get the ImageData and create a new printer Image from it
ImageData imageData = image.getImageData();
Image printImage = new Image(printer, imageData);
http://www.eclipse.org/swt/faq.php#noprintimage

Categories

Resources