Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Jun 20, 2020
2 parents 7cd1990 + 45c218d commit 72b7fdf
Show file tree
Hide file tree
Showing 24 changed files with 609 additions and 98 deletions.
3 changes: 2 additions & 1 deletion src/org/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.infinity.util.IdsMapCache;
import org.infinity.util.IniMapCache;
import org.infinity.util.Misc;
import org.infinity.util.Platform;
import org.infinity.util.StringTable;
import org.infinity.util.Table2daCache;
import org.infinity.util.io.DlcManager;
Expand Down Expand Up @@ -472,7 +473,7 @@ public void run()
setExtendedState(prefs.getInt(WINDOW_STATE, NORMAL));

// XXX: Workaround to trigger standard window closing callback on OSX when using command-Q
if (System.getProperty("os.name").startsWith("Mac OS X")) {
if (Platform.IS_MACOS) {
enableOSXQuitStrategy();
}

Expand Down
12 changes: 11 additions & 1 deletion src/org/infinity/datatype/SectionCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public final class SectionCount extends DecNumber
{
private final Class<? extends StructEntry> section;
private Class<? extends StructEntry> section;

public SectionCount(ByteBuffer buffer, int offset, int length, String desc,
Class<? extends StructEntry> section)
Expand All @@ -35,4 +35,14 @@ public Class<? extends StructEntry> getSection()
{
return section;
}

public void setSection(Class<? extends StructEntry> section)
{
if (!this.section.equals(section)) {
Class<? extends StructEntry> cls = this.section;
this.section = Objects.requireNonNull(section, "Class for SectionCount must not be null");
if (getParent() != null)
getParent().updateSectionCount(cls);
}
}
}
12 changes: 11 additions & 1 deletion src/org/infinity/datatype/SectionOffset.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public final class SectionOffset extends HexNumber
{
private final Class<? extends StructEntry> section;
private Class<? extends StructEntry> section;

public SectionOffset(ByteBuffer buffer, int offset, String desc,
Class<? extends StructEntry> section)
Expand All @@ -35,4 +35,14 @@ public Class<? extends StructEntry> getSection()
{
return section;
}

public void setSection(Class<? extends StructEntry> section)
{
if (!this.section.equals(section)) {
Class<? extends StructEntry> cls = this.section;
this.section = Objects.requireNonNull(section, "Class for SectionOffset must not be null");
if (getParent() != null)
getParent().updateSectionOffset(cls);
}
}
}
2 changes: 1 addition & 1 deletion src/org/infinity/gui/BrowserMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

public final class BrowserMenuBar extends JMenuBar implements KeyEventDispatcher
{
public static final String VERSION = "v2.1-20200502";
public static final String VERSION = "v2.1-20200620";
public static final LookAndFeelInfo DEFAULT_LOOKFEEL =
new LookAndFeelInfo("Metal", "javax.swing.plaf.metal.MetalLookAndFeel");

Expand Down
24 changes: 21 additions & 3 deletions src/org/infinity/gui/ColorGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.infinity.util.Platform;

/**
* Implements a grid of selectable color indices.
*/
Expand Down Expand Up @@ -729,9 +731,25 @@ private void updateDisplay(Graphics g)
int x = gapX + col*(gapX + colorSize.width);
int y = gapY + row*(gapY + colorSize.height);

g2d.setPaint(BackgroundPattern);
g2d.fillRect(x, y, colorSize.width, colorSize.height);
g2d.setPaint(null);
if (Platform.IS_UNIX) {
// XXX: Workaround for issue: java.lang.InternalError "Surface not cachable"
g2d.setColor(new Color(0xffffff));
g2d.fillRect(x, y, colorSize.width, colorSize.height);
g2d.setColor(new Color(0xc0c0c0));
for (int ofsY = 0; ofsY < colorSize.height; ofsY += 4) {
for (int ofsX = 0; ofsX < colorSize.width; ofsX += 4) {
if ((ofsY & 0x4) != (ofsX & 0x4)) {
int boxH = Math.min(4, colorSize.height - ofsY);
int boxW = Math.min(4, colorSize.width - ofsX);
g2d.fillRect(x + ofsX, y + ofsY, boxW, boxH);
}
}
}
} else {
g2d.setPaint(BackgroundPattern);
g2d.fillRect(x, y, colorSize.width, colorSize.height);
g2d.setPaint(null);
}

boolean alpha = (i != 0); // Color at index 0 is implicitly treated as transparent
g.setColor(new Color(listColors.get(i).getRGB(), alpha));
Expand Down
81 changes: 69 additions & 12 deletions src/org/infinity/gui/LinkButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,41 @@ final public class LinkButton extends JLabel implements MouseListener, ActionLis
* @param resourceRef The game resource as ResourceRef object.
*/
public LinkButton(ResourceRef resourceRef)
{
this(resourceRef, 0);
}

/**
* Creates a link button which points to an internal game resource as specified by the argument.
* @param resourceRef The game resource as ResourceRef object.
* @param maxLength Max. number of characters displayed in the label text. Full string is displayed as tooltip instead.
*/
public LinkButton(ResourceRef resourceRef, int maxLength)
{
super();
setHorizontalAlignment(SwingConstants.LEFT);
setResource(resourceRef);
setResource(resourceRef, maxLength);
}

/**
* Creates a link button which points to an internal game resource as specified by the argument.
* @param resourceName The game resource as string.
*/
public LinkButton(String resourceName)
{
this(resourceName, 0);
}

/**
* Creates a link button which points to an internal game resource as specified by the argument.
* @param resourceName The game resource as string.
* @param maxLength Max. number of characters displayed in the label text. Full string is displayed as tooltip instead.
*/
public LinkButton(String resourceName, int maxLength)
{
super();
setHorizontalAlignment(SwingConstants.LEFT);
setResource(resourceName);
setResource(resourceName, maxLength);
}

/**
Expand All @@ -65,54 +85,82 @@ public LinkButton(String resourceName)
* @param url The actual URL of the link.
*/
public LinkButton(String text, String url)
{
this(text, url, 0);
}

/**
* Creates a link button which points to an external URL.
* @param text The display name of the link.
* @param url The actual URL of the link.
* @param maxLength Max. number of characters displayed in the label text. Full string is displayed as tooltip instead.
*/
public LinkButton(String text, String url, int maxLength)
{
super();
setHorizontalAlignment(SwingConstants.LEFT);
setUrl(text, url);
setUrl(text, url, maxLength);
}

/** Creates a link from the specified resource reference. */
public void setResource(ResourceRef resourceRef)
{
setResource(resourceRef, 0);
}

/** Creates a link from the specified resource reference. */
public void setResource(ResourceRef resourceRef, int maxLength)
{
if (resourceRef != null) {
setResource(ResourceFactory.getResourceEntry(resourceRef.getResourceName()), resourceRef.toString());
setResource(ResourceFactory.getResourceEntry(resourceRef.getResourceName()), resourceRef.toString(), maxLength);
} else {
setResource(null, null);
setResource(null, null, maxLength);
}
}

/** Attempts to create a link from the specified resource name. */
public void setResource(String resourceName)
{
setResource(ResourceFactory.getResourceEntry(resourceName), resourceName);
setResource(ResourceFactory.getResourceEntry(resourceName), resourceName, 0);
}

/** Attempts to create a link from the specified resource name. */
public void setResource(String resourceName, int maxLength)
{
setResource(ResourceFactory.getResourceEntry(resourceName), resourceName, maxLength);
}

private void setResource(ResourceEntry entry, String resourceName)
private void setResource(ResourceEntry entry, String resourceName, int maxLength)
{
isResource = true;
removeActionListener(this);
this.entry = entry;
if (entry != null) {
addActionListener(this);
setLink(resourceName, entry.getResourceName(), true);
setLink(resourceName, entry.getResourceName(), true, maxLength);
setEnabled(true);
setToolTipText(null);
// setToolTipText(null);
} else {
setLink(resourceName, null, false);
setLink(resourceName, null, false, maxLength);
setEnabled(false);
setToolTipText("Resource not found");
}
}

/** Sets link or label text, depending on arguments. */
private void setLink(String text, String resource, boolean asLink)
private void setLink(String text, String resource, boolean asLink, int maxLength)
{
removeMouseListener(this);
setCursor(null);

if (text == null) {
text = resource;
}
String toolTip = null;
if (maxLength > 0 && text != null && text.length() > maxLength) {
toolTip = text;
text = text.substring(0, maxLength) + "...";
}

if (!asLink) {
setText(text);
Expand All @@ -123,10 +171,19 @@ private void setLink(String text, String resource, boolean asLink)
} else {
setText("");
}

if (toolTip != null)
setToolTipText(toolTip);
}

/** Creates a link to an external URL. */
public void setUrl(String text, String url)
{
setUrl(text, url, 0);
}

/** Creates a link to an external URL. */
public void setUrl(String text, String url, int maxLength)
{
isResource = false;
if (url == null || url.isEmpty()) {
Expand All @@ -137,7 +194,7 @@ public void setUrl(String text, String url)
}
this.url = url;
addActionListener(this);
setLink(text, url, true);
setLink(text, url, true, maxLength);
setEnabled(true);
}

Expand Down
4 changes: 3 additions & 1 deletion src/org/infinity/gui/StringEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ private void save(boolean interactive)
if (!Files.isDirectory(outPath)) {
outPath = outPath.getParent();
}
outFile = outPath.resolve(StringTable.getPath(StringTable.Type.MALE).getFileName());
outFile = outPath.resolve(StringTable.getPath(StringTable.Type.MALE).getFileName().toString());
} else {
JOptionPane.showMessageDialog(this, "Operation cancelled.", "Information",
JOptionPane.INFORMATION_MESSAGE);
Expand Down Expand Up @@ -770,6 +770,8 @@ private void save(boolean interactive)
JOptionPane.showMessageDialog(this, "File(s) written successfully.", "Save complete",
JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
bSync.setEnabled(isSync);
bAdd.setEnabled(isAdd);
Expand Down
Loading

0 comments on commit 72b7fdf

Please sign in to comment.