I'm learning new features of Java 8 with the book Java SE 8 for the Really Impatient
On the pages 76 and 77 the author says:
We always want the circle centered in the scene.
...
When the scene width changes, so does
that property. All that remains is to bind that computed property to
the circle’s centerX property:
circle.centerXProperty().bind(Bindings.divide(scene.widthProperty(),
2));
As there was no complete runnable sample I created my own. Here is it:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Exercise0404 extends Application {
#Override
public void start(Stage stage) throws Exception {
Circle circle = new Circle(50);
FlowPane pane = new FlowPane(circle);
Scene scene = new Scene(pane);
circle.centerXProperty().bind(scene.widthProperty().divide(2));
circle.centerYProperty().bind(scene.heightProperty().divide(2));
stage.setScene(scene);
stage.setTitle("Hello");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
But if I run the code and resize the scene the circle doesn't move to the center. Do I miss anything?
You are putting your circle in a FlowPane which in charge of the layout.
When you use absolute positioning, prefer the use of an adequate pane: javafx.scene.layout.Pane. From Pane javadoc:
This class may be used directly in cases where absolute positioning of children is required since it does not perform layout beyond resizing resizable children to their preferred sizes.
You just have to change the FlowPane to a Pane and it will work.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Exercise0404 extends Application {
#Override
public void start(Stage stage) throws Exception {
Circle circle = new Circle(50);
Pane pane = new Pane(circle);
Scene scene = new Scene(pane);
circle.centerXProperty().bind(scene.widthProperty().divide(2));
circle.centerYProperty().bind(scene.heightProperty().divide(2));
stage.setScene(scene);
stage.setTitle("Hello");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Related
I used this library:
path_provider 1.5.1
It's working fine
but the pdf file not opened in full screen
Did you try flutter_full_pdf_viewer library?
import 'package:flutter/material.dart';
import 'package:flutter_full_pdf_viewer/flutter_full_pdf_viewer.dart';
class ShowPdfPage extends StatelessWidget {
String pdfPath;
#override
Widget build(BuildContext context) {
pdfPath = //your awesome path retrieved with path_provider;
return PDFViewerScaffold(path: pdfPath);
}
}
In Vaadin Flow, there exists no Component that is essentially a Scrollable Layout.
In Vaadin 8, this was done by the Panel.
Is there a way to achieve a scrollable Component in Vaadin Flow?
Edit: I have now published an add-on here that provides the class VerticalScrollLayout, and also the class HorizontalScrollLayout. If there are suggestions for improvements, feel free to contact me or comment here.
Yes it is possible, although there is no existing Component that does it automatically.
The way to go is placing a VerticalLayout (for a vertical scroll bar) inside another component, and setting the display property of that VerticalLayout from flex to block. (credits to Diego Sanz Villafruela in the vaadin forum)
I have made my own VerticalScrollLayout class that does it all for you, so that using it in a view is as easy as using a simple VerticalLayout
public class VerticalScrollLayout extends VerticalLayout {
private VerticalLayout content;
public VerticalScrollLayout(){
preparePanel();
}
public VerticalScrollLayout(Component... children){
preparePanel();
this.add(children);
}
private void preparePanel() {
setWidth("100%");
setHeight("100%");
getStyle().set("overflow", "auto");
content = new VerticalLayout();
content.getStyle().set("display", "block");
content.setWidth("100%");
content.setPadding(false);
super.add(content);
}
public VerticalLayout getContent(){
return content;
}
#Override
public void add(Component... components){
content.add(components);
}
#Override
public void remove(Component... components){
content.remove(components);
}
#Override
public void removeAll(){
content.removeAll();
}
#Override
public void addComponentAsFirst(Component component) {
content.addComponentAtIndex(0, component);
}
}
There is now an official component for scrolling:
https://vaadin.com/docs/latest/components/scroller
For some reason I can't work out yet, my agent doesn't intercept java LinkageError instances.
Agent code:
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.SuperMethodCall;
import net.bytebuddy.matcher.ElementMatchers;
import java.lang.instrument.Instrumentation;
public class MyAgent {
public static void premain(String arguments, Instrumentation instrumentation) {
new AgentBuilder.Default()
.type(ElementMatchers.isSubTypeOf(LinkageError.class))
.transform((builder, type, classLoader, module) ->
builder.constructor(ElementMatchers.isDefaultConstructor())
.intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(MyInterceptor.class)))
).installOn(instrumentation);
}
}
Interceptor code:
public class MyInterceptor {
#RuntimeType
public static void intercept(#Origin Constructor<?> constructor) throws Exception {
System.out.println("Intercepted: " + constructor.getName());
}
}
Test code:
public static void main(String[] args) {
new NoClassDefFoundError("should be intercepted!!!").toString();
new Foo("oh").toString();
}
What is puzzling is that replacing ElementMatchers.isSubTypeOf(LinkageError.class) with ElementMatchers.nameContains("Foo") gives the expected result and Foo constructor is intercepted.
The NoClassDefFoundError is loaded by the bootstrap loader. It willnot be able to see your interceptor class which is why it is never triggered.
Try using the Advice class (as a visitor) to add bytecode to matched classes which should resolve this problem.
May i know how to init global variables in play framework? if can show in Japid is the best.
Appreciate your help.
Thanks
I found the solution.
Below is my example:
I create a class and extends to Action.Simple
package common;
import play.Play;
import play.mvc.Action;
import play.mvc.Http.Context;
import play.mvc.Result;
public class Init extends Action.Simple{
#Override
public Result call(Context ctx) throws Throwable {
ctx.args.put("resourcesurl", Play.application().configuration().getString("resources.url"));
return delegate.call(ctx);
}
}
and this is my controller:
#With(Init.class)
public class Museum extends JapidController{
public static Result nes(){
return renderJapid();
}
}
at my html:
<img src="${Context.current().args.get("resourcesurl")}/resources/test.jpg"/>
hope this help others as well.
Good day,
I am writing to you because I tried to follow your instructions [here: http://wiki.eclipse.org/CDT/cdt-debug-dsf-gdb-extensibility ] for adding a new command to gdb while using cdt eclipse.
I does not seem to work at all. I put print statements in all of the methods of all the extended classes. Nothing gets printed, which indicates that none of these methods are called. Following is my code. What am I missing?
(i didn't get to the point of actually implementing the new services factory since i there
plugin.xml:
<plugin>
<extension
point="org.eclipse.debug.core.launchDelegates">
<launchDelegate
delegate="tracerdubug.MyTracerLaunchDelegate"
id="TracerDubug.MyTracerLaunchDelegate"
modes="debug, run">
</launchDelegate>
</extension>
</plugin>
TracerRunControl:
public class TracerRunControl extends GDBRunControl_7_0 {
public TracerRunControl(DsfSession session) {
super(session);
System.out.println("TracerRunControl");
}
}
//################################################################
public class MyTracerLaunchDelegate extends GdbLaunchDelegate implements ILaunchConfigurationDelegate2{
public MyTracerLaunchDelegate() {
super();
System.out.println("MyTracerLaunchDelegate::ctr()");
}
#Override
public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor ) throws CoreException {
System.out.println("MyTracerLaunchDelegate::launch()");
super.launch(config, mode, launch, monitor);
}
#Override
protected IDsfDebugServicesFactory newServiceFactory(String version) {
System.out.println("MyTracerLaunchDelegate");
return new TracerDebugServicesFactory(version);
}
}
//################################################################
public class TracerDebugServicesFactory extends GdbDebugServicesFactory {
public TracerDebugServicesFactory(String version) {
super(version);
// TODO Auto-generated constructor stub
}
#Override
protected ICommandControl createCommandControl(DsfSession session, ILaunchConfiguration config) {
GDBControl_7_0 g = new GDBControl_7_0(session,config);
System.out.println("TracerDebugServicesFactory::createCommandControl");
return g;
}
#Override
protected IRunControl createRunControlService(DsfSession session) {
System.out.println("TracerDebugServicesFactory::createProcessesService");
return new TracerRunControl(session);
}
#Override
protected IProcesses createProcessesService(DsfSession session) {
System.out.println("TracerDebugServicesFactory::createProcessesService");
return new GDBProcesses_7_0(session);
}
}
Thanks,
Shai
I had the same problem and got the answer from another forum. You must add more info and more extensions:
<extension
point="org.eclipse.debug.core.launchDelegates">
<launchDelegate
delegate="tracerdubug.MyTracerLaunchDelegate"
delegate="Tracerdubug.MyTracerLaunchDelegate"
delegateDescription="Your description"
id="org.eclipse.cdt.dsf.gdb.launch.localCLaunch"
modes="debug"
name="My GDB Launch Delegate"
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"
type="org.eclipse.cdt.launch.applicationLaunchType">
</launchDelegate>
</extension>
<extension point="org.eclipse.debug.ui.launchConfigurationTypeImages">
<launchConfigurationTypeImage
icon="icons/img.gif"
configTypeID="Tracerdubug.MyTracerLaunchDelegate"
id="Tracerdubug.TabGroups.launcher.Image">
</launchConfigurationTypeImage>
</extension>
<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
type="Tracerdubug.MyTracerLaunchDelegate"
class="Tracerdubug.TabGroups.TabGroupTest"
id="Tracerdubug.TabGroups.TabGroupTest">
</launchConfigurationTabGroup>
</extension>
and you need a new class = Tracerdubug.TabGroups.TabGroupTest:
package Tracerdubug.TabGroups;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.CDebuggerTab;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.CMainAttachTab;
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.AttachCDebuggerTab;
import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.EnvironmentTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class TabGroupTest extends AbstractLaunchConfigurationTabGroup {
// Create an array of tabs to be displayed in the debug dialog
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs =
new ILaunchConfigurationTab[] {,
new CMainAttachTab(),
new CArgumentsTab(),
new EnvironmentTab(),
new SourceLookupTab(),
new CommonTab(),
};
setTabs(tabs);
}
}
You can also create your own tabs, see: http://www.eclipse.org/articles/Article-Launch-Framework/launch.html
My command factory is loaded, I'm now learning how to use an existing service to send the command...