use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class DateTimeSpinner3D method calcPreferredSize.
@Override
protected Dimension calcPreferredSize() {
Dimension size = super.calcPreferredSize();
Label l = new Label("Thu Dec 27 55 55 AM", "Spinner3DRow");
size.setWidth((int) (l.getPreferredW() * 1.5f + convertToPixels(10f)));
return size;
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class DateTimeSpinner3D method initSpinner.
void initSpinner() {
if (date == null) {
date = Spinner3D.createDate(startDate.getTime() + off, endDate.getTime() + off, currentDate.getTime());
date.setPreferredW((int) (new Label("Thu Dec 27", "Spinner3DRow").getPreferredW() * 1.5f));
Style dateStyle = Style.createProxyStyle(date.getRowStyle(), date.getSelectedRowStyle());
dateStyle.setAlignment(Component.RIGHT);
dateStyle.setPaddingRight(3f);
this.setCurrentDate(currentDate);
this.setStartDate(startDate);
this.setEndDate(endDate);
time = new TimeSpinner3D();
// getUnselectedStyle().setBgColor(date.getUnselectedStyle().getBgColor());
// getUnselectedStyle().setBgTransparency(255);
addComponents();
}
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class Validator method trimLongString.
/**
* Long error messages are trimmed to fit the available space in the layout
*
* @param errorMessage the string to be trimmed
* @param uiid the uiid of the errorMessage
* @param width the maximum width
* @return the new String trimmed to fit the available width
*/
private String trimLongString(String errorMessage, String uiid, int width) {
Label errorLabel = new Label(errorMessage, uiid);
while (errorLabel.getPreferredW() > width && errorMessage.length() > 1) {
errorMessage = errorMessage.substring(0, errorMessage.length() - 1);
errorLabel.setText(errorMessage);
}
return errorMessage;
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class JavaSEPort method downloadSkin.
private File downloadSkin(File skinDir, String url, String version, JLabel label) throws IOException {
String fileName = url.substring(url.lastIndexOf("/"));
File skin = new File(skinDir.getAbsolutePath() + "/" + fileName);
HttpURLConnection.setFollowRedirects(true);
URL u = new URL(url);
FileOutputStream os = new FileOutputStream(skin);
URLConnection uc = u.openConnection();
InputStream is = uc.getInputStream();
int length = uc.getContentLength();
byte[] buffer = new byte[65536];
int size = is.read(buffer);
int offset = 0;
int percent = 0;
String msg = label.getText();
if (length > 0) {
System.out.println("Downloading " + length + " bytes");
}
while (size > -1) {
offset += size;
if (length > 0) {
float f = ((float) offset) / ((float) length) * 100;
if (percent != ((int) f)) {
percent = (int) f;
label.setText(msg + " " + percent + "%");
label.repaint();
}
} else {
if (percent < offset / 102400) {
percent = offset / 102400;
System.out.println("Downloaded " + percent + "00Kb");
}
}
os.write(buffer, 0, size);
size = is.read(buffer);
}
is.close();
os.close();
// store the skin version
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put(fileName, version);
return skin;
}
use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.
the class GameCanvasImplementation method captureAudio.
public void captureAudio(ActionListener response) {
captureResponse = response;
try {
final Form current = Display.getInstance().getCurrent();
final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
if (record == null) {
player.cleanup();
throw new RuntimeException("Capture Audio is not supported on this device");
}
final Form cam = new Form();
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
player.play();
final Label time = new Label("0:00");
cam.addComponent(BorderLayout.SOUTH, time);
cam.revalidate();
ActionListener l = new ActionListener() {
boolean recording = false;
OutputStream out = null;
String audioPath = null;
RecordControl record;
public void actionPerformed(ActionEvent evt) {
if (!recording) {
record = (RecordControl) player.nativePlayer.getControl("RecordControl");
recording = true;
String type = record.getContentType();
String prefix = "";
if (type.endsWith("wav")) {
prefix = ".wav";
} else if (type.endsWith("amr")) {
prefix = ".amr";
} else if (type.endsWith("3gpp")) {
prefix = ".3gp";
}
audioPath = getOutputMediaFile() + prefix;
try {
out = FileSystemStorage.getInstance().openOutputStream(audioPath);
record.setRecordStream(out);
record.startRecord();
cam.registerAnimated(new Animation() {
long current = System.currentTimeMillis();
long zero = current;
int sec = 0;
public boolean animate() {
long now = System.currentTimeMillis();
if (now - current > 1000) {
current = now;
sec++;
return true;
}
return false;
}
public void paint(Graphics g) {
String txt = sec / 60 + ":" + sec % 60;
time.setText(txt);
}
});
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("failed to store audio to " + audioPath);
} finally {
}
} else {
if (out != null) {
try {
record.stopRecord();
record.commit();
out.close();
player.cleanup();
} catch (Exception ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(audioPath));
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
cam.addPointerReleasedListener(l);
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException("failed to start camera");
}
}
Aggregations