X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=ui%2FNavBar.java;h=e99115c329ede86d6cd7919618d6b0346134d39e;hb=faad7ff24ecb94772745ecb68ccf921d656dbeb6;hp=ba788f367d8fa92c4cfb6b4ae648baa8338b4ba2;hpb=e47e88eb1890632fdae5d5b0b0a84c2881a2c69b;p=fanfix.git diff --git a/ui/NavBar.java b/ui/NavBar.java index ba788f3..e99115c 100644 --- a/ui/NavBar.java +++ b/ui/NavBar.java @@ -80,7 +80,10 @@ public class NavBar extends ListenerPanel { }); page = new JTextField(Integer.toString(min)); - page.setPreferredSize(new Dimension(page.getPreferredSize().width * 2, + page.setPreferredSize( + new Dimension(new JButton("1234").getPreferredSize().width, + new JButton("dummy").getPreferredSize().height)); + page.setMaximumSize(new Dimension(Integer.MAX_VALUE, page.getPreferredSize().height)); page.addActionListener(new ActionListener() { @Override @@ -94,12 +97,12 @@ public class NavBar extends ListenerPanel { if (setIndex(pageNb)) fireActionPerformed(PAGE_CHANGED); } catch (NumberFormatException nfe) { - page.setText(Integer.toString(index + 1)); + page.setText(Integer.toString(index)); } } }); - maxPage = new JLabel(" of " + max); + maxPage = new JLabel("of " + max); next = new JButton(); next.addActionListener(new ActionListener() { @@ -122,13 +125,15 @@ public class NavBar extends ListenerPanel { this.add(first); this.add(previous); + this.add(new JLabel(" ")); this.add(page); + this.add(new JLabel(" ")); this.add(maxPage); + this.add(new JLabel(" ")); this.add(next); this.add(last); - label = new JLabel(""); - this.add(label); + this.add(label = new JLabel("")); this.min = min; this.max = max; @@ -150,23 +155,20 @@ public class NavBar extends ListenerPanel { } /** - * The current index, must be between {@link NavBar#min} and + * The current index, should be between {@link NavBar#min} and * {@link NavBar#max}, both inclusive. * * @param index * the new index * - * @return TRUE if the index changed - * - * @throws IndexOutOfBoundsException - * if the index is out of bounds according to - * {@link NavBar#getMin()} and {@link NavBar#getMax()}. + * @return TRUE if the index changed, FALSE if not (either it was already at + * that value, or it is outside of the bounds set by + * {@link NavBar#min} and {@link NavBar#max}) */ - public boolean setIndex(int index) { + public synchronized boolean setIndex(int index) { if (index != this.index) { if (index < min || (index > max && max != -1)) { - throw new IndexOutOfBoundsException(String.format( - "Index %d but min/max is [%d/%d]", index, min, max)); + return false; } this.index = index; @@ -199,7 +201,7 @@ public class NavBar extends ListenerPanel { * @param min * the new min */ - public void setMin(int min) { + public synchronized void setMin(int min) { this.min = min; if (index < min) { index = min; @@ -231,13 +233,13 @@ public class NavBar extends ListenerPanel { * @param max * the new max */ - public void setMax(int max) { + public synchronized void setMax(int max) { this.max = max; if (index > max && max != -1) { index = max; } - maxPage.setText(" of " + max); + maxPage.setText("of " + max); updateEnabled(); updateLabel(); } @@ -267,7 +269,7 @@ public class NavBar extends ListenerPanel { * * @return TRUE if it changed */ - public boolean next() { + public synchronized boolean next() { if (setIndex(index + 1)) { fireActionPerformed(PAGE_CHANGED); return true; @@ -281,7 +283,7 @@ public class NavBar extends ListenerPanel { * * @return TRUE if it changed */ - public boolean previous() { + public synchronized boolean previous() { if (setIndex(index - 1)) { fireActionPerformed(PAGE_CHANGED); return true; @@ -295,7 +297,7 @@ public class NavBar extends ListenerPanel { * * @return TRUE if it changed */ - public boolean first() { + public synchronized boolean first() { if (setIndex(min)) { fireActionPerformed(PAGE_CHANGED); return true; @@ -309,7 +311,7 @@ public class NavBar extends ListenerPanel { * * @return TRUE if it changed */ - public boolean last() { + public synchronized boolean last() { if (setIndex(max)) { fireActionPerformed(PAGE_CHANGED); return true; @@ -355,7 +357,7 @@ public class NavBar extends ListenerPanel { * Update the navigation buttons "enabled" state according to the current * index value. */ - private void updateEnabled() { + private synchronized void updateEnabled() { first.setEnabled(index > min); previous.setEnabled(index > min); next.setEnabled(index < max || max == -1);