Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#83 #100

Merged
merged 3 commits into from
Feb 10, 2024
Merged

#83 #100

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/urChatBasic/backend/logging/URLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ public static void init () throws IOException, URISyntaxException
logDir.mkdir();
}

System.setProperty("log4j2.configurationFile", DriverGUI.class.getResource(LOG4J_CONFIG_FILE).toURI().toString());
File logConfigFile = new File(DriverGUI.class.getResource(LOG4J_CONFIG_FILE).toURI());

if(!logConfigFile.exists())
throw new IOException("LOG FILE NOT FOUND");

// System.setProperty("log4j2.debug", "true");
System.setProperty("log4j2.configurationFile", logConfigFile.toString());

LOGGER = LoggerFactory.getLogger(URLogger.class);
LOGGER = LoggerFactory.getLogger("urchat");

Logger testLog = getLogger(LOGGER.getName(), Logger.class);

Expand Down
2 changes: 1 addition & 1 deletion src/urChatBasic/backend/utils/URPreferencesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ else if (URProfilesUtil.getActiveProfilePath().nodeExists(styleName))

} catch (Exception e)
{
Constants.LOGGER.error("Active Profile: ["+URProfilesUtil.getActiveProfileName()+"] Unable to load ["+loadedStyle.getAttribute("name")+"]"+ " attempted with path: " + stylePrefPath);
Constants.LOGGER.error("Active Profile: ["+URProfilesUtil.getActiveProfileName()+"] Unable to load ["+loadedStyle.getAttribute("name")+"]"+ " attempted with path: " + stylePrefPath, e);
return targetStyle;
}

Expand Down
27 changes: 16 additions & 11 deletions src/urChatBasic/backend/utils/URProfilesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,17 @@ public static String[] getProfiles ()
return profileNames;
}


public static void deleteProfile (String profileName)
{
deleteProfile(profileName, true);
}

public static void deleteProfile (String profileName, boolean fireListeners)
{
try
{
String[] allProfiles = getProfiles();

if(allProfiles.length > 1)
{
Constants.LOGGER.info( "Deleting profile [" + profileName + "].");
Constants.BASE_PREFS.node(profileName).removeNode();
fireListeners(EventType.DELETE);
}
else
throw new BackingStoreException("Unable to delete the last profile.");

if(profileName.equals(getActiveProfileName()))
{
if(profileExists(getDefaultProfile()))
Expand All @@ -85,6 +80,16 @@ public static void deleteProfile (String profileName)
}
}

if(allProfiles.length > 1)
{
Constants.LOGGER.info( "Deleting profile [" + profileName + "].");
Constants.BASE_PREFS.node(profileName).removeNode();
if(fireListeners)
fireListeners(EventType.DELETE);
}
else
throw new BackingStoreException("Unable to delete the last profile.");

} catch (BackingStoreException e)
{
Constants.LOGGER.error("Problem deleting profile [" + profileName +"]." + e.getLocalizedMessage());
Expand All @@ -96,7 +101,7 @@ public static void deleteProfile (String profileName)
*/
public static void deleteProfile ()
{
deleteProfile(getActiveProfileName());
deleteProfile(getActiveProfileName(), true);
}

public static String getActiveProfileName ()
Expand Down
59 changes: 32 additions & 27 deletions src/urChatBasic/backend/utils/URStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class URStyle extends SimpleAttributeSet
*
* @param defaultFont
*/
public URStyle(String name, Font defaultFont)
public URStyle (String name, Font defaultFont)
{
super();
this.addAttribute("name", name);
Expand All @@ -50,7 +50,7 @@ public URStyle(String name, Font defaultFont)
*
* @param defaultFont
*/
public URStyle(String name, Font defaultFont, Color defaultForeground, Color defaultBackground)
public URStyle (String name, Font defaultFont, Color defaultForeground, Color defaultBackground)
{
super();
this.addAttribute("name", name);
Expand All @@ -59,17 +59,22 @@ public URStyle(String name, Font defaultFont, Color defaultForeground, Color def
setBackground(defaultBackground);
}

public URStyle(SimpleAttributeSet fromAttributeSet)
public URStyle (SimpleAttributeSet fromAttributeSet)
{
super(fromAttributeSet);
}

public String getName()
public String getName ()
{
return getAttribute("name").toString();
}

public Font getFont()
public void setName (String newName)
{
addAttribute("name", newName);
}

public Font getFont ()
{
// int savedFontBoldItalic = 0;

Expand All @@ -84,8 +89,7 @@ public Font getFont()
fontMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(this) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
fontMap.put(TextAttribute.UNDERLINE, StyleConstants.isUnderline(this) ? TextAttribute.UNDERLINE_ON : -1);

Font styleFont = new Font(StyleConstants.getFontFamily(this), Font.PLAIN, StyleConstants.getFontSize(this))
.deriveFont(fontMap);
Font styleFont = new Font(StyleConstants.getFontFamily(this), Font.PLAIN, StyleConstants.getFontSize(this)).deriveFont(fontMap);

return styleFont;
// Font styleFont = new Font(StyleConstants.getFontFamily(this), savedFontBoldItalic,
Expand All @@ -94,7 +98,7 @@ public Font getFont()
// return styleFont;
}

public void setFont(Font newFont)
public void setFont (Font newFont)
{
StyleConstants.setFontFamily(this, newFont.getFamily());
StyleConstants.setBold(this, newFont.isBold());
Expand All @@ -103,84 +107,85 @@ public void setFont(Font newFont)
StyleConstants.setUnderline(this, isUnderline(newFont));
}

public Optional<Color> getForeground()
public Optional<Color> getForeground ()
{
if(getAttribute(StyleConstants.Foreground) != null)
if (getAttribute(StyleConstants.Foreground) != null)
return Optional.of(StyleConstants.getForeground(this));
else
return Optional.empty();
}

public Optional<Color> getBackground()
public Optional<Color> getBackground ()
{
if(getAttribute(StyleConstants.Background) != null)
if (getAttribute(StyleConstants.Background) != null)
return Optional.of(StyleConstants.getBackground(this));
else
return Optional.empty();
}

public Optional<Boolean> isBold()
public Optional<Boolean> isBold ()
{
if (getAttribute(StyleConstants.Bold) != null)
return Optional.of(StyleConstants.isBold(this));
else
return Optional.empty();
}

public Optional<Boolean> isItalic()
public Optional<Boolean> isItalic ()
{
if (getAttribute(StyleConstants.Italic) != null)
return Optional.of(StyleConstants.isItalic(this));
else
return Optional.empty();
}

public Optional<String> getFamily()
public Optional<String> getFamily ()
{
if (getAttribute(StyleConstants.FontFamily) != null)
return Optional.of(StyleConstants.getFontFamily(this));
else
return Optional.empty();
}

public Optional<Integer> getSize()
public Optional<Integer> getSize ()
{
if (getAttribute(StyleConstants.FontSize) != null)
return Optional.of(StyleConstants.getFontSize(this));
else
return Optional.empty();
}

public Optional<Boolean> isUnderline()
public Optional<Boolean> isUnderline ()
{
if (getAttribute(StyleConstants.Underline) != null)
if (getAttribute(StyleConstants.Underline) != null)
return Optional.of(StyleConstants.isUnderline(this));
else
return Optional.empty();
}

// https://docs.oracle.com/javase/6/docs/api/java/awt/font/TextAttribute.html#UNDERLINE
public static boolean isUnderline(Font targetFont)
public static boolean isUnderline (Font targetFont)
{
if (targetFont != null && targetFont.getAttributes().get(TextAttribute.UNDERLINE) != null)
return (int) targetFont.getAttributes().get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON;

return false;
}

public void setForeground(Color newColour)
public void setForeground (Color newColour)
{
StyleConstants.setForeground(this, newColour);
}

public void setBackground(Color newColour)
public void setBackground (Color newColour)
{
StyleConstants.setBackground(this, newColour);
}

public void load(Preferences prefPath)
public void load (Preferences prefPath)
{
try {
try
{
URStyle loadedStyle = URPreferencesUtil.loadStyle(this, prefPath);
setFont(loadedStyle.getFont());
loadedStyle.getForeground().ifPresent(fg -> setForeground(fg));
Expand All @@ -191,24 +196,24 @@ public void load(Preferences prefPath)
}
}

public static String getKeymap(Object attributeObject)
public static String getKeymap (Object attributeObject)
{
return getKeymap(attributeObject.toString());
}

public static String getKeymap(String attributeName)
public static String getKeymap (String attributeName)
{
return ATTRIBUTE_KEYMAP.get(attributeName);
}

public boolean equals(URStyle otherStyle)
public boolean equals (URStyle otherStyle)
{
return getFont().equals(otherStyle.getFont()) && getForeground().equals(otherStyle.getForeground())
&& getBackground().equals(otherStyle.getBackground());
}

@Override
public URStyle clone()
public URStyle clone ()
{
return (URStyle) super.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class URUncaughtExceptionHandler implements Thread.UncaughtExceptionHandl

@Override
public void uncaughtException(Thread t, Throwable e) {
Constants.LOGGER.error( "Uncaught exception: " + e.getLocalizedMessage(), e);
Constants.LOGGER.error( "Uncaught exception: " + e.getStackTrace(), e);
}
}
5 changes: 3 additions & 2 deletions src/urChatBasic/base/IRCChannelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void initChannel()
// this.myMenu = new ChannelPopUp();
createChannelPopUp();
fontDialog.setVisible(false);
fontDialog.addSaveListener(new SaveFontListener());
fontDialog.addFontSaveListener(new SaveFontListener());

myActions = new IRCActions(this);
}
Expand Down Expand Up @@ -1014,7 +1014,8 @@ public void setFont(Font f)
{
public void run()
{
lineFormatter.setFont(fontDialog.getFontPanel().getFont());
// lineFormatter.setFont(fontDialog.getFontPanel().getFont());
lineFormatter.setStyle(fontDialog.getFontPanel().getStyle());
}
});
} else
Expand Down
9 changes: 8 additions & 1 deletion src/urChatBasic/frontend/LineFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public LineFormatter(URStyle baseStyle, JTextPane docOwner ,final IRCServerBase
initStyles(baseStyle);
}

public void setStyle (URStyle newStyle)
{
targetStyle = newStyle.clone();
if (doc.getLength() > 0)
updateStyles(targetStyle);
}

public void setFont (Font newFont)
{
targetStyle.setFont(newFont);
Expand Down Expand Up @@ -156,6 +163,7 @@ public URStyle defaultStyle(String name, boolean load)
StyleConstants.setItalic(tempStyle, targetStyle.getFont().isItalic());

StyleConstants.setForeground(tempStyle, myForeground);
StyleConstants.setBackground(tempStyle, myBackground);

if (load)
tempStyle.load(settingsPath);
Expand Down Expand Up @@ -783,7 +791,6 @@ public URStyle getStyleAtPosition(int position, String relativeLine)
Constants.LOGGER.error(ble.getLocalizedMessage());
}
AttributeSet textStyle = doc.getCharacterElement(position).getAttributes();

return new URStyle(new SimpleAttributeSet(textStyle));
}

Expand Down
Loading
Loading