Java源码示例:org.apache.pivot.wtk.Label
示例1
@Override
public void startup(final Display display, Map<String, String> map) throws Exception {
MosaicPane mosaicPane = new MosaicPane();
mosaicPane.getComponentKeyListeners().add(getKeyListener());
ModelLoader loader = new ModelLoader(map.get("file"));
String[] model = loader.getModel(map.get("surface"));
System.out.println("model.length = " + model.length);
int i = 0;
for(String def : model) {
String[] args = def.split("[\\s]*\\,[\\s]*");
int offset = args.length > 4 ? args.length - 4 : 0;
String id = args.length == 4 ? "" + (i++) : args[0];
Label l = getLabel(i > 4 ? colors[random.nextInt(5)] : colors[i], id);
mosaicPane.add(l, id,
Double.parseDouble(args[offset + 0]),
Double.parseDouble(args[offset + 1]),
Double.parseDouble(args[offset + 2]),
Double.parseDouble(args[offset + 3]));
clientMap.put(id, l);
}
//Now that we've added the definitions and components to the Surface we can add it to the Engine.
mosaicPane.getEngine().addSurface(mosaicPane.getSurface());
window.setContent(mosaicPane);
window.setTitle("Mosaic Layout Engine Demo (Pivot)");
window.setMaximized(true);
window.open(display);
addMouseHandler(mosaicPane);
}
示例2
private void moveCursor(MosaicPane pane, Component source, int dir) {
switch(dir) {
case 37 : pane.getSurface().cursorLeft();break;
case 38 : pane.getSurface().cursorUp();break;
case 39 : pane.getSurface().cursorRight();break;
case 40 : pane.getSurface().cursorDown();break;
}
Label l = (Label)clientMap.get(pane.getSurface().getCursor());
System.out.println("component at cursor = " + l);
pane.getSurface().requestMoveCancel(source);
pane.getSurface().requestMoveBegin(l);
}
示例3
public Label getLabel(Color c, String text) {
Label label = new Label();
label.setText(text);
label.getStyles().put("font", new Font("Arial", Font.BOLD, 24));
label.getStyles().put("color", Color.WHITE);
label.getStyles().put("backgroundColor", c);
label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
label.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
return label;
}
示例4
private ComponentKeyListener getKeyListener() {
if(listener == null) {
listener = new ComponentKeyListener.Adapter() {
Component source = null;
@Override
public boolean keyTyped(Component component, char character) {
releaseShift();
return false;
}
@Override
public boolean keyPressed(Component paramComponent, int paramInt,
KeyLocation paramKeyLocation) {
System.out.println("keyPressed paramComp = " + paramComponent);
System.out.println("keyPressed paramInt = " + paramInt);
System.out.println("keyPressed paramKeyLocation " + paramKeyLocation);
if(paramKeyLocation == KeyLocation.LEFT && paramInt == 16) {
System.out.println("press shift");
pressShift();
}else if(paramKeyLocation == KeyLocation.STANDARD && paramInt == 9) {
System.out.println("press tab");
MosaicPane pane = (MosaicPane)paramComponent;
Label l = (Label)clientMap.get(pane.getSurface().getCursor());
source = l;
pane.getSurface().requestMoveBegin(l);
}else if(paramKeyLocation == KeyLocation.STANDARD && paramInt == 10) {
MosaicPane pane = (MosaicPane)paramComponent;
pane.getSurface().requestMoveCommit(source, null, null);
}else if(paramKeyLocation == KeyLocation.STANDARD && paramInt == 27) {
MosaicPane pane = (MosaicPane)paramComponent;
pane.getSurface().requestMoveCancel(source);
}else if(paramKeyLocation == KeyLocation.STANDARD && paramInt >= 37 && paramInt <= 40) {
moveCursor((MosaicPane)paramComponent, source, paramInt);
}else{
System.out.println("release shift");
releaseShift();
}
return false;
}
@Override
public boolean keyReleased(Component paramComponent, int paramInt,
KeyLocation paramKeyLocation) {
if(paramKeyLocation == KeyLocation.LEFT && paramInt == 16) {
System.out.println("release shift");
releaseShift();
}else if(paramKeyLocation == KeyLocation.STANDARD && paramInt == 9) {
System.out.println("release tab");
}else{
System.out.println("release shift");
releaseShift();
}
return false;
}
};
}
return listener;
}