The GreekLetterWidget

I’m currently writing some maths software in which I wanted to be able to use Greek letters as well as Roman. Since Java uses Unicode, this was no problem internally. But how could the user input Greek as well as Roman characters, through a standard US/UK keyboard, and without obscure and slow character codes?

So I wrote a widget which had 25 buttons, labelled with the lower case Greek letters. It has an instance variable which is a reference to a textfield. When the user clicks a button, the corresponding character is appended to that textfield, and focus is placed on that textfield, ready for the next keystroke.

Here it is:

/**
 * This is a UI widget supporting the input of Greek letters
 * It produces a 5 X 5 grid of buttons, labelled with lower case Greek letters
 * When a button is clicked, the corresponding letter is appended to a supplied
 * text field
 * @author Walter Milner
 */
public class GreekLetterWidget extends JComponent implements ActionListener {
    private MyButton[] buttons = new MyButton[25];
    private MyTextField textField;
/**
 * make an instance, of size 100 by 100
 * @param textField The textfield to which the letter will be appended
 */
    public GreekLetterWidget(MyTextField textField) {
        this.textField = textField;
        setLayout(new GridLayout(5, 5));
        setSize(100, 100);
        // Greek letter buttons
        char[] c = new char[1];
        c[0] = ‘\u03B1′;
        String s = new String(c);
        Insets inset = new Insets(1, 1, 1, 1);
        for (int i = 0; i < 25; i++) {
            buttons[i] = new MyButton(s);
            buttons[i].setToolTipText(s);
            c[0]++;
            s = new String(c);
            buttons[i].setMargin(inset);
            buttons[i].addActionListener(this);
            add(buttons[i]);
        }
    }
    public void setField(MyTextField target)
    {
        textField=target;
    }
    public void actionPerformed(ActionEvent e) {
        Object obj = e.getSource();
        textField.setText(textField.getText() + ((MyButton) obj).getText());
        textField.requestFocus();
    }
}

This looks like:

screenshot

screenshot

The widget is used (in a sub-classed JDialog using a GridBagLayout) with code like this
glw = new GreekLetterWidget(funcTextField);
c.gridx = 3;
c.gridy = 0;
c.gridheight = 2;
add(glw, c);

The setTextField() method is provided so that this can be used with more than one text field in a dialog. The textfields need to have a focuslistener, and in the gainFocus, setTextField is called with that text field as the parameter. That means that when the user clicks on a textfield, from then on GreekLetter button clicks go into that text field.

Published in: on June 17, 2009 at 8:09 am Leave a Comment
Tags: , , , ,

Padding a JLabel

Googling for this was pretty fruitless, but I eventually got a hint, which worked out OK. The hack is to have an ‘empty’ border around the text. If you also want a visible border, you can combine that with the empty border in a compound border. So you have something like:

public class MyLabel extends JLabel {
    static Font labelFont = new Font(”SansSerif”, Font.PLAIN, 12);
    static Border gap = BorderFactory.createEmptyBorder(4, 2, 4, 2);
    static Border blueline = BorderFactory.createLineBorder(Color.blue);
    static Border compound = BorderFactory.createCompoundBorder(blueline, gap);
    MyLabel(String text) {
        super(text);
        setFont(labelFont);
        setBorder(compound);
    }
}

which looks like:

screenshot

screenshot

Published in: on at 7:44 am Leave a Comment
Tags: , , , ,

Fodor’s Concepts – Where Cognitive Science Went Wrong

I’m into the first chapter, then I had to go back to the ‘Typological Conventions’ at the start. And I found that these were not straight-forward. Here is a version:

Rule 1: Names of concepts are written in capitals

Rule 2: Names of English expressions appear in single quotes.

Rule 3: Names of semantic values of words and concepts are written in italics.

At a glance, this is clear. But if you think carefully, it entails a great deal – possibly the whole book. To start with, it refers to names. Do these kinds of things have names? For example, does the English phrase ‘red’ have a name? If so, what is it? Is it the word red?

What is a name? In terms of how the term is used (hence a Wittgensteinian approach), names are used where there are a set of similar things, and names arbitrarily label and distinguish them. For example, ‘What is the name of this mountain?’, ‘What is the name of this river?’, ‘What is your name?’ and so on. Otherwise, things don’t have names. Or you could ask ‘What is the name of your name?’  Since your name is (more or less) unique, it does not need a name to distinguish it from other names.

I think here ‘name’ is used as in ‘is expressed by’. Then we would have a modified version

1. Concepts are expressed by text written in capitals.

2. Phrases are expressed by text in quotes.

3. Semantic values of words and concepts are expressed in italics.

However the third rule also entails the assertion that word phrases and concepts have ’semantic values’.  So this would be more explicit as follows:

1. Words and concepts both have associated semantic values

2. Semantic values are expressed in italics

3. Concepts are expressed in capitals

4. Word phrases are expressed in quotes ( to distinguish them from surrounding text which discusses the word phrases).

Then, for example, the concept RED and the word ‘red’ both have the semantic value being red.

But that asserts that words and concepts mean things, and it seems that if a word phrase and a concept mean the same thing, the concept is redundant, and we only need to discuss the word phrase and its meaning. But I suppose that would beg the question of why some phrases, like ‘Colorless green ideas’, do not have meanings.

Published in: on June 2, 2009 at 11:02 am Leave a Comment

The death of J.G.Ballard

Just heard the news. Things like The Crystal World, The Drowned World, The Atrocity Exhibition, Crash, The Day of Creation, The Terminal Beach were incredibly good. His visions were surreal, obsessive, neurotic, fascinating, and his writing exposed the stuff in our heads as being far weirder than we might care for, so that the most bizarre was in fact recognisable and familar.

If you haven’t read him, do so. Like the advert says, he’s worth it.

Published in: on April 20, 2009 at 10:37 am Leave a Comment

Oil is running out. Hello!!?? OIL IS RUNNING OUT!!!

Gore’s film ‘An Inconvenient Truth’ tries to raise consciousness of the threat of global warming caused by CO2 levels in the atmosphere. I’m just becoming aware of the significance of another change – no more oil.

Have a look at Peak Oil. The modelling done by Hubbert back in 1956 turned out to be very accurate. Many nations (including the UK) have already passed Peak Oil. It would be irrational to suppose that reserves in Saudi Arabia are effectively infinite. So all the data  predicts that somewhere in the next 3 decades, we will run out of oil and gas.

What would it be like in developed nations without a car? How would you get to work? What would then happen to suburbia? You can live without working, but not without food. How would food be distributed to supermarkets? Prior to that, how would food be produced without agricultural machinery? Tractor engines have 400 horse power – what farm has 400 horses? Where do the insecticides and fertilizers come from? What does that imply for current world population levels?

So you need an alternative energy source – wind/tidal or nuclear. Biofuels could not be produced in sufficient quantity – not that and grow food (see last paragraph). But that is needed within the next 30 years at the most. How long does it take to design and build a nuclear power station? How many in the UK currently have approved plans? None.

If you could produce sufficient nuclear power quickly enough, vehicles would need effective batteries – or fuel cells at a reasonable cost. That might come to pass, with a lot of R and D. Maybe. Otherwise.. well, nothing that I know of. Hydrogen maybe, but you still need power to produce it. Most people snigger about electric cars. I know they don’t work very well. But they are about as effective, in terms of range and speed, as a horse. And that will be the only alternative.

But what about nations which do not have nuclear power? What will happen to them? In that light, what do the ambitions of Iran look like?

On the positive side – no global warming. That’s OK then.

Published in: on April 16, 2009 at 11:56 am Comments (3)
Tags: , , , ,

How people learn

This is an attempt to describe how ‘adults’ learn new concepts in a formal setting, such as a college course. I’m mostly thinking about ’scientific’ subjects like maths physics and computing. I’m using learning Java as the source of examples.

It uses some other ideas. Two crucial ones are frames and mental spaces . Read that link if you are interested in this and want to make sense of this blog.  It also uses the idea of a compression.

Psychologists have usually treated concepts as categories, delineated by a definition. Work by people like Rosch showed this was simplistic, with ‘real’ concepts being more complex than this. This led to the idea of concept being based on an ‘ideal’ instance (prototype theory), a set of remembered examples (exemplars), and degree of possession of typical features (typicality).

Moving beyond concept as category, Neisser and others developed the idea of concept as implicit theory – which is very relevant to ‘understanding’ an idea. To understand what a Java object is, we need a lot more than simply to be able to decide if something is an object or not.

Typical college teaching shows all of the aspects of concepts. Often definitions are given, examples, descriptions (usually of typical instances) and so on. In addition, students will usually work through ‘exercises’ in which they are obliged to engage actively with some examples.

There is a particular problem if there is no definition of a concept. For example, the Java class/object concept has no semantic definition ( the syntax of a class definition is available, but it is no use to a student trying to understand what a class is). In this situation there is usually some teaching discourse (in a textbook or lecture) which tries to deliver an understanding of the idea through prose – but this is extremely difficult. For example one standard Java student text says that ‘objects belong to classes’. But this strongly suggests that a class is a set, and an object is an element in the set, which supports the partonomy/taxonomy confusion.

In these situations we have general concepts (class/object, or type) and examples ( JButtons, JFrames, classes developed by the student in lab sessions, or for type, ints, chars, doubles, booleans and so on).

A student coming to understand these general concepts does so by taking the examples (a multiplicity of mental spaces which include the examples), and compressing them into a frame. That’s it.

Students are individuals, and there are individual differences. For example one student may be slow to do this – he may be very fluent handling ints and doubles, while denying any recognition of the idea of type. Other students may actually do this too fast – rather as infants over-generalize terms. For example one student had absorbed the idea of inheritance, and had then assumed that ActionListener, WindowListener, MouseMotionListener and so on were sub-classes of a common base class ( semantically correct but syntactically wrong, since these are interfaces and not classes).

Published in: on February 1, 2009 at 11:58 am Comments (2)
Tags: , , , , , , ,

An example blend

How do we really understand ideas? How do we make sense of things beyond the purely concrete? Like time, or jokes, or freedom, or software? That’s my question.

And I think at least part of the answer is as conceptual blends. Not my idea – it comes largely from Gilles Fauconnier. Let me outline one of his examples.

The idea of a ‘computer virus’. An irritating idea, but also creative and imaginative.

Blends have (usually) 2 input spaces. In this case, one is a computer program. This space has several ’slots’
Made by a human (programmer)
Useful
Needs computer hardware to run on

The other input space is a biological virus
Made by evolution
Harmful
Needs host living cell
Reproduces

Then we do a selective projection of these slots. In other words, we pick some from one input and some from the other. This is very precise – its not a blend as in food blender – we don’t get mush. In the output space we have

Made by a programmer
Harmful
Needs host hardware
Reproduces

And there you have a new idea.

But this is not at a conscious explicit level – the first people to write viruses did not work it out like this, in the sense that they were aware of what they were doing in this way. The hypothesis is that the human central nervous system holds, uses and transforms concepts in a way somehow related to the process described here.

Published in: on January 28, 2009 at 12:52 pm Comments (1)
Tags: , , , ,

What a Java class really is

At the heart of OOP is a statement like
someObject.someMethod();
This is usually decribed as ‘calling’ or ‘invoking’ someMethod on the object someObject.

It is an imperative, and it is usually described as sending a ‘message’ to someObject, telling it to do someMethod. This is a more or less explict metaphor, built on top of metaphors we are probably unaware of – unless we have read Lakoff. But there are big problems with it. As a minor point, the ‘message’ metaphor has two difficulties
1. Messages are asynchronous. If I send you a message by email or SMS or post, it might be several days before you read it.
2. Messages are optional – they can be ignored.

But the big problem is who is the agent – that is, who is the imperative addressed to – who is supposed to do it? In English, this is implicit, as in
“Stand up!”
or explicit, as in
“No-one leaves the hall, Sargeant!”
Usually the Java form
someObject.someMethod();
is thought of as a message TO someObject, telling IT to do its someMethod. This is wrong, since the agent which executes the method is actually the ’system’, the JRE. Futher, it breaks the metaphor, since often the method is something which happens TO the object, not carried out by him. Eg in a personnel system we might have a method to fire an employee, and we would say
joe.dismiss();
but Joe does not dismiss himself – it is done to him.

So what does the . actually mean? It is to identify the namespace of the method, and the object primarily affected. That is, someMethod() might occur in several classes. Which one do we want? The one in the class that someObject belongs to. And which object will someMethod() primarily affect? someObject.

So a class is a namespace.

Published in: on January 27, 2009 at 10:18 am Leave a Comment
Tags: , , , , , ,

He drenched beer into his jacket

You can’t say that – yeah? The correct version would be
‘He drenched his jacket with beer’

This post is to understand something in ‘The Stuff of Thought’ by Steve Pinker.

Some things you can say 2 ways eg
He splashed paint onto the wall
He splashed the wall with paint.

or
He rubbed oil into the wood
He rubbed the wood with oil.

But other verbs only work one way (the * is the ‘wrong’ form):
He nailed posters onto the board
*He nailed the board with posters.

He covered the bed with an afghan
*He covered an afghan onto the bed

He poured water into the glass
*He poured the glass with water.

Why do some verbs work both ways, while others only work one way (and of those, some work with the ‘with’ version, and some don’t).

One option is that this is just how it is, and to learn English you have to learn them one at a time. But Pinker’s answer (original paper by Beth Levin – reference at the end) is that the correct syntax depends on the meaning of the verb, at a deep level.

All the sentences contain a term for the role of ‘content’, which is some stuff, and a ‘container’, which is a place or holder or locator. So for example in
He drenched his jacket with beer
the jacket is the container, and beer is the content, the stuff which goes ‘into’ the container.

All the sentences have a direct object, which is ‘the thing affected’. In
He drenched his jacket with beer
the direct object is the jacket (’he’ is the subject, and ‘beer’ is the oblique object).

The point – the correct syntactic form is determined by whether the verb is ‘about’ the content or the container.

The verbs to drench and to cover are ‘about’ the container, so sentences with them have to have the container as the direct object. So you cannot say
He drenched beer onto his jacket, nor
He covered a cloth onto the table

The verbs nail, pour and coil are about the content, so they cannot have the container as the direct object – that is, not
He poured the glass with water, nor
He coiled the pole with rope ( but ‘He coiled rope around the pole’ is OK)

Some verbs are ‘about’ both container and content, so you can say either eg
He loaded hay onto the wagon, and
He loaded the wagon with hay.

All these have the same syntactic form:
subject – verb – direct object – preposition – oblique object
but if you fill those slots arbitrarily, you get things like
He drenched beer into his jacket
which are wrong, in the sense that a native speaker would not normally say them, and the reason they would not is the deep meaning of the verb.

Original paper:

Levin, B. 1985 Lexical semantics in review: An Introduction (Lexicon Project Working Paper #1) Cambridhge Mass: MIT Center for Cognitive Science

Published in: on January 26, 2009 at 1:34 pm Leave a Comment

Brace yourselves for impact

The FSA’s ban on short selling ended at close of play on Friday, just when Barclays was saying ‘I don’t know why you’re all selling my shares, there’s nothing wrong with us.. Really.. Stop selling.. Please”

A coincidence that suggests there might be a bit of a todo on Monday. Let’s see..

Well of course there was, but that had more to do with the largest corporate loss in UK history than any other factor. Sometimes facts overrule sentiment – but here they both pulled in the same direction.

Published in: on January 17, 2009 at 9:57 am Leave a Comment
Tags: , , , ,