git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix lib
[fanfix.git]
/
src
/
be
/
nikiroo
/
fanfix
/
reader
/
ui
/
GuiReaderNavBar.java
diff --git
a/src/be/nikiroo/fanfix/reader/ui/GuiReaderNavBar.java
b/src/be/nikiroo/fanfix/reader/ui/GuiReaderNavBar.java
index 0f3d8dc67ba6296629262e0b79399a0601a33670..099b3c87a0e66eb7d7074e3d58f350889c685f9d 100644
(file)
--- a/
src/be/nikiroo/fanfix/reader/ui/GuiReaderNavBar.java
+++ b/
src/be/nikiroo/fanfix/reader/ui/GuiReaderNavBar.java
@@
-36,17
+36,20
@@
public class GuiReaderNavBar extends JPanel {
* Create a new navigation bar.
* <p>
* The minimum must be lower or equal to the maximum.
* Create a new navigation bar.
* <p>
* The minimum must be lower or equal to the maximum.
+ * <p>
+ * Note than a max of "-1" means "infinite".
*
* @param min
*
* @param min
- * the minimum page number
+ * the minimum page number
(cannot be negative)
* @param max
* @param max
- * the maximum page number
+ * the maximum page number (cannot be lower than min, except if
+ * -1 (infinite))
*
* @throws IndexOutOfBoundsException
*
* @throws IndexOutOfBoundsException
- * if min > max
+ * if min > max
and max is not "-1"
*/
public GuiReaderNavBar(int min, int max) {
*/
public GuiReaderNavBar(int min, int max) {
- if (min > max) {
+ if (min > max
&& max != -1
) {
throw new IndexOutOfBoundsException(String.format(
"min (%d) > max (%d)", min, max));
}
throw new IndexOutOfBoundsException(String.format(
"min (%d) > max (%d)", min, max));
}
@@
-60,24
+63,28
@@
public class GuiReaderNavBar extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(GuiReaderNavBar.this.min);
@Override
public void actionPerformed(ActionEvent e) {
setIndex(GuiReaderNavBar.this.min);
+ fireEvent();
}
});
navButtons[1] = createNavButton(" < ", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(index - 1);
}
});
navButtons[1] = createNavButton(" < ", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(index - 1);
+ fireEvent();
}
});
navButtons[2] = createNavButton(" > ", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(index + 1);
}
});
navButtons[2] = createNavButton(" > ", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(index + 1);
+ fireEvent();
}
});
navButtons[3] = createNavButton(">>", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(GuiReaderNavBar.this.max);
}
});
navButtons[3] = createNavButton(">>", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setIndex(GuiReaderNavBar.this.max);
+ fireEvent();
}
});
}
});
@@
-114,15
+121,14
@@
public class GuiReaderNavBar extends JPanel {
* @param index
* the new index
*/
* @param index
* the new index
*/
- p
rivate
void setIndex(int index) {
+ p
ublic
void setIndex(int index) {
if (index != this.index) {
if (index != this.index) {
- if (index < min ||
index > max
) {
+ if (index < min ||
(index > max && max != -1)
) {
throw new IndexOutOfBoundsException(String.format(
"Index %d but min/max is [%d/%d]", index, min, max));
}
this.index = index;
throw new IndexOutOfBoundsException(String.format(
"Index %d but min/max is [%d/%d]", index, min, max));
}
this.index = index;
- fireEvent();
updateLabel();
}
updateLabel();
}
@@
-130,7
+136,7
@@
public class GuiReaderNavBar extends JPanel {
}
/**
}
/**
- * The minimun page number.
+ * The minimun page number.
Cannot be negative.
*
* @return the min
*/
*
* @return the min
*/
@@
-139,7
+145,7
@@
public class GuiReaderNavBar extends JPanel {
}
/**
}
/**
- * The minimum page number.
+ * The minimum page number.
Cannot be negative.
* <p>
* May update the index if needed (if the index is < the new min).
* <p>
* <p>
* May update the index if needed (if the index is < the new min).
* <p>
@@
-153,17
+159,15
@@
public class GuiReaderNavBar extends JPanel {
this.min = min;
if (index < min) {
index = min;
this.min = min;
if (index < min) {
index = min;
- updateEnabled();
- updateLabel();
- fireEvent();
- } else {
- updateEnabled();
- updateLabel();
}
}
+ updateEnabled();
+ updateLabel();
+
}
/**
}
/**
- * The maximum page number.
+ * The maximum page number. Cannot be lower than min, except if -1
+ * (infinite).
*
* @return the max
*/
*
* @return the max
*/
@@
-172,7
+176,8
@@
public class GuiReaderNavBar extends JPanel {
}
/**
}
/**
- * The maximum page number.
+ * The maximum page number. Cannot be lower than min, except if -1
+ * (infinite).
* <p>
* May update the index if needed (if the index is > the new max).
* <p>
* <p>
* May update the index if needed (if the index is > the new max).
* <p>
@@
-184,15
+189,11
@@
public class GuiReaderNavBar extends JPanel {
*/
public void setMax(int max) {
this.max = max;
*/
public void setMax(int max) {
this.max = max;
- if (index > max) {
+ if (index > max
&& max != -1
) {
index = max;
index = max;
- updateEnabled();
- updateLabel();
- fireEvent();
- } else {
- updateEnabled();
- updateLabel();
}
}
+ updateEnabled();
+ updateLabel();
}
/**
}
/**
@@
-246,9
+247,9
@@
public class GuiReaderNavBar extends JPanel {
}
/**
}
/**
- * Notify a chnge of page.
+ * Notify a ch
a
nge of page.
*/
*/
- p
rivate
void fireEvent() {
+ p
ublic
void fireEvent() {
for (ActionListener listener : listeners) {
try {
listener.actionPerformed(new ActionEvent(this,
for (ActionListener listener : listeners) {
try {
listener.actionPerformed(new ActionEvent(this,
@@
-289,8
+290,8
@@
public class GuiReaderNavBar extends JPanel {
private void updateEnabled() {
navButtons[0].setEnabled(index > min);
navButtons[1].setEnabled(index > min);
private void updateEnabled() {
navButtons[0].setEnabled(index > min);
navButtons[1].setEnabled(index > min);
- navButtons[2].setEnabled(index < max);
- navButtons[3].setEnabled(index < max);
+ navButtons[2].setEnabled(index < max
|| max == -1
);
+ navButtons[3].setEnabled(index < max
|| max == -1
);
}
/**
}
/**
@@
-313,7
+314,12
@@
public class GuiReaderNavBar extends JPanel {
protected String computeLabel(int index,
@SuppressWarnings("unused") int min, int max) {
protected String computeLabel(int index,
@SuppressWarnings("unused") int min, int max) {
- String base = " <B>Page <SPAN COLOR='#444466'>%d</SPAN> / %d</B>";
+ String base = " <B>Page <SPAN COLOR='#444466'>%d</SPAN> ";
+ if (max >= 0) {
+ base += "/ %d";
+ }
+ base += "</B>";
+
String ifLabel = ": %s";
String display = base;
String ifLabel = ": %s";
String display = base;
@@
-324,6
+330,10
@@
public class GuiReaderNavBar extends JPanel {
display = "<HTML>" + display + "</HTML>";
display = "<HTML>" + display + "</HTML>";
- return String.format(display, index, max, label);
+ if (max >= 0) {
+ return String.format(display, index, max, label);
+ }
+
+ return String.format(display, index, label);
}
}
}
}