I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon.
public void mouseClicked(MouseEvent e) {
polygon.addPoint(e.getX(), e.getY());
repaint();
}
But I don't know if this is the best way to draw custom shapes.
It should be possible to edit a drawn shape:
resize
change its fill color
change the stroke color
copy/paste it
move a single point of the polygon
...
I have seen people creating an own class implementing the Shape class and using a GeneralPath. But again I have no idea if this is a good way.
Now I can create my own shape with a polygon (or with a GeneralPath) but I have no clue how to attach all the edit functions to my own shape (the edit functions I mean the resize, move, etc from above).
I hope somebody could show me a way to do this or maybe write a little bit of code to demonstrate this.
Thanks in advance!!
Many years ago when I was at uni they said to put a capital i (I) in front of interfaces. Is this still a convention because I see many interfaces that do not follow this.
Hi all,
I have a small piece of code which basically impements a HTTP-Client,
i.e. it POSTS request and works with re RESPONSE. As long as HTTP is
concenerned everthing work well. For some reason I now have to support
HTTPS too. So here is briefly what I do in order to get a connection opened:
URL url = new URL(serverAddress);
HttpsURLConnection httpsConn = (HttpsURLConnection) url.openConnection();
This fails, stating:
sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to com.sun.net.ssl.HttpsURLConnection
I guess this is kinda trivial, but I just don't get what I'm doing wrong in this one...
Googled it, and the code just looks right - not?
any ideas are appreciated!
thanks,
K
Hi,
I need to decide which configuration framework to use. At the moment I am thinking between using properties files and XML files. My configuration needs to have some primitive grouping, e.g. in XML format would be something like:
<configuration>
<group name="abc">
<param1>value1</param1>
<param2>value2</param2>
</group>
<group name="def">
<param3>value3</param3>
<param4>value4</param4>
</group>
</configuration>
or a properties file (something similar to log4j.properties):
group.abc.param1 = value1
group.abc.param2 = value2
group.def.param3 = value3
group.def.param4 = value4
I need bi-directional (read and write) configuration library/framework. Nice feature would be - that I could read out somehow different configuration groups as different objects, so I could later pass them to different places, e.g. - reading everything what belongs to group "abc" as one object and "def" as another. If that is not possible I can always split single configuration object into smaller ones myself in the application initialization part of course.
Which framework would best fit for me?
In the course of my work i need to develop an authorization engine ( i'm already authenticated and i check access of a user to an action ) in order to store all the authorization logic inside a same place and be able to reuse it and i have created the mini library.
http://github.com/eltados/canny (updated)
what do you think about it? What are the limits of my approch ?
Do you understand the benefit or it?
Is there any lightweight Authorization engine library i could have a look at?
I had a look at spring security and it does not really answer my requirement. The main idea is that i want to be able to reuse the same code to controll access in the controllers and the views.
I came across this code today whilst reading Accelerated GWT (Gupta) - page 151.
public static void getListOfBooks(String category, BookStore bookStore) {
serviceInstance.getBooks(category, bookStore.new BookListUpdaterCallback());
}
public static void storeOrder(List books, String userName, BookStore bookStore) {
serviceInstance.storeOrder(books, userName, bookStore.new StoreOrderCallback());
}
What are those new operators doing there? I've never seen such syntax, can anyone explain?
when coding. try to solve the puzzle:
how to design the class/methods when InputStreamDigestComputor throw IOException?
It seems we can't use this degisn structure due to the template method throw exception but overrided method not throw it. but if change the overrided method to throw it, will cause other subclass both throw it.
So can any good suggestion for this case?
abstract class DigestComputor{
String compute(DigestAlgorithm algorithm){
MessageDigest instance;
try {
instance = MessageDigest.getInstance(algorithm.toString());
updateMessageDigest(instance);
return hex(instance.digest());
} catch (NoSuchAlgorithmException e) {
LOG.error(e.getMessage(), e);
throw new UnsupportedOperationException(e.getMessage(), e);
}
}
abstract void updateMessageDigest(MessageDigest instance);
}
class ByteBufferDigestComputor extends DigestComputor{
private final ByteBuffer byteBuffer;
public ByteBufferDigestComputor(ByteBuffer byteBuffer) {
super();
this.byteBuffer = byteBuffer;
}
@Override
void updateMessageDigest(MessageDigest instance) {
instance.update(byteBuffer);
}
}
class InputStreamDigestComputor extends DigestComputor{
// this place has error. due to exception. if I change the overrided method to throw it. evey caller will handle the exception. but
@Override
void updateMessageDigest(MessageDigest instance) {
throw new IOException();
}
}
I was trying to match files in a directory that had two dots in their name, something like theme.default.properties
I thought the pattern .\\..\\.. should be the required pattern [. matches any character and \. matches a dot] but it matches both oneTwo.txt and theme.default.properties
I tried the following:
[resources/themes has two files oneTwo.txt and theme.default.properties]
1.
public static void loadThemes()
{
File themeDirectory = new File("resources/themes");
if(themeDirectory.exists())
{
File[] themeFiles = themeDirectory.listFiles();
for(File themeFile : themeFiles)
{
if(themeFile.getName().matches(".\\..\\.."));
{
System.out.println(themeFile.getName());
}
}
}
}
This prints nothing
and the following
File[] themeFiles = themeDirectory.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.matches(".\\..\\..");
}
});
for (File file : themeFiles)
{
System.out.println(file.getName());
}
prints both
oneTwo.txt
theme.default.properties
I am unable to find why these two give different results and which pattern I should be using to match two dots...
Can someone help?
I have an Enum for Days of week (with Everyday, weekend and weekdays) as follows where each entry has an int value.
public enum DaysOfWeek {
Everyday(127),
Weekend(65),
Weekdays(62),
Monday(2),
Tuesday(4),
Wednesday(8),
Thursday(16),
Friday(32),
Saturday(64),
Sunday(1);
private int bitValue;
private DaysOfWeek(int n){
this.bitValue = n;
}
public int getBitValue(){
return this.bitValue;
}
}
Given a TOTAL of any combination of the entries, what would be the simplest way to calculate all individual values and make an arraylist from it. For example given the number 56 (i.e. Wed+Thur+Fri), how to calculate the list of individual values.
I've looked all around and decided to make my own library for accessing the EVE API.
Requests are sent to a server address such as /account/Characters.xml.aspx. Characters.xml.aspx requires two item be submitted in POST and then it returns an XML file. So far I have this but it does not work, probably becuase I am using GET instead of POST:
//Get the API data
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
String url = "http://api.eveonline.com/account/Characters.xml.aspx?userID="+
userID+"?apiKey="+key;
Document doc = builder.parse(url);
How would I go about being able to parst an XML file that is generated by submitting variables in POST?
Hello everyone
Didn't want to bother people in here, but since i am under a time pressure, i am desperate to get help. My questions is how to link the file choosen from a JChooser to a file, and how to converte it to stringm being able to display and edit it in a TextArea.
i hav ethe GUI set up using swing, but the link between actionListener and the Jchooser is not complete
Any help would be much appreciated
code:
http://pastebin.com/p3fb17Wi
Can anyone help in architecture design of one of my complex application.
Requirement :
In web based application, we need to generate Excel kind of report as HTML page
and after that we need to perform different kinds of operations like
Add manual rows
Delete rows
Edit rows
adding comments based on each cell
viewing the added comments.
attaching the file based on each cell
viewing the attached file.
Collapsible functionality for some of rows
In the process of design we have come up with DB design and application framework is Spring.
and for Web not yet finalized.
what is the best approach to implement this kind of UI?
--JSF?(keep in mind we need to Excel operations like above mentioned operations)
-- Any reporting tool which will provide editing functionality?
Please suggest me How can we do it? and what is the best technology for it? or is there any reporting tools?
I have 10 instances of the class movie which I wish to add to an Arraylist named Catalogue1
in a class containing a main method I write the following
ArrayList catalogue1= new ArrayList ()
//the class movie is defined in another class
Movie movie1= new Movie ()
Movie movie2= new Movie ()
Catalogue.Add (1, movie1)
What is wrong? Should I define somewhere what kind of Objects this arraylist named catalogue should contain?
Thank you in advance
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3));
private JPanel outputPanel = new JPanel(new GridLayout(1,1));
private JTextField serverTf = new JTextField("");
private JTextField pageTf = new JTextField("");
private JTextArea outputTa = new JTextArea();
private JButton connectBt = new JButton("Connect");
private JScrollPane outputSp = new JScrollPane(outputTa);
public void init()
{
setSize(500,500);
setLayout(new GridLayout(3,1));
add(addressEntryPanel);
addressEntryPanel.add(serverTf);
addressEntryPanel.add(pageTf);
addressEntryPanel.add(connectBt);
addressEntryPanel.setPreferredSize(new Dimension(50,50));
addressEntryPanel.setMaximumSize(addressEntryPanel.getPreferredSize());
addressEntryPanel.setMinimumSize(addressEntryPanel.getPreferredSize());
add(outputPanel);
outputPanel.add(outputSp);
outputTa.setLineWrap(true);
connectBt.addActionListener(this);
The problem is when debugging and putting it in a page the components / panels resize depending on the applet size. I don't want this. I want the textfields to be a certain size, and the text area to be a certain size. I've put stuff in there to set the size of them but they aren't working. How do I go about actually setting a strict size for either the components or the JPanel.
Hello,
I maintain a large document archive and I often use bit fields to record the status of my documents during processing or when validating them. My legacy code simply uses static int constants such as:
static int DOCUMENT_STATUS_NO_STATE = 0
static int DOCUMENT_STATUS_OK = 1
static int DOCUMENT_STATUS_NO_TIF_FILE = 2
static int DOCUMENT_STATUS_NO_PDF_FILE = 4
This makes it pretty easy to indicate the state a document is in, by setting the appropriate flags. For example:
status = DOCUMENT_STATUS_NO_TIF_FILE | DOCUMENT_STATUS_NO_PDF_FILE;
Since the approach of using static constants is bad practice and because I would like to improve the code, I was looking to use Enums to achieve the same. There are a few requirements, one of them being the need to save the status into a database as a numeric type. So there is a need to transform the enumeration constants to a numeric value. Below is my first approach and I wonder if this is the correct way to go about this?
class DocumentStatus{
public enum StatusFlag {
DOCUMENT_STATUS_NOT_DEFINED(1<<0),
DOCUMENT_STATUS_OK(1<<1),
DOCUMENT_STATUS_MISSING_TID_DIR(1<<2),
DOCUMENT_STATUS_MISSING_TIF_FILE(1<<3),
DOCUMENT_STATUS_MISSING_PDF_FILE(1<<4),
DOCUMENT_STATUS_MISSING_OCR_FILE(1<<5),
DOCUMENT_STATUS_PAGE_COUNT_TIF(1<<6),
DOCUMENT_STATUS_PAGE_COUNT_PDF(1<<7),
DOCUMENT_STATUS_UNAVAILABLE(1<<8),
private final long statusFlagValue;
StatusFlag(long statusFlagValue) {
this.statusFlagValue = statusFlagValue
}
public long getStatusFlagValue(){
return statusFlagValue
}
}
/**
* Translates a numeric status code into a Set of StatusFlag enums
* @param numeric statusValue
* @return EnumSet representing a documents status
*/
public EnumSet<StatusFlag> getStatusFlags(long statusValue)
{
EnumSet statusFlags = EnumSet.noneOf(StatusFlag.class)
StatusFlag.each { statusFlag ->
long flagValue = statusFlag.statusFlagValue
if ( (flagValue&statusValue ) == flagValue )
{
statusFlags.add(statusFlag)
}
}
return statusFlags
}
/**
* Translates a set of StatusFlag enums into a numeric status code
* @param Set if statusFlags
* @return numeric representation of the document status
*/
public long getStatusValue(Set<StatusFlag> flags)
{
long value=0
flags.each { statusFlag ->
value|=statusFlag.getStatusFlagValue()
}
return value
}
public static void main(String[] args) {
DocumentStatus ds = new DocumentStatus();
Set statusFlags = EnumSet.of(
StatusFlag.DOCUMENT_STATUS_OK,
StatusFlag.DOCUMENT_STATUS_UNAVAILABLE)
assert ds.getStatusValue( statusFlags )==258 // 0000.0001|0000.0010
long numericStatusCode = 56
statusFlags = ds.getStatusFlags(numericStatusCode)
assert !statusFlags.contains(StatusFlag.DOCUMENT_STATUS_OK)
assert statusFlags.contains(StatusFlag.DOCUMENT_STATUS_MISSING_TIF_FILE)
assert statusFlags.contains(StatusFlag.DOCUMENT_STATUS_MISSING_PDF_FILE)
assert statusFlags.contains(StatusFlag.DOCUMENT_STATUS_MISSING_OCR_FILE)
}
}
So I am using DocumentBuilderFactory and DocumentBuilder to parse an xml.
So it is DOM parser.
But what I am trying to do is extract byte-array data (its an image encoded in base64)
Store it in one object and later in code write it out to another xml encoded in base64.
What is the best way to store this in btw.
Store it as string? or as ByteArray?
How can I extract byte array data in best way and write it out.
I am not experienced with this so wanted to get opinion from the group.
UPDATE: I am given XML I do not have control of incoming XML that comes in binary64 encoded
< byte-array >
... base64 encoded image ...
< /byte-array >
Using parser I have I need to store this node and question is should that be byte or string
and then writing it out to another node in new xml. again in base64 encoding.
thanks
Hello,
I configure my web application to use SSL using my own self signed certificate. Everything is working fine but here my whole site is https now as i used :-
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
However, i only want my login page to use SSL and not complete site. What changes do i need to make in my application?
Thanks in advance :)
Assign the following 25 scores to a one dimensional int array called "temp"
34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66
Move the scores to a 2 dimensional int array called "scores" row wise
-- meaning the first 5 scores go into row 0 etc
For a project, I have to convert a binary string into (an array of) bytes and write it out to a file in binary.
Say that I have a sentence converted into a code string using a huffman encoding. For example, if the sentence was: "hello" h = 00 e = 01, l = 10, o = 11
Then the string representation would be 0001101011.
How would I convert that into a byte? <-- If that question doesn't make sense it's because I know little about bits/byte bitwise shifting and all that has to do with manipulating 1's and 0's.