org.apache.pivot.wtk.Label Java Examples

The following examples show how to use org.apache.pivot.wtk.Label. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MosaicPaneRefImpl.java    From Mosaic with Apache License 2.0 5 votes vote down vote up
@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);
  }
 
Example #2
Source File: MosaicPaneRefImpl.java    From Mosaic with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: MosaicPaneRefImpl.java    From Mosaic with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: MosaicPaneRefImpl.java    From Mosaic with Apache License 2.0 4 votes vote down vote up
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;
}