Java Tutorial/Swing/Client Property
Each instance of every component can manage its own set of key/value pairs.
public final void putClientProperty(Object key, Object value) public final Object getClientProperty(Object key)
14. Swing»s Client Properties Summary Table
Class Accessed By Property Name Type AbstractButton hideActionText Boolean AbstractButton html / BasicHTML.propertyKey View BasicButtonListener initialDefaultButton JButton BasicButtonUI html / BasicHTML.propertyKey View BasicComboBoxUI JComboBox.isTableCellEditor / Boolean
BasicComboBoxUI.IS_TABLE_CELL_EDITOR
BasicEditorPaneUI JEditorPane.honorDisplayProperties / Boolean
JEditorPane.HONOR_DISPLAY_PROPERTIES
BasicEditorPaneUI JEditorPane.w3cLengthUnits / Boolean
JEditorPane.W3C_LENGTH_UNITS
BasicHTML html / BasicHTML.propertyKey View BasicHTML html.disable / Boolean
BasicLabelUI html / BasicHTML.propertyKey View BasicListUI List.isFileList Boolean BasicMenuItemUI html / BasicHTML.propertyKey View BasicMenuItemUI maxTextWidth / Integer
BasicMenuItemUI.MAX_TEXT_WIDTH
BasicMenuItemUI maxAccWidth / Integer
BasicMenuItemUI.MAX_ACC_WIDTH
BasicPopupMenuUI doNotCancelPopup Boolean BasicRadioButtonUI html / BasicHTML.propertyKey View BasicRootPaneUI temporaryDefaultButton Object BasicSliderUI Slider.paintThumbArrowShape Boolean BasicTabbedPaneUI __index_to_remove__ Integer BasicTableUI Table.isFileList Boolean BasicTextUI JPasswordField.cutCopyAllowed Boolean BasicToggleButtonUI html / BasicHTML.propertyKey View BasicToolBarUI JToolBar.focusedCompIndex / Integer
BasicToolBarUI. FOCUSED_COMP_INDEX
BasicToolBarUI JToolBar.isRollover / Boolean
BasicToolBarUI. IS_ROLLOVER
BasicToolTipUI html / BasicHTML.propertyKey View BluePrintEngine __arrow_direction__ Integer DefaultCaret caretAspectRatio Number DefaultCaret caretWidth Integer DefaultCaret JPasswordField.cutCopyAllowed Boolean DefaultDesktopManager JDesktopPane.dragMode String; valid values are null, outline, and faster FrameView charset String GTKFileChooserUI GTKFileChooser.showDirectoryIcons Boolean GTKFileChooserUI GTKFileChooser.showFileIcons Boolean JInternalFrame wasIconOnce / Boolean
DefaultDesktopManager.HAS_BEEN_ICONIFIED_PROPERTY
JComponent nextFocus / JComponent.NEXT_FOCUS Component JComponent InputVerifier / InputVerifier
JComponent.INPUT_VERIFIER_KEY
JComponent _WhenInFocusedWindow / Hashtable
JComponent.WHEN_IN_FOCUSED_WINDOW_BINDINGS
JComponent ToolTipText / String
JComponent.TOOL_TIP_TEXT_KEY
JComponent TransferHandler / TransferHandler
JComponent.TRANSFER_HANDLER_KEY
JComponent AncestorNotifier / AncestorNotifier
JComponent.ANCESTOR_NOTIFIER_KEY
JComponent labeledBy / JComponent / Accessible
JLabel.LABELED_BY_PROPERTY
JEditorPane charset String JLabel html / BasicHTML.propertyKey View JLayeredPane layeredContainerLayer / Integer
JLayeredPane.LAYER_PROPERTY
JPasswordField JPasswordField.cutCopyAllowed Boolean JPopupMenu JPopupMenu.firePopupMenuCanceled Boolean JTable JTable.autoStartsEdit Boolean JTable terminateEditOnFocusLost Boolean JToolBar JToolBar.isRollover Boolean MetalBorders NoButtonRollover / Boolean
MetalBorders.NO_BUTTON_ROLLOVER
MetalBorders JInternalFrame.messageType Integer MetalFileChooserUI FileChooser.useShellFolder Boolean MetalIconFactory paintActive Boolean MetalInternalFrame TitlePane JInternalFrame.messageType Integer MetalInternalFrameUI JInternalFrame.isPalette / Boolean
MetalInternalFrameUI.IS_PALETTE
MetalRadioButtonUI html / BasicHTML.propertyKey View MetalScrollBarUI JScrollBar.isFreeStanding / Boolean
MetalScrollBarUI.FREE_STANDING_PROP
MetalSliderUI JSlider.isFilled / Boolean
MetalTreeUI JTree.lineStyle / String; valid values are Angled (MetalTreeUI. LEG_LINE_STYLE_STRING), Horizontal (MetalTreeUI .HORIZ_STYLE_STRING), and None (MetalTreeUI. NO_STYLE_STRING)
MotifGraphicsUtils html / BasicHTML.propertyKey View MotifGraphicsUtils maxAccWidth / Integer
MotifGraphicsUtils.MAX_ACC_WIDTH
PopupFactory __force_heavy_weight_popup__ / Boolean
PopupFactory.forceHeavyWeightPopupKey
SpringLayout SpringLayout.class SpringLayout. Constraints SwingUtilities html / BasicHTML.propertyKey View SynthEditorPaneUI JEditorPane.honorDisplayProperties / Boolean
JEditorPane.HONOR_DISPLAY_PROPERTIES
SynthGraphicUtils html / BasicHTML.propertyKey View SynthMenuItemUI html / BasicHTML.propertyKey View SynthToolTipUI html / BasicHTML.propertyKey View WindowsDesktopManager JInternalFrame.frameType String; valid values are null and optionDialog WindowsFileChooserUI FileChooser.useShellFolder Boolean WindowsSliderUI Slider.paintThumbArrowShape Boolean WindowsToolBarUI XPStyle.subclass String
14. Using JTree client property: Produce horizontal lines between level-one nodes
import java.awt.BorderLayout; import java.awt.Color; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.UIManager; class TreeNodeVector extends Vector
String name; TreeNodeVector(String name) < this.name = name; >TreeNodeVector(String name, E elements[]) < this.name = name; for (int i = 0, n = elements.length; i < n; i++) < add(elements[i]); >> public String toString()
> public class ChangingTreeLineStyleColorHorizontal
public static void main(final String args[]) < JFrame frame = new JFrame("JTreeSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vectorv1 = new TreeNodeVector("Two", new String[] < "Mercury", "Venus", "Mars" >); Vector v2 = new TreeNodeVector("Three"); v2.add(System.getProperties()); v2.add(v1); Object rootNodes[] = ; Vector rootVector = new TreeNodeVector("Root", rootNodes); JTree tree = new JTree(rootVector); UIManager.put("Tree.line", Color.GREEN); tree.putClientProperty("JTree.lineStyle", "Horizontal"); frame.add(new JScrollPane(tree), BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); >
Java Client property(String name, Object value)
Java Client property(String name, Object value) Set the new configuration property, if already set, the existing value of the property will be updated.
Introduction
Set the new configuration property, if already set, the existing value of the property will be updated. Setting a null value into a property effectively removes the property from the property bag.
Syntax
The method property() from Client is declared as:
public C property(String name, Object value);
The method property() has the following parameter:
- Stringname — property name.
- Objectvalue — (new) property value. null value removes the property with the given name.
The method property() returns the updated configurable instance.
Example
The following code shows how to use Client from javax.ws.rs.client.
Specifically, the code shows you how to use Java Client property(String name, Object value)
import java.net.URI; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import org.glassfish.jersey.client.ClientProperties; import org.piccolo.Configuration; import org.piccolo.Configuration.Setting; import org.piccolo.auth.AuthorizationController; import com.owlike.genson.Genson; /**/* w w w . d em o 2 s . c o m*/ * Controls the authorizations */ public class AuthorizationControllerImpl implements AuthorizationController < private int timeout; private URI serviceBaseUri; public AuthorizationControllerImpl(Configuration configuration) < serviceBaseUri = UriBuilder.fromUri(configuration.getSetting(Setting.AUTH_SERVICE_URI)).build(); timeout = Integer.parseInt(configuration.getSetting(Setting.AUTH_SERVICE_TIMEOUT)); > public boolean requestAccess(String id) < try < Client client = ClientBuilder.newClient(); client.property(ClientProperties.CONNECT_TIMEOUT, timeout); client.property(ClientProperties.READ_TIMEOUT, timeout); WebTarget webTarget = client.target(serviceBaseUri); Builder builder = webTarget.path("piccoloUser").path("canAccess").path(id).request() .accept(MediaType.APPLICATION_JSON); Response response = builder.get(); String responseString = response.readEntity(String.class); ServiceResponse serviceResponse = new Genson.Builder().create().deserialize(responseString, ServiceResponse.class); return serviceResponse.isIsallowed(); > catch (Exception e) < e.printStackTrace(); return false; > > /** * Tests accessing the service. * @param args required by API, not used. */ public static void main(String. args) < AuthorizationController authorizationController = new AuthorizationControllerImpl(new Configuration()); System.out.println(authorizationController.requestAccess("1234")); > public static class ServiceResponse < private boolean isallowed; public boolean isIsallowed() < return isallowed; > public void setIsallowed(boolean isallowed) < this.isallowed = isallowed; > > >
import org.codehaus.jackson.map.ObjectMapper; import javax.imageio.ImageIO; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.core.*; import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /**/* w w w . d e m o 2 s . co m */ * Created by redi on 6/1/15. */ public class ConsumerMain < public static void main(String. args) throws IOException < Client client = ClientBuilder.newClient(); client.property("TestProperty", "TestValue"); Response res = client.target("http://localhost:8080/soa-web/test/hello").request("application/json").get(); String message = res.readEntity(String.class); ObjectMapper objectMapper = new ObjectMapper(); Student student = objectMapper.readValue(message, Student.class); System.out.println(student.getFirstName() + ": " + student.getLastName()); System.out.println("/test/hello: " + message); res = client.target("http://localhost:8080/soa-web/test/hello?id=5").request("application/json").get(); message = res.readEntity(String.class); System.out.println("/test/hello?id=5: " + message); res = client.target("http://localhost:8080/soa-web/test/lista").request("application/json").get(); message = res.readEntity(String.class); System.out.println("/test/lista: " + message); res = client.target("http://localhost:8080/soa-web/test/img").request("image/png").get(); byte[] imageData = res.readEntity(byte[].class); InputStream in = new ByteArrayInputStream(imageData); BufferedImage image = ImageIO.read(in); ImageIO.write(image, "png", new File("downloadedImage.png")); Form form = new Form(); form.param("id", "wartoscid"); res = client.target("http://localhost:8080/soa-web/test/post").request("application/json") .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); message = res.readEntity(String.class); System.out.println("/test/post: " + message); res = client.target("http://localhost:8080/soa-web/test/pdf").request("document/pdf").get(); final Path destination = Paths.get("downloadedPDF.pdf"); try < final InputStream inputStream = res.readEntity(InputStream.class); Files.copy(inputStream, destination); inputStream.close(); > catch (Exception e) < System.out.println("file exists"); > form = new Form(); form.param("username", "admin"); form.param("password", "haslo"); res = client.target("http://localhost:8080/soa-web/test/validate").request() .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); System.out.println("Validation: " + res); res = client.target("http://localhost:8080/soa-web/test/helloSecured").request("application/json").get(); message = res.readEntity(String.class); // System.out.println("/test/helloSecured: " + message); > >
import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import com.toastedbits.plugins.codeconnect.Neo4jDefaults; public class JerseyClientFactory < public static Client buildClient(final String username, final String password) < Client client = ClientBuilder.newClient(); //Only provide auth if at least one of username or password was provided //Fallback to default neo4j credentials if only one of username/passowrd was specified for the other param if (StringUtils.isNotEmpty(username) || StringUtils.isNotEmpty(password)) < String uname = username; if (StringUtils.isEmpty(uname)) < uname = Neo4jDefaults.USER; >// w w w. d e m o 2s .c o m String pword = password; if (StringUtils.isEmpty(pword)) < pword = Neo4jDefaults.PASSWORD; >HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(uname, pword); client.register(feature); > int connectTimeout = Integer.parseInt( System.getProperty(CodeConnectConfig.CONNECT_TIMEOUT, CodeConnectConfig.CONNECT_TIMEOUT_DEFAULT)); int readTimeout = Integer.parseInt( System.getProperty(CodeConnectConfig.READ_TIMEOUT, CodeConnectConfig.READ_TIMEOUT_DEFAULT)); client.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout); client.property(ClientProperties.READ_TIMEOUT, readTimeout); return client; > >
Related
- Java Client target(UriBuilder uriBuilder)
- Java Client target(Link link)
- Java Client register(Class componentClass)
- Java Client property(String name, Object value)
- Java Client close()
- Java Client getConfiguration()
- Java Client register(Class componentClass, int priority)
demo2s.com | Email: | Demo Source and Support. All rights reserved.