use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class BaseSpinner method createSeparator.
Component createSeparator() {
Label l = new Label(" ") {
public void repaint() {
getParent().repaint();
}
};
l.setUIID("SpinnerSeparator");
return l;
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class TimeSpinner method addComponents.
void addComponents() {
setLayout(new LayeredLayout());
LayeredLayout ll = (LayeredLayout) getLayout();
Container content = new Container(BoxLayout.x());
Style allStyles = content.getAllStyles();
allStyles.setMargin(0, 0, 0, 0);
allStyles.setPadding(0, 0, 0, 0);
allStyles.setBgTransparency(0);
allStyles.setBorder(Border.createEmpty());
if (amPM != null) {
content.addComponent(hour);
hourComponents.add(hour);
if (durationMode) {
Label l = new Label(getUIManager().localize("hours", "hours"));
l.setUIID("TimeSpinnerHoursLabel");
hourComponents.add(l);
content.addComponent(l);
}
content.addComponent(createSeparator());
content.addComponent(minute);
minuteComponents.add(minute);
if (durationMode) {
Label l = new Label(getUIManager().localize("minutes", "minutes"));
l.setUIID("TimeSpinnerMinutesLabel");
minuteComponents.add(l);
content.addComponent(l);
}
if (showMeridiem) {
content.addComponent(createSeparator());
content.addComponent(amPM);
}
}
setHoursVisible(showHours);
setMinutesVisible(showMinutes);
addComponent(content);
ll.setInsets(content, "0 auto 0 auto");
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class LiveDemo method start.
public void start() {
Form previewForm = new Form("Preview Theme");
Toolbar tb = new Toolbar();
previewForm.setToolbar(tb);
tb.setTitle("Preview Theme");
tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
previewForm.setLayout(new BorderLayout());
Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
first.addComponent(new Label("This is a Label"));
first.addComponent(new Button("This is a Button"));
MultiButton mb = new MultiButton("This is a MultiButton");
mb.setTextLine2("Second line of text");
FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
first.addComponent(mb);
TextField txt = new TextField();
txt.setHint("This is a TextField");
first.addComponent(txt);
first.addComponent(new CheckBox("This is a CheckBox"));
RadioButton rb1 = new RadioButton("This is a Radio Button 1");
rb1.setGroup("group");
first.addComponent(rb1);
RadioButton rb2 = new RadioButton("This is a Radio Button 2");
rb2.setGroup("group");
first.addComponent(rb2);
final Slider s = new Slider();
s.setText("50%");
s.setProgress(50);
s.setEditable(true);
s.setRenderPercentageOnTop(true);
first.addComponent(s);
Button b1 = new Button("Show a Dialog");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
}
});
first.addComponent(b1);
previewForm.add(BorderLayout.CENTER, first);
previewForm.show();
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ResourceEditorView method createFileChooser.
public static JFileChooser createFileChooser(final String label, final String... type) {
String dir = Preferences.userNodeForPackage(ResourceEditorView.class).get("lastDir", System.getProperty("user.home"));
JFileChooser chooser = new JFileChooser(dir);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
for (String s : type) {
if (f.getName().toLowerCase().endsWith(s)) {
return true;
}
}
return false;
}
@Override
public String getDescription() {
return label;
}
});
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
return chooser;
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class TimelineEditor method selectFile.
/**
* Selects a gif file using a file chooser and converts it to a timeline
*/
public static void selectFile(ResourceEditorView view, EditableResources res, String timelineName) {
File[] files = ResourceEditorView.showOpenFileChooser("Images", ".gif");
if (files != null) {
File sel = files[0];
if (timelineName == null) {
timelineName = sel.getName();
}
Preferences.userNodeForPackage(view.getClass()).put("lastDir", sel.getParentFile().getAbsolutePath());
ImageReader iReader = ImageIO.getImageReadersBySuffix("gif").next();
try {
iReader.setInput(ImageIO.createImageInputStream(new FileInputStream(sel)));
int frames = iReader.getNumImages(true);
AnimationObject[] anims = new AnimationObject[frames];
int currentTime = 0;
for (int frameIter = 0; frameIter < frames; frameIter++) {
BufferedImage currentImage = iReader.read(frameIter);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ImageIO.write(currentImage, "png", bo);
bo.close();
// create a PNG image in the resource file
String label = sel.getName() + " frame:" + frameIter;
EncodedImage i = EncodedImage.create(bo.toByteArray());
res.setImage(label, i);
int duration = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter));
Point pos = AnimationImpl.getPixelOffsets(iReader, frameIter);
anims[frameIter] = AnimationObject.createAnimationImage(i, pos.x, pos.y);
anims[frameIter].setStartTime(currentTime);
anims[frameIter].setEndTime(100000000);
String disposeMethod = getDisposalMethod(iReader, frameIter);
if (disposeMethod != null) {
if ("restoreToBackgroundColor".equals(disposeMethod)) {
if (frameIter + 1 < frames) {
int t = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter + 1));
anims[frameIter].setEndTime(currentTime + t);
} else {
anims[frameIter].setEndTime(currentTime + duration);
}
// for(int iter = frameIter ; iter >= 0 ; iter--) {
// anims[iter].setEndTime(currentTime);
// }
}
// "none" |
// "doNotDispose" | "restoreToBackgroundColor" |
// "restoreToPrevious"
}
currentTime += duration;
}
Timeline t = Timeline.createTimeline(currentTime, anims, new com.codename1.ui.geom.Dimension(iReader.getWidth(0), iReader.getHeight(0)));
res.setImage(timelineName, t);
view.setSelectedResource(timelineName);
} catch (IOException err) {
err.printStackTrace();
JOptionPane.showMessageDialog(JFrame.getFrames()[0], "Error reading file " + err, "IO Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Aggregations