Is manipulating CSS-data via Integer in GWT possible? - java

I am writing a software (GWT) in which different images of soccerclubs and its names should be shown. So i wrote the following method:
public void updateClubNameHeader(String clubName, int logoNumber) {
clubLabelFrame.clear();
HTML clubLogo = new HTML();
clubLogo.setStyleName("clublogo_img");
clubLabelFrame.add(clubLogo);
Label clubNameLabel = new Label(clubName);
clubNameLabel.setStyleName("clubnameLabel"); <--- logoNumber?
clubLabelFrame.add(clubNameLabel);
}
It is no problem to change the names of the club (clubNameLabel), but if i want to have a new logo as well, this CSS-style is used: (filenames: 1.jpg, 2.jpg, ...)
.clublogo_img {
...
background-image: url("images/1.jpg") !important
}
The problem: If i want to represent every possible club, i have to write round about ~100 styles.
The question: Is it possible to pass my integer logoNumber to the CSS, so that this one style is enough the show all the chosen logos?

You cannot do it with CSS. You can do it with GWT:
clubLogo.getElement().getStyle().setBackgroundImage("url(\"images/" + imageNumber + ".jpg\")");

Related

How to make an image float above the text in OpenPDF to realize the seal function?

I found that OpenPDF's Image.class seems to have only 6 image positioning methods, and among them, there is only the option to add the image below the text (that is Image.UNDERLYING), but there is no option to let the image float above the text.
The source code of OpenPDF's Image class is as follows:
public static final int DEFAULT = 0;
public static final int RIGHT = 2;
public static final int LEFT = 0;
public static final int MIDDLE = 1;
public static final int TEXTWRAP = 4;
public static final int UNDERLYING = 8;
I want to implement the function of editing the contract. It needs to put a seal image on top of the text, and the position of the image needs to be dynamically set (because the length of the contract text may change). This may involve pagination and absolute positioning. I found that the PdfContentByte class seems to be able to add images to the text, but I don't know how it can dynamically position the images. It would be nice if there was a way to do this in sequence with Document#add like the Paragraph class, but I haven't found it yet.
The effect I want to achieve is roughly like this: Click to view the picture
How can I achieve my needs?
If you want to add something to an existing PDF with OpenPdf, you surely use a PdfStamper.
To add an image above the existing content of some page, simply retrieve the overcontent of the target page from the stamper and add the image to it.

how to put css styling for one specific checkbox in checkboxGroup of vaadin 8

I have a checkboxgroup which has multiple checkboxes. I have certain checkboxes which needs to look different, either by bold text or colored text ,which wont change irrespective of selection/unselection.
I have following code to build checkboxgroup. But I am not able to put style specific to one checkbox, because I dont have access to it. How can I do that
CheckBoxGroup<ReferenceScreenResultAnswer> answersOptionGroup = new CheckBoxGroup<>(question.getText());
List<ReferenceScreenResultAnswer> checkBoxItems = new ArrayList<>();
answersOptionGroup.setItems(checkBoxItems);
.......
// this is where i want to put CSS to specific checkbox/values
for (Answer answer : preSelectedAnswer)
{
ReferenceScreenResultAnswer rsra = new ReferenceScreenResultAnswer();
rsra.setAnswer(answer);
rsra.setReferenceScreenResultQuestion(rsrq);
answersOptionGroup.select(rsra);
}
I can do invidiual checkboxes like
CheckBox cb = new CheckBox();
cb.setCaptionAsHtml(true);
cb.setCaption("<b> hello </b> there");
But I am not able to access individual checkboxes from CheckBoxGroup. Any idea how to access them
i found the answer:
// css style the pre selected answer, so they look different irrespective
// of their selection
answersOptionGroup.setItemCaptionGenerator(new ItemCaptionGenerator<ReferenceScreenResultAnswer>()
{
#Override
public String apply(ReferenceScreenResultAnswer item)
{
if (preSelectedAnswer.contains(item.getAnswer()))
return "<strong>" + item.getAnswer().toString() + "</strong>";
else
return item.getAnswer().toString();
}
});

(Kind of solved but still appreciate better answers) Android Studio: How to identify certain special pages in a PDF file?

I am writing an app that generates Maths worksheets for school students. It will, for example, generate 2 to 5 pages of simple Maths questions and 1 to 2 pages of answers. The PDF can be saved to file and loaded again later. Then it has a print function that can print all the pages. I want to make it skip printing the answer pages.
Is it possible to automatically identify which pages are the answer pages? I can only think of a workaround by making those answer pages have special height or width but not even sure if this works. Are there any better ways to do this?
Ok, I continued the project and used the following method: when constructing the PDF, I put the word "Answer on the top left corner with a gray rectangle surrounding it drawn with drawRect(). Then before the actual printing, I used the following code inside the PrintDocumentAdapter() class to check whether the color of the pixel 0,0 is gray or not.
#Override
public void onStart() {
if (parcelFileDescriptor != null) {
try {
pdfRenderer = new PdfRenderer(parcelFileDescriptor);
} catch (IOException e) {
e.printStackTrace();
}
}
int tempTotal = pdfRenderer.getPageCount();
Bitmap[] tempBitmap = new Bitmap[tempTotal];
finalTotal = tempTotal;
for (int pageNum = 0; pageNum < tempTotal; pageNum++) {
PdfRenderer.Page tempPage = pdfRenderer.openPage(pageNum);
tempBitmap[pageNum] = Bitmap.createBitmap(WS_WIDTH, WS_HEIGHT, Bitmap.Config.ARGB_8888);
tempPage.render(tempBitmap[pageNum], null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT);
if (tempBitmap[pageNum].getPixel(0, 0) == Color.GRAY) {
finalTotal--;
}
tempPage.close();
}
}
It works fine. At least should cause no problem if the users only attempt to print PDF files constructed with my app. :P
Please tell me if you know a better way to do this. Thanks!

How do I get an image into an Object[] in Java?

Hello I'm trying to place an image as a bullet point type of thing in a JOptionPane. What is displayed in the JOptionPane I've put in side an object array. But it just doesn't take the image. it shows me the file name though...
Any ideas?
public void popups(){
ImageIcon bullet = new ImageIcon("imgs/bullet.png");
Object[] instr = {+bullet+ "text "};
JOptionPane.showMessageDialog(null, instr, "Instrucciones", 1);
}
EDIT:
StringBuilder html = new StringBuilder();
html.append("<html><ul> list-style-image: url ('imgs/bullet.png')</ul>"
+ "<ul>"
+ "<li>TEXT"
+ "<li>TEXT"
+ "</ul></html>");
JOptionPane.showMessageDialog(null, html, "Instrucciones", 1);
Provide a style specifying the image.
ul {
list-style-image: url('https://i.stack.imgur.com/gJmeJ.png');
}
Then the effect of this:
<ul>
<li>This is a list point.
<li>This is a 2nd list point.
</ul>
Is this:
Note: That image was generated using a Swing based JLabel. Swing's support for CSS is quite limited / patchy, so always best to check.

adding a field name as a method parameter

I have a Swing form where I want to detect edited field data so I can update the data via a web service. There doesn't seem to be a simple way to do this as there are a plethora of medium to complex code examples for this, most of which are over my head! However, I think I found a simple solution that will fit my needs and I wanted to run it by the group for input / suggestions. FYI: it may not matter but know that I am using NetBeans so things like listeners are auto-coded by the app.
Step 1: When I load the form, I am saving all the data to a Class array so I know the starting point of the each field. Here is the code for that load:
public void coSetSearchDetail(String coDetail){
String[] text;
System.out.println("SingleCO Result: "+ coDetail);
text = coDetail.split("\\|");
txtName_CoDetail.setText(text[1]);
txtAddr_CoDetail.setText(text[2]);
txtAddr2_CoDetail.setText(text[3]);
txtCity_CoDetail.setText(text[4]);
txtState_CoDetail.setText(text[5]);
txtZip_CoDetail.setText(text[6]);
stringarrayCoDetails[0] = text[0];
stringarrayCoDetails[1] = text[1];
stringarrayCoDetails[2] = text[2];
stringarrayCoDetails[3] = text[3];
stringarrayCoDetails[4] = text[4];
stringarrayCoDetails[5] = text[5];
stringarrayCoDetails[6] = text[6];
java.awt.CardLayout card = (java.awt.CardLayout)pnlMain.getLayout();
card.show(pnlMain, "pnlCoDetail");
}
Step 2: I created a Lost Focus event listener for one field and am testing the current value of the field against the array:
private void txtName_CoDetailFocusLost(java.awt.event.FocusEvent evt) {
if (!(txtName_CoDetail.getText().equals(stringarrayCoDetails[1]))){
createEditBorder();
}
}
private void createEditBorder (){
Border border = BorderFactory.createLineBorder(Color.RED, 2);
txtName_CoDetail.setBorder(border);
}
Besides the general question of "is this an OK approach?", I would like to be able to pass the field name to the createEditBorder method so the listener for each data field can call it and I have one method for "edited text" formatting.

Categories

Resources